Package com.aowagie.text.pdf
Class TrueTypeFontSubSet
- java.lang.Object
-
- com.aowagie.text.pdf.TrueTypeFontSubSet
-
class TrueTypeFontSubSet extends java.lang.ObjectSubsets a True Type font by removing the unneeded glyphs from the font.
-
-
Field Summary
Fields Modifier and Type Field Description private static intARG_1_AND_2_ARE_WORDSprivate intdirectoryOffsetprivate static int[]entrySelectorsprivate java.lang.StringfileNameThe file name.private intfontPtrprivate intglyfTableRealSizeprivate java.util.ArrayListglyphsInListprivate java.util.HashMapglyphsUsed(package private) static intHEAD_LOCA_FORMAT_OFFSETprivate booleanincludeCmapprivate booleanincludeExtrasprivate booleanlocaShortTableprivate int[]locaTableprivate intlocaTableRealSizeprivate static intMORE_COMPONENTSprivate byte[]newGlyfTableprivate int[]newLocaTableprivate byte[]newLocaTableOutprivate byte[]outFontprivate RandomAccessFileOrArrayrfThe file in use.private static intTABLE_CHECKSUMprivate static intTABLE_LENGTHprivate static intTABLE_OFFSETprivate java.util.HashMaptableDirectoryContains the location of the several tables.private inttableGlyphOffsetprivate static java.lang.String[]tableNamesCmapprivate static java.lang.String[]tableNamesExtraprivate static java.lang.String[]tableNamesSimpleprivate static intWE_HAVE_A_SCALEprivate static intWE_HAVE_A_TWO_BY_TWOprivate static intWE_HAVE_AN_X_AND_Y_SCALE
-
Constructor Summary
Constructors Constructor Description TrueTypeFontSubSet(java.lang.String fileName, RandomAccessFileOrArray rf, java.util.HashMap glyphsUsed, int directoryOffset, boolean includeCmap, boolean includeExtras)Creates a new TrueTypeFontSubSet
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidassembleFont()private intcalculateChecksum(byte[] b)private voidcheckGlyphComposite(int glyph)private voidcreateNewGlyphTables()private voidcreateTableDirectory()private voidflatGlyphs()private voidlocaTobytes()(package private) byte[]process()Does the actual work of subsetting the font.private voidreadLoca()private java.lang.StringreadStandardString(int length)Reads aStringfrom the font file as bytes using the Cp1252 encoding.private voidwriteFontInt(int n)private voidwriteFontShort(int n)private voidwriteFontString(java.lang.String s)
-
-
-
Field Detail
-
tableNamesSimple
private static final java.lang.String[] tableNamesSimple
-
tableNamesCmap
private static final java.lang.String[] tableNamesCmap
-
tableNamesExtra
private static final java.lang.String[] tableNamesExtra
-
entrySelectors
private static final int[] entrySelectors
-
TABLE_CHECKSUM
private static final int TABLE_CHECKSUM
- See Also:
- Constant Field Values
-
TABLE_OFFSET
private static final int TABLE_OFFSET
- See Also:
- Constant Field Values
-
TABLE_LENGTH
private static final int TABLE_LENGTH
- See Also:
- Constant Field Values
-
HEAD_LOCA_FORMAT_OFFSET
static final int HEAD_LOCA_FORMAT_OFFSET
- See Also:
- Constant Field Values
-
ARG_1_AND_2_ARE_WORDS
private static final int ARG_1_AND_2_ARE_WORDS
- See Also:
- Constant Field Values
-
WE_HAVE_A_SCALE
private static final int WE_HAVE_A_SCALE
- See Also:
- Constant Field Values
-
MORE_COMPONENTS
private static final int MORE_COMPONENTS
- See Also:
- Constant Field Values
-
WE_HAVE_AN_X_AND_Y_SCALE
private static final int WE_HAVE_AN_X_AND_Y_SCALE
- See Also:
- Constant Field Values
-
WE_HAVE_A_TWO_BY_TWO
private static final int WE_HAVE_A_TWO_BY_TWO
- See Also:
- Constant Field Values
-
tableDirectory
private java.util.HashMap tableDirectory
Contains the location of the several tables. The key is the name of the table and the value is anint[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.
-
rf
private final RandomAccessFileOrArray rf
The file in use.
-
fileName
private final java.lang.String fileName
The file name.
-
includeCmap
private final boolean includeCmap
-
includeExtras
private final boolean includeExtras
-
locaShortTable
private boolean locaShortTable
-
locaTable
private int[] locaTable
-
glyphsUsed
private final java.util.HashMap glyphsUsed
-
glyphsInList
private final java.util.ArrayList glyphsInList
-
tableGlyphOffset
private int tableGlyphOffset
-
newLocaTable
private int[] newLocaTable
-
newLocaTableOut
private byte[] newLocaTableOut
-
newGlyfTable
private byte[] newGlyfTable
-
glyfTableRealSize
private int glyfTableRealSize
-
locaTableRealSize
private int locaTableRealSize
-
outFont
private byte[] outFont
-
fontPtr
private int fontPtr
-
directoryOffset
private final int directoryOffset
-
-
Constructor Detail
-
TrueTypeFontSubSet
TrueTypeFontSubSet(java.lang.String fileName, RandomAccessFileOrArray rf, java.util.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 directoryfileName- the file name of the fontglyphsUsed- the glyphs usedincludeCmap-trueif the table cmap is to be included in the generated font
-
-
Method Detail
-
process
byte[] process() throws java.io.IOException, DocumentExceptionDoes the actual work of subsetting the font.- Returns:
- the subset font
- Throws:
java.io.IOException- on errorDocumentException- on error
-
assembleFont
private void assembleFont() throws java.io.IOException- Throws:
java.io.IOException
-
createTableDirectory
private void createTableDirectory() throws java.io.IOException, DocumentException- Throws:
java.io.IOExceptionDocumentException
-
readLoca
private void readLoca() throws java.io.IOException, DocumentException- Throws:
java.io.IOExceptionDocumentException
-
createNewGlyphTables
private void createNewGlyphTables() throws java.io.IOException- Throws:
java.io.IOException
-
locaTobytes
private void locaTobytes()
-
flatGlyphs
private void flatGlyphs() throws java.io.IOException, DocumentException- Throws:
java.io.IOExceptionDocumentException
-
checkGlyphComposite
private void checkGlyphComposite(int glyph) throws java.io.IOException- Throws:
java.io.IOException
-
readStandardString
private java.lang.String readStandardString(int length) throws java.io.IOExceptionReads aStringfrom the font file as bytes using the Cp1252 encoding.- Parameters:
length- the length of bytes to read- Returns:
- the
Stringread - Throws:
java.io.IOException- the font file could not be read
-
writeFontShort
private void writeFontShort(int n)
-
writeFontInt
private void writeFontInt(int n)
-
writeFontString
private void writeFontString(java.lang.String s)
-
calculateChecksum
private int calculateChecksum(byte[] b)
-
-