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

Wrong string bounds using helvetica font in rotated Graphics.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.1
    • 1.4.1
    • client-libs
    • 2d
    • rc
    • x86, sparc
    • linux_redhat_7.2, solaris_8

      There is a text measurement regression in JDK 1.4.1 on Solaris and Linux

      The following program prints "37" as the width of the string
      when run on JDK1.4, but "0" on JDK 1.4.1.

      The problem appears to have begun around the time that changes were
      made to mappings of the legacy font names.

      import java.awt.*;
      import java.awt.geom.*;
      import java.awt.image.*;

      public class RotMetricsBug {

         public static void main(String[] args) {
              BufferedImage bi = new BufferedImage(10,10,BufferedImage.TYPE_INT_RGB);
              Graphics2D g2d = (Graphics2D)bi.getGraphics();
              g2d.rotate(Math.PI*3/2.0);
              Font f= new Font("helvetica", Font. PLAIN, 12);
              g2d.setFont(f);
              FontMetrics fm = g2d.getFontMetrics();
              System.out.println("Str wid = " + fm.stringWidth("abcdef"));
              Rectangle2D r2d = fm.getStringBounds("abcdef", g2d);
              System.out.println("wid = " + (float)r2d.getWidth());
         }

      }

      This is a particular problem when printing using this font in landscape
      mode as landscape mode involves a rotated graphics, and the above APIs are
      used in generating postscript.

            prr Philip Race
            prr Philip Race
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: