Strange differences in printing between 1.5 and 1.6

I've been successfully running for some time now an application which prints CD labels based on information in a database.

The front label is fairly simple, dividing a square area into four rectangles, the top left and bottom right are squares of different sizes, the top right contains text (artist name(s)) printed horizontally, and the bottom left contains text (album name) printed rotated 90 degrees clockwise, both text fields centred both horizontally and vertically, with respect to the rectangle orientation. The application lays out a print preview panel, and if I'm satisfied with it I invoke a print function, which uses exactly the same code as the preview.

This has been working fine for a year and a half (for in excess of 600 labels) under Java 1.5. Now, using 1.6, the print preview works OK, after modifying the code for problem#1, but the printed output gets the bottom left area wrong. The reason I found problem#1 was that I test whether there is room for all the text on one line, and if not split it. I do that using FontMetrics.stringWidth(String). Under 1.6, when an affine transform is applied to rotate the rectangle, stringWidth returns a negative number - on 1.5 it was positive.

After changing the code to take the absolute value of stringWidth, the text in the rotated rectangle is not centered vertically, and seems to be

possibly centered horizontally, but in a much larger rectangle, so that most of the text is invisible, being outside the visible rectangle.. If I have to split this rectangle it's even worse, the text falling completely outside the rectangle, and the two lines being aligned according to different widths, quite apart from being presented in reverse order.

If stringWidth is behaving correctly, I'd like to know what the explanation is, and why it behaves differently depending on whether I'm creating a print preview or actually printing.

As a matter of interest, I just triedchanging the orientation of the bottom left rectangle to rotated 90 degrees anticlockwise - print preview exactly as expected, same displacement on the printer. I'm having to keep a copy of 1.5 just for this application, and having to remember to change my PATH every time I run it.

A similar application which writes the tray inserts, which produces, for the spines, text rectangles in BOTH rotated orientations, AND 180 degree rotation, works without a problem in 1.6.

[2456 byte] By [digbya] at [2007-11-26 20:49:43]
# 1
Presumably you are running this on the same system.The readme docs for java documentation specify what changed in the VM. Probably something in the GUI changed.
jschella at 2007-7-10 2:13:50 > top of Java-index,Java Essentials,Java Programming...
# 2

Yes, of course, I'm running on the same system. My testing technique involved parallel tests in two command prompt windows, the only difference between the two being tha PATH environment variable.

I have resolved the problem by using Math.abs() for all the invocations of stringWidth, getHeight and getDescent for my rotated rectangle.

I'd still like to know where it is described that the return values for these methods are negative when the rectangles are rotated 90 degrees, and why.

I have found another resolution to the problem, by doing all stringWidth, getHeight and getDescent processing before rotating. The negative values only seem to occur when rotated ?0?

Message was edited by:

digby

digbya at 2007-7-10 2:13:50 > top of Java-index,Java Essentials,Java Programming...