2

I am in strife.

I am using a Bahnschrift Variable Font as a font for all of the text & labels of my JavaFX program. However, when I am going to use a variant of the font, the font only appears as the regular variant of the font.

More specifically, the title class doesn't show the Bold Bahnschrift Variant but only shows the Regular Bahnschrift Variant. I am also considering it to be condensed but the program doesn't seem to recognize it; so I am also asking how to make this possible.

For reference, here are the CSS files:

HelpPane.css

@import "standard.css";

.scroll-pane > .viewport, .scroll-pane {
    -fx-background-color: #ffffff22;
    -fx-border-color: #00000000;
}

.title {
    -fx-font-size : 30px;
    -fx-font-weight : bold;
}

.heading1 {
    -fx-font-size : 24px;
}

sample.css

@font-face {
    src: url('file:src/assets/font/Bahnschrift.ttf');
}

.label, .text {
    -fx-font-family: "Bahnschrift";
    -fx-text-fill: #000000;
}

2 Answers2

2

I think that JavaFX doesn't support variable fonts.

Checking the JavaFX CSS documentation, there are no -fx-font-feature-settings and -fx-font-variable-settings declarations in the documentation, and even appending format("opentype-variations") to the font url declaration can't help either. -fx-font-weight didn't even make a dent.

Even JavaFX's FXML and Java code doesn't give a compromise.

As of the moment, static fonts might as well be recommended.

0

Not all fonts have support for multiple font weights. Have you made sure that this is not the case for the font you've chosen?

Anthony
  • 321
  • 2
  • 10
  • My Variable Bahnschrift Font file has multiple font weights and font spacings: Light, SemiLight, Regular, SemiBold and Bold; (same for the spacings) – codingClown Apr 28 '21 at 10:57
  • FYI the font file is from https://www.dafontfree.io/bahnschrift-font/. – codingClown Apr 28 '21 at 11:21
  • Just tried with basic CSS and works as you said. So not a file issue. – Anthony Apr 28 '21 at 11:50
  • However, it doesn't work in the JavaFX CSS. Tried using font-feature-settings and even -fx-font-feature-settings and it didn't even work. The -fx-font-weight also doesn't work. I am referring to the JavaFX CSS, not the website CSS. – codingClown Apr 28 '21 at 12:12
  • I think I have the same problem as here below: https://stackoverflow.com/questions/65644527/variable-fonts-in-javafx – codingClown Apr 28 '21 at 12:46
  • From the JavaFX documentation, "Font Properties - Most classes that use text will support the following font properties. In some cases a similar set of properties will be supported but with a different prefix instead of "-fx-font"." Maybe try this. Otherwise I would agree with your conclusion. – Anthony Apr 29 '21 at 10:31
  • If you ctrl+f "" it will bring you to the font section and its at the bottom of the section. https://docs.oracle.com/cd/E17802_01/javafx/javafx/1.3/docs/api/javafx.scene/doc-files/cssref.html – Anthony Apr 29 '21 at 10:46
  • It looks like that this doesn't apply to variable fonts though. It might as well apply to other Java libraries and modules, I guess. – codingClown Apr 29 '21 at 11:48