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 th...@kodak.com on 2007/01/01 02:22:03 UTC

Re: auto adust canvas size

Hi Sean,

Sean Wheller <se...@inwords.co.za> wrote on 12/30/2006 09:03:13 AM:

> I am using batik to generate PNG from SVG created using Inkscape.

> The PNG files are output but they contain the whole canvas size as 
defined in 
> the SVG source by Inkscape.

> width="595.27557pt"
> height="841.88977pt"

   As the SVG specification says they should.  The Width/Height say
what size canvas the document should be drawn into.

> This results in the actual picture that is drawn on the canvas being 
> surrounded by a large whitespace. Obviously when such images are 
included in 
> a web page or PDF the result is not desired.

   Actually the surround should be transparent, although it is still
wasteful.

> How can I tell batik to render only the picture and not the canvas?

   Write code to make Batik non-conformant.  You could also try adding
script to your documents change the width, height and viewBox attributes 
based on the return value of 'getBBox' on the outermost SVG element.

> I cannot guarantee that the picture drawn will always be at the same 
> coordinates on the canvas.

   There is also no good reason that the bounds of the geometry in
the document will describe the desired region to render (it
is quite common for very large rectangles to be put in documents
as backgrounds, however the content of interest may only cover a
small portion of the rect).  In the general case this is something
that only the author of the document can do which is why there is
the viewBox attribute.

Re: auto adust canvas size

Posted by Sean Wheller <se...@inwords.co.za>.
Hey looks like I solved this, though my action was not directed at solving the 
problem.

I am not sure where the problem is now, but I re-installed sodipodi.

Then I opened inkscape and adjusted canvas size. This time I changed the unit 
of measure for the canvas from pt to px.

I ran batik and it finally works. So I reverted the file and checked again. 
Sure enough no problem. So I ran a diff on the local file and the one in SVN 
which was created before I had sodipodi installed and before I change the 
canvas unit measure.

The main difference with impact

    xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
-   width="744.09448819" 
-   height="1052.3622047" 
+   width="475pt" 
+   height="350pt" 
    id="svg2"
    sodipodi:version="0.32"
    inkscape:version="0.43"
    sodipodi:docbase="/home/sean/work/ericsson/docs/trunk/rfp/celtel/images"
-   sodipodi:docname="hxc-block.svg"> 
+   sodipodi:docname="hxc-block.svg" 
+   version="1.0"> 

Somehow either after actually setting the unit measure for the canvas, not 
just accepting the default or the fact that I installed sodipodi changed the 
behaviour of Inkscape.

I am sure of one thing prior to installing sodipodi, Inkscape was not adding 
the @version to the svg element. Not sure about the unit thing. It could be 
that the added pt in width and height is from me or because of sodipodi. 
Either way the file created without sodipodi installed did not have an unit 
of measure after the floating point.

I will pass this along to the Inkscape team.

-- 
Sean Wheller
Technical Author
email: sean@inwords.co.za
im: seanwhe@jabber.org
skype: seanwhe
cel: +27-84-854-9408
web: http://www.inwords.co.za

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


Re: auto adust canvas size

Posted by Sean Wheller <se...@inwords.co.za>.
On Wednesday 03 January 2007 12:59, thomas.deweese@kodak.com wrote:
> > > Sean Wheller <se...@inwords.co.za> wrote on 01/02/2007 06:52:56 AM:
>  > >  > It seems that setting the canvas size smaller is not the solution.
>  > >  > Batik still renders an image with a huge amount of wasted space.
> >
> > On Tuesday 02 January 2007 14:49, thomas.deweese@kodak.com wrote:
>  > > What you probably want to have is a viewBox as well as a width
>  > > and height.   Something like:
>  > > <svg
>  > >     width="452.64005pt"
>  > >     height="320.53pt"
>  > >     viewBox="0 0 452.64 320.53"
>  > >     [... the rest of the attrs ...]
>
> Sean Wheller <se...@inwords.co.za> wrote on 01/02/2007 08:20:40 AM:
>  > I am aware of the view box option and it does work when passed at the
>  > command line. [...]
>  >
>  > Surely, there must be a way of doing this in an automated fashion. The
>  > whole documentation system is docbook, built using ant so I guess it can
>  > be done.
>  >
>  > How can I use the getBBox you mentioned in earlier post?
>
>    Well if you can add an 'onload' event handler to the root SVG element
> (might be possible in docbook using a stylsheet) it is pretty simple
> (note that this is using Java from Javascript to print the result):
>
>         onload="System.err.println('BBox: ' +
> document.getRootElement().getBBox())"

