Package com.itextpdf.text.pdf
Class Type1Font
- java.lang.Object
-
- com.itextpdf.text.pdf.BaseFont
-
- com.itextpdf.text.pdf.Type1Font
-
class Type1Font extends BaseFont
Reads a Type1 font
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.itextpdf.text.pdf.BaseFont
BaseFont.StreamFont
-
-
Field Summary
Fields Modifier and Type Field Description private int
Ascender
A variable.private boolean
builtinFont
true
if this font is one of the 14 built in fonts.private int
CapHeight
A variable.private java.lang.String
CharacterSet
The character set of the font.private java.util.HashMap<java.lang.Object,java.lang.Object[]>
CharMetrics
Represents the section CharMetrics in the AFM file.private int
Descender
A variable.private java.lang.String
EncodingScheme
The font's encoding name.private java.lang.String
FamilyName
The family name of the font.private java.lang.String
fileName
The file in use.private java.lang.String
FontName
The Postscript font name.private java.lang.String
FullName
The full name of the font.private boolean
IsFixedPitch
true
if all the characters have the same width.private float
ItalicAngle
The italic angle of the font, usually 0.0 or negative.private java.util.HashMap<java.lang.String,java.lang.Object[]>
KernPairs
Represents the section KernPairs in the AFM file.private int
llx
The llx of the FontBox.private int
lly
The lly of the FontBox.protected byte[]
pfb
The PFB file if the input was made with abyte
array.private static int[]
PFB_TYPES
Types of records in a PFB file.private static FontsResourceAnchor
resourceAnchor
private int
StdHW
A variable.private int
StdVW
A variable.private int
UnderlinePosition
The underline position.private int
UnderlineThickness
The underline thickness.private int
urx
The lurx of the FontBox.private int
ury
The ury of the FontBox.private java.lang.String
Weight
The weight of the font: normal, bold, etc.private int
XHeight
A variable.-
Fields inherited from class com.itextpdf.text.pdf.BaseFont
ASCENT, AWT_ASCENT, AWT_DESCENT, AWT_LEADING, AWT_MAXADVANCE, BBOXLLX, BBOXLLY, BBOXURX, BBOXURY, BuiltinFonts14, CACHED, CAPHEIGHT, CHAR_RANGE_ARABIC, CHAR_RANGE_CYRILLIC, CHAR_RANGE_HEBREW, CHAR_RANGE_LATIN, charBBoxes, CID_NEWLINE, compressionLevel, COURIER, COURIER_BOLD, COURIER_BOLDOBLIQUE, COURIER_OBLIQUE, CP1250, CP1252, CP1257, DEFAULT_FONT_MATRIX, DESCENT, differences, directTextToByte, embedded, EMBEDDED, encoding, fastWinansi, FONT_TYPE_CJK, FONT_TYPE_DOCUMENT, FONT_TYPE_T1, FONT_TYPE_T3, FONT_TYPE_TT, FONT_TYPE_TTUNI, FONT_WEIGHT, fontCache, fontSpecific, fontType, forceWidthsOutput, HELVETICA, HELVETICA_BOLD, HELVETICA_BOLDOBLIQUE, HELVETICA_OBLIQUE, IDENTITY_H, IDENTITY_V, ITALICANGLE, MACROMAN, NOT_CACHED, NOT_EMBEDDED, notdef, PARAGRAPH_SEPARATOR, RESOURCE_PATH, specialMap, STRIKETHROUGH_POSITION, STRIKETHROUGH_THICKNESS, SUBSCRIPT_OFFSET, SUBSCRIPT_SIZE, subset, subsetRanges, SUPERSCRIPT_OFFSET, SUPERSCRIPT_SIZE, SYMBOL, TIMES_BOLD, TIMES_BOLDITALIC, TIMES_ITALIC, TIMES_ROMAN, UNDERLINE_POSITION, UNDERLINE_THICKNESS, unicodeDifferences, vertical, WEIGHT_CLASS, WIDTH_CLASS, widths, WINANSI, ZAPFDINGBATS
-
-
Constructor Summary
Constructors Constructor Description Type1Font(java.lang.String afmFile, java.lang.String enc, boolean emb, byte[] ttfAfm, byte[] pfb, boolean forceRead)
Creates a new Type1 font.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String[][]
getAllNameEntries()
Gets all the entries of the names-table.java.lang.String[][]
getFamilyFontName()
Gets the family name of the font.private PdfDictionary
getFontBaseType(PdfIndirectReference fontDescriptor, int firstChar, int lastChar, byte[] shortTag)
Generates the font dictionary for this font.float
getFontDescriptor(int key, float fontSize)
Gets the font parameter identified bykey
.private PdfDictionary
getFontDescriptor(PdfIndirectReference fontStream)
Generates the font descriptor for this font ornull
if it is one of the 14 built in fonts.java.lang.String[][]
getFullFontName()
Gets the full name of the font.PdfStream
getFullFontStream()
If the embedded flag isfalse
or if the font is one of the 14 built in types, it returnsnull
, otherwise the font is read and output in a PdfStream object.int
getKerning(int char1, int char2)
Gets the kerning between two Unicode characters.java.lang.String
getPostscriptFontName()
Gets the postscript font name.protected int[]
getRawCharBBox(int c, java.lang.String name)
(package private) int
getRawWidth(int c, java.lang.String name)
Gets the width from the font according to thename
or, if thename
is null, meaning it is a symbolic font, the charc
.boolean
hasKernPairs()
Checks if the font has any kerning pairs.void
process(RandomAccessFileOrArray rf)
Reads the font metricsvoid
setFontDescriptor(int key, float value)
Sets the font parameter identified bykey
.boolean
setKerning(int char1, int char2, int kern)
Sets the kerning between two Unicode chars.void
setPostscriptFontName(java.lang.String name)
Sets the font name that will appear in the pdf font dictionary.(package private) void
writeFont(PdfWriter writer, PdfIndirectReference ref, java.lang.Object[] params)
Outputs to the writer the font dictionaries and streams.-
Methods inherited from class com.itextpdf.text.pdf.BaseFont
addSubsetRange, charExists, convertToBytes, convertToBytes, correctArabicAdvance, createBuiltInFontDictionary, createEncoding, createFont, createFont, createFont, createFont, createFont, createFont, createFont, createSubsetPrefix, enumerateTTCNames, enumerateTTCNames, getAllFontNames, getAllNameEntries, getAscent, getAscentPoint, getBaseName, getCharBBox, getCidCode, getCodePagesSupported, getCompressionLevel, getDescent, getDescentPoint, getDifferences, getDocumentFonts, getDocumentFonts, getEncoding, getFontMatrix, getFontType, getFullFontName, getSubfamily, getUnicodeDifferences, getUnicodeDifferences, getUnicodeEquivalent, getWidth, getWidth, getWidthPoint, getWidthPoint, getWidthPointKerned, getWidths, isDirectTextToByte, isEmbedded, isFontSpecific, isForceWidthsOutput, isSubset, isVertical, normalizeEncoding, setCharAdvance, setCompressionLevel, setDirectTextToByte, setForceWidthsOutput, setSubset
-
-
-
-
Field Detail
-
resourceAnchor
private static FontsResourceAnchor resourceAnchor
-
pfb
protected byte[] pfb
The PFB file if the input was made with abyte
array.
-
FontName
private java.lang.String FontName
The Postscript font name.
-
FullName
private java.lang.String FullName
The full name of the font.
-
FamilyName
private java.lang.String FamilyName
The family name of the font.
-
Weight
private java.lang.String Weight
The weight of the font: normal, bold, etc.
-
ItalicAngle
private float ItalicAngle
The italic angle of the font, usually 0.0 or negative.
-
IsFixedPitch
private boolean IsFixedPitch
true
if all the characters have the same width.
-
CharacterSet
private java.lang.String CharacterSet
The character set of the font.
-
llx
private int llx
The llx of the FontBox.
-
lly
private int lly
The lly of the FontBox.
-
urx
private int urx
The lurx of the FontBox.
-
ury
private int ury
The ury of the FontBox.
-
UnderlinePosition
private int UnderlinePosition
The underline position.
-
UnderlineThickness
private int UnderlineThickness
The underline thickness.
-
EncodingScheme
private java.lang.String EncodingScheme
The font's encoding name. This encoding is 'StandardEncoding' or 'AdobeStandardEncoding' for a font that can be totally encoded according to the characters names. For all other names the font is treated as symbolic.
-
CapHeight
private int CapHeight
A variable.
-
XHeight
private int XHeight
A variable.
-
Ascender
private int Ascender
A variable.
-
Descender
private int Descender
A variable.
-
StdHW
private int StdHW
A variable.
-
StdVW
private int StdVW
A variable.
-
CharMetrics
private java.util.HashMap<java.lang.Object,java.lang.Object[]> CharMetrics
Represents the section CharMetrics in the AFM file. Each value of this array contains aObject[4]
with an Integer, Integer, String and int[]. This is the code, width, name and char bbox. The key is the name of the char and also an Integer with the char number.
-
KernPairs
private java.util.HashMap<java.lang.String,java.lang.Object[]> KernPairs
Represents the section KernPairs in the AFM file. The key is the name of the first character and the value is aObject[]
with 2 elements for each kern pair. Position 0 is the name of the second character and position 1 is the kerning distance. This is repeated for all the pairs.
-
fileName
private java.lang.String fileName
The file in use.
-
builtinFont
private boolean builtinFont
true
if this font is one of the 14 built in fonts.
-
PFB_TYPES
private static final int[] PFB_TYPES
Types of records in a PFB file. ASCII is 1 and BINARY is 2. They have to appear in the PFB file in this sequence.
-
-
Constructor Detail
-
Type1Font
Type1Font(java.lang.String afmFile, java.lang.String enc, boolean emb, byte[] ttfAfm, byte[] pfb, boolean forceRead) throws DocumentException, java.io.IOException
Creates a new Type1 font.- Parameters:
ttfAfm
- the AFM file if the input is made with abyte
arraypfb
- the PFB file if the input is made with abyte
arrayafmFile
- the name of one of the 14 built-in fonts or the location of an AFM file. The file must end in '.afm'enc
- the encoding to be applied to this fontemb
- true if the font is to be embedded in the PDF- Throws:
DocumentException
- the AFM file is invalidjava.io.IOException
- the AFM file could not be read- Since:
- 2.1.5
-
-
Method Detail
-
getRawWidth
int getRawWidth(int c, java.lang.String name)
Gets the width from the font according to thename
or, if thename
is null, meaning it is a symbolic font, the charc
.- Specified by:
getRawWidth
in classBaseFont
- Parameters:
c
- the char if the font is symbolicname
- the glyph name- Returns:
- the width of the char
-
getKerning
public int getKerning(int char1, int char2)
Gets the kerning between two Unicode characters. The characters are converted to names and this names are used to find the kerning pairs in theHashMap
KernPairs
.- Specified by:
getKerning
in classBaseFont
- Parameters:
char1
- the first charchar2
- the second char- Returns:
- the kerning to be applied
-
process
public void process(RandomAccessFileOrArray rf) throws DocumentException, java.io.IOException
Reads the font metrics- Parameters:
rf
- the AFM file- Throws:
DocumentException
- the AFM file is invalidjava.io.IOException
- the AFM file could not be read
-
getFullFontStream
public PdfStream getFullFontStream() throws DocumentException
If the embedded flag isfalse
or if the font is one of the 14 built in types, it returnsnull
, otherwise the font is read and output in a PdfStream object.- Specified by:
getFullFontStream
in classBaseFont
- Returns:
- the PdfStream containing the font or
null
- Throws:
DocumentException
- if there is an error reading the font- Since:
- 2.1.3
-
getFontDescriptor
private PdfDictionary getFontDescriptor(PdfIndirectReference fontStream)
Generates the font descriptor for this font ornull
if it is one of the 14 built in fonts.- Parameters:
fontStream
- the indirect reference to a PdfStream containing the font ornull
- Returns:
- the PdfDictionary containing the font descriptor or
null
-
getFontBaseType
private PdfDictionary getFontBaseType(PdfIndirectReference fontDescriptor, int firstChar, int lastChar, byte[] shortTag)
Generates the font dictionary for this font.- Parameters:
firstChar
- the first valid characterlastChar
- the last valid charactershortTag
- a 256 bytes longbyte
array where each unused byte is represented by 0fontDescriptor
- the indirect reference to a PdfDictionary containing the font descriptor ornull
- Returns:
- the PdfDictionary containing the font dictionary
-
writeFont
void writeFont(PdfWriter writer, PdfIndirectReference ref, java.lang.Object[] params) throws DocumentException, java.io.IOException
Outputs to the writer the font dictionaries and streams.- Specified by:
writeFont
in classBaseFont
- Parameters:
writer
- the writer for this documentref
- the font indirect referenceparams
- several parameters that depend on the font type- Throws:
java.io.IOException
- on errorDocumentException
- error in generating the object
-
getFontDescriptor
public float getFontDescriptor(int key, float fontSize)
Gets the font parameter identified bykey
. Valid values forkey
areASCENT
,CAPHEIGHT
,DESCENT
,ITALICANGLE
,BBOXLLX
,BBOXLLY
,BBOXURX
andBBOXURY
.- Specified by:
getFontDescriptor
in classBaseFont
- Parameters:
key
- the parameter to be extractedfontSize
- the font size in points- Returns:
- the parameter in points
-
setFontDescriptor
public void setFontDescriptor(int key, float value)
Sets the font parameter identified bykey
. Valid values forkey
areASCENT
,AWT_ASCENT
,CAPHEIGHT
,DESCENT
,AWT_DESCENT
,ITALICANGLE
,BBOXLLX
,BBOXLLY
,BBOXURX
andBBOXURY
.- Overrides:
setFontDescriptor
in classBaseFont
- Parameters:
key
- the parameter to be updatedvalue
- the parameter value
-
getPostscriptFontName
public java.lang.String getPostscriptFontName()
Gets the postscript font name.- Specified by:
getPostscriptFontName
in classBaseFont
- Returns:
- the postscript font name
-
getFullFontName
public java.lang.String[][] getFullFontName()
Gets the full name of the font. If it is a True Type font each array element will have {Platform ID, Platform Encoding ID, Language ID, font name}. The interpretation of this values can be found in the Open Type specification, chapter 2, in the 'name' table.
For the other fonts the array has a single element with {"", "", "", font name}.- Specified by:
getFullFontName
in classBaseFont
- Returns:
- the full name of the font
-
getAllNameEntries
public java.lang.String[][] getAllNameEntries()
Gets all the entries of the names-table. If it is a True Type font each array element will have {Name ID, Platform ID, Platform Encoding ID, Language ID, font name}. The interpretation of this values can be found in the Open Type specification, chapter 2, in the 'name' table.
For the other fonts the array has a single element with {"4", "", "", "", font name}.- Specified by:
getAllNameEntries
in classBaseFont
- Returns:
- the full name of the font
-
getFamilyFontName
public java.lang.String[][] getFamilyFontName()
Gets the family name of the font. If it is a True Type font each array element will have {Platform ID, Platform Encoding ID, Language ID, font name}. The interpretation of this values can be found in the Open Type specification, chapter 2, in the 'name' table.
For the other fonts the array has a single element with {"", "", "", font name}.- Specified by:
getFamilyFontName
in classBaseFont
- Returns:
- the family name of the font
-
hasKernPairs
public boolean hasKernPairs()
Checks if the font has any kerning pairs.- Specified by:
hasKernPairs
in classBaseFont
- Returns:
true
if the font has any kerning pairs
-
setPostscriptFontName
public void setPostscriptFontName(java.lang.String name)
Sets the font name that will appear in the pdf font dictionary. Use with care as it can easily make a font unreadable if not embedded.- Specified by:
setPostscriptFontName
in classBaseFont
- Parameters:
name
- the new font name
-
setKerning
public boolean setKerning(int char1, int char2, int kern)
Sets the kerning between two Unicode chars.- Specified by:
setKerning
in classBaseFont
- Parameters:
char1
- the first charchar2
- the second charkern
- the kerning to apply in normalized 1000 units- Returns:
true
if the kerning was applied,false
otherwise
-
getRawCharBBox
protected int[] getRawCharBBox(int c, java.lang.String name)
- Specified by:
getRawCharBBox
in classBaseFont
-
-