Class TrueTypeFontSubset


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

      • TABLE_NAMES_SUBSET

        private static final java.lang.String[] TABLE_NAMES_SUBSET
      • TABLE_NAMES

        private static final java.lang.String[] TABLE_NAMES
      • entrySelectors

        private static final int[] entrySelectors
      • HEAD_LOCA_FORMAT_OFFSET

        private static final int HEAD_LOCA_FORMAT_OFFSET
        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
      • tableDirectory

        private java.util.Map<java.lang.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.
      • fileName

        private java.lang.String fileName
        The file name.
      • locaShortTable

        private boolean locaShortTable
      • locaTable

        private int[] locaTable
      • glyphsUsed

        private java.util.Set<java.lang.Integer> glyphsUsed
      • glyphsInList

        private java.util.List<java.lang.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 java.lang.String[] tableNames
    • Constructor Detail

      • TrueTypeFontSubset

        TrueTypeFontSubset​(java.lang.String fileName,
                           RandomAccessFileOrArray rf,
                           java.util.Set<java.lang.Integer> glyphsUsed,
                           int directoryOffset,
                           boolean subset)
        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
    • Method Detail

      • process

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

        private void assembleFont()
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • createTableDirectory

        private void createTableDirectory()
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readLoca

        private void readLoca()
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • createNewGlyphTables

        private void createNewGlyphTables()
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • locaToBytes

        private void locaToBytes()
      • flatGlyphs

        private void flatGlyphs()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • 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.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:
        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)