Fix font family switching
Also add workaround of using font weight other than regular and bold.
This commit is contained in:
parent
2d6393cc2b
commit
79ba01a20e
@ -109,10 +109,8 @@ public class TreePage extends AbstractPage {
|
||||
// copy existing style classes and properties to the new tree
|
||||
findDisplayedTree().ifPresent(tv -> {
|
||||
List<String> 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());
|
||||
|
@ -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));
|
||||
|
@ -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<String> 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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Black.otf
Normal file
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Black.otf
Normal file
Binary file not shown.
Binary file not shown.
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Bold.otf
Normal file
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Bold.otf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Italic.otf
Normal file
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Italic.otf
Normal file
Binary file not shown.
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Light.otf
Normal file
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Light.otf
Normal file
Binary file not shown.
Binary file not shown.
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Medium.otf
Normal file
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Medium.otf
Normal file
Binary file not shown.
Binary file not shown.
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Regular.otf
Normal file
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Regular.otf
Normal file
Binary file not shown.
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-SemiBold.otf
Normal file
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-SemiBold.otf
Normal file
Binary file not shown.
Binary file not shown.
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Thin.otf
Normal file
BIN
sampler/src/main/resources/assets/fonts/Inter/Inter-Thin.otf
Normal file
Binary file not shown.
Binary file not shown.
94
sampler/src/main/resources/assets/fonts/Inter/LICENSE.txt
Normal file
94
sampler/src/main/resources/assets/fonts/Inter/LICENSE.txt
Normal file
@ -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.
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user