Printing rotated shapes modifies stroke

Hi,

I'm writing some code that draws the same rectangle twice: the first time on the default graphic context and the second time on a rotated graphic context. The code works and I get the two shapes printed as I wanted with the correct stroke of 3 points. But when I try to print these objects, the first rectangle is printed with a 3 points stroke where the second rectangle is printed with a thin stroke (less than 1 ponint!)

Why is this happening? I'm using the same method to display and to print the shapes. The printing is done using the standard java.awt.print classes. I've already tried using the RenderingHints class but with no useful results. Any idea?

Thanks for your help

miki

This is the code:

Shape shape = new Rectangle(0, 0, 150, 30);

g2.translate(200, 200);

g2.setStroke(new BasicStroke(3.0f));

Rectangle rect = shape.getBounds();

g2.draw(shape);

AffineTransform at = new AffineTransform();

at.rotate(Math.toRadians(45.0));

AffineTransform atTrans = new AffineTransform();

atTrans.concatenate(at);

atTrans.translate(0, -(rect.height/2));

atTrans.translate(2.866, 0);

AffineTransform savedAT = g2.getTransform();

g2.transform(atTrans);

g2.setStroke(new BasicStroke(3.0f));

g2.draw(shape);

g2.setTransform(savedAT);

[1368 byte] By [mikic2a] at [2007-9-28 11:40:19]
# 1

Create a special implementation of Shape which delegates all methods to the normal Shape.

All that is, except the getPathIterator methods.

For these, create a delegating PathIterator which applies the transform before returning the coordinates. Then, instead of setting the transform in the graphics, set it in your delegating PathIterator.

I'm not, joking, it works for me.

IanSchneidera at 2007-7-12 2:25:40 > top of Java-index,Other Topics,Java Game Development...
# 2

Ian,

thanks for the reply... I've found a different work around that it's as good (at least for me). I use the createStrokedShape method on the Stroke interface passing my rectangle as parameter. Then I use the fill method on the Grpahics2D object (instead of draw) and I get objects with the same stroke width wathever the rotation.

miki

mikic2a at 2007-7-12 2:25:40 > top of Java-index,Other Topics,Java Game Development...