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

TextLayout displays arabic letters incorrectly using font Sakkal Majalla

    XMLWordPrintable

    Details

    • Subcomponent:
      2d
    • Introduced In Version:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      Displaying text in a Graphics2D canvas using TextLayout displays certain Arabic characters incorrectly when using the font "Sakkal Majalla". Using "Arial" it works fine.
      This worked in the past (f.e. at least in 1.8.0_92) and in other JREs (f.e. Zulu 1.8 and Adopt 1.8).
      It stopped working in 1.8 261 (at least).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just run the program below (ensure that the font "Sakkal Majalla" is installed on your system): you will see a canvas showing two times the same text, once using "Arial" and once using "Sakkal Majalla"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Both lines of text look the same (modular minor differences due to different fonts).
      ACTUAL -
      Two texts look completely different.

      ---------- BEGIN SOURCE ----------
          public static void main(String[] args) {
              String sakkal_majalla = "Sakkal Majalla";

              Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
              if (Arrays.stream(fonts).noneMatch(font -> font.getFamily().equals(sakkal_majalla))) {
                  System.err.println("Cannot find font '" + sakkal_majalla + "' in the system.");
                  System.exit(1);
              }

              JPanel panel = new JPanel() {
                  @Override
                  protected void paintComponent(Graphics g) {
                      super.paintComponent(g);

                      Graphics2D g2d = (Graphics2D) g;

                      String text = "\u062D\u0643\u0648";
                      g2d.setColor(Color.black);

                      int x = 10;
                      int y = 50;
                      drawString(g2d, text, "Arial", x, y);
                      drawString(g2d, text, sakkal_majalla, x, y + 50);
                  }

                  private void drawString(Graphics2D g2d, String text, String font, int x, int y) {
                      new TextLayout(text, new Font(font, Font.PLAIN, 30), g2d.getFontRenderContext()).draw(g2d, x, y);
                  }
              };

              panel.setBackground(Color.white);

              JFrame frame = new JFrame("Font rendering");
              frame.add(panel);
              frame.setSize(200, 300);
              frame.setLocationRelativeTo(null);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
          }

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

      FREQUENCY : always


        Attachments

        1. 17ea_from_submitter.png
          17ea_from_submitter.png
          3 kB
        2. 8u212_from_submitter.png
          8u212_from_submitter.png
          3 kB
        3. 8u221_from_submitter.png
          8u221_from_submitter.png
          3 kB
        4. Capture1.PNG
          Capture1.PNG
          33 kB
        5. TestApp.java
          2 kB

          Activity

            People

            Assignee:
            rmahajan Rajat Mahajan
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: