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 |
getNormalizedPath(int code)
Returns the normalized glyph path for the given character code in a PDF.
|
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 in a PDF.
|
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 |
load(PDDocument doc,
org.apache.pdfbox.io.RandomAccessRead randomAccessRead,
Encoding encoding)
Loads a TTF to be embedded into a document as a simple font.
|
static PDTrueTypeFont |
load(PDDocument doc,
org.apache.fontbox.ttf.TrueTypeFont ttf,
Encoding encoding)
Loads a TTF to be embedded into a document as a simple font.
|
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, hasExplicitWidth, isFontSymbolic, isNonZeroBoundingBox, isStandard14, isSymbolic, isVertical, readEncoding, subset, toUnicode, toUnicode, willBeSubsetencode, equals, getAverageFontWidth, getCOSObject, getDisplacement, getFontDescriptor, getFontMatrix, getPositionVector, getSpaceWidth, getStandard14AFM, getStringWidth, getSubType, getToUnicodeCMap, getType, getWidth, getWidths, hashCode, readCMap, setFontDescriptor, toStringpublic PDTrueTypeFont(COSDictionary fontDictionary) throws IOException
fontDictionary - The font dictionary according to the PDF specification.IOException - if the font could not be createdpublic 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.public static PDTrueTypeFont load(PDDocument doc, org.apache.fontbox.ttf.TrueTypeFont ttf, 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.ttf - A true type fontencoding - The PostScript encoding vector to be used for embedding.IOException - If there is an error loading the data.public static PDTrueTypeFont load(PDDocument doc, org.apache.pdfbox.io.RandomAccessRead randomAccessRead, 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.randomAccessRead - the source of the TTF.encoding - The PostScript encoding vector to be used for embedding.IOException - 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 PDFontLikepublic org.apache.fontbox.util.BoundingBox getBoundingBox()
throws IOException
PDFontLikegetBoundingBox in interface PDFontLikeIOException - if the bounding box could not be readpublic boolean isDamaged()
PDFontLikeisDamaged in interface PDFontLikepublic org.apache.fontbox.ttf.TrueTypeFont getTrueTypeFont()
public float getWidthFromFont(int code)
throws IOException
PDFontLikegetWidthFromFont in interface PDFontLikecode - 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. See the cyan rectangles in the
DrawPrintTextLocations.java example to see this in action.
getHeight in interface PDFontLikecode - character codeIOException - if the height could not be readprotected 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
IOException - if the data could not be readpublic boolean isEmbedded()
PDFontLikeisEmbedded in interface PDFontLikepublic 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 PDSimpleFontname - glyph nameIOException - if the path could not be readpublic GeneralPath getNormalizedPath(int code) throws IOException
PDVectorFontgetNormalizedPath in interface PDVectorFontcode - character code in a PDF. Not to be confused with unicode.IOException - if the font could not be readpublic boolean hasGlyph(String name) throws IOException
PDSimpleFonthasGlyph in class PDSimpleFontname - glyph nameIOException - 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.IOException - if the font could not be readpublic int codeToGID(int code)
throws IOException
code - character codeIOException - if the data could not be readCopyright © 2002–2022 The Apache Software Foundation. All rights reserved.