Class TrueTypeFont


  • public class TrueTypeFont
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.SortedMap<java.lang.String,​java.lang.Object> tables  
      private int type  
    • Constructor Summary

      Constructors 
      Constructor Description
      TrueTypeFont​(int type)
      Creates a new instance of TrueTypeParser
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addTable​(java.lang.String tagString, TrueTypeTable table)
      Add a table to the font
      void addTable​(java.lang.String tagString, java.nio.ByteBuffer data)
      Add a table to the font
      private static int calculateChecksum​(java.lang.String tagString, java.nio.ByteBuffer data)
      Calculate the checksum for a given table
      short getEntrySelector()
      Get the entry selector
      private int getLength()
      Get the length of the font
      short getNumTables()
      Get the number of tables
      short getRangeShift()
      Get the range shift
      short getSearchRange()
      Get the search range
      TrueTypeTable getTable​(java.lang.String tagString)
      Get a table by name.
      int getType()
      Get the type of this font
      static void main​(java.lang.String[] args)  
      private static void parseDirectories​(java.nio.ByteBuffer data, int numTables, TrueTypeFont ttf)
      Get directory entries from a font
      static TrueTypeFont parseFont​(byte[] orig)
      Parses a TrueType font from a byte array
      static TrueTypeFont parseFont​(java.nio.ByteBuffer inBuf)
      Parses a TrueType font from a byte buffer
      void removeTable​(java.lang.String tagString)
      Remove a table by name
      java.lang.String toString()
      Write the font to a pretty string
      private void updateChecksumAdj​(java.nio.ByteBuffer fontData)
      Update the checksumAdj field in the head table
      byte[] writeFont()
      Write a font given the type and an array of Table Directory Entries
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • type

        private int type
      • tables

        private java.util.SortedMap<java.lang.String,​java.lang.Object> tables
    • Constructor Detail

      • TrueTypeFont

        public TrueTypeFont​(int type)
        Creates a new instance of TrueTypeParser
    • Method Detail

      • parseFont

        public static TrueTypeFont parseFont​(byte[] orig)
        Parses a TrueType font from a byte array
      • parseFont

        public static TrueTypeFont parseFont​(java.nio.ByteBuffer inBuf)
        Parses a TrueType font from a byte buffer
      • getType

        public int getType()
        Get the type of this font
      • addTable

        public void addTable​(java.lang.String tagString,
                             java.nio.ByteBuffer data)
        Add a table to the font
        Parameters:
        tagString - the name of this table, as a 4 character string (i.e. cmap or head)
        data - the data for this table, as a byte buffer
      • addTable

        public void addTable​(java.lang.String tagString,
                             TrueTypeTable table)
        Add a table to the font
        Parameters:
        tagString - the name of this table, as a 4 character string (i.e. cmap or head)
        table - the table
      • getTable

        public TrueTypeTable getTable​(java.lang.String tagString)
        Get a table by name. This command causes the table in question to be parsed, if it has not already been parsed.
        Parameters:
        tagString - the name of this table, as a 4 character string (i.e. cmap or head)
      • removeTable

        public void removeTable​(java.lang.String tagString)
        Remove a table by name
        Parameters:
        tagString - the name of this table, as a 4 character string (i.e. cmap or head)
      • getNumTables

        public short getNumTables()
        Get the number of tables
      • getSearchRange

        public short getSearchRange()
        Get the search range
      • getEntrySelector

        public short getEntrySelector()
        Get the entry selector
      • getRangeShift

        public short getRangeShift()
        Get the range shift
      • writeFont

        public byte[] writeFont()
        Write a font given the type and an array of Table Directory Entries
      • calculateChecksum

        private static int calculateChecksum​(java.lang.String tagString,
                                             java.nio.ByteBuffer data)
        Calculate the checksum for a given table
        Parameters:
        tagString - the name of the data
        data - the data in the table
      • parseDirectories

        private static void parseDirectories​(java.nio.ByteBuffer data,
                                             int numTables,
                                             TrueTypeFont ttf)
        Get directory entries from a font
      • getLength

        private int getLength()
        Get the length of the font
        Returns:
        the length of the entire font, in bytes
      • updateChecksumAdj

        private void updateChecksumAdj​(java.nio.ByteBuffer fontData)
        Update the checksumAdj field in the head table
      • toString

        public java.lang.String toString()
        Write the font to a pretty string
        Overrides:
        toString in class java.lang.Object
      • main

        public static void main​(java.lang.String[] args)
        Parameters:
        args - the command line arguments