You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Steven Huey <st...@stevenhuey.net> on 2005/03/20 05:14:53 UTC

Dynamic width, height, & viewBox

Hello,

I've got something like the following:

private SVGOMSVGElement svgElement;
.
.
.
svgElement = (SVGOMSVGElement) canvas.getSVGDocument().getRootElement();
.
.
.
updateManager.getUpdateRunnableQueue().invokeLater(
     new Runnable() {
         public void run() {
             svgElement.setAttributeNS(null, "viewBox", "# # # #");
         }
     }
);

The svgElement assignment takes place within the gvtBuildCompleted 
method of a GVTTreeBuilderListener, and the # symbols in the 
setAttributeNS call are actual values. I end up with a RuntimeException 
and after checking the SVGOMSVGElement source I found:

public SVGAnimatedRect getViewBox() {
     throw new RuntimeException(" !!! TODO: getViewBox()");
}

Is there any other way to dynamically change the size of the viewBox 
attribute? I'm also looking to change the height and width attributes 
at the same time. Basically what I'm trying to accomplish is given a 
large SVG document view only a specific area within the document so I'm 
trying to set the width, height, and viewBox attributes accordingly.

Thanks,
Steve


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


Re: Dynamic width, height, & viewBox

Posted by Thomas DeWeese <Th...@Kodak.com>.
Steven Huey wrote:
> Thomas,
> 
> I don't see which transform I'd adjust since I'm not interested in 
> scaling, translating, or rotating the image, just sort of cropping it 
> temporarily. Could you elaborate?

    Actually what you want to do is translate the canvas so
a point x,y is at the upper left of the canvas and that
the content is scaled so that your viewable width/height
fills the canvas width/height.

    The main effect of viewBox is to translate and scale
the secondary effect (especially in your case) is to clip
to that rectangle.

> 
> On Mar 20, 2005, at 3:14 PM, Thomas DeWeese wrote:
> 
>>    If you can have a 'g' element and simply adjust the transform
>> on that element it will be _much_ faster.
> 
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Dynamic width, height, & viewBox

Posted by Steven Huey <st...@stevenhuey.net>.
Thomas,

I don't see which transform I'd adjust since I'm not interested in 
scaling, translating, or rotating the image, just sort of cropping it 
temporarily. Could you elaborate?

On Mar 20, 2005, at 3:14 PM, Thomas DeWeese wrote:

>    If you can have a 'g' element and simply adjust the transform
> on that element it will be _much_ faster.


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


Re: Dynamic width, height, & viewBox

Posted by Thomas DeWeese <Th...@Kodak.com>.
Steven Huey wrote:

> I have it working now, although it does seem to be a pretty resource 
> intensive operation. I ended up having to use the -Xms and -Xmx options 
> for the command line java tool in order to not get any OutOfMemory errors.
> 
> Can you quickly explain what's going on behind the scenes that causes 
> this to be so resource intensive? Is there a better way to accomplish 
> what I'm doing?

    When you change the size of a viewport (i.e. an SVG element)
The entire graphics tree under that element is recreated so % units
can be recalculated.

    If you can have a 'g' element and simply adjust the transform
on that element it will be _much_ faster.

> If it matters, the SVG file I'm working with is about 2MB in size.
> 
> - Steve
> 
> On Mar 20, 2005, at 8:25 AM, Thomas DeWeese wrote:
> 
>> Steven Huey wrote:
>>
>>> svgElement = (SVGOMSVGElement) canvas.getSVGDocument().getRootElement();
>>> updateManager.getUpdateRunnableQueue().invokeLater(
>>>     new Runnable() {
>>>         public void run() {
>>>             svgElement.setAttributeNS(null, "viewBox", "# # # #");
>>>         }
>>>     }
>>> );
>>
>>
>>    The ecmascript version of this works fine for me with CVS Batik:
>>
>> <?xml version="1.0"?>
>> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
>>           "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
>> <svg id="foo" width="450" height="500"
>>      xmlns:xlink="http://www.w3.org/1999/xlink"
>>      viewBox="0 0 450 500">
>>    <rect x="10" y="10" width="200" height="300"
>>          fill="red" stroke="blue" stroke-width="10"
>>          onclick="document.rootElement.setAttribute('viewBox', '0 0 
>> 220 320')"
>>          />
>> </svg>
>>
>>> I end up with a RuntimeException and after checking the 
>>> SVGOMSVGElement source I found:
>>> public SVGAnimatedRect getViewBox() {
>>>     throw new RuntimeException(" !!! TODO: getViewBox()");
>>> }
>>
>>
>>    There is no reason for the set call to trigger getViewBox.
>> Is it possible that your code to calculate the viewBox is calling
>> this method?  In which case I guess for now you will need to get
>> the raw attribute and parse it yourself.
>>
>>> Is there any other way to dynamically change the size of the viewBox 
>>> attribute? I'm also looking to change the height and width attributes 
>>> at the same time. Basically what I'm trying to accomplish is given a 
>>> large SVG document view only a specific area within the document so 
>>> I'm trying to set the width, height, and viewBox attributes accordingly.
>>> Thanks,
>>> Steve
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Dynamic width, height, & viewBox

