se-edu / addressbook-level3

:ab::three: Address Book sample application (Level 3)
https://se-education.org/addressbook-level3
MIT License
28 stars 430 forks source link

Loading of embedded fonts via CSS causes runtime issues #111

Closed kouyk closed 2 years ago

kouyk commented 3 years ago

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.

damithc commented 3 years ago

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

LimJunxue commented 3 years ago

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.