diff --git a/sampler/src/main/java/atlantafx/sampler/page/components/TreePage.java b/sampler/src/main/java/atlantafx/sampler/page/components/TreePage.java index 92721d1..39a6691 100644 --- a/sampler/src/main/java/atlantafx/sampler/page/components/TreePage.java +++ b/sampler/src/main/java/atlantafx/sampler/page/components/TreePage.java @@ -109,10 +109,8 @@ public class TreePage extends AbstractPage { // copy existing style classes and properties to the new tree findDisplayedTree().ifPresent(tv -> { List currentStyles = tv.getStyleClass(); - System.out.println("C = " + currentStyles); currentStyles.remove("tree-view"); newTree.getStyleClass().addAll(currentStyles); - System.out.println("N = " + newTree.getStyleClass()); newTree.setShowRoot(tv.isShowRoot()); newTree.setDisable(tv.isDisable()); diff --git a/sampler/src/main/java/atlantafx/sampler/page/general/ColorBlock.java b/sampler/src/main/java/atlantafx/sampler/page/general/ColorBlock.java index 59e594a..0195b5e 100644 --- a/sampler/src/main/java/atlantafx/sampler/page/general/ColorBlock.java +++ b/sampler/src/main/java/atlantafx/sampler/page/general/ColorBlock.java @@ -71,10 +71,8 @@ class ColorBlock extends VBox { if (bgFill == null) { return; } toggleHover(true); - // doesn't play quite well with transparency, because we not calc - // actual underlying background color to flatten bgFill - expandIcon.setFill(getColorLuminance(flattenColor(bgBaseColor.get(), bgFill)) < LUMINANCE_THRESHOLD ? - Color.WHITE : Color.BLACK + expandIcon.setFill( + getColorLuminance(flattenColor(bgBaseColor.get(), bgFill)) < LUMINANCE_THRESHOLD ? Color.WHITE : Color.BLACK ); }); colorBox.setOnMouseExited(e -> toggleHover(false)); diff --git a/sampler/src/main/java/atlantafx/sampler/page/general/TypographyPage.java b/sampler/src/main/java/atlantafx/sampler/page/general/TypographyPage.java index 3eefd96..7aa6153 100755 --- a/sampler/src/main/java/atlantafx/sampler/page/general/TypographyPage.java +++ b/sampler/src/main/java/atlantafx/sampler/page/general/TypographyPage.java @@ -14,6 +14,8 @@ import javafx.scene.control.Label; import javafx.scene.control.Spinner; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; +import javafx.scene.layout.Pane; +import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.scene.text.TextFlow; @@ -27,13 +29,14 @@ import static atlantafx.base.theme.Styles.*; public class TypographyPage extends AbstractPage { private static final double CONTROL_WIDTH = 200; + private static final String DEFAULT_FONT_ID = "Default"; public static final String NAME = "Typography"; @Override public String getName() { return NAME; } - private GridPane fontSizeSampleContent; + private Pane fontSizeSampleContent; public TypographyPage() { super(); @@ -51,7 +54,7 @@ public class TypographyPage extends AbstractPage { controlsGrid.add(fontSizeSpinner(), 1, 1); var fontSizeSample = fontSizeSample(); - fontSizeSampleContent = (GridPane) fontSizeSample.getContent(); + fontSizeSampleContent = (Pane) fontSizeSample.getContent(); userContent.getChildren().setAll( controlsGrid, @@ -68,14 +71,14 @@ public class TypographyPage extends AbstractPage { final var tm = ThemeManager.getInstance(); ComboBox comboBox = new ComboBox<>(); - comboBox.getItems().add(tm.getFontFamily()); + comboBox.getItems().add(tm.isDefaultFontFamily() ? DEFAULT_FONT_ID : tm.getFontFamily()); comboBox.getItems().addAll(FXCollections.observableArrayList(Font.getFamilies())); comboBox.setPrefWidth(CONTROL_WIDTH); comboBox.getSelectionModel().select(tm.getFontFamily()); comboBox.valueProperty().addListener((obs, old, val) -> { if (val != null) { - tm.setFontFamily(val); + tm.setFontFamily(DEFAULT_FONT_ID.equals(val) ? ThemeManager.DEFAULT_FONT_FAMILY_NAME : val); tm.reloadCustomCSS(); updateFontInfo(Duration.ofMillis(1000)); } @@ -153,15 +156,50 @@ public class TypographyPage extends AbstractPage { } private SampleBlock fontWeightSample() { - var box = new HBox(10, + var sample1 = new HBox(10, text("Bold", TEXT_BOLD), text("Bolder", TEXT_BOLDER), text("Normal", TEXT_NORMAL), text("Lighter", TEXT_LIGHTER) ); - box.setAlignment(Pos.BASELINE_LEFT); + sample1.setAlignment(Pos.BASELINE_LEFT); - return new SampleBlock("Font weight", box); + var sample2 = new HBox(10, + textInlineStyle("900", "-fx-font-weight:900;"), + textInlineStyle("800", "-fx-font-weight:800;"), + textInlineStyle("700", "-fx-font-weight:700;"), + textInlineStyle("600", "-fx-font-weight:600;"), + textInlineStyle("500", "-fx-font-weight:500;"), + textInlineStyle("400", "-fx-font-weight:400;"), + textInlineStyle("300", "-fx-font-weight:300;"), + textInlineStyle("200", "-fx-font-weight:200;"), + textInlineStyle("100", "-fx-font-weight:100;") + ); + sample2.setAlignment(Pos.BASELINE_LEFT); + + var sample3 = new HBox(10, + textInlineStyle("900", "-fx-font-family:'Inter Black';"), + textInlineStyle("800", "-fx-font-family:'Inter Extra Bold';"), + textInlineStyle("700", "-fx-font-family:'Inter Bold';"), + textInlineStyle("600", "-fx-font-family:'Inter Semi Bold';"), + textInlineStyle("500", "-fx-font-family:'Inter Medium';"), + textInlineStyle("400", "-fx-font-family:'Inter Regular';"), + textInlineStyle("300", "-fx-font-family:'Inter Light';"), + textInlineStyle("200", "-fx-font-family:'Inter Extra Light';"), + textInlineStyle("100", "-fx-font-family:'Inter Thin';") + ); + sample3.setAlignment(Pos.BASELINE_LEFT); + + // JDK-8090423: https://bugs.openjdk.org/browse/JDK-8090423 + // Workaround: https://edencoding.com/resources/css_properties/fx-font-weight/ + return new SampleBlock("Font weight", new VBox(10, + sample1, + sample2, + sample3, + text("JavaFX only supports Bold or Regular font weight. See the source code for workaround.", + TEXT, TEXT_SMALL, DANGER + ) + )); } private SampleBlock fontStyleSample() { @@ -212,6 +250,12 @@ public class TypographyPage extends AbstractPage { return t; } + private Text textInlineStyle(String text, String style) { + var t = new Text(text); + t.setStyle(style); + return t; + } + private Hyperlink hyperlink(String text, boolean visited, boolean disabled) { var h = new Hyperlink(text); h.setVisited(visited); diff --git a/sampler/src/main/java/atlantafx/sampler/theme/ThemeManager.java b/sampler/src/main/java/atlantafx/sampler/theme/ThemeManager.java index 947add1..44decc7 100644 --- a/sampler/src/main/java/atlantafx/sampler/theme/ThemeManager.java +++ b/sampler/src/main/java/atlantafx/sampler/theme/ThemeManager.java @@ -19,7 +19,7 @@ public final class ThemeManager { private static final String DUMMY_STYLESHEET = Resources.getResource("assets/styles/empty.css").toString(); private static final PseudoClass USER_CUSTOM = PseudoClass.getPseudoClass("user-custom"); - private static final String DEFAULT_FONT_FAMILY_NAME = "Application Default"; + public static final String DEFAULT_FONT_FAMILY_NAME = "Inter"; // KEY | VALUE // -fx-property | value; @@ -99,10 +99,15 @@ public final class ThemeManager { } public void setFontFamily(String fontFamily) { + Objects.requireNonNull(fontFamily); setCustomDeclaration("-fx-font-family", "\"" + fontFamily + "\""); this.fontFamily = fontFamily; } + public boolean isDefaultFontFamily() { + return Objects.equals(DEFAULT_FONT_FAMILY_NAME, getFontFamily()); + } + public int getFontSize() { return fontSize; } diff --git a/sampler/src/main/resources/assets/fonts/Inter-Bold.otf b/sampler/src/main/resources/assets/fonts/Inter-Bold.otf deleted file mode 100755 index d5c49b8..0000000 Binary files a/sampler/src/main/resources/assets/fonts/Inter-Bold.otf and /dev/null differ diff --git a/sampler/src/main/resources/assets/fonts/Inter-Italic.otf b/sampler/src/main/resources/assets/fonts/Inter-Italic.otf deleted file mode 100755 index eb772c8..0000000 Binary files a/sampler/src/main/resources/assets/fonts/Inter-Italic.otf and /dev/null differ diff --git a/sampler/src/main/resources/assets/fonts/Inter-Medium.otf b/sampler/src/main/resources/assets/fonts/Inter-Medium.otf deleted file mode 100755 index c5075ca..0000000 Binary files a/sampler/src/main/resources/assets/fonts/Inter-Medium.otf and /dev/null differ diff --git a/sampler/src/main/resources/assets/fonts/Inter-Regular.otf b/sampler/src/main/resources/assets/fonts/Inter-Regular.otf deleted file mode 100755 index f3a05e7..0000000 Binary files a/sampler/src/main/resources/assets/fonts/Inter-Regular.otf and /dev/null differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-Black.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-Black.otf new file mode 100644 index 0000000..8684287 Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-Black.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-BlackItalic.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-BlackItalic.otf new file mode 100644 index 0000000..7001434 Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-BlackItalic.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-Bold.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-Bold.otf new file mode 100644 index 0000000..502bba3 Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-Bold.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-BoldItalic.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-BoldItalic.otf new file mode 100644 index 0000000..a1f7d88 Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-BoldItalic.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-ExtraBold.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-ExtraBold.otf new file mode 100644 index 0000000..7410f73 Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-ExtraBold.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-ExtraBoldItalic.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-ExtraBoldItalic.otf new file mode 100644 index 0000000..7d451cb Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-ExtraBoldItalic.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-ExtraLight.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-ExtraLight.otf new file mode 100644 index 0000000..6e9672f Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-ExtraLight.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-ExtraLightItalic.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-ExtraLightItalic.otf new file mode 100644 index 0000000..e7789f9 Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-ExtraLightItalic.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-Italic.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-Italic.otf new file mode 100644 index 0000000..4e2906e Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-Italic.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-Light.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-Light.otf new file mode 100644 index 0000000..80ee72b Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-Light.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-LightItalic.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-LightItalic.otf new file mode 100644 index 0000000..ba2cb1b Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-LightItalic.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-Medium.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-Medium.otf new file mode 100644 index 0000000..6604db3 Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-Medium.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-MediumItalic.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-MediumItalic.otf new file mode 100644 index 0000000..ea66c5a Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-MediumItalic.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-Regular.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-Regular.otf new file mode 100644 index 0000000..fdb121d Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-Regular.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-SemiBold.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-SemiBold.otf new file mode 100644 index 0000000..78482e6 Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-SemiBold.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-SemiBoldItalic.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-SemiBoldItalic.otf new file mode 100644 index 0000000..e74b874 Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-SemiBoldItalic.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-Thin.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-Thin.otf new file mode 100644 index 0000000..90def70 Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-Thin.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/Inter-ThinItalic.otf b/sampler/src/main/resources/assets/fonts/Inter/Inter-ThinItalic.otf new file mode 100644 index 0000000..cc7419c Binary files /dev/null and b/sampler/src/main/resources/assets/fonts/Inter/Inter-ThinItalic.otf differ diff --git a/sampler/src/main/resources/assets/fonts/Inter/LICENSE.txt b/sampler/src/main/resources/assets/fonts/Inter/LICENSE.txt new file mode 100644 index 0000000..ff80f8c --- /dev/null +++ b/sampler/src/main/resources/assets/fonts/Inter/LICENSE.txt @@ -0,0 +1,94 @@ +Copyright (c) 2016-2020 The Inter Project Authors. +"Inter" is trademark of Rasmus Andersson. +https://github.com/rsms/inter + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION AND CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/sampler/src/main/resources/assets/styles/index.css b/sampler/src/main/resources/assets/styles/index.css index 6f2a28b..16341bb 100755 --- a/sampler/src/main/resources/assets/styles/index.css +++ b/sampler/src/main/resources/assets/styles/index.css @@ -1,12 +1,115 @@ /** SPDX-License-Identifier: MIT */ @font-face { - font-family: "Application Default"; - src: url('../fonts/Inter-Regular.otf'); + font-family: "Inter"; + font-weight: 900; + src: url('../fonts/Inter/Inter-Black.otf') format('truetype'); +} +@font-face { + font-family: "Inter"; + font-weight: 900; + font-style: italic, oblique; + src: url('../fonts/Inter/Inter-BlackItalic.otf') format('truetype'); +} + +@font-face { + font-family: "Inter"; + font-weight: 800; + src: url('../fonts/Inter/Inter-ExtraBold.otf') format('truetype'); +} +@font-face { + font-family: "Inter"; + font-weight: 800; + font-style: italic, oblique; + src: url('../fonts/Inter/Inter-ExtraBoldItalic.otf') format('truetype'); +} + +@font-face { + font-family: "Inter"; + font-weight: 700; + src: url('../fonts/Inter/Inter-Bold.otf') format('truetype'); +} +@font-face { + font-family: "Inter"; + font-weight: 700; + font-style: italic, oblique; + src: url('../fonts/Inter/Inter-BoldItalic.otf') format('truetype'); +} + +@font-face { + font-family: "Inter"; + font-weight: 600; + src: url('../fonts/Inter/Inter-SemiBold.otf') format('truetype'); +} +@font-face { + font-family: "Inter"; + font-weight: 600; + font-style: italic, oblique; + src: url('../fonts/Inter/Inter-SemiBoldItalic.otf') format('truetype'); +} + +@font-face { + font-family: "Inter"; + font-weight: 500; + src: url('../fonts/Inter/Inter-Medium.otf') format('truetype'); +} +@font-face { + font-family: "Inter"; + font-weight: 500; + font-style: italic, oblique; + src: url('../fonts/Inter/Inter-MediumItalic.otf') format('truetype'); +} + +@font-face { + font-family: "Inter"; + font-weight: 400; + src: url('../fonts/Inter/Inter-Regular.otf') format('truetype'); +} +@font-face { + font-family: "Inter"; + font-weight: 400; + font-style: italic, oblique; + src: url('../fonts/Inter/Inter-Italic.otf') format('truetype'); +} + +@font-face { + font-family: "Inter"; + font-weight: 300; + src: url('../fonts/Inter/Inter-Light.otf') format('truetype'); +} +@font-face { + font-family: "Inter"; + font-weight: 300; + font-style: italic, oblique; + src: url('../fonts/Inter/Inter-LightItalic.otf') format('truetype'); +} + +@font-face { + font-family: "Inter"; + font-weight: 200; + src: url('../fonts/Inter/Inter-ExtraLight.otf') format('truetype'); +} +@font-face { + font-family: "Inter"; + font-weight: 200; + font-style: italic, oblique; + src: url('../fonts/Inter/Inter-ExtraLightItalic.otf') format('truetype'); +} + +@font-face { + font-family: "Inter"; + font-weight: 100; + src: url('../fonts/Inter/Inter-Thin.otf') format('truetype'); +} +@font-face { + font-family: "Inter"; + font-weight: 100; + font-style: italic, oblique; + src: url('../fonts/Inter/Inter-ThinItalic.otf') format('truetype'); } .root { - -fx-font-family: "Application Default"; + -fx-font-family: "Inter"; } .root:showcase-mode #sidebar, .root:showcase-mode .page > .header {