Posted by Steven Huey <st...@stevenhuey.net>.
Thomas,

I have it working now, although it does seem to be a pretty resource 
intensive operation. I ended up having to use the -Xms and -Xmx options 
for the command line java tool in order to not get any OutOfMemory 
errors.

Can you quickly explain what's going on behind the scenes that causes 
this to be so resource intensive? Is there a better way to accomplish 
what I'm doing?

If it matters, the SVG file I'm working with is about 2MB in size.

- Steve

On Mar 20, 2005, at 8:25 AM, Thomas DeWeese wrote:

> Steven Huey wrote:
>
>> svgElement = (SVGOMSVGElement) 
>> canvas.getSVGDocument().getRootElement();
>> updateManager.getUpdateRunnableQueue().invokeLater(
>>     new Runnable() {
>>         public void run() {
>>             svgElement.setAttributeNS(null, "viewBox", "# # # #");
>>         }
>>     }
>> );
>
>    The ecmascript version of this works fine for me with CVS Batik:
>
> <?xml version="1.0"?>
> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
>           "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
> <svg id="foo" width="450" height="500"
>      xmlns:xlink="http://www.w3.org/1999/xlink"
>      viewBox="0 0 450 500">
>    <rect x="10" y="10" width="200" height="300"
>          fill="red" stroke="blue" stroke-width="10"
>          onclick="document.rootElement.setAttribute('viewBox', '0 0 
> 220 320')"
>          />
> </svg>
>
>> I end up with a RuntimeException and after checking the 
>> SVGOMSVGElement source I found:
>> public SVGAnimatedRect getViewBox() {
>>     throw new RuntimeException(" !!! TODO: getViewBox()");
>> }
>
>    There is no reason for the set call to trigger getViewBox.
> Is it possible that your code to calculate the viewBox is calling
> this method?  In which case I guess for now you will need to get
> the raw attribute and parse it yourself.
>
>> Is there any other way to dynamically change the size of the viewBox 
>> attribute? I'm also looking to change the height and width attributes 
>> at the same time. Basically what I'm trying to accomplish is given a 
>> large SVG document view only a specific area within the document so 
>> I'm trying to set the width, height, and viewBox attributes 
>> accordingly.
>> Thanks,
>> Steve
>> ---------------------------------------------------------------------
>> 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
>
>


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


Re: Dynamic width, height, & viewBox

Posted by Thomas DeWeese <Th...@Kodak.com>.
Steven Huey wrote:

> svgElement = (SVGOMSVGElement) canvas.getSVGDocument().getRootElement();
> updateManager.getUpdateRunnableQueue().invokeLater(
>     new Runnable() {
>         public void run() {
>             svgElement.setAttributeNS(null, "viewBox", "# # # #");
>         }
>     }
> );

    The ecmascript version of this works fine for me with CVS Batik:

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
           "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg id="foo" width="450" height="500"
      xmlns:xlink="http://www.w3.org/1999/xlink"
      viewBox="0 0 450 500">
    <rect x="10" y="10" width="200" height="300"
          fill="red" stroke="blue" stroke-width="10"
          onclick="document.rootElement.setAttribute('viewBox', '0 0 220 
320')"
          />
</svg>

> I end up with a RuntimeException 
> and after checking the SVGOMSVGElement source I found:
> 
> public SVGAnimatedRect getViewBox() {
>     throw new RuntimeException(" !!! TODO: getViewBox()");
> }

    There is no reason for the set call to trigger getViewBox.
Is it possible that your code to calculate the viewBox is calling
this method?  In which case I guess for now you will need to get
the raw attribute and parse it yourself.

> 
> Is there any other way to dynamically change the size of the viewBox 
> attribute? I'm also looking to change the height and width attributes at 
> the same time. Basically what I'm trying to accomplish is given a large 
> SVG document view only a specific area within the document so I'm trying 
> to set the width, height, and viewBox attributes accordingly.
> 
> Thanks,
> Steve
> 
> 
> ---------------------------------------------------------------------
> 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