-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
None
-
beta
-
sparc
-
solaris_7
FontMetrics.stringWidth() should return the natural advance of the string
along its baseline.
The program below when run against 2D merlin builds from after Oct 27th
prints stringWidth values which are actually the advance of the measured string
in the transformed (rotated) coordinate system.
ie strings rotated by 90 or 270 degrees are claimed to be of zero-width.
The stringBounds method returns correct results.
import java.awt.*;
import java.awt.geom.*;
public class TextRotatedLength extends Component {
public static void main(String args[]) {
Frame f = new Frame();
TextRotatedLength td = new TextRotatedLength();
f.add("Center", td);
f.pack();
f.show();
}
public Dimension getPreferredSize() {
return new Dimension (100, 100);
}
public Dimension getMinimumSize() {
return getPreferredSize();
}
public void paint(Graphics g) {
FontMetrics fm;
int len;
Rectangle2D bounds;
int ypos = 0;
String astr = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
Font f = new Font("serif", Font.PLAIN, 12);
g.setFont(f);
Graphics2D g2d = (Graphics2D)g;
int rots = 8;
double totalAngle = 0.0;
double angle = (2.0*Math.PI)/rots;
for (int i=0; i<9; i++) {
fm = g.getFontMetrics();
len = fm.stringWidth(astr);
bounds = fm.getStringBounds(astr, g);
System.out.println("Angle of Rotation="+totalAngle);
System.out.println("stringWidth()="+len);
System.out.println("getStringBounds() from="+bounds);
g2d.rotate(angle);
totalAngle+=angle;
}
}
}
along its baseline.
The program below when run against 2D merlin builds from after Oct 27th
prints stringWidth values which are actually the advance of the measured string
in the transformed (rotated) coordinate system.
ie strings rotated by 90 or 270 degrees are claimed to be of zero-width.
The stringBounds method returns correct results.
import java.awt.*;
import java.awt.geom.*;
public class TextRotatedLength extends Component {
public static void main(String args[]) {
Frame f = new Frame();
TextRotatedLength td = new TextRotatedLength();
f.add("Center", td);
f.pack();
f.show();
}
public Dimension getPreferredSize() {
return new Dimension (100, 100);
}
public Dimension getMinimumSize() {
return getPreferredSize();
}
public void paint(Graphics g) {
FontMetrics fm;
int len;
Rectangle2D bounds;
int ypos = 0;
String astr = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
Font f = new Font("serif", Font.PLAIN, 12);
g.setFont(f);
Graphics2D g2d = (Graphics2D)g;
int rots = 8;
double totalAngle = 0.0;
double angle = (2.0*Math.PI)/rots;
for (int i=0; i<9; i++) {
fm = g.getFontMetrics();
len = fm.stringWidth(astr);
bounds = fm.getStringBounds(astr, g);
System.out.println("Angle of Rotation="+totalAngle);
System.out.println("stringWidth()="+len);
System.out.println("getStringBounds() from="+bounds);
g2d.rotate(angle);
totalAngle+=angle;
}
}
}