Class AbstractSvgNodeRenderer
java.lang.Object
com.itextpdf.svg.renderers.impl.AbstractSvgNodeRenderer
- All Implemented Interfaces:
ISvgNodeRenderer
- Direct Known Subclasses:
AbstractBranchSvgNodeRenderer, EllipseSvgNodeRenderer, ImageSvgNodeRenderer, LineSvgNodeRenderer, PathSvgNodeRenderer, PolylineSvgNodeRenderer, RectangleSvgNodeRenderer, TextLeafSvgNodeRenderer, TextSvgBranchRenderer, UseSvgNodeRenderer
ISvgNodeRenderer abstract implementation.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class(package private) static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionMap that contains attributes and styles used for drawing operations.(package private) boolean(package private) booleanprivate static final org.slf4j.Loggerprivate static final MarkerVertexType[]private ISvgNodeRenderer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidapplyFillAndStrokeProperties(AbstractSvgNodeRenderer.FillProperties fillProperties, AbstractSvgNodeRenderer.StrokeProperties strokeProperties, SvgDrawContext context) (package private) AffineTransformApplies non-scaling-stroke vector-effect to this renderer by concatenating all transformations applied from the top level of the svg to the current one, inverting it and applying to the current canvas.calculateFillProperties(SvgDrawContext context) calculateStrokeProperties(SvgDrawContext context) (package private) AffineTransformCalculate the transformation for the viewport based on the context.booleanMethod to see if the renderer can create a viewportprotected booleanMethod to see if a certain renderer can use fill.protected voiddeepCopyAttributesAndStyles(ISvgNodeRenderer deepCopy) Make a deep copy of the styles and attributes of this renderer Helper method for deep copying logicprotected abstract voiddoDraw(SvgDrawContext context) Draws this element to a canvas-like object maintained in the context.(package private) voiddoStrokeOrFill(String fillRuleRawValue, PdfCanvas currentCanvas) Do stroke or fill based ondoFill/doStrokefields.final voiddraw(SvgDrawContext context) Applies transformations set to this object, if any, and delegates the drawing of this element and its children to thedoDrawmethod.private booleandrawInClipPath(SvgDrawContext context) getAttribute(String key) Retrieves the property value for a given key name.Get a modifiable copy of the style and attribute mapgetAttributeOrDefault(String key, String defaultValue) Retrieves the property value for a given key name or default if the property value isnullor missing.private TransparentColorgetColorFromAttributeValue(SvgDrawContext context, String rawColorValue, float objectBoundingBoxMargin, float parentOpacity) floatDeprecated.floatgetCurrentFontSize(SvgDrawContext context) Return font-size of the current element in px.getCurrentViewBox(SvgDrawContext context) Gets the viewbox from the first parent element which can define it.private floatprivate floatgetOpacityByAttributeName(String attributeName, float generalOpacity) Gets the parent of this renderer.(package private) ClipPathSvgNodeRendererGets parentClipPathSvgNodeRendererif it exists ornullotherwise.protected booleanisHidden()Check if this renderer should draw the element based on its attributes (e.g.private StringnormalizeLocalUrlName(String name) protected floatparseAbsoluteLength(String length, float percentBaseValue, float defaultValue, SvgDrawContext context) Deprecated.protected floatparseHorizontalLength(String length, SvgDrawContext context) Parse x-axis length value.protected floatparseVerticalLength(String length, SvgDrawContext context) Parse y-axis length value.(package private) voidpostDraw(SvgDrawContext context) Operations to be performed after drawing the element.(package private) voidpreDraw(SvgDrawContext context) Operations to perform before drawing an element.(package private) String[]voidsetAttribute(String key, String value) Sets a property key and value pairs for a given attributevoidsetAttributesAndStyles(Map<String, String> attributesAndStyles) Sets the map of XML node attributes and CSS style properties that this renderer needs.voidsetParent(ISvgNodeRenderer parent) Sets the parent of this renderer.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ISvgNodeRenderer
createDeepCopy, getObjectBoundingBox
-
Field Details
-
MARKER_VERTEX_TYPES
-
LOGGER
private static final org.slf4j.Logger LOGGER -
attributesAndStyles
-
doFill
boolean doFill -
doStroke
boolean doStroke -
parent
-
-
Constructor Details
-
AbstractSvgNodeRenderer
public AbstractSvgNodeRenderer()
-
-
Method Details
-
setParent
Description copied from interface:ISvgNodeRendererSets the parent of this renderer. The parent may be the source of inherited properties and default values.- Specified by:
setParentin interfaceISvgNodeRenderer- Parameters:
parent- the parent renderer
-
getParent
Description copied from interface:ISvgNodeRendererGets the parent of this renderer. The parent may be the source of inherited properties and default values.- Specified by:
getParentin interfaceISvgNodeRenderer- Returns:
- the parent renderer; null in case of a root node
-
setAttributesAndStyles
Description copied from interface:ISvgNodeRendererSets the map of XML node attributes and CSS style properties that this renderer needs.- Specified by:
setAttributesAndStylesin interfaceISvgNodeRenderer- Parameters:
attributesAndStyles- the mapping from key names to values
-
getAttribute
Description copied from interface:ISvgNodeRendererRetrieves the property value for a given key name.- Specified by:
getAttributein interfaceISvgNodeRenderer- Parameters:
key- the name of the property to search for- Returns:
- the value for this key, or
null
-
getAttributeOrDefault
Retrieves the property value for a given key name or default if the property value isnullor missing.- Parameters:
key- the name of the property to search fordefaultValue- the default value to be returned if the property isnullor missing- Returns:
- the value for this key, or
defaultValue
-
setAttribute
Description copied from interface:ISvgNodeRendererSets a property key and value pairs for a given attribute- Specified by:
setAttributein interfaceISvgNodeRenderer- Parameters:
key- the name of the attributevalue- the value of the attribute
-
getAttributeMapCopy
Description copied from interface:ISvgNodeRendererGet a modifiable copy of the style and attribute map- Specified by:
getAttributeMapCopyin interfaceISvgNodeRenderer- Returns:
- copy of the attributes and styles-map
-
draw
Applies transformations set to this object, if any, and delegates the drawing of this element and its children to thedoDrawmethod.- Specified by:
drawin interfaceISvgNodeRenderer- Parameters:
context- the object that knows the place to draw this element and maintains its state
-
canElementFill
protected boolean canElementFill()Method to see if a certain renderer can use fill.- Returns:
- true if the renderer can use fill
-
canConstructViewPort
public boolean canConstructViewPort()Method to see if the renderer can create a viewport- Returns:
- true if the renderer can construct a viewport
-
getCurrentFontSize
Deprecated.Return font-size of the current element in px.This method is deprecated in favour of
getCurrentFontSize(SvgDrawContext)because current one can't support relative values (em, rem) and those can't be resolved withoutSvgDrawContext.- Returns:
- absolute value of font-size
-
getCurrentFontSize
Return font-size of the current element in px.- Parameters:
context- draw context from which root font size can be extracted- Returns:
- absolute value of font-size
-
getCurrentViewBox
Gets the viewbox from the first parent element which can define it.See SVG specification to find which elements can define a viewbox.
- Parameters:
context- draw context from which fallback viewbox can be extracted- Returns:
- the viewbox or
nullif the element doesn't have parent which can define the viewbox
-
deepCopyAttributesAndStyles
Make a deep copy of the styles and attributes of this renderer Helper method for deep copying logic- Parameters:
deepCopy- renderer to insert the deep copied attributes into
-
doDraw
Draws this element to a canvas-like object maintained in the context.- Parameters:
context- the object that knows the place to draw this element and maintains its state
-
retrieveAlignAndMeet
String[] retrieveAlignAndMeet() -
isHidden
protected boolean isHidden()Check if this renderer should draw the element based on its attributes (e.g. visibility/display)- Returns:
- true if element won't be drawn, false otherwise
-
getParentClipPath
ClipPathSvgNodeRenderer getParentClipPath()Gets parentClipPathSvgNodeRendererif it exists ornullotherwise.- Returns:
- the parent
ClipPathSvgNodeRendererornullotherwise
-
applyNonScalingStrokeTransform
Applies non-scaling-stroke vector-effect to this renderer by concatenating all transformations applied from the top level of the svg to the current one, inverting it and applying to the current canvas.- Parameters:
context- the SVG draw context- Returns:
- the transformation that was inverted and applied to this renderer to achieve non-scaling-stroke vector-effect
-
calculateViewPortTranslation
Calculate the transformation for the viewport based on the context. Only used by elements that can create viewports- Parameters:
context- the SVG draw context- Returns:
- the transformation that needs to be applied to this renderer
-
postDraw
Operations to be performed after drawing the element. This includes filling, stroking.- Parameters:
context- the svg draw context
-
doStrokeOrFill
-
preDraw
Operations to perform before drawing an element. This includes setting stroke color and width, fill color.- Parameters:
context- the svg draw context
-
applyFillAndStrokeProperties
void applyFillAndStrokeProperties(AbstractSvgNodeRenderer.FillProperties fillProperties, AbstractSvgNodeRenderer.StrokeProperties strokeProperties, SvgDrawContext context) -
parseHorizontalLength
Parse x-axis length value. If this method is called and there is no view port inSvgDrawContext, a default current viewport will be created. This can happen if svg is created manually (not throughSvgImageorSvgImageXObject) and don't havePdfRootSvgNodeRendereras its parent.- Parameters:
length-Stringlength for parsingcontext- currentSvgDrawContextinstance- Returns:
- absolute length in points
-
parseVerticalLength
Parse y-axis length value. If this method is called and there is no view port inSvgDrawContext, a default current viewport will be created. This can happen if svg is created manually (not throughSvgImageorSvgImageXObject) and don't havePdfRootSvgNodeRendereras its parent.- Parameters:
length-Stringlength for parsingcontext- currentSvgDrawContextinstance- Returns:
- absolute length in points
-
parseAbsoluteLength
@Deprecated protected float parseAbsoluteLength(String length, float percentBaseValue, float defaultValue, SvgDrawContext context) Deprecated.Parse length attributes.This method is deprecated and
SvgCssUtils.parseAbsoluteLength(AbstractSvgNodeRenderer, String, float, float, SvgDrawContext)should be used instead.- Parameters:
length-Stringfor parsingpercentBaseValue- the value on which percent length is based ondefaultValue- default value if length is not recognizedcontext- currentSvgDrawContext- Returns:
- absolute value in points
-
getColorFromAttributeValue
private TransparentColor getColorFromAttributeValue(SvgDrawContext context, String rawColorValue, float objectBoundingBoxMargin, float parentOpacity) -
getOpacityByAttributeName
-
drawInClipPath
-
normalizeLocalUrlName
-
getOpacity
private float getOpacity() -
calculateFillProperties
-
calculateStrokeProperties
-