Code coverage report for fontkit/src/opentype/shapers/DefaultShaper.coffee

Statements: 96.67% (29 / 30)      Branches: 83.33% (5 / 6)      Functions: 100% (3 / 3)      Lines: 96.67% (29 / 30)      Ignored: none     

All files » fontkit/src/opentype/shapers/ » DefaultShaper.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 531 1   1   19   19   15     4   19     19   19       10 10 156 156 1 1     1 1 1 1     1 2 2 2     1 1     155   10   1  
Script = require '../../layout/Script'
unicode = require 'unicode-properties'
 
class DefaultShaper
  @getGlobalFeatures: (script, isVertical = false) ->
    features = ['ccmp', 'locl', 'rlig', 'mark', 'mkmk']
    
    switch Script.direction(script)
      when 'ltr'
        features.push 'ltra', 'ltrm'
        
      when 'rtl'
        features.push 'rtla', 'rtlm'
      
    Iif isVertical
      features.push 'vert'
    else
      features.push 'calt', 'clig', 'liga', 'rclt', 'curs', 'kern'
      
    return features
    
  @assignFeatures: (glyphs, script) ->
    # Enable contextual fractions
    i = 0
    while i < glyphs.length
      glyph = glyphs[i]
      if glyph.codePoints[0] is 0x2044 # fraction slash
        start = i - 1
        end = i + 1
        
        # Apply numerator
        while start >= 0 and unicode.isDigit(glyphs[start].codePoints[0])
          glyphs[start].features.numr = true
          glyphs[start].features.frac = true
          start--
          
        # Apply denominator
        while end < glyphs.length and unicode.isDigit(glyphs[end].codePoints[0])
          glyphs[end].features.dnom = true
          glyphs[end].features.frac = true
          end++
          
        # Apply fraction slash
        glyph.features.frac = true
        i = end - 1
        
      else
        i++
        
    return ['frac', 'numr', 'dnom']
    
module.exports = DefaultShaper