Skip to content

Add a lineGap configuration option to the Font object #681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/opentype.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
6 changes: 4 additions & 2 deletions src/tables/sfnt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -229,6 +230,7 @@ function fontToSfntTable(font) {
});

const hheaTable = hhea.make({
lineGap: globals.lineGap,
ascender: globals.ascender,
descender: globals.descender,
advanceWidthMax: globals.advanceWidthMax,
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('font.js', function() {
ascender: 800,
descender: 0,
fsSelection: 42,
lineGap: 500,
tables: {os2: {achVendID: 'TEST'}},
glyphs: glyphs
});
Expand All @@ -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');
});
Expand Down