@mlightcad/mtext-renderer 0.6.4 → 0.6.5
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/dist/index.js +60 -47
- package/dist/index.umd.cjs +3 -3
- package/dist/mtext-renderer-worker.js +113 -100
- package/lib/font/defaultFontLoader.d.ts +1 -1
- package/lib/font/fontLoader.d.ts +8 -3
- package/package.json +8 -3
package/dist/index.js
CHANGED
|
@@ -135,7 +135,7 @@ function Oa(t) {
|
|
|
135
135
|
const a = () => {
|
|
136
136
|
t.removeEventListener("success", s), t.removeEventListener("error", i);
|
|
137
137
|
}, s = () => {
|
|
138
|
-
r(
|
|
138
|
+
r(Me(t.result)), a();
|
|
139
139
|
}, i = () => {
|
|
140
140
|
n(t.error), a();
|
|
141
141
|
};
|
|
@@ -166,7 +166,7 @@ let Vt = {
|
|
|
166
166
|
if (e === "store")
|
|
167
167
|
return r.objectStoreNames[1] ? void 0 : r.objectStore(r.objectStoreNames[0]);
|
|
168
168
|
}
|
|
169
|
-
return
|
|
169
|
+
return Me(t[e]);
|
|
170
170
|
},
|
|
171
171
|
set(t, e, r) {
|
|
172
172
|
return t[e] = r, !0;
|
|
@@ -180,15 +180,15 @@ function Tn(t) {
|
|
|
180
180
|
}
|
|
181
181
|
function Ua(t) {
|
|
182
182
|
return Ea().includes(t) ? function(...e) {
|
|
183
|
-
return t.apply(qt(this), e),
|
|
183
|
+
return t.apply(qt(this), e), Me(this.request);
|
|
184
184
|
} : function(...e) {
|
|
185
|
-
return
|
|
185
|
+
return Me(t.apply(qt(this), e));
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
188
|
function Ra(t) {
|
|
189
189
|
return typeof t == "function" ? Ua(t) : (t instanceof IDBTransaction && La(t), zt(t, Ca()) ? new Proxy(t, Vt) : t);
|
|
190
190
|
}
|
|
191
|
-
function
|
|
191
|
+
function Me(t) {
|
|
192
192
|
if (t instanceof IDBRequest)
|
|
193
193
|
return Oa(t);
|
|
194
194
|
if (Tt.has(t))
|
|
@@ -198,9 +198,9 @@ function Ae(t) {
|
|
|
198
198
|
}
|
|
199
199
|
const qt = (t) => xt.get(t);
|
|
200
200
|
function Aa(t, e, { blocked: r, upgrade: n, blocking: a, terminated: s } = {}) {
|
|
201
|
-
const i = indexedDB.open(t, e), o =
|
|
201
|
+
const i = indexedDB.open(t, e), o = Me(i);
|
|
202
202
|
return n && i.addEventListener("upgradeneeded", (u) => {
|
|
203
|
-
n(
|
|
203
|
+
n(Me(i.result), u.oldVersion, u.newVersion, Me(i.transaction), u);
|
|
204
204
|
}), r && i.addEventListener("blocked", (u) => r(
|
|
205
205
|
// Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
|
|
206
206
|
u.oldVersion,
|
|
@@ -269,14 +269,23 @@ Tn((t) => ({
|
|
|
269
269
|
return wr(e, r) || t.has(e, r);
|
|
270
270
|
}
|
|
271
271
|
}));
|
|
272
|
-
const
|
|
272
|
+
const Ue = {
|
|
273
273
|
fonts: "fonts"
|
|
274
274
|
}, Ct = [
|
|
275
275
|
{
|
|
276
276
|
version: 1,
|
|
277
277
|
stores: [
|
|
278
278
|
{
|
|
279
|
-
name:
|
|
279
|
+
name: Ue.fonts,
|
|
280
|
+
keyPath: "name"
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
version: 1,
|
|
286
|
+
stores: [
|
|
287
|
+
{
|
|
288
|
+
name: Ue.fonts,
|
|
280
289
|
keyPath: "name"
|
|
281
290
|
}
|
|
282
291
|
]
|
|
@@ -299,7 +308,7 @@ const Pe = {
|
|
|
299
308
|
* @param fontData The font data to store
|
|
300
309
|
*/
|
|
301
310
|
async set(e, r) {
|
|
302
|
-
await (await this.getDatabase()).put(
|
|
311
|
+
await (await this.getDatabase()).put(Ue.fonts, { ...r, name: e });
|
|
303
312
|
}
|
|
304
313
|
/**
|
|
305
314
|
* Gets a font from the cache
|
|
@@ -307,27 +316,27 @@ const Pe = {
|
|
|
307
316
|
* @returns The font data if found, undefined otherwise
|
|
308
317
|
*/
|
|
309
318
|
async get(e) {
|
|
310
|
-
return await (await this.getDatabase()).get(
|
|
319
|
+
return await (await this.getDatabase()).get(Ue.fonts, e);
|
|
311
320
|
}
|
|
312
321
|
/**
|
|
313
322
|
* Deletes a font from the cache
|
|
314
323
|
* @param fileName The font file name (key)
|
|
315
324
|
*/
|
|
316
325
|
async delete(e) {
|
|
317
|
-
await (await this.getDatabase()).delete(
|
|
326
|
+
await (await this.getDatabase()).delete(Ue.fonts, e);
|
|
318
327
|
}
|
|
319
328
|
/**
|
|
320
329
|
* Gets all fonts from the cache
|
|
321
330
|
* @returns An array of all font data in the cache
|
|
322
331
|
*/
|
|
323
332
|
async getAll() {
|
|
324
|
-
return await (await this.getDatabase()).getAll(
|
|
333
|
+
return await (await this.getDatabase()).getAll(Ue.fonts);
|
|
325
334
|
}
|
|
326
335
|
/**
|
|
327
336
|
* Clears all fonts from the cache
|
|
328
337
|
*/
|
|
329
338
|
async clear() {
|
|
330
|
-
await (await this.getDatabase()).clear(
|
|
339
|
+
await (await this.getDatabase()).clear(Ue.fonts);
|
|
331
340
|
}
|
|
332
341
|
/**
|
|
333
342
|
* Checks if a font exists in the cache
|
|
@@ -918,7 +927,7 @@ An(Un, Rn, 2, 1);
|
|
|
918
927
|
sr[28] = 0;
|
|
919
928
|
ir[28] = 258;
|
|
920
929
|
var Qa = Ka;
|
|
921
|
-
function
|
|
930
|
+
function Pe(t, e, r, n, a) {
|
|
922
931
|
return Math.pow(1 - a, 3) * t + 3 * Math.pow(1 - a, 2) * a * e + 3 * (1 - a) * Math.pow(a, 2) * r + Math.pow(a, 3) * n;
|
|
923
932
|
}
|
|
924
933
|
function Ce() {
|
|
@@ -945,15 +954,15 @@ Ce.prototype.addBezier = function(t, e, r, n, a, s, i, o) {
|
|
|
945
954
|
if (p === 0)
|
|
946
955
|
continue;
|
|
947
956
|
var y = -v / p;
|
|
948
|
-
0 < y && y < 1 && (c === 0 && this.addX(
|
|
957
|
+
0 < y && y < 1 && (c === 0 && this.addX(Pe(u[c], h[c], l[c], f[c], y)), c === 1 && this.addY(Pe(u[c], h[c], l[c], f[c], y)));
|
|
949
958
|
continue;
|
|
950
959
|
}
|
|
951
960
|
var m = Math.pow(p, 2) - 4 * v * d;
|
|
952
961
|
if (!(m < 0)) {
|
|
953
962
|
var b = (-p + Math.sqrt(m)) / (2 * d);
|
|
954
|
-
0 < b && b < 1 && (c === 0 && this.addX(
|
|
963
|
+
0 < b && b < 1 && (c === 0 && this.addX(Pe(u[c], h[c], l[c], f[c], b)), c === 1 && this.addY(Pe(u[c], h[c], l[c], f[c], b)));
|
|
955
964
|
var x = (-p - Math.sqrt(m)) / (2 * d);
|
|
956
|
-
0 < x && x < 1 && (c === 0 && this.addX(
|
|
965
|
+
0 < x && x < 1 && (c === 0 && this.addX(Pe(u[c], h[c], l[c], f[c], x)), c === 1 && this.addY(Pe(u[c], h[c], l[c], f[c], x)));
|
|
957
966
|
}
|
|
958
967
|
}
|
|
959
968
|
};
|
|
@@ -2934,7 +2943,7 @@ var Pn = { parse: ls, make: ps }, lt = [
|
|
|
2934
2943
|
"Yacutesmall",
|
|
2935
2944
|
"Thornsmall",
|
|
2936
2945
|
"Ydieresissmall"
|
|
2937
|
-
],
|
|
2946
|
+
], Re = [
|
|
2938
2947
|
".notdef",
|
|
2939
2948
|
".null",
|
|
2940
2949
|
"nonmarkingreturn",
|
|
@@ -3223,17 +3232,17 @@ yt.prototype.charToGlyphIndex = function(t) {
|
|
|
3223
3232
|
function ur(t) {
|
|
3224
3233
|
switch (t.version) {
|
|
3225
3234
|
case 1:
|
|
3226
|
-
this.names =
|
|
3235
|
+
this.names = Re.slice();
|
|
3227
3236
|
break;
|
|
3228
3237
|
case 2:
|
|
3229
3238
|
this.names = new Array(t.numberOfGlyphs);
|
|
3230
3239
|
for (var e = 0; e < t.numberOfGlyphs; e++)
|
|
3231
|
-
t.glyphNameIndex[e] <
|
|
3240
|
+
t.glyphNameIndex[e] < Re.length ? this.names[e] = Re[t.glyphNameIndex[e]] : this.names[e] = t.names[t.glyphNameIndex[e] - Re.length];
|
|
3232
3241
|
break;
|
|
3233
3242
|
case 2.5:
|
|
3234
3243
|
this.names = new Array(t.numberOfGlyphs);
|
|
3235
3244
|
for (var r = 0; r < t.numberOfGlyphs; r++)
|
|
3236
|
-
this.names[r] =
|
|
3245
|
+
this.names[r] = Re[r + t.glyphNameIndex[r]];
|
|
3237
3246
|
break;
|
|
3238
3247
|
case 3:
|
|
3239
3248
|
this.names = [];
|
|
@@ -5242,7 +5251,7 @@ function fi(t, e) {
|
|
|
5242
5251
|
var r = {}, n = new E.Parser(t, e);
|
|
5243
5252
|
switch (r.version = n.parseVersion(), r.italicAngle = n.parseFixed(), r.underlinePosition = n.parseShort(), r.underlineThickness = n.parseShort(), r.isFixedPitch = n.parseULong(), r.minMemType42 = n.parseULong(), r.maxMemType42 = n.parseULong(), r.minMemType1 = n.parseULong(), r.maxMemType1 = n.parseULong(), r.version) {
|
|
5244
5253
|
case 1:
|
|
5245
|
-
r.names =
|
|
5254
|
+
r.names = Re.slice();
|
|
5246
5255
|
break;
|
|
5247
5256
|
case 2:
|
|
5248
5257
|
r.numberOfGlyphs = n.parseUShort(), r.glyphNameIndex = new Array(r.numberOfGlyphs);
|
|
@@ -5250,7 +5259,7 @@ function fi(t, e) {
|
|
|
5250
5259
|
r.glyphNameIndex[a] = n.parseUShort();
|
|
5251
5260
|
r.names = [];
|
|
5252
5261
|
for (var s = 0; s < r.numberOfGlyphs; s++)
|
|
5253
|
-
if (r.glyphNameIndex[s] >=
|
|
5262
|
+
if (r.glyphNameIndex[s] >= Re.length) {
|
|
5254
5263
|
var i = n.parseChar();
|
|
5255
5264
|
r.names.push(n.parseString(i));
|
|
5256
5265
|
}
|
|
@@ -6311,7 +6320,7 @@ function Ci(t, e, r, n) {
|
|
|
6311
6320
|
function Ei(t, e, r, n, a) {
|
|
6312
6321
|
return a.lowMemory ? Ci(t, e, r, n) : wi(t, e, r, n);
|
|
6313
6322
|
}
|
|
6314
|
-
var la = { getPath: ua, parse: Ei }, ca,
|
|
6323
|
+
var la = { getPath: ua, parse: Ei }, ca, Be, fa, tr;
|
|
6315
6324
|
function pa(t) {
|
|
6316
6325
|
this.font = t, this.getCommands = function(e) {
|
|
6317
6326
|
return la.getPath(e).commands;
|
|
@@ -6537,7 +6546,7 @@ pa.prototype.exec = function(t, e) {
|
|
|
6537
6546
|
if (!a) {
|
|
6538
6547
|
ke.prototype = Mi, a = this._fpgmState = new ke("fpgm", r.tables.fpgm), a.funcs = [], a.font = r, exports.DEBUG && (console.log("---EXEC FPGM---"), a.step = -1);
|
|
6539
6548
|
try {
|
|
6540
|
-
|
|
6549
|
+
Be(a);
|
|
6541
6550
|
} catch (h) {
|
|
6542
6551
|
console.log("Hinting error in FPGM:" + h), this._errorState = 3;
|
|
6543
6552
|
return;
|
|
@@ -6552,7 +6561,7 @@ pa.prototype.exec = function(t, e) {
|
|
|
6552
6561
|
n.cvt = [];
|
|
6553
6562
|
exports.DEBUG && (console.log("---EXEC PREP---"), n.step = -1);
|
|
6554
6563
|
try {
|
|
6555
|
-
|
|
6564
|
+
Be(n);
|
|
6556
6565
|
} catch (h) {
|
|
6557
6566
|
this._errorState < 2 && console.log("Hinting error in PREP:" + h), this._errorState = 2;
|
|
6558
6567
|
}
|
|
@@ -6588,7 +6597,7 @@ fa = function(t, e) {
|
|
|
6588
6597
|
t.instructions && !o.inhibitGridFit && (o = new ke("glyf", t.instructions), o.gZone = o.z0 = o.z1 = o.z2 = i, o.contours = s, i.push(
|
|
6589
6598
|
new me(0, 0),
|
|
6590
6599
|
new me(Math.round(t.advanceWidth * r), 0)
|
|
6591
|
-
), exports.DEBUG && (console.log("---EXEC COMPOSITE---"), o.step = -1),
|
|
6600
|
+
), exports.DEBUG && (console.log("---EXEC COMPOSITE---"), o.step = -1), Be(o), i.length -= 2);
|
|
6592
6601
|
}
|
|
6593
6602
|
return i;
|
|
6594
6603
|
};
|
|
@@ -6611,14 +6620,14 @@ tr = function(t, e, r, n) {
|
|
|
6611
6620
|
if (i.push(
|
|
6612
6621
|
new me(0, 0),
|
|
6613
6622
|
new me(Math.round(t.advanceWidth * r), 0)
|
|
6614
|
-
),
|
|
6623
|
+
), Be(e), i.length -= 2, exports.DEBUG) {
|
|
6615
6624
|
console.log("FINISHED GLYPH", e.stack);
|
|
6616
6625
|
for (var d = 0; d < s; d++)
|
|
6617
6626
|
console.log(d, i[d].x, i[d].y);
|
|
6618
6627
|
}
|
|
6619
6628
|
}
|
|
6620
6629
|
};
|
|
6621
|
-
|
|
6630
|
+
Be = function(t) {
|
|
6622
6631
|
var e = t.prog;
|
|
6623
6632
|
if (e) {
|
|
6624
6633
|
var r = e.length, n;
|
|
@@ -6810,7 +6819,7 @@ function ao(t) {
|
|
|
6810
6819
|
var a = t.ip, s = t.prog;
|
|
6811
6820
|
t.prog = t.funcs[r];
|
|
6812
6821
|
for (var i = 0; i < n; i++)
|
|
6813
|
-
|
|
6822
|
+
Be(t), exports.DEBUG && console.log(
|
|
6814
6823
|
++t.step,
|
|
6815
6824
|
i + 1 < n ? "next loopcall" : "done loopcall",
|
|
6816
6825
|
i
|
|
@@ -6821,7 +6830,7 @@ function so(t) {
|
|
|
6821
6830
|
var e = t.stack.pop();
|
|
6822
6831
|
exports.DEBUG && console.log(t.step, "CALL[]", e);
|
|
6823
6832
|
var r = t.ip, n = t.prog;
|
|
6824
|
-
t.prog = t.funcs[e],
|
|
6833
|
+
t.prog = t.funcs[e], Be(t), t.ip = r, t.prog = n, exports.DEBUG && console.log(++t.step, "returning from", e);
|
|
6825
6834
|
}
|
|
6826
6835
|
function io(t) {
|
|
6827
6836
|
var e = t.stack, r = e.pop();
|
|
@@ -8078,7 +8087,7 @@ function iu(t) {
|
|
|
8078
8087
|
function ne(t) {
|
|
8079
8088
|
this.font = t, this.features = {};
|
|
8080
8089
|
}
|
|
8081
|
-
function
|
|
8090
|
+
function Ae(t) {
|
|
8082
8091
|
this.id = t.id, this.tag = t.tag, this.substitution = t.substitution;
|
|
8083
8092
|
}
|
|
8084
8093
|
function tt(t, e) {
|
|
@@ -8288,35 +8297,35 @@ ne.prototype.lookupFeature = function(t) {
|
|
|
8288
8297
|
var l = u[h], f = this.getSubstitutionType(o, l), c = this.getLookupMethod(o, l), p = void 0;
|
|
8289
8298
|
switch (f) {
|
|
8290
8299
|
case "11":
|
|
8291
|
-
p = c(e.current), p && s.splice(r, 1, new
|
|
8300
|
+
p = c(e.current), p && s.splice(r, 1, new Ae({
|
|
8292
8301
|
id: 11,
|
|
8293
8302
|
tag: t.tag,
|
|
8294
8303
|
substitution: p
|
|
8295
8304
|
}));
|
|
8296
8305
|
break;
|
|
8297
8306
|
case "12":
|
|
8298
|
-
p = c(e.current), p && s.splice(r, 1, new
|
|
8307
|
+
p = c(e.current), p && s.splice(r, 1, new Ae({
|
|
8299
8308
|
id: 12,
|
|
8300
8309
|
tag: t.tag,
|
|
8301
8310
|
substitution: p
|
|
8302
8311
|
}));
|
|
8303
8312
|
break;
|
|
8304
8313
|
case "63":
|
|
8305
|
-
p = c(e), Array.isArray(p) && p.length && s.splice(r, 1, new
|
|
8314
|
+
p = c(e), Array.isArray(p) && p.length && s.splice(r, 1, new Ae({
|
|
8306
8315
|
id: 63,
|
|
8307
8316
|
tag: t.tag,
|
|
8308
8317
|
substitution: p
|
|
8309
8318
|
}));
|
|
8310
8319
|
break;
|
|
8311
8320
|
case "41":
|
|
8312
|
-
p = c(e), p && s.splice(r, 1, new
|
|
8321
|
+
p = c(e), p && s.splice(r, 1, new Ae({
|
|
8313
8322
|
id: 41,
|
|
8314
8323
|
tag: t.tag,
|
|
8315
8324
|
substitution: p
|
|
8316
8325
|
}));
|
|
8317
8326
|
break;
|
|
8318
8327
|
case "21":
|
|
8319
|
-
p = c(e.current), p && s.splice(r, 1, new
|
|
8328
|
+
p = c(e.current), p && s.splice(r, 1, new Ae({
|
|
8320
8329
|
id: 21,
|
|
8321
8330
|
tag: t.tag,
|
|
8322
8331
|
substitution: p
|
|
@@ -8435,7 +8444,7 @@ var hn = {
|
|
|
8435
8444
|
41: Su
|
|
8436
8445
|
};
|
|
8437
8446
|
function pr(t, e, r) {
|
|
8438
|
-
t instanceof
|
|
8447
|
+
t instanceof Ae && hn[t.id] && hn[t.id](t, e, r);
|
|
8439
8448
|
}
|
|
8440
8449
|
function ku(t) {
|
|
8441
8450
|
for (var e = [].concat(t.backtrack), r = e.length - 1; r >= 0; r--) {
|
|
@@ -8501,7 +8510,7 @@ function Tu(t) {
|
|
|
8501
8510
|
if (f instanceof Error)
|
|
8502
8511
|
return console.info(f.message);
|
|
8503
8512
|
f.forEach(function(c, p) {
|
|
8504
|
-
c instanceof
|
|
8513
|
+
c instanceof Ae && (pr(c, a, p), s.context[p] = c.substitution);
|
|
8505
8514
|
});
|
|
8506
8515
|
}
|
|
8507
8516
|
}
|
|
@@ -11022,7 +11031,7 @@ class ge {
|
|
|
11022
11031
|
n.push({
|
|
11023
11032
|
fontName: h,
|
|
11024
11033
|
url: u,
|
|
11025
|
-
status: o
|
|
11034
|
+
status: o ? "Success" : "FailedToLoad"
|
|
11026
11035
|
}), o && this.fileNames.push(h);
|
|
11027
11036
|
});
|
|
11028
11037
|
}), n;
|
|
@@ -11228,8 +11237,10 @@ class mh {
|
|
|
11228
11237
|
try {
|
|
11229
11238
|
const r = await fetch(e);
|
|
11230
11239
|
this._avaiableFonts = await r.json();
|
|
11231
|
-
} catch {
|
|
11232
|
-
throw new Error(
|
|
11240
|
+
} catch (r) {
|
|
11241
|
+
throw new Error(
|
|
11242
|
+
`Filed to get avaiable font from '${e}' due to ${r}!`
|
|
11243
|
+
);
|
|
11233
11244
|
}
|
|
11234
11245
|
this._avaiableFonts.forEach((r) => {
|
|
11235
11246
|
r.url = this._baseUrl + r.file;
|
|
@@ -11245,7 +11256,9 @@ class mh {
|
|
|
11245
11256
|
* @returns Promise that resolves to an array of FontLoadStatus objects
|
|
11246
11257
|
*/
|
|
11247
11258
|
async load(e) {
|
|
11248
|
-
e
|
|
11259
|
+
if (e == null || e.length === 0)
|
|
11260
|
+
return [];
|
|
11261
|
+
await this.getAvaiableFonts();
|
|
11249
11262
|
const r = [], n = [], a = {};
|
|
11250
11263
|
this._avaiableFonts.forEach((o) => {
|
|
11251
11264
|
o.name.forEach((u) => {
|
|
@@ -11256,7 +11269,7 @@ class mh {
|
|
|
11256
11269
|
h && (ge.instance.isFontLoaded(u) ? n.push({
|
|
11257
11270
|
fontName: u,
|
|
11258
11271
|
url: h,
|
|
11259
|
-
status:
|
|
11272
|
+
status: "Success"
|
|
11260
11273
|
}) : r.push(h));
|
|
11261
11274
|
});
|
|
11262
11275
|
let s = [];
|
|
@@ -11268,8 +11281,8 @@ class mh {
|
|
|
11268
11281
|
const u = o.toLowerCase();
|
|
11269
11282
|
return i[u] || {
|
|
11270
11283
|
fontName: u,
|
|
11271
|
-
url:
|
|
11272
|
-
status:
|
|
11284
|
+
url: "",
|
|
11285
|
+
status: "NotFound"
|
|
11273
11286
|
};
|
|
11274
11287
|
});
|
|
11275
11288
|
}
|