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

Dubious FontMetrics values from NullFontScaler

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b144
    • CPU:
      generic
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

      Problem has been observed in all versions of Java SE JVM since (at least) 1.4

      ADDITIONAL OS VERSION INFORMATION :
      Windows 10 - latest as of Oct. 2016

      A DESCRIPTION OF THE PROBLEM :
      Java SE does not correctly support the Google "Noto Sans CJK" fonts.

      The fonts can be created using "new Font()", but the resulting font object does not work correctly for drawing characters.

      It appears that Java is maybe choosing poor vertical metric information (ascent, descent, etc.) from this font. The ascent and descent values for this font are nowhere near expected values (i.e. -239 ascent and 240 descent for a 10pt font).

      Current OpenJDK release does not have the same problem with these fonts.
      Non-CJK Noto fonts (Sans and Serif) do not have the same problem.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Download Noto Sans CJK JP fonts (file = NotoSansCJKjp-hinted.zip) from https://www.google.com/get/noto/

      2. Extract fonts to a folder.

      3. Use Control Panel/Fonts to install "Noto Sans CJK JP Regular" (file = NotoSansCJKjp-regular.otf)

      4. Run Java app that creates and inspects Font object for this font. (see executable test case)



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      For each font I expect an ascent value close to the font size (10) and a descent value somewhere near 10-30% of the font size (1-3).
      ACTUAL -
      Arial - ascent: 10
      Arial - descent: 2

      Noto Sans CJK - ascent: -239
      Noto Sans CJK - descent: 240


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Font;
      import java.awt.FontMetrics;

      import javax.swing.JFrame;
      import javax.swing.JLabel;

      public class FontAscentTest {

      public static void main(String[] args)
      {
      JFrame someFrame = new JFrame();
      JLabel label = new JLabel("Label Text");

      Font arial = new Font("Arial", Font.PLAIN, 10);
      FontMetrics fm_arial = label.getFontMetrics(arial);
      System.out.printf("Arial - ascent: %d\n", fm_arial.getAscent());
      System.out.printf("Arial - descent: %d\n", fm_arial.getDescent());
      System.out.println();

      Font notoSansCJK = new Font("Noto Sans CJK JP Regular", Font.PLAIN, 10);
      FontMetrics fm_noto = label.getFontMetrics(notoSansCJK);
      System.out.printf("Noto Sans CJK - ascent: %d\n", fm_noto.getAscent());
      System.out.printf("Noto Sans CJK - descent: %d\n", fm_noto.getDescent());
      System.out.println();

      label.setFont(arial);
      // label.setFont(notoSansCJK);
      someFrame.add(label);

      someFrame.setSize(530, 530);
      someFrame.setVisible(true);
      }
      }

      ---------- END SOURCE ----------

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: