public abstract class PDFont extends Object implements COSObjectable, PDFontLike, Subsettable
| Modifier and Type | Field and Description |
|---|---|
protected static Matrix |
DEFAULT_FONT_MATRIX |
protected COSDictionary |
dict |
| Modifier | Constructor and Description |
|---|---|
protected |
PDFont(COSDictionary fontDictionary)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract byte[] |
encode(int unicode)
Encodes the given Unicode code point for use in a PDF content stream.
|
byte[] |
encode(String text)
Encodes the given string for use in a PDF content stream.
|
byte[] |
encodeLeniently(String text)
Similar to encode() but handles leniently cases where fonts don't have a glyph by assuming the identity mapping
|
boolean |
equals(Object other) |
float |
getAverageFontWidth()
This will get the average font width for all characters.
|
abstract org.apache.fontbox.util.BoundingBox |
getBoundingBox()
Returns the font's bounding box.
|
COSDictionary |
getCOSObject() |
Vector |
getDisplacement(int code)
Returns the displacement vector (w0, w1) in text space, for the given character.
|
PDFontDescriptor |
getFontDescriptor()
Returns the font descriptor, may be null.
|
Matrix |
getFontMatrix()
Returns the font matrix, which represents the transformation from glyph space to text space.
|
abstract float |
getHeight(int code)
Returns the height of the given character, in glyph space.
|
abstract String |
getName()
Returns the name of this font, either the PostScript "BaseName" or the Type 3 "Name".
|
Vector |
getPositionVector(int code)
Returns the position vector (v), in text space, for the given character.
|
float |
getSpaceWidth()
Determines the width of the space character.
|
protected org.apache.fontbox.afm.FontMetrics |
getStandard14AFM()
Returns the AFM if this is a Standard 14 font.
|
protected abstract float |
getStandard14Width(int code)
Returns the glyph width from the AFM if this is a Standard 14 font.
|
float |
getStringWidth(String text)
Returns the width of the given Unicode string.
|
float |
getStringWidthLeniently(String text)
Similar to getStringWidth() but handles leniently fonts where glyphs are missing, assuming the identity mapping
of glyphs
Uses encodeLeniently() instead of encode()
|
String |
getSubType()
This will get the subtype of font.
|
protected org.apache.fontbox.cmap.CMap |
getToUnicodeCMap() |
String |
getType()
This will always return "Font" for fonts.
|
float |
getWidth(int code)
Returns the advance width of the given character, in glyph space.
|
abstract float |
getWidthFromFont(int code)
Returns the width of a glyph in the embedded font file.
|
protected List<Float> |
getWidths()
The widths of the characters.
|
int |
hashCode() |
abstract boolean |
isDamaged()
Returns true if the embedded font file is damaged.
|
abstract boolean |
isEmbedded()
Returns true if the font file is embedded in the PDF.
|
boolean |
isStandard14()
Returns true if this font is one of the "Standard 14" fonts and receives special handling.
|
abstract boolean |
isVertical()
Returns true if the font uses vertical writing mode.
|
protected org.apache.fontbox.cmap.CMap |
readCMap(COSBase base)
/** Reads a CMap given a COS Stream or Name.
|
abstract int |
readCode(InputStream in)
Reads a character code from a content stream string.
|
protected void |
setFontDescriptor(PDFontDescriptor fontDescriptor)
Sets the font descriptor when embedding a font.
|
String |
toString() |
String |
toUnicode(int code)
Returns the Unicode character sequence which corresponds to the given character code.
|
String |
toUnicode(int code,
GlyphList customGlyphList)
Returns the Unicode character sequence which corresponds to the given character code.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waithasExplicitWidthaddToSubset, subset, willBeSubsetprotected static final Matrix DEFAULT_FONT_MATRIX
protected final COSDictionary dict
protected PDFont(COSDictionary fontDictionary) throws IOException
fontDictionary - Font dictionary.IOExceptionprotected final org.apache.fontbox.afm.FontMetrics getStandard14AFM()
public PDFontDescriptor getFontDescriptor()
PDFontLikegetFontDescriptor in interface PDFontLikeprotected final void setFontDescriptor(PDFontDescriptor fontDescriptor)
protected final org.apache.fontbox.cmap.CMap readCMap(COSBase base) throws IOException
base - COSName or COSStreamIOExceptionpublic COSDictionary getCOSObject()
getCOSObject in interface COSObjectableCOSBase that matches this Java object.public Vector getPositionVector(int code)
PDFontLikegetPositionVector in interface PDFontLikecode - character codepublic Vector getDisplacement(int code) throws IOException
code - character codeIOExceptionpublic float getWidth(int code)
throws IOException
PDFontLikegetWidth in interface PDFontLikecode - character codeIOExceptionprotected abstract float getStandard14Width(int code)
code - character codepublic abstract float getWidthFromFont(int code)
throws IOException
PDFontLikegetWidthFromFont in interface PDFontLikecode - character codeIOException - if the font could not be readpublic abstract boolean isEmbedded()
PDFontLikeisEmbedded in interface PDFontLikepublic abstract float getHeight(int code)
throws IOException
PDFontLikePDFontLike.getWidth(int) method returns the advance width of a glyph, but there is no corresponding advance height. The
logical height of a character is the same for every character in a font, so if you want that, retrieve the font
bbox's height. Otherwise if you want the visual bounds of the glyph then call getPath(..) on the appropriate
PDFont subclass to retrieve the glyph outline as a GeneralPath.getHeight in interface PDFontLikecode - character codeIOExceptionpublic final byte[] encode(String text) throws IOException
text - Any Unicode text.IOException - If the text could not be encoded.public final byte[] encodeLeniently(String text) throws IOException
IOExceptionprotected abstract byte[] encode(int unicode)
throws IOException
This method is called when embedding text in PDFs and when filling in fields.
unicode - Unicode code point.IOException - If the text could not be encoded.public float getStringWidth(String text) throws IOException
text - The text to get the width of.IOException - If there is an error getting the width information.public float getStringWidthLeniently(String text) throws IOException
IOExceptionpublic float getAverageFontWidth()
getAverageFontWidth in interface PDFontLikepublic abstract int readCode(InputStream in) throws IOException
in - string streamIOException - if the CMap or stream cannot be readpublic String toUnicode(int code, GlyphList customGlyphList) throws IOException
code - character codecustomGlyphList - a custom glyph list to use instead of the Adobe Glyph ListIOExceptionpublic String toUnicode(int code) throws IOException
code - character codeIOExceptionpublic String getType()
public String getSubType()
public abstract String getName()
PDFontLikegetName in interface PDFontLikepublic abstract org.apache.fontbox.util.BoundingBox getBoundingBox()
throws IOException
PDFontLikegetBoundingBox in interface PDFontLikeIOExceptionprotected final List<Float> getWidths()
public Matrix getFontMatrix()
PDFontLikegetFontMatrix in interface PDFontLikepublic float getSpaceWidth()
public abstract boolean isVertical()
public boolean isStandard14()
public abstract boolean isDamaged()
PDFontLikeisDamaged in interface PDFontLikeprotected org.apache.fontbox.cmap.CMap getToUnicodeCMap()
Copyright © 2019 sejda. All rights reserved.