Class TTFontParser


  • public class TTFontParser
    extends java.lang.Object
    Apple TT specification
    http://developer.apple.com/fonts/TTRefMan/RM06/Chap6.html
    Microsoft OpenType spec
    http://www.microsoft.com/typography/otspec/otff.htm
    • Constructor Summary

      Constructors 
      Constructor Description
      TTFontParser()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Map parseTable_cmap​(TTTable data)  
      java.util.Map parseTable_cmap_subtable​(TTTable data)  
      TTFontHeader parseTable_head​(TTTable data)
      This table gives global information about the font.
      TTHorizontalHeader parseTable_hhea​(TTTable data)
      FIXED Table version number 0x00010000 for version 1.0.
      int[] parseTable_hmtx​(TTTable data, int count)
      The type longHorMetric is defined as an array where each element has two parts: the advance width, which is of type USHORT, and the left side bearing, which is of type SHORT.
      int[] parseTable_loca​(TTTable data, boolean shortLocationFormat)  
      TTNaming parseTable_name​(TTTable data)  
      TTMetrics parseTable_os2​(TTTable data)
      USHORT version 0x0001 SHORT xAvgCharWidth; USHORT usWeightClass; USHORT usWidthClass; SHORT fsType; SHORT ySubscriptXSize; SHORT ySubscriptYSize; SHORT ySubscriptXOffset; SHORT ySubscriptYOffset; SHORT ySuperscriptXSize; SHORT ySuperscriptYSize; SHORT ySuperscriptXOffset; SHORT ySuperscriptYOffset; SHORT yStrikeoutSize; SHORT yStrikeoutPosition; SHORT sFamilyClass; PANOSE panose; ULONG ulUnicodeRange1 Bits 0–31 ULONG ulUnicodeRange2 Bits 32–63 ULONG ulUnicodeRange3 Bits 64–95 ULONG ulUnicodeRange4 Bits 96–127 CHAR achVendID[4]; USHORT fsSelection; USHORT usFirstCharIndex USHORT usLastCharIndex USHORT sTypoAscender USHORT sTypoDescender USHORT sTypoLineGap USHORT usWinAscent USHORT usWinDescent ULONG ulCodePageRange1 Bits 0-31 ULONG ulCodePageRange2 Bits 32-63 SHORT sxHeight SHORT sCapHeight USHORT usDefaultChar USHORT usBreakChar USHORT usMaxContext
      TTPostScriptInformation parseTable_post​(TTTable data)
      Type Name Description Fixed Version 0x00010000 for version 1.0 0x00020000 for version 2.0 0x00025000 for version 2.5 (deprecated) 0x00030000 for version 3.0 Fixed italicAngle Italic angle in counter-clockwise degrees from the vertical.
      TTTable[] parseTables​(TTFont font)  
      byte[] readBytes​(de.intarsys.tools.randomaccess.IRandomAccess random, int count)  
      protected java.util.Map readCMapFormat0​(de.intarsys.tools.randomaccess.IRandomAccess random)  
      protected java.util.Map readCMapFormat4​(de.intarsys.tools.randomaccess.IRandomAccess random)  
      protected java.util.Map readCMapFormat6​(de.intarsys.tools.randomaccess.IRandomAccess random)  
      float readFixed​(de.intarsys.tools.randomaccess.IRandomAccess random)  
      int readInt​(de.intarsys.tools.randomaccess.IRandomAccess random)  
      protected TTNameRecord readNameRecord​(de.intarsys.tools.randomaccess.IRandomAccess random, int stringTableOffset)  
      short readShort​(de.intarsys.tools.randomaccess.IRandomAccess random)  
      TTTable readTable​(TTFont font, de.intarsys.tools.randomaccess.IRandomAccess random)  
      void readTables​(TTFont font, de.intarsys.tools.randomaccess.IRandomAccess random)  
      long readUInt​(de.intarsys.tools.randomaccess.IRandomAccess random)  
      int readUShort​(de.intarsys.tools.randomaccess.IRandomAccess random)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TTFontParser

        public TTFontParser()
    • Method Detail

      • parseTable_cmap

        public java.util.Map parseTable_cmap​(TTTable data)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • parseTable_cmap_subtable

        public java.util.Map parseTable_cmap_subtable​(TTTable data)
                                               throws java.io.IOException
        Throws:
        java.io.IOException
      • parseTable_head

        public TTFontHeader parseTable_head​(TTTable data)
                                     throws java.io.IOException
        This table gives global information about the font.
          Type        Name        Description
          FIXED        Table version number        0x00010000 for version 1.0.
          FIXED        fontRevision        Set by font manufacturer.
          ULONG        checkSumAdjustment        To compute:  set it to 0, sum the entire font as ULONG, then store 0xB1B0AFBA - sum.
          ULONG        magicNumber        Set to 0x5F0F3CF5.
          USHORT        flags        Bit 0 - baseline for font at y=0;
                                                 Bit 1 - left sidebearing at x=0;
                                                 Bit 2 - instructions may depend on point size;
                                                 Bit 3 - force ppem to integer values for all internal scaler math; may use fractional ppem sizes if this bit is clear;
                                                 Bit 4 - instructions may alter advance width (the advance widths might not scale linearly);
                                                 Note: All other bits must be zero.
          USHORT        unitsPerEm        Valid range is from 16 to 16384
          longDateTime        created        International date (8-byte field).
          longDateTime        modified        International date (8-byte field).
          FWORD        xMin        For all glyph bounding boxes.
          FWORD        yMin        For all glyph bounding boxes.
          FWORD        xMax        For all glyph bounding boxes.
          FWORD        yMax        For all glyph bounding boxes.
          USHORT        macStyle        Bit 0 bold (if set to 1); Bit 1 italic (if set to 1)Bits 2-15 reserved (set to 0).
          USHORT        lowestRecPPEM        Smallest readable size in pixels.
          SHORT        fontDirectionHint         0   Fully mixed directional glyphs; 1   Only strongly left to right; 2   Like 1 but also contains neutrals ;-1   Only strongly right to left;-2   Like -1 but also contains neutrals.
          SHORT        indexToLocFormat        0 for short offsets, 1 for long.
          SHORT        glyphDataFormat        0 for current format.
         
        Parameters:
        data - docme
        Returns:
        docme
        Throws:
        java.io.IOException - docme
      • parseTable_hhea

        public TTHorizontalHeader parseTable_hhea​(TTTable data)
                                           throws java.io.IOException
          FIXED        Table version number        0x00010000 for version 1.0.
          FWORD        Ascender        Typographic ascent.
          FWORD        Descender        Typographic descent.
          FWORD        LineGap        Typographic line gap. Negative LineGap values are treated as zero in Windows 3.1, System 6, and System 7.
          UFWORD        advanceWidthMax        Maximum advance width value in ‘hmtx’ table.
          FWORD        minLeftSideBearing        Minimum left sidebearing value in ‘hmtx’ table.
          FWORD        minRightSideBearing        Minimum right sidebearing value; calculated as Min(aw - lsb - (xMax - xMin)).
          FWORD        xMaxExtent        Max(lsb + (xMax - xMin)).
          SHORT        caretSlopeRise        Used to calculate the slope of the cursor (rise/run); 1 for vertical.
          SHORT        caretSlopeRun        0 for vertical.
          SHORT        (reserved)        set to 0
          SHORT        (reserved)        set to 0
          SHORT        (reserved)        set to 0
          SHORT        (reserved)        set to 0
          SHORT        (reserved)        set to 0
          SHORT        metricDataFormat        0 for current format.
          USHORT        numberOfHMetrics        Number of hMetric entries in  ‘hmtx’ table; may be smaller than the total number of glyphs in the font.
         
        Parameters:
        data - docme
        Returns:
        docme
        Throws:
        java.io.IOException - docme
      • parseTable_hmtx

        public int[] parseTable_hmtx​(TTTable data,
                                     int count)
                              throws java.io.IOException
         The type longHorMetric is defined as an array where each element has
         two parts: the advance width, which is of type USHORT, and the left side
         bearing, which is of type SHORT. These fields are in font design units.
          typedef struct         _longHorMetric {
                         USHORT        advanceWidth;
                         SHORT                lsb;
          }  longHorMetric;
         
          Field Type Description
          hMetrics longHorMetric [numberOfHMetrics] Paired advance width and
                                         left side bearing values for each glyph. The value
                                         numOfHMetrics comes from the 'hhea' table. If the font is
                                         monospaced, only one entry need be in the array, but that
                                         entry is required. The last entry applies to all subsequent
                                         glyphs.
          leftSideBearing SHORT[ ] Here the advanceWidth is assumed to be the
                                         same as the advanceWidth for the last entry above. The
                                         number of entries in this array is derived from numGlyphs
                                         (from 'maxp' table) minus numberOfHMetrics. This generally
                                         is used with a run of monospaced glyphs (e.g., Kanji fonts
                                         or Courier fonts). Only one run is allowed and it must be
                                         at the end. This allows a monospaced font to vary the left
                                         side bearing values for each glyph.
         
        Parameters:
        data - docme
        count - docme
        Returns:
        docme
        Throws:
        java.io.IOException - docme
      • parseTable_loca

        public int[] parseTable_loca​(TTTable data,
                                     boolean shortLocationFormat)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • parseTable_name

        public TTNaming parseTable_name​(TTTable data)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • parseTable_os2

        public TTMetrics parseTable_os2​(TTTable data)
                                 throws java.io.IOException
          USHORT        version        0x0001
          SHORT        xAvgCharWidth;
          USHORT        usWeightClass;
          USHORT        usWidthClass;
          SHORT        fsType;
          SHORT        ySubscriptXSize;
          SHORT        ySubscriptYSize;
          SHORT        ySubscriptXOffset;
          SHORT        ySubscriptYOffset;
          SHORT        ySuperscriptXSize;
          SHORT        ySuperscriptYSize;
          SHORT        ySuperscriptXOffset;
          SHORT        ySuperscriptYOffset;
          SHORT        yStrikeoutSize;
          SHORT        yStrikeoutPosition;
          SHORT        sFamilyClass;
          PANOSE        panose;
          ULONG        ulUnicodeRange1        Bits 0–31
          ULONG        ulUnicodeRange2        Bits 32–63
          ULONG        ulUnicodeRange3        Bits 64–95
          ULONG        ulUnicodeRange4        Bits 96–127
          CHAR        achVendID[4];
          USHORT        fsSelection;
          USHORT        usFirstCharIndex
          USHORT        usLastCharIndex
          USHORT        sTypoAscender
          USHORT        sTypoDescender
          USHORT        sTypoLineGap
          USHORT        usWinAscent
          USHORT        usWinDescent
          ULONG        ulCodePageRange1        Bits 0-31
          ULONG        ulCodePageRange2        Bits 32-63
          SHORT                  sxHeight
                 SHORT                 sCapHeight
                 USHORT                 usDefaultChar
                 USHORT                 usBreakChar
                 USHORT                 usMaxContext
         
        Parameters:
        data - docme
        Returns:
        docme
        Throws:
        java.io.IOException - docme
      • parseTable_post

        public TTPostScriptInformation parseTable_post​(TTTable data)
                                                throws java.io.IOException
         Type         Name                 Description
         Fixed         Version         0x00010000 for version 1.0
                                                 0x00020000 for version 2.0
                                                 0x00025000 for version 2.5 (deprecated)
                                                 0x00030000 for version 3.0
         Fixed         italicAngle         Italic angle in counter-clockwise degrees from the vertical. Zero for upright text, negative for text that leans to the right (forward).
         FWord         underlinePosition         This is the suggested distance of the top of the underline from the baseline (negative values indicate below baseline).
                                                         The PostScript definition of this FontInfo dictionary key (the y coordinate of the center of the stroke) is not used for historical reasons. The value of the PostScript key may be calculated by subtracting half the underlineThickness from the value of this field.
         FWord         underlineThickness         Suggested values for the underline thickness.
         ULONG         isFixedPitch         Set to 0 if the font is proportionally spaced, non-zero if the font is not proportionally spaced (i.e. monospaced).
         ULONG         minMemType42         Minimum memory usage when an OpenType font is downloaded.
         ULONG         maxMemType42         Maximum memory usage when an OpenType font is downloaded.
         ULONG         minMemType1         Minimum memory usage when an OpenType font is downloaded as a Type 1 font.
         ULONG         maxMemType1         Maximum memory usage when an OpenType font is downloaded as a Type 1 font.
         
        Parameters:
        data - docme
        Returns:
        docme
        Throws:
        java.io.IOException - docme
      • parseTables

        public TTTable[] parseTables​(TTFont font)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readBytes

        public byte[] readBytes​(de.intarsys.tools.randomaccess.IRandomAccess random,
                                int count)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readCMapFormat0

        protected java.util.Map readCMapFormat0​(de.intarsys.tools.randomaccess.IRandomAccess random)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readCMapFormat4

        protected java.util.Map readCMapFormat4​(de.intarsys.tools.randomaccess.IRandomAccess random)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readCMapFormat6

        protected java.util.Map readCMapFormat6​(de.intarsys.tools.randomaccess.IRandomAccess random)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readFixed

        public float readFixed​(de.intarsys.tools.randomaccess.IRandomAccess random)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readInt

        public int readInt​(de.intarsys.tools.randomaccess.IRandomAccess random)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readNameRecord

        protected TTNameRecord readNameRecord​(de.intarsys.tools.randomaccess.IRandomAccess random,
                                              int stringTableOffset)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readShort

        public short readShort​(de.intarsys.tools.randomaccess.IRandomAccess random)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readTable

        public TTTable readTable​(TTFont font,
                                 de.intarsys.tools.randomaccess.IRandomAccess random)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • readTables

        public void readTables​(TTFont font,
                               de.intarsys.tools.randomaccess.IRandomAccess random)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readUInt

        public long readUInt​(de.intarsys.tools.randomaccess.IRandomAccess random)
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • readUShort

        public int readUShort​(de.intarsys.tools.randomaccess.IRandomAccess random)
                       throws java.io.IOException
        Throws:
        java.io.IOException