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

Text width depends on the graphics transform

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 9
    • client-libs
    • 2d
    • windows

      See the discussion: http://mail.openjdk.java.net/pipermail/swing-dev/2016-April/005797.html

      The text width can be differ for different graphics transforms.

      To reproduce the issue run the following code sample on Windows:
      -------------------------------
      import java.awt.Graphics2D;
      import java.awt.image.BufferedImage;

      public class CharWidthTest {

          static final String TEXT = "The quick brown fox jumps over the lazy dog"
                  + "The quick brown fox jumps over the lazy dog";
          static final String LONG_TEXT = TEXT + TEXT.toUpperCase();

          public static void main(String[] args) {
              BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);

              Graphics2D g = img.createGraphics();
              int textWidth1 = g.getFontMetrics().stringWidth(LONG_TEXT);
              g.scale(2, 2);
              int textWidth2 = g.getFontMetrics().stringWidth(LONG_TEXT);
              g.dispose();

              if (textWidth1 != textWidth2) {
                  throw new RuntimeException("Text size is different!");
              }
          }
      }
      -------------------------------

            Unassigned Unassigned
            alexsch Alexandr Scherbatiy
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: