Package org.apache.pdfbox.pdmodel.font
Class PDTrueTypeFont
java.lang.Object
org.apache.pdfbox.pdmodel.font.PDFont
org.apache.pdfbox.pdmodel.font.PDSimpleFont
org.apache.pdfbox.pdmodel.font.PDTrueTypeFont
- All Implemented Interfaces:
COSObjectable
This is the TrueType implementation of fonts.
- Author:
- Ben Litchfield
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
This is the key to a property in the PDFBox_External_Fonts.properties file to load a Font when a mapping does not exist for the current font.Fields inherited from class org.apache.pdfbox.pdmodel.font.PDFont
cmap, cmapObjects, font, fontMatrix, resourceRootCMAP, toUnicodeCmap
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Calling this will release all cached information.Looks up, creates, returns the AWT Font.float
getFontWidth
(int charCode) Determines the width of the given character.Return the TTF font as TrueTypeFont.static PDTrueTypeFont
This will load a TTF to be embedded into a document.static PDTrueTypeFont
loadTTF
(PDDocument doc, File file) This will load a TTF to be embedded into a document.static PDTrueTypeFont
loadTTF
(PDDocument doc, InputStream stream) This will load a TTF to be embedded into a document.static PDTrueTypeFont
loadTTF
(PDDocument doc, InputStream stream, Encoding enc) This will load a TTF to be embedded into a document.static PDTrueTypeFont
loadTTF
(PDDocument doc, String file) This will load a TTF font from a font file.Methods inherited from class org.apache.pdfbox.pdmodel.font.PDSimpleFont
determineEncoding, drawString, getAverageFontWidth, getFontBoundingBox, getFontHeight, getFontWidth, getSpaceWidth, getToUnicode, isFontSubstituted, setIsFontSubstituted, setToUnicode, writeFont
Methods inherited from class org.apache.pdfbox.pdmodel.font.PDFont
clearResources, cmapEncoding, drawString, encode, encodeToCID, equals, getAFM, getAverageFontWidthFromAFMFile, getBaseFont, getCodeFromArray, getCOSObject, getEncoding, getFirstChar, getFontDescriptor, getFontEncoding, getFontMatrix, getFontWidthFromAFMFile, getLastChar, getStringFromArray, getStringWidth, getSubType, getToUnicodeCMap, getType, getWidths, hashCode, hasToUnicode, isSymbolicFont, isType0Font, isType1Font, isType3Font, parseCmap, setBaseFont, setEncoding, setFirstChar, setFontDescriptor, setFontEncoding, setHasToUnicode, setLastChar, setWidths
-
Field Details
-
UNKNOWN_FONT
This is the key to a property in the PDFBox_External_Fonts.properties file to load a Font when a mapping does not exist for the current font.- See Also:
-
-
Constructor Details
-
PDTrueTypeFont
public PDTrueTypeFont()Constructor. -
PDTrueTypeFont
Constructor.- Parameters:
fontDictionary
- The font dictionary according to the PDF specification.- Throws:
IOException
- exception if something went wrong when loading the font.
-
-
Method Details
-
loadTTF
This will load a TTF font from a font file.- Parameters:
doc
- The PDF document that will hold the embedded font.file
- The file on the filesystem that holds the font file.- Returns:
- A true type font.
- Throws:
IOException
- If there is an error loading the file data.
-
loadTTF
This will load a TTF to be embedded into a document.- Parameters:
doc
- The PDF document that will hold the embedded font.file
- a ttf file.- Returns:
- a PDTrueTypeFont instance.
- Throws:
IOException
- If there is an error loading the data.
-
loadTTF
This will load a TTF to be embedded into a document.- Parameters:
doc
- The PDF document that will hold the embedded font.stream
- a ttf input stream.- Returns:
- a PDTrueTypeFont instance.
- Throws:
IOException
- If there is an error loading the data.
-
loadTTF
public static PDTrueTypeFont loadTTF(PDDocument doc, InputStream stream, Encoding enc) throws IOException This will load a TTF to be embedded into a document.- Parameters:
doc
- The PDF document that will hold the embedded font.stream
- a ttf input stream.enc
- The font encoding.- Returns:
- a PDTrueTypeFont instance.
- Throws:
IOException
- If there is an error loading the data.
-
loadTTF
This will load a TTF to be embedded into a document.- Parameters:
fontStream
- a ttf input stream.enc
- The font encoding.- Returns:
- a PDTrueTypeFont instance.
- Throws:
IOException
- If there is an error loading the data.
-
getawtFont
Looks up, creates, returns the AWT Font.- Overrides:
getawtFont
in classPDSimpleFont
- Returns:
- returns the awt font to bes used for rendering
- Throws:
IOException
- if something went wrong.
-
getTTFFont
Return the TTF font as TrueTypeFont.- Returns:
- the TTF font
- Throws:
IOException
- If there is an error loading the data
-
clear
public void clear()Description copied from class:PDFont
Calling this will release all cached information. -
getFontWidth
public float getFontWidth(int charCode) Description copied from class:PDFont
Determines the width of the given character.- Overrides:
getFontWidth
in classPDFont
- Parameters:
charCode
- the code of the given character- Returns:
- the width of the character
-