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

Line/Font metrics Ascent and Descent values changed from JDK8 and JDK11

    Details

    • Subcomponent:
      2d
    • Introduced In Version:
      11
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows regardless of versions.

      A DESCRIPTION OF THE PROBLEM :
      The values returned by LineMetrics.Ascent and Descent have changed in JDK11 compared to JDK8. This happens with all the time but not with all fonts.
      The difference, despite small, gives visible results when trying to align text vertically.

      Problem also exist with OpenJDK 12 and 13.

      REGRESSION : Last worked in version 8u241

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      With font <java.awt.Font[family=Calibri,name=Calibri,style=plain,size=10]> for exemple:

              System.out.println("Font metrics :");
              System.out.println("- Ascent : " + fm.getAscent());
              System.out.println("- Descent : " + fm.getDescent());
              System.out.println("Line metrics : ");
              System.out.println("- Ascent : " + lm.getAscent());
              System.out.println("- Descent : " + lm.getAscent());

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Font metrics :
      - Ascent : 9
      - Descent : 2
      Line metrics :
      - Ascent : 8.603516
      - Descent : 8.603516
      ACTUAL -
      Font metrics :
      - Ascent : 8
      - Descent : 3
      Line metrics :
      - Ascent : 7.5
      - Descent : 7.5

      ---------- BEGIN SOURCE ----------
      With font:
      <java.awt.Font[family=Arial,name=Arial,style=plain,size=14]>
      <java.awt.Font[family=Arial,name=Arial,style=plain,size=8]>
      <java.awt.Font[family=Calibri,name=Calibri,style=plain,size=10]>

          private static void displayFontInformation(String fontName, boolean isBold, boolean isItalic, int fontSize, String text)
          {

              GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
              BufferedImage bufferedImage = new BufferedImage(2, 2, BufferedImage.TYPE_4BYTE_ABGR_PRE);

              Graphics2D graphics2D = ge.createGraphics(bufferedImage);
              graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);

              int fontStyle = (isItalic == true ? Font.ITALIC : 0);
              fontStyle = fontStyle | (isBold == true ? Font.BOLD : 0);

              Font font = new Font(fontName, fontStyle, fontSize);

              FontMetrics fm = graphics2D.getFontMetrics(font);
              LineMetrics lm = font.getLineMetrics(text, graphics2D.getFontRenderContext());

              System.out.println("--- <" + font + ">");
              System.out.println("Font metrics :");
              System.out.println("- Ascent : " + fm.getAscent());
              System.out.println("- Descent : " + fm.getDescent());
              System.out.println("- Leading : " + fm.getLeading());
              System.out.println("Line metrics : ");
              System.out.println("- Ascent : " + lm.getAscent());
              System.out.println("- Descent : " + lm.getAscent());
              System.out.println("- Leading : " + lm.getLeading());
              System.out.println("- Underline pos : " + lm.getUnderlineOffset());
              System.out.println("- Underline width: " + lm.getUnderlineThickness());

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

      CUSTOMER SUBMITTED WORKAROUND :
      No workaround.

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                prr Philip Race
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: