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
Provides information and calculations needed by render listeners
to display/evaluate text render operations.
This is passed between the
This is passed between the
PdfCanvasProcessor
and
IEventListener
objects as text rendering operations are
discovered-
Field Summary
FieldsModifier and TypeFieldDescriptionHierarchy of nested canvas tags for the text from the most inner (nearest to text) tag to the most outer.private final PdfString
private String
private final Matrix
private final Matrix
private float
Fields inherited from class com.itextpdf.kernel.pdf.canvas.parser.data.AbstractRenderInfo
gs
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
TextRenderInfo
(TextRenderInfo parent, PdfString str, float horizontalOffset) Used for creating sub-TextRenderInfos for each individual character.TextRenderInfo
(PdfString str, CanvasGraphicsState gs, Matrix textMatrix, Stack<CanvasTag> canvasTagHierarchy) Creates a new TextRenderInfo object -
Method Summary
Modifier and TypeMethodDescriptionprivate float
convertHeightFromTextSpaceToUserSpace
(float height) private float
convertWidthFromTextSpaceToUserSpace
(float width) Gets /ActualText tag entry value if this text chunk is marked content.private float[]
Gets the ascent line for the text (i.e.Gets the baseline for the text (i.e.Gets hierarchy of the canvas tags that wraps given text.Provides detail useful if a listener needs access to the position of each individual glyph in the text render operationprivate int
getCharCode
(String string) Converts a single character string to char code.float
Gets the descent line for the text (i.e.Gets /E tag (expansion text) entry value if this text chunk is marked content.getFont()
Getter for the fontfloat
float
float
int
getMcid()
Gets the marked-content identifier associated with thisTextRenderInfo
instanceprivate 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
getText()
Gets the text to be rendered according to canvas operators.Gets original Text matrix.int
private LineSegment
getUnscaledBaselineWithOffset
(float yOffset) private float
Calculates the width of a space character in text space units.float
private float[]
getWidthAndWordSpacing
(PdfString string) Calculates width and word spacing of a single character PDF string.float
boolean
hasMcid
(int mcid) Checks if the text belongs to a marked content sequence with a given mcid.boolean
hasMcid
(int mcid, boolean checkTheTopmostLevelOnly) Checks if the text belongs to a marked content sequence with a given mcid.boolean
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 Details
-
string
-
text
-
textToUserSpaceTransformMatrix
-
textMatrix
-
unscaledWidth
private float unscaledWidth -
canvasTagHierarchy
Hierarchy of nested canvas tags for the text from the most inner (nearest to text) tag to the most outer.
-
-
Constructor Details
-
TextRenderInfo
public TextRenderInfo(PdfString str, CanvasGraphicsState gs, Matrix textMatrix, 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
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 Details
-
getText
Gets the text to be rendered according to canvas operators.- Returns:
- the text to render
-
getPdfString
- Returns:
- original PDF string
-
getTextMatrix
Gets original Text matrix.- Returns:
- text matrix.
-
hasMcid
public boolean hasMcid(int mcid) Checks if the text belongs to a marked content sequence with a given mcid.- Parameters:
mcid
- a marked content id- Returns:
- true if the text is marked with this id
-
hasMcid
public boolean hasMcid(int mcid, boolean checkTheTopmostLevelOnly) Checks if the text 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 the text is marked with this id
-
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
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
-
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
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
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
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
- Returns:
- the current fill 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
Gets /ActualText tag entry value if this text chunk is marked content.- Returns:
- /ActualText value or
null
if none found
-
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
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
-
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
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
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
Converts a single character string to char code.- Parameters:
string
- single character string to convert to.- Returns:
- char code.
-
splitString
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()
-