com.lowagie.text.pdf

Class BaseFont

public abstract class BaseFont extends Object

Base class for the several font types supported

Author: Paulo Soares (psoares@consiste.pt)

Nested Class Summary
static classBaseFont.StreamFont
Generates the PDF stream with the Type1 and Truetype fonts returning a PdfStream.
Field Summary
static intASCENT
The maximum height above the baseline reached by glyphs in this font, excluding the height of glyphs for accented characters.
static intAWT_ASCENT
java.awt.Font property
static intAWT_DESCENT
java.awt.Font property
static intAWT_LEADING
java.awt.Font property
static intAWT_MAXADVANCE
java.awt.Font property
static intBBOXLLX
The lower left x glyph coordinate.
static intBBOXLLY
The lower left y glyph coordinate.
static intBBOXURX
The upper right x glyph coordinate.
static intBBOXURY
The upper right y glyph coordinate.
protected static HashMapBuiltinFonts14
list of the 14 built in fonts.
protected int[][]charBBoxes
static booleanCACHED
if the font has to be cached
static intCAPHEIGHT
The y coordinate of the top of flat capital letters, measured from the baseline.
static int[]CHAR_RANGE_ARABIC
static int[]CHAR_RANGE_CYRILLIC
static int[]CHAR_RANGE_HEBREW
static int[]CHAR_RANGE_LATIN
static charCID_NEWLINE
The fake CID code that represents a newline.
static StringCOURIER
This is a possible value of a base 14 type 1 font
static StringCOURIER_BOLD
This is a possible value of a base 14 type 1 font
static StringCOURIER_BOLDOBLIQUE
This is a possible value of a base 14 type 1 font
static StringCOURIER_OBLIQUE
This is a possible value of a base 14 type 1 font
static StringCP1250
A possible encoding.
static StringCP1252
A possible encoding.
static StringCP1257
A possible encoding.
protected String[]differences
encoding names
protected booleandirectTextToByte
Converts char directly to byte by casting.
static intDESCENT
The maximum depth below the baseline reached by glyphs in this font.
protected booleanembedded
true if the font is to be embedded in the PDF
protected Stringencoding
encoding used with this font
static booleanEMBEDDED
if the font has to be embedded
protected booleanfastWinansi
protected static HashMapfontCache
cache for the fonts already used.
protected booleanfontSpecific
true if the font must use it's built in encoding.
intfontType
The font type.
protected booleanforceWidthsOutput
Forces the output of the width array.
static intFONT_TYPE_CJK
The font is CJK.
static intFONT_TYPE_DOCUMENT
A font already inside the document.
static intFONT_TYPE_T1
The font is Type 1.
static intFONT_TYPE_T3
A Type3 font.
static intFONT_TYPE_TT
The font is True Type with a standard encoding.
static intFONT_TYPE_TTUNI
The font is True Type with a Unicode encoding.
static StringHELVETICA
This is a possible value of a base 14 type 1 font
static StringHELVETICA_BOLD
This is a possible value of a base 14 type 1 font
static StringHELVETICA_BOLDOBLIQUE
This is a possible value of a base 14 type 1 font
static StringHELVETICA_OBLIQUE
This is a possible value of a base 14 type 1 font
static StringIDENTITY_H
The Unicode encoding with horizontal writing.
static StringIDENTITY_V
The Unicode encoding with vertical writing.
static intITALICANGLE
The angle, expressed in degrees counterclockwise from the vertical, of the dominant vertical strokes of the font.
static StringMACROMAN
A possible encoding.
static Stringnotdef
a not defined character in a custom PDF encoding
static booleanNOT_CACHED
if the font doesn't have to be cached
static booleanNOT_EMBEDDED
if the font doesn't have to be embedded
static StringRESOURCE_PATH
The path to the font resources.
protected IntHashtablespecialMap
Custom encodings use this map to key the Unicode character to the single byte code.
protected booleansubset
Indicates if all the glyphs and widths for that particular encoding should be included in the document.
protected ArrayListsubsetRanges
static StringSYMBOL
This is a possible value of a base 14 type 1 font
static StringTIMES_BOLD
This is a possible value of a base 14 type 1 font
static StringTIMES_BOLDITALIC
This is a possible value of a base 14 type 1 font
static StringTIMES_ITALIC
This is a possible value of a base 14 type 1 font
static StringTIMES_ROMAN
This is a possible value of a base 14 type 1 font
protected char[]unicodeDifferences
same as differences but with the unicode codes
protected int[]widths
table of characters widths for this encoding
static StringWINANSI
A possible encoding.
static StringZAPFDINGBATS
This is a possible value of a base 14 type 1 font
Constructor Summary
protected BaseFont()
Creates new BaseFont
Method Summary
static voidaddFont(PRIndirectReference fontRef, IntHashtable hits, ArrayList fonts)
voidaddSubsetRange(int[] range)
Adds a character range when subsetting.
booleancharExists(char c)
Checks if a character exists in this font.
byte[]convertToBytes(String text)
Converts a String to a byte array according to the font's encoding.
voidcorrectArabicAdvance()
iText expects Arabic Diactrics (tashkeel) to have zero advance but some fonts, most notably those that come with Windows, like times.ttf, have non-zero advance for those characters.
protected voidcreateEncoding()
Creates the widths and the differences arrays
static BaseFontcreateFont(String name, String encoding, boolean embedded)
Creates a new font.
static BaseFontcreateFont(String name, String encoding, boolean embedded, boolean cached, byte[] ttfAfm, byte[] pfb)
Creates a new font.
static BaseFontcreateFont(PRIndirectReference fontRef)
Creates a font based on an existing document font.
static StringcreateSubsetPrefix()
Creates a unique subset prefix to be added to the font name when the font is embedded and subset.
static String[]enumerateTTCNames(String ttcFile)
Enumerates the postscript font names present inside a True Type Collection.
static String[]enumerateTTCNames(byte[] ttcArray)
Enumerates the postscript font names present inside a True Type Collection.
static Object[]getAllFontNames(String name, String encoding, byte[] ttfAfm)
Gets all the names from the font.
intgetAscent(String text)
Gets the ascent of a String in normalized 1000 units.
floatgetAscentPoint(String text, float fontSize)
Gets the ascent of a String in points.
protected static StringgetBaseName(String name)
Gets the name without the modifiers Bold, Italic or BoldItalic.
int[]getCharBBox(char c)
Gets the smallest box enclosing the character contours.
chargetCidCode(char c)
Gets the CID code given an Unicode.
String[]getCodePagesSupported()
Gets the code pages supported by the font.
intgetDescent(String text)
Gets the descent of a String in normalized 1000 units.
floatgetDescentPoint(String text, float fontSize)
Gets the descent of a String in points.
String[]getDifferences()
Gets the array with the names of the characters.
static ArrayListgetDocumentFonts(PdfReader reader)
Gets a list of all document fonts.
static ArrayListgetDocumentFonts(PdfReader reader, int page)
Gets a list of the document fonts in a particular page.
StringgetEncoding()
Gets the encoding used to convert String into byte[].
abstract String[][]getFamilyFontName()
Gets the family name of the font.
abstract floatgetFontDescriptor(int key, float fontSize)
Gets the font parameter identified by key.
intgetFontType()
Gets the font type.
abstract String[][]getFullFontName()
Gets the full name of the font.
static String[][]getFullFontName(String name, String encoding, byte[] ttfAfm)
Gets the full name of the font.
abstract intgetKerning(char char1, char char2)
Gets the kerning between two Unicode chars.
abstract StringgetPostscriptFontName()
Gets the postscript font name.
protected abstract int[]getRawCharBBox(int c, String name)
abstract intgetRawWidth(int c, String name)
Gets the width from the font according to the Unicode char c or the name.
static InputStreamgetResourceStream(String key)
Gets the font resources.
static InputStreamgetResourceStream(String key, ClassLoader loader)
Gets the font resources.
chargetUnicodeDifferences(int index)
Gets the Unicode character corresponding to the byte output to the pdf stream.
char[]getUnicodeDifferences()
Gets the array with the unicode characters.
chargetUnicodeEquivalent(char c)
Gets the Unicode equivalent to a CID.
intgetWidth(char char1)
Gets the width of a char in normalized 1000 units.
intgetWidth(String text)
Gets the width of a String in normalized 1000 units.
floatgetWidthPoint(String text, float fontSize)
Gets the width of a String in points.
floatgetWidthPoint(char char1, float fontSize)
Gets the width of a char in points.
floatgetWidthPointKerned(String text, float fontSize)
Gets the width of a String in points taking kerning into account.
int[]getWidths()
Gets the font width array.
abstract booleanhasKernPairs()
Checks if the font has any kerning pairs.
booleanisDirectTextToByte()
Gets the direct conversion of char to byte.
booleanisEmbedded()
Gets the embedded flag.
booleanisFontSpecific()
Gets the symbolic flag of the font.
booleanisForceWidthsOutput()
Gets the state of the property.
booleanisSubset()
Indicates if all the glyphs and widths for that particular encoding should be included in the document.
protected static StringnormalizeEncoding(String enc)
Normalize the encoding names.
static voidrecourseFonts(PdfDictionary page, IntHashtable hits, ArrayList fonts, int level)
booleansetCharAdvance(char c, int advance)
Sets the character advance.
voidsetDirectTextToByte(boolean directTextToByte)
Sets the conversion of char directly to byte by casting.
voidsetForceWidthsOutput(boolean forceWidthsOutput)
Set to true to force the generation of the widths array.
abstract booleansetKerning(char char1, char char2, int kern)
Sets the kerning between two Unicode chars.
abstract voidsetPostscriptFontName(String name)
Sets the font name that will appear in the pdf font dictionary.
voidsetSubset(boolean subset)
Indicates if all the glyphs and widths for that particular encoding should be included in the document.
abstract voidwriteFont(PdfWriter writer, PdfIndirectReference ref, Object[] params)
Outputs to the writer the font dictionaries and streams.

