Skip to content

Commit 1334243

Browse files
committed
Expose private glyph info and position members
Expose them as non-enumerable properties for clients who might need them.
1 parent 20ec420 commit 1334243

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

hbjs.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,10 +1118,17 @@ function hbjs(Module) {
11181118
var infosArray = Module.HEAPU32.subarray(infosPtr32, infosPtr32 + this.getLength() * 5);
11191119
var infos = [];
11201120
for (var i = 0; i < infosArray.length; i += 5) {
1121-
infos.push({
1121+
var info = {
11221122
codepoint: infosArray[i],
11231123
cluster: infosArray[i + 2],
1124-
});
1124+
};
1125+
for (var [name, idx] of [['mask', 1], ['var1', 3], ['var2', 4]]) {
1126+
Object.defineProperty(info, name, {
1127+
value: infosArray[i + idx],
1128+
enumerable: false
1129+
});
1130+
}
1131+
infos.push(info);
11251132
}
11261133
return infos;
11271134
},
@@ -1146,12 +1153,17 @@ function hbjs(Module) {
11461153
var positionsArray = Module.HEAP32.subarray(positionsPtr32, positionsPtr32 + this.getLength() * 5);
11471154
var positions = [];
11481155
for (var i = 0; i < positionsArray.length; i += 5) {
1149-
positions.push({
1156+
var position = {
11501157
x_advance: positionsArray[i],
11511158
y_advance: positionsArray[i + 1],
11521159
x_offset: positionsArray[i + 2],
11531160
y_offset: positionsArray[i + 3],
1161+
};
1162+
Object.defineProperty(position, 'var', {
1163+
value: positionsArray[i + 4],
1164+
enumerable: false
11541165
});
1166+
positions.push(position);
11551167
}
11561168
return positions;
11571169
},

test/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,27 @@ describe('Buffer', function () {
687687
]);
688688
});
689689

690+
it('glyph infos and positions have private properties', function () {
691+
blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
692+
face = hb.createFace(blob);
693+
font = hb.createFont(face);
694+
buffer = hb.createBuffer();
695+
buffer.addText('fi');
696+
buffer.guessSegmentProperties();
697+
hb.shape(font, buffer);
698+
const infos = buffer.getGlyphInfos();
699+
const positions = buffer.getGlyphPositions();
700+
701+
expect(infos.length).to.equal(1);
702+
expect(positions.length).to.equal(1);
703+
expect(Object.keys(infos[0])).to.deep.equal(['codepoint', 'cluster']);
704+
expect(Object.keys(positions[0])).to.deep.equal(['x_advance', 'y_advance', 'x_offset', 'y_offset']);
705+
expect(infos[0].mask).to.not.be.undefined;
706+
expect(infos[0].var1).to.not.be.undefined;
707+
expect(infos[0].var2).to.not.be.undefined;
708+
expect(positions[0].var).to.not.be.undefined;
709+
});
710+
690711
it('getPositions returns empty array for buffer without positions', function () {
691712
blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
692713
face = hb.createFace(blob);
@@ -993,3 +1014,4 @@ describe('misc', function () {
9931014
}
9941015
});
9951016
});
1017+

0 commit comments

Comments
 (0)