public class PDTrueTypeFont extends PDSimpleFont implements PDVectorFont
encoding, glyphList
DEFAULT_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.
|
BoundingBox |
getBoundingBox()
Returns the font's bounding box.
|
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.
|
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, willBeSubset
encode, equals, getAverageFontWidth, getCOSObject, getDisplacement, getFontDescriptor, getFontMatrix, getPositionVector, getSpaceWidth, getStandard14AFM, getStringWidth, getSubType, getType, getWidth, getWidths, hashCode, readCMap, setFontDescriptor, toString
public PDTrueTypeFont(COSDictionary fontDictionary) throws IOException
fontDictionary
- The font dictionary according to the PDF specification.IOException
public 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
PDSimpleFont
readEncodingFromFont
in class PDSimpleFont
IOException
- if the font file could not be read.public int readCode(InputStream in) throws IOException
PDFont
readCode
in class PDFont
in
- string streamIOException
- if the CMap or stream cannot be readpublic String getName()
PDFontLike
getName
in interface PDFontLike
getName
in class PDFont
public BoundingBox getBoundingBox() throws IOException
PDFontLike
getBoundingBox
in interface PDFontLike
getBoundingBox
in class PDFont
IOException
public boolean isDamaged()
PDFontLike
isDamaged
in interface PDFontLike
isDamaged
in class PDFont
public TrueTypeFont getTrueTypeFont()
public float getWidthFromFont(int code) throws IOException
PDFontLike
getWidthFromFont
in interface PDFontLike
getWidthFromFont
in class PDFont
code
- character codeIOException
- if the font could not be readpublic float getHeight(int code) throws IOException
PDFontLike
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 PDFontLike
getHeight
in class PDFont
code
- character codeIOException
protected byte[] encode(int unicode) throws IOException
PDFont
This method is called when embedding text in PDFs and when filling in fields.
encode
in class PDFont
unicode
- Unicode code point.IOException
- If the text could not be encoded.protected Map<Integer,Integer> getGIDToCode() throws IOException
IOException
public boolean isEmbedded()
PDFontLike
isEmbedded
in interface PDFontLike
isEmbedded
in class PDFont
public GeneralPath getPath(int code) throws IOException
PDVectorFont
getPath
in interface PDVectorFont
code
- character codeIOException
- if the font could not be readpublic GeneralPath getPath(String name) throws IOException
PDSimpleFont
getPath
in class PDSimpleFont
IOException
- if the path could not be readpublic boolean hasGlyph(String name) throws IOException
PDSimpleFont
hasGlyph
in class PDSimpleFont
IOException
- if the path could not be readpublic FontBoxFont getFontBoxFont()
PDSimpleFont
getFontBoxFont
in class PDSimpleFont
public boolean hasGlyph(int code) throws IOException
PDVectorFont
hasGlyph
in interface PDVectorFont
code
- character codeIOException
public int codeToGID(int code) throws IOException
code
- character codeIOException
Copyright © 2002–2016 The Apache Software Foundation. All rights reserved.