I am developing an applet to display simple map data that includes text
displayed at various angles.
The applet uses a canvas within a scrollpane. The data is first drawn on a
buffered image using the Java 2D API before being 'painted' to the canvas.
I am using the AffineTransform class to do the translation/rotation as
shown below
FontMetrics fm = gc.getFontMetrics(); // gc = Graphics2D instance
Rectangle2D box = fm.getStringBounds(theText.trim(), gc);
float incrX = (float)(box.getWidth()/2.0);
float incrY = (float)(box.getHeight()/2.0);
gc.setPaint(Color.black);
// apply transform first
AffineTransform aft =
(gc.getDeviceConfiguration()).getDefaultTransform();
// apply translation then rotate
aft.setToTranslation(currX, currY); // position of centre of text box
gc.transform(aft);
aft.setToRotation(Math.toRadians(-currAngle)); // rotation for this
string
gc.transform(aft);
gc.drawString(theText.trim(), -incrX, incrY);
// undo the transform
aft.setToRotation(Math.toRadians(currAngle));
gc.transform(aft);
aft.setToTranslation(-currX, -currY);
gc.transform(aft);
Although the first character of the text string is postioned & rotated
correctly, each subsequent character seems to be slightly offset from the
previous character below the (rotated) string baseline giving a stepped
appearance.
Has anyone any thoughts on how to cure this.
Thanks in advance,
Marco Rondelli
P.S. Using JDK 1.2, IE 5.0, NT 4.0
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 2D Home Page: http://java.sun.com/products/java-media/2D/