Skip to content

Commit eee3c3e

Browse files
authored
Merge pull request #110 from harfbuzz/language-tags
Add tests for 3-letter and private language tags
2 parents c58274c + 9a15aff commit eee3c3e

File tree

3 files changed

+72
-28
lines changed

3 files changed

+72
-28
lines changed

harfbuzz

Submodule harfbuzz updated 358 files
144 KB
Binary file not shown.

test/index.js

+71-27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs');
22
const path = require('path');
3-
const {expect} = require('chai');
3+
const { expect } = require('chai');
44
let hb;
55

66
before(async function () {
@@ -36,8 +36,8 @@ describe('Face', function () {
3636
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSansArabic-Variable.ttf')));
3737
this.face = hb.createFace(this.blob);
3838
expect(this.face.getAxisInfos()).to.deep.equal({
39-
wght: {min: 100, default: 400, max: 900},
40-
wdth: {min: 62.5, default: 100, max: 100}
39+
wght: { min: 100, default: 400, max: 900 },
40+
wdth: { min: 62.5, default: 100, max: 100 }
4141
});
4242
});
4343

@@ -73,7 +73,7 @@ describe('Font', function () {
7373
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSansArabic-Variable.ttf')));
7474
this.face = hb.createFace(this.blob);
7575
this.font = hb.createFont(this.face);
76-
this.font.setVariations({'wght': 789});
76+
this.font.setVariations({ 'wght': 789 });
7777
this.buffer = hb.createBuffer();
7878
this.buffer.addText('آلو');
7979
this.buffer.guessSegmentProperties();
@@ -165,9 +165,9 @@ describe('shape', function () {
165165
this.buffer.guessSegmentProperties();
166166
hb.shape(this.font, this.buffer)
167167
const glyphs = this.buffer.json();
168-
expect(glyphs[0]).to.deep.equal({cl: 0, g: 68, ax: 561, ay: 0, dx: 0, dy: 0, flags: 0} /* a */);
169-
expect(glyphs[1]).to.deep.equal({cl: 1, g: 69, ax: 615, ay: 0, dx: 0, dy: 0, flags: 0} /* b */);
170-
expect(glyphs[2]).to.deep.equal({cl: 2, g: 70, ax: 480, ay: 0, dx: 0, dy: 0, flags: 0} /* c */);
168+
expect(glyphs[0]).to.deep.equal({ cl: 0, g: 68, ax: 561, ay: 0, dx: 0, dy: 0, flags: 0 } /* a */);
169+
expect(glyphs[1]).to.deep.equal({ cl: 1, g: 69, ax: 615, ay: 0, dx: 0, dy: 0, flags: 0 } /* b */);
170+
expect(glyphs[2]).to.deep.equal({ cl: 2, g: 70, ax: 480, ay: 0, dx: 0, dy: 0, flags: 0 } /* c */);
171171
});
172172

173173
it('shape Arabic string', function () {
@@ -179,10 +179,10 @@ describe('shape', function () {
179179
this.buffer.guessSegmentProperties();
180180
hb.shape(this.font, this.buffer)
181181
const glyphs = this.buffer.json();
182-
expect(glyphs[0]).to.deep.equal({cl: 3, g: 213, ax: 532, ay: 0, dx: 0, dy: 0, flags: 1} /* د */);
183-
expect(glyphs[1]).to.deep.equal({cl: 2, g: 529, ax: 637, ay: 0, dx: 0, dy: 0, flags: 1} /* ج */);
184-
expect(glyphs[2]).to.deep.equal({cl: 1, g: 101, ax: 269, ay: 0, dx: 0, dy: 0, flags: 0} /* ب */);
185-
expect(glyphs[3]).to.deep.equal({cl: 0, g: 50, ax: 235, ay: 0, dx: 0, dy: 0, flags: 0} /* أ */);
182+
expect(glyphs[0]).to.deep.equal({ cl: 3, g: 213, ax: 532, ay: 0, dx: 0, dy: 0, flags: 1 } /* د */);
183+
expect(glyphs[1]).to.deep.equal({ cl: 2, g: 529, ax: 637, ay: 0, dx: 0, dy: 0, flags: 1 } /* ج */);
184+
expect(glyphs[2]).to.deep.equal({ cl: 1, g: 101, ax: 269, ay: 0, dx: 0, dy: 0, flags: 0 } /* ب */);
185+
expect(glyphs[3]).to.deep.equal({ cl: 0, g: 50, ax: 235, ay: 0, dx: 0, dy: 0, flags: 0 } /* أ */);
186186
});
187187

188188
it('shape with tracing', function () {
@@ -198,18 +198,18 @@ describe('shape', function () {
198198
"m": "start table GSUB script tag 'latn'",
199199
"glyphs": true,
200200
"t": [
201-
{cl: 0, g: 68},
202-
{cl: 1, g: 69},
203-
{cl: 2, g: 70},
201+
{ cl: 0, g: 68 },
202+
{ cl: 1, g: 69 },
203+
{ cl: 2, g: 70 },
204204
],
205205
});
206206
expect(result[41]).to.deep.equal({
207207
"m": "end table GPOS script tag 'latn'",
208208
"glyphs": true,
209209
"t": [
210-
{cl: 0, g: 68, ax: 561, ay: 0, dx: 0, dy: 0},
211-
{cl: 1, g: 69, ax: 615, ay: 0, dx: 0, dy: 0},
212-
{cl: 2, g: 70, ax: 480, ay: 0, dx: 0, dy: 0},
210+
{ cl: 0, g: 68, ax: 561, ay: 0, dx: 0, dy: 0 },
211+
{ cl: 1, g: 69, ax: 615, ay: 0, dx: 0, dy: 0 },
212+
{ cl: 2, g: 70, ax: 480, ay: 0, dx: 0, dy: 0 },
213213
],
214214
});
215215
});
@@ -227,25 +227,69 @@ describe('shape', function () {
227227
"m": "start table GSUB script tag 'latn'",
228228
"glyphs": true,
229229
"t": [
230-
{cl: 0, g: 73},
231-
{cl: 1, g: 76},
232-
{cl: 2, g: 3},
233-
{cl: 3, g: 36},
234-
{cl: 4, g: 57},
230+
{ cl: 0, g: 73 },
231+
{ cl: 1, g: 76 },
232+
{ cl: 2, g: 3 },
233+
{ cl: 3, g: 36 },
234+
{ cl: 4, g: 57 },
235235
],
236236
});
237237
expect(result[28]).to.deep.equal({
238238
"m": "end table GPOS script tag 'latn'",
239239
"glyphs": true,
240240
"t": [
241-
{cl: 0, g: 73, ax: 344, ay: 0, dx: 0, dy: 0},
242-
{cl: 1, g: 76, ax: 258, ay: 0, dx: 0, dy: 0},
243-
{cl: 2, g: 3, ax: 260, ay: 0, dx: 0, dy: 0},
244-
{cl: 3, g: 36, ax: 639, ay: 0, dx: 0, dy: 0},
245-
{cl: 4, g: 57, ax: 600, ay: 0, dx: 0, dy: 0},
241+
{ cl: 0, g: 73, ax: 344, ay: 0, dx: 0, dy: 0 },
242+
{ cl: 1, g: 76, ax: 258, ay: 0, dx: 0, dy: 0 },
243+
{ cl: 2, g: 3, ax: 260, ay: 0, dx: 0, dy: 0 },
244+
{ cl: 3, g: 36, ax: 639, ay: 0, dx: 0, dy: 0 },
245+
{ cl: 4, g: 57, ax: 600, ay: 0, dx: 0, dy: 0 },
246246
],
247247
});
248248
});
249+
250+
it('shape with 3-letter languae tag', function () {
251+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSansDevanagari-Regular.otf')));
252+
this.face = hb.createFace(this.blob);
253+
this.font = hb.createFont(this.face);
254+
this.buffer = hb.createBuffer();
255+
this.buffer.addText('५ल');
256+
this.buffer.guessSegmentProperties();
257+
hb.shape(this.font, this.buffer)
258+
var glyphs = this.buffer.json();
259+
expect(glyphs).to.have.lengthOf(2);
260+
expect(glyphs[0].g).to.equal(118);
261+
262+
this.buffer = hb.createBuffer();
263+
this.buffer.addText('५ल');
264+
this.buffer.setLanguage('dty');
265+
this.buffer.guessSegmentProperties();
266+
hb.shape(this.font, this.buffer)
267+
var glyphs = this.buffer.json();
268+
expect(glyphs).to.have.lengthOf(2);
269+
expect(glyphs[0].g).to.equal(123);
270+
});
271+
272+
it('shape with OpenType language tag', function () {
273+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSansDevanagari-Regular.otf')));
274+
this.face = hb.createFace(this.blob);
275+
this.font = hb.createFont(this.face);
276+
this.buffer = hb.createBuffer();
277+
this.buffer.addText('५ल');
278+
this.buffer.guessSegmentProperties();
279+
hb.shape(this.font, this.buffer)
280+
var glyphs = this.buffer.json();
281+
expect(glyphs).to.have.lengthOf(2);
282+
expect(glyphs[0].g).to.equal(118);
283+
284+
this.buffer = hb.createBuffer();
285+
this.buffer.addText('५ल');
286+
this.buffer.setLanguage('x-hbot-4e455020'); // 'NEP '
287+
this.buffer.guessSegmentProperties();
288+
hb.shape(this.font, this.buffer)
289+
var glyphs = this.buffer.json();
290+
expect(glyphs).to.have.lengthOf(2);
291+
expect(glyphs[0].g).to.equal(123);
292+
});
249293
});
250294

251295
describe('misc', function () {

0 commit comments

Comments
 (0)