Class TextPosition


  • public final class TextPosition
    extends Object
    This represents a string and a position on the screen of those characters.
    • Constructor Summary

      Constructors 
      Constructor Description
      TextPosition​(int pageRotation, float pageWidth, float pageHeight, Matrix textMatrix, float endX, float endY, float maxHeight, float individualWidth, float spaceWidth, String unicode, int[] charCodes, PDFont font, float fontSize, int fontSizeInPt)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(TextPosition tp2)
      Determine if this TextPosition logically contains another (i.e.
      int[] getCharacterCodes()
      Return the internal PDF character codes of the glyphs in this text.
      float getDir()
      Return the direction/orientation of the string in this object based on its text matrix.
      PDFont getFont()
      This will get the font for the text being drawn.
      float getFontSize()
      This will get the font size that this object is suppose to be drawn at.
      float getFontSizeInPt()
      This will get the font size in pt.
      float getHeight()
      This will get the maximum height of all characters in this string.
      float getHeightDir()
      This will get the maximum height of all characters in this string.
      float[] getIndividualWidths()
      Get the widths of each individual character.
      Matrix getTextMatrix()
      Return the text matrix stored in this object.
      String getUnicode()
      Return the string of characters stored in this object.
      float getWidth()
      This will get the width of the string when page rotation adjusted coordinates are used.
      float getWidthDirAdj()
      This will get the width of the string when text direction adjusted coordinates are used.
      float getWidthOfSpace()
      This will get the width of a space character.
      float getX()
      This will get the page rotation adjusted x position of the character.
      float getXDirAdj()
      This will get the text direction adjusted x position of the character.
      float getXScale()  
      float getY()
      This will get the y position of the text, adjusted so that 0,0 is upper left and it is adjusted based on the page rotation.
      float getYDirAdj()
      This will get the y position of the text, adjusted so that 0,0 is upper left and it is adjusted based on the text direction.
      float getYScale()  
      boolean isDiacritic()  
      void mergeDiacritic​(TextPosition diacritic)
      Merge a single character TextPosition into the current object.
      String toString()
      Show the string data for this text position.
    • Constructor Detail

      • TextPosition

        public TextPosition​(int pageRotation,
                            float pageWidth,
                            float pageHeight,
                            Matrix textMatrix,
                            float endX,
                            float endY,
                            float maxHeight,
                            float individualWidth,
                            float spaceWidth,
                            String unicode,
                            int[] charCodes,
                            PDFont font,
                            float fontSize,
                            int fontSizeInPt)
        Constructor.
        Parameters:
        pageRotation - rotation of the page that the text is located in
        pageWidth - rotation of the page that the text is located in
        pageHeight - rotation of the page that the text is located in
        textMatrix - TextMatrix for start of text (in display units)
        endX - x coordinate of the end position
        endY - y coordinate of the end position
        maxHeight - Maximum height of text (in display units)
        individualWidth - The width of the given character/string. (in text units)
        spaceWidth - The width of the space character. (in display units)
        unicode - The string of Unicode characters to be displayed.
        charCodes - An array of the internal PDF character codes for the glyphs in this text.
        font - The current font for this text position.
        fontSize - The new font size.
        fontSizeInPt - The font size in pt units.
    • Method Detail

      • getUnicode

        public String getUnicode()
        Return the string of characters stored in this object.
        Returns:
        The string on the screen.
      • getCharacterCodes

        public int[] getCharacterCodes()
        Return the internal PDF character codes of the glyphs in this text.
        Returns:
        an array of internal PDF character codes
      • getTextMatrix

        public Matrix getTextMatrix()
        Return the text matrix stored in this object.
        Returns:
        The Matrix containing the starting text position
      • getDir

        public float getDir()
        Return the direction/orientation of the string in this object based on its text matrix.
        Returns:
        The direction of the text (0, 90, 180, or 270)
      • getX

        public float getX()
        This will get the page rotation adjusted x position of the character. This is adjusted based on page rotation so that the upper left is 0,0.
        Returns:
        The x coordinate of the character.
      • getXDirAdj

        public float getXDirAdj()
        This will get the text direction adjusted x position of the character. This is adjusted based on text direction so that the first character in that direction is in the upper left at 0,0.
        Returns:
        The x coordinate of the text.
      • getY

        public float getY()
        This will get the y position of the text, adjusted so that 0,0 is upper left and it is adjusted based on the page rotation.
        Returns:
        The adjusted y coordinate of the character.
      • getYDirAdj

        public float getYDirAdj()
        This will get the y position of the text, adjusted so that 0,0 is upper left and it is adjusted based on the text direction.
        Returns:
        The adjusted y coordinate of the character.
      • getWidth

        public float getWidth()
        This will get the width of the string when page rotation adjusted coordinates are used.
        Returns:
        The width of the text in display units.
      • getWidthDirAdj

        public float getWidthDirAdj()
        This will get the width of the string when text direction adjusted coordinates are used.
        Returns:
        The width of the text in display units.
      • getHeight

        public float getHeight()
        This will get the maximum height of all characters in this string.
        Returns:
        The maximum height of all characters in this string.
      • getHeightDir

        public float getHeightDir()
        This will get the maximum height of all characters in this string.
        Returns:
        The maximum height of all characters in this string.
      • getFontSize

        public float getFontSize()
        This will get the font size that this object is suppose to be drawn at.
        Returns:
        The font size.
      • getFontSizeInPt

        public float getFontSizeInPt()
        This will get the font size in pt. To get this size we have to multiply the pdf-fontsize and the scaling from the textmatrix
        Returns:
        The font size in pt.
      • getFont

        public PDFont getFont()
        This will get the font for the text being drawn.
        Returns:
        The font size.
      • getWidthOfSpace

        public float getWidthOfSpace()
        This will get the width of a space character. This is useful for some algorithms such as the text stripper, that need to know the width of a space character.
        Returns:
        The width of a space character.
      • getXScale

        public float getXScale()
        Returns:
        Returns the xScale.
      • getYScale

        public float getYScale()
        Returns:
        Returns the yScale.
      • getIndividualWidths

        public float[] getIndividualWidths()
        Get the widths of each individual character.
        Returns:
        An array that is the same length as the length of the string.
      • contains

        public boolean contains​(TextPosition tp2)
        Determine if this TextPosition logically contains another (i.e. they overlap and should be rendered on top of each other).
        Parameters:
        tp2 - The other TestPosition to compare against
        Returns:
        True if tp2 is contained in the bounding box of this text.
      • mergeDiacritic

        public void mergeDiacritic​(TextPosition diacritic)
        Merge a single character TextPosition into the current object. This is to be used only for cases where we have a diacritic that overlaps an existing TextPosition. In a graphical display, we could overlay them, but for text extraction we need to merge them. Use the contains() method to test if two objects overlap.
        Parameters:
        diacritic - TextPosition to merge into the current TextPosition.
      • isDiacritic

        public boolean isDiacritic()
        Returns:
        True if the current character is a diacritic char.
      • toString

        public String toString()
        Show the string data for this text position.
        Overrides:
        toString in class Object
        Returns:
        A human readable form of this object.