Class TrueTypeFontSubset

java.lang.Object
com.itextpdf.io.font.TrueTypeFontSubset

class TrueTypeFontSubset extends Object
Subsets a True Type font by removing the unneeded glyphs from the font.
  • Field Details

    • TABLE_NAMES_SUBSET

      private static final String[] TABLE_NAMES_SUBSET
    • TABLE_NAMES

      private static final String[] TABLE_NAMES
    • entrySelectors

      private static final int[] entrySelectors
    • TABLE_CHECKSUM

      private static final int TABLE_CHECKSUM
      See Also:
    • TABLE_OFFSET

      private static final int TABLE_OFFSET
      See Also:
    • TABLE_LENGTH

      private static final int TABLE_LENGTH
      See Also:
    • HEAD_LOCA_FORMAT_OFFSET

      private static final int HEAD_LOCA_FORMAT_OFFSET
      See Also:
    • ARG_1_AND_2_ARE_WORDS

      private static final int ARG_1_AND_2_ARE_WORDS
      See Also:
    • WE_HAVE_A_SCALE

      private static final int WE_HAVE_A_SCALE
      See Also:
    • MORE_COMPONENTS

      private static final int MORE_COMPONENTS
      See Also:
    • WE_HAVE_AN_X_AND_Y_SCALE

      private static final int WE_HAVE_AN_X_AND_Y_SCALE
      See Also:
    • WE_HAVE_A_TWO_BY_TWO

      private static final int WE_HAVE_A_TWO_BY_TWO
      See Also:
    • tableDirectory

      private Map<String,int[]> 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.
    • rf

      The file in use.
    • fileName

      private String fileName
      The file name.
    • locaShortTable

      private boolean locaShortTable
    • locaTable

      private int[] locaTable
    • glyphsUsed

      private Set<Integer> glyphsUsed
    • glyphsInList

      private List<Integer> 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 int directoryOffset
    • tableNames

      private final String[] tableNames
  • Constructor Details

    • TrueTypeFontSubset

      TrueTypeFontSubset(String fileName, RandomAccessFileOrArray rf, Set<Integer> glyphsUsed, int directoryOffset, boolean subset)
      Creates a new TrueTypeFontSubSet
      Parameters:
      fileName - the file name of the font
      glyphsUsed - the glyphs used
      directoryOffset - The offset from the start of the file to the table directory
  • Method Details

    • process

      byte[] process() throws IOException
      Does the actual work of subsetting the font.
      Returns:
      the subset font
      Throws:
      IOException - on error
    • assembleFont

      private void assembleFont() throws IOException
      Throws:
      IOException
    • createTableDirectory

      private void createTableDirectory() throws IOException
      Throws:
      IOException
    • readLoca

      private void readLoca() throws IOException
      Throws:
      IOException
    • createNewGlyphTables

      private void createNewGlyphTables() throws IOException
      Throws:
      IOException
    • locaToBytes

      private void locaToBytes()
    • flatGlyphs

      private void flatGlyphs() throws IOException
      Throws:
      IOException
    • checkGlyphComposite

      private void checkGlyphComposite(int glyph) throws IOException
      Throws:
      IOException
    • readStandardString

      private String readStandardString(int length) throws IOException
      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
    • writeFontShort

      private void writeFontShort(int n)
    • writeFontInt

      private void writeFontInt(int n)
    • writeFontString

      private void writeFontString(String s)
    • calculateChecksum

      private int calculateChecksum(byte[] b)