I see. Tried this on one file, but then I face the issue of having to add this 
to all SVG files as they hit SVN or the nightly build will not work and I 
don't think the engineers will remember to add it. So I must find a solution 
that purely requires an SVG file as created by Inkscape.

>
>    Getting it in Java is roughly the same but you need to do some casting
> in some places.  If you can add the Javascript onload event attribute then
> the onload script can add the viewBox attribute at that point and it will
> be respected during transcoding.
>
>    To do it in Java however you will probably need to modify the
> SVGAbstractTranscoder (the preserveAspectRatio transform calculation
> starts at around line 240).
>
>    I might look into adding an 'auto-aoi' command line option.

Will take a look.

I am also looking into extracting the required values and passing them to ant 
properties using xpath and Andariel Ant Tasks [http://andariel.uworks.net/]. 
If this solution works, then I should be able to create a foreach loop with 
ant-contrib, get values of SVG element attributes, pass them back as Andariel 
properties to populate the java command arguments.

-- 
Sean Wheller
Technical Author
email: sean@inwords.co.za
im: seanwhe@jabber.org
skype: seanwhe
cel: +27-84-854-9408
web: http://www.inwords.co.za

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


Re: auto adust canvas size

Posted by th...@kodak.com.
Hi Sean,

> > Sean Wheller <se...@inwords.co.za> wrote on 01/02/2007 06:52:56 AM:
> >  > It seems that setting the canvas size smaller is not the solution.
> >  > Batik still renders an image with a huge amount of wasted space.

> On Tuesday 02 January 2007 14:49, thomas.deweese@kodak.com wrote:
> > What you probably want to have is a viewBox as well as a width
> > and height.   Something like:
> > <svg
> >     width="452.64005pt"
> >     height="320.53pt"
> >     viewBox="0 0 452.64 320.53"
> >     [... the rest of the attrs ...]

Sean Wheller <se...@inwords.co.za> wrote on 01/02/2007 08:20:40 AM:

> I am aware of the view box option and it does work when passed at the 
command 
> line. [...]

> Surely, there must be a way of doing this in an automated fashion. The 
whole 
> documentation system is docbook, built using ant so I guess it can be 
done.
> 
> How can I use the getBBox you mentioned in earlier post?

   Well if you can add an 'onload' event handler to the root SVG element
(might be possible in docbook using a stylsheet) it is pretty simple
(note that this is using Java from Javascript to print the result):

        onload="System.err.println('BBox: ' + 
document.getRootElement().getBBox())"

   Getting it in Java is roughly the same but you need to do some casting 
in
some places.  If you can add the Javascript onload event attribute then 
the
onload script can add the viewBox attribute at that point and it will be 
respected during transcoding.

   To do it in Java however you will probably need to modify the
SVGAbstractTranscoder (the preserveAspectRatio transform calculation 
starts at around line 240).

   I might look into adding an 'auto-aoi' command line option.

Re: auto adust canvas size

Posted by Sean Wheller <se...@inwords.co.za>.
On Tuesday 02 January 2007 14:49, thomas.deweese@kodak.com wrote:
> Sean Wheller <se...@inwords.co.za> wrote on 01/02/2007 06:52:56 AM:
>  > On Tuesday 02 January 2007 10:49, Sean Wheller wrote:
>  > > On Monday 01 January 2007 03:22, thomas.deweese@kodak.com wrote:
>  > > > As the SVG specification says they should.  The Width/Height say
>  > > > what size canvas the document should be drawn into.
>  > >
>  > > So perhaps the only thing to do is open each SVG, adjust the canvas to
>  > > the required size. Well ... until I can get some time to automate the
>  > > process.
>  >
>  > It seems that setting the canvas size smaller is not the solution.
>  > Batik still renders an image with a huge amount of wasted space.
>
>    Since you are setting '-dpi 300' this is correct
> (452pt =~ 6.277in * 300dpi =~ 1833 pix).  What you
> probably want to have is a viewBox as well as a width
> and height.   Something like:
> <svg
>     width="452.64005pt"
>     height="320.53pt"
>     viewBox="0 0 452.64 320.53"
>     [... the rest of the attrs ...]
>
>    This should give you a 1.8K pixel picture
> of the 0,0 -> 452x320 rectangle of the canvas
> (Presumably you want the high resolution for print
> or something).

Correct I need 300 dpi for print. 

I am aware of the view box option and it does work when passed at the command 
line. Now while I can revisit each SVG image and try to find the correct 
settings for each particular images view box, this type of thing is not 
practical. Some of our documents have upwards of 300 images in them. In 
addition, I cannot expect engineers using Inkscape to fiddle around with type 
of thing. So I will have to constantly monitor every SVG added by them.

