static
BaseFont
createFont
(
String
name,
String
encoding, boolean embedded, boolean forceRead)
Creates a new font.
static
BaseFont
createFont
(
String
name,
String
encoding, boolean embedded, boolean cached, byte[] ttfAfm, byte[] pfb)
Creates a new font.
static
BaseFont
createFont
(
String
name,
String
encoding, boolean embedded, boolean cached, byte[] ttfAfm, byte[] pfb, boolean noThrow)
Creates a new font.
static
BaseFont
createFont
(
String
name,
String
encoding, boolean embedded, boolean cached, byte[] ttfAfm, byte[] pfb, boolean noThrow, boolean forceRead)
Creates a new font.
static
String
createSubsetPrefix
()
Creates a unique subset prefix to be added to the font name when the font is embedded and subset.
static
String
[]
enumerateTTCNames
(byte[] ttcArray)
Enumerates the postscript font names present inside a True Type Collection.
static
String
[]
enumerateTTCNames
(
String
ttcFile)
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.
abstract
String
[][]
getAllNameEntries
()
Gets all the entries of the names-table.
static
String
[][]
getAllNameEntries
(
String
name,
String
encoding, byte[] ttfAfm)
Gets all the entries of the namestable from the font.
getAscent
(
String
text)
Gets the ascent of a
String
in normalized 1000 units.
float
getAscentPoint
(
String
text, float fontSize)
Gets the ascent of a
String
in points.
protected static
String
getBaseName
(
String
name)
Gets the name without the modifiers Bold, Italic or BoldItalic.
int[]
getCharBBox
(int c)
Gets the smallest box enclosing the character contours.
getCidCode
(int c)
Gets the CID code given an Unicode.
String
[]
getCodePagesSupported
()
Gets the code pages supported by the font.
getCompressionLevel
()
Returns the compression level used for the font streams.
getDescent
(
String
text)
Gets the descent of a
String
in normalized 1000 units.
float
getDescentPoint
(
String
text, float fontSize)
Gets the descent of a
String
in points.
String
[]
getDifferences
()
Gets the array with the names of the characters.
static
ArrayList
<
Object
[]>
getDocumentFonts
(
PdfReader
reader)
Gets a list of all document fonts.
static
ArrayList
<
Object
[]>
getDocumentFonts
(
PdfReader
reader, int page)
Gets a list of the document fonts in a particular page.
String
getEncoding
()
Gets the encoding used to convert
String
into
byte[]
.
abstract
String
[][]
getFamilyFontName
()
Gets the family name of the font.
abstract float
getFontDescriptor
(int key, float fontSize)
Gets the font parameter identified by
key
.
double[]
getFontMatrix
()
get default array of six numbers specifying the font matrix, mapping glyph space to text space
getFontType
()
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 int
getKerning
(int char1, int char2)
Gets the kerning between two Unicode chars.
abstract
String
getPostscriptFontName
()
Gets the postscript font name.
protected abstract int[]
getRawCharBBox
(int c,
String
name)
String
getSubfamily
()
char[]
getUnicodeDifferences
()
Gets the array with the unicode characters.
getUnicodeEquivalent
(int c)
Gets the Unicode equivalent to a CID.
getWidth
(int char1)
Gets the width of a
char
in normalized 1000 units.
getWidth
(
String
text)
Gets the width of a
String
in normalized 1000 units.
float
getWidthPoint
(int char1, float fontSize)
Gets the width of a
char
in points.
float
getWidthPoint
(
String
text, float fontSize)
Gets the width of a
String
in points.
float
getWidthPointKerned
(
String
text, float fontSize)
Gets the width of a
String
in points taking kerning into account.
int[]
getWidths
()
Gets the font width array.
abstract boolean
hasKernPairs
()
Checks if the font has any kerning pairs.
boolean
isDirectTextToByte
()
Gets the direct conversion of
char
to
byte
.
boolean
isEmbedded
()
Gets the embedded flag.
boolean
isFontSpecific
()
Gets the symbolic flag of the font.
boolean
isForceWidthsOutput
()
Gets the state of the property.
boolean
isSubset
()
Indicates if all the glyphs and widths for that particular encoding should be included in the document.
boolean
isVertical
()
Indicates whether the font is used for verticl writing or not.
protected static
String
normalizeEncoding
(
String
enc)
Normalize the encoding names.
boolean
setCharAdvance
(int c, int advance)
Sets the character advance.
setCompressionLevel
(int compressionLevel)
Sets the compression level to be used for the font streams.
setDirectTextToByte
(boolean directTextToByte)
Sets the conversion of
char
directly to
byte
by casting.
setFontDescriptor
(int key, float value)
Sets the font parameter identified by
key
.
setForceWidthsOutput
(boolean forceWidthsOutput)
Set to
true
to force the generation of the widths array.
abstract boolean
setKerning
(int char1, int char2, int kern)
Sets the kerning between two Unicode chars.
abstract void
setPostscriptFontName
(
String
name)
Sets the font name that will appear in the pdf font dictionary.
setSubset
(boolean subset)
Indicates if all the glyphs and widths for that particular encoding should be included in the document.
createFont
public static BaseFont createFont(String name,
String encoding,
boolean embedded)
throws DocumentException,
IOException
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);
createFont
public static BaseFont createFont(String name,
String encoding,
boolean embedded,
boolean forceRead)
throws DocumentException,
IOException
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);
forceRead
- in some cases (TrueTypeFont, Type1Font), the full font file will be read and kept in memory if forceRead is true
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
Since:
2.1.5
createFont
public static BaseFont createFont(String name,
String encoding,
boolean embedded,
boolean cached,
byte[] ttfAfm,
byte[] pfb)
throws DocumentException,
IOException
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"
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
Since:
iText 0.80
createFont
public static BaseFont createFont(String name,
String encoding,
boolean embedded,
boolean cached,
byte[] ttfAfm,
byte[] pfb,
boolean noThrow)
throws DocumentException,
IOException
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"
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
noThrow
- if true will not throw an exception if the font is not recognized and will return null, if false will throw an exception if the font is not recognized. Note that even if true an exception may be thrown in some circumstances. This parameter is useful for FontFactory that may have to check many invalid font names before finding the right one
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
Since:
2.0.3
createFont
public static BaseFont createFont(String name,
String encoding,
boolean embedded,
boolean cached,
byte[] ttfAfm,
byte[] pfb,
boolean noThrow,
boolean forceRead)
throws DocumentException,
IOException
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"
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
noThrow
- if true will not throw an exception if the font is not recognized and will return null, if false will throw an exception if the font is not recognized. Note that even if true an exception may be thrown in some circumstances. This parameter is useful for FontFactory that may have to check many invalid font names before finding the right one
forceRead
- in some cases (TrueTypeFont, Type1Font), the full font file will be read and kept in memory if forceRead is true
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
Since:
2.1.5
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
getAllNameEntries
public abstract 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}.
Returns:
the full name of the font
Since:
2.0.8
getFullFontName
public static String[][] getFullFontName(String name,
String encoding,
byte[] ttfAfm)
throws DocumentException,
IOException
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
getAllFontNames
public static Object[] getAllFontNames(String name,
String encoding,
byte[] ttfAfm)
throws DocumentException,
IOException
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
getAllNameEntries
public static String[][] getAllNameEntries(String name,
String encoding,
byte[] ttfAfm)
throws DocumentException,
IOException
Gets all the entries of the namestable 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
Since:
2.0.8
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
enumerateTTCNames
public static String[] enumerateTTCNames(String ttcFile)
throws DocumentException,
IOException
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)
throws DocumentException,
IOException
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
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 addSubsetRange(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
getUnicodeEquivalent
public int getUnicodeEquivalent(int 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.
getDocumentFonts
public static ArrayList<Object[]> 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<Object[]> 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
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.
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