|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lowagie.text.pdf.BaseFont
com.lowagie.text.pdf.TrueTypeFont
com.lowagie.text.pdf.TrueTypeFontUnicode
Represents a True Type font with Unicode encoding. All the character in the font can be used directly by using the encoding Identity-H or Identity-V. This is the only way to represent some character sets such as Thai.
Nested Class Summary | |
protected static class |
TrueTypeFont.FontHeader
The components of table 'head'. |
protected static class |
TrueTypeFont.HorizontalHeader
The components of table 'hhea'. |
protected static class |
TrueTypeFont.WindowsMetrics
The components of table 'OS/2'. |
Nested classes inherited from class com.lowagie.text.pdf.BaseFont |
BaseFont.StreamFont |
Field Summary | |
protected int[][] |
bboxes
|
protected boolean |
cff
|
protected int |
cffLength
|
protected int |
cffOffset
|
protected HashMap |
cmap10
The map containing the code information for the table 'cmap', encoding 1.0. |
protected HashMap |
cmap31
The map containing the code information for the table 'cmap', encoding 3.1 in Unicode. |
(package private) static String[] |
codePages
The code pages possible for a True Type font. |
protected int |
directoryOffset
The offset from the start of the file to the table directory. |
protected String[][] |
familyName
The family name of the font |
protected String |
fileName
The file name. |
protected String |
fontName
The font name. |
protected String[][] |
fullName
The full name of the font |
protected int[] |
GlyphWidths
The width of the glyphs. |
protected TrueTypeFont.FontHeader |
head
The content of table 'head'. |
protected TrueTypeFont.HorizontalHeader |
hhea
The content of table 'hhea'. |
protected boolean |
isFixedPitch
true if all the glyphs have the same width. |
protected double |
italicAngle
The italic angle. |
protected boolean |
justNames
|
protected IntHashtable |
kerning
The map containing the kerning information. |
protected TrueTypeFont.WindowsMetrics |
os_2
The content of table 'OS/2'. |
protected RandomAccessFileOrArray |
rf
The file in use. |
protected String |
style
The style modifier |
protected HashMap |
tables
Contains the location of the several tables. |
protected String |
ttcIndex
The index for the TTC font. |
(package private) boolean |
vertical
true if the encoding is vertical. |
Constructor Summary | |
(package private) |
TrueTypeFontUnicode(String ttFile,
String enc,
boolean emb,
byte[] ttfAfm)
Creates a new TrueType font addressed by Unicode characters. |
Method Summary | |
protected void |
addRangeUni(HashMap longTag,
boolean includeMetrics,
boolean subsetp)
|
boolean |
charExists(char c)
Checks if a character exists in this font. |
(package private) void |
checkCff()
|
protected static int[] |
compactRanges(ArrayList ranges)
|
int |
compare(Object o1,
Object o2)
The method used to sort the metrics array. |
(package private) byte[] |
convertToBytes(String text)
A forbidden operation. |
(package private) void |
fillTables()
Reads the tables 'head', 'hhea', 'OS/2' and 'post' filling several variables. |
(package private) String |
getBaseFont()
Gets the Postscript font name. |
int[] |
getCharBBox(char c)
Gets the smallest box enclosing the character contours. |
private PdfDictionary |
getCIDFontType2(PdfIndirectReference fontDescriptor,
String subsetPrefix,
Object[] metrics)
Generates the CIDFontTyte2 dictionary. |
String[] |
getCodePagesSupported()
Gets the code pages supported by the font. |
String[][] |
getFamilyFontName()
Gets the family name of the font. |
protected PdfDictionary |
getFontBaseType(PdfIndirectReference fontDescriptor,
String subsetPrefix,
int firstChar,
int lastChar,
byte[] shortTag)
Generates the font dictionary for this font. |
private PdfDictionary |
getFontBaseType(PdfIndirectReference descendant,
String subsetPrefix,
PdfIndirectReference toUnicode)
Generates the font dictionary. |
float |
getFontDescriptor(int key,
float fontSize)
Gets the font parameter identified by key . |
protected PdfDictionary |
getFontDescriptor(PdfIndirectReference fontStream,
String subsetPrefix)
Generates the font descriptor for this font. |
protected byte[] |
getFullFont()
|
String[][] |
getFullFontName()
Gets the full name of the font. |
protected int |
getGlyphWidth(int glyph)
Gets a glyph width. |
int |
getKerning(char char1,
char char2)
Gets the kerning between two Unicode chars. |
int[] |
getMetricsTT(int c)
Gets the glyph index and metrics for a character. |
(package private) String[][] |
getNames(int id)
Extracts the names of the font in all the languages available. |
String |
getPostscriptFontName()
Gets the postscript font name. |
protected int[] |
getRawCharBBox(int c,
String name)
|
(package private) int |
getRawWidth(int c,
String name)
Gets the width from the font according to the unicode char c . |
private PdfStream |
getToUnicode(Object[] metrics)
Creates a ToUnicode CMap to allow copy and paste from Acrobat. |
protected static String |
getTTCName(String name)
Gets the name from a composed TTC file name. |
int |
getWidth(String text)
Gets the width of a String in normalized 1000 units. |
boolean |
hasKernPairs()
Checks if the font has any kerning pairs. |
(package private) void |
process(byte[] ttfAfm)
Reads the font data. |
(package private) void |
readCMaps()
Reads the several maps from the table 'cmap'. |
(package private) HashMap |
readFormat0()
The information in the maps of the table 'cmap' is coded in several formats. |
(package private) HashMap |
readFormat4()
The information in the maps of the table 'cmap' is coded in several formats. |
(package private) HashMap |
readFormat6()
The information in the maps of the table 'cmap' is coded in several formats. |
protected void |
readGlyphWidths()
Reads the glyphs widths. |
(package private) void |
readKerning()
Reads the kerning information from the 'kern' table. |
protected String |
readStandardString(int length)
Reads a String from the font file as bytes using the Cp1252
encoding. |
protected String |
readUnicodeString(int length)
Reads a Unicode String from the font file. |
boolean |
setCharAdvance(char c,
int advance)
Sets the character advance. |
boolean |
setKerning(char char1,
char char2,
int kern)
Sets the kerning between two Unicode chars. |
void |
setPostscriptFontName(String name)
Sets the font name that will appear in the pdf font dictionary. |
(package private) static String |
toHex(int n)
Gets an hex string in the format "<HHHH>". |
(package private) void |
writeFont(PdfWriter writer,
PdfIndirectReference ref,
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 |
Methods inherited from interface java.util.Comparator |
equals |
Field Detail |
boolean vertical
true
if the encoding is vertical.
static final String[] codePages
protected boolean justNames
protected HashMap tables
int[2]
where position 0
is the offset from the start of the file and position 1 is the length
of the table.
protected RandomAccessFileOrArray rf
protected String fileName
protected boolean cff
protected int cffOffset
protected int cffLength
protected int directoryOffset
protected String ttcIndex
String
for a
TTF file.
protected String style
protected TrueTypeFont.FontHeader head
protected TrueTypeFont.HorizontalHeader hhea
protected TrueTypeFont.WindowsMetrics os_2
protected int[] GlyphWidths
protected int[][] bboxes
protected HashMap cmap10
int[2]
where position 0
is the glyph number and position 1 is the glyph width normalized to 1000
units.
protected HashMap cmap31
The key is the code and the value is an int
[2] where position 0
is the glyph number and position 1 is the glyph width normalized to 1000
units.
protected IntHashtable kerning
Integer
where the top 16 bits
are the glyph number for the first character and the lower 16 bits are the
glyph number for the second character. The value is the amount of kerning in
normalized 1000 units as an Integer
. This value is usually negative.
protected String fontName
protected String[][] fullName
protected String[][] familyName
protected double italicAngle
-Math.atan2(hhea.caretSlopeRun, hhea.caretSlopeRise) * 180 / Math.PI
protected boolean isFixedPitch
true
if all the glyphs have the same width.
Constructor Detail |
TrueTypeFontUnicode(String ttFile, String enc, boolean emb, byte[] ttfAfm) throws DocumentException, IOException
ttFile
- the location of the font on file. The file must end in '.ttf'.
The modifiers after the name are ignored.enc
- the encoding to be applied to this fontemb
- true if the font is to be embedded in the PDFttfAfm
- the font as a byte
array
DocumentException
- the font is invalid
IOException
- the font file could not be readMethod Detail |
public int getWidth(String text)
String
in normalized 1000 units.
getWidth
in class BaseFont
text
- the String
to get the witdth of
private PdfStream getToUnicode(Object[] metrics)
metrics
- metrics[0] contains the glyph index and metrics[2]
contains the Unicode code
null
DocumentException
- on errorstatic String toHex(int n)
n
- the number
private PdfDictionary getCIDFontType2(PdfIndirectReference fontDescriptor, String subsetPrefix, Object[] metrics)
fontDescriptor
- the indirect reference to the font descriptorsubsetPrefix
- the subset prefixmetrics
- the horizontal width metrics
private PdfDictionary getFontBaseType(PdfIndirectReference descendant, String subsetPrefix, PdfIndirectReference toUnicode)
descendant
- the descendant dictionarysubsetPrefix
- the subset prefixtoUnicode
- the ToUnicode stream
public int compare(Object o1, Object o2)
compare
in interface Comparator
o1
- the first elemento2
- the second element
void writeFont(PdfWriter writer, PdfIndirectReference ref, Object[] params) throws DocumentException, IOException
writeFont
in class TrueTypeFont
writer
- the writer for this documentref
- the font indirect referenceparams
- several parameters that depend on the font type
IOException
- on error
DocumentException
- error in generating the objectbyte[] convertToBytes(String text)
convertToBytes
in class BaseFont
text
- the text
null
public boolean charExists(char c)
charExists
in class BaseFont
c
- the character to check
true
if the character has a glyph,
false
otherwisepublic boolean setCharAdvance(char c, int advance)
setCharAdvance
in class BaseFont
c
- the characteradvance
- the character advance normalized to 1000 units
true
if the advance was set,
false
otherwisepublic int[] getCharBBox(char c)
BaseFont
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].
getCharBBox
in class BaseFont
c
- the character to get the contour bounding box from
null
protected static String getTTCName(String name)
name
- the full name
void fillTables() throws DocumentException, IOException
DocumentException
- the font is invalid
IOException
- the font file could not be readString getBaseFont() throws DocumentException, IOException
DocumentException
- the font is invalid
IOException
- the font file could not be readString[][] getNames(int id) throws DocumentException, IOException
id
- the name id to retrieve
DocumentException
- on error
IOException
- on errorvoid checkCff()
void process(byte[] ttfAfm) throws DocumentException, IOException
ttfAfm
- the font as a byte
array, possibly null
DocumentException
- the font is invalid
IOException
- the font file could not be readprotected String readStandardString(int length) throws IOException
String
from the font file as bytes using the Cp1252
encoding.
length
- the length of bytes to read
String
read
IOException
- the font file could not be readprotected String readUnicodeString(int length) throws IOException
String
from the font file. Each character is
represented by two bytes.
length
- the length of bytes to read. The String
will have length
/2
characters
String
read
IOException
- the font file could not be readprotected void readGlyphWidths() throws DocumentException, IOException
DocumentException
- the font is invalid
IOException
- the font file could not be readprotected int getGlyphWidth(int glyph)
glyph
- the glyph to get the width of
void readCMaps() throws DocumentException, IOException
DocumentException
- the font is invalid
IOException
- the font file could not be readHashMap readFormat0() throws IOException
HashMap
representing this map
IOException
- the font file could not be readHashMap readFormat4() throws IOException
HashMap
representing this map
IOException
- the font file could not be readHashMap readFormat6() throws IOException
HashMap
representing this map
IOException
- the font file could not be readvoid readKerning() throws IOException
IOException
- the font file could not be readpublic int getKerning(char char1, char char2)
getKerning
in class BaseFont
char1
- the first charchar2
- the second char
int getRawWidth(int c, String name)
c
.
If the name
is null it's a symbolic font.
getRawWidth
in class BaseFont
c
- the unicode charname
- the glyph name
protected PdfDictionary getFontDescriptor(PdfIndirectReference fontStream, String subsetPrefix)
subsetPrefix
- the subset prefixfontStream
- the indirect reference to a PdfStream containing the font or null
null
DocumentException
- if there is an errorprotected PdfDictionary getFontBaseType(PdfIndirectReference fontDescriptor, String subsetPrefix, int firstChar, int lastChar, byte[] shortTag)
subsetPrefix
- the subset prefxfirstChar
- the first valid characterlastChar
- the last valid charactershortTag
- a 256 bytes long byte
array where each unused byte is represented by 0fontDescriptor
- the indirect reference to a PdfDictionary containing the font descriptor or null
DocumentException
- if there is an errorprotected byte[] getFullFont() throws IOException
IOException
protected static int[] compactRanges(ArrayList ranges)
protected void addRangeUni(HashMap longTag, boolean includeMetrics, boolean subsetp)
public float getFontDescriptor(int key, float fontSize)
key
. Valid values
for key
are ASCENT
, CAPHEIGHT
, DESCENT
and ITALICANGLE
.
getFontDescriptor
in class BaseFont
key
- the parameter to be extractedfontSize
- the font size in points
public int[] getMetricsTT(int c)
c
- the character
int
array with {glyph index, width}public String getPostscriptFontName()
getPostscriptFontName
in class BaseFont
public String[] getCodePagesSupported()
getCodePagesSupported
in class BaseFont
public String[][] getFullFontName()
getFullFontName
in class BaseFont
public String[][] getFamilyFontName()
getFamilyFontName
in class BaseFont
public boolean hasKernPairs()
hasKernPairs
in class BaseFont
true
if the font has any kerning pairspublic void setPostscriptFontName(String name)
setPostscriptFontName
in class BaseFont
name
- the new font namepublic boolean setKerning(char char1, char char2, int kern)
setKerning
in class BaseFont
char1
- the first charchar2
- the second charkern
- the kerning to apply in normalized 1000 units
true
if the kerning was applied, false
otherwiseprotected int[] getRawCharBBox(int c, String name)
getRawCharBBox
in class BaseFont
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |