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

Fontmetrics for large Fonts has zero width

XMLWordPrintable

    • 2d
    • 14
    • b20
    • x86_64
    • windows_10

        ADDITIONAL SYSTEM INFORMATION :
        Occurs on Windows and Linux.

        A DESCRIPTION OF THE PROBLEM :
        In Java 17.0.10 the font metrics returns a string width of zero for large font size. Moreover, every subsequent call for that font metrics with "normal" size will also return zero width, unless that size was requested before the "breaking" one.

        Seems to be related to https://bugs.openjdk.org/browse/JDK-8233097

        REGRESSION : Last worked in version 11

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Build and run the source code


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        size 12 width 58.02
        size 100,000 width 24,744.094
        size 7 width 33.845
        size 8 width 38.68
        size 9 width 43.515
        size 10 width 48.35
        size 11 width 53.185
        size 12 width 58.02
        size 14 width 67.689
        size 16 width 77.359
        size 18 width 87.029
        size 20 width 96.699
        size 24 width 116.039
        ACTUAL -
        size 12 width 58.02
        size 100,000 width 0
        size 7 width 0
        size 8 width 0
        size 9 width 0
        size 10 width 0
        size 11 width 0
        size 12 width 58.02
        size 14 width 0
        size 16 width 0
        size 18 width 0
        size 20 width 0
        size 24 width 0

        ---------- BEGIN SOURCE ----------
            public static void main(String[] args) {
                String testString = "Test String";
                Font font = new Font("SansSerif", Font.PLAIN, 12);
                FontRenderContext frc = new FontRenderContext(null, false, true);
                System.out.println(MessageFormat.format("size {0} width {1}", font.getSize(), font.getStringBounds(testString, frc).getWidth()));
                // breaking size
                font = font.deriveFont(100000f);
                System.out.println(MessageFormat.format("size {0} width {1}", font.getSize(), font.getStringBounds(testString, frc).getWidth()));
                float[] sizes = new float[] {7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 24};
                for (float size: sizes) {
                    font = font.deriveFont(size);
                    System.out.println(MessageFormat.format("size {0} width {1}", font.getSize(), font.getStringBounds(testString, frc).getWidth()));
                }
            }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        None, unless using JDK11 is an option

        FREQUENCY : always


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

                Created:
                Updated:
                Resolved: