Class PathSvgNodeRenderer
java.lang.Object
com.itextpdf.svg.renderers.impl.AbstractSvgNodeRenderer
com.itextpdf.svg.renderers.impl.PathSvgNodeRenderer
- All Implemented Interfaces:
IMarkerCapable, ISvgNodeRenderer
ISvgNodeRenderer implementation for the <path> tag.-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractSvgNodeRenderer
AbstractSvgNodeRenderer.FillProperties, AbstractSvgNodeRenderer.StrokeProperties -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringThe regular expression to find invalid operators in the PathData attribute of the <path> elementprivate static final Patternprivate static final Stringprivate static final PatternThe regular expression to split the PathData attribute of the <path> elementprivate ClosePathFields inherited from class AbstractSvgNodeRenderer
attributesAndStyles, doFill, doStroke -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate List<IPathShape> addMoveToShapes(IPathShape pathShape, String[] pathProperties, IPathShape beforeMoveShape) private static String[]concatenate(String[] first, String[] second) (package private) booleancontainsInvalidAttributes(String attributes) Creates a deep copy of this renderer, including it's subtree of childrenvoiddoDraw(SvgDrawContext context) Draws this element to a canvas-like object maintained in the context.voiddrawMarker(SvgDrawContext context, MarkerVertexType markerVertexType) Draws a marker in the specified context.private static booleandoublegetAutoOrientAngle(MarkerSvgNodeRenderer marker, boolean reverse) Calculates marker orientation angle iforientattribute is set toautoprivate static PointgetCurrentPoint(IPathShape previousShape) getObjectBoundingBox(SvgDrawContext context) Calculates the current object bounding box.private String[]getShapeCoordinates(IPathShape shape, IPathShape previousShape, String[] pathProperties) Gets the coordinates that shall be passed toIPathShape.setCoordinates(String[], Point)for the current shape.(package private) Collection<IPathShape> Processes theSvgConstants.Attributes.DAbstractSvgNodeRenderer.attributesAndStylesand converts them into one or moreIPathShapeobjects to be drawn on the canvas.(package private) Collection<String> private List<IPathShape> processPathOperator(String[] pathProperties, IPathShape previousShape) Processes an individual pathing operator and all of its arguments, converting into one or moreIPathShapeobjects.(package private) StringseparateDecimalPoints(String input) Iterate over the input string and separate numbers from each other with space chars(package private) static String[]Gets an array of strings representing operators with their arguments, e.g.Methods inherited from class AbstractSvgNodeRenderer
applyFillAndStrokeProperties, applyNonScalingStrokeTransform, calculateViewPortTranslation, canConstructViewPort, canElementFill, deepCopyAttributesAndStyles, doStrokeOrFill, draw, getAttribute, getAttributeMapCopy, getAttributeOrDefault, getCurrentFontSize, getCurrentFontSize, getCurrentViewBox, getParent, getParentClipPath, isHidden, parseAbsoluteLength, parseHorizontalLength, parseVerticalLength, postDraw, preDraw, retrieveAlignAndMeet, setAttribute, setAttributesAndStyles, setParent
-
Field Details
-
SPACE_CHAR
- See Also:
-
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:
-
INVALID_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
-
-
Constructor Details
-
PathSvgNodeRenderer
public PathSvgNodeRenderer()
-
-
Method Details
-
doDraw
Draws this element to a canvas-like object maintained in the context.- Specified by:
doDrawin classAbstractSvgNodeRenderer- Parameters:
context- the object that knows the place to draw this element and maintains its state
-
createDeepCopy
Description copied from interface:ISvgNodeRendererCreates a deep copy of this renderer, including it's subtree of children- Specified by:
createDeepCopyin interfaceISvgNodeRenderer- Returns:
- deep copy of this renderer
-
getObjectBoundingBox
Description copied from interface:ISvgNodeRendererCalculates the current object bounding box.- Specified by:
getObjectBoundingBoxin interfaceISvgNodeRenderer- Parameters:
context- the current context, for instance it contains current viewport and available font data- Returns:
- the
Rectanglerepresenting the current object's bounding box, or null if bounding box is undefined
-
getShapeCoordinates
private String[] getShapeCoordinates(IPathShape shape, IPathShape previousShape, String[] pathProperties) Gets the coordinates that shall be passed toIPathShape.setCoordinates(String[], 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 ofStrings- Returns:
- a
Stringarray of coordinates that shall be passed toIPathShape.setCoordinates(String[], Point)
-
processPathOperator
Processes an individual pathing operator and all of its arguments, converting into one or moreIPathShapeobjects.- Parameters:
pathProperties- The property operator and all arguments as an array ofStringspreviousShape- The previous shape which can affect the positioning of the current shape. If no previous shape existsnullis passed.- Returns:
- a
Listof eachIPathShapethat should be drawn to represent the operator.
-
addMoveToShapes
private List<IPathShape> addMoveToShapes(IPathShape pathShape, String[] pathProperties, IPathShape beforeMoveShape) -
getShapes
Collection<IPathShape> getShapes()Processes theSvgConstants.Attributes.DAbstractSvgNodeRenderer.attributesAndStylesand converts them into one or moreIPathShapeobjects to be drawn on the canvas.Each individual operator is passed to
processPathOperator(String[], IPathShape)to be processed individually.- Returns:
- a
Collectionof eachIPathShapethat should be drawn to represent the path.
-
concatenate
-
containsInvalidAttributes
-
parsePathOperations
Collection<String> parsePathOperations() -
separateDecimalPoints
-
splitPathStringIntoOperators
-
endsWithNonWhitespace
-
drawMarker
Description copied from interface:IMarkerCapableDraws a marker in the specified context. The marker is drawn on the vertices defined according to the given marker type.- Specified by:
drawMarkerin 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
Description copied from interface:IMarkerCapableCalculates marker orientation angle iforientattribute is set toauto- Specified by:
getAutoOrientAnglein 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
-