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

1em is not always equal to the font size specified in css

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_131"
      Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.15063]

      A DESCRIPTION OF THE PROBLEM :
      If the font size of a parent is specified in pt values in css, children with font sizes specified in em values will not always be correct.

      For example, if a pane has two children, panes A and B. Each of them contain a Text. If you set the font size of the root pane to 8pt in css and the font size of pane A to 1em in css, you would expect both labels to have the exact same size since 1em = font size (according to modena.css).

      With some font sizes, this is true, but with others there are fairly significant errors.

      Tested on jdk-9+181 and 8.131

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Select a font size to test, and run the application.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Every label should have the exact same font size.
      ACTUAL -
      The font size for the 1em label is 10.69 while the font size for the label that inherits its font size from the root pane is 10.66.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package fontsizetest;

      import javafx.application.Application;
      import javafx.beans.binding.Bindings;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.VBox;
      import javafx.scene.text.Text;
      import javafx.stage.Stage;

      /**
       *
       * @author Dean
       */
      public class FontSizeTest extends Application {

          @Override
          public void start(Stage primaryStage) {
              int levels = 5;
              VBox root = new VBox();
              root.setStyle("-fx-font-size:8pt");
              VBox A = new VBox();
              VBox B = new VBox();
              A.setStyle("-fx-font-size:1em;");
              Text textA = new Text("Text Test");
              Text textB = new Text("Text Test");

              Label labelAFont = new Label();
              Label labelBFont = new Label();
              labelAFont.textProperty().bind(Bindings.concat("Text A Font: ", textA.fontProperty().asString()));
              labelBFont.textProperty().bind(Bindings.concat("Text B Font: ", textB.fontProperty().asString()));
              Label labelABounds = new Label();
              Label labelBBounds = new Label();
              labelABounds.textProperty().bind(Bindings.concat("Text A Bounds: ", textA.layoutBoundsProperty().asString()));
              labelBBounds.textProperty().bind(Bindings.concat("Text B Bounds: ", textB.layoutBoundsProperty().asString()));

              A.getChildren().addAll(textA, labelAFont, labelABounds);
              B.getChildren().addAll(textB, labelBFont, labelBBounds);
              root.getChildren().addAll(A, B);
              Scene scene = new Scene(root, 600, 250);

              primaryStage.setTitle("Font Size Test");
              primaryStage.setScene(scene);
              primaryStage.show();

          }

          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              launch(args);
          }

      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: