Skip to content

Commit

Permalink
Merge pull request #80 from harfbuzz/trace-buffer-type
Browse files Browse the repository at this point in the history
Trace buffer type
  • Loading branch information
simoncozens authored May 13, 2023
2 parents ed48087 + 549d3f1 commit d4bdc98
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hbjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ static hb_bool_t do_trace (hb_buffer_t *buffer,
HB_BUFFER_SERIALIZE_FORMAT_JSON,
HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES);
user_data->consumed += consumed;
if (hb_buffer_get_content_type(buffer) == HB_BUFFER_CONTENT_TYPE_GLYPHS) {
_user_data_printf (user_data, ", \"glyphs\": true");
} else {
_user_data_printf (user_data, ", \"glyphs\": false");
}
_user_data_printf (user_data, "},\n");

return 1;
Expand Down
29 changes: 29 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,33 @@ describe('shape', function () {
expect(glyphs[2]).to.deep.equal({cl: 1, g: 101, ax: 269, ay: 0, dx: 0, dy: 0, flags: 0} /* ب */);
expect(glyphs[3]).to.deep.equal({cl: 0, g: 50, ax: 235, ay: 0, dx: 0, dy: 0, flags: 0} /* أ */);
});

it('shape with tracing', function () {
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
this.face = hb.createFace(this.blob);
this.font = hb.createFont(this.face);
this.buffer = hb.createBuffer();
this.buffer.addText('abc');
this.buffer.guessSegmentProperties();
const result = hb.shapeWithTrace(this.font, this.buffer, 0, 0)
expect(result).to.have.lengthOf(42);
expect(result[0]).to.deep.equal({
"m": "start table GSUB",
"glyphs": true,
"t": [
{cl: 0, g: 68},
{cl: 1, g: 69},
{cl: 2, g: 70},
],
});
expect(result[41]).to.deep.equal({
"m": "end table GPOS",
"glyphs": true,
"t": [
{cl: 0, g: 68, ax: 561, ay: 0, dx: 0, dy: 0},
{cl: 1, g: 69, ax: 615, ay: 0, dx: 0, dy: 0},
{cl: 2, g: 70, ax: 480, ay: 0, dx: 0, dy: 0},
],
});
});
});

0 comments on commit d4bdc98

Please sign in to comment.