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 Andy Norman <an...@simulsoft.com> on 2009/04/02 21:33:46 UTC

how does one set a viewport with Batik via code

Hi,

I've been trying to implement the W3C example

http://nelson.w3.org/TR/2000/CR-SVG-20001102/coords.html#ExamplePreserveAspectRatio

on a JSVGCanvas using Batik 1.6, but haven't been able to figure out how 
to create named viewport entities as the example above shows.  Can 
anyone tell me how to achieve this via Batik Java code?

My ultimate goal is to scale a symbol instanced with a <use> 
element...maybe I am going about this incorrectly?

Many thanks for any info,

Andy

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


Re: how does one set a viewport with Batik via code

Posted by Andy Norman <an...@simulsoft.com>.
Hi, Helder,

Thanks for your reply.  I agree re: general SVG questions should be 
addressed in other forums (and thanks for the reference).  My query was 
too open-ended. 

My Batik-specific question is really:  how to create a viewport entity 
definition in the internal DOM via code, so that upon SVGGenerator 
stream(out) the document contains

<!ENTITY Viewport1 "<rect x='.5' y='.5' width='49' height='29'
fill='none' stroke='blue'/>">
<!ENTITY Viewport2 "<rect x='.5' y='.5' width='29' height='59'
fill='none' stroke='blue'/>">
]>

I ask this because it's the only way I know how to verify that the 
internal DOM matches the W3C example.


>> I've been trying to implement the W3C example
>> http://nelson.w3.org/TR/2000/CR-SVG-20001102/coords.html#ExamplePreserveAspectRatio
>>     
>
>   
> I'd suggest taking a look at the version 1.1 of the SVG specification
> [1] (the section you mention is also there [2]). It's generally the
> one implementations best support [3]. If you decide to stick with
> version 1.0, I'd suggest using the official version of the
> specification [4].
>
>   
Yes, it definitely helps to look at the original and correct version!  
Fortunately, no material difference in this particular case...
>> on a JSVGCanvas using Batik 1.6, but haven't been able to figure out how to
>> create named viewport entities as the example above shows.  Can anyone tell
>> me how to achieve this via Batik Java code?
>>     
>
> Do you mean using the SVG Generator [1]? As far as I know, I guess
> that the generator doesn't create this sort of entities (but I'm not
> familiar with it, so I might be wrong). If you really intend this, I'd
> suggest using a general XML parser/generator.
>
>
>   
My SVG content is initially created 100% by Batik internally, via user 
commands communicated to an interactive JSVGCanvas wrapped in a desktop 
GUI.  No ECMAScript.  The SVG is streamed out as mentioned prior.  I 
just need the canvas to show the same results if the user reloads the 
file later from disk.
>   
>> My ultimate goal is to scale a symbol instanced with a <use> element...maybe
>> I am going about this incorrectly?
>>     
>
> I'd say that you could use a transform attribute [5] directly in the
> use element instead. Something like:
>
>   <use transform="scale(2)" xlink:href="#ElementId" />
>
> This will likely be better supported among implementations than the
> attempt of using "preserveAspectRatio", which assume child SVG
> element(s).
>
>
>   
Setting the scale on the <use> means additional transform manipulations 
to keep the x,y location correct.  I interpret the viewport specs to 
mean I can place the viewport without using transforms - letting the 
viewport take care of scaling within itself, and I'm always in favor of 
letting someone else do the work for me ;-). 

The only implementation I was concerned with was Batik's, but if users 
can't exchange the generated SVG with other programs then indeed I might 
be wise to work out the transforms instead.
>
>
> Hope this helps,
>
>   Helder Magalhães
>
>
>   
It does.  Thanks much for you input!  I'll take a closer look at the 
transform manipulations.  But I am still looking to find out how to 
create those viewport entities, and reference them, via Batik.

Regards,

Andy

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


Re: how does one set a viewport with Batik via code

Posted by Helder Magalhães <he...@gmail.com>.
Hi Andy,



> I've been trying to implement the W3C example
> http://nelson.w3.org/TR/2000/CR-SVG-20001102/coords.html#ExamplePreserveAspectRatio

I'd suggest taking a look at the version 1.1 of the SVG specification
[1] (the section you mention is also there [2]). It's generally the
one implementations best support [3]. If you decide to stick with
version 1.0, I'd suggest using the official version of the
specification [4].



> on a JSVGCanvas using Batik 1.6, but haven't been able to figure out how to
> create named viewport entities as the example above shows.  Can anyone tell
> me how to achieve this via Batik Java code?

Do you mean using the SVG Generator [1]? As far as I know, I guess
that the generator doesn't create this sort of entities (but I'm not
familiar with it, so I might be wrong). If you really intend this, I'd
suggest using a general XML parser/generator.



> My ultimate goal is to scale a symbol instanced with a <use> element...maybe
> I am going about this incorrectly?

I'd say that you could use a transform attribute [5] directly in the
use element instead. Something like:

  <use transform="scale(2)" xlink:href="#ElementId" />

This will likely be better supported among implementations than the
attempt of using "preserveAspectRatio", which assume child SVG
element(s).



If you have general SVG questions, you may consider posting at SVG
Developers [6], a group with a larger community and (usually) fast
responsiveness. ;-)



Hope this helps,

  Helder Magalhães



[1] http://www.w3.org/TR/SVG11/
[2] http://www.w3.org/TR/SVG11/coords.html#ExamplePreserveAspectRatio
[3] http://codedread.com/svg-support.php
[4] http://www.w3.org/TR/SVG10/
[4] http://xmlgraphics.apache.org/batik/using/svg-generator.html
[5] http://www.w3.org/TR/SVG11/coords.html#TransformAttribute
[6] http://tech.groups.yahoo.com/group/svg-developers/

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