-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #595 from moontypespace/gasp_table
gasp table
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// The `gasp` table contains global information about the font. | ||
// https://learn.microsoft.com/de-de/typography/opentype/spec/gasp | ||
|
||
import check from '../check.js'; | ||
import parse from '../parse.js'; | ||
import table from '../table.js'; | ||
|
||
//const GASP_SYMMETRIC_GRIDFIT = 0x0004 | ||
//const GASP_SYMMETRIC_SMOOTHING = 0x0008 | ||
//const GASP_DOGRAY = 0x0002 | ||
//const GASP_GRIDFIT = 0x0001 | ||
|
||
// Parse the `gasp` table | ||
function parseGaspTable(data, start) { | ||
const gasp = {}; | ||
const p = new parse.Parser(data, start); | ||
gasp.version = p.parseUShort(); | ||
check.argument(gasp.version <= 0x0001, 'Unsupported gasp table version.'); | ||
gasp.numRanges = p.parseUShort(); | ||
gasp.gaspRanges = []; | ||
for (let i = 0; i < gasp.numRanges; i++) { | ||
gasp.gaspRanges[i] = { | ||
rangeMaxPPEM: p.parseUShort(), | ||
rangeGaspBehavior: p.parseUShort(), | ||
}; | ||
} | ||
return gasp; | ||
} | ||
|
||
|
||
function makeGaspTable(gasp) { | ||
const result = new table.Table('gasp', [ | ||
{name: 'version', type: 'USHORT', value: 0x0001}, | ||
{name: 'numRanges', type: 'USHORT', value: gasp.numRanges}, | ||
]); | ||
|
||
for (let i in gasp.numRanges) { | ||
result.fields.push({name: 'rangeMaxPPEM', type: 'USHORT', value: gasp.numRanges[i].rangeMaxPPEM}); | ||
result.fields.push({name: 'rangeGaspBehavior', type: 'USHORT', value: gasp.numRanges[i].rangeGaspBehavior}); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export default { parse: parseGaspTable, make: makeGaspTable }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import assert from 'assert'; | ||
import { Font, Path, Glyph, parse, load} from '../../src/opentype.js'; | ||
import { readFileSync } from 'fs'; | ||
const loadSync = (url, opt) => parse(readFileSync(url), opt); | ||
|
||
describe('tables/gasp.js', function () { | ||
const font = loadSync('./test/fonts/Roboto-Black.ttf'); | ||
|
||
it('can parse gasp table version', function() { | ||
assert.equal(font.tables.gasp.version, 1); | ||
}); | ||
it('can parse gasp table numRanges', function() { | ||
assert.equal(font.tables.gasp.numRanges, 2); | ||
}); | ||
|
||
it('can parse gasp table numRanges 0 rangeMaxPPEM', function() { | ||
assert.equal(font.tables.gasp.gaspRanges[0].rangeMaxPPEM, 8); // default value | ||
}); | ||
|
||
it('can parse gasp table numRanges 0 rangeGaspBehavior', function() { | ||
assert.equal(font.tables.gasp.gaspRanges[0].rangeGaspBehavior, 0x0002); //GASP_DOGRAY = 0x0002 | ||
}); | ||
|
||
it('can parse gasp table numRanges 1 rangeMaxPPEM', function() { | ||
assert.equal(font.tables.gasp.gaspRanges[1].rangeMaxPPEM, 0xFFFF); // default value | ||
}); | ||
|
||
it('can parse gasp table numRanges 1 rangeGaspBehavior', function() { | ||
assert.equal(font.tables.gasp.gaspRanges[1].rangeGaspBehavior, 0x0001 + 0x0002 + 0x0004 + 0x0008); // all flags set = 15 | ||
}); | ||
|
||
}); |