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