Glyph = require './Glyph'
CBDT = require '../tables/EBDT'
class BitmapGlyph extends Glyph
_decode: ->
unless @_decoded
cblc = @_font.CBLC
table = cblc.sizes[0].indexSubTableArray[0]
offset = table.subtable.offsetArray[@id - table.firstGlyphIndex]
return null unless offset?
@_font.stream.pos = @_font.directory.tables.CBDT.offset + table.subtable.imageDataOffset + offset
@_decoded = CBDT.glyph.decode @_font.stream, version: table.subtable.imageFormat
return @_decoded
getImageForSize: (size) ->
return @_decode()?.data
_getBBox: ->
metrics = @_decode()?.metrics
if metrics
return [0, -metrics.height+metrics.bearingY, metrics.width, metrics.bearingY]
return [0, 0, 0, 0]
render: (ctx, size) ->
img = @getImageForSize size
cblc = @_font.CBLC
ppem = cblc.sizes[0].ppemY
if img
ctx.image img, height: (@bbox[3] - @bbox[1]) * size / ppem, x: 0, y: @bbox[1] * size / ppem
module.exports = BitmapGlyph
|