Class TTFontParser

java.lang.Object
de.intarsys.cwt.font.truetype.TTFontParser

public class TTFontParser extends 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
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
     
    This table gives global information about the font.
    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)
     
     
    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
    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.
     
    byte[]
    readBytes(de.intarsys.tools.randomaccess.IRandomAccess random, int count)
     
    protected Map
    readCMapFormat0(de.intarsys.tools.randomaccess.IRandomAccess random)
     
    protected Map
    readCMapFormat4(de.intarsys.tools.randomaccess.IRandomAccess random)
     
    protected 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)
     
    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 Details

    • TTFontParser

      public TTFontParser()
  • Method Details

    • parseTable_cmap

      public Map parseTable_cmap(TTTable data) throws IOException
      Throws:
      IOException
    • parseTable_cmap_subtable

      public Map parseTable_cmap_subtable(TTTable data) throws IOException
      Throws:
      IOException
    • parseTable_head

      public TTFontHeader parseTable_head(TTTable data) throws 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:
      IOException - docme
    • parseTable_hhea

      public TTHorizontalHeader parseTable_hhea(TTTable data) throws 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:
      IOException - docme
    • parseTable_hmtx

      public int[] parseTable_hmtx(TTTable data, int count) throws 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:
      IOException - docme
    • parseTable_loca

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

      public TTNaming parseTable_name(TTTable data) throws IOException
      Throws:
      IOException
    • parseTable_os2

      public TTMetrics parseTable_os2(TTTable data) throws 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:
      IOException - docme
    • parseTable_post

      public TTPostScriptInformation parseTable_post(TTTable data) throws 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:
      IOException - docme
    • parseTables

      public TTTable[] parseTables(TTFont font) throws IOException
      Throws:
      IOException
    • readBytes

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

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

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

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

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

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

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

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

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

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

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

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