My project uses the Google Open Sans font. It comes in 10 variants:
Light, Regular, Italic, Light Italic, Bold, Extrabold, Semibold, Bold Italic, Extrabold Italic, and Semibold Italic.
By reading the JavaFX CSS reference it seems obvious that you can select the bold variant by choosing a font-family of "Open Sans" and a font-weight of "bold", but it is unclear how you can style your application to use variants like "Light", "Extrabold", or "Semibold Italic" for instance.
I am trying to use the Light version. To make JavaFX avare of it, I have loaded it in my code using this code
Font.loadFont("/fonts/OpenSans-Light-webfont.ttf");
This gives me back a font which is named "Open Sans" and has a style of "Light". But as can be seen in the CSS reference "Light" is not a supported font style (only italic and oblique is supported).
I have tried styling labels with a font family of "Open Sans Light", but that does not work, even though "Open Sans Bold" actually selects the bold variant.
I have also tried using a font family "Open Sans" along with a font weight of 100 (the lightest), but that does not work either.
Consequently I hereby suggest the following improvements:
1. Document in the CSS reference how JavaFX is made aware of fonts which are bundled with an application (I do not know if Font.load is the only way).
2. Document the relationship between de facto standard font naming (like Open Sans Extrabold) and JavaFX CSS properties.
3. Support the selection of all Open Sans font variants through CSS. (Not to support Open Sans, but to support all fonts which have all these kinds of variants - I just recommend using Open Sans as a test case, since it is free and has many variants)
Light, Regular, Italic, Light Italic, Bold, Extrabold, Semibold, Bold Italic, Extrabold Italic, and Semibold Italic.
By reading the JavaFX CSS reference it seems obvious that you can select the bold variant by choosing a font-family of "Open Sans" and a font-weight of "bold", but it is unclear how you can style your application to use variants like "Light", "Extrabold", or "Semibold Italic" for instance.
I am trying to use the Light version. To make JavaFX avare of it, I have loaded it in my code using this code
Font.loadFont("/fonts/OpenSans-Light-webfont.ttf");
This gives me back a font which is named "Open Sans" and has a style of "Light". But as can be seen in the CSS reference "Light" is not a supported font style (only italic and oblique is supported).
I have tried styling labels with a font family of "Open Sans Light", but that does not work, even though "Open Sans Bold" actually selects the bold variant.
I have also tried using a font family "Open Sans" along with a font weight of 100 (the lightest), but that does not work either.
Consequently I hereby suggest the following improvements:
1. Document in the CSS reference how JavaFX is made aware of fonts which are bundled with an application (I do not know if Font.load is the only way).
2. Document the relationship between de facto standard font naming (like Open Sans Extrabold) and JavaFX CSS properties.
3. Support the selection of all Open Sans font variants through CSS. (Not to support Open Sans, but to support all fonts which have all these kinds of variants - I just recommend using Open Sans as a test case, since it is free and has many variants)
- relates to
-
JDK-8089002 Difficulty using font variants in CSS
-
- Closed
-