Package com.itextpdf.text.pdf
Class TrueTypeFontUnicode
- java.lang.Object
-
- com.itextpdf.text.pdf.BaseFont
-
- com.itextpdf.text.pdf.TrueTypeFont
-
- com.itextpdf.text.pdf.TrueTypeFontUnicode
-
- All Implemented Interfaces:
java.util.Comparator<int[]>
class TrueTypeFontUnicode extends TrueTypeFont implements java.util.Comparator<int[]>
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
-
Nested classes/interfaces inherited from class com.itextpdf.text.pdf.TrueTypeFont
TrueTypeFont.FontHeader, TrueTypeFont.HorizontalHeader, TrueTypeFont.WindowsMetrics
-
Nested classes/interfaces inherited from class com.itextpdf.text.pdf.BaseFont
BaseFont.StreamFont
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,Glyph>
glyphSubstitutionMap
private static byte[]
rotbits
private static java.util.List<Language>
SUPPORTED_LANGUAGES_FOR_OTF
private Language
supportedLanguage
-
Fields inherited from class com.itextpdf.text.pdf.TrueTypeFont
allNameEntries, bboxes, cff, cffLength, cffOffset, cmap10, cmap31, cmapExt, codePages, directoryOffset, familyName, fileName, fontName, fullName, glyphIdToChar, glyphWidthsByIndex, head, hhea, isFixedPitch, italicAngle, justNames, kerning, maxGlyphId, os_2, rf, style, subFamily, tables, ttcIndex, underlinePosition, underlineThickness
-
Fields inherited from class com.itextpdf.text.pdf.BaseFont
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, DEFAULT_FONT_MATRIX, 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, FONT_WEIGHT, fontCache, fontSpecific, fontType, forceWidthsOutput, HELVETICA, HELVETICA_BOLD, HELVETICA_BOLDOBLIQUE, HELVETICA_OBLIQUE, IDENTITY_H, IDENTITY_V, ITALICANGLE, MACROMAN, NOT_CACHED, NOT_EMBEDDED, notdef, PARAGRAPH_SEPARATOR, 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, vertical, WEIGHT_CLASS, WIDTH_CLASS, widths, WINANSI, ZAPFDINGBATS
-
-
Constructor Summary
Constructors Constructor Description TrueTypeFontUnicode(java.lang.String ttFile, java.lang.String enc, boolean emb, byte[] ttfAfm, boolean forceRead)
Creates a new TrueType font addressed by Unicode characters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
charExists(int c)
Checks if a character exists in this font.int
compare(int[] o1, int[] o2)
The method used to sort the metrics array.(package private) byte[]
convertToBytes(int char1)
Converts achar
to a byte array according to the font's encoding.byte[]
convertToBytes(java.lang.String text)
A forbidden operation.int[]
getCharBBox(int c)
Gets the smallest box enclosing the character contours.int
GetCharFromGlyphId(int gid)
PdfDictionary
getCIDFontType2(PdfIndirectReference fontDescriptor, java.lang.String subsetPrefix, java.lang.Object[] metrics)
Generates the CIDFontTyte2 dictionary.PdfDictionary
getFontBaseType(PdfIndirectReference descendant, java.lang.String subsetPrefix, PdfIndirectReference toUnicode)
Generates the font dictionary.PdfStream
getFullFontStream()
Returns a PdfStream object with the full font program.protected java.util.Map<java.lang.String,Glyph>
getGlyphSubstitutionMap()
int[]
getMetricsTT(int c)
Gets the glyph index and metrics for a character.(package private) Language
getSupportedLanguage()
PdfStream
getToUnicode(java.lang.Object[] metrics)
Creates a ToUnicode CMap to allow copy and paste from Acrobat.int
getWidth(int char1)
Gets the width of achar
in normalized 1000 units.int
getWidth(java.lang.String text)
Gets the width of aString
in normalized 1000 units.(package private) void
process(byte[] ttfAfm, boolean preload)
Reads the font data.private void
readGsubTable()
boolean
setCharAdvance(int c, int advance)
Sets the character advance.(package private) static java.lang.String
toHex(int n)
Gets an hex string in the format "<HHHH>".private static java.lang.String
toHex4(int n)
(package private) void
writeFont(PdfWriter writer, PdfIndirectReference ref, java.lang.Object[] params)
Outputs to the writer the font dictionaries and streams.-
Methods inherited from class com.itextpdf.text.pdf.TrueTypeFont
addRangeUni, addRangeUni, checkCff, compactRanges, fillTables, getAllNameEntries, getAllNames, getBaseFont, getCodePagesSupported, getFamilyFontName, getFontBaseType, getFontDescriptor, getFontDescriptor, getFullFont, getFullFontName, getGlyphWidth, getKerning, getNames, getPostscriptFontName, getRawCharBBox, getRawWidth, getSubfamily, getSubSet, getTTCName, hasKernPairs, isWinAnsiSupported, readCffFont, readCMaps, readFormat0, readFormat12, readFormat4, readFormat6, readGlyphWidths, readKerning, readStandardString, readUnicodeString, setKerning, setPostscriptFontName
-
Methods inherited from class com.itextpdf.text.pdf.BaseFont
addSubsetRange, correctArabicAdvance, createBuiltInFontDictionary, createEncoding, createFont, createFont, createFont, createFont, createFont, createFont, createFont, createSubsetPrefix, enumerateTTCNames, enumerateTTCNames, getAllFontNames, getAllNameEntries, getAscent, getAscentPoint, getBaseName, getCidCode, getCompressionLevel, getDescent, getDescentPoint, getDifferences, getDocumentFonts, getDocumentFonts, getEncoding, getFontMatrix, getFontType, getFullFontName, getUnicodeDifferences, getUnicodeDifferences, getUnicodeEquivalent, getWidthPoint, getWidthPoint, getWidthPointKerned, getWidths, isDirectTextToByte, isEmbedded, isFontSpecific, isForceWidthsOutput, isSubset, isVertical, normalizeEncoding, setCompressionLevel, setDirectTextToByte, setFontDescriptor, setForceWidthsOutput, setSubset
-
-
-
-
Field Detail
-
SUPPORTED_LANGUAGES_FOR_OTF
private static final java.util.List<Language> SUPPORTED_LANGUAGES_FOR_OTF
-
glyphSubstitutionMap
private java.util.Map<java.lang.String,Glyph> glyphSubstitutionMap
-
supportedLanguage
private Language supportedLanguage
-
rotbits
private static final byte[] rotbits
-
-
Constructor Detail
-
TrueTypeFontUnicode
TrueTypeFontUnicode(java.lang.String ttFile, java.lang.String enc, boolean emb, byte[] ttfAfm, boolean forceRead) throws DocumentException, java.io.IOException
Creates a new TrueType font addressed by Unicode characters. The font will always be embedded.- Parameters:
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 abyte
array- Throws:
DocumentException
- the font is invalidjava.io.IOException
- the font file could not be read
-
-
Method Detail
-
process
void process(byte[] ttfAfm, boolean preload) throws DocumentException, java.io.IOException
Description copied from class:TrueTypeFont
Reads the font data.- Overrides:
process
in classTrueTypeFont
- Parameters:
ttfAfm
- the font as abyte
array, possiblynull
- Throws:
DocumentException
- the font is invalidjava.io.IOException
- the font file could not be read
-
getWidth
public int getWidth(int char1)
Gets the width of achar
in normalized 1000 units.
-
getWidth
public int getWidth(java.lang.String text)
Gets the width of aString
in normalized 1000 units.
-
getToUnicode
public PdfStream getToUnicode(java.lang.Object[] metrics)
Creates a ToUnicode CMap to allow copy and paste from Acrobat.- Parameters:
metrics
- metrics[0] contains the glyph index and metrics[2] contains the Unicode code- Returns:
- the stream representing this CMap or
null
-
toHex4
private static java.lang.String toHex4(int n)
-
toHex
static java.lang.String toHex(int n)
Gets an hex string in the format "<HHHH>".- Parameters:
n
- the number- Returns:
- the hex string
-
getCIDFontType2
public PdfDictionary getCIDFontType2(PdfIndirectReference fontDescriptor, java.lang.String subsetPrefix, java.lang.Object[] metrics)
Generates the CIDFontTyte2 dictionary.- Parameters:
fontDescriptor
- the indirect reference to the font descriptorsubsetPrefix
- the subset prefixmetrics
- the horizontal width metrics- Returns:
- a stream
-
getFontBaseType
public PdfDictionary getFontBaseType(PdfIndirectReference descendant, java.lang.String subsetPrefix, PdfIndirectReference toUnicode)
Generates the font dictionary.- Parameters:
descendant
- the descendant dictionarysubsetPrefix
- the subset prefixtoUnicode
- the ToUnicode stream- Returns:
- the stream
-
GetCharFromGlyphId
public int GetCharFromGlyphId(int gid)
-
compare
public int compare(int[] o1, int[] o2)
The method used to sort the metrics array.- Specified by:
compare
in interfacejava.util.Comparator<int[]>
- Parameters:
o1
- the first elemento2
- the second element- Returns:
- the comparison
-
writeFont
void writeFont(PdfWriter writer, PdfIndirectReference ref, java.lang.Object[] params) throws DocumentException, java.io.IOException
Outputs to the writer the font dictionaries and streams.- Overrides:
writeFont
in classTrueTypeFont
- Parameters:
writer
- the writer for this documentref
- the font indirect referenceparams
- several parameters that depend on the font type- Throws:
java.io.IOException
- on errorDocumentException
- error in generating the object
-
getFullFontStream
public PdfStream getFullFontStream() throws java.io.IOException, DocumentException
Returns a PdfStream object with the full font program.- Overrides:
getFullFontStream
in classTrueTypeFont
- Returns:
- a PdfStream with the font program
- Throws:
java.io.IOException
DocumentException
- Since:
- 2.1.3
-
convertToBytes
public byte[] convertToBytes(java.lang.String text)
A forbidden operation. Will throw a null pointer exception.- Overrides:
convertToBytes
in classBaseFont
- Parameters:
text
- the text- Returns:
- always
null
-
convertToBytes
byte[] convertToBytes(int char1)
Description copied from class:BaseFont
Converts achar
to a byte array according to the font's encoding.- Overrides:
convertToBytes
in classBaseFont
- Parameters:
char1
- thechar
to be converted- Returns:
- an array of
byte
representing the conversion according to the font's encoding
-
getMetricsTT
public int[] getMetricsTT(int c)
Gets the glyph index and metrics for a character.- Overrides:
getMetricsTT
in classTrueTypeFont
- Parameters:
c
- the character- Returns:
- an
int
array with {glyph index, width}
-
charExists
public boolean charExists(int c)
Checks if a character exists in this font.- Overrides:
charExists
in classBaseFont
- Parameters:
c
- the character to check- Returns:
true
if the character has a glyph,false
otherwise
-
setCharAdvance
public boolean setCharAdvance(int c, int advance)
Sets the character advance.- Overrides:
setCharAdvance
in classBaseFont
- Parameters:
c
- the characteradvance
- the character advance normalized to 1000 units- Returns:
true
if the advance was set,false
otherwise
-
getCharBBox
public int[] getCharBBox(int c)
Description copied from class:BaseFont
Gets the smallest box enclosing the character contours. It will returnnull
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].- Overrides:
getCharBBox
in classBaseFont
- Parameters:
c
- the character to get the contour bounding box from- Returns:
- an array of four floats with the bounding box in the format [llx,lly,urx,ury] or
null
-
getGlyphSubstitutionMap
protected java.util.Map<java.lang.String,Glyph> getGlyphSubstitutionMap()
-
getSupportedLanguage
Language getSupportedLanguage()
-
readGsubTable
private void readGsubTable() throws java.io.IOException
- Throws:
java.io.IOException
-
-