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

[macos] TextLayout no longer uses proper font to draw Chinese characters

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Mac OSX, Java 1.8 update 172

      A DESCRIPTION OF THE PROBLEM :
      Only on Mac (still works on Windows):
      Using the "java.awt.font.TextLayout" to draw Chinese characters with a certain font no longer seems to use that font, it does some kind of fallback on another font.
      Using Graphics.drawString() directly still works.
      This used to work with Java 1.8 update 44 but it broke, probably sometime in Java 1.8 update 162.

      REGRESSION : Last worked in version selected='selected'

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use both the "java.awt.font.TextLayout" and "java.awt.Graphics" to draw the Chinese character 将 using the "Monaco" font. They will draw it differently.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The correct drawing is the one done by java.awt.Graphics and is the one here: https://en.wiktionary.org/wiki/%E5%B0%86
      ACTUAL -
      The "java.awt.font.TextLayout" draws the character differently than the "java.awt.Graphics", as if it does not take the set font into account.

      ---------- BEGIN SOURCE ----------
      public class Test {
        public static void main(String[] args) {
          System.err.println(System.getProperty("java.version"));
          JFrame fr = new JFrame("ABC");
          fr.setSize(500, 500);
          final JTextArea jta = new JTextArea() {
            @Override
            protected void paintComponent(Graphics g) {
              super.paintComponent(g);
              g.drawString(getText(), 320, 320);
              TextLayout tl = new TextLayout(getText(), getFont(), new FontRenderContext(null, true, false));
              tl.draw((Graphics2D) g, 120, 120);
            }
          };
          jta.setFont(new Font("Monaco", 0, 16));
          jta.setText("将");

          fr.getContentPane().add(jta, BorderLayout.CENTER);

          fr.setVisible(true);

        }


      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      I have found no workaround for this.

      FREQUENCY : always


        Attachments

        1. chineseChar.rtf
          0.4 kB
        2. expected.png
          expected.png
          22 kB
        3. Test.java
          1.0 kB

          Activity

            People

            • Assignee:
              psadhukhan Prasanta Sadhukhan
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: