msdfgen-ts 0.1.0 → 0.3.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.
- package/README.md +42 -6
- package/dist/atlas-worker.js +2727 -1307
- package/dist/msdfgen-ts.iife.js +3 -2
- package/dist/msdfgen-ts.js +3153 -1378
- package/dist/types/atlas-gen.d.ts +58 -28
- package/dist/types/font/font.d.ts +38 -3
- package/dist/types/font/glyph-run.d.ts +50 -0
- package/dist/types/font/script.d.ts +47 -0
- package/dist/types/font/shaper.d.ts +41 -0
- package/dist/types/font/tables/gdef.d.ts +25 -0
- package/dist/types/font/tables/glyf.d.ts +3 -1
- package/dist/types/font/tables/gpos.d.ts +85 -0
- package/dist/types/font/tables/kern.d.ts +31 -14
- package/dist/types/font/tables/otl.d.ts +27 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/msdf/shape-msdf.d.ts +51 -0
- package/dist/types/shape/normalize.d.ts +12 -1
- package/dist/types/shape/union.d.ts +58 -0
- package/dist/types/svg/svg.d.ts +78 -0
- package/package.json +40 -18
package/dist/atlas-worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class St {
|
|
2
2
|
/**
|
|
3
3
|
* @param buffer Source buffer (the full font file).
|
|
4
4
|
* @param byteOffset Starting position (default 0).
|
|
@@ -78,228 +78,228 @@ class Mt {
|
|
|
78
78
|
return this._view.getInt16(t, !1);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
function
|
|
82
|
-
const n = new
|
|
81
|
+
function Qi(s, t) {
|
|
82
|
+
const n = new St(s, t);
|
|
83
83
|
n.skip(2);
|
|
84
|
-
const
|
|
85
|
-
let
|
|
86
|
-
for (let
|
|
87
|
-
const c = n.u16(),
|
|
88
|
-
let
|
|
89
|
-
c === 3 &&
|
|
90
|
-
}
|
|
91
|
-
if (!
|
|
92
|
-
const
|
|
93
|
-
return
|
|
94
|
-
}
|
|
95
|
-
function
|
|
96
|
-
const n = new
|
|
84
|
+
const e = n.u16();
|
|
85
|
+
let i = null;
|
|
86
|
+
for (let r = 0; r < e; r++) {
|
|
87
|
+
const c = n.u16(), a = n.u16(), l = n.u32(), h = t + l, f = n.peekU16(h);
|
|
88
|
+
let u = -1;
|
|
89
|
+
c === 3 && a === 10 && f === 12 ? u = 5 : c === 0 && a === 6 && f === 12 ? u = 4 : c === 0 && a === 4 && f === 12 ? u = 3 : c === 3 && a === 1 && f === 4 ? u = 2 : c === 0 && a <= 3 && f === 4 && (u = 1), u > ((i == null ? void 0 : i.priority) ?? -1) && (i = { priority: u, subtableAbsOffset: h });
|
|
90
|
+
}
|
|
91
|
+
if (!i) return () => 0;
|
|
92
|
+
const o = n.peekU16(i.subtableAbsOffset);
|
|
93
|
+
return o === 12 ? to(s, i.subtableAbsOffset) : o === 4 ? no(s, i.subtableAbsOffset) : () => 0;
|
|
94
|
+
}
|
|
95
|
+
function to(s, t) {
|
|
96
|
+
const n = new St(s, t);
|
|
97
97
|
n.skip(2), n.skip(2), n.skip(4), n.skip(4);
|
|
98
|
-
const
|
|
99
|
-
for (let c = 0; c <
|
|
100
|
-
|
|
98
|
+
const e = n.u32(), i = new Uint32Array(e), o = new Uint32Array(e), r = new Uint32Array(e);
|
|
99
|
+
for (let c = 0; c < e; c++)
|
|
100
|
+
i[c] = n.u32(), o[c] = n.u32(), r[c] = n.u32();
|
|
101
101
|
return (c) => {
|
|
102
|
-
let
|
|
103
|
-
for (;
|
|
104
|
-
const
|
|
105
|
-
if (c <
|
|
106
|
-
else if (c >
|
|
107
|
-
else return (
|
|
102
|
+
let a = 0, l = e - 1;
|
|
103
|
+
for (; a <= l; ) {
|
|
104
|
+
const h = a + l >>> 1, f = i[h] ?? 0, u = o[h] ?? 0;
|
|
105
|
+
if (c < f) l = h - 1;
|
|
106
|
+
else if (c > u) a = h + 1;
|
|
107
|
+
else return (r[h] ?? 0) + (c - f);
|
|
108
108
|
}
|
|
109
109
|
return 0;
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
function
|
|
113
|
-
const n = new
|
|
112
|
+
function no(s, t) {
|
|
113
|
+
const n = new St(s, t);
|
|
114
114
|
n.skip(2), n.skip(2), n.skip(2);
|
|
115
|
-
const
|
|
115
|
+
const i = n.u16() >>> 1;
|
|
116
116
|
n.skip(6);
|
|
117
|
-
const
|
|
118
|
-
for (let
|
|
117
|
+
const o = new Uint16Array(i);
|
|
118
|
+
for (let f = 0; f < i; f++) o[f] = n.u16();
|
|
119
119
|
n.skip(2);
|
|
120
|
-
const
|
|
121
|
-
for (let
|
|
122
|
-
const c = new Int16Array(
|
|
123
|
-
for (let
|
|
124
|
-
const
|
|
125
|
-
for (let
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
return (
|
|
129
|
-
if (
|
|
130
|
-
let
|
|
131
|
-
for (;
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
else if (
|
|
136
|
-
|
|
120
|
+
const r = new Uint16Array(i);
|
|
121
|
+
for (let f = 0; f < i; f++) r[f] = n.u16();
|
|
122
|
+
const c = new Int16Array(i);
|
|
123
|
+
for (let f = 0; f < i; f++) c[f] = n.i16();
|
|
124
|
+
const a = new Int32Array(i), l = new Uint16Array(i);
|
|
125
|
+
for (let f = 0; f < i; f++)
|
|
126
|
+
a[f] = n.pos, l[f] = n.u16();
|
|
127
|
+
const h = new DataView(s);
|
|
128
|
+
return (f) => {
|
|
129
|
+
if (f > 65535) return 0;
|
|
130
|
+
let u = 0, p = i - 1;
|
|
131
|
+
for (; u <= p; ) {
|
|
132
|
+
const y = u + p >>> 1, _ = o[y] ?? 0;
|
|
133
|
+
if (f > _)
|
|
134
|
+
u = y + 1;
|
|
135
|
+
else if (f < (r[y] ?? 0))
|
|
136
|
+
p = y - 1;
|
|
137
137
|
else {
|
|
138
|
-
if ((
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
141
|
-
return
|
|
142
|
-
const
|
|
143
|
-
return w === 0 ? 0 : w +
|
|
138
|
+
if ((o[y] ?? 0) === 65535) return 0;
|
|
139
|
+
const x = l[y] ?? 0, b = c[y] ?? 0, M = r[y] ?? 0;
|
|
140
|
+
if (x === 0)
|
|
141
|
+
return f + b & 65535;
|
|
142
|
+
const k = (a[y] ?? 0) + x + (f - M) * 2, w = h.getUint16(k, !1);
|
|
143
|
+
return w === 0 ? 0 : w + b & 65535;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
return 0;
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
const n = new
|
|
149
|
+
function eo(s, t) {
|
|
150
|
+
const n = new St(s, t);
|
|
151
151
|
n.skip(4), n.skip(4), n.skip(4), n.skip(4), n.skip(2);
|
|
152
|
-
const
|
|
152
|
+
const e = n.u16();
|
|
153
153
|
n.skip(16), n.skip(8), n.skip(2), n.skip(2), n.skip(2);
|
|
154
|
-
const
|
|
155
|
-
return { unitsPerEm:
|
|
154
|
+
const i = n.i16();
|
|
155
|
+
return { unitsPerEm: e, indexToLocFormat: i };
|
|
156
156
|
}
|
|
157
|
-
function
|
|
158
|
-
const n = new
|
|
157
|
+
function so(s, t) {
|
|
158
|
+
const n = new St(s, t);
|
|
159
159
|
n.skip(4);
|
|
160
|
-
const
|
|
160
|
+
const e = n.i16(), i = n.i16(), o = n.i16();
|
|
161
161
|
n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(8), n.skip(2);
|
|
162
|
-
const
|
|
163
|
-
return { ascender:
|
|
162
|
+
const r = n.u16();
|
|
163
|
+
return { ascender: e, descender: i, lineGap: o, numberOfHMetrics: r };
|
|
164
164
|
}
|
|
165
|
-
function
|
|
166
|
-
const
|
|
167
|
-
let
|
|
168
|
-
for (let c = 0; c <
|
|
169
|
-
const
|
|
170
|
-
|
|
165
|
+
function io(s, t, n, e) {
|
|
166
|
+
const i = new St(s, t), o = [];
|
|
167
|
+
let r = 0;
|
|
168
|
+
for (let c = 0; c < e; c++) {
|
|
169
|
+
const a = i.u16(), l = i.i16();
|
|
170
|
+
o[c] = { advanceWidth: a, lsb: l }, r = a;
|
|
171
171
|
}
|
|
172
|
-
for (let c =
|
|
173
|
-
const
|
|
174
|
-
|
|
172
|
+
for (let c = e; c < n; c++) {
|
|
173
|
+
const a = i.i16();
|
|
174
|
+
o[c] = { advanceWidth: r, lsb: a };
|
|
175
175
|
}
|
|
176
|
-
return
|
|
176
|
+
return o;
|
|
177
177
|
}
|
|
178
|
-
function
|
|
179
|
-
const
|
|
180
|
-
if (
|
|
181
|
-
for (let c = 0; c <
|
|
178
|
+
function oo(s, t, n, e) {
|
|
179
|
+
const i = new St(s, t), o = n + 1, r = [];
|
|
180
|
+
if (e === 0)
|
|
181
|
+
for (let c = 0; c < o; c++) r[c] = i.u16() * 2;
|
|
182
182
|
else
|
|
183
|
-
for (let c = 0; c <
|
|
184
|
-
return
|
|
183
|
+
for (let c = 0; c < o; c++) r[c] = i.u32();
|
|
184
|
+
return r;
|
|
185
185
|
}
|
|
186
|
-
function
|
|
187
|
-
const n = new
|
|
186
|
+
function ro(s, t) {
|
|
187
|
+
const n = new St(s, t);
|
|
188
188
|
return n.skip(4), { numGlyphs: n.u16() };
|
|
189
189
|
}
|
|
190
|
-
function
|
|
191
|
-
return
|
|
190
|
+
function co(s, t, n, e) {
|
|
191
|
+
return s * n + t * e;
|
|
192
192
|
}
|
|
193
|
-
function
|
|
194
|
-
return
|
|
193
|
+
function z(s, t, n, e) {
|
|
194
|
+
return s * e - t * n;
|
|
195
195
|
}
|
|
196
|
-
function
|
|
197
|
-
return (1 - n) *
|
|
196
|
+
function ao(s, t, n) {
|
|
197
|
+
return (1 - n) * s + n * t;
|
|
198
198
|
}
|
|
199
|
-
function
|
|
200
|
-
return +(
|
|
199
|
+
function pt(s) {
|
|
200
|
+
return +(s > 0) - +(s < 0);
|
|
201
201
|
}
|
|
202
|
-
function
|
|
203
|
-
return 2 * +(
|
|
202
|
+
function Nt(s) {
|
|
203
|
+
return 2 * +(s > 0) - 1;
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function Ri(s, t, n, e) {
|
|
206
206
|
if (t === 0 || Math.abs(n) > 1e12 * Math.abs(t))
|
|
207
|
-
return n === 0 ?
|
|
208
|
-
const
|
|
209
|
-
if (
|
|
210
|
-
const
|
|
211
|
-
return
|
|
212
|
-
} else if (
|
|
213
|
-
return
|
|
207
|
+
return n === 0 ? e === 0 ? -1 : 0 : (s[0] = -e / n, 1);
|
|
208
|
+
const i = n * n - 4 * t * e;
|
|
209
|
+
if (i > 0) {
|
|
210
|
+
const o = Math.sqrt(i);
|
|
211
|
+
return s[0] = (-n + o) / (2 * t), s[1] = (-n - o) / (2 * t), 2;
|
|
212
|
+
} else if (i === 0)
|
|
213
|
+
return s[0] = -n / (2 * t), 1;
|
|
214
214
|
return 0;
|
|
215
215
|
}
|
|
216
|
-
function
|
|
217
|
-
const
|
|
218
|
-
if (c <
|
|
219
|
-
let
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
return
|
|
216
|
+
function lo(s, t, n, e) {
|
|
217
|
+
const i = t * t, o = 1 / 9 * (i - 3 * n), r = 1 / 54 * (t * (2 * i - 9 * n) + 27 * e), c = r * r, a = o * o * o, l = t * (1 / 3);
|
|
218
|
+
if (c < a) {
|
|
219
|
+
let h = r / Math.sqrt(a);
|
|
220
|
+
h < -1 && (h = -1), h > 1 && (h = 1), h = Math.acos(h);
|
|
221
|
+
const f = -2 * Math.sqrt(o);
|
|
222
|
+
return s[0] = f * Math.cos(1 / 3 * h) - l, s[1] = f * Math.cos(1 / 3 * (h + 2 * Math.PI)) - l, s[2] = f * Math.cos(1 / 3 * (h - 2 * Math.PI)) - l, 3;
|
|
223
223
|
} else {
|
|
224
|
-
const
|
|
225
|
-
return
|
|
224
|
+
const h = (r < 0 ? 1 : -1) * Math.pow(Math.abs(r) + Math.sqrt(c - a), 0.3333333333333333), f = h === 0 ? 0 : o / h;
|
|
225
|
+
return s[0] = h + f - l, h === f || Math.abs(h - f) < 1e-12 * Math.abs(h + f) ? (s[1] = -0.5 * (h + f) - l, 2) : 1;
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
function
|
|
228
|
+
function ho(s, t, n, e, i) {
|
|
229
229
|
if (t !== 0) {
|
|
230
|
-
const
|
|
231
|
-
if (Math.abs(
|
|
232
|
-
return
|
|
233
|
-
}
|
|
234
|
-
return
|
|
235
|
-
}
|
|
236
|
-
const
|
|
237
|
-
function
|
|
238
|
-
return ((
|
|
239
|
-
}
|
|
240
|
-
function
|
|
241
|
-
const c =
|
|
242
|
-
let
|
|
243
|
-
|
|
244
|
-
for (let
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
let
|
|
250
|
-
|
|
251
|
-
const
|
|
252
|
-
if (
|
|
253
|
-
}
|
|
254
|
-
return
|
|
255
|
-
}
|
|
256
|
-
function
|
|
257
|
-
return
|
|
258
|
-
}
|
|
259
|
-
function
|
|
260
|
-
let
|
|
261
|
-
if (
|
|
230
|
+
const o = n / t;
|
|
231
|
+
if (Math.abs(o) < 1e6)
|
|
232
|
+
return lo(s, o, e / t, i / t);
|
|
233
|
+
}
|
|
234
|
+
return Ri(s, n, e, i);
|
|
235
|
+
}
|
|
236
|
+
const fo = 24;
|
|
237
|
+
function _n(s, t, n, e) {
|
|
238
|
+
return ((e + s) * e + t) * e + n;
|
|
239
|
+
}
|
|
240
|
+
function uo(s, t, n, e, i, o, r) {
|
|
241
|
+
const c = o < 0;
|
|
242
|
+
let a = e - o * (i - e) / (r - o);
|
|
243
|
+
a > e && a < i || (a = 0.5 * (e + i));
|
|
244
|
+
for (let l = 0; l < fo; l++) {
|
|
245
|
+
const h = _n(s, t, n, a);
|
|
246
|
+
if (h === 0) return a;
|
|
247
|
+
h < 0 === c ? e = a : i = a;
|
|
248
|
+
const f = (3 * a + 2 * s) * a + t;
|
|
249
|
+
let u = a - h / f;
|
|
250
|
+
u > e && u < i || (u = 0.5 * (e + i));
|
|
251
|
+
const p = u - a;
|
|
252
|
+
if (a = u, (p < 0 ? -p : p) <= 1e-15 * (a < 0 ? -a : a)) break;
|
|
253
|
+
}
|
|
254
|
+
return a;
|
|
255
|
+
}
|
|
256
|
+
function Dn(s, t, n, e, i, o, r, c, a) {
|
|
257
|
+
return o === 0 ? c[a++] = e : o < 0 != r < 0 && (c[a++] = uo(s, t, n, e, i, o, r)), a;
|
|
258
|
+
}
|
|
259
|
+
function po(s, t, n, e, i, o) {
|
|
260
|
+
let r = 0;
|
|
261
|
+
if (s === 0) {
|
|
262
262
|
if (t === 0) return 0;
|
|
263
|
-
const
|
|
264
|
-
return
|
|
263
|
+
const u = -n / t;
|
|
264
|
+
return u >= e && u <= i && (o[r++] = u), r;
|
|
265
265
|
}
|
|
266
|
-
const c = t * t - 4 *
|
|
266
|
+
const c = t * t - 4 * s * n;
|
|
267
267
|
if (c < 0) return 0;
|
|
268
|
-
const
|
|
269
|
-
let
|
|
270
|
-
if (
|
|
271
|
-
|
|
272
|
-
else if (
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
return
|
|
277
|
-
}
|
|
278
|
-
function
|
|
279
|
-
if (
|
|
280
|
-
const c = 1 /
|
|
281
|
-
t *= c, n *= c,
|
|
282
|
-
const
|
|
283
|
-
let
|
|
284
|
-
if (
|
|
285
|
-
|
|
268
|
+
const a = Math.sqrt(c), l = -0.5 * (t + (t < 0 ? -a : a));
|
|
269
|
+
let h, f;
|
|
270
|
+
if (l === 0)
|
|
271
|
+
h = 0, f = 0;
|
|
272
|
+
else if (h = l / s, f = n / l, h > f) {
|
|
273
|
+
const u = h;
|
|
274
|
+
h = f, f = u;
|
|
275
|
+
}
|
|
276
|
+
return h >= e && h <= i && (o[r++] = h), f !== h && f >= e && f <= i && (o[r++] = f), r;
|
|
277
|
+
}
|
|
278
|
+
function _o(s, t, n, e, i, o, r) {
|
|
279
|
+
if (s === 0) return po(t, n, e, i, o, r);
|
|
280
|
+
const c = 1 / s;
|
|
281
|
+
t *= c, n *= c, e *= c;
|
|
282
|
+
const a = _n(t, n, e, i), l = _n(t, n, e, o), h = t * t - 3 * n;
|
|
283
|
+
let f = 0;
|
|
284
|
+
if (h <= 0)
|
|
285
|
+
f = Dn(t, n, e, i, o, a, l, r, 0);
|
|
286
286
|
else {
|
|
287
|
-
const
|
|
288
|
-
let
|
|
289
|
-
if (
|
|
290
|
-
const
|
|
291
|
-
|
|
287
|
+
const u = Math.sqrt(h) / 3, p = -t / 3, y = p - u, _ = p + u;
|
|
288
|
+
let g = i, x = a;
|
|
289
|
+
if (y > i && y < o) {
|
|
290
|
+
const b = _n(t, n, e, y);
|
|
291
|
+
f = Dn(t, n, e, g, y, x, b, r, f), g = y, x = b;
|
|
292
292
|
}
|
|
293
|
-
if (
|
|
294
|
-
const
|
|
295
|
-
|
|
293
|
+
if (_ > i && _ < o) {
|
|
294
|
+
const b = _n(t, n, e, _);
|
|
295
|
+
f = Dn(t, n, e, g, _, x, b, r, f), g = _, x = b;
|
|
296
296
|
}
|
|
297
|
-
|
|
297
|
+
f = Dn(t, n, e, g, o, x, l, r, f);
|
|
298
298
|
}
|
|
299
|
-
return
|
|
299
|
+
return l === 0 && (r[f++] = o), f;
|
|
300
300
|
}
|
|
301
|
-
const
|
|
302
|
-
class
|
|
301
|
+
const ft = 0, at = 1, nn = 2, Vs = 4, yo = 4, K = [0, 0, 0];
|
|
302
|
+
class ot {
|
|
303
303
|
/**
|
|
304
304
|
* @param type Segment type (LINEAR=0, QUADRATIC=1, CUBIC=2).
|
|
305
305
|
* @param p0x Start x.
|
|
@@ -311,15 +311,15 @@ class it {
|
|
|
311
311
|
* @param p3x CUBIC: end x. Others: 0.
|
|
312
312
|
* @param p3y CUBIC: end y. Others: 0.
|
|
313
313
|
*/
|
|
314
|
-
constructor(t, n,
|
|
315
|
-
this.type = t, this.p0x = n, this.p0y =
|
|
314
|
+
constructor(t, n, e, i, o, r, c, a, l) {
|
|
315
|
+
this.type = t, this.p0x = n, this.p0y = e, this.p1x = i, this.p1y = o, this.p2x = r, this.p2y = c, this.p3x = a, this.p3y = l, this.color = 7;
|
|
316
316
|
}
|
|
317
317
|
/** Endpoint x (the on-curve destination of this segment). */
|
|
318
318
|
endX() {
|
|
319
319
|
switch (this.type) {
|
|
320
|
-
case
|
|
320
|
+
case ft:
|
|
321
321
|
return this.p1x;
|
|
322
|
-
case
|
|
322
|
+
case at:
|
|
323
323
|
return this.p2x;
|
|
324
324
|
default:
|
|
325
325
|
return this.p3x;
|
|
@@ -328,9 +328,9 @@ class it {
|
|
|
328
328
|
/** Endpoint y. */
|
|
329
329
|
endY() {
|
|
330
330
|
switch (this.type) {
|
|
331
|
-
case
|
|
331
|
+
case ft:
|
|
332
332
|
return this.p1y;
|
|
333
|
-
case
|
|
333
|
+
case at:
|
|
334
334
|
return this.p2y;
|
|
335
335
|
default:
|
|
336
336
|
return this.p3y;
|
|
@@ -344,20 +344,20 @@ class it {
|
|
|
344
344
|
* @param out Two-element array [x, y] to write into (reuse to avoid allocation).
|
|
345
345
|
*/
|
|
346
346
|
point(t, n) {
|
|
347
|
-
const
|
|
347
|
+
const e = t;
|
|
348
348
|
switch (this.type) {
|
|
349
|
-
case
|
|
350
|
-
n[0] = this.p0x +
|
|
349
|
+
case ft: {
|
|
350
|
+
n[0] = this.p0x + e * (this.p1x - this.p0x), n[1] = this.p0y + e * (this.p1y - this.p0y);
|
|
351
351
|
return;
|
|
352
352
|
}
|
|
353
|
-
case
|
|
354
|
-
const
|
|
355
|
-
n[0] =
|
|
353
|
+
case at: {
|
|
354
|
+
const i = this.p0x + e * (this.p1x - this.p0x), o = this.p0y + e * (this.p1y - this.p0y), r = this.p1x + e * (this.p2x - this.p1x), c = this.p1y + e * (this.p2y - this.p1y);
|
|
355
|
+
n[0] = i + e * (r - i), n[1] = o + e * (c - o);
|
|
356
356
|
return;
|
|
357
357
|
}
|
|
358
358
|
default: {
|
|
359
|
-
const
|
|
360
|
-
n[0] =
|
|
359
|
+
const i = this.p0x + e * (this.p1x - this.p0x), o = this.p0y + e * (this.p1y - this.p0y), r = this.p1x + e * (this.p2x - this.p1x), c = this.p1y + e * (this.p2y - this.p1y), a = this.p2x + e * (this.p3x - this.p2x), l = this.p2y + e * (this.p3y - this.p2y), h = i + e * (r - i), f = o + e * (c - o), u = r + e * (a - r), p = c + e * (l - c);
|
|
360
|
+
n[0] = h + e * (u - h), n[1] = f + e * (p - f);
|
|
361
361
|
return;
|
|
362
362
|
}
|
|
363
363
|
}
|
|
@@ -370,20 +370,20 @@ class it {
|
|
|
370
370
|
* @param out Two-element array [dx, dy] to write into.
|
|
371
371
|
*/
|
|
372
372
|
direction(t, n) {
|
|
373
|
-
const
|
|
373
|
+
const e = t;
|
|
374
374
|
switch (this.type) {
|
|
375
|
-
case
|
|
375
|
+
case ft: {
|
|
376
376
|
n[0] = this.p1x - this.p0x, n[1] = this.p1y - this.p0y;
|
|
377
377
|
return;
|
|
378
378
|
}
|
|
379
|
-
case
|
|
380
|
-
const
|
|
381
|
-
|
|
379
|
+
case at: {
|
|
380
|
+
const i = this.p1x - this.p0x + e * (this.p2x - this.p1x - (this.p1x - this.p0x)), o = this.p1y - this.p0y + e * (this.p2y - this.p1y - (this.p1y - this.p0y));
|
|
381
|
+
i !== 0 || o !== 0 ? (n[0] = i, n[1] = o) : (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y);
|
|
382
382
|
return;
|
|
383
383
|
}
|
|
384
384
|
default: {
|
|
385
|
-
const
|
|
386
|
-
|
|
385
|
+
const i = this.p1x - this.p0x, o = this.p1y - this.p0y, r = this.p2x - this.p1x, c = this.p2y - this.p1y, a = this.p3x - this.p2x, l = this.p3y - this.p2y, h = i + e * (r - i) + e * (r + e * (a - r) - (i + e * (r - i))), f = o + e * (c - o) + e * (c + e * (l - c) - (o + e * (c - o)));
|
|
386
|
+
h !== 0 || f !== 0 ? (n[0] = h, n[1] = f) : e === 0 ? (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y) : e === 1 ? (n[0] = this.p3x - this.p1x, n[1] = this.p3y - this.p1y) : (n[0] = h, n[1] = f);
|
|
387
387
|
return;
|
|
388
388
|
}
|
|
389
389
|
}
|
|
@@ -398,80 +398,80 @@ class it {
|
|
|
398
398
|
splitInThirds() {
|
|
399
399
|
const t = [0, 0], n = [0, 0];
|
|
400
400
|
switch (this.type) {
|
|
401
|
-
case
|
|
401
|
+
case ft: {
|
|
402
402
|
this.point(1 / 3, t), this.point(2 / 3, n);
|
|
403
|
-
const
|
|
404
|
-
return
|
|
403
|
+
const e = new ot(ft, this.p0x, this.p0y, t[0], t[1], 0, 0, 0, 0), i = new ot(ft, t[0], t[1], n[0], n[1], 0, 0, 0, 0), o = new ot(ft, n[0], n[1], this.p1x, this.p1y, 0, 0, 0, 0);
|
|
404
|
+
return e.color = i.color = o.color = this.color, [e, i, o];
|
|
405
405
|
}
|
|
406
|
-
case
|
|
406
|
+
case at: {
|
|
407
407
|
this.point(1 / 3, t), this.point(2 / 3, n);
|
|
408
|
-
const
|
|
409
|
-
|
|
408
|
+
const e = this.p0x + 1 / 3 * (this.p1x - this.p0x), i = this.p0y + 1 / 3 * (this.p1y - this.p0y), o = this.p0x + 5 / 9 * (this.p1x - this.p0x), r = this.p0y + 5 / 9 * (this.p1y - this.p0y), c = this.p1x + 4 / 9 * (this.p2x - this.p1x), a = this.p1y + 4 / 9 * (this.p2y - this.p1y), l = o + 0.5 * (c - o), h = r + 0.5 * (a - r), f = this.p1x + 2 / 3 * (this.p2x - this.p1x), u = this.p1y + 2 / 3 * (this.p2y - this.p1y), p = new ot(
|
|
409
|
+
at,
|
|
410
410
|
this.p0x,
|
|
411
411
|
this.p0y,
|
|
412
|
-
|
|
413
|
-
|
|
412
|
+
e,
|
|
413
|
+
i,
|
|
414
414
|
t[0],
|
|
415
415
|
t[1],
|
|
416
416
|
0,
|
|
417
417
|
0
|
|
418
|
-
),
|
|
419
|
-
|
|
418
|
+
), y = new ot(
|
|
419
|
+
at,
|
|
420
420
|
t[0],
|
|
421
421
|
t[1],
|
|
422
|
-
h,
|
|
423
422
|
l,
|
|
423
|
+
h,
|
|
424
424
|
n[0],
|
|
425
425
|
n[1],
|
|
426
426
|
0,
|
|
427
427
|
0
|
|
428
|
-
),
|
|
429
|
-
|
|
428
|
+
), _ = new ot(
|
|
429
|
+
at,
|
|
430
430
|
n[0],
|
|
431
431
|
n[1],
|
|
432
|
-
a,
|
|
433
432
|
f,
|
|
433
|
+
u,
|
|
434
434
|
this.p2x,
|
|
435
435
|
this.p2y,
|
|
436
436
|
0,
|
|
437
437
|
0
|
|
438
438
|
);
|
|
439
|
-
return
|
|
439
|
+
return p.color = y.color = _.color = this.color, [p, y, _];
|
|
440
440
|
}
|
|
441
441
|
default: {
|
|
442
442
|
this.point(1 / 3, t), this.point(2 / 3, n);
|
|
443
|
-
const
|
|
444
|
-
|
|
443
|
+
const e = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0x : this.p0x + 1 / 3 * (this.p1x - this.p0x), i = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0y : this.p0y + 1 / 3 * (this.p1y - this.p0y), o = this.p0x + 1 / 3 * (this.p1x - this.p0x), r = this.p0y + 1 / 3 * (this.p1y - this.p0y), c = this.p1x + 1 / 3 * (this.p2x - this.p1x), a = this.p1y + 1 / 3 * (this.p2y - this.p1y), l = this.p2x + 1 / 3 * (this.p3x - this.p2x), h = this.p2y + 1 / 3 * (this.p3y - this.p2y), f = o + 1 / 3 * (c - o), u = r + 1 / 3 * (a - r), p = c + 1 / 3 * (l - c), y = a + 1 / 3 * (h - a), _ = f + 2 / 3 * (p - f), g = u + 2 / 3 * (y - u), x = this.p0x + 2 / 3 * (this.p1x - this.p0x), b = this.p0y + 2 / 3 * (this.p1y - this.p0y), M = this.p1x + 2 / 3 * (this.p2x - this.p1x), k = this.p1y + 2 / 3 * (this.p2y - this.p1y), w = this.p2x + 2 / 3 * (this.p3x - this.p2x), T = this.p2y + 2 / 3 * (this.p3y - this.p2y), D = x + 2 / 3 * (M - x), m = b + 2 / 3 * (k - b), A = M + 2 / 3 * (w - M), d = k + 2 / 3 * (T - k), R = D + 1 / 3 * (A - D), S = m + 1 / 3 * (d - m), E = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3x : this.p2x + 2 / 3 * (this.p3x - this.p2x), I = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3y : this.p2y + 2 / 3 * (this.p3y - this.p2y), F = new ot(
|
|
444
|
+
nn,
|
|
445
445
|
this.p0x,
|
|
446
446
|
this.p0y,
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
a,
|
|
447
|
+
e,
|
|
448
|
+
i,
|
|
450
449
|
f,
|
|
450
|
+
u,
|
|
451
451
|
t[0],
|
|
452
452
|
t[1]
|
|
453
|
-
),
|
|
454
|
-
|
|
453
|
+
), V = new ot(
|
|
454
|
+
nn,
|
|
455
455
|
t[0],
|
|
456
456
|
t[1],
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
457
|
+
_,
|
|
458
|
+
g,
|
|
459
|
+
R,
|
|
460
|
+
S,
|
|
461
461
|
n[0],
|
|
462
462
|
n[1]
|
|
463
|
-
),
|
|
464
|
-
|
|
463
|
+
), B = new ot(
|
|
464
|
+
nn,
|
|
465
465
|
n[0],
|
|
466
466
|
n[1],
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
467
|
+
A,
|
|
468
|
+
d,
|
|
469
|
+
E,
|
|
470
|
+
I,
|
|
471
471
|
this.p3x,
|
|
472
472
|
this.p3y
|
|
473
473
|
);
|
|
474
|
-
return
|
|
474
|
+
return F.color = V.color = B.color = this.color, [F, V, B];
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
}
|
|
@@ -488,95 +488,95 @@ class it {
|
|
|
488
488
|
* @param oy Query point y (shape space).
|
|
489
489
|
* @param out Reusable result object (mutated).
|
|
490
490
|
*/
|
|
491
|
-
signedDistance(t, n,
|
|
491
|
+
signedDistance(t, n, e) {
|
|
492
492
|
switch (this.type) {
|
|
493
|
-
case
|
|
494
|
-
const
|
|
495
|
-
if (
|
|
496
|
-
const
|
|
497
|
-
if (Math.abs(
|
|
498
|
-
|
|
493
|
+
case ft: {
|
|
494
|
+
const i = this.p0x, o = this.p0y, r = this.p1x, c = this.p1y, a = t - i, l = n - o, h = r - i, f = c - o, u = h * h + f * f, p = (a * h + l * f) / u, y = p > 0.5, _ = (y ? r : i) - t, g = (y ? c : o) - n, x = Math.sqrt(_ * _ + g * g);
|
|
495
|
+
if (p > 0 && p < 1) {
|
|
496
|
+
const k = Math.sqrt(h * h + f * f), w = h / k, D = f / k * a - w * l;
|
|
497
|
+
if (Math.abs(D) < x) {
|
|
498
|
+
e.distance = D, e.dot = 0, e.param = p;
|
|
499
499
|
return;
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
const
|
|
505
|
-
|
|
502
|
+
const b = a * f - l * h;
|
|
503
|
+
e.distance = Nt(b) * x;
|
|
504
|
+
const M = Math.sqrt(h * h + f * f);
|
|
505
|
+
e.dot = x === 0 || M === 0 ? 0 : Math.abs((h * _ + f * g) / (M * x)), e.param = p;
|
|
506
506
|
return;
|
|
507
507
|
}
|
|
508
|
-
case
|
|
509
|
-
const
|
|
510
|
-
let w =
|
|
511
|
-
const
|
|
512
|
-
let
|
|
508
|
+
case at: {
|
|
509
|
+
const i = this.p0x, o = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y, h = i - t, f = o - n, u = r - i, p = c - o, y = a - r - u, _ = l - c - p, g = y * y + _ * _, x = 3 * (u * y + p * _), b = 2 * (u * u + p * p) + (h * y + f * _), M = h * u + f * p, k = _o(g, x, b, M, 0, 1, K);
|
|
510
|
+
let w = u, T = p;
|
|
511
|
+
const D = h * h + f * f;
|
|
512
|
+
let m = Nt(w * f - T * h), A = D, d = -(h * w + f * T) / (w * w + T * T);
|
|
513
513
|
{
|
|
514
|
-
const
|
|
515
|
-
|
|
514
|
+
const S = a - t, E = l - n, I = S * S + E * E;
|
|
515
|
+
I < A && (w = a - r, T = l - c, m = Nt(w * E - T * S), A = I, d = ((t - r) * w + (n - c) * T) / (w * w + T * T));
|
|
516
516
|
}
|
|
517
|
-
for (let
|
|
518
|
-
const
|
|
519
|
-
if (
|
|
520
|
-
const
|
|
521
|
-
if (
|
|
522
|
-
const
|
|
523
|
-
|
|
517
|
+
for (let S = 0; S < k; ++S) {
|
|
518
|
+
const E = K[S];
|
|
519
|
+
if (E > 0 && E < 1) {
|
|
520
|
+
const I = h + 2 * E * u + E * E * y, F = f + 2 * E * p + E * E * _, V = I * I + F * F;
|
|
521
|
+
if (V <= A) {
|
|
522
|
+
const B = u + E * y, nt = p + E * _;
|
|
523
|
+
m = Nt(B * F - nt * I), A = V, d = E;
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
526
|
}
|
|
527
|
-
const
|
|
528
|
-
if (
|
|
529
|
-
|
|
527
|
+
const R = m * Math.sqrt(A);
|
|
528
|
+
if (d >= 0 && d <= 1) {
|
|
529
|
+
e.distance = R, e.dot = 0, e.param = d;
|
|
530
530
|
return;
|
|
531
531
|
}
|
|
532
|
-
if (
|
|
533
|
-
const
|
|
534
|
-
|
|
532
|
+
if (e.distance = R, e.param = d, d < 0.5) {
|
|
533
|
+
const S = Math.sqrt(u * u + p * p), E = Math.sqrt(D);
|
|
534
|
+
e.dot = E === 0 || S === 0 ? 0 : Math.abs((u * h + p * f) / (S * E));
|
|
535
535
|
} else {
|
|
536
|
-
const
|
|
537
|
-
|
|
536
|
+
const S = a - r, E = l - c, I = a - t, F = l - n, V = Math.sqrt(S * S + E * E), B = Math.sqrt(I * I + F * F);
|
|
537
|
+
e.dot = V === 0 || B === 0 ? 0 : Math.abs((S * I + E * F) / (V * B));
|
|
538
538
|
}
|
|
539
539
|
return;
|
|
540
540
|
}
|
|
541
541
|
default: {
|
|
542
|
-
const
|
|
543
|
-
let
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
let
|
|
542
|
+
const i = this.p0x, o = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y, h = this.p3x, f = this.p3y, u = i - t, p = o - n, y = r - i, _ = c - o, g = a - r - y, x = l - c - _, b = h - a - (a - r) - g, M = f - l - (l - c) - x;
|
|
543
|
+
let k = y, w = _;
|
|
544
|
+
k === 0 && w === 0 && (k = a - i, w = l - o);
|
|
545
|
+
const T = Math.sqrt(u * u + p * p);
|
|
546
|
+
let D = Nt(k * p - w * u) * T, m = -(u * k + p * w) / (k * k + w * w);
|
|
547
547
|
{
|
|
548
|
-
const
|
|
549
|
-
if (
|
|
550
|
-
let
|
|
551
|
-
|
|
548
|
+
const A = h - t, d = f - n, R = Math.sqrt(A * A + d * d);
|
|
549
|
+
if (R < Math.abs(D)) {
|
|
550
|
+
let S = h - a, E = f - l;
|
|
551
|
+
S === 0 && E === 0 && (S = h - r, E = f - c), k = S, w = E, D = Nt(k * d - w * A) * R, m = ((k - A) * k + (w - d) * w) / (k * k + w * w);
|
|
552
552
|
}
|
|
553
553
|
}
|
|
554
|
-
for (let
|
|
555
|
-
let
|
|
556
|
-
if (
|
|
557
|
-
let nt =
|
|
554
|
+
for (let A = 0; A <= Vs; ++A) {
|
|
555
|
+
let d = 1 / Vs * A, R = u + 3 * d * y + 3 * d * d * g + d * d * d * b, S = p + 3 * d * _ + 3 * d * d * x + d * d * d * M, E = 3 * y + 6 * d * g + 3 * d * d * b, I = 3 * _ + 6 * d * x + 3 * d * d * M, F = 6 * g + 6 * d * b, V = 6 * x + 6 * d * M, B = d - (R * E + S * I) / (E * E + I * I + (R * F + S * V));
|
|
556
|
+
if (B > 0 && B < 1) {
|
|
557
|
+
let nt = yo;
|
|
558
558
|
do {
|
|
559
|
-
if (
|
|
560
|
-
|
|
561
|
-
} while (
|
|
562
|
-
const
|
|
563
|
-
|
|
559
|
+
if (d = B, R = u + 3 * d * y + 3 * d * d * g + d * d * d * b, S = p + 3 * d * _ + 3 * d * d * x + d * d * d * M, E = 3 * y + 6 * d * g + 3 * d * d * b, I = 3 * _ + 6 * d * x + 3 * d * d * M, !--nt) break;
|
|
560
|
+
F = 6 * g + 6 * d * b, V = 6 * x + 6 * d * M, B = d - (R * E + S * I) / (E * E + I * I + (R * F + S * V));
|
|
561
|
+
} while (B > 0 && B < 1);
|
|
562
|
+
const j = Math.sqrt(R * R + S * S);
|
|
563
|
+
j < Math.abs(D) && (D = Nt(E * S - I * R) * j, m = d);
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
|
-
if (
|
|
567
|
-
|
|
566
|
+
if (m >= 0 && m <= 1) {
|
|
567
|
+
e.distance = D, e.dot = 0, e.param = m;
|
|
568
568
|
return;
|
|
569
569
|
}
|
|
570
|
-
if (
|
|
571
|
-
let
|
|
572
|
-
|
|
573
|
-
const
|
|
574
|
-
|
|
570
|
+
if (e.distance = D, e.param = m, m < 0.5) {
|
|
571
|
+
let A = y, d = _;
|
|
572
|
+
A === 0 && d === 0 && (A = a - i, d = l - o);
|
|
573
|
+
const R = Math.sqrt(A * A + d * d);
|
|
574
|
+
e.dot = T === 0 || R === 0 ? 0 : Math.abs((A * u + d * p) / (R * T));
|
|
575
575
|
} else {
|
|
576
|
-
let
|
|
577
|
-
|
|
578
|
-
const
|
|
579
|
-
|
|
576
|
+
let A = h - a, d = f - l;
|
|
577
|
+
A === 0 && d === 0 && (A = h - r, d = f - c);
|
|
578
|
+
const R = h - t, S = f - n, E = Math.sqrt(A * A + d * d), I = Math.sqrt(R * R + S * S);
|
|
579
|
+
e.dot = E === 0 || I === 0 ? 0 : Math.abs((A * R + d * S) / (E * I));
|
|
580
580
|
}
|
|
581
581
|
return;
|
|
582
582
|
}
|
|
@@ -593,58 +593,58 @@ class it {
|
|
|
593
593
|
* @param dyOut Output array (length >= 3) — crossing directions (±1).
|
|
594
594
|
* @returns Number of crossings written (0..3).
|
|
595
595
|
*/
|
|
596
|
-
scanlineIntersections(t, n,
|
|
596
|
+
scanlineIntersections(t, n, e) {
|
|
597
597
|
switch (this.type) {
|
|
598
|
-
case
|
|
599
|
-
const
|
|
600
|
-
if (t >=
|
|
601
|
-
const
|
|
602
|
-
return n[0] =
|
|
598
|
+
case ft: {
|
|
599
|
+
const i = this.p0y, o = this.p1y;
|
|
600
|
+
if (t >= i && t < o || t >= o && t < i) {
|
|
601
|
+
const r = (t - i) / (o - i);
|
|
602
|
+
return n[0] = ao(this.p0x, this.p1x, r), e[0] = pt(o - i), 1;
|
|
603
603
|
}
|
|
604
604
|
return 0;
|
|
605
605
|
}
|
|
606
|
-
case
|
|
607
|
-
const
|
|
608
|
-
let
|
|
609
|
-
n[
|
|
606
|
+
case at: {
|
|
607
|
+
const i = this.p0x, o = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y;
|
|
608
|
+
let h = 0, f = t > o ? 1 : -1;
|
|
609
|
+
n[h] = i, o === t && (o < c || o === c && o < l ? e[h++] = 1 : f = 1);
|
|
610
610
|
{
|
|
611
|
-
const
|
|
612
|
-
if (
|
|
613
|
-
const
|
|
614
|
-
|
|
611
|
+
const u = r - i, p = c - o, y = a - r - u, _ = l - c - p, g = Ri(K, _, 2 * p, o - t);
|
|
612
|
+
if (g >= 2 && K[0] > K[1]) {
|
|
613
|
+
const x = K[0];
|
|
614
|
+
K[0] = K[1], K[1] = x;
|
|
615
615
|
}
|
|
616
|
-
for (let
|
|
617
|
-
const
|
|
618
|
-
|
|
616
|
+
for (let x = 0; x < g && h < 2; ++x) {
|
|
617
|
+
const b = K[x];
|
|
618
|
+
b >= 0 && b <= 1 && (n[h] = i + 2 * b * u + b * b * y, f * (p + b * _) >= 0 && (e[h++] = f, f = -f));
|
|
619
619
|
}
|
|
620
620
|
}
|
|
621
|
-
return
|
|
621
|
+
return l === t && (f > 0 && h > 0 && (--h, f = -1), (l < c || l === c && l < o) && h < 2 && (n[h] = a, f < 0 && (e[h++] = -1, f = 1))), f !== (t >= l ? 1 : -1) && (h > 0 ? --h : (Math.abs(l - t) < Math.abs(o - t) && (n[h] = a), e[h++] = f)), h;
|
|
622
622
|
}
|
|
623
623
|
default: {
|
|
624
|
-
const
|
|
625
|
-
let
|
|
626
|
-
n[
|
|
624
|
+
const i = this.p0x, o = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y, h = this.p3x, f = this.p3y;
|
|
625
|
+
let u = 0, p = t > o ? 1 : -1;
|
|
626
|
+
n[u] = i, o === t && (o < c || o === c && (o < l || o === l && o < f) ? e[u++] = 1 : p = 1);
|
|
627
627
|
{
|
|
628
|
-
const
|
|
629
|
-
if (
|
|
630
|
-
if (
|
|
631
|
-
const w =
|
|
632
|
-
|
|
628
|
+
const y = h - 3 * a + 3 * r - i, _ = f - 3 * l + 3 * c - o, g = 3 * a - 6 * r + 3 * i, x = 3 * l - 6 * c + 3 * o, b = 3 * r - 3 * i, M = 3 * c - 3 * o, k = ho(K, _, x, M, o - t);
|
|
629
|
+
if (k >= 2) {
|
|
630
|
+
if (K[0] > K[1]) {
|
|
631
|
+
const w = K[0];
|
|
632
|
+
K[0] = K[1], K[1] = w;
|
|
633
633
|
}
|
|
634
|
-
if (
|
|
635
|
-
const w =
|
|
636
|
-
if (
|
|
637
|
-
const
|
|
638
|
-
|
|
634
|
+
if (k >= 3 && K[1] > K[2]) {
|
|
635
|
+
const w = K[1];
|
|
636
|
+
if (K[1] = K[2], K[2] = w, K[0] > K[1]) {
|
|
637
|
+
const T = K[0];
|
|
638
|
+
K[0] = K[1], K[1] = T;
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
641
|
}
|
|
642
|
-
for (let w = 0; w <
|
|
643
|
-
const
|
|
644
|
-
|
|
642
|
+
for (let w = 0; w < k && u < 3; ++w) {
|
|
643
|
+
const T = K[w];
|
|
644
|
+
T >= 0 && T <= 1 && (n[u] = ((y * T + g) * T + b) * T + i, p * ((3 * _ * T + 2 * x) * T + M) >= 0 && (e[u++] = p, p = -p));
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
|
-
return
|
|
647
|
+
return f === t && (p > 0 && u > 0 && (--u, p = -1), (f < l || f === l && (f < c || f === c && f < o)) && u < 3 && (n[u] = h, p < 0 && (e[u++] = -1, p = 1))), p !== (t >= f ? 1 : -1) && (u > 0 ? --u : (Math.abs(f - t) < Math.abs(o - t) && (n[u] = h), e[u++] = p)), u;
|
|
648
648
|
}
|
|
649
649
|
}
|
|
650
650
|
}
|
|
@@ -656,202 +656,1290 @@ class it {
|
|
|
656
656
|
* @returns A new CUBIC EdgeSegment with identical geometry.
|
|
657
657
|
*/
|
|
658
658
|
convertToCubic() {
|
|
659
|
-
const t = this.p0x + 0.6666666666666666 * (this.p1x - this.p0x), n = this.p0y + 2 / 3 * (this.p1y - this.p0y),
|
|
660
|
-
|
|
659
|
+
const t = this.p0x + 0.6666666666666666 * (this.p1x - this.p0x), n = this.p0y + 2 / 3 * (this.p1y - this.p0y), e = this.p1x + 1 / 3 * (this.p2x - this.p1x), i = this.p1y + 1 / 3 * (this.p2y - this.p1y), o = new ot(
|
|
660
|
+
nn,
|
|
661
661
|
this.p0x,
|
|
662
662
|
this.p0y,
|
|
663
663
|
t,
|
|
664
664
|
n,
|
|
665
|
-
|
|
666
|
-
|
|
665
|
+
e,
|
|
666
|
+
i,
|
|
667
667
|
this.p2x,
|
|
668
668
|
this.p2y
|
|
669
669
|
);
|
|
670
|
-
return
|
|
670
|
+
return o.color = this.color, o;
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
|
-
const
|
|
674
|
-
function
|
|
675
|
-
const
|
|
676
|
-
for (const c of
|
|
677
|
-
const
|
|
678
|
-
|
|
673
|
+
const go = 1, xo = 2, Mo = 4, wo = 8, js = 16, Xs = 32, Ao = 1, Ws = 2, bo = 8, mo = 32, ko = 64, Uo = 128;
|
|
674
|
+
function To(s, t, n, e, i) {
|
|
675
|
+
const o = Li(s, t, n, e, i), r = [];
|
|
676
|
+
for (const c of o) {
|
|
677
|
+
const a = Co(c);
|
|
678
|
+
a.length > 0 && r.push(a);
|
|
679
679
|
}
|
|
680
|
-
return { contours:
|
|
680
|
+
return { contours: r, inverseYAxis: !1 };
|
|
681
681
|
}
|
|
682
|
-
function
|
|
683
|
-
if (
|
|
684
|
-
const
|
|
685
|
-
return
|
|
682
|
+
function Li(s, t, n, e, i) {
|
|
683
|
+
if (e === 0) return [];
|
|
684
|
+
const o = t + n, r = new St(s, o), c = r.i16();
|
|
685
|
+
return r.skip(8), c >= 0 ? vo(r, c) : So(s, r, t, i);
|
|
686
686
|
}
|
|
687
|
-
function
|
|
687
|
+
function vo(s, t) {
|
|
688
688
|
if (t === 0) return [];
|
|
689
|
-
const n =
|
|
690
|
-
for (let
|
|
691
|
-
const
|
|
692
|
-
|
|
693
|
-
const
|
|
694
|
-
for (let
|
|
695
|
-
const
|
|
696
|
-
if (
|
|
697
|
-
let
|
|
698
|
-
for (;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
const
|
|
689
|
+
const n = [];
|
|
690
|
+
for (let f = 0; f < t; f++) n[f] = s.u16();
|
|
691
|
+
const e = (n[t - 1] ?? 0) + 1, i = s.u16();
|
|
692
|
+
s.skip(i);
|
|
693
|
+
const o = new Uint8Array(e);
|
|
694
|
+
for (let f = 0; f < e; ) {
|
|
695
|
+
const u = s.u8();
|
|
696
|
+
if (o[f++] = u, u & wo) {
|
|
697
|
+
let p = s.u8();
|
|
698
|
+
for (; p-- > 0; ) o[f++] = u;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
const r = new Float64Array(e);
|
|
702
702
|
let c = 0;
|
|
703
|
-
for (let
|
|
704
|
-
const
|
|
705
|
-
if (
|
|
706
|
-
const
|
|
707
|
-
c +=
|
|
708
|
-
} else
|
|
709
|
-
|
|
710
|
-
}
|
|
711
|
-
const
|
|
703
|
+
for (let f = 0; f < e; f++) {
|
|
704
|
+
const u = o[f] ?? 0;
|
|
705
|
+
if (u & xo) {
|
|
706
|
+
const p = s.u8();
|
|
707
|
+
c += u & js ? p : -p;
|
|
708
|
+
} else u & js || (c += s.i16());
|
|
709
|
+
r[f] = c;
|
|
710
|
+
}
|
|
711
|
+
const a = new Float64Array(e);
|
|
712
712
|
c = 0;
|
|
713
|
-
for (let
|
|
714
|
-
const
|
|
715
|
-
if (
|
|
716
|
-
const
|
|
717
|
-
c +=
|
|
718
|
-
} else
|
|
719
|
-
|
|
720
|
-
}
|
|
721
|
-
const
|
|
722
|
-
let
|
|
723
|
-
for (let
|
|
724
|
-
const
|
|
725
|
-
|
|
726
|
-
}
|
|
727
|
-
return
|
|
728
|
-
}
|
|
729
|
-
function
|
|
730
|
-
const
|
|
731
|
-
if (
|
|
732
|
-
const
|
|
733
|
-
for (let c = 0; c <
|
|
734
|
-
const
|
|
735
|
-
|
|
713
|
+
for (let f = 0; f < e; f++) {
|
|
714
|
+
const u = o[f] ?? 0;
|
|
715
|
+
if (u & Mo) {
|
|
716
|
+
const p = s.u8();
|
|
717
|
+
c += u & Xs ? p : -p;
|
|
718
|
+
} else u & Xs || (c += s.i16());
|
|
719
|
+
a[f] = c;
|
|
720
|
+
}
|
|
721
|
+
const l = [];
|
|
722
|
+
let h = 0;
|
|
723
|
+
for (let f = 0; f < t; f++) {
|
|
724
|
+
const u = n[f] ?? 0, p = Eo(o, r, a, h, u);
|
|
725
|
+
p.length > 0 && l.push(p), h = u + 1;
|
|
726
|
+
}
|
|
727
|
+
return l;
|
|
728
|
+
}
|
|
729
|
+
function Eo(s, t, n, e, i) {
|
|
730
|
+
const o = i - e + 1;
|
|
731
|
+
if (o <= 0) return [];
|
|
732
|
+
const r = [];
|
|
733
|
+
for (let c = 0; c < o; c++) {
|
|
734
|
+
const a = s[e + c] ?? 0, l = t[e + c] ?? 0, h = n[e + c] ?? 0;
|
|
735
|
+
r.push({ x: l, y: h, onCurve: (a & go) !== 0 });
|
|
736
736
|
}
|
|
737
|
-
return
|
|
737
|
+
return r;
|
|
738
738
|
}
|
|
739
|
-
function
|
|
740
|
-
const t =
|
|
739
|
+
function Co(s) {
|
|
740
|
+
const t = s.length;
|
|
741
741
|
if (t <= 0) return [];
|
|
742
742
|
const n = [];
|
|
743
743
|
for (let c = 0; c < t; c++) {
|
|
744
|
-
const
|
|
745
|
-
n.push(
|
|
746
|
-
x: Math.trunc((
|
|
747
|
-
y: Math.trunc((
|
|
744
|
+
const a = s[c], l = s[(c + 1) % t];
|
|
745
|
+
n.push(a), !a.onCurve && !l.onCurve && n.push({
|
|
746
|
+
x: Math.trunc((a.x + l.x) / 2),
|
|
747
|
+
y: Math.trunc((a.y + l.y) / 2),
|
|
748
748
|
onCurve: !0
|
|
749
749
|
});
|
|
750
750
|
}
|
|
751
|
-
const
|
|
752
|
-
let
|
|
751
|
+
const e = n.length;
|
|
752
|
+
let i = 0;
|
|
753
753
|
if (!n[0].onCurve) {
|
|
754
|
-
for (let c = 1; c <
|
|
754
|
+
for (let c = 1; c < e; c++)
|
|
755
755
|
if (n[c].onCurve) {
|
|
756
|
-
|
|
756
|
+
i = c;
|
|
757
757
|
break;
|
|
758
758
|
}
|
|
759
759
|
}
|
|
760
|
-
const
|
|
761
|
-
let
|
|
762
|
-
for (;
|
|
763
|
-
const c = n[(
|
|
764
|
-
if (
|
|
765
|
-
|
|
760
|
+
const o = [];
|
|
761
|
+
let r = 0;
|
|
762
|
+
for (; r < e; ) {
|
|
763
|
+
const c = n[(i + r) % e], a = n[(i + r + 1) % e];
|
|
764
|
+
if (a.onCurve)
|
|
765
|
+
o.push(new ot(ft, c.x, c.y, a.x, a.y, 0, 0, 0, 0)), r += 1;
|
|
766
766
|
else {
|
|
767
|
-
const
|
|
768
|
-
|
|
767
|
+
const l = n[(i + r + 2) % e];
|
|
768
|
+
o.push(new ot(at, c.x, c.y, a.x, a.y, l.x, l.y, 0, 0)), r += 2;
|
|
769
769
|
}
|
|
770
770
|
}
|
|
771
|
-
return e;
|
|
772
|
-
}
|
|
773
|
-
function Po(i, t, n, s) {
|
|
774
|
-
const o = [];
|
|
775
|
-
let e = 0;
|
|
776
|
-
do {
|
|
777
|
-
e = t.u16();
|
|
778
|
-
const p = t.u16();
|
|
779
|
-
let c, r;
|
|
780
|
-
e & vo ? (c = t.i16(), r = t.i16()) : (c = t.u8(), r = t.u8(), e & ks && (c > 127 && (c -= 256), r > 127 && (r -= 256)));
|
|
781
|
-
let h = 0, l = 0;
|
|
782
|
-
e & ks && (h = c, l = r);
|
|
783
|
-
let a = 1, f = 0, y = 0, _ = 1;
|
|
784
|
-
e & Co ? a = _ = t.f2dot14() : e & Ro ? (a = t.f2dot14(), _ = t.f2dot14()) : e & To && (a = t.f2dot14(), f = t.f2dot14(), y = t.f2dot14(), _ = t.f2dot14());
|
|
785
|
-
const u = s(p), x = Go(u, a, f, y, _, h, l);
|
|
786
|
-
for (const g of x) o.push(g);
|
|
787
|
-
} while (e & Io);
|
|
788
771
|
return o;
|
|
789
772
|
}
|
|
790
|
-
function
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
(
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
773
|
+
function So(s, t, n, e) {
|
|
774
|
+
const i = [];
|
|
775
|
+
let o = 0;
|
|
776
|
+
do {
|
|
777
|
+
o = t.u16();
|
|
778
|
+
const r = t.u16();
|
|
779
|
+
let c, a;
|
|
780
|
+
o & Ao ? (c = t.i16(), a = t.i16()) : (c = t.u8(), a = t.u8(), o & Ws && (c > 127 && (c -= 256), a > 127 && (a -= 256)));
|
|
781
|
+
let l = 0, h = 0;
|
|
782
|
+
o & Ws && (l = c, h = a);
|
|
783
|
+
let f = 1, u = 0, p = 0, y = 1;
|
|
784
|
+
o & bo ? f = y = t.f2dot14() : o & ko ? (f = t.f2dot14(), y = t.f2dot14()) : o & Uo && (f = t.f2dot14(), u = t.f2dot14(), p = t.f2dot14(), y = t.f2dot14());
|
|
785
|
+
const _ = e(r), g = Io(_, f, u, p, y, l, h);
|
|
786
|
+
for (const x of g) i.push(x);
|
|
787
|
+
} while (o & mo);
|
|
788
|
+
return i;
|
|
789
|
+
}
|
|
790
|
+
function zs(s) {
|
|
791
|
+
return s >= 0 ? Math.floor(s + 0.5) : Math.ceil(s - 0.5);
|
|
792
|
+
}
|
|
793
|
+
function Io(s, t, n, e, i, o, r) {
|
|
794
|
+
if (t === 1 && n === 0 && e === 0 && i === 1 && o === 0 && r === 0) return s;
|
|
795
|
+
const a = t === 1 && n === 0 && e === 0 && i === 1;
|
|
796
|
+
return s.map(
|
|
797
|
+
(l) => l.map((h) => a ? { x: h.x + o, y: h.y + r, onCurve: h.onCurve } : {
|
|
798
|
+
x: zs(t * h.x + n * h.y + o),
|
|
799
|
+
y: zs(e * h.x + i * h.y + r),
|
|
800
|
+
onCurve: h.onCurve
|
|
801
801
|
})
|
|
802
802
|
);
|
|
803
803
|
}
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
804
|
+
const on = 1, Xn = 2, Do = 4, Ct = 8, xn = 16, C = {
|
|
805
|
+
/** Unicode codepoint per glyph. */
|
|
806
|
+
_cp: new Int32Array(64),
|
|
807
|
+
/** Glyph index per glyph. */
|
|
808
|
+
_gid: new Uint16Array(64),
|
|
809
|
+
/** PROP_* bits per glyph. */
|
|
810
|
+
_gp: new Uint16Array(64),
|
|
811
|
+
/** x advance, font units. */
|
|
812
|
+
_xa: new Float64Array(64),
|
|
813
|
+
/** x offset, font units. */
|
|
814
|
+
_xo: new Float64Array(64),
|
|
815
|
+
/** y offset, font units (y-up). */
|
|
816
|
+
_yo: new Float64Array(64),
|
|
817
|
+
/** Script-run end indices and ICU script codes (see script.ts: itemize). */
|
|
818
|
+
_runEnd: new Int32Array(64),
|
|
819
|
+
_runScript: new Int32Array(64)
|
|
820
|
+
};
|
|
821
|
+
function dn(s, t, n, e) {
|
|
822
|
+
if (s & n & 14) return !1;
|
|
823
|
+
if (s & Ct) {
|
|
824
|
+
if (n & 16) return e !== null && t < e.length && e[t] !== 65535;
|
|
825
|
+
if (n & 65280) return (n & 65280) === (s & 65280);
|
|
826
|
+
}
|
|
827
|
+
return !0;
|
|
828
|
+
}
|
|
829
|
+
function rs(s, t, n, e) {
|
|
830
|
+
const i = C._gp, o = C._gid;
|
|
831
|
+
for (let r = s + 1; r < t; r++) {
|
|
832
|
+
const c = i[r];
|
|
833
|
+
if (!(c & on) && dn(c, o[r], n, e)) return r;
|
|
834
|
+
}
|
|
835
|
+
return -1;
|
|
836
|
+
}
|
|
837
|
+
function Fi(s) {
|
|
838
|
+
if (C._gid.length >= s) return;
|
|
839
|
+
let t = C._gid.length;
|
|
840
|
+
for (; t < s; ) t *= 2;
|
|
841
|
+
C._cp = new Int32Array(t), C._gid = new Uint16Array(t), C._gp = new Uint16Array(t), C._xa = new Float64Array(t), C._xo = new Float64Array(t), C._yo = new Float64Array(t), C._runEnd = new Int32Array(t), C._runScript = new Int32Array(t);
|
|
842
|
+
}
|
|
843
|
+
let rn = new Uint8Array(64);
|
|
844
|
+
class Ro {
|
|
845
|
+
/**
|
|
846
|
+
* @param buffer Full font buffer.
|
|
847
|
+
* @param offset Byte offset of the kern table.
|
|
848
|
+
*/
|
|
849
|
+
constructor(t, n) {
|
|
850
|
+
this._pairs = [], this._counts = [], this._cross = [];
|
|
851
|
+
const e = new DataView(t);
|
|
852
|
+
this._dv = e;
|
|
853
|
+
const i = e.getUint16(n) === 1, o = i ? e.getUint32(n + 4) : e.getUint16(n + 2);
|
|
854
|
+
let r = n + (i ? 8 : 4), c = !1, a = !1;
|
|
855
|
+
for (let l = 0; l < o && r + 8 <= e.byteLength; l++) {
|
|
856
|
+
let h, f, u, p, y = !1, _;
|
|
857
|
+
if (i) {
|
|
858
|
+
h = e.getUint32(r);
|
|
859
|
+
const g = e.getUint8(r + 4);
|
|
860
|
+
f = e.getUint8(r + 5), u = !(g & 128), p = !!(g & 64), y = !!(g & 32), _ = r + 8;
|
|
861
|
+
} else {
|
|
862
|
+
h = e.getUint16(r + 2), f = e.getUint8(r + 4);
|
|
863
|
+
const g = e.getUint8(r + 5);
|
|
864
|
+
u = !!(g & 1), p = !!(g & 4), _ = r + 6;
|
|
865
|
+
}
|
|
866
|
+
if (f === 1 && (c = !0), p && (a = !0), f === 0 && u && !y && (this._pairs.push(_ + 8), this._counts.push(e.getUint16(_)), this._cross.push(p)), h < 6) break;
|
|
867
|
+
r += h;
|
|
868
|
+
}
|
|
869
|
+
this._hasData = o > 0, this._hasMachine = c, this._hasCross = a;
|
|
870
|
+
}
|
|
871
|
+
/** Kern value of subtable `s` for a pair, 0 if not listed (binary search, like HarfBuzz). */
|
|
872
|
+
_get(t, n, e) {
|
|
873
|
+
const i = this._dv, o = this._pairs[t], r = (n << 16 | e) >>> 0;
|
|
874
|
+
let c = 0, a = this._counts[t] - 1;
|
|
875
|
+
for (; c <= a; ) {
|
|
876
|
+
const l = c + a >> 1, h = i.getUint32(o + 6 * l);
|
|
877
|
+
if (h < r) c = l + 1;
|
|
878
|
+
else if (h > r) a = l - 1;
|
|
879
|
+
else return i.getInt16(o + 6 * l + 4);
|
|
880
|
+
}
|
|
881
|
+
return 0;
|
|
882
|
+
}
|
|
883
|
+
/** Kerns `run[start, end)`. */
|
|
884
|
+
_apply(t, n) {
|
|
885
|
+
const e = C._gid, i = C._xa, o = C._xo, r = C._yo;
|
|
886
|
+
let c = !1, a = !1;
|
|
887
|
+
for (let l = 0; l < this._pairs.length; l++) {
|
|
888
|
+
const h = this._cross[l];
|
|
889
|
+
h && !c && (c = !0, rn.length < n && (rn = new Uint8Array(n * 2)), rn.fill(0, t, n));
|
|
890
|
+
for (let f = t; f < n; ) {
|
|
891
|
+
const u = rs(f, n, Ct, null);
|
|
892
|
+
if (u < 0) {
|
|
893
|
+
f++;
|
|
894
|
+
continue;
|
|
895
|
+
}
|
|
896
|
+
const p = this._get(l, e[f], e[u]);
|
|
897
|
+
if (p)
|
|
898
|
+
if (h)
|
|
899
|
+
p === -32768 ? (rn[u] = 1, r[u] = 0) : (r[u] = p, a = !0);
|
|
900
|
+
else {
|
|
901
|
+
const y = p / 2;
|
|
902
|
+
i[f] = i[f] + y, i[u] = i[u] + p - y, o[u] = o[u] + p - y;
|
|
903
|
+
}
|
|
904
|
+
f = u;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
if (a)
|
|
908
|
+
for (let l = t + 1; l < n; l++) rn[l] || (r[l] = r[l] + r[l - 1]);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
const Gt = 65535, Pi = new Uint16Array(0);
|
|
912
|
+
function Lo(s, t) {
|
|
913
|
+
const n = s.getUint16(t + 4);
|
|
914
|
+
if (!n) return new Uint32Array(0);
|
|
915
|
+
const e = t + n, i = new Uint32Array(s.getUint16(e));
|
|
916
|
+
for (let o = 0; o < i.length; o++) i[o] = s.getUint32(e + 2 + 6 * o);
|
|
917
|
+
return i;
|
|
918
|
+
}
|
|
919
|
+
function qi(s, t) {
|
|
920
|
+
const n = s.getUint16(t), e = s.getUint16(t + 2);
|
|
921
|
+
let i = -1;
|
|
922
|
+
if (n === 1) {
|
|
923
|
+
for (let r = 0; r < e; r++) i = Math.max(i, s.getUint16(t + 4 + 2 * r));
|
|
924
|
+
const o = new Uint16Array(i + 1).fill(Gt);
|
|
925
|
+
for (let r = e - 1; r >= 0; r--) o[s.getUint16(t + 4 + 2 * r)] = r;
|
|
926
|
+
return o;
|
|
927
|
+
}
|
|
928
|
+
if (n === 2) {
|
|
929
|
+
for (let r = 0; r < e; r++) i = Math.max(i, s.getUint16(t + 6 + 6 * r));
|
|
930
|
+
const o = new Uint16Array(i + 1).fill(Gt);
|
|
931
|
+
for (let r = e - 1; r >= 0; r--) {
|
|
932
|
+
const c = t + 4 + 6 * r, a = s.getUint16(c), l = s.getUint16(c + 2), h = s.getUint16(c + 4);
|
|
933
|
+
for (let f = a; f <= l; f++) o[f] = h + f - a;
|
|
934
|
+
}
|
|
935
|
+
return o;
|
|
936
|
+
}
|
|
937
|
+
return Pi;
|
|
938
|
+
}
|
|
939
|
+
function ts(s, t) {
|
|
940
|
+
const n = s.getUint16(t);
|
|
941
|
+
if (n === 1) {
|
|
942
|
+
const e = s.getUint16(t + 2), i = s.getUint16(t + 4), o = new Uint16Array(e + i);
|
|
943
|
+
for (let r = 0; r < i; r++) o[e + r] = s.getUint16(t + 6 + 2 * r);
|
|
944
|
+
return o;
|
|
945
|
+
}
|
|
946
|
+
if (n === 2) {
|
|
947
|
+
const e = s.getUint16(t + 2);
|
|
948
|
+
let i = -1;
|
|
949
|
+
for (let r = 0; r < e; r++) i = Math.max(i, s.getUint16(t + 6 + 6 * r));
|
|
950
|
+
const o = new Uint16Array(i + 1);
|
|
951
|
+
for (let r = e - 1; r >= 0; r--) {
|
|
952
|
+
const c = t + 4 + 6 * r, a = s.getUint16(c + 2), l = s.getUint16(c + 4);
|
|
953
|
+
for (let h = s.getUint16(c); h <= a; h++) o[h] = l;
|
|
954
|
+
}
|
|
955
|
+
return o;
|
|
956
|
+
}
|
|
957
|
+
return Pi;
|
|
958
|
+
}
|
|
959
|
+
class Fo {
|
|
960
|
+
/**
|
|
961
|
+
* @param buffer Full font buffer.
|
|
962
|
+
* @param offset Byte offset of the GDEF table.
|
|
963
|
+
* @param numGlyphs `maxp.numGlyphs`.
|
|
964
|
+
*/
|
|
965
|
+
constructor(t, n, e) {
|
|
966
|
+
this._setCache = [];
|
|
967
|
+
const i = new DataView(t);
|
|
968
|
+
this._dv = i;
|
|
969
|
+
const o = i.getUint16(n + 2), r = i.getUint16(n + 4), c = i.getUint16(n + 10), a = o >= 2 ? i.getUint16(n + 12) : 0;
|
|
970
|
+
if (this._sets = a ? n + a : 0, !r) {
|
|
971
|
+
this._props = null;
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
const l = ts(i, n + r), h = c ? ts(i, n + c) : new Uint16Array(0), f = new Uint16Array(e);
|
|
975
|
+
for (let u = 0; u < e && u < l.length; u++)
|
|
976
|
+
switch (l[u]) {
|
|
977
|
+
case 1:
|
|
978
|
+
f[u] = Xn;
|
|
979
|
+
break;
|
|
980
|
+
case 2:
|
|
981
|
+
f[u] = Do;
|
|
982
|
+
break;
|
|
983
|
+
case 3:
|
|
984
|
+
f[u] = Ct | (h[u] ?? 0) << 8;
|
|
985
|
+
break;
|
|
986
|
+
}
|
|
987
|
+
this._props = f;
|
|
988
|
+
}
|
|
989
|
+
/** Coverage of mark glyph set `index` (empty if the font has none). */
|
|
990
|
+
_markSet(t) {
|
|
991
|
+
let n = this._setCache[t];
|
|
992
|
+
if (!n) {
|
|
993
|
+
const e = this._dv, i = this._sets;
|
|
994
|
+
n = i && t < e.getUint16(i + 2) ? qi(e, i + e.getUint32(i + 4 + 4 * t)) : new Uint16Array(0), this._setCache[t] = n;
|
|
995
|
+
}
|
|
996
|
+
return n;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
const Oi = "ZyyyZinhArabArmnBengBopoCherCoptCyrlDsrtDevaEthiGeorGothGrekGujrGuruHaniHangHebrHiraKndaKanaKhmrLaooLatnMlymMongMymrOgamItalOryaRunrSinhSyrcTamlTeluThaaThaiTibtCansYiiiTglgHanoBuhdTagbBraiCprtLimbLinbOsmaShawTaleUgarHrktBugiGlagKharSyloTaluTfngXpeoBaliBatkBlisBrahChamCirtCyrsEgydEgyhEgypGeokHansHantHmngHungIndsJavaKaliLatfLatgLepcLinaMandMayaMeroNkooOrkhPermPhagPhnxPlrdRoroSaraSyreSyrjSyrnTengVaiiVispXsuxZxxxZzzzCariJpanLanaLyciLydiOlckRjngSaurSgnwSundMoonMteiArmiAvstCakmKoreKthiManiPhliPhlpPhlvPrtiSamrTavtZmthZsymBamuLisuNkgbSarbBassDuplElbaGranKpelLomaMendMercNarbNbatPalmSindWaraAfakJurcMrooNshuShrdSoraTakrTangWoleHluwKhojTirhAghbMahjAhomHatrModiMultPaucSiddAdlmBhksMarcNewaOsgeHanbJamoZsyeGonmSoyoZanbDogrGongMakaMedfRohgSogdSogoElymHmnpNandWchoChrsDiakKitsYeziCpmnOugrTnsaTotoVithKawiNagmAranGaraGukhKraiOnaoSunuTodrTutgBerfSidtTayoTols", Vn = Oi.length / 4, rt = 0, Et = 1, Wn = 25, Po = 8, qo = 14;
|
|
1000
|
+
function mn(s) {
|
|
1001
|
+
return Oi.substring(s * 4, s * 4 + 4);
|
|
1002
|
+
}
|
|
1003
|
+
const Oo = [], Go = [];
|
|
1004
|
+
function Rn(s, t) {
|
|
1005
|
+
const n = t ? Go : Oo;
|
|
1006
|
+
let e = n[s];
|
|
1007
|
+
if (e === void 0) {
|
|
1008
|
+
try {
|
|
1009
|
+
e = new RegExp(`^\\p{${t ? "scx" : "sc"}=${mn(s)}}$`, "u");
|
|
1010
|
+
} catch {
|
|
1011
|
+
e = null;
|
|
1012
|
+
}
|
|
1013
|
+
n[s] = e;
|
|
1014
|
+
}
|
|
1015
|
+
return e;
|
|
1016
|
+
}
|
|
1017
|
+
let Ee = null;
|
|
1018
|
+
const Ln = [Wn, rt, Et, Po, qo], Mn = [[rt], [Wn]], Zs = /* @__PURE__ */ new Map();
|
|
1019
|
+
let Fn = null;
|
|
1020
|
+
const $s = /* @__PURE__ */ new Map();
|
|
1021
|
+
function Ce(s) {
|
|
1022
|
+
if (s < 128)
|
|
1023
|
+
return Mn[s >= 65 && s <= 90 || s >= 97 && s <= 122 ? 1 : 0];
|
|
1024
|
+
let t;
|
|
1025
|
+
if (s < 65536) {
|
|
1026
|
+
Fn || (Fn = new Uint16Array(65536));
|
|
1027
|
+
const n = Fn[s];
|
|
1028
|
+
if (n) return Mn[n - 1];
|
|
1029
|
+
t = Js(s), Fn[s] = t + 1;
|
|
1030
|
+
} else
|
|
1031
|
+
t = $s.get(s), t === void 0 && (t = Js(s), $s.set(s, t));
|
|
1032
|
+
return Mn[t];
|
|
1033
|
+
}
|
|
1034
|
+
function Js(s) {
|
|
1035
|
+
const t = String.fromCodePoint(s);
|
|
1036
|
+
let n = 103;
|
|
1037
|
+
for (let r = 0; r < Ln.length + Vn; r++) {
|
|
1038
|
+
const c = r < Ln.length ? Ln[r] : r - Ln.length, a = Rn(c, !1);
|
|
1039
|
+
if (a && a.test(t)) {
|
|
1040
|
+
n = c;
|
|
1041
|
+
break;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
let e = [n];
|
|
1045
|
+
if (!Ee) {
|
|
1046
|
+
let r = "";
|
|
1047
|
+
for (let c = 0; c < Vn; c++)
|
|
1048
|
+
Rn(c, !1) && Rn(c, !0) && (r += `${r ? "|" : ""}(?!\\p{sc=${mn(c)}})\\p{scx=${mn(c)}}`);
|
|
1049
|
+
Ee = new RegExp(`^(?:${r})$`, "u");
|
|
1050
|
+
}
|
|
1051
|
+
if (Ee.test(t)) {
|
|
1052
|
+
const r = [];
|
|
1053
|
+
for (let c = 0; c < Vn; c++) {
|
|
1054
|
+
const a = Rn(c, !0);
|
|
1055
|
+
a && a.test(t) && r.push(c);
|
|
1056
|
+
}
|
|
1057
|
+
r.length && (e = No(n, r));
|
|
1058
|
+
}
|
|
1059
|
+
const i = e.join(",");
|
|
1060
|
+
let o = Zs.get(i);
|
|
1061
|
+
return o === void 0 && (o = Mn.length, Mn.push(e), Zs.set(i, o)), o;
|
|
1062
|
+
}
|
|
1063
|
+
function No(s, t) {
|
|
1064
|
+
if (s === t[0]) return t;
|
|
1065
|
+
if (s !== Et && s !== rt) {
|
|
1066
|
+
const n = t.indexOf(s, 1);
|
|
1067
|
+
if (n < 0) {
|
|
1068
|
+
t.push(s);
|
|
1069
|
+
const e = t[0];
|
|
1070
|
+
t[0] = s, t[t.length - 1] = e;
|
|
1071
|
+
} else
|
|
1072
|
+
t[n] = t[0], t[0] = s;
|
|
1073
|
+
return t;
|
|
1074
|
+
}
|
|
1075
|
+
if (s === rt) {
|
|
1076
|
+
if (t.length === 1) return [rt, t[0]];
|
|
1077
|
+
for (let n = 1; n < t.length; n++)
|
|
1078
|
+
if (t[0] === Wn || t[n] < t[0]) {
|
|
1079
|
+
const e = t[0];
|
|
1080
|
+
t[0] = t[n], t[n] = e;
|
|
1081
|
+
}
|
|
1082
|
+
return t;
|
|
1083
|
+
}
|
|
1084
|
+
t.push(t[0]), t[0] = s;
|
|
1085
|
+
for (let n = 2; n < t.length; n++)
|
|
1086
|
+
if (t[1] === Wn || t[n] < t[1]) {
|
|
1087
|
+
const e = t[1];
|
|
1088
|
+
t[1] = t[n], t[n] = e;
|
|
1089
|
+
}
|
|
1090
|
+
return t;
|
|
1091
|
+
}
|
|
1092
|
+
const cn = [
|
|
1093
|
+
40,
|
|
1094
|
+
41,
|
|
1095
|
+
91,
|
|
1096
|
+
93,
|
|
1097
|
+
123,
|
|
1098
|
+
125,
|
|
1099
|
+
3898,
|
|
1100
|
+
3899,
|
|
1101
|
+
3900,
|
|
1102
|
+
3901,
|
|
1103
|
+
5787,
|
|
1104
|
+
5788,
|
|
1105
|
+
8261,
|
|
1106
|
+
8262,
|
|
1107
|
+
8317,
|
|
1108
|
+
8318,
|
|
1109
|
+
8333,
|
|
1110
|
+
8334,
|
|
1111
|
+
8968,
|
|
1112
|
+
8969,
|
|
1113
|
+
8970,
|
|
1114
|
+
8971,
|
|
1115
|
+
9001,
|
|
1116
|
+
9002,
|
|
1117
|
+
10088,
|
|
1118
|
+
10089,
|
|
1119
|
+
10090,
|
|
1120
|
+
10091,
|
|
1121
|
+
10092,
|
|
1122
|
+
10093,
|
|
1123
|
+
10094,
|
|
1124
|
+
10095,
|
|
1125
|
+
10096,
|
|
1126
|
+
10097,
|
|
1127
|
+
10098,
|
|
1128
|
+
10099,
|
|
1129
|
+
10100,
|
|
1130
|
+
10101,
|
|
1131
|
+
10181,
|
|
1132
|
+
10182,
|
|
1133
|
+
10214,
|
|
1134
|
+
10215,
|
|
1135
|
+
10216,
|
|
1136
|
+
10217,
|
|
1137
|
+
10218,
|
|
1138
|
+
10219,
|
|
1139
|
+
10220,
|
|
1140
|
+
10221,
|
|
1141
|
+
10222,
|
|
1142
|
+
10223,
|
|
1143
|
+
10627,
|
|
1144
|
+
10628,
|
|
1145
|
+
10629,
|
|
1146
|
+
10630,
|
|
1147
|
+
10631,
|
|
1148
|
+
10632,
|
|
1149
|
+
10633,
|
|
1150
|
+
10634,
|
|
1151
|
+
10635,
|
|
1152
|
+
10636,
|
|
1153
|
+
10637,
|
|
1154
|
+
10640,
|
|
1155
|
+
10639,
|
|
1156
|
+
10638,
|
|
1157
|
+
10641,
|
|
1158
|
+
10642,
|
|
1159
|
+
10643,
|
|
1160
|
+
10644,
|
|
1161
|
+
10645,
|
|
1162
|
+
10646,
|
|
1163
|
+
10647,
|
|
1164
|
+
10648,
|
|
1165
|
+
10712,
|
|
1166
|
+
10713,
|
|
1167
|
+
10714,
|
|
1168
|
+
10715,
|
|
1169
|
+
10748,
|
|
1170
|
+
10749,
|
|
1171
|
+
11810,
|
|
1172
|
+
11811,
|
|
1173
|
+
11812,
|
|
1174
|
+
11813,
|
|
1175
|
+
11814,
|
|
1176
|
+
11815,
|
|
1177
|
+
11816,
|
|
1178
|
+
11817,
|
|
1179
|
+
11861,
|
|
1180
|
+
11862,
|
|
1181
|
+
11863,
|
|
1182
|
+
11864,
|
|
1183
|
+
11865,
|
|
1184
|
+
11866,
|
|
1185
|
+
11867,
|
|
1186
|
+
11868,
|
|
1187
|
+
12296,
|
|
1188
|
+
12297,
|
|
1189
|
+
12298,
|
|
1190
|
+
12299,
|
|
1191
|
+
12300,
|
|
1192
|
+
12301,
|
|
1193
|
+
12302,
|
|
1194
|
+
12303,
|
|
1195
|
+
12304,
|
|
1196
|
+
12305,
|
|
1197
|
+
12308,
|
|
1198
|
+
12309,
|
|
1199
|
+
12310,
|
|
1200
|
+
12311,
|
|
1201
|
+
12312,
|
|
1202
|
+
12313,
|
|
1203
|
+
12314,
|
|
1204
|
+
12315,
|
|
1205
|
+
65113,
|
|
1206
|
+
65114,
|
|
1207
|
+
65115,
|
|
1208
|
+
65116,
|
|
1209
|
+
65117,
|
|
1210
|
+
65118,
|
|
1211
|
+
65288,
|
|
1212
|
+
65289,
|
|
1213
|
+
65339,
|
|
1214
|
+
65341,
|
|
1215
|
+
65371,
|
|
1216
|
+
65373,
|
|
1217
|
+
65375,
|
|
1218
|
+
65376,
|
|
1219
|
+
65378,
|
|
1220
|
+
65379
|
|
1221
|
+
];
|
|
1222
|
+
let an = null;
|
|
1223
|
+
function Ho(s) {
|
|
1224
|
+
if (s < 40 || s > 125 && s < 3898) return 0;
|
|
1225
|
+
if (!an) {
|
|
1226
|
+
an = /* @__PURE__ */ new Map();
|
|
1227
|
+
for (let t = 0; t < cn.length; t += 2)
|
|
1228
|
+
an.set(cn[t], cn[t + 1]), an.set(cn[t + 1], -cn[t]);
|
|
1229
|
+
}
|
|
1230
|
+
return an.get(s) ?? 0;
|
|
1231
|
+
}
|
|
1232
|
+
const Qs = 32, kt = [], Qt = [];
|
|
1233
|
+
let Dt = 0, zn = rt;
|
|
1234
|
+
const Ot = [];
|
|
1235
|
+
let tn = [], Ht = [];
|
|
1236
|
+
const ti = [];
|
|
1237
|
+
function ni(s) {
|
|
1238
|
+
let t = ti[s];
|
|
1239
|
+
return t || (ti[s] = t = [s]), t;
|
|
1240
|
+
}
|
|
1241
|
+
function Se() {
|
|
1242
|
+
const s = Ot[0];
|
|
1243
|
+
return s === rt ? zn : s;
|
|
1244
|
+
}
|
|
1245
|
+
function ei(s, t) {
|
|
1246
|
+
let n = Dt;
|
|
1247
|
+
if (n <= 0) return;
|
|
1248
|
+
n > kt.length && (n = kt.length);
|
|
1249
|
+
let e = kt.length - 1;
|
|
1250
|
+
for (t ? (e--, n--, Dt = 1) : Dt = 0; n > 0; e--, n--) Qt[e] = s;
|
|
1251
|
+
}
|
|
1252
|
+
function Bo() {
|
|
1253
|
+
const s = tn, t = Ot;
|
|
1254
|
+
if (s.length === 0 || t.length === 0) return !1;
|
|
1255
|
+
if (s.length === 1 && t.length === 1) {
|
|
1256
|
+
const c = s[0];
|
|
1257
|
+
return c <= Et ? !0 : t[0] <= Et ? (t[0] = c, !0) : t[0] === c;
|
|
1258
|
+
}
|
|
1259
|
+
let n = 0, e = t[n++];
|
|
1260
|
+
if (s[0] <= Et)
|
|
1261
|
+
return s.length === 2 && e <= Et && zn === rt && (zn = s[1]), !0;
|
|
1262
|
+
if (e <= Et)
|
|
1263
|
+
return Gi(Ot, s), !0;
|
|
1264
|
+
let i = s.indexOf(e) >= 0;
|
|
1265
|
+
if (n === t.length) return i;
|
|
1266
|
+
let o = 0;
|
|
1267
|
+
i || (e = s[o++], i = t.indexOf(e, n) >= 0);
|
|
1268
|
+
let r = 0;
|
|
1269
|
+
if (i && (t[r++] = e), o !== s.length)
|
|
1270
|
+
for (; n < t.length; n++) s.indexOf(t[n], o) >= 0 && (t[r++] = t[n]);
|
|
1271
|
+
return r > 0 ? (t.length = r, !0) : !1;
|
|
1272
|
+
}
|
|
1273
|
+
function Gi(s, t) {
|
|
1274
|
+
s.length = t.length;
|
|
1275
|
+
for (let n = 0; n < t.length; n++) s[n] = t[n];
|
|
1276
|
+
}
|
|
1277
|
+
function Ko(s, t, n, e) {
|
|
1278
|
+
if (t === 0) return 0;
|
|
1279
|
+
let i = rt, o = 0;
|
|
1280
|
+
for (; o < t; o++) {
|
|
1281
|
+
const l = Ce(s[o]);
|
|
1282
|
+
if (l.length !== 1) break;
|
|
1283
|
+
const h = l[0];
|
|
1284
|
+
if (!(h <= Et || h === i)) {
|
|
1285
|
+
if (i !== rt) break;
|
|
1286
|
+
i = h;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
if (o === t)
|
|
1290
|
+
return n[0] = t, e[0] = i, 1;
|
|
1291
|
+
kt.length = 0, Qt.length = 0, Dt = 0, zn = rt, Ot.length = 1, Ot[0] = rt, Ht = Ce(s[0]);
|
|
1292
|
+
let r = 1, c = s[0], a = 0;
|
|
1293
|
+
for (; Ot.length; ) {
|
|
1294
|
+
let l = !1;
|
|
1295
|
+
for (; r <= t; ) {
|
|
1296
|
+
const h = r - 1, f = c;
|
|
1297
|
+
tn = Ht, r === t ? r++ : (c = s[r++], Ht = Ce(c), Ht[0] === Et && Ht.length > 1 && (tn[0] === rt && (tn = Ht.slice(1)), Ht = ni(Et)));
|
|
1298
|
+
const u = Ho(f);
|
|
1299
|
+
if (u > 0)
|
|
1300
|
+
kt.length === Qs && (kt.shift(), Qt.shift(), Dt === Qs && Dt--), ei(Se(), !1), kt.push(f), Qt.push(rt), Dt++;
|
|
1301
|
+
else if (u < 0) {
|
|
1302
|
+
for (let p = kt.length - 1; p >= 0; p--)
|
|
1303
|
+
if (kt[p] === -u) {
|
|
1304
|
+
const y = Qt[p];
|
|
1305
|
+
y !== rt && (tn = ni(y));
|
|
1306
|
+
const _ = kt.length - 1 - p;
|
|
1307
|
+
kt.length -= _, Qt.length -= _, Dt = Math.max(0, Dt - _);
|
|
1308
|
+
break;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
if (!Bo()) {
|
|
1312
|
+
const p = Se();
|
|
1313
|
+
ei(p, u > 0), n[a] = h, e[a++] = p, Gi(Ot, tn), l = !0;
|
|
1314
|
+
break;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
l || (n[a] = t, e[a++] = Se(), Ot.length = 0);
|
|
1318
|
+
}
|
|
1319
|
+
return a;
|
|
1320
|
+
}
|
|
1321
|
+
const si = [];
|
|
1322
|
+
function Mt(s) {
|
|
1323
|
+
return (s.charCodeAt(0) << 24 | s.charCodeAt(1) << 16 | s.charCodeAt(2) << 8 | s.charCodeAt(3)) >>> 0;
|
|
1324
|
+
}
|
|
1325
|
+
const Yo = "Bengbng2Devadev2Gujrgjr2Gurugur2Kndaknd2Mlymmlm2Oryaory2Tamltml2Telutel2Mymrmym2", Vo = "HirakanaLaoolao Yiiiyi Nkoonko Vaiivai Zmthmath";
|
|
1326
|
+
function ii(s, t) {
|
|
1327
|
+
for (let n = 0; n < s.length; n += 8)
|
|
1328
|
+
if (s.substring(n, n + 4) === t) return s.substring(n + 4, n + 8);
|
|
1329
|
+
return "";
|
|
1330
|
+
}
|
|
1331
|
+
function Ni(s) {
|
|
1332
|
+
let t = si[s];
|
|
1333
|
+
if (!t) {
|
|
1334
|
+
t = [];
|
|
1335
|
+
const n = mn(s), e = ii(Yo, n);
|
|
1336
|
+
e && (e !== "mym2" && t.push(Mt(e.substring(0, 3) + "3")), t.push(Mt(e))), t.push(Mt(ii(Vo, n) || n.toLowerCase())), si[s] = t;
|
|
1337
|
+
}
|
|
1338
|
+
return t;
|
|
1339
|
+
}
|
|
1340
|
+
const Hi = 64, jn = 64, jo = ["abvm", "blwm", "mark", "mkmk", "curs", "dist", "kern"].map(Mt), Xo = Mt("kern"), oi = [Mt("DFLT"), Mt("dflt"), Mt("latn")], Ie = 0, De = 1, Pn = 2, Ut = new Uint16Array(0), Wo = new Int16Array(0), zo = new Uint32Array(0);
|
|
1341
|
+
class ln {
|
|
1342
|
+
constructor(t, n, e, i) {
|
|
1343
|
+
this._type = t, this._fmt = n, this._off = e, this._cov = i, this._cd1 = Ut, this._cd2 = Ut, this._cd3 = Ut, this._vf1 = 0, this._vf2 = 0, this._len1 = 0, this._len2 = 0, this._n1 = 0, this._n2 = 0, this._simple = !1, this._kx = Wo, this._ps = zo, this._sg = Ut;
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
class Zo {
|
|
1347
|
+
constructor(t, n, e) {
|
|
1348
|
+
this._props = t, this._set = n, this._subs = e;
|
|
1349
|
+
let i = 0;
|
|
1350
|
+
for (const r of e) i = Math.max(i, r._cov.length);
|
|
1351
|
+
const o = new Uint8Array(i);
|
|
1352
|
+
for (const r of e) {
|
|
1353
|
+
const c = r._cov;
|
|
1354
|
+
for (let a = 0; a < c.length; a++) c[a] !== Gt && (o[a] = 1);
|
|
1355
|
+
}
|
|
1356
|
+
this._any = o, this._pairs = e.length > 0 && e.every((r) => r._simple);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
class $o {
|
|
1360
|
+
constructor(t, n) {
|
|
1361
|
+
this._lookups = t, this._kern = n;
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
let gt = new DataView(new ArrayBuffer(0)), ri = 0, qn = 0, ci = 0, It = 0, Pt = null;
|
|
1365
|
+
const Re = new Int32Array(Hi * jn);
|
|
1366
|
+
function On(s, t, n) {
|
|
1367
|
+
let e = s;
|
|
1368
|
+
t & 1 && (C._xo[n] = C._xo[n] + gt.getInt16(e), e += 2), t & 2 && (C._yo[n] = C._yo[n] + gt.getInt16(e), e += 2), t & 4 && (C._xa[n] = C._xa[n] + gt.getInt16(e));
|
|
1369
|
+
}
|
|
1370
|
+
function Jo(s, t, n) {
|
|
1371
|
+
const e = C._gid, i = C._gp, o = C._xa, r = s._any, c = s._subs, a = s._props, l = s._set;
|
|
1372
|
+
for (let h = t; h < n; h++) {
|
|
1373
|
+
const f = e[h];
|
|
1374
|
+
if (f >= r.length || !r[f]) continue;
|
|
1375
|
+
const u = i[h];
|
|
1376
|
+
if (u & a & 14 || u & Ct && !dn(u, f, a, l)) continue;
|
|
1377
|
+
let p = h + 1;
|
|
1378
|
+
if (p >= n) break;
|
|
1379
|
+
const y = i[p];
|
|
1380
|
+
if ((y & (on | Ct) || y & a & 14) && (p = rs(h, n, a, l), p < 0))
|
|
815
1381
|
continue;
|
|
1382
|
+
const _ = e[p];
|
|
1383
|
+
for (let g = 0; g < c.length; g++) {
|
|
1384
|
+
const x = c[g], b = x._cov, M = f < b.length ? b[f] : Gt;
|
|
1385
|
+
if (M === Gt) continue;
|
|
1386
|
+
let k = -1;
|
|
1387
|
+
if (x._fmt === 1) {
|
|
1388
|
+
if (M >= x._ps.length - 1) continue;
|
|
1389
|
+
const w = x._sg;
|
|
1390
|
+
let T = x._ps[M], D = x._ps[M + 1] - 1;
|
|
1391
|
+
for (; T <= D; ) {
|
|
1392
|
+
const m = T + D >> 1, A = w[m];
|
|
1393
|
+
if (A < _) T = m + 1;
|
|
1394
|
+
else if (A > _) D = m - 1;
|
|
1395
|
+
else {
|
|
1396
|
+
k = m;
|
|
1397
|
+
break;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
} else {
|
|
1401
|
+
const w = f < x._cd1.length ? x._cd1[f] : 0, T = _ < x._cd2.length ? x._cd2[_] : 0;
|
|
1402
|
+
w < x._n1 && T < x._n2 && (k = w * x._n2 + T);
|
|
1403
|
+
}
|
|
1404
|
+
if (!(k < 0)) {
|
|
1405
|
+
o[h] = o[h] + x._kx[k], h = p - 1;
|
|
1406
|
+
break;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
function ai(s) {
|
|
1412
|
+
let t = 0;
|
|
1413
|
+
for (let n = s & 255; n; n &= n - 1) t++;
|
|
1414
|
+
return t * 2;
|
|
1415
|
+
}
|
|
1416
|
+
class Qo {
|
|
1417
|
+
/**
|
|
1418
|
+
* @param buffer Full font buffer.
|
|
1419
|
+
* @param offset Byte offset of the GPOS table.
|
|
1420
|
+
* @param gdef The font's GDEF (mark filtering sets), or null.
|
|
1421
|
+
*/
|
|
1422
|
+
constructor(t, n, e) {
|
|
1423
|
+
this._lookupCache = [], this._planCache = [], this._covCache = /* @__PURE__ */ new Map(), this._cdCache = /* @__PURE__ */ new Map();
|
|
1424
|
+
const i = new DataView(t);
|
|
1425
|
+
this._view = i, this._scripts = n + i.getUint16(n + 4), this._features = n + i.getUint16(n + 6), this._lookupList = n + i.getUint16(n + 8), this._gdef = e;
|
|
1426
|
+
}
|
|
1427
|
+
/** Coverage at `base + rel` (offset 0 = HarfBuzz's Null coverage). */
|
|
1428
|
+
_cov(t, n) {
|
|
1429
|
+
if (!n) return Ut;
|
|
1430
|
+
let e = this._covCache.get(t + n);
|
|
1431
|
+
return e || (e = qi(this._view, t + n), this._covCache.set(t + n, e)), e;
|
|
1432
|
+
}
|
|
1433
|
+
/** ClassDef at `base + rel` (offset 0 = every glyph class 0). */
|
|
1434
|
+
_cd(t, n) {
|
|
1435
|
+
if (!n) return Ut;
|
|
1436
|
+
let e = this._cdCache.get(t + n);
|
|
1437
|
+
return e || (e = ts(this._view, t + n), this._cdCache.set(t + n, e)), e;
|
|
1438
|
+
}
|
|
1439
|
+
/** Absolute offset of the Script table tagged `t`, or 0. */
|
|
1440
|
+
_script(t) {
|
|
1441
|
+
const n = this._view, e = this._scripts;
|
|
1442
|
+
for (let i = 0, o = n.getUint16(e); i < o; i++)
|
|
1443
|
+
if (n.getUint32(e + 2 + 6 * i) === t) return e + n.getUint16(e + 6 + 6 * i);
|
|
1444
|
+
return 0;
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* The lookups to apply to a run whose OpenType script tags (most
|
|
1448
|
+
* preferred first) are `tags`, cached under ICU script code `code`.
|
|
1449
|
+
* port of hb-ot-layout.cc: hb_ot_layout_table_select_script (falls back to
|
|
1450
|
+
* DFLT, dflt, then latn) + hb-ot-map.cc: hb_ot_map_builder_t::compile.
|
|
1451
|
+
*/
|
|
1452
|
+
_plan(t, n) {
|
|
1453
|
+
let e = this._planCache[t];
|
|
1454
|
+
if (e) return e;
|
|
1455
|
+
const i = this._view;
|
|
1456
|
+
let o = 0;
|
|
1457
|
+
for (let l = 0; l < n.length && !o; l++) o = this._script(n[l]);
|
|
1458
|
+
for (let l = 0; l < oi.length && !o; l++) o = this._script(oi[l]);
|
|
1459
|
+
const r = [];
|
|
1460
|
+
let c = !1;
|
|
1461
|
+
const a = o ? i.getUint16(o) : 0;
|
|
1462
|
+
if (a) {
|
|
1463
|
+
const l = o + a, h = i.getUint16(l + 2), f = this._features, u = i.getUint16(f), p = i.getUint16(l + 4);
|
|
1464
|
+
for (let y = -1; y < p; y++) {
|
|
1465
|
+
const _ = y < 0 ? h : i.getUint16(l + 6 + 2 * y);
|
|
1466
|
+
if (_ >= u) continue;
|
|
1467
|
+
const g = i.getUint32(f + 2 + 6 * _);
|
|
1468
|
+
if (y >= 0 && jo.indexOf(g) < 0) continue;
|
|
1469
|
+
g === Xo && (c = !0);
|
|
1470
|
+
const x = f + i.getUint16(f + 6 + 6 * _);
|
|
1471
|
+
for (let b = 0, M = i.getUint16(x + 2); b < M; b++) {
|
|
1472
|
+
const k = i.getUint16(x + 4 + 2 * b);
|
|
1473
|
+
r.indexOf(k) < 0 && r.push(k);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
return r.sort((l, h) => l - h), e = new $o(r, c), this._planCache[t] = e, e;
|
|
1478
|
+
}
|
|
1479
|
+
/** Lookup `li`, decoded on first use; null if out of range. */
|
|
1480
|
+
_lookup(t) {
|
|
1481
|
+
const n = this._lookupCache[t];
|
|
1482
|
+
if (n) return n;
|
|
1483
|
+
const e = this._view, i = this._lookupList;
|
|
1484
|
+
if (t >= e.getUint16(i)) return null;
|
|
1485
|
+
const o = i + e.getUint16(i + 2 + 2 * t), r = e.getUint16(o), c = e.getUint16(o + 2), a = e.getUint16(o + 4);
|
|
1486
|
+
let l = null;
|
|
1487
|
+
c & 16 && (l = this._gdef ? this._gdef._markSet(e.getUint16(o + 6 + 2 * a)) : Ut);
|
|
1488
|
+
const h = [];
|
|
1489
|
+
for (let u = 0; u < a; u++) {
|
|
1490
|
+
let p = o + e.getUint16(o + 6 + 2 * u), y = r;
|
|
1491
|
+
y === 9 && (y = e.getUint16(p + 2), p += e.getUint32(p + 4));
|
|
1492
|
+
const _ = this._sub(y, p);
|
|
1493
|
+
_ && h.push(_);
|
|
816
1494
|
}
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
1495
|
+
const f = new Zo(c, l, h);
|
|
1496
|
+
return this._lookupCache[t] = f, f;
|
|
1497
|
+
}
|
|
1498
|
+
/** Decodes one subtable; null for unsupported types/formats. */
|
|
1499
|
+
_sub(t, n) {
|
|
1500
|
+
const e = this._view, i = e.getUint16(n);
|
|
1501
|
+
if (t === 1 || t === 2) {
|
|
1502
|
+
if (i !== 1 && i !== 2) return null;
|
|
1503
|
+
const o = new ln(t, i, n, this._cov(n, e.getUint16(n + 2)));
|
|
1504
|
+
return o._vf1 = e.getUint16(n + 4), o._len1 = ai(o._vf1), t === 2 && (o._vf2 = e.getUint16(n + 6), o._len2 = ai(o._vf2), i === 2 && (o._cd1 = this._cd(n, e.getUint16(n + 8)), o._cd2 = this._cd(n, e.getUint16(n + 10)), o._n1 = e.getUint16(n + 12), o._n2 = e.getUint16(n + 14)), (o._vf1 & 15) === 4 && o._vf2 === 0 && this._decodePairs(o)), o;
|
|
822
1505
|
}
|
|
823
|
-
|
|
1506
|
+
if (t === 7) {
|
|
1507
|
+
if (i === 3) return new ln(t, i, n, this._cov(n, e.getUint16(n + 6)));
|
|
1508
|
+
if (i !== 1 && i !== 2) return null;
|
|
1509
|
+
const o = new ln(t, i, n, this._cov(n, e.getUint16(n + 2)));
|
|
1510
|
+
return i === 2 && (o._cd1 = this._cd(n, e.getUint16(n + 4))), o;
|
|
1511
|
+
}
|
|
1512
|
+
if (t === 8) {
|
|
1513
|
+
if (i === 3) {
|
|
1514
|
+
const r = e.getUint16(n + 2);
|
|
1515
|
+
return new ln(t, i, n, this._cov(n, e.getUint16(n + 6 + 2 * r)));
|
|
1516
|
+
}
|
|
1517
|
+
if (i !== 1 && i !== 2) return null;
|
|
1518
|
+
const o = new ln(t, i, n, this._cov(n, e.getUint16(n + 2)));
|
|
1519
|
+
return i === 2 && (o._cd1 = this._cd(n, e.getUint16(n + 4)), o._cd2 = this._cd(n, e.getUint16(n + 6)), o._cd3 = this._cd(n, e.getUint16(n + 8))), o;
|
|
1520
|
+
}
|
|
1521
|
+
return null;
|
|
1522
|
+
}
|
|
1523
|
+
/** Decodes a plain-kerning PairPos (XAdvance of the first glyph only) into typed arrays. */
|
|
1524
|
+
_decodePairs(t) {
|
|
1525
|
+
const n = this._view, e = t._off, i = t._len1;
|
|
1526
|
+
if (t._simple = !0, t._fmt === 2) {
|
|
1527
|
+
const h = t._n1 * t._n2, f = new Int16Array(h);
|
|
1528
|
+
for (let u = 0; u < h; u++) f[u] = n.getInt16(e + 16 + u * i);
|
|
1529
|
+
t._kx = f;
|
|
1530
|
+
return;
|
|
1531
|
+
}
|
|
1532
|
+
const o = n.getUint16(e + 8), r = new Uint32Array(o + 1);
|
|
1533
|
+
let c = 0;
|
|
1534
|
+
for (let h = 0; h < o; h++)
|
|
1535
|
+
r[h] = c, c += n.getUint16(e + n.getUint16(e + 10 + 2 * h));
|
|
1536
|
+
r[o] = c;
|
|
1537
|
+
const a = new Uint16Array(c), l = new Int16Array(c);
|
|
1538
|
+
for (let h = 0; h < o; h++) {
|
|
1539
|
+
const f = e + n.getUint16(e + 10 + 2 * h);
|
|
1540
|
+
for (let u = 0, p = r[h + 1] - r[h]; u < p; u++) {
|
|
1541
|
+
const y = f + 2 + u * (2 + i);
|
|
1542
|
+
a[r[h] + u] = n.getUint16(y), l[r[h] + u] = n.getInt16(y + 2);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
t._ps = r, t._sg = a, t._kx = l;
|
|
824
1546
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
1547
|
+
/**
|
|
1548
|
+
* Applies `plan` to `run[start, end)`, one HarfBuzz buffer (a script run).
|
|
1549
|
+
* port of hb-ot-layout.cc: apply_forward, for each lookup in turn.
|
|
1550
|
+
*/
|
|
1551
|
+
_position(t, n, e) {
|
|
1552
|
+
gt = this._view, ri = n, qn = e, ci = Math.max((e - n) * 64, 16384);
|
|
1553
|
+
const i = t._lookups;
|
|
1554
|
+
for (let o = 0; o < i.length; o++) {
|
|
1555
|
+
const r = this._lookup(i[o]);
|
|
1556
|
+
if (!r || !r._subs.length) continue;
|
|
1557
|
+
if (It = r._props, Pt = r._set, r._pairs) {
|
|
1558
|
+
Jo(r, n, e);
|
|
1559
|
+
continue;
|
|
1560
|
+
}
|
|
1561
|
+
const c = C._gp, a = C._gid, l = r._any;
|
|
1562
|
+
for (let h = n; h < e; ) {
|
|
1563
|
+
const f = a[h];
|
|
1564
|
+
if (f < l.length && l[f] && dn(c[h], f, It, Pt)) {
|
|
1565
|
+
const u = this._applyAt(r, h, 0);
|
|
1566
|
+
if (u >= 0) {
|
|
1567
|
+
h = u;
|
|
1568
|
+
continue;
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
h++;
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
/** First subtable of `lk` that applies at `i`: returns the next index, or −1. */
|
|
1576
|
+
_applyAt(t, n, e) {
|
|
1577
|
+
const i = t._subs;
|
|
1578
|
+
for (let o = 0; o < i.length; o++) {
|
|
1579
|
+
const r = this._applySub(i[o], n, e);
|
|
1580
|
+
if (r >= 0) return r;
|
|
1581
|
+
}
|
|
1582
|
+
return -1;
|
|
1583
|
+
}
|
|
1584
|
+
/** One subtable at glyph `i`: returns the index to continue from, or −1. */
|
|
1585
|
+
_applySub(t, n, e) {
|
|
1586
|
+
const i = C._gid[n], o = t._cov, r = i < o.length ? o[i] : Gt;
|
|
1587
|
+
if (r === Gt) return -1;
|
|
1588
|
+
const c = gt, a = t._off;
|
|
1589
|
+
switch (t._type) {
|
|
1590
|
+
case 1: {
|
|
1591
|
+
if (t._fmt === 1)
|
|
1592
|
+
On(a + 6, t._vf1, n);
|
|
1593
|
+
else {
|
|
1594
|
+
if (r >= c.getUint16(a + 6)) return -1;
|
|
1595
|
+
On(a + 8 + r * t._len1, t._vf1, n);
|
|
1596
|
+
}
|
|
1597
|
+
return n + 1;
|
|
1598
|
+
}
|
|
1599
|
+
case 2: {
|
|
1600
|
+
let l = n + 1;
|
|
1601
|
+
if (l >= qn) return -1;
|
|
1602
|
+
const h = C._gp[l];
|
|
1603
|
+
if ((h & (on | Ct) || h & It & 14) && (l = rs(n, qn, It, Pt), l < 0))
|
|
1604
|
+
return -1;
|
|
1605
|
+
const f = C._gid[l];
|
|
1606
|
+
if (t._simple) {
|
|
1607
|
+
const p = t._kx;
|
|
1608
|
+
if (t._fmt === 1) {
|
|
1609
|
+
if (r >= t._ps.length - 1) return -1;
|
|
1610
|
+
const g = t._sg;
|
|
1611
|
+
let x = t._ps[r], b = t._ps[r + 1] - 1;
|
|
1612
|
+
for (; x <= b; ) {
|
|
1613
|
+
const M = x + b >> 1, k = g[M];
|
|
1614
|
+
if (k < f) x = M + 1;
|
|
1615
|
+
else if (k > f) b = M - 1;
|
|
1616
|
+
else
|
|
1617
|
+
return C._xa[n] = C._xa[n] + p[M], l;
|
|
1618
|
+
}
|
|
1619
|
+
return -1;
|
|
1620
|
+
}
|
|
1621
|
+
const y = i < t._cd1.length ? t._cd1[i] : 0, _ = f < t._cd2.length ? t._cd2[f] : 0;
|
|
1622
|
+
return y >= t._n1 || _ >= t._n2 ? -1 : (C._xa[n] = C._xa[n] + p[y * t._n2 + _], l);
|
|
1623
|
+
}
|
|
1624
|
+
let u;
|
|
1625
|
+
if (t._fmt === 1) {
|
|
1626
|
+
if (r >= c.getUint16(a + 8)) return -1;
|
|
1627
|
+
const p = a + c.getUint16(a + 10 + 2 * r), y = 2 + t._len1 + t._len2;
|
|
1628
|
+
let _ = 0, g = c.getUint16(p) - 1;
|
|
1629
|
+
for (u = -1; _ <= g; ) {
|
|
1630
|
+
const x = _ + g >> 1, b = p + 2 + x * y, M = c.getUint16(b);
|
|
1631
|
+
if (M < f) _ = x + 1;
|
|
1632
|
+
else if (M > f) g = x - 1;
|
|
1633
|
+
else {
|
|
1634
|
+
u = b + 2;
|
|
1635
|
+
break;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
if (u < 0) return -1;
|
|
1639
|
+
} else {
|
|
1640
|
+
const p = i < t._cd1.length ? t._cd1[i] : 0, y = f < t._cd2.length ? t._cd2[f] : 0;
|
|
1641
|
+
if (p >= t._n1 || y >= t._n2) return -1;
|
|
1642
|
+
u = a + 16 + (p * t._n2 + y) * (t._len1 + t._len2);
|
|
1643
|
+
}
|
|
1644
|
+
return t._vf1 && On(u, t._vf1, n), t._vf2 && On(u + t._len1, t._vf2, l), t._len2 ? l + 1 : l;
|
|
1645
|
+
}
|
|
1646
|
+
case 7:
|
|
1647
|
+
return this._context(t, n, i, r, e);
|
|
1648
|
+
case 8:
|
|
1649
|
+
return this._chain(t, n, i, r, e);
|
|
1650
|
+
}
|
|
1651
|
+
return -1;
|
|
1652
|
+
}
|
|
1653
|
+
/** port of ContextFormat1/2/3::apply (SequenceContext). */
|
|
1654
|
+
_context(t, n, e, i, o) {
|
|
1655
|
+
const r = gt, c = t._off;
|
|
1656
|
+
if (t._fmt === 3) {
|
|
1657
|
+
const p = r.getUint16(c + 2), y = this._input(n, p, Pn, Ut, c + 8, c, o);
|
|
1658
|
+
return y < 0 ? -1 : (this._apply(c + 6 + 2 * p, r.getUint16(c + 4), p, o), y);
|
|
1659
|
+
}
|
|
1660
|
+
let a = i, l = c + 4, h = Ie;
|
|
1661
|
+
if (t._fmt === 2 && (a = e < t._cd1.length ? t._cd1[e] : 0, l = c + 6, h = De), a >= r.getUint16(l)) return -1;
|
|
1662
|
+
const f = r.getUint16(l + 2 + 2 * a);
|
|
1663
|
+
if (!f) return -1;
|
|
1664
|
+
const u = c + f;
|
|
1665
|
+
for (let p = 0, y = r.getUint16(u); p < y; p++) {
|
|
1666
|
+
const _ = u + r.getUint16(u + 2 + 2 * p), g = r.getUint16(_), x = this._input(n, g, h, t._cd1, _ + 4, 0, o);
|
|
1667
|
+
if (!(x < 0))
|
|
1668
|
+
return this._apply(_ + 4 + 2 * Math.max(g - 1, 0), r.getUint16(_ + 2), g, o), x;
|
|
1669
|
+
}
|
|
1670
|
+
return -1;
|
|
1671
|
+
}
|
|
1672
|
+
/** port of ChainContextFormat1/2/3::apply (ChainedSequenceContext). */
|
|
1673
|
+
_chain(t, n, e, i, o) {
|
|
1674
|
+
const r = gt, c = t._off;
|
|
1675
|
+
if (t._fmt === 3) {
|
|
1676
|
+
let p = c + 2;
|
|
1677
|
+
const y = r.getUint16(p), _ = p + 2;
|
|
1678
|
+
p += 2 + 2 * y;
|
|
1679
|
+
const g = r.getUint16(p), x = p + 2;
|
|
1680
|
+
p += 2 + 2 * g;
|
|
1681
|
+
const b = r.getUint16(p), M = p + 2;
|
|
1682
|
+
p += 2 + 2 * b;
|
|
1683
|
+
const k = this._input(n, g, Pn, Ut, x + 2, c, o);
|
|
1684
|
+
return k < 0 || !this._lookahead(k, b, Pn, Ut, M, c) || !this._backtrack(n, y, Pn, Ut, _, c) ? -1 : (this._apply(p + 2, r.getUint16(p), g, o), k);
|
|
1685
|
+
}
|
|
1686
|
+
let a = i, l = c + 4, h = Ie;
|
|
1687
|
+
if (t._fmt === 2 && (a = e < t._cd2.length ? t._cd2[e] : 0, l = c + 10, h = De), a >= r.getUint16(l)) return -1;
|
|
1688
|
+
const f = r.getUint16(l + 2 + 2 * a);
|
|
1689
|
+
if (!f) return -1;
|
|
1690
|
+
const u = c + f;
|
|
1691
|
+
for (let p = 0, y = r.getUint16(u); p < y; p++) {
|
|
1692
|
+
let _ = u + r.getUint16(u + 2 + 2 * p);
|
|
1693
|
+
const g = r.getUint16(_), x = _ + 2;
|
|
1694
|
+
_ += 2 + 2 * g;
|
|
1695
|
+
const b = r.getUint16(_), M = _ + 2;
|
|
1696
|
+
_ += 2 + 2 * Math.max(b - 1, 0);
|
|
1697
|
+
const k = r.getUint16(_), w = _ + 2;
|
|
1698
|
+
_ += 2 + 2 * k;
|
|
1699
|
+
const T = this._input(n, b, h, t._cd2, M, 0, o);
|
|
1700
|
+
if (!(T < 0) && this._lookahead(T, k, h, t._cd3, w, 0) && this._backtrack(n, g, h, t._cd1, x, 0))
|
|
1701
|
+
return this._apply(_ + 2, r.getUint16(_), b, o), T;
|
|
1702
|
+
}
|
|
1703
|
+
return -1;
|
|
1704
|
+
}
|
|
1705
|
+
/** Whether glyph `g` matches rule item `v` (glyph id, class, or coverage offset from `base`). */
|
|
1706
|
+
_matches(t, n, e, i, o) {
|
|
1707
|
+
if (t === Ie) return o === i;
|
|
1708
|
+
if (t === De) return (o < n.length ? n[o] : 0) === i;
|
|
1709
|
+
const r = this._cov(e, i);
|
|
1710
|
+
return o < r.length && r[o] !== Gt;
|
|
1711
|
+
}
|
|
1712
|
+
/**
|
|
1713
|
+
* Next glyph after `j` matching item `v`, or −1 (skipping_iterator_t::next
|
|
1714
|
+
* with a match function): ignored glyphs are skipped; a default ignorable
|
|
1715
|
+
* is skipped unless it matches; any other mismatch fails.
|
|
1716
|
+
*/
|
|
1717
|
+
_next(t, n, e, i, o) {
|
|
1718
|
+
const r = C._gp, c = C._gid;
|
|
1719
|
+
for (let a = t + 1; a < qn; a++) {
|
|
1720
|
+
const l = r[a], h = c[a];
|
|
1721
|
+
if (dn(l, h, It, Pt)) {
|
|
1722
|
+
if (this._matches(n, e, i, o, h)) return a;
|
|
1723
|
+
if (!(l & on))
|
|
1724
|
+
return -1;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
return -1;
|
|
1728
|
+
}
|
|
1729
|
+
/** skipping_iterator_t::prev counterpart of {@link Gpos._next}. */
|
|
1730
|
+
_prev(t, n, e, i, o) {
|
|
1731
|
+
const r = C._gp, c = C._gid;
|
|
1732
|
+
for (let a = t - 1; a >= ri; a--) {
|
|
1733
|
+
const l = r[a], h = c[a];
|
|
1734
|
+
if (dn(l, h, It, Pt)) {
|
|
1735
|
+
if (this._matches(n, e, i, o, h)) return a;
|
|
1736
|
+
if (!(l & on))
|
|
1737
|
+
return -1;
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
return -1;
|
|
1741
|
+
}
|
|
1742
|
+
/**
|
|
1743
|
+
* port of match_input: matches input items 1..count−1 (u16 values from
|
|
1744
|
+
* `seq`) after glyph `i`; records match positions for this nesting level.
|
|
1745
|
+
* Returns the match end (exclusive), or −1.
|
|
1746
|
+
*/
|
|
1747
|
+
_input(t, n, e, i, o, r, c) {
|
|
1748
|
+
if (n > jn) return -1;
|
|
1749
|
+
const a = c * jn;
|
|
1750
|
+
Re[a] = t;
|
|
1751
|
+
let l = t;
|
|
1752
|
+
for (let h = 1; h < n; h++) {
|
|
1753
|
+
if (l = this._next(l, e, i, r, gt.getUint16(o + 2 * (h - 1))), l < 0) return -1;
|
|
1754
|
+
Re[a + h] = l;
|
|
1755
|
+
}
|
|
1756
|
+
return l + 1;
|
|
1757
|
+
}
|
|
1758
|
+
/** port of match_lookahead, starting at `end`. */
|
|
1759
|
+
_lookahead(t, n, e, i, o, r) {
|
|
1760
|
+
let c = t - 1;
|
|
1761
|
+
for (let a = 0; a < n; a++)
|
|
1762
|
+
if (c = this._next(c, e, i, r, gt.getUint16(o + 2 * a)), c < 0) return !1;
|
|
1763
|
+
return !0;
|
|
1764
|
+
}
|
|
1765
|
+
/** port of match_backtrack (item 0 is the glyph right before `i`). */
|
|
1766
|
+
_backtrack(t, n, e, i, o, r) {
|
|
1767
|
+
let c = t;
|
|
1768
|
+
for (let a = 0; a < n; a++)
|
|
1769
|
+
if (c = this._prev(c, e, i, r, gt.getUint16(o + 2 * a)), c < 0) return !1;
|
|
1770
|
+
return !0;
|
|
1771
|
+
}
|
|
1772
|
+
/**
|
|
1773
|
+
* port of apply_lookup (GPOS: the buffer never changes length): applies
|
|
1774
|
+
* each SequenceLookupRecord at its matched position, in design order.
|
|
1775
|
+
*/
|
|
1776
|
+
_apply(t, n, e, i) {
|
|
1777
|
+
const o = i * jn;
|
|
1778
|
+
for (let r = 0; r < n; r++) {
|
|
1779
|
+
const c = gt.getUint16(t + 4 * r);
|
|
1780
|
+
if (c >= e || i + 1 >= Hi || ci-- <= 0) continue;
|
|
1781
|
+
const a = this._lookup(gt.getUint16(t + 4 * r + 2));
|
|
1782
|
+
if (!a) continue;
|
|
1783
|
+
const l = It, h = Pt;
|
|
1784
|
+
It = a._props, Pt = a._set, this._applyAt(a, Re[o + c], i + 1), It = l, Pt = h;
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
function tr(s) {
|
|
1789
|
+
if (s < 173) return !1;
|
|
1790
|
+
if (s < 65536) {
|
|
1791
|
+
switch (s >> 8) {
|
|
1792
|
+
case 0:
|
|
1793
|
+
return s === 173;
|
|
1794
|
+
case 3:
|
|
1795
|
+
return s === 847;
|
|
1796
|
+
case 6:
|
|
1797
|
+
return s === 1564;
|
|
1798
|
+
case 23:
|
|
1799
|
+
return s >= 6068 && s <= 6069;
|
|
1800
|
+
case 24:
|
|
1801
|
+
return s >= 6155 && s <= 6159;
|
|
1802
|
+
case 32:
|
|
1803
|
+
return s >= 8203 && s <= 8207 || s >= 8234 && s <= 8238 || s >= 8288 && s <= 8303;
|
|
1804
|
+
case 254:
|
|
1805
|
+
return s >= 65024 && s <= 65039 || s === 65279;
|
|
1806
|
+
case 255:
|
|
1807
|
+
return s >= 65520 && s <= 65528;
|
|
1808
|
+
}
|
|
1809
|
+
return !1;
|
|
1810
|
+
}
|
|
1811
|
+
return s >= 119155 && s <= 119162 || s >= 917504 && s <= 921599;
|
|
1812
|
+
}
|
|
1813
|
+
function nr(s, t, n) {
|
|
1814
|
+
const e = s.metrics.unitsPerEm;
|
|
1815
|
+
switch (t) {
|
|
1816
|
+
case 160:
|
|
1817
|
+
return s.advance(n);
|
|
1818
|
+
case 8193:
|
|
1819
|
+
case 8195:
|
|
1820
|
+
case 12288:
|
|
1821
|
+
return e;
|
|
1822
|
+
case 8192:
|
|
1823
|
+
case 8194:
|
|
1824
|
+
return e / 2;
|
|
1825
|
+
case 8196:
|
|
1826
|
+
return e / 3;
|
|
1827
|
+
case 8197:
|
|
1828
|
+
return e / 4;
|
|
1829
|
+
case 8198:
|
|
1830
|
+
return e / 6;
|
|
1831
|
+
case 8201:
|
|
1832
|
+
return e / 5;
|
|
1833
|
+
case 8202:
|
|
1834
|
+
return e / 16;
|
|
1835
|
+
case 8287:
|
|
1836
|
+
return e * 4 / 18;
|
|
1837
|
+
case 8239:
|
|
1838
|
+
return s.advance(n) / 2;
|
|
1839
|
+
case 8199: {
|
|
1840
|
+
for (let i = 48; i <= 57; i++) {
|
|
1841
|
+
const o = s.glyphId(i);
|
|
1842
|
+
if (o) return s.advance(o);
|
|
1843
|
+
}
|
|
1844
|
+
return s.advance(n);
|
|
1845
|
+
}
|
|
1846
|
+
case 8200: {
|
|
1847
|
+
const i = s.glyphId(46) || s.glyphId(44);
|
|
1848
|
+
return s.advance(i || n);
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
return -1;
|
|
1852
|
+
}
|
|
1853
|
+
let Le = null;
|
|
1854
|
+
const li = /* @__PURE__ */ new Map();
|
|
1855
|
+
function er(s) {
|
|
1856
|
+
if (s < 768) return !1;
|
|
1857
|
+
let t = li.get(s);
|
|
1858
|
+
return t === void 0 && (Le || (Le = new RegExp("^\\p{Mn}$", "u")), t = Le.test(String.fromCodePoint(s)), li.set(s, t)), t;
|
|
1859
|
+
}
|
|
1860
|
+
function sr(s, t) {
|
|
1861
|
+
const n = t.length;
|
|
1862
|
+
Fi(n);
|
|
1863
|
+
const e = C._cp, i = C._gid, o = C._gp, r = C._xa, c = C._xo, a = C._yo, l = s._glyphProps(), h = s._advances(), f = h.length ? h[h.length - 1] : 0, u = s.glyphId(32);
|
|
1864
|
+
let p = !1, y = 0, _ = 0;
|
|
1865
|
+
for (let M = 0; M < n; M++) {
|
|
1866
|
+
let k = t.charCodeAt(M);
|
|
1867
|
+
if (k >= 55296 && k < 56320 && M + 1 < n) {
|
|
1868
|
+
const A = t.charCodeAt(M + 1);
|
|
1869
|
+
A >= 56320 && A < 57344 && (k = (k - 55296 << 10) + (A - 56320) + 65536, M++);
|
|
1870
|
+
}
|
|
1871
|
+
let w = s.glyphId(k), T = -1;
|
|
1872
|
+
!w && k >= 160 && u && ((k === 8192 || k === 8193) && (w = s.glyphId(k + 2)), w || (T = nr(s, k, u), T >= 0 && (w = u)));
|
|
1873
|
+
const D = k >= 173 && tr(k);
|
|
1874
|
+
let m;
|
|
1875
|
+
l ? m = w < l.length ? l[w] : 0 : m = !D && er(k) ? Ct : Xn, D && (m |= k === 8204 ? xn : xn | on, p = !0), y |= m, e[_] = k, i[_] = w, o[_] = m, r[_] = T >= 0 ? T : w < h.length ? h[w] : f, c[_] = 0, a[_] = 0, _++;
|
|
1876
|
+
}
|
|
1877
|
+
const g = Ko(e, _, C._runEnd, C._runScript), x = (y & Ct) !== 0;
|
|
1878
|
+
let b = 0;
|
|
1879
|
+
for (let M = 0; M < g; M++) {
|
|
1880
|
+
const k = C._runEnd[M];
|
|
1881
|
+
Vi(s, b, k, C._runScript[M], x), b = k;
|
|
1882
|
+
}
|
|
1883
|
+
if (p)
|
|
1884
|
+
for (let M = 0; M < _; M++) o[M] & xn && (r[M] = c[M] = a[M] = 0);
|
|
1885
|
+
return _;
|
|
1886
|
+
}
|
|
1887
|
+
const cs = 0, Bi = 1, as = 2, ir = 3, ls = 4, Gn = as | ls, or = cs | ls, rr = as, hi = cs, Fe = Bi, cr = "BengDevaGujrGuruKndaMlymOryaTamlTelu", ar = "TibtMongSinhBuhdHanoTglgTagbLimbTaleBugiKharSyloTfngBaliNkooPhagChamKaliLepcRjngSaurSundEgypJavaKthiMteiLanaTavtBatkBrahMandCakmPlrdShrdTakrDuplGranKhojSindMahjManiModiHmngPhlpSiddTirhAhomMultAdlmBhksMarcNewaGonmSoyoZanbDogrGongRohgMakaMedfSogoSogdElymNandHmnpWchoChrsDiakKitsYeziCpmnOugrTnsaTotoVithKawiNagmGaraGukhKraiOnaoSunuTodrTutgBerfSidtTayoTolsJurcPcunSeal", Ki = Mt("DFLT"), Yi = Mt("latn"), lr = Mt("mymr"), fi = [Ki, Mt("dflt"), Yi];
|
|
1888
|
+
function hr(s, t) {
|
|
1889
|
+
if (!s) return 0;
|
|
1890
|
+
for (let n = 0; n < t.length; n++) if (s.indexOf(t[n]) >= 0) return t[n];
|
|
1891
|
+
for (let n = 0; n < 3; n++)
|
|
1892
|
+
if (s.indexOf(fi[n]) >= 0) return fi[n];
|
|
1893
|
+
return 0;
|
|
1894
|
+
}
|
|
1895
|
+
function fr(s, t) {
|
|
1896
|
+
const n = t === Ki || t === Yi;
|
|
1897
|
+
return s === "Thai" || s === "Laoo" ? rr : s === "Hang" ? or : s === "Khmr" ? hi : s === "Mymr" ? n || t === lr ? Gn : Fe : cr.indexOf(s) >= 0 ? n ? Gn : (t & 255) === 51 ? Fe : hi : ar.indexOf(s) >= 0 ? n ? Gn : Fe : Gn;
|
|
1898
|
+
}
|
|
1899
|
+
function ur(s, t) {
|
|
1900
|
+
const n = s._shaperCache();
|
|
1901
|
+
let e = n[t];
|
|
1902
|
+
return e < 0 && (e = fr(mn(t), hr(s._gsubScriptTags(), Ni(t))), n[t] = e), e;
|
|
1903
|
+
}
|
|
1904
|
+
function ui(s, t, n) {
|
|
1905
|
+
const e = C._gp, i = C._xa, o = C._xo;
|
|
1906
|
+
for (let r = s; r < t; r++)
|
|
1907
|
+
e[r] & Ct && (n && (o[r] = o[r] - i[r]), i[r] = 0);
|
|
829
1908
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
1909
|
+
function Vi(s, t, n, e, i) {
|
|
1910
|
+
const o = ur(s, e), r = s._gposTable(), c = s._kernTable(), a = r ? r._plan(e, Ni(e)) : null, l = c !== null && c._hasData && !(a && a._kern) && (o & ls) !== 0, h = !i || l && c._hasMachine ? cs : o & ir, f = !r && (!l || !c._hasCross);
|
|
1911
|
+
h === Bi && ui(t, n, f), a && r._position(a, t, n), l && c._apply(t, n), h === as && ui(t, n, f);
|
|
1912
|
+
}
|
|
1913
|
+
function pr(s, t, n) {
|
|
1914
|
+
Fi(2);
|
|
1915
|
+
const e = s._glyphProps(), i = s.advance(t), o = s.advance(n);
|
|
1916
|
+
return C._gid[0] = t, C._gid[1] = n, C._gp[0] = e ? t < e.length ? e[t] : 0 : Xn, C._gp[1] = e ? n < e.length ? e[n] : 0 : Xn, C._xa[0] = i, C._xa[1] = o, C._xo[0] = C._xo[1] = C._yo[0] = C._yo[1] = 0, Vi(s, 0, 2, rt, ((C._gp[0] | C._gp[1]) & Ct) !== 0), C._xa[0] + C._xa[1] - i - o;
|
|
1917
|
+
}
|
|
1918
|
+
function _r(s) {
|
|
1919
|
+
const t = new St(s);
|
|
833
1920
|
if (t.u32() === 1953784678) {
|
|
834
1921
|
if (t.skip(4), t.u32() === 0) throw new Error("TTC contains no fonts");
|
|
835
|
-
const
|
|
836
|
-
t.seek(
|
|
1922
|
+
const i = t.u32();
|
|
1923
|
+
t.seek(i);
|
|
837
1924
|
} else
|
|
838
1925
|
t.seek(0);
|
|
839
|
-
return
|
|
1926
|
+
return yr(s, t);
|
|
840
1927
|
}
|
|
841
|
-
function
|
|
1928
|
+
function yr(s, t) {
|
|
842
1929
|
t.skip(4);
|
|
843
1930
|
const n = t.u16();
|
|
844
1931
|
t.skip(6);
|
|
845
|
-
const
|
|
846
|
-
for (let
|
|
847
|
-
const
|
|
1932
|
+
const e = /* @__PURE__ */ new Map();
|
|
1933
|
+
for (let i = 0; i < n; i++) {
|
|
1934
|
+
const o = String.fromCharCode(t.u8(), t.u8(), t.u8(), t.u8());
|
|
848
1935
|
t.skip(4);
|
|
849
|
-
const
|
|
850
|
-
|
|
1936
|
+
const r = t.u32(), c = t.u32();
|
|
1937
|
+
e.set(o, { offset: r, length: c });
|
|
851
1938
|
}
|
|
852
|
-
return
|
|
1939
|
+
return e;
|
|
853
1940
|
}
|
|
854
|
-
|
|
1941
|
+
const pi = 2048, gr = 65536;
|
|
1942
|
+
class xr {
|
|
855
1943
|
/**
|
|
856
1944
|
* Parses a TrueType font from an ArrayBuffer.
|
|
857
1945
|
*
|
|
@@ -862,19 +1950,17 @@ class Yo {
|
|
|
862
1950
|
* @param buffer Raw font file bytes.
|
|
863
1951
|
*/
|
|
864
1952
|
constructor(t) {
|
|
865
|
-
this._buffer = t, this._tables =
|
|
866
|
-
const n = this._tables.get("head"),
|
|
1953
|
+
this._buffer = t, this._tables = _r(t);
|
|
1954
|
+
const n = this._tables.get("head"), e = this._tables.get("maxp"), i = this._tables.get("hhea"), o = this._tables.get("hmtx"), r = this._tables.get("loca"), c = this._tables.get("cmap");
|
|
867
1955
|
if (!n) throw new Error("Font missing required `head` table");
|
|
868
|
-
if (!
|
|
869
|
-
if (!
|
|
870
|
-
if (!
|
|
871
|
-
if (!
|
|
1956
|
+
if (!e) throw new Error("Font missing required `maxp` table");
|
|
1957
|
+
if (!i) throw new Error("Font missing required `hhea` table");
|
|
1958
|
+
if (!o) throw new Error("Font missing required `hmtx` table");
|
|
1959
|
+
if (!r) throw new Error("Font missing required `loca` table");
|
|
872
1960
|
if (!c) throw new Error("Font missing required `cmap` table");
|
|
873
|
-
this._head =
|
|
874
|
-
const
|
|
875
|
-
this._hhea =
|
|
876
|
-
const h = this._tables.get("kern");
|
|
877
|
-
this._kern = h ? Oo(t, h.offset) : () => 0, this.metrics = {
|
|
1961
|
+
this._head = eo(t, n.offset);
|
|
1962
|
+
const a = ro(t, e.offset);
|
|
1963
|
+
this._hhea = so(t, i.offset), this._hmtx = io(t, o.offset, a.numGlyphs, this._hhea.numberOfHMetrics), this._loca = oo(t, r.offset, a.numGlyphs, this._head.indexToLocFormat), this._cmap = Qi(t, c.offset), this._cmapCache = null, this._layoutLoaded = !1, this._gdef = null, this._gpos = null, this._kern = null, this._gsubScripts = null, this._shapers = null, this._advanceTable = null, this._pairCache = /* @__PURE__ */ new Map(), this.metrics = {
|
|
878
1964
|
unitsPerEm: this._head.unitsPerEm,
|
|
879
1965
|
ascender: this._hhea.ascender,
|
|
880
1966
|
descender: this._hhea.descender,
|
|
@@ -888,7 +1974,11 @@ class Yo {
|
|
|
888
1974
|
* @param codepoint Unicode scalar value.
|
|
889
1975
|
*/
|
|
890
1976
|
glyphId(t) {
|
|
891
|
-
return this._cmap(t);
|
|
1977
|
+
if (t >= pi || t < 0) return this._cmap(t);
|
|
1978
|
+
let n = this._cmapCache;
|
|
1979
|
+
n || (n = this._cmapCache = new Uint16Array(pi));
|
|
1980
|
+
let e = n[t];
|
|
1981
|
+
return e || (n[t] = e = this._cmap(t) + 1), e - 1;
|
|
892
1982
|
}
|
|
893
1983
|
/**
|
|
894
1984
|
* Total glyph count (`maxp.numGlyphs`), including `.notdef` at index 0.
|
|
@@ -918,14 +2008,63 @@ class Yo {
|
|
|
918
2008
|
return (this._hmtx[t] ?? this._hmtx[this._hmtx.length - 1] ?? { lsb: 0 }).lsb;
|
|
919
2009
|
}
|
|
920
2010
|
/**
|
|
921
|
-
* Kerning
|
|
922
|
-
*
|
|
2011
|
+
* Kerning between two glyphs in font units: how much positioning the pair
|
|
2012
|
+
* on its own changes its total advance (GPOS `kern` and other default
|
|
2013
|
+
* positioning features, else the legacy `kern` table, as Chrome applies
|
|
2014
|
+
* them). Pairwise only — {@link Atlas.layout} kerns whole runs, which also
|
|
2015
|
+
* accounts for script runs and contextual kerning.
|
|
923
2016
|
*
|
|
924
2017
|
* @param leftGlyphId Left glyph index.
|
|
925
2018
|
* @param rightGlyphId Right glyph index.
|
|
2019
|
+
* @returns Advance adjustment in font units, 0 for an unkerned pair.
|
|
926
2020
|
*/
|
|
927
2021
|
kerning(t, n) {
|
|
928
|
-
|
|
2022
|
+
const e = t < 32768 && n < 32768 ? t << 15 | n : -1 - (t * 65536 + n), i = this._pairCache.get(e);
|
|
2023
|
+
return i !== void 0 ? i : this._kerningMiss(e, t, n);
|
|
2024
|
+
}
|
|
2025
|
+
/** {@link Font.kerning}'s cache miss, kept out of line so the hit path stays small. */
|
|
2026
|
+
_kerningMiss(t, n, e) {
|
|
2027
|
+
const i = pr(this, n, e);
|
|
2028
|
+
return this._pairCache.size >= gr && this._pairCache.clear(), this._pairCache.set(t, i), i;
|
|
2029
|
+
}
|
|
2030
|
+
/** Parses GDEF, GPOS, kern and GSUB's script list on first use (keeps `new Font` cheap). */
|
|
2031
|
+
_loadLayout() {
|
|
2032
|
+
if (this._layoutLoaded) return;
|
|
2033
|
+
this._layoutLoaded = !0;
|
|
2034
|
+
const t = this._buffer, n = this._tables.get("GDEF"), e = this._tables.get("GPOS"), i = this._tables.get("kern"), o = this._tables.get("GSUB");
|
|
2035
|
+
n && (this._gdef = new Fo(t, n.offset, this.numGlyphs)), e && (this._gpos = new Qo(t, e.offset, this._gdef)), i && (this._kern = new Ro(t, i.offset)), o && (this._gsubScripts = Lo(new DataView(t), o.offset));
|
|
2036
|
+
}
|
|
2037
|
+
/** @internal GSUB's script tags, or null when the font has no GSUB. */
|
|
2038
|
+
_gsubScriptTags() {
|
|
2039
|
+
return this._loadLayout(), this._gsubScripts;
|
|
2040
|
+
}
|
|
2041
|
+
/** @internal Per-script shaper flags cache (see shaper.ts: shaperOf), -1 = unset. */
|
|
2042
|
+
_shaperCache() {
|
|
2043
|
+
let t = this._shapers;
|
|
2044
|
+
return t || (t = this._shapers = new Int8Array(Vn).fill(-1)), t;
|
|
2045
|
+
}
|
|
2046
|
+
/** @internal Advance widths by glyph id (dense copy of `hmtx` for layout). */
|
|
2047
|
+
_advances() {
|
|
2048
|
+
let t = this._advanceTable;
|
|
2049
|
+
if (!t) {
|
|
2050
|
+
const n = this._hmtx.length;
|
|
2051
|
+
t = new Uint16Array(n);
|
|
2052
|
+
for (let e = 0; e < n; e++) t[e] = this._hmtx[e].advanceWidth;
|
|
2053
|
+
this._advanceTable = t;
|
|
2054
|
+
}
|
|
2055
|
+
return t;
|
|
2056
|
+
}
|
|
2057
|
+
/** @internal GDEF glyph props per glyph, or null (classes are then synthesized). */
|
|
2058
|
+
_glyphProps() {
|
|
2059
|
+
return this._loadLayout(), this._gdef ? this._gdef._props : null;
|
|
2060
|
+
}
|
|
2061
|
+
/** @internal The GPOS table, or null. */
|
|
2062
|
+
_gposTable() {
|
|
2063
|
+
return this._loadLayout(), this._gpos;
|
|
2064
|
+
}
|
|
2065
|
+
/** @internal The legacy kern table, or null. */
|
|
2066
|
+
_kernTable() {
|
|
2067
|
+
return this._loadLayout(), this._kern;
|
|
929
2068
|
}
|
|
930
2069
|
/**
|
|
931
2070
|
* Parses and returns the outline of a glyph as a Shape (raw font units, y-up).
|
|
@@ -942,12 +2081,12 @@ class Yo {
|
|
|
942
2081
|
shape(t) {
|
|
943
2082
|
const n = this._tables.get("glyf");
|
|
944
2083
|
if (!n) return { contours: [], inverseYAxis: !1 };
|
|
945
|
-
const
|
|
946
|
-
return
|
|
2084
|
+
const e = this._loca, i = e[t] ?? 0, r = (e[t + 1] ?? i) - i;
|
|
2085
|
+
return To(
|
|
947
2086
|
this._buffer,
|
|
948
2087
|
n.offset,
|
|
949
|
-
|
|
950
|
-
|
|
2088
|
+
i,
|
|
2089
|
+
r,
|
|
951
2090
|
(c) => this._glyphRaw(c)
|
|
952
2091
|
);
|
|
953
2092
|
}
|
|
@@ -960,583 +2099,820 @@ class Yo {
|
|
|
960
2099
|
_glyphRaw(t) {
|
|
961
2100
|
const n = this._tables.get("glyf");
|
|
962
2101
|
if (!n) return [];
|
|
963
|
-
const
|
|
964
|
-
return
|
|
2102
|
+
const e = this._loca, i = e[t] ?? 0, r = (e[t + 1] ?? i) - i;
|
|
2103
|
+
return Li(
|
|
965
2104
|
this._buffer,
|
|
966
2105
|
n.offset,
|
|
967
|
-
|
|
968
|
-
|
|
2106
|
+
i,
|
|
2107
|
+
r,
|
|
969
2108
|
(c) => this._glyphRaw(c)
|
|
970
2109
|
);
|
|
971
2110
|
}
|
|
972
2111
|
}
|
|
973
|
-
function
|
|
2112
|
+
function dr(s, t) {
|
|
974
2113
|
const n = 1 / t;
|
|
975
|
-
for (const
|
|
976
|
-
for (let
|
|
977
|
-
const
|
|
978
|
-
if (
|
|
979
|
-
const
|
|
980
|
-
|
|
2114
|
+
for (const e of s.contours)
|
|
2115
|
+
for (let i = 0; i < e.length; i++) {
|
|
2116
|
+
const o = e[i];
|
|
2117
|
+
if (o.p0x *= n, o.p0y *= n, o.p1x *= n, o.p1y *= n, o.p2x *= n, o.p2y *= n, o.p3x *= n, o.p3y *= n, o.type === at) {
|
|
2118
|
+
const r = o.p1x - o.p0x, c = o.p1y - o.p0y, a = o.p2x - o.p1x, l = o.p2y - o.p1y;
|
|
2119
|
+
z(r, c, a, l) === 0 && (e[i] = new ot(ft, o.p0x, o.p0y, o.p2x, o.p2y, 0, 0, 0, 0));
|
|
2120
|
+
} else if (o.type === nn) {
|
|
2121
|
+
const r = o.p2x - o.p1x, c = o.p2y - o.p1y, a = 1.5 * o.p1x - 0.5 * o.p0x, l = 1.5 * o.p1y - 0.5 * o.p0y;
|
|
2122
|
+
z(o.p1x - o.p0x, o.p1y - o.p0y, r, c) === 0 && z(r, c, o.p3x - o.p2x, o.p3y - o.p2y) === 0 ? e[i] = new ot(ft, o.p0x, o.p0y, o.p3x, o.p3y, 0, 0, 0, 0) : a === 1.5 * o.p2x - 0.5 * o.p3x && l === 1.5 * o.p2y - 0.5 * o.p3y && (e[i] = new ot(at, o.p0x, o.p0y, a, l, o.p3x, o.p3y, 0, 0));
|
|
981
2123
|
}
|
|
982
2124
|
}
|
|
983
2125
|
}
|
|
984
|
-
const
|
|
985
|
-
function
|
|
986
|
-
switch (t[n] =
|
|
987
|
-
case
|
|
2126
|
+
const _i = 1e-6, Mr = 1.1111111111111112, wr = new Float64Array(16);
|
|
2127
|
+
function yi(s, t, n) {
|
|
2128
|
+
switch (t[n] = s.p0x, t[n + 1] = s.p0y, t[n + 2] = s.p1x, t[n + 3] = s.p1y, s.type) {
|
|
2129
|
+
case ft:
|
|
988
2130
|
return 1;
|
|
989
|
-
case
|
|
990
|
-
return t[n + 4] =
|
|
2131
|
+
case at:
|
|
2132
|
+
return t[n + 4] = s.p2x, t[n + 5] = s.p2y, 2;
|
|
991
2133
|
default:
|
|
992
|
-
return t[n + 4] =
|
|
2134
|
+
return t[n + 4] = s.p2x, t[n + 5] = s.p2y, t[n + 6] = s.p3x, t[n + 7] = s.p3y, 3;
|
|
993
2135
|
}
|
|
994
2136
|
}
|
|
995
|
-
function
|
|
2137
|
+
function gi(s, t, n) {
|
|
996
2138
|
if (n === 3) {
|
|
997
|
-
const
|
|
998
|
-
(
|
|
2139
|
+
const e = s[t], i = s[t + 1], o = s[t + 2], r = s[t + 3], c = s[t + 4], a = s[t + 5], l = s[t + 6], h = s[t + 7];
|
|
2140
|
+
(o === e && r === i || o === l && r === h) && (c === e && a === i || c === l && a === h) && (s[t + 2] = l, s[t + 3] = h, n = 1);
|
|
999
2141
|
}
|
|
1000
2142
|
if (n === 2) {
|
|
1001
|
-
const
|
|
1002
|
-
(
|
|
1003
|
-
}
|
|
1004
|
-
return n === 1 &&
|
|
1005
|
-
}
|
|
1006
|
-
function
|
|
1007
|
-
const n =
|
|
1008
|
-
let
|
|
1009
|
-
if (!(
|
|
1010
|
-
|
|
1011
|
-
const
|
|
1012
|
-
let c = 0,
|
|
1013
|
-
if (
|
|
1014
|
-
const
|
|
1015
|
-
|
|
1016
|
-
}
|
|
1017
|
-
if (
|
|
1018
|
-
const
|
|
1019
|
-
|
|
1020
|
-
}
|
|
1021
|
-
if (
|
|
1022
|
-
const
|
|
1023
|
-
|
|
1024
|
-
}
|
|
1025
|
-
if (
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
}
|
|
1029
|
-
c *=
|
|
1030
|
-
const
|
|
1031
|
-
if (
|
|
1032
|
-
const
|
|
1033
|
-
if (
|
|
1034
|
-
const st =
|
|
1035
|
-
if (st) return
|
|
1036
|
-
const
|
|
1037
|
-
return
|
|
1038
|
-
}
|
|
1039
|
-
let w = 1,
|
|
1040
|
-
if (
|
|
1041
|
-
const
|
|
1042
|
-
if (
|
|
1043
|
-
const
|
|
1044
|
-
if (
|
|
1045
|
-
const
|
|
1046
|
-
if (
|
|
1047
|
-
const st =
|
|
1048
|
-
return st ? w *
|
|
1049
|
-
}
|
|
1050
|
-
const
|
|
1051
|
-
return
|
|
1052
|
-
}
|
|
1053
|
-
function
|
|
1054
|
-
let
|
|
1055
|
-
if (
|
|
1056
|
-
const
|
|
1057
|
-
|
|
1058
|
-
}
|
|
1059
|
-
if (
|
|
2143
|
+
const e = s[t], i = s[t + 1], o = s[t + 2], r = s[t + 3], c = s[t + 4], a = s[t + 5];
|
|
2144
|
+
(o === e && r === i || o === c && r === a) && (s[t + 2] = c, s[t + 3] = a, n = 1);
|
|
2145
|
+
}
|
|
2146
|
+
return n === 1 && s[t] === s[t + 2] && s[t + 1] === s[t + 3] && (n = 0), n;
|
|
2147
|
+
}
|
|
2148
|
+
function Ar(s, t) {
|
|
2149
|
+
const n = wr;
|
|
2150
|
+
let e = yi(s, n, 0), i = yi(t, n, 8);
|
|
2151
|
+
if (!(e >= 1 && e <= 3 && i >= 1 && i <= 3) || n[e * 2] !== n[8] || n[e * 2 + 1] !== n[9]) return 0;
|
|
2152
|
+
e = gi(n, 0, e), i = gi(n, 8, i);
|
|
2153
|
+
const o = n[e * 2], r = n[e * 2 + 1];
|
|
2154
|
+
let c = 0, a = 0, l = 0, h = 0, f = 0, u = 0, p = 0, y = 0, _ = 0, g = 0, x = 0, b = 0;
|
|
2155
|
+
if (e >= 1 && (c = n[(e - 1) * 2] - o, a = n[(e - 1) * 2 + 1] - r), e >= 2) {
|
|
2156
|
+
const j = n[(e - 2) * 2] - n[(e - 1) * 2], W = n[(e - 2) * 2 + 1] - n[(e - 1) * 2 + 1];
|
|
2157
|
+
l = j - c, h = W - a;
|
|
2158
|
+
}
|
|
2159
|
+
if (e >= 3) {
|
|
2160
|
+
const j = n[(e - 3) * 2] - n[(e - 2) * 2], W = n[(e - 3) * 2 + 1] - n[(e - 2) * 2 + 1], et = n[(e - 2) * 2] - n[(e - 1) * 2], st = n[(e - 2) * 2 + 1] - n[(e - 1) * 2 + 1];
|
|
2161
|
+
f = j - et - l, u = W - st - h, l *= 3, h *= 3;
|
|
2162
|
+
}
|
|
2163
|
+
if (i >= 1 && (p = n[10] - o, y = n[11] - r), i >= 2) {
|
|
2164
|
+
const j = n[12] - n[10], W = n[13] - n[11];
|
|
2165
|
+
_ = j - p, g = W - y;
|
|
2166
|
+
}
|
|
2167
|
+
if (i >= 3) {
|
|
2168
|
+
const j = n[14] - n[12], W = n[15] - n[13], et = n[12] - n[10], st = n[13] - n[11];
|
|
2169
|
+
x = j - et - _, b = W - st - g, _ *= 3, g *= 3;
|
|
2170
|
+
}
|
|
2171
|
+
c *= e, a *= e, p *= i, y *= i;
|
|
2172
|
+
const M = c !== 0 || a !== 0;
|
|
2173
|
+
if (M && (p !== 0 || y !== 0)) {
|
|
2174
|
+
const j = Math.sqrt(c * c + a * a), W = Math.sqrt(p * p + y * y), et = j * z(c, a, _, g) + W * z(l, h, p, y);
|
|
2175
|
+
if (et) return pt(et);
|
|
2176
|
+
const st = j * j * z(c, a, x, b) + j * W * z(l, h, _, g) + W * W * z(f, u, p, y);
|
|
2177
|
+
if (st) return pt(st);
|
|
2178
|
+
const Lt = j * z(l, h, x, b) + W * z(f, u, _, g);
|
|
2179
|
+
return pt(Lt || z(f, u, x, b));
|
|
2180
|
+
}
|
|
2181
|
+
let w = 1, T = l, D = h, m = f, A = u, d = p, R = y, S = _, E = g, I = x, F = b;
|
|
2182
|
+
if (M && (T = _, D = g, m = x, A = b, d = c, R = a, S = l, E = h, I = f, F = u, w = -1), d !== 0 || R !== 0) {
|
|
2183
|
+
const j = z(m, A, d, R);
|
|
2184
|
+
if (j) return w * pt(j);
|
|
2185
|
+
const W = z(T, D, S, E);
|
|
2186
|
+
if (W) return w * pt(W);
|
|
2187
|
+
const et = z(m, A, S, E);
|
|
2188
|
+
if (et) return w * pt(et);
|
|
2189
|
+
const st = z(T, D, I, F);
|
|
2190
|
+
return st ? w * pt(st) : w * pt(z(m, A, I, F));
|
|
2191
|
+
}
|
|
2192
|
+
const V = Math.sqrt(T * T + D * D), B = Math.sqrt(S * S + E * E), nt = Math.sqrt(V) * z(T, D, I, F) + Math.sqrt(B) * z(m, A, S, E);
|
|
2193
|
+
return pt(nt || z(m, A, I, F));
|
|
2194
|
+
}
|
|
2195
|
+
function xi(s, t, n, e, i) {
|
|
2196
|
+
let o = s[t];
|
|
2197
|
+
if (o.type === at) {
|
|
2198
|
+
const r = o.convertToCubic();
|
|
2199
|
+
s[t] = r, o = r;
|
|
2200
|
+
}
|
|
2201
|
+
if (o.type === nn)
|
|
1060
2202
|
if (n === 0) {
|
|
1061
|
-
const
|
|
1062
|
-
|
|
2203
|
+
const r = Math.sqrt((o.p1x - o.p0x) ** 2 + (o.p1y - o.p0y) ** 2);
|
|
2204
|
+
o.p1x += r * e, o.p1y += r * i;
|
|
1063
2205
|
} else {
|
|
1064
|
-
const
|
|
1065
|
-
|
|
2206
|
+
const r = Math.sqrt((o.p2x - o.p3x) ** 2 + (o.p2y - o.p3y) ** 2);
|
|
2207
|
+
o.p2x += r * e, o.p2y += r * i;
|
|
1066
2208
|
}
|
|
1067
2209
|
}
|
|
1068
|
-
const
|
|
1069
|
-
function
|
|
1070
|
-
for (let t = 0; t <
|
|
1071
|
-
const n =
|
|
1072
|
-
let
|
|
1073
|
-
for (let
|
|
1074
|
-
const
|
|
1075
|
-
(
|
|
2210
|
+
const hn = [0, 0], fn = [0, 0];
|
|
2211
|
+
function br(s) {
|
|
2212
|
+
for (let t = 0; t < s.contours.length; t++) {
|
|
2213
|
+
const n = s.contours[t];
|
|
2214
|
+
let e = 0;
|
|
2215
|
+
for (let i = 0; i < n.length; i++) {
|
|
2216
|
+
const o = n[i];
|
|
2217
|
+
(o.p0x !== o.endX() || o.p0y !== o.endY()) && (n[e++] = o);
|
|
1076
2218
|
}
|
|
1077
|
-
n.length =
|
|
2219
|
+
n.length = e;
|
|
1078
2220
|
}
|
|
1079
|
-
for (const t of
|
|
2221
|
+
for (const t of s.contours)
|
|
1080
2222
|
if (t.length === 1) {
|
|
1081
|
-
const [n,
|
|
1082
|
-
t.length = 0, t.push(n,
|
|
2223
|
+
const [n, e, i] = t[0].splitInThirds();
|
|
2224
|
+
t.length = 0, t.push(n, e, i);
|
|
1083
2225
|
} else if (t.length > 0) {
|
|
1084
2226
|
const n = t.length;
|
|
1085
|
-
for (let
|
|
1086
|
-
const
|
|
1087
|
-
|
|
1088
|
-
const c = Math.sqrt(
|
|
1089
|
-
if (c === 0 ||
|
|
1090
|
-
const
|
|
1091
|
-
if (
|
|
1092
|
-
const
|
|
1093
|
-
let
|
|
1094
|
-
const
|
|
1095
|
-
if (
|
|
1096
|
-
|
|
2227
|
+
for (let e = 0; e < n; e++) {
|
|
2228
|
+
const i = (e + n - 1) % n, o = t[i], r = t[e];
|
|
2229
|
+
o.direction(1, hn), r.direction(0, fn);
|
|
2230
|
+
const c = Math.sqrt(hn[0] ** 2 + hn[1] ** 2), a = Math.sqrt(fn[0] ** 2 + fn[1] ** 2);
|
|
2231
|
+
if (c === 0 || a === 0) continue;
|
|
2232
|
+
const l = hn[0] / c, h = hn[1] / c, f = fn[0] / a, u = fn[1] / a;
|
|
2233
|
+
if (co(l, h, f, u) < _i - 1) {
|
|
2234
|
+
const p = _i - 1, y = Mr * Math.sqrt(1 - p * p) / p;
|
|
2235
|
+
let _ = f - l, g = u - h;
|
|
2236
|
+
const x = Math.sqrt(_ * _ + g * g);
|
|
2237
|
+
if (x === 0) continue;
|
|
2238
|
+
_ = y * _ / x, g = y * g / x, Ar(o, r) < 0 && (_ = -_, g = -g), xi(t, i, 1, -g, _), xi(t, e, 0, g, -_);
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
const di = 1e-5, ns = 1e-6, mr = 2e4, kr = 1e5;
|
|
2244
|
+
function Ur(s) {
|
|
2245
|
+
return [s.p0x, s.p0y, s.p1x, s.p1y, s.p2x, s.p2y, s.p3x, s.p3y].slice(0, 2 * s.type + 4);
|
|
2246
|
+
}
|
|
2247
|
+
function Mi(s) {
|
|
2248
|
+
const t = s.length / 2 - 2;
|
|
2249
|
+
return new ot(
|
|
2250
|
+
t,
|
|
2251
|
+
s[0],
|
|
2252
|
+
s[1],
|
|
2253
|
+
s[2],
|
|
2254
|
+
s[3],
|
|
2255
|
+
s[4] ?? 0,
|
|
2256
|
+
s[5] ?? 0,
|
|
2257
|
+
s[6] ?? 0,
|
|
2258
|
+
s[7] ?? 0
|
|
2259
|
+
);
|
|
2260
|
+
}
|
|
2261
|
+
const it = new Float64Array(8), ct = new Float64Array(8), Bt = new Float64Array(8);
|
|
2262
|
+
function es(s, t, n, e) {
|
|
2263
|
+
const i = s.length, o = i / 2 - 1;
|
|
2264
|
+
for (let r = 0; r <= o; r++) {
|
|
2265
|
+
for (let c = 0; c < i; c++) Bt[c] = s[c];
|
|
2266
|
+
for (let c = 0, a = i; c < o; c++, a -= 2) {
|
|
2267
|
+
const l = c < o - r ? t : n;
|
|
2268
|
+
for (let h = 0; h < a - 2; h++) Bt[h] = Bt[h] + l * (Bt[h + 2] - Bt[h]);
|
|
2269
|
+
}
|
|
2270
|
+
e[2 * r] = Bt[0], e[2 * r + 1] = Bt[1];
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
function Tr(s, t, n) {
|
|
2274
|
+
return es(s, t, n, it), Array.from(it.subarray(0, s.length));
|
|
2275
|
+
}
|
|
2276
|
+
let ss = 0, is = 0, Rt = -1, wn = -1, An = 0, bn = 0, Zn = 0, $n = 0;
|
|
2277
|
+
function vr(s, t) {
|
|
2278
|
+
Rt = -1, wn = -1;
|
|
2279
|
+
let n = 0;
|
|
2280
|
+
for (let h = 0; h < 2; h++) {
|
|
2281
|
+
const f = h ? s.length - 2 : 0;
|
|
2282
|
+
for (let u = 0; u < 2; u++) {
|
|
2283
|
+
const p = u ? t.length - 2 : 0;
|
|
2284
|
+
s[f] === t[p] && s[f + 1] === t[p + 1] && (n++, Rt = h, wn = u);
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
if (n !== 1) {
|
|
2288
|
+
Rt = -1;
|
|
2289
|
+
return;
|
|
2290
|
+
}
|
|
2291
|
+
const e = Rt ? s.length - 2 : 0;
|
|
2292
|
+
An = s[e], bn = s[e + 1];
|
|
2293
|
+
let i = 0, o = 0;
|
|
2294
|
+
for (let h = 2; h < s.length && i === 0 && o === 0; h += 2) {
|
|
2295
|
+
const f = Rt ? s.length - 2 - h : h;
|
|
2296
|
+
i = s[f] - An, o = s[f + 1] - bn;
|
|
2297
|
+
}
|
|
2298
|
+
let r = 0, c = 0;
|
|
2299
|
+
for (let h = 2; h < t.length && r === 0 && c === 0; h += 2) {
|
|
2300
|
+
const f = wn ? t.length - 2 - h : h;
|
|
2301
|
+
r = t[f] - An, c = t[f + 1] - bn;
|
|
2302
|
+
}
|
|
2303
|
+
const a = Math.hypot(i, o), l = Math.hypot(r, c);
|
|
2304
|
+
Zn = i / a - r / l, $n = o / a - c / l, Math.hypot(Zn, $n) > 1e-9 || (Rt = -1);
|
|
2305
|
+
}
|
|
2306
|
+
function Er(s, t) {
|
|
2307
|
+
const n = Rt ? s - 2 : 0;
|
|
2308
|
+
for (let i = 0; i < s; i += 2)
|
|
2309
|
+
if (i !== n && (it[i] - An) * Zn + (it[i + 1] - bn) * $n <= 0) return !1;
|
|
2310
|
+
const e = wn ? t - 2 : 0;
|
|
2311
|
+
for (let i = 0; i < t; i += 2)
|
|
2312
|
+
if (i !== e && (ct[i] - An) * Zn + (ct[i + 1] - bn) * $n >= 0) return !1;
|
|
2313
|
+
return !0;
|
|
2314
|
+
}
|
|
2315
|
+
function yn(s, t, n, e, i, o, r) {
|
|
2316
|
+
if (--ss < 0 || --is < 0) return;
|
|
2317
|
+
const c = s.length, a = e.length;
|
|
2318
|
+
es(s, t, n, it), es(e, i, o, ct);
|
|
2319
|
+
let l = 1 / 0, h = 1 / 0, f = -1 / 0, u = -1 / 0;
|
|
2320
|
+
for (let M = 0; M < c; M += 2)
|
|
2321
|
+
l = Math.min(l, it[M]), h = Math.min(h, it[M + 1]), f = Math.max(f, it[M]), u = Math.max(u, it[M + 1]);
|
|
2322
|
+
let p = 1 / 0, y = 1 / 0, _ = -1 / 0, g = -1 / 0;
|
|
2323
|
+
for (let M = 0; M < a; M += 2)
|
|
2324
|
+
p = Math.min(p, ct[M]), y = Math.min(y, ct[M + 1]), _ = Math.max(_, ct[M]), g = Math.max(g, ct[M + 1]);
|
|
2325
|
+
if (l > _ || p > f || h > g || y > u || Rt >= 0 && (Rt ? n === 1 : t === 0) && (wn ? o === 1 : i === 0) && Er(c, a))
|
|
2326
|
+
return;
|
|
2327
|
+
const x = Math.max(f - l, u - h), b = Math.max(_ - p, g - y);
|
|
2328
|
+
if (c === 4 && a === 4 || x < di && b < di) {
|
|
2329
|
+
const M = it[c - 2] - it[0], k = it[c - 1] - it[1], w = ct[a - 2] - ct[0], T = ct[a - 1] - ct[1], D = z(M, k, w, T), m = z(ct[0] - it[0], ct[1] - it[1], w, T) / D, A = z(ct[0] - it[0], ct[1] - it[1], M, k) / D;
|
|
2330
|
+
m >= 0 && m <= 1 && A >= 0 && A <= 1 && r.push(t + m * (n - t), i + A * (o - i));
|
|
2331
|
+
} else x > b ? (yn(s, t, (t + n) / 2, e, i, o, r), yn(s, (t + n) / 2, n, e, i, o, r)) : (yn(s, t, n, e, i, (i + o) / 2, r), yn(s, t, n, e, (i + o) / 2, o, r));
|
|
2332
|
+
}
|
|
2333
|
+
function Nn(s, t, n) {
|
|
2334
|
+
const e = s[2] - s[0], i = s[3] - s[1];
|
|
2335
|
+
return ((t - s[0]) * e + (n - s[1]) * i) / (e * e + i * i);
|
|
2336
|
+
}
|
|
2337
|
+
function Cr(s, t, n) {
|
|
2338
|
+
if (s.length !== 4 || t.length !== 4) return !1;
|
|
2339
|
+
const e = s[2] - s[0], i = s[3] - s[1], o = 1e-9 * Math.hypot(e, i);
|
|
2340
|
+
return Math.abs(z(e, i, t[0] - s[0], t[1] - s[1])) > o || Math.abs(z(e, i, t[2] - s[0], t[3] - s[1])) > o ? !1 : (n.push(Nn(s, t[0], t[1]), 0, Nn(s, t[2], t[3]), 1), n.push(0, Nn(t, s[0], s[1]), 1, Nn(t, s[2], s[3])), !0);
|
|
2341
|
+
}
|
|
2342
|
+
function Sr(s) {
|
|
2343
|
+
const t = [];
|
|
2344
|
+
for (let n = s.length - 2; n >= 0; n -= 2) t.push(s[n], s[n + 1]);
|
|
2345
|
+
return t;
|
|
2346
|
+
}
|
|
2347
|
+
function Ir(s, t) {
|
|
2348
|
+
if (s.length !== t.length) return !1;
|
|
2349
|
+
for (let n = 0; n < s.length; n++) if (!(Math.abs(s[n] - t[n]) < ns)) return !1;
|
|
2350
|
+
return !0;
|
|
2351
|
+
}
|
|
2352
|
+
const un = [0, 0], Kt = [0, 0], Jn = [0, 0, 0], Qn = [0, 0, 0];
|
|
2353
|
+
let en = new Int32Array(8);
|
|
2354
|
+
const Dr = 0, Rr = 1;
|
|
2355
|
+
function wi(s, t, n, e) {
|
|
2356
|
+
let i = 0;
|
|
2357
|
+
for (let o = 0; o < s.length; o++) {
|
|
2358
|
+
if (e < t[4 * o + 1] - 1e-9 || e > t[4 * o + 3] + 1e-9) continue;
|
|
2359
|
+
const r = s[o].scanlineIntersections(e, Jn, Qn);
|
|
2360
|
+
for (let c = 0; c < r; c++) Jn[c] <= n && (i += Qn[c]);
|
|
2361
|
+
}
|
|
2362
|
+
return i !== 0;
|
|
2363
|
+
}
|
|
2364
|
+
function Ai(s, t, n, e, i, o, r) {
|
|
2365
|
+
en.fill(0, 0, n);
|
|
2366
|
+
for (let a = 0; a < s.length; a++) {
|
|
2367
|
+
if (r < i[4 * a + 1] - 1e-9 || r > i[4 * a + 3] + 1e-9) continue;
|
|
2368
|
+
const l = s[a].scanlineIntersections(r, Jn, Qn);
|
|
2369
|
+
for (let h = 0; h < l; h++) Jn[h] <= o && (en[t[a]] += Qn[h]);
|
|
2370
|
+
}
|
|
2371
|
+
let c = !1;
|
|
2372
|
+
for (let a = 1; a < n && !c; a++) c = en[a] !== 0;
|
|
2373
|
+
return en[0] !== 0 && (e === Rr ? c : !c);
|
|
2374
|
+
}
|
|
2375
|
+
function Lr(s) {
|
|
2376
|
+
const t = Fr([s.contours]);
|
|
2377
|
+
t && (s.contours = t);
|
|
2378
|
+
}
|
|
2379
|
+
function Fr(s, t = Dr) {
|
|
2380
|
+
const n = s.flat(), e = n.flat(), i = e.map(Ur), o = i.length, r = s.length, c = r > 1;
|
|
2381
|
+
en.length < r && (en = new Int32Array(r));
|
|
2382
|
+
const a = new Float64Array(4 * o), l = new Int32Array(o), h = new Int32Array(o);
|
|
2383
|
+
let f = 0;
|
|
2384
|
+
for (let m = 0; m < r; m++)
|
|
2385
|
+
for (const A of s[m]) {
|
|
2386
|
+
for (let d = 0; d < A.length; d++)
|
|
2387
|
+
l[f + d] = f + (d + 1) % A.length, h[f + d] = m;
|
|
2388
|
+
f += A.length;
|
|
2389
|
+
}
|
|
2390
|
+
for (let m = 0; m < o; m++) {
|
|
2391
|
+
const A = i[m];
|
|
2392
|
+
let d = 1 / 0, R = 1 / 0, S = -1 / 0, E = -1 / 0;
|
|
2393
|
+
for (let I = 0; I < A.length; I += 2)
|
|
2394
|
+
d = Math.min(d, A[I]), R = Math.min(R, A[I + 1]), S = Math.max(S, A[I]), E = Math.max(E, A[I + 1]);
|
|
2395
|
+
a[4 * m] = d, a[4 * m + 1] = R, a[4 * m + 2] = S, a[4 * m + 3] = E;
|
|
2396
|
+
}
|
|
2397
|
+
const u = Array.from({ length: o }, (m, A) => A).sort((m, A) => a[4 * m] - a[4 * A]), p = i.map(() => []), y = new Uint8Array(o);
|
|
2398
|
+
is = kr;
|
|
2399
|
+
for (let m = 0; m < o; m++) {
|
|
2400
|
+
const A = u[m];
|
|
2401
|
+
for (let d = m + 1; d < o; d++) {
|
|
2402
|
+
const R = u[d];
|
|
2403
|
+
if (a[4 * R] > a[4 * A + 2]) break;
|
|
2404
|
+
if (a[4 * A + 1] > a[4 * R + 3] || a[4 * R + 1] > a[4 * A + 3]) continue;
|
|
2405
|
+
const S = Math.min(A, R), E = Math.max(A, R);
|
|
2406
|
+
l[S] !== E && l[E] !== S && (y[S] = y[E] = 1);
|
|
2407
|
+
const I = [];
|
|
2408
|
+
if (ss = mr, Cr(i[S], i[E], I) || (vr(i[S], i[E]), yn(i[S], 0, 1, i[E], 0, 1, I)), ss < 0 || is < 0) return null;
|
|
2409
|
+
for (let F = 0; F < I.length; F += 2)
|
|
2410
|
+
p[S].push(I[F]), p[E].push(I[F + 1]);
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
const _ = p.map((m) => {
|
|
2414
|
+
const A = [0];
|
|
2415
|
+
for (const d of m.sort((R, S) => R - S))
|
|
2416
|
+
d - A[A.length - 1] > 1e-7 && d < 1 - 1e-7 && A.push(d);
|
|
2417
|
+
return A.push(1), A;
|
|
2418
|
+
});
|
|
2419
|
+
let g = !1;
|
|
2420
|
+
const x = [], b = [];
|
|
2421
|
+
let M = 0;
|
|
2422
|
+
for (const m of n) {
|
|
2423
|
+
const A = M + m.length;
|
|
2424
|
+
let d = !0;
|
|
2425
|
+
for (let I = M; I < A; I++) (y[I] || _[I].length > 2) && (d = !1);
|
|
2426
|
+
let R = !1, S = !1, E = !1;
|
|
2427
|
+
for (let I = M; I < A; I++) {
|
|
2428
|
+
const F = _[I];
|
|
2429
|
+
for (let V = 1; V < F.length; V++) {
|
|
2430
|
+
const B = Tr(i[I], F[V - 1], F[V]), nt = Mi(B);
|
|
2431
|
+
nt.point(0.5, un), nt.direction(0.5, Kt);
|
|
2432
|
+
const j = Math.hypot(Kt[0], Kt[1]), W = Math.hypot(B[B.length - 2] - B[0], B[B.length - 1] - B[1]);
|
|
2433
|
+
if (!(j === 0 || W === 0)) {
|
|
2434
|
+
if (!d || !R) {
|
|
2435
|
+
const et = Math.min(1e-6, W * W / 64) / j, st = un[0] + Kt[1] * et, Lt = un[1] - Kt[0] * et, Xt = un[0] - Kt[1] * et, Wt = un[1] + Kt[0] * et;
|
|
2436
|
+
S = c ? Ai(e, h, r, t, a, st, Lt) : wi(e, a, st, Lt), E = c ? Ai(e, h, r, t, a, Xt, Wt) : wi(e, a, Xt, Wt), R = !0;
|
|
2437
|
+
}
|
|
2438
|
+
S === E ? h[I] === 0 && (g = !0) : (x.push(B), b.push(S), h[I] !== 0 && (g = !0));
|
|
1097
2439
|
}
|
|
1098
2440
|
}
|
|
1099
2441
|
}
|
|
2442
|
+
M = A;
|
|
2443
|
+
}
|
|
2444
|
+
const k = 2 * b.filter(Boolean).length >= b.length, w = [];
|
|
2445
|
+
for (let m = 0; m < x.length; m++) {
|
|
2446
|
+
let A = x[m];
|
|
2447
|
+
b[m] !== k && (A = Sr(A), g = !0);
|
|
2448
|
+
let d = !1;
|
|
2449
|
+
for (let R = 0; R < w.length && !d; R++) d = Ir(w[R], A);
|
|
2450
|
+
d ? g = !0 : w.push(A);
|
|
2451
|
+
}
|
|
2452
|
+
if (!g) return null;
|
|
2453
|
+
const T = new Uint8Array(w.length), D = [];
|
|
2454
|
+
for (let m = 0; m < w.length; m++) {
|
|
2455
|
+
if (T[m]) continue;
|
|
2456
|
+
T[m] = 1;
|
|
2457
|
+
const A = [w[m]];
|
|
2458
|
+
for (; ; ) {
|
|
2459
|
+
const d = A[A.length - 1], R = d[d.length - 2], S = d[d.length - 1];
|
|
2460
|
+
if (A.length > 1 && Math.hypot(R - A[0][0], S - A[0][1]) < ns) {
|
|
2461
|
+
A[0][0] = R, A[0][1] = S;
|
|
2462
|
+
break;
|
|
2463
|
+
}
|
|
2464
|
+
let E = -1, I = ns;
|
|
2465
|
+
for (let F = 0; F < w.length; F++) {
|
|
2466
|
+
if (T[F]) continue;
|
|
2467
|
+
const V = Math.hypot(w[F][0] - R, w[F][1] - S);
|
|
2468
|
+
V < I && (E = F, I = V);
|
|
2469
|
+
}
|
|
2470
|
+
if (E < 0) return null;
|
|
2471
|
+
T[E] = 1, w[E][0] = R, w[E][1] = S, A.push(w[E]);
|
|
2472
|
+
}
|
|
2473
|
+
D.push(A.map(Mi));
|
|
2474
|
+
}
|
|
2475
|
+
return D;
|
|
1100
2476
|
}
|
|
1101
|
-
const
|
|
1102
|
-
function
|
|
1103
|
-
return Math.trunc(3 + 2.875 *
|
|
2477
|
+
const ne = 1, ee = 2, Pr = 3, se = 4, qr = 5, Or = 6, hs = 7, ht = [0, 0], Yt = [0, 0];
|
|
2478
|
+
function Gr(s, t) {
|
|
2479
|
+
return Math.trunc(3 + 2.875 * s / (t - 1) - 1.4375 + 0.5) - 3;
|
|
1104
2480
|
}
|
|
1105
|
-
function
|
|
1106
|
-
return
|
|
2481
|
+
function Nr(s, t, n, e, i) {
|
|
2482
|
+
return s * n + t * e <= 0 || Math.abs(s * e - t * n) > i;
|
|
1107
2483
|
}
|
|
1108
|
-
function
|
|
1109
|
-
const t = Number(
|
|
1110
|
-
return
|
|
2484
|
+
function Hr(s) {
|
|
2485
|
+
const t = Number(s.v & 1n);
|
|
2486
|
+
return s.v >>= 1n, t;
|
|
1111
2487
|
}
|
|
1112
|
-
function
|
|
1113
|
-
const t = Number(
|
|
1114
|
-
return
|
|
2488
|
+
function Br(s) {
|
|
2489
|
+
const t = Number(s.v % 3n);
|
|
2490
|
+
return s.v /= 3n, t;
|
|
1115
2491
|
}
|
|
1116
|
-
function
|
|
1117
|
-
return [
|
|
2492
|
+
function bi(s) {
|
|
2493
|
+
return [Or, qr, Pr][Br(s)];
|
|
1118
2494
|
}
|
|
1119
|
-
function
|
|
1120
|
-
const n =
|
|
1121
|
-
|
|
2495
|
+
function gn(s, t) {
|
|
2496
|
+
const n = s.v << 1 + Hr(t);
|
|
2497
|
+
s.v = (n | n >> 3) & hs;
|
|
1122
2498
|
}
|
|
1123
|
-
function
|
|
1124
|
-
const
|
|
1125
|
-
|
|
2499
|
+
function Kr(s, t, n) {
|
|
2500
|
+
const e = s.v & n;
|
|
2501
|
+
e === ne || e === ee || e === se ? s.v = e ^ hs : gn(s, t);
|
|
1126
2502
|
}
|
|
1127
|
-
function
|
|
1128
|
-
const
|
|
1129
|
-
|
|
1130
|
-
const
|
|
1131
|
-
for (const c of
|
|
2503
|
+
function Yr(s, t, n = 0n) {
|
|
2504
|
+
const e = Math.sin(t), i = { v: bi({ v: n }) }, o = { v: n };
|
|
2505
|
+
o.v = n, i.v = bi(o);
|
|
2506
|
+
const r = [];
|
|
2507
|
+
for (const c of s.contours) {
|
|
1132
2508
|
if (c.length === 0) continue;
|
|
1133
|
-
|
|
1134
|
-
const
|
|
1135
|
-
let
|
|
1136
|
-
for (let
|
|
1137
|
-
const
|
|
1138
|
-
|
|
1139
|
-
const
|
|
1140
|
-
|
|
1141
|
-
const
|
|
1142
|
-
|
|
1143
|
-
}
|
|
1144
|
-
if (
|
|
1145
|
-
|
|
1146
|
-
for (const
|
|
1147
|
-
} else if (
|
|
1148
|
-
const
|
|
1149
|
-
|
|
1150
|
-
const
|
|
1151
|
-
if (
|
|
1152
|
-
for (let
|
|
1153
|
-
const
|
|
1154
|
-
c[(
|
|
2509
|
+
r.length = 0, c[c.length - 1].direction(1, ht);
|
|
2510
|
+
const l = Math.sqrt(ht[0] * ht[0] + ht[1] * ht[1]);
|
|
2511
|
+
let h = l > 0 ? ht[0] / l : 0, f = l > 0 ? ht[1] / l : 0;
|
|
2512
|
+
for (let u = 0; u < c.length; u++) {
|
|
2513
|
+
const p = c[u];
|
|
2514
|
+
p.direction(0, Yt);
|
|
2515
|
+
const y = Math.sqrt(Yt[0] * Yt[0] + Yt[1] * Yt[1]), _ = y > 0 ? Yt[0] / y : 0, g = y > 0 ? Yt[1] / y : 0;
|
|
2516
|
+
Nr(h, f, _, g, e) && r.push(u), p.direction(1, ht);
|
|
2517
|
+
const x = Math.sqrt(ht[0] * ht[0] + ht[1] * ht[1]);
|
|
2518
|
+
h = x > 0 ? ht[0] / x : 0, f = x > 0 ? ht[1] / x : 0;
|
|
2519
|
+
}
|
|
2520
|
+
if (r.length === 0) {
|
|
2521
|
+
gn(i, o);
|
|
2522
|
+
for (const u of c) u.color = i.v;
|
|
2523
|
+
} else if (r.length === 1) {
|
|
2524
|
+
const u = [0, hs, 0];
|
|
2525
|
+
gn(i, o), u[0] = i.v, gn(i, o), u[2] = i.v;
|
|
2526
|
+
const p = r[0], y = c.length;
|
|
2527
|
+
if (y >= 3)
|
|
2528
|
+
for (let _ = 0; _ < y; _++) {
|
|
2529
|
+
const g = Gr(_, y);
|
|
2530
|
+
c[(p + _) % y].color = u[1 + g];
|
|
1155
2531
|
}
|
|
1156
|
-
else if (
|
|
1157
|
-
const
|
|
1158
|
-
if (
|
|
1159
|
-
const
|
|
1160
|
-
|
|
2532
|
+
else if (y >= 1) {
|
|
2533
|
+
const _ = [null, null, null, null, null, null, null], g = c[0].splitInThirds();
|
|
2534
|
+
if (_[0 + 3 * p] = g[0], _[1 + 3 * p] = g[1], _[2 + 3 * p] = g[2], y >= 2) {
|
|
2535
|
+
const x = c[1].splitInThirds();
|
|
2536
|
+
_[3 - 3 * p] = x[0], _[4 - 3 * p] = x[1], _[5 - 3 * p] = x[2], _[0].color = _[1].color = u[0], _[2].color = _[3].color = u[1], _[4].color = _[5].color = u[2];
|
|
1161
2537
|
} else
|
|
1162
|
-
|
|
2538
|
+
_[0].color = u[0], _[1].color = u[1], _[2].color = u[2];
|
|
1163
2539
|
c.length = 0;
|
|
1164
|
-
for (const
|
|
2540
|
+
for (const x of _) x !== null && c.push(x);
|
|
1165
2541
|
}
|
|
1166
2542
|
} else {
|
|
1167
|
-
const
|
|
1168
|
-
let
|
|
1169
|
-
const
|
|
1170
|
-
|
|
1171
|
-
const
|
|
1172
|
-
for (let
|
|
1173
|
-
const
|
|
1174
|
-
|
|
2543
|
+
const u = r.length;
|
|
2544
|
+
let p = 0;
|
|
2545
|
+
const y = r[0], _ = c.length;
|
|
2546
|
+
gn(i, o);
|
|
2547
|
+
const g = i.v;
|
|
2548
|
+
for (let x = 0; x < _; x++) {
|
|
2549
|
+
const b = (y + x) % _;
|
|
2550
|
+
p + 1 < u && r[p + 1] === b && (++p, Kr(i, o, p === u - 1 ? g : 0)), c[b].color = i.v;
|
|
1175
2551
|
}
|
|
1176
2552
|
}
|
|
1177
2553
|
}
|
|
1178
2554
|
}
|
|
1179
|
-
const Y = Number.MAX_VALUE,
|
|
1180
|
-
let
|
|
1181
|
-
const
|
|
1182
|
-
let
|
|
1183
|
-
function
|
|
1184
|
-
const t =
|
|
2555
|
+
const Y = Number.MAX_VALUE, P = [0, 0], dt = [0, 0];
|
|
2556
|
+
let mi = 0, Z = new Float64Array(0), J = new Float64Array(0), N = new Float64Array(0), H = new Float64Array(0), Q = new Int32Array(0), tt = new Float64Array(0), Zt = new Float64Array(0), $t = new Float64Array(0), Jt = new Float64Array(0), Vt = new Int32Array(0);
|
|
2557
|
+
const $ = [0, 0];
|
|
2558
|
+
let ki = 0, Pe = new Float64Array(0), qe = new Float64Array(0), Oe = new Float64Array(0), Ge = new Float64Array(0), Ne = new Float64Array(0), He = new Float64Array(0), Be = new Float64Array(0), Ke = new Float64Array(0), Ye = new Float64Array(0), Ve = new Float64Array(0), je = new Float64Array(0), Xe = new Float64Array(0), Ui = 0, pn = new Int32Array(0);
|
|
2559
|
+
function Vr(s) {
|
|
2560
|
+
const t = s.length;
|
|
1185
2561
|
if (t === 0) return 0;
|
|
1186
2562
|
let n = 0;
|
|
1187
2563
|
if (t === 1) {
|
|
1188
|
-
|
|
1189
|
-
const
|
|
1190
|
-
|
|
1191
|
-
const
|
|
1192
|
-
|
|
1193
|
-
const c =
|
|
1194
|
-
n +=
|
|
2564
|
+
s[0].point(0, $);
|
|
2565
|
+
const e = $[0], i = $[1];
|
|
2566
|
+
s[0].point(1 / 3, $);
|
|
2567
|
+
const o = $[0], r = $[1];
|
|
2568
|
+
s[0].point(2 / 3, $);
|
|
2569
|
+
const c = $[0], a = $[1];
|
|
2570
|
+
n += e * r - i * o, n += o * a - r * c, n += c * i - a * e;
|
|
1195
2571
|
} else if (t === 2) {
|
|
1196
|
-
|
|
1197
|
-
const
|
|
1198
|
-
|
|
1199
|
-
const
|
|
1200
|
-
|
|
1201
|
-
const c =
|
|
1202
|
-
|
|
1203
|
-
const
|
|
1204
|
-
n +=
|
|
2572
|
+
s[0].point(0, $);
|
|
2573
|
+
const e = $[0], i = $[1];
|
|
2574
|
+
s[0].point(0.5, $);
|
|
2575
|
+
const o = $[0], r = $[1];
|
|
2576
|
+
s[1].point(0, $);
|
|
2577
|
+
const c = $[0], a = $[1];
|
|
2578
|
+
s[1].point(0.5, $);
|
|
2579
|
+
const l = $[0], h = $[1];
|
|
2580
|
+
n += e * r - i * o, n += o * a - r * c, n += c * h - a * l, n += l * i - h * e;
|
|
1205
2581
|
} else {
|
|
1206
|
-
const
|
|
1207
|
-
let
|
|
1208
|
-
for (let
|
|
1209
|
-
const c =
|
|
1210
|
-
n +=
|
|
2582
|
+
const e = s[t - 1];
|
|
2583
|
+
let i = e.p0x, o = e.p0y;
|
|
2584
|
+
for (let r = 0; r < t; r++) {
|
|
2585
|
+
const c = s[r].p0x, a = s[r].p0y;
|
|
2586
|
+
n += i * a - o * c, i = c, o = a;
|
|
1211
2587
|
}
|
|
1212
2588
|
}
|
|
1213
2589
|
return n > 0 ? -1 : n < 0 ? 1 : 0;
|
|
1214
2590
|
}
|
|
1215
|
-
function
|
|
1216
|
-
const c =
|
|
1217
|
-
let
|
|
1218
|
-
if (
|
|
1219
|
-
c.direction(0,
|
|
1220
|
-
const
|
|
1221
|
-
if (
|
|
1222
|
-
const
|
|
1223
|
-
c.point(0,
|
|
1224
|
-
const
|
|
1225
|
-
if (
|
|
1226
|
-
const
|
|
1227
|
-
Math.abs(
|
|
2591
|
+
function jr(s, t, n, e, i, o, r) {
|
|
2592
|
+
const c = r[s][t];
|
|
2593
|
+
let a = n;
|
|
2594
|
+
if (o < 0) {
|
|
2595
|
+
c.direction(0, P);
|
|
2596
|
+
const l = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
|
|
2597
|
+
if (l > 0) {
|
|
2598
|
+
const h = P[0] / l, f = P[1] / l;
|
|
2599
|
+
c.point(0, dt);
|
|
2600
|
+
const u = e - dt[0], p = i - dt[1];
|
|
2601
|
+
if (u * h + p * f < 0) {
|
|
2602
|
+
const _ = u * f - p * h;
|
|
2603
|
+
Math.abs(_) <= Math.abs(a) && (a = _);
|
|
1228
2604
|
}
|
|
1229
2605
|
}
|
|
1230
2606
|
}
|
|
1231
|
-
if (
|
|
1232
|
-
c.direction(1,
|
|
1233
|
-
const
|
|
1234
|
-
if (
|
|
1235
|
-
const
|
|
1236
|
-
c.point(1,
|
|
1237
|
-
const
|
|
1238
|
-
if (
|
|
1239
|
-
const
|
|
1240
|
-
Math.abs(
|
|
2607
|
+
if (o > 1) {
|
|
2608
|
+
c.direction(1, P);
|
|
2609
|
+
const l = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
|
|
2610
|
+
if (l > 0) {
|
|
2611
|
+
const h = P[0] / l, f = P[1] / l;
|
|
2612
|
+
c.point(1, dt);
|
|
2613
|
+
const u = e - dt[0], p = i - dt[1];
|
|
2614
|
+
if (u * h + p * f > 0) {
|
|
2615
|
+
const _ = u * f - p * h;
|
|
2616
|
+
Math.abs(_) <= Math.abs(a) && (a = _);
|
|
1241
2617
|
}
|
|
1242
2618
|
}
|
|
1243
2619
|
}
|
|
1244
|
-
return
|
|
2620
|
+
return a;
|
|
1245
2621
|
}
|
|
1246
|
-
function
|
|
1247
|
-
let
|
|
1248
|
-
if (
|
|
1249
|
-
const
|
|
1250
|
-
Math.abs(
|
|
2622
|
+
function yt(s, t, n, e, i, o, r, c, a) {
|
|
2623
|
+
let l = s < 0 ? t : n;
|
|
2624
|
+
if (i >= 0) {
|
|
2625
|
+
const h = jr(e, i, s, r, c, o, a);
|
|
2626
|
+
Math.abs(h) < Math.abs(l) && (l = h);
|
|
1251
2627
|
}
|
|
1252
|
-
return
|
|
2628
|
+
return l;
|
|
1253
2629
|
}
|
|
1254
|
-
function
|
|
1255
|
-
return Math.max(Math.min(
|
|
2630
|
+
function mt(s, t, n) {
|
|
2631
|
+
return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
|
|
1256
2632
|
}
|
|
1257
|
-
function
|
|
2633
|
+
function Xr(s, t, n, e, i, o, r, c) {
|
|
1258
2634
|
if (c.length !== t * n * 3)
|
|
1259
2635
|
throw new Error(`generateMSDF: out.length ${c.length} !== ${t * n * 3}`);
|
|
1260
|
-
const
|
|
1261
|
-
if (
|
|
2636
|
+
const a = s.contours, l = a.length;
|
|
2637
|
+
if (l === 0) {
|
|
1262
2638
|
c.fill(0);
|
|
1263
2639
|
return;
|
|
1264
2640
|
}
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
for (let
|
|
1268
|
-
|
|
1269
|
-
let
|
|
1270
|
-
for (let
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
for (let
|
|
1274
|
-
const
|
|
1275
|
-
for (let
|
|
1276
|
-
const
|
|
1277
|
-
|
|
1278
|
-
let
|
|
1279
|
-
const
|
|
1280
|
-
|
|
1281
|
-
const
|
|
1282
|
-
|
|
1283
|
-
const
|
|
1284
|
-
|
|
1285
|
-
const
|
|
1286
|
-
|
|
1287
|
-
const nt =
|
|
1288
|
-
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
if (
|
|
1292
|
-
const
|
|
1293
|
-
|
|
1294
|
-
}
|
|
1295
|
-
const
|
|
1296
|
-
for (let
|
|
1297
|
-
for (let
|
|
1298
|
-
const
|
|
1299
|
-
for (let
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1302
|
-
for (let
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1305
|
-
const
|
|
1306
|
-
if (
|
|
1307
|
-
const
|
|
1308
|
-
(
|
|
2641
|
+
const h = e / r;
|
|
2642
|
+
Vt.length < l && (Vt = new Int32Array(l));
|
|
2643
|
+
for (let p = 0; p < l; p++) Vt[p] = Vr(a[p]);
|
|
2644
|
+
Ui < l + 1 && (pn = new Int32Array(l + 1), Ui = l + 1);
|
|
2645
|
+
let f = 0;
|
|
2646
|
+
for (let p = 0; p < l; p++)
|
|
2647
|
+
pn[p] = f, f += a[p].length;
|
|
2648
|
+
pn[l] = f, ki < f && (Pe = new Float64Array(f), qe = new Float64Array(f), Oe = new Float64Array(f), Ge = new Float64Array(f), Ne = new Float64Array(f), He = new Float64Array(f), Be = new Float64Array(f), Ke = new Float64Array(f), Ye = new Float64Array(f), Ve = new Float64Array(f), je = new Float64Array(f), Xe = new Float64Array(f), ki = f);
|
|
2649
|
+
for (let p = 0; p < l; p++) {
|
|
2650
|
+
const y = a[p], _ = y.length, g = pn[p];
|
|
2651
|
+
for (let x = 0; x < _; x++) {
|
|
2652
|
+
const b = y[x], M = y[(x + _ - 1) % _], k = y[(x + 1) % _], w = g + x;
|
|
2653
|
+
b.point(0, dt), Pe[w] = dt[0], qe[w] = dt[1], b.point(1, dt), Oe[w] = dt[0], Ge[w] = dt[1], b.direction(0, P);
|
|
2654
|
+
let T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
|
|
2655
|
+
const D = T > 0 ? P[0] / T : 0, m = T > 0 ? P[1] / T : 0;
|
|
2656
|
+
Ne[w] = D, He[w] = m, b.direction(1, P), T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
|
|
2657
|
+
const A = T > 0 ? P[0] / T : 0, d = T > 0 ? P[1] / T : 0;
|
|
2658
|
+
Be[w] = A, Ke[w] = d, M.direction(1, P), T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
|
|
2659
|
+
const R = T > 0 ? P[0] / T : 0, S = T > 0 ? P[1] / T : 0;
|
|
2660
|
+
k.direction(0, P), T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
|
|
2661
|
+
const E = T > 0 ? P[0] / T : 0, I = T > 0 ? P[1] / T : 0, F = R + D, V = S + m, B = Math.sqrt(F * F + V * V);
|
|
2662
|
+
Ye[w] = B > 0 ? F / B : 0, Ve[w] = B > 0 ? V / B : 0;
|
|
2663
|
+
const nt = A + E, j = d + I, W = Math.sqrt(nt * nt + j * j);
|
|
2664
|
+
je[w] = W > 0 ? -(nt / W) : 0, Xe[w] = W > 0 ? -(j / W) : 0;
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
if (mi < l) {
|
|
2668
|
+
const p = l * 3;
|
|
2669
|
+
Z = new Float64Array(p), J = new Float64Array(p), N = new Float64Array(p), H = new Float64Array(p), Q = new Int32Array(p), tt = new Float64Array(p), Zt = new Float64Array(l), $t = new Float64Array(l), Jt = new Float64Array(l), mi = l;
|
|
2670
|
+
}
|
|
2671
|
+
const u = { distance: 0, dot: 0, param: 0 };
|
|
2672
|
+
for (let p = 0; p < n; p++)
|
|
2673
|
+
for (let y = 0; y < t; y++) {
|
|
2674
|
+
const _ = (y + 0.5) / e - i, g = (p + 0.5) / e - o;
|
|
2675
|
+
for (let L = 0; L < l; L++) {
|
|
2676
|
+
const v = a[L], ut = v.length, U = L * 3, O = pn[L];
|
|
2677
|
+
Z[U] = Z[U + 1] = Z[U + 2] = -Y, J[U] = J[U + 1] = J[U + 2] = 0, N[U] = N[U + 1] = N[U + 2] = -Y, H[U] = H[U + 1] = H[U + 2] = Y, Q[U] = Q[U + 1] = Q[U + 2] = -1, tt[U] = tt[U + 1] = tt[U + 2] = 0;
|
|
2678
|
+
for (let G = 0; G < ut; G++) {
|
|
2679
|
+
const X = v[G], Me = X.color, we = (Me & ne) !== 0, Ae = (Me & ee) !== 0, be = (Me & se) !== 0;
|
|
2680
|
+
X.signedDistance(_, g, u);
|
|
2681
|
+
const In = u.distance, zt = u.dot, me = u.param, Ft = Math.abs(In);
|
|
2682
|
+
if (we) {
|
|
2683
|
+
const Tt = Math.abs(Z[U]);
|
|
2684
|
+
(Ft < Tt || Ft === Tt && zt < J[U]) && (Z[U] = In, J[U] = zt, Q[U] = G, tt[U] = me);
|
|
1309
2685
|
}
|
|
1310
|
-
if (
|
|
1311
|
-
const
|
|
1312
|
-
(
|
|
2686
|
+
if (Ae) {
|
|
2687
|
+
const Tt = Math.abs(Z[U + 1]);
|
|
2688
|
+
(Ft < Tt || Ft === Tt && zt < J[U + 1]) && (Z[U + 1] = In, J[U + 1] = zt, Q[U + 1] = G, tt[U + 1] = me);
|
|
1313
2689
|
}
|
|
1314
|
-
if (
|
|
1315
|
-
const
|
|
1316
|
-
(
|
|
2690
|
+
if (be) {
|
|
2691
|
+
const Tt = Math.abs(Z[U + 2]);
|
|
2692
|
+
(Ft < Tt || Ft === Tt && zt < J[U + 2]) && (Z[U + 2] = In, J[U + 2] = zt, Q[U + 2] = G, tt[U + 2] = me);
|
|
1317
2693
|
}
|
|
1318
|
-
const
|
|
1319
|
-
if (
|
|
1320
|
-
const
|
|
1321
|
-
Math.abs(
|
|
2694
|
+
const _t = O + G, ke = _ - Pe[_t], Ue = g - qe[_t], Te = _ - Oe[_t], ve = g - Ge[_t], Hs = Ne[_t], Bs = He[_t], Ks = Be[_t], Ys = Ke[_t], $i = ke * Ye[_t] + Ue * Ve[_t], Ji = Te * je[_t] + ve * Xe[_t];
|
|
2695
|
+
if ($i > 0 && -(ke * Hs + Ue * Bs) > 0) {
|
|
2696
|
+
const q = ke * Bs - Ue * Hs;
|
|
2697
|
+
Math.abs(q) < Ft && (we && (q <= 0 && q > N[U] ? N[U] = q : q > 0 && q < H[U] && (H[U] = q)), Ae && (q <= 0 && q > N[U + 1] ? N[U + 1] = q : q > 0 && q < H[U + 1] && (H[U + 1] = q)), be && (q <= 0 && q > N[U + 2] ? N[U + 2] = q : q > 0 && q < H[U + 2] && (H[U + 2] = q)));
|
|
1322
2698
|
}
|
|
1323
|
-
if (
|
|
1324
|
-
const
|
|
1325
|
-
Math.abs(
|
|
2699
|
+
if (Ji > 0 && Te * Ks + ve * Ys > 0) {
|
|
2700
|
+
const q = Te * Ys - ve * Ks;
|
|
2701
|
+
Math.abs(q) < Ft && (we && (q <= 0 && q > N[U] ? N[U] = q : q > 0 && q < H[U] && (H[U] = q)), Ae && (q <= 0 && q > N[U + 1] ? N[U + 1] = q : q > 0 && q < H[U + 1] && (H[U + 1] = q)), be && (q <= 0 && q > N[U + 2] ? N[U + 2] = q : q > 0 && q < H[U + 2] && (H[U + 2] = q)));
|
|
1326
2702
|
}
|
|
1327
2703
|
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
),
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
),
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
2704
|
+
Zt[L] = yt(
|
|
2705
|
+
Z[U],
|
|
2706
|
+
N[U],
|
|
2707
|
+
H[U],
|
|
2708
|
+
L,
|
|
2709
|
+
Q[U],
|
|
2710
|
+
tt[U],
|
|
2711
|
+
_,
|
|
2712
|
+
g,
|
|
2713
|
+
a
|
|
2714
|
+
), $t[L] = yt(
|
|
2715
|
+
Z[U + 1],
|
|
2716
|
+
N[U + 1],
|
|
2717
|
+
H[U + 1],
|
|
2718
|
+
L,
|
|
2719
|
+
Q[U + 1],
|
|
2720
|
+
tt[U + 1],
|
|
2721
|
+
_,
|
|
2722
|
+
g,
|
|
2723
|
+
a
|
|
2724
|
+
), Jt[L] = yt(
|
|
2725
|
+
Z[U + 2],
|
|
2726
|
+
N[U + 2],
|
|
2727
|
+
H[U + 2],
|
|
2728
|
+
L,
|
|
2729
|
+
Q[U + 2],
|
|
2730
|
+
tt[U + 2],
|
|
2731
|
+
_,
|
|
2732
|
+
g,
|
|
2733
|
+
a
|
|
1358
2734
|
);
|
|
1359
2735
|
}
|
|
1360
|
-
let
|
|
1361
|
-
for (let
|
|
1362
|
-
const
|
|
2736
|
+
let x = -Y, b = 0, M = -Y, k = Y, w = -1, T = -1, D = 0, m = -Y, A = 0, d = -Y, R = Y, S = -1, E = -1, I = 0, F = -Y, V = 0, B = -Y, nt = Y, j = -1, W = -1, et = 0, st = -Y, Lt = 0, Xt = -Y, Wt = Y, us = -1, ps = -1, _s = 0, kn = -Y, ys = 0, ie = -Y, oe = Y, gs = -1, xs = -1, ds = 0, Un = -Y, Ms = 0, re = -Y, ce = Y, ws = -1, As = -1, bs = 0, Tn = -Y, ms = 0, ae = -Y, le = Y, ks = -1, Us = -1, Ts = 0, vn = -Y, vs = 0, he = -Y, fe = Y, Es = -1, Cs = -1, Ss = 0, En = -Y, Is = 0, ue = -Y, pe = Y, Ds = -1, Rs = -1, Ls = 0;
|
|
2737
|
+
for (let L = 0; L < l; L++) {
|
|
2738
|
+
const v = L * 3, ut = Vt[L], U = mt(Zt[L], $t[L], Jt[L]);
|
|
1363
2739
|
{
|
|
1364
|
-
const
|
|
1365
|
-
(
|
|
2740
|
+
const O = Z[v], G = J[v], X = Math.abs(O);
|
|
2741
|
+
(X < Math.abs(x) || X === Math.abs(x) && G < b) && (x = O, b = G, w = L, T = Q[v], D = tt[v]), N[v] > M && (M = N[v]), H[v] < k && (k = H[v]);
|
|
1366
2742
|
}
|
|
1367
2743
|
{
|
|
1368
|
-
const
|
|
1369
|
-
(
|
|
2744
|
+
const O = Z[v + 1], G = J[v + 1], X = Math.abs(O);
|
|
2745
|
+
(X < Math.abs(m) || X === Math.abs(m) && G < A) && (m = O, A = G, S = L, E = Q[v + 1], I = tt[v + 1]), N[v + 1] > d && (d = N[v + 1]), H[v + 1] < R && (R = H[v + 1]);
|
|
1370
2746
|
}
|
|
1371
2747
|
{
|
|
1372
|
-
const
|
|
1373
|
-
(
|
|
2748
|
+
const O = Z[v + 2], G = J[v + 2], X = Math.abs(O);
|
|
2749
|
+
(X < Math.abs(F) || X === Math.abs(F) && G < V) && (F = O, V = G, j = L, W = Q[v + 2], et = tt[v + 2]), N[v + 2] > B && (B = N[v + 2]), H[v + 2] < nt && (nt = H[v + 2]);
|
|
1374
2750
|
}
|
|
1375
|
-
if (
|
|
2751
|
+
if (ut > 0 && U >= 0) {
|
|
1376
2752
|
{
|
|
1377
|
-
const
|
|
1378
|
-
(
|
|
2753
|
+
const O = Z[v], G = J[v], X = Math.abs(O);
|
|
2754
|
+
(X < Math.abs(st) || X === Math.abs(st) && G < Lt) && (st = O, Lt = G, us = L, ps = Q[v], _s = tt[v]), N[v] > Xt && (Xt = N[v]), H[v] < Wt && (Wt = H[v]);
|
|
1379
2755
|
}
|
|
1380
2756
|
{
|
|
1381
|
-
const
|
|
1382
|
-
(
|
|
2757
|
+
const O = Z[v + 1], G = J[v + 1], X = Math.abs(O);
|
|
2758
|
+
(X < Math.abs(kn) || X === Math.abs(kn) && G < ys) && (kn = O, ys = G, gs = L, xs = Q[v + 1], ds = tt[v + 1]), N[v + 1] > ie && (ie = N[v + 1]), H[v + 1] < oe && (oe = H[v + 1]);
|
|
1383
2759
|
}
|
|
1384
2760
|
{
|
|
1385
|
-
const
|
|
1386
|
-
(
|
|
2761
|
+
const O = Z[v + 2], G = J[v + 2], X = Math.abs(O);
|
|
2762
|
+
(X < Math.abs(Un) || X === Math.abs(Un) && G < Ms) && (Un = O, Ms = G, ws = L, As = Q[v + 2], bs = tt[v + 2]), N[v + 2] > re && (re = N[v + 2]), H[v + 2] < ce && (ce = H[v + 2]);
|
|
1387
2763
|
}
|
|
1388
2764
|
}
|
|
1389
|
-
if (
|
|
2765
|
+
if (ut < 0 && U <= 0) {
|
|
1390
2766
|
{
|
|
1391
|
-
const
|
|
1392
|
-
(
|
|
2767
|
+
const O = Z[v], G = J[v], X = Math.abs(O);
|
|
2768
|
+
(X < Math.abs(Tn) || X === Math.abs(Tn) && G < ms) && (Tn = O, ms = G, ks = L, Us = Q[v], Ts = tt[v]), N[v] > ae && (ae = N[v]), H[v] < le && (le = H[v]);
|
|
1393
2769
|
}
|
|
1394
2770
|
{
|
|
1395
|
-
const
|
|
1396
|
-
(
|
|
2771
|
+
const O = Z[v + 1], G = J[v + 1], X = Math.abs(O);
|
|
2772
|
+
(X < Math.abs(vn) || X === Math.abs(vn) && G < vs) && (vn = O, vs = G, Es = L, Cs = Q[v + 1], Ss = tt[v + 1]), N[v + 1] > he && (he = N[v + 1]), H[v + 1] < fe && (fe = H[v + 1]);
|
|
1397
2773
|
}
|
|
1398
2774
|
{
|
|
1399
|
-
const
|
|
1400
|
-
(
|
|
2775
|
+
const O = Z[v + 2], G = J[v + 2], X = Math.abs(O);
|
|
2776
|
+
(X < Math.abs(En) || X === Math.abs(En) && G < Is) && (En = O, Is = G, Ds = L, Rs = Q[v + 2], Ls = tt[v + 2]), N[v + 2] > ue && (ue = N[v + 2]), H[v + 2] < pe && (pe = H[v + 2]);
|
|
1401
2777
|
}
|
|
1402
2778
|
}
|
|
1403
2779
|
}
|
|
1404
|
-
const
|
|
2780
|
+
const _e = yt(
|
|
2781
|
+
x,
|
|
2782
|
+
M,
|
|
2783
|
+
k,
|
|
2784
|
+
w,
|
|
2785
|
+
T,
|
|
2786
|
+
D,
|
|
2787
|
+
_,
|
|
1405
2788
|
g,
|
|
2789
|
+
a
|
|
2790
|
+
), ye = yt(
|
|
1406
2791
|
m,
|
|
1407
|
-
|
|
1408
|
-
|
|
2792
|
+
d,
|
|
2793
|
+
R,
|
|
2794
|
+
S,
|
|
1409
2795
|
E,
|
|
1410
|
-
C,
|
|
1411
|
-
u,
|
|
1412
|
-
x,
|
|
1413
|
-
r
|
|
1414
|
-
), xn = lt(
|
|
1415
|
-
F,
|
|
1416
|
-
b,
|
|
1417
|
-
N,
|
|
1418
2796
|
I,
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
X,
|
|
1426
|
-
V,
|
|
2797
|
+
_,
|
|
2798
|
+
g,
|
|
2799
|
+
a
|
|
2800
|
+
), ge = yt(
|
|
2801
|
+
F,
|
|
2802
|
+
B,
|
|
1427
2803
|
nt,
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
),
|
|
2804
|
+
j,
|
|
2805
|
+
W,
|
|
2806
|
+
et,
|
|
2807
|
+
_,
|
|
2808
|
+
g,
|
|
2809
|
+
a
|
|
2810
|
+
), Zi = mt(_e, ye, ge), Fs = yt(
|
|
1435
2811
|
st,
|
|
1436
|
-
sn,
|
|
1437
|
-
on,
|
|
1438
|
-
$n,
|
|
1439
|
-
Zn,
|
|
1440
|
-
jn,
|
|
1441
|
-
u,
|
|
1442
|
-
x,
|
|
1443
|
-
r
|
|
1444
|
-
), bs = lt(
|
|
1445
|
-
Nt,
|
|
1446
|
-
en,
|
|
1447
|
-
cn,
|
|
1448
|
-
ts,
|
|
1449
|
-
ns,
|
|
1450
|
-
ss,
|
|
1451
|
-
u,
|
|
1452
|
-
x,
|
|
1453
|
-
r
|
|
1454
|
-
), ws = lt(
|
|
1455
|
-
Ut,
|
|
1456
|
-
rn,
|
|
1457
|
-
an,
|
|
1458
|
-
es,
|
|
1459
|
-
is,
|
|
1460
|
-
cs,
|
|
1461
|
-
u,
|
|
1462
|
-
x,
|
|
1463
|
-
r
|
|
1464
|
-
), Ht = gt(ds, bs, ws), As = lt(
|
|
1465
|
-
Yt,
|
|
1466
|
-
hn,
|
|
1467
|
-
pn,
|
|
1468
|
-
as,
|
|
1469
|
-
hs,
|
|
1470
|
-
ps,
|
|
1471
|
-
u,
|
|
1472
|
-
x,
|
|
1473
|
-
r
|
|
1474
|
-
), Es = lt(
|
|
1475
2812
|
Xt,
|
|
1476
|
-
ln,
|
|
1477
|
-
fn,
|
|
1478
|
-
fs,
|
|
1479
|
-
ys,
|
|
1480
|
-
us,
|
|
1481
|
-
u,
|
|
1482
|
-
x,
|
|
1483
|
-
r
|
|
1484
|
-
), Ds = lt(
|
|
1485
2813
|
Wt,
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
2814
|
+
us,
|
|
2815
|
+
ps,
|
|
2816
|
+
_s,
|
|
2817
|
+
_,
|
|
2818
|
+
g,
|
|
2819
|
+
a
|
|
2820
|
+
), Ps = yt(
|
|
2821
|
+
kn,
|
|
2822
|
+
ie,
|
|
2823
|
+
oe,
|
|
1489
2824
|
gs,
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
2825
|
+
xs,
|
|
2826
|
+
ds,
|
|
2827
|
+
_,
|
|
2828
|
+
g,
|
|
2829
|
+
a
|
|
2830
|
+
), qs = yt(
|
|
2831
|
+
Un,
|
|
2832
|
+
re,
|
|
2833
|
+
ce,
|
|
2834
|
+
ws,
|
|
2835
|
+
As,
|
|
2836
|
+
bs,
|
|
2837
|
+
_,
|
|
2838
|
+
g,
|
|
2839
|
+
a
|
|
2840
|
+
), Cn = mt(Fs, Ps, qs), Os = yt(
|
|
2841
|
+
Tn,
|
|
2842
|
+
ae,
|
|
2843
|
+
le,
|
|
2844
|
+
ks,
|
|
2845
|
+
Us,
|
|
2846
|
+
Ts,
|
|
2847
|
+
_,
|
|
2848
|
+
g,
|
|
2849
|
+
a
|
|
2850
|
+
), Gs = yt(
|
|
2851
|
+
vn,
|
|
2852
|
+
he,
|
|
2853
|
+
fe,
|
|
2854
|
+
Es,
|
|
2855
|
+
Cs,
|
|
2856
|
+
Ss,
|
|
2857
|
+
_,
|
|
2858
|
+
g,
|
|
2859
|
+
a
|
|
2860
|
+
), Ns = yt(
|
|
2861
|
+
En,
|
|
2862
|
+
ue,
|
|
2863
|
+
pe,
|
|
2864
|
+
Ds,
|
|
2865
|
+
Rs,
|
|
2866
|
+
Ls,
|
|
2867
|
+
_,
|
|
2868
|
+
g,
|
|
2869
|
+
a
|
|
2870
|
+
), Sn = mt(Os, Gs, Ns);
|
|
2871
|
+
let wt, At, bt, xe = 0;
|
|
2872
|
+
if (Cn >= 0 && Math.abs(Cn) <= Math.abs(Sn)) {
|
|
2873
|
+
wt = Fs, At = Ps, bt = qs, xe = 1;
|
|
2874
|
+
for (let L = 0; L < l; L++)
|
|
2875
|
+
if (Vt[L] > 0) {
|
|
2876
|
+
const v = Zt[L], ut = $t[L], U = Jt[L], O = mt(v, ut, U);
|
|
2877
|
+
Math.abs(O) < Math.abs(Sn) && O > mt(wt, At, bt) && (wt = v, At = ut, bt = U);
|
|
1502
2878
|
}
|
|
1503
|
-
} else if (
|
|
1504
|
-
|
|
1505
|
-
for (let
|
|
1506
|
-
if (
|
|
1507
|
-
const
|
|
1508
|
-
Math.abs(
|
|
2879
|
+
} else if (Sn <= 0 && Math.abs(Sn) < Math.abs(Cn)) {
|
|
2880
|
+
wt = Os, At = Gs, bt = Ns, xe = -1;
|
|
2881
|
+
for (let L = 0; L < l; L++)
|
|
2882
|
+
if (Vt[L] < 0) {
|
|
2883
|
+
const v = Zt[L], ut = $t[L], U = Jt[L], O = mt(v, ut, U);
|
|
2884
|
+
Math.abs(O) < Math.abs(Cn) && O < mt(wt, At, bt) && (wt = v, At = ut, bt = U);
|
|
1509
2885
|
}
|
|
1510
2886
|
} else {
|
|
1511
|
-
const
|
|
1512
|
-
c[
|
|
2887
|
+
const L = (p * t + y) * 3;
|
|
2888
|
+
c[L + 0] = _e * h + 0.5, c[L + 1] = ye * h + 0.5, c[L + 2] = ge * h + 0.5;
|
|
1513
2889
|
continue;
|
|
1514
2890
|
}
|
|
1515
|
-
for (let
|
|
1516
|
-
if (
|
|
1517
|
-
const
|
|
1518
|
-
|
|
2891
|
+
for (let L = 0; L < l; L++)
|
|
2892
|
+
if (Vt[L] !== xe) {
|
|
2893
|
+
const v = Zt[L], ut = $t[L], U = Jt[L], O = mt(v, ut, U), G = mt(wt, At, bt);
|
|
2894
|
+
O * G >= 0 && Math.abs(O) < Math.abs(G) && (wt = v, At = ut, bt = U);
|
|
1519
2895
|
}
|
|
1520
|
-
|
|
1521
|
-
const
|
|
1522
|
-
c[
|
|
2896
|
+
mt(wt, At, bt) === Zi && (wt = _e, At = ye, bt = ge);
|
|
2897
|
+
const de = (p * t + y) * 3;
|
|
2898
|
+
c[de + 0] = wt * h + 0.5, c[de + 1] = At * h + 0.5, c[de + 2] = bt * h + 0.5;
|
|
1523
2899
|
}
|
|
1524
2900
|
}
|
|
1525
|
-
const
|
|
1526
|
-
function
|
|
2901
|
+
const ji = 0, Wr = 1, zr = 2, Zr = 3;
|
|
2902
|
+
function $r(s, t) {
|
|
1527
2903
|
switch (t) {
|
|
1528
|
-
case
|
|
1529
|
-
return
|
|
1530
|
-
case
|
|
1531
|
-
return (
|
|
1532
|
-
case
|
|
1533
|
-
return
|
|
1534
|
-
case
|
|
1535
|
-
return
|
|
2904
|
+
case ji:
|
|
2905
|
+
return s !== 0;
|
|
2906
|
+
case Wr:
|
|
2907
|
+
return (s & 1) !== 0;
|
|
2908
|
+
case zr:
|
|
2909
|
+
return s > 0;
|
|
2910
|
+
case Zr:
|
|
2911
|
+
return s < 0;
|
|
1536
2912
|
}
|
|
1537
2913
|
return !1;
|
|
1538
2914
|
}
|
|
1539
|
-
class
|
|
2915
|
+
class Jr {
|
|
1540
2916
|
constructor() {
|
|
1541
2917
|
this._intersections = [], this._lastIndex = 0;
|
|
1542
2918
|
}
|
|
@@ -1548,10 +2924,10 @@ class he {
|
|
|
1548
2924
|
*/
|
|
1549
2925
|
setIntersections(t) {
|
|
1550
2926
|
if (this._intersections = t, this._lastIndex = 0, t.length > 0) {
|
|
1551
|
-
t.sort((
|
|
2927
|
+
t.sort((e, i) => pt(e.x - i.x));
|
|
1552
2928
|
let n = 0;
|
|
1553
|
-
for (let
|
|
1554
|
-
n += t[
|
|
2929
|
+
for (let e = 0; e < t.length; e++)
|
|
2930
|
+
n += t[e].direction, t[e].direction = n;
|
|
1555
2931
|
}
|
|
1556
2932
|
}
|
|
1557
2933
|
/**
|
|
@@ -1563,16 +2939,16 @@ class he {
|
|
|
1563
2939
|
_moveTo(t) {
|
|
1564
2940
|
const n = this._intersections.length;
|
|
1565
2941
|
if (n === 0) return -1;
|
|
1566
|
-
let
|
|
1567
|
-
if (t < this._intersections[
|
|
2942
|
+
let e = this._lastIndex;
|
|
2943
|
+
if (t < this._intersections[e].x)
|
|
1568
2944
|
do {
|
|
1569
|
-
if (
|
|
2945
|
+
if (e === 0)
|
|
1570
2946
|
return this._lastIndex = 0, -1;
|
|
1571
|
-
--
|
|
1572
|
-
} while (t < this._intersections[
|
|
2947
|
+
--e;
|
|
2948
|
+
} while (t < this._intersections[e].x);
|
|
1573
2949
|
else
|
|
1574
|
-
for (;
|
|
1575
|
-
return this._lastIndex =
|
|
2950
|
+
for (; e < n - 1 && t >= this._intersections[e + 1].x; ) ++e;
|
|
2951
|
+
return this._lastIndex = e, e;
|
|
1576
2952
|
}
|
|
1577
2953
|
/**
|
|
1578
2954
|
* Returns the accumulated winding number at x.
|
|
@@ -1592,323 +2968,365 @@ class he {
|
|
|
1592
2968
|
* @returns True when filled.
|
|
1593
2969
|
*/
|
|
1594
2970
|
filled(t, n) {
|
|
1595
|
-
return
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
const
|
|
1599
|
-
function
|
|
1600
|
-
const
|
|
1601
|
-
for (const
|
|
1602
|
-
for (const
|
|
1603
|
-
const
|
|
1604
|
-
for (let c = 0; c <
|
|
1605
|
-
|
|
1606
|
-
}
|
|
1607
|
-
n.setIntersections(
|
|
1608
|
-
}
|
|
1609
|
-
const
|
|
1610
|
-
function
|
|
1611
|
-
if (n === 0 ||
|
|
1612
|
-
const c = new
|
|
1613
|
-
for (let
|
|
1614
|
-
const
|
|
1615
|
-
|
|
1616
|
-
for (let
|
|
1617
|
-
const
|
|
1618
|
-
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
for (let
|
|
1622
|
-
for (let
|
|
1623
|
-
const
|
|
1624
|
-
if (
|
|
1625
|
-
let
|
|
1626
|
-
if (
|
|
1627
|
-
const
|
|
1628
|
-
|
|
2971
|
+
return $r(this.sumIntersections(t), n);
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
const Ti = [0, 0, 0], vi = [0, 0, 0];
|
|
2975
|
+
function Qr(s, t, n) {
|
|
2976
|
+
const e = [];
|
|
2977
|
+
for (const i of s.contours)
|
|
2978
|
+
for (const o of i) {
|
|
2979
|
+
const r = o.scanlineIntersections(t, Ti, vi);
|
|
2980
|
+
for (let c = 0; c < r; c++)
|
|
2981
|
+
e.push({ x: Ti[c], direction: vi[c] });
|
|
2982
|
+
}
|
|
2983
|
+
n.setIntersections(e);
|
|
2984
|
+
}
|
|
2985
|
+
const sn = 2, Xi = 1, We = 1.001, tc = 1.1111111111111112, te = 0.01;
|
|
2986
|
+
function nc(s, t, n, e, i, o, r) {
|
|
2987
|
+
if (n === 0 || e === 0) return;
|
|
2988
|
+
const c = new Jr(), a = new Int8Array(n * e);
|
|
2989
|
+
for (let l = 0; l < e; l++) {
|
|
2990
|
+
const h = (l + 0.5) / i - r;
|
|
2991
|
+
Qr(t, h, c);
|
|
2992
|
+
for (let f = 0; f < n; f++) {
|
|
2993
|
+
const u = (f + 0.5) / i - o, p = c.filled(u, ji), y = (l * n + f) * 3, _ = s[y], g = s[y + 1], x = s[y + 2], b = lt(_, g, x), M = l * n + f;
|
|
2994
|
+
b === 0.5 ? a[M] = 0 : b > 0.5 !== p ? (s[y] = 1 - _, s[y + 1] = 1 - g, s[y + 2] = 1 - x, a[M] = -1) : a[M] = 1;
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
for (let l = 0; l < e; l++)
|
|
2998
|
+
for (let h = 0; h < n; h++) {
|
|
2999
|
+
const f = l * n + h;
|
|
3000
|
+
if (a[f] !== 0) continue;
|
|
3001
|
+
let u = 0;
|
|
3002
|
+
if (h > 0 && (u += a[f - 1]), h < n - 1 && (u += a[f + 1]), l > 0 && (u += a[f - n]), l < e - 1 && (u += a[f + n]), u < 0) {
|
|
3003
|
+
const p = (l * n + h) * 3;
|
|
3004
|
+
s[p] = 1 - s[p], s[p + 1] = 1 - s[p + 1], s[p + 2] = 1 - s[p + 2];
|
|
1629
3005
|
}
|
|
1630
3006
|
}
|
|
1631
3007
|
}
|
|
1632
|
-
const
|
|
1633
|
-
function
|
|
1634
|
-
const
|
|
1635
|
-
|
|
3008
|
+
const ze = [0, 0];
|
|
3009
|
+
function ec(s, t, n, e, i, o, r, c) {
|
|
3010
|
+
const a = new Uint8Array(n * e);
|
|
3011
|
+
sc(a, t, n, e, i, o, r), ic(a, s, n, e, i, c), ac(a, s, n, e, c, tc), lc(a, s, n, e);
|
|
1636
3012
|
}
|
|
1637
|
-
function
|
|
3013
|
+
function sc(s, t, n, e, i, o, r) {
|
|
1638
3014
|
for (const c of t.contours) {
|
|
1639
3015
|
if (c.length === 0) continue;
|
|
1640
|
-
let
|
|
1641
|
-
for (const
|
|
1642
|
-
const
|
|
1643
|
-
if (!(
|
|
1644
|
-
|
|
1645
|
-
const
|
|
1646
|
-
|
|
3016
|
+
let a = c[c.length - 1];
|
|
3017
|
+
for (const l of c) {
|
|
3018
|
+
const h = a.color & l.color;
|
|
3019
|
+
if (!(h & h - 1)) {
|
|
3020
|
+
l.point(0, ze);
|
|
3021
|
+
const f = i * (ze[0] + o), u = i * (ze[1] + r), p = Math.floor(f - 0.5) | 0, y = Math.floor(u - 0.5) | 0, _ = p + 1, g = y + 1;
|
|
3022
|
+
p < n && y < e && _ >= 0 && g >= 0 && (p >= 0 && y >= 0 && (s[y * n + p] |= sn), _ < n && y >= 0 && (s[y * n + _] |= sn), p >= 0 && g < e && (s[g * n + p] |= sn), _ < n && g < e && (s[g * n + _] |= sn));
|
|
1647
3023
|
}
|
|
1648
|
-
|
|
3024
|
+
a = l;
|
|
1649
3025
|
}
|
|
1650
3026
|
}
|
|
1651
3027
|
}
|
|
1652
|
-
function
|
|
1653
|
-
let
|
|
1654
|
-
for (let
|
|
1655
|
-
const
|
|
3028
|
+
function Hn(s, t, n) {
|
|
3029
|
+
let e = 0;
|
|
3030
|
+
for (let i = 0; i < 3; i++) {
|
|
3031
|
+
const o = s[t + i], r = s[n + i], c = o - r;
|
|
1656
3032
|
if (c === 0) continue;
|
|
1657
|
-
const
|
|
1658
|
-
if (
|
|
1659
|
-
const
|
|
1660
|
-
|
|
3033
|
+
const a = (o - 0.5) / c;
|
|
3034
|
+
if (a > 0 && a < 1) {
|
|
3035
|
+
const l = 1 - a, h = l * s[t] + a * s[n], f = l * s[t + 1] + a * s[n + 1], u = l * s[t + 2] + a * s[n + 2], p = i === 0 ? h : i === 1 ? f : u;
|
|
3036
|
+
lt(h, f, u) === p && (e |= i === 0 ? ne : i === 1 ? ee : se);
|
|
1661
3037
|
}
|
|
1662
3038
|
}
|
|
1663
|
-
return
|
|
1664
|
-
}
|
|
1665
|
-
function At(i, t, n, s, o, e) {
|
|
1666
|
-
(e & Jt && n[s] !== o || e & tn && n[s + 1] !== o || e & nn && n[s + 2] !== o) && (i[t] |= Tt);
|
|
3039
|
+
return e;
|
|
1667
3040
|
}
|
|
1668
|
-
function
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
3041
|
+
function qt(s, t, n, e, i, o) {
|
|
3042
|
+
(o & ne && n[e] !== i || o & ee && n[e + 1] !== i || o & se && n[e + 2] !== i) && (s[t] |= sn);
|
|
3043
|
+
}
|
|
3044
|
+
function ic(s, t, n, e, i, o) {
|
|
3045
|
+
const r = We / o, c = We / o, a = We * Math.SQRT2 / o;
|
|
3046
|
+
for (let l = 0; l < e; l++)
|
|
3047
|
+
for (let h = 0; h < n - 1; h++) {
|
|
3048
|
+
const f = (l * n + h) * 3, u = f + 3, p = lt(t[f], t[f + 1], t[f + 2]), y = lt(t[u], t[u + 1], t[u + 2]);
|
|
3049
|
+
if (Math.abs(p - 0.5) + Math.abs(y - 0.5) < r) {
|
|
3050
|
+
const _ = Hn(t, f, u);
|
|
3051
|
+
qt(s, l * n + h, t, f, p, _), qt(s, l * n + h + 1, t, u, y, _);
|
|
1676
3052
|
}
|
|
1677
3053
|
}
|
|
1678
|
-
for (let
|
|
1679
|
-
for (let
|
|
1680
|
-
const
|
|
1681
|
-
if (Math.abs(
|
|
1682
|
-
const
|
|
1683
|
-
|
|
3054
|
+
for (let l = 0; l < e - 1; l++)
|
|
3055
|
+
for (let h = 0; h < n; h++) {
|
|
3056
|
+
const f = (l * n + h) * 3, u = ((l + 1) * n + h) * 3, p = lt(t[f], t[f + 1], t[f + 2]), y = lt(t[u], t[u + 1], t[u + 2]);
|
|
3057
|
+
if (Math.abs(p - 0.5) + Math.abs(y - 0.5) < c) {
|
|
3058
|
+
const _ = Hn(t, f, u);
|
|
3059
|
+
qt(s, l * n + h, t, f, p, _), qt(s, (l + 1) * n + h, t, u, y, _);
|
|
1684
3060
|
}
|
|
1685
3061
|
}
|
|
1686
|
-
for (let
|
|
1687
|
-
for (let
|
|
1688
|
-
const
|
|
1689
|
-
if (Math.abs(
|
|
1690
|
-
const
|
|
1691
|
-
|
|
3062
|
+
for (let l = 0; l < e - 1; l++)
|
|
3063
|
+
for (let h = 0; h < n - 1; h++) {
|
|
3064
|
+
const f = (l * n + h) * 3, u = (l * n + h + 1) * 3, p = ((l + 1) * n + h) * 3, y = ((l + 1) * n + h + 1) * 3, _ = lt(t[f], t[f + 1], t[f + 2]), g = lt(t[u], t[u + 1], t[u + 2]), x = lt(t[p], t[p + 1], t[p + 2]), b = lt(t[y], t[y + 1], t[y + 2]);
|
|
3065
|
+
if (Math.abs(_ - 0.5) + Math.abs(b - 0.5) < a) {
|
|
3066
|
+
const M = Hn(t, f, y);
|
|
3067
|
+
qt(s, l * n + h, t, f, _, M), qt(s, (l + 1) * n + h + 1, t, y, b, M);
|
|
1692
3068
|
}
|
|
1693
|
-
if (Math.abs(
|
|
1694
|
-
const
|
|
1695
|
-
|
|
3069
|
+
if (Math.abs(g - 0.5) + Math.abs(x - 0.5) < a) {
|
|
3070
|
+
const M = Hn(t, u, p);
|
|
3071
|
+
qt(s, l * n + h + 1, t, u, g, M), qt(s, (l + 1) * n + h, t, p, x, M);
|
|
1696
3072
|
}
|
|
1697
3073
|
}
|
|
1698
3074
|
}
|
|
1699
|
-
function
|
|
1700
|
-
const
|
|
1701
|
-
return
|
|
3075
|
+
function oc(s, t, n) {
|
|
3076
|
+
const e = t < s ? t : s, i = s < t ? t : s, o = n < i ? n : i;
|
|
3077
|
+
return e < o ? o : e;
|
|
1702
3078
|
}
|
|
1703
|
-
function
|
|
1704
|
-
return
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
3079
|
+
function rc(s, t, n, e) {
|
|
3080
|
+
return lt(
|
|
3081
|
+
s[t] + e * (s[n] - s[t]),
|
|
3082
|
+
s[t + 1] + e * (s[n + 1] - s[t + 1]),
|
|
3083
|
+
s[t + 2] + e * (s[n + 2] - s[t + 2])
|
|
1708
3084
|
);
|
|
1709
3085
|
}
|
|
1710
|
-
function
|
|
1711
|
-
return
|
|
1712
|
-
Math.fround(
|
|
1713
|
-
Math.fround(
|
|
1714
|
-
Math.fround(
|
|
3086
|
+
function os(s, t, n, e) {
|
|
3087
|
+
return oc(
|
|
3088
|
+
Math.fround(e * (e * n[0] + t[0]) + s[0]),
|
|
3089
|
+
Math.fround(e * (e * n[1] + t[1]) + s[1]),
|
|
3090
|
+
Math.fround(e * (e * n[2] + t[2]) + s[2])
|
|
1715
3091
|
);
|
|
1716
3092
|
}
|
|
1717
|
-
const
|
|
1718
|
-
function
|
|
1719
|
-
if (
|
|
1720
|
-
const
|
|
1721
|
-
return
|
|
3093
|
+
const jt = [0, 0, 0], vt = [0, 0, 0], Ze = [0, 0, 0], xt = [0, 0, 0], Ei = 1, Wi = 2;
|
|
3094
|
+
function fs(s, t, n, e, i, o, r, c) {
|
|
3095
|
+
if (e > 0.5 && i > 0.5 && o <= 0.5 || e < 0.5 && i < 0.5 && o >= 0.5 || !c && cc(e, i, o) !== o) {
|
|
3096
|
+
const a = (n - s) * r, l = (t - n) * r;
|
|
3097
|
+
return o >= e - a && o <= e + a && o >= i - l && o <= i + l ? Ei : Ei | Wi;
|
|
1722
3098
|
}
|
|
1723
3099
|
return 0;
|
|
1724
3100
|
}
|
|
1725
|
-
function
|
|
1726
|
-
return (
|
|
3101
|
+
function zi(s) {
|
|
3102
|
+
return (s & Wi) !== 0;
|
|
1727
3103
|
}
|
|
1728
|
-
function
|
|
1729
|
-
return Math.max(Math.min(
|
|
3104
|
+
function cc(s, t, n) {
|
|
3105
|
+
return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
|
|
1730
3106
|
}
|
|
1731
|
-
function
|
|
1732
|
-
const
|
|
1733
|
-
if (Math.abs(
|
|
3107
|
+
function Bn(s, t, n, e, i, o) {
|
|
3108
|
+
const r = lt(s[n], s[n + 1], s[n + 2]);
|
|
3109
|
+
if (Math.abs(e - 0.5) < Math.abs(r - 0.5)) return !1;
|
|
1734
3110
|
for (let c = 0; c < 3; c++) {
|
|
1735
|
-
const
|
|
1736
|
-
if (
|
|
1737
|
-
const
|
|
1738
|
-
if (
|
|
1739
|
-
const
|
|
1740
|
-
if (
|
|
3111
|
+
const a = s[t + c] - s[t + (c + 1) % 3], l = s[n + c] - s[n + (c + 1) % 3], h = a - l;
|
|
3112
|
+
if (h === 0) continue;
|
|
3113
|
+
const f = a / h;
|
|
3114
|
+
if (f > te && f < 1 - te) {
|
|
3115
|
+
const u = rc(s, t, n, f), p = fs(0, 1, f, e, r, u, i, o);
|
|
3116
|
+
if (zi(p)) return !0;
|
|
1741
3117
|
}
|
|
1742
3118
|
}
|
|
1743
3119
|
return !1;
|
|
1744
3120
|
}
|
|
1745
|
-
function
|
|
1746
|
-
if (!(
|
|
1747
|
-
const
|
|
1748
|
-
|
|
1749
|
-
const
|
|
1750
|
-
|
|
1751
|
-
const
|
|
1752
|
-
return
|
|
1753
|
-
}
|
|
1754
|
-
function
|
|
1755
|
-
if (!(
|
|
1756
|
-
|
|
1757
|
-
const
|
|
1758
|
-
let
|
|
1759
|
-
return
|
|
1760
|
-
}
|
|
1761
|
-
function
|
|
1762
|
-
const
|
|
1763
|
-
Math.fround(
|
|
1764
|
-
),
|
|
1765
|
-
if (
|
|
1766
|
-
if (
|
|
1767
|
-
const
|
|
1768
|
-
if (
|
|
3121
|
+
function Ci(s, t, n, e, i, o, r, c, a) {
|
|
3122
|
+
if (!(a > 0 && a < 1)) return 0;
|
|
3123
|
+
const l = a > r ? 0 : a, h = a > r ? a : 1;
|
|
3124
|
+
xt[0] = s[t], xt[1] = s[t + 1], xt[2] = s[t + 2];
|
|
3125
|
+
const f = a > r ? n : os(xt, jt, vt, a);
|
|
3126
|
+
xt[0] = s[t], xt[1] = s[t + 1], xt[2] = s[t + 2];
|
|
3127
|
+
const u = a > r ? os(xt, jt, vt, a) : e;
|
|
3128
|
+
return fs(l, h, r, f, u, c, i, o);
|
|
3129
|
+
}
|
|
3130
|
+
function Kn(s, t, n, e, i, o, r, c, a) {
|
|
3131
|
+
if (!(r > te && r < 1 - te)) return !1;
|
|
3132
|
+
xt[0] = s[t], xt[1] = s[t + 1], xt[2] = s[t + 2];
|
|
3133
|
+
const l = os(xt, jt, vt, r);
|
|
3134
|
+
let h = fs(0, 1, r, n, e, l, i, o);
|
|
3135
|
+
return h |= Ci(s, t, n, e, i, o, r, l, c), h |= Ci(s, t, n, e, i, o, r, l, a), zi(h);
|
|
3136
|
+
}
|
|
3137
|
+
function $e(s, t, n, e, i, o, r, c, a, l, h, f, u) {
|
|
3138
|
+
const p = Math.fround(s[t + l] - s[t + h]), y = Math.fround(
|
|
3139
|
+
Math.fround(s[n + l] - s[n + h]) + Math.fround(s[e + l] - s[e + h])
|
|
3140
|
+
), _ = Math.fround(s[i + l] - s[i + h]), g = Math.fround(Math.fround(_ - y) + p), x = Math.fround(Math.fround(y - p) - p), b = p;
|
|
3141
|
+
if (g === 0 || Math.abs(x) > 1e12 * Math.abs(g)) {
|
|
3142
|
+
if (x !== 0) {
|
|
3143
|
+
const k = -b / x;
|
|
3144
|
+
if (Kn(s, t, o, r, c, a, k, f, u)) return !0;
|
|
1769
3145
|
}
|
|
1770
3146
|
return !1;
|
|
1771
3147
|
}
|
|
1772
|
-
const
|
|
1773
|
-
if (
|
|
1774
|
-
const
|
|
1775
|
-
if (
|
|
1776
|
-
const
|
|
1777
|
-
if (
|
|
1778
|
-
} else if (
|
|
1779
|
-
const
|
|
1780
|
-
if (
|
|
3148
|
+
const M = x * x - 4 * g * b;
|
|
3149
|
+
if (M > 0) {
|
|
3150
|
+
const k = Math.sqrt(M), w = (-x + k) / (2 * g);
|
|
3151
|
+
if (Kn(s, t, o, r, c, a, w, f, u)) return !0;
|
|
3152
|
+
const T = (-x - k) / (2 * g);
|
|
3153
|
+
if (Kn(s, t, o, r, c, a, T, f, u)) return !0;
|
|
3154
|
+
} else if (M === 0) {
|
|
3155
|
+
const k = -x / (2 * g);
|
|
3156
|
+
if (Kn(s, t, o, r, c, a, k, f, u)) return !0;
|
|
1781
3157
|
}
|
|
1782
3158
|
return !1;
|
|
1783
3159
|
}
|
|
1784
|
-
function
|
|
1785
|
-
const
|
|
1786
|
-
if (Math.abs(
|
|
1787
|
-
for (let
|
|
1788
|
-
|
|
1789
|
-
Math.fround(
|
|
1790
|
-
),
|
|
1791
|
-
const
|
|
1792
|
-
return !!(
|
|
1793
|
-
|
|
3160
|
+
function Yn(s, t, n, e, i, o, r, c) {
|
|
3161
|
+
const a = lt(s[i], s[i + 1], s[i + 2]);
|
|
3162
|
+
if (Math.abs(o - 0.5) < Math.abs(a - 0.5)) return !1;
|
|
3163
|
+
for (let u = 0; u < 3; u++)
|
|
3164
|
+
Ze[u] = Math.fround(
|
|
3165
|
+
Math.fround(s[t + u] - s[n + u]) - s[e + u]
|
|
3166
|
+
), jt[u] = Math.fround(-s[t + u] - Ze[u]), vt[u] = Math.fround(s[i + u] + Ze[u]);
|
|
3167
|
+
const l = vt[0] !== 0 ? -0.5 * jt[0] / vt[0] : -1, h = vt[1] !== 0 ? -0.5 * jt[1] / vt[1] : -1, f = vt[2] !== 0 ? -0.5 * jt[2] / vt[2] : -1;
|
|
3168
|
+
return !!($e(
|
|
3169
|
+
s,
|
|
1794
3170
|
t,
|
|
1795
3171
|
n,
|
|
1796
|
-
s,
|
|
1797
|
-
o,
|
|
1798
3172
|
e,
|
|
3173
|
+
i,
|
|
3174
|
+
o,
|
|
3175
|
+
a,
|
|
1799
3176
|
r,
|
|
1800
|
-
p,
|
|
1801
3177
|
c,
|
|
1802
3178
|
0,
|
|
1803
3179
|
1,
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
) ||
|
|
1807
|
-
|
|
3180
|
+
l,
|
|
3181
|
+
h
|
|
3182
|
+
) || $e(
|
|
3183
|
+
s,
|
|
1808
3184
|
t,
|
|
1809
3185
|
n,
|
|
1810
|
-
s,
|
|
1811
|
-
o,
|
|
1812
3186
|
e,
|
|
3187
|
+
i,
|
|
3188
|
+
o,
|
|
3189
|
+
a,
|
|
1813
3190
|
r,
|
|
1814
|
-
p,
|
|
1815
3191
|
c,
|
|
1816
3192
|
1,
|
|
1817
3193
|
2,
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
) ||
|
|
1821
|
-
|
|
3194
|
+
h,
|
|
3195
|
+
f
|
|
3196
|
+
) || $e(
|
|
3197
|
+
s,
|
|
1822
3198
|
t,
|
|
1823
3199
|
n,
|
|
1824
|
-
s,
|
|
1825
|
-
o,
|
|
1826
3200
|
e,
|
|
3201
|
+
i,
|
|
3202
|
+
o,
|
|
3203
|
+
a,
|
|
1827
3204
|
r,
|
|
1828
|
-
p,
|
|
1829
3205
|
c,
|
|
1830
3206
|
2,
|
|
1831
3207
|
0,
|
|
1832
|
-
|
|
1833
|
-
|
|
3208
|
+
f,
|
|
3209
|
+
l
|
|
1834
3210
|
));
|
|
1835
3211
|
}
|
|
1836
|
-
function
|
|
1837
|
-
const
|
|
1838
|
-
for (let
|
|
1839
|
-
for (let
|
|
1840
|
-
const
|
|
1841
|
-
let
|
|
1842
|
-
if (
|
|
1843
|
-
const
|
|
1844
|
-
|
|
3212
|
+
function ac(s, t, n, e, i, o) {
|
|
3213
|
+
const r = o / i, c = o / i, a = o * Math.SQRT2 / i;
|
|
3214
|
+
for (let l = 0; l < e; l++)
|
|
3215
|
+
for (let h = 0; h < n; h++) {
|
|
3216
|
+
const f = l * n + h, u = f * 3, p = lt(t[u], t[u + 1], t[u + 2]), y = (s[f] & sn) !== 0, _ = h > 0, g = h < n - 1, x = l > 0, b = l < e - 1, M = _ ? (f - 1) * 3 : -1, k = g ? (f + 1) * 3 : -1, w = x ? (f - n) * 3 : -1, T = b ? (f + n) * 3 : -1;
|
|
3217
|
+
let D = !1;
|
|
3218
|
+
if (_ && Bn(t, u, M, p, r, y) && (D = !0), !D && x && Bn(t, u, w, p, c, y) && (D = !0), !D && g && Bn(t, u, k, p, r, y) && (D = !0), !D && b && Bn(t, u, T, p, c, y) && (D = !0), !D && _ && x) {
|
|
3219
|
+
const m = (f - n - 1) * 3;
|
|
3220
|
+
Yn(t, u, M, w, m, p, a, y) && (D = !0);
|
|
1845
3221
|
}
|
|
1846
|
-
if (!
|
|
1847
|
-
const
|
|
1848
|
-
|
|
3222
|
+
if (!D && g && x) {
|
|
3223
|
+
const m = (f - n + 1) * 3;
|
|
3224
|
+
Yn(t, u, k, w, m, p, a, y) && (D = !0);
|
|
1849
3225
|
}
|
|
1850
|
-
if (!
|
|
1851
|
-
const
|
|
1852
|
-
|
|
3226
|
+
if (!D && _ && b) {
|
|
3227
|
+
const m = (f + n - 1) * 3;
|
|
3228
|
+
Yn(t, u, M, T, m, p, a, y) && (D = !0);
|
|
1853
3229
|
}
|
|
1854
|
-
if (!
|
|
1855
|
-
const
|
|
1856
|
-
|
|
3230
|
+
if (!D && g && b) {
|
|
3231
|
+
const m = (f + n + 1) * 3;
|
|
3232
|
+
Yn(t, u, k, T, m, p, a, y) && (D = !0);
|
|
1857
3233
|
}
|
|
1858
|
-
|
|
3234
|
+
D && (s[f] |= Xi);
|
|
1859
3235
|
}
|
|
1860
3236
|
}
|
|
1861
|
-
function
|
|
1862
|
-
const
|
|
1863
|
-
for (let
|
|
1864
|
-
if (
|
|
1865
|
-
const
|
|
1866
|
-
t[
|
|
3237
|
+
function lc(s, t, n, e) {
|
|
3238
|
+
const i = n * e;
|
|
3239
|
+
for (let o = 0; o < i; o++)
|
|
3240
|
+
if (s[o] & Xi) {
|
|
3241
|
+
const r = o * 3, c = lt(t[r], t[r + 1], t[r + 2]);
|
|
3242
|
+
t[r] = c, t[r + 1] = c, t[r + 2] = c;
|
|
1867
3243
|
}
|
|
1868
3244
|
}
|
|
1869
|
-
function
|
|
1870
|
-
return Math.max(Math.min(
|
|
3245
|
+
function lt(s, t, n) {
|
|
3246
|
+
return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
|
|
3247
|
+
}
|
|
3248
|
+
const hc = 3, fc = 0n, Si = 16;
|
|
3249
|
+
function uc(s, t, n, e = !0) {
|
|
3250
|
+
if (e && Lr(s), s.contours.length === 0) return null;
|
|
3251
|
+
const i = pc(s), o = t, r = n, c = Math.max(1, Math.ceil((i.maxX - i.minX) * o)) + 2 * r, a = Math.max(1, Math.ceil((i.maxY - i.minY) * o)) + 2 * r, l = r / o - i.minX, h = r / o - i.minY;
|
|
3252
|
+
br(s), Yr(s, hc, fc);
|
|
3253
|
+
const f = new Float32Array(c * a * 3);
|
|
3254
|
+
return Xr(s, c, a, o, l, h, r, f), nc(f, s, c, a, o, l, h), ec(f, s, c, a, o, l, h, r), {
|
|
3255
|
+
msdf: f,
|
|
3256
|
+
w: c,
|
|
3257
|
+
h: a,
|
|
3258
|
+
planeLeft: -l,
|
|
3259
|
+
planeBottom: -h,
|
|
3260
|
+
planeRight: c / o - l,
|
|
3261
|
+
planeTop: a / o - h
|
|
3262
|
+
};
|
|
3263
|
+
}
|
|
3264
|
+
const Je = [0, 0];
|
|
3265
|
+
function pc(s) {
|
|
3266
|
+
let t = 1 / 0, n = 1 / 0, e = -1 / 0, i = -1 / 0;
|
|
3267
|
+
for (const o of s.contours)
|
|
3268
|
+
for (const r of o)
|
|
3269
|
+
for (let c = 0; c <= Si; c++) {
|
|
3270
|
+
r.point(c / Si, Je);
|
|
3271
|
+
const a = Je[0], l = Je[1];
|
|
3272
|
+
a < t && (t = a), l < n && (n = l), a > e && (e = a), l > i && (i = l);
|
|
3273
|
+
}
|
|
3274
|
+
return { minX: t, minY: n, maxX: e, maxY: i };
|
|
1871
3275
|
}
|
|
1872
|
-
function
|
|
3276
|
+
function _c(s) {
|
|
1873
3277
|
let t = 0, n = 0;
|
|
1874
|
-
for (const c of
|
|
3278
|
+
for (const c of s)
|
|
1875
3279
|
t += c.w * c.h, n = Math.max(n, c.w);
|
|
1876
|
-
|
|
1877
|
-
const
|
|
1878
|
-
let
|
|
1879
|
-
for (const c of
|
|
1880
|
-
for (let
|
|
1881
|
-
const
|
|
1882
|
-
if (!(c.w >
|
|
1883
|
-
if (c.x =
|
|
1884
|
-
const
|
|
1885
|
-
|
|
1886
|
-
} else c.h ===
|
|
1887
|
-
x:
|
|
1888
|
-
y:
|
|
1889
|
-
w:
|
|
3280
|
+
s.sort((c, a) => a.h - c.h);
|
|
3281
|
+
const i = [{ x: 0, y: 0, w: Math.max(Math.ceil(Math.sqrt(t / 0.95)), n), h: 1 / 0 }];
|
|
3282
|
+
let o = 0, r = 0;
|
|
3283
|
+
for (const c of s)
|
|
3284
|
+
for (let a = i.length - 1; a >= 0; a--) {
|
|
3285
|
+
const l = i[a];
|
|
3286
|
+
if (!(c.w > l.w || c.h > l.h)) {
|
|
3287
|
+
if (c.x = l.x, c.y = l.y, r = Math.max(r, c.y + c.h), o = Math.max(o, c.x + c.w), c.w === l.w && c.h === l.h) {
|
|
3288
|
+
const h = i.pop();
|
|
3289
|
+
h && a < i.length && (i[a] = h);
|
|
3290
|
+
} else c.h === l.h ? (l.x += c.w, l.w -= c.w) : c.w === l.w ? (l.y += c.h, l.h -= c.h) : (i.push({
|
|
3291
|
+
x: l.x + c.w,
|
|
3292
|
+
y: l.y,
|
|
3293
|
+
w: l.w - c.w,
|
|
1890
3294
|
h: c.h
|
|
1891
|
-
}),
|
|
3295
|
+
}), l.y += c.h, l.h -= c.h);
|
|
1892
3296
|
break;
|
|
1893
3297
|
}
|
|
1894
3298
|
}
|
|
1895
3299
|
return {
|
|
1896
|
-
w:
|
|
3300
|
+
w: o,
|
|
1897
3301
|
// container width
|
|
1898
|
-
h:
|
|
3302
|
+
h: r,
|
|
1899
3303
|
// container height
|
|
1900
|
-
fill: t / (
|
|
3304
|
+
fill: t / (o * r) || 0
|
|
1901
3305
|
// space utilization
|
|
1902
3306
|
};
|
|
1903
3307
|
}
|
|
1904
|
-
const
|
|
1905
|
-
|
|
1906
|
-
|
|
3308
|
+
const Ii = 4, yc = {
|
|
3309
|
+
x: 0,
|
|
3310
|
+
y: 0,
|
|
3311
|
+
w: 0,
|
|
3312
|
+
h: 0,
|
|
3313
|
+
advance: 0,
|
|
3314
|
+
planeLeft: 0,
|
|
3315
|
+
planeBottom: 0,
|
|
3316
|
+
planeRight: 0,
|
|
3317
|
+
planeTop: 0
|
|
3318
|
+
};
|
|
3319
|
+
function Qe(s) {
|
|
3320
|
+
const t = s < 0 ? 0 : s > 1 ? 1 : s;
|
|
1907
3321
|
return ~Math.trunc(255.5 - 255 * t) & 255;
|
|
1908
3322
|
}
|
|
1909
|
-
class
|
|
3323
|
+
class gc {
|
|
3324
|
+
/**
|
|
3325
|
+
* @param font Font for the glyph/layout methods; `null` for a shapes-only atlas.
|
|
3326
|
+
* @param opts Generation scale and distance range.
|
|
3327
|
+
*/
|
|
1910
3328
|
constructor(t, n = {}) {
|
|
1911
|
-
this._width = 0, this._height = 0, this._pixels = new Uint8Array(0), this._cache = /* @__PURE__ */ new Map(), this.
|
|
3329
|
+
this._width = 0, this._height = 0, this._pixels = new Uint8Array(0), this._cache = /* @__PURE__ */ new Map(), this._byGid = [], this._cacheByKey = /* @__PURE__ */ new Map(), this._font = t, this._pxPerEm = n.pixelsPerEm ?? 40, this._pxrange = n.pxrange ?? 4, this._floats = n.float ? new Float32Array(0) : null, this.pxrangeEm = this._pxrange / this._pxPerEm;
|
|
1912
3330
|
}
|
|
1913
3331
|
/** Packed atlas texture width in texels (chosen by potpack). */
|
|
1914
3332
|
get width() {
|
|
@@ -1922,24 +3340,19 @@ class De {
|
|
|
1922
3340
|
get texture() {
|
|
1923
3341
|
return this._pixels;
|
|
1924
3342
|
}
|
|
3343
|
+
/** {@link Atlas.texture} as raw float RGB, not clamped to [0, 1], for zoom that
|
|
3344
|
+
* outruns 8 bits; `null` without the `float` option. */
|
|
3345
|
+
get floatTexture() {
|
|
3346
|
+
return this._floats;
|
|
3347
|
+
}
|
|
1925
3348
|
/**
|
|
1926
3349
|
* Batched generate + pack. Generates MSDFs for any codepoints not
|
|
1927
3350
|
* already cached, then runs potpack **once** over the whole cache.
|
|
1928
3351
|
* Returns the `AtlasGlyph` for each requested codepoint, in order.
|
|
1929
3352
|
*/
|
|
1930
3353
|
glyphs(t) {
|
|
1931
|
-
const n =
|
|
1932
|
-
|
|
1933
|
-
for (const o of t) {
|
|
1934
|
-
const e = this._cache.get(o);
|
|
1935
|
-
if (e) {
|
|
1936
|
-
n.push(e.glyph);
|
|
1937
|
-
continue;
|
|
1938
|
-
}
|
|
1939
|
-
const p = this._generateForGlyphId(this._font.glyphId(o));
|
|
1940
|
-
this._cache.set(o, p), n.push(p.glyph), s++;
|
|
1941
|
-
}
|
|
1942
|
-
return s > 0 && this._repack(), n;
|
|
3354
|
+
const n = this._requireFont();
|
|
3355
|
+
return this.glyphsByIndex(Array.from(t, (e) => n.glyphId(e)));
|
|
1943
3356
|
}
|
|
1944
3357
|
/**
|
|
1945
3358
|
* Single-glyph convenience: generates + packs if missing. Repacks the
|
|
@@ -1954,25 +3367,22 @@ class De {
|
|
|
1954
3367
|
* Unicode codepoint — the {@link Atlas.glyphs} twin for glyphs with no
|
|
1955
3368
|
* reachable cmap entry. Icon fonts (e.g. Lucide) commonly have far more
|
|
1956
3369
|
* glyphs than mapped codepoints; this is how the rest of the set gets
|
|
1957
|
-
* generated. Shares one packed atlas texture with
|
|
1958
|
-
*
|
|
1959
|
-
* through either method. Cached separately from {@link Atlas.glyphs} (a
|
|
1960
|
-
* codepoint and a glyph index are different numbers in the same integer
|
|
1961
|
-
* space — sharing one cache would collide them).
|
|
3370
|
+
* generated. Shares one cache and one packed atlas texture with
|
|
3371
|
+
* {@link Atlas.glyphs}, which maps codepoints to glyph indices first.
|
|
1962
3372
|
*/
|
|
1963
3373
|
glyphsByIndex(t) {
|
|
1964
3374
|
const n = [];
|
|
1965
|
-
let
|
|
1966
|
-
for (const
|
|
1967
|
-
const
|
|
1968
|
-
if (
|
|
1969
|
-
n.push(
|
|
3375
|
+
let e = 0;
|
|
3376
|
+
for (const i of t) {
|
|
3377
|
+
const o = this._cache.get(i);
|
|
3378
|
+
if (o) {
|
|
3379
|
+
n.push(o.glyph);
|
|
1970
3380
|
continue;
|
|
1971
3381
|
}
|
|
1972
|
-
const
|
|
1973
|
-
this.
|
|
3382
|
+
const r = this._generateForGlyphId(i);
|
|
3383
|
+
this._cache.set(i, r), this._byGid[i] = r.glyph, n.push(r.glyph), e++;
|
|
1974
3384
|
}
|
|
1975
|
-
return
|
|
3385
|
+
return e > 0 && this._repack(), n;
|
|
1976
3386
|
}
|
|
1977
3387
|
/** Single-glyph convenience for {@link Atlas.glyphsByIndex} — see its
|
|
1978
3388
|
* doc. For more than one glyph, prefer {@link Atlas.glyphsByIndex}
|
|
@@ -1981,59 +3391,74 @@ class De {
|
|
|
1981
3391
|
return this.glyphsByIndex([t])[0];
|
|
1982
3392
|
}
|
|
1983
3393
|
/**
|
|
1984
|
-
*
|
|
1985
|
-
*
|
|
1986
|
-
*
|
|
3394
|
+
* Batched generate + pack for arbitrary shapes (e.g. from `parseSvg`),
|
|
3395
|
+
* keyed by a caller-chosen string — the {@link Atlas.glyphs} twin for
|
|
3396
|
+
* non-font input. Shapes must be y-up, in the units `pixelsPerEm` scales
|
|
3397
|
+
* (`parseSvg` makes 1 unit = the viewBox height). A new shape is mutated
|
|
3398
|
+
* (overlaps merged, normalized + coloured); a cached key ignores the shape
|
|
3399
|
+
* passed. `advance` is 0. Shares the one packed texture with the glyph cache.
|
|
1987
3400
|
*/
|
|
3401
|
+
shapes(t) {
|
|
3402
|
+
const n = [];
|
|
3403
|
+
let e = 0;
|
|
3404
|
+
for (const [i, o] of t) {
|
|
3405
|
+
let r = this._cacheByKey.get(i);
|
|
3406
|
+
r || (r = this._generate(o, 0), this._cacheByKey.set(i, r), e++), n.push(r.glyph);
|
|
3407
|
+
}
|
|
3408
|
+
return e > 0 && this._repack(), n;
|
|
3409
|
+
}
|
|
3410
|
+
/** The font, or a clear error for glyph/layout calls on a shapes-only atlas. */
|
|
3411
|
+
_requireFont() {
|
|
3412
|
+
if (!this._font) throw new Error("Atlas: no font — this atlas only supports shapes()");
|
|
3413
|
+
return this._font;
|
|
3414
|
+
}
|
|
3415
|
+
/** Generates the MSDF for `glyphId`. Does not cache and does not pack. */
|
|
1988
3416
|
_generateForGlyphId(t) {
|
|
1989
|
-
const n = this.
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
advance: o,
|
|
1997
|
-
planeLeft: 0,
|
|
1998
|
-
planeBottom: 0,
|
|
1999
|
-
planeRight: 0,
|
|
2000
|
-
planeTop: 0
|
|
2001
|
-
}, msdf: null };
|
|
2002
|
-
const p = qe(e), c = this._pxPerEm, r = this._pxrange, h = Math.max(1, Math.ceil((p.maxX - p.minX) * c)) + 2 * r, l = Math.max(1, Math.ceil((p.maxY - p.minY) * c)) + 2 * r, a = r / c - p.minX, f = r / c - p.minY;
|
|
2003
|
-
zo(e), ne(e, Ae, Ee);
|
|
2004
|
-
const y = new Float32Array(h * l * 3);
|
|
2005
|
-
return ee(e, h, l, c, a, f, r, y), fe(y, e, h, l, c, a, f), ye(y, e, h, l, c, a, f, r), { glyph: {
|
|
3417
|
+
const n = this._requireFont(), e = n.metrics.unitsPerEm, i = n.shape(t);
|
|
3418
|
+
return dr(i, e), this._generate(i, n.advance(t) / e);
|
|
3419
|
+
}
|
|
3420
|
+
/** Generates one entry from an em-unit shape. Does not cache or pack. */
|
|
3421
|
+
_generate(t, n) {
|
|
3422
|
+
const e = uc(t, this._pxPerEm, this._pxrange);
|
|
3423
|
+
return { glyph: {
|
|
2006
3424
|
x: 0,
|
|
2007
3425
|
y: 0,
|
|
2008
|
-
w:
|
|
2009
|
-
h:
|
|
2010
|
-
advance:
|
|
2011
|
-
planeLeft:
|
|
2012
|
-
planeBottom:
|
|
2013
|
-
planeRight:
|
|
2014
|
-
planeTop:
|
|
2015
|
-
}, msdf:
|
|
3426
|
+
w: e ? e.w : 0,
|
|
3427
|
+
h: e ? e.h : 0,
|
|
3428
|
+
advance: n,
|
|
3429
|
+
planeLeft: e ? e.planeLeft : 0,
|
|
3430
|
+
planeBottom: e ? e.planeBottom : 0,
|
|
3431
|
+
planeRight: e ? e.planeRight : 0,
|
|
3432
|
+
planeTop: e ? e.planeTop : 0
|
|
3433
|
+
}, msdf: e ? e.msdf : null };
|
|
2016
3434
|
}
|
|
2017
3435
|
/**
|
|
2018
|
-
* Lays out `text` left-to-right on a single line,
|
|
3436
|
+
* Lays out `text` left-to-right on a single line, kerned the way Chrome
|
|
3437
|
+
* kerns it (see src/font/shaper.ts: script runs, GPOS or the `kern` table).
|
|
2019
3438
|
* Generates any missing glyphs and packs the atlas **once** for the
|
|
2020
|
-
* whole run. Baseline is y=0 (`penY`
|
|
2021
|
-
* is the
|
|
3439
|
+
* whole run. Baseline is y=0 (`penY` is the glyph's GPOS y offset, almost
|
|
3440
|
+
* always 0); each `penX` is the glyph's drawing origin in em. One entry
|
|
3441
|
+
* per codepoint (no ligatures). `text` must not contain `\n` — use
|
|
2022
3442
|
* {@link Atlas.layoutMultiline} for multi-line input.
|
|
2023
3443
|
*/
|
|
2024
3444
|
layout(t) {
|
|
2025
|
-
const n =
|
|
2026
|
-
|
|
2027
|
-
this.
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
const
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
3445
|
+
const n = this._requireFont(), e = sr(n, t), i = C._gid, o = C._gp;
|
|
3446
|
+
let r = 0;
|
|
3447
|
+
const c = this._byGid;
|
|
3448
|
+
for (let y = 0; y < e; y++) {
|
|
3449
|
+
const _ = i[y];
|
|
3450
|
+
if (o[y] & xn || c[_]) continue;
|
|
3451
|
+
const g = this._generateForGlyphId(_);
|
|
3452
|
+
this._cache.set(_, g), c[_] = g.glyph, r++;
|
|
3453
|
+
}
|
|
3454
|
+
r > 0 && this._repack();
|
|
3455
|
+
const a = C._xa, l = C._xo, h = C._yo, f = n.metrics.unitsPerEm, u = [];
|
|
3456
|
+
let p = 0;
|
|
3457
|
+
for (let y = 0; y < e; y++) {
|
|
3458
|
+
const _ = o[y] & xn ? yc : c[i[y]];
|
|
3459
|
+
u.push({ glyph: _, penX: (p + l[y]) / f, penY: h[y] / f }), p += a[y];
|
|
3460
|
+
}
|
|
3461
|
+
return { glyphs: u, widthEm: p / f };
|
|
2037
3462
|
}
|
|
2038
3463
|
/**
|
|
2039
3464
|
* Lays out `text` as one or more `\n`-separated lines, each run through
|
|
@@ -2051,92 +3476,87 @@ class De {
|
|
|
2051
3476
|
* cropping.
|
|
2052
3477
|
*/
|
|
2053
3478
|
layoutMultiline(t) {
|
|
2054
|
-
const n = this.
|
|
2055
|
-
`),
|
|
3479
|
+
const n = this._requireFont(), e = n.metrics.unitsPerEm, i = (n.metrics.ascender - n.metrics.descender + n.metrics.lineGap) / e, o = t.split(`
|
|
3480
|
+
`), r = [];
|
|
2056
3481
|
let c = 0;
|
|
2057
|
-
for (let
|
|
2058
|
-
const { glyphs:
|
|
2059
|
-
for (const
|
|
2060
|
-
|
|
3482
|
+
for (let a = 0; a < o.length; a++) {
|
|
3483
|
+
const { glyphs: l, widthEm: h } = this.layout(o[a]), f = -a * i;
|
|
3484
|
+
for (const u of l)
|
|
3485
|
+
r.push({ glyph: u.glyph, penX: u.penX, penY: f + u.penY });
|
|
3486
|
+
h > c && (c = h);
|
|
2061
3487
|
}
|
|
2062
|
-
return { glyphs:
|
|
3488
|
+
return { glyphs: r, widthEm: c, heightEm: o.length * i };
|
|
2063
3489
|
}
|
|
2064
|
-
/** Repacks every cached
|
|
2065
|
-
*
|
|
2066
|
-
*
|
|
2067
|
-
*
|
|
3490
|
+
/** Repacks every cached entry (glyph-index- and string-keyed caches — one
|
|
3491
|
+
* shared texture) with potpack, reallocates the texture, and re-blits each
|
|
3492
|
+
* MSDF at its assigned rect. Called by `glyphsByIndex()`/`shapes()` after
|
|
3493
|
+
* any batch of new inserts — once per batch.
|
|
3494
|
+
*
|
|
3495
|
+
* Each cell gets a 1-texel gutter of zeros on its right and bottom, so a
|
|
3496
|
+
* quad covering the whole cell can sample its full rect: linear filtering
|
|
3497
|
+
* at the edge blends with zeros (further outside the glyph), never with a
|
|
3498
|
+
* neighbouring glyph's texels. */
|
|
2068
3499
|
_repack() {
|
|
2069
3500
|
const t = [];
|
|
2070
|
-
for (const
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
o.entry.glyph.x = o.x, o.entry.glyph.y = o.y, this._blit(o.entry.msdf, o.x, o.y, o.w, o.h);
|
|
3501
|
+
for (const i of [this._cache, this._cacheByKey])
|
|
3502
|
+
for (const { glyph: o, msdf: r } of i.values())
|
|
3503
|
+
r && t.push({ w: o.w + 1, h: o.h + 1, x: 0, y: 0, glyph: o, msdf: r });
|
|
3504
|
+
const { w: n, h: e } = _c(t);
|
|
3505
|
+
this._width = n, this._height = e, this._pixels = new Uint8Array(n * e * Ii), this._floats && (this._floats = new Float32Array(n * e * 3));
|
|
3506
|
+
for (const i of t)
|
|
3507
|
+
i.glyph.x = i.x, i.glyph.y = i.y, this._blit(i.msdf, i.x, i.y, i.glyph.w, i.glyph.h);
|
|
2078
3508
|
}
|
|
2079
3509
|
/**
|
|
2080
3510
|
* Quantise `msdf` (float, y-up, row 0 = bottom, w×h×3) into `_pixels` at
|
|
2081
3511
|
* atlas rect (`ax`, `ay`, `w`, `h`) — the single y-flip point.
|
|
2082
3512
|
*/
|
|
2083
|
-
_blit(t, n,
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
3513
|
+
_blit(t, n, e, i, o) {
|
|
3514
|
+
var a;
|
|
3515
|
+
const r = this._width, c = this._pixels;
|
|
3516
|
+
for (let l = 0; l < o; l++) {
|
|
3517
|
+
const h = e + (o - 1 - l);
|
|
3518
|
+
(a = this._floats) == null || a.set(t.subarray(l * i * 3, (l + 1) * i * 3), (h * r + n) * 3);
|
|
3519
|
+
for (let f = 0; f < i; f++) {
|
|
3520
|
+
const u = (l * i + f) * 3, p = (h * r + (n + f)) * Ii;
|
|
3521
|
+
c[p] = Qe(t[u]), c[p + 1] = Qe(t[u + 1]), c[p + 2] = Qe(t[u + 2]), c[p + 3] = 255;
|
|
2090
3522
|
}
|
|
2091
3523
|
}
|
|
2092
3524
|
}
|
|
2093
3525
|
}
|
|
2094
|
-
const
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
for (const e of i.contours)
|
|
2098
|
-
for (const p of e)
|
|
2099
|
-
for (let c = 0; c <= Ks; c++) {
|
|
2100
|
-
p.point(c / Ks, zn);
|
|
2101
|
-
const r = zn[0], h = zn[1];
|
|
2102
|
-
r < t && (t = r), h < n && (n = h), r > s && (s = r), h > o && (o = h);
|
|
2103
|
-
}
|
|
2104
|
-
return { minX: t, minY: n, maxX: s, maxY: o };
|
|
2105
|
-
}
|
|
2106
|
-
const Qs = /* @__PURE__ */ new Map();
|
|
2107
|
-
self.onmessage = (i) => {
|
|
2108
|
-
const t = i.data;
|
|
3526
|
+
const Di = /* @__PURE__ */ new Map();
|
|
3527
|
+
self.onmessage = (s) => {
|
|
3528
|
+
const t = s.data;
|
|
2109
3529
|
if (t.type === "build")
|
|
2110
3530
|
try {
|
|
2111
|
-
let n =
|
|
3531
|
+
let n = Di.get(t.fontKey);
|
|
2112
3532
|
if (!n) {
|
|
2113
3533
|
if (!t.font)
|
|
2114
3534
|
throw new Error(
|
|
2115
3535
|
`atlas-worker: no cached font for fontKey "${t.fontKey}" and no \`font\` bytes provided on this request`
|
|
2116
3536
|
);
|
|
2117
|
-
n = new
|
|
3537
|
+
n = new xr(t.font), Di.set(t.fontKey, n);
|
|
2118
3538
|
}
|
|
2119
|
-
const
|
|
2120
|
-
...
|
|
2121
|
-
penX:
|
|
2122
|
-
penY:
|
|
2123
|
-
})),
|
|
3539
|
+
const e = performance.now(), i = new gc(n, { pixelsPerEm: t.pixelsPerEm, pxrange: t.pxrange }), { glyphs: o, widthEm: r, heightEm: c } = i.layoutMultiline(t.text), a = performance.now() - e, l = o.map(({ glyph: u, penX: p, penY: y }) => ({
|
|
3540
|
+
...u,
|
|
3541
|
+
penX: p,
|
|
3542
|
+
penY: y
|
|
3543
|
+
})), h = i.texture.slice().buffer, f = {
|
|
2124
3544
|
type: "built",
|
|
2125
3545
|
id: t.id,
|
|
2126
3546
|
pixelsPerEm: t.pixelsPerEm,
|
|
2127
3547
|
pxrange: t.pxrange,
|
|
2128
|
-
pxrangeEm:
|
|
2129
|
-
width:
|
|
2130
|
-
height:
|
|
2131
|
-
texture:
|
|
2132
|
-
glyphs:
|
|
2133
|
-
widthEm:
|
|
3548
|
+
pxrangeEm: i.pxrangeEm,
|
|
3549
|
+
width: i.width,
|
|
3550
|
+
height: i.height,
|
|
3551
|
+
texture: h,
|
|
3552
|
+
glyphs: l,
|
|
3553
|
+
widthEm: r,
|
|
2134
3554
|
heightEm: c,
|
|
2135
|
-
genMs:
|
|
3555
|
+
genMs: a
|
|
2136
3556
|
};
|
|
2137
|
-
self.postMessage(
|
|
3557
|
+
self.postMessage(f, [h]);
|
|
2138
3558
|
} catch (n) {
|
|
2139
|
-
const
|
|
2140
|
-
self.postMessage(
|
|
3559
|
+
const e = { type: "error", id: t.id, message: String(n) };
|
|
3560
|
+
self.postMessage(e);
|
|
2141
3561
|
}
|
|
2142
3562
|
};
|