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

UI Incorrect shaping of chars in the Unicode Mongolian range (0x1800-0x18FF)

XMLWordPrintable

    • 2d
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      I observed the issue in
      - version 14.0.2 under Windows 10
      - version 11.0.8 under Linux Mint 10.3 (=> Ubuntu 18.04)

      A DESCRIPTION OF THE PROBLEM :
      Background:
      The Mongolian script (Unicode range 0x1800 - 18FF) is a "complex" script, requiring for proper shaping paying attention to the context of each character (for instance, in OpenType, OT tables like "isol", "init", "medi", "fina" and "rlig" are required, as with Arabic).

      If a Mongolian text is set into an AWT / Swing control it is not correctly shaped, unless some additional text is also added in some other "complex" script, like Arabic or Devanāgarī.

      I am convinced the problem is in the `src/java.desktop/share/classes/sun/font/FontUtilies.java` class; in its method `public static boolean isComplexCharCode(int code)` around line 290, there is the following code:
      ```
              else if (code < 0x1780) {
                  return false;
              }
              else if (code <= 0x17ff) { // 1780 - 17FF Khmer
                  return true;
              }
              else if (code < 0x200c) {
                  return false;
              }
      ```
      which returns `false` for the Mongolian range. I propose to correct it into:
      ```
              else if (code < 0x1780) {
                  return false;
              }
              else if (code <= 0x18ff) { // 1780 - 17FF Khmer
                  return true; // 1800 - 18FF Mongolian
              }
              else if (code < 0x200c) {
                  return false;
              }
       ```
      which returns true if the passed-in character code is a Khmer or a Mongolian character.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Set a Mongolian text (for instance "ᠪᠠᠢᠨ᠎ᠠ") into an AWT / Swing control and a Mongolian + Devanāgarī or Devanāgarī + Mongolian text in another (for instance "ᠪᠠᠢᠨ᠎ᠠ अनुच्छेद" or "अनुच्छेद ᠪᠠᠢᠨ᠎ᠠ").

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The Mongolian text is correctly shaped in both cases
      ACTUAL -
      The Mongolian text is correctly shaped in the second case, as the other "complex" text triggers the proper shaping, but it is incorrectly shaped in the first case (something like "á ª á   á ¢ á ¨ á  ").

      The example source attached below shows wrong and correct shaping cases for Swing labels; other controls exhibit the same behaviour.

      ---------- BEGIN SOURCE ----------
      package com.vistamaresoft.swingtest;
      import javax.swing.BoxLayout;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      public class Main
      {
          private JFrame frame;
          private static Main window;

          public Main()
          {
              frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setTitle("Mongolian Swing Test");
              frame.setBounds(100, 100, 300, 200);
              //Set up the GUI.
              JPanel panel = new JPanel();
              panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
              JLabel label = new JLabel("ᠪᠠᠢᠨ᠎ᠠ"); // NOT CORRECT
              panel.add(label);
              label = new JLabel("Abc ᠪᠠᠢᠨ᠎ᠠ"); // NOT CORRECT
              panel.add(label);
              label = new JLabel("ᠪᠠᠢᠨ᠎ᠠ كتاب "); // CORRECT
              panel.add(label);
              label = new JLabel("كتاب ᠪᠠᠢᠨ᠎ᠠ"); // CORRECT
              panel.add(label);
              label = new JLabel("ᠪᠠᠢᠨ᠎ᠠ अनुच्छेद"); // CORRECT
              panel.add(label);
              label = new JLabel("अनुच्छेद ᠪᠠᠢᠨ᠎ᠠ"); // CORRECT
              panel.add(label);
              frame.setContentPane(panel);
          }

          public static void main(String[] args)
          {
              window = new Main();
              window.frame.setVisible(true);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      As adding arbitrary strings to UI element to trigger the correct shaping is in general not feasible, I am not aware of any workaround.

      FREQUENCY : always


        1. Capture.JPG
          Capture.JPG
          65 kB
        2. Main.java
          2 kB
        3. Main.java
          1 kB

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

              Created:
              Updated: