xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Kunkee <ra...@randallkunkee.com>
Subject Re: JSVGCanvas.setRenderingTransform()
Date Tue, 24 Apr 2007 06:50:20 GMT
Finally getting back to testing this and posting the results.

Thanks, Michael, for your reply.

Yes, I want to zoom in with a given center point.  However the  
solution offered below doesn't work. Or perhaps it's not universal  
enough.  Or I'm doing something wrong.  Here's what I have:

The outer svg element is:
<svg height="647px" width="1024px" viewBox="-334 -78 649 410" etc  
(xml namespace stuff) >

As I stated before, I have another element (in a different namespace,  
let's call it x):

<x:defpicturesize viewBox="32 -63 269 169"> (call these the desired  
values). To help me know if I'm doing the right thing, I also have a  
<rect x="32" y="-63" width="269" height="169" stroke="#00ff00"/>. If  
my zoom is correct, then I just just see the edges of this rectangle.  
Alas, the formula below is pretty far off.

This gives sx=2.4126394, and sy=2.4260354. I have tested these zoom  
values and know them to be accurate. I can manually scroll until the  
desired viewBox just fits my window.  Zoom is easy to calculate, i.e.  
width of svg / width of desired viewBox, and likewise with the svg  
height and the desired height.

I calculate the center of the box I want to zoom to as (desired_x +  
desired_width/2, desired_y / desired_height/2), i.e. these are my  
center points you describe below as x and y. Applying the formulas  
below, I get (for tx, ty) = ( -235.20445, -30.659761).

Sadly, on the actual display the view is far to the left of where it  
should be. Through trial and error, I have found that the actual X  
translation to center on the zoomed in viewBox is tx = -1124.7725 and  
ty is about -146. Of course, these numbers only work for the default  
window size of my application. If I start with a larger window, the x  
translation is no longer correct.

Any more ideas about this?

Another question: when I call getRenderingTransform(), shouldn't I  
get something other than the identify transformation? It's always the  
identity transformation before I start. I create my transformation by  
creating the translation matrix and then concatenating the scaling  
matrix. Shouldn't the renderingTransform not be [[1.0, 0.0, 0.0],  
[0.0, 1.0, 0.0]]?

Thanks,
Randy



On Apr 17, 2007, at 4:06 PM, Bishop, Michael W. CONTR J9C880 wrote:

> It sounds like you're trying to scale around a certain center point:
>
> Given a center point (x,y) and scale values sx, sy, you derive  
> translate values tx and ty:
>
> tx = -x * (sx - 1.0);
> ty = -y * (sy - 1.0);
>
> translate(tx, ty);
> scale(sx, sy);
>
> Michael Bishop
>
> ________________________________
>
> From: randy.kunkee@us.abb.com [mailto:randy.kunkee@us.abb.com]
> Sent: Tue 4/17/2007 4:10 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: JSVGCanvas.setRenderingTransform()
>
>
>
> I hope somebody can shed some light on this.
>
> Basically, I want to do in software what could be done with a  
> control-drag-mousebutton1. Seems like there could be a simple  
> interface to call to do this, but I haven't found it yet.
>
> I'm trying to implement what I call a "pre-zoomed" SVG file. In my  
> SVG file, I have added an element <x:defaultpicturesize viewBox="x  
> y w h"/>.
>
> Since I haven't found a call to "zoom it to this box", I tried  
> using setRenderingTransform(). After loading the SVG file (and  
> after gvtRenderingCompleted() is called), I look for this element.   
> If I find one, I create an AffineTransform and call  
> setRenderingTransform()
>
> The problem is that this thing does not do what I expect it to.
>
> It is easy enough to center up the picture (if that's all I wanted  
> to do). I simply calculate the difference between the center of the  
> <svg:svg viewbox="..."> and the center of my desired viewbox. This  
> is straightforward and produces a view that looks close to centered  
> (but clearly is not exactly centered).
>
> When I apply a scaling transformation things go very off. First of  
> all, scaling appears to happen based on the upper left-hand corner  
> of the picture. For example, if I only scale (say 2x) what  
> previously was in the upper left-hand corner now fills the entire  
> display.
>
> So I think, translate the upper left-hand corner of the desired  
> viewbox to the x and y of the <svg:svg> viewbox and then scale.  
> Still not right. Then I think, okay, it's scaling first so my  
> translation values actually need to be multiplied by the scale  
> factor - better but still not right.
>
> What am I missing here? Seems like this should be an easy thing to do.
>
> Regards,
> Randy
> <winmail.dat>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users- 
> help@xmlgraphics.apache.org


---------------------------------------------------------------------
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