com.lowagie.text.pdf

Class TrueTypeFontSubSet

class TrueTypeFontSubSet extends Object

Subsets a True Type font by removing the unneeded glyphs from the font.

Author: Paulo Soares (psoares@consiste.pt)

Field Summary
static intARG_1_AND_2_ARE_WORDS
protected intdirectoryOffset
static int[]entrySelectors
protected StringfileName
The file name.
protected intfontPtr
protected intglyfTableRealSize
protected ArrayListglyphsInList
protected HashMapglyphsUsed
static intHEAD_LOCA_FORMAT_OFFSET
protected booleanincludeCmap
protected booleanincludeExtras
protected booleanlocaShortTable
protected int[]locaTable
protected intlocaTableRealSize
static intMORE_COMPONENTS
protected byte[]newGlyfTable
protected int[]newLocaTable
protected byte[]newLocaTableOut
protected byte[]outFont
protected RandomAccessFileOrArrayrf
The file in use.
protected HashMaptableDirectory
Contains the location of the several tables.
protected inttableGlyphOffset
static String[]tableNamesCmap
static String[]tableNamesExtra
static String[]tableNamesSimple
static intTABLE_CHECKSUM
static intTABLE_LENGTH
static intTABLE_OFFSET
static intWE_HAVE_AN_X_AND_Y_SCALE
static intWE_HAVE_A_SCALE
static intWE_HAVE_A_TWO_BY_TWO
Constructor Summary
TrueTypeFontSubSet(String fileName, RandomAccessFileOrArray rf, HashMap glyphsUsed, int directoryOffset, boolean includeCmap, boolean includeExtras)
Creates a new TrueTypeFontSubSet
Method Summary
protected voidassembleFont()
protected intcalculateChecksum(byte[] b)
protected voidcheckGlyphComposite(int glyph)
protected voidcreateNewGlyphTables()
protected voidcreateTableDirectory()
protected voidflatGlyphs()
protected voidlocaTobytes()
byte[]process()
Does the actual work of subsetting the font.
protected voidreadLoca()
protected StringreadStandardString(int length)
Reads a String from the font file as bytes using the Cp1252 encoding.
protected voidwriteFontInt(int n)
protected voidwriteFontShort(int n)
protected voidwriteFontString(String s)

Field Detail

ARG_1_AND_2_ARE_WORDS

static final int ARG_1_AND_2_ARE_WORDS

directoryOffset

protected int directoryOffset

entrySelectors

static final int[] entrySelectors

fileName

protected String fileName
The file name.

fontPtr

protected int fontPtr

glyfTableRealSize

protected int glyfTableRealSize

glyphsInList

protected ArrayList glyphsInList

glyphsUsed

protected HashMap glyphsUsed

HEAD_LOCA_FORMAT_OFFSET

static final int HEAD_LOCA_FORMAT_OFFSET

includeCmap

protected boolean includeCmap

includeExtras

protected boolean includeExtras

locaShortTable

protected boolean locaShortTable

locaTable

protected int[] locaTable

locaTableRealSize

protected int locaTableRealSize

MORE_COMPONENTS

static final int MORE_COMPONENTS

newGlyfTable

protected byte[] newGlyfTable

newLocaTable

protected int[] newLocaTable

newLocaTableOut

protected byte[] newLocaTableOut

outFont

protected byte[] outFont

rf

protected RandomAccessFileOrArray rf
The file in use.

tableDirectory

protected HashMap tableDirectory
Contains the location of the several tables. The key is the name of the table and the value is an int[3] where position 0 is the checksum, position 1 is the offset from the start of the file and position 2 is the length of the table.

tableGlyphOffset

protected int tableGlyphOffset

tableNamesCmap

static final String[] tableNamesCmap

tableNamesExtra

static final String[] tableNamesExtra

tableNamesSimple

static final String[] tableNamesSimple

TABLE_CHECKSUM

static final int TABLE_CHECKSUM

TABLE_LENGTH

static final int TABLE_LENGTH

TABLE_OFFSET

static final int TABLE_OFFSET

WE_HAVE_AN_X_AND_Y_SCALE

static final int WE_HAVE_AN_X_AND_Y_SCALE

WE_HAVE_A_SCALE

static final int WE_HAVE_A_SCALE

WE_HAVE_A_TWO_BY_TWO

static final int WE_HAVE_A_TWO_BY_TWO

Constructor Detail

TrueTypeFontSubSet

TrueTypeFontSubSet(String fileName, RandomAccessFileOrArray rf, HashMap glyphsUsed, int directoryOffset, boolean includeCmap, boolean includeExtras)
Creates a new TrueTypeFontSubSet

Parameters: directoryOffset The offset from the start of the file to the table directory fileName the file name of the font glyphsUsed the glyphs used includeCmap true if the table cmap is to be included in the generated font

Method Detail

assembleFont

protected void assembleFont()

calculateChecksum

protected int calculateChecksum(byte[] b)

checkGlyphComposite

protected void checkGlyphComposite(int glyph)

createNewGlyphTables

protected void createNewGlyphTables()

createTableDirectory

protected void createTableDirectory()

flatGlyphs

protected void flatGlyphs()

locaTobytes

protected void locaTobytes()

process

byte[] process()
Does the actual work of subsetting the font.

Returns: the subset font

Throws: IOException on error DocumentException on error

readLoca

protected void readLoca()

readStandardString

protected String readStandardString(int length)
Reads a String from the font file as bytes using the Cp1252 encoding.

Parameters: length the length of bytes to read

Returns: the String read

Throws: IOException the font file could not be read

writeFontInt

protected void writeFontInt(int n)

writeFontShort

protected void writeFontShort(int n)

writeFontString

protected void writeFontString(String s)