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

OpenJDK can't support render text with rotation for DBCS fonts

    Details

    • Subcomponent:
      2d
    • CPU:
      x86_64
    • OS:
      windows

      Description

      (Reporting on behalf of https://github.com/linxingyun )

      OpenJDK has bug on DBCS fonts’ support: it can’t support to render text with rotation for the fonts like: MingLiu, HeiT, MS PGothic, MS PMincho, Batang and Gulim.

      Because I am not able to enter bug in the offical OpenJDK website, I am entering bug here to see if you could help to help to redirect this problem to a proper guy to handle it. Thanks a lot!

      Below is the sample code to reproduce the problem:

      import java.awt.Color;
      import java.awt.Font;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.image.BufferedImage;
      import java.io.File;

      import javax.imageio.ImageIO;

      public class TestFontRender {

      private static final String IMAGE_TYPE="png";
      // You may need to change the filepath below in order to save the image in proper path.
      private static final String IMAGE_FILEPATH="c:\fontRender_openjdk.png";

      /**
       * @param args
       */
      public static void main(String[] args) {

          TestFontRender code = new TestFontRender();
          BufferedImage bufferImage = code.getImage();
          code.saveImage(bufferImage, IMAGE_TYPE, IMAGE_FILEPATH);
      }

      public BufferedImage getImage() {
          int width = 800;
          int height = 600;
          int degree = -90;
          BufferedImage image = new BufferedImage(width, height,
                  BufferedImage.TYPE_INT_RGB);

          Graphics g = image.getGraphics();

          Color background = new Color(255, 255, 255);
          g.setColor(background);
          g.fillRect(0, 0, width, height);

          g.setColor(getColor());
          g.drawRect(0, 0, width - 1, height - 1);

          Color textColor = new Color(255, 0, 0);
          g.setColor(textColor);

          //"MS PGothic" font
          String text = "Height (日本平均)アイウ MS PGothic angle=0";
          Font textFont = new Font("MS PGothic",Font.PLAIN,14);
          g.setFont(textFont);
          Graphics2D g2d_1 = (Graphics2D) g.create();
          g2d_1.translate(20, 20);
          g2d_1.drawString(text, 0, 0);

          g2d_1.translate(20, 300);
          g2d_1.rotate(degree * Math.PI / 180);
          text = "Height (日本平均)アイウ MS PGothic angle=-90";
          g2d_1.drawString(text, 0, 0);

          //"MS PMincho" font
          text = "Height (日本平均)アイウ MS PMincho angle=0";
          textFont = new Font("MS PMincho",Font.PLAIN,14);
          g.setFont(textFont);
          Graphics2D g2d_2 = (Graphics2D) g.create();
          g2d_2.translate(85, 55);
          g2d_2.drawString(text, 0, 0);

          g2d_2.translate(55, 300);
          g2d_2.rotate(degree * Math.PI / 180);
          text = "Height (日本平均)アイウ MS PMincho angle=-90";
          g2d_2.drawString(text, 0, 0);


          //"Gulim" font
          text = "Height (Korea) Gulim angle=0";
          textFont = new Font("Gulim",Font.PLAIN,14);
          g.setFont(textFont);
          Graphics2D g2d_3 = (Graphics2D) g.create();
          g2d_3.translate(145, 85);
          g2d_3.drawString(text, 0, 0);

          g2d_3.translate(85, 300);
          g2d_3.rotate(degree * Math.PI / 180);
          text = "Height (Korea) Gulim angle=-90";
          g2d_3.drawString(text, 0, 0);


          //"HeiT" font
          text = "Height (平均) HeiT angle=0";
          textFont = new Font("HeiT",Font.PLAIN,14);
          g.setFont(textFont);
          Graphics2D g2d_4 = (Graphics2D) g.create();
          g2d_4.translate(200, 115);
          g2d_4.drawString(text, 0, 0);

          g2d_4.translate(115, 300);
          g2d_4.rotate(degree * Math.PI / 180);
          text = "Height (平均) HeiT angle=-90";
          g2d_4.drawString(text, 0, 0);


          g.dispose();
          return image;
      }

      private Color getColor() {
          int R = (int) (Math.random() * 255);
          int G = (int) (Math.random() * 255);
          int B = (int) (Math.random() * 255);
          return new Color(R, G, B);
      }

      public void saveImage(BufferedImage image, String format, String filePath) {
          try {
              ImageIO.write(image, format, new File(filePath));
          } catch (Exception e) {
              throw new RuntimeException(e);
          }
      }

      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                prr Philip Race
                Reporter:
                akasko Alex Kasko
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: