xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bishop, Michael W. CONTR J9C880" <Michael.Bis...@je.jfcom.mil>
Subject RE: Scaling around a center point...
Date Thu, 08 Dec 2005 15:53:51 GMT
     The madness certainly has begun.  I managed to put something
together based on your suggestions and a little bit of hacking.  The
class I wrote tracks move translations and scale translations
separately, but adds them together when setting the attribute back to
the document.
     Now another similar question.  How can I get rotate information
from the incoming AffineTransform?  I can get scaleX/Y and translateX/Y,
but there is no visible way to get rotate information.  If my transform
attribute looke like:

transform="translate(x, y) scale(x, y) rotate(t)"

Is there a way to get the value of t?

Michael Bishop

-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com] 
Sent: Thursday, December 08, 2005 6:03 AM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Scaling around a center point...

Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Michael.Bishop@je.jfcom.mil> wrote on

12/07/2005 01:56:24 PM:

> Now this is getting more complicated.  The second time I scale an 
element, it 
> moves because the translation value is appended.  This is tough to 
> Let's say the center point is 100,100.  If I scale to 2x, I add a 
> by (-100 * 1), (-100 * 1).  My new translation value is (-100, -100). 
Now if 
> I scale to 3x, I add a translation by (-100 * 2), (-100 * 2).  My new 
> translation value is (-300, -300).  This is wrong.  Why?  Because it 
> take the first scale into effect!  If I started at a scale factor of
> scaled directly to 3x, my new translation value would be (-200, -200).

    You need to multiply your new scale matrix by your old scale matrix
get your new scale/transform matrix.  If you do this your new translate
will be multiplied by the previous scale factor giving you: 
        -100*2*2 + -100 = -500 which I think is right for a 6x scale.

> To summarize, I need to keep translations appended by moving the

> RELATIVE to the previous value and I need to keep translations by 
scaling the 
> element ABSOLUTE:
> transform=(translate(mx, my) translate(sx, sy) scale(x, y))
> Where (mx,my) is the move translation (incremented based on movement),

> sy) is the scale translation (set based on scale factor) and (x, y) is

the scale factor.
> So far so good.

    This is the path to madness ;)  You need to setup the code so it 
care why it has a translate (be it for translate or for scaling) it just


> The problem is that if I use the above transform attribute, I need to 
> TWO translate values from the AffineTransform; one for movement, one

> scaling.  How can I do this?  If I can't, how can I "parse" an
> element into the various values?  The reason I switched to an 
> was to avoid using string parsing to get the various bits I need.

    If you look under the hood of the AWTTransformProducer there is a
parser and a handler.  The handler get's called back when the parser
handles major pieces of the transform attribute (like the 'translate'
or 'scale' pieces).

> ...nevermind, that's not how you get center X/Y.  Now it stays put for
> part; I'm getting random incorrect translations that I haven't been
to solve yet.
> Michael Bishop
> From: Bishop, Michael W. CONTR J9C880 
> Sent: Wednesday, December 07, 2005 12:44 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: Scaling around a center point...
> More transform issues!  As you may recall, I add a translate value to 
> objects around the canvas.  Now I'm working on scaling and I like the 
scale to
> be uniform around the center of element.  I get the center point by 
asking the
> Element for its bounding box:
> centerX = boundingBox.getWidth() - boundingBox.getX();
> centerY = boundingBox.getHeight() - boundingBox.getY();
> In the SVG Essentials book I have, it says to scale around a center 
point, the
> translate should be set to:
> translate(-centerX * (factor - 1), -centerY * (factor - 1))
> Instead of setting the above, I ADD the above to the existing
if one
> exists.  However, when I scale, the element stays nowhere near the 
> point.  I tried simply SETTING the translate values, losing the
> and it's still wrong.  Is there a better technique for scaling around 
> center of an element, or is my math just wrong somewhere?
> Michael Bishop

To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

View raw message