pdf.js
Version:
A PDF generation library for Node.js
37 lines (28 loc) • 1.14 kB
text/coffeescript
Table = require '../table'
Data = require '../../data'
class HmtxTable extends Table
parse: (data) ->
data.pos =
= []
for i in [0... .hhea.numberOfMetrics]
.push
advance: data.readUInt16()
lsb: data.readInt16()
lsbCount = .maxp.numGlyphs - .hhea.numberOfMetrics
= (data.readInt16() for i in [0...lsbCount])
= (m.advance for m in )
last = [ .length - 1]
.push(last) for i in [0...lsbCount]
forGlyph: (id) ->
return [id] if id of
metrics =
advance: [ .length - 1].advance
lsb: [id - .length]
encode: (mapping) ->
table = new Data
for id in mapping
metric = id
table.writeUInt16 metric.advance
table.writeUInt16 metric.lsb
return table.data
module.exports = HmtxTable