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 James Shaw <he...@btopenworld.com> on 2005/03/18 16:38:23 UTC

Using viewBox for unit conversion

I have been looking for a way to reflect an object about its y axis; I 
understand that I need a transform matrix to do this, and that you 
cannot translate by cms, ins or other units.  The ppl on #svg 
recommended using a viewbox.

I've checked on #svg, and I understand that a document like this:

<svg width="20cm" height="10cm" viewBox="0 0 200 100">
    <line x1="0" y1="0" x2="20" y2="10" style="stroke: blue; 
stroke-width: 1"/>
</svg>

should produce a drawing 20x10cms.  However, when I preview this in 
squiggle or a JSVGScrollPane, the drawing is about 80x40 pixels.  I 
would have expected batik to use the screen dpi (or similar measurement) 
to correct render the document at 100% zoom.

Am I using viewBox incorrectly, or am I using Batik wrongly?

Thanks in advance
James Shaw

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


Re: Using viewBox for unit conversion

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi James,

James Shaw wrote:

> That's what I would expect, but it doesn't seem to be the case for me -- 
> the document appears much smaller than I would expect.

    If you are using your own frame you may need subclass the canvas and
implement the 'setMySize' method.  Here is what the JSVGViewerFrame
does (from squiggle):

                 public void setMySize(Dimension d) {
                     setPreferredSize(d);
                     invalidate();
                     if (JSVGViewerFrame.this.autoAdjust) {
                         JSVGViewerFrame.this.pack();
                     }
                 }


>> Depending on how complex your object is you might try to use translate 
>> and scale tranforms.
>> <svg width="20cm" height="10cm" viewBox="0 0 20 10" 
>> style="fill:red;stroke:blue">
>>  <g transform="translate(0,10) scale(1,-1)">
>>   <line x1="0" y1="0" x2="20" y2="10" style="stroke: blue; 
>> stroke-width: 1"  />
>>  </g>
>> </svg>
>>
>> Patrick
>>
> Thanks for this suggestion.  I did try to use scale(1,-1) but it caused 
> the object to disappear entirely (am I doing something really stupid 
> here?)  

   I don't know if it's really stupid ;) but the translate is also
important other wise everything will be drawn in the negative
part of the coordinate system.  The general thing is to translate
by the height of the viewing area (for vertical flip).

> Also, since switching from hardcoded cms to userspace coords, 
> I've noticed discrepancies in line widths between the SVG viewed in a 
> JSVGCanvas and via FOP (using the PDFTranscoder).  To avoid these 
> problems, I would really like to stick with centimetres and find a 
> simple way of reflecting objects.

    Use translate and scale together...


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


Re: Using viewBox for unit conversion

Posted by James Shaw <he...@btopenworld.com>.
Patrick Egan wrote:
> Hi James,
> My understanding is the viewBox attribute defines a mapping between user 
> space co-ordinates and the co-ordinates of the svg viewport, and in your 
> case you are effectively scaling the image down by a factor of 10 ( 200 
> user units=20cm and 100 user units = 10 cm).
That's what I would expect, but it doesn't seem to be the case for me -- 
the document appears much smaller than I would expect.
> 
> Depending on how complex your object is you might try to use translate 
> and scale tranforms.
> <svg width="20cm" height="10cm" viewBox="0 0 20 10" 
> style="fill:red;stroke:blue">
>  <g transform="translate(0,10) scale(1,-1)">
>   <line x1="0" y1="0" x2="20" y2="10" style="stroke: blue; stroke-width: 
> 1"  />
>  </g>
> </svg>
> 
> Patrick
> 
Thanks for this suggestion.  I did try to use scale(1,-1) but it caused 
the object to disappear entirely (am I doing something really stupid 
here?)  Also, since switching from hardcoded cms to userspace coords, 
I've noticed discrepancies in line widths between the SVG viewed in a 
JSVGCanvas and via FOP (using the PDFTranscoder).  To avoid these 
problems, I would really like to stick with centimetres and find a 
simple way of reflecting objects.

Thanks
James Shaw

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


Re: Using viewBox for unit conversion

Posted by Patrick Egan <pe...@gresham-forms.co.uk>.
Hi James,
My understanding is the viewBox attribute defines a mapping between user 
space co-ordinates and the co-ordinates of the svg viewport, and in your 
case you are effectively scaling the image down by a factor of 10 ( 200 
user units=20cm and 100 user units = 10 cm).

Depending on how complex your object is you might try to use translate 
and scale tranforms.
<svg width="20cm" height="10cm" viewBox="0 0 20 10" 
style="fill:red;stroke:blue">
  <g transform="translate(0,10) scale(1,-1)">
   <line x1="0" y1="0" x2="20" y2="10" style="stroke: blue; 
stroke-width: 1"  />
  </g>
</svg>

Patrick

James Shaw wrote:

> I have been looking for a way to reflect an object about its y axis; I 
> understand that I need a transform matrix to do this, and that you 
> cannot translate by cms, ins or other units.  The ppl on #svg 
> recommended using a viewbox.
>
> I've checked on #svg, and I understand that a document like this:
>
> <svg width="20cm" height="10cm" viewBox="0 0 200 100">
>    <line x1="0" y1="0" x2="20" y2="10" style="stroke: blue; 
> stroke-width: 1"/>
> </svg>
>
> should produce a drawing 20x10cms.  However, when I preview this in 
> squiggle or a JSVGScrollPane, the drawing is about 80x40 pixels.  I 
> would have expected batik to use the screen dpi (or similar 
> measurement) to correct render the document at 100% zoom.
>
> Am I using viewBox incorrectly, or am I using Batik wrongly?
>
> Thanks in advance
> James Shaw
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>


Important - This e-mail and the information that it contains may be
confidential, legally privileged and protected by law.  Access by the
intended recipient only is authorised.  Any liability (in negligence or
otherwise) arising from any third party acting, or refraining from acting,
on any information contained in this e-mail is hereby excluded.  If you are
not the intended recipient, please notify the sender immediately and do not
disclose the contents to any other person, use it for any purpose, or store
or copy the information in any medium.  Copyright in this e-mail and
attachments created by us belongs to the author and
also asserts the right to be identified as such and object to any misuse.

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