Package com.itextpdf.svg.renderers.impl
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
public abstract class AbstractSvgNodeRenderer extends java.lang.Object implements ISvgNodeRenderer
ISvgNodeRenderer
abstract implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
AbstractSvgNodeRenderer.FillProperties
(package private) static class
AbstractSvgNodeRenderer.StrokeProperties
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.lang.String>
attributesAndStyles
Map that contains attributes and styles used for drawing operations.(package private) boolean
doFill
(package private) boolean
doStroke
private static org.slf4j.Logger
LOGGER
private static MarkerVertexType[]
MARKER_VERTEX_TYPES
private ISvgNodeRenderer
parent
-
Constructor Summary
Constructors Constructor Description AbstractSvgNodeRenderer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description (package private) void
applyFillAndStrokeProperties(AbstractSvgNodeRenderer.FillProperties fillProperties, AbstractSvgNodeRenderer.StrokeProperties strokeProperties, SvgDrawContext context)
(package private) AffineTransform
applyNonScalingStrokeTransform(SvgDrawContext context)
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.private AbstractSvgNodeRenderer.FillProperties
calculateFillProperties(SvgDrawContext context)
private AbstractSvgNodeRenderer.StrokeProperties
calculateStrokeProperties(SvgDrawContext context)
(package private) AffineTransform
calculateViewPortTranslation(SvgDrawContext context)
Calculate the transformation for the viewport based on the context.boolean
canConstructViewPort()
Method to see if the renderer can create a viewportprotected boolean
canElementFill()
Method to see if a certain renderer can use fill.protected void
deepCopyAttributesAndStyles(ISvgNodeRenderer deepCopy)
Make a deep copy of the styles and attributes of this renderer Helper method for deep copying logicprotected abstract void
doDraw(SvgDrawContext context)
Draws this element to a canvas-like object maintained in the context.(package private) void
doStrokeOrFill(java.lang.String fillRuleRawValue, PdfCanvas currentCanvas)
Do stroke or fill based ondoFill/doStroke
fields.void
draw(SvgDrawContext context)
Applies transformations set to this object, if any, and delegates the drawing of this element and its children to thedoDraw
method.private boolean
drawInClipPath(SvgDrawContext context)
java.lang.String
getAttribute(java.lang.String key)
Retrieves the property value for a given key name.java.util.Map<java.lang.String,java.lang.String>
getAttributeMapCopy()
Get a modifiable copy of the style and attribute mapjava.lang.String
getAttributeOrDefault(java.lang.String key, java.lang.String defaultValue)
Retrieves the property value for a given key name or default if the property value isnull
or missing.private TransparentColor
getColorFromAttributeValue(SvgDrawContext context, java.lang.String rawColorValue, float objectBoundingBoxMargin, float parentOpacity)
float
getCurrentFontSize()
Deprecated.float
getCurrentFontSize(SvgDrawContext context)
Return font-size of the current element in px.Rectangle
getCurrentViewBox(SvgDrawContext context)
Gets the viewbox from the first parent element which can define it.private float
getOpacity()
private float
getOpacityByAttributeName(java.lang.String attributeName, float generalOpacity)
ISvgNodeRenderer
getParent()
Gets the parent of this renderer.(package private) ClipPathSvgNodeRenderer
getParentClipPath()
Gets parentClipPathSvgNodeRenderer
if it exists ornull
otherwise.protected boolean
isHidden()
Check if this renderer should draw the element based on its attributes (e.g.private java.lang.String
normalizeLocalUrlName(java.lang.String name)
protected float
parseAbsoluteLength(java.lang.String length, float percentBaseValue, float defaultValue, SvgDrawContext context)
Deprecated.protected float
parseHorizontalLength(java.lang.String length, SvgDrawContext context)
Parse x-axis length value.protected float
parseVerticalLength(java.lang.String length, SvgDrawContext context)
Parse y-axis length value.(package private) void
postDraw(SvgDrawContext context)
Operations to be performed after drawing the element.(package private) void
preDraw(SvgDrawContext context)
Operations to perform before drawing an element.(package private) java.lang.String[]
retrieveAlignAndMeet()
void
setAttribute(java.lang.String key, java.lang.String value)
Sets a property key and value pairs for a given attributevoid
setAttributesAndStyles(java.util.Map<java.lang.String,java.lang.String> attributesAndStyles)
Sets the map of XML node attributes and CSS style properties that this renderer needs.void
setParent(ISvgNodeRenderer parent)
Sets the parent of this renderer.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.itextpdf.svg.renderers.ISvgNodeRenderer
createDeepCopy, getObjectBoundingBox
-
-
-
-
Field Detail
-
MARKER_VERTEX_TYPES
private static final MarkerVertexType[] MARKER_VERTEX_TYPES
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
attributesAndStyles
protected java.util.Map<java.lang.String,java.lang.String> attributesAndStyles
Map that contains attributes and styles used for drawing operations.
-
doFill
boolean doFill
-
doStroke
boolean doStroke
-
parent
private ISvgNodeRenderer parent
-
-
Method Detail
-
setParent
public void setParent(ISvgNodeRenderer parent)
Description copied from interface:ISvgNodeRenderer
Sets the parent of this renderer. The parent may be the source of inherited properties and default values.- Specified by:
setParent
in interfaceISvgNodeRenderer
- Parameters:
parent
- the parent renderer
-
getParent
public ISvgNodeRenderer getParent()
Description copied from interface:ISvgNodeRenderer
Gets the parent of this renderer. The parent may be the source of inherited properties and default values.- Specified by:
getParent
in interfaceISvgNodeRenderer
- Returns:
- the parent renderer; null in case of a root node
-
setAttributesAndStyles
public void setAttributesAndStyles(java.util.Map<java.lang.String,java.lang.String> attributesAndStyles)
Description copied from interface:ISvgNodeRenderer
Sets the map of XML node attributes and CSS style properties that this renderer needs.- Specified by:
setAttributesAndStyles
in interfaceISvgNodeRenderer
- Parameters:
attributesAndStyles
- the mapping from key names to values
-
getAttribute
public java.lang.String getAttribute(java.lang.String key)
Description copied from interface:ISvgNodeRenderer
Retrieves the property value for a given key name.- Specified by:
getAttribute
in interfaceISvgNodeRenderer
- Parameters:
key
- the name of the property to search for- Returns:
- the value for this key, or
null
-
getAttributeOrDefault
public java.lang.String getAttributeOrDefault(java.lang.String key, java.lang.String defaultValue)
Retrieves the property value for a given key name or default if the property value isnull
or missing.- Parameters:
key
- the name of the property to search fordefaultValue
- the default value to be returned if the property isnull
or missing- Returns:
- the value for this key, or
defaultValue
-
setAttribute
public void setAttribute(java.lang.String key, java.lang.String value)
Description copied from interface:ISvgNodeRenderer
Sets a property key and value pairs for a given attribute- Specified by:
setAttribute
in interfaceISvgNodeRenderer
- Parameters:
key
- the name of the attributevalue
- the value of the attribute
-
getAttributeMapCopy
public java.util.Map<java.lang.String,java.lang.String> getAttributeMapCopy()
Description copied from interface:ISvgNodeRenderer
Get a modifiable copy of the style and attribute map- Specified by:
getAttributeMapCopy
in interfaceISvgNodeRenderer
- Returns:
- copy of the attributes and styles-map
-
draw
public final void draw(SvgDrawContext context)
Applies transformations set to this object, if any, and delegates the drawing of this element and its children to thedoDraw
method.- Specified by:
draw
in 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 public float 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
public float getCurrentFontSize(SvgDrawContext context)
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
public Rectangle getCurrentViewBox(SvgDrawContext context)
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
null
if the element doesn't have parent which can define the viewbox
-
deepCopyAttributesAndStyles
protected void deepCopyAttributesAndStyles(ISvgNodeRenderer deepCopy)
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
protected abstract void doDraw(SvgDrawContext context)
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
java.lang.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 parentClipPathSvgNodeRenderer
if it exists ornull
otherwise.- Returns:
- the parent
ClipPathSvgNodeRenderer
ornull
otherwise
-
applyNonScalingStrokeTransform
AffineTransform applyNonScalingStrokeTransform(SvgDrawContext context)
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
AffineTransform calculateViewPortTranslation(SvgDrawContext context)
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
void postDraw(SvgDrawContext context)
Operations to be performed after drawing the element. This includes filling, stroking.- Parameters:
context
- the svg draw context
-
doStrokeOrFill
void doStrokeOrFill(java.lang.String fillRuleRawValue, PdfCanvas currentCanvas)
Do stroke or fill based ondoFill/doStroke
fields.- Parameters:
fillRuleRawValue
- fill rule attribute value.currentCanvas
- current canvas to draw on.
-
preDraw
void preDraw(SvgDrawContext context)
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
protected float parseHorizontalLength(java.lang.String length, SvgDrawContext context)
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 throughSvgImage
orSvgImageXObject
) and don't havePdfRootSvgNodeRenderer
as its parent.- Parameters:
length
-String
length for parsingcontext
- currentSvgDrawContext
instance- Returns:
- absolute length in points
-
parseVerticalLength
protected float parseVerticalLength(java.lang.String length, SvgDrawContext context)
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 throughSvgImage
orSvgImageXObject
) and don't havePdfRootSvgNodeRenderer
as its parent.- Parameters:
length
-String
length for parsingcontext
- currentSvgDrawContext
instance- Returns:
- absolute length in points
-
parseAbsoluteLength
@Deprecated protected float parseAbsoluteLength(java.lang.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
-String
for 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, java.lang.String rawColorValue, float objectBoundingBoxMargin, float parentOpacity)
-
getOpacityByAttributeName
private float getOpacityByAttributeName(java.lang.String attributeName, float generalOpacity)
-
drawInClipPath
private boolean drawInClipPath(SvgDrawContext context)
-
normalizeLocalUrlName
private java.lang.String normalizeLocalUrlName(java.lang.String name)
-
getOpacity
private float getOpacity()
-
calculateFillProperties
private AbstractSvgNodeRenderer.FillProperties calculateFillProperties(SvgDrawContext context)
-
calculateStrokeProperties
private AbstractSvgNodeRenderer.StrokeProperties calculateStrokeProperties(SvgDrawContext context)
-
-