Package com.itextpdf.svg.renderers.impl
Class PathSvgNodeRenderer
- java.lang.Object
-
- com.itextpdf.svg.renderers.impl.AbstractSvgNodeRenderer
-
- com.itextpdf.svg.renderers.impl.PathSvgNodeRenderer
-
- All Implemented Interfaces:
IMarkerCapable
,ISvgNodeRenderer
public class PathSvgNodeRenderer extends AbstractSvgNodeRenderer implements IMarkerCapable
ISvgNodeRenderer
implementation for the <path> tag.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
INVALID_OPERATOR_REGEX
The regular expression to find invalid operators in the PathData attribute of the <path> elementprivate static java.util.regex.Pattern
INVALID_REGEX_PATTERN
private static java.lang.String
SPACE_CHAR
private static java.util.regex.Pattern
SPLIT_PATTERN
The regular expression to split the PathData attribute of the <path> elementprivate ClosePath
zOperator
-
Fields inherited from class com.itextpdf.svg.renderers.impl.AbstractSvgNodeRenderer
attributesAndStyles, doFill, doStroke, partOfClipPath
-
-
Constructor Summary
Constructors Constructor Description PathSvgNodeRenderer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.List<IPathShape>
addMoveToShapes(IPathShape pathShape, java.lang.String[] pathProperties, IPathShape beforeMoveShape)
private static java.lang.String[]
concatenate(java.lang.String[] first, java.lang.String[] second)
(package private) boolean
containsInvalidAttributes(java.lang.String attributes)
ISvgNodeRenderer
createDeepCopy()
Creates a deep copy of this renderer, including it's subtree of childrenvoid
doDraw(SvgDrawContext context)
Draws this element to a canvas-like object maintained in the context.void
drawMarker(SvgDrawContext context, MarkerVertexType markerVertexType)
Draws a marker in the specified context.private static boolean
endsWithNonWhitespace(java.lang.StringBuilder sb)
double
getAutoOrientAngle(MarkerSvgNodeRenderer marker, boolean reverse)
Calculates marker orientation angle iforient
attribute is set toauto
private static Point
getCurrentPoint(IPathShape previousShape)
Rectangle
getObjectBoundingBox(SvgDrawContext context)
Calculates the current object bounding box.private java.lang.String[]
getShapeCoordinates(IPathShape shape, IPathShape previousShape, java.lang.String[] pathProperties)
Gets the coordinates that shall be passed toIPathShape.setCoordinates(java.lang.String[], com.itextpdf.kernel.geom.Point)
for the current shape.(package private) java.util.Collection<IPathShape>
getShapes()
Processes theSvgConstants.Attributes.D
AbstractSvgNodeRenderer.attributesAndStyles
and converts them into one or moreIPathShape
objects to be drawn on the canvas.(package private) java.util.Collection<java.lang.String>
parsePathOperations()
private java.util.List<IPathShape>
processPathOperator(java.lang.String[] pathProperties, IPathShape previousShape)
Processes an individual pathing operator and all of its arguments, converting into one or moreIPathShape
objects.(package private) java.lang.String
separateDecimalPoints(java.lang.String input)
Iterate over the input string and separate numbers from each other with space chars(package private) static java.lang.String[]
splitPathStringIntoOperators(java.lang.String path)
Gets an array of strings representing operators with their arguments, e.g.-
Methods inherited from class com.itextpdf.svg.renderers.impl.AbstractSvgNodeRenderer
calculateViewPortTranslation, canConstructViewPort, canElementFill, deepCopyAttributesAndStyles, draw, getAttribute, getAttributeMapCopy, getAttributeOrDefault, getCurrentFontSize, getParent, parseAbsoluteLength, postDraw, preDraw, setAttribute, setAttributesAndStyles, setParent, setPartOfClipPath
-
-
-
-
Field Detail
-
SPACE_CHAR
private static final java.lang.String SPACE_CHAR
- See Also:
- Constant Field Values
-
INVALID_OPERATOR_REGEX
private static final java.lang.String INVALID_OPERATOR_REGEX
The regular expression to find invalid operators in the PathData attribute of the <path> elementFind any occurrence of a letter that is not an operator
- See Also:
- Constant Field Values
-
INVALID_REGEX_PATTERN
private static final java.util.regex.Pattern INVALID_REGEX_PATTERN
-
SPLIT_PATTERN
private static final java.util.regex.Pattern SPLIT_PATTERN
The regular expression to split the PathData attribute of the <path> elementSince
containsInvalidAttributes(String)
is called before the use of this expression inparsePathOperations()
the attribute to be split is valid.SVG defines 6 types of path commands, for a total of 20 commands:
MoveTo: M, m LineTo: L, l, H, h, V, v Cubic Bezier Curve: C, c, S, s Quadratic Bezier Curve: Q, q, T, t Elliptical Arc Curve: A, a ClosePath: Z, z
-
zOperator
private ClosePath zOperator
-
-
Method Detail
-
doDraw
public void doDraw(SvgDrawContext context)
Description copied from class:AbstractSvgNodeRenderer
Draws this element to a canvas-like object maintained in the context.- Specified by:
doDraw
in classAbstractSvgNodeRenderer
- Parameters:
context
- the object that knows the place to draw this element and maintains its state
-
createDeepCopy
public ISvgNodeRenderer createDeepCopy()
Description copied from interface:ISvgNodeRenderer
Creates a deep copy of this renderer, including it's subtree of children- Specified by:
createDeepCopy
in interfaceISvgNodeRenderer
- Returns:
- deep copy of this renderer
-
getObjectBoundingBox
public Rectangle getObjectBoundingBox(SvgDrawContext context)
Description copied from interface:ISvgNodeRenderer
Calculates the current object bounding box.- Specified by:
getObjectBoundingBox
in interfaceISvgNodeRenderer
- Parameters:
context
- the current context, for instance it contains current viewport and available font data- Returns:
- the
Rectangle
representing the current object's bounding box, or null if bounding box is undefined
-
getShapeCoordinates
private java.lang.String[] getShapeCoordinates(IPathShape shape, IPathShape previousShape, java.lang.String[] pathProperties)
Gets the coordinates that shall be passed toIPathShape.setCoordinates(java.lang.String[], com.itextpdf.kernel.geom.Point)
for the current shape.- Parameters:
shape
- The current shape.previousShape
- The previous shape which can affect the coordinates of the current shape.pathProperties
- The operator and all arguments as an array ofString
s- Returns:
- a
String
array of coordinates that shall be passed toIPathShape.setCoordinates(java.lang.String[], com.itextpdf.kernel.geom.Point)
-
processPathOperator
private java.util.List<IPathShape> processPathOperator(java.lang.String[] pathProperties, IPathShape previousShape)
Processes an individual pathing operator and all of its arguments, converting into one or moreIPathShape
objects.- Parameters:
pathProperties
- The property operator and all arguments as an array ofString
spreviousShape
- The previous shape which can affect the positioning of the current shape. If no previous shape existsnull
is passed.- Returns:
- a
List
of eachIPathShape
that should be drawn to represent the operator.
-
addMoveToShapes
private java.util.List<IPathShape> addMoveToShapes(IPathShape pathShape, java.lang.String[] pathProperties, IPathShape beforeMoveShape)
-
getShapes
java.util.Collection<IPathShape> getShapes()
Processes theSvgConstants.Attributes.D
AbstractSvgNodeRenderer.attributesAndStyles
and converts them into one or moreIPathShape
objects to be drawn on the canvas.Each individual operator is passed to
processPathOperator(String[], IPathShape)
to be processed individually.- Returns:
- a
Collection
of eachIPathShape
that should be drawn to represent the path.
-
concatenate
private static java.lang.String[] concatenate(java.lang.String[] first, java.lang.String[] second)
-
containsInvalidAttributes
boolean containsInvalidAttributes(java.lang.String attributes)
-
parsePathOperations
java.util.Collection<java.lang.String> parsePathOperations()
-
separateDecimalPoints
java.lang.String separateDecimalPoints(java.lang.String input)
Iterate over the input string and separate numbers from each other with space chars
-
splitPathStringIntoOperators
static java.lang.String[] splitPathStringIntoOperators(java.lang.String path)
Gets an array of strings representing operators with their arguments, e.g. {"M 100 100", "L 300 100", "L200, 300", "z"}
-
endsWithNonWhitespace
private static boolean endsWithNonWhitespace(java.lang.StringBuilder sb)
-
drawMarker
public void drawMarker(SvgDrawContext context, MarkerVertexType markerVertexType)
Description copied from interface:IMarkerCapable
Draws a marker in the specified context. The marker is drawn on the vertices defined according to the given marker type.- Specified by:
drawMarker
in interfaceIMarkerCapable
- Parameters:
context
- the object that knows the place to draw this element and maintains its statemarkerVertexType
- type of marker that determine on which vertices of the given element marker should be drawn
-
getAutoOrientAngle
public double getAutoOrientAngle(MarkerSvgNodeRenderer marker, boolean reverse)
Description copied from interface:IMarkerCapable
Calculates marker orientation angle iforient
attribute is set toauto
- Specified by:
getAutoOrientAngle
in interfaceIMarkerCapable
- Parameters:
marker
- marker for which the rotation angle should be calculatedreverse
- indicates that the resulting angle should be rotated 180 degrees- Returns:
- marker orientation angle so that its positive x-axis is pointing in the direction of the path at the point it is placed
-
getCurrentPoint
private static Point getCurrentPoint(IPathShape previousShape)
-
-