Skip to content

Commit 48884cf

Browse files
committed
Add face.getTableFeatureTags()
1 parent 58bef3f commit 48884cf

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

hb.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ _hb_draw_funcs_set_close_path_func
6767
_hb_glyph_info_get_glyph_flags
6868
_hb_language_from_string
6969
_hb_ot_layout_table_get_script_tags
70+
_hb_ot_layout_table_get_feature_tags
7071
_hb_ot_layout_script_get_language_tags
7172
_hb_ot_layout_language_get_feature_tags
7273
_hb_ot_var_get_axis_infos

hbjs.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,30 @@ function hbjs(Module) {
159159
}
160160
return tags;
161161
},
162+
/**
163+
* Return all features enumerated in the specified face's
164+
* GSUB table or GPOS table.
165+
* @param {string} table: The table to query, either "GSUB" or "GPOS".
166+
**/
167+
getTableFeatureTags: function (table) {
168+
var tableTag = hb_tag(table);
169+
var startOffset = 0;
170+
var featureCount = STATIC_ARRAY_SIZE;
171+
var featureCountPtr = Module.stackAlloc(4);
172+
var featureTagsPtr = Module.stackAlloc(STATIC_ARRAY_SIZE * 4);
173+
var tags = [];
174+
while (featureCount == STATIC_ARRAY_SIZE) {
175+
Module.HEAPU32[featureCountPtr / 4] = featureCount;
176+
exports.hb_ot_layout_table_get_feature_tags(ptr, tableTag, startOffset,
177+
featureCountPtr, featureTagsPtr);
178+
featureCount = Module.HEAPU32[featureCountPtr / 4];
179+
var scriptTags = Module.HEAPU32.subarray(featureTagsPtr / 4,
180+
featureTagsPtr / 4 + featureCount);
181+
tags.push(...Array.from(scriptTags).map(_hb_untag));
182+
startOffset += featureCount;
183+
}
184+
return tags;
185+
},
162186
/**
163187
* Return language tags in the given face's GSUB or GPOS table, underneath
164188
* the specified script index.

test/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ describe('Face', function () {
5454
expect(face.getTableScriptTags('GPOS')).to.deep.equal(['DFLT', 'cyrl', 'dev2', 'deva', 'grek', 'latn']);
5555
});
5656

57+
it('getTableFeatureTags returns tags for a font', function () {
58+
blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
59+
face = hb.createFace(blob);
60+
expect(face.getTableFeatureTags('GSUB')).to.deep.equal([
61+
'aalt', 'abvs', 'akhn', 'blwf', 'blwf', 'blws', 'c2sc', 'case', 'ccmp', 'ccmp',
62+
'ccmp', 'ccmp', 'cjct', 'cjct', 'dnom', 'frac', 'half', 'half', 'half', 'half',
63+
'haln', 'liga', 'lnum', 'locl', 'locl', 'locl', 'locl', 'locl', 'locl', 'locl',
64+
'locl', 'locl', 'locl', 'locl', 'locl', 'nukt', 'numr', 'onum', 'ordn', 'pnum',
65+
'pres', 'pres', 'psts', 'rkrf', 'rphf', 'rtlm', 'salt', 'sinf', 'smcp', 'ss03',
66+
'ss04', 'ss06', 'ss07', 'subs', 'sups', 'tnum', 'vatu', 'zero'
67+
]);
68+
expect(face.getTableFeatureTags('GPOS')).to.deep.equal(['abvm', 'blwm', 'dist', 'kern', 'mark', 'mkmk']);
69+
});
70+
5771
it('getScriptLanguageTags returns tags for a font', function () {
5872
blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
5973
face = hb.createFace(blob);

0 commit comments

Comments
 (0)