Skip to content

Commit

Permalink
Implement noLayoutClosure flag, closes #22
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Mar 25, 2024
1 parent 3d73ccb commit 154077d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Options:
- `targetFormat` - the format to output, can be either `'sfnt'`, `'woff'`, or `'woff2'`.
- `preserveNameIds` - an array of numbers specifying the extra name ids to preserve in the `name` table. By default the harfbuzz subsetter drops most of these. Use case described [here](https://github.com/papandreou/subset-font/issues/7).
- `variationAxes` - an object specifying a full or partial instancing of variation axes in the font. Only works with variable fonts. See the example above.
- `noLayoutClosure` - don't perform glyph closure for layout substitution (GSUB). Equivalent to `hb-subset --no-layout-closure` and `pyftsubset --no-layout-closure`.

For backwards compatibility reasons, `'truetype'` is supported as an alias for `'sfnt'`.

Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async function subsetFont(
targetFormat = fontverter.detectFormat(originalFont),
preserveNameIds,
variationAxes,
noLayoutClosure,
} = {}
) {
if (typeof text !== 'string') {
Expand Down Expand Up @@ -76,6 +77,13 @@ async function subsetFont(
}
}

if (noLayoutClosure) {
exports.hb_subset_input_set_flags(
input,
exports.hb_subset_input_get_flags(input) | 0x00000200 // HB_SUBSET_FLAGS_NO_LAYOUT_CLOSURE
);
}

// Add unicodes indices
const inputUnicodes = exports.hb_subset_input_unicode_set(input);
for (const c of text) {
Expand Down
45 changes: 45 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,51 @@ describe('subset-font', function () {
});
});

// https://github.com/papandreou/subset-font/issues/22
describe('with an icon font', function () {
before(async function () {
this.materialIconsFont = await readFile(
pathModule.resolve(
__dirname,
'..',
'testdata',
'MaterialIcons-Regular.ttf'
)
);
});

describe('without the noLayoutClosure flag', function () {
it('should retain more glyphs', async function () {
const result = await subsetFont(
this.materialIconsFont,
`_abcdefghijklmnopqrstuvwxyz0123456789${String.fromCodePoint(
0xe5c5,
0xe5c8
)}`
);

expect(result.length, 'to be greater than', 300000);
});
});

describe('with the noLayoutClosure flag', function () {
it('should retain more glyphs', async function () {
const result = await subsetFont(
this.materialIconsFont,
`_abcdefghijklmnopqrstuvwxyz0123456789${String.fromCodePoint(
0xe5c5,
0xe5c8
)}`,
{
noLayoutClosure: true,
}
);

expect(result.length, 'to be less than', 3000);
});
});
});

describe('with a truncated font', function () {
before(async function () {
this.truncatedTtfFont = (
Expand Down
Binary file added testdata/MaterialIcons-Regular.ttf
Binary file not shown.

0 comments on commit 154077d

Please sign in to comment.