Just a quick note in case someone else runs into this.

I was troubleshooting a problem with printing to PDF via iText, and realized
that iText's Graphics2D implementation behaves differently from AWT's with
regard to treatment of AffineTransform.  The following code proves the point:

    AffineTransform savedTransform = g.getTransform();
    // make some global modifications
    AffineTransform globalTransform = g.getTransform();

    g.scale(...); // local modifications for item A
    // draw item A
    g.setTransform(globalTransform);

    g.rotate(...); // local modifications for item B
    // draw item B
    g.setTransform(globalTransform);

    g.rotate(...); // local modifications for item C
    // draw item C
    g.setTransform(globalTransform);

    ...

In the AWT's implementation, the later setTranform calls will restore the
drawing state to what it was at the initial call to getTransform.  In iText,
it will make no difference at all because the calls to Graphics2D's
trasformation methods have been modifying the actual instance referred to by
globalTransform.  The question is whether setTranform ought to *copy* its
parameter into the current AffineTransform (which is the behavior of the AWT)
or simply *adopt* the parameter as its AffineTransform.  The issue isn't
crystal clear in the API docs ("Overwrites the Transform in the Graphics2D
context."), but the intent appears to be clear, that the AffineTransform
actually used by the Graphics2D instance should never be exposed to the
outside world.

A good immediate workaround is to adopt a policy of cloning AffineTransform
instances prior to calling setTransform if you intend to later either modify
your own instance or change the effective transform via methods in Graphics2D.

-- 
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to