harfbuzzjs 0.3.2 → 0.3.4
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.
- package/README.md +3 -2
- package/config-override-subset.h +2 -0
- package/config-override.h +3 -0
- package/examples/hb-subset.example.node.js +2 -2
- package/examples/hbjs.example.html +1 -1
- package/examples/hbjs.example.node.js +2 -3
- package/examples/nohbjs.html +2 -1
- package/hb-subset.wasm +0 -0
- package/hb.wasm +0 -0
- package/hbjs.cc +10 -5
- package/hbjs.js +19 -10
- package/package.json +7 -3
- package/test/fonts/noto/NotoSans-Regular.ttf +0 -0
- package/test/fonts/noto/NotoSansArabic-Variable.ttf +0 -0
- package/test/fonts/noto/OFL.txt +93 -0
- package/test/index.js +185 -0
- package/examples/Mada.abjad.otf +0 -0
- package/examples/Roboto-Black.ttf +0 -0
- package/examples/Roboto.abc.ttf +0 -0
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ demo source is in [gh-pages](https://github.com/harfbuzz/harfbuzzjs/tree/gh-page
|
|
|
15
15
|
|
|
16
16
|
## Usage and testing
|
|
17
17
|
|
|
18
|
-
###
|
|
18
|
+
### TL;DR
|
|
19
19
|
|
|
20
20
|
```javascript
|
|
21
21
|
hb = require("hbjs.js")
|
|
@@ -30,7 +30,7 @@ WebAssembly.instantiateStreaming(fetch("hb.wasm")).then(function (result) {
|
|
|
30
30
|
buffer.addText('abc'); // Fill it with some stuff
|
|
31
31
|
buffer.guessSegmentProperties(); // Set script, language and direction
|
|
32
32
|
hb.shape(font, buffer); // Shape the text, determining glyph IDs and positions
|
|
33
|
-
var output =
|
|
33
|
+
var output = buffer.json();
|
|
34
34
|
|
|
35
35
|
// Enumerate the glyphs
|
|
36
36
|
var xCursor = 0;
|
|
@@ -53,6 +53,7 @@ WebAssembly.instantiateStreaming(fetch("hb.wasm")).then(function (result) {
|
|
|
53
53
|
font.destroy();
|
|
54
54
|
face.destroy();
|
|
55
55
|
blob.destroy();
|
|
56
|
+
})
|
|
56
57
|
})
|
|
57
58
|
```
|
|
58
59
|
|
package/config-override-subset.h
CHANGED
package/config-override.h
CHANGED
|
@@ -8,8 +8,8 @@ const SUBSET_TEXT = 'abc';
|
|
|
8
8
|
|
|
9
9
|
(async () => {
|
|
10
10
|
const { instance: { exports } } = await WebAssembly.instantiate(await readFile(join(__dirname, '../hb-subset.wasm')));
|
|
11
|
-
const fileName = '
|
|
12
|
-
const fontBlob = await readFile(join(__dirname, '/', fileName));
|
|
11
|
+
const fileName = 'NotoSans-Regular.ttf';
|
|
12
|
+
const fontBlob = await readFile(join(__dirname, '../test/fonts/noto', fileName));
|
|
13
13
|
|
|
14
14
|
const t = performance.now();
|
|
15
15
|
const heapu8 = new Uint8Array(exports.memory.buffer);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<script>
|
|
4
4
|
// instantiateStreaming isn't supported in Safari yet, see nohbjs.html
|
|
5
5
|
WebAssembly.instantiateStreaming(fetch("../hb.wasm")).then(function (result) {
|
|
6
|
-
fetch('
|
|
6
|
+
fetch('../test/fonts/noto/NotoSans-Regular.ttf').then(function (x) {
|
|
7
7
|
return x.arrayBuffer();
|
|
8
8
|
}).then(function (blob) {
|
|
9
9
|
document.body.innerText = JSON.stringify(example(hbjs(result.instance), new Uint8Array(blob)), undefined, 2);
|
|
@@ -3,7 +3,6 @@ var path = require('path');
|
|
|
3
3
|
var example = require('./hbjs.example.js');
|
|
4
4
|
|
|
5
5
|
require('../').then(function (hbjs) {
|
|
6
|
-
console.log(example(hbjs, new Uint8Array(fs.readFileSync(path.resolve(__dirname, '
|
|
7
|
-
console.log(example(hbjs, new Uint8Array(fs.readFileSync(path.resolve(__dirname, '
|
|
8
|
-
console.log(example(hbjs, new Uint8Array(fs.readFileSync(path.resolve(__dirname, 'Mada.abjad.otf'))), "أبجد"));
|
|
6
|
+
console.log(example(hbjs, new Uint8Array(fs.readFileSync(path.resolve(__dirname, '../test/fonts/noto/NotoSans-Regular.ttf')))));
|
|
7
|
+
console.log(example(hbjs, new Uint8Array(fs.readFileSync(path.resolve(__dirname, '../test/fonts/noto/NotoSansArabic-Variable.ttf'))), "أبجد"));
|
|
9
8
|
}, console.log);
|
package/examples/nohbjs.html
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
1
2
|
<script>
|
|
2
3
|
var utf8Encoder = new TextEncoder("utf8");
|
|
3
4
|
|
|
@@ -10,7 +11,7 @@ fetch("../hb.wasm").then(function (x) {
|
|
|
10
11
|
}).then(function (result) {
|
|
11
12
|
var exports = result.instance.exports;
|
|
12
13
|
|
|
13
|
-
fetch('
|
|
14
|
+
fetch('../test/fonts/noto/NotoSans-Regular.ttf').then(function (x) {
|
|
14
15
|
return x.arrayBuffer();
|
|
15
16
|
}).then(function (fontBlob) {
|
|
16
17
|
var heapu8 = new Uint8Array(exports.memory.buffer);
|
package/hb-subset.wasm
CHANGED
|
Binary file
|
package/hb.wasm
CHANGED
|
Binary file
|
package/hbjs.cc
CHANGED
|
@@ -138,7 +138,7 @@ hbjs_glyph_svg (hb_font_t *font, hb_codepoint_t glyph, char *buf, unsigned buf_s
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
user_data_t draw_data(buf, buf_size);
|
|
141
|
-
|
|
141
|
+
hb_font_draw_glyph (font, glyph, funcs, &draw_data);
|
|
142
142
|
if (draw_data.failure)
|
|
143
143
|
return -1;
|
|
144
144
|
|
|
@@ -153,9 +153,9 @@ static hb_bool_t do_trace (hb_buffer_t *buffer,
|
|
|
153
153
|
unsigned int consumed;
|
|
154
154
|
unsigned int num_glyphs = hb_buffer_get_length (buffer);
|
|
155
155
|
|
|
156
|
-
if (
|
|
156
|
+
if (strncmp(message, "start table GSUB", 16) == 0) {
|
|
157
157
|
user_data->current_phase = HB_SHAPE_GSUB_PHASE;
|
|
158
|
-
} else if (
|
|
158
|
+
} else if (strncmp(message, "start table GPOS", 16) == 0) {
|
|
159
159
|
user_data->current_phase = HB_SHAPE_GPOS_PHASE;
|
|
160
160
|
}
|
|
161
161
|
|
|
@@ -170,10 +170,10 @@ static hb_bool_t do_trace (hb_buffer_t *buffer,
|
|
|
170
170
|
if (user_data->stop_phase != HB_SHAPE_DONT_STOP) {
|
|
171
171
|
// Do we need to start stopping?
|
|
172
172
|
char buf[12];
|
|
173
|
-
snprintf (buf, 12, "%d", user_data->stop_at);
|
|
173
|
+
snprintf (buf, 12, "%d ", user_data->stop_at);
|
|
174
174
|
if ((user_data->current_phase == user_data->stop_phase) &&
|
|
175
175
|
(strncmp(message, "end lookup ", 11) == 0) &&
|
|
176
|
-
(
|
|
176
|
+
(strncmp(message + 11, buf, strlen(buf)) == 0)) {
|
|
177
177
|
user_data->stopping = true;
|
|
178
178
|
}
|
|
179
179
|
}
|
|
@@ -190,6 +190,11 @@ static hb_bool_t do_trace (hb_buffer_t *buffer,
|
|
|
190
190
|
HB_BUFFER_SERIALIZE_FORMAT_JSON,
|
|
191
191
|
HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES);
|
|
192
192
|
user_data->consumed += consumed;
|
|
193
|
+
if (hb_buffer_get_content_type(buffer) == HB_BUFFER_CONTENT_TYPE_GLYPHS) {
|
|
194
|
+
_user_data_printf (user_data, ", \"glyphs\": true");
|
|
195
|
+
} else {
|
|
196
|
+
_user_data_printf (user_data, ", \"glyphs\": false");
|
|
197
|
+
}
|
|
193
198
|
_user_data_printf (user_data, "},\n");
|
|
194
199
|
|
|
195
200
|
return 1;
|
package/hbjs.js
CHANGED
|
@@ -35,6 +35,7 @@ function hbjs(instance) {
|
|
|
35
35
|
if (s == "PRESERVE_DEFAULT_IGNORABLES") { return 0x4; }
|
|
36
36
|
if (s == "REMOVE_DEFAULT_IGNORABLES") { return 0x8; }
|
|
37
37
|
if (s == "DO_NOT_INSERT_DOTTED_CIRCLE") { return 0x10; }
|
|
38
|
+
if (s == "PRODUCE_UNSAFE_TO_CONCAT") { return 0x40; }
|
|
38
39
|
return 0x0;
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -142,7 +143,7 @@ function hbjs(instance) {
|
|
|
142
143
|
var unicodeSetPtr = exports.hb_set_create();
|
|
143
144
|
exports.hb_face_collect_unicodes(ptr, unicodeSetPtr);
|
|
144
145
|
var result = typedArrayFromSet(unicodeSetPtr, Uint32Array);
|
|
145
|
-
exports.hb_set_destroy(
|
|
146
|
+
exports.hb_set_destroy(unicodeSetPtr);
|
|
146
147
|
return result;
|
|
147
148
|
},
|
|
148
149
|
/**
|
|
@@ -237,14 +238,21 @@ function hbjs(instance) {
|
|
|
237
238
|
};
|
|
238
239
|
}
|
|
239
240
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Use when you know the input range should be ASCII.
|
|
243
|
+
* Faster than encoding to UTF-8
|
|
244
|
+
**/
|
|
245
|
+
function createAsciiString(text) {
|
|
246
|
+
var ptr = exports.malloc(text.length + 1);
|
|
247
|
+
for (let i = 0; i < text.length; ++i) {
|
|
248
|
+
const char = text.charCodeAt(i);
|
|
249
|
+
if (char > 127) throw new Error('Expected ASCII text');
|
|
250
|
+
heapu8[ptr + i] = char;
|
|
251
|
+
}
|
|
252
|
+
heapu8[ptr + text.length] = 0;
|
|
245
253
|
return {
|
|
246
254
|
ptr: ptr,
|
|
247
|
-
length:
|
|
255
|
+
length: text.length,
|
|
248
256
|
free: function () { exports.free(ptr); }
|
|
249
257
|
};
|
|
250
258
|
}
|
|
@@ -304,6 +312,7 @@ function hbjs(instance) {
|
|
|
304
312
|
* "PRESERVE_DEFAULT_IGNORABLES"
|
|
305
313
|
* "REMOVE_DEFAULT_IGNORABLES"
|
|
306
314
|
* "DO_NOT_INSERT_DOTTED_CIRCLE"
|
|
315
|
+
* "PRODUCE_UNSAFE_TO_CONCAT"
|
|
307
316
|
*/
|
|
308
317
|
setFlags: function (flags) {
|
|
309
318
|
var flagValue = 0
|
|
@@ -318,7 +327,7 @@ function hbjs(instance) {
|
|
|
318
327
|
* @param {string} language: The buffer language
|
|
319
328
|
*/
|
|
320
329
|
setLanguage: function (language) {
|
|
321
|
-
var str =
|
|
330
|
+
var str = createAsciiString(language);
|
|
322
331
|
exports.hb_buffer_set_language(ptr, exports.hb_language_from_string(str.ptr,-1));
|
|
323
332
|
str.free();
|
|
324
333
|
},
|
|
@@ -327,7 +336,7 @@ function hbjs(instance) {
|
|
|
327
336
|
* @param {string} script: The buffer script
|
|
328
337
|
*/
|
|
329
338
|
setScript: function (script) {
|
|
330
|
-
var str =
|
|
339
|
+
var str = createAsciiString(script);
|
|
331
340
|
exports.hb_buffer_set_script(ptr, exports.hb_script_from_string(str.ptr,-1));
|
|
332
341
|
str.free();
|
|
333
342
|
},
|
|
@@ -419,7 +428,7 @@ function hbjs(instance) {
|
|
|
419
428
|
function shapeWithTrace(font, buffer, features, stop_at, stop_phase) {
|
|
420
429
|
var bufLen = 1024 * 1024;
|
|
421
430
|
var traceBuffer = exports.malloc(bufLen);
|
|
422
|
-
var featurestr =
|
|
431
|
+
var featurestr = createAsciiString(features);
|
|
423
432
|
var traceLen = exports.hbjs_shape_with_trace(font.ptr, buffer.ptr, featurestr.ptr, stop_at, stop_phase, traceBuffer, bufLen);
|
|
424
433
|
featurestr.free();
|
|
425
434
|
var trace = utf8Decoder.decode(heapu8.subarray(traceBuffer, traceBuffer + traceLen - 1));
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "harfbuzzjs",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Minimal version of HarfBuzz for JavaScript use",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
7
|
+
"test": "mocha test/index.js"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"harfbuzz",
|
|
@@ -29,5 +29,9 @@
|
|
|
29
29
|
"bugs": {
|
|
30
30
|
"url": "https://github.com/harfbuzz/harfbuzzjs/issues"
|
|
31
31
|
},
|
|
32
|
-
"homepage": "https://github.com/harfbuzz/harfbuzzjs#readme"
|
|
32
|
+
"homepage": "https://github.com/harfbuzz/harfbuzzjs#readme",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"chai": "^4.3.7",
|
|
35
|
+
"mocha": "^10.2.0"
|
|
36
|
+
}
|
|
33
37
|
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2015-2021 Google LLC. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
package/test/index.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const {expect} = require('chai');
|
|
4
|
+
let hb;
|
|
5
|
+
|
|
6
|
+
before(async function () {
|
|
7
|
+
hb = await require('..');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
afterEach(function () {
|
|
11
|
+
if (this.blob) this.blob.destroy();
|
|
12
|
+
if (this.face) this.face.destroy();
|
|
13
|
+
if (this.font) this.font.destroy();
|
|
14
|
+
if (this.buffer) this.buffer.destroy();
|
|
15
|
+
this.blob = this.face = this.font = this.buffer = null;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('Face', function () {
|
|
19
|
+
it('collectUnicodes reflects codepoints supported by the font', function () {
|
|
20
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
|
|
21
|
+
this.face = hb.createFace(this.blob);
|
|
22
|
+
const codepoints = [...this.face.collectUnicodes()];
|
|
23
|
+
expect(codepoints).to.include('a'.codePointAt(0));
|
|
24
|
+
expect(codepoints).not.to.include('ا'.codePointAt(0));
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('exposes upem', function () {
|
|
28
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
|
|
29
|
+
this.face = hb.createFace(this.blob);
|
|
30
|
+
expect(this.face.upem).to.equal(1000);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('getAxisInfos returns details of a variable font', function () {
|
|
34
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSansArabic-Variable.ttf')));
|
|
35
|
+
this.face = hb.createFace(this.blob);
|
|
36
|
+
expect(this.face.getAxisInfos()).to.deep.equal({
|
|
37
|
+
wght: {min: 100, default: 400, max: 900},
|
|
38
|
+
wdth: {min: 62.5, default: 100, max: 100}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('getAxisInfos returns an empty object for a non-variable font', function () {
|
|
43
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
|
|
44
|
+
this.face = hb.createFace(this.blob);
|
|
45
|
+
expect(Object.keys(this.face.getAxisInfos())).to.have.lengthOf(0);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('Font', function () {
|
|
50
|
+
it('glyphName returns names for glyph ids', function () {
|
|
51
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
|
|
52
|
+
this.face = hb.createFace(this.blob);
|
|
53
|
+
this.font = hb.createFont(this.face);
|
|
54
|
+
expect(this.font.glyphName(20)).to.equal('one');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('setScale affects advances', function () {
|
|
58
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
|
|
59
|
+
this.face = hb.createFace(this.blob);
|
|
60
|
+
this.font = hb.createFont(this.face);
|
|
61
|
+
this.buffer = hb.createBuffer();
|
|
62
|
+
this.buffer.addText('a');
|
|
63
|
+
this.buffer.guessSegmentProperties();
|
|
64
|
+
this.font.setScale(1000 * 2, 1000 * 2);
|
|
65
|
+
hb.shape(this.font, this.buffer)
|
|
66
|
+
const glyphs = this.buffer.json();
|
|
67
|
+
expect(glyphs[0].ax).to.equal(561 * 2);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('setVariations affects advances', function () {
|
|
71
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSansArabic-Variable.ttf')));
|
|
72
|
+
this.face = hb.createFace(this.blob);
|
|
73
|
+
this.font = hb.createFont(this.face);
|
|
74
|
+
this.font.setVariations({'wght': 789});
|
|
75
|
+
this.buffer = hb.createBuffer();
|
|
76
|
+
this.buffer.addText('آلو');
|
|
77
|
+
this.buffer.guessSegmentProperties();
|
|
78
|
+
hb.shape(this.font, this.buffer)
|
|
79
|
+
const glyphs = this.buffer.json();
|
|
80
|
+
expect(glyphs[0].ax).to.equal(526);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('Buffer', function () {
|
|
85
|
+
it('setDirection controls direction of glyphs', function () {
|
|
86
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
|
|
87
|
+
this.face = hb.createFace(this.blob);
|
|
88
|
+
this.font = hb.createFont(this.face);
|
|
89
|
+
this.buffer = hb.createBuffer();
|
|
90
|
+
this.buffer.addText('rtl');
|
|
91
|
+
this.buffer.setDirection('rtl');
|
|
92
|
+
hb.shape(this.font, this.buffer)
|
|
93
|
+
const glyphs = this.buffer.json();
|
|
94
|
+
expect(glyphs[0].g).to.equal(79); // l
|
|
95
|
+
expect(glyphs[1].g).to.equal(87); // t
|
|
96
|
+
expect(glyphs[2].g).to.equal(85); // r
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('setClusterLevel affects cluster merging', function () {
|
|
100
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
|
|
101
|
+
this.face = hb.createFace(this.blob);
|
|
102
|
+
this.font = hb.createFont(this.face);
|
|
103
|
+
this.buffer = hb.createBuffer();
|
|
104
|
+
this.buffer.setClusterLevel(1);
|
|
105
|
+
this.buffer.addText('x́');
|
|
106
|
+
this.buffer.guessSegmentProperties();
|
|
107
|
+
hb.shape(this.font, this.buffer)
|
|
108
|
+
const glyphs = this.buffer.json();
|
|
109
|
+
expect(glyphs[0].cl).to.equal(0);
|
|
110
|
+
expect(glyphs[1].cl).to.equal(1);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('setFlags with PRESERVE_DEFAULT_IGNORABLES affects glyph ids', function () {
|
|
114
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
|
|
115
|
+
this.face = hb.createFace(this.blob);
|
|
116
|
+
this.font = hb.createFont(this.face);
|
|
117
|
+
this.buffer = hb.createBuffer();
|
|
118
|
+
this.buffer.addText('\u200dhi');
|
|
119
|
+
this.buffer.setFlags(['PRESERVE_DEFAULT_IGNORABLES']);
|
|
120
|
+
this.buffer.guessSegmentProperties();
|
|
121
|
+
hb.shape(this.font, this.buffer)
|
|
122
|
+
const glyphs = this.buffer.json();
|
|
123
|
+
expect(glyphs[0].g).not.to.equal(3 /* space */);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('shape', function () {
|
|
128
|
+
it('shape Latin string', function () {
|
|
129
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
|
|
130
|
+
this.face = hb.createFace(this.blob);
|
|
131
|
+
this.font = hb.createFont(this.face);
|
|
132
|
+
this.buffer = hb.createBuffer();
|
|
133
|
+
this.buffer.addText('abc');
|
|
134
|
+
this.buffer.guessSegmentProperties();
|
|
135
|
+
hb.shape(this.font, this.buffer)
|
|
136
|
+
const glyphs = this.buffer.json();
|
|
137
|
+
expect(glyphs[0]).to.deep.equal({cl: 0, g: 68, ax: 561, ay: 0, dx: 0, dy: 0, flags: 0} /* a */);
|
|
138
|
+
expect(glyphs[1]).to.deep.equal({cl: 1, g: 69, ax: 615, ay: 0, dx: 0, dy: 0, flags: 0} /* b */);
|
|
139
|
+
expect(glyphs[2]).to.deep.equal({cl: 2, g: 70, ax: 480, ay: 0, dx: 0, dy: 0, flags: 0} /* c */);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('shape Arabic string', function () {
|
|
143
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSansArabic-Variable.ttf')));
|
|
144
|
+
this.face = hb.createFace(this.blob);
|
|
145
|
+
this.font = hb.createFont(this.face);
|
|
146
|
+
this.buffer = hb.createBuffer();
|
|
147
|
+
this.buffer.addText('أبجد');
|
|
148
|
+
this.buffer.guessSegmentProperties();
|
|
149
|
+
hb.shape(this.font, this.buffer)
|
|
150
|
+
const glyphs = this.buffer.json();
|
|
151
|
+
expect(glyphs[0]).to.deep.equal({cl: 3, g: 213, ax: 532, ay: 0, dx: 0, dy: 0, flags: 1} /* د */);
|
|
152
|
+
expect(glyphs[1]).to.deep.equal({cl: 2, g: 529, ax: 637, ay: 0, dx: 0, dy: 0, flags: 1} /* ج */);
|
|
153
|
+
expect(glyphs[2]).to.deep.equal({cl: 1, g: 101, ax: 269, ay: 0, dx: 0, dy: 0, flags: 0} /* ب */);
|
|
154
|
+
expect(glyphs[3]).to.deep.equal({cl: 0, g: 50, ax: 235, ay: 0, dx: 0, dy: 0, flags: 0} /* أ */);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('shape with tracing', function () {
|
|
158
|
+
this.blob = hb.createBlob(fs.readFileSync(path.join(__dirname, 'fonts/noto/NotoSans-Regular.ttf')));
|
|
159
|
+
this.face = hb.createFace(this.blob);
|
|
160
|
+
this.font = hb.createFont(this.face);
|
|
161
|
+
this.buffer = hb.createBuffer();
|
|
162
|
+
this.buffer.addText('abc');
|
|
163
|
+
this.buffer.guessSegmentProperties();
|
|
164
|
+
const result = hb.shapeWithTrace(this.font, this.buffer, 0, 0)
|
|
165
|
+
expect(result).to.have.lengthOf(42);
|
|
166
|
+
expect(result[0]).to.deep.equal({
|
|
167
|
+
"m": "start table GSUB script tag 'latn'",
|
|
168
|
+
"glyphs": true,
|
|
169
|
+
"t": [
|
|
170
|
+
{cl: 0, g: 68},
|
|
171
|
+
{cl: 1, g: 69},
|
|
172
|
+
{cl: 2, g: 70},
|
|
173
|
+
],
|
|
174
|
+
});
|
|
175
|
+
expect(result[41]).to.deep.equal({
|
|
176
|
+
"m": "end table GPOS script tag 'latn'",
|
|
177
|
+
"glyphs": true,
|
|
178
|
+
"t": [
|
|
179
|
+
{cl: 0, g: 68, ax: 561, ay: 0, dx: 0, dy: 0},
|
|
180
|
+
{cl: 1, g: 69, ax: 615, ay: 0, dx: 0, dy: 0},
|
|
181
|
+
{cl: 2, g: 70, ax: 480, ay: 0, dx: 0, dy: 0},
|
|
182
|
+
],
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
});
|
package/examples/Mada.abjad.otf
DELETED
|
Binary file
|
|
Binary file
|
package/examples/Roboto.abc.ttf
DELETED
|
Binary file
|