diff --git a/src/font.js b/src/font.js index b232ff19..b9e6c91b 100644 --- a/src/font.js +++ b/src/font.js @@ -52,6 +52,7 @@ function createDefaultNamesInfo(options) { * @property {Number} unitsPerEm * @property {Number} ascender * @property {Number} descender + * @property {Number} lineGap * @property {Number} createdTimestamp * @property {Number} weightClass * @property {Number} italicAngle @@ -91,6 +92,7 @@ function Font(options) { this.createdTimestamp = options.createdTimestamp; this.italicAngle = options.italicAngle || 0; this.weightClass = options.weightClass || 0; + this.lineGap = options.lineGap || 0; let selection = 0; if (options.fsSelection) { diff --git a/src/opentype.js b/src/opentype.js index 0fd00854..079a40aa 100644 --- a/src/opentype.js +++ b/src/opentype.js @@ -320,6 +320,7 @@ function parseBuffer(buffer, opt={}) { font.tables.hhea = hhea.parse(table.data, table.offset); font.ascender = font.tables.hhea.ascender; font.descender = font.tables.hhea.descender; + font.lineGap = font.tables.hhea.lineGap; font.numberOfHMetrics = font.tables.hhea.numberOfHMetrics; break; case 'hmtx': diff --git a/src/tables/sfnt.js b/src/tables/sfnt.js index 8abdb844..9b2ce3ba 100644 --- a/src/tables/sfnt.js +++ b/src/tables/sfnt.js @@ -206,6 +206,7 @@ function fontToSfntTable(font) { }; globals.ascender = font.ascender; globals.descender = font.descender; + globals.lineGap = font.lineGap; // macStyle bits must agree with the fsSelection bits let macStyle = 0; @@ -214,7 +215,7 @@ function fontToSfntTable(font) { } if (font.italicAngle < 0) { macStyle |= font.macStyleValues.ITALIC; - } + } const headTable = head.make({ flags: 3, // 00000011 (baseline for font at y=0; left sidebearing point at x=0) @@ -229,6 +230,7 @@ function fontToSfntTable(font) { }); const hheaTable = hhea.make({ + lineGap: globals.lineGap, ascender: globals.ascender, descender: globals.descender, advanceWidthMax: globals.advanceWidthMax, @@ -254,7 +256,7 @@ function fontToSfntTable(font) { // ordering was chosen experimentally. sTypoAscender: globals.ascender, sTypoDescender: globals.descender, - sTypoLineGap: 0, + sTypoLineGap: globals.lineGap || 0, usWinAscent: globals.yMax, usWinDescent: Math.abs(globals.yMin), ulCodePageRange1: 1, // FIXME: hard-code Latin 1 support for now diff --git a/test/font.js b/test/font.js index e15217b8..5305a863 100644 --- a/test/font.js +++ b/test/font.js @@ -28,6 +28,7 @@ describe('font.js', function() { ascender: 800, descender: 0, fsSelection: 42, + lineGap: 500, tables: {os2: {achVendID: 'TEST'}}, glyphs: glyphs }); @@ -37,6 +38,9 @@ describe('font.js', function() { it('accept 0 as descender value', function() { assert.equal(font.descender, 0); }); + it('accept 500 as lineGap value', function() { + assert.equal(font.lineGap, 500); + }); it('tables definition must be supported', function() { assert.equal(font.tables.os2.achVendID, 'TEST'); });