Field Detail

ASCENT

public static final int ASCENT
The maximum height above the baseline reached by glyphs in this font, excluding the height of glyphs for accented characters.

AWT_ASCENT

public static final int AWT_ASCENT
java.awt.Font property

AWT_DESCENT

public static final int AWT_DESCENT
java.awt.Font property

AWT_LEADING

public static final int AWT_LEADING
java.awt.Font property

AWT_MAXADVANCE

public static final int AWT_MAXADVANCE
java.awt.Font property

BBOXLLX

public static final int BBOXLLX
The lower left x glyph coordinate.

BBOXLLY

public static final int BBOXLLY
The lower left y glyph coordinate.

BBOXURX

public static final int BBOXURX
The upper right x glyph coordinate.

BBOXURY

public static final int BBOXURY
The upper right y glyph coordinate.

BuiltinFonts14

protected static final HashMap BuiltinFonts14
list of the 14 built in fonts.

charBBoxes

protected int[][] charBBoxes

CACHED

public static final boolean CACHED
if the font has to be cached

CAPHEIGHT

public static final int CAPHEIGHT
The y coordinate of the top of flat capital letters, measured from the baseline.

CHAR_RANGE_ARABIC

public static final int[] CHAR_RANGE_ARABIC

CHAR_RANGE_CYRILLIC

