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

Statements: 93.33% (14 / 15)      Branches: 100% (0 / 0)      Functions: 66.67% (2 / 3)      Lines: 92.86% (13 / 14)      Ignored: none     

All files » fontkit/src/tables/ » cmap.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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 1111   1           1         1       1       1 1   1         1                                   12                 12                                                                                       1           1        
r = require 'restructure'
 
SubHeader = new r.Struct
  firstCode:      r.uint16
  entryCount:     r.uint16
  idDelta:        r.int16
  idRangeOffset:  r.uint16
  
CmapGroup = new r.Struct
  startCharCode:  r.uint32
  endCharCode:    r.uint32
  glyphID:        r.uint32
  
UnicodeValueRange = new r.Struct
  startUnicodeValue:  r.uint24
  additionalCount:    r.uint8
  
UVSMapping = new r.Struct
  unicodeValue: r.uint24
  glyphID:      r.uint16
  
DefaultUVS = new r.Array(UnicodeValueRange, r.uint32)
NonDefaultUVS = new r.Array(UVSMapping, r.uint32)
  
VarSelectorRecord = new r.Struct
  varSelector:    r.uint24
  defaultUVS:     new r.Pointer(r.uint32, DefaultUVS, type: 'parent')
  nonDefaultUVS:  new r.Pointer(r.uint32, NonDefaultUVS, type: 'parent')
  
CmapSubtable = new r.VersionedStruct r.uint16,
  0: # Byte encoding
    length:     r.uint16   # Total table length in bytes (set to 262 for format 0)
    language:   r.uint16   # Language code for this encoding subtable, or zero if language-independent
    codeMap:    new r.LazyArray(r.uint8, 256)
    
  2: # High-byte mapping (CJK)
    length:           r.uint16
    language:         r.uint16
    subHeaderKeys:    new r.Array(r.uint16, 256)
    subHeaderCount:   -> Math.max.apply(Math, @subHeaderKeys)
    subHeaders:       new r.LazyArray(SubHeader, 'subHeaderCount')
    glyphIndexArray:  new r.LazyArray(r.uint16, 'subHeaderCount')
  
  4: # Segment mapping to delta values
    length:           r.uint16              # Total table length in bytes
    language:         r.uint16              # Language code
    segCountX2:       r.uint16
    segCount:         -> @segCountX2 >> 1
    searchRange:      r.uint16
    entrySelector:    r.uint16
    rangeShift:       r.uint16
    endCode:          new r.LazyArray(r.uint16, 'segCount')
    reservedPad:      new r.Reserved(r.uint16)       # This value should be zero
    startCode:        new r.LazyArray(r.uint16, 'segCount')
    idDelta:          new r.LazyArray(r.int16, 'segCount')
    idRangeOffset:    new r.LazyArray(r.uint16, 'segCount')
    glyphIndexArray:  new r.LazyArray(r.uint16, -> (@length - @_currentOffset) / 2)
    
  6: # Trimmed table
    length:         r.uint16
    language:       r.uint16
    firstCode:      r.uint16
    entryCount:     r.uint16
    glyphIndices:   new r.LazyArray(r.uint16, 'entryCount')
    
  8: # mixed 16-bit and 32-bit coverage
    reserved: new r.Reserved(r.uint16)
    length:   r.uint32
    language: r.uint16
    is32:     new r.LazyArray(r.uint8, 8192)
    nGroups:  r.uint32
    groups:   new r.LazyArray(CmapGroup, 'nGroups')
    
  10: # Trimmed Array
    reserved:       new r.Reserved(r.uint16)
    length:         r.uint32
    language:       r.uint32
    firstCode:      r.uint32
    entryCount:     r.uint32
    glyphIndices:   new r.LazyArray(r.uint16, 'numChars')
    
  12: # Segmented coverage
    reserved: new r.Reserved(r.uint16)
    length:   r.uint32
    language: r.uint32
    nGroups:  r.uint32
    groups:   new r.LazyArray(CmapGroup, 'nGroups')
    
  13: # Many-to-one range mappings (same as 12 except for group.startGlyphID)
    reserved: new r.Reserved(r.uint16)
    length:   r.uint32
    language: r.uint32
    nGroups:  r.uint32
    groups:   new r.LazyArray(CmapGroup, 'nGroups')
    
  14: # Unicode Variation Sequences
    length:       r.uint32
    numRecords:   r.uint32
    varSelectors: new r.LazyArray(VarSelectorRecord, 'numRecords')
 
CmapEntry = new r.Struct
  platformID:  r.uint16  # Platform identifier
  encodingID:  r.uint16  # Platform-specific encoding identifier
  table:       new r.Pointer(r.uint32, CmapSubtable, type: 'parent', lazy: yes)
  
# character to glyph mapping
module.exports = new r.Struct
  version:      r.uint16
  numSubtables: r.uint16
  tables:       new r.Array(CmapEntry, 'numSubtables')