Package com.itextpdf.io.font
Class Type1Font
java.lang.Object
com.itextpdf.io.font.FontProgram
com.itextpdf.io.font.Type1Font
Font program parsed from Adobe Type 1 AFM/PFM metrics and optional PFB outline data.
-
Field Summary
Fields inherited from class com.itextpdf.io.font.FontProgram
avgWidth, codeToGlyph, DEFAULT_WIDTH, encodingScheme, fontIdentification, fontMetrics, fontNames, HORIZONTAL_SCALING_FACTOR, isFontSpecific, registry, unicodeToGlyph, UNITS_NORMALIZATION -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates an empty Type 1 font program.protectedCreates a lightweight Type 1 font program for a named base font without parsing metrics.protectedCreates a Type 1 font program from AFM/PFM metrics and optional PFB data without remapping codes.protectedType1Font(String metricsPath, String binaryPath, byte[] afm, byte[] pfb, FontEncoding fontEncoding) Creates aType1Fontby parsing the AFM/PFM metrics and, optionally, the PFB binary data, then applying an explicit encoding to the resulting glyph maps. -
Method Summary
Modifier and TypeMethodDescriptionprotected static Type1FontcreateStandardFont(String name) Creates a font program for one of the PDF standard Type 1 fonts.Gets the AFMCharacterSetdeclaration.byte[]int[]Find glyph by glyph name.intgetKerning(Glyph first, Glyph second) Gets the kerning between two glyphs.intComputes the PDF font descriptor flags for this program.booleanChecks if the font has any kerning pairs.voidinitializeGlyphs(FontEncoding fontEncoding) Deprecated.to make privatebooleanChecks whether this program represents a built-in standard font.booleanisBuiltWith(String fontProgram) Checks whether theFontProgramwas built with corresponding fontName.protected voidprocess()Parses AFM/PFM metrics, character metrics, and kerning pairs into this font program.booleansetKerning(int first, int second, int kern) Sets the kerning between two Unicode chars.Methods inherited from class com.itextpdf.io.font.FontProgram
convertGlyphSpaceToTextSpace, convertGlyphSpaceToTextSpace, convertGlyphSpaceToTextSpace, convertTextSpaceToGlyphSpace, countOfGlyphs, fixSpaceIssue, getAvgWidth, getCharBBox, getFontIdentification, getFontMetrics, getFontNames, getGlyph, getGlyphByCode, getKerning, getRegistry, getWidth, isFontSpecific, setBbox, setBold, setCapHeight, setFixedPitch, setFontFamily, setFontName, setFontStretch, setFontWeight, setItalicAngle, setRegistry, setStemH, setStemV, setTypoAscender, setTypoDescender, setXHeight, toString
-
Constructor Details
-
Type1Font
protected Type1Font()Creates an empty Type 1 font program. -
Type1Font
protected Type1Font(String metricsPath, String binaryPath, byte[] afm, byte[] pfb) throws IOException Creates a Type 1 font program from AFM/PFM metrics and optional PFB data without remapping codes.- Parameters:
-
metricsPath- metrics file path, built-in font name, ornullwhenafmis supplied -
binaryPath- PFB path, ornullwhenpfbis supplied -
afm- AFM/PFM bytes, ornullwhenmetricsPathis supplied -
pfb- PFB bytes, ornullwhenbinaryPathis supplied - Throws:
-
IOException- if supplied font data cannot be read or parsed
-
Type1Font
protected Type1Font(String metricsPath, String binaryPath, byte[] afm, byte[] pfb, FontEncoding fontEncoding) throws IOException Creates aType1Fontby parsing the AFM/PFM metrics and, optionally, the PFB binary data, then applying an explicit encoding to the resulting glyph maps.The font source may be supplied either as file-system paths or as raw byte arrays; one pair (
metricsPath/binaryPathorafm/pfb) must be non-null. After parsing, iffontEncodingis non-null,initializeGlyphs(FontEncoding)is called to remap character codes according to that encoding.- Parameters:
-
metricsPath- path to the AFM or PFM metrics file, or a built-in standard font name, ornullifafmbytes are provided instead -
binaryPath- path to the PFB binary file, ornullifpfbbytes are provided or if the font is a built-in standard font -
afm- byte contents of the AFM or PFM metrics file, ornullifmetricsPathis provided instead -
pfb- byte contents of the PFB binary file, ornullifbinaryPathis provided or if the font is a built-in standard font -
fontEncoding- the encoding used to remap character codes to Unicode values after the font has been parsed; may benullto skip glyph remapping - Throws:
-
IOException- if an I/O error occurs while reading the metrics or binary file, or if the AFM/PFM data is malformed
-
Type1Font
Creates a lightweight Type 1 font program for a named base font without parsing metrics.- Parameters:
-
baseFont- PostScript base-font name
-
-
Method Details
-
createStandardFont
Creates a font program for one of the PDF standard Type 1 fonts.- Parameters:
-
name- standard font name - Returns:
- initialized standard-font program
- Throws:
-
IOException- if font cannot be read or parsed
-
initializeGlyphs
Deprecated.to make privateFills missing character codes incodeToGlyphmap.- Parameters:
-
fontEncoding- to be used to map unicode values to character codes.
-
isBuiltInFont
public boolean isBuiltInFont()Checks whether this program represents a built-in standard font.- Returns:
-
truewhen no external font program is required
-
getPdfFontFlags
public int getPdfFontFlags()Description copied from class:FontProgramComputes the PDF font descriptor flags for this program.- Specified by:
-
getPdfFontFlagsin classFontProgram - Returns:
- bit set defined by the PDF font descriptor specification
-
getCharacterSet
Gets the AFMCharacterSetdeclaration.- Returns:
-
character set description, or
nullwhen absent
-
hasKernPairs
public boolean hasKernPairs()Checks if the font has any kerning pairs.- Overrides:
-
hasKernPairsin classFontProgram - Returns:
-
trueif the font has any kerning pairs.
-
getKerning
Description copied from class:FontProgramGets the kerning between two glyphs.- Specified by:
-
getKerningin classFontProgram - Parameters:
-
first- the first glyph -
second- the second glyph - Returns:
- the kerning to be applied
-
setKerning
public boolean setKerning(int first, int second, int kern) Sets the kerning between two Unicode chars.- Parameters:
-
first- the first unicode char. -
second- the second unicode char. -
kern- the kerning to apply in normalized 1000 units. - Returns:
-
trueif the kerning was applied,falseotherwise.
-
getGlyph
Find glyph by glyph name.- Parameters:
-
name- Glyph name - Returns:
- Glyph instance if found, otherwise null.
-
getFontStreamBytes
public byte[] getFontStreamBytes() -
getFontStreamLengths
public int[] getFontStreamLengths() -
isBuiltWith
Description copied from class:FontProgramChecks whether theFontProgramwas built with corresponding fontName. Default value is false unless overridden.- Overrides:
-
isBuiltWithin classFontProgram - Parameters:
-
fontProgram- a font name or path to a font program - Returns:
- true, if the FontProgram was built with the fontProgram. Otherwise false.
-
process
Parses AFM/PFM metrics, character metrics, and kerning pairs into this font program.- Throws:
-
IOException- if mandatory sections are missing or the metrics source cannot be read
-