From e00194bd336d1b0c7bd96026daa4a261eeeb1891 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Fri, 12 May 2023 14:52:22 +0300 Subject: [PATCH 1/2] [trace] Know if a buffer is glyphs or not --- hbjs.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hbjs.cc b/hbjs.cc index 946ab2d..849a43b 100644 --- a/hbjs.cc +++ b/hbjs.cc @@ -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; From 549d3f141434e075f7cbd2368534a5528d57a952 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Fri, 12 May 2023 14:52:35 +0300 Subject: [PATCH 2/2] Add a simple test for shapeWithTrace() --- test/index.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/index.js b/test/index.js index d7b9ae0..f7a69cd 100644 --- a/test/index.js +++ b/test/index.js @@ -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}, + ], + }); + }); });