public final class TextPosition
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private int[] |
charCodes |
private static java.util.Map<java.lang.Integer,java.lang.String> |
DIACRITICS |
private float |
direction |
private float |
endX |
private float |
endY |
private PDFont |
font |
private float |
fontSize |
private int |
fontSizePt |
private static org.apache.commons.logging.Log |
LOG |
private float |
maxHeight |
private float |
pageHeight |
private float |
pageWidth |
private int |
rotation |
private Matrix |
textMatrix |
private java.lang.String |
unicode |
private float |
widthOfSpace |
private float[] |
widths |
private float |
x |
private float |
y |
Constructor and Description |
---|
TextPosition(int pageRotation,
float pageWidth,
float pageHeight,
Matrix textMatrix,
float endX,
float endY,
float maxHeight,
float individualWidth,
float spaceWidth,
java.lang.String unicode,
int[] charCodes,
PDFont font,
float fontSize,
int fontSizeInPt)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
combineDiacritic(java.lang.String str)
Combine the diacritic, for example, convert non-combining diacritic characters to their
combining counterparts.
|
boolean |
contains(TextPosition tp2)
Determine if this TextPosition logically contains another (i.e.
|
private static java.util.Map<java.lang.Integer,java.lang.String> |
createDiacritics() |
boolean |
equals(java.lang.Object o) |
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.
|
float |
getEndX()
This will get the x coordinate of the end position.
|
float |
getEndY()
This will get the y coordinate of the end position.
|
PDFont |
getFont()
This will get the font for the text being drawn.
|
float |
getFontSize()
This will get the font size that has been set with the "Tf" operator (Set text font and
size).
|
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.
|
float |
getPageHeight()
This will get the height of the page that the text is located in.
|
float |
getPageWidth()
This will get the width of the page that the text is located in.
|
int |
getRotation()
This will get the rotation of the page that the text is located in.
|
Matrix |
getTextMatrix()
The matrix containing the starting text position and scaling.
|
java.lang.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.
|
private float |
getWidthRot(float rotation)
Get the length or width of the text, based on a given rotation.
|
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.
|
private float |
getXRot(float rotation)
Return the X starting coordinate of the text, adjusted by the given rotation amount.
|
float |
getXScale()
This will get the X scaling factor.
|
float |
getY()
This will get the page rotation adjusted x position of the character.
|
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.
|
private float |
getYLowerLeftRot(float rotation)
This will get the y position of the character with 0,0 in lower left.
|
float |
getYScale()
This will get the Y scaling factor.
|
int |
hashCode() |
private void |
insertDiacritic(int i,
TextPosition diacritic)
Inserts the diacritic TextPosition to the str of this TextPosition and updates the widths
array to include the extra character width.
|
boolean |
isDiacritic() |
void |
mergeDiacritic(TextPosition diacritic)
Merge a single character TextPosition into the current object.
|
java.lang.String |
toString()
Show the string data for this text position.
|
private static final org.apache.commons.logging.Log LOG
private static final java.util.Map<java.lang.Integer,java.lang.String> DIACRITICS
private final Matrix textMatrix
private final float endX
private final float endY
private final float maxHeight
private final int rotation
private final float x
private final float y
private final float pageHeight
private final float pageWidth
private final float widthOfSpace
private final int[] charCodes
private final PDFont font
private final float fontSize
private final int fontSizePt
private float[] widths
private java.lang.String unicode
private float direction
public TextPosition(int pageRotation, float pageWidth, float pageHeight, Matrix textMatrix, float endX, float endY, float maxHeight, float individualWidth, float spaceWidth, java.lang.String unicode, int[] charCodes, PDFont font, float fontSize, int fontSizeInPt)
pageRotation
- rotation of the page that the text is located inpageWidth
- width of the page that the text is located inpageHeight
- height of the page that the text is located intextMatrix
- text rendering matrix 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 (see getFontSizeInPt()
for details).private static java.util.Map<java.lang.Integer,java.lang.String> createDiacritics()
public java.lang.String getUnicode()
public int[] getCharacterCodes()
public Matrix getTextMatrix()
public float getDir()
TextPosition text = ... Matrix m = text.getTextMatrix().clone(); m.concatenate(text.getFont().getFontMatrix()); int angle = (int) Math.round(Math.toDegrees(Math.atan2(m.getShearY(), m.getScaleY())));
private float getXRot(float rotation)
rotation
- Rotation to apply (0, 90, 180, or 270). 0 will perform no adjustments.public float getX()
public float getXDirAdj()
getDir()
) and adjusts the coordinates to awt. This is useful when doing
text extraction, to compare the glyph positions when imagining these to be horizontal. See also
this answer by Michael Klink for
further details and
PDFBOX-4597 for a sample
file.private float getYLowerLeftRot(float rotation)
rotation
- Rotation to apply to text to adjust the 0,0 location (0,90,180,270)public float getY()
public float getYDirAdj()
private float getWidthRot(float rotation)
rotation
- Rotation that was used to determine coordinates (0,90,180,270)public float getWidth()
public float getWidthDirAdj()
public float getHeight()
public float getHeightDir()
public float getFontSize()
public float getFontSizeInPt()
getFontSize()
with the text matrix (set by the "Tm" operator)
horizontal scaling factor and truncate the result to integer. The actual rendering may appear
bigger or smaller depending on the current transformation matrix (set by the "cm" operator).
To get the size in rendering, use getXScale()
.public PDFont getFont()
public float getWidthOfSpace()
public float getXScale()
public float getYScale()
public float[] getIndividualWidths()
public boolean contains(TextPosition tp2)
tp2
- The other TestPosition to compare againstpublic void mergeDiacritic(TextPosition diacritic)
diacritic
- TextPosition to merge into the current TextPosition.private void insertDiacritic(int i, TextPosition diacritic)
i
- current characterdiacritic
- The diacritic TextPositionprivate java.lang.String combineDiacritic(java.lang.String str)
str
- String to normalizepublic boolean isDiacritic()
public java.lang.String toString()
toString
in class java.lang.Object
public float getEndX()
public float getEndY()
public int getRotation()
public float getPageHeight()
public float getPageWidth()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object