public static final int[] CHAR_RANGE_CYRILLIC

CHAR_RANGE_HEBREW

public static final int[] CHAR_RANGE_HEBREW

CHAR_RANGE_LATIN

public static final int[] CHAR_RANGE_LATIN

CID_NEWLINE

public static final char CID_NEWLINE
The fake CID code that represents a newline.

COURIER

public static final String COURIER
This is a possible value of a base 14 type 1 font

COURIER_BOLD

public static final String COURIER_BOLD
This is a possible value of a base 14 type 1 font

COURIER_BOLDOBLIQUE

public static final String COURIER_BOLDOBLIQUE
This is a possible value of a base 14 type 1 font

COURIER_OBLIQUE

public static final String COURIER_OBLIQUE
This is a possible value of a base 14 type 1 font

CP1250

public static final String CP1250
A possible encoding.

CP1252

public static final String CP1252
A possible encoding.

CP1257

public static final String CP1257
A possible encoding.

differences

protected String[] differences
encoding names

directTextToByte

protected boolean directTextToByte
Converts char directly to byte by casting.

DESCENT

public static final int DESCENT
The maximum depth below the baseline reached by glyphs in this font. The value is a negative number.

embedded

protected boolean embedded
true if the font is to be embedded in the PDF

encoding

protected String encoding
encoding used with this font

