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 PdfStringprivate Stringprivate final Matrixprivate final Matrixprivate floatFields inherited from class AbstractRenderInfo
gs -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateTextRenderInfo(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 floatconvertHeightFromTextSpaceToUserSpace(float height) private floatconvertWidthFromTextSpaceToUserSpace(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 intgetCharCode(String string) Converts a single character string to char code.floatGets 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 fontfloatfloatfloatintgetMcid()Gets the marked-content identifier associated with thisTextRenderInfoinstanceprivate floatgetPdfStringWidth(PdfString string, boolean singleCharString) Gets the width of a PDF string in text space unitsfloatgetRise()The rise represents how far above the nominal baseline the text should be rendered.floatgetText()Gets the text to be rendered according to canvas operators.Gets original Text matrix.intprivate LineSegmentgetUnscaledBaselineWithOffset(float yOffset) private floatCalculates the width of a space character in text space units.floatprivate float[]getWidthAndWordSpacing(PdfString string) Calculates width and word spacing of a single character PDF string.floatbooleanhasMcid(int mcid) Checks if thisTextRenderInfoinstance belongs to a marked content sequence with a given mcid.booleanhasMcid(int mcid, boolean checkTheTopmostLevelOnly) Checks if thisTextRenderInfoinstance belongs to a marked content sequence with a given mcid.booleanDetermines if the text represented by thisTextRenderInfoinstance 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 AbstractRenderInfo
checkGraphicsState, getGraphicsState, isGraphicsStatePreserved, preserveGraphicsState, releaseGraphicsState
-
Field Details
-
string
-
text
-
textToUserSpaceTransformMatrix
-
textMatrix
-
unscaledWidth
private float unscaledWidth -
canvasTagHierarchy
-
-
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
-
hasMcid
public boolean hasMcid(int mcid) Checks if thisTextRenderInfoinstance belongs to a marked content sequence with a given mcid.- Parameters:
mcid- a marked content id- Returns:
trueif thisTextRenderInfoinstance is marked with this id,falseotherwise
-
hasMcid
public boolean hasMcid(int mcid, boolean checkTheTopmostLevelOnly) Checks if thisTextRenderInfoinstance 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:
trueif thisTextRenderInfoinstance is marked with this id,falseotherwise
-
getMcid
public int getMcid()Gets the marked-content identifier associated with thisTextRenderInfoinstance- 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
-
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
TextRenderInfoobjects 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
nullif none found
-
getExpansionText
Gets /E tag (expansion text) entry value if this text chunk is marked content.- Returns:
- /E value or
nullif none found
-
isReversedChars
public boolean isReversedChars()Determines if the text represented by thisTextRenderInfoinstance is written in a text showing operator wrapped by /ReversedChars marked content sequence- Returns:
trueif this text block lies within /ReversedChars block,falseotherwise
-
getCanvasTagHierarchy
-
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
-
getAscentDescent
private float[] getAscentDescent()
-