Class DefaultCachedImageHandler

java.lang.Object
org.apache.batik.svggen.DefaultCachedImageHandler
All Implemented Interfaces:
XMLConstants, CachedImageHandler, ErrorConstants, GenericImageHandler, SVGSyntax, CSSConstants, SVGConstants
Direct Known Subclasses:
CachedImageHandlerBase64Encoder, CachedImageHandlerJPEGEncoder, CachedImageHandlerPNGEncoder

public abstract class DefaultCachedImageHandler extends Object implements CachedImageHandler, SVGSyntax, ErrorConstants
This class is a default implementation of the GenericImageHandler for handlers implementing a caching strategy.
See Also:
  • Field Details

  • Constructor Details

    • DefaultCachedImageHandler

      public DefaultCachedImageHandler()
  • Method Details

    • getImageCacher

      public ImageCacher getImageCacher()
      The image cache can be used by subclasses for efficient image storage
      Specified by:
      getImageCacher in interface CachedImageHandler
      Returns:
      the image cache
    • setDOMTreeManager

      public void setDOMTreeManager(DOMTreeManager domTreeManager)
      This GenericImageHandler implementation does not need to interact with the DOMTreeManager.
      Specified by:
      setDOMTreeManager in interface GenericImageHandler
    • createElement

      public Element createElement(SVGGeneratorContext generatorContext)
      Creates an Element which can refer to an image. Note that no assumptions should be made by the caller about the corresponding SVG tag. By default, an <image> tag is used, but the CachedImageHandlerBase64Encoder, for example, overrides this method to use a different tag.
      Specified by:
      createElement in interface GenericImageHandler
    • handleImage

      public AffineTransform handleImage(Image image, Element imageElement, int x, int y, int width, int height, SVGGeneratorContext generatorContext)
      The handler sets the xlink:href tag and returns a transform
      Specified by:
      handleImage in interface GenericImageHandler
      Parameters:
      image - the image under consideration
      imageElement - the DOM Element for this image
      x - x coordinate
      y - y coordinate
      width - width for rendering
      height - height for rendering
      generatorContext - the SVGGeneratorContext
      Returns:
      transform converting the image dimension to rendered dimension
    • handleImage

      public AffineTransform handleImage(RenderedImage image, Element imageElement, int x, int y, int width, int height, SVGGeneratorContext generatorContext)
      The handler sets the xlink:href tag and returns a transform
      Specified by:
      handleImage in interface GenericImageHandler
      Parameters:
      image - the image under consideration
      imageElement - the DOM Element for this image
      x - x coordinate
      y - y coordinate
      width - width for rendering
      height - height for rendering
      generatorContext - the SVGGeneratorContext
      Returns:
      transform converting the image dimension to rendered dimension
    • handleImage

      public AffineTransform handleImage(RenderableImage image, Element imageElement, double x, double y, double width, double height, SVGGeneratorContext generatorContext)
      The handler sets the xlink:href tag and returns a transform
      Specified by:
      handleImage in interface GenericImageHandler
      Parameters:
      image - the image under consideration
      imageElement - the DOM Element for this image
      x - x coordinate
      y - y coordinate
      width - width for rendering
      height - height for rendering
      generatorContext - the SVGGeneratorContext
      Returns:
      transform converting the image dimension to rendered dimension
    • handleTransform

      protected AffineTransform handleTransform(Element imageElement, double x, double y, double srcWidth, double srcHeight, double dstWidth, double dstHeight, SVGGeneratorContext generatorContext)
      Determines the transformation needed to get the cached image to scale & position properly. Sets x and y attributes on the element accordingly.
    • handleEmptyImage

      protected void handleEmptyImage(Element imageElement)
    • handleHREF

      public void handleHREF(Image image, Element imageElement, SVGGeneratorContext generatorContext) throws SVGGraphics2DIOException
      The handler should set the xlink:href tag and the width and height attributes.
      Throws:
      SVGGraphics2DIOException
    • buildBufferedImage

      public BufferedImage buildBufferedImage(Dimension size)
      This method creates a BufferedImage of the right size and type for the derived class.
    • handleHREF

      protected void handleHREF(RenderedImage image, Element imageElement, SVGGeneratorContext generatorContext) throws SVGGraphics2DIOException
      This template method should set the xlink:href attribute on the input Element parameter
      Throws:
      SVGGraphics2DIOException
    • handleHREF

      protected void handleHREF(RenderableImage image, Element imageElement, SVGGeneratorContext generatorContext) throws SVGGraphics2DIOException
      This method will delegate to the handleHREF which uses a RenderedImage
      Throws:
      SVGGraphics2DIOException
    • cacheBufferedImage

      protected void cacheBufferedImage(Element imageElement, BufferedImage buf, SVGGeneratorContext generatorContext) throws SVGGraphics2DIOException
      Throws:
      SVGGraphics2DIOException
    • getRefPrefix

      public abstract String getRefPrefix()
      Should return the prefix with wich the image reference should be pre-concatenated.
    • encodeImage

      public abstract void encodeImage(BufferedImage buf, OutputStream os) throws IOException
      Derived classes should implement this method and encode the input BufferedImage as needed
      Throws:
      IOException
    • getBufferedImageType

      public abstract int getBufferedImageType()
      This template method should be overridden by derived classes to declare the image type they need for saving to file.