Skip to content

Commit 46d3363

Browse files
committed
Add font.subFont()
1 parent 5fc9036 commit 46d3363

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

hb.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ _hb_face_reference_table
2626
_hb_font_create
2727
_hb_font_destroy
2828
_hb_font_reference
29+
_hb_font_create_sub_font
2930
_hb_font_glyph_to_string
3031
_hb_font_set_scale
3132
_hb_font_set_variations

hbjs.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ function hbjs(Module) {
218218

219219
return {
220220
ptr: ptr,
221+
/**
222+
* Create a sub font.
223+
* @returns {object} Object representing the sub font.
224+
**/
225+
subFont: function () {
226+
return createFont(null, exports.hb_font_create_sub_font(ptr));
227+
},
221228
/**
222229
* Return font horizontal extents.
223230
* @returns {object} Object with ascender, descender, and lineGap properties.

test/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,34 @@ describe('Face', function () {
4949
});
5050

5151
describe('Font', function () {
52+
it('subFont creates a sub font', function () {
53+
blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
54+
face = hb.createFace(blob);
55+
font = hb.createFont(face);
56+
let subFont = font.subFont();
57+
expect(subFont.ptr).to.not.equal(font.ptr);
58+
subFont.destroy();
59+
});
60+
61+
it('subFont font funcs fallback to parent', function () {
62+
blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
63+
face = hb.createFace(blob);
64+
font = hb.createFont(face);
65+
let subFont = font.subFont();
66+
expect(subFont.ptr).to.not.equal(font.ptr);
67+
68+
fontFuncs = hb.createFontFuncs();
69+
fontFuncs.setGlyphNameFunc(function (font_, glyph) {
70+
expect(font_.ptr).to.equal(subFont.ptr);
71+
return null;
72+
});
73+
subFont.setFuncs(fontFuncs);
74+
75+
expect(subFont.glyphName(20)).to.equal("gid20");
76+
expect(subFont.glyphHAdvance(20)).to.equal(font.glyphHAdvance(20));
77+
subFont.destroy();
78+
});
79+
5280
it('hExtents returns extents for the font', function () {
5381
blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
5482
face = hb.createFace(blob);

0 commit comments

Comments
 (0)