Code coverage report for fontkit/src/opentype/GlyphIterator.coffee

Statements: 97.37% (37 / 38)      Branches: 100% (4 / 4)      Functions: 90.91% (10 / 11)      Lines: 97.06% (33 / 34)      Ignored: none     

All files » fontkit/src/opentype/ » GlyphIterator.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 551 1   116     534   1 6959   1 6689 6682 6682   1 7109 7109 7   7109 427   6682     374           423 423 423 423     58 58 58 58 58     39183 39183 39183 6735   39183   1  
class GlyphIterator
  get = require('../get')(this)
  constructor: (@glyphs, flags) ->
    @reset flags
    
  reset: (@flags = {}) ->
    @index = 0
  
  get 'cur', ->
    return @glyphs[@index] or null
    
  shouldIgnore = (glyph, flags) ->
    return ((flags.ignoreMarks and glyph.isMark) or
           (flags.ignoreBaseGlyphs and not glyph.isMark) or
           (flags.ignoreLigatures and glyph.isLigature))
           
  move = (dir) ->
    @index += dir
    while 0 <= @index < @glyphs.length and shouldIgnore @glyphs[@index], @flags
      @index += dir
      
    unless 0 <= @index < @glyphs.length
      return null
      
    return @glyphs[@index]
    
  next: ->
    move.call this, 1
    
  prev: ->
    move.call this, -1
    
  peek: (count = 1) ->
    idx = @index
    res = @increment count
    @index = idx
    return res
    
  peekIndex: (count = 1) ->
    idx = @index
    @increment count
    res = @index
    @index = idx
    return res
    
  increment: (count = 1) ->
    dir = if count < 0 then -1 else 1
    count = Math.abs count
    while count--
      move.call this, dir
      
    return @glyphs[@index]
 
module.exports = GlyphIterator