com.lowagie.text.pdf
class TrueTypeFont extends BaseFont
Modifier and Type | Class and Description |
---|---|
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'.
|
BaseFont.StreamFont
Modifier and Type | Field and Description |
---|---|
protected java.lang.String[][] |
allNameEntries
All the names of the Names-Table
|
protected int[][] |
bboxes |
protected boolean |
cff |
protected int |
cffLength |
protected int |
cffOffset |
protected java.util.HashMap |
cmap10
The map containing the code information for the table 'cmap', encoding 1.0.
|
protected java.util.HashMap |
cmap31
The map containing the code information for the table 'cmap', encoding 3.1
in Unicode.
|
protected java.util.HashMap |
cmapExt |
(package private) static java.lang.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 java.lang.String[][] |
familyName
The family name of the font
|
protected java.lang.String |
fileName
The file name.
|
protected java.lang.String |
fontName
The font name.
|
protected java.lang.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 java.lang.String |
style
The style modifier
|
protected java.util.HashMap |
tables
Contains the location of the several tables.
|
protected java.lang.String |
ttcIndex
The index for the TTC font.
|
protected int |
underlinePosition |
protected int |
underlineThickness |
ASCENT, AWT_ASCENT, AWT_DESCENT, AWT_LEADING, AWT_MAXADVANCE, BBOXLLX, BBOXLLY, BBOXURX, BBOXURY, BuiltinFonts14, CACHED, CAPHEIGHT, CHAR_RANGE_ARABIC, CHAR_RANGE_CYRILLIC, CHAR_RANGE_HEBREW, CHAR_RANGE_LATIN, charBBoxes, CID_NEWLINE, compressionLevel, COURIER, COURIER_BOLD, COURIER_BOLDOBLIQUE, COURIER_OBLIQUE, CP1250, CP1252, CP1257, DESCENT, differences, directTextToByte, embedded, EMBEDDED, encoding, fastWinansi, FONT_TYPE_CJK, FONT_TYPE_DOCUMENT, FONT_TYPE_T1, FONT_TYPE_T3, FONT_TYPE_TT, FONT_TYPE_TTUNI, fontCache, fontSpecific, fontType, forceWidthsOutput, HELVETICA, HELVETICA_BOLD, HELVETICA_BOLDOBLIQUE, HELVETICA_OBLIQUE, IDENTITY_H, IDENTITY_V, ITALICANGLE, MACROMAN, NOT_CACHED, NOT_EMBEDDED, notdef, RESOURCE_PATH, specialMap, STRIKETHROUGH_POSITION, STRIKETHROUGH_THICKNESS, SUBSCRIPT_OFFSET, SUBSCRIPT_SIZE, subset, subsetRanges, SUPERSCRIPT_OFFSET, SUPERSCRIPT_SIZE, SYMBOL, TIMES_BOLD, TIMES_BOLDITALIC, TIMES_ITALIC, TIMES_ROMAN, UNDERLINE_POSITION, UNDERLINE_THICKNESS, unicodeDifferences, widths, WINANSI, ZAPFDINGBATS
Modifier | Constructor and Description |
---|---|
protected |
TrueTypeFont()
This constructor is present to allow extending the class.
|
(package private) |
TrueTypeFont(java.lang.String ttFile,
java.lang.String enc,
boolean emb,
byte[] ttfAfm,
boolean justNames,
boolean forceRead)
Creates a new TrueType font.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addRangeUni(java.util.HashMap longTag,
boolean includeMetrics,
boolean subsetp) |
(package private) void |
checkCff() |
protected static int[] |
compactRanges(java.util.ArrayList ranges) |
(package private) void |
fillTables()
Reads the tables 'head', 'hhea', 'OS/2' and 'post' filling several variables.
|
java.lang.String[][] |
getAllNameEntries()
Gets all the entries of the Names-Table.
|
(package private) java.lang.String[][] |
getAllNames()
Extracts all the names of the names-Table
|
(package private) java.lang.String |
getBaseFont()
Gets the Postscript font name.
|
java.lang.String[] |
getCodePagesSupported()
Gets the code pages supported by the font.
|
java.lang.String[][] |
getFamilyFontName()
Gets the family name of the font.
|
protected PdfDictionary |
getFontBaseType(PdfIndirectReference fontDescriptor,
java.lang.String subsetPrefix,
int firstChar,
int lastChar,
byte[] shortTag)
Generates the font dictionary for this font.
|
float |
getFontDescriptor(int key,
float fontSize)
Gets the font parameter identified by
key . |
protected PdfDictionary |
getFontDescriptor(PdfIndirectReference fontStream,
java.lang.String subsetPrefix,
PdfIndirectReference cidset)
Generates the font descriptor for this font.
|
protected byte[] |
getFullFont() |
java.lang.String[][] |
getFullFontName()
Gets the full name of the font.
|
PdfStream |
getFullFontStream()
Returns a PdfStream object with the full font program.
|
protected int |
getGlyphWidth(int glyph)
Gets a glyph width.
|
int |
getKerning(int char1,
int char2)
Gets the kerning between two Unicode chars.
|
int[] |
getMetricsTT(int c)
Gets the glyph index and metrics for a character.
|
(package private) java.lang.String[][] |
getNames(int id)
Extracts the names of the font in all the languages available.
|
java.lang.String |
getPostscriptFontName()
Gets the postscript font name.
|
protected int[] |
getRawCharBBox(int c,
java.lang.String name) |
(package private) int |
getRawWidth(int c,
java.lang.String name)
Gets the width from the font according to the unicode char
c . |
protected static java.lang.String |
getTTCName(java.lang.String name)
Gets the name from a composed TTC file name.
|
boolean |
hasKernPairs()
Checks if the font has any kerning pairs.
|
(package private) void |
process(byte[] ttfAfm,
boolean preload)
Reads the font data.
|
private void |
readBbox() |
protected byte[] |
readCffFont()
If this font file is using the Compact Font File Format, then this method
will return the raw bytes needed for the font stream.
|
(package private) void |
readCMaps()
Reads the several maps from the table 'cmap'.
|
(package private) java.util.HashMap |
readFormat0()
The information in the maps of the table 'cmap' is coded in several formats.
|
(package private) java.util.HashMap |
readFormat12() |
(package private) java.util.HashMap |
readFormat4()
The information in the maps of the table 'cmap' is coded in several formats.
|
(package private) java.util.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 java.lang.String |
readStandardString(int length)
Reads a
String from the font file as bytes using the Cp1252
encoding. |
protected java.lang.String |
readUnicodeString(int length)
Reads a Unicode
String from the font file. |
boolean |
setKerning(int char1,
int char2,
int kern)
Sets the kerning between two Unicode chars.
|
void |
setPostscriptFontName(java.lang.String name)
Sets the font name that will appear in the pdf font dictionary.
|
(package private) void |
writeFont(PdfWriter writer,
PdfIndirectReference ref,
java.lang.Object[] params)
Outputs to the writer the font dictionaries and streams.
|
addSubsetRange, charExists, convertToBytes, convertToBytes, correctArabicAdvance, createEncoding, createFont, createFont, createFont, createFont, createFont, createFont, createFont, createSubsetPrefix, enumerateTTCNames, enumerateTTCNames, getAllFontNames, getAllNameEntries, getAscent, getAscentPoint, getBaseName, getCharBBox, getCidCode, getCompressionLevel, getDescent, getDescentPoint, getDifferences, getDocumentFonts, getDocumentFonts, getEncoding, getFontType, getFullFontName, getResourceStream, getResourceStream, getUnicodeDifferences, getUnicodeDifferences, getUnicodeEquivalent, getWidth, getWidth, getWidthPoint, getWidthPoint, getWidthPointKerned, getWidths, isDirectTextToByte, isEmbedded, isFontSpecific, isForceWidthsOutput, isSubset, normalizeEncoding, setCharAdvance, setCompressionLevel, setDirectTextToByte, setForceWidthsOutput, setSubset
static final java.lang.String[] codePages
protected boolean justNames
protected java.util.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 java.lang.String fileName
protected boolean cff
protected int cffOffset
protected int cffLength
protected int directoryOffset
protected java.lang.String ttcIndex
String
for a
TTF file.protected java.lang.String style
protected TrueTypeFont.FontHeader head
protected TrueTypeFont.HorizontalHeader hhea
protected TrueTypeFont.WindowsMetrics os_2
protected int[] GlyphWidths
protected int[][] bboxes
protected java.util.HashMap cmap10
int[2]
where position 0
is the glyph number and position 1 is the glyph width normalized to 1000
units.protected java.util.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 java.util.HashMap cmapExt
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 java.lang.String fontName
protected java.lang.String[][] fullName
protected java.lang.String[][] allNameEntries
protected java.lang.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.protected int underlinePosition
protected int underlineThickness
protected TrueTypeFont()
TrueTypeFont(java.lang.String ttFile, java.lang.String enc, boolean emb, byte[] ttfAfm, boolean justNames, boolean forceRead) throws DocumentException, java.io.IOException
ttFile
- the location of the font on file. The file must end in '.ttf' or
'.ttc' but can have modifiers after the nameenc
- the encoding to be applied to this fontemb
- true if the font is to be embedded in the PDFttfAfm
- the font as a byte
arrayDocumentException
- the font is invalidjava.io.IOException
- the font file could not be readprotected static java.lang.String getTTCName(java.lang.String name)
name
- the full namevoid fillTables() throws DocumentException, java.io.IOException
DocumentException
- the font is invalidjava.io.IOException
- the font file could not be readjava.lang.String getBaseFont() throws DocumentException, java.io.IOException
DocumentException
- the font is invalidjava.io.IOException
- the font file could not be readjava.lang.String[][] getNames(int id) throws DocumentException, java.io.IOException
id
- the name id to retrieveDocumentException
- on errorjava.io.IOException
- on errorjava.lang.String[][] getAllNames() throws DocumentException, java.io.IOException
DocumentException
- on errorjava.io.IOException
- on errorvoid checkCff()
void process(byte[] ttfAfm, boolean preload) throws DocumentException, java.io.IOException
ttfAfm
- the font as a byte
array, possibly null
DocumentException
- the font is invalidjava.io.IOException
- the font file could not be readprotected java.lang.String readStandardString(int length) throws java.io.IOException
String
from the font file as bytes using the Cp1252
encoding.length
- the length of bytes to readString
readjava.io.IOException
- the font file could not be readprotected java.lang.String readUnicodeString(int length) throws java.io.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
charactersString
readjava.io.IOException
- the font file could not be readprotected void readGlyphWidths() throws DocumentException, java.io.IOException
DocumentException
- the font is invalidjava.io.IOException
- the font file could not be readprotected int getGlyphWidth(int glyph)
glyph
- the glyph to get the width ofprivate void readBbox() throws DocumentException, java.io.IOException
DocumentException
java.io.IOException
void readCMaps() throws DocumentException, java.io.IOException
DocumentException
- the font is invalidjava.io.IOException
- the font file could not be readjava.util.HashMap readFormat12() throws java.io.IOException
java.io.IOException
java.util.HashMap readFormat0() throws java.io.IOException
HashMap
representing this mapjava.io.IOException
- the font file could not be readjava.util.HashMap readFormat4() throws java.io.IOException
HashMap
representing this mapjava.io.IOException
- the font file could not be readjava.util.HashMap readFormat6() throws java.io.IOException
HashMap
representing this mapjava.io.IOException
- the font file could not be readvoid readKerning() throws java.io.IOException
java.io.IOException
- the font file could not be readpublic int getKerning(int char1, int char2)
getKerning
in class BaseFont
char1
- the first charchar2
- the second charint getRawWidth(int c, java.lang.String name)
c
.
If the name
is null it's a symbolic font.getRawWidth
in class BaseFont
c
- the unicode charname
- the glyph nameprotected PdfDictionary getFontDescriptor(PdfIndirectReference fontStream, java.lang.String subsetPrefix, PdfIndirectReference cidset)
subsetPrefix
- the subset prefixfontStream
- the indirect reference to a PdfStream containing the font or null
null
protected PdfDictionary getFontBaseType(PdfIndirectReference fontDescriptor, java.lang.String subsetPrefix, int firstChar, int lastChar, byte[] shortTag)
subsetPrefix
- the subset prefixfirstChar
- 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
protected byte[] getFullFont() throws java.io.IOException
java.io.IOException
protected static int[] compactRanges(java.util.ArrayList ranges)
protected void addRangeUni(java.util.HashMap longTag, boolean includeMetrics, boolean subsetp)
void writeFont(PdfWriter writer, PdfIndirectReference ref, java.lang.Object[] params) throws DocumentException, java.io.IOException
writeFont
in class BaseFont
writer
- the writer for this documentref
- the font indirect referenceparams
- several parameters that depend on the font typejava.io.IOException
- on errorDocumentException
- error in generating the objectprotected byte[] readCffFont() throws java.io.IOException
java.io.IOException
public PdfStream getFullFontStream() throws java.io.IOException, DocumentException
getFullFontStream
in class BaseFont
java.io.IOException
DocumentException
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 pointspublic int[] getMetricsTT(int c)
c
- the characterint
array with {glyph index, width}public java.lang.String getPostscriptFontName()
getPostscriptFontName
in class BaseFont
public java.lang.String[] getCodePagesSupported()
getCodePagesSupported
in class BaseFont
public java.lang.String[][] getFullFontName()
getFullFontName
in class BaseFont
public java.lang.String[][] getAllNameEntries()
getAllNameEntries
in class BaseFont
public java.lang.String[][] getFamilyFontName()
getFamilyFontName
in class BaseFont
public boolean hasKernPairs()
hasKernPairs
in class BaseFont
true
if the font has any kerning pairspublic void setPostscriptFontName(java.lang.String name)
setPostscriptFontName
in class BaseFont
name
- the new font namepublic boolean setKerning(int char1, int char2, int kern)
setKerning
in class BaseFont
char1
- the first charchar2
- the second charkern
- the kerning to apply in normalized 1000 unitstrue
if the kerning was applied, false
otherwiseprotected int[] getRawCharBBox(int c, java.lang.String name)
getRawCharBBox
in class BaseFont