Skip to content

Commit 154077d

Browse files
committed
Implement noLayoutClosure flag, closes #22
1 parent 3d73ccb commit 154077d

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Options:
5252
- `targetFormat` - the format to output, can be either `'sfnt'`, `'woff'`, or `'woff2'`.
5353
- `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).
5454
- `variationAxes` - an object specifying a full or partial instancing of variation axes in the font. Only works with variable fonts. See the example above.
55+
- `noLayoutClosure` - don't perform glyph closure for layout substitution (GSUB). Equivalent to `hb-subset --no-layout-closure` and `pyftsubset --no-layout-closure`.
5556

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

index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ async function subsetFont(
2727
targetFormat = fontverter.detectFormat(originalFont),
2828
preserveNameIds,
2929
variationAxes,
30+
noLayoutClosure,
3031
} = {}
3132
) {
3233
if (typeof text !== 'string') {
@@ -76,6 +77,13 @@ async function subsetFont(
7677
}
7778
}
7879

80+
if (noLayoutClosure) {
81+
exports.hb_subset_input_set_flags(
82+
input,
83+
exports.hb_subset_input_get_flags(input) | 0x00000200 // HB_SUBSET_FLAGS_NO_LAYOUT_CLOSURE
84+
);
85+
}
86+
7987
// Add unicodes indices
8088
const inputUnicodes = exports.hb_subset_input_unicode_set(input);
8189
for (const c of text) {

test/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,51 @@ describe('subset-font', function () {
253253
});
254254
});
255255

256+
// https://github.com/papandreou/subset-font/issues/22
257+
describe('with an icon font', function () {
258+
before(async function () {
259+
this.materialIconsFont = await readFile(
260+
pathModule.resolve(
261+
__dirname,
262+
'..',
263+
'testdata',
264+
'MaterialIcons-Regular.ttf'
265+
)
266+
);
267+
});
268+
269+
describe('without the noLayoutClosure flag', function () {
270+
it('should retain more glyphs', async function () {
271+
const result = await subsetFont(
272+
this.materialIconsFont,
273+
`_abcdefghijklmnopqrstuvwxyz0123456789${String.fromCodePoint(
274+
0xe5c5,
275+
0xe5c8
276+
)}`
277+
);
278+
279+
expect(result.length, 'to be greater than', 300000);
280+
});
281+
});
282+
283+
describe('with the noLayoutClosure flag', function () {
284+
it('should retain more glyphs', async function () {
285+
const result = await subsetFont(
286+
this.materialIconsFont,
287+
`_abcdefghijklmnopqrstuvwxyz0123456789${String.fromCodePoint(
288+
0xe5c5,
289+
0xe5c8
290+
)}`,
291+
{
292+
noLayoutClosure: true,
293+
}
294+
);
295+
296+
expect(result.length, 'to be less than', 3000);
297+
});
298+
});
299+
});
300+
256301
describe('with a truncated font', function () {
257302
before(async function () {
258303
this.truncatedTtfFont = (

testdata/MaterialIcons-Regular.ttf

348 KB
Binary file not shown.

0 commit comments

Comments
 (0)