@kittl/pdfkit 0.17.3 → 0.17.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3706 @@
1
+ function write_svg (doc, svg, x, y, options) {
2
+
3
+ const NamedColors = {
4
+ aliceblue: [240, 248, 255],
5
+ antiquewhite: [250, 235, 215],
6
+ aqua: [0, 255, 255],
7
+ aquamarine: [127, 255, 212],
8
+ azure: [240, 255, 255],
9
+ beige: [245, 245, 220],
10
+ bisque: [255, 228, 196],
11
+ black: [0, 0, 0],
12
+ blanchedalmond: [255, 235, 205],
13
+ blue: [0, 0, 255],
14
+ blueviolet: [138, 43, 226],
15
+ brown: [165, 42, 42],
16
+ burlywood: [222, 184, 135],
17
+ cadetblue: [95, 158, 160],
18
+ chartreuse: [127, 255, 0],
19
+ chocolate: [210, 105, 30],
20
+ coral: [255, 127, 80],
21
+ cornflowerblue: [100, 149, 237],
22
+ cornsilk: [255, 248, 220],
23
+ crimson: [220, 20, 60],
24
+ cyan: [0, 255, 255],
25
+ darkblue: [0, 0, 139],
26
+ darkcyan: [0, 139, 139],
27
+ darkgoldenrod: [184, 134, 11],
28
+ darkgray: [169, 169, 169],
29
+ darkgrey: [169, 169, 169],
30
+ darkgreen: [0, 100, 0],
31
+ darkkhaki: [189, 183, 107],
32
+ darkmagenta: [139, 0, 139],
33
+ darkolivegreen: [85, 107, 47],
34
+ darkorange: [255, 140, 0],
35
+ darkorchid: [153, 50, 204],
36
+ darkred: [139, 0, 0],
37
+ darksalmon: [233, 150, 122],
38
+ darkseagreen: [143, 188, 143],
39
+ darkslateblue: [72, 61, 139],
40
+ darkslategray: [47, 79, 79],
41
+ darkslategrey: [47, 79, 79],
42
+ darkturquoise: [0, 206, 209],
43
+ darkviolet: [148, 0, 211],
44
+ deeppink: [255, 20, 147],
45
+ deepskyblue: [0, 191, 255],
46
+ dimgray: [105, 105, 105],
47
+ dimgrey: [105, 105, 105],
48
+ dodgerblue: [30, 144, 255],
49
+ firebrick: [178, 34, 34],
50
+ floralwhite: [255, 250, 240],
51
+ forestgreen: [34, 139, 34],
52
+ fuchsia: [255, 0, 255],
53
+ gainsboro: [220, 220, 220],
54
+ ghostwhite: [248, 248, 255],
55
+ gold: [255, 215, 0],
56
+ goldenrod: [218, 165, 32],
57
+ gray: [128, 128, 128],
58
+ grey: [128, 128, 128],
59
+ green: [0, 128, 0],
60
+ greenyellow: [173, 255, 47],
61
+ honeydew: [240, 255, 240],
62
+ hotpink: [255, 105, 180],
63
+ indianred: [205, 92, 92],
64
+ indigo: [75, 0, 130],
65
+ ivory: [255, 255, 240],
66
+ khaki: [240, 230, 140],
67
+ lavender: [230, 230, 250],
68
+ lavenderblush: [255, 240, 245],
69
+ lawngreen: [124, 252, 0],
70
+ lemonchiffon: [255, 250, 205],
71
+ lightblue: [173, 216, 230],
72
+ lightcoral: [240, 128, 128],
73
+ lightcyan: [224, 255, 255],
74
+ lightgoldenrodyellow: [250, 250, 210],
75
+ lightgray: [211, 211, 211],
76
+ lightgrey: [211, 211, 211],
77
+ lightgreen: [144, 238, 144],
78
+ lightpink: [255, 182, 193],
79
+ lightsalmon: [255, 160, 122],
80
+ lightseagreen: [32, 178, 170],
81
+ lightskyblue: [135, 206, 250],
82
+ lightslategray: [119, 136, 153],
83
+ lightslategrey: [119, 136, 153],
84
+ lightsteelblue: [176, 196, 222],
85
+ lightyellow: [255, 255, 224],
86
+ lime: [0, 255, 0],
87
+ limegreen: [50, 205, 50],
88
+ linen: [250, 240, 230],
89
+ magenta: [255, 0, 255],
90
+ maroon: [128, 0, 0],
91
+ mediumaquamarine: [102, 205, 170],
92
+ mediumblue: [0, 0, 205],
93
+ mediumorchid: [186, 85, 211],
94
+ mediumpurple: [147, 112, 219],
95
+ mediumseagreen: [60, 179, 113],
96
+ mediumslateblue: [123, 104, 238],
97
+ mediumspringgreen: [0, 250, 154],
98
+ mediumturquoise: [72, 209, 204],
99
+ mediumvioletred: [199, 21, 133],
100
+ midnightblue: [25, 25, 112],
101
+ mintcream: [245, 255, 250],
102
+ mistyrose: [255, 228, 225],
103
+ moccasin: [255, 228, 181],
104
+ navajowhite: [255, 222, 173],
105
+ navy: [0, 0, 128],
106
+ oldlace: [253, 245, 230],
107
+ olive: [128, 128, 0],
108
+ olivedrab: [107, 142, 35],
109
+ orange: [255, 165, 0],
110
+ orangered: [255, 69, 0],
111
+ orchid: [218, 112, 214],
112
+ palegoldenrod: [238, 232, 170],
113
+ palegreen: [152, 251, 152],
114
+ paleturquoise: [175, 238, 238],
115
+ palevioletred: [219, 112, 147],
116
+ papayawhip: [255, 239, 213],
117
+ peachpuff: [255, 218, 185],
118
+ peru: [205, 133, 63],
119
+ pink: [255, 192, 203],
120
+ plum: [221, 160, 221],
121
+ powderblue: [176, 224, 230],
122
+ purple: [128, 0, 128],
123
+ rebeccapurple: [102, 51, 153],
124
+ red: [255, 0, 0],
125
+ rosybrown: [188, 143, 143],
126
+ royalblue: [65, 105, 225],
127
+ saddlebrown: [139, 69, 19],
128
+ salmon: [250, 128, 114],
129
+ sandybrown: [244, 164, 96],
130
+ seagreen: [46, 139, 87],
131
+ seashell: [255, 245, 238],
132
+ sienna: [160, 82, 45],
133
+ silver: [192, 192, 192],
134
+ skyblue: [135, 206, 235],
135
+ slateblue: [106, 90, 205],
136
+ slategray: [112, 128, 144],
137
+ slategrey: [112, 128, 144],
138
+ snow: [255, 250, 250],
139
+ springgreen: [0, 255, 127],
140
+ steelblue: [70, 130, 180],
141
+ tan: [210, 180, 140],
142
+ teal: [0, 128, 128],
143
+ thistle: [216, 191, 216],
144
+ tomato: [255, 99, 71],
145
+ turquoise: [64, 224, 208],
146
+ violet: [238, 130, 238],
147
+ wheat: [245, 222, 179],
148
+ white: [255, 255, 255],
149
+ whitesmoke: [245, 245, 245],
150
+ yellow: [255, 255, 0]
151
+ };
152
+ const DefaultColors = {
153
+ black: [NamedColors.black, 1],
154
+ white: [NamedColors.white, 1],
155
+ transparent: [NamedColors.black, 0]
156
+ };
157
+ const Entities = {
158
+ quot: 34,
159
+ amp: 38,
160
+ lt: 60,
161
+ gt: 62,
162
+ apos: 39,
163
+ OElig: 338,
164
+ oelig: 339,
165
+ Scaron: 352,
166
+ scaron: 353,
167
+ Yuml: 376,
168
+ circ: 710,
169
+ tilde: 732,
170
+ ensp: 8194,
171
+ emsp: 8195,
172
+ thinsp: 8201,
173
+ zwnj: 8204,
174
+ zwj: 8205,
175
+ lrm: 8206,
176
+ rlm: 8207,
177
+ ndash: 8211,
178
+ mdash: 8212,
179
+ lsquo: 8216,
180
+ rsquo: 8217,
181
+ sbquo: 8218,
182
+ ldquo: 8220,
183
+ rdquo: 8221,
184
+ bdquo: 8222,
185
+ dagger: 8224,
186
+ Dagger: 8225,
187
+ permil: 8240,
188
+ lsaquo: 8249,
189
+ rsaquo: 8250,
190
+ euro: 8364,
191
+ nbsp: 160,
192
+ iexcl: 161,
193
+ cent: 162,
194
+ pound: 163,
195
+ curren: 164,
196
+ yen: 165,
197
+ brvbar: 166,
198
+ sect: 167,
199
+ uml: 168,
200
+ copy: 169,
201
+ ordf: 170,
202
+ laquo: 171,
203
+ not: 172,
204
+ shy: 173,
205
+ reg: 174,
206
+ macr: 175,
207
+ deg: 176,
208
+ plusmn: 177,
209
+ sup2: 178,
210
+ sup3: 179,
211
+ acute: 180,
212
+ micro: 181,
213
+ para: 182,
214
+ middot: 183,
215
+ cedil: 184,
216
+ sup1: 185,
217
+ ordm: 186,
218
+ raquo: 187,
219
+ frac14: 188,
220
+ frac12: 189,
221
+ frac34: 190,
222
+ iquest: 191,
223
+ Agrave: 192,
224
+ Aacute: 193,
225
+ Acirc: 194,
226
+ Atilde: 195,
227
+ Auml: 196,
228
+ Aring: 197,
229
+ AElig: 198,
230
+ Ccedil: 199,
231
+ Egrave: 200,
232
+ Eacute: 201,
233
+ Ecirc: 202,
234
+ Euml: 203,
235
+ Igrave: 204,
236
+ Iacute: 205,
237
+ Icirc: 206,
238
+ Iuml: 207,
239
+ ETH: 208,
240
+ Ntilde: 209,
241
+ Ograve: 210,
242
+ Oacute: 211,
243
+ Ocirc: 212,
244
+ Otilde: 213,
245
+ Ouml: 214,
246
+ times: 215,
247
+ Oslash: 216,
248
+ Ugrave: 217,
249
+ Uacute: 218,
250
+ Ucirc: 219,
251
+ Uuml: 220,
252
+ Yacute: 221,
253
+ THORN: 222,
254
+ szlig: 223,
255
+ agrave: 224,
256
+ aacute: 225,
257
+ acirc: 226,
258
+ atilde: 227,
259
+ auml: 228,
260
+ aring: 229,
261
+ aelig: 230,
262
+ ccedil: 231,
263
+ egrave: 232,
264
+ eacute: 233,
265
+ ecirc: 234,
266
+ euml: 235,
267
+ igrave: 236,
268
+ iacute: 237,
269
+ icirc: 238,
270
+ iuml: 239,
271
+ eth: 240,
272
+ ntilde: 241,
273
+ ograve: 242,
274
+ oacute: 243,
275
+ ocirc: 244,
276
+ otilde: 245,
277
+ ouml: 246,
278
+ divide: 247,
279
+ oslash: 248,
280
+ ugrave: 249,
281
+ uacute: 250,
282
+ ucirc: 251,
283
+ uuml: 252,
284
+ yacute: 253,
285
+ thorn: 254,
286
+ yuml: 255,
287
+ fnof: 402,
288
+ Alpha: 913,
289
+ Beta: 914,
290
+ Gamma: 915,
291
+ Delta: 916,
292
+ Epsilon: 917,
293
+ Zeta: 918,
294
+ Eta: 919,
295
+ Theta: 920,
296
+ Iota: 921,
297
+ Kappa: 922,
298
+ Lambda: 923,
299
+ Mu: 924,
300
+ Nu: 925,
301
+ Xi: 926,
302
+ Omicron: 927,
303
+ Pi: 928,
304
+ Rho: 929,
305
+ Sigma: 931,
306
+ Tau: 932,
307
+ Upsilon: 933,
308
+ Phi: 934,
309
+ Chi: 935,
310
+ Psi: 936,
311
+ Omega: 937,
312
+ alpha: 945,
313
+ beta: 946,
314
+ gamma: 947,
315
+ delta: 948,
316
+ epsilon: 949,
317
+ zeta: 950,
318
+ eta: 951,
319
+ theta: 952,
320
+ iota: 953,
321
+ kappa: 954,
322
+ lambda: 955,
323
+ mu: 956,
324
+ nu: 957,
325
+ xi: 958,
326
+ omicron: 959,
327
+ pi: 960,
328
+ rho: 961,
329
+ sigmaf: 962,
330
+ sigma: 963,
331
+ tau: 964,
332
+ upsilon: 965,
333
+ phi: 966,
334
+ chi: 967,
335
+ psi: 968,
336
+ omega: 969,
337
+ thetasym: 977,
338
+ upsih: 978,
339
+ piv: 982,
340
+ bull: 8226,
341
+ hellip: 8230,
342
+ prime: 8242,
343
+ Prime: 8243,
344
+ oline: 8254,
345
+ frasl: 8260,
346
+ weierp: 8472,
347
+ image: 8465,
348
+ real: 8476,
349
+ trade: 8482,
350
+ alefsym: 8501,
351
+ larr: 8592,
352
+ uarr: 8593,
353
+ rarr: 8594,
354
+ darr: 8595,
355
+ harr: 8596,
356
+ crarr: 8629,
357
+ lArr: 8656,
358
+ uArr: 8657,
359
+ rArr: 8658,
360
+ dArr: 8659,
361
+ hArr: 8660,
362
+ forall: 8704,
363
+ part: 8706,
364
+ exist: 8707,
365
+ empty: 8709,
366
+ nabla: 8711,
367
+ isin: 8712,
368
+ notin: 8713,
369
+ ni: 8715,
370
+ prod: 8719,
371
+ sum: 8721,
372
+ minus: 8722,
373
+ lowast: 8727,
374
+ radic: 8730,
375
+ prop: 8733,
376
+ infin: 8734,
377
+ ang: 8736,
378
+ and: 8743,
379
+ or: 8744,
380
+ cap: 8745,
381
+ cup: 8746,
382
+ int: 8747,
383
+ there4: 8756,
384
+ sim: 8764,
385
+ cong: 8773,
386
+ asymp: 8776,
387
+ ne: 8800,
388
+ equiv: 8801,
389
+ le: 8804,
390
+ ge: 8805,
391
+ sub: 8834,
392
+ sup: 8835,
393
+ nsub: 8836,
394
+ sube: 8838,
395
+ supe: 8839,
396
+ oplus: 8853,
397
+ otimes: 8855,
398
+ perp: 8869,
399
+ sdot: 8901,
400
+ lceil: 8968,
401
+ rceil: 8969,
402
+ lfloor: 8970,
403
+ rfloor: 8971,
404
+ lang: 9001,
405
+ rang: 9002,
406
+ loz: 9674,
407
+ spades: 9824,
408
+ clubs: 9827,
409
+ hearts: 9829,
410
+ diams: 9830
411
+ };
412
+ const PathArguments = {
413
+ A: 7,
414
+ a: 7,
415
+ C: 6,
416
+ c: 6,
417
+ H: 1,
418
+ h: 1,
419
+ L: 2,
420
+ l: 2,
421
+ M: 2,
422
+ m: 2,
423
+ Q: 4,
424
+ q: 4,
425
+ S: 4,
426
+ s: 4,
427
+ T: 2,
428
+ t: 2,
429
+ V: 1,
430
+ v: 1,
431
+ Z: 0,
432
+ z: 0
433
+ };
434
+ const PathFlags = {
435
+ A3: true,
436
+ A4: true,
437
+ a3: true,
438
+ a4: true
439
+ };
440
+ const Properties = {
441
+ color: {
442
+ inherit: true,
443
+ initial: undefined
444
+ },
445
+ visibility: {
446
+ inherit: true,
447
+ initial: 'visible',
448
+ values: {
449
+ hidden: 'hidden',
450
+ collapse: 'hidden',
451
+ visible: 'visible'
452
+ }
453
+ },
454
+ fill: {
455
+ inherit: true,
456
+ initial: DefaultColors.black
457
+ },
458
+ stroke: {
459
+ inherit: true,
460
+ initial: 'none'
461
+ },
462
+ 'stop-color': {
463
+ inherit: false,
464
+ initial: DefaultColors.black
465
+ },
466
+ 'fill-opacity': {
467
+ inherit: true,
468
+ initial: 1
469
+ },
470
+ 'stroke-opacity': {
471
+ inherit: true,
472
+ initial: 1
473
+ },
474
+ 'stop-opacity': {
475
+ inherit: false,
476
+ initial: 1
477
+ },
478
+ 'fill-rule': {
479
+ inherit: true,
480
+ initial: 'nonzero',
481
+ values: {
482
+ nonzero: 'nonzero',
483
+ evenodd: 'evenodd'
484
+ }
485
+ },
486
+ 'clip-rule': {
487
+ inherit: true,
488
+ initial: 'nonzero',
489
+ values: {
490
+ nonzero: 'nonzero',
491
+ evenodd: 'evenodd'
492
+ }
493
+ },
494
+ 'stroke-width': {
495
+ inherit: true,
496
+ initial: 1
497
+ },
498
+ 'stroke-dasharray': {
499
+ inherit: true,
500
+ initial: []
501
+ },
502
+ 'stroke-dashoffset': {
503
+ inherit: true,
504
+ initial: 0
505
+ },
506
+ 'stroke-miterlimit': {
507
+ inherit: true,
508
+ initial: 4
509
+ },
510
+ 'stroke-linejoin': {
511
+ inherit: true,
512
+ initial: 'miter',
513
+ values: {
514
+ miter: 'miter',
515
+ round: 'round',
516
+ bevel: 'bevel'
517
+ }
518
+ },
519
+ 'stroke-linecap': {
520
+ inherit: true,
521
+ initial: 'butt',
522
+ values: {
523
+ butt: 'butt',
524
+ round: 'round',
525
+ square: 'square'
526
+ }
527
+ },
528
+ 'font-size': {
529
+ inherit: true,
530
+ initial: 16,
531
+ values: {
532
+ 'xx-small': 9,
533
+ 'x-small': 10,
534
+ small: 13,
535
+ medium: 16,
536
+ large: 18,
537
+ 'x-large': 24,
538
+ 'xx-large': 32
539
+ }
540
+ },
541
+ 'font-family': {
542
+ inherit: true,
543
+ initial: 'sans-serif'
544
+ },
545
+ 'font-weight': {
546
+ inherit: true,
547
+ initial: 'normal',
548
+ values: {
549
+ 600: 'bold',
550
+ 700: 'bold',
551
+ 800: 'bold',
552
+ 900: 'bold',
553
+ bold: 'bold',
554
+ bolder: 'bold',
555
+ 500: 'normal',
556
+ 400: 'normal',
557
+ 300: 'normal',
558
+ 200: 'normal',
559
+ 100: 'normal',
560
+ normal: 'normal',
561
+ lighter: 'normal'
562
+ }
563
+ },
564
+ 'font-style': {
565
+ inherit: true,
566
+ initial: 'normal',
567
+ values: {
568
+ italic: 'italic',
569
+ oblique: 'italic',
570
+ normal: 'normal'
571
+ }
572
+ },
573
+ 'text-anchor': {
574
+ inherit: true,
575
+ initial: 'start',
576
+ values: {
577
+ start: 'start',
578
+ middle: 'middle',
579
+ end: 'end'
580
+ }
581
+ },
582
+ direction: {
583
+ inherit: true,
584
+ initial: 'ltr',
585
+ values: {
586
+ ltr: 'ltr',
587
+ rtl: 'rtl'
588
+ }
589
+ },
590
+ 'dominant-baseline': {
591
+ inherit: true,
592
+ initial: 'baseline',
593
+ values: {
594
+ auto: 'baseline',
595
+ baseline: 'baseline',
596
+ 'before-edge': 'before-edge',
597
+ 'text-before-edge': 'before-edge',
598
+ middle: 'middle',
599
+ central: 'central',
600
+ 'after-edge': 'after-edge',
601
+ 'text-after-edge': 'after-edge',
602
+ ideographic: 'ideographic',
603
+ alphabetic: 'alphabetic',
604
+ hanging: 'hanging',
605
+ mathematical: 'mathematical'
606
+ }
607
+ },
608
+ 'alignment-baseline': {
609
+ inherit: false,
610
+ initial: undefined,
611
+ values: {
612
+ auto: 'baseline',
613
+ baseline: 'baseline',
614
+ 'before-edge': 'before-edge',
615
+ 'text-before-edge': 'before-edge',
616
+ middle: 'middle',
617
+ central: 'central',
618
+ 'after-edge': 'after-edge',
619
+ 'text-after-edge': 'after-edge',
620
+ ideographic: 'ideographic',
621
+ alphabetic: 'alphabetic',
622
+ hanging: 'hanging',
623
+ mathematical: 'mathematical'
624
+ }
625
+ },
626
+ 'baseline-shift': {
627
+ inherit: true,
628
+ initial: 'baseline',
629
+ values: {
630
+ baseline: 'baseline',
631
+ sub: 'sub',
632
+ super: 'super'
633
+ }
634
+ },
635
+ 'word-spacing': {
636
+ inherit: true,
637
+ initial: 0,
638
+ values: {
639
+ normal: 0
640
+ }
641
+ },
642
+ 'letter-spacing': {
643
+ inherit: true,
644
+ initial: 0,
645
+ values: {
646
+ normal: 0
647
+ }
648
+ },
649
+ 'text-decoration': {
650
+ inherit: false,
651
+ initial: 'none',
652
+ values: {
653
+ none: 'none',
654
+ underline: 'underline',
655
+ overline: 'overline',
656
+ 'line-through': 'line-through'
657
+ }
658
+ },
659
+ 'xml:space': {
660
+ inherit: true,
661
+ initial: 'default',
662
+ css: 'white-space',
663
+ values: {
664
+ preserve: 'preserve',
665
+ default: 'default',
666
+ pre: 'preserve',
667
+ 'pre-line': 'preserve',
668
+ 'pre-wrap': 'preserve',
669
+ nowrap: 'default'
670
+ }
671
+ },
672
+ 'marker-start': {
673
+ inherit: true,
674
+ initial: 'none'
675
+ },
676
+ 'marker-mid': {
677
+ inherit: true,
678
+ initial: 'none'
679
+ },
680
+ 'marker-end': {
681
+ inherit: true,
682
+ initial: 'none'
683
+ },
684
+ opacity: {
685
+ inherit: false,
686
+ initial: 1
687
+ },
688
+ transform: {
689
+ inherit: false,
690
+ initial: [1, 0, 0, 1, 0, 0]
691
+ },
692
+ display: {
693
+ inherit: false,
694
+ initial: 'inline',
695
+ values: {
696
+ none: 'none',
697
+ inline: 'inline',
698
+ block: 'inline'
699
+ }
700
+ },
701
+ 'clip-path': {
702
+ inherit: false,
703
+ initial: 'none'
704
+ },
705
+ mask: {
706
+ inherit: false,
707
+ initial: 'none'
708
+ },
709
+ overflow: {
710
+ inherit: false,
711
+ initial: 'hidden',
712
+ values: {
713
+ hidden: 'hidden',
714
+ scroll: 'hidden',
715
+ visible: 'visible'
716
+ }
717
+ }
718
+ };
719
+ const blendModeMap = {
720
+ normal: 'Normal',
721
+ multiply: 'Multiply',
722
+ screen: 'Screen',
723
+ overlay: 'Overlay',
724
+ darken: 'Darken',
725
+ lighten: 'Lighten',
726
+ 'color-dodge': 'ColorDodge',
727
+ 'color-burn': 'ColorBurn',
728
+ 'hard-light': 'HardLight',
729
+ 'soft-light': 'SoftLight',
730
+ softlight: 'SoftLight',
731
+ difference: 'Difference',
732
+ exclusion: 'Exclusion',
733
+ hue: 'Hue',
734
+ saturation: 'Saturation',
735
+ color: 'Color',
736
+ luminosity: 'Luminosity'
737
+ };
738
+ function docBeginGroup(bbox) {
739
+ let group = new function PDFGroup() {}();
740
+ group.name = 'G' + (doc._groupCount = (doc._groupCount || 0) + 1);
741
+ group.resources = doc.ref();
742
+ group.xobj = doc.ref({
743
+ Type: 'XObject',
744
+ Subtype: 'Form',
745
+ FormType: 1,
746
+ BBox: bbox,
747
+ Group: {
748
+ S: 'Transparency',
749
+ CS: colorSpace,
750
+ I: true,
751
+ K: false
752
+ },
753
+ Resources: group.resources
754
+ });
755
+ group.xobj.write('');
756
+ group.savedMatrix = doc._ctm;
757
+ group.savedPage = doc.page;
758
+ groupStack.push(group);
759
+ doc._ctm = [1, 0, 0, 1, 0, 0];
760
+ doc.page = {
761
+ width: doc.page.width,
762
+ height: doc.page.height,
763
+ write: function (data) {
764
+ group.xobj.write(data);
765
+ },
766
+ fonts: {},
767
+ xobjects: {},
768
+ ext_gstates: {},
769
+ patterns: {}
770
+ };
771
+ return group;
772
+ }
773
+ function docEndGroup(group) {
774
+ if (group !== groupStack.pop()) {
775
+ throw 'Group not matching';
776
+ }
777
+ if (Object.keys(doc.page.fonts).length) {
778
+ group.resources.data.Font = doc.page.fonts;
779
+ }
780
+ if (Object.keys(doc.page.xobjects).length) {
781
+ group.resources.data.XObject = doc.page.xobjects;
782
+ }
783
+ if (Object.keys(doc.page.ext_gstates).length) {
784
+ group.resources.data.ExtGState = doc.page.ext_gstates;
785
+ }
786
+ if (Object.keys(doc.page.patterns).length) {
787
+ group.resources.data.Pattern = doc.page.patterns;
788
+ }
789
+ group.resources.end();
790
+ group.xobj.end();
791
+ doc._ctm = group.savedMatrix;
792
+ doc.page = group.savedPage;
793
+ }
794
+ function docInsertGroup(group) {
795
+ doc.page.xobjects[group.name] = group.xobj;
796
+ doc.addContent('/' + group.name + ' Do');
797
+ }
798
+ function docApplyMask(group, clip) {
799
+ let name = 'M' + (doc._maskCount = (doc._maskCount || 0) + 1);
800
+ let gstate = doc.ref({
801
+ Type: 'ExtGState',
802
+ CA: 1,
803
+ ca: 1,
804
+ BM: 'Normal',
805
+ SMask: {
806
+ S: 'Luminosity',
807
+ G: group.xobj,
808
+ BC: clip ? [0, 0, 0] : [1, 1, 1]
809
+ }
810
+ });
811
+ gstate.end();
812
+ doc.page.ext_gstates[name] = gstate;
813
+ doc.addContent('/' + name + ' gs');
814
+ }
815
+ function applyBlendMode(group, blendMode) {
816
+ const key = String(blendMode || '').toLowerCase();
817
+ const pdfBlendMode = blendModeMap[key] || 'Normal';
818
+ const name = 'M' + pdfBlendMode;
819
+ const gstate = doc.ref({
820
+ Type: 'ExtGState',
821
+ CA: 1,
822
+ ca: 1,
823
+ BM: pdfBlendMode,
824
+ G: group.xobj
825
+ });
826
+ gstate.end();
827
+ doc.page.ext_gstates[name] = gstate;
828
+ doc.addContent('/' + name + ' gs');
829
+ }
830
+ function docCreatePattern(group, dx, dy, matrix) {
831
+ let pattern = new function PDFPattern() {}();
832
+ pattern.group = group;
833
+ pattern.dx = dx;
834
+ pattern.dy = dy;
835
+ pattern.matrix = matrix || [1, 0, 0, 1, 0, 0];
836
+ return pattern;
837
+ }
838
+ function docUsePattern(pattern, stroke) {
839
+ let name = 'P' + (doc._patternCount = (doc._patternCount || 0) + 1);
840
+ let ref = doc.ref({
841
+ Type: 'Pattern',
842
+ PatternType: 1,
843
+ PaintType: 1,
844
+ TilingType: 2,
845
+ BBox: [0, 0, pattern.dx, pattern.dy],
846
+ XStep: pattern.dx,
847
+ YStep: pattern.dy,
848
+ Matrix: multiplyMatrix(doc._ctm, pattern.matrix),
849
+ Resources: {
850
+ ProcSet: ['PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'],
851
+ XObject: function () {
852
+ let temp = {};
853
+ temp[pattern.group.name] = pattern.group.xobj;
854
+ return temp;
855
+ }()
856
+ }
857
+ });
858
+ ref.write('/' + pattern.group.name + ' Do');
859
+ ref.end();
860
+ doc.page.patterns[name] = ref;
861
+ if (stroke) {
862
+ doc.addContent('/Pattern CS');
863
+ doc.addContent('/' + name + ' SCN');
864
+ } else {
865
+ doc.addContent('/Pattern cs');
866
+ doc.addContent('/' + name + ' scn');
867
+ }
868
+ }
869
+ function docBeginText(font, size) {
870
+ if (!doc.page.fonts[font.id]) {
871
+ doc.page.fonts[font.id] = font.ref();
872
+ }
873
+ doc.addContent('BT').addContent('/' + font.id + ' ' + size + ' Tf');
874
+ }
875
+ function docSetTextMatrix(a, b, c, d, e, f) {
876
+ doc.addContent(validateNumber(a) + ' ' + validateNumber(b) + ' ' + validateNumber(-c) + ' ' + validateNumber(-d) + ' ' + validateNumber(e) + ' ' + validateNumber(f) + ' Tm');
877
+ }
878
+ function docSetTextMode(fill, stroke) {
879
+ let mode = fill && stroke ? 2 : stroke ? 1 : fill ? 0 : 3;
880
+ doc.addContent(mode + ' Tr');
881
+ }
882
+ function docWriteGlyphs(positions, font) {
883
+ let commands = [];
884
+ let commandStr = '';
885
+ const skew = font.fauxItalic ? -0.25 : 0;
886
+ function addChar(char) {
887
+ commandStr += char.glyph;
888
+ if (char.kern === 0) return;
889
+ commands.push(`<${commandStr}> ${validateNumber(char.kern)}`);
890
+ commandStr = '';
891
+ }
892
+ function flush() {
893
+ if (commandStr.length) {
894
+ commands.push(`<${commandStr}> 0`);
895
+ commandStr = '';
896
+ }
897
+ if (commands.length) {
898
+ doc.addContent(`[${commands.join(' ')}] TJ`);
899
+ commands = [];
900
+ }
901
+ }
902
+ for (let i = 0; i < positions.length; i++) {
903
+ const pos = positions[i];
904
+ if (pos.hidden || isEqual(pos.width, 0)) {
905
+ flush();
906
+ continue;
907
+ }
908
+ if (pos.continuous) {
909
+ addChar(pos);
910
+ continue;
911
+ }
912
+ flush();
913
+ const cos = Math.cos(pos.rotate);
914
+ const sin = Math.sin(pos.rotate);
915
+ docSetTextMatrix(cos * pos.scale, sin * pos.scale, cos * skew - sin, sin * skew + cos, pos.x, pos.y);
916
+ addChar(pos);
917
+ }
918
+ flush();
919
+ }
920
+ function docEndText() {
921
+ doc.addContent('ET');
922
+ }
923
+ function docFillColor(color) {
924
+ if (color[0].constructor.name === 'PDFPattern') {
925
+ doc.fillOpacity(color[1]);
926
+ docUsePattern(color[0], false);
927
+ } else {
928
+ doc.fillColor(color[0], color[1]);
929
+ }
930
+ }
931
+ function docStrokeColor(color) {
932
+ if (color[0].constructor.name === 'PDFPattern') {
933
+ doc.strokeOpacity(color[1]);
934
+ docUsePattern(color[0], true);
935
+ } else {
936
+ doc.strokeColor(color[0], color[1]);
937
+ }
938
+ }
939
+ function docInsertLink(x, y, w, h, url) {
940
+ let ref = doc.ref({
941
+ Type: 'Annot',
942
+ Subtype: 'Link',
943
+ Rect: [x, y, w, h],
944
+ Border: [0, 0, 0],
945
+ A: {
946
+ S: 'URI',
947
+ URI: new String(url)
948
+ }
949
+ });
950
+ ref.end();
951
+ links.push(ref);
952
+ }
953
+ function parseXml(xml) {
954
+ let SvgNode = function (tag, type, value, error) {
955
+ this.error = error;
956
+ this.nodeName = tag;
957
+ this.nodeValue = value;
958
+ this.nodeType = type;
959
+ this.attributes = Object.create(null);
960
+ this.childNodes = [];
961
+ this.parentNode = null;
962
+ this.id = '';
963
+ this.textContent = '';
964
+ this.classList = [];
965
+ };
966
+ SvgNode.prototype.getAttribute = function (attr) {
967
+ return this.attributes[attr] != null ? this.attributes[attr] : null;
968
+ };
969
+ SvgNode.prototype.getElementById = function (id) {
970
+ let result = null;
971
+ (function recursive(node) {
972
+ if (result) {
973
+ return;
974
+ }
975
+ if (node.nodeType === 1) {
976
+ if (node.id === id) {
977
+ result = node;
978
+ }
979
+ for (let i = 0; i < node.childNodes.length; i++) {
980
+ recursive(node.childNodes[i]);
981
+ }
982
+ }
983
+ })(this);
984
+ return result;
985
+ };
986
+ SvgNode.prototype.getElementsByTagName = function (tag) {
987
+ let result = [];
988
+ (function recursive(node) {
989
+ if (node.nodeType === 1) {
990
+ if (node.nodeName === tag) {
991
+ result.push(node);
992
+ }
993
+ for (let i = 0; i < node.childNodes.length; i++) {
994
+ recursive(node.childNodes[i]);
995
+ }
996
+ }
997
+ })(this);
998
+ return result;
999
+ };
1000
+ let parser = new StringParser(xml.trim()),
1001
+ result,
1002
+ child,
1003
+ error = false;
1004
+ let recursive = function () {
1005
+ let temp, child;
1006
+ if (temp = parser.match(/^<([\w:.-]+)\s*/, true)) {
1007
+ let node = new SvgNode(temp[1], 1, null, error);
1008
+ while (temp = parser.match(/^([\w:.-]+)(?:\s*=\s*"([^"]*)"|\s*=\s*'([^']*)')?\s*/, true)) {
1009
+ let attr = temp[1],
1010
+ value = decodeEntities(temp[2] || temp[3] || '');
1011
+ if (!node.attributes[attr]) {
1012
+ node.attributes[attr] = value;
1013
+ if (attr === 'id') {
1014
+ node.id = value;
1015
+ }
1016
+ if (attr === 'class') {
1017
+ node.classList = value.split(' ');
1018
+ }
1019
+ } else {
1020
+ warningCallback('parseXml: duplicate attribute "' + attr + '"');
1021
+ error = true;
1022
+ }
1023
+ }
1024
+ if (parser.match(/^>/)) {
1025
+ while (child = recursive()) {
1026
+ node.childNodes.push(child);
1027
+ child.parentNode = node;
1028
+ node.textContent += child.nodeType === 3 || child.nodeType === 4 ? child.nodeValue : child.textContent;
1029
+ }
1030
+ if (temp = parser.match(/^<\/([\w:.-]+)\s*>/, true)) {
1031
+ if (temp[1] === node.nodeName) {
1032
+ return node;
1033
+ } else {
1034
+ warningCallback('parseXml: tag not matching, opening "' + node.nodeName + '" & closing "' + temp[1] + '"');
1035
+ error = true;
1036
+ return node;
1037
+ }
1038
+ } else {
1039
+ warningCallback('parseXml: tag not matching, opening "' + node.nodeName + '" & not closing');
1040
+ error = true;
1041
+ return node;
1042
+ }
1043
+ } else if (parser.match(/^\/>/)) {
1044
+ return node;
1045
+ } else {
1046
+ warningCallback('parseXml: tag could not be parsed "' + node.nodeName + '"');
1047
+ error = true;
1048
+ }
1049
+ } else if (temp = parser.match(/^<!--[\s\S]*?-->/)) {
1050
+ return new SvgNode(null, 8, temp, error);
1051
+ } else if (temp = parser.match(/^<\?[\s\S]*?\?>/)) {
1052
+ return new SvgNode(null, 7, temp, error);
1053
+ } else if (temp = parser.match(/^<!DOCTYPE\s*([\s\S]*?)>/)) {
1054
+ return new SvgNode(null, 10, temp, error);
1055
+ } else if (temp = parser.match(/^<!\[CDATA\[([\s\S]*?)\]\]>/, true)) {
1056
+ return new SvgNode('#cdata-section', 4, temp[1], error);
1057
+ } else if (temp = parser.match(/^([^<]+)/, true)) {
1058
+ return new SvgNode('#text', 3, decodeEntities(temp[1]), error);
1059
+ }
1060
+ };
1061
+ while (child = recursive()) {
1062
+ if (child.nodeType === 1 && !result) {
1063
+ result = child;
1064
+ } else if (child.nodeType === 1 || child.nodeType === 3 && child.nodeValue.trim() !== '') {
1065
+ warningCallback('parseXml: data after document end has been discarded');
1066
+ }
1067
+ }
1068
+ if (parser.matchAll()) {
1069
+ warningCallback('parseXml: parsing error');
1070
+ }
1071
+ return result;
1072
+ }
1073
+ function decodeEntities(str) {
1074
+ return str.replace(/&(?:#([0-9]+)|#[xX]([0-9A-Fa-f]+)|([0-9A-Za-z]+));/g, function (mt, m0, m1, m2) {
1075
+ if (m0) {
1076
+ return String.fromCharCode(parseInt(m0, 10));
1077
+ } else if (m1) {
1078
+ return String.fromCharCode(parseInt(m1, 16));
1079
+ } else if (m2 && Entities[m2]) {
1080
+ return String.fromCharCode(Entities[m2]);
1081
+ } else {
1082
+ return mt;
1083
+ }
1084
+ });
1085
+ }
1086
+ function parseColor(raw) {
1087
+ let temp, result;
1088
+ raw = (raw || '').trim();
1089
+ if (temp = NamedColors[raw]) {
1090
+ result = [temp.slice(), 1];
1091
+ } else if (temp = raw.match(/^cmyk\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9.]+)\s*\)$/i)) {
1092
+ temp[1] = parseInt(temp[1]);
1093
+ temp[2] = parseInt(temp[2]);
1094
+ temp[3] = parseInt(temp[3]);
1095
+ temp[4] = parseInt(temp[4]);
1096
+ if (temp[1] <= 100 && temp[2] <= 100 && temp[3] <= 100 && temp[4] <= 100) {
1097
+ result = [temp.slice(1, 5), 1];
1098
+ }
1099
+ } else if (temp = raw.match(/^rgba\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9.]+)\s*\)$/i)) {
1100
+ temp[1] = parseInt(temp[1]);
1101
+ temp[2] = parseInt(temp[2]);
1102
+ temp[3] = parseInt(temp[3]);
1103
+ temp[4] = parseFloat(temp[4]);
1104
+ if (temp[1] < 256 && temp[2] < 256 && temp[3] < 256 && temp[4] <= 1) {
1105
+ result = [temp.slice(1, 4), temp[4]];
1106
+ }
1107
+ } else if (temp = raw.match(/^rgb\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)$/i)) {
1108
+ temp[1] = parseInt(temp[1]);
1109
+ temp[2] = parseInt(temp[2]);
1110
+ temp[3] = parseInt(temp[3]);
1111
+ if (temp[1] < 256 && temp[2] < 256 && temp[3] < 256) {
1112
+ result = [temp.slice(1, 4), 1];
1113
+ }
1114
+ } else if (temp = raw.match(/^rgb\(\s*([0-9.]+)%\s*,\s*([0-9.]+)%\s*,\s*([0-9.]+)%\s*\)$/i)) {
1115
+ temp[1] = 2.55 * parseFloat(temp[1]);
1116
+ temp[2] = 2.55 * parseFloat(temp[2]);
1117
+ temp[3] = 2.55 * parseFloat(temp[3]);
1118
+ if (temp[1] < 256 && temp[2] < 256 && temp[3] < 256) {
1119
+ result = [temp.slice(1, 4), 1];
1120
+ }
1121
+ } else if (temp = raw.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i)) {
1122
+ result = [[parseInt(temp[1], 16), parseInt(temp[2], 16), parseInt(temp[3], 16)], 1];
1123
+ } else if (temp = raw.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i)) {
1124
+ result = [[0x11 * parseInt(temp[1], 16), 0x11 * parseInt(temp[2], 16), 0x11 * parseInt(temp[3], 16)], 1];
1125
+ }
1126
+ return colorCallback ? colorCallback(result, raw) : result;
1127
+ }
1128
+ function opacityToColor(color, opacity, isMask) {
1129
+ let newColor = color[0].slice(),
1130
+ newOpacity = color[1] * opacity;
1131
+ if (isMask) {
1132
+ for (let i = 0; i < color.length; i++) {
1133
+ newColor[i] *= newOpacity;
1134
+ }
1135
+ return [newColor, 1];
1136
+ } else {
1137
+ return [newColor, newOpacity];
1138
+ }
1139
+ }
1140
+ function multiplyMatrix() {
1141
+ function multiply(a, b) {
1142
+ return [a[0] * b[0] + a[2] * b[1], a[1] * b[0] + a[3] * b[1], a[0] * b[2] + a[2] * b[3], a[1] * b[2] + a[3] * b[3], a[0] * b[4] + a[2] * b[5] + a[4], a[1] * b[4] + a[3] * b[5] + a[5]];
1143
+ }
1144
+ let result = arguments[0];
1145
+ for (let i = 1; i < arguments.length; i++) {
1146
+ result = multiply(result, arguments[i]);
1147
+ }
1148
+ return result;
1149
+ }
1150
+ function transformPoint(p, m) {
1151
+ return [m[0] * p[0] + m[2] * p[1] + m[4], m[1] * p[0] + m[3] * p[1] + m[5]];
1152
+ }
1153
+ function getGlobalMatrix() {
1154
+ let ctm = doc._ctm;
1155
+ for (let i = groupStack.length - 1; i >= 0; i--) {
1156
+ ctm = multiplyMatrix(groupStack[i].savedMatrix, ctm);
1157
+ }
1158
+ return ctm;
1159
+ }
1160
+ function getPageBBox() {
1161
+ return new SvgShape().M(0, 0).L(doc.page.width, 0).L(doc.page.width, doc.page.height).L(0, doc.page.height).transform(inverseMatrix(getGlobalMatrix())).getBoundingBox();
1162
+ }
1163
+ function inverseMatrix(m) {
1164
+ let dt = m[0] * m[3] - m[1] * m[2];
1165
+ return [m[3] / dt, -m[1] / dt, -m[2] / dt, m[0] / dt, (m[2] * m[5] - m[3] * m[4]) / dt, (m[1] * m[4] - m[0] * m[5]) / dt];
1166
+ }
1167
+ function validateMatrix(m) {
1168
+ let m0 = validateNumber(m[0]),
1169
+ m1 = validateNumber(m[1]),
1170
+ m2 = validateNumber(m[2]),
1171
+ m3 = validateNumber(m[3]),
1172
+ m4 = validateNumber(m[4]),
1173
+ m5 = validateNumber(m[5]);
1174
+ if (isNotEqual(m0 * m3 - m1 * m2, 0)) {
1175
+ return [m0, m1, m2, m3, m4, m5];
1176
+ }
1177
+ }
1178
+ function solveEquation(curve) {
1179
+ let a = curve[2] || 0,
1180
+ b = curve[1] || 0,
1181
+ c = curve[0] || 0;
1182
+ if (isEqual(a, 0) && isEqual(b, 0)) {
1183
+ return [];
1184
+ } else if (isEqual(a, 0)) {
1185
+ return [-c / b];
1186
+ } else {
1187
+ let d = b * b - 4 * a * c;
1188
+ if (isNotEqual(d, 0) && d > 0) {
1189
+ return [(-b + Math.sqrt(d)) / (2 * a), (-b - Math.sqrt(d)) / (2 * a)];
1190
+ } else if (isEqual(d, 0)) {
1191
+ return [-b / (2 * a)];
1192
+ } else {
1193
+ return [];
1194
+ }
1195
+ }
1196
+ }
1197
+ function getCurveValue(t, curve) {
1198
+ return (curve[0] || 0) + (curve[1] || 0) * t + (curve[2] || 0) * t * t + (curve[3] || 0) * t * t * t;
1199
+ }
1200
+ function isEqual(number, ref) {
1201
+ return Math.abs(number - ref) < 1e-10;
1202
+ }
1203
+ function isNotEqual(number, ref) {
1204
+ return Math.abs(number - ref) >= 1e-10;
1205
+ }
1206
+ function validateNumber(n) {
1207
+ return n > -1e21 && n < 1e21 ? Math.round(n * 1e6) / 1e6 : 0;
1208
+ }
1209
+ function isArrayLike(v) {
1210
+ return typeof v === 'object' && v !== null && typeof v.length === 'number';
1211
+ }
1212
+ function parseTranform(v) {
1213
+ let parser = new StringParser((v || '').trim()),
1214
+ result = [1, 0, 0, 1, 0, 0],
1215
+ temp;
1216
+ while (temp = parser.match(/^([A-Za-z]+)\s*[(]([^(]+)[)]/, true)) {
1217
+ let func = temp[1],
1218
+ nums = [],
1219
+ parser2 = new StringParser(temp[2].trim()),
1220
+ temp2;
1221
+ while (temp2 = parser2.matchNumber()) {
1222
+ nums.push(Number(temp2));
1223
+ parser2.matchSeparator();
1224
+ }
1225
+ if (func === 'matrix' && nums.length === 6) {
1226
+ result = multiplyMatrix(result, [nums[0], nums[1], nums[2], nums[3], nums[4], nums[5]]);
1227
+ } else if (func === 'translate' && nums.length === 2) {
1228
+ result = multiplyMatrix(result, [1, 0, 0, 1, nums[0], nums[1]]);
1229
+ } else if (func === 'translate' && nums.length === 1) {
1230
+ result = multiplyMatrix(result, [1, 0, 0, 1, nums[0], 0]);
1231
+ } else if (func === 'scale' && nums.length === 2) {
1232
+ result = multiplyMatrix(result, [nums[0], 0, 0, nums[1], 0, 0]);
1233
+ } else if (func === 'scale' && nums.length === 1) {
1234
+ result = multiplyMatrix(result, [nums[0], 0, 0, nums[0], 0, 0]);
1235
+ } else if (func === 'rotate' && nums.length === 3) {
1236
+ let a = nums[0] * Math.PI / 180;
1237
+ result = multiplyMatrix(result, [1, 0, 0, 1, nums[1], nums[2]], [Math.cos(a), Math.sin(a), -Math.sin(a), Math.cos(a), 0, 0], [1, 0, 0, 1, -nums[1], -nums[2]]);
1238
+ } else if (func === 'rotate' && nums.length === 1) {
1239
+ let a = nums[0] * Math.PI / 180;
1240
+ result = multiplyMatrix(result, [Math.cos(a), Math.sin(a), -Math.sin(a), Math.cos(a), 0, 0]);
1241
+ } else if (func === 'skewX' && nums.length === 1) {
1242
+ let a = nums[0] * Math.PI / 180;
1243
+ result = multiplyMatrix(result, [1, 0, Math.tan(a), 1, 0, 0]);
1244
+ } else if (func === 'skewY' && nums.length === 1) {
1245
+ let a = nums[0] * Math.PI / 180;
1246
+ result = multiplyMatrix(result, [1, Math.tan(a), 0, 1, 0, 0]);
1247
+ } else {
1248
+ return;
1249
+ }
1250
+ parser.matchSeparator();
1251
+ }
1252
+ if (parser.matchAll()) {
1253
+ return;
1254
+ }
1255
+ return result;
1256
+ }
1257
+ function parseAspectRatio(aspectRatio, availWidth, availHeight, elemWidth, elemHeight, initAlign) {
1258
+ let temp = (aspectRatio || '').trim().match(/^(none)$|^x(Min|Mid|Max)Y(Min|Mid|Max)(?:\s+(meet|slice))?$/) || [],
1259
+ ratioType = temp[1] || temp[4] || 'meet',
1260
+ xAlign = temp[2] || 'Mid',
1261
+ yAlign = temp[3] || 'Mid',
1262
+ scaleX = availWidth / elemWidth,
1263
+ scaleY = availHeight / elemHeight,
1264
+ dx = {
1265
+ Min: 0,
1266
+ Mid: 0.5,
1267
+ Max: 1
1268
+ }[xAlign] - (initAlign || 0),
1269
+ dy = {
1270
+ Min: 0,
1271
+ Mid: 0.5,
1272
+ Max: 1
1273
+ }[yAlign] - (initAlign || 0);
1274
+ if (ratioType === 'slice') {
1275
+ scaleY = scaleX = Math.max(scaleX, scaleY);
1276
+ } else if (ratioType === 'meet') {
1277
+ scaleY = scaleX = Math.min(scaleX, scaleY);
1278
+ }
1279
+ return [scaleX, 0, 0, scaleY, dx * (availWidth - elemWidth * scaleX), dy * (availHeight - elemHeight * scaleY)];
1280
+ }
1281
+ function parseStyleAttr(v) {
1282
+ let result = Object.create(null);
1283
+ v = (v || '').trim().split(/;/);
1284
+ for (let i = 0; i < v.length; i++) {
1285
+ let key = (v[i].split(':')[0] || '').trim(),
1286
+ value = (v[i].split(':')[1] || '').trim();
1287
+ if (key) {
1288
+ result[key] = value;
1289
+ }
1290
+ }
1291
+ if (result['marker']) {
1292
+ if (!result['marker-start']) {
1293
+ result['marker-start'] = result['marker'];
1294
+ }
1295
+ if (!result['marker-mid']) {
1296
+ result['marker-mid'] = result['marker'];
1297
+ }
1298
+ if (!result['marker-end']) {
1299
+ result['marker-end'] = result['marker'];
1300
+ }
1301
+ }
1302
+ if (result['font']) {
1303
+ let fontFamily = null,
1304
+ fontSize = null,
1305
+ fontStyle = 'normal',
1306
+ fontWeight = 'normal',
1307
+ fontVariant = 'normal';
1308
+ let parts = result['font'].split(/\s+/);
1309
+ for (let i = 0; i < parts.length; i++) {
1310
+ switch (parts[i]) {
1311
+ case 'normal':
1312
+ break;
1313
+ case 'italic':
1314
+ case 'oblique':
1315
+ fontStyle = parts[i];
1316
+ break;
1317
+ case 'small-caps':
1318
+ fontVariant = parts[i];
1319
+ break;
1320
+ case 'bold':
1321
+ case 'bolder':
1322
+ case 'lighter':
1323
+ case '100':
1324
+ case '200':
1325
+ case '300':
1326
+ case '400':
1327
+ case '500':
1328
+ case '600':
1329
+ case '700':
1330
+ case '800':
1331
+ case '900':
1332
+ fontWeight = parts[i];
1333
+ break;
1334
+ default:
1335
+ if (!fontSize) {
1336
+ fontSize = parts[i].split('/')[0];
1337
+ } else {
1338
+ if (!fontFamily) {
1339
+ fontFamily = parts[i];
1340
+ } else {
1341
+ fontFamily += ' ' + parts[i];
1342
+ }
1343
+ }
1344
+ break;
1345
+ }
1346
+ }
1347
+ if (!result['font-style']) {
1348
+ result['font-style'] = fontStyle;
1349
+ }
1350
+ if (!result['font-variant']) {
1351
+ result['font-variant'] = fontVariant;
1352
+ }
1353
+ if (!result['font-weight']) {
1354
+ result['font-weight'] = fontWeight;
1355
+ }
1356
+ if (!result['font-size']) {
1357
+ result['font-size'] = fontSize;
1358
+ }
1359
+ if (!result['font-family']) {
1360
+ result['font-family'] = fontFamily;
1361
+ }
1362
+ }
1363
+ return result;
1364
+ }
1365
+ function parseSelector(v) {
1366
+ let parts = v.split(/(?=[.#])/g),
1367
+ ids = [],
1368
+ classes = [],
1369
+ tags = [],
1370
+ temp;
1371
+ for (let i = 0; i < parts.length; i++) {
1372
+ if (temp = parts[i].match(/^[#]([_A-Za-z0-9-]+)$/)) {
1373
+ ids.push(temp[1]);
1374
+ } else if (temp = parts[i].match(/^[.]([_A-Za-z0-9-]+)$/)) {
1375
+ classes.push(temp[1]);
1376
+ } else if (temp = parts[i].match(/^([_A-Za-z0-9-]+)$/)) {
1377
+ tags.push(temp[1]);
1378
+ } else if (parts[i] !== '*') {
1379
+ return;
1380
+ }
1381
+ }
1382
+ return {
1383
+ tags: tags,
1384
+ ids: ids,
1385
+ classes: classes,
1386
+ specificity: ids.length * 10000 + classes.length * 100 + tags.length
1387
+ };
1388
+ }
1389
+ function parseStyleSheet(v) {
1390
+ const parser = new StringParser(v.trim());
1391
+ const rules = [];
1392
+ let m;
1393
+ while (m = parser.match(/^\s*([^{}]*?)\s*\{([^{}]*?)\}/, true)) {
1394
+ const css = parseStyleAttr(m[2]);
1395
+ const selectors = m[1].split(',');
1396
+ for (let i = 0; i < selectors.length; i++) {
1397
+ const selector = parseSelector(selectors[i].trim());
1398
+ if (selector) rules.push({
1399
+ selector,
1400
+ css
1401
+ });
1402
+ }
1403
+ }
1404
+ return rules;
1405
+ }
1406
+ function matchesSelector(elem, selector) {
1407
+ if (elem.nodeType !== 1) {
1408
+ return false;
1409
+ }
1410
+ for (let i = 0; i < selector.tags.length; i++) {
1411
+ if (selector.tags[i] !== elem.nodeName) {
1412
+ return false;
1413
+ }
1414
+ }
1415
+ for (let i = 0; i < selector.ids.length; i++) {
1416
+ if (selector.ids[i] !== elem.id) {
1417
+ return false;
1418
+ }
1419
+ }
1420
+ for (let i = 0; i < selector.classes.length; i++) {
1421
+ if (elem.classList.indexOf(selector.classes[i]) === -1) {
1422
+ return false;
1423
+ }
1424
+ }
1425
+ return true;
1426
+ }
1427
+ function getStyle(elem) {
1428
+ let result = Object.create(null);
1429
+ let specificities = Object.create(null);
1430
+ for (let i = 0; i < styleRules.length; i++) {
1431
+ let rule = styleRules[i];
1432
+ if (matchesSelector(elem, rule.selector)) {
1433
+ for (let key in rule.css) {
1434
+ if (!(specificities[key] > rule.selector.specificity)) {
1435
+ result[key] = rule.css[key];
1436
+ specificities[key] = rule.selector.specificity;
1437
+ }
1438
+ }
1439
+ }
1440
+ }
1441
+ return result;
1442
+ }
1443
+ function combineArrays(array1, array2) {
1444
+ return array1.concat(array2.slice(array1.length));
1445
+ }
1446
+ function getAscent(font, size) {
1447
+ return Math.max(font.ascender, (font.bbox[3] || font.bbox.maxY) * (font.scale || 1)) * size / 1000;
1448
+ }
1449
+ function getDescent(font, size) {
1450
+ return Math.min(font.descender, (font.bbox[1] || font.bbox.minY) * (font.scale || 1)) * size / 1000;
1451
+ }
1452
+ function getXHeight(font, size) {
1453
+ return (font.xHeight || 0.5 * (font.ascender - font.descender)) * size / 1000;
1454
+ }
1455
+ function getBaseline(font, size, baseline, shift) {
1456
+ let dy1, dy2;
1457
+ switch (baseline) {
1458
+ case 'middle':
1459
+ dy1 = 0.5 * getXHeight(font, size);
1460
+ break;
1461
+ case 'central':
1462
+ dy1 = 0.5 * (getDescent(font, size) + getAscent(font, size));
1463
+ break;
1464
+ case 'after-edge':
1465
+ case 'text-after-edge':
1466
+ dy1 = getDescent(font, size);
1467
+ break;
1468
+ case 'alphabetic':
1469
+ case 'auto':
1470
+ case 'baseline':
1471
+ dy1 = 0;
1472
+ break;
1473
+ case 'mathematical':
1474
+ dy1 = 0.5 * getAscent(font, size);
1475
+ break;
1476
+ case 'hanging':
1477
+ dy1 = 0.8 * getAscent(font, size);
1478
+ break;
1479
+ case 'before-edge':
1480
+ case 'text-before-edge':
1481
+ dy1 = getAscent(font, size);
1482
+ break;
1483
+ default:
1484
+ dy1 = 0;
1485
+ break;
1486
+ }
1487
+ switch (shift) {
1488
+ case 'baseline':
1489
+ dy2 = 0;
1490
+ break;
1491
+ case 'super':
1492
+ dy2 = 0.6 * size;
1493
+ break;
1494
+ case 'sub':
1495
+ dy2 = -0.6 * size;
1496
+ break;
1497
+ default:
1498
+ dy2 = shift;
1499
+ break;
1500
+ }
1501
+ return dy1 - dy2;
1502
+ }
1503
+ function getTextPos(font, size, text) {
1504
+ let encoded = font.encode('' + text),
1505
+ hex = encoded[0],
1506
+ pos = encoded[1],
1507
+ data = [];
1508
+ for (let i = 0; i < hex.length; i++) {
1509
+ let unicode = font.unicode ? font.unicode[parseInt(hex[i], 16)] : [text.charCodeAt(i)];
1510
+ data.push({
1511
+ glyph: hex[i],
1512
+ unicode: unicode,
1513
+ kern: pos[i].advanceWidth - pos[i].xAdvance,
1514
+ width: pos[i].advanceWidth * size / 1000,
1515
+ xOffset: pos[i].xOffset * size / 1000,
1516
+ yOffset: pos[i].yOffset * size / 1000,
1517
+ xAdvance: pos[i].xAdvance * size / 1000,
1518
+ yAdvance: pos[i].yAdvance * size / 1000
1519
+ });
1520
+ }
1521
+ return data;
1522
+ }
1523
+ function createSVGElement(obj, inherits) {
1524
+ switch (obj.nodeName) {
1525
+ case 'use':
1526
+ return new SvgElemUse(obj, inherits);
1527
+ case 'symbol':
1528
+ return new SvgElemSymbol(obj, inherits);
1529
+ case 'g':
1530
+ return new SvgElemGroup(obj, inherits);
1531
+ case 'a':
1532
+ return new SvgElemLink(obj, inherits);
1533
+ case 'svg':
1534
+ return new SvgElemSvg(obj, inherits);
1535
+ case 'image':
1536
+ return new SVGElemImage(obj, inherits);
1537
+ case 'rect':
1538
+ return new SvgElemRect(obj, inherits);
1539
+ case 'circle':
1540
+ return new SvgElemCircle(obj, inherits);
1541
+ case 'ellipse':
1542
+ return new SvgElemEllipse(obj, inherits);
1543
+ case 'line':
1544
+ return new SvgElemLine(obj, inherits);
1545
+ case 'polyline':
1546
+ return new SvgElemPolyline(obj, inherits);
1547
+ case 'polygon':
1548
+ return new SvgElemPolygon(obj, inherits);
1549
+ case 'path':
1550
+ return new SvgElemPath(obj, inherits);
1551
+ case 'text':
1552
+ return new SvgElemText(obj, inherits);
1553
+ case 'tspan':
1554
+ return new SvgElemTspan(obj, inherits);
1555
+ case 'textPath':
1556
+ return new SvgElemTextPath(obj, inherits);
1557
+ case '#text':
1558
+ case '#cdata-section':
1559
+ return new SvgElemTextNode(obj);
1560
+ default:
1561
+ return new SvgElem(obj, inherits);
1562
+ }
1563
+ }
1564
+ function getObjectStyles(obj) {
1565
+ if (!obj.attributes.style) return {};
1566
+ const styles = obj.attributes.style.split(';');
1567
+ return styles.reduce((acc, style) => {
1568
+ const [key, value] = style.split(':');
1569
+ if (!key) {
1570
+ return acc;
1571
+ }
1572
+ acc[key.trim()] = value.trim();
1573
+ return acc;
1574
+ }, {});
1575
+ }
1576
+ function parseCSSBlendMode(blendMode) {
1577
+ return blendMode.split('-').map(string => string.charAt(0).toUpperCase() + string.slice(1)).join('');
1578
+ }
1579
+ var StringParser = function (str) {
1580
+ this.match = function (exp, all) {
1581
+ let temp = str.match(exp);
1582
+ if (!temp || temp.index !== 0) {
1583
+ return;
1584
+ }
1585
+ str = str.substring(temp[0].length);
1586
+ return all ? temp : temp[0];
1587
+ };
1588
+ this.matchSeparator = function () {
1589
+ return this.match(/^(?:\s*,\s*|\s*|)/);
1590
+ };
1591
+ this.matchSpace = function () {
1592
+ return this.match(/^(?:\s*)/);
1593
+ };
1594
+ this.matchLengthUnit = function () {
1595
+ return this.match(/^(?:px|pt|cm|mm|in|pc|em|ex|%|)/);
1596
+ };
1597
+ this.matchNumber = function () {
1598
+ return this.match(/^(?:[-+]?(?:[0-9]+[.][0-9]+|[0-9]+[.]|[.][0-9]+|[0-9]+)(?:[eE][-+]?[0-9]+)?)/);
1599
+ };
1600
+ this.matchAll = function () {
1601
+ return this.match(/^[\s\S]+/);
1602
+ };
1603
+ };
1604
+ var BezierSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
1605
+ let divisions = 6 * precision;
1606
+ let equationX = [p1x, -3 * p1x + 3 * c1x, 3 * p1x - 6 * c1x + 3 * c2x, -p1x + 3 * c1x - 3 * c2x + p2x];
1607
+ let equationY = [p1y, -3 * p1y + 3 * c1y, 3 * p1y - 6 * c1y + 3 * c2y, -p1y + 3 * c1y - 3 * c2y + p2y];
1608
+ let derivativeX = [-3 * p1x + 3 * c1x, 6 * p1x - 12 * c1x + 6 * c2x, -3 * p1x + 9 * c1x - 9 * c2x + 3 * p2x];
1609
+ let derivativeY = [-3 * p1y + 3 * c1y, 6 * p1y - 12 * c1y + 6 * c2y, -3 * p1y + 9 * c1y - 9 * c2y + 3 * p2y];
1610
+ let lengthMap = [0];
1611
+ for (let i = 1; i <= divisions; i++) {
1612
+ let t = (i - 0.5) / divisions;
1613
+ let dx = getCurveValue(t, derivativeX) / divisions,
1614
+ dy = getCurveValue(t, derivativeY) / divisions,
1615
+ l = Math.sqrt(dx * dx + dy * dy);
1616
+ lengthMap[i] = lengthMap[i - 1] + l;
1617
+ }
1618
+ this.totalLength = lengthMap[divisions];
1619
+ this.startPoint = [p1x, p1y, isEqual(p1x, c1x) && isEqual(p1y, c1y) ? Math.atan2(c2y - c1y, c2x - c1x) : Math.atan2(c1y - p1y, c1x - p1x)];
1620
+ this.endPoint = [p2x, p2y, isEqual(c2x, p2x) && isEqual(c2y, p2y) ? Math.atan2(c2y - c1y, c2x - c1x) : Math.atan2(p2y - c2y, p2x - c2x)];
1621
+ this.getBoundingBox = function () {
1622
+ let temp;
1623
+ let minX = getCurveValue(0, equationX),
1624
+ minY = getCurveValue(0, equationY),
1625
+ maxX = getCurveValue(1, equationX),
1626
+ maxY = getCurveValue(1, equationY);
1627
+ if (minX > maxX) {
1628
+ temp = maxX;
1629
+ maxX = minX;
1630
+ minX = temp;
1631
+ }
1632
+ if (minY > maxY) {
1633
+ temp = maxY;
1634
+ maxY = minY;
1635
+ minY = temp;
1636
+ }
1637
+ let rootsX = solveEquation(derivativeX);
1638
+ for (let i = 0; i < rootsX.length; i++) {
1639
+ if (rootsX[i] >= 0 && rootsX[i] <= 1) {
1640
+ let x = getCurveValue(rootsX[i], equationX);
1641
+ if (x < minX) {
1642
+ minX = x;
1643
+ }
1644
+ if (x > maxX) {
1645
+ maxX = x;
1646
+ }
1647
+ }
1648
+ }
1649
+ let rootsY = solveEquation(derivativeY);
1650
+ for (let i = 0; i < rootsY.length; i++) {
1651
+ if (rootsY[i] >= 0 && rootsY[i] <= 1) {
1652
+ let y = getCurveValue(rootsY[i], equationY);
1653
+ if (y < minY) {
1654
+ minY = y;
1655
+ }
1656
+ if (y > maxY) {
1657
+ maxY = y;
1658
+ }
1659
+ }
1660
+ }
1661
+ return [minX, minY, maxX, maxY];
1662
+ };
1663
+ this.getPointAtLength = function (l) {
1664
+ if (isEqual(l, 0)) {
1665
+ return this.startPoint;
1666
+ }
1667
+ if (isEqual(l, this.totalLength)) {
1668
+ return this.endPoint;
1669
+ }
1670
+ if (l < 0 || l > this.totalLength) {
1671
+ return;
1672
+ }
1673
+ for (let i = 1; i <= divisions; i++) {
1674
+ let l1 = lengthMap[i - 1],
1675
+ l2 = lengthMap[i];
1676
+ if (l1 <= l && l <= l2) {
1677
+ let t = (i - (l2 - l) / (l2 - l1)) / divisions,
1678
+ x = getCurveValue(t, equationX),
1679
+ y = getCurveValue(t, equationY),
1680
+ dx = getCurveValue(t, derivativeX),
1681
+ dy = getCurveValue(t, derivativeY);
1682
+ return [x, y, Math.atan2(dy, dx)];
1683
+ }
1684
+ }
1685
+ };
1686
+ };
1687
+ var LineSegment = function (p1x, p1y, p2x, p2y) {
1688
+ this.totalLength = Math.sqrt((p2x - p1x) * (p2x - p1x) + (p2y - p1y) * (p2y - p1y));
1689
+ this.startPoint = [p1x, p1y, Math.atan2(p2y - p1y, p2x - p1x)];
1690
+ this.endPoint = [p2x, p2y, Math.atan2(p2y - p1y, p2x - p1x)];
1691
+ this.getBoundingBox = function () {
1692
+ return [Math.min(this.startPoint[0], this.endPoint[0]), Math.min(this.startPoint[1], this.endPoint[1]), Math.max(this.startPoint[0], this.endPoint[0]), Math.max(this.startPoint[1], this.endPoint[1])];
1693
+ };
1694
+ this.getPointAtLength = function (l) {
1695
+ if (l >= 0 && l <= this.totalLength) {
1696
+ let r = l / this.totalLength || 0,
1697
+ x = this.startPoint[0] + r * (this.endPoint[0] - this.startPoint[0]),
1698
+ y = this.startPoint[1] + r * (this.endPoint[1] - this.startPoint[1]);
1699
+ return [x, y, this.startPoint[2]];
1700
+ }
1701
+ };
1702
+ };
1703
+ var SvgShape = function () {
1704
+ this.pathCommands = [];
1705
+ this.pathSegments = [];
1706
+ this.startPoint = null;
1707
+ this.endPoint = null;
1708
+ this.totalLength = 0;
1709
+ let startX = 0,
1710
+ startY = 0,
1711
+ currX = 0,
1712
+ currY = 0,
1713
+ lastCom,
1714
+ lastCtrlX,
1715
+ lastCtrlY;
1716
+ this.move = function (x, y) {
1717
+ startX = currX = x;
1718
+ startY = currY = y;
1719
+ return null;
1720
+ };
1721
+ this.line = function (x, y) {
1722
+ let segment = new LineSegment(currX, currY, x, y);
1723
+ currX = x;
1724
+ currY = y;
1725
+ return segment;
1726
+ };
1727
+ this.curve = function (c1x, c1y, c2x, c2y, x, y) {
1728
+ let segment = new BezierSegment(currX, currY, c1x, c1y, c2x, c2y, x, y);
1729
+ currX = x;
1730
+ currY = y;
1731
+ return segment;
1732
+ };
1733
+ this.close = function () {
1734
+ let segment = new LineSegment(currX, currY, startX, startY);
1735
+ currX = startX;
1736
+ currY = startY;
1737
+ return segment;
1738
+ };
1739
+ this.addCommand = function (data) {
1740
+ this.pathCommands.push(data);
1741
+ let segment = this[data[0]].apply(this, data.slice(3));
1742
+ if (segment) {
1743
+ segment.hasStart = data[1];
1744
+ segment.hasEnd = data[2];
1745
+ this.startPoint = this.startPoint || segment.startPoint;
1746
+ this.endPoint = segment.endPoint;
1747
+ this.pathSegments.push(segment);
1748
+ this.totalLength += segment.totalLength;
1749
+ }
1750
+ };
1751
+ this.M = function (x, y) {
1752
+ this.addCommand(['move', true, true, x, y]);
1753
+ lastCom = 'M';
1754
+ return this;
1755
+ };
1756
+ this.m = function (x, y) {
1757
+ return this.M(currX + x, currY + y);
1758
+ };
1759
+ this.Z = this.z = function () {
1760
+ this.addCommand(['close', true, true]);
1761
+ lastCom = 'Z';
1762
+ return this;
1763
+ };
1764
+ this.L = function (x, y) {
1765
+ this.addCommand(['line', true, true, x, y]);
1766
+ lastCom = 'L';
1767
+ return this;
1768
+ };
1769
+ this.l = function (x, y) {
1770
+ return this.L(currX + x, currY + y);
1771
+ };
1772
+ this.H = function (x) {
1773
+ return this.L(x, currY);
1774
+ };
1775
+ this.h = function (x) {
1776
+ return this.L(currX + x, currY);
1777
+ };
1778
+ this.V = function (y) {
1779
+ return this.L(currX, y);
1780
+ };
1781
+ this.v = function (y) {
1782
+ return this.L(currX, currY + y);
1783
+ };
1784
+ this.C = function (c1x, c1y, c2x, c2y, x, y) {
1785
+ this.addCommand(['curve', true, true, c1x, c1y, c2x, c2y, x, y]);
1786
+ lastCom = 'C';
1787
+ lastCtrlX = c2x;
1788
+ lastCtrlY = c2y;
1789
+ return this;
1790
+ };
1791
+ this.c = function (c1x, c1y, c2x, c2y, x, y) {
1792
+ return this.C(currX + c1x, currY + c1y, currX + c2x, currY + c2y, currX + x, currY + y);
1793
+ };
1794
+ this.S = function (c1x, c1y, x, y) {
1795
+ return this.C(currX + (lastCom === 'C' ? currX - lastCtrlX : 0), currY + (lastCom === 'C' ? currY - lastCtrlY : 0), c1x, c1y, x, y);
1796
+ };
1797
+ this.s = function (c1x, c1y, x, y) {
1798
+ return this.C(currX + (lastCom === 'C' ? currX - lastCtrlX : 0), currY + (lastCom === 'C' ? currY - lastCtrlY : 0), currX + c1x, currY + c1y, currX + x, currY + y);
1799
+ };
1800
+ this.Q = function (cx, cy, x, y) {
1801
+ let c1x = currX + 2 / 3 * (cx - currX),
1802
+ c1y = currY + 2 / 3 * (cy - currY),
1803
+ c2x = x + 2 / 3 * (cx - x),
1804
+ c2y = y + 2 / 3 * (cy - y);
1805
+ this.addCommand(['curve', true, true, c1x, c1y, c2x, c2y, x, y]);
1806
+ lastCom = 'Q';
1807
+ lastCtrlX = cx;
1808
+ lastCtrlY = cy;
1809
+ return this;
1810
+ };
1811
+ this.q = function (c1x, c1y, x, y) {
1812
+ return this.Q(currX + c1x, currY + c1y, currX + x, currY + y);
1813
+ };
1814
+ this.T = function (x, y) {
1815
+ return this.Q(currX + (lastCom === 'Q' ? currX - lastCtrlX : 0), currY + (lastCom === 'Q' ? currY - lastCtrlY : 0), x, y);
1816
+ };
1817
+ this.t = function (x, y) {
1818
+ return this.Q(currX + (lastCom === 'Q' ? currX - lastCtrlX : 0), currY + (lastCom === 'Q' ? currY - lastCtrlY : 0), currX + x, currY + y);
1819
+ };
1820
+ this.A = function (rx, ry, fi, fa, fs, x, y) {
1821
+ if (isEqual(rx, 0) || isEqual(ry, 0)) {
1822
+ this.addCommand(['line', true, true, x, y]);
1823
+ } else {
1824
+ fi = fi * (Math.PI / 180);
1825
+ rx = Math.abs(rx);
1826
+ ry = Math.abs(ry);
1827
+ fa = 1 * !!fa;
1828
+ fs = 1 * !!fs;
1829
+ let x1 = Math.cos(fi) * (currX - x) / 2 + Math.sin(fi) * (currY - y) / 2,
1830
+ y1 = Math.cos(fi) * (currY - y) / 2 - Math.sin(fi) * (currX - x) / 2,
1831
+ lambda = x1 * x1 / (rx * rx) + y1 * y1 / (ry * ry);
1832
+ if (lambda > 1) {
1833
+ rx *= Math.sqrt(lambda);
1834
+ ry *= Math.sqrt(lambda);
1835
+ }
1836
+ let r = Math.sqrt(Math.max(0, rx * rx * ry * ry - rx * rx * y1 * y1 - ry * ry * x1 * x1) / (rx * rx * y1 * y1 + ry * ry * x1 * x1)),
1837
+ x2 = (fa === fs ? -1 : 1) * r * rx * y1 / ry,
1838
+ y2 = (fa === fs ? 1 : -1) * r * ry * x1 / rx;
1839
+ let cx = Math.cos(fi) * x2 - Math.sin(fi) * y2 + (currX + x) / 2,
1840
+ cy = Math.sin(fi) * x2 + Math.cos(fi) * y2 + (currY + y) / 2,
1841
+ th1 = Math.atan2((y1 - y2) / ry, (x1 - x2) / rx),
1842
+ th2 = Math.atan2((-y1 - y2) / ry, (-x1 - x2) / rx);
1843
+ if (fs === 0 && th2 - th1 > 0) {
1844
+ th2 -= 2 * Math.PI;
1845
+ } else if (fs === 1 && th2 - th1 < 0) {
1846
+ th2 += 2 * Math.PI;
1847
+ }
1848
+ let segms = Math.ceil(Math.abs(th2 - th1) / (Math.PI / precision));
1849
+ for (let i = 0; i < segms; i++) {
1850
+ let th3 = th1 + i * (th2 - th1) / segms,
1851
+ th4 = th1 + (i + 1) * (th2 - th1) / segms,
1852
+ t = 4 / 3 * Math.tan((th4 - th3) / 4);
1853
+ let c1x = cx + Math.cos(fi) * rx * (Math.cos(th3) - t * Math.sin(th3)) - Math.sin(fi) * ry * (Math.sin(th3) + t * Math.cos(th3)),
1854
+ c1y = cy + Math.sin(fi) * rx * (Math.cos(th3) - t * Math.sin(th3)) + Math.cos(fi) * ry * (Math.sin(th3) + t * Math.cos(th3)),
1855
+ c2x = cx + Math.cos(fi) * rx * (Math.cos(th4) + t * Math.sin(th4)) - Math.sin(fi) * ry * (Math.sin(th4) - t * Math.cos(th4)),
1856
+ c2y = cy + Math.sin(fi) * rx * (Math.cos(th4) + t * Math.sin(th4)) + Math.cos(fi) * ry * (Math.sin(th4) - t * Math.cos(th4)),
1857
+ endX = cx + Math.cos(fi) * rx * Math.cos(th4) - Math.sin(fi) * ry * Math.sin(th4),
1858
+ endY = cy + Math.sin(fi) * rx * Math.cos(th4) + Math.cos(fi) * ry * Math.sin(th4);
1859
+ this.addCommand(['curve', i === 0, i === segms - 1, c1x, c1y, c2x, c2y, endX, endY]);
1860
+ }
1861
+ }
1862
+ lastCom = 'A';
1863
+ return this;
1864
+ };
1865
+ this.a = function (rx, ry, fi, fa, fs, x, y) {
1866
+ return this.A(rx, ry, fi, fa, fs, currX + x, currY + y);
1867
+ };
1868
+ this.path = function (d) {
1869
+ let command,
1870
+ value,
1871
+ temp,
1872
+ parser = new StringParser((d || '').trim());
1873
+ while (command = parser.match(/^[astvzqmhlcASTVZQMHLC]/)) {
1874
+ parser.matchSeparator();
1875
+ let values = [];
1876
+ while (value = PathFlags[command + values.length] ? parser.match(/^[01]/) : parser.matchNumber()) {
1877
+ parser.matchSeparator();
1878
+ if (values.length === PathArguments[command]) {
1879
+ this[command].apply(this, values);
1880
+ values = [];
1881
+ if (command === 'M') {
1882
+ command = 'L';
1883
+ } else if (command === 'm') {
1884
+ command = 'l';
1885
+ }
1886
+ }
1887
+ values.push(Number(value));
1888
+ }
1889
+ if (values.length === PathArguments[command]) {
1890
+ this[command].apply(this, values);
1891
+ } else {
1892
+ warningCallback('SvgPath: command ' + command + ' with ' + values.length + ' numbers');
1893
+ return;
1894
+ }
1895
+ }
1896
+ if (temp = parser.matchAll()) {
1897
+ warningCallback('SvgPath: unexpected string ' + temp);
1898
+ }
1899
+ return this;
1900
+ };
1901
+ this.getBoundingBox = function () {
1902
+ let bbox = [Infinity, Infinity, -Infinity, -Infinity];
1903
+ function addBounds(bbox1) {
1904
+ if (bbox1[0] < bbox[0]) {
1905
+ bbox[0] = bbox1[0];
1906
+ }
1907
+ if (bbox1[2] > bbox[2]) {
1908
+ bbox[2] = bbox1[2];
1909
+ }
1910
+ if (bbox1[1] < bbox[1]) {
1911
+ bbox[1] = bbox1[1];
1912
+ }
1913
+ if (bbox1[3] > bbox[3]) {
1914
+ bbox[3] = bbox1[3];
1915
+ }
1916
+ }
1917
+ for (let i = 0; i < this.pathSegments.length; i++) {
1918
+ addBounds(this.pathSegments[i].getBoundingBox());
1919
+ }
1920
+ if (bbox[0] === Infinity) {
1921
+ bbox[0] = 0;
1922
+ }
1923
+ if (bbox[1] === Infinity) {
1924
+ bbox[1] = 0;
1925
+ }
1926
+ if (bbox[2] === -Infinity) {
1927
+ bbox[2] = 0;
1928
+ }
1929
+ if (bbox[3] === -Infinity) {
1930
+ bbox[3] = 0;
1931
+ }
1932
+ return bbox;
1933
+ };
1934
+ this.getPointAtLength = function (l) {
1935
+ if (l >= 0 && l <= this.totalLength) {
1936
+ let temp;
1937
+ for (let i = 0; i < this.pathSegments.length; i++) {
1938
+ if (temp = this.pathSegments[i].getPointAtLength(l)) {
1939
+ return temp;
1940
+ }
1941
+ l -= this.pathSegments[i].totalLength;
1942
+ }
1943
+ return this.endPoint;
1944
+ }
1945
+ };
1946
+ this.transform = function (m) {
1947
+ this.pathSegments = [];
1948
+ this.startPoint = null;
1949
+ this.endPoint = null;
1950
+ this.totalLength = 0;
1951
+ for (let i = 0; i < this.pathCommands.length; i++) {
1952
+ let data = this.pathCommands.shift();
1953
+ for (let j = 3; j < data.length; j += 2) {
1954
+ let p = transformPoint([data[j], data[j + 1]], m);
1955
+ data[j] = p[0];
1956
+ data[j + 1] = p[1];
1957
+ }
1958
+ this.addCommand(data);
1959
+ }
1960
+ return this;
1961
+ };
1962
+ this.mergeShape = function (shape) {
1963
+ for (let i = 0; i < shape.pathCommands.length; i++) {
1964
+ this.addCommand(shape.pathCommands[i].slice());
1965
+ }
1966
+ return this;
1967
+ };
1968
+ this.clone = function () {
1969
+ return new SvgShape().mergeShape(this);
1970
+ };
1971
+ this.insertInDocument = function () {
1972
+ for (let i = 0; i < this.pathCommands.length; i++) {
1973
+ let command = this.pathCommands[i][0],
1974
+ values = this.pathCommands[i].slice(3);
1975
+ switch (command) {
1976
+ case 'move':
1977
+ doc.moveTo(values[0], values[1]);
1978
+ break;
1979
+ case 'line':
1980
+ doc.lineTo(values[0], values[1]);
1981
+ break;
1982
+ case 'curve':
1983
+ doc.bezierCurveTo(values[0], values[1], values[2], values[3], values[4], values[5]);
1984
+ break;
1985
+ case 'close':
1986
+ doc.closePath();
1987
+ break;
1988
+ }
1989
+ }
1990
+ };
1991
+ this.getSubPaths = function () {
1992
+ let subPaths = [],
1993
+ shape = new SvgShape();
1994
+ for (let i = 0; i < this.pathCommands.length; i++) {
1995
+ let data = this.pathCommands[i],
1996
+ command = this.pathCommands[i][0];
1997
+ if (command === 'move' && i !== 0) {
1998
+ subPaths.push(shape);
1999
+ shape = new SvgShape();
2000
+ }
2001
+ shape.addCommand(data);
2002
+ }
2003
+ subPaths.push(shape);
2004
+ return subPaths;
2005
+ };
2006
+ this.getMarkers = function () {
2007
+ let markers = [],
2008
+ subPaths = this.getSubPaths();
2009
+ for (let i = 0; i < subPaths.length; i++) {
2010
+ let subPath = subPaths[i],
2011
+ subPathMarkers = [];
2012
+ for (let j = 0; j < subPath.pathSegments.length; j++) {
2013
+ let segment = subPath.pathSegments[j];
2014
+ if (isNotEqual(segment.totalLength, 0) || j === 0 || j === subPath.pathSegments.length - 1) {
2015
+ if (segment.hasStart) {
2016
+ let startMarker = segment.getPointAtLength(0),
2017
+ prevEndMarker = subPathMarkers.pop();
2018
+ if (prevEndMarker) {
2019
+ startMarker[2] = 0.5 * (prevEndMarker[2] + startMarker[2]);
2020
+ }
2021
+ subPathMarkers.push(startMarker);
2022
+ }
2023
+ if (segment.hasEnd) {
2024
+ let endMarker = segment.getPointAtLength(segment.totalLength);
2025
+ subPathMarkers.push(endMarker);
2026
+ }
2027
+ }
2028
+ }
2029
+ markers = markers.concat(subPathMarkers);
2030
+ }
2031
+ return markers;
2032
+ };
2033
+ };
2034
+ var SvgElem = function (obj, inherits) {
2035
+ let styleCache = Object.create(null);
2036
+ let childrenCache = null;
2037
+ this.name = obj.nodeName;
2038
+ this.isOuterElement = obj === svg || !obj.parentNode;
2039
+ this.inherits = inherits || (!this.isOuterElement ? createSVGElement(obj.parentNode, null) : null);
2040
+ this.stack = this.inherits ? this.inherits.stack.concat(obj) : [obj];
2041
+ this.style = parseStyleAttr(typeof obj.getAttribute === 'function' && obj.getAttribute('style'));
2042
+ this.css = useCSS ? getComputedStyle(obj) : getStyle(obj);
2043
+ this.allowedChildren = [];
2044
+ this.attr = function (key) {
2045
+ if (typeof obj.getAttribute === 'function') {
2046
+ return obj.getAttribute(key);
2047
+ }
2048
+ };
2049
+ this.resolveUrl = function (value) {
2050
+ let temp = (value || '').match(/^\s*(?:url\("(.*)#(.*)"\)|url\('(.*)#(.*)'\)|url\((.*)#(.*)\)|(.*)#(.*))\s*$/) || [];
2051
+ let file = temp[1] || temp[3] || temp[5] || temp[7],
2052
+ id = temp[2] || temp[4] || temp[6] || temp[8];
2053
+ if (id) {
2054
+ if (!file) {
2055
+ let svgObj = svg.getElementById(id);
2056
+ if (svgObj) {
2057
+ if (this.stack.indexOf(svgObj) === -1) {
2058
+ return svgObj;
2059
+ } else {
2060
+ warningCallback('SVGtoPDF: loop of circular references for id "' + id + '"');
2061
+ return;
2062
+ }
2063
+ }
2064
+ }
2065
+ if (documentCallback) {
2066
+ let svgs = documentCache[file];
2067
+ if (!svgs) {
2068
+ svgs = documentCallback(file);
2069
+ if (!isArrayLike(svgs)) {
2070
+ svgs = [svgs];
2071
+ }
2072
+ for (let i = 0; i < svgs.length; i++) {
2073
+ if (typeof svgs[i] === 'string') {
2074
+ svgs[i] = parseXml(svgs[i]);
2075
+ }
2076
+ }
2077
+ documentCache[file] = svgs;
2078
+ }
2079
+ for (let i = 0; i < svgs.length; i++) {
2080
+ let svgObj = svgs[i].getElementById(id);
2081
+ if (svgObj) {
2082
+ if (this.stack.indexOf(svgObj) === -1) {
2083
+ return svgObj;
2084
+ } else {
2085
+ warningCallback('SVGtoPDF: loop of circular references for id "' + file + '#' + id + '"');
2086
+ return;
2087
+ }
2088
+ }
2089
+ }
2090
+ }
2091
+ }
2092
+ };
2093
+ this.computeUnits = function (value, unit, percent, isFontSize) {
2094
+ if (unit === '%') {
2095
+ return parseFloat(value) / 100 * (isFontSize || percent != null ? percent : this.getViewport());
2096
+ } else if (unit === 'ex' || unit === 'em') {
2097
+ return value * {
2098
+ em: 1,
2099
+ ex: 0.5
2100
+ }[unit] * (isFontSize ? percent : this.get('font-size'));
2101
+ } else {
2102
+ return value * {
2103
+ '': 1,
2104
+ px: 1,
2105
+ pt: 96 / 72,
2106
+ cm: 96 / 2.54,
2107
+ mm: 96 / 25.4,
2108
+ in: 96,
2109
+ pc: 96 / 6
2110
+ }[unit];
2111
+ }
2112
+ };
2113
+ this.computeLength = function (value, percent, initial, isFontSize) {
2114
+ let parser = new StringParser((value || '').trim()),
2115
+ temp1,
2116
+ temp2;
2117
+ if (typeof (temp1 = parser.matchNumber()) === 'string' && typeof (temp2 = parser.matchLengthUnit()) === 'string' && !parser.matchAll()) {
2118
+ return this.computeUnits(temp1, temp2, percent, isFontSize);
2119
+ }
2120
+ return initial;
2121
+ };
2122
+ this.computeLengthList = function (value, percent, strict) {
2123
+ let parser = new StringParser((value || '').trim()),
2124
+ result = [],
2125
+ temp1,
2126
+ temp2;
2127
+ while (typeof (temp1 = parser.matchNumber()) === 'string' && typeof (temp2 = parser.matchLengthUnit()) === 'string') {
2128
+ result.push(this.computeUnits(temp1, temp2, percent));
2129
+ parser.matchSeparator();
2130
+ }
2131
+ if (strict && parser.matchAll()) {
2132
+ return;
2133
+ }
2134
+ return result;
2135
+ };
2136
+ this.getLength = function (key, percent, initial) {
2137
+ return this.computeLength(this.attr(key), percent, initial);
2138
+ };
2139
+ this.getLengthList = function (key, percent) {
2140
+ return this.computeLengthList(this.attr(key), percent);
2141
+ };
2142
+ this.getUrl = function (key) {
2143
+ return this.resolveUrl(this.attr(key));
2144
+ };
2145
+ this.getNumberList = function (key) {
2146
+ let parser = new StringParser((this.attr(key) || '').trim()),
2147
+ result = [],
2148
+ temp;
2149
+ while (temp = parser.matchNumber()) {
2150
+ result.push(Number(temp));
2151
+ parser.matchSeparator();
2152
+ }
2153
+ result.error = parser.matchAll();
2154
+ return result;
2155
+ };
2156
+ this.getViewbox = function (key, initial) {
2157
+ let viewBox = this.getNumberList(key);
2158
+ if (viewBox.length === 4 && viewBox[2] >= 0 && viewBox[3] >= 0) {
2159
+ return viewBox;
2160
+ }
2161
+ return initial;
2162
+ };
2163
+ this.getPercent = function (key, initial) {
2164
+ const value = this.attr(key);
2165
+ const parser = new StringParser((value || '').trim());
2166
+ let number = parser.matchNumber();
2167
+ if (!number) {
2168
+ return initial;
2169
+ }
2170
+ if (parser.match('%')) {
2171
+ number *= 0.01;
2172
+ }
2173
+ if (parser.matchAll()) {
2174
+ return initial;
2175
+ }
2176
+ return Math.max(0, Math.min(1, number));
2177
+ };
2178
+ this.chooseValue = function () {
2179
+ for (let i = 0; i < arguments.length; i++) {
2180
+ if (arguments[i] != null && arguments[i] === arguments[i]) {
2181
+ return arguments[i];
2182
+ }
2183
+ }
2184
+ return arguments[arguments.length - 1];
2185
+ };
2186
+ this.get = function (key) {
2187
+ if (styleCache[key] !== undefined) {
2188
+ return styleCache[key];
2189
+ }
2190
+ let keyInfo = Properties[key] || {},
2191
+ value,
2192
+ result;
2193
+ for (let i = 0; i < 3; i++) {
2194
+ switch (i) {
2195
+ case 0:
2196
+ if (key !== 'transform') {
2197
+ value = this.css[keyInfo.css || key];
2198
+ }
2199
+ break;
2200
+ case 1:
2201
+ value = this.style[key];
2202
+ break;
2203
+ case 2:
2204
+ value = this.attr(key);
2205
+ break;
2206
+ }
2207
+ if (value === 'inherit') {
2208
+ result = this.inherits ? this.inherits.get(key) : keyInfo.initial;
2209
+ if (result != null) {
2210
+ return styleCache[key] = result;
2211
+ }
2212
+ }
2213
+ if (keyInfo.values != null) {
2214
+ result = keyInfo.values[value];
2215
+ if (result != null) {
2216
+ return styleCache[key] = result;
2217
+ }
2218
+ }
2219
+ if (value != null) {
2220
+ let parsed;
2221
+ switch (key) {
2222
+ case 'font-size':
2223
+ result = this.computeLength(value, this.inherits ? this.inherits.get(key) : keyInfo.initial, undefined, true);
2224
+ break;
2225
+ case 'baseline-shift':
2226
+ result = this.computeLength(value, this.get('font-size'));
2227
+ break;
2228
+ case 'font-family':
2229
+ result = value || undefined;
2230
+ break;
2231
+ case 'opacity':
2232
+ case 'stroke-opacity':
2233
+ case 'fill-opacity':
2234
+ case 'stop-opacity':
2235
+ parsed = parseFloat(value);
2236
+ if (!isNaN(parsed)) {
2237
+ result = Math.max(0, Math.min(1, parsed));
2238
+ }
2239
+ break;
2240
+ case 'transform':
2241
+ result = parseTranform(value);
2242
+ break;
2243
+ case 'stroke-dasharray':
2244
+ if (value === 'none') {
2245
+ result = [];
2246
+ } else if (parsed = this.computeLengthList(value, this.getViewport(), true)) {
2247
+ let sum = 0,
2248
+ error = false;
2249
+ for (let j = 0; j < parsed.length; j++) {
2250
+ if (parsed[j] < 0) {
2251
+ error = true;
2252
+ }
2253
+ sum += parsed[j];
2254
+ }
2255
+ if (!error) {
2256
+ if (parsed.length % 2 === 1) {
2257
+ parsed = parsed.concat(parsed);
2258
+ }
2259
+ result = sum === 0 ? [] : parsed;
2260
+ }
2261
+ }
2262
+ break;
2263
+ case 'color':
2264
+ if (value === 'none' || value === 'transparent') {
2265
+ result = 'none';
2266
+ } else {
2267
+ result = parseColor(value);
2268
+ }
2269
+ break;
2270
+ case 'fill':
2271
+ case 'stroke':
2272
+ if (value === 'none' || value === 'transparent') {
2273
+ result = 'none';
2274
+ } else if (value === 'currentColor') {
2275
+ result = this.get('color');
2276
+ } else if (parsed = parseColor(value)) {
2277
+ return parsed;
2278
+ } else if (parsed = (value || '').split(' ')) {
2279
+ let object = this.resolveUrl(parsed[0]),
2280
+ fallbackColor = parseColor(parsed[1]);
2281
+ if (object == null) {
2282
+ result = fallbackColor;
2283
+ } else if (object.nodeName === 'linearGradient' || object.nodeName === 'radialGradient') {
2284
+ result = new SvgElemGradient(object, null, fallbackColor);
2285
+ } else if (object.nodeName === 'pattern') {
2286
+ result = new SvgElemPattern(object, null, fallbackColor);
2287
+ } else {
2288
+ result = fallbackColor;
2289
+ }
2290
+ }
2291
+ break;
2292
+ case 'stop-color':
2293
+ if (value === 'none' || value === 'transparent') {
2294
+ result = 'none';
2295
+ } else if (value === 'currentColor') {
2296
+ result = this.get('color');
2297
+ } else {
2298
+ result = parseColor(value);
2299
+ }
2300
+ break;
2301
+ case 'marker-start':
2302
+ case 'marker-mid':
2303
+ case 'marker-end':
2304
+ case 'clip-path':
2305
+ case 'mask':
2306
+ if (value === 'none') {
2307
+ result = 'none';
2308
+ } else {
2309
+ result = this.resolveUrl(value);
2310
+ }
2311
+ break;
2312
+ case 'stroke-width':
2313
+ parsed = this.computeLength(value, this.getViewport());
2314
+ if (parsed != null && parsed >= 0) {
2315
+ result = parsed;
2316
+ }
2317
+ break;
2318
+ case 'stroke-miterlimit':
2319
+ parsed = parseFloat(value);
2320
+ if (parsed != null && parsed >= 1) {
2321
+ result = parsed;
2322
+ }
2323
+ break;
2324
+ case 'word-spacing':
2325
+ case 'letter-spacing':
2326
+ result = this.computeLength(value, this.getViewport());
2327
+ break;
2328
+ case 'stroke-dashoffset':
2329
+ result = this.computeLength(value, this.getViewport());
2330
+ if (result != null) {
2331
+ if (result < 0) {
2332
+ let dasharray = this.get('stroke-dasharray');
2333
+ for (let j = 0; j < dasharray.length; j++) {
2334
+ result += dasharray[j];
2335
+ }
2336
+ }
2337
+ }
2338
+ break;
2339
+ }
2340
+ if (result != null) {
2341
+ return styleCache[key] = result;
2342
+ }
2343
+ }
2344
+ }
2345
+ return styleCache[key] = keyInfo.inherit && this.inherits ? this.inherits.get(key) : keyInfo.initial;
2346
+ };
2347
+ this.getChildren = function () {
2348
+ if (childrenCache != null) {
2349
+ return childrenCache;
2350
+ }
2351
+ let children = [];
2352
+ for (let i = 0; i < obj.childNodes.length; i++) {
2353
+ let child = obj.childNodes[i];
2354
+ if (!child.error && this.allowedChildren.indexOf(child.nodeName) !== -1) {
2355
+ children.push(createSVGElement(child, this));
2356
+ }
2357
+ }
2358
+ return childrenCache = children;
2359
+ };
2360
+ this.getParentVWidth = function () {
2361
+ return this.inherits ? this.inherits.getVWidth() : viewportWidth;
2362
+ };
2363
+ this.getParentVHeight = function () {
2364
+ return this.inherits ? this.inherits.getVHeight() : viewportHeight;
2365
+ };
2366
+ this.getParentViewport = function () {
2367
+ return Math.sqrt(0.5 * this.getParentVWidth() * this.getParentVWidth() + 0.5 * this.getParentVHeight() * this.getParentVHeight());
2368
+ };
2369
+ this.getVWidth = function () {
2370
+ return this.getParentVWidth();
2371
+ };
2372
+ this.getVHeight = function () {
2373
+ return this.getParentVHeight();
2374
+ };
2375
+ this.getViewport = function () {
2376
+ return Math.sqrt(0.5 * this.getVWidth() * this.getVWidth() + 0.5 * this.getVHeight() * this.getVHeight());
2377
+ };
2378
+ this.getBoundingBox = function () {
2379
+ let shape = this.getBoundingShape();
2380
+ return shape.getBoundingBox();
2381
+ };
2382
+ };
2383
+ var SvgElemStylable = function (obj, inherits) {
2384
+ SvgElem.call(this, obj, inherits);
2385
+ this.transform = function () {
2386
+ doc.transform.apply(doc, this.getTransformation());
2387
+ };
2388
+ this.clip = function () {
2389
+ if (this.get('clip-path') !== 'none') {
2390
+ let clipPath = new SvgElemClipPath(this.get('clip-path'), null);
2391
+ clipPath.useMask(this.getBoundingBox());
2392
+ return true;
2393
+ }
2394
+ };
2395
+ this.mask = function () {
2396
+ if (this.get('mask') !== 'none') {
2397
+ let mask = new SvgElemMask(this.get('mask'), null);
2398
+ mask.useMask(this.getBoundingBox());
2399
+ return true;
2400
+ }
2401
+ };
2402
+ this.getFill = function (isClip, isMask) {
2403
+ let opacity = this.get('opacity'),
2404
+ fill = this.get('fill'),
2405
+ fillOpacity = this.get('fill-opacity');
2406
+ if (isClip) {
2407
+ return DefaultColors.white;
2408
+ }
2409
+ if (fill !== 'none' && opacity && fillOpacity) {
2410
+ if (fill instanceof SvgElemGradient || fill instanceof SvgElemPattern) {
2411
+ return fill.getPaint(this.getBoundingBox(), fillOpacity * opacity, isClip, isMask);
2412
+ }
2413
+ return opacityToColor(fill, fillOpacity * opacity, isMask);
2414
+ }
2415
+ };
2416
+ this.getStroke = function (isClip, isMask) {
2417
+ let opacity = this.get('opacity'),
2418
+ stroke = this.get('stroke'),
2419
+ strokeOpacity = this.get('stroke-opacity');
2420
+ if (isClip || isEqual(this.get('stroke-width'), 0)) {
2421
+ return;
2422
+ }
2423
+ if (stroke !== 'none' && opacity && strokeOpacity) {
2424
+ if (stroke instanceof SvgElemGradient || stroke instanceof SvgElemPattern) {
2425
+ return stroke.getPaint(this.getBoundingBox(), strokeOpacity * opacity, isClip, isMask);
2426
+ }
2427
+ return opacityToColor(stroke, strokeOpacity * opacity, isMask);
2428
+ }
2429
+ };
2430
+ };
2431
+ var SvgElemHasChildren = function (obj, inherits) {
2432
+ SvgElemStylable.call(this, obj, inherits);
2433
+ this.allowedChildren = ['use', 'g', 'a', 'svg', 'image', 'rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'path', 'text'];
2434
+ this.getBoundingShape = function () {
2435
+ let shape = new SvgShape(),
2436
+ children = this.getChildren();
2437
+ for (let i = 0; i < children.length; i++) {
2438
+ if (children[i].get('display') !== 'none') {
2439
+ if (typeof children[i].getBoundingShape === 'function') {
2440
+ let childShape = children[i].getBoundingShape().clone();
2441
+ if (typeof children[i].getTransformation === 'function') {
2442
+ childShape.transform(children[i].getTransformation());
2443
+ }
2444
+ shape.mergeShape(childShape);
2445
+ }
2446
+ }
2447
+ }
2448
+ return shape;
2449
+ };
2450
+ this.drawChildren = function (isClip, isMask) {
2451
+ let children = this.getChildren();
2452
+ for (let i = 0; i < children.length; i++) {
2453
+ if (children[i].get('display') !== 'none') {
2454
+ if (typeof children[i].drawInDocument === 'function') {
2455
+ children[i].drawInDocument(isClip, isMask);
2456
+ }
2457
+ }
2458
+ }
2459
+ };
2460
+ };
2461
+ var SvgElemContainer = function (obj, inherits) {
2462
+ SvgElemHasChildren.call(this, obj, inherits);
2463
+ this.drawContent = function (isClip, isMask, blendMode) {
2464
+ this.transform();
2465
+ let clipped = this.clip(),
2466
+ masked = this.mask(),
2467
+ group;
2468
+ if ((this.get('opacity') < 1 || clipped || masked || blendMode) && !isClip) {
2469
+ group = docBeginGroup(getPageBBox());
2470
+ }
2471
+ this.drawChildren(isClip, isMask);
2472
+ if (group) {
2473
+ docEndGroup(group);
2474
+ if (blendMode) {
2475
+ applyBlendMode(group, blendMode);
2476
+ }
2477
+ doc.fillOpacity(this.get('opacity'));
2478
+ docInsertGroup(group);
2479
+ }
2480
+ };
2481
+ };
2482
+ var SvgElemUse = function (obj, inherits) {
2483
+ SvgElemContainer.call(this, obj, inherits);
2484
+ let x = this.getLength('x', this.getVWidth(), 0),
2485
+ y = this.getLength('y', this.getVHeight(), 0),
2486
+ child = this.getUrl('href') || this.getUrl('xlink:href');
2487
+ if (child) {
2488
+ child = createSVGElement(child, this);
2489
+ }
2490
+ this.getChildren = function () {
2491
+ return child ? [child] : [];
2492
+ };
2493
+ this.drawInDocument = function (isClip, isMask) {
2494
+ doc.save();
2495
+ this.drawContent(isClip, isMask);
2496
+ doc.restore();
2497
+ };
2498
+ this.getTransformation = function () {
2499
+ return multiplyMatrix(this.get('transform'), [1, 0, 0, 1, x, y]);
2500
+ };
2501
+ };
2502
+ var SvgElemSymbol = function (obj, inherits) {
2503
+ SvgElemContainer.call(this, obj, inherits);
2504
+ let width = this.getLength('width', this.getParentVWidth(), this.getParentVWidth()),
2505
+ height = this.getLength('height', this.getParentVHeight(), this.getParentVHeight());
2506
+ if (inherits instanceof SvgElemUse) {
2507
+ width = inherits.getLength('width', inherits.getParentVWidth(), width);
2508
+ height = inherits.getLength('height', inherits.getParentVHeight(), height);
2509
+ }
2510
+ let aspectRatio = (this.attr('preserveAspectRatio') || '').trim(),
2511
+ viewBox = this.getViewbox('viewBox', [0, 0, width, height]);
2512
+ this.getVWidth = function () {
2513
+ return viewBox[2];
2514
+ };
2515
+ this.getVHeight = function () {
2516
+ return viewBox[3];
2517
+ };
2518
+ this.drawInDocument = function (isClip, isMask) {
2519
+ doc.save();
2520
+ this.drawContent(isClip, isMask);
2521
+ doc.restore();
2522
+ };
2523
+ this.getTransformation = function () {
2524
+ return multiplyMatrix(parseAspectRatio(aspectRatio, width, height, viewBox[2], viewBox[3]), [1, 0, 0, 1, -viewBox[0], -viewBox[1]]);
2525
+ };
2526
+ };
2527
+ var SvgElemGroup = function (obj, inherits) {
2528
+ SvgElemContainer.call(this, obj, inherits);
2529
+ this.drawInDocument = function (isClip, isMask) {
2530
+ doc.save();
2531
+ if (this.link && !isClip && !isMask) {
2532
+ this.addLink();
2533
+ }
2534
+ const styles = getObjectStyles(obj);
2535
+ if (styles['mix-blend-mode']) {
2536
+ this.drawContent(isClip, isMask, parseCSSBlendMode(styles['mix-blend-mode']));
2537
+ } else {
2538
+ this.drawContent(isClip, isMask);
2539
+ }
2540
+ doc.restore();
2541
+ };
2542
+ this.getTransformation = function () {
2543
+ return this.get('transform');
2544
+ };
2545
+ };
2546
+ var SvgElemLink = function (obj, inherits) {
2547
+ if (inherits && inherits.isText) {
2548
+ SvgElemTspan.call(this, obj, inherits);
2549
+ this.allowedChildren = ['textPath', 'tspan', '#text', '#cdata-section', 'a'];
2550
+ } else {
2551
+ SvgElemGroup.call(this, obj, inherits);
2552
+ }
2553
+ this.link = this.attr('href') || this.attr('xlink:href');
2554
+ this.addLink = function () {
2555
+ if (this.link.match(/^(?:[a-z][a-z0-9+.-]*:|\/\/)?/i) && this.getChildren().length) {
2556
+ let bbox = this.getBoundingShape().transform(getGlobalMatrix()).getBoundingBox();
2557
+ docInsertLink(bbox[0], bbox[1], bbox[2], bbox[3], this.link);
2558
+ }
2559
+ };
2560
+ };
2561
+ var SvgElemSvg = function (obj, inherits) {
2562
+ SvgElemContainer.call(this, obj, inherits);
2563
+ let width = this.getLength('width', this.getParentVWidth(), this.getParentVWidth()),
2564
+ height = this.getLength('height', this.getParentVHeight(), this.getParentVHeight()),
2565
+ x = this.getLength('x', this.getParentVWidth(), 0),
2566
+ y = this.getLength('y', this.getParentVHeight(), 0);
2567
+ if (inherits instanceof SvgElemUse) {
2568
+ width = inherits.getLength('width', inherits.getParentVWidth(), width);
2569
+ height = inherits.getLength('height', inherits.getParentVHeight(), height);
2570
+ }
2571
+ let aspectRatio = this.attr('preserveAspectRatio'),
2572
+ viewBox = this.getViewbox('viewBox', [0, 0, width, height]);
2573
+ if (this.isOuterElement && preserveAspectRatio) {
2574
+ x = y = 0;
2575
+ width = viewportWidth;
2576
+ height = viewportHeight;
2577
+ aspectRatio = preserveAspectRatio;
2578
+ }
2579
+ this.getVWidth = function () {
2580
+ return viewBox[2];
2581
+ };
2582
+ this.getVHeight = function () {
2583
+ return viewBox[3];
2584
+ };
2585
+ this.drawInDocument = function (isClip, isMask) {
2586
+ doc.save();
2587
+ if (this.get('overflow') === 'hidden') {
2588
+ new SvgShape().M(x, y).L(x + width, y).L(x + width, y + height).L(x, y + height).Z().transform(this.get('transform')).insertInDocument();
2589
+ doc.clip();
2590
+ }
2591
+ this.drawContent(isClip, isMask);
2592
+ doc.restore();
2593
+ };
2594
+ this.getTransformation = function () {
2595
+ return multiplyMatrix(this.get('transform'), [1, 0, 0, 1, x, y], parseAspectRatio(aspectRatio, width, height, viewBox[2], viewBox[3]), [1, 0, 0, 1, -viewBox[0], -viewBox[1]]);
2596
+ };
2597
+ };
2598
+ var SVGElemImage = function (obj, inherits) {
2599
+ SvgElemStylable.call(this, obj, inherits);
2600
+ const {
2601
+ src: imageSrc,
2602
+ properties
2603
+ } = imageCallback(this.attr('href') || this.attr('xlink:href') || '');
2604
+ let x = this.getLength('x', this.getVWidth(), 0),
2605
+ y = this.getLength('y', this.getVHeight(), 0),
2606
+ width = this.getLength('width', this.getVWidth(), 'auto'),
2607
+ height = this.getLength('height', this.getVHeight(), 'auto'),
2608
+ image;
2609
+ try {
2610
+ image = doc.openImage(imageSrc, properties);
2611
+ } catch (e) {
2612
+ warningCallback('SVGElemImage: failed to open image "' + e + '" in PDFKit', e);
2613
+ }
2614
+ if (image) {
2615
+ if (width === 'auto' && height !== 'auto') {
2616
+ width = height * image.width / image.height;
2617
+ } else if (height === 'auto' && width !== 'auto') {
2618
+ height = width * image.height / image.width;
2619
+ } else if (width === 'auto' && height === 'auto') {
2620
+ width = image.width;
2621
+ height = image.height;
2622
+ }
2623
+ }
2624
+ if (width === 'auto' || width < 0) {
2625
+ width = 0;
2626
+ }
2627
+ if (height === 'auto' || height < 0) {
2628
+ height = 0;
2629
+ }
2630
+ this.getTransformation = function () {
2631
+ return this.get('transform');
2632
+ };
2633
+ this.getBoundingShape = function () {
2634
+ return new SvgShape().M(x, y).L(x + width, y).M(x + width, y + height).L(x, y + height);
2635
+ };
2636
+ this.drawInDocument = function (isClip) {
2637
+ if (this.get('visibility') === 'hidden' || !image) {
2638
+ return;
2639
+ }
2640
+ doc.save();
2641
+ this.transform();
2642
+ if (this.get('overflow') === 'hidden') {
2643
+ doc.rect(x, y, width, height).clip();
2644
+ }
2645
+ this.clip();
2646
+ this.mask();
2647
+ doc.translate(x, y);
2648
+ doc.transform.apply(doc, parseAspectRatio(this.attr('preserveAspectRatio'), width, height, image ? image.width : width, image ? image.height : height));
2649
+ if (!isClip) {
2650
+ doc.fillOpacity(this.get('opacity'));
2651
+ doc.image(image, 0, 0);
2652
+ } else {
2653
+ doc.rect(0, 0, image.width, image.height);
2654
+ docFillColor(DefaultColors.white).fill();
2655
+ }
2656
+ doc.restore();
2657
+ };
2658
+ };
2659
+ var SvgElemPattern = function (obj, inherits, fallback) {
2660
+ SvgElemHasChildren.call(this, obj, inherits);
2661
+ this.ref = function () {
2662
+ let ref = this.getUrl('href') || this.getUrl('xlink:href');
2663
+ if (ref && ref.nodeName === obj.nodeName) {
2664
+ return new SvgElemPattern(ref, inherits, fallback);
2665
+ }
2666
+ }.call(this);
2667
+ let _attr = this.attr;
2668
+ this.attr = function (key) {
2669
+ let attr = _attr.call(this, key);
2670
+ if (attr != null || key === 'href' || key === 'xlink:href') {
2671
+ return attr;
2672
+ }
2673
+ return this.ref ? this.ref.attr(key) : null;
2674
+ };
2675
+ let _getChildren = this.getChildren;
2676
+ this.getChildren = function () {
2677
+ let children = _getChildren.call(this);
2678
+ if (children.length > 0) {
2679
+ return children;
2680
+ }
2681
+ return this.ref ? this.ref.getChildren() : [];
2682
+ };
2683
+ this.getPaint = function (bBox, gOpacity, isClip, isMask) {
2684
+ let bBoxUnitsPattern = this.attr('patternUnits') !== 'userSpaceOnUse',
2685
+ bBoxUnitsContent = this.attr('patternContentUnits') === 'objectBoundingBox',
2686
+ x = this.getLength('x', bBoxUnitsPattern ? 1 : this.getParentVWidth(), 0),
2687
+ y = this.getLength('y', bBoxUnitsPattern ? 1 : this.getParentVHeight(), 0),
2688
+ width = this.getLength('width', bBoxUnitsPattern ? 1 : this.getParentVWidth(), 0),
2689
+ height = this.getLength('height', bBoxUnitsPattern ? 1 : this.getParentVHeight(), 0);
2690
+ if (bBoxUnitsContent && !bBoxUnitsPattern) {
2691
+ x = (x - bBox[0]) / (bBox[2] - bBox[0]) || 0;
2692
+ y = (y - bBox[1]) / (bBox[3] - bBox[1]) || 0;
2693
+ width = width / (bBox[2] - bBox[0]) || 0;
2694
+ height = height / (bBox[3] - bBox[1]) || 0;
2695
+ } else if (!bBoxUnitsContent && bBoxUnitsPattern) {
2696
+ x = bBox[0] + x * (bBox[2] - bBox[0]);
2697
+ y = bBox[1] + y * (bBox[3] - bBox[1]);
2698
+ width = width * (bBox[2] - bBox[0]);
2699
+ height = height * (bBox[3] - bBox[1]);
2700
+ }
2701
+ let viewBox = this.getViewbox('viewBox', [0, 0, width, height]),
2702
+ aspectRatio = (this.attr('preserveAspectRatio') || '').trim(),
2703
+ aspectRatioMatrix = multiplyMatrix(parseAspectRatio(aspectRatio, width, height, viewBox[2], viewBox[3], 0), [1, 0, 0, 1, -viewBox[0], -viewBox[1]]),
2704
+ matrix = parseTranform(this.attr('patternTransform'));
2705
+ if (bBoxUnitsContent) {
2706
+ matrix = multiplyMatrix([bBox[2] - bBox[0], 0, 0, bBox[3] - bBox[1], bBox[0], bBox[1]], matrix);
2707
+ }
2708
+ matrix = multiplyMatrix(matrix, [1, 0, 0, 1, x, y]);
2709
+ if ((matrix = validateMatrix(matrix)) && (aspectRatioMatrix = validateMatrix(aspectRatioMatrix)) && (width = validateNumber(width)) && (height = validateNumber(height))) {
2710
+ let group = docBeginGroup([0, 0, width, height]);
2711
+ doc.transform.apply(doc, aspectRatioMatrix);
2712
+ this.drawChildren(isClip, isMask);
2713
+ docEndGroup(group);
2714
+ return [docCreatePattern(group, width, height, matrix), gOpacity];
2715
+ } else {
2716
+ return fallback ? [fallback[0], fallback[1] * gOpacity] : undefined;
2717
+ }
2718
+ };
2719
+ this.getVWidth = function () {
2720
+ let bBoxUnitsPattern = this.attr('patternUnits') !== 'userSpaceOnUse',
2721
+ width = this.getLength('width', bBoxUnitsPattern ? 1 : this.getParentVWidth(), 0);
2722
+ return this.getViewbox('viewBox', [0, 0, width, 0])[2];
2723
+ };
2724
+ this.getVHeight = function () {
2725
+ let bBoxUnitsPattern = this.attr('patternUnits') !== 'userSpaceOnUse',
2726
+ height = this.getLength('height', bBoxUnitsPattern ? 1 : this.getParentVHeight(), 0);
2727
+ return this.getViewbox('viewBox', [0, 0, 0, height])[3];
2728
+ };
2729
+ };
2730
+ var SvgElemGradient = function (obj, inherits, fallback) {
2731
+ SvgElem.call(this, obj, inherits);
2732
+ this.allowedChildren = ['stop'];
2733
+ this.ref = function () {
2734
+ let ref = this.getUrl('href') || this.getUrl('xlink:href');
2735
+ if (ref && ref.nodeName === obj.nodeName) {
2736
+ return new SvgElemGradient(ref, inherits, fallback);
2737
+ }
2738
+ }.call(this);
2739
+ let _attr = this.attr;
2740
+ this.attr = function (key) {
2741
+ let attr = _attr.call(this, key);
2742
+ if (attr != null || key === 'href' || key === 'xlink:href') {
2743
+ return attr;
2744
+ }
2745
+ return this.ref ? this.ref.attr(key) : null;
2746
+ };
2747
+ let _getChildren = this.getChildren;
2748
+ this.getChildren = function () {
2749
+ let children = _getChildren.call(this);
2750
+ if (children.length > 0) {
2751
+ return children;
2752
+ }
2753
+ return this.ref ? this.ref.getChildren() : [];
2754
+ };
2755
+ this.getPaint = function (bBox, gOpacity, isClip, isMask) {
2756
+ let children = this.getChildren();
2757
+ if (children.length === 0) {
2758
+ return;
2759
+ }
2760
+ if (children.length === 1) {
2761
+ let child = children[0],
2762
+ stopColor = child.get('stop-color');
2763
+ if (stopColor === 'none') {
2764
+ return;
2765
+ }
2766
+ return opacityToColor(stopColor, child.get('stop-opacity') * gOpacity, isMask);
2767
+ }
2768
+ let bBoxUnits = this.attr('gradientUnits') !== 'userSpaceOnUse',
2769
+ matrix = parseTranform(this.attr('gradientTransform')),
2770
+ spread = this.attr('spreadMethod'),
2771
+ grad,
2772
+ x1,
2773
+ x2,
2774
+ y1,
2775
+ y2,
2776
+ r2,
2777
+ nAfter = 0,
2778
+ nBefore = 0,
2779
+ nTotal = 1;
2780
+ if (matrix && bBoxUnits) {
2781
+ matrix = multiplyMatrix([bBox[2] - bBox[0], 0, 0, bBox[3] - bBox[1], bBox[0], bBox[1]], matrix);
2782
+ }
2783
+ if (matrix && (matrix = validateMatrix(matrix))) {
2784
+ if (this.name === 'linearGradient') {
2785
+ x1 = this.getLength('x1', bBoxUnits ? 1 : this.getVWidth(), 0);
2786
+ x2 = this.getLength('x2', bBoxUnits ? 1 : this.getVWidth(), bBoxUnits ? 1 : this.getVWidth());
2787
+ y1 = this.getLength('y1', bBoxUnits ? 1 : this.getVHeight(), 0);
2788
+ y2 = this.getLength('y2', bBoxUnits ? 1 : this.getVHeight(), 0);
2789
+ } else {
2790
+ x2 = this.getLength('cx', bBoxUnits ? 1 : this.getVWidth(), bBoxUnits ? 0.5 : 0.5 * this.getVWidth());
2791
+ y2 = this.getLength('cy', bBoxUnits ? 1 : this.getVHeight(), bBoxUnits ? 0.5 : 0.5 * this.getVHeight());
2792
+ r2 = this.getLength('r', bBoxUnits ? 1 : this.getViewport(), bBoxUnits ? 0.5 : 0.5 * this.getViewport());
2793
+ x1 = this.getLength('fx', bBoxUnits ? 1 : this.getVWidth(), x2);
2794
+ y1 = this.getLength('fy', bBoxUnits ? 1 : this.getVHeight(), y2);
2795
+ if (r2 < 0) {
2796
+ warningCallback('SvgElemGradient: negative r value');
2797
+ }
2798
+ let d = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)),
2799
+ multiplier = 1;
2800
+ if (d > r2) {
2801
+ multiplier = r2 / d;
2802
+ x1 = x2 + (x1 - x2) * multiplier;
2803
+ y1 = y2 + (y1 - y2) * multiplier;
2804
+ }
2805
+ r2 = Math.max(r2, d * multiplier * (1 + 1e-6));
2806
+ }
2807
+ if (spread === 'reflect' || spread === 'repeat') {
2808
+ let inv = inverseMatrix(matrix),
2809
+ corner1 = transformPoint([bBox[0], bBox[1]], inv),
2810
+ corner2 = transformPoint([bBox[2], bBox[1]], inv),
2811
+ corner3 = transformPoint([bBox[2], bBox[3]], inv),
2812
+ corner4 = transformPoint([bBox[0], bBox[3]], inv);
2813
+ if (this.name === 'linearGradient') {
2814
+ nAfter = Math.max((corner1[0] - x2) * (x2 - x1) + (corner1[1] - y2) * (y2 - y1), (corner2[0] - x2) * (x2 - x1) + (corner2[1] - y2) * (y2 - y1), (corner3[0] - x2) * (x2 - x1) + (corner3[1] - y2) * (y2 - y1), (corner4[0] - x2) * (x2 - x1) + (corner4[1] - y2) * (y2 - y1)) / (Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
2815
+ nBefore = Math.max((corner1[0] - x1) * (x1 - x2) + (corner1[1] - y1) * (y1 - y2), (corner2[0] - x1) * (x1 - x2) + (corner2[1] - y1) * (y1 - y2), (corner3[0] - x1) * (x1 - x2) + (corner3[1] - y1) * (y1 - y2), (corner4[0] - x1) * (x1 - x2) + (corner4[1] - y1) * (y1 - y2)) / (Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
2816
+ } else {
2817
+ nAfter = Math.sqrt(Math.max(Math.pow(corner1[0] - x2, 2) + Math.pow(corner1[1] - y2, 2), Math.pow(corner2[0] - x2, 2) + Math.pow(corner2[1] - y2, 2), Math.pow(corner3[0] - x2, 2) + Math.pow(corner3[1] - y2, 2), Math.pow(corner4[0] - x2, 2) + Math.pow(corner4[1] - y2, 2))) / r2 - 1;
2818
+ }
2819
+ nAfter = Math.ceil(nAfter + 0.5);
2820
+ nBefore = Math.ceil(nBefore + 0.5);
2821
+ nTotal = nBefore + 1 + nAfter;
2822
+ }
2823
+ if (this.name === 'linearGradient') {
2824
+ grad = doc.linearGradient(x1 - nBefore * (x2 - x1), y1 - nBefore * (y2 - y1), x2 + nAfter * (x2 - x1), y2 + nAfter * (y2 - y1));
2825
+ } else {
2826
+ grad = doc.radialGradient(x1, y1, 0, x2, y2, r2 + nAfter * r2);
2827
+ }
2828
+ for (let n = 0; n < nTotal; n++) {
2829
+ let offset = 0,
2830
+ inOrder = spread !== 'reflect' || (n - nBefore) % 2 === 0;
2831
+ for (let i = 0; i < children.length; i++) {
2832
+ let child = children[inOrder ? i : children.length - 1 - i],
2833
+ stopColor = child.get('stop-color');
2834
+ if (stopColor === 'none') {
2835
+ stopColor = DefaultColors.transparent;
2836
+ }
2837
+ stopColor = opacityToColor(stopColor, child.get('stop-opacity') * gOpacity, isMask);
2838
+ offset = Math.max(offset, inOrder ? child.getPercent('offset', 0) : 1 - child.getPercent('offset', 0));
2839
+ if (i === 0 && offset > 0) {
2840
+ grad.stop((n + 0) / nTotal, stopColor[0], stopColor[1]);
2841
+ }
2842
+ grad.stop((n + offset) / (nAfter + nBefore + 1), stopColor[0], stopColor[1]);
2843
+ if (i === children.length - 1 && offset < 1) {
2844
+ grad.stop((n + 1) / nTotal, stopColor[0], stopColor[1]);
2845
+ }
2846
+ }
2847
+ }
2848
+ grad.setTransform.apply(grad, matrix);
2849
+ return [grad, 1];
2850
+ } else {
2851
+ return fallback ? [fallback[0], fallback[1] * gOpacity] : undefined;
2852
+ }
2853
+ };
2854
+ };
2855
+ var SvgElemBasicShape = function (obj, inherits) {
2856
+ SvgElemStylable.call(this, obj, inherits);
2857
+ this.dashScale = 1;
2858
+ this.getBoundingShape = function () {
2859
+ return this.shape;
2860
+ };
2861
+ this.getTransformation = function () {
2862
+ return this.get('transform');
2863
+ };
2864
+ this.drawInDocument = function (isClip, isMask) {
2865
+ if (this.get('visibility') === 'hidden' || !this.shape) {
2866
+ return;
2867
+ }
2868
+ doc.save();
2869
+ this.transform();
2870
+ this.clip();
2871
+ if (!isClip) {
2872
+ let masked = this.mask(),
2873
+ group;
2874
+ if (masked) {
2875
+ group = docBeginGroup(getPageBBox());
2876
+ }
2877
+ let subPaths = this.shape.getSubPaths(),
2878
+ fill = this.getFill(isClip, isMask),
2879
+ stroke = this.getStroke(isClip, isMask),
2880
+ lineWidth = this.get('stroke-width'),
2881
+ lineCap = this.get('stroke-linecap');
2882
+ if (fill || stroke) {
2883
+ if (fill) {
2884
+ docFillColor(fill);
2885
+ }
2886
+ if (stroke) {
2887
+ for (let j = 0; j < subPaths.length; j++) {
2888
+ if (isEqual(subPaths[j].totalLength, 0)) {
2889
+ if ((lineCap === 'square' || lineCap === 'round') && lineWidth > 0) {
2890
+ if (subPaths[j].startPoint && subPaths[j].startPoint.length > 1) {
2891
+ let x = subPaths[j].startPoint[0],
2892
+ y = subPaths[j].startPoint[1];
2893
+ docFillColor(stroke);
2894
+ if (lineCap === 'square') {
2895
+ doc.rect(x - 0.5 * lineWidth, y - 0.5 * lineWidth, lineWidth, lineWidth);
2896
+ } else if (lineCap === 'round') {
2897
+ doc.circle(x, y, 0.5 * lineWidth);
2898
+ }
2899
+ doc.fill();
2900
+ }
2901
+ }
2902
+ }
2903
+ }
2904
+ let dashArray = this.get('stroke-dasharray'),
2905
+ dashOffset = this.get('stroke-dashoffset');
2906
+ if (isNotEqual(this.dashScale, 1)) {
2907
+ for (let j = 0; j < dashArray.length; j++) {
2908
+ dashArray[j] *= this.dashScale;
2909
+ }
2910
+ dashOffset *= this.dashScale;
2911
+ }
2912
+ docStrokeColor(stroke);
2913
+ doc.lineWidth(lineWidth).miterLimit(this.get('stroke-miterlimit')).lineJoin(this.get('stroke-linejoin')).lineCap(lineCap).dash(dashArray, {
2914
+ phase: dashOffset
2915
+ });
2916
+ }
2917
+ for (let j = 0; j < subPaths.length; j++) {
2918
+ if (subPaths[j].totalLength > 0) {
2919
+ subPaths[j].insertInDocument();
2920
+ }
2921
+ }
2922
+ if (fill && stroke) {
2923
+ doc.fillAndStroke(this.get('fill-rule'));
2924
+ } else if (fill) {
2925
+ doc.fill(this.get('fill-rule'));
2926
+ } else if (stroke) {
2927
+ doc.stroke();
2928
+ }
2929
+ }
2930
+ let markerStart = this.get('marker-start'),
2931
+ markerMid = this.get('marker-mid'),
2932
+ markerEnd = this.get('marker-end');
2933
+ if (markerStart !== 'none' || markerMid !== 'none' || markerEnd !== 'none') {
2934
+ let markersPos = this.shape.getMarkers();
2935
+ if (markerStart !== 'none' && markersPos.length > 0) {
2936
+ let marker = new SvgElemMarker(markerStart, null);
2937
+ marker.drawMarker(false, isMask, markersPos[0], lineWidth);
2938
+ }
2939
+ if (markerMid !== 'none') {
2940
+ for (let i = 1; i < markersPos.length - 1; i++) {
2941
+ let marker = new SvgElemMarker(markerMid, null);
2942
+ marker.drawMarker(false, isMask, markersPos[i], lineWidth);
2943
+ }
2944
+ }
2945
+ if (markerEnd !== 'none' && markersPos.length > 0) {
2946
+ let marker = new SvgElemMarker(markerEnd, null);
2947
+ marker.drawMarker(false, isMask, markersPos[markersPos.length - 1], lineWidth);
2948
+ }
2949
+ }
2950
+ if (group) {
2951
+ docEndGroup(group);
2952
+ docInsertGroup(group);
2953
+ }
2954
+ } else {
2955
+ this.shape.insertInDocument();
2956
+ docFillColor(DefaultColors.white);
2957
+ doc.fill(this.get('clip-rule'));
2958
+ }
2959
+ doc.restore();
2960
+ };
2961
+ };
2962
+ var SvgElemRect = function (obj, inherits) {
2963
+ SvgElemBasicShape.call(this, obj, inherits);
2964
+ let x = this.getLength('x', this.getVWidth(), 0),
2965
+ y = this.getLength('y', this.getVHeight(), 0),
2966
+ w = this.getLength('width', this.getVWidth(), 0),
2967
+ h = this.getLength('height', this.getVHeight(), 0),
2968
+ rx = this.getLength('rx', this.getVWidth()),
2969
+ ry = this.getLength('ry', this.getVHeight());
2970
+ if (rx === undefined && ry === undefined) {
2971
+ rx = ry = 0;
2972
+ } else if (rx === undefined && ry !== undefined) {
2973
+ rx = ry;
2974
+ } else if (rx !== undefined && ry === undefined) {
2975
+ ry = rx;
2976
+ }
2977
+ if (w > 0 && h > 0) {
2978
+ if (rx && ry) {
2979
+ rx = Math.min(rx, 0.5 * w);
2980
+ ry = Math.min(ry, 0.5 * h);
2981
+ this.shape = new SvgShape().M(x + rx, y).L(x + w - rx, y).A(rx, ry, 0, 0, 1, x + w, y + ry).L(x + w, y + h - ry).A(rx, ry, 0, 0, 1, x + w - rx, y + h).L(x + rx, y + h).A(rx, ry, 0, 0, 1, x, y + h - ry).L(x, y + ry).A(rx, ry, 0, 0, 1, x + rx, y).Z();
2982
+ } else {
2983
+ this.shape = new SvgShape().M(x, y).L(x + w, y).L(x + w, y + h).L(x, y + h).Z();
2984
+ }
2985
+ } else {
2986
+ this.shape = new SvgShape();
2987
+ }
2988
+ };
2989
+ var SvgElemCircle = function (obj, inherits) {
2990
+ SvgElemBasicShape.call(this, obj, inherits);
2991
+ let cx = this.getLength('cx', this.getVWidth(), 0),
2992
+ cy = this.getLength('cy', this.getVHeight(), 0),
2993
+ r = this.getLength('r', this.getViewport(), 0);
2994
+ if (r > 0) {
2995
+ this.shape = new SvgShape().M(cx + r, cy).A(r, r, 0, 0, 1, cx - r, cy).A(r, r, 0, 0, 1, cx + r, cy).Z();
2996
+ } else {
2997
+ this.shape = new SvgShape();
2998
+ }
2999
+ };
3000
+ var SvgElemEllipse = function (obj, inherits) {
3001
+ SvgElemBasicShape.call(this, obj, inherits);
3002
+ let cx = this.getLength('cx', this.getVWidth(), 0),
3003
+ cy = this.getLength('cy', this.getVHeight(), 0),
3004
+ rx = this.getLength('rx', this.getVWidth(), 0),
3005
+ ry = this.getLength('ry', this.getVHeight(), 0);
3006
+ if (rx > 0 && ry > 0) {
3007
+ this.shape = new SvgShape().M(cx + rx, cy).A(rx, ry, 0, 0, 1, cx - rx, cy).A(rx, ry, 0, 0, 1, cx + rx, cy).Z();
3008
+ } else {
3009
+ this.shape = new SvgShape();
3010
+ }
3011
+ };
3012
+ var SvgElemLine = function (obj, inherits) {
3013
+ SvgElemBasicShape.call(this, obj, inherits);
3014
+ let x1 = this.getLength('x1', this.getVWidth(), 0),
3015
+ y1 = this.getLength('y1', this.getVHeight(), 0),
3016
+ x2 = this.getLength('x2', this.getVWidth(), 0),
3017
+ y2 = this.getLength('y2', this.getVHeight(), 0);
3018
+ this.shape = new SvgShape().M(x1, y1).L(x2, y2);
3019
+ };
3020
+ var SvgElemPolyline = function (obj, inherits) {
3021
+ SvgElemBasicShape.call(this, obj, inherits);
3022
+ let points = this.getNumberList('points');
3023
+ this.shape = new SvgShape();
3024
+ for (let i = 0; i < points.length - 1; i += 2) {
3025
+ if (i === 0) {
3026
+ this.shape.M(points[i], points[i + 1]);
3027
+ } else {
3028
+ this.shape.L(points[i], points[i + 1]);
3029
+ }
3030
+ }
3031
+ if (points.error) {
3032
+ warningCallback('SvgElemPolygon: unexpected string ' + points.error);
3033
+ }
3034
+ if (points.length % 2 === 1) {
3035
+ warningCallback('SvgElemPolyline: uneven number of coordinates');
3036
+ }
3037
+ };
3038
+ var SvgElemPolygon = function (obj, inherits) {
3039
+ SvgElemBasicShape.call(this, obj, inherits);
3040
+ let points = this.getNumberList('points');
3041
+ this.shape = new SvgShape();
3042
+ for (let i = 0; i < points.length - 1; i += 2) {
3043
+ if (i === 0) {
3044
+ this.shape.M(points[i], points[i + 1]);
3045
+ } else {
3046
+ this.shape.L(points[i], points[i + 1]);
3047
+ }
3048
+ }
3049
+ this.shape.Z();
3050
+ if (points.error) {
3051
+ warningCallback('SvgElemPolygon: unexpected string ' + points.error);
3052
+ }
3053
+ if (points.length % 2 === 1) {
3054
+ warningCallback('SvgElemPolygon: uneven number of coordinates');
3055
+ }
3056
+ };
3057
+ var SvgElemPath = function (obj, inherits) {
3058
+ SvgElemBasicShape.call(this, obj, inherits);
3059
+ this.shape = new SvgShape().path(this.attr('d'));
3060
+ let pathLength = this.getLength('pathLength', this.getViewport());
3061
+ this.pathLength = pathLength > 0 ? pathLength : undefined;
3062
+ this.dashScale = this.pathLength !== undefined ? this.shape.totalLength / this.pathLength : 1;
3063
+ };
3064
+ var SvgElemMarker = function (obj, inherits) {
3065
+ SvgElemHasChildren.call(this, obj, inherits);
3066
+ let width = this.getLength('markerWidth', this.getParentVWidth(), 3),
3067
+ height = this.getLength('markerHeight', this.getParentVHeight(), 3),
3068
+ viewBox = this.getViewbox('viewBox', [0, 0, width, height]);
3069
+ this.getVWidth = function () {
3070
+ return viewBox[2];
3071
+ };
3072
+ this.getVHeight = function () {
3073
+ return viewBox[3];
3074
+ };
3075
+ this.drawMarker = function (isClip, isMask, posArray, strokeWidth) {
3076
+ doc.save();
3077
+ let orient = this.attr('orient'),
3078
+ units = this.attr('markerUnits'),
3079
+ rotate = orient === 'auto' ? posArray[2] : (parseFloat(orient) || 0) * Math.PI / 180,
3080
+ scale = units === 'userSpaceOnUse' ? 1 : strokeWidth;
3081
+ doc.transform(Math.cos(rotate) * scale, Math.sin(rotate) * scale, -Math.sin(rotate) * scale, Math.cos(rotate) * scale, posArray[0], posArray[1]);
3082
+ let refX = this.getLength('refX', this.getVWidth(), 0),
3083
+ refY = this.getLength('refY', this.getVHeight(), 0),
3084
+ aspectRatioMatrix = parseAspectRatio(this.attr('preserveAspectRatio'), width, height, viewBox[2], viewBox[3], 0.5);
3085
+ if (this.get('overflow') === 'hidden') {
3086
+ doc.rect(aspectRatioMatrix[0] * (viewBox[0] + viewBox[2] / 2 - refX) - width / 2, aspectRatioMatrix[3] * (viewBox[1] + viewBox[3] / 2 - refY) - height / 2, width, height).clip();
3087
+ }
3088
+ doc.transform.apply(doc, aspectRatioMatrix);
3089
+ doc.translate(-refX, -refY);
3090
+ let group;
3091
+ if (this.get('opacity') < 1 && !isClip) {
3092
+ group = docBeginGroup(getPageBBox());
3093
+ }
3094
+ this.drawChildren(isClip, isMask);
3095
+ if (group) {
3096
+ docEndGroup(group);
3097
+ doc.fillOpacity(this.get('opacity'));
3098
+ docInsertGroup(group);
3099
+ }
3100
+ doc.restore();
3101
+ };
3102
+ };
3103
+ var SvgElemClipPath = function (obj, inherits) {
3104
+ SvgElemHasChildren.call(this, obj, inherits);
3105
+ this.useMask = function (bBox) {
3106
+ let group = docBeginGroup(getPageBBox());
3107
+ doc.save();
3108
+ doc.transform.apply(doc, this.get('transform'));
3109
+ if (this.attr('clipPathUnits') === 'objectBoundingBox') {
3110
+ doc.transform(bBox[2] - bBox[0], 0, 0, bBox[3] - bBox[1], bBox[0], bBox[1]);
3111
+ }
3112
+ this.clip();
3113
+ this.drawChildren(true, false);
3114
+ doc.restore();
3115
+ docEndGroup(group);
3116
+ docApplyMask(group, true);
3117
+ };
3118
+ };
3119
+ var SvgElemMask = function (obj, inherits) {
3120
+ SvgElemHasChildren.call(this, obj, inherits);
3121
+ this.useMask = function (bBox) {
3122
+ let group = docBeginGroup(getPageBBox());
3123
+ doc.save();
3124
+ if (this.attr('maskUnits') === 'userSpaceOnUse') {
3125
+ this.getLength('x', this.getVWidth(), -0.1 * (bBox[2] - bBox[0]) + bBox[0]);
3126
+ this.getLength('y', this.getVHeight(), -0.1 * (bBox[3] - bBox[1]) + bBox[1]);
3127
+ this.getLength('width', this.getVWidth(), 1.2 * (bBox[2] - bBox[0]));
3128
+ this.getLength('height', this.getVHeight(), 1.2 * (bBox[3] - bBox[1]));
3129
+ } else {
3130
+ this.getLength('x', this.getVWidth(), -0.1) * (bBox[2] - bBox[0]) + bBox[0];
3131
+ this.getLength('y', this.getVHeight(), -0.1) * (bBox[3] - bBox[1]) + bBox[1];
3132
+ this.getLength('width', this.getVWidth(), 1.2) * (bBox[2] - bBox[0]);
3133
+ this.getLength('height', this.getVHeight(), 1.2) * (bBox[3] - bBox[1]);
3134
+ }
3135
+ if (this.attr('maskContentUnits') === 'objectBoundingBox') {
3136
+ doc.transform(bBox[2] - bBox[0], 0, 0, bBox[3] - bBox[1], bBox[0], bBox[1]);
3137
+ }
3138
+ this.clip();
3139
+ this.drawChildren(false, true);
3140
+ doc.restore();
3141
+ docEndGroup(group);
3142
+ docApplyMask(group, true);
3143
+ };
3144
+ };
3145
+ var SvgElemTextContainer = function (obj, inherits) {
3146
+ SvgElemStylable.call(this, obj, inherits);
3147
+ this.allowedChildren = ['tspan', '#text', '#cdata-section', 'a'];
3148
+ this.isText = true;
3149
+ this.getBoundingShape = function () {
3150
+ let shape = new SvgShape();
3151
+ for (let i = 0; i < this._pos.length; i++) {
3152
+ let pos = this._pos[i];
3153
+ if (!pos.hidden) {
3154
+ let dx0 = pos.ascent * Math.sin(pos.rotate),
3155
+ dy0 = -pos.ascent * Math.cos(pos.rotate),
3156
+ dx1 = pos.descent * Math.sin(pos.rotate),
3157
+ dy1 = -pos.descent * Math.cos(pos.rotate),
3158
+ dx2 = pos.width * Math.cos(pos.rotate),
3159
+ dy2 = pos.width * Math.sin(pos.rotate);
3160
+ shape.M(pos.x + dx0, pos.y + dy0).L(pos.x + dx0 + dx2, pos.y + dy0 + dy2).M(pos.x + dx1 + dx2, pos.y + dy1 + dy2).L(pos.x + dx1, pos.y + dy1);
3161
+ }
3162
+ }
3163
+ return shape;
3164
+ };
3165
+ this.drawTextInDocument = function (isClip, isMask) {
3166
+ if (this.link && !isClip && !isMask) {
3167
+ this.addLink();
3168
+ }
3169
+ if (this.get('text-decoration') === 'underline') {
3170
+ this.decorate(0.05 * this._font.size, -0.075 * this._font.size, isClip, isMask);
3171
+ }
3172
+ if (this.get('text-decoration') === 'overline') {
3173
+ this.decorate(0.05 * this._font.size, getAscent(this._font.font, this._font.size) + 0.075 * this._font.size, isClip, isMask);
3174
+ }
3175
+ let fill = this.getFill(isClip, isMask),
3176
+ stroke = this.getStroke(isClip, isMask),
3177
+ strokeWidth = this.get('stroke-width');
3178
+ if (this._font.fauxBold) {
3179
+ if (!stroke) {
3180
+ stroke = fill;
3181
+ strokeWidth = this._font.size * 0.03;
3182
+ } else {
3183
+ strokeWidth += this._font.size * 0.03;
3184
+ }
3185
+ }
3186
+ let children = this.getChildren();
3187
+ for (let i = 0; i < children.length; i++) {
3188
+ let childElem = children[i];
3189
+ switch (childElem.name) {
3190
+ case 'tspan':
3191
+ case 'textPath':
3192
+ case 'a':
3193
+ if (childElem.get('display') !== 'none') {
3194
+ childElem.drawTextInDocument(isClip, isMask);
3195
+ }
3196
+ break;
3197
+ case '#text':
3198
+ case '#cdata-section':
3199
+ if (this.get('visibility') === 'hidden') {
3200
+ continue;
3201
+ }
3202
+ if (fill || stroke || isClip) {
3203
+ if (fill) {
3204
+ docFillColor(fill);
3205
+ }
3206
+ if (stroke && strokeWidth) {
3207
+ docStrokeColor(stroke);
3208
+ doc.lineWidth(strokeWidth).miterLimit(this.get('stroke-miterlimit')).lineJoin(this.get('stroke-linejoin')).lineCap(this.get('stroke-linecap')).dash(this.get('stroke-dasharray'), {
3209
+ phase: this.get('stroke-dashoffset')
3210
+ });
3211
+ }
3212
+ docBeginText(this._font.font, this._font.size);
3213
+ docSetTextMode(!!fill, !!stroke);
3214
+ docWriteGlyphs(childElem._pos, this._font);
3215
+ docEndText();
3216
+ }
3217
+ break;
3218
+ }
3219
+ }
3220
+ if (this.get('text-decoration') === 'line-through') {
3221
+ this.decorate(0.05 * this._font.size, 0.5 * (getAscent(this._font.font, this._font.size) + getDescent(this._font.font, this._font.size)), isClip, isMask);
3222
+ }
3223
+ };
3224
+ this.decorate = function (lineWidth, linePosition, isClip, isMask) {
3225
+ let fill = this.getFill(isClip, isMask),
3226
+ stroke = this.getStroke(isClip, isMask);
3227
+ if (fill) {
3228
+ docFillColor(fill);
3229
+ }
3230
+ if (stroke) {
3231
+ docStrokeColor(stroke);
3232
+ doc.lineWidth(this.get('stroke-width')).miterLimit(this.get('stroke-miterlimit')).lineJoin(this.get('stroke-linejoin')).lineCap(this.get('stroke-linecap')).dash(this.get('stroke-dasharray'), {
3233
+ phase: this.get('stroke-dashoffset')
3234
+ });
3235
+ }
3236
+ for (let j = 0, pos = this._pos; j < pos.length; j++) {
3237
+ if (!pos[j].hidden && isNotEqual(pos[j].width, 0)) {
3238
+ let dx0 = (linePosition + lineWidth / 2) * Math.sin(pos[j].rotate),
3239
+ dy0 = -(linePosition + lineWidth / 2) * Math.cos(pos[j].rotate),
3240
+ dx1 = (linePosition - lineWidth / 2) * Math.sin(pos[j].rotate),
3241
+ dy1 = -(linePosition - lineWidth / 2) * Math.cos(pos[j].rotate),
3242
+ dx2 = pos[j].width * Math.cos(pos[j].rotate),
3243
+ dy2 = pos[j].width * Math.sin(pos[j].rotate);
3244
+ new SvgShape().M(pos[j].x + dx0, pos[j].y + dy0).L(pos[j].x + dx0 + dx2, pos[j].y + dy0 + dy2).L(pos[j].x + dx1 + dx2, pos[j].y + dy1 + dy2).L(pos[j].x + dx1, pos[j].y + dy1).Z().insertInDocument();
3245
+ if (fill && stroke) {
3246
+ doc.fillAndStroke();
3247
+ } else if (fill) {
3248
+ doc.fill();
3249
+ } else if (stroke) {
3250
+ doc.stroke();
3251
+ }
3252
+ }
3253
+ }
3254
+ };
3255
+ };
3256
+ var SvgElemTextNode = function (obj) {
3257
+ this.name = obj.nodeName;
3258
+ this.textContent = obj.nodeValue;
3259
+ };
3260
+ var SvgElemTspan = function (obj, inherits) {
3261
+ SvgElemTextContainer.call(this, obj, inherits);
3262
+ };
3263
+ var SvgElemTextPath = function (obj, inherits) {
3264
+ SvgElemTextContainer.call(this, obj, inherits);
3265
+ let temp;
3266
+ if ((temp = this.attr('path')) && temp.trim() !== '') {
3267
+ let pathLength = this.getLength('pathLength', this.getViewport());
3268
+ this.pathObject = new SvgShape().path(temp);
3269
+ this.pathLength = pathLength > 0 ? pathLength : this.pathObject.totalLength;
3270
+ this.pathScale = this.pathObject.totalLength / this.pathLength;
3271
+ } else if ((temp = this.getUrl('href') || this.getUrl('xlink:href')) && temp.nodeName === 'path') {
3272
+ let pathElem = new SvgElemPath(temp, this);
3273
+ this.pathObject = pathElem.shape.clone().transform(pathElem.get('transform'));
3274
+ this.pathLength = this.chooseValue(pathElem.pathLength, this.pathObject.totalLength);
3275
+ this.pathScale = this.pathObject.totalLength / this.pathLength;
3276
+ }
3277
+ };
3278
+ var SvgElemText = function (obj, inherits) {
3279
+ SvgElemTextContainer.call(this, obj, inherits);
3280
+ this.allowedChildren = ['textPath', 'tspan', '#text', '#cdata-section', 'a'];
3281
+ (function (textParentElem) {
3282
+ let processedText = '',
3283
+ remainingText = obj.textContent,
3284
+ textPaths = [],
3285
+ currentChunk = [],
3286
+ currentAnchor,
3287
+ currentDirection,
3288
+ currentX = 0,
3289
+ currentY = 0;
3290
+ function doAnchoring() {
3291
+ if (currentChunk.length) {
3292
+ let last = currentChunk[currentChunk.length - 1];
3293
+ let first = currentChunk[0];
3294
+ let width = last.x + last.width - first.x;
3295
+ let anchordx = {
3296
+ startltr: 0,
3297
+ middleltr: 0.5,
3298
+ endltr: 1,
3299
+ startrtl: 1,
3300
+ middlertl: 0.5,
3301
+ endrtl: 0
3302
+ }[currentAnchor + currentDirection] * width || 0;
3303
+ for (let i = 0; i < currentChunk.length; i++) {
3304
+ currentChunk[i].x -= anchordx;
3305
+ }
3306
+ }
3307
+ currentChunk = [];
3308
+ }
3309
+ function adjustLength(pos, length, spacingAndGlyphs) {
3310
+ let firstChar = pos[0],
3311
+ lastChar = pos[pos.length - 1],
3312
+ startX = firstChar.x,
3313
+ endX = lastChar.x + lastChar.width;
3314
+ if (spacingAndGlyphs) {
3315
+ let textScale = length / (endX - startX);
3316
+ if (textScale > 0 && textScale < Infinity) {
3317
+ for (let j = 0; j < pos.length; j++) {
3318
+ pos[j].continuous = false;
3319
+ pos[j].x = startX + textScale * (pos[j].x - startX);
3320
+ pos[j].scale *= textScale;
3321
+ pos[j].width *= textScale;
3322
+ }
3323
+ }
3324
+ } else {
3325
+ if (pos.length >= 2) {
3326
+ let spaceDiff = (length - (endX - startX)) / (pos.length - 1);
3327
+ for (let j = 0; j < pos.length; j++) {
3328
+ pos[j].continuous = false;
3329
+ pos[j].x += j * spaceDiff;
3330
+ }
3331
+ }
3332
+ }
3333
+ currentX += length - (endX - startX);
3334
+ }
3335
+ function recursive(currentElem, parentElem) {
3336
+ currentElem._x = combineArrays(currentElem.getLengthList('x', currentElem.getVWidth()), parentElem ? parentElem._x.slice(parentElem._pos.length) : []);
3337
+ currentElem._y = combineArrays(currentElem.getLengthList('y', currentElem.getVHeight()), parentElem ? parentElem._y.slice(parentElem._pos.length) : []);
3338
+ currentElem._dx = combineArrays(currentElem.getLengthList('dx', currentElem.getVWidth()), parentElem ? parentElem._dx.slice(parentElem._pos.length) : []);
3339
+ currentElem._dy = combineArrays(currentElem.getLengthList('dy', currentElem.getVHeight()), parentElem ? parentElem._dy.slice(parentElem._pos.length) : []);
3340
+ currentElem._rot = combineArrays(currentElem.getNumberList('rotate'), parentElem ? parentElem._rot.slice(parentElem._pos.length) : []);
3341
+ currentElem._defRot = currentElem.chooseValue(currentElem._rot[currentElem._rot.length - 1], parentElem && parentElem._defRot, 0);
3342
+ if (currentElem.name === 'textPath') {
3343
+ currentElem._y = [];
3344
+ }
3345
+ let fontOptions = {
3346
+ fauxItalic: false,
3347
+ fauxBold: false
3348
+ },
3349
+ fontNameorLink = fontCallback(currentElem.get('font-family'), currentElem.get('font-weight') === 'bold', currentElem.get('font-style') === 'italic', fontOptions);
3350
+ try {
3351
+ doc.font(fontNameorLink);
3352
+ } catch (e) {
3353
+ warningCallback('SVGElemText: failed to open font "' + fontNameorLink + '" in PDFKit', e);
3354
+ }
3355
+ currentElem._pos = [];
3356
+ currentElem._index = 0;
3357
+ currentElem._font = {
3358
+ font: doc._font,
3359
+ size: currentElem.get('font-size'),
3360
+ fauxItalic: fontOptions.fauxItalic,
3361
+ fauxBold: fontOptions.fauxBold
3362
+ };
3363
+ let textLength = currentElem.getLength('textLength', currentElem.getVWidth(), undefined),
3364
+ spacingAndGlyphs = currentElem.attr('lengthAdjust') === 'spacingAndGlyphs',
3365
+ wordSpacing = currentElem.get('word-spacing'),
3366
+ letterSpacing = currentElem.get('letter-spacing'),
3367
+ textAnchor = currentElem.get('text-anchor'),
3368
+ textDirection = currentElem.get('direction'),
3369
+ baseline = getBaseline(currentElem._font.font, currentElem._font.size, currentElem.get('alignment-baseline') || currentElem.get('dominant-baseline'), currentElem.get('baseline-shift'));
3370
+ if (currentElem.name === 'textPath') {
3371
+ doAnchoring();
3372
+ currentX = currentY = 0;
3373
+ }
3374
+ let children = currentElem.getChildren();
3375
+ for (let i = 0; i < children.length; i++) {
3376
+ let childElem = children[i];
3377
+ switch (childElem.name) {
3378
+ case 'tspan':
3379
+ case 'textPath':
3380
+ case 'a':
3381
+ recursive(childElem, currentElem);
3382
+ break;
3383
+ case '#text':
3384
+ case '#cdata-section':
3385
+ {
3386
+ let rawText = childElem.textContent,
3387
+ renderedText = rawText,
3388
+ words;
3389
+ childElem._font = currentElem._font;
3390
+ childElem._pos = [];
3391
+ remainingText = remainingText.substring(rawText.length);
3392
+ if (currentElem.get('xml:space') === 'preserve') {
3393
+ renderedText = renderedText.replace(/[\s]/g, ' ');
3394
+ } else {
3395
+ renderedText = renderedText.replace(/[\s]+/g, ' ');
3396
+ if (processedText.match(/[\s]$|^$/)) {
3397
+ renderedText = renderedText.replace(/^[\s]/, '');
3398
+ }
3399
+ if (remainingText.match(/^[\s]*$/)) {
3400
+ renderedText = renderedText.replace(/[\s]$/, '');
3401
+ }
3402
+ }
3403
+ processedText += rawText;
3404
+ if (wordSpacing === 0) {
3405
+ words = [renderedText];
3406
+ } else {
3407
+ words = renderedText.split(/(\s)/);
3408
+ }
3409
+ for (let w = 0; w < words.length; w++) {
3410
+ let pos = getTextPos(currentElem._font.font, currentElem._font.size, words[w]);
3411
+ for (let j = 0; j < pos.length; j++) {
3412
+ let index = currentElem._index,
3413
+ xAttr = currentElem._x[index],
3414
+ yAttr = currentElem._y[index],
3415
+ dxAttr = currentElem._dx[index],
3416
+ dyAttr = currentElem._dy[index],
3417
+ rotAttr = currentElem._rot[index],
3418
+ continuous = !(w === 0 && j === 0);
3419
+ if (letterSpacing !== 0) {
3420
+ continuous = false;
3421
+ }
3422
+ if (wordSpacing !== 0) {
3423
+ continuous = false;
3424
+ }
3425
+ if (xAttr !== undefined) {
3426
+ continuous = false;
3427
+ doAnchoring();
3428
+ currentX = xAttr;
3429
+ }
3430
+ if (yAttr !== undefined) {
3431
+ continuous = false;
3432
+ doAnchoring();
3433
+ currentY = yAttr;
3434
+ }
3435
+ if (dxAttr !== undefined) {
3436
+ continuous = false;
3437
+ currentX += dxAttr;
3438
+ }
3439
+ if (dyAttr !== undefined) {
3440
+ continuous = false;
3441
+ currentY += dyAttr;
3442
+ }
3443
+ if (rotAttr !== undefined || currentElem._defRot !== 0) {
3444
+ continuous = false;
3445
+ }
3446
+ let position = {
3447
+ glyph: pos[j].glyph,
3448
+ rotate: Math.PI / 180 * currentElem.chooseValue(rotAttr, currentElem._defRot),
3449
+ x: currentX + pos[j].xOffset,
3450
+ kern: pos[j].kern,
3451
+ y: currentY + baseline + pos[j].yOffset,
3452
+ width: pos[j].width,
3453
+ ascent: getAscent(currentElem._font.font, currentElem._font.size),
3454
+ descent: getDescent(currentElem._font.font, currentElem._font.size),
3455
+ scale: 1,
3456
+ hidden: false,
3457
+ continuous: continuous
3458
+ };
3459
+ currentChunk.push(position);
3460
+ childElem._pos.push(position);
3461
+ currentElem._pos.push(position);
3462
+ currentElem._index += pos[j].unicode.length;
3463
+ if (currentChunk.length === 1) {
3464
+ currentAnchor = textAnchor;
3465
+ currentDirection = textDirection;
3466
+ }
3467
+ currentX += pos[j].xAdvance + letterSpacing;
3468
+ currentY += pos[j].yAdvance;
3469
+ }
3470
+ if (words[w] === ' ') {
3471
+ currentX += wordSpacing;
3472
+ }
3473
+ }
3474
+ break;
3475
+ }
3476
+ default:
3477
+ remainingText = remainingText.substring(childElem.textContent.length);
3478
+ }
3479
+ }
3480
+ if (textLength && currentElem._pos.length) {
3481
+ adjustLength(currentElem._pos, textLength, spacingAndGlyphs);
3482
+ }
3483
+ if (currentElem.name === 'textPath' || currentElem.name === 'text') {
3484
+ doAnchoring();
3485
+ }
3486
+ if (currentElem.name === 'textPath') {
3487
+ textPaths.push(currentElem);
3488
+ let pathObject = currentElem.pathObject;
3489
+ if (pathObject) {
3490
+ currentX = pathObject.endPoint[0];
3491
+ currentY = pathObject.endPoint[1];
3492
+ }
3493
+ }
3494
+ if (parentElem) {
3495
+ parentElem._pos = parentElem._pos.concat(currentElem._pos);
3496
+ parentElem._index += currentElem._index;
3497
+ }
3498
+ }
3499
+ function textOnPath(currentElem) {
3500
+ let pathObject = currentElem.pathObject,
3501
+ pathLength = currentElem.pathLength,
3502
+ pathScale = currentElem.pathScale;
3503
+ if (pathObject) {
3504
+ let textOffset = currentElem.getLength('startOffset', pathLength, 0);
3505
+ for (let j = 0; j < currentElem._pos.length; j++) {
3506
+ let charMidX = textOffset + currentElem._pos[j].x + 0.5 * currentElem._pos[j].width;
3507
+ if (charMidX > pathLength || charMidX < 0) {
3508
+ currentElem._pos[j].hidden = true;
3509
+ } else {
3510
+ let pointOnPath = pathObject.getPointAtLength(charMidX * pathScale);
3511
+ if (isNotEqual(pathScale, 1)) {
3512
+ currentElem._pos[j].scale *= pathScale;
3513
+ currentElem._pos[j].width *= pathScale;
3514
+ }
3515
+ currentElem._pos[j].x = pointOnPath[0] - 0.5 * currentElem._pos[j].width * Math.cos(pointOnPath[2]) - currentElem._pos[j].y * Math.sin(pointOnPath[2]);
3516
+ currentElem._pos[j].y = pointOnPath[1] - 0.5 * currentElem._pos[j].width * Math.sin(pointOnPath[2]) + currentElem._pos[j].y * Math.cos(pointOnPath[2]);
3517
+ currentElem._pos[j].rotate = pointOnPath[2] + currentElem._pos[j].rotate;
3518
+ currentElem._pos[j].continuous = false;
3519
+ }
3520
+ }
3521
+ } else {
3522
+ for (let j = 0; j < currentElem._pos.length; j++) {
3523
+ currentElem._pos[j].hidden = true;
3524
+ }
3525
+ }
3526
+ }
3527
+ recursive(textParentElem, null);
3528
+ for (let i = 0; i < textPaths.length; i++) {
3529
+ textOnPath(textPaths[i]);
3530
+ }
3531
+ })(this);
3532
+ this.getTransformation = function () {
3533
+ return this.get('transform');
3534
+ };
3535
+ this.drawInDocument = function (isClip, isMask) {
3536
+ doc.save();
3537
+ this.transform();
3538
+ this.clip();
3539
+ let masked = this.mask(),
3540
+ group;
3541
+ if (masked) {
3542
+ group = docBeginGroup(getPageBBox());
3543
+ }
3544
+ this.drawTextInDocument(isClip, isMask);
3545
+ if (group) {
3546
+ docEndGroup(group);
3547
+ docInsertGroup(group);
3548
+ }
3549
+ doc.restore();
3550
+ };
3551
+ };
3552
+ options = options || {};
3553
+ var pxToPt = options.assumePt ? 1 : 72 / 96,
3554
+ viewportWidth = (options.width || doc.page.width) / pxToPt,
3555
+ viewportHeight = (options.height || doc.page.height) / pxToPt,
3556
+ preserveAspectRatio = options.preserveAspectRatio || null,
3557
+ useCSS = options.useCSS && typeof SVGElement !== 'undefined' && svg instanceof SVGElement && typeof getComputedStyle === 'function',
3558
+ warningCallback = options.warningCallback,
3559
+ fontCallback = options.fontCallback,
3560
+ imageCallback = options.imageCallback,
3561
+ colorCallback = options.colorCallback,
3562
+ documentCallback = options.documentCallback,
3563
+ precision = Math.ceil(Math.max(1, options.precision)) || 3,
3564
+ groupStack = [],
3565
+ documentCache = {},
3566
+ links = [],
3567
+ styleRules = [],
3568
+ colorSpace = 'DeviceRGB';
3569
+ if (doc._activeColorProfile) {
3570
+ colorSpace = doc._activeColorProfile.ref;
3571
+ }
3572
+ if (typeof warningCallback !== 'function') {
3573
+ warningCallback = function (str) {
3574
+ console.warn(str);
3575
+ };
3576
+ }
3577
+ if (typeof fontCallback !== 'function') {
3578
+ fontCallback = function (family, bold, italic, fontOptions) {
3579
+ if (bold && italic) {
3580
+ if (Object.prototype.hasOwnProperty.call(doc._registeredFonts, family + '-BoldItalic')) {
3581
+ return family + '-BoldItalic';
3582
+ } else if (Object.prototype.hasOwnProperty.call(doc._registeredFonts, family + '-Italic')) {
3583
+ fontOptions.fauxBold = true;
3584
+ return family + '-Italic';
3585
+ } else if (Object.prototype.hasOwnProperty.call(doc._registeredFonts, family + '-Bold')) {
3586
+ fontOptions.fauxItalic = true;
3587
+ return family + '-Bold';
3588
+ } else if (Object.prototype.hasOwnProperty.call(doc._registeredFonts, family)) {
3589
+ fontOptions.fauxBold = true;
3590
+ fontOptions.fauxItalic = true;
3591
+ return family;
3592
+ }
3593
+ }
3594
+ if (bold && !italic) {
3595
+ if (Object.prototype.hasOwnProperty.call(doc._registeredFonts, family + '-Bold')) {
3596
+ return family + '-Bold';
3597
+ } else if (Object.prototype.hasOwnProperty.call(doc._registeredFonts, family)) {
3598
+ fontOptions.fauxBold = true;
3599
+ return family;
3600
+ }
3601
+ }
3602
+ if (!bold && italic) {
3603
+ if (Object.prototype.hasOwnProperty.call(doc._registeredFonts, family + '-Italic')) {
3604
+ return family + '-Italic';
3605
+ } else if (Object.prototype.hasOwnProperty.call(doc._registeredFonts, family)) {
3606
+ fontOptions.fauxItalic = true;
3607
+ return family;
3608
+ }
3609
+ }
3610
+ if (!bold && !italic) {
3611
+ if (Object.prototype.hasOwnProperty.call(doc._registeredFonts, family)) {
3612
+ return family;
3613
+ }
3614
+ }
3615
+ if (family.match(/(?:^|,)\s*serif\s*$/)) {
3616
+ if (bold && italic) {
3617
+ return 'Times-BoldItalic';
3618
+ }
3619
+ if (bold && !italic) {
3620
+ return 'Times-Bold';
3621
+ }
3622
+ if (!bold && italic) {
3623
+ return 'Times-Italic';
3624
+ }
3625
+ if (!bold && !italic) {
3626
+ return 'Times-Roman';
3627
+ }
3628
+ } else if (family.match(/(?:^|,)\s*monospace\s*$/)) {
3629
+ if (bold && italic) {
3630
+ return 'Courier-BoldOblique';
3631
+ }
3632
+ if (bold && !italic) {
3633
+ return 'Courier-Bold';
3634
+ }
3635
+ if (!bold && italic) {
3636
+ return 'Courier-Oblique';
3637
+ }
3638
+ if (!bold && !italic) {
3639
+ return 'Courier';
3640
+ }
3641
+ } else {
3642
+ if (bold && italic) {
3643
+ return 'Helvetica-BoldOblique';
3644
+ }
3645
+ if (bold && !italic) {
3646
+ return 'Helvetica-Bold';
3647
+ }
3648
+ if (!bold && italic) {
3649
+ return 'Helvetica-Oblique';
3650
+ }
3651
+ if (!bold && !italic) {
3652
+ return 'Helvetica';
3653
+ }
3654
+ }
3655
+ };
3656
+ }
3657
+ if (typeof imageCallback !== 'function') {
3658
+ imageCallback = function (link) {
3659
+ return {
3660
+ src: link.trim()
3661
+ };
3662
+ };
3663
+ }
3664
+ if (typeof colorCallback !== 'function') {
3665
+ colorCallback = null;
3666
+ } else {
3667
+ for (let color in DefaultColors) {
3668
+ let newColor = colorCallback(DefaultColors[color], color);
3669
+ DefaultColors[color][0] = newColor[0];
3670
+ DefaultColors[color][1] = newColor[1];
3671
+ }
3672
+ }
3673
+ if (typeof documentCallback !== 'function') {
3674
+ documentCallback = null;
3675
+ }
3676
+ if (typeof svg === 'string') {
3677
+ svg = parseXml(svg);
3678
+ }
3679
+ if (svg) {
3680
+ let styles = svg.getElementsByTagName('style');
3681
+ for (let i = 0; i < styles.length; i++) {
3682
+ styleRules = styleRules.concat(parseStyleSheet(styles[i].textContent));
3683
+ }
3684
+ let elem = createSVGElement(svg, null);
3685
+ if (typeof elem.drawInDocument === 'function') {
3686
+ if (options.useCSS && !useCSS) {
3687
+ warningCallback('SVGtoPDF: useCSS option can only be used for SVG *elements* in compatible browsers');
3688
+ }
3689
+ let savedFillColor = doc._fillColor;
3690
+ doc.save().translate(x || 0, y || 0).scale(pxToPt);
3691
+ elem.drawInDocument();
3692
+ for (let i = 0; i < links.length; i++) {
3693
+ doc.page.annotations.push(links[i]);
3694
+ }
3695
+ doc.restore();
3696
+ doc._fillColor = savedFillColor;
3697
+ } else {
3698
+ warningCallback("SVGtoPDF: this element can't be rendered directly: " + svg.nodeName);
3699
+ }
3700
+ } else {
3701
+ warningCallback('SVGtoPDF: the input does not look like a valid SVG');
3702
+ }
3703
+ }
3704
+
3705
+ export { write_svg as default };
3706
+ //# sourceMappingURL=write_svg.es.js.map