EMBEDDED

public static final boolean EMBEDDED
if the font has to be embedded

fastWinansi

protected boolean fastWinansi

fontCache

protected static HashMap fontCache
cache for the fonts already used.

fontSpecific

protected boolean fontSpecific
true if the font must use it's built in encoding. In that case the encoding is only used to map a char to the position inside the font, not to the expected char name.

fontType

int fontType
The font type.

forceWidthsOutput

protected boolean forceWidthsOutput
Forces the output of the width array. Only matters for the 14 built-in fonts.

FONT_TYPE_CJK

public static final int FONT_TYPE_CJK
The font is CJK.

FONT_TYPE_DOCUMENT

public static final int FONT_TYPE_DOCUMENT
A font already inside the document.

FONT_TYPE_T1

public static final int FONT_TYPE_T1
The font is Type 1.

FONT_TYPE_T3

public static final int FONT_TYPE_T3
A Type3 font.

FONT_TYPE_TT

public static final int FONT_TYPE_TT
The font is True Type with a standard encoding.

FONT_TYPE_TTUNI

public static final int FONT_TYPE_TTUNI
The font is True Type with a Unicode encoding.

HELVETICA

public static final String HELVETICA
This is a possible value of a base 14 type 1 font

HELVETICA_BOLD

public static final String HELVETICA_BOLD
This is a possible value of a base 14 type 1 font

HELVETICA_BOLDOBLIQUE

public static final String HELVETICA_BOLDOBLIQUE
This is a possible value of a base 14 type 1 font

HELVETICA_OBLIQUE

public static final String HELVETICA_OBLIQUE
This is a possible value of a base 14 type 1 font

IDENTITY_H

public static final String IDENTITY_H
The Unicode encoding with horizontal writing.

IDENTITY_V

public static final String IDENTITY_V
The Unicode encoding with vertical writing.

ITALICANGLE

public static final int ITALICANGLE
The angle, expressed in degrees counterclockwise from the vertical, of the dominant vertical strokes of the font. The value is negative for fonts that slope to the right, as almost all italic fonts do.

MACROMAN

public static final String MACROMAN
A possible encoding.

notdef

public static final String notdef
a not defined character in a custom PDF encoding

NOT_CACHED

public static final boolean NOT_CACHED
if the font doesn't have to be cached

NOT_EMBEDDED

public static final boolean NOT_EMBEDDED
if the font doesn't have to be embedded

RESOURCE_PATH

public static final String RESOURCE_PATH
The path to the font resources.

specialMap

protected IntHashtable specialMap
Custom encodings use this map to key the Unicode character to the single byte code.

subset

protected boolean subset
Indicates if all the glyphs and widths for that particular encoding should be included in the document.

subsetRanges

protected ArrayList subsetRanges

SYMBOL

public static final String SYMBOL
This is a possible value of a base 14 type 1 font

TIMES_BOLD

public static final String TIMES_BOLD
This is a possible value of a base 14 type 1 font

TIMES_BOLDITALIC

public static final String TIMES_BOLDITALIC
This is a possible value of a base 14 type 1 font

TIMES_ITALIC

public static final String TIMES_ITALIC
This is a possible value of a base 14 type 1 font

TIMES_ROMAN

public static final String TIMES_ROMAN
This is a possible value of a base 14 type 1 font

unicodeDifferences

protected char[] unicodeDifferences
same as differences but with the unicode codes

widths

