|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lowagie.text.pdf.BaseFont
public abstract class BaseFont
Base class for the several font types supported
Nested Class Summary | |
---|---|
(package private) static class |
BaseFont.StreamFont
Generates the PDF stream with the Type1 and Truetype fonts returning a PdfStream. |
Field Summary | |
---|---|
static int |
ASCENT
The maximum height above the baseline reached by glyphs in this font, excluding the height of glyphs for accented characters. |
static int |
AWT_ASCENT
java.awt.Font property |
static int |
AWT_DESCENT
java.awt.Font property |
static int |
AWT_LEADING
java.awt.Font property |
static int |
AWT_MAXADVANCE
java.awt.Font property |
static int |
BBOXLLX
The lower left x glyph coordinate. |
static int |
BBOXLLY
The lower left y glyph coordinate. |
static int |
BBOXURX
The upper right x glyph coordinate. |
static int |
BBOXURY
The upper right y glyph coordinate. |
protected static java.util.HashMap |
BuiltinFonts14
list of the 14 built in fonts. |
static boolean |
CACHED
if the font has to be cached |
static int |
CAPHEIGHT
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
|
protected int[][] |
charBBoxes
|
static char |
CID_NEWLINE
The fake CID code that represents a newline. |
static java.lang.String |
COURIER
This is a possible value of a base 14 type 1 font |
static java.lang.String |
COURIER_BOLD
This is a possible value of a base 14 type 1 font |
static java.lang.String |
COURIER_BOLDOBLIQUE
This is a possible value of a base 14 type 1 font |
static java.lang.String |
COURIER_OBLIQUE
This is a possible value of a base 14 type 1 font |
static java.lang.String |
CP1250
A possible encoding. |
static java.lang.String |
CP1252
A possible encoding. |
static java.lang.String |
CP1257
A possible encoding. |
static int |
DESCENT
The maximum depth below the baseline reached by glyphs in this font. |
protected java.lang.String[] |
differences
encoding names |
protected boolean |
directTextToByte
Converts char directly to byte
by casting. |
protected boolean |
embedded
true if the font is to be embedded in the PDF |
static boolean |
EMBEDDED
if the font has to be embedded |
protected java.lang.String |
encoding
encoding used with this font |
protected boolean |
fastWinansi
|
static int |
FONT_TYPE_CJK
The font is CJK. |
static int |
FONT_TYPE_DOCUMENT
A font already inside the document. |
static int |
FONT_TYPE_T1
The font is Type 1. |
static int |
FONT_TYPE_T3
A Type3 font. |
static int |
FONT_TYPE_TT
The font is True Type with a standard encoding. |
static int |
FONT_TYPE_TTUNI
The font is True Type with a Unicode encoding. |
protected static java.util.HashMap |
fontCache
cache for the fonts already used. |
protected boolean |
fontSpecific
true if the font must use it's built in encoding. |
(package private) int |
fontType
The font type. |
protected boolean |
forceWidthsOutput
Forces the output of the width array. |
static java.lang.String |
HELVETICA
This is a possible value of a base 14 type 1 font |
static java.lang.String |
HELVETICA_BOLD
This is a possible value of a base 14 type 1 font |
static java.lang.String |
HELVETICA_BOLDOBLIQUE
This is a possible value of a base 14 type 1 font |
static java.lang.String |
HELVETICA_OBLIQUE
This is a possible value of a base 14 type 1 font |
static java.lang.String |
IDENTITY_H
The Unicode encoding with horizontal writing. |
static java.lang.String |
IDENTITY_V
The Unicode encoding with vertical writing. |
static int |
ITALICANGLE
The angle, expressed in degrees counterclockwise from the vertical, of the dominant vertical strokes of the font. |
static java.lang.String |
MACROMAN
A possible encoding. |
static boolean |
NOT_CACHED
if the font doesn't have to be cached |
static boolean |
NOT_EMBEDDED
if the font doesn't have to be embedded |
static java.lang.String |
notdef
a not defined character in a custom PDF encoding |
static java.lang.String |
RESOURCE_PATH
The path to the font resources. |
protected boolean |
subset
Indicates if all the glyphs and widths for that particular encoding should be included in the document. |
protected java.util.ArrayList |
subsetRanges
|
static java.lang.String |
SYMBOL
This is a possible value of a base 14 type 1 font |
static java.lang.String |
TIMES_BOLD
This is a possible value of a base 14 type 1 font |
static java.lang.String |
TIMES_BOLDITALIC
This is a possible value of a base 14 type 1 font |
static java.lang.String |
TIMES_ITALIC
This is a possible value of a base 14 type 1 font |
static java.lang.String |
TIMES_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 java.lang.String |
WINANSI
A possible encoding. |
static java.lang.String |
ZAPFDINGBATS
This is a possible value of a base 14 type 1 font |
Constructor Summary | |
---|---|
protected |
BaseFont()
Creates new BaseFont |
Method Summary | |
---|---|
private static void |
addFont(PRIndirectReference fontRef,
IntHashtable hits,
java.util.ArrayList fonts)
|
void |
addSubsetRange(int[] range)
Adds a character range when subsetting. |
boolean |
charExists(char c)
Checks if a character exists in this font. |
(package private) byte[] |
convertToBytes(java.lang.String text)
Converts a String to a byte array according
to the font's encoding. |
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. |
protected void |
createEncoding()
Creates the widths and the differences arrays |
static BaseFont |
createFont(PRIndirectReference fontRef)
Creates a font based on an existing document font. |
static BaseFont |
createFont(java.lang.String name,
java.lang.String encoding,
boolean embedded)
Creates a new font. |
static BaseFont |
createFont(java.lang.String name,
java.lang.String encoding,
boolean embedded,
boolean cached,
byte[] ttfAfm,
byte[] pfb)
Creates a new font. |
static java.lang.String |
createSubsetPrefix()
Creates a unique subset prefix to be added to the font name when the font is embedded and subset. |
static java.lang.String[] |
enumerateTTCNames(byte[] ttcArray)
Enumerates the postscript font names present inside a True Type Collection. |
static java.lang.String[] |
enumerateTTCNames(java.lang.String ttcFile)
Enumerates the postscript font names present inside a True Type Collection. |
static java.lang.Object[] |
getAllFontNames(java.lang.String name,
java.lang.String encoding,
byte[] ttfAfm)
Gets all the names from the font. |
int |
getAscent(java.lang.String text)
Gets the ascent of a String in normalized 1000 units. |
float |
getAscentPoint(java.lang.String text,
float fontSize)
Gets the ascent of a String in points. |
protected static java.lang.String |
getBaseName(java.lang.String name)
Gets the name without the modifiers Bold, Italic or BoldItalic. |
int[] |
getCharBBox(char c)
Gets the smallest box enclosing the character contours. |
char |
getCidCode(char c)
Gets the CID code given an Unicode. |
java.lang.String[] |
getCodePagesSupported()
Gets the code pages supported by the font. |
int |
getDescent(java.lang.String text)
Gets the descent of a String in normalized 1000 units. |
float |
getDescentPoint(java.lang.String text,
float fontSize)
Gets the descent of a String in points. |
java.lang.String[] |
getDifferences()
Gets the array with the names of the characters. |
static java.util.ArrayList |
getDocumentFonts(PdfReader reader)
Gets a list of all document fonts. |
static java.util.ArrayList |
getDocumentFonts(PdfReader reader,
int page)
Gets a list of the document fonts in a particular page. |
java.lang.String |
getEncoding()
Gets the encoding used to convert String into byte[] . |
abstract java.lang.String[][] |
getFamilyFontName()
Gets the family name of the font. |
abstract float |
getFontDescriptor(int key,
float fontSize)
Gets the font parameter identified by key . |
int |
getFontType()
Gets the font type. |
abstract java.lang.String[][] |
getFullFontName()
Gets the full name of the font. |
static java.lang.String[][] |
getFullFontName(java.lang.String name,
java.lang.String encoding,
byte[] ttfAfm)
Gets the full name of the font. |
abstract int |
getKerning(char char1,
char char2)
Gets the kerning between two Unicode chars. |
abstract java.lang.String |
getPostscriptFontName()
Gets the postscript font name. |
protected abstract int[] |
getRawCharBBox(int c,
java.lang.String name)
|
(package private) abstract int |
getRawWidth(int c,
java.lang.String name)
Gets the width from the font according to the Unicode char c
or the name . |
static java.io.InputStream |
getResourceStream(java.lang.String key)
Gets the font resources. |
static java.io.InputStream |
getResourceStream(java.lang.String key,
java.lang.ClassLoader loader)
Gets the font resources. |
char[] |
getUnicodeDifferences()
Gets the array with the unicode characters. |
(package private) char |
getUnicodeDifferences(int index)
Gets the Unicode character corresponding to the byte output to the pdf stream. |
char |
getUnicodeEquivalent(char c)
Gets the Unicode equivalent to a CID. |
int |
getWidth(char char1)
Gets the width of a char in normalized 1000 units. |
int |
getWidth(java.lang.String text)
Gets the width of a String in normalized 1000 units. |
float |
getWidthPoint(char char1,
float fontSize)
Gets the width of a char in points. |
float |
getWidthPoint(java.lang.String text,
float fontSize)
Gets the width of a String in points. |
float |
getWidthPointKerned(java.lang.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. |
protected static java.lang.String |
normalizeEncoding(java.lang.String enc)
Normalize the encoding names. |
private static void |
recourseFonts(PdfDictionary page,
IntHashtable hits,
java.util.ArrayList fonts,
int level)
|
boolean |
setCharAdvance(char c,
int advance)
Sets the character advance. |
void |
setDirectTextToByte(boolean directTextToByte)
Sets the conversion of char directly to byte
by casting. |
void |
setForceWidthsOutput(boolean forceWidthsOutput)
Set to true to force the generation of the
widths array. |
abstract boolean |
setKerning(char char1,
char char2,
int kern)
Sets the kerning between two Unicode chars. |
abstract void |
setPostscriptFontName(java.lang.String name)
Sets the font name that will appear in the pdf font dictionary. |
void |
setSubset(boolean subset)
Indicates if all the glyphs and widths for that particular encoding should be included in the document. |
(package private) abstract void |
writeFont(PdfWriter writer,
PdfIndirectReference ref,
java.lang.Object[] params)
Outputs to the writer the font dictionaries and streams. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String COURIER
public static final java.lang.String COURIER_BOLD
public static final java.lang.String COURIER_OBLIQUE
public static final java.lang.String COURIER_BOLDOBLIQUE
public static final java.lang.String HELVETICA
public static final java.lang.String HELVETICA_BOLD
public static final java.lang.String HELVETICA_OBLIQUE
public static final java.lang.String HELVETICA_BOLDOBLIQUE
public static final java.lang.String SYMBOL
public static final java.lang.String TIMES_ROMAN
public static final java.lang.String TIMES_BOLD
public static final java.lang.String TIMES_ITALIC
public static final java.lang.String TIMES_BOLDITALIC
public static final java.lang.String ZAPFDINGBATS
public static final int ASCENT
public static final int CAPHEIGHT
public static final int DESCENT
public static final int ITALICANGLE
public static final int BBOXLLX
public static final int BBOXLLY
public static final int BBOXURX
public static final int BBOXURY
public static final int AWT_ASCENT
public static final int AWT_DESCENT
public static final int AWT_LEADING
public static final int AWT_MAXADVANCE
public static final int FONT_TYPE_T1
public static final int FONT_TYPE_TT
public static final int FONT_TYPE_CJK
public static final int FONT_TYPE_TTUNI
public static final int FONT_TYPE_DOCUMENT
public static final int FONT_TYPE_T3
public static final java.lang.String IDENTITY_H
public static final java.lang.String IDENTITY_V
public static final java.lang.String CP1250
public static final java.lang.String CP1252
public static final java.lang.String CP1257
public static final java.lang.String WINANSI
public static final java.lang.String MACROMAN
public static final int[] CHAR_RANGE_LATIN
public static final int[] CHAR_RANGE_ARABIC
public static final int[] CHAR_RANGE_HEBREW
public static final int[] CHAR_RANGE_CYRILLIC
public static final boolean EMBEDDED
public static final boolean NOT_EMBEDDED
public static final boolean CACHED
public static final boolean NOT_CACHED
public static final java.lang.String RESOURCE_PATH
public static final char CID_NEWLINE
protected java.util.ArrayList subsetRanges
int fontType
public static final java.lang.String notdef
protected int[] widths
protected java.lang.String[] differences
protected char[] unicodeDifferences
protected int[][] charBBoxes
protected java.lang.String encoding
protected boolean embedded
protected boolean fontSpecific
encoding
is only used to map a char to the position inside
the font, not to the expected char name.
protected static java.util.HashMap fontCache
protected static final java.util.HashMap BuiltinFonts14
protected boolean forceWidthsOutput
protected boolean directTextToByte
char
directly to byte
by casting.
protected boolean subset
protected boolean fastWinansi
Constructor Detail |
---|
protected BaseFont()
Method Detail |
---|
public static BaseFont createFont(java.lang.String name, java.lang.String encoding, boolean embedded) throws DocumentException, java.io.IOException
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
DocumentException
- the font is invalid
java.io.IOException
- the font file could not be readpublic static BaseFont createFont(java.lang.String name, java.lang.String encoding, boolean embedded, boolean cached, byte[] ttfAfm, byte[] pfb) throws DocumentException, java.io.IOException
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 newttfAfm
- the true type font or the afm in a byte arraypfb
- the pfb in a byte array
DocumentException
- the font is invalid
java.io.IOException
- the font file could not be readpublic static BaseFont createFont(PRIndirectReference fontRef)
fontRef
- the reference to the document font
protected static java.lang.String getBaseName(java.lang.String name)
name
- the full name of the font
protected static java.lang.String normalizeEncoding(java.lang.String enc)
enc
- the encoding to be normalized
protected void createEncoding()
widths
and the differences
arrays
abstract int getRawWidth(int c, java.lang.String name)
c
or the name
. If the name
is null it's a symbolic font.
c
- the unicode charname
- the glyph name
public abstract int getKerning(char char1, char char2)
char1
- the first charchar2
- the second char
public abstract boolean setKerning(char char1, char char2, int kern)
char1
- the first charchar2
- the second charkern
- the kerning to apply in normalized 1000 units
true
if the kerning was applied, false
otherwisepublic int getWidth(char char1)
char
in normalized 1000 units.
char1
- the unicode char
to get the width of
public int getWidth(java.lang.String text)
String
in normalized 1000 units.
text
- the String
to get the witdth of
public int getDescent(java.lang.String text)
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
public int getAscent(java.lang.String text)
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
public float getDescentPoint(java.lang.String text, float fontSize)
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
public float getAscentPoint(java.lang.String text, float fontSize)
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
public float getWidthPointKerned(java.lang.String text, float fontSize)
String
in points taking kerning
into account.
text
- the String
to get the witdth offontSize
- the font size
public float getWidthPoint(java.lang.String text, float fontSize)
String
in points.
text
- the String
to get the witdth offontSize
- the font size
public float getWidthPoint(char char1, float fontSize)
char
in points.
char1
- the char
to get the witdth offontSize
- the font size
byte[] convertToBytes(java.lang.String text)
String
to a byte array according
to the font's encoding.
text
- the String
to be converted
byte
representing the conversion according to the font's encodingabstract void writeFont(PdfWriter writer, PdfIndirectReference ref, java.lang.Object[] params) throws DocumentException, java.io.IOException
writer
- the writer for this documentref
- the font indirect referenceparams
- several parameters that depend on the font type
java.io.IOException
- on error
DocumentException
- error in generating the objectpublic java.lang.String getEncoding()
String
into byte[]
.
public abstract float getFontDescriptor(int key, float fontSize)
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
public int getFontType()
public boolean isEmbedded()
true
if the font is embedded.public boolean isFontSpecific()
true
if the font is symbolicpublic static java.lang.String createSubsetPrefix()
char getUnicodeDifferences(int index)
index
- the byte index
public abstract java.lang.String getPostscriptFontName()
public abstract void setPostscriptFontName(java.lang.String name)
name
- the new font namepublic abstract java.lang.String[][] getFullFontName()
public static java.lang.String[][] getFullFontName(java.lang.String name, java.lang.String encoding, byte[] ttfAfm) throws DocumentException, java.io.IOException
name
- the name of the fontencoding
- the encoding of the fontttfAfm
- the true type font or the afm in a byte array
DocumentException
- on error
java.io.IOException
- on errorpublic static java.lang.Object[] getAllFontNames(java.lang.String name, java.lang.String encoding, byte[] ttfAfm) throws DocumentException, java.io.IOException
name
- the name of the fontencoding
- the encoding of the fontttfAfm
- the true type font or the afm in a byte array
DocumentException
- on error
java.io.IOException
- on errorpublic abstract java.lang.String[][] getFamilyFontName()
public java.lang.String[] getCodePagesSupported()
public static java.lang.String[] enumerateTTCNames(java.lang.String ttcFile) throws DocumentException, java.io.IOException
ttcFile
- the file name of the font
DocumentException
- on error
java.io.IOException
- on errorpublic static java.lang.String[] enumerateTTCNames(byte[] ttcArray) throws DocumentException, java.io.IOException
ttcArray
- the font as a byte
array
DocumentException
- on error
java.io.IOException
- on errorpublic int[] getWidths()
public java.lang.String[] getDifferences()
public char[] getUnicodeDifferences()
public boolean isForceWidthsOutput()
public void setForceWidthsOutput(boolean forceWidthsOutput)
true
to force the generation of the
widths array.
forceWidthsOutput
- true
to force the generation of the
widths arraypublic boolean isDirectTextToByte()
char
to byte
.
setDirectTextToByte(boolean directTextToByte)
public void setDirectTextToByte(boolean directTextToByte)
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.public boolean isSubset()
false
to include all the glyphs and widths.public void setSubset(boolean subset)
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.
subset
- new value of property subsetpublic static java.io.InputStream getResourceStream(java.lang.String key)
key
- the full name of the resource
InputStream
to get the resource or
null
if not foundpublic static java.io.InputStream getResourceStream(java.lang.String key, java.lang.ClassLoader loader)
key
- the full name of the resourceloader
- the ClassLoader to load the resource or null to try the ones available
InputStream
to get the resource or
null
if not foundpublic char getUnicodeEquivalent(char c)
c
- the CID code
public char getCidCode(char c)
c
- the Unicode
public abstract boolean hasKernPairs()
true
if the font has any kerning pairspublic boolean charExists(char c)
c
- the character to check
true
if the character has a glyph,
false
otherwisepublic boolean setCharAdvance(char c, int advance)
c
- the characteradvance
- the character advance normalized to 1000 units
true
if the advance was set,
false
otherwiseprivate static void addFont(PRIndirectReference fontRef, IntHashtable hits, java.util.ArrayList fonts)
private static void recourseFonts(PdfDictionary page, IntHashtable hits, java.util.ArrayList fonts, int level)
public static java.util.ArrayList getDocumentFonts(PdfReader reader)
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
public static java.util.ArrayList getDocumentFonts(PdfReader reader, int page)
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
public int[] getCharBBox(char c)
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
null
protected abstract int[] getRawCharBBox(int c, java.lang.String name)
public void correctArabicAdvance()
public void addSubsetRange(int[] range)
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.
range
- the character range
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |