Package com.tom_roush.pdfbox.text
Class TextPosition
- java.lang.Object
-
- com.tom_roush.pdfbox.text.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 booleancontains(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.floatgetDir()Return the direction/orientation of the string in this object based on its text matrix.PDFontgetFont()This will get the font for the text being drawn.floatgetFontSize()This will get the font size that this object is suppose to be drawn at.floatgetFontSizeInPt()This will get the font size in pt.floatgetHeight()This will get the maximum height of all characters in this string.floatgetHeightDir()This will get the maximum height of all characters in this string.float[]getIndividualWidths()Get the widths of each individual character.MatrixgetTextMatrix()Return the text matrix stored in this object.StringgetUnicode()Return the string of characters stored in this object.floatgetWidth()This will get the width of the string when page rotation adjusted coordinates are used.floatgetWidthDirAdj()This will get the width of the string when text direction adjusted coordinates are used.floatgetWidthOfSpace()This will get the width of a space character.floatgetX()This will get the page rotation adjusted x position of the character.floatgetXDirAdj()This will get the text direction adjusted x position of the character.floatgetXScale()floatgetY()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.floatgetYDirAdj()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.floatgetYScale()booleanisDiacritic()voidmergeDiacritic(TextPosition diacritic)Merge a single character TextPosition into the current object.StringtoString()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 inpageWidth- rotation of the page that the text is located inpageHeight- rotation of the page that the text is located intextMatrix- TextMatrix for start of text (in display units)endX- x coordinate of the end positionendY- y coordinate of the end positionmaxHeight- 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.
-
-