xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DeWeese Thomas <thomas.dewe...@gmail.com>
Subject Re: Set a zooming-strategy to an SVGCanvas
Date Thu, 10 May 2012 22:18:25 GMT
Hi,

On May 10, 2012, at 8:53 AM, ml@mherrn.de wrote:

> Hi,
> 
> I am trying build a JSVGCanvas that automatically zooms the SVG image it
> displays, depending on a given strategy.
> 
> Possible strategies are:
>  * Zoom the image to fit into the canvas (do not respect aspect ratio)
>  * Zoom the image to fit into the canvas, but respect aspect ratio (zoom
> until either width or height of the canvas is filled)
>  * Zoom to canvas width (if the height of the image is larger than the
> height of the canvas, some part of the image will be outside of the
> viewport)
> 
> (As I understand all these cases and a lot more are defined in the SVG
> standard in the preserveAspectRatio attribute:
>> http://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute)
> 
> The first one works quite well.
> The second one works, when the image will always be centered.
> But the second one does _not_ work, if I want the image always in the top
> left corner of the canvas.
> 
> The example application and SVG file are attached to this mail.

	I didn't see them show up as attachments.

> I did it like Heinz Doerr describes in this Thread:
>> http://mail-archives.apache.org/mod_mbox/xmlgraphics-batik-users/200906.mbox/%3c4A3E3C33.60508@ecoms.de%3e
> 
> If I change the SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN in
> line 17 to
> SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_NONE (first case)
> or
> SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMID (second case,
> working)
> everything is quite well.
> But using SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN (second
> case, not working) It doesn't:
> When the application starts, the image is always displayed as expected.
> But when extending the width of the window, the image starts beginning to
> move out of the canvas on the top. Addionally when lowering the width of
> the window, the image starts to move down inside the canvas (not staying
> in the top left corner).

	Do you have 'recenterOnResize' enabled?  That might react badly to your
reimplementation of calculateViewingTransform.

> Some questions arise:
>  1. Is overriding calculateViewingTransform(String, SVGSVGElement) the
> correct way to achieve this?

	This is probably the best way to get what you want.

>  2. What am I doing wrong here (or where is my misunderstanding)?

	It is very easy to make small mistakes in the calculation of AffineTransforms
that can lead to effects like this.  Resize is especially tricky because it requires a
trip through the SVG Document event handlers and it's complex to get the viewing
transform and the display transform to behave sensibly.

>  3. Where can I get more information about utilizing batik in such a way?
> The classes and methods I am using and overriding here aren't documented
> very good...

	Ask questions here and read the source.

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


Mime
View raw message