Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8344037

Font.loadFont() loads light/thin fonts as fonts with distinct families.

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      I tested Font.loadFont() for JetBrains Mono font (https://fonts.google.com/specimen/JetBrains+Mono) and Ubuntu font (https://fonts.google.com/specimen/Ubuntu). When I load light/thin fonts then for these fonts distinct families are created. For example, this is a piece of `System.out.println(javafx.scene.text.Font.getFamilies())` command: JetBrains Mono NL, JetBrains Mono NL Light, JetBrains Mono NL Thin, .... Ubuntu, Ubuntu Condensed, Ubuntu Light, Ubuntu Mono, Ubuntu Thin

      The reason why I say it is a bug because `-fx-font-weight: 300` doesn't work. It is necessary to use `-fx-font-family: 'Ubuntu Light';-fx-font-weight: normal;` to make font lighter. And this contradicts the specification (https://openjfx.io/javadoc/23/javafx.graphics/javafx/scene/doc-files/cssref.html#typefont) , where it is stated:
      <font-weight> The font's weight, using the following syntax:
      [ normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 ]

      So, no `lighter`, no `100`, `200`, `300` will work.




      ---------- BEGIN SOURCE ----------
      public class JavaFxTest10 extends Application {

          @Override
          public void start(Stage primaryStage) {
              var fonts = List.of(
                      "JetBrainsMonoNL-Bold.ttf",
                      "JetBrainsMonoNL-BoldItalic.ttf",
                      "JetBrainsMonoNL-Regular.ttf",
                      "JetBrainsMonoNL-Light.ttf",
                      "JetBrainsMonoNL-LightItalic.ttf",
                      "JetBrainsMonoNL-Thin.ttf",
                      "JetBrainsMonoNL-ThinItalic.ttf");
              fonts.forEach(f -> Font.loadFont(JavaFxTest10.class.getResource(f).toExternalForm(), 10));
              System.out.println(javafx.scene.text.Font.getFamilies());

              var label1 = new Label("Some text");
              label1.setStyle("-fx-font-family: 'JetBrains Mono NL';-fx-font-weight: normal;");//OK
              var label2 = new Label("Some text");
              label2.setStyle("-fx-font-family: 'JetBrains Mono NL';-fx-font-weight: 100;");//NOT OK
              var label3 = new Label("Some text");
              label3.setStyle("-fx-font-family: 'JetBrains Mono NL Thin';-fx-font-weight: normal;");//OK
              var root = new VBox(label1, label2, label3);
              root.setStyle("-fx-font-size: 18px");
              Scene scene = new Scene(root, 400, 200);
              primaryStage.setScene(scene);
              primaryStage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            prr Philip Race
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: