harfbuzzjs 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/hbjs.js +43 -15
  2. package/package.json +1 -1
  3. package/test/index.js +28 -15
package/hbjs.js CHANGED
@@ -1139,17 +1139,10 @@ function hbjs(Module) {
1139
1139
  var infosArray = Module.HEAPU32.subarray(infosPtr32, infosPtr32 + this.getLength() * 5);
1140
1140
  var infos = [];
1141
1141
  for (var i = 0; i < infosArray.length; i += 5) {
1142
- var info = {
1142
+ infos.push({
1143
1143
  codepoint: infosArray[i],
1144
1144
  cluster: infosArray[i + 2],
1145
- };
1146
- for (var [name, idx] of [['mask', 1], ['var1', 3], ['var2', 4]]) {
1147
- Object.defineProperty(info, name, {
1148
- value: infosArray[i + idx],
1149
- enumerable: false
1150
- });
1151
- }
1152
- infos.push(info);
1145
+ });
1153
1146
  }
1154
1147
  return infos;
1155
1148
  },
@@ -1174,21 +1167,56 @@ function hbjs(Module) {
1174
1167
  var positionsArray = Module.HEAP32.subarray(positionsPtr32, positionsPtr32 + this.getLength() * 5);
1175
1168
  var positions = [];
1176
1169
  for (var i = 0; i < positionsArray.length; i += 5) {
1177
- var position = {
1170
+ positions.push({
1178
1171
  x_advance: positionsArray[i],
1179
1172
  y_advance: positionsArray[i + 1],
1180
1173
  x_offset: positionsArray[i + 2],
1181
1174
  y_offset: positionsArray[i + 3],
1182
- };
1183
- Object.defineProperty(position, 'var', {
1184
- value: positionsArray[i + 4],
1185
- enumerable: false
1186
1175
  });
1187
- positions.push(position);
1188
1176
  }
1189
1177
  return positions;
1190
1178
  },
1191
1179
  /**
1180
+ * Get the glyph information and positions from the buffer.
1181
+ * @returns {object[]} The glyph information and positions.
1182
+ *
1183
+ * The glyph information is returned as an array of objects with the
1184
+ * properties from getGlyphInfos and getGlyphPositions combined.
1185
+ */
1186
+ getGlyphInfosAndPositions: function () {
1187
+ var infosPtr32 = exports.hb_buffer_get_glyph_infos(ptr, 0) / 4;
1188
+ var infosArray = Module.HEAPU32.subarray(infosPtr32, infosPtr32 + this.getLength() * 5);
1189
+
1190
+ var positionsPtr32 = exports.hb_buffer_get_glyph_positions(ptr, 0) / 4;
1191
+ var positionsArray = positionsPtr32 ? Module.HEAP32.subarray(positionsPtr32, positionsPtr32 + this.getLength() * 5) : null;
1192
+
1193
+ var out = [];
1194
+ for (var i = 0; i < infosArray.length; i += 5) {
1195
+ var info = {
1196
+ codepoint: infosArray[i],
1197
+ cluster: infosArray[i + 2],
1198
+ };
1199
+ for (var [name, idx] of [['mask', 1], ['var1', 3], ['var2', 4]]) {
1200
+ Object.defineProperty(info, name, {
1201
+ value: infosArray[i + idx],
1202
+ enumerable: false
1203
+ });
1204
+ }
1205
+ if (positionsArray) {
1206
+ info.x_advance = positionsArray[i];
1207
+ info.y_advance = positionsArray[i + 1];
1208
+ info.x_offset = positionsArray[i + 2];
1209
+ info.y_offset = positionsArray[i + 3];
1210
+ Object.defineProperty(info, 'var', {
1211
+ value: positionsArray[i + 4],
1212
+ enumerable: false
1213
+ });
1214
+ }
1215
+ out.push(info);
1216
+ }
1217
+ return out;
1218
+ },
1219
+ /**
1192
1220
  * Update the glyph positions in the buffer.
1193
1221
  * @param {object[]} positions The new glyph positions.
1194
1222
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "harfbuzzjs",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Minimal version of HarfBuzz for JavaScript use",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test/index.js CHANGED
@@ -659,6 +659,7 @@ describe('Buffer', function () {
659
659
  buffer = hb.createBuffer();
660
660
  expect(buffer.getGlyphInfos()).to.deep.equal([]);
661
661
  expect(buffer.getGlyphPositions()).to.deep.equal([]);
662
+ expect(buffer.getGlyphInfosAndPositions()).to.deep.equal([]);
662
663
  });
663
664
 
664
665
  it('getInfos and getPositions return non empty arrays for non empty buffer', function () {
@@ -670,31 +671,46 @@ describe('Buffer', function () {
670
671
  buffer.guessSegmentProperties();
671
672
 
672
673
  // before shaping
673
- expect(buffer.getGlyphInfos()).to.deep.equal([
674
+ let infos = buffer.getGlyphInfos();
675
+ let positions = buffer.getGlyphPositions();
676
+ let infosAndPositions = buffer.getGlyphInfosAndPositions();
677
+
678
+ expect(infos).to.deep.equal([
674
679
  { codepoint: 120, cluster: 0 },
675
680
  { codepoint: 768, cluster: 1 },
676
681
  { codepoint: 102, cluster: 2 },
677
682
  { codepoint: 105, cluster: 3 }
678
683
  ]);
679
- expect(buffer.getGlyphPositions()).to.deep.equal([
684
+ expect(positions).to.deep.equal([
680
685
  { x_advance: 0, y_advance: 0, x_offset: 0, y_offset: 0 },
681
686
  { x_advance: 0, y_advance: 0, x_offset: 0, y_offset: 0 },
682
687
  { x_advance: 0, y_advance: 0, x_offset: 0, y_offset: 0 },
683
688
  { x_advance: 0, y_advance: 0, x_offset: 0, y_offset: 0 }
684
689
  ]);
685
690
 
691
+ for (let i = 0; i < infosAndPositions.length; i++) {
692
+ expect(infosAndPositions[i]).to.deep.equal({ ...infos[i], ...positions[i] });
693
+ }
694
+
686
695
  hb.shape(font, buffer);
687
696
  // after shaping
688
- expect(buffer.getGlyphInfos()).to.deep.equal([
697
+ infos = buffer.getGlyphInfos();
698
+ positions = buffer.getGlyphPositions();
699
+ infosAndPositions = buffer.getGlyphInfosAndPositions();
700
+
701
+ expect(infos).to.deep.equal([
689
702
  { codepoint: 91, cluster: 0 },
690
703
  { codepoint: 2662, cluster: 0 },
691
704
  { codepoint: 1652, cluster: 2 }
692
705
  ]);
693
- expect(buffer.getGlyphPositions()).to.deep.equal([
706
+ expect(positions).to.deep.equal([
694
707
  { x_advance: 529, y_advance: 0, x_offset: 0, y_offset: 0 },
695
708
  { x_advance: 0, y_advance: 0, x_offset: 97, y_offset: 0 },
696
709
  { x_advance: 602, y_advance: 0, x_offset: 0, y_offset: 0 }
697
710
  ]);
711
+ for (let i = 0; i < infosAndPositions.length; i++) {
712
+ expect(infosAndPositions[i]).to.deep.equal({ ...infos[i], ...positions[i] });
713
+ }
698
714
  });
699
715
 
700
716
  it('glyph infos and positions have private properties', function () {
@@ -705,17 +721,14 @@ describe('Buffer', function () {
705
721
  buffer.addText('fi');
706
722
  buffer.guessSegmentProperties();
707
723
  hb.shape(font, buffer);
708
- const infos = buffer.getGlyphInfos();
709
- const positions = buffer.getGlyphPositions();
710
-
711
- expect(infos.length).to.equal(1);
712
- expect(positions.length).to.equal(1);
713
- expect(Object.keys(infos[0])).to.deep.equal(['codepoint', 'cluster']);
714
- expect(Object.keys(positions[0])).to.deep.equal(['x_advance', 'y_advance', 'x_offset', 'y_offset']);
715
- expect(infos[0].mask).to.not.be.undefined;
716
- expect(infos[0].var1).to.not.be.undefined;
717
- expect(infos[0].var2).to.not.be.undefined;
718
- expect(positions[0].var).to.not.be.undefined;
724
+ const infosAndPositions = buffer.getGlyphInfosAndPositions();
725
+
726
+ expect(infosAndPositions.length).to.equal(1);
727
+ expect(Object.keys(infosAndPositions[0])).to.deep.equal(['codepoint', 'cluster', 'x_advance', 'y_advance', 'x_offset', 'y_offset']);
728
+ expect(infosAndPositions[0].mask).to.not.be.undefined;
729
+ expect(infosAndPositions[0].var1).to.not.be.undefined;
730
+ expect(infosAndPositions[0].var2).to.not.be.undefined;
731
+ expect(infosAndPositions[0].var).to.not.be.undefined;
719
732
  });
720
733
 
721
734
  it('getPositions returns empty array for buffer without positions', function () {