org.apache.fop.render

## Class AbstractGenericSVGHandler

- java.lang.Object
- - org.apache.fop.render.AbstractGenericSVGHandler

- All Implemented Interfaces:
    RendererContextConstants, XMLHandler
  Direct Known Subclasses:
    AFPSVGHandler, Java2DSVGHandler, PCLSVGHandler, PDFSVGHandler, PSSVGHandler

      public abstract class AbstractGenericSVGHandler
      extends Object
      implements XMLHandler, RendererContextConstants

  Generic XML handler for SVG. Uses Apache Batik for SVG processing and simply paints to a Graphics2DAdapter and thus ultimatively to Graphics2D interface that is presented.

  To use this class, subclass it and implement the missing methods (supportsRenderer, for example).

- - ### Field Summary

    - ### Fields inherited from interface org.apache.fop.render.XMLHandler

      `HANDLE_ALL`

    - ### Fields inherited from interface org.apache.fop.render.RendererContextConstants

      `FOREIGN_ATTRIBUTES, HANDLER_CONFIGURATION, HEIGHT, OUTPUT_STREAM, PAGE_VIEWPORT, WIDTH, XPOS, YPOS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractGenericSVGHandler()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected org.apache.batik.gvt.GraphicsNode` | `buildGraphicsNode(FOUserAgent userAgent, org.apache.batik.bridge.BridgeContext ctx, Document doc)` Builds the GVT root.
    `protected org.apache.xmlgraphics.java2d.Graphics2DImagePainter` | `createGraphics2DImagePainter(org.apache.batik.gvt.GraphicsNode root, org.apache.batik.bridge.BridgeContext ctx, Dimension imageSize)` Creates a graphics 2D image painter implementation
    `protected String` | `getDocumentURI(Document doc)` Gets the document URI from a Document instance if possible.
    `protected Dimension` | `getImageSize(RendererContext.RendererContextWrapper wrappedContext)` Returns the image size
    `String` | `getNamespace()`
    `void` | `handleXML(RendererContext context, Document doc, String ns)` Handle an external xml document inside a Foreign Object Area.
    `protected void` | `renderSVGDocument(RendererContext rendererContext, Document doc)` Render the SVG document.
    `protected void` | `updateRendererContext(RendererContext context)` Override this method to update the renderer context if it needs special settings for certain conditions.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.fop.render.XMLHandler

      `supportsRenderer`

- - ### Constructor Detail

    - #### AbstractGenericSVGHandler

          public AbstractGenericSVGHandler()

  - ### Method Detail

    - #### handleXML

          public void handleXML(RendererContext context,
                                Document doc,
                                String ns)
                         throws Exception

      Handle an external xml document inside a Foreign Object Area.

      This may throw an exception if for some reason it cannot be handled. The caller is expected to deal with this exception.

      The implementation may convert the XML document internally to another XML dialect (SVG, for example) and call renderXML() on the AbstractRenderer again (which can be retrieved through the RendererContext).

      Specified by:
        `handleXML` in interface `XMLHandler`
      Parameters:
        `context` - The RendererContext (contains the user agent)
        `doc` - A DOM containing the foreign object to be processed
        `ns` - The Namespace of the foreign object
      Throws:
        `Exception` - If an error occurs during processing.

    - #### createGraphics2DImagePainter

          protected org.apache.xmlgraphics.java2d.Graphics2DImagePainter createGraphics2DImagePainter(org.apache.batik.gvt.GraphicsNode root,
                                                                                                      org.apache.batik.bridge.BridgeContext ctx,
                                                                                                      Dimension imageSize)

      Creates a graphics 2D image painter implementation
      Parameters:
        `root` - the batik graphics node root
        `ctx` - the batik bridge context
        `imageSize` - the image size
      Returns:
        a new graphics 2D image painter implementation

    - #### buildGraphicsNode

          protected org.apache.batik.gvt.GraphicsNode buildGraphicsNode(FOUserAgent userAgent,
                                                                        org.apache.batik.bridge.BridgeContext ctx,
                                                                        Document doc)

      Builds the GVT root.
      Parameters:
        `userAgent` - the user agent
        `ctx` - the batik bridge context
        `doc` - the document
      Returns:
        a built GVT root tree

    - #### getImageSize

          protected Dimension getImageSize(RendererContext.RendererContextWrapper wrappedContext)

      Returns the image size
      Parameters:
        `wrappedContext` - renderer context wrapper
      Returns:
        the image size

    - #### renderSVGDocument

          protected void renderSVGDocument(RendererContext rendererContext,
                                           Document doc)
                                    throws IOException

      Render the SVG document.
      Parameters:
        `rendererContext` - the renderer context
        `doc` - the SVG document
      Throws:
        `IOException` - In case of an I/O error while painting the image

    - #### getDocumentURI

          protected String getDocumentURI(Document doc)

      Gets the document URI from a Document instance if possible.
      Parameters:
        `doc` - the Document
      Returns:
        the URI or null

    - #### updateRendererContext

          protected void updateRendererContext(RendererContext context)

      Override this method to update the renderer context if it needs special settings for certain conditions.
      Parameters:
        `context` - the renderer context

    - #### getNamespace

          public String getNamespace()

      Specified by:
        `getNamespace` in interface `XMLHandler`
      Returns:
        the XML namespace for the XML dialect this XMLHandler supports, null if all XML content is handled by this instance.

Copyright © 2023 Apache Software Foundation. All rights reserved.