com.lowagie.text.pdf

Class TrueTypeFontUnicode

class TrueTypeFontUnicode extends TrueTypeFont implements Comparator

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.

Author: Paulo Soares (psoares@consiste.pt)

Field Summary
static byte[]rotbits
booleanvertical
true if the encoding is vertical.
Constructor Summary
TrueTypeFontUnicode(String ttFile, String enc, boolean emb, byte[] ttfAfm)
Creates a new TrueType font addressed by Unicode characters.
Method Summary
booleancharExists(int c)
Checks if a character exists in this font.
intcompare(Object o1, Object o2)
The method used to sort the metrics array.
byte[]convertToBytes(String text)
A forbidden operation.
byte[]convertToBytes(int char1)
int[]getCharBBox(int c)
PdfDictionarygetCIDFontType2(PdfIndirectReference fontDescriptor, String subsetPrefix, Object[] metrics)
Generates the CIDFontTyte2 dictionary.
PdfDictionarygetFontBaseType(PdfIndirectReference descendant, String subsetPrefix, PdfIndirectReference toUnicode)
Generates the font dictionary.
PdfStreamgetFullFontStream()
Returns a PdfStream object with the full font program.
int[]getMetricsTT(int c)
Gets the glyph index and metrics for a character.
PdfStreamgetToUnicode(Object[] metrics)
Creates a ToUnicode CMap to allow copy and paste from Acrobat.
intgetWidth(int char1)
Gets the width of a char in normalized 1000 units.
intgetWidth(String text)
Gets the width of a String in normalized 1000 units.
booleansetCharAdvance(int c, int advance)
Sets the character advance.
static StringtoHex(int n)
Gets an hex string in the format "<HHHH>".
static StringtoHex4(int n)
voidwriteFont(PdfWriter writer, PdfIndirectReference ref, Object[] params)
Outputs to the writer the font dictionaries and streams.

Field Detail

rotbits

private static final byte[] rotbits

vertical

boolean vertical
true if the encoding is vertical.

Constructor Detail

TrueTypeFontUnicode

TrueTypeFontUnicode(String ttFile, String enc, boolean emb, byte[] ttfAfm)
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 font emb true if the font is to be embedded in the PDF ttfAfm the font as a byte array

Throws: DocumentException the font is invalid IOException the font file could not be read

Method Detail

charExists

public boolean charExists(int c)
Checks if a character exists in this font.

Parameters: c the character to check

Returns: true if the character has a glyph, false otherwise

compare

public int compare(Object o1, Object o2)
The method used to sort the metrics array.

Parameters: o1 the first element o2 the second element

Returns: the comparison

convertToBytes

byte[] convertToBytes(String text)
A forbidden operation. Will throw a null pointer exception.

Parameters: text the text

Returns: always null

convertToBytes

byte[] convertToBytes(int char1)

getCharBBox

public int[] getCharBBox(int c)

getCIDFontType2

private PdfDictionary getCIDFontType2(PdfIndirectReference fontDescriptor, String subsetPrefix, Object[] metrics)
Generates the CIDFontTyte2 dictionary.

Parameters: fontDescriptor the indirect reference to the font descriptor subsetPrefix the subset prefix metrics the horizontal width metrics

Returns: a stream

getFontBaseType

private PdfDictionary getFontBaseType(PdfIndirectReference descendant, String subsetPrefix, PdfIndirectReference toUnicode)
Generates the font dictionary.

Parameters: descendant the descendant dictionary subsetPrefix the subset prefix toUnicode the ToUnicode stream

Returns: the stream

getFullFontStream

public PdfStream getFullFontStream()
Returns a PdfStream object with the full font program.

Returns: a PdfStream with the font program

Since: 2.1.3

getMetricsTT

public int[] getMetricsTT(int c)
Gets the glyph index and metrics for a character.

Parameters: c the character

Returns: an int array with {glyph index, width}

getToUnicode

private PdfStream getToUnicode(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

Throws: DocumentException on error

getWidth

public int getWidth(int char1)
Gets the width of a char in normalized 1000 units.

Parameters: char1 the unicode char to get the width of

Returns: the width in normalized 1000 units

getWidth

public int getWidth(String text)
Gets the width of a String in normalized 1000 units.

Parameters: text the String to get the width of

Returns: the width in normalized 1000 units

setCharAdvance

public boolean setCharAdvance(int c, int advance)
Sets the character advance.

Parameters: c the character advance the character advance normalized to 1000 units

Returns: true if the advance was set, false otherwise

toHex

static String toHex(int n)
Gets an hex string in the format "<HHHH>".

Parameters: n the number

Returns: the hex string

toHex4

private static String toHex4(int n)

writeFont

void writeFont(PdfWriter writer, PdfIndirectReference ref, Object[] params)
Outputs to the writer the font dictionaries and streams.

Parameters: writer the writer for this document ref the font indirect reference params several parameters that depend on the font type

Throws: IOException on error DocumentException error in generating the object