Package com.itextpdf.svg.processors.impl
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 SvgProcessorContext
private ICssResolver
private Map
<String, ISvgNodeRenderer> private ProcessorState
private ISvgNodeRendererFactory
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate ISvgNodeRenderer
Extract result from internal processorState and clean up afterwards(package private) void
executeDepthFirstTraversal
(INode startingNode) Start the depth-first traversal of the INode tree, pushing the results on the stack(package private) IElementNode
findFirstElement
(INode node, String tagName) Find the first element in the node-tree that corresponds with the passed tag-name.(package private) void
performSetup
(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 boolean
processAsText
(INode node) Check if this node is a text node that needs to be processed by the parentprivate void
processText
(ITextNode textNode) Process the text contained in the text-nodeprivate void
Recursive 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: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 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
-