protected int[] widths
table of characters widths for this encoding

WINANSI

public static final String WINANSI
A possible encoding.

ZAPFDINGBATS

public static final String ZAPFDINGBATS
This is a possible value of a base 14 type 1 font

Constructor Detail

BaseFont

protected BaseFont()
Creates new BaseFont

Method Detail

addFont

private static void addFont(PRIndirectReference fontRef, IntHashtable hits, ArrayList fonts)

addSubsetRange

public void addSubsetRange(int[] range)
Adds a character range when subsetting. The range is an int array where the first element is the start range inclusive and the second element is the end range inclusive. Several ranges are allowed in the same array.

Parameters: range the character range

charExists

public boolean charExists(char c)
Checks if a character exists in this font.

Parameters: c the character to check

Returns: true if the character has a glyph, false otherwise

convertToBytes

byte[] convertToBytes(String text)
Converts a String to a byte array according to the font's encoding.

Parameters: text the String to be converted

Returns: an array of byte representing the conversion according to the font's encoding

correctArabicAdvance

public void correctArabicAdvance()
iText expects Arabic Diactrics (tashkeel) to have zero advance but some fonts, most notably those that come with Windows, like times.ttf, have non-zero advance for those characters. This method makes those character to have zero width advance and work correctly in the iText Arabic shaping and reordering context.

createEncoding

protected void createEncoding()
Creates the widths and the differences arrays

createFont

public static BaseFont createFont(String name, String encoding, boolean embedded)
Creates a new font. This font can be one of the 14 built in types, a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or collection) or a CJK font from the Adobe Asian Font Pack. TrueType fonts and CJK fonts can have an optional style modifier appended to the name. These modifiers are: Bold, Italic and BoldItalic. An example would be "STSong-Light,Bold". Note that this modifiers do not work if the font is embedded. Fonts in TrueType collections are addressed by index such as "msgothic.ttc,1". This would get the second font (indexes start at 0), in this case "MS PGothic".

The fonts are cached and if they already exist they are extracted from the cache, not parsed again.

Besides the common encodings described by name, custom encodings can also be made. These encodings will only work for the single byte fonts Type1 and TrueType. The encoding string starts with a '#' followed by "simple" or "full". If "simple" there is a decimal for the first character position and then a list of hex values representing the Unicode codes that compose that encoding.
The "simple" encoding is recommended for TrueType fonts as the "full" encoding risks not matching the character with the right glyph if not done with care.
The "full" encoding is specially aimed at Type1 fonts where the glyphs have to be described by non standard names like the Tex math fonts. Each group of three elements compose a code position: the one byte code order in decimal or as 'x' (x cannot be the space), the name and the Unicode character used to access the glyph. The space must be assigned to character position 32 otherwise text justification will not work.

Example for a "simple" encoding that includes the Unicode character space, A, B and ecyrillic:

 "# simple 32 0020 0041 0042 0454"
 

Example for a "full" encoding for a Type1 Tex font:

 "# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020"
 

This method calls:

 createFont(name, encoding, embedded, true, null, null);
 

Parameters: name the name of the font or it's location on file encoding the encoding to be applied to this font embedded true if the font is to be embedded in the PDF

Returns: returns a new font. This font may come from the cache

Throws: DocumentException the font is invalid IOException the font file could not be read

createFont

public static BaseFont createFont(String name, String encoding, boolean embedded, boolean cached, byte[] ttfAfm, byte[] pfb)
Creates a new font. This font can be one of the 14 built in types, a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or collection) or a CJK font from the Adobe Asian Font Pack. TrueType fonts and CJK fonts can have an optional style modifier appended to the name. These modifiers are: Bold, Italic and BoldItalic. An example would be "STSong-Light,Bold". Note that this modifiers do not work if the font is embedded. Fonts in TrueType collections are addressed by index such as "msgothic.ttc,1". This would get the second font (indexes start at 0), in this case "MS PGothic".

The fonts may or may not be cached depending on the flag cached. If the byte arrays are present the font will be read from them instead of the name. A name is still required to identify the font type.

