Package ome.services

Class SVGRasterizer


  • public class SVGRasterizer
    extends java.lang.Object
    This class provides a simple and method based API for converting a SVG document fragment to a BufferedImage.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  SVGRasterizer.Rasterizer
      An image transcoder that stores the resulting image.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.batik.transcoder.TranscodingHints hints
      The transcoder hints.
      protected java.awt.image.BufferedImage img
      The image that represents the SVG document.
      protected org.apache.batik.transcoder.TranscoderInput input
      The transcoder input.
    • Constructor Summary

      Constructors 
      Constructor Description
      SVGRasterizer​(java.io.InputStream istream)
      Constructs a new SVGRasterizer converter.
      SVGRasterizer​(java.io.Reader reader)
      Constructs a new SVGRasterizer converter.
      SVGRasterizer​(java.lang.String uri)
      Constructs a new SVGRasterizer.
      SVGRasterizer​(java.net.URL url)
      Constructs a new SVGRasterizer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.image.BufferedImage createBufferedImage()
      Returns the image that represents the SVG document.
      void createJPEG​(java.io.OutputStream outputStream)
      Returns the image that represents the SVG document as a JPEG.
      void setAlternateStylesheet​(java.lang.String alternateStylesheet)
      Sets the alternate stylesheet to use.
      void setBackgroundColor​(java.awt.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​(java.lang.String language)
      Sets the preferred language to use.
      void setMedia​(java.lang.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​(java.lang.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 java.awt.image.BufferedImage img
        The image that represents the SVG document.
    • Constructor Detail

      • SVGRasterizer

        public SVGRasterizer​(java.lang.String uri)
        Constructs a new SVGRasterizer.
        Parameters:
        uri - the uri of the document to rasterize
      • SVGRasterizer

        public SVGRasterizer​(java.net.URL url)
        Constructs a new SVGRasterizer.
        Parameters:
        url - the URL of the document to rasterize
      • SVGRasterizer

        public SVGRasterizer​(java.io.InputStream istream)
        Constructs a new SVGRasterizer converter.
        Parameters:
        istream - the input stream that represents the SVG document to rasterize
      • SVGRasterizer

        public SVGRasterizer​(java.io.Reader reader)
        Constructs a new SVGRasterizer converter.
        Parameters:
        reader - the reader that represents the SVG document to rasterize
    • Method Detail

      • createBufferedImage

        public java.awt.image.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​(java.io.OutputStream outputStream)
                        throws org.apache.batik.transcoder.TranscoderException
        Returns the image that represents the SVG document as a JPEG.
        Parameters:
        outputStream - The stream to use.
        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:
        height - the image height
      • setLanguages

        public void setLanguages​(java.lang.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 conversion factor.
      • setUserStyleSheetURI

        public void setUserStyleSheetURI​(java.lang.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 further 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​(java.lang.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​(java.lang.String alternateStylesheet)
        Sets the alternate stylesheet to use. For further 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​(java.awt.Paint p)
        Sets the Paint to use for the background of the image.
        Parameters:
        p - the paint to use for the background