Class DefaultSvgProcessor
java.lang.Object
com.itextpdf.svg.processors.impl.DefaultSvgProcessor
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprivate SvgProcessorContextprivate ICssResolverprivate Map<String, ISvgNodeRenderer> private ProcessorStateprivate ISvgNodeRendererFactory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate ISvgNodeRendererExtract result from internal processorState and clean up afterwards(package private) voidexecuteDepthFirstTraversal(INode startingNode) Start the depth-first traversal of the INode tree, pushing the results on the stack(package private) IElementNodefindFirstElement(INode node, String tagName) Find the first element in the node-tree that corresponds with the passed tag-name.(package private) voidperformSetup(INode root, ISvgConverterProperties converterProps) Load in configuration, set initial processorState and create/fill-in context of the processorprocess(INode root, ISvgConverterProperties converterProps) Process an SVG, returning the root of a renderer-tree and a list of named objects wrapped in a processor result objectprivate booleanprocessAsText(INode node) Check if this node is a text node that needs to be processed by the parentprivate voidprocessText(ITextNode textNode) Process the text contained in the text-nodeprivate voidRecursive visit of the object tree, depth-first, processing the visited node and calling visit on its children.
-
Field Details
-
processorState
-
cssResolver
-
rendererFactory
-
namedObjects
-
context
-
-
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:ISvgProcessorProcess an SVG, returning the root of a renderer-tree and a list of named objects wrapped in a processor result object- Specified by:
processin interfaceISvgProcessor- Parameters:
root- Root of the INode representation of the SVGconverterProps- 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
Load in configuration, set initial processorState and create/fill-in context of the processor- Parameters:
converterProps- that contains configuration properties and operations
-
executeDepthFirstTraversal
Start the depth-first traversal of the INode tree, pushing the results on the stack- Parameters:
startingNode- node to start on
-
createResultAndClean
Extract result from internal processorState and clean up afterwards- Returns:
- Root renderer of the processed SVG
-
visit
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
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
Process the text contained in the text-node- Parameters:
textNode- node containing text to process
-
findFirstElement
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 withtagName- name of the tag that needs to be fonund- Returns:
- IElementNode
-