Besides the common encodings described by name, custom encodings can also be made. These encodings will only work for the single byte fonts Type1 and TrueType. The encoding string starts with a '#' followed by "simple" or "full". If "simple" there is a decimal for the first character position and then a list of hex values representing the Unicode codes that compose that encoding.
The "simple" encoding is recommended for TrueType fonts as the "full" encoding risks not matching the character with the right glyph if not done with care.
The "full" encoding is specially aimed at Type1 fonts where the glyphs have to be described by non standard names like the Tex math fonts. Each group of three elements compose a code position: the one byte code order in decimal or as 'x' (x cannot be the space), the name and the Unicode character used to access the glyph. The space must be assigned to character position 32 otherwise text justification will not work.

Example for a "simple" encoding that includes the Unicode character space, A, B and ecyrillic:

 "# simple 32 0020 0041 0042 0454"
 

Example for a "full" encoding for a Type1 Tex font:

 "# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020"
 

Parameters: name the name of the font or it's location on file encoding the encoding to be applied to this font embedded true if the font is to be embedded in the PDF cached true if the font comes from the cache or is added to the cache if new, false if the font is always created new ttfAfm the true type font or the afm in a byte array pfb the pfb in a byte array

Returns: returns a new font. This font may come from the cache but only if cached is true, otherwise it will always be created new

Throws: DocumentException the font is invalid IOException the font file could not be read

createFont

public static BaseFont createFont(PRIndirectReference fontRef)
Creates a font based on an existing document font. The created font font may not behave as expected, depending on the encoding or subset.

Parameters: fontRef the reference to the document font

Returns: the font

createSubsetPrefix

public static String createSubsetPrefix()
Creates a unique subset prefix to be added to the font name when the font is embedded and subset.

Returns: the subset prefix

enumerateTTCNames

public static String[] enumerateTTCNames(String ttcFile)
Enumerates the postscript font names present inside a True Type Collection.

Parameters: ttcFile the file name of the font

Returns: the postscript font names

Throws: DocumentException on error IOException on error

enumerateTTCNames

public static String[] enumerateTTCNames(byte[] ttcArray)
Enumerates the postscript font names present inside a True Type Collection.

Parameters: ttcArray the font as a byte array

Returns: the postscript font names

Throws: DocumentException on error IOException on error

getAllFontNames

public static Object[] getAllFontNames(String name, String encoding, byte[] ttfAfm)
Gets all the names from the font. Only the required tables are read.

Parameters: name the name of the font encoding the encoding of the font ttfAfm the true type font or the afm in a byte array

Returns: an array of Object[] built with {getPostscriptFontName(), getFamilyFontName(), getFullFontName()}

Throws: DocumentException on error IOException on error

getAscent

public int getAscent(String text)
Gets the ascent of a String in normalized 1000 units. The ascent will always be greater than or equal to zero even if all the characters have a lower ascent.

Parameters: text the String to get the ascent of

Returns: the ascent in normalized 1000 units

getAscentPoint

public float getAscentPoint(String text, float fontSize)
Gets the ascent of a String in points. The ascent will always be greater than or equal to zero even if all the characters have a lower ascent.

Parameters: text the String to get the ascent of fontSize the size of the font

Returns: the ascent in points

getBaseName

protected static String getBaseName(String name)
Gets the name without the modifiers Bold, Italic or BoldItalic.

Parameters: name the full name of the font

Returns: the name without the modifiers Bold, Italic or BoldItalic

getCharBBox

public int[] getCharBBox(char c)
Gets the smallest box enclosing the character contours. It will return null if the font has not the information or the character has no contours, as in the case of the space, for example. Characters with no contours may also return [0,0,0,0].

Parameters: c the character to get the contour bounding box from

Returns: an array of four floats with the bounding box in the format [llx,lly,urx,ury] or null

getCidCode

public char getCidCode(char c)
Gets the CID code given an Unicode. It has only meaning with CJK fonts.

Parameters: c the Unicode

Returns: the CID equivalent

getCodePagesSupported

