Package com.itextpdf.svg.renderers
Class SvgDrawContext
java.lang.Object
com.itextpdf.svg.renderers.SvgDrawContext
The SvgDrawContext keeps a stack of
PdfCanvas instances, which represent all levels of XObjects that are added to the root canvas.
-
Constructor Summary
ConstructorsConstructorDescriptionSvgDrawContext(ResourceResolver resourceResolver, FontProvider fontProvider) Create an instance of the context that is used to store information when converting SVG. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNamedObject(String name, ISvgNodeRenderer namedObject) Adds a named object to the draw context.voidaddNamedObjects(Map<String, ISvgNodeRenderer> namedObjects) * Adds a number of named object to the draw context.voidaddTextMove(float additionalMoveX, float additionalMoveY) Increment the stored text move.voidAdds an ID that has been referenced by a use element.voidaddViewPort(Rectangle viewPort) Adds a viewbox to the context.Gets clipping element transformation matrix.Concatenates all transformations applied from the top level of the svg to the current one.Gets the SVG CSS context.Retrieves the current top of the stack, without modifying the stack.Get the current canvas transformation.Get the current viewbox.Gets the custom viewport of SVG.Gets the FontProvider to be used during the drawing operations.Deprecated.getNamedObject(String name) Get a named object based on its name.float[]Deprecated.was replaced bygetSvgTextProperties()float[]Retrieves relative position for the current text SVG element relative to the last origin identified by absolute position.Gets the ResourceResolver to be used during the drawing operations.Get the current root transformation that was last applied.Get the viewbox which is the root viewport for the current document.RetrievesSvgTextPropertiesfor text SVG elements.Gets list of temporary fonts from @font-face.float[]Get the stored current text move.booleanisIdUsedByUseTagBefore(String elementId) Returns true when this id has been used beforevoidmoveRelativePosition(float dx, float dy) Adds move to the current relative position for the text SVG element.Retrieves the current top of the stack, thereby taking the current item off the stack.voidPops the last template id from the stack.voidpushCanvas(PdfCanvas canvas) Adds aPdfCanvasto the stack (by definition its top), for use in drawing operations.booleanpushPatternId(String patternId) Add pattern id to stack.voidRemove the currently set view box.voidremoveUsedId(String elementId) Removes an ID that has been referenced by a use element.voidResets clipping element transformation matrix.voidResets current relative position for the text SVG element.voidReset the stored text move to [0f,0f]voidsetCssContext(SvgCssContext cssContext) Sets the SVG CSS context.voidsetCustomViewport(Rectangle customViewport) Sets the custom viewport of SVG.voidsetLastTextTransform(AffineTransform newTransform) Deprecated.in favour ofsetRootTransform(AffineTransform)voidsetPreviousElementTextMove(float[] previousElementTextMove) Deprecated.was replaced bysetSvgTextProperties(SvgTextProperties)voidsetRootTransform(AffineTransform newTransform) Set the current root transformation.voidsetSvgTextProperties(SvgTextProperties textProperties) SetsSvgTextPropertiesfor textSVG elements.voidsetTempFonts(FontSet tempFonts) Sets the FontSet.intsize()Get the current size of the stack, signifying the nesting level of the XObjects.
-
Constructor Details
-
SvgDrawContext
Create an instance of the context that is used to store information when converting SVG.- Parameters:
-
resourceResolver- instance ofResourceResolver -
fontProvider- instance ofFontProvider
-
-
Method Details
-
getCustomViewport
Gets the custom viewport of SVG.The custom viewport is used to resolve percent values of the top level svg.
- Returns:
- the custom viewport
-
setCustomViewport
Sets the custom viewport of SVG.The custom viewport is used to resolve percent values of the top level svg.
- Parameters:
-
customViewport- the custom viewport
-
getCurrentCanvas
Retrieves the current top of the stack, without modifying the stack.- Returns:
- the current canvas that can be used for drawing operations.
-
popCanvas
Retrieves the current top of the stack, thereby taking the current item off the stack.- Returns:
- the current canvas that can be used for drawing operations.
-
pushCanvas
Adds aPdfCanvasto the stack (by definition its top), for use in drawing operations.- Parameters:
-
canvas- the new top of the stack
-
size
public int size()Get the current size of the stack, signifying the nesting level of the XObjects.- Returns:
- the current size of the stack.
-
addViewPort
Adds a viewbox to the context.- Parameters:
-
viewPort- rectangle representing the current viewbox
-
getCurrentViewPort
Get the current viewbox.- Returns:
- the viewbox as it is currently set
-
getRootViewPort
Get the viewbox which is the root viewport for the current document.- Returns:
- root viewbox.
-
removeCurrentViewPort
public void removeCurrentViewPort()Remove the currently set view box. -
addNamedObject
Adds a named object to the draw context. These objects can then be referenced from a different tag.- Parameters:
-
name- name of the object -
namedObject- object to be referenced
-
getNamedObject
Get a named object based on its name. If the name isn't listed, this method will return null.- Parameters:
-
name- name of the object you want to reference - Returns:
- the referenced object
-
getResourceResolver
Gets the ResourceResolver to be used during the drawing operations.- Returns:
- resource resolver instance
-
addNamedObjects
* Adds a number of named object to the draw context. These objects can then be referenced from a different tag.- Parameters:
-
namedObjects- Map containing the named objects keyed to their ID strings
-
getFontProvider
Gets the FontProvider to be used during the drawing operations.- Returns:
- font provider instance
-
getTempFonts
Gets list of temporary fonts from @font-face.- Returns:
- font set instance
-
setTempFonts
Sets the FontSet.- Parameters:
-
tempFonts- font set to be used during drawing operations
-
isIdUsedByUseTagBefore
Returns true when this id has been used before- Parameters:
-
elementId- element id to check - Returns:
- true if id has been encountered before through a use element
-
addUsedId
Adds an ID that has been referenced by a use element.- Parameters:
-
elementId- referenced element ID
-
removeUsedId
Removes an ID that has been referenced by a use element.- Parameters:
-
elementId- referenced element ID
-
getLastTextTransform
Deprecated.in favour ofgetRootTransform()Get the text transformation that was last applied.- Returns:
-
AffineTransformrepresenting the last text transformation
-
setLastTextTransform
Deprecated.in favour ofsetRootTransform(AffineTransform)Set the last text transformation.- Parameters:
-
newTransform- last text transformation
-
getRootTransform
Get the current root transformation that was last applied.- Returns:
-
AffineTransformrepresenting the root transformation.
-
setRootTransform
Set the current root transformation.- Parameters:
-
newTransform- root transformation.
-
getTextMove
public float[] getTextMove()Get the stored current text move.- Returns:
- [horizontal text move, vertical text move]
-
resetTextMove
public void resetTextMove()Reset the stored text move to [0f,0f] -
addTextMove
public void addTextMove(float additionalMoveX, float additionalMoveY) Increment the stored text move.- Parameters:
-
additionalMoveX- horizontal value to add -
additionalMoveY- vertical value to add
-
getCurrentCanvasTransform
Get the current canvas transformation.- Returns:
-
the
AffineTransformrepresenting the current canvas transformation
-
getCssContext
Gets the SVG CSS context.- Returns:
- the SVG CSS context
-
setCssContext
Sets the SVG CSS context.- Parameters:
-
cssContext- the SVG CSS context
-
pushPatternId
Add pattern id to stack. Check if the id is already in the stack. If it is, then returnfalseand not add, if it is not - add and returntrue.- Parameters:
-
patternId- pattern id - Returns:
-
trueif pattern id was not on the stack and was pushed;falseif it is on the stack
-
popPatternId
public void popPatternId()Pops the last template id from the stack. -
setPreviousElementTextMove
Deprecated.was replaced bysetSvgTextProperties(SvgTextProperties)Sets a previous element text move.- Parameters:
-
previousElementTextMove- previous element text move
-
getPreviousElementTextMove
Deprecated.was replaced bygetSvgTextProperties()Gets a previous element text move.- Returns:
- the previous element text move
-
getSvgTextProperties
RetrievesSvgTextPropertiesfor text SVG elements.- Returns:
-
SvgTextPropertiestext properties
-
setSvgTextProperties
SetsSvgTextPropertiesfor textSVG elements.- Parameters:
-
textProperties-SvgTextPropertiesto set
-
getRelativePosition
public float[] getRelativePosition()Retrieves relative position for the current text SVG element relative to the last origin identified by absolute position.- Returns:
- relative position for the current text SVG element
-
moveRelativePosition
public void moveRelativePosition(float dx, float dy) Adds move to the current relative position for the text SVG element.- Parameters:
-
dx- x-axis movement -
dy- y-axis movement
-
resetRelativePosition
public void resetRelativePosition()Resets current relative position for the text SVG element. -
getClippingElementTransform
Gets clipping element transformation matrix.It is used to preserve clipping element transformation matrix and before drawing clipped element revert canvas transformation matrix into original state. After clipped element will be drawn, clipping element transformation matrix will be used once again to return clipping element matrix for next siblings.
- Returns:
- the current clipping element transformation matrix
-
resetClippingElementTransform
public void resetClippingElementTransform()Resets clipping element transformation matrix.See
getClippingElementTransform()for more info about clipping element transformation matrix. -
getConcatenatedTransform
Concatenates all transformations applied from the top level of the svg to the current one.- Returns:
-
AffineTransforminstance
-
getRootTransform()