Problem under OS X

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ChrisSterritt

Problem under OS X

Post by ChrisSterritt » Fri Feb 28, 2003 2:20 am

Hello,

Just downloaded JFreeChart after being away from it for a while, and the new improvements are fantastic -- thanks for the great tool!

I ran the demos, however, and all the Y-axis labels (which are rotated 90 degrees) looked as if they'd been squashed to about 2 points and then resized -- they were just blocks that vaguely approximated text.

I'll be glad to run tests, look at the source, etc. (I program Java for a living) if you want to tell me where to look. I'll even post a bug to Apple/Sun when we find it's their fault :-).

Java version: Java HotSpot(TM) Client VM (build 1.3.1_03-69, mixed mode)

Thanks,
--chris sterritt

David Gilbert

Re: Problem under OS X

Post by David Gilbert » Tue Mar 04, 2003 11:06 am

Hi Chris,

Thanks for the report. This has been reported by one or two others, and seems to be specific to MacOS X.

The code that draws the rotated strings is in the RefineryUtilities class in the JCommon class library:

/**
* A utility method for drawing rotated text.
* <P>
* A common rotation is -Math.PI/2 which draws text 'vertically' (with the top of the
* characters on the left).
*
* @param text the text.
* @param g2 the graphics device.
* @param x the x-coordinate.
* @param y the y-coordinate.
* @param rotation the clockwise rotation (in radians).
*/
public static void drawRotatedString(String text, Graphics2D g2,
float x, float y, double rotation) {

if ((text == null) || (text.equals(""))) {
return;
}

AffineTransform saved = g2.getTransform();

// apply the rotation...
AffineTransform rotate = AffineTransform.getRotateInstance(rotation, x, y);
g2.transform(rotate);

// workaround for JDC bug ID 4312117 and others...
TextLayout tl = new TextLayout(text, g2.getFont(), g2.getFontRenderContext());
tl.draw(g2, x, y);

// replaces this code...
//g2.drawString(text, x, y);

g2.setTransform(saved);

}

Perhaps you could try it out without the TextLayout workaround to see if that makes a difference.

Regards,

Dave Gilbert

ChrisSterritt

Re: Problem under OS X

Post by ChrisSterritt » Sat Mar 08, 2003 10:34 pm

Hi David,

Yes, commenting out the 'workaround' and putting in the old code works fine.

Thanks,
--chris sterritt

Locked