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 ----------

      1. FontAscentTest.java
        1 kB
        Abhijit Roy
      2. NotoSansCJKjp-Regular.otf
        15.67 MB
        Abhijit Roy

        Activity

        Hide
        aroy Abhijit Roy (Inactive) added a comment -
        Checked this issue for 8,8u101,8u102,8u111,8u112,9ea on macOS and could not reproduce the issue.

        Steps to reproduce:
        **********************
        - Install the attached font file(NotoSansCJKjp-Regular.otf)
        - Run the attached test program(Test.java) with JDK.


        Result:
        *********
        OS : Windows 7 64 bit [Version 6.1.7601]


        JDK:
        ++++
        8 b132 : Fail
        8u102 b14 : Fail
        8u111 b14 : Fail
        8u112 b15 : Fail
        8u122ea b02 : Fail
        9ea b133 : Fail

        Output:
        *********
        Arial - ascent: 10
        Arial - descent: 2

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


        ==============================================================
        Show
        aroy Abhijit Roy (Inactive) added a comment - Checked this issue for 8,8u101,8u102,8u111,8u112,9ea on macOS and could not reproduce the issue. Steps to reproduce: ********************** - Install the attached font file(NotoSansCJKjp-Regular.otf) - Run the attached test program(Test.java) with JDK. Result: ********* OS : Windows 7 64 bit [Version 6.1.7601] JDK: ++++ 8 b132 : Fail 8u102 b14 : Fail 8u111 b14 : Fail 8u112 b15 : Fail 8u122ea b02 : Fail 9ea b133 : Fail Output: ********* Arial - ascent: 10 Arial - descent: 2 Noto Sans CJK - ascent: -239 Noto Sans CJK - descent: 240 ==============================================================
        Hide
        prr Philip Race added a comment -
        This is reproducible on Linux. The issue appear to be the same as
        https://bugs.openjdk.java.net/browse/JDK-8074562 (Not supporting CFF/CID fonts)
        A fix is in progress but the Noto fonts show there is still work to do there.
        What actually happens here is we "error out" whilst initialising the scaler.
        So you aren't getting the Noto fonts at all. The dubious ascent/descent may be
        the result of default values. I'll take a look at that part to see if it is worth
        improving those, but otherwise this is a dup.
        Show
        prr Philip Race added a comment - This is reproducible on Linux. The issue appear to be the same as https://bugs.openjdk.java.net/browse/JDK-8074562 (Not supporting CFF/CID fonts) A fix is in progress but the Noto fonts show there is still work to do there. What actually happens here is we "error out" whilst initialising the scaler. So you aren't getting the Noto fonts at all. The dubious ascent/descent may be the result of default values. I'll take a look at that part to see if it is worth improving those, but otherwise this is a dup.
        Hide
        prr Philip Race added a comment -
        When we fail to initialise a font it gets a NULL scaler which basically is supposed
        to report no glyphs .. zero metrics. For whatever reason for the float values instead
        of 0.0f it is using 0xf0. I think maybe this was meant to be 0x0 .. or perhaps
        the "f" was to mean float in which case we shouldn't have 0x.
        Since floats are expected we should just pass 0.0f which is a lot less mysterious
        than the conversion to float we apparently got for the other case.

        This therefore does NOT fix the actual rendering. That will be handled under 8074562.
        Show
        prr Philip Race added a comment - When we fail to initialise a font it gets a NULL scaler which basically is supposed to report no glyphs .. zero metrics. For whatever reason for the float values instead of 0.0f it is using 0xf0. I think maybe this was meant to be 0x0 .. or perhaps the "f" was to mean float in which case we shouldn't have 0x. Since floats are expected we should just pass 0.0f which is a lot less mysterious than the conversion to float we apparently got for the other case. This therefore does NOT fix the actual rendering. That will be handled under 8074562.
        Hide
        hgupdate HG Updates added a comment -
        URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/96153792172a
        User: prr
        Date: 2016-10-25 16:57:26 +0000
        Show
        hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/96153792172a User: prr Date: 2016-10-25 16:57:26 +0000
        Hide
        hgupdate HG Updates added a comment -
        URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/96153792172a
        User: lana
        Date: 2016-11-09 22:58:42 +0000
        Show
        hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/96153792172a User: lana Date: 2016-11-09 22:58:42 +0000

          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: