You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by "Evenblij, Paul" <Pa...@nl.compuware.com> on 2001/09/28 19:40:00 UTC

SVGTransform does not handle identity transforms correctly

Hi there,

I have found another issue with SVGTransform. 
Perform the following sequence of calls on SVGGraphics2D instance g2d: 

  g2d.translate(10,10);        
  g2d.scale(2, 2);        
  g2d.scale(0.5, 0.5);
  g2d.translate(20,40);
  g2d.rotate(0);
  g2d.translate(-30,-50);

  g2d.fillRect(10,10, 100,80);

Attentive readers will note that the series of transformations should have
no net effect whatsoever. Still, Batik generates the following SVG:

<rect x="10" y="10" transform="translate(10,10)  translate(20,40)
translate(-30,-50)" width="100" style="fill:black; stroke:none;" height="80"
/>

Obviously, the transform string is not optimized. This is due to the "scale"
transforms (which, taken together, form an identity) and the "rotate" (which
is also an identity). Identity transforms are not converted to SVG (note the
double spaces between the "translate"s). This is correct. However, the first
"translate" is by then already converted, and can no longer be concatenated
to the next.

I have created a patch which addresses this issue. It adds an "isIdentity()"
method to the TransformStackElement class, and reconstructs the public
"toSVGTransform()" method in SVGTransform, so that identities do not keep
similar transforms from being concatenated, not even if they are "hidden",
like the paired scale transforms above. It also removes the "isIdentity()"
implementation from SVGTransform itself, since this is now handled
generically by TransformStackElement.

Generated output of the patched code reads:

<rect x="10" y="10" width="100" style="fill:black; stroke:none;" height="80"
/>

I have created bug 3871 for this, and attached the proposed patch.

Cheers,
Paul

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


Re: SVGTransform does not handle identity transforms correctly

Posted by Vincent Hardy <vi...@sun.com>.
Paul,

Thanks a lot for your detailed bug report. I will look at it in details
and commit your patch shortly.

Regards,
Vincent.

"Evenblij, Paul" wrote:
> 
> Hi there,
> 
> I have found another issue with SVGTransform.
> Perform the following sequence of calls on SVGGraphics2D instance g2d:
> 
>   g2d.translate(10,10);
>   g2d.scale(2, 2);
>   g2d.scale(0.5, 0.5);
>   g2d.translate(20,40);
>   g2d.rotate(0);
>   g2d.translate(-30,-50);
> 
>   g2d.fillRect(10,10, 100,80);
> 
> Attentive readers will note that the series of transformations should have
> no net effect whatsoever. Still, Batik generates the following SVG:
> 
> <rect x="10" y="10" transform="translate(10,10)  translate(20,40)
> translate(-30,-50)" width="100" style="fill:black; stroke:none;" height="80"
> />
> 
> Obviously, the transform string is not optimized. This is due to the "scale"
> transforms (which, taken together, form an identity) and the "rotate" (which
> is also an identity). Identity transforms are not converted to SVG (note the
> double spaces between the "translate"s). This is correct. However, the first
> "translate" is by then already converted, and can no longer be concatenated
> to the next.
> 
> I have created a patch which addresses this issue. It adds an "isIdentity()"
> method to the TransformStackElement class, and reconstructs the public
> "toSVGTransform()" method in SVGTransform, so that identities do not keep
> similar transforms from being concatenated, not even if they are "hidden",
> like the paired scale transforms above. It also removes the "isIdentity()"
> implementation from SVGTransform itself, since this is now handled
> generically by TransformStackElement.
> 
> Generated output of the patched code reads:
> 
> <rect x="10" y="10" width="100" style="fill:black; stroke:none;" height="80"
> />
> 
> I have created bug 3871 for this, and attached the proposed patch.
> 
> Cheers,
> Paul
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-dev-help@xml.apache.org

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