Class 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 the PdfContentStreamProcessor and RenderListener objects as text rendering operations are discovered
    • Field Detail

      • text

        private java.lang.String text
      • textToUserSpaceTransformMatrix

        private final Matrix textToUserSpaceTransformMatrix
      • 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 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
        markedContentInfo - 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 TextRenderInfo
        string - the content of a TextRenderInfo
        horizontalOffset - 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 id
        checkTheTopmostLevelOnly - 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 - see getRise() 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 - see getRise() 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 - see getRise() 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. 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)
        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.
      • splitString

        private PdfString[] splitString​(PdfString string)
        Split PDF string into array of single character PDF strings.
        Parameters:
        string - PDF string to be splitted.
        Returns:
        splitted PDF string.