ome.services
Class SVGRasterizer

java.lang.Object
  extended by ome.services.SVGRasterizer

public class SVGRasterizer
extends Object

This class provides a simple and method based API for converting a SVG document fragment to a BufferedImage.

Author:
Thierry Kormann, Chris Allan/a> (Modifications for OMERO; adding JPEG support; updating to Batik 1.7)

Nested Class Summary
protected  class SVGRasterizer.Rasterizer
          An image transcoder that stores the resulting image.
 
Field Summary
protected  org.apache.batik.transcoder.TranscodingHints hints
          The transcoder hints.
protected  BufferedImage img
          The image that represents the SVG document.
protected  org.apache.batik.transcoder.TranscoderInput input
          The transcoder input.
 
Constructor Summary
SVGRasterizer(InputStream istream)
          Constructs a new SVGRasterizer converter.
SVGRasterizer(Reader reader)
          Constructs a new SVGRasterizer converter.
SVGRasterizer(String uri)
          Constructs a new SVGRasterizer.
SVGRasterizer(URL url)
          Constructs a new SVGRasterizer.
 
Method Summary
 BufferedImage createBufferedImage()
          Returns the image that represents the SVG document.
 void createJPEG(OutputStream outputStream)
          Returns the image that represents the SVG document as a JPEG.
 void setAlternateStylesheet(String alternateStylesheet)
          Sets the alternate stylesheet to use.
 void setBackgroundColor(Paint p)
          Sets the Paint to use for the background of the image.
 void setImageHeight(float height)
          Sets the height of the image to rasterize.
 void setImageWidth(float width)
          Sets the width of the image to rasterize.
 void setLanguages(String language)
          Sets the preferred language to use.
 void setMedia(String media)
          Sets the media to rasterize.
 void setPixelToMMFactor(float px2mm)
          Sets the unit conversion factor to the specified value.
 void setQuality(float quality)
          Sets the quality of the image to rasterize when rasterizing to a JPEG.
 void setUserStyleSheetURI(String uri)
          Sets the uri of the user stylesheet.
 void setXMLParserValidating(boolean b)
          Sets whether or not the XML parser used to parse SVG document should be validating or not, depending on the specified parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

input

protected org.apache.batik.transcoder.TranscoderInput input
The transcoder input.


hints

protected org.apache.batik.transcoder.TranscodingHints hints
The transcoder hints.


img

protected BufferedImage img
The image that represents the SVG document.

Constructor Detail

SVGRasterizer

public SVGRasterizer(String uri)
Constructs a new SVGRasterizer.

Parameters:
uri - the uri of the document to rasterize

SVGRasterizer

public SVGRasterizer(URL url)
Constructs a new SVGRasterizer.

Parameters:
url - the URL of the document to rasterize

SVGRasterizer

public SVGRasterizer(InputStream istream)
Constructs a new SVGRasterizer converter.

Parameters:
istream - the input stream that represents the SVG document to rasterize

SVGRasterizer

public SVGRasterizer(Reader reader)
Constructs a new SVGRasterizer converter.

Parameters:
reader - the reader that represents the SVG document to rasterize
Method Detail

createBufferedImage

public BufferedImage createBufferedImage()
                                  throws org.apache.batik.transcoder.TranscoderException
Returns the image that represents the SVG document.

Throws:
org.apache.batik.transcoder.TranscoderException

createJPEG

public void createJPEG(OutputStream outputStream)
                throws org.apache.batik.transcoder.TranscoderException
Returns the image that represents the SVG document as a JPEG.

Throws:
org.apache.batik.transcoder.TranscoderException

setQuality

public void setQuality(float quality)
Sets the quality of the image to rasterize when rasterizing to a JPEG.

Parameters:
quality - the percentage quality

setImageWidth

public void setImageWidth(float width)
Sets the width of the image to rasterize.

Parameters:
width - the image width

setImageHeight

public void setImageHeight(float height)
Sets the height of the image to rasterize.

Parameters:
width - the image height

setLanguages

public void setLanguages(String language)
Sets the preferred language to use. SVG documents can provide text in multiple languages, this method lets you control which language to use if possible. e.g. "en" for english or "fr" for french.

Parameters:
language - the preferred language to use

setPixelToMMFactor

public void setPixelToMMFactor(float px2mm)
Sets the unit conversion factor to the specified value. This method lets you choose how units such as 'em' are converted. e.g. 0.26458 is 96dpi (the default) or 0.3528 is 72dpi.

Parameters:
px2mm - the pixel to millimeter convertion factor.

setUserStyleSheetURI

public void setUserStyleSheetURI(String uri)
Sets the uri of the user stylesheet. The user stylesheet can be used to override styles.

Parameters:
uri - the uri of the user stylesheet

setXMLParserValidating

public void setXMLParserValidating(boolean b)
Sets whether or not the XML parser used to parse SVG document should be validating or not, depending on the specified parameter. For futher details about how media work, see the Media types in the CSS2 specification.

Parameters:
b - true means the XML parser will validate its input

setMedia

public void setMedia(String media)
Sets the media to rasterize. The medium should be separated by comma. e.g. "screen", "print" or "screen, print"

Parameters:
media - the media to use

setAlternateStylesheet

public void setAlternateStylesheet(String alternateStylesheet)
Sets the alternate stylesheet to use. For futher details, you can have a look at the Associating Style Sheets with XML documents.

Parameters:
alternateStylesheet - the alternate stylesheet to use if possible

setBackgroundColor

public void setBackgroundColor(Paint p)
Sets the Paint to use for the background of the image.

Parameters:
p - the paint to use for the background


OmeroJava Api

Version: 4.3.3-00d1137e-b2894

Copyright © 2009 The University of Dundee. All Rights Reserved.