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 the PdfCanvasProcessor and IEventListener objects as text rendering operations are discovered
  • 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 displayed
      gs - 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 operation
      canvasTagHierarchy - the marked content tags sequence, if available
  • Method Details

    • getText

      public 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 this TextRenderInfo instance belongs to a marked content sequence with a given mcid.
      Parameters:
      mcid - a marked content id
      Returns:
      true if this TextRenderInfo instance is marked with this id, false otherwise
    • hasMcid

      public boolean hasMcid (int mcid, boolean checkTheTopmostLevelOnly)
      Checks if this TextRenderInfo instance belongs to a marked content sequence with a given mcid.
      Parameters:
      mcid - a marked content id
      checkTheTopmostLevelOnly - indicates whether to check the topmost level of marked content stack only
      Returns:
      true if this TextRenderInfo instance is marked with this id, false otherwise
    • getMcid

      public int getMcid()
      Gets the marked-content identifier associated with this TextRenderInfo 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 - see getRise() 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 - see getRise() 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 - see getRise() 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. The getBaseline(), getAscentLine() and getDescentLine() 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 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 String getActualText()
      Gets /ActualText tag entry value if this text chunk is marked content.
      Returns:
      /ActualText value or null if none found
    • getExpansionText

      public 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 this TextRenderInfo 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 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