Package com.itextpdf.text.pdf.parser
Class TextRenderInfo
- java.lang.Object
-
- com.itextpdf.text.pdf.parser.TextRenderInfo
-
public class TextRenderInfo extends java.lang.Object
Provides information and calculations needed by render listeners to display/evaluate text render operations.
This is passed between thePdfContentStreamProcessor
andRenderListener
objects as text rendering operations are discovered
-
-
Field Summary
Fields Modifier and Type Field Description private double[]
fontMatrix
private GraphicsState
gs
private java.util.Collection<MarkedContentInfo>
markedContentInfos
Array containing marked content info for the text.private PdfString
string
private java.lang.String
text
private Matrix
textToUserSpaceTransformMatrix
private java.lang.Float
unscaledWidth
-
Constructor Summary
Constructors Modifier Constructor Description private
TextRenderInfo(TextRenderInfo parent, PdfString string, float horizontalOffset)
Used for creating sub-TextRenderInfos for each individual character(package private)
TextRenderInfo(PdfString string, GraphicsState gs, Matrix textMatrix, java.util.Collection<MarkedContentInfo> markedContentInfo)
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)
private java.lang.String
decode(PdfString in)
Decodes a PdfString (which will contain glyph ids encoded in the font's encoding) based on the active font, and determine the unicode equivalentLineSegment
getAscentLine()
Gets the ascentline for the text (i.e.LineSegment
getBaseline()
Gets the baseline for the text (i.e.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.LineSegment
getDescentLine()
Gets the descentline for the text (i.e.BaseColor
getFillColor()
DocumentFont
getFont()
Getter for the fontjava.lang.Integer
getMcid()
PdfString
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()
private float
getStringWidth(java.lang.String string)
Gets the width of a String in text space unitsBaseColor
getStrokeColor()
java.lang.String
getText()
int
getTextRenderMode()
LineSegment
getUnscaledBaseline()
private LineSegment
getUnscaledBaselineWithOffset(float yOffset)
private float
getUnscaledFontSpaceWidth()
Calculates the width of a space character.(package private) float
getUnscaledWidth()
private float[]
getWidthAndWordSpacing(PdfString string, boolean singleCharString)
Calculates width and word spacing of a single character PDF string.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.private PdfString[]
splitString(PdfString string)
Split PDF string into array of single character PDF strings.
-
-
-
Field Detail
-
string
private final PdfString string
-
text
private java.lang.String text
-
textToUserSpaceTransformMatrix
private final Matrix textToUserSpaceTransformMatrix
-
gs
private final GraphicsState gs
-
unscaledWidth
private java.lang.Float unscaledWidth
-
fontMatrix
private double[] fontMatrix
-
markedContentInfos
private final java.util.Collection<MarkedContentInfo> markedContentInfos
Array containing marked content info for the text.- Since:
- 5.0.2
-
-
Constructor Detail
-
TextRenderInfo
TextRenderInfo(PdfString string, GraphicsState gs, Matrix textMatrix, java.util.Collection<MarkedContentInfo> markedContentInfo)
Creates a new TextRenderInfo object- Parameters:
string
- 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 operationmarkedContentInfo
- the marked content sequence, if available
-
TextRenderInfo
private TextRenderInfo(TextRenderInfo parent, PdfString string, float horizontalOffset)
Used for creating sub-TextRenderInfos for each individual character- Parameters:
parent
- the parent TextRenderInfostring
- the content of a TextRenderInfohorizontalOffset
- the unscaled horizontal offset of the character that this TextRenderInfo represents- Since:
- 5.3.3
-
-
Method Detail
-
getText
public java.lang.String getText()
- Returns:
- the text to render
-
getPdfString
public PdfString getPdfString()
- Returns:
- original PDF string
-
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
- Since:
- 5.0.2
-
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
- Since:
- 5.3.5
-
getMcid
public java.lang.Integer getMcid()
- Returns:
- the marked content associated with the TextRenderInfo instance.
-
getUnscaledWidth
float getUnscaledWidth()
- Returns:
- the unscaled (i.e. in Text space) width of the text
-
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
- Since:
- 5.0.2
-
getUnscaledBaseline
public LineSegment getUnscaledBaseline()
-
getAscentLine
public LineSegment getAscentLine()
Gets the ascentline 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:
- the ascentline line segment
- Since:
- 5.0.2
-
getDescentLine
public LineSegment getDescentLine()
Gets the descentline 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:
- the descentline line segment
- Since:
- 5.0.2
-
getUnscaledBaselineWithOffset
private LineSegment getUnscaledBaselineWithOffset(float yOffset)
-
getFont
public DocumentFont getFont()
Getter for the font- Returns:
- the font
- Since:
- iText 5.0.2
-
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)
- Since:
- 5.3.3
-
convertWidthFromTextSpaceToUserSpace
private float convertWidthFromTextSpaceToUserSpace(float width)
- Parameters:
width
- the width, in text space- Returns:
- the width in user space
- Since:
- 5.3.3
-
convertHeightFromTextSpaceToUserSpace
private float convertHeightFromTextSpaceToUserSpace(float height)
- Parameters:
height
- the height, in text space- Returns:
- the height in user space
- Since:
- 5.3.3
-
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
- Since:
- iText 5.0.1
-
getFillColor
public BaseColor getFillColor()
- Returns:
- the current fill color.
-
getStrokeColor
public BaseColor getStrokeColor()
- Returns:
- the current stroke color.
-
getUnscaledFontSpaceWidth
private float getUnscaledFontSpaceWidth()
Calculates the width of a space character. If the font does not define a width for a standard space character , we also attempt to use the width of (a non-breaking space in many fonts)- Returns:
- the width of a single space character in text space units
-
getStringWidth
private float getStringWidth(java.lang.String string)
Gets the width of a String in text space units- Parameters:
string
- the string that needs measuring- Returns:
- the width of a String 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
-
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 - Since:
- 5.3.3
-
getWidthAndWordSpacing
private float[] getWidthAndWordSpacing(PdfString string, boolean singleCharString)
Calculates width and word spacing of a single character PDF string.- Parameters:
string
- a character to calculate width.singleCharString
- true if PDF string represents single character, false otherwise.- Returns:
- array of 2 items: first item is a character width, second item is a calculated word spacing.
-
decode
private java.lang.String decode(PdfString in)
Decodes a PdfString (which will contain glyph ids encoded in the font's encoding) based on the active font, and determine the unicode equivalent- Parameters:
in
- the String that needs to be encoded- Returns:
- the encoded String
-
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.
-
-