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.
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.
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.
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
public static final boolean EMBEDDED
if the font has to be embedded
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_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.
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.
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
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
charBBoxes
protected int[][] charBBoxes
differences
protected String[] differences
encoding names
directTextToByte
protected boolean directTextToByte
Converts char
directly to byte
by casting.
embedded
protected boolean embedded
true if the font is to be embedded in the PDF
encoding
protected String encoding
encoding used with this font
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
(package private) int fontType
The font type.
forceWidthsOutput
protected boolean forceWidthsOutput
Forces the output of the width array. Only matters for the 14
built-in fonts.
notdef
public static final String notdef
a not defined character in a custom PDF encoding
subset
protected boolean subset
Indicates if all the glyphs and widths for that particular
encoding should be included in the document.
unicodeDifferences
protected char[] unicodeDifferences
same as differences but with the unicode codes
widths
protected int[] widths
table of characters widths for this encoding
charExists
public boolean charExists(char c)
Checks if a character exists in this font.
c
- the character to check
true
if the character has a glyph,
false
otherwise
convertToBytes
(package private) byte[] convertToBytes(String text)
Converts a String
to a byte array according
to the font's encoding.
text
- the String
to be converted
- an array of
byte
representing the conversion according to the font's encoding
createEncoding
protected void createEncoding()
Creates the widths
and the differences
arrays
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 by an AFM 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.
This method calls:
createFont(name, encoding, embedded, true, null, null);
name
- the name of the font or it's location on fileencoding
- the encoding to be applied to this fontembedded
- true if the font is to be embedded in the PDF
- returns a new font. This font may come from the cache
createFont
public static BaseFont createFont(String name,
String encoding,
boolean embedded,
boolean cached,
ttfAfm[] ,
pfb[] )
throws DocumentException,
IOException
Creates a new font. This font can be one of the 14 built in types,
a Type1 font referred by an AFM 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. The name is still required to identify
the font type.
name
- the name of the font or it's location on fileencoding
- the encoding to be applied to this fontembedded
- true if the font is to be embedded in the PDFcached
- true if the font comes from the cache or is added to
the cache if new, false if the font is always created new
- returns a new font. This font may come from the cache but only if cached
is true, otherwise it will always be created new
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.
fontRef
- the reference to the document 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.
enumerateTTCNames
public static String[] enumerateTTCNames(String ttcFile)
throws DocumentException,
IOException
Enumerates the postscript font names present inside a
True Type Collection.
ttcFile
- the file name of the font
- the postscript font names
enumerateTTCNames
public static String[] enumerateTTCNames(ttcArray[] )
throws DocumentException,
IOException
Enumerates the postscript font names present inside a
True Type Collection.
- the postscript font names
getAllFontNames
public static Object[] getAllFontNames(String name,
String encoding,
ttfAfm[] )
throws DocumentException,
IOException
Gets all the names from the font. Only the required tables are read.
name
- the name of the fontencoding
- the encoding of the font
- an array of Object[] built with {getPostscriptFontName(), getFamilyFontName(), getFullFontName()}
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.
text
- the String
to get the ascent of
- 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.
text
- the String
to get the ascent offontSize
- the size of the font
getBaseName
protected static String getBaseName(String name)
Gets the name without the modifiers Bold, Italic or BoldItalic.
name
- the full name of the font
- 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].
c
- the character to get the contour bounding box from
- 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.
getCodePagesSupported
public String[] getCodePagesSupported()
Gets the code pages supported by the font. This has only meaning
with True Type fonts.
- 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.
text
- the String
to get the descent of
- 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.
text
- the String
to get the descent offontSize
- the size of the font
getDifferences
public String[] getDifferences()
Gets the array with the names of the characters.
- 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.
reader
- the document where the fonts are to be listed from
- 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.
reader
- the document where the fonts are to be listed frompage
- the page to list the fonts from
- the list of fonts and references
getEncoding
public String getEncoding()
Gets the encoding used to convert String
into byte[]
.
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}.
- 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
.
key
- the parameter to be extractedfontSize
- the font size 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.
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}.
- the full name of the font
getFullFontName
public static String[][] getFullFontName(String name,
String encoding,
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}.
name
- the name of the fontencoding
- the encoding of the font
- the full name of the font
getKerning
public abstract int getKerning(char char1,
char char2)
Gets the kerning between two Unicode chars.
char1
- the first charchar2
- the second char
- the kerning to be applied in normalized 1000 units
getPostscriptFontName
public abstract String getPostscriptFontName()
Gets the postscript font name.
getRawCharBBox
protected abstract int[] getRawCharBBox(int c,
String name)
getRawWidth
(package private) 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.
c
- the unicode charname
- the glyph name
getResourceStream
public static InputStream getResourceStream(String key)
Gets the font resources.
key
- the full name of the resource
- the
InputStream
to get the resource or
null
if not found
getResourceStream
public static InputStream getResourceStream(String key,
ClassLoader loader)
Gets the font resources.
key
- the full name of the resourceloader
- the ClassLoader to load the resource or null to try the ones available
- the
InputStream
to get the resource or
null
if not found
getUnicodeDifferences
public char[] getUnicodeDifferences()
Gets the array with the unicode characters.
- the array with the unicode characters
getUnicodeDifferences
(package private) char getUnicodeDifferences(int index)
Gets the Unicode character corresponding to the byte output to the pdf stream.
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.
getWidth
public int getWidth(String text)
Gets the width of a String
in normalized 1000 units.
text
- the String
to get the witdth of
- the width in normalized 1000 units
getWidth
public int getWidth(char char1)
Gets the width of a char
in normalized 1000 units.
char1
- the unicode char
to get the width of
- the width in normalized 1000 units
getWidthPoint
public float getWidthPoint(String text,
float fontSize)
Gets the width of a String
in points.
text
- the String
to get the witdth offontSize
- the font size
getWidthPoint
public float getWidthPoint(char char1,
float fontSize)
Gets the width of a char
in points.
char1
- the char
to get the witdth offontSize
- the font size
getWidthPointKerned
public float getWidthPointKerned(String text,
float fontSize)
Gets the width of a String
in points taking kerning
into account.
text
- the String
to get the witdth offontSize
- the font size
getWidths
public int[] getWidths()
Gets the font width array.
hasKernPairs
public abstract boolean hasKernPairs()
Checks if the font has any kerning pairs.
true
if the font has any kerning pairs
isDirectTextToByte
public boolean isDirectTextToByte()
Gets the direct conversion of char
to byte
.
- value of property directTextToByte.
setDirectTextToByte(boolean directTextToByte)
isEmbedded
public boolean isEmbedded()
Gets the embedded flag.
true
if the font is embedded.
isFontSpecific
public boolean isFontSpecific()
Gets the symbolic flag of the font.
true
if the font is symbolic
isForceWidthsOutput
public boolean isForceWidthsOutput()
Gets the state of the property.
- 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.
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".
enc
- the encoding to be normalized
setCharAdvance
public boolean setCharAdvance(char c,
int advance)
Sets the character advance.
c
- the characteradvance
- the character advance normalized to 1000 units
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().
directTextToByte
- New value of property directTextToByte.
setForceWidthsOutput
public void setForceWidthsOutput(boolean forceWidthsOutput)
Set to true
to force the generation of the
widths array.
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.
char1
- the first charchar2
- the second charkern
- the kerning to apply in normalized 1000 units
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.
setSubset
public void setSubset(boolean subset)
Indicates if all the glyphs and widths for that particular
encoding should be included in the document. Set to false
to include all.
subset
- new value of property subset
writeFont
(package private) abstract void writeFont(PdfWriter writer,
PdfIndirectReference ref,
params[] )
throws DocumentException,
IOException
Outputs to the writer the font dictionaries and streams.
writer
- the writer for this documentref
- the font indirect reference