public String[] getCodePagesSupported()
Gets the code pages supported by the font. This has only meaning with True Type fonts.

Returns: the code pages supported by the font

getDescent

public int getDescent(String text)
Gets the descent of a String in normalized 1000 units. The descent will always be less than or equal to zero even if all the characters have an higher descent.

Parameters: text the String to get the descent of

Returns: the dexcent in normalized 1000 units

getDescentPoint

public float getDescentPoint(String text, float fontSize)
Gets the descent of a String in points. The descent will always be less than or equal to zero even if all the characters have an higher descent.

Parameters: text the String to get the descent of fontSize the size of the font

Returns: the dexcent in points

getDifferences

public String[] getDifferences()
Gets the array with the names of the characters.

Returns: the array with the names of the characters

getDocumentFonts

public static ArrayList getDocumentFonts(PdfReader reader)
Gets a list of all document fonts. Each element of the ArrayList contains a Object[]{String,PRIndirectReference} with the font name and the indirect reference to it.

Parameters: reader the document where the fonts are to be listed from

Returns: the list of fonts and references

getDocumentFonts

public static ArrayList getDocumentFonts(PdfReader reader, int page)
Gets a list of the document fonts in a particular page. Each element of the ArrayList contains a Object[]{String,PRIndirectReference} with the font name and the indirect reference to it.

Parameters: reader the document where the fonts are to be listed from page the page to list the fonts from

Returns: the list of fonts and references

getEncoding

public String getEncoding()
Gets the encoding used to convert String into byte[].

Returns: the encoding name

getFamilyFontName

public abstract 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}.

Returns: the family name of the font

getFontDescriptor

public abstract float getFontDescriptor(int key, float fontSize)
Gets the font parameter identified by key. Valid values for key are ASCENT, AWT_ASCENT, CAPHEIGHT, DESCENT, AWT_DESCENT, ITALICANGLE, BBOXLLX, BBOXLLY, BBOXURX and BBOXURY.

Parameters: key the parameter to be extracted fontSize the font size in points

Returns: the parameter in points

getFontType

public int getFontType()
Gets the font type. The font types can be: FONT_TYPE_T1, FONT_TYPE_TT, FONT_TYPE_CJK and FONT_TYPE_TTUNI.

Returns: the font type

getFullFontName

public abstract 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}.

Returns: the full name of the font

getFullFontName

public static String[][] getFullFontName(String name, String encoding, byte[] ttfAfm)
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}.

Parameters: name the name of the font encoding the encoding of the font ttfAfm the true type font or the afm in a byte array

Returns: the full name of the font

Throws: DocumentException on error IOException on error

getKerning

public abstract int getKerning(char char1, char char2)
Gets the kerning between two Unicode chars.

Parameters: char1 the first char char2 the second char

Returns: the kerning to be applied in normalized 1000 units

getPostscriptFontName

public abstract String getPostscriptFontName()
Gets the postscript font name.

Returns: the postscript font name

getRawCharBBox

protected abstract int[] getRawCharBBox(int c, String name)

getRawWidth

abstract int getRawWidth(int c, String name)
Gets the width from the font according to the Unicode char c or the name. If the name is null it's a symbolic font.

Parameters: c the unicode char name the glyph name

Returns: the width of the char

getResourceStream

public static InputStream getResourceStream(String key)
Gets the font resources.

Parameters: key the full name of the resource

Returns: the InputStream to get the resource or null if not found

getResourceStream

public static InputStream getResourceStream(String key, ClassLoader loader)
Gets the font resources.

Parameters: key the full name of the resource loader the ClassLoader to load the resource or null to try the ones available

Returns: the InputStream to get the resource or null if not found

getUnicodeDifferences

char getUnicodeDifferences(int index)
Gets the Unicode character corresponding to the byte output to the pdf stream.

Parameters: index the byte index

Returns: the Unicode character

getUnicodeDifferences

public char[] getUnicodeDifferences()
Gets the array with the unicode characters.

Returns: the array with the unicode characters

getUnicodeEquivalent

