1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | const num2swu = num => String.fromCodePoint(0x1D80C + parseInt(num) - 250);
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | const coord2swu = coord => coord.map(num => num2swu(num)).join('');
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | const swu2code = swuSym => parseInt(swuSym.codePointAt(0));
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | const swu2id = swuSym => swu2code(swuSym) - 0x40000;
|
64 |
|
65 |
|
66 |
|
67 | let sizes = {};
|
68 | const zoom = 2;
|
69 | const bound = 76 * zoom;
|
70 | const canvaser = document.createElement("canvas");
|
71 | canvaser.width = bound;
|
72 | canvaser.height = bound;
|
73 | const context = canvaser.getContext("2d");
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | const symbolSize = function (id) {
|
85 | if (id in sizes) {
|
86 | return [...sizes[id]];
|
87 | }
|
88 |
|
89 | context.clearRect(0, 0, bound, bound);
|
90 | context.font = 30 * zoom + "px 'SuttonSignWritingLine'";
|
91 | context.fillText(String.fromCodePoint(id + 0xF0000), 0, 0);
|
92 | const imgData = context.getImageData(0, 0, bound, bound).data;
|
93 | let w, h, i, s;
|
94 |
|
95 | wloop: for (w = bound - 1; w >= 0; w--) {
|
96 | for (h = 0; h < bound; h += 1) {
|
97 | for (s = 0; s < 4; s += 1) {
|
98 | i = w * 4 + h * 4 * bound + s;
|
99 |
|
100 | if (imgData[i]) {
|
101 | break wloop;
|
102 | }
|
103 | }
|
104 | }
|
105 | }
|
106 |
|
107 | var width = w;
|
108 |
|
109 | hloop: for (h = bound - 1; h >= 0; h--) {
|
110 | for (w = 0; w < width; w += 1) {
|
111 | for (s = 0; s < 4; s += 1) {
|
112 | i = w * 4 + h * 4 * bound + s;
|
113 |
|
114 | if (imgData[i]) {
|
115 | break hloop;
|
116 | }
|
117 | }
|
118 | }
|
119 | }
|
120 |
|
121 | var height = h + 1;
|
122 | width = Math.ceil(width / zoom);
|
123 | height = Math.ceil(height / zoom);
|
124 |
|
125 | if (14394 == id) {
|
126 | width = 19;
|
127 | }
|
128 |
|
129 | if ([10468, 10480, 10496, 10512, 10500, 10532, 10548, 10862, 10878, 10894, 11058, 11074, 11476, 11488, 11492, 11504, 11508, 11520, 10516, 10910, 10926, 11042, 11082, 10942].includes(id)) {
|
130 | width = 20;
|
131 | }
|
132 |
|
133 | if (31921 == id) {
|
134 | width = 22;
|
135 | }
|
136 |
|
137 | if (38460 == id) {
|
138 | width = 23;
|
139 | }
|
140 |
|
141 | if ([20164, 20212].includes(id)) {
|
142 | width = 25;
|
143 | }
|
144 |
|
145 | if (31894 == id) {
|
146 | width = 28;
|
147 | }
|
148 |
|
149 | if (46698 == id) {
|
150 | width = 29;
|
151 | }
|
152 |
|
153 | if (29606 == id) {
|
154 | width = 30;
|
155 | }
|
156 |
|
157 | if (44855 == id) {
|
158 | width = 40;
|
159 | }
|
160 |
|
161 | if (32667 == id) {
|
162 | width = 50;
|
163 | }
|
164 |
|
165 | if ([11088, 11474, 11490, 11506].includes(id)) {
|
166 | height = 20;
|
167 | }
|
168 |
|
169 | if (6285 == id) {
|
170 | height = 21;
|
171 | }
|
172 |
|
173 | if (40804 == id) {
|
174 | height = 31;
|
175 | }
|
176 |
|
177 | if (41475 == id) {
|
178 | height = 36;
|
179 | }
|
180 |
|
181 |
|
182 |
|
183 | if (width == 0 && height == 0) {
|
184 | const sizefix = {
|
185 | 9: [15, 30],
|
186 | 10: [21, 30],
|
187 | 11: [30, 15],
|
188 | 12: [30, 21],
|
189 | 13: [15, 30],
|
190 | 14: [21, 30]
|
191 | };
|
192 |
|
193 | if (id in sizefix) {
|
194 | width = sizefix[id][0];
|
195 | height = sizefix[id][1];
|
196 | }
|
197 | }
|
198 |
|
199 | if (width == 0 && height == 0) {
|
200 | return undefined;
|
201 | }
|
202 |
|
203 | sizes[id] = [width, height];
|
204 | return [width, height];
|
205 | };
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 | const symbolSize$1 = function (swu) {
|
218 | return symbolSize(swu2id(swu));
|
219 | };
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | const symbolLine = function (id) {
|
231 | return String.fromCodePoint(id + 0xF0000);
|
232 | };
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | const symbolFill = function (id) {
|
245 | return String.fromCodePoint(id + 0x100000);
|
246 | };
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 | const symbolText = function (id) {
|
260 | return ` <text class="sym-fill" fill="white" style="pointer-events:none;font-family:'SuttonSignWritingFill';font-size:30px;">${symbolFill(id)}</text>
|
261 | <text class="sym-line" fill="black" style="pointer-events:none;font-family:'SuttonSignWritingLine';font-size:30px;">${symbolLine(id)}</text>`;
|
262 | };
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 | const symbolLine$1 = function (swu) {
|
275 | return symbolLine(swu2id(swu));
|
276 | };
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 | const symbolFill$1 = function (swu) {
|
289 | return symbolFill(swu2id(swu));
|
290 | };
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | const symbolText$1 = function (swu) {
|
304 | return symbolText(swu2id(swu));
|
305 | };
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 | let re = {
|
321 | 'colorize': 'C',
|
322 | 'colorhex': '(?:[0-9a-fA-F]{3}){1,2}',
|
323 | 'colorname': '[a-zA-Z]+',
|
324 | 'padding': 'P[0-9]{2}',
|
325 | 'zoom': 'Z(?:[0-9]+(?:\\.[0-9]+)?|x)',
|
326 | 'zoomsym': 'Z[0-9]{2},[0-9]+(?:\\.[0-9]+)?(?:,[0-9]{3}x[0-9]{3})?',
|
327 | 'classbase': '-?[_a-zA-Z][_a-zA-Z0-9-]{0,100}',
|
328 | 'id': '[a-zA-Z][_a-zA-Z0-9-]{0,100}'
|
329 | };
|
330 | re.colorbase = `(?:${re.colorhex}|${re.colorname})`;
|
331 | re.color = `_${re.colorbase}_`;
|
332 | re.colors = `_${re.colorbase}(?:,${re.colorbase})?_`;
|
333 | re.background = `G${re.color}`;
|
334 | re.detail = `D${re.colors}`;
|
335 | re.detailsym = `D[0-9]{2}${re.colors}`;
|
336 | re.classes = `${re.classbase}(?: ${re.classbase})*`;
|
337 | re.full = `-(${re.colorize})?(${re.padding})?(${re.background})?(${re.detail})?(${re.zoom})?(?:-((?:${re.detailsym})*)((?:${re.zoomsym})*))?(?:-(${re.classes})?!(?:(${re.id})!)?)?`;
|
338 |
|
339 | const prefixColor = color => {
|
340 | const regex = new RegExp(`^${re.colorhex}$`);
|
341 | return (regex.test(color) ? '#' : '') + color;
|
342 | };
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 | const parse = styleString => {
|
361 | const regex = `^${re.full}`;
|
362 | const m = (typeof styleString === 'string' ? styleString.match(new RegExp(regex)) : []) || [];
|
363 | return {
|
364 | 'colorize': !m[1] ? undefined : !!m[1],
|
365 | 'padding': !m[2] ? undefined : parseInt(m[2].slice(1)),
|
366 | 'background': !m[3] ? undefined : prefixColor(m[3].slice(2, -1)),
|
367 | 'detail': !m[4] ? undefined : m[4].slice(2, -1).split(',').map(prefixColor),
|
368 | 'zoom': !m[5] ? undefined : m[5] === 'Zx' ? 'x' : parseFloat(m[5].slice(1)),
|
369 | 'detailsym': !m[6] ? undefined : m[6].match(new RegExp(re.detailsym, 'g')).map(val => {
|
370 | const parts = val.split('_');
|
371 | const detail = parts[1].split(',').map(prefixColor);
|
372 | return {
|
373 | 'index': parseInt(parts[0].slice(1)),
|
374 | 'detail': detail
|
375 | };
|
376 | }),
|
377 | 'zoomsym': !m[7] ? undefined : m[7].match(new RegExp(re.zoomsym, 'g')).map(val => {
|
378 | const parts = val.split(',');
|
379 | return {
|
380 | 'index': parseInt(parts[0].slice(1)),
|
381 | 'zoom': parseFloat(parts[1]),
|
382 | 'offset': !parts[2] ? undefined : parts[2].split('x').map(val => parseInt(val) - 500)
|
383 | };
|
384 | }),
|
385 | 'classes': !m[8] ? undefined : m[8],
|
386 | 'id': !m[9] ? undefined : m[9]
|
387 | };
|
388 | };
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 | let re$1 = {
|
406 | 'symbol': '(?:(?:\uD8C0[\uDC01-\uDFFF])|(?:[\uD8C1-\uD8FC][\uDC00-\uDFFF])|(?:\uD8FD[\uDC00-\uDC80]))',
|
407 | 'coord': '(?:\uD836[\uDC0C-\uDDFF]){2}',
|
408 | 'sort': '\uD836\uDC00',
|
409 | 'box': '\uD836[\uDC01-\uDC04]'
|
410 | };
|
411 | re$1.prefix = `(?:${re$1.sort}(?:${re$1.symbol})+)`;
|
412 | re$1.spatial = `${re$1.symbol}${re$1.coord}`;
|
413 | re$1.signbox = `${re$1.box}${re$1.coord}(?:${re$1.spatial})*`;
|
414 | re$1.sign = `${re$1.prefix}?${re$1.signbox}`;
|
415 | re$1.sortable = `${re$1.prefix}${re$1.signbox}`;
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 | let re$1$1 = {
|
425 | 'colorize': 'C',
|
426 | 'colorhex': '(?:[0-9a-fA-F]{3}){1,2}',
|
427 | 'colorname': '[a-zA-Z]+',
|
428 | 'padding': 'P[0-9]{2}',
|
429 | 'zoom': 'Z(?:[0-9]+(?:\\.[0-9]+)?|x)',
|
430 | 'zoomsym': 'Z[0-9]{2},[0-9]+(?:\\.[0-9]+)?(?:,[0-9]{3}x[0-9]{3})?',
|
431 | 'classbase': '-?[_a-zA-Z][_a-zA-Z0-9-]{0,100}',
|
432 | 'id': '[a-zA-Z][_a-zA-Z0-9-]{0,100}'
|
433 | };
|
434 | re$1$1.colorbase = `(?:${re$1$1.colorhex}|${re$1$1.colorname})`;
|
435 | re$1$1.color = `_${re$1$1.colorbase}_`;
|
436 | re$1$1.colors = `_${re$1$1.colorbase}(?:,${re$1$1.colorbase})?_`;
|
437 | re$1$1.background = `G${re$1$1.color}`;
|
438 | re$1$1.detail = `D${re$1$1.colors}`;
|
439 | re$1$1.detailsym = `D[0-9]{2}${re$1$1.colors}`;
|
440 | re$1$1.classes = `${re$1$1.classbase}(?: ${re$1$1.classbase})*`;
|
441 | re$1$1.full = `-(${re$1$1.colorize})?(${re$1$1.padding})?(${re$1$1.background})?(${re$1$1.detail})?(${re$1$1.zoom})?(?:-((?:${re$1$1.detailsym})*)((?:${re$1$1.zoomsym})*))?(?:-(${re$1$1.classes})?!(?:(${re$1$1.id})!)?)?`;
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 | const swu2num = swuNum => parseInt(swuNum.codePointAt(0)) - 0x1D80C + 250;
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 | const swu2coord = swuCoord => [swu2num(swuCoord.slice(0, 2)), swu2num(swuCoord.slice(2, 4))];
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 | const swu2code$1 = swuSym => parseInt(swuSym.codePointAt(0));
|
486 |
|
487 | const parse$1 = {
|
488 | |
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 | symbol: swuSym => {
|
503 | const regex = `^(${re$1.symbol})(${re$1.coord})?(${re$1$1.full})?`;
|
504 | const symbol = typeof swuSym === 'string' ? swuSym.match(new RegExp(regex)) : undefined;
|
505 | return {
|
506 | 'symbol': symbol ? symbol[1] : undefined,
|
507 | 'coord': symbol && symbol[2] ? swu2coord(symbol[2]) : undefined,
|
508 | 'style': symbol ? symbol[3] : undefined
|
509 | };
|
510 | },
|
511 |
|
512 | |
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 | sign: swuSign => {
|
546 | const regex = `^(${re$1.prefix})?(${re$1.signbox})(${re$1$1.full})?`;
|
547 | const sign = typeof swuSign === 'string' ? swuSign.match(new RegExp(regex)) : undefined;
|
548 |
|
549 | if (sign) {
|
550 | return {
|
551 | 'sequence': sign[1] ? sign[1].slice(2).match(/.{2}/g) : undefined,
|
552 | 'box': sign[2].slice(0, 2),
|
553 | 'max': swu2coord(sign[2].slice(2, 6)),
|
554 | 'spatials': sign[2].length < 7 ? undefined : sign[2].slice(6).match(/(.{6})/g).map(m => {
|
555 | return {
|
556 | symbol: m.slice(0, 2),
|
557 | coord: swu2coord(m.slice(2))
|
558 | };
|
559 | }),
|
560 | 'style': sign[3]
|
561 | };
|
562 | } else {
|
563 | return {};
|
564 | }
|
565 | }
|
566 | };
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 | const category = [0x40001, 0x461e1, 0x4bca1, 0x4bfa1, 0x4e8e1, 0x4efa1, 0x4f2a1];
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 | const ranges = {
|
583 | 'all': [0x40001, 0x4f480],
|
584 | 'writing': [0x40001, 0x4efa0],
|
585 | 'hand': [0x40001, 0x461e0],
|
586 | 'movement': [0x461e1, 0x4bca0],
|
587 | 'dynamic': [0x4bca1, 0x4bfa0],
|
588 | 'head': [0x4bfa1, 0x4e8e0],
|
589 | 'hcenter': [0x4bfa1, 0x4e8e0],
|
590 | 'vcenter': [0x4bfa1, 0x4ec40],
|
591 | 'trunk': [0x4e8e1, 0x4ec40],
|
592 | 'limb': [0x4ec41, 0x4efa0],
|
593 | 'location': [0x4efa1, 0x4f2a0],
|
594 | 'punctuation': [0x4f2a1, 0x4f480]
|
595 | };
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 | const colors = ['#0000CC', '#CC0000', '#FF0099', '#006600', '#000000', '#884411', '#FF9900'];
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 | const colorize = swuSym => {
|
616 | const parsed = parse$1.symbol(swuSym);
|
617 | let color = '#000000';
|
618 |
|
619 | if (parsed.symbol) {
|
620 | const code = swu2code$1(parsed.symbol);
|
621 | const index = category.findIndex(val => val > code);
|
622 | color = colors[index < 0 ? 6 : index - 1];
|
623 | }
|
624 |
|
625 | return color;
|
626 | };
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 | const symbolSvg = swuSym => {
|
648 | const parsed = parse$1.symbol(swuSym);
|
649 | const blank = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>';
|
650 |
|
651 | if (parsed.symbol) {
|
652 | let size = symbolSize$1(parsed.symbol);
|
653 |
|
654 | if (size) {
|
655 | let styling = parse(parsed.style);
|
656 | let line;
|
657 | let symSvg = symbolText$1(parsed.symbol);
|
658 | symSvg = ` <g transform="translate(500,500)">
|
659 | ${symSvg}
|
660 | </g>`;
|
661 |
|
662 | if (styling.colorize) {
|
663 | line = colorize(parsed.symbol);
|
664 | } else if (styling.detail) {
|
665 | line = styling.detail[0];
|
666 | }
|
667 |
|
668 | if (line) {
|
669 | symSvg = symSvg.replace(/class="sym-line" fill="black"/, `class="sym-line" fill="${line}"`);
|
670 | }
|
671 |
|
672 | let fill = styling.detail && styling.detail[1];
|
673 |
|
674 | if (fill) {
|
675 | symSvg = symSvg.replace(/class="sym-fill" fill="white"/, `class="sym-fill" fill="${fill}"`);
|
676 | }
|
677 |
|
678 | let x1 = 500;
|
679 | let y1 = 500;
|
680 | let background = '';
|
681 |
|
682 | if (styling.padding) {
|
683 | x1 -= styling.padding;
|
684 | y1 -= styling.padding;
|
685 | size[0] += styling.padding * 2;
|
686 | size[1] += styling.padding * 2;
|
687 | }
|
688 |
|
689 | if (styling.background) {
|
690 | background = `\n <rect x="${x1}" y="${y1}" width="${size[0]}" height="${size[1]}" style="fill:${styling.background};" />`;
|
691 | }
|
692 |
|
693 | let sizing = '';
|
694 |
|
695 | if (styling.zoom != 'x') {
|
696 | sizing = ` width="${size[0] * (styling.zoom ? styling.zoom : 1)}" height="${size[1] * (styling.zoom ? styling.zoom : 1)}"`;
|
697 | }
|
698 |
|
699 | let classes = '';
|
700 |
|
701 | if (styling.classes) {
|
702 | classes = ` class="${styling.classes}"`;
|
703 | }
|
704 |
|
705 | let id = '';
|
706 |
|
707 | if (styling.id) {
|
708 | id = ` id="${styling.id}"`;
|
709 | }
|
710 |
|
711 | return `<svg${classes}${id} version="1.1" xmlns="http://www.w3.org/2000/svg"${sizing} viewBox="${x1} ${y1} ${size[0]} ${size[1]}">
|
712 | <text font-size="0">${swuSym}</text>${background}
|
713 | ${symSvg}
|
714 | </svg>`;
|
715 | }
|
716 | }
|
717 |
|
718 | return blank;
|
719 | };
|
720 |
|
721 | const symbolCanvas = function (swuSym) {
|
722 | const parsed = parse$1.symbol(swuSym);
|
723 |
|
724 | if (parsed.symbol) {
|
725 | let size = symbolSize$1(parsed.symbol);
|
726 |
|
727 | if (size) {
|
728 | const canvas = document.createElement('canvas');
|
729 | const context = canvas.getContext('2d');
|
730 | let styling = parse(parsed.style);
|
731 | let line = 'black';
|
732 |
|
733 | if (styling.colorize) {
|
734 | line = colorize(parsed.symbol);
|
735 | } else if (styling.detail) {
|
736 | line = styling.detail[0];
|
737 | }
|
738 |
|
739 | let fill = styling.detail && styling.detail[1] || 'white';
|
740 | let x1 = 500;
|
741 | let x2 = x1 + size[0];
|
742 | let y1 = 500;
|
743 | let y2 = y1 + size[1];
|
744 |
|
745 | if (styling.padding) {
|
746 | x1 -= styling.padding;
|
747 | y1 -= styling.padding;
|
748 | x2 += styling.padding;
|
749 | y2 += styling.padding;
|
750 | }
|
751 |
|
752 | let sizing = 1;
|
753 |
|
754 | if (styling.zoom != 'x') {
|
755 | sizing = styling.zoom;
|
756 | }
|
757 |
|
758 | let w = (x2 - x1) * sizing;
|
759 | let h = (y2 - y1) * sizing;
|
760 | canvas.width = w ? w : 1;
|
761 | canvas.height = h ? h : 1;
|
762 |
|
763 | if (styling.background) {
|
764 | context.rect(0, 0, w, h);
|
765 | context.fillStyle = styling.background;
|
766 | context.fill();
|
767 | }
|
768 |
|
769 | context.font = 30 * sizing + "px 'SuttonSignWritingFill'";
|
770 | context.fillStyle = fill;
|
771 | context.fillText(symbolFill$1(parsed.symbol), (500 - x1) * sizing, (500 - y1) * sizing);
|
772 | context.font = 30 * sizing + "px 'SuttonSignWritingLine'";
|
773 | context.fillStyle = line;
|
774 | context.fillText(symbolLine$1(parsed.symbol), (500 - x1) * sizing, (500 - y1) * sizing);
|
775 | return canvas;
|
776 | }
|
777 | }
|
778 | };
|
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 |
|
790 | const symbolPng = swuSym => {
|
791 | const canvas = symbolCanvas(swuSym);
|
792 | const png = canvas.toDataURL("image/png");
|
793 | canvas.remove();
|
794 | return png;
|
795 | };
|
796 |
|
797 | const blank = null;
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 | const symbolNormalize = swuSym => {
|
809 | const parsed = parse$1.symbol(swuSym);
|
810 |
|
811 | if (parsed.symbol) {
|
812 | let size = symbolSize$1(parsed.symbol);
|
813 |
|
814 | if (size) {
|
815 | return `${parsed.symbol}${coord2swu([500 - parseInt(size[0] / 2), 500 - parseInt(size[1] / 2)])}${parsed.style || ''}`;
|
816 | }
|
817 | } else {
|
818 | return blank;
|
819 | }
|
820 | };
|
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 |
|
832 |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 |
|
851 | const signSvg = swuSign => {
|
852 | let parsed = parse$1.sign(swuSign);
|
853 | const blank = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>';
|
854 |
|
855 | if (parsed.spatials) {
|
856 | let styling = parse(parsed.style);
|
857 |
|
858 | if (styling.detailsym) {
|
859 | styling.detailsym.forEach(sym => {
|
860 | if (parsed.spatials[sym.index - 1]) {
|
861 | parsed.spatials[sym.index - 1].detail = sym.detail;
|
862 | }
|
863 | });
|
864 | }
|
865 |
|
866 | let x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
867 | let y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
868 | let x2 = parsed.max[0];
|
869 | let y2 = parsed.max[1];
|
870 |
|
871 | if (styling.zoomsym) {
|
872 | styling.zoomsym.forEach(sym => {
|
873 | if (parsed.spatials[sym.index - 1]) {
|
874 | parsed.spatials[sym.index - 1].zoom = sym.zoom;
|
875 |
|
876 | if (sym.offset) {
|
877 | parsed.spatials[sym.index - 1].coord[0] += sym.offset[0];
|
878 | parsed.spatials[sym.index - 1].coord[1] += sym.offset[1];
|
879 | }
|
880 |
|
881 | let size = symbolSize$1(parsed.spatials[sym.index - 1].symbol);
|
882 | x2 = Math.max(x2, parsed.spatials[sym.index - 1].coord[0] + size[0] * sym.zoom);
|
883 | y2 = Math.max(y2, parsed.spatials[sym.index - 1].coord[1] + size[1] * sym.zoom);
|
884 | }
|
885 | });
|
886 | }
|
887 |
|
888 | let classes = '';
|
889 |
|
890 | if (styling.classes) {
|
891 | classes = ` class="${styling.classes}"`;
|
892 | }
|
893 |
|
894 | let id = '';
|
895 |
|
896 | if (styling.id) {
|
897 | id = ` id="${styling.id}"`;
|
898 | }
|
899 |
|
900 | let background = '';
|
901 |
|
902 | if (styling.padding) {
|
903 | x1 -= styling.padding;
|
904 | y1 -= styling.padding;
|
905 | x2 += styling.padding;
|
906 | y2 += styling.padding;
|
907 | }
|
908 |
|
909 | if (styling.background) {
|
910 | background = `\n <rect x="${x1}" y="${y1}" width="${x2 - x1}" height="${y2 - y1}" style="fill:${styling.background};" />`;
|
911 | }
|
912 |
|
913 | let sizing = '';
|
914 |
|
915 | if (styling.zoom != 'x') {
|
916 | sizing = ` width="${(x2 - x1) * (styling.zoom ? styling.zoom : 1)}" height="${(y2 - y1) * (styling.zoom ? styling.zoom : 1)}"`;
|
917 | }
|
918 |
|
919 | let svg = `<svg${classes}${id} version="1.1" xmlns="http://www.w3.org/2000/svg"${sizing} viewBox="${x1} ${y1} ${x2 - x1} ${y2 - y1}">
|
920 | <text font-size="0">${swuSign}</text>${background}`;
|
921 | const line = styling.detail && styling.detail[0];
|
922 | const fill = styling.detail && styling.detail[1];
|
923 | svg += '\n' + parsed.spatials.map(spatial => {
|
924 | let svg = symbolText$1(spatial.symbol, spatial.coord);
|
925 | let symLine = line;
|
926 |
|
927 | if (spatial.detail) {
|
928 | symLine = spatial.detail[0];
|
929 | } else if (styling.colorize) {
|
930 | symLine = colorize(spatial.symbol);
|
931 | }
|
932 |
|
933 | if (symLine) {
|
934 | svg = svg.replace(/class="sym-line" fill="black"/, `class="sym-line" fill="${symLine}"`);
|
935 | }
|
936 |
|
937 | let symFill = fill;
|
938 |
|
939 | if (spatial.detail && spatial.detail[1]) {
|
940 | symFill = spatial.detail[1];
|
941 | }
|
942 |
|
943 | if (symFill) {
|
944 | svg = svg.replace(/class="sym-fill" fill="white"/, `class="sym-fill" fill="${symFill}"`);
|
945 | }
|
946 |
|
947 | if (spatial.zoom) {
|
948 | svg = `<g transform="scale(${spatial.zoom})">${svg}</g>`;
|
949 | }
|
950 |
|
951 | return ` <g transform="translate(${spatial.coord[0]},${spatial.coord[1]})">
|
952 | ${svg}
|
953 | </g>`;
|
954 | }).join('\n');
|
955 | svg += '\n</svg>';
|
956 | return svg;
|
957 | }
|
958 |
|
959 | return blank;
|
960 | };
|
961 |
|
962 | const signCanvas = function (swuSign) {
|
963 | const parsed = parse$1.sign(swuSign);
|
964 |
|
965 | if (parsed.spatials) {
|
966 | const canvas = document.createElement('canvas');
|
967 | const context = canvas.getContext('2d');
|
968 | let styling = parse(parsed.style);
|
969 |
|
970 | if (styling.detailsym) {
|
971 | styling.detailsym.forEach(sym => {
|
972 | if (parsed.spatials[sym.index - 1]) {
|
973 | parsed.spatials[sym.index - 1].detail = sym.detail;
|
974 | }
|
975 | });
|
976 | }
|
977 |
|
978 | let x1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[0]));
|
979 | let y1 = Math.min(...parsed.spatials.map(spatial => spatial.coord[1]));
|
980 | let x2 = parsed.max[0];
|
981 | let y2 = parsed.max[1];
|
982 |
|
983 | if (styling.zoomsym) {
|
984 | styling.zoomsym.forEach(sym => {
|
985 | if (parsed.spatials[sym.index - 1]) {
|
986 | parsed.spatials[sym.index - 1].zoom = sym.zoom;
|
987 |
|
988 | if (sym.offset) {
|
989 | parsed.spatials[sym.index - 1].coord[0] += sym.offset[0];
|
990 | parsed.spatials[sym.index - 1].coord[1] += sym.offset[1];
|
991 | }
|
992 |
|
993 | let size = symbolSize$1(parsed.spatials[sym.index - 1].symbol);
|
994 | x2 = Math.max(x2, parsed.spatials[sym.index - 1].coord[0] + size[0] * sym.zoom);
|
995 | y2 = Math.max(y2, parsed.spatials[sym.index - 1].coord[1] + size[1] * sym.zoom);
|
996 | }
|
997 | });
|
998 | }
|
999 |
|
1000 | if (styling.padding) {
|
1001 | x1 -= styling.padding;
|
1002 | y1 -= styling.padding;
|
1003 | x2 += styling.padding;
|
1004 | y2 += styling.padding;
|
1005 | }
|
1006 |
|
1007 | let sizing = 1;
|
1008 |
|
1009 | if (styling.zoom != 'x') {
|
1010 | sizing = styling.zoom;
|
1011 | }
|
1012 |
|
1013 | let w = (x2 - x1) * sizing;
|
1014 | let h = (y2 - y1) * sizing;
|
1015 | canvas.width = w ? w : 1;
|
1016 | canvas.height = h ? h : 1;
|
1017 |
|
1018 | if (styling.background) {
|
1019 | context.rect(0, 0, w, h);
|
1020 | context.fillStyle = styling.background;
|
1021 | context.fill();
|
1022 | }
|
1023 |
|
1024 | const line = styling.detail && styling.detail[0] || "black";
|
1025 | const fill = styling.detail && styling.detail[1] || "white";
|
1026 | parsed.spatials.forEach(spatial => {
|
1027 | let symLine = line;
|
1028 |
|
1029 | if (spatial.detail) {
|
1030 | symLine = spatial.detail[0];
|
1031 | } else if (styling.colorize) {
|
1032 | symLine = colorize(spatial.symbol);
|
1033 | }
|
1034 |
|
1035 | let symFill = fill;
|
1036 |
|
1037 | if (spatial.detail && spatial.detail[1]) {
|
1038 | symFill = spatial.detail[1];
|
1039 | }
|
1040 |
|
1041 | let symZoom = spatial.zoom || 1;
|
1042 | context.font = 30 * sizing * symZoom + "px 'SuttonSignWritingFill'";
|
1043 | context.fillStyle = symFill;
|
1044 | context.fillText(symbolFill$1(spatial.symbol), (spatial.coord[0] - x1) * sizing, (spatial.coord[1] - y1) * sizing);
|
1045 | context.font = 30 * sizing * symZoom + "px 'SuttonSignWritingLine'";
|
1046 | context.fillStyle = symLine;
|
1047 | context.fillText(symbolLine$1(spatial.symbol), (spatial.coord[0] - x1) * sizing, (spatial.coord[1] - y1) * sizing);
|
1048 | });
|
1049 | return canvas;
|
1050 | }
|
1051 | };
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 | const signPng = swuSign => {
|
1064 | const canvas = signCanvas(swuSign);
|
1065 | const png = canvas.toDataURL("image/png");
|
1066 | canvas.remove();
|
1067 | return png;
|
1068 | };
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 | const signNormalize = swuSign => {
|
1081 | const parsed = parse$1.sign(swuSign);
|
1082 |
|
1083 | if (parsed.spatials) {
|
1084 | const symbolsizes = parsed.spatials.reduce((output, spatial) => {
|
1085 | const size = symbolSize$1(spatial.symbol);
|
1086 | output[spatial.symbol] = {
|
1087 | width: size[0],
|
1088 | height: size[1]
|
1089 | };
|
1090 | return output;
|
1091 | }, {});
|
1092 |
|
1093 | const bbox = symbols => {
|
1094 | const x1 = Math.min(...symbols.map(spatial => spatial.coord[0]));
|
1095 | const y1 = Math.min(...symbols.map(spatial => spatial.coord[1]));
|
1096 | const x2 = Math.max(...symbols.map(spatial => spatial.coord[0] + parseInt(symbolsizes[spatial.symbol].width)));
|
1097 | const y2 = Math.max(...symbols.map(spatial => spatial.coord[1] + parseInt(symbolsizes[spatial.symbol].height)));
|
1098 | return {
|
1099 | x1: x1,
|
1100 | y1: y1,
|
1101 | x2: x2,
|
1102 | y2: y2
|
1103 | };
|
1104 | };
|
1105 |
|
1106 | const hrange = ranges['hcenter'];
|
1107 | const hsyms = parsed.spatials.filter(spatial => {
|
1108 | const dec = parseInt(spatial.symbol.slice(1, 4), 16);
|
1109 | return hrange[0] <= dec && hrange[1] >= dec;
|
1110 | });
|
1111 | const vrange = ranges['vcenter'];
|
1112 | const vsyms = parsed.spatials.filter(spatial => {
|
1113 | const dec = parseInt(spatial.symbol.slice(1, 4), 16);
|
1114 | return vrange[0] <= dec && vrange[1] >= dec;
|
1115 | });
|
1116 | let abox = bbox(parsed.spatials);
|
1117 | let max = [abox.x2, abox.y2];
|
1118 |
|
1119 | if (hsyms.length) {
|
1120 | const hbox = bbox(hsyms);
|
1121 | abox.x1 = hbox.x1;
|
1122 | abox.x2 = hbox.x2;
|
1123 | }
|
1124 |
|
1125 | if (vsyms.length) {
|
1126 | const vbox = bbox(vsyms);
|
1127 | abox.y1 = vbox.y1;
|
1128 | abox.y2 = vbox.y2;
|
1129 | }
|
1130 |
|
1131 | const offset = [parseInt((abox.x2 + abox.x1) / 2) - 500, parseInt((abox.y2 + abox.y1) / 2) - 500];
|
1132 | const swuout = (parsed.sequence ? 'ð ' + parsed.sequence.join('') : '') + parsed.box + coord2swu([max[0] - offset[0], max[1] - offset[1]]) + parsed.spatials.map(spatial => spatial.symbol + coord2swu([spatial.coord[0] - offset[0], spatial.coord[1] - offset[1]])).join('') + (parsed.style || '');
|
1133 | return swuout;
|
1134 | }
|
1135 | };
|
1136 |
|
1137 | export { signNormalize, signPng, signSvg, symbolFill$1 as symbolFill, symbolLine$1 as symbolLine, symbolNormalize, symbolPng, symbolSize$1 as symbolSize, symbolSvg, symbolText$1 as symbolText };
|
1138 |
|
1139 |
|