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 Uwe Köster <uw...@gmx.de> on 2003/08/29 10:20:42 UTC

Problem with reading svg files generated by SVGGraphics2D

Hello!
 
 
Things I did:
- create swing component which paints into SVGGraphics2D
- write the generated document to disk using the stream method of
SVGGraphics2D works fine. 
The generated file is readable by Squiggle GUI and transformable into
JPEG using Squiggle GUI too.
 
But i need to be independent from Squiggle GUI and try to use an
implementation similar to the one used by batik-rasterizer command line
interface.
Trying to use batik-rasterizer to transform my svg (generated with
SVGGraphics2D) into JPEG file fails with:
... org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
Width (0) and height (0) cannot be <= 0
        at
org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown
Source)
        at
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown
Source)
        at
org.apache.batik.apps.rasterizer.SVGConverter.transcode(Unknown Source)
        at org.apache.batik.apps.rasterizer.SVGConverter.execute(Unknown
Source)
        at org.apache.batik.apps.rasterizer.Main.execute(Unknown Source)
        at org.apache.batik.apps.rasterizer.Main.main(Unknown Source)
... error (SVGConverter.error.while.rasterizing.file)
 
I get the same error in my own code which should write a JPEG too. 
Trying to work around this by setting the missing values fails with
ClassCastException.
Code snippet:
            HashMap map = new HashMap();
            map.put(JPEGTranscoder.KEY_QUALITY, new Float(0.99));
            map.put(ImageTranscoder.KEY_BACKGROUND_COLOR,
backgroundColor);
            map.put(ImageTranscoder.KEY_HEIGHT, new Float(200));
            map.put(ImageTranscoder.KEY_WIDTH, new Float(200));
            svgGraphics2D.setRenderingHints(map);
 
Trying to use the method setRenderingHint inherited from
AbstractGraphics2D
public void setRenderingHint(RenderingHints.Key hintKey, Object
hintValue)
does not give me a hint which Keys i should use to prevent failing while
rasterizing.
 
How can i proceed to be able to read once written svg files without the
use of Squiggle GUI?
 
Thank you in advance!
 
Regards
Uwe
 
Attached a svg i generated with SVGGraphics2D 

Re: Problem with reading svg files generated by SVGGraphics2D

Posted by Thomas DeWeese <Th...@Kodak.com>.
Uwe Köster wrote:
> Hello!
>  
>  
> Things I did:
> - create swing component which paints into SVGGraphics2D
> - write the generated document to disk using the stream method of
> SVGGraphics2D works fine. 
> The generated file is readable by Squiggle GUI and transformable into
> JPEG using Squiggle GUI too.
>  
> But i need to be independent from Squiggle GUI and try to use an
> implementation similar to the one used by batik-rasterizer command line
> interface.
> Trying to use batik-rasterizer to transform my svg (generated with
> SVGGraphics2D) into JPEG file fails with:
> ... org.apache.batik.transcoder.TranscoderException: null
> Enclosed Exception:
> Width (0) and height (0) cannot be <= 0

   This is a bug, but really a fairly minor one since you almost always
want to provide the w/h of the SVG (especially when generating a raster)
otherwise it arbitrarily picks 400x400.  See below for better ways to
fix this.

> I get the same error in my own code which should write a JPEG too. 
> Trying to work around this by setting the missing values fails wit
> ClassCastException.

   I think you want to provide these hints to the PNGTranscoder not
to the SVGGraphics2D.  You can tell the svgGraphics2D what to set
for width/height on the svg element it generates with:

setSVGCanvasSize(Dimension svgCanvasSize)

    This is really what you want to do.

    Good luck!

> Code snippet:
>             HashMap map = new HashMap();
>             map.put(JPEGTranscoder.KEY_QUALITY, new Float(0.99));
>             map.put(ImageTranscoder.KEY_BACKGROUND_COLOR,
> backgroundColor);
>             map.put(ImageTranscoder.KEY_HEIGHT, new Float(200));
>             map.put(ImageTranscoder.KEY_WIDTH, new Float(200));
>             svgGraphics2D.setRenderingHints(map);
>  
> Trying to use the method setRenderingHint inherited from
> AbstractGraphics2D
> public void setRenderingHint(RenderingHints.Key hintKey, Object
> hintValue)
> does not give me a hint which Keys i should use to prevent failing while
> rasterizing.
>  
> How can i proceed to be able to read once written svg files without the
> use of Squiggle GUI?
>  
> Thank you in advance!
>  
> Regards
> Uwe
>  
> Attached a svg i generated with SVGGraphics2D 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org




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