Code coverage report for fontkit/src/tables/kern.coffee

Statements: 88.24% (15 / 17)      Branches: 100% (0 / 0)      Functions: 66.67% (4 / 6)      Lines: 84.62% (11 / 13)      Ignored: none     

All files » fontkit/src/tables/ » kern.coffee
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 791   1         1       4   1 2 2     1                                                 1                                               4   1                  
r = require 'restructure'
 
KernPair = new r.Struct
  left:   r.uint16
  right:  r.uint16
  value:  r.int16
  
ClassTable = new r.Struct
  firstGlyph: r.uint16
  nGlyphs: r.uint16
  offsets: new r.Array(r.uint16, 'nGlyphs')
  max: -> @offsets.length and Math.max.apply Math, @offsets
  
Kern2Array = new r.Struct
  off: -> @_startOffset - @parent.parent._startOffset
  len: -> (((@parent.leftTable.max - @off) / @parent.rowWidth) + 1) * (@parent.rowWidth / 2)
  values: new r.LazyArray r.int16, 'len'
  
KernSubtable = new r.VersionedStruct 'format', 
  0:
    nPairs:         r.uint16
    searchRange:    r.uint16
    entrySelector:  r.uint16
    rangeShift:     r.uint16
    pairs:          new r.Array(KernPair, 'nPairs')
  
  2:
    rowWidth:   r.uint16
    leftTable:  new r.Pointer r.uint16, ClassTable, type: 'parent'
    rightTable: new r.Pointer r.uint16, ClassTable, type: 'parent'
    array:      new r.Pointer r.uint16, Kern2Array, type: 'parent'
 
  3:
    glyphCount:       r.uint16
    kernValueCount:   r.uint8
    leftClassCount:   r.uint8
    rightClassCount:  r.uint8
    flags:            r.uint8
    kernValue:        new r.Array(r.int16, 'kernValueCount')
    leftClass:        new r.Array(r.uint8, 'glyphCount')
    rightClass:       new r.Array(r.uint8, 'glyphCount')
    kernIndex:        new r.Array(r.uint8, -> @leftClassCount * @rightClassCount)
 
KernTable = new r.VersionedStruct 'version',
  0: # Microsoft uses this format
    subVersion: r.uint16  # Microsoft has an extra sub-table version number
    length:     r.uint16  # Length of the subtable, in bytes
    format:     r.uint8   # Format of subtable
    coverage:   new r.Bitfield r.uint8, [
      'horizontal'    # 1 if table has horizontal data, 0 if vertical
      'minimum'       # If set to 1, the table has minimum values. If set to 0, the table has kerning values.
      'crossStream'   # If set to 1, kerning is perpendicular to the flow of the text
      'override'      # If set to 1 the value in this table replaces the accumulated value
    ]
    subtable:   KernSubtable
    padding: new r.Reserved r.uint8, -> @length - @_currentOffset
  1: # Apple uses this format
    length:     r.uint32
    coverage:   new r.Bitfield r.uint8, [
      null, null, null, null, null,
      'variation'     # Set if table has variation kerning values
      'crossStream'   # Set if table has cross-stream kerning values
      'vertical'      # Set if table has vertical kerning values
    ]
    format:     r.uint8
    tupleIndex: r.uint16
    subtable:   KernSubtable
    padding: new r.Reserved r.uint8, -> @length - @_currentOffset
 
module.exports = new r.VersionedStruct r.uint16,
  0: # Microsoft Version
    nTables:    r.uint16
    tables:     new r.Array(KernTable, 'nTables')
    
  1: # Apple Version
    reserved:   new r.Reserved(r.uint16) # the other half of the version number
    nTables:    r.uint32
    tables:     new r.Array(KernTable, 'nTables')