Class DefaultSvgProcessor

java.lang.Object
com.itextpdf.svg.processors.impl.DefaultSvgProcessor
All Implemented Interfaces:
ISvgProcessor

public class DefaultSvgProcessor extends Object implements ISvgProcessor
Default implementation of ISvgProcessor. This implementation traverses the INode tree depth-first, using a stack to recreate a tree of ISvgNodeRenderer with the same structure.
  • Field Details

  • Constructor Details

    • DefaultSvgProcessor

      public DefaultSvgProcessor()
      Instantiates a DefaultSvgProcessor object.
  • Method Details

    • process

      public ISvgProcessorResult process(INode root, ISvgConverterProperties converterProps) throws SvgProcessingException
      Description copied from interface: ISvgProcessor
      Process an SVG, returning the root of a renderer-tree and a list of named objects wrapped in a processor result object
      Specified by:
      process in interface ISvgProcessor
      Parameters:
      root - Root of the INode representation of the SVG
      converterProps - configuration properties
      Returns:
      root of the renderer-tree representing the SVG wrapped in {link ISvgProcessorResult}
      Throws:
      SvgProcessingException - throws an exception if the root node is null or if the child node being processed is null
    • performSetup

      void performSetup(INode root, ISvgConverterProperties converterProps)
      Load in configuration, set initial processorState and create/fill-in context of the processor
      Parameters:
      converterProps - that contains configuration properties and operations
    • executeDepthFirstTraversal

      void executeDepthFirstTraversal(INode startingNode)
      Start the depth-first traversal of the INode tree, pushing the results on the stack
      Parameters:
      startingNode - node to start on
    • createResultAndClean

      private ISvgNodeRenderer createResultAndClean()
      Extract result from internal processorState and clean up afterwards
      Returns:
      Root renderer of the processed SVG
    • visit

      private void visit(INode node)
      Recursive visit of the object tree, depth-first, processing the visited node and calling visit on its children. Visit responsibilities for element nodes: - Assign styles(CSS and attributes) to element - Create Renderer based on element - push and pop renderer to stack Visit responsibilities for text nodes - add text to parent object
      Parameters:
      node - INode to visit
    • processAsText

      private boolean processAsText(INode node)
      Check if this node is a text node that needs to be processed by the parent
      Parameters:
      node - node to check
      Returns:
      true if the node should be processed as text, false otherwise
    • processText

      private void processText(ITextNode textNode)
      Process the text contained in the text-node
      Parameters:
      textNode - node containing text to process
    • findFirstElement

      IElementNode findFirstElement(INode node, String tagName)
      Find the first element in the node-tree that corresponds with the passed tag-name. Search is performed depth-first
      Parameters:
      node - root-node to start with
      tagName - name of the tag that needs to be fonund
      Returns:
      IElementNode