Package com.itextpdf.svg.processors.impl
Class DefaultSvgProcessor
- java.lang.Object
-
- com.itextpdf.svg.processors.impl.DefaultSvgProcessor
-
- All Implemented Interfaces:
ISvgProcessor
public class DefaultSvgProcessor extends java.lang.Object implements ISvgProcessor
Default implementation ofISvgProcessor. This implementation traverses theINodetree depth-first, using a stack to recreate a tree ofISvgNodeRendererwith the same structure.
-
-
Field Summary
Fields Modifier and Type Field Description private SvgProcessorContextcontextprivate ICssResolvercssResolverprivate java.util.Map<java.lang.String,ISvgNodeRenderer>namedObjectsprivate ProcessorStateprocessorStateprivate ISvgNodeRendererFactoryrendererFactory
-
Constructor Summary
Constructors Constructor Description DefaultSvgProcessor()Instantiates a DefaultSvgProcessor object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private ISvgNodeRenderercreateResultAndClean()Extract 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, java.lang.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 processorISvgProcessorResultprocess(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 voidvisit(INode node)Recursive visit of the object tree, depth-first, processing the visited node and calling visit on its children.
-
-
-
Field Detail
-
processorState
private ProcessorState processorState
-
cssResolver
private ICssResolver cssResolver
-
rendererFactory
private ISvgNodeRendererFactory rendererFactory
-
namedObjects
private java.util.Map<java.lang.String,ISvgNodeRenderer> namedObjects
-
context
private SvgProcessorContext context
-
-
Method Detail
-
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
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, java.lang.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 withtagName- name of the tag that needs to be fonund- Returns:
- IElementNode
-
-