Code coverage report for fontkit/src/glyph/SBIXGlyph.coffee

Statements: 65.22% (15 / 23)      Branches: 25% (2 / 8)      Functions: 75% (3 / 4)      Lines: 66.67% (14 / 21)      Ignored: none     

All files » fontkit/src/glyph/ » SBIXGlyph.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 351 1   1 1       1     1 1   1 1 1   1     1 1                     1  
TTFGlyph = require './TTFGlyph'
r = require 'restructure'
 
class SBIXGlyph extends TTFGlyph
  SBIXImage = new r.Struct
    originX: r.uint16
    originY: r.uint16
    type: new r.String(4)
    data: new r.Buffer -> @parent.buflen - @_currentOffset
  
  getImageForSize: (size) ->
    for table in @_font.sbix.imageTables
      Ebreak if table.ppem >= size
    
    offsets = table.imageOffsets
    start = offsets[@id]
    end = offsets[@id + 1]
    
    Iif start is end
      return null
      
    @_font.stream.pos = start
    return SBIXImage.decode @_font.stream, buflen: end - start
    
  render: (ctx, size) ->
    img = @getImageForSize size
    if img?
      scale = size / @_font.unitsPerEm
      ctx.image img.data, height: size, x: img.originX, y: (@bbox.minY - img.originY) * scale
      
    if @_font.sbix.flags.renderOutlines
      super
    
module.exports = SBIXGlyph