JDK-6904962 : GlyphVector.getVisualBounds should not be affected by leading or trailing white space.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2009-11-25
  • Updated: 2010-07-09
  • Resolved: 2009-12-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u21Fixed 7 b78Fixed
Description
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;

public class Bds {
  public static void main(String args[]) {
   String s1 = "a";
   String s2 = s1+" ";
   String s3 = " "+s1;
   Font f = new Font("Dialog", Font.PLAIN, 12);
   FontRenderContext frc = new FontRenderContext(null, false, false);
   GlyphVector gv1 = f.createGlyphVector(frc, s1);
   GlyphVector gv2 = f.createGlyphVector(frc, s2);
   GlyphVector gv3 = f.createGlyphVector(frc, s3);
   Rectangle2D bds1 = gv1.getVisualBounds();
   Rectangle2D bds2 = gv2.getVisualBounds();
   Rectangle2D bds3 = gv3.getVisualBounds();
   System.out.println(bds1);
   System.out.println(bds2);
   System.out.println(bds3);
  }
} 

JDK 1.5 :-
% java Bds
java.awt.geom.Rectangle2D$Float[x=0.4375,y=-6.359375,w=5.734375,h=6.5]
java.awt.geom.Rectangle2D$Float[x=0.4375,y=-6.359375,w=5.734375,h=6.5]
java.awt.geom.Rectangle2D$Float[x=3.4375,y=-6.359375,w=5.734375,h=6.5]

JDK 1.6 :-
% java Bds
java.awt.geom.Rectangle2D$Float[x=0.4375,y=-6.359375,w=5.734375,h=6.5]
java.awt.geom.Rectangle2D$Float[x=0.4375,y=-6.359375,w=6.5625,h=6.5]
java.awt.geom.Rectangle2D$Float[x=0.0,y=-6.359375,w=9.171875,h=6.5]

Comments
EVALUATION Looks like this was likely broken in the JDK 6 b03 fix for 5074057: glyph visual bounds incorrect when frc is rotated
25-11-2009