all files / fontkit/src/layout/ GlyphRun.coffee

26.92% Statements 7/26
100% Branches 0/0
40% Functions 2/5
26.92% Lines 7/26
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                                                                
BBox = require '../glyph/BBox'
 
class GlyphRun
  get = require('../get')(this)
  constructor: (@glyphs, @positions) ->
    
  get 'advanceWidth', ->
    width = 0
    for position in @positions
      width += position.xAdvance
      
    return width
    
  get 'advanceHeight', ->
    height = 0
    for position in @positions
      height += position.yAdvance
      
    return height
      
  get 'bbox', ->
    bbox = new BBox
    
    x = 0
    y = 0
    for glyph, index in @glyphs
      p = @positions[index]
      b = glyph.bbox
      
      bbox.addPoint b.minX + x + p.xOffset, b.minY + y + p.yOffset
      bbox.addPoint b.maxX + x + p.xOffset, b.maxY + y + p.yOffset
      
      x += p.xAdvance
      y += p.yAdvance
      
    return bbox
    
module.exports = GlyphRun