Package com.itextpdf.svg.renderers.impl
Class TextSvgBranchRenderer
- java.lang.Object
-
- com.itextpdf.svg.renderers.impl.AbstractSvgNodeRenderer
-
- com.itextpdf.svg.renderers.impl.TextSvgBranchRenderer
-
- All Implemented Interfaces:
ISvgTextNodeRenderer
,ISvgNodeRenderer
- Direct Known Subclasses:
TextSvgTSpanBranchRenderer
public class TextSvgBranchRenderer extends AbstractSvgNodeRenderer implements ISvgTextNodeRenderer
ISvgNodeRenderer
implementation for the <text> and <tspan> tag.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TextSvgBranchRenderer.ClippedElementDrawer
-
Nested classes/interfaces inherited from class com.itextpdf.svg.renderers.impl.AbstractSvgNodeRenderer
AbstractSvgNodeRenderer.FillProperties, AbstractSvgNodeRenderer.StrokeProperties
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ISvgTextNodeRenderer>
children
private boolean
moveResolved
private Rectangle
objectBoundingBox
private Paragraph
paragraph
protected boolean
performRootTransformations
Deprecated.private boolean
posResolved
protected static AffineTransform
TEXTFLIP
Top level transformation to flip the y-axis results in the character glyphs being mirrored, this tf corrects for this behaviourprivate boolean
whiteSpaceProcessed
private float
xMove
private float[]
xPos
private float
yMove
private float[]
yPos
-
Fields inherited from class com.itextpdf.svg.renderers.impl.AbstractSvgNodeRenderer
attributesAndStyles, doFill, doStroke
-
-
Constructor Summary
Constructors Constructor Description TextSvgBranchRenderer()
Creates newTextSvgBranchRenderer
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addChild(ISvgTextNodeRenderer child)
Adds a child to the currentTextSvgBranchRenderer
renderer.(package private) void
addTextChild(Text text, SvgDrawContext drawContext)
(package private) void
applyFillAndStrokeProperties(AbstractSvgNodeRenderer.FillProperties fillProperties, AbstractSvgNodeRenderer.StrokeProperties strokeProperties, SvgDrawContext context)
(package private) void
applyFontProperties(IElement element, SvgDrawContext context)
private void
applyTextAnchor()
private void
applyTextAnchor(java.lang.String textAnchorValue, boolean isRtl)
(package private) void
applyTextRenderingMode(IElement element)
private void
collectChildren(java.util.List<ISvgTextNodeRenderer> children)
boolean
containsAbsolutePositionChange()
This method is deprecated and will be replaced with new signaturecontainsAbsolutePositionChange(SvgDrawContext)
.boolean
containsAbsolutePositionChange(SvgDrawContext context)
Checks whether current <text> or <tspan> element contains absolute position attributes.boolean
containsRelativeMove()
Deprecated.boolean
containsRelativeMove(SvgDrawContext context)
Checks whether current <text> or <tspan> element contains relative position change.ISvgNodeRenderer
createDeepCopy()
Creates a deep copy of this renderer, including it's subtree of childrenprivate void
deepCopyChildren(TextSvgBranchRenderer deepCopy)
protected void
doDraw(SvgDrawContext context)
Method that will set properties to be inherited by this branch renderer's children and will iterate over all children in order to draw them.private void
drawLastTextChunk(SvgDrawContext context)
(package private) void
fillCopy(TextSvgBranchRenderer copy)
float[][]
getAbsolutePositionChanges()
This method is deprecated and will be replaced with new signaturegetAbsolutePositionChanges(SvgDrawContext)
.float[][]
getAbsolutePositionChanges(SvgDrawContext context)
Gets absolute position of the current <text> or <tspan> element.java.util.List<ISvgTextNodeRenderer>
getChildren()
Retrieves a list of all children of the currentTextSvgBranchRenderer
renderer.private static Rectangle
getCommonRectangleWithAnchor(Rectangle commonRect, Rectangle textChunkRect, float absoluteX, java.lang.String textAnchorValue)
Adjust absolutely positioned text chunk (shift it to the start of view port, apply text anchor) and merge it with the common text rectangle.Rectangle
getObjectBoundingBox(SvgDrawContext context)
Calculates the current object bounding box.private float[]
getPositionsFromString(java.lang.String rawValuesString, SvgDrawContext context, boolean isHorizontal)
float[]
getRelativeTranslation()
Deprecated.float[]
getRelativeTranslation(SvgDrawContext context)
Gets relative translation of the current <text> or <tspan> element.private Point
getStartPoint(SvgDrawContext context, Point basePoint)
float
getTextContentLength(float parentFontSize, PdfFont font)
Deprecated.TextRectangle
getTextRectangle(SvgDrawContext context, Point startPoint)
Return the bounding rectangle of the text element.private static AffineTransform
getTextTransform(float[][] absolutePositions, SvgDrawContext context)
void
markWhiteSpaceProcessed()
Marks white-space property as processed.(package private) void
performDrawing(SvgDrawContext context)
(package private) void
preDraw(SvgDrawContext context)
Operations to perform before drawing an element.private void
resolveAbsoluteTextPosition(SvgDrawContext context)
private void
resolveRelativeTextMove(SvgDrawContext context)
private void
startNewTextChunk(SvgDrawContext context, AffineTransform newTransform)
-
Methods inherited from class com.itextpdf.svg.renderers.impl.AbstractSvgNodeRenderer
applyNonScalingStrokeTransform, calculateViewPortTranslation, canConstructViewPort, canElementFill, deepCopyAttributesAndStyles, doStrokeOrFill, draw, getAttribute, getAttributeMapCopy, getAttributeOrDefault, getCurrentFontSize, getCurrentFontSize, getCurrentViewBox, getParent, getParentClipPath, isHidden, parseAbsoluteLength, parseHorizontalLength, parseVerticalLength, postDraw, retrieveAlignAndMeet, setAttribute, setAttributesAndStyles, setParent
-
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
draw, getAttribute, getAttributeMapCopy, getParent, setAttribute, setAttributesAndStyles, setParent
-
-
-
-
Field Detail
-
TEXTFLIP
protected static final AffineTransform TEXTFLIP
Top level transformation to flip the y-axis results in the character glyphs being mirrored, this tf corrects for this behaviour
-
children
private final java.util.List<ISvgTextNodeRenderer> children
-
performRootTransformations
@Deprecated protected boolean performRootTransformations
Deprecated.
-
paragraph
private Paragraph paragraph
-
objectBoundingBox
private Rectangle objectBoundingBox
-
moveResolved
private boolean moveResolved
-
xMove
private float xMove
-
yMove
private float yMove
-
posResolved
private boolean posResolved
-
xPos
private float[] xPos
-
yPos
private float[] yPos
-
whiteSpaceProcessed
private boolean whiteSpaceProcessed
-
-
Constructor Detail
-
TextSvgBranchRenderer
public TextSvgBranchRenderer()
Creates newTextSvgBranchRenderer
instance.
-
-
Method Detail
-
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
-
fillCopy
void fillCopy(TextSvgBranchRenderer copy)
-
addChild
public final void addChild(ISvgTextNodeRenderer child)
Adds a child to the currentTextSvgBranchRenderer
renderer.- Parameters:
child
-ISvgTextNodeRenderer
child to add
-
getChildren
public final java.util.List<ISvgTextNodeRenderer> getChildren()
Retrieves a list of all children of the currentTextSvgBranchRenderer
renderer.- Returns:
- a list of
ISvgTextNodeRenderer
children
-
getTextContentLength
@Deprecated public float getTextContentLength(float parentFontSize, PdfFont font)
Deprecated.Description copied from interface:ISvgTextNodeRenderer
Gets text content length.- Specified by:
getTextContentLength
in interfaceISvgTextNodeRenderer
- Parameters:
parentFontSize
- parent font sizefont
- current font- Returns:
- text content length
-
getRelativeTranslation
@Deprecated public float[] getRelativeTranslation()
Deprecated.Description copied from interface:ISvgTextNodeRenderer
This method is deprecated and will be replaced with new signaturegetRelativeTranslation(SvgDrawContext)
. This is needed because xMove/yMove can contain relative values, so SvgDrawContext is needed to resolve them.- Specified by:
getRelativeTranslation
in interfaceISvgTextNodeRenderer
- Returns:
- text relative translation
-
getRelativeTranslation
public float[] getRelativeTranslation(SvgDrawContext context)
Gets relative translation of the current <text> or <tspan> element.- Parameters:
context
- currentSvgDrawContext
- Returns:
- float array that contains relative
dx
anddy
translations
-
containsRelativeMove
@Deprecated public boolean containsRelativeMove()
Deprecated.Description copied from interface:ISvgTextNodeRenderer
This method is deprecated and will be replaced with new signaturecontainsRelativeMove(SvgDrawContext)
. This is needed because xMove/yMove can contain relative values, so SvgDrawContext is needed to resolve them.- Specified by:
containsRelativeMove
in interfaceISvgTextNodeRenderer
- Returns:
true
if there is a relative move,false
otherwise
-
containsRelativeMove
public boolean containsRelativeMove(SvgDrawContext context)
Checks whether current <text> or <tspan> element contains relative position change.- Parameters:
context
- currentSvgDrawContext
- Returns:
true
is current element contains relative position,false
otherwise
-
containsAbsolutePositionChange
public boolean containsAbsolutePositionChange()
Description copied from interface:ISvgTextNodeRenderer
This method is deprecated and will be replaced with new signaturecontainsAbsolutePositionChange(SvgDrawContext)
. This is needed because x/y can contain relative values, so SvgDrawContext is needed to resolve them.- Specified by:
containsAbsolutePositionChange
in interfaceISvgTextNodeRenderer
- Returns:
true
if an absolute position is specified via x/y attributes,false
otherwise
-
containsAbsolutePositionChange
public boolean containsAbsolutePositionChange(SvgDrawContext context)
Checks whether current <text> or <tspan> element contains absolute position attributes.- Parameters:
context
- currentSvgDrawContext
- Returns:
true
is current element contains absolute position,false
otherwise
-
getAbsolutePositionChanges
public float[][] getAbsolutePositionChanges()
Description copied from interface:ISvgTextNodeRenderer
This method is deprecated and will be replaced with new signaturegetAbsolutePositionChanges(SvgDrawContext)
. This is needed because x/y can contain relative values, so SvgDrawContext is needed to resolve them.- Specified by:
getAbsolutePositionChanges
in interfaceISvgTextNodeRenderer
- Returns:
- text absolute position
-
getAbsolutePositionChanges
public float[][] getAbsolutePositionChanges(SvgDrawContext context)
Gets absolute position of the current <text> or <tspan> element.- Parameters:
context
- currentSvgDrawContext
- Returns:
- float array that contains absolute
x
andy
positions as either single item arrays or null if attribute is not present
-
markWhiteSpaceProcessed
public void markWhiteSpaceProcessed()
Marks white-space property as processed.
-
getTextRectangle
public TextRectangle getTextRectangle(SvgDrawContext context, Point startPoint)
Description copied from interface:ISvgTextNodeRenderer
Return the bounding rectangle of the text element.- Specified by:
getTextRectangle
in interfaceISvgTextNodeRenderer
- Parameters:
context
- currentSvgDrawContext
startPoint
- end point of previous text element- Returns:
- created instance of
TextRectangle
-
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
-
preDraw
void preDraw(SvgDrawContext context)
Description copied from class:AbstractSvgNodeRenderer
Operations to perform before drawing an element. This includes setting stroke color and width, fill color.- Overrides:
preDraw
in classAbstractSvgNodeRenderer
- Parameters:
context
- the svg draw context
-
doDraw
protected void doDraw(SvgDrawContext context)
Method that will set properties to be inherited by this branch renderer's children and will iterate over all children in order to draw them.- Specified by:
doDraw
in classAbstractSvgNodeRenderer
- Parameters:
context
- the object that knows the place to draw this element and maintains its state
-
applyFontProperties
void applyFontProperties(IElement element, SvgDrawContext context)
-
applyTextRenderingMode
void applyTextRenderingMode(IElement element)
-
addTextChild
void addTextChild(Text text, SvgDrawContext drawContext)
-
performDrawing
void performDrawing(SvgDrawContext context)
-
startNewTextChunk
private void startNewTextChunk(SvgDrawContext context, AffineTransform newTransform)
-
drawLastTextChunk
private void drawLastTextChunk(SvgDrawContext context)
-
applyFillAndStrokeProperties
void applyFillAndStrokeProperties(AbstractSvgNodeRenderer.FillProperties fillProperties, AbstractSvgNodeRenderer.StrokeProperties strokeProperties, SvgDrawContext context)
- Overrides:
applyFillAndStrokeProperties
in classAbstractSvgNodeRenderer
-
resolveRelativeTextMove
private void resolveRelativeTextMove(SvgDrawContext context)
-
resolveAbsoluteTextPosition
private void resolveAbsoluteTextPosition(SvgDrawContext context)
-
getPositionsFromString
private float[] getPositionsFromString(java.lang.String rawValuesString, SvgDrawContext context, boolean isHorizontal)
-
getTextTransform
private static AffineTransform getTextTransform(float[][] absolutePositions, SvgDrawContext context)
-
getCommonRectangleWithAnchor
private static Rectangle getCommonRectangleWithAnchor(Rectangle commonRect, Rectangle textChunkRect, float absoluteX, java.lang.String textAnchorValue)
Adjust absolutely positioned text chunk (shift it to the start of view port, apply text anchor) and merge it with the common text rectangle.- Parameters:
commonRect
- rectangle for the whole text tagtextChunkRect
- rectangle for the last absolutely positioned text chunkabsoluteX
- last absolute x positiontextAnchorValue
- text anchor for the last text chunk- Returns:
- merged common text rectangle
-
deepCopyChildren
private void deepCopyChildren(TextSvgBranchRenderer deepCopy)
-
applyTextAnchor
private void applyTextAnchor()
-
applyTextAnchor
private void applyTextAnchor(java.lang.String textAnchorValue, boolean isRtl)
-
getStartPoint
private Point getStartPoint(SvgDrawContext context, Point basePoint)
-
collectChildren
private void collectChildren(java.util.List<ISvgTextNodeRenderer> children)
-
-