public char getUnicodeEquivalent(char c)
Gets the Unicode equivalent to a CID. The (inexistent) CID is translated as '\n'. It has only meaning with CJK fonts with Identity encoding.

Parameters: c the CID code

Returns: the Unicode equivalent

getWidth

public int getWidth(char char1)
Gets the width of a char in normalized 1000 units.

Parameters: char1 the unicode char to get the width of

Returns: the width in normalized 1000 units

getWidth

public int getWidth(String text)
Gets the width of a String in normalized 1000 units.

Parameters: text the String to get the witdth of

Returns: the width in normalized 1000 units

getWidthPoint

public float getWidthPoint(String text, float fontSize)
Gets the width of a String in points.

Parameters: text the String to get the witdth of fontSize the font size

Returns: the width in points

getWidthPoint

public float getWidthPoint(char char1, float fontSize)
Gets the width of a char in points.

Parameters: char1 the char to get the witdth of fontSize the font size

Returns: the width in points

getWidthPointKerned

public float getWidthPointKerned(String text, float fontSize)
Gets the width of a String in points taking kerning into account.

Parameters: text the String to get the witdth of fontSize the font size

Returns: the width in points

getWidths

public int[] getWidths()
Gets the font width array.

Returns: the font width array

hasKernPairs

public abstract boolean hasKernPairs()
Checks if the font has any kerning pairs.

Returns: true if the font has any kerning pairs

isDirectTextToByte

public boolean isDirectTextToByte()
Gets the direct conversion of char to byte.

Returns: value of property directTextToByte.

See Also: BaseFont

isEmbedded

public boolean isEmbedded()
Gets the embedded flag.

Returns: true if the font is embedded.

isFontSpecific

public boolean isFontSpecific()
Gets the symbolic flag of the font.

Returns: true if the font is symbolic

isForceWidthsOutput

public boolean isForceWidthsOutput()
Gets the state of the property.

Returns: value of property forceWidthsOutput

isSubset

public boolean isSubset()
Indicates if all the glyphs and widths for that particular encoding should be included in the document.

Returns: false to include all the glyphs and widths.

normalizeEncoding

protected static String normalizeEncoding(String enc)
Normalize the encoding names. "winansi" is changed to "Cp1252" and "macroman" is changed to "MacRoman".

Parameters: enc the encoding to be normalized

Returns: the normalized encoding

recourseFonts

private static void recourseFonts(PdfDictionary page, IntHashtable hits, ArrayList fonts, int level)

setCharAdvance

public boolean setCharAdvance(char c, int advance)
Sets the character advance.

Parameters: c the character advance the character advance normalized to 1000 units

Returns: true if the advance was set, false otherwise

setDirectTextToByte

public void setDirectTextToByte(boolean directTextToByte)
Sets the conversion of char directly to byte by casting. This is a low level feature to put the bytes directly in the content stream without passing through String.getBytes().

Parameters: directTextToByte New value of property directTextToByte.

setForceWidthsOutput

public void setForceWidthsOutput(boolean forceWidthsOutput)
Set to true to force the generation of the widths array.

Parameters: forceWidthsOutput true to force the generation of the widths array

setKerning

public abstract boolean setKerning(char char1, char char2, int kern)
Sets the kerning between two Unicode chars.

Parameters: char1 the first char char2 the second char kern the kerning to apply in normalized 1000 units

Returns: true if the kerning was applied, false otherwise

setPostscriptFontName

public abstract void setPostscriptFontName(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.

Parameters: name the new font name

setSubset

public void setSubset(boolean subset)
Indicates if all the glyphs and widths for that particular encoding should be included in the document. When set to true only the glyphs used will be included in the font. When set to false and (int[]) was not called the full font will be included otherwise just the characters ranges will be included.

Parameters: subset new value of property subset

writeFont

abstract void writeFont(PdfWriter writer, PdfIndirectReference ref, Object[] params)
Outputs to the writer the font dictionaries and streams.

Parameters: writer the writer for this document ref the font indirect reference params several parameters that depend on the font type

Throws: IOException on error DocumentException error in generating the object