Surely, there must be a way of doing this in an automated fashion. The whole 
documentation system is docbook, built using ant so I guess it can be done.

How can I use the getBBox you mentioned in earlier post?

p.s. Many thanks for your response.

Happy New Year

-- 
Sean Wheller
Technical Author
email: sean@inwords.co.za
im: seanwhe@jabber.org
skype: seanwhe
cel: +27-84-854-9408
web: http://www.inwords.co.za

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


Re: auto adust canvas size

Posted by th...@kodak.com.
Hi Sean,

Sean Wheller <se...@inwords.co.za> wrote on 01/02/2007 06:52:56 AM:

> On Tuesday 02 January 2007 10:49, Sean Wheller wrote:
> > On Monday 01 January 2007 03:22, thomas.deweese@kodak.com wrote:
> > > As the SVG specification says they should.  The Width/Height say
> > > what size canvas the document should be drawn into.
> >
> > So perhaps the only thing to do is open each SVG, adjust the canvas to 
the
> > required size. Well ... until I can get some time to automate the 
process.
> 
> It seems that setting the canvas size smaller is not the solution. 
> Batik still renders an image with a huge amount of wasted space.

   Since you are setting '-dpi 300' this is correct
(452pt =~ 6.277in * 300dpi =~ 1833 pix).  What you
probably want to have is a viewBox as well as a width
and height.   Something like:
<svg
    width="452.64005pt"
    height="320.53pt"
    viewBox="0 0 452.64 320.53"
    [... the rest of the attrs ...]

   This should give you a 1.8K pixel picture
of the 0,0 -> 452x320 rectangle of the canvas
(Presumably you want the high resolution for print
or something).


> So while the SVG is set
> <svg
>    xmlns:dc="http://purl.org/dc/elements/1.1/"
>    xmlns:cc="http://web.resource.org/cc/"
>    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>    xmlns:svg="http://www.w3.org/2000/svg"
>    xmlns="http://www.w3.org/2000/svg"
>    xmlns:xlink="http://www.w3.org/1999/xlink"
>    xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
>    xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
>    width="452.64005pt"
>    height="320.53pt"
>    id="svg2"
>    sodipodi:version="0.32"
>    inkscape:version="0.43"
>    sodipodi:docbase="/home/sean/work/ericsson/docs/trunk/images"
>    sodipodi:docname="hxc-block.svg"
>    version="1.0">"
> 
> The resulting PNG file is
> 1886x1336 pixel
> -- 
> Sean Wheller
> Technical Author
> email: sean@inwords.co.za
> im: seanwhe@jabber.org
> skype: seanwhe
> cel: +27-84-854-9408
> web: http://www.inwords.co.za
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 

Re: auto adust canvas size

Posted by Sean Wheller <se...@inwords.co.za>.
On Tuesday 02 January 2007 10:49, Sean Wheller wrote:
> On Monday 01 January 2007 03:22, thomas.deweese@kodak.com wrote:
> > As the SVG specification says they should.  The Width/Height say
> > what size canvas the document should be drawn into.
>
> So perhaps the only thing to do is open each SVG, adjust the canvas to the
> required size. Well ... until I can get some time to automate the process.

It seems that setting the canvas size smaller is not the solution. Batik still 
renders an image with a huge amount of wasted space.

So while the SVG is set
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://web.resource.org/cc/"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="452.64005pt"
   height="320.53pt"
   id="svg2"
   sodipodi:version="0.32"
   inkscape:version="0.43"
   sodipodi:docbase="/home/sean/work/ericsson/docs/trunk/images"
   sodipodi:docname="hxc-block.svg"
   version="1.0">"

The resulting PNG file is
1886x1336 pixel
-- 
Sean Wheller
Technical Author
email: sean@inwords.co.za
im: seanwhe@jabber.org
skype: seanwhe
cel: +27-84-854-9408
web: http://www.inwords.co.za

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


Re: auto adust canvas size

Posted by Sean Wheller <se...@inwords.co.za>.
On Monday 01 January 2007 03:22, thomas.deweese@kodak.com wrote:
> As the SVG specification says they should.  The Width/Height say
> what size canvas the document should be drawn into.

So perhaps the only thing to do is open each SVG, adjust the canvas to the 
required size. Well ... until I can get some time to automate the process.

Thanks,

-- 
Sean Wheller
Technical Author
email: sean@inwords.co.za
im: seanwhe@jabber.org
skype: seanwhe
cel: +27-84-854-9408
web: http://www.inwords.co.za

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