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 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

but how does it work for the default fonts?
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?

8 Comments

My Variable Bahnschrift Font file has multiple font weights and font spacings: Light, SemiLight, Regular, SemiBold and Bold; (same for the spacings)
FYI the font file is from dafontfree.io/bahnschrift-font.
Just tried with basic CSS and works as you said. So not a file issue.
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.
I think I have the same problem as here below: stackoverflow.com/questions/65644527/variable-fonts-in-javafx
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.