se-edu/addressbook-level3

Loading of embedded fonts via CSS causes runtime issues

Closed this issue · 2 comments

kouyk commented

When loading fonts via CSS, it is required that the absolute path to the font does not contain any spaces. Spaces will be encoded as %20 in the path and passed to the loading function directly, resulting in a failure.

Reference: https://stackoverflow.com/questions/33973921/javafx-font-face-css-error-loadstylesheetunprivileged/41753098

This bug occurs when the project is launched directly in the IDE, and when the project directory or any of the parent directories contains a space in its name. It does not affect any JAR files.

@kouyk thanks for reporting this.
@se-edu/tech-team-level1 should we switch to the solution suggested in the S/O post above?

I noticed the StackOverflow answer states that it is a bug in JavaFX 8, so I tested it myself. (Windows10, Java11, JavaFX11)

Still threw the same error anyway:
image

Can confirm that this effectively works:

public class Main {
    public static void main(String[] args) {
        Font.loadFont(Main.class.getResourceAsStream("font/Roboto-Medium.ttf"), 16);
        Application.launch(MainApp.class, args);
    }
}

So yea, we can switch to the solution if embedded fonts are used.