Class TextRenderInfo
- java.lang.Object
-
- com.itextpdf.kernel.pdf.canvas.parser.data.AbstractRenderInfo
-
- com.itextpdf.kernel.pdf.canvas.parser.data.TextRenderInfo
-
- All Implemented Interfaces:
IEventData
public class TextRenderInfo extends AbstractRenderInfo
Provides information and calculations needed by render listeners to display/evaluate text render operations.
This is passed between thePdfCanvasProcessor
andIEventListener
objects as text rendering operations are discovered
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<CanvasTag>
canvasTagHierarchy
Hierarchy of nested canvas tags for the text from the most inner (nearest to text) tag to the most outer.private PdfString
string
private java.lang.String
text
private Matrix
textMatrix
private Matrix
textToUserSpaceTransformMatrix
private float
unscaledWidth
-
Fields inherited from class com.itextpdf.kernel.pdf.canvas.parser.data.AbstractRenderInfo
gs
-
-
Constructor Summary
Constructors Modifier Constructor Description private
TextRenderInfo(TextRenderInfo parent, PdfString str, float horizontalOffset)
Used for creating sub-TextRenderInfos for each individual character.TextRenderInfo(PdfString str, CanvasGraphicsState gs, Matrix textMatrix, java.util.Stack<CanvasTag> canvasTagHierarchy)
Creates a new TextRenderInfo object
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private float
convertHeightFromTextSpaceToUserSpace(float height)
private float
convertWidthFromTextSpaceToUserSpace(float width)
java.lang.String
getActualText()
Gets /ActualText tag entry value if this text chunk is marked content.private float[]
getAscentDescent()
LineSegment
getAscentLine()
Gets the ascent line for the text (i.e.LineSegment
getBaseline()
Gets the baseline for the text (i.e.java.util.List<CanvasTag>
getCanvasTagHierarchy()
Gets hierarchy of the canvas tags that wraps given text.java.util.List<TextRenderInfo>
getCharacterRenderInfos()
Provides detail useful if a listener needs access to the position of each individual glyph in the text render operationprivate int
getCharCode(java.lang.String string)
Converts a single character string to char code.float
getCharSpacing()
LineSegment
getDescentLine()
Gets the descent line for the text (i.e.java.lang.String
getExpansionText()
Gets /E tag (expansion text) entry value if this text chunk is marked content.Color
getFillColor()
PdfFont
getFont()
Getter for the fontfloat
getFontSize()
float
getHorizontalScaling()
float
getLeading()
int
getMcid()
Gets the marked-content identifier associated with thisTextRenderInfo
instancePdfString
getPdfString()
private float
getPdfStringWidth(PdfString string, boolean singleCharString)
Gets the width of a PDF string in text space unitsfloat
getRise()
The rise represents how far above the nominal baseline the text should be rendered.float
getSingleSpaceWidth()
Color
getStrokeColor()
java.lang.String
getText()
Gets the text to be rendered according to canvas operators.Matrix
getTextMatrix()
Gets original Text matrix.int
getTextRenderMode()
LineSegment
getUnscaledBaseline()
private LineSegment
getUnscaledBaselineWithOffset(float yOffset)
private float
getUnscaledFontSpaceWidth()
Calculates the width of a space character in text space units.float
getUnscaledWidth()
private float[]
getWidthAndWordSpacing(PdfString string)
Calculates width and word spacing of a single character PDF string.float
getWordSpacing()
boolean
hasMcid(int mcid)
Checks if thisTextRenderInfo
instance belongs to a marked content sequence with a given mcid.boolean
hasMcid(int mcid, boolean checkTheTopmostLevelOnly)
Checks if thisTextRenderInfo
instance belongs to a marked content sequence with a given mcid.boolean
isReversedChars()
Determines if the text represented by thisTextRenderInfo
instance is written in a text showing operator wrapped by /ReversedChars marked content sequenceprivate PdfString[]
splitString(PdfString string)
Split PDF string into array of single character PDF strings.-
Methods inherited from class com.itextpdf.kernel.pdf.canvas.parser.data.AbstractRenderInfo
checkGraphicsState, getGraphicsState, isGraphicsStatePreserved, preserveGraphicsState, releaseGraphicsState
-
-
-
-
Field Detail
-
string
private final PdfString string
-
text
private java.lang.String text
-
textToUserSpaceTransformMatrix
private final Matrix textToUserSpaceTransformMatrix
-
textMatrix
private final Matrix textMatrix
-
unscaledWidth
private float unscaledWidth
-
canvasTagHierarchy
private final java.util.List<CanvasTag> canvasTagHierarchy
Hierarchy of nested canvas tags for the text from the most inner (nearest to text) tag to the most outer.
-
-
Constructor Detail
-
TextRenderInfo
public TextRenderInfo(PdfString str, CanvasGraphicsState gs, Matrix textMatrix, java.util.Stack<CanvasTag> canvasTagHierarchy)
Creates a new TextRenderInfo object- Parameters:
str
- the PDF string that should be displayedgs
- the graphics state (note: at this time, this is not immutable, so don't cache it)textMatrix
- the text matrix at the time of the render operationcanvasTagHierarchy
- the marked content tags sequence, if available
-
TextRenderInfo
private TextRenderInfo(TextRenderInfo parent, PdfString str, float horizontalOffset)
Used for creating sub-TextRenderInfos for each individual character.- Parameters:
parent
- the parent TextRenderInfostr
- the content of a TextRenderInfohorizontalOffset
- the unscaled horizontal offset of the character that this TextRenderInfo represents
-
-
Method Detail
-
getText
public java.lang.String getText()
Gets the text to be rendered according to canvas operators.- Returns:
- the text to render
-
getPdfString
public PdfString getPdfString()
- Returns:
- original PDF string
-
getTextMatrix
public Matrix getTextMatrix()
Gets original Text matrix.- Returns:
- text matrix.
-
hasMcid
public boolean hasMcid(int mcid)
Checks if thisTextRenderInfo
instance belongs to a marked content sequence with a given mcid.- Parameters:
mcid
- a marked content id- Returns:
true
if thisTextRenderInfo
instance is marked with this id,false
otherwise
-
hasMcid
public boolean hasMcid(int mcid, boolean checkTheTopmostLevelOnly)
Checks if thisTextRenderInfo
instance belongs to a marked content sequence with a given mcid.- Parameters:
mcid
- a marked content idcheckTheTopmostLevelOnly
- indicates whether to check the topmost level of marked content stack only- Returns:
true
if thisTextRenderInfo
instance is marked with this id,false
otherwise
-
getMcid
public int getMcid()
Gets the marked-content identifier associated with thisTextRenderInfo
instance- Returns:
- associated marked-content identifier or -1 in case content is unmarked
-
getBaseline
public LineSegment getBaseline()
Gets the baseline for the text (i.e. the line that the text 'sits' on) This value includes the Rise of the draw operation - seegetRise()
for the amount added by Rise- Returns:
- the baseline line segment
-
getUnscaledBaseline
public LineSegment getUnscaledBaseline()
-
getAscentLine
public LineSegment getAscentLine()
Gets the ascent line for the text (i.e. the line that represents the topmost extent that a string of the current font could have). This value includes the Rise of the draw operation - seegetRise()
for the amount added by Rise.- Returns:
- a LineSegment instance
-
getDescentLine
public LineSegment getDescentLine()
Gets the descent line for the text (i.e. the line that represents the bottom most extent that a string of the current font could have). This value includes the Rise of the draw operation - seegetRise()
for the amount added by Rise.- Returns:
- a LineSegment instance
-
getFont
public PdfFont getFont()
Getter for the font- Returns:
- the font
-
getRise
public float getRise()
The rise represents how far above the nominal baseline the text should be rendered. ThegetBaseline()
,getAscentLine()
andgetDescentLine()
methods already include Rise. This method is exposed to allow listeners to determine if an explicit rise was involved in the computation of the baseline (this might be useful, for example, for identifying superscript rendering)- Returns:
- The Rise for the text draw operation, in user space units (Ts value, scaled to user space)
-
getCharacterRenderInfos
public java.util.List<TextRenderInfo> getCharacterRenderInfos()
Provides detail useful if a listener needs access to the position of each individual glyph in the text render operation- Returns:
- A list of
TextRenderInfo
objects that represent each glyph used in the draw operation. The next effect is if there was a separate Tj opertion for each character in the rendered string
-
getSingleSpaceWidth
public float getSingleSpaceWidth()
- Returns:
- The width, in user space units, of a single space character in the current font
-
getTextRenderMode
public int getTextRenderMode()
- Returns:
- the text render mode that should be used for the text. From the
PDF specification, this means:
- 0 = Fill text
- 1 = Stroke text
- 2 = Fill, then stroke text
- 3 = Invisible
- 4 = Fill text and add to path for clipping
- 5 = Stroke text and add to path for clipping
- 6 = Fill, then stroke text and add to path for clipping
- 7 = Add text to padd for clipping
-
getFillColor
public Color getFillColor()
- Returns:
- the current fill color.
-
getStrokeColor
public Color getStrokeColor()
- Returns:
- the current stroke color.
-
getFontSize
public float getFontSize()
-
getHorizontalScaling
public float getHorizontalScaling()
-
getCharSpacing
public float getCharSpacing()
-
getWordSpacing
public float getWordSpacing()
-
getLeading
public float getLeading()
-
getActualText
public java.lang.String getActualText()
Gets /ActualText tag entry value if this text chunk is marked content.- Returns:
- /ActualText value or
null
if none found
-
getExpansionText
public java.lang.String getExpansionText()
Gets /E tag (expansion text) entry value if this text chunk is marked content.- Returns:
- /E value or
null
if none found
-
isReversedChars
public boolean isReversedChars()
Determines if the text represented by thisTextRenderInfo
instance is written in a text showing operator wrapped by /ReversedChars marked content sequence- Returns:
true
if this text block lies within /ReversedChars block,false
otherwise
-
getCanvasTagHierarchy
public java.util.List<CanvasTag> getCanvasTagHierarchy()
Gets hierarchy of the canvas tags that wraps given text.- Returns:
- list of the wrapping canvas tags. The first tag is the innermost (nearest to the text).
-
getUnscaledWidth
public float getUnscaledWidth()
- Returns:
- the unscaled (i.e. in Text space) width of the text
-
getUnscaledBaselineWithOffset
private LineSegment getUnscaledBaselineWithOffset(float yOffset)
-
convertWidthFromTextSpaceToUserSpace
private float convertWidthFromTextSpaceToUserSpace(float width)
- Parameters:
width
- the width, in text space- Returns:
- the width in user space
-
convertHeightFromTextSpaceToUserSpace
private float convertHeightFromTextSpaceToUserSpace(float height)
- Parameters:
height
- the height, in text space- Returns:
- the height in user space
-
getUnscaledFontSpaceWidth
private float getUnscaledFontSpaceWidth()
Calculates the width of a space character in text space units.- Returns:
- the width of a single space character in text space units
-
getPdfStringWidth
private float getPdfStringWidth(PdfString string, boolean singleCharString)
Gets the width of a PDF string in text space units- Parameters:
string
- the string that needs measuring- Returns:
- the width of a String in text space units
-
getWidthAndWordSpacing
private float[] getWidthAndWordSpacing(PdfString string)
Calculates width and word spacing of a single character PDF string. IMPORTANT: Shall ONLY be used for a single character pdf strings.- Parameters:
string
- a character to calculate width.- Returns:
- array of 2 items: first item is a character width, second item is a calculated word spacing.
-
getCharCode
private int getCharCode(java.lang.String string)
Converts a single character string to char code.- Parameters:
string
- single character string to convert to.- Returns:
- char code.
-
splitString
private PdfString[] splitString(PdfString string)
Split PDF string into array of single character PDF strings.- Parameters:
string
- PDF string to be split.- Returns:
- split PDF string.
-
getAscentDescent
private float[] getAscentDescent()
-
-