all files / fontkit/src/subset/ Subset.coffee

100% Statements 17/17
100% Branches 4/4
100% Functions 5/5
100% Lines 17/17
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             21× 13×   21× 19× 19×   21×            
r = require 'restructure'
 
class Subset
  constructor: (@font) ->
    @glyphs = []
    @mapping = {}
    
    # always include the missing glyph
    @includeGlyph 0
    
  includeGlyph: (glyph) ->    
    if typeof glyph is 'object'
      glyph = glyph.id
    
    unless @mapping[glyph]?
      @glyphs.push glyph
      @mapping[glyph] = @glyphs.length - 1
      
    return @mapping[glyph]
    
  encodeStream: ->
    s = new r.EncodeStream
    
    process.nextTick =>
      @encode s
      s.end()
      
    return s
    
module.exports = Subset