public class PDTrueTypeFont extends PDSimpleFont implements PDVectorFont
encoding, glyphListDEFAULT_FONT_MATRIX, dict| Constructor and Description |
|---|
PDTrueTypeFont(COSDictionary fontDictionary)
Creates a new TrueType font from a Font dictionary.
|
| Modifier and Type | Method and Description |
|---|---|
int |
codeToGID(int code)
Returns the GID for the given character code.
|
protected byte[] |
encode(int unicode)
Encodes the given Unicode code point for use in a PDF content stream.
|
String |
getBaseFont()
Returns the PostScript name of the font.
|
org.apache.fontbox.util.BoundingBox |
getBoundingBox()
Returns the font's bounding box.
|
org.apache.fontbox.FontBoxFont |
getFontBoxFont()
Returns the embedded or system font used for rendering.
|
protected Map<Integer,Integer> |
getGIDToCode()
Inverts the font's code -> GID mapping.
|
float |
getHeight(int code)
Returns the height of the given character, in glyph space.
|
String |
getName()
Returns the name of this font, either the PostScript "BaseName" or the Type 3 "Name".
|
GeneralPath |
getPath(int code)
Returns the glyph path for the given character code.
|
GeneralPath |
getPath(String name)
Returns the path for the character with the given name.
|
org.apache.fontbox.ttf.TrueTypeFont |
getTrueTypeFont()
Returns the embedded or substituted TrueType font.
|
float |
getWidthFromFont(int code)
Returns the width of a glyph in the embedded font file.
|
boolean |
hasGlyph(int code)
Returns true if this font contains a glyph for the given character code.
|
boolean |
hasGlyph(String name)
Returns true if the font contains the character with the given name.
|
boolean |
isDamaged()
Returns true if the embedded font file is damaged.
|
boolean |
isEmbedded()
Returns true if the font file is embedded in the PDF.
|
static PDTrueTypeFont |
load(PDDocument doc,
File file,
Encoding encoding)
Loads a TTF to be embedded into a document as a simple font.
|
static PDTrueTypeFont |
load(PDDocument doc,
InputStream input,
Encoding encoding)
Loads a TTF to be embedded into a document as a simple font.
|
static PDTrueTypeFont |
loadTTF(PDDocument doc,
File file)
Deprecated.
Use
PDType0Font.load(PDDocument, File) instead. |
static PDTrueTypeFont |
loadTTF(PDDocument doc,
InputStream input)
Deprecated.
Use
PDType0Font.load(PDDocument, InputStream) instead. |
int |
readCode(InputStream in)
Reads a character code from a content stream string.
|
protected Encoding |
readEncodingFromFont()
Called by readEncoding() if the encoding needs to be extracted from the font file.
|
addToSubset, getEncoding, getGlyphList, getStandard14Width, getSymbolicFlag, isFontSymbolic, isStandard14, isSymbolic, isVertical, readEncoding, subset, toUnicode, toUnicode, willBeSubsetencode, equals, getAverageFontWidth, getCOSObject, getDisplacement, getFontDescriptor, getFontMatrix, getPositionVector, getSpaceWidth, getStandard14AFM, getStringWidth, getSubType, getType, getWidth, getWidths, hashCode, readCMap, setFontDescriptor, toStringpublic PDTrueTypeFont(COSDictionary fontDictionary) throws IOException
fontDictionary - The font dictionary according to the PDF specification.IOExceptionpublic static PDTrueTypeFont load(PDDocument doc, File file, Encoding encoding) throws IOException
Note: Simple fonts only support 256 characters. For Unicode support, use
PDType0Font.load(PDDocument, File) instead.
doc - The PDF document that will hold the embedded font.file - A TTF file.encoding - The PostScript encoding vector to be used for embedding.IOException - If there is an error loading the data.public static PDTrueTypeFont load(PDDocument doc, InputStream input, Encoding encoding) throws IOException
Note: Simple fonts only support 256 characters. For Unicode support, use
PDType0Font.load(PDDocument, InputStream) instead.
doc - The PDF document that will hold the embedded font.input - A TTF file streamencoding - The PostScript encoding vector to be used for embedding.IOException - If there is an error loading the data.@Deprecated public static PDTrueTypeFont loadTTF(PDDocument doc, File file) throws IOException
PDType0Font.load(PDDocument, File) instead.doc - The PDF document that will hold the embedded font.file - A TTF file.IOException - If there is an error loading the data.@Deprecated public static PDTrueTypeFont loadTTF(PDDocument doc, InputStream input) throws IOException
PDType0Font.load(PDDocument, InputStream) instead.doc - The PDF document that will hold the embedded font.input - A TTF file streamIOException - If there is an error loading the data.public final String getBaseFont()
protected Encoding readEncodingFromFont() throws IOException
PDSimpleFontreadEncodingFromFont in class PDSimpleFontIOException - if the font file could not be read.public int readCode(InputStream in) throws IOException
PDFontreadCode in class PDFontin - string streamIOException - if the CMap or stream cannot be readpublic String getName()
PDFontLikegetName in interface PDFontLikegetName in class PDFontpublic org.apache.fontbox.util.BoundingBox getBoundingBox()
throws IOException
PDFontLikegetBoundingBox in interface PDFontLikegetBoundingBox in class PDFontIOExceptionpublic boolean isDamaged()
PDFontLikeisDamaged in interface PDFontLikeisDamaged in class PDFontpublic org.apache.fontbox.ttf.TrueTypeFont getTrueTypeFont()
public float getWidthFromFont(int code)
throws IOException
PDFontLikegetWidthFromFont in interface PDFontLikegetWidthFromFont in class PDFontcode - character codeIOException - if the font could not be readpublic float getHeight(int code)
throws IOException
PDFontLike
Warning: This method is deprecated in PDFBox 2.0 because there is no meaningful value
which it can return. The PDFontLike.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 PDFontLikegetHeight in class PDFontcode - character codeIOExceptionprotected byte[] encode(int unicode)
throws IOException
PDFontThis method is called when embedding text in PDFs and when filling in fields.
encode in class PDFontunicode - Unicode code point.IOException - If the text could not be encoded.protected Map<Integer,Integer> getGIDToCode() throws IOException
IOExceptionpublic boolean isEmbedded()
PDFontLikeisEmbedded in interface PDFontLikeisEmbedded in class PDFontpublic GeneralPath getPath(int code) throws IOException
PDVectorFontgetPath in interface PDVectorFontcode - character code in a PDF. Not to be confused with unicode.IOException - if the font could not be readpublic GeneralPath getPath(String name) throws IOException
PDSimpleFontgetPath in class PDSimpleFontIOException - if the path could not be readpublic boolean hasGlyph(String name) throws IOException
PDSimpleFonthasGlyph in class PDSimpleFontIOException - if the path could not be readpublic org.apache.fontbox.FontBoxFont getFontBoxFont()
PDSimpleFontgetFontBoxFont in class PDSimpleFontpublic boolean hasGlyph(int code)
throws IOException
PDVectorFonthasGlyph in interface PDVectorFontcode - character code in a PDF. Not to be confused with unicode.IOExceptionpublic int codeToGID(int code)
throws IOException
code - character codeIOExceptionCopyright © 2002–2017 The Apache Software Foundation. All rights reserved.