jspdf.src.js
723 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.jsPDF = {})));
}(this, (function (exports) { 'use strict';
/**
* JavaScript Polyfill functions for jsPDF
* Collected from public resources by
* https://github.com/diegocr
*/
(function (global) {
if (typeof global.console !== "object") {
// Console-polyfill. MIT license.
// https://github.com/paulmillr/console-polyfill
// Make it safe to do console.log() always.
global.console = {};
var con = global.console;
var prop, method;
var dummy = function () {};
var properties = ["memory"];
var methods = ("assert,clear,count,debug,dir,dirxml,error,exception,group," + "groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd," + "show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn").split(",");
while (prop = properties.pop()) if (!con[prop]) con[prop] = {};
while (method = methods.pop()) if (!con[method]) con[method] = dummy;
}
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
if (typeof global.btoa === "undefined") {
global.btoa = function (data) {
// discuss at: http://phpjs.org/functions/base64_encode/
// original by: Tyler Akins (http://rumkin.com)
// improved by: Bayron Guevara
// improved by: Thunder.m
// improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// improved by: Rafal Kukawski (http://kukawski.pl)
// bugfixed by: Pellentesque Malesuada
// example 1: base64_encode('Kevin van Zonneveld');
// returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
var o1,
o2,
o3,
h1,
h2,
h3,
h4,
bits,
i = 0,
ac = 0,
enc = "",
tmp_arr = [];
if (!data) {
return data;
}
do {
// pack three octets into four hexets
o1 = data.charCodeAt(i++);
o2 = data.charCodeAt(i++);
o3 = data.charCodeAt(i++);
bits = o1 << 16 | o2 << 8 | o3;
h1 = bits >> 18 & 0x3f;
h2 = bits >> 12 & 0x3f;
h3 = bits >> 6 & 0x3f;
h4 = bits & 0x3f; // use hexets to index into b64, and append result to encoded string
tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
} while (i < data.length);
enc = tmp_arr.join("");
var r = data.length % 3;
return (r ? enc.slice(0, r - 3) : enc) + "===".slice(r || 3);
};
}
if (typeof global.atob === "undefined") {
global.atob = function (data) {
// discuss at: http://phpjs.org/functions/base64_decode/
// original by: Tyler Akins (http://rumkin.com)
// improved by: Thunder.m
// improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// input by: Aman Gupta
// input by: Brett Zamir (http://brett-zamir.me)
// bugfixed by: Onno Marsman
// bugfixed by: Pellentesque Malesuada
// bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
// returns 1: 'Kevin van Zonneveld'
var o1,
o2,
o3,
h1,
h2,
h3,
h4,
bits,
i = 0,
ac = 0,
dec = "",
tmp_arr = [];
if (!data) {
return data;
}
data += "";
do {
// unpack four hexets into three octets using index points in b64
h1 = b64.indexOf(data.charAt(i++));
h2 = b64.indexOf(data.charAt(i++));
h3 = b64.indexOf(data.charAt(i++));
h4 = b64.indexOf(data.charAt(i++));
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
o1 = bits >> 16 & 0xff;
o2 = bits >> 8 & 0xff;
o3 = bits & 0xff;
if (h3 == 64) {
tmp_arr[ac++] = String.fromCharCode(o1);
} else if (h4 == 64) {
tmp_arr[ac++] = String.fromCharCode(o1, o2);
} else {
tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
}
} while (i < data.length);
dec = tmp_arr.join("");
return dec;
};
}
if (!Array.prototype.map) {
Array.prototype.map = function (fun
/*, thisArg */
) {
if (this === void 0 || this === null || typeof fun !== "function") throw new TypeError();
var t = Object(this),
len = t.length >>> 0,
res = new Array(len);
var thisArg = arguments.length > 1 ? arguments[1] : void 0;
for (var i = 0; i < len; i++) {
// NOTE: Absolute correctness would demand Object.defineProperty
// be used. But this method is fairly new, and failure is
// possible only if Object.prototype or Array.prototype
// has a property |i| (very unlikely), so use a less-correct
// but more portable alternative.
if (i in t) res[i] = fun.call(thisArg, t[i], i, t);
}
return res;
};
}
if (!Array.isArray) {
Array.isArray = function (arg) {
return Object.prototype.toString.call(arg) === "[object Array]";
};
}
if (!Array.prototype.forEach) {
Array.prototype.forEach = function (fun, thisArg) {
if (this === void 0 || this === null || typeof fun !== "function") throw new TypeError();
var t = Object(this),
len = t.length >>> 0;
for (var i = 0; i < len; i++) {
if (i in t) fun.call(thisArg, t[i], i, t);
}
};
}
if (!Object.keys) {
Object.keys = function () {
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !{
toString: null
}.propertyIsEnumerable("toString"),
dontEnums = ["toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "constructor"],
dontEnumsLength = dontEnums.length;
return function (obj) {
if (typeof obj !== "object" && (typeof obj !== "function" || obj === null)) {
throw new TypeError();
}
var result = [],
prop,
i;
for (prop in obj) {
if (hasOwnProperty.call(obj, prop)) {
result.push(prop);
}
}
if (hasDontEnumBug) {
for (i = 0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) {
result.push(dontEnums[i]);
}
}
}
return result;
};
}();
}
if (typeof Object.assign != "function") {
Object.assign = function (target) {
if (target == null) {
throw new TypeError("Cannot convert undefined or null to object");
}
target = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source != null) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
}
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, "");
};
}
if (!String.prototype.trimLeft) {
String.prototype.trimLeft = function () {
return this.replace(/^\s+/g, "");
};
}
if (!String.prototype.trimRight) {
String.prototype.trimRight = function () {
return this.replace(/\s+$/g, "");
};
}
})(typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function("return this")()); // `self` is undefined in Firefox for Android content script context
// while `this` is nsIContentFrameMessageManager
// with an attribute `content` that corresponds to the window
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : factory();
})(window, function () {
/**
* @this {Promise}
*/
function finallyConstructor(callback) {
var constructor = this.constructor;
return this.then(function (value) {
return constructor.resolve(callback()).then(function () {
return value;
});
}, function (reason) {
return constructor.resolve(callback()).then(function () {
return constructor.reject(reason);
});
});
} // Store setTimeout reference so promise-polyfill will be unaffected by
// other code modifying setTimeout (like sinon.useFakeTimers())
var setTimeoutFunc = setTimeout;
function noop() {} // Polyfill for Function.prototype.bind
function bind(fn, thisArg) {
return function () {
fn.apply(thisArg, arguments);
};
}
/**
* @constructor
* @param {Function} fn
*/
function Promise(fn) {
if (!(this instanceof Promise)) throw new TypeError('Promises must be constructed via new');
if (typeof fn !== 'function') throw new TypeError('not a function');
/** @type {!number} */
this._state = 0;
/** @type {!boolean} */
this._handled = false;
/** @type {Promise|undefined} */
this._value = undefined;
/** @type {!Array<!Function>} */
this._deferreds = [];
doResolve(fn, this);
}
function handle(self, deferred) {
while (self._state === 3) {
self = self._value;
}
if (self._state === 0) {
self._deferreds.push(deferred);
return;
}
self._handled = true;
Promise._immediateFn(function () {
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
if (cb === null) {
(self._state === 1 ? resolve : reject)(deferred.promise, self._value);
return;
}
var ret;
try {
ret = cb(self._value);
} catch (e) {
reject(deferred.promise, e);
return;
}
resolve(deferred.promise, ret);
});
}
function resolve(self, newValue) {
try {
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.');
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
var then = newValue.then;
if (newValue instanceof Promise) {
self._state = 3;
self._value = newValue;
finale(self);
return;
} else if (typeof then === 'function') {
doResolve(bind(then, newValue), self);
return;
}
}
self._state = 1;
self._value = newValue;
finale(self);
} catch (e) {
reject(self, e);
}
}
function reject(self, newValue) {
self._state = 2;
self._value = newValue;
finale(self);
}
function finale(self) {
if (self._state === 2 && self._deferreds.length === 0) {
Promise._immediateFn(function () {
if (!self._handled) {
Promise._unhandledRejectionFn(self._value);
}
});
}
for (var i = 0, len = self._deferreds.length; i < len; i++) {
handle(self, self._deferreds[i]);
}
self._deferreds = null;
}
/**
* @constructor
*/
function Handler(onFulfilled, onRejected, promise) {
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
this.promise = promise;
}
/**
* Take a potentially misbehaving resolver function and make sure
* onFulfilled and onRejected are only called once.
*
* Makes no guarantees about asynchrony.
*/
function doResolve(fn, self) {
var done = false;
try {
fn(function (value) {
if (done) return;
done = true;
resolve(self, value);
}, function (reason) {
if (done) return;
done = true;
reject(self, reason);
});
} catch (ex) {
if (done) return;
done = true;
reject(self, ex);
}
}
Promise.prototype['catch'] = function (onRejected) {
return this.then(null, onRejected);
};
Promise.prototype.then = function (onFulfilled, onRejected) {
// @ts-ignore
var prom = new this.constructor(noop);
handle(this, new Handler(onFulfilled, onRejected, prom));
return prom;
};
Promise.prototype['finally'] = finallyConstructor;
Promise.all = function (arr) {
return new Promise(function (resolve, reject) {
if (!arr || typeof arr.length === 'undefined') throw new TypeError('Promise.all accepts an array');
var args = Array.prototype.slice.call(arr);
if (args.length === 0) return resolve([]);
var remaining = args.length;
function res(i, val) {
try {
if (val && (typeof val === 'object' || typeof val === 'function')) {
var then = val.then;
if (typeof then === 'function') {
then.call(val, function (val) {
res(i, val);
}, reject);
return;
}
}
args[i] = val;
if (--remaining === 0) {
resolve(args);
}
} catch (ex) {
reject(ex);
}
}
for (var i = 0; i < args.length; i++) {
res(i, args[i]);
}
});
};
Promise.resolve = function (value) {
if (value && typeof value === 'object' && value.constructor === Promise) {
return value;
}
return new Promise(function (resolve) {
resolve(value);
});
};
Promise.reject = function (value) {
return new Promise(function (resolve, reject) {
reject(value);
});
};
Promise.race = function (values) {
return new Promise(function (resolve, reject) {
for (var i = 0, len = values.length; i < len; i++) {
values[i].then(resolve, reject);
}
});
}; // Use polyfill for setImmediate for performance gains
Promise._immediateFn = typeof setImmediate === 'function' && function (fn) {
setImmediate(fn);
} || function (fn) {
setTimeoutFunc(fn, 0);
};
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
if (typeof console !== 'undefined' && console) {
console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console
}
};
/** @suppress {undefinedVars} */
var globalNS = function () {
// the only reliable means to get the global object is
// `Function('return this')()`
// However, this causes CSP violations in Chrome apps.
if (typeof self !== 'undefined') {
return self;
}
if (typeof window !== 'undefined') {
return window;
}
if (typeof global !== 'undefined') {
return global;
}
throw new Error('unable to locate global object');
}();
if (!('Promise' in globalNS)) {
globalNS['Promise'] = Promise;
} else if (!globalNS.Promise.prototype['finally']) {
globalNS.Promise.prototype['finally'] = finallyConstructor;
}
});
function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
/** @license
* jsPDF - PDF Document creation from JavaScript
* Version 2.0.0 Built on 2019-01-22T15:32:38.220Z
* CommitID 0110a2202b
*
* Copyright (c) 2015-2018 yWorks GmbH, http://www.yworks.com
* 2015-2018 Lukas Holländer <lukas.hollaender@yworks.com>, https://github.com/HackbrettXXX
* 2010-2016 James Hall <james@parall.ax>, https://github.com/MrRio/jsPDF
* 2010 Aaron Spike, https://github.com/acspike
* 2012 Willow Systems Corporation, willow-systems.com
* 2012 Pablo Hess, https://github.com/pablohess
* 2012 Florian Jenett, https://github.com/fjenett
* 2013 Warren Weckesser, https://github.com/warrenweckesser
* 2013 Youssef Beddad, https://github.com/lifof
* 2013 Lee Driscoll, https://github.com/lsdriscoll
* 2013 Stefan Slonevskiy, https://github.com/stefslon
* 2013 Jeremy Morel, https://github.com/jmorel
* 2013 Christoph Hartmann, https://github.com/chris-rock
* 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
* 2014 James Makes, https://github.com/dollaruw
* 2014 Diego Casorran, https://github.com/diegocr
* 2014 Steven Spungin, https://github.com/Flamenco
* 2014 Kenneth Glassey, https://github.com/Gavvers
*
* Licensed under the MIT License
*
* Contributor(s):
* siefkenj, ahwolf, rickygu, Midnith, saintclair, eaparango,
* kim3er, mfo, alnorth, Flamenco
*/
/**
* Creates new jsPDF document object instance.
* @name jsPDF
* @class
* @param orientation {string/Object} Orientation of the first page. Possible values are "portrait" or "landscape" (or shortcuts "p" (Default), "l") <br />
* Can also be an options object.
* @param unit {string} Measurement unit to be used when coordinates are specified.<br />
* Possible values are "pt" (points), "mm" (Default), "cm", "in" or "px".
* @param format {string/Array} The format of the first page. Can be <ul><li>a0 - a10</li><li>b0 - b10</li><li>c0 - c10</li><li>c0 - c10</li><li>dl</li><li>letter</li><li>government-letter</li><li>legal</li><li>junior-legal</li><li>ledger</li><li>tabloid</li><li>credit-card</li></ul><br />
* Default is "a4". If you want to use your own format just pass instead of one of the above predefined formats the size as an number-array , e.g. [595.28, 841.89]
* @returns {jsPDF} jsPDF-instance
* @description
* If the first parameter (orientation) is an object, it will be interpreted as an object of named parameters
* ```
* {
* orientation: 'p',
* unit: 'mm',
* format: 'a4',
* hotfixes: [] // an array of hotfix strings to enable
* }
* ```
*/
var jsPDF = function (global) {
var pdfVersion = "1.3",
pageFormats = {
// Size in pt of various paper formats
a0: [2383.94, 3370.39],
a1: [1683.78, 2383.94],
a2: [1190.55, 1683.78],
a3: [841.89, 1190.55],
a4: [595.28, 841.89],
a5: [419.53, 595.28],
a6: [297.64, 419.53],
a7: [209.76, 297.64],
a8: [147.4, 209.76],
a9: [104.88, 147.4],
a10: [73.7, 104.88],
b0: [2834.65, 4008.19],
b1: [2004.09, 2834.65],
b2: [1417.32, 2004.09],
b3: [1000.63, 1417.32],
b4: [708.66, 1000.63],
b5: [498.9, 708.66],
b6: [354.33, 498.9],
b7: [249.45, 354.33],
b8: [175.75, 249.45],
b9: [124.72, 175.75],
b10: [87.87, 124.72],
c0: [2599.37, 3676.54],
c1: [1836.85, 2599.37],
c2: [1298.27, 1836.85],
c3: [918.43, 1298.27],
c4: [649.13, 918.43],
c5: [459.21, 649.13],
c6: [323.15, 459.21],
c7: [229.61, 323.15],
c8: [161.57, 229.61],
c9: [113.39, 161.57],
c10: [79.37, 113.39],
dl: [311.81, 623.62],
letter: [612, 792],
"government-letter": [576, 756],
legal: [612, 1008],
"junior-legal": [576, 360],
ledger: [1224, 792],
tabloid: [792, 1224],
"credit-card": [153, 243]
};
/**
* jsPDF's Internal PubSub Implementation.
* Backward compatible rewritten on 2014 by
* Diego Casorran, https://github.com/diegocr
*
* @class
* @name PubSub
* @ignore
*/
function PubSub(context) {
var topics = {};
this.subscribe = function (topic, callback, once) {
if (typeof callback !== "function") {
return false;
}
if (!topics.hasOwnProperty(topic)) {
topics[topic] = {};
}
var id = Math.random().toString(35);
topics[topic][id] = [callback, !!once];
return id;
};
this.unsubscribe = function (token) {
for (var topic in topics) {
if (topics[topic][token]) {
delete topics[topic][token];
return true;
}
}
return false;
};
this.publish = function (topic) {
if (topics.hasOwnProperty(topic)) {
var args = Array.prototype.slice.call(arguments, 1),
idr = [];
for (var id in topics[topic]) {
var sub = topics[topic][id];
try {
sub[0].apply(context, args);
} catch (ex) {
if (global.console) {
console.error("jsPDF PubSub Error", ex.message, ex);
}
}
if (sub[1]) idr.push(id);
}
if (idr.length) idr.forEach(this.unsubscribe);
}
};
}
/**
* @constructor
* @private
*/
function jsPDF(orientation, unit, format, compressPdf) {
var options = {};
if (_typeof(orientation) === "object") {
options = orientation;
orientation = options.orientation;
unit = options.unit || unit;
format = options.format || format;
compressPdf = options.compress || options.compressPdf || compressPdf;
} // Default options
unit = unit || "mm";
format = format || "a4";
orientation = ("" + (orientation || "P")).toLowerCase();
var format_as_string = ("" + format).toLowerCase(),
compress = !!compressPdf && typeof Uint8Array === "function",
textColor = options.textColor || "0 g",
drawColor = options.drawColor || "0 G",
activeFontSize = options.fontSize || 16,
activeCharSpace = options.charSpace || 0,
R2L = options.R2L || false,
lineHeightProportion = options.lineHeight || 1.15,
lineWidth = options.lineWidth || 0.200025,
// 2mm
fileId = "00000000000000000000000000000000",
objectNumber = 2,
// 'n' Current object number
outToPages = !1,
// switches where out() prints. outToPages true = push to pages obj. outToPages false = doc builder content
offsets = [],
// List of offsets. Activated and reset by buildDocument(). Pupulated by various calls buildDocument makes.
fonts = {},
// collection of font objects, where key is fontKey - a dynamically created label for a given font.
fontmap = {},
// mapping structure fontName > fontStyle > font key - performance layer. See addFont()
activeFontKey,
// will be string representing the KEY of the font as combination of fontName + fontStyle
fontStateStack = [],
//
patterns = {},
// collection of pattern objects
patternMap = {},
// see fonts
gStates = {},
// collection of graphic state objects
gStatesMap = {},
// see fonts
activeGState = null,
k,
// Scale factor
tmp,
page = 0,
currentPage,
pages = [],
pagesContext = [],
// same index as pages and pagedim
pagedim = [],
content = [],
additionalObjects = [],
lineCapID = 0,
lineJoinID = 0,
content_length = 0,
renderTargets = {},
renderTargetMap = {},
renderTargetStack = [],
pageX,
pageY,
pageMatrix,
// only used for FormObjects
pageWidth,
pageHeight,
pageMode,
zoomMode,
layoutMode,
creationDate,
documentProperties = {
title: "",
subject: "",
author: "",
keywords: "",
creator: ""
},
API = {},
ApiMode = {
COMPAT: "compat",
ADVANCED: "advanced"
},
apiMode = ApiMode.COMPAT,
events = new PubSub(API),
hotfixes = options.hotfixes || [],
/////////////////////
// Private functions
/////////////////////
generateColorString = function generateColorString(options) {
var color;
var ch1 = options.ch1;
var ch2 = options.ch2;
var ch3 = options.ch3;
var ch4 = options.ch4;
var precision = options.precision;
var letterArray = options.pdfColorType === "draw" ? ["G", "RG", "K"] : ["g", "rg", "k"];
if (typeof ch1 === "string" && ch1.charAt(0) !== "#") {
var rgbColor = new RGBColor(ch1);
if (rgbColor.ok) {
ch1 = rgbColor.toHex();
}
} //convert short rgb to long form
if (typeof ch1 === "string" && /^#[0-9A-Fa-f]{3}$/.test(ch1)) {
ch1 = "#" + ch1[1] + ch1[1] + ch1[2] + ch1[2] + ch1[3] + ch1[3];
}
if (typeof ch1 === "string" && /^#[0-9A-Fa-f]{6}$/.test(ch1)) {
var hex = parseInt(ch1.substr(1), 16);
ch1 = hex >> 16 & 255;
ch2 = hex >> 8 & 255;
ch3 = hex & 255;
}
if (typeof ch2 === "undefined" || typeof ch4 === "undefined" && ch1 === ch2 && ch2 === ch3) {
// Gray color space.
if (typeof ch1 === "string") {
color = ch1 + " " + letterArray[0];
} else {
switch (options.precision) {
case 2:
color = f2(ch1 / 255) + " " + letterArray[0];
break;
case 3:
default:
color = f3(ch1 / 255) + " " + letterArray[0];
}
}
} else if (typeof ch4 === "undefined" || _typeof(ch4) === "object") {
// assume RGB
if (typeof ch1 === "string") {
color = [ch1, ch2, ch3, letterArray[1]].join(" ");
} else {
switch (options.precision) {
case 2:
color = [f2(ch1 / 255), f2(ch2 / 255), f2(ch3 / 255), letterArray[1]].join(" ");
break;
default:
case 3:
color = [f3(ch1 / 255), f3(ch2 / 255), f3(ch3 / 255), letterArray[1]].join(" ");
}
} // assume RGBA
if (ch4 && ch4.a === 0) {
//TODO Implement transparency.
//WORKAROUND use white for now
color = ["255", "255", "255", letterArray[1]].join(" ");
}
} else {
// assume CMYK
if (typeof ch1 === "string") {
color = [ch1, ch2, ch3, ch4, letterArray[2]].join(" ");
} else {
switch (options.precision) {
case 2:
color = [f2(ch1), f2(ch2), f2(ch3), f2(ch4), letterArray[2]].join(" ");
break;
case 3:
default:
color = [f3(ch1), f3(ch2), f3(ch3), f3(ch4), letterArray[2]].join(" ");
}
}
}
return color;
},
convertDateToPDFDate = function convertDateToPDFDate(parmDate) {
var padd2 = function padd2(number) {
return ("0" + parseInt(number)).slice(-2);
};
var result = "";
var tzoffset = parmDate.getTimezoneOffset(),
tzsign = tzoffset < 0 ? "+" : "-",
tzhour = Math.floor(Math.abs(tzoffset / 60)),
tzmin = Math.abs(tzoffset % 60),
timeZoneString = [tzsign, padd2(tzhour), "'", padd2(tzmin), "'"].join("");
result = ["D:", parmDate.getFullYear(), padd2(parmDate.getMonth() + 1), padd2(parmDate.getDate()), padd2(parmDate.getHours()), padd2(parmDate.getMinutes()), padd2(parmDate.getSeconds()), timeZoneString].join("");
return result;
},
convertPDFDateToDate = function convertPDFDateToDate(parmPDFDate) {
var year = parseInt(parmPDFDate.substr(2, 4), 10);
var month = parseInt(parmPDFDate.substr(6, 2), 10) - 1;
var date = parseInt(parmPDFDate.substr(8, 2), 10);
var hour = parseInt(parmPDFDate.substr(10, 2), 10);
var minutes = parseInt(parmPDFDate.substr(12, 2), 10);
var seconds = parseInt(parmPDFDate.substr(14, 2), 10);
var timeZoneHour = parseInt(parmPDFDate.substr(16, 2), 10);
var timeZoneMinutes = parseInt(parmPDFDate.substr(20, 2), 10);
var resultingDate = new Date(year, month, date, hour, minutes, seconds, 0);
return resultingDate;
},
setCreationDate = function setCreationDate(date) {
var tmpCreationDateString;
var regexPDFCreationDate = /^D:(20[0-2][0-9]|203[0-7]|19[7-9][0-9])(0[0-9]|1[0-2])([0-2][0-9]|3[0-1])(0[0-9]|1[0-9]|2[0-3])(0[0-9]|[1-5][0-9])(0[0-9]|[1-5][0-9])(\+0[0-9]|\+1[0-4]|\-0[0-9]|\-1[0-1])\'(0[0-9]|[1-5][0-9])\'?$/;
if (_typeof(date) === undefined) {
date = new Date();
}
if (_typeof(date) === "object" && Object.prototype.toString.call(date) === "[object Date]") {
tmpCreationDateString = convertDateToPDFDate(date);
} else if (regexPDFCreationDate.test(date)) {
tmpCreationDateString = date;
} else {
tmpCreationDateString = convertDateToPDFDate(new Date());
}
creationDate = tmpCreationDateString;
return creationDate;
},
getCreationDate = function getCreationDate(type) {
var result = creationDate;
if (type === "jsDate") {
result = convertPDFDateToDate(creationDate);
}
return result;
},
setFileId = function setFileId(value) {
value = value || "12345678901234567890123456789012".split("").map(function () {
return "ABCDEF0123456789".charAt(Math.floor(Math.random() * 16));
}).join("");
fileId = value;
return fileId;
},
getFileId = function getFileId() {
return fileId;
},
f2 = function f2(number) {
return number.toFixed(2); // Ie, %.2f
},
f3 = function f3(number) {
return number.toFixed(3); // Ie, %.3f
},
// high precision float
hpf = function hpf(number) {
return number.toFixed(16).replace(/0+$/, "");
},
scaleByK = function scaleByK(coordinate) {
if (apiMode === ApiMode.COMPAT) {
return coordinate * k;
} else if (apiMode === ApiMode.ADVANCED) {
return coordinate;
}
},
transformY = function transformY(y) {
if (apiMode === ApiMode.COMPAT) {
return pageHeight - y;
} else if (apiMode === ApiMode.ADVANCED) {
return y;
}
},
transformScaleY = function transformScaleY(y) {
return scaleByK(transformY(y));
},
padd2Hex = function padd2Hex(hexString) {
var s = "00" + hexString;
return s.substr(s.length - 2);
},
advancedApiModeTrap = function advancedApiModeTrap(methodName) {
if (apiMode !== ApiMode.ADVANCED) {
throw new Error(methodName + " is only available in 'advanced' API mode. " + "You need to call advancedAPI() first.");
}
},
out = function out(string) {
string = typeof string === "string" ? string : string.toString();
if (outToPages) {
/* set by beginPage */
pages[currentPage].push(string);
} else {
// +1 for '\n' that will be used to join 'content'
content_length += string.length + 1;
content.push(string);
}
},
newObject = function newObject() {
// Begin a new object
objectNumber++;
offsets[objectNumber] = content_length;
out(objectNumber + " 0 obj");
return objectNumber;
},
// Does not output the object until after the pages have been output.
// Returns an object containing the objectId and content.
// All pages have been added so the object ID can be estimated to start right after.
// This does not modify the current objectNumber; It must be updated after the newObjects are output.
newAdditionalObject = function newAdditionalObject() {
var objId = pages.length * 2 + 1;
objId += additionalObjects.length;
var obj = {
objId: objId,
content: ""
};
additionalObjects.push(obj);
return obj;
},
// Does not output the object. The caller must call newObjectDeferredBegin(oid) before outputing any data
newObjectDeferred = function newObjectDeferred() {
objectNumber++;
offsets[objectNumber] = function () {
return content_length;
};
return objectNumber;
},
newObjectDeferredBegin = function newObjectDeferredBegin(oid) {
offsets[oid] = content_length;
},
putStream = function putStream(str) {
out("stream");
out(str);
out("endstream");
},
appendBuffer = function appendBuffer(buffer1, buffer2) {
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
tmp.set(new Uint8Array(buffer1), 0);
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
return tmp;
},
putPages = function putPages() {
var n,
p,
arr,
i,
deflater,
adler32,
adler32cs,
wPt,
hPt,
pageObjectNumbers = [];
adler32cs = global.adler32cs || jsPDF.API.adler32cs;
if (compress && typeof adler32cs === "undefined") {
compress = false;
} // outToPages = false as set in endDocument(). out() writes to content.
for (n = 1; n <= page; n++) {
pageObjectNumbers.push(newObject());
wPt = (pageWidth = pagedim[n].width) * k;
hPt = (pageHeight = pagedim[n].height) * k;
out("<</Type /Page");
out("/Parent 1 0 R");
out("/Resources 2 0 R");
out("/MediaBox [0 0 " + hpf(wPt) + " " + hpf(hPt) + "]"); // Added for annotation plugin
events.publish("putPage", {
pageNumber: n,
page: pages[n]
});
out("/Contents " + (objectNumber + 1) + " 0 R");
out(">>");
out("endobj"); // Page content
p = pages[n].join("\n");
if (apiMode === ApiMode.ADVANCED) {
// if the user forgot to switch back to COMPAT mode, we must balance the graphics stack again
p += "\nQ";
}
newObject();
if (compress) {
arr = [];
i = p.length;
while (i--) {
arr[i] = p.charCodeAt(i);
}
adler32 = adler32cs.from(p);
deflater = new Deflater(6);
p = deflater.append(new Uint8Array(arr));
p = appendBuffer(p, deflater.flush());
arr = new Uint8Array(p.byteLength + 6);
arr.set(new Uint8Array([120, 156]));
arr.set(p, 2);
arr.set(new Uint8Array([adler32 & 0xff, adler32 >> 8 & 0xff, adler32 >> 16 & 0xff, adler32 >> 24 & 0xff]), p.byteLength + 2);
var strings = [],
chunkSize = 0xffff; // There is a maximum stack size. We cannot call String.fromCharCode with as many arguments as we want
for (var j = 0; j * chunkSize < arr.length; j++) {
strings.push(String.fromCharCode.apply(null, arr.subarray(j * chunkSize, (j + 1) * chunkSize)));
}
p = strings.join('');
out("<</Length " + p.length + " /Filter [/FlateDecode]>>");
} else {
out("<</Length " + p.length + ">>");
}
putStream(p);
out("endobj");
}
offsets[1] = content_length;
out("1 0 obj");
out("<</Type /Pages");
var kids = "/Kids [";
for (i = 0; i < page; i++) {
kids += pageObjectNumbers[i] + " 0 R ";
}
out(kids + "]");
out("/Count " + page);
out(">>");
out("endobj");
events.publish("postPutPages");
},
putFont = function putFont(font) {
events.publish("putFont", {
font: font,
out: out,
newObject: newObject,
putStream: putStream
});
if (font.isAlreadyPutted !== true) {
font.objectNumber = newObject();
out("<<");
out("/Type /Font");
out("/BaseFont /" + font.postScriptName);
out("/Subtype /Type1");
if (typeof font.encoding === "string") {
out("/Encoding /" + font.encoding);
}
out("/FirstChar 32");
out("/LastChar 255");
out(">>");
out("endobj");
}
},
putFonts = function putFonts() {
for (var fontKey in fonts) {
if (fonts.hasOwnProperty(fontKey)) {
putFont(fonts[fontKey]);
}
}
},
putXObject = function putXObject(xObject) {
xObject.objectNumber = newObject();
out("<<");
out("/Type /XObject");
out("/Subtype /Form");
out("/BBox [" + [hpf(xObject.x), hpf(xObject.y), hpf(xObject.x + xObject.width), hpf(xObject.y + xObject.height)].join(" ") + "]");
out("/Matrix [" + xObject.matrix.toString() + "]"); // TODO: /Resources
var p = xObject.pages[1].join("\n");
out("/Length " + p.length);
out(">>");
putStream(p);
out("endobj");
},
putXObjects = function putXObjects() {
for (var xObjectKey in renderTargets) {
if (renderTargets.hasOwnProperty(xObjectKey)) {
putXObject(renderTargets[xObjectKey]);
}
}
},
interpolateAndEncodeRGBStream = function interpolateAndEncodeRGBStream(colors, numberSamples) {
var tValues = [];
var t;
var dT = 1.0 / (numberSamples - 1);
for (t = 0.0; t < 1.0; t += dT) {
tValues.push(t);
}
tValues.push(1.0); // add first and last control point if not present
if (colors[0].offset != 0.0) {
var c0 = {
offset: 0.0,
color: colors[0].color
};
colors.unshift(c0);
}
if (colors[colors.length - 1].offset != 1.0) {
var c1 = {
offset: 1.0,
color: colors[colors.length - 1].color
};
colors.push(c1);
}
var out = "";
var index = 0;
for (var i = 0; i < tValues.length; i++) {
t = tValues[i];
while (t > colors[index + 1].offset) {
index++;
}
var a = colors[index].offset;
var b = colors[index + 1].offset;
var d = (t - a) / (b - a);
var aColor = colors[index].color;
var bColor = colors[index + 1].color;
out += padd2Hex(Math.round((1 - d) * aColor[0] + d * bColor[0]).toString(16)) + padd2Hex(Math.round((1 - d) * aColor[1] + d * bColor[1]).toString(16)) + padd2Hex(Math.round((1 - d) * aColor[2] + d * bColor[2]).toString(16));
}
return out.trim();
},
putShadingPattern = function putShadingPattern(pattern, numberSamples) {
/*
Axial patterns shade between the two points specified in coords, radial patterns between the inner
and outer circle.
The user can specify an array (colors) that maps t-Values in [0, 1] to RGB colors. These are now
interpolated to equidistant samples and written to pdf as a sample (type 0) function.
*/
// The number of color samples that should be used to describe the shading.
// The higher, the more accurate the gradient will be.
numberSamples || (numberSamples = 21);
var funcObjectNumber = newObject();
var stream = interpolateAndEncodeRGBStream(pattern.colors, numberSamples);
out("<< /FunctionType 0");
out("/Domain [0.0 1.0]");
out("/Size [" + numberSamples + "]");
out("/BitsPerSample 8");
out("/Range [0.0 1.0 0.0 1.0 0.0 1.0]");
out("/Decode [0.0 1.0 0.0 1.0 0.0 1.0]");
out("/Length " + stream.length); // The stream is Hex encoded
out("/Filter /ASCIIHexDecode");
out(">>");
putStream(stream);
out("endobj");
pattern.objectNumber = newObject();
out("<< /ShadingType " + pattern.type);
out("/ColorSpace /DeviceRGB");
var coords = "/Coords [" + hpf(parseFloat(pattern.coords[0])) + " " + // x1
hpf(parseFloat(pattern.coords[1])) + " "; // y1
if (pattern.type === 2) {
// axial
coords += hpf(parseFloat(pattern.coords[2])) + " " + // x2
hpf(parseFloat(pattern.coords[3])); // y2
} else {
// radial
coords += hpf(parseFloat(pattern.coords[2])) + " " + // r1
hpf(parseFloat(pattern.coords[3])) + " " + // x2
hpf(parseFloat(pattern.coords[4])) + " " + // y2
hpf(parseFloat(pattern.coords[5])); // r2
}
coords += "]";
out(coords);
if (pattern.matrix) {
out("/Matrix [" + pattern.matrix.toString() + "]");
}
out("/Function " + funcObjectNumber + " 0 R");
out("/Extend [true true]");
out(">>");
out("endobj");
},
putTilingPattern = function putTilingPattern(pattern) {
var resourcesObjectNumber = newObject();
out("<<");
putResourceDictionary();
out(">>");
out("endobj");
pattern.objectNumber = newObject();
out("<< /Type /Pattern");
out("/PatternType 1"); // tiling pattern
out("/PaintType 1"); // colored tiling pattern
out("/TilingType 1"); // constant spacing
out("/BBox [" + pattern.boundingBox.map(hpf).join(" ") + "]");
out("/XStep " + hpf(pattern.xStep));
out("/YStep " + hpf(pattern.yStep));
out("/Length " + pattern.stream.length);
out("/Resources " + resourcesObjectNumber + " 0 R"); // TODO: resources
pattern.matrix && out("/Matrix [" + pattern.matrix.toString() + "]");
out(">>");
putStream(pattern.stream);
out("endobj");
},
putPatterns = function putPatterns() {
var patternKey;
for (patternKey in patterns) {
if (patterns.hasOwnProperty(patternKey)) {
if (patterns[patternKey] instanceof API.ShadingPattern) {
putShadingPattern(patterns[patternKey]);
} else if (patterns[patternKey] instanceof API.TilingPattern) {
putTilingPattern(patterns[patternKey]);
}
}
}
},
putGState = function putGState(gState) {
gState.objectNumber = newObject();
out("<<");
for (var p in gState) {
switch (p) {
case "opacity":
out("/ca " + f2(gState[p]));
break;
case "stroke-opacity":
out("/CA " + f2(gState[p]));
break;
}
}
out(">>");
out("endobj");
},
putGStates = function putGStates() {
var gStateKey;
for (gStateKey in gStates) {
if (gStates.hasOwnProperty(gStateKey)) {
putGState(gStates[gStateKey]);
}
}
},
putXobjectDict = function putXobjectDict() {
for (var xObjectKey in renderTargets) {
if (renderTargets.hasOwnProperty(xObjectKey) && renderTargets[xObjectKey].objectNumber >= 0) {
out("/" + xObjectKey + " " + renderTargets[xObjectKey].objectNumber + " 0 R");
}
}
events.publish("putXobjectDict");
},
putShadingPatternDict = function putShadingPatternDict() {
for (var patternKey in patterns) {
if (patterns.hasOwnProperty(patternKey) && patterns[patternKey] instanceof API.ShadingPattern && patterns[patternKey].objectNumber >= 0) {
out("/" + patternKey + " " + patterns[patternKey].objectNumber + " 0 R");
}
}
events.publish("putShadingPatternDict");
},
putTilingPatternDict = function putTilingPatternDict() {
for (var patternKey in patterns) {
if (patterns.hasOwnProperty(patternKey) && patterns[patternKey] instanceof API.TilingPattern && patterns[patternKey].objectNumber >= 0) {
out("/" + patternKey + " " + patterns[patternKey].objectNumber + " 0 R");
}
}
events.publish("putTilingPatternDict");
},
putGStatesDict = function putGStatesDict() {
var gStateKey;
for (gStateKey in gStates) {
if (gStates.hasOwnProperty(gStateKey) && gStates[gStateKey].objectNumber >= 0) {
out("/" + gStateKey + " " + gStates[gStateKey].objectNumber + " 0 R");
}
}
events.publish("putGStateDict");
},
putResourceDictionary = function putResourceDictionary() {
out("/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]");
out("/Font <<"); // Do this for each font, the '1' bit is the index of the font
for (var fontKey in fonts) {
if (fonts.hasOwnProperty(fontKey)) {
out("/" + fontKey + " " + fonts[fontKey].objectNumber + " 0 R");
}
}
out(">>");
out("/Shading <<");
putShadingPatternDict();
out(">>");
out("/Pattern <<");
putTilingPatternDict();
out(">>");
out("/ExtGState <<");
putGStatesDict();
out(">>");
out("/XObject <<");
putXobjectDict();
out(">>");
},
putResources = function putResources() {
putFonts();
putGStates();
putXObjects();
putPatterns();
events.publish("putResources"); // Resource dictionary
offsets[2] = content_length;
out("2 0 obj");
out("<<");
putResourceDictionary();
out(">>");
out("endobj");
events.publish("postPutResources");
},
putAdditionalObjects = function putAdditionalObjects() {
events.publish("putAdditionalObjects");
for (var i = 0; i < additionalObjects.length; i++) {
var obj = additionalObjects[i];
offsets[obj.objId] = content_length;
out(obj.objId + " 0 obj");
out(obj.content);
out("endobj");
}
objectNumber += additionalObjects.length;
events.publish("postPutAdditionalObjects");
},
addToFontDictionary = function addToFontDictionary(fontKey, fontName, fontStyle) {
// this is mapping structure for quick font key lookup.
// returns the KEY of the font (ex: "F1") for a given
// pair of font name and type (ex: "Arial". "Italic")
if (!fontmap.hasOwnProperty(fontName)) {
fontmap[fontName] = {};
}
fontmap[fontName][fontStyle] = fontKey;
},
addFont = function addFont(postScriptName, fontName, fontStyle, encoding, isStandardFont) {
isStandardFont = isStandardFont || false;
var fontKey = "F" + (Object.keys(fonts).length + 1).toString(10),
// This is FontObject
font = {
id: fontKey,
postScriptName: postScriptName,
fontName: fontName,
fontStyle: fontStyle,
encoding: encoding,
isStandardFont: isStandardFont,
metadata: {}
};
var instance = this;
events.publish("addFont", {
font: font,
instance: instance
});
if (fontKey !== undefined) {
fonts[fontKey] = font;
addToFontDictionary(fontKey, fontName, fontStyle);
}
return fontKey;
},
addFonts = function addFonts() {
var HELVETICA = "helvetica",
TIMES = "times",
COURIER = "courier",
NORMAL = "normal",
BOLD = "bold",
ITALIC = "italic",
BOLD_ITALIC = "bolditalic",
ZAPF = "zapfdingbats",
SYMBOL = "symbol",
standardFonts = [["Helvetica", HELVETICA, NORMAL, "WinAnsiEncoding"], ["Helvetica-Bold", HELVETICA, BOLD, "WinAnsiEncoding"], ["Helvetica-Oblique", HELVETICA, ITALIC, "WinAnsiEncoding"], ["Helvetica-BoldOblique", HELVETICA, BOLD_ITALIC, "WinAnsiEncoding"], ["Courier", COURIER, NORMAL, "WinAnsiEncoding"], ["Courier-Bold", COURIER, BOLD, "WinAnsiEncoding"], ["Courier-Oblique", COURIER, ITALIC, "WinAnsiEncoding"], ["Courier-BoldOblique", COURIER, BOLD_ITALIC, "WinAnsiEncoding"], ["Times-Roman", TIMES, NORMAL, "WinAnsiEncoding"], ["Times-Bold", TIMES, BOLD, "WinAnsiEncoding"], ["Times-Italic", TIMES, ITALIC, "WinAnsiEncoding"], ["Times-BoldItalic", TIMES, BOLD_ITALIC, "WinAnsiEncoding"], ["ZapfDingbats", ZAPF, NORMAL, null], ["Symbol", SYMBOL, NORMAL, null]];
for (var i = 0, l = standardFonts.length; i < l; i++) {
var fontKey = addFont(standardFonts[i][0], standardFonts[i][1], standardFonts[i][2], standardFonts[i][3], true); // adding aliases for standard fonts, this time matching the capitalization
var parts = standardFonts[i][0].split("-");
addToFontDictionary(fontKey, parts[0], parts[1] || "");
}
events.publish("addFonts", {
fonts: fonts,
dictionary: fontmap
});
},
matrixMult = function matrixMult(m1, m2) {
return new Matrix(m1.a * m2.a + m1.b * m2.c, m1.a * m2.b + m1.b * m2.d, m1.c * m2.a + m1.d * m2.c, m1.c * m2.b + m1.d * m2.d, m1.e * m2.a + m1.f * m2.c + m2.e, m1.e * m2.b + m1.f * m2.d + m2.f);
},
Matrix = function Matrix(a, b, c, d, e, f) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
this.f = f;
};
Matrix.prototype = {
toString: function toString() {
return [hpf(this.a), hpf(this.b), hpf(this.c), hpf(this.d), hpf(this.e), hpf(this.f)].join(" ");
},
inversed: function inversed() {
var a = this.a,
b = this.b,
c = this.c,
d = this.d,
e = this.e,
f = this.f;
var quot = 1 / (a * d - b * c);
var aInv = d * quot;
var bInv = -b * quot;
var cInv = -c * quot;
var dInv = a * quot;
var eInv = -aInv * e - cInv * f;
var fInv = -bInv * e - dInv * f;
return new Matrix(aInv, bInv, cInv, dInv, eInv, fInv);
}
};
var unitMatrix = new Matrix(1, 0, 0, 1, 0, 0),
// Used (1) to save the current stream state to the XObjects stack and (2) to save completed form
// objects in the xObjects map.
RenderTarget = function RenderTarget() {
this.page = page;
this.currentPage = currentPage;
this.pages = pages.slice(0);
this.pagedim = pagedim.slice(0);
this.pagesContext = pagesContext.slice(0);
this.x = pageX;
this.y = pageY;
this.matrix = pageMatrix;
this.width = pageWidth;
this.height = pageHeight;
this.id = ""; // set by endFormObject()
this.objectNumber = -1; // will be set by putXObject()
};
RenderTarget.prototype = {
restore: function restore() {
page = this.page;
currentPage = this.currentPage;
pagesContext = this.pagesContext;
pagedim = this.pagedim;
pages = this.pages;
pageX = this.x;
pageY = this.y;
pageMatrix = this.matrix;
pageWidth = this.width;
pageHeight = this.height;
}
};
var beginNewRenderTarget = function beginNewRenderTarget(x, y, width, height, matrix) {
// save current state
renderTargetStack.push(new RenderTarget()); // clear pages
page = currentPage = 0;
pages = [];
pageX = x;
pageY = y;
pageMatrix = matrix;
beginPage(width, height);
},
endFormObject = function endFormObject(key) {
// only add it if it is not already present (the keys provided by the user must be unique!)
if (renderTargetMap[key]) return; // save the created xObject
var newXObject = new RenderTarget();
var xObjectId = "Xo" + (Object.keys(renderTargets).length + 1).toString(10);
newXObject.id = xObjectId;
renderTargetMap[key] = xObjectId;
renderTargets[xObjectId] = newXObject;
events.publish("addFormObject", newXObject); // restore state from stack
renderTargetStack.pop().restore();
},
/**
* Adds a new pattern for later use.
* @param {String} key The key by it can be referenced later. The keys must be unique!
* @param {API.Pattern} pattern The pattern
*/
addPattern = function addPattern(key, pattern) {
// only add it if it is not already present (the keys provided by the user must be unique!)
if (patternMap[key]) return;
var prefix = pattern instanceof API.ShadingPattern ? "Sh" : "P";
var patternKey = prefix + (Object.keys(patterns).length + 1).toString(10);
pattern.id = patternKey;
patternMap[key] = patternKey;
patterns[patternKey] = pattern;
events.publish("addPattern", pattern);
},
/**
* Adds a new Graphics State. Duplicates are automatically eliminated.
* @param {String} key Might also be null, if no later reference to this gState is needed
* @param {Object} gState The gState object
*/
addGState = function addGState(key, gState) {
// only add it if it is not already present (the keys provided by the user must be unique!)
if (key && gStatesMap[key]) return;
var duplicate = false;
for (var s in gStates) {
if (gStates.hasOwnProperty(s)) {
if (gStates[s].equals(gState)) {
duplicate = true;
break;
}
}
}
if (duplicate) {
gState = gStates[s];
} else {
var gStateKey = "GS" + (Object.keys(gStates).length + 1).toString(10);
gStates[gStateKey] = gState;
gState.id = gStateKey;
} // several user keys may point to the same GState object
key && (gStatesMap[key] = gState.id);
events.publish("addGState", gState);
return gState;
},
SAFE = function __safeCall(fn) {
fn.foo = function __safeCallWrapper() {
try {
return fn.apply(this, arguments);
} catch (e) {
var stack = e.stack || "";
if (~stack.indexOf(" at ")) stack = stack.split(" at ")[1];
var m = "Error in function " + stack.split("\n")[0].split("<")[0] + ": " + e.message;
if (global.console) {
global.console.error(m, e);
if (global.alert) alert(m);
} else {
throw new Error(m);
}
}
};
fn.foo.bar = fn;
return fn.foo;
},
to8bitStream = function to8bitStream(text, flags) {
/**
* PDF 1.3 spec:
* "For text strings encoded in Unicode, the first two bytes must be 254 followed by
* 255, representing the Unicode byte order marker, U+FEFF. (This sequence conflicts
* with the PDFDocEncoding character sequence thorn ydieresis, which is unlikely
* to be a meaningful beginning of a word or phrase.) The remainder of the
* string consists of Unicode character codes, according to the UTF-16 encoding
* specified in the Unicode standard, version 2.0. Commonly used Unicode values
* are represented as 2 bytes per character, with the high-order byte appearing first
* in the string."
*
* In other words, if there are chars in a string with char code above 255, we
* recode the string to UCS2 BE - string doubles in length and BOM is prepended.
*
* HOWEVER!
* Actual *content* (body) text (as opposed to strings used in document properties etc)
* does NOT expect BOM. There, it is treated as a literal GID (Glyph ID)
*
* Because of Adobe's focus on "you subset your fonts!" you are not supposed to have
* a font that maps directly Unicode (UCS2 / UTF16BE) code to font GID, but you could
* fudge it with "Identity-H" encoding and custom CIDtoGID map that mimics Unicode
* code page. There, however, all characters in the stream are treated as GIDs,
* including BOM, which is the reason we need to skip BOM in content text (i.e. that
* that is tied to a font).
*
* To signal this "special" PDFEscape / to8bitStream handling mode,
* API.text() function sets (unless you overwrite it with manual values
* given to API.text(.., flags) )
* flags.autoencode = true
* flags.noBOM = true
*
* ===================================================================================
* `flags` properties relied upon:
* .sourceEncoding = string with encoding label.
* "Unicode" by default. = encoding of the incoming text.
* pass some non-existing encoding name
* (ex: 'Do not touch my strings! I know what I am doing.')
* to make encoding code skip the encoding step.
* .outputEncoding = Either valid PDF encoding name
* (must be supported by jsPDF font metrics, otherwise no encoding)
* or a JS object, where key = sourceCharCode, value = outputCharCode
* missing keys will be treated as: sourceCharCode === outputCharCode
* .noBOM
* See comment higher above for explanation for why this is important
* .autoencode
* See comment higher above for explanation for why this is important
*/
var i, l, sourceEncoding, encodingBlock, outputEncoding, newtext, isUnicode, ch, bch;
flags = flags || {};
sourceEncoding = flags.sourceEncoding || "Unicode";
outputEncoding = flags.outputEncoding; // This 'encoding' section relies on font metrics format
// attached to font objects by, among others,
// "Willow Systems' standard_font_metrics plugin"
// see jspdf.plugin.standard_font_metrics.js for format
// of the font.metadata.encoding Object.
// It should be something like
// .encoding = {'codePages':['WinANSI....'], 'WinANSI...':{code:code, ...}}
// .widths = {0:width, code:width, ..., 'fof':divisor}
// .kerning = {code:{previous_char_code:shift, ..., 'fof':-divisor},...}
if ((flags.autoencode || outputEncoding) && fonts[activeFontKey].metadata && fonts[activeFontKey].metadata[sourceEncoding] && fonts[activeFontKey].metadata[sourceEncoding].encoding) {
encodingBlock = fonts[activeFontKey].metadata[sourceEncoding].encoding; // each font has default encoding. Some have it clearly defined.
if (!outputEncoding && fonts[activeFontKey].encoding) {
outputEncoding = fonts[activeFontKey].encoding;
} // Hmmm, the above did not work? Let's try again, in different place.
if (!outputEncoding && encodingBlock.codePages) {
outputEncoding = encodingBlock.codePages[0]; // let's say, first one is the default
}
if (typeof outputEncoding === "string") {
outputEncoding = encodingBlock[outputEncoding];
} // we want output encoding to be a JS Object, where
// key = sourceEncoding's character code and
// value = outputEncoding's character code.
if (outputEncoding) {
isUnicode = false;
newtext = [];
for (i = 0, l = text.length; i < l; i++) {
ch = outputEncoding[text.charCodeAt(i)];
if (ch) {
newtext.push(String.fromCharCode(ch));
} else {
newtext.push(text[i]);
} // since we are looping over chars anyway, might as well
// check for residual unicodeness
if (newtext[i].charCodeAt(0) >> 8) {
/* more than 255 */
isUnicode = true;
}
}
text = newtext.join("");
}
}
i = text.length; // isUnicode may be set to false above. Hence the triple-equal to undefined
while (isUnicode === undefined && i !== 0) {
if (text.charCodeAt(i - 1) >> 8) {
/* more than 255 */
isUnicode = true;
}
i--;
}
if (!isUnicode) {
return text;
}
newtext = flags.noBOM ? [] : [254, 255];
for (i = 0, l = text.length; i < l; i++) {
ch = text.charCodeAt(i);
bch = ch >> 8; // divide by 256
if (bch >> 8) {
/* something left after dividing by 256 second time */
throw new Error("Character at position " + i + " of string '" + text + "' exceeds 16bits. Cannot be encoded into UCS-2 BE");
}
newtext.push(bch);
newtext.push(ch - (bch << 8));
}
return String.fromCharCode.apply(undefined, newtext);
},
pdfEscape = function pdfEscape(text, flags) {
/**
* Replace '/', '(', and ')' with pdf-safe versions
*
* Doing to8bitStream does NOT make this PDF display unicode text. For that
* we also need to reference a unicode font and embed it - royal pain in the rear.
*
* There is still a benefit to to8bitStream - PDF simply cannot handle 16bit chars,
* which JavaScript Strings are happy to provide. So, while we still cannot display
* 2-byte characters property, at least CONDITIONALLY converting (entire string containing)
* 16bit chars to (USC-2-BE) 2-bytes per char + BOM streams we ensure that entire PDF
* is still parseable.
* This will allow immediate support for unicode in document properties strings.
*/
return to8bitStream(text, flags).replace(/\\/g, "\\\\").replace(/\(/g, "\\(").replace(/\)/g, "\\)");
},
putInfo = function putInfo() {
out("/Producer (jsPDF " + jsPDF.version + ")");
for (var key in documentProperties) {
if (documentProperties.hasOwnProperty(key) && documentProperties[key]) {
out("/" + key.substr(0, 1).toUpperCase() + key.substr(1) + " (" + pdfEscape(documentProperties[key]) + ")");
}
}
out("/CreationDate (" + creationDate + ")");
},
putCatalog = function putCatalog() {
out("/Type /Catalog");
out("/Pages 1 0 R"); // PDF13ref Section 7.2.1
if (!zoomMode) zoomMode = "fullwidth";
switch (zoomMode) {
case "fullwidth":
out("/OpenAction [3 0 R /FitH null]");
break;
case "fullheight":
out("/OpenAction [3 0 R /FitV null]");
break;
case "fullpage":
out("/OpenAction [3 0 R /Fit]");
break;
case "original":
out("/OpenAction [3 0 R /XYZ null null 1]");
break;
default:
var pcn = "" + zoomMode;
if (pcn.substr(pcn.length - 1) === "%") zoomMode = parseInt(zoomMode) / 100;
if (typeof zoomMode === "number") {
out("/OpenAction [3 0 R /XYZ null null " + f2(zoomMode) + "]");
}
}
if (!layoutMode) layoutMode = "continuous";
switch (layoutMode) {
case "continuous":
out("/PageLayout /OneColumn");
break;
case "single":
out("/PageLayout /SinglePage");
break;
case "two":
case "twoleft":
out("/PageLayout /TwoColumnLeft");
break;
case "tworight":
out("/PageLayout /TwoColumnRight");
break;
}
if (pageMode) {
/**
* A name object specifying how the document should be displayed when opened:
* UseNone : Neither document outline nor thumbnail images visible -- DEFAULT
* UseOutlines : Document outline visible
* UseThumbs : Thumbnail images visible
* FullScreen : Full-screen mode, with no menu bar, window controls, or any other window visible
*/
out("/PageMode /" + pageMode);
}
events.publish("putCatalog");
},
putTrailer = function putTrailer() {
out("/Size " + (objectNumber + 1));
out("/Root " + objectNumber + " 0 R");
out("/Info " + (objectNumber - 1) + " 0 R");
out("/ID [ <" + fileId + "> <" + fileId + "> ]");
},
beginPage = function beginPage(width, height) {
outToPages = true;
pages[++page] = [];
pagedim[page] = {
width: Number(width) || pageWidth,
height: Number(height) || pageHeight
};
pagesContext[page] = {};
_setPage(page);
},
_addPage = function _addPage(width, height) {
// Dimensions are stored as user units and converted to points on output
var orientation = typeof height === "string" && height.toLowerCase();
if (typeof width === "string") {
var format = width.toLowerCase();
if (pageFormats.hasOwnProperty(format)) {
width = pageFormats[format][0] / k;
height = pageFormats[format][1] / k;
}
}
if (Array.isArray(width)) {
height = width[1];
width = width[0];
}
if (orientation) {
switch (orientation.substr(0, 1)) {
case "l":
if (height > width) orientation = "s";
break;
case "p":
if (width > height) orientation = "s";
break;
}
if (orientation === "s") {
tmp = width;
width = height;
height = tmp;
}
}
beginPage(width, height); // Set line width
out(hpf(lineWidth * k) + " w"); // Set draw color
out(drawColor); // resurrecting non-default line caps, joins
if (lineCapID !== 0) {
out(lineCapID + " J");
}
if (lineJoinID !== 0) {
out(lineJoinID + " j");
}
events.publish("addPage", {
pageNumber: page
});
},
_deletePage = function _deletePage(n) {
if (n > 0 && n <= page) {
pages.splice(n, 1);
pagedim.splice(n, 1);
page--;
if (currentPage > page) {
currentPage = page;
}
this.setPage(currentPage);
}
},
_setPage = function _setPage(n) {
if (n > 0 && n <= page) {
currentPage = n;
pageWidth = pagedim[n].width;
pageHeight = pagedim[n].height;
}
},
/**
* Returns a document-specific font key - a label assigned to a
* font name + font type combination at the time the font was added
* to the font inventory.
*
* Font key is used as label for the desired font for a block of text
* to be added to the PDF document stream.
* @private
* @function
* @param {String} fontName can be undefined on "falthy" to indicate "use current"
* @param {String} fontStyle can be undefined on "falthy" to indicate "use current"
* @returns {String} Font key.
*/
_getFont = function getFont(fontName, fontStyle, options) {
var key = undefined,
fontNameLowerCase;
options = options || {};
fontName = fontName !== undefined ? fontName : fonts[activeFontKey].fontName;
fontStyle = fontStyle !== undefined ? fontStyle : fonts[activeFontKey].fontStyle;
fontNameLowerCase = fontName.toLowerCase();
if (fontmap[fontNameLowerCase] !== undefined && fontmap[fontNameLowerCase][fontStyle] !== undefined) {
key = fontmap[fontNameLowerCase][fontStyle];
} else if (fontmap[fontName] !== undefined && fontmap[fontName][fontStyle] !== undefined) {
key = fontmap[fontName][fontStyle];
} else {
if (options.disableWarning === false) {
console.warn("Unable to look up font label for font '" + fontName + "', '" + fontStyle + "'. Refer to getFontList() for available fonts.");
}
}
if (!key && !options.noFallback) {
key = fontmap["times"][fontStyle];
if (key == null) {
key = fontmap["times"]["normal"];
}
}
return key;
},
buildDocument = function buildDocument() {
outToPages = false; // switches out() to content
objectNumber = 2;
content_length = 0;
content = [];
offsets = [];
additionalObjects = []; // Added for AcroForm
events.publish("buildDocument"); // putHeader()
out("%PDF-" + pdfVersion);
out("%\xBA\xDF\xAC\xE0");
putPages(); // Must happen after putPages
// Modifies current object Id
putAdditionalObjects();
putResources(); // Info
newObject();
out("<<");
putInfo();
out(">>");
out("endobj"); // Catalog
newObject();
out("<<");
putCatalog();
out(">>");
out("endobj"); // Cross-ref
var o = content_length,
i,
p = "0000000000";
out("xref");
out("0 " + (objectNumber + 1));
out(p + " 65535 f ");
for (i = 1; i <= objectNumber; i++) {
var offset = offsets[i];
if (typeof offset === "function") {
out((p + offsets[i]()).slice(-10) + " 00000 n ");
} else {
out((p + offsets[i]).slice(-10) + " 00000 n ");
}
} // Trailer
out("trailer");
out("<<");
putTrailer();
out(">>");
out("startxref");
out("" + o);
out("%%EOF");
outToPages = true;
return content.join("\n");
},
getStyle = function getStyle(style) {
// see path-painting operators in PDF spec
// The default in MrRio's implementation is "S" (stroke), whereas the default in the yWorks implementation
// was "n" (none). Although this has nothing to do with transforms, we should use the API switch here.
var op = apiMode === ApiMode.COMPAT ? "S" : "n";
if (style === "D") {
op = "S"; // stroke
} else if (style === "F") {
op = "f"; // fill
} else if (style === "FD" || style === "DF") {
op = "B"; // both
} else if (style === "f" || style === "f*" || style === "B" || style === "B*") {
/*
Allow direct use of these PDF path-painting operators:
- f fill using nonzero winding number rule
- f* fill using even-odd rule
- B fill then stroke with fill using non-zero winding number rule
- B* fill then stroke with fill using even-odd rule
*/
op = style;
}
return op;
},
// puts the style for the previously drawn path. If a patternKey is provided, the pattern is used to fill
// the path. Use patternMatrix to transform the pattern to rhe right location.
putStyle = function putStyle(style, patternKey, patternData) {
if (style === null || apiMode === ApiMode.ADVANCED && style === undefined) {
return;
}
style = getStyle(style); // stroking / filling / both the path
if (!patternKey) {
out(style);
return;
}
if (!patternData) {
patternData = {
matrix: unitMatrix
};
}
if (patternData instanceof Matrix) {
patternData = {
matrix: patternData
};
}
patternData.key = patternKey;
patternData || (patternData = unitMatrix);
fillWithPattern(patternData, style);
},
fillWithPattern = function fillWithPattern(patternData, style) {
var patternId = patternMap[patternData.key];
var pattern = patterns[patternId];
if (pattern instanceof API.ShadingPattern) {
out("q");
out(clipRuleFromStyle(style));
if (pattern.gState) {
API.setGState(pattern.gState);
}
out(patternData.matrix.toString() + " cm");
out("/" + patternId + " sh");
out("Q");
} else if (pattern instanceof API.TilingPattern) {
// pdf draws patterns starting at the bottom left corner and they are not affected by the global transformation,
// so we must flip them
var matrix = new Matrix(1, 0, 0, -1, 0, pageHeight);
if (patternData.matrix) {
matrix = matrixMult(patternData.matrix || unitMatrix, matrix); // we cannot apply a matrix to the pattern on use so we must abuse the pattern matrix and create new instances
// for each use
patternId = pattern.createClone(patternData.key, patternData.boundingBox, patternData.xStep, patternData.yStep, matrix).id;
}
out("q");
out("/Pattern cs");
out("/" + patternId + " scn");
if (pattern.gState) {
API.setGState(pattern.gState);
}
out(style);
out("Q");
}
},
clipRuleFromStyle = function clipRuleFromStyle(style) {
switch (style) {
case "f":
case "F":
return "W n";
case "f*":
return "W* n";
case "B":
return "W S";
case "B*":
return "W* S";
// these two are for compatibility reasons (in the past, calling any primitive method with a shading pattern
// and "n"/"S" as style would still fill/fill and stroke the path)
case "S":
return "W S";
case "n":
return "W n";
}
},
getArrayBuffer = function getArrayBuffer() {
var data = buildDocument(),
len = data.length,
ab = new ArrayBuffer(len),
u8 = new Uint8Array(ab);
while (len--) {
u8[len] = data.charCodeAt(len);
}
return ab;
},
getBlob = function getBlob() {
return new Blob([getArrayBuffer()], {
type: "application/pdf"
});
},
_output = SAFE(function (type, options) {
if (typeof options === "string") {
options = {
filename: options
};
} else {
options = options || {};
options.filename = options.filename || "generated.pdf";
}
var datauri = ("" + type).substr(0, 6) === "dataur" ? "data:application/pdf;filename=" + options.filename + ";base64," + btoa(buildDocument()) : 0;
switch (type) {
case undefined:
return buildDocument();
case "save":
if ((typeof navigator === "undefined" ? "undefined" : _typeof(navigator)) === "object" && navigator.getUserMedia) {
if (global.URL === undefined || global.URL.createObjectURL === undefined) {
return API.output("dataurlnewwindow");
}
}
saveAs(getBlob(), options.filename);
if (typeof saveAs.unload === "function") {
if (global.setTimeout) {
setTimeout(saveAs.unload, 911);
}
}
break;
case "arraybuffer":
return getArrayBuffer();
case "blob":
return getBlob();
case "bloburi":
case "bloburl":
// User is responsible of calling revokeObjectURL
return global.URL && global.URL.createObjectURL(getBlob()) || void 0;
case "datauristring":
case "dataurlstring":
return datauri;
case "dataurlnewwindow":
var htmlForNewWindow = "<html>" + "<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;} </style>" + "<body>" + '<iframe src="' + this.output("datauristring") + '"></iframe>' + "</body></html>";
var nW = global.open();
if (nW !== null) {
nW.document.write(htmlForNewWindow);
}
if (nW || typeof safari === "undefined") return nW;
/* pass through */
case "datauri":
case "dataurl":
return global.document.location.href = datauri;
default:
throw new Error('Output type "' + type + '" is not supported.');
} // @TODO: Add different output options
}),
/**
* Used to see if a supplied hotfix was requested when the pdf instance was created.
* @param {string} hotfixName - The name of the hotfix to check.
* @returns {boolean}
*/
hasHotfix = function hasHotfix(hotfixName) {
return Array.isArray(hotfixes) === true && hotfixes.indexOf(hotfixName) > -1;
};
switch (unit) {
case "pt":
k = 1;
break;
case "mm":
k = 72 / 25.4000508;
break;
case "cm":
k = 72 / 2.54000508;
break;
case "in":
k = 72;
break;
case "px":
if (hasHotfix("px_scaling") == true) {
k = 72 / 96;
} else {
k = 96 / 72;
}
break;
case "pc":
k = 12;
break;
case "em":
k = 12;
break;
case "ex":
k = 6;
break;
default:
throw "Invalid unit: " + unit;
}
setCreationDate();
setFileId(); //---------------------------------------
// Public API
/**
* Object exposing internal API to plugins
* @public
* @ignore
*/
API.internal = {
pdfEscape: pdfEscape,
getStyle: getStyle,
/**
* Returns {FontObject} describing a particular font.
* @public
* @function
* @param {String} fontName (Optional) Font's family name
* @param {String} fontStyle (Optional) Font's style variation name (Example:"Italic")
* @returns {FontObject}
*/
getFont: function getFont() {
return fonts[_getFont.apply(API, arguments)];
},
getFontSize: function getFontSize() {
return activeFontSize;
},
getCharSpace: function getCharSpace() {
return activeCharSpace;
},
getTextColor: function getTextColor() {
var colorEncoded = textColor.split(" ");
if (colorEncoded.length === 2 && colorEncoded[1] === "g") {
// convert grayscale value to rgb so that it can be converted to hex for consistency
var floatVal = parseFloat(colorEncoded[0]);
colorEncoded = [floatVal, floatVal, floatVal, "r"];
}
var colorAsHex = "#";
for (var i = 0; i < 3; i++) {
colorAsHex += ("0" + Math.floor(parseFloat(colorEncoded[i]) * 255).toString(16)).slice(-2);
}
return colorAsHex;
},
getLineHeight: function getLineHeight() {
return activeFontSize * lineHeightProportion;
},
write: function write(string1
/*, string2, string3, etc */
) {
out(arguments.length === 1 ? string1 : Array.prototype.join.call(arguments, " "));
},
getCoordinateString: function getCoordinateString(value) {
return hpf(scaleByK(value));
},
getVerticalCoordinateString: function getVerticalCoordinateString(value) {
return hpf(transformScaleY(value));
},
collections: {},
newObject: newObject,
newAdditionalObject: newAdditionalObject,
newObjectDeferred: newObjectDeferred,
newObjectDeferredBegin: newObjectDeferredBegin,
putStream: putStream,
events: events,
// ratio that you use in multiplication of a given "size" number to arrive to 'point'
// units of measurement.
// scaleFactor is set at initialization of the document and calculated against the stated
// default measurement units for the document.
// If default is "mm", k is the number that will turn number in 'mm' into 'points' number.
// through multiplication.
scaleFactor: k,
pageSize: {
getWidth: function getWidth() {
return pageWidth;
},
getHeight: function getHeight() {
return pageHeight;
}
},
output: function output(type, options) {
return _output(type, options);
},
getNumberOfPages: function getNumberOfPages() {
return pages.length - 1;
},
pages: pages,
out: out,
f2: f2,
getPageInfo: function getPageInfo(pageNumberOneBased) {
var objId = (pageNumberOneBased - 1) * 2 + 3;
return {
objId: objId,
pageNumber: pageNumberOneBased,
pageContext: pagesContext[pageNumberOneBased]
};
},
getCurrentPageInfo: function getCurrentPageInfo() {
var objId = (currentPage - 1) * 2 + 3;
return {
objId: objId,
pageNumber: currentPage,
pageContext: pagesContext[currentPage]
};
},
getPDFVersion: function getPDFVersion() {
return pdfVersion;
},
hasHotfix: hasHotfix //Expose the hasHotfix check so plugins can also check them.
};
function advancedAPI() {
// prepend global change of basis matrix
// (Now, instead of converting every coordinate to the pdf coordinate system, we apply a matrix
// that does this job for us (however, texts, images and similar objects must be drawn bottom up))
this.saveGraphicsState();
out(new Matrix(k, 0, 0, -k, 0, pageHeight * k).toString() + " cm");
this.setFontSize(this.getFontSize() / k);
apiMode = ApiMode.ADVANCED;
}
function compatAPI() {
this.restoreGraphicsState();
apiMode = ApiMode.COMPAT;
}
/**
* @callback ApiSwitchBody
* @param {jsPDF} pdf
*/
/**
* For compatibility reasons jsPDF offers two API modes which differ in the way they convert between the the usual
* screen coordinates and the PDF coordinate system.
* - "compat": Offers full compatibility across all plugins but does not allow arbitrary transforms
* - "advanced": Allows arbitrary transforms and more advanced features like pattern fills. Some plugins might
* not support this mode, though.
* Initial mode is "compat".
*
* You can either provide a callback to the body argument, which means that jsPDF will automatically switch back to
* the original API mode afterwards; or you can omit the callback and switch back manually using {@link compatAPI}.
*
* Note, that the calls to {@link saveGraphicsState} and {@link restoreGraphicsState} need to be balanced within the
* callback or between calls of this method and its counterpart {@link compatAPI}. Calls to {@link beginFormObject}
* or {@link beginTilingPattern} need to be closed by their counterparts before switching back to "compat" API mode.
*
* @param {ApiSwitchBody=} body When provided, this callback will be called after the API mode has been switched.
* The API mode will be switched back automatically afterwards.
* @returns {jsPDF}
* @methodOf jsPDF#
* @name advancedAPI
*/
API.advancedAPI = function (body) {
var doSwitch = apiMode === ApiMode.COMPAT;
if (doSwitch) {
advancedAPI.call(this);
}
if (typeof body !== "function") {
return this;
}
body(this);
if (doSwitch) {
compatAPI.call(this);
}
return this;
};
/**
* Switches to "compat" API mode. See {@link advancedAPI} for more details.
*
* @param {ApiSwitchBody=} body When provided, this callback will be called after the API mode has been switched.
* The API mode will be switched back automatically afterwards.
* @return {jsPDF}
* @methodOf jsPDF#
* @name compatApi
*/
API.compatAPI = function (body) {
var doSwitch = apiMode === ApiMode.ADVANCED;
if (doSwitch) {
compatAPI.call(this);
}
if (typeof body !== "function") {
return this;
}
body(this);
if (doSwitch) {
advancedAPI.call(this);
}
return this;
};
/**
* @return {boolean} True iff the current API mode is "advanced". See {@link advancedAPI}.
* @methodOf jsPDF#
* @name isAdvancedAPI
*/
API.isAdvancedAPI = function () {
return apiMode === ApiMode.ADVANCED;
};
/**
* Inserts a debug comment into the pdf.
* @param {String} text
* @returns {jsPDF}
* @methodOf jsPDF#
* @name comment
*/
API.comment = function (text) {
out("#" + text);
return this;
};
/**
* An object representing a pdf graphics state.
* @param parameters A parameter object that contains all properties this graphics state wants to set.
* Supported are: opacity, stroke-opacity
* @constructor
*/
API.GState = function (parameters) {
var supported = "opacity,stroke-opacity".split(",");
for (var p in parameters) {
if (parameters.hasOwnProperty(p) && supported.indexOf(p) >= 0) {
this[p] = parameters[p];
}
}
this.id = ""; // set by addGState()
this.objectNumber = -1; // will be set by putGState()
};
API.GState.prototype.equals = function equals(other) {
var ignore = "id,objectNumber,equals";
if (!other || _typeof(other) !== _typeof(this)) return false;
var count = 0;
for (var p in this) {
if (ignore.indexOf(p) >= 0) continue;
if (this.hasOwnProperty(p) && !other.hasOwnProperty(p)) return false;
if (this[p] !== other[p]) return false;
count++;
}
for (var p in other) {
if (other.hasOwnProperty(p) && ignore.indexOf(p) < 0) count--;
}
return count === 0;
};
/**
* Adds a new {@link GState} for later use. See {@link setGState}.
* @param {String} key
* @param {GState} gState
* @function
* @instance
* @returns {jsPDF}
*
* @methodOf jsPDF#
* @name addPage
*/
API.addGState = function (key, gState) {
addGState(key, gState);
return this;
};
/**
* Adds (and transfers the focus to) new page to the PDF document.
* @param {String/Array} format The format of the new page. Can be <ul><li>a0 - a10</li><li>b0 - b10</li><li>c0 - c10</li><li>c0 - c10</li><li>dl</li><li>letter</li><li>government-letter</li><li>legal</li><li>junior-legal</li><li>ledger</li><li>tabloid</li><li>credit-card</li></ul><br />
* Default is "a4". If you want to use your own format just pass instead of one of the above predefined formats the size as an number-array , e.g. [595.28, 841.89]
* @param {string} orientation Orientation of the new page. Possible values are "portrait" or "landscape" (or shortcuts "p" (Default), "l")
* @function
* @instance
* @returns {jsPDF}
*
* @memberOf jsPDF
* @name addPage
*/
API.addPage = function (format, orientation) {
_addPage.apply(this, arguments);
return this;
};
/**
* Adds (and transfers the focus to) new page to the PDF document.
* @function
* @instance
* @returns {jsPDF}
*
* @memberOf jsPDF
* @name setPage
* @param {number} page Switch the active page to the page number specified
* @example
* doc = jsPDF()
* doc.addPage()
* doc.addPage()
* doc.text('I am on page 3', 10, 10)
* doc.setPage(1)
* doc.text('I am on page 1', 10, 10)
*/
API.setPage = function (page) {
_setPage.apply(this, arguments);
return this;
};
/**
* @name insertPage
* @memberOf jsPDF
*
* @function
* @instance
* @param {Object} beforePage
* @returns {jsPDF}
*/
API.insertPage = function (beforePage) {
this.addPage();
this.movePage(currentPage, beforePage);
return this;
};
/**
* @name movePage
* @memberOf jsPDF
* @function
* @instance
* @param {Object} targetPage
* @param {Object} beforePage
* @returns {jsPDF}
*/
API.movePage = function (targetPage, beforePage) {
var tmpPagesContext, tmpPagedim, tmpPages, i;
if (targetPage > beforePage) {
tmpPages = pages[targetPage];
tmpPagedim = pagedim[targetPage];
tmpPagesContext = pagesContext[targetPage];
for (i = targetPage; i > beforePage; i--) {
pages[i] = pages[i - 1];
pagedim[i] = pagedim[i - 1];
pagesContext[i] = pagesContext[i - 1];
}
pages[beforePage] = tmpPages;
pagedim[beforePage] = tmpPagedim;
pagesContext[beforePage] = tmpPagesContext;
this.setPage(beforePage);
} else if (targetPage < beforePage) {
tmpPages = pages[targetPage];
tmpPagedim = pagedim[targetPage];
tmpPagesContext = pagesContext[targetPage];
for (i = targetPage; i < beforePage; i++) {
pages[i] = pages[i + 1];
pagedim[i] = pagedim[i + 1];
pagesContext[i] = pagesContext[i + 1];
}
pages[beforePage] = tmpPages;
pagedim[beforePage] = tmpPagedim;
pagesContext[beforePage] = tmpPagesContext;
this.setPage(beforePage);
}
return this;
};
/**
* @name deletePage
* @memberOf jsPDF
* @function
* @instance
* @returns {jsPDF}
*/
API.deletePage = function () {
_deletePage.apply(this, arguments);
return this;
};
/**
* @name setCreationDate
* @memberOf jsPDF
* @function
* @instance
* @param {Object} date
* @returns {jsPDF}
*/
API.setCreationDate = function (date) {
setCreationDate(date);
return this;
};
/**
* @name getCreationDate
* @memberOf jsPDF
* @function
* @instance
* @param {Object} type
* @returns {Object}
*/
API.getCreationDate = function (type) {
return getCreationDate(type);
};
/**
* @name setFileId
* @memberOf jsPDF
* @function
* @instance
* @param {string} value GUID
* @returns {jsPDF}
*/
API.setFileId = function (value) {
setFileId(value);
return this;
};
/**
* @name getFileId
* @memberOf jsPDF
* @function
* @instance
*
* @returns {string} GUID
*/
API.getFileId = function () {
return getFileId();
};
/**
* Set the display mode options of the page like zoom and layout.
*
* @param {integer|String} zoom You can pass an integer or percentage as
* a string. 2 will scale the document up 2x, '200%' will scale up by the
* same amount. You can also set it to 'fullwidth', 'fullheight',
* 'fullpage', or 'original'.
*
* Only certain PDF readers support this, such as Adobe Acrobat
*
* @param {string} layout Layout mode can be: 'continuous' - this is the
* default continuous scroll. 'single' - the single page mode only shows one
* page at a time. 'twoleft' - two column left mode, first page starts on
* the left, and 'tworight' - pages are laid out in two columns, with the
* first page on the right. This would be used for books.
* @param {string} pmode 'UseOutlines' - it shows the
* outline of the document on the left. 'UseThumbs' - shows thumbnails along
* the left. 'FullScreen' - prompts the user to enter fullscreen mode.
*
* @returns {jsPDF}
* @function
* @instance
* @name setDisplayMode
* @methodOf jsPDF#
*/
API.setDisplayMode = function (zoom, layout, pmode) {
zoomMode = zoom;
layoutMode = layout;
pageMode = pmode;
var validPageModes = [undefined, null, "UseNone", "UseOutlines", "UseThumbs", "FullScreen"];
if (validPageModes.indexOf(pmode) == -1) {
throw new Error('Page mode must be one of UseNone, UseOutlines, UseThumbs, or FullScreen. "' + pmode + '" is not recognized.');
}
return this;
};
/**
* Saves the current graphics state ("pushes it on the stack"). It can be restored by {@link restoreGraphicsState}
* later. Here, the general pdf graphics state is meant, also including the current transformation matrix,
* fill and stroke colors etc.
* @function
* @returns {jsPDF}
* @methodOf jsPDF#
* @name saveGraphicsState
*/
API.saveGraphicsState = function () {
out("q"); // as we cannot set font key and size independently we must keep track of both
fontStateStack.push({
key: activeFontKey,
size: activeFontSize,
color: textColor
});
return this;
};
/**
* Restores a previously saved graphics state saved by {@link saveGraphicsState} ("pops the stack").
* @function
* @returns {jsPDF}
* @methodOf jsPDF#
* @name restoreGraphicsState
*/
API.restoreGraphicsState = function () {
out("Q"); // restore previous font state
var fontState = fontStateStack.pop();
activeFontKey = fontState.key;
activeFontSize = fontState.size;
textColor = fontState.color;
activeGState = null;
return this;
};
/**
* Appends this matrix to the left of all previously applied matrices.
*
* Only available in "advanced" API mode.
*
* @param {Matrix} matrix
* @function
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setCurrentTransformationMatrix
*/
API.setCurrentTransformationMatrix = function (matrix) {
advancedApiModeTrap("setCurrentTransformationMatrix()");
out(matrix.toString() + " cm");
return this;
};
/**
* Starts a new pdf form object, which means that all conseequent draw calls target a new independent object
* until {@link endFormObject} is called. The created object can be referenced and drawn later using
* {@link doFormObject}. Nested form objects are possible.
* x, y, width, height set the bounding box that is used to clip the content.
*
* Only available in "advanced" API mode.
*
* @param {number} x
* @param {number} y
* @param {number} width
* @param {number} height
* @param {Matrix} matrix The matrix that will be applied to convert the form objects coordinate system to
* the parent's.
* @function
* @returns {jsPDF}
* @methodOf jsPDF#
* @name beginFormObject
*/
API.beginFormObject = function (x, y, width, height, matrix) {
advancedApiModeTrap("beginFormObject()"); // The user can set the output target to a new form object. Nested form objects are possible.
// Currently, they use the resource dictionary of the surrounding stream. This should be changed, as
// the PDF-Spec states:
// "In PDF 1.2 and later versions, form XObjects may be independent of the content streams in which
// they appear, and this is strongly recommended although not requiredIn PDF 1.2 and later versions,
// form XObjects may be independent of the content streams in which they appear, and this is strongly
// recommended although not required"
beginNewRenderTarget(x, y, width, height, matrix);
return this;
};
/**
* Completes and saves the form object. Only available in "advanced" API mode.
* @param {String} key The key by which this form object can be referenced.
* @function
* @returns {jsPDF}
* @methodOf jsPDF#
* @name endFormObject
*/
API.endFormObject = function (key) {
advancedApiModeTrap("endFormObject()");
endFormObject(key);
return this;
};
/**
* Draws the specified form object by referencing to the respective pdf XObject created with
* {@link API.beginFormObject} and {@link endFormObject}.
* The location is determined by matrix.
*
* Only available in "advanced" API mode.
*
* @param {String} key The key to the form object.
* @param {Matrix} matrix The matrix applied before drawing the form object.
* @function
* @returns {jsPDF}
* @methodOf jsPDF#
* @name doFormObject
*/
API.doFormObject = function (key, matrix) {
advancedApiModeTrap("doFormObject()");
var xObject = renderTargets[renderTargetMap[key]];
out("q");
out(matrix.toString() + " cm");
out("/" + xObject.id + " Do");
out("Q");
return this;
};
/**
* Returns the form object specified by key.
* @param key {String}
* @returns {{x: number, y: number, width: number, height: number, matrix: Matrix}}
* @function
* @returns {jsPDF}
* @methodOf jsPDF#
* @name getFormObject
*/
API.getFormObject = function (key) {
var xObject = renderTargets[renderTargetMap[key]];
return {
x: xObject.x,
y: xObject.y,
width: xObject.width,
height: xObject.height,
matrix: xObject.matrix
};
};
/**
* A matrix object for 2D homogenous transformations:
* | a b 0 |
* | c d 0 |
* | e f 1 |
* pdf multiplies matrices righthand: v' = v x m1 x m2 x ...
* @param {number} a
* @param {number} b
* @param {number} c
* @param {number} d
* @param {number} e
* @param {number} f
* @constructor
*/
API.Matrix = Matrix;
/**
* Multiplies two matrices. (see {@link Matrix})
* @param {Matrix} m1
* @param {Matrix} m2
* @methodOf jsPDF#
* @name matrixMult
*/
API.matrixMult = matrixMult;
/**
* The unit matrix (equivalent to new Matrix(1, 0, 0, 1, 0, 0)).
* @type {Matrix}
* @fieldOf jsPDF#
* @name unitMatrix
*/
API.unitMatrix = unitMatrix;
var Pattern = function Pattern(gState, matrix) {
this.gState = gState;
this.matrix = matrix;
this.id = ""; // set by addPattern()
this.objectNumber = -1; // will be set by putPattern()
};
/**
* A pattern describing a shading pattern.
*
* Only available in "advanced" API mode.
*
* @param {String} type One of "axial" or "radial"
* @param {Array<Number>} coords Either [x1, y1, x2, y2] for "axial" type describing the two interpolation points
* or [x1, y1, r, x2, y2, r2] for "radial" describing inner and the outer circle.
* @param {Array<Object>} colors An array of objects with the fields "offset" and "color". "offset" describes
* the offset in parameter space [0, 1]. "color" is an array of length 3 describing RGB values in [0, 255].
* @param {GState=} gState An additional graphics state that gets applied to the pattern (optional).
* @param {Matrix=} matrix A matrix that describes the transformation between the pattern coordinate system
* and the use coordinate system (optional).
* @constructor
* @extends API.Pattern
*/
API.ShadingPattern = function (type, coords, colors, gState, matrix) {
advancedApiModeTrap("ShadingPattern"); // see putPattern() for information how they are realized
this.type = type === "axial" ? 2 : 3;
this.coords = coords;
this.colors = colors;
Pattern.call(this, gState, matrix);
};
/**
* A PDF Tiling pattern.
*
* Only available in "advanced" API mode.
*
* @param {Array.<Number>} boundingBox The bounding box at which one pattern cell gets clipped.
* @param {Number} xStep Horizontal spacing between pattern cells.
* @param {Number} yStep Vertical spacing between pattern cells.
* @param {API.GState=} gState An additional graphics state that gets applied to the pattern (optional).
* @param {Matrix=} matrix A matrix that describes the transformation between the pattern coordinate system
* and the use coordinate system (optional).
* @constructor
* @extends API.Pattern
*/
API.TilingPattern = function (boundingBox, xStep, yStep, gState, matrix) {
advancedApiModeTrap("TilingPattern");
this.boundingBox = boundingBox;
this.xStep = xStep;
this.yStep = yStep;
this.stream = ""; // set by endTilingPattern();
this.cloneIndex = 0;
Pattern.call(this, gState, matrix);
};
API.TilingPattern.prototype = {
createClone: function createClone(patternKey, boundingBox, xStep, yStep, matrix) {
var clone = new API.TilingPattern(boundingBox || this.boundingBox, xStep || this.xStep, yStep || this.yStep, this.gState, matrix || this.matrix);
clone.stream = this.stream;
var key = patternKey + "$$" + this.cloneIndex++ + "$$";
addPattern(key, clone);
return clone;
}
};
/**
* Adds a new {@link API.ShadingPattern} for later use. Only available in "advanced" API mode.
* @param {String} key
* @param {Pattern} pattern
* @function
* @returns {jsPDF}
* @methodOf jsPDF#
* @name addPattern
*/
API.addShadingPattern = function (key, pattern) {
advancedApiModeTrap("addShadingPattern()");
addPattern(key, pattern);
return this;
};
/**
* Begins a new tiling pattern. All subsequent render calls are drawn to this pattern until {@link API.endTilingPattern}
* gets called. Only available in "advanced" API mode.
* @param {API.Pattern} pattern
* @methodOf jsPDF#
* @name beginTilingPattern
*/
API.beginTilingPattern = function (pattern) {
advancedApiModeTrap("beginTilingPattern()");
beginNewRenderTarget(pattern.boundingBox[0], pattern.boundingBox[1], pattern.boundingBox[2] - pattern.boundingBox[0], pattern.boundingBox[3] - pattern.boundingBox[1], pattern.matrix);
};
/**
* Ends a tiling pattern and sets the render target to the one active before {@link API.beginTilingPattern} has been called.
*
* Only available in "advanced" API mode.
*
* @param {string} key A unique key that is used to reference this pattern at later use.
* @param {API.Pattern} pattern The pattern to end.
* @methodOf jsPDF#
* @name endTilingPattern
*/
API.endTilingPattern = function (key, pattern) {
advancedApiModeTrap("endTilingPattern()"); // retrieve the stream
pattern.stream = pages[currentPage].join("\n");
addPattern(key, pattern);
events.publish("endTilingPattern", pattern); // restore state from stack
renderTargetStack.pop().restore();
};
/**
* Adds text to page. Supports adding multiline text when 'text' argument is an Array of Strings.
*
* @function
* @param {String|Array} text String or array of strings to be added to the page. Each line is shifted one line down
* per font, spacing settings declared before this call.
* @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {Object} options Collection of settings signalling how the text must be encoded. Defaults are sane. If you
* think you want to pass some flags, you likely can read the source.
* @param {number|Matrix} transform If transform is a number the text will be rotated by this value around the
* anchor set by x and y.
*
* If it is a Matrix, this matrix gets directly applied to the text, which allows shearing
* effects etc.; the x and y offsets are then applied AFTER the coordinate system has been established by this
* matrix. This means passing a rotation matrix that is equivalent to some rotation angle will in general yield a
* DIFFERENT result. A matrix is only allowed in "advanced" API mode.
*
* @param align {string}
* @returns {jsPDF}
* @methodOf jsPDF#
* @name text
*/
API.text = function (text, x, y, options, transform) {
/**
* Inserts something like this into PDF
* BT
* /F1 16 Tf % Font name + size
* 16 TL % How many units down for next line in multiline text
* 0 g % color
* 28.35 813.54 Td % position
* (line one) Tj
* T* (line two) Tj
* T* (line three) Tj
* ET
*/
if (transform !== undefined && transform instanceof Matrix) {
advancedApiModeTrap("The transform parameter of text() with a Matrix value");
}
var xtra = "";
var isHex = false;
var lineHeight = lineHeightProportion;
var scope = this;
function ESC(s) {
s = s.split("\t").join(Array(options.TabLen || 9).join(" "));
return pdfEscape(s, flags);
}
function transformTextToSpecialArray(text) {
//we don't want to destroy original text array, so cloning it
var sa = text.concat();
var da = [];
var len = sa.length;
var curDa; //we do array.join('text that must not be PDFescaped")
//thus, pdfEscape each component separately
while (len--) {
curDa = sa.shift();
if (typeof curDa === "string") {
da.push(curDa);
} else {
if (Object.prototype.toString.call(text) === "[object Array]" && curDa.length === 1) {
da.push(curDa[0]);
} else {
da.push([curDa[0], curDa[1], curDa[2]]);
}
}
}
return da;
}
function processTextByFunction(text, processingFunction) {
var result;
if (typeof text === "string") {
result = processingFunction(text)[0];
} else if (Object.prototype.toString.call(text) === "[object Array]") {
//we don't want to destroy original text array, so cloning it
var sa = text.concat();
var da = [];
var len = sa.length;
var curDa;
var tmpResult; //we do array.join('text that must not be PDFescaped")
//thus, pdfEscape each component separately
while (len--) {
curDa = sa.shift();
if (typeof curDa === "string") {
da.push(processingFunction(curDa)[0]);
} else if (Object.prototype.toString.call(curDa) === "[object Array]" && curDa[0] === "string") {
tmpResult = processingFunction(curDa[0], curDa[1], curDa[2]);
da.push([tmpResult[0], tmpResult[1], tmpResult[2]]);
}
}
result = da;
}
return result;
} //backwardsCompatibility
var tmp; // Pre-August-2012 the order of arguments was function(x, y, text, flags)
// in effort to make all calls have similar signature like
// function(data, coordinates... , miscellaneous)
// this method had its args flipped.
// code below allows backward compatibility with old arg order.
if (typeof text === "number") {
tmp = y;
y = x;
x = text;
text = tmp;
}
var flags = arguments[3];
var angle = arguments[4];
var align = arguments[5];
if (_typeof(flags) !== "object" || flags === null) {
if (typeof angle === "string") {
align = angle;
angle = null;
}
if (typeof flags === "string") {
align = flags;
flags = null;
}
if (typeof flags === "number") {
angle = flags;
flags = null;
}
options = {
flags: flags,
angle: angle,
align: align
};
} //Check if text is of type String
var textIsOfTypeString = false;
var tmpTextIsOfTypeString = true;
if (typeof text === "string") {
textIsOfTypeString = true;
} else if (Object.prototype.toString.call(text) === "[object Array]") {
//we don't want to destroy original text array, so cloning it
var sa = text.concat();
var da = [];
var len = sa.length;
var curDa; //we do array.join('text that must not be PDFescaped")
//thus, pdfEscape each component separately
while (len--) {
curDa = sa.shift();
if (typeof curDa !== "string" || Object.prototype.toString.call(curDa) === "[object Array]" && typeof curDa[0] !== "string") {
tmpTextIsOfTypeString = false;
}
}
textIsOfTypeString = tmpTextIsOfTypeString;
}
if (textIsOfTypeString === false) {
throw new Error('Type of text must be string or Array. "' + text + '" is not recognized.');
} //Escaping
var activeFontEncoding = fonts[activeFontKey].encoding;
if (activeFontEncoding === "WinAnsiEncoding" || activeFontEncoding === "StandardEncoding") {
text = processTextByFunction(text, function (text, posX, posY) {
return [ESC(text), posX, posY];
});
} //If there are any newlines in text, we assume
//the user wanted to print multiple lines, so break the
//text up into an array. If the text is already an array,
//we assume the user knows what they are doing.
//Convert text into an array anyway to simplify
//later code.
if (typeof text === "string") {
if (text.match(/[\r?\n]/)) {
text = text.split(/\r\n|\r|\n/g);
} else {
text = [text];
}
} //multiline
var maxWidth = options.maxWidth || 0;
if (maxWidth > 0) {
if (typeof text === "string") {
text = scope.splitTextToSize(text, maxWidth);
} else if (Object.prototype.toString.call(text) === "[object Array]") {
text = scope.splitTextToSize(text.join(" "), maxWidth);
}
} //creating Payload-Object to make text byRef
var payload = {
text: text,
x: x,
y: y,
options: options,
mutex: {
pdfEscape: pdfEscape,
activeFontKey: activeFontKey,
fonts: fonts,
activeFontSize: activeFontSize
}
};
events.publish("preProcessText", payload);
text = payload.text;
options = payload.options; //angle
var angle = options.angle;
var transformationMatrix = null;
if (angle && typeof angle === "number") {
angle *= Math.PI / 180;
if (apiMode === ApiMode.ADVANCED) {
angle = -angle;
}
var c = Math.cos(angle),
s = Math.sin(angle);
transformationMatrix = new Matrix(c, s, -s, c, 0, 0);
} else if (angle && angle instanceof Matrix) {
transformationMatrix = angle;
} //charSpace
var charSpace = options.charSpace;
if (charSpace !== undefined) {
xtra += charSpace + " Tc\n";
} //lang
var lang = options.lang;
var tmpRenderingMode = -1;
var parmRenderingMode = options.renderingMode || options.stroke;
var pageContext = scope.internal.getCurrentPageInfo().pageContext;
switch (parmRenderingMode) {
case 0:
case false:
case "fill":
tmpRenderingMode = 0;
break;
case 1:
case true:
case "stroke":
tmpRenderingMode = 1;
break;
case 2:
case "fillThenStroke":
tmpRenderingMode = 2;
break;
case 3:
case "invisible":
tmpRenderingMode = 3;
break;
case 4:
case "fillAndAddForClipping":
tmpRenderingMode = 4;
break;
case 5:
case "strokeAndAddPathForClipping":
tmpRenderingMode = 5;
break;
case 6:
case "fillThenStrokeAndAddToPathForClipping":
tmpRenderingMode = 6;
break;
case 7:
case "addToPathForClipping":
tmpRenderingMode = 7;
break;
}
var usedRenderingMode = pageContext.usedRenderingMode || -1; //if the coder wrote it explicitly to use a specific
//renderingMode, then use it
if (tmpRenderingMode !== -1) {
xtra += tmpRenderingMode + " Tr\n"; //otherwise check if we used the rendering Mode already
//if so then set the rendering Mode...
} else if (usedRenderingMode !== -1) {
xtra += "0 Tr\n";
}
if (tmpRenderingMode !== -1) {
pageContext.usedRenderingMode = tmpRenderingMode;
} //align
var align = options.align || "left";
var leading = activeFontSize * lineHeight;
var pageWidth = scope.internal.pageSize.getWidth();
var k = scope.internal.scaleFactor;
var activeFont = fonts[activeFontKey];
var charSpace = options.charSpace || activeCharSpace;
var maxWidth = options.maxWidth || 0;
var lineWidths;
var flags = {};
var wordSpacingPerLine = [];
if (Object.prototype.toString.call(text) === "[object Array]") {
var da = transformTextToSpecialArray(text);
var newY;
var maxLineLength;
var lineWidths;
if (align !== "left") {
lineWidths = da.map(function (v) {
return scope.getStringUnitWidth(v, {
font: activeFont,
charSpace: charSpace,
fontSize: activeFontSize
}) * activeFontSize / k;
});
}
var maxLineLength = Math.max.apply(Math, lineWidths); //The first line uses the "main" Td setting,
//and the subsequent lines are offset by the
//previous line's x coordinate.
var prevWidth = 0;
var delta;
var newX;
var xOffset = 0;
if (align === "right") {
xOffset = -lineWidths[0];
text = [];
for (var i = 0, len = da.length; i < len; i++) {
delta = maxLineLength - lineWidths[i];
if (i === 0) {
newX = 0;
newY = 0;
} else {
newX = prevWidth - lineWidths[i];
newY = leading;
}
text.push([da[i], newX, newY]);
prevWidth = lineWidths[i];
}
} else if (align === "center") {
xOffset = -lineWidths[0] / 2;
text = [];
for (var i = 0, len = da.length; i < len; i++) {
delta = (maxLineLength - lineWidths[i]) / 2;
if (i === 0) {
newX = 0;
newY = 0;
} else {
newX = (prevWidth - lineWidths[i]) / 2;
newY = leading;
}
text.push([da[i], newX, newY]);
prevWidth = lineWidths[i];
}
} else if (align === "left") {
text = [];
for (var i = 0, len = da.length; i < len; i++) {
text.push(da[i]);
}
} else if (align === "justify") {
text = [];
var maxWidth = maxWidth !== 0 ? maxWidth : pageWidth;
for (var i = 0, len = da.length; i < len; i++) {
newX = 0;
newY = i === 0 ? 0 : leading;
if (i < len - 1) {
wordSpacingPerLine.push((maxWidth - lineWidths[i]) / (da[i].split(" ").length - 1));
}
text.push([da[i], newX, newY]);
}
} else {
throw new Error('Unrecognized alignment option, use "left", "center", "right" or "justify".');
}
} //R2L
var doReversing = typeof options.R2L === "boolean" ? options.R2L : R2L;
if (doReversing === true) {
text = processTextByFunction(text, function (text, posX, posY) {
return [text.split("").reverse().join(""), posX, posY];
});
} //creating Payload-Object to make text byRef
var payload = {
text: text,
x: x,
y: y,
options: options,
mutex: {
pdfEscape: pdfEscape,
activeFontKey: activeFontKey,
fonts: fonts,
activeFontSize: activeFontSize
}
};
events.publish("postProcessText", payload);
text = payload.text;
isHex = payload.mutex.isHex;
var da = transformTextToSpecialArray(text);
text = [];
var variant = 0;
var len = da.length;
var posX;
var posY;
var content;
var wordSpacing = "";
for (var i = 0; i < len; i++) {
wordSpacing = "";
if (Object.prototype.toString.call(da[i]) !== "[object Array]") {
content = (isHex ? "<" : "(") + da[i] + (isHex ? ">" : ")");
variant = 0;
} else if (Object.prototype.toString.call(da[i]) === "[object Array]") {
posX = da[i][1] * k; // x offset must always be scaled!
// y offset/leading must NOT be scaled by k as it is dependent of the font size, which is always given
// in plain pt
posY = -da[i][2];
content = (isHex ? "<" : "(") + da[i][0] + (isHex ? ">" : ")");
variant = 1;
}
if (wordSpacingPerLine !== undefined && wordSpacingPerLine[i] !== undefined) {
wordSpacing = wordSpacingPerLine[i] + " Tw\n";
}
if (variant === 1 && i > 0) {
text.push(wordSpacing + hpf(posX) + " " + hpf(posY) + " " + " Td\n" + content);
} else {
text.push(wordSpacing + content);
}
}
if (variant === 0) {
text = text.join(" Tj\nT* ");
} else {
text = text.join(" Tj\n");
}
if (apiMode === ApiMode.ADVANCED && transformationMatrix === null) {
transformationMatrix = unitMatrix;
}
if (transformationMatrix !== null) {
// It is kind of more intuitive to apply a plain rotation around the text anchor set by x and y
// but when the user supplies an arbitrary transformation matrix, the x and y offsets should be applied
// in the coordinate system established by this matrix
if (typeof angle === "number") {
transformationMatrix = matrixMult(transformationMatrix, new Matrix(1, 0, 0, 1, scaleByK(x), transformScaleY(y)));
} else {
transformationMatrix = matrixMult(new Matrix(1, 0, 0, 1, scaleByK(x), transformScaleY(y)), transformationMatrix);
}
transformationMatrix = matrixMult( // xOffset must always be scaled!
new Matrix(1, 0, 0, 1, xOffset * k, 0), transformationMatrix);
if (apiMode === ApiMode.ADVANCED) {
transformationMatrix = matrixMult(new Matrix(1, 0, 0, -1, 0, 0), transformationMatrix);
}
text = transformationMatrix.toString() + " Tm\n" + text;
} else {
text = hpf(scaleByK(x + xOffset)) + " " + hpf(transformScaleY(y)) + " " + " Td\n" + text;
}
text += " Tj\n";
var result = "BT\n/" + activeFontKey + " " + activeFontSize + " Tf\n" + // font face, style, size
(activeFontSize * lineHeight).toFixed(2) + " TL\n" + // line spacing
textColor + "\n";
result += xtra;
result += text;
result += "ET";
out(result);
return scope;
};
/**
* Letter spacing method to print text with gaps
*
* @function
* @instance
* @param {String|Array} text String to be added to the page.
* @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {number} spacing Spacing (in units declared at inception)
* @returns {jsPDF}
* @methodOf jsPDF#
* @name lstext
* @deprecated We'll be removing this function. It doesn't take character width into account.
*/
API.lstext = function (text, x, y, spacing) {
console.warn("jsPDF.lstext is deprecated");
for (var i = 0, len = text.length; i < len; i++, x += spacing) {
this.text(text[i], x, y);
}
return this;
};
/**
* Draws a line from (x1, y1) to (x2, y2). No extra call to {@link API.stroke} is needed.
* @param {number} x1
* @param {number} y1
* @param {number} x2
* @param {number} y2
* @return {jsPDF}
* @methodOf jsPDF#
* @name line
*/
API.line = function (x1, y1, x2, y2) {
if (apiMode === ApiMode.COMPAT) {
return this.lines([[x2 - x1, y2 - y1]], x1, y1, [1, 1], "D");
} else {
return this.lines([[x2 - x1, y2 - y1]], x1, y1, [1, 1]).stroke();
}
};
/**
* Begin a new subpath by moving the current point to coordinates (x, y). The PDF "m" operator.
* @param {number} x
* @param {number} y
* @methodOf jsPDF#
* @name moveTo
*/
API.moveTo = function (x, y) {
out(hpf(scaleByK(x)) + " " + hpf(transformScaleY(y)) + " m");
};
/**
* Append a straight line segment from the current point to the point (x, y). The PDF "l" operator.
* @param {number} x
* @param {number} y
* @methodOf jsPDF#
* @name lineTo
*/
API.lineTo = function (x, y) {
out(hpf(scaleByK(x)) + " " + hpf(transformScaleY(y)) + " l");
};
/**
* Append a cubic Bézier curve to the current path. The curve shall extend from the current point to the point
* (x3, y3), using (x1, y1) and (x2, y2) as Bézier control points. The new current point shall be (x3, x3).
* @param {number} x1
* @param {number} y1
* @param {number} x2
* @param {number} y2
* @param {number} x3
* @param {number} y3
* @methodOf jsPDF#
* @name curveTo
*/
API.curveTo = function (x1, y1, x2, y2, x3, y3) {
out([hpf(scaleByK(x1)), hpf(transformScaleY(y1)), hpf(scaleByK(x2)), hpf(transformScaleY(y2)), hpf(scaleByK(x3)), hpf(transformScaleY(y3)), "c"].join(" "));
}; // PDF supports these path painting and clip path operators:
//
// S - stroke
// s - close/stroke
// f (F) - fill non-zero
// f* - fill evenodd
// B - fill stroke nonzero
// B* - fill stroke evenodd
// b - close fill stroke nonzero
// b* - close fill stroke evenodd
// n - nothing (consume path)
// W - clip nonzero
// W* - clip evenodd
//
// In order to keep the API small, we omit the close-and-fill/stroke operators and provide a separate close()
// method.
/**
* Close the current path. The PDF "h" operator.
* @return jsPDF
* @methodOf jsPDF#
* @name close
*/
API.close = function () {
out("h");
return this;
};
/**
* Stroke the path. The PDF "S" operator.
* @return jsPDF
* @methodOf jsPDF#
* @name stroke
*/
API.stroke = function () {
out("S");
return this;
};
/**
* @typedef {Object} PatternData
* @property {string} key The key of the pattern
* @property {Matrix} matrix The matrix that gets applied to the pattern right before drawing.
* @property {number[]|undefined} boundingBox Only relevant for tiling patterns. The bounding box at which one
* pattern cell gets clipped
* @property {number|undefined} xStep Only relevant for tiling patterns. Horizontal spacing between pattern cells
* @property {number|undefined} yStep Only relevant for tiling patterns. Vertical spacing between pattern cells
*/
/**
* Fill the current path using the nonzero winding number rule. If a pattern is provided, the path will be filled
* with this pattern, otherwise with the current fill color. Equivalent to the PDF "f" operator.
* @param {PatternData=} pattern If provided the path will be filled with this pattern
* @return jsPDF
* @methodOf jsPDF#
* @name fill
*/
API.fill = function (pattern) {
fillWithOptionalPattern("f", pattern);
return this;
};
/**
* Fill the current path using the even-odd rule. The PDF f* operator.
* @see API.fill
* @param {PatternData=} pattern Optional pattern
* @return jsPDF
* @methodOf jsPDF#
* @name fillEvenOdd
*/
API.fillEvenOdd = function (pattern) {
fillWithOptionalPattern("f*", pattern);
return this;
};
/**
* Fill using the nonzero winding number rule and then stroke the current Path. The PDF "B" operator.
* @see API.fill
* @param {PatternData=} pattern Optional pattern
* @return jsPDF
* @methodOf jsPDF#
* @name fillStroke
*/
API.fillStroke = function (pattern) {
fillWithOptionalPattern("B", pattern);
return this;
};
/**
* Fill using the even-odd rule and then stroke the current Path. The PDF "B" operator.
* @see API.fill
* @param {PatternData=} pattern Optional pattern
* @return jsPDF
* @methodOf jsPDF#
* @name fillStrokeEvenOdd
*/
API.fillStrokeEvenOdd = function (pattern) {
fillWithOptionalPattern("B*", pattern);
return this;
};
function fillWithOptionalPattern(style, pattern) {
if (_typeof(pattern) === "object") {
fillWithPattern(pattern, style);
} else {
out(style);
}
}
/**
* Modify the current clip path by intersecting it with the current path using the nonzero winding number rule. Note
* that this will NOT consume the current path. In order to only use this path for clipping call
* {@link API.discardPath} afterwards.
*
* When in "compat" API mode this method has a historical bug and will always stroke the path as well, use
* {@link API.clip_fixed} instead.
* @return jsPDF
* @methodOf jsPDF#
* @name clip
*/
API.clip = function () {
if (apiMode === ApiMode.COMPAT) {
// By patrick-roberts, github.com/MrRio/jsPDF/issues/328
// Call .clip() after calling .rect() with a style argument of null
out("W"); // clip
out("S"); // stroke path; necessary for clip to work
} else {
out("W");
}
return this;
};
/**
* Modify the current clip path by intersecting it with the current path using the even-odd rule. Note
* that this will NOT consume the current path. In order to only use this path for clipping call
* {@link API.discardPath} afterwards.
*
* @return jsPDF
* @methodOf jsPDF#
* @name clipEvenOdd
*/
API.clipEvenOdd = function () {
out("W*");
return this;
};
/**
* Consumes the current path without any effect. Mainly used in combination with {@link clip} or
* {@link clipEvenOdd}. The PDF "n" operator.
* @return {jsPDF}
* @methodOf jsPDF#
* @name discardPath
*/
API.discardPath = function () {
out("n");
return this;
};
/**
* This fixes the previous function clip(). Perhaps the 'stroke path' hack was due to the missing 'n' instruction?
* We introduce the fixed version so as to not break API.
* @param fillRule
* @deprecated Don't use this method when in "advanced" API mode.
* @methodOf jsPDF#
* @name clip_fixed
*/
API.clip_fixed = function (fillRule) {
// Call .clip() after calling drawing ops with a style argument of null
// W is the PDF clipping op
if ("evenodd" === fillRule) {
out("W*");
} else {
out("W");
} // End the path object without filling or stroking it.
// This operator is a path-painting no-op, used primarily for the side effect of changing the current clipping path
// (see Section 4.4.3, “Clipping Path Operators”)
out("n");
};
/**
* @typedef {Object} PatternData
* {Matrix|undefined} matrix
* {Number|undefined} xStep
* {Number|undefined} yStep
* {Array.<Number>|undefined} boundingBox
*/
/**
* Adds series of curves (straight lines or cubic bezier curves) to canvas, starting at `x`, `y` coordinates.
* All data points in `lines` are relative to last line origin.
* `x`, `y` become x1,y1 for first line / curve in the set.
* For lines you only need to specify [x2, y2] - (ending point) vector against x1, y1 starting point.
* For bezier curves you need to specify [x2,y2,x3,y3,x4,y4] - vectors to control points 1, 2, ending point. All vectors are against the start of the curve - x1,y1.
*
* @example .lines([[2,2],[-2,2],[1,1,2,2,3,3],[2,1]], 212,110, 10) // line, line, bezier curve, line
* @param {Array} lines Array of *vector* shifts as pairs (lines) or sextets (cubic bezier curves).
* @param {Number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {Number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {Number} scale (Defaults to [1.0,1.0]) x,y Scaling factor for all vectors. Elements can be any floating number Sub-one makes drawing smaller. Over-one grows the drawing. Negative flips the direction.
* @param {String=} style A string specifying the painting style or null. Valid styles include:
* 'S' [default] - stroke,
* 'F' - fill,
* and 'DF' (or 'FD') - fill then stroke.
* In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple
* method calls. The last drawing method call used to define the shape should not have a null style argument.
*
* In "advanced" API mode this parameter is deprecated.
* @param {Boolean=} closed If true, the path is closed with a straight line from the end of the last curve to the starting point.
* @param {String=} patternKey The pattern key for the pattern that should be used to fill the path. Deprecated!
* @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that
* will modify the pattern on use. Deprecated!
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name lines
*/
API.lines = function (lines, x, y, scale, style, closed, patternKey, patternData) {
var scalex, scaley, i, l, leg, x2, y2, x3, y3, x4, y4; // Pre-August-2012 the order of arguments was function(x, y, lines, scale, style)
// in effort to make all calls have similar signature like
// function(content, coordinateX, coordinateY , miscellaneous)
// this method had its args flipped.
// code below allows backward compatibility with old arg order.
if (typeof lines === "number") {
var tmp = y;
y = x;
x = lines;
lines = tmp;
}
scale = scale || [1, 1]; // starting point
this.moveTo(x, y);
scalex = scale[0];
scaley = scale[1];
l = lines.length; //, x2, y2 // bezier only. In page default measurement "units", *after* scaling
//, x3, y3 // bezier only. In page default measurement "units", *after* scaling
// ending point for all, lines and bezier. . In page default measurement "units", *after* scaling
x4 = x; // last / ending point = starting point for first item.
y4 = y; // last / ending point = starting point for first item.
for (i = 0; i < l; i++) {
leg = lines[i];
if (leg.length === 2) {
// simple line
x4 = leg[0] * scalex + x4; // here last x4 was prior ending point
y4 = leg[1] * scaley + y4; // here last y4 was prior ending point
this.lineTo(x4, y4);
} else {
// bezier curve
x2 = leg[0] * scalex + x4; // here last x4 is prior ending point
y2 = leg[1] * scaley + y4; // here last y4 is prior ending point
x3 = leg[2] * scalex + x4; // here last x4 is prior ending point
y3 = leg[3] * scaley + y4; // here last y4 is prior ending point
x4 = leg[4] * scalex + x4; // here last x4 was prior ending point
y4 = leg[5] * scaley + y4; // here last y4 was prior ending point
this.curveTo(x2, y2, x3, y3, x4, y4);
}
}
if (closed) {
this.close();
}
putStyle(style, patternKey, patternData);
return this;
};
/**
* Similar to {@link API.lines} but all coordinates are interpreted as absolute coordinates instead of relative.
* @param {Array<Object>} lines An array of {op: operator, c: coordinates} object, where op is one of "m" (move to), "l" (line to)
* "c" (cubic bezier curve) and "h" (close (sub)path)). c is an array of coordinates. "m" and "l" expect two, "c"
* six and "h" an empty array (or undefined).
* @param {String=} style The style. Deprecated!
* @param {String=} patternKey The pattern key for the pattern that should be used to fill the path. Deprecated!
* @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that
* will modify the pattern on use. Deprecated!
* @function
* @returns {jsPDF}
* @methodOf jsPDF#
* @name path
*/
API.path = function (lines, style, patternKey, patternData) {
for (var i = 0; i < lines.length; i++) {
var leg = lines[i];
var coords = leg.c;
switch (leg.op) {
case "m":
this.moveTo(coords[0], coords[1]);
break;
case "l":
this.lineTo(coords[0], coords[1]);
break;
case "c":
this.curveTo.apply(this, coords);
break;
case "h":
this.close();
break;
}
}
putStyle(style, patternKey, patternData);
return this;
};
/**
* Adds a rectangle to PDF
*
* @param {Number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {Number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {Number} w Width (in units declared at inception of PDF document)
* @param {Number} h Height (in units declared at inception of PDF document)
* @param {String=} style A string specifying the painting style or null. Valid styles include:
* 'S' [default] - stroke,
* 'F' - fill,
* and 'DF' (or 'FD') - fill then stroke.
* In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple
* method calls. The last drawing method call used to define the shape should not have a null style argument.
*
* In "advanced" API mode this parameter is deprecated.
* @param {String=} patternKey The pattern key for the pattern that should be used to fill the primitive. Deprecated!
* @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that
* will modify the pattern on use. Deprecated!
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name rect
*/
API.rect = function (x, y, w, h, style, patternKey, patternData) {
if (apiMode === ApiMode.COMPAT) {
h = -h;
}
out([hpf(scaleByK(x)), hpf(transformScaleY(y)), hpf(scaleByK(w)), hpf(scaleByK(h)), "re"].join(" "));
putStyle(style, patternKey, patternData);
return this;
};
/**
* Adds a triangle to PDF
*
* @param {Number} x1 Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {Number} y1 Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {Number} x2 Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {Number} y2 Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {Number} x3 Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {Number} y3 Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {String=} style A string specifying the painting style or null. Valid styles include:
* 'S' [default] - stroke,
* 'F' - fill,
* and 'DF' (or 'FD') - fill then stroke.
* In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple
* method calls. The last drawing method call used to define the shape should not have a null style argument.
*
* In "advanced" API mode this parameter is deprecated.
* @param {String=} patternKey The pattern key for the pattern that should be used to fill the primitive. Deprecated!
* @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that
* will modify the pattern on use. Deprecated!
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name triangle
*/
API.triangle = function (x1, y1, x2, y2, x3, y3, style, patternKey, patternData) {
this.lines([[x2 - x1, y2 - y1], // vector to point 2
[x3 - x2, y3 - y2], // vector to point 3
[x1 - x3, y1 - y3] // closing vector back to point 1
], x1, y1, // start of path
[1, 1], style, true, patternKey, patternData);
return this;
};
/**
* Adds a rectangle with rounded corners to PDF
*
* @param {Number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {Number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {Number} w Width (in units declared at inception of PDF document)
* @param {Number} h Height (in units declared at inception of PDF document)
* @param {Number} rx Radius along x axis (in units declared at inception of PDF document)
* @param {Number} ry Radius along y axis (in units declared at inception of PDF document)
* @param {String=} style A string specifying the painting style or null. Valid styles include:
* 'S' [default] - stroke,
* 'F' - fill,
* and 'DF' (or 'FD') - fill then stroke.
* In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple
* method calls. The last drawing method call used to define the shape should not have a null style argument.
*
* In "advanced" API mode this parameter is deprecated.
* @param {String=} patternKey The pattern key for the pattern that should be used to fill the primitive. Deprecated!
* @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that
* will modify the pattern on use. Deprecated!
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name roundedRect
*/
API.roundedRect = function (x, y, w, h, rx, ry, style, patternKey, patternData) {
var MyArc = 4 / 3 * (Math.SQRT2 - 1);
rx = Math.min(rx, w * 0.5);
ry = Math.min(ry, h * 0.5);
this.lines([[w - 2 * rx, 0], [rx * MyArc, 0, rx, ry - ry * MyArc, rx, ry], [0, h - 2 * ry], [0, ry * MyArc, -(rx * MyArc), ry, -rx, ry], [-w + 2 * rx, 0], [-(rx * MyArc), 0, -rx, -(ry * MyArc), -rx, -ry], [0, -h + 2 * ry], [0, -(ry * MyArc), rx * MyArc, -ry, rx, -ry]], x + rx, y, // start of path
[1, 1], style, true, patternKey, patternData);
return this;
};
/**
* Adds an ellipse to PDF
*
* @param {Number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {Number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {Number} rx Radius along x axis (in units declared at inception of PDF document)
* @param {Number} ry Radius along y axis (in units declared at inception of PDF document)
* @param {String=} style A string specifying the painting style or null. Valid styles include:
* 'S' [default] - stroke,
* 'F' - fill,
* and 'DF' (or 'FD') - fill then stroke.
* In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple
* method calls. The last drawing method call used to define the shape should not have a null style argument.
*
* In "advanced" API mode this parameter is deprecated.
* @param {String=} patternKey The pattern key for the pattern that should be used to fill the primitive. Deprecated!
* @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that
* will modify the pattern on use. Deprecated!
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name ellipse
*/
API.ellipse = function (x, y, rx, ry, style, patternKey, patternData) {
var lx = 4 / 3 * (Math.SQRT2 - 1) * rx,
ly = 4 / 3 * (Math.SQRT2 - 1) * ry;
this.moveTo(x + rx, y);
this.curveTo(x + rx, y - ly, x + lx, y - ry, x, y - ry);
this.curveTo(x - lx, y - ry, x - rx, y - ly, x - rx, y);
this.curveTo(x - rx, y + ly, x - lx, y + ry, x, y + ry);
this.curveTo(x + lx, y + ry, x + rx, y + ly, x + rx, y);
putStyle(style, patternKey, patternData);
return this;
};
/**
* Adds an circle to PDF
*
* @param {Number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {Number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {Number} r Radius (in units declared at inception of PDF document)
* @param {String=} style A string specifying the painting style or null. Valid styles include:
* 'S' [default] - stroke,
* 'F' - fill,
* and 'DF' (or 'FD') - fill then stroke.
* In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple
* method calls. The last drawing method call used to define the shape should not have a null style argument.
*
* In "advanced" API mode this parameter is deprecated.
* @param {String=} patternKey The pattern key for the pattern that should be used to fill the primitive. Deprecated!
* @param {(Matrix|PatternData)=} patternData The matrix that transforms the pattern into user space, or an object that
* will modify the pattern on use. Deprecated!
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name circle
*/
API.circle = function (x, y, r, style, patternKey, patternData) {
return this.ellipse(x, y, r, r, style, patternKey, patternData);
};
/**
* Adds a properties to the PDF document
*
* @param {Object} properties A property_name-to-property_value object structure.
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setProperties
*/
API.setProperties = function (properties) {
// copying only those properties we can render.
for (var property in documentProperties) {
if (documentProperties.hasOwnProperty(property) && properties[property]) {
documentProperties[property] = properties[property];
}
}
return this;
};
/**
* Sets font size for upcoming text elements.
*
* @param {number} size Font size in points.
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setFontSize
*/
API.setFontSize = function (size) {
// convert font size into current unit system
if (apiMode === ApiMode.ADVANCED) {
activeFontSize = size / k;
} else {
activeFontSize = size;
}
out("/" + activeFontKey + " " + activeFontSize + " Tf");
return this;
};
/**
* @return {number}
* @methodOf jsPDF#
* @name getFontSize
*/
API.getFontSize = function () {
if (apiMode === ApiMode.COMPAT) {
return activeFontSize;
} else {
return activeFontSize * k;
}
};
/**
* Sets text font face, variant for upcoming text elements.
* See output of jsPDF.getFontList() for possible font names, styles.
*
* @param {string} fontName Font name or family. Example: "times"
* @param {string} fontStyle Font style or variant. Example: "italic"
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setFont
*/
API.setFont = function (fontName, fontStyle) {
activeFontKey = _getFont(fontName, fontStyle); // if font is not found, the above line blows up and we never go further
out("/" + activeFontKey + " " + activeFontSize + " Tf");
return this;
};
/**
* Switches font style or variant for upcoming text elements,
* while keeping the font face or family same.
* See output of jsPDF.getFontList() for possible font names, styles.
*
* @param {string} style Font style or variant. Example: "italic"
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setFontStyle
*/
API.setFontStyle = API.setFontType = function (style) {
activeFontKey = _getFont(undefined, style); // if font is not found, the above line blows up and we never go further
out("/" + activeFontKey + " " + activeFontSize + " Tf");
return this;
};
/**
* Returns an object - a tree of fontName to fontStyle relationships available to
* active PDF document.
*
* @public
* @function
* @instance
* @returns {Object} Like {'times':['normal', 'italic', ... ], 'arial':['normal', 'bold', ... ], ... }
* @methodOf jsPDF#
* @name getFontList
*/
API.getFontList = function () {
// TODO: iterate over fonts array or return copy of fontmap instead in case more are ever added.
var list = {},
fontName,
fontStyle,
tmp;
for (fontName in fontmap) {
if (fontmap.hasOwnProperty(fontName)) {
list[fontName] = tmp = [];
for (fontStyle in fontmap[fontName]) {
if (fontmap[fontName].hasOwnProperty(fontStyle)) {
tmp.push(fontStyle);
}
}
}
}
return list;
};
/**
* Add a custom font to the current instance.
*
* @param {String} postScriptName name of the Font. Example: "Menlo-Regular"
* @param {String} fontName of font-family from @font-face definition. Example: "Menlo Regular"
* @param {String} fontStyle style. Example: "normal"
* @function
* @instance
* @methodOf jsPDF
* @name addFont
*/
API.addFont = function (postScriptName, fontName, fontStyle, encoding) {
encoding = encoding || "Identity-H";
addFont.call(this, postScriptName, fontName, fontStyle, encoding);
};
/**
* Sets line width for upcoming lines.
*
* @param {number} width Line width (in units declared at inception of PDF document)
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setLineWidth
*/
API.setLineWidth = function (width) {
out(scaleByK(width).toFixed(2) + " w");
return this;
};
/**
* Sets the stroke color for upcoming elements.
*
* Depending on the number of arguments given, Gray, RGB, or CMYK
* color space is implied.
*
* When only ch1 is given, "Gray" color space is implied and it
* must be a value in the range from 0.00 (solid black) to to 1.00 (white)
* if values are communicated as String types, or in range from 0 (black)
* to 255 (white) if communicated as Number type.
* The RGB-like 0-255 range is provided for backward compatibility.
*
* When only ch1,ch2,ch3 are given, "RGB" color space is implied and each
* value must be in the range from 0.00 (minimum intensity) to to 1.00
* (max intensity) if values are communicated as String types, or
* from 0 (min intensity) to to 255 (max intensity) if values are communicated
* as Number types.
* The RGB-like 0-255 range is provided for backward compatibility.
*
* When ch1,ch2,ch3,ch4 are given, "CMYK" color space is implied and each
* value must be a in the range from 0.00 (0% concentration) to to
* 1.00 (100% concentration)
*
* Because JavaScript treats fixed point numbers badly (rounds to
* floating point nearest to binary representation) it is highly advised to
* communicate the fractional numbers as String types, not JavaScript Number type.
*
* @param {Number|String} ch1 Color channel value or {string} ch1 color value in hexadecimal, example: '#FFFFFF'
* @param {Number|String} ch2 Color channel value
* @param {Number|String} ch3 Color channel value
* @param {Number|String} ch4 Color channel value
*
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setDrawColor
*/
API.setDrawColor = function (ch1, ch2, ch3, ch4) {
var options = {
ch1: ch1,
ch2: ch2,
ch3: ch3,
ch4: ch4,
pdfColorType: "draw",
precision: 2
};
out(generateColorString(options));
return this;
};
/**
* Sets the fill color for upcoming elements.
*
* Depending on the number of arguments given, Gray, RGB, or CMYK
* color space is implied.
*
* When only ch1 is given, "Gray" color space is implied and it
* must be a value in the range from 0.00 (solid black) to to 1.00 (white)
* if values are communicated as String types, or in range from 0 (black)
* to 255 (white) if communicated as Number type.
* The RGB-like 0-255 range is provided for backward compatibility.
*
* When only ch1,ch2,ch3 are given, "RGB" color space is implied and each
* value must be in the range from 0.00 (minimum intensity) to to 1.00
* (max intensity) if values are communicated as String types, or
* from 0 (min intensity) to to 255 (max intensity) if values are communicated
* as Number types.
* The RGB-like 0-255 range is provided for backward compatibility.
*
* When ch1,ch2,ch3,ch4 are given, "CMYK" color space is implied and each
* value must be a in the range from 0.00 (0% concentration) to to
* 1.00 (100% concentration)
*
* Because JavaScript treats fixed point numbers badly (rounds to
* floating point nearest to binary representation) it is highly advised to
* communicate the fractional numbers as String types, not JavaScript Number type.
*
* @param {Number|String} ch1 Color channel value or {string} ch1 color value in hexadecimal, example: '#FFFFFF'
* @param {Number|String} ch2 Color channel value
* @param {Number|String} ch3 Color channel value
* @param {Number|String} ch4 Color channel value
*
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setFillColor
*/
API.setFillColor = function (ch1, ch2, ch3, ch4) {
var options = {
ch1: ch1,
ch2: ch2,
ch3: ch3,
ch4: ch4,
pdfColorType: "fill",
precision: 2
};
out(generateColorString(options));
return this;
};
/**
* Sets the text color for upcoming elements.
*
* Depending on the number of arguments given, Gray, RGB, or CMYK
* color space is implied.
*
* When only ch1 is given, "Gray" color space is implied and it
* must be a value in the range from 0.00 (solid black) to to 1.00 (white)
* if values are communicated as String types, or in range from 0 (black)
* to 255 (white) if communicated as Number type.
* The RGB-like 0-255 range is provided for backward compatibility.
*
* When only ch1,ch2,ch3 are given, "RGB" color space is implied and each
* value must be in the range from 0.00 (minimum intensity) to to 1.00
* (max intensity) if values are communicated as String types, or
* from 0 (min intensity) to to 255 (max intensity) if values are communicated
* as Number types.
* The RGB-like 0-255 range is provided for backward compatibility.
*
* When ch1,ch2,ch3,ch4 are given, "CMYK" color space is implied and each
* value must be a in the range from 0.00 (0% concentration) to to
* 1.00 (100% concentration)
*
* Because JavaScript treats fixed point numbers badly (rounds to
* floating point nearest to binary representation) it is highly advised to
* communicate the fractional numbers as String types, not JavaScript Number type.
*
* @param {Number|String} ch1 Color channel value or {string} ch1 color value in hexadecimal, example: '#FFFFFF'
* @param {Number|String} ch2 Color channel value
* @param {Number|String} ch3 Color channel value
* @param {Number|String} ch4 Color channel value
*
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setTextColor
*/
API.setTextColor = function (ch1, ch2, ch3, ch4) {
var options = {
ch1: ch1,
ch2: ch2,
ch3: ch3,
ch4: ch4,
pdfColorType: "text",
precision: 3
};
textColor = generateColorString(options);
return this;
};
/**
* Initializes the default character set that the user wants to be global..
*
* @param {number} charSpace
* @function
* @instance
* @returns {jsPDF} jsPDF-instance
* @methodOf jsPDF
* @name setCharSpace
*/
API.setCharSpace = function (charSpace) {
if (apiMode === ApiMode.COMPAT) {
activeCharSpace = charSpace;
} else if (apiMode === ApiMode.ADVANCED) {
activeCharSpace = charSpace / k;
}
return this;
};
/**
* Initializes the default character set that the user wants to be global..
*
* @param {boolean} boolean
* @function
* @instance
* @returns {jsPDF} jsPDF-instance
* @methodOf jsPDF
* @name setR2L
*/
API.setR2L = function (boolean) {
R2L = boolean;
return this;
};
/**
* Sets a either previously added {@link GState} (via {@link addGState}) or a new {@link GState}.
* @param {String|GState} gState If type is string, a previously added GState is used, if type is GState
* it will be added before use.
* @function
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setGState
*/
API.setGState = function (gState) {
if (typeof gState === "string") {
gState = gStates[gStatesMap[gState]];
} else {
gState = addGState(null, gState);
}
if (!gState.equals(activeGState)) {
out("/" + gState.id + " gs");
activeGState = gState;
}
};
/**
* Is an Object providing a mapping from human-readable to
* integer flag values designating the varieties of line cap
* and join styles.
*
* @fieldOf jsPDF#
* @name CapJoinStyles
*/
API.CapJoinStyles = {
0: 0,
butt: 0,
but: 0,
miter: 0,
1: 1,
round: 1,
rounded: 1,
circle: 1,
2: 2,
projecting: 2,
project: 2,
square: 2,
bevel: 2
};
/**
* Sets the line cap styles
* See {jsPDF.CapJoinStyles} for variants
*
* @param {String|Number} style A string or number identifying the type of line cap
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setLineCap
*/
API.setLineCap = function (style) {
var id = this.CapJoinStyles[style];
if (id === undefined) {
throw new Error("Line cap style of '" + style + "' is not recognized. See or extend .CapJoinStyles property for valid styles");
}
lineCapID = id;
out(id + " J");
return this;
};
/**
* Sets the line join styles
* See {jsPDF.CapJoinStyles} for variants
*
* @param {String|Number} style A string or number identifying the type of line join
* @function
* @instance
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setLineJoin
*/
API.setLineJoin = function (style) {
var id = this.CapJoinStyles[style];
if (id === undefined) {
throw new Error("Line join style of '" + style + "' is not recognized. See or extend .CapJoinStyles property for valid styles");
}
lineJoinID = id;
out(id + " j");
return this;
};
/**
* Sets the miter limit.
* @param {number} miterLimit
* @function
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setMiterLimit
*/
API.setLineMiterLimit = function (miterLimit) {
out(hpf(miterLimit) + " M");
return this;
};
/**
* Sets the line dash pattern.
* @param {Array<number>} array An array containing 0-2 numbers. The first number sets the length of the
* dashes, the second number the length of the gaps. If the second number is missing, the gaps are considered
* to be as long as the dashes. An empty array means solid, unbroken lines.
* @param phase The phase lines start with.
* @function
* @returns {jsPDF}
* @methodOf jsPDF#
* @name setLineDashPattern
*/
API.setLineDashPattern = function (array, phase) {
out(["[" + (array[0] !== undefined ? array[0] : ""), (array[1] !== undefined ? array[1] : "") + "]", phase, "d"].join(" "));
return this;
};
/**
* Generates the PDF document.
*
* If `type` argument is undefined, output is raw body of resulting PDF returned as a string.
*
* @param {string} type A string identifying one of the possible output types.
* @param {Object} options An object providing some additional signalling to PDF generator.
*
* @function
* @instance
* @returns {jsPDF}
* @memberOf jsPDF
* @name output
*/
API.output = _output;
/**
* Saves as PDF document. An alias of jsPDF.output('save', 'filename.pdf')
*
* @memberOf jsPDF
* @name save
* @function
* @instance
* @param {string} filename The filename including extension.
* @returns {jsPDF} jsPDF-instance
*/
API.save = function (filename) {
API.output("save", filename);
}; // applying plugins (more methods) ON TOP of built-in API.
// this is intentional as we allow plugins to override
// built-ins
for (var plugin in jsPDF.API) {
if (jsPDF.API.hasOwnProperty(plugin)) {
if (plugin === "events" && jsPDF.API.events.length) {
(function (events, newEvents) {
// jsPDF.API.events is a JS Array of Arrays
// where each Array is a pair of event name, handler
// Events were added by plugins to the jsPDF instantiator.
// These are always added to the new instance and some ran
// during instantiation.
var eventname, handler_and_args, i;
for (i = newEvents.length - 1; i !== -1; i--) {
// subscribe takes 3 args: 'topic', function, runonce_flag
// if undefined, runonce is false.
// users can attach callback directly,
// or they can attach an array with [callback, runonce_flag]
// that's what the "apply" magic is for below.
eventname = newEvents[i][0];
handler_and_args = newEvents[i][1];
events.subscribe.apply(events, [eventname].concat(typeof handler_and_args === "function" ? [handler_and_args] : handler_and_args));
}
})(events, jsPDF.API.events);
} else {
API[plugin] = jsPDF.API[plugin];
}
}
} //////////////////////////////////////////////////////
// continuing initialization of jsPDF Document object
//////////////////////////////////////////////////////
// Add the first page automatically
addFonts();
activeFontKey = "F1";
_addPage(format, orientation);
events.publish("initialized");
return API;
}
/**
* jsPDF.API is a STATIC property of jsPDF class.
* jsPDF.API is an object you can add methods and properties to.
* The methods / properties you add will show up in new jsPDF objects.
*
* One property is prepopulated. It is the 'events' Object. Plugin authors can add topics,
* callbacks to this object. These will be reassigned to all new instances of jsPDF.
*
* @static
* @public
* @memberOf jsPDF
* @name API
*
* @example
* jsPDF.API.mymethod = function(){
* // 'this' will be ref to internal API object. see jsPDF source
* // , so you can refer to built-in methods like so:
* // this.line(....)
* // this.text(....)
* }
* var pdfdoc = new jsPDF()
* pdfdoc.mymethod() // <- !!!!!!
*/
jsPDF.API = {
events: []
};
/**
* The version of jsPDF
* @name version
* @type {string}
* @memberOf jsPDF
*/
jsPDF.version = "0.0.0";
if (typeof define === "function" && define.amd) {
define(function () {
return jsPDF;
});
} else if (typeof module !== "undefined" && module.exports) {
module.exports = jsPDF;
module.exports.jsPDF = jsPDF;
} else {
global.jsPDF = jsPDF;
}
return jsPDF;
}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function("return this")()); // `self` is undefined in Firefox for Android content script context
// while `this` is nsIContentFrameMessageManager
// with an attribute `content` that corresponds to the window
/**
* @license
* Copyright (c) 2016 Alexander Weidt,
* https://github.com/BiggA94
*
* Licensed under the MIT License. http://opensource.org/licenses/mit-license
*/
/**
* jsPDF AcroForm Plugin
*
* @name AcroForm
* @module
*/
(function (jsPDFAPI, globalObj) {
var scope;
var pageHeight;
var scaleFactor = 1;
var inherit = function inherit(child, parent) {
child.prototype = Object.create(parent.prototype);
child.prototype.constructor = child;
};
var scale = function scale(x) {
return x * (scaleFactor / 1); // 1 = (96 / 72)
};
var createFormXObject = function createFormXObject(formObject) {
var xobj = new AcroFormXObject();
var height = AcroFormAppearance.internal.getHeight(formObject) || 0;
var width = AcroFormAppearance.internal.getWidth(formObject) || 0;
xobj.BBox = [0, 0, width.toFixed(2), height.toFixed(2)];
return xobj;
};
var setBitPosition = function setBitPosition(variable, position, value) {
variable = variable || 0;
value = value || 1;
var bitMask = 1;
bitMask = bitMask << position - 1;
if (value == 1) {
// Set the Bit to 1
var variable = variable | bitMask;
} else {
// Set the Bit to 0
var variable = variable & ~bitMask;
}
return variable;
};
/**
* Calculating the Ff entry:
*
* The Ff entry contains flags, that have to be set bitwise In the Following
* the number in the Comment is the BitPosition
*/
var calculateFlagsOnOptions = function calculateFlagsOnOptions(flags, opts, PDFVersion) {
var PDFVersion = PDFVersion || 1.3;
var flags = flags || 0; // 1, readOnly
if (opts.readOnly == true) {
flags = setBitPosition(flags, 1);
} // 2, required
if (opts.required == true) {
flags = setBitPosition(flags, 2);
} // 4, noExport
if (opts.noExport == true) {
flags = setBitPosition(flags, 3);
} // 13, multiline
if (opts.multiline == true) {
flags = setBitPosition(flags, 13);
} // 14, Password
if (opts.password) {
flags = setBitPosition(flags, 14);
} // 15, NoToggleToOff (Radio buttons only
if (opts.noToggleToOff) {
flags = setBitPosition(flags, 15);
} // 16, Radio
if (opts.radio) {
flags = setBitPosition(flags, 16);
} // 17, Pushbutton
if (opts.pushbutton) {
flags = setBitPosition(flags, 17);
} // 18, Combo (If not set, the choiceField is a listBox!!)
if (opts.combo) {
flags = setBitPosition(flags, 18);
} // 19, Edit
if (opts.edit) {
flags = setBitPosition(flags, 19);
} // 20, Sort
if (opts.sort) {
flags = setBitPosition(flags, 20);
} // 21, FileSelect, PDF 1.4...
if (opts.fileSelect && PDFVersion >= 1.4) {
flags = setBitPosition(flags, 21);
} // 22, MultiSelect (PDF 1.4)
if (opts.multiSelect && PDFVersion >= 1.4) {
flags = setBitPosition(flags, 22);
} // 23, DoNotSpellCheck (PDF 1.4)
if (opts.doNotSpellCheck && PDFVersion >= 1.4) {
flags = setBitPosition(flags, 23);
} // 24, DoNotScroll (PDF 1.4)
if (opts.doNotScroll == true && PDFVersion >= 1.4) {
flags = setBitPosition(flags, 24);
} // 25, RichText (PDF 1.4)
if (opts.richText && PDFVersion >= 1.4) {
flags = setBitPosition(flags, 25);
}
return flags;
};
var calculateCoordinates = function calculateCoordinates(args) {
var x = args[0];
var y = args[1];
var w = args[2];
var h = args[3];
var coordinates = {};
if (Array.isArray(x)) {
x[0] = scale(x[0]);
x[1] = scale(x[1]);
x[2] = scale(x[2]);
x[3] = scale(x[3]);
} else {
x = scale(x);
y = scale(y);
w = scale(w);
h = scale(h);
}
coordinates.lowerLeft_X = x || 0;
coordinates.lowerLeft_Y = scale(pageHeight) - y - h || 0;
coordinates.upperRight_X = x + w || 0;
coordinates.upperRight_Y = scale(pageHeight) - y || 0;
return [coordinates.lowerLeft_X.toFixed(2), coordinates.lowerLeft_Y.toFixed(2), coordinates.upperRight_X.toFixed(2), coordinates.upperRight_Y.toFixed(2)];
};
var calculateAppearanceStream = function calculateAppearanceStream(formObject) {
if (formObject.appearanceStreamContent) {
// If appearanceStream is already set, use it
return formObject.appearanceStreamContent;
}
if (!formObject.V && !formObject.DV) {
return;
} // else calculate it
var stream = [];
var text = formObject.V || formObject.DV;
var calcRes = calculateX(formObject, text);
stream.push("/Tx BMC");
stream.push("q");
stream.push("/F1 " + calcRes.fontSize.toFixed(2) + " Tf");
stream.push("1 0 0 1 0 0 Tm"); // Text Matrix
stream.push("BT"); // Begin Text
stream.push(calcRes.text);
stream.push("ET"); // End Text
stream.push("Q");
stream.push("EMC");
var appearanceStreamContent = new createFormXObject(formObject);
appearanceStreamContent.stream = stream.join("\n");
return appearanceStreamContent;
};
var calculateX = function calculateX(formObject, text, font, maxFontSize) {
var maxFontSize = maxFontSize || 12;
var font = font || "helvetica";
var returnValue = {
text: "",
fontSize: ""
}; // Remove Brackets
text = text.substr(0, 1) == "(" ? text.substr(1) : text;
text = text.substr(text.length - 1) == ")" ? text.substr(0, text.length - 1) : text; // split into array of words
var textSplit = text.split(" ");
var fontSize = maxFontSize; // The Starting fontSize (The Maximum)
var lineSpacing = 2;
var borderPadding = 2;
var height = AcroFormAppearance.internal.getHeight(formObject) || 0;
height = height < 0 ? -height : height;
var width = AcroFormAppearance.internal.getWidth(formObject) || 0;
width = width < 0 ? -width : width;
var isSmallerThanWidth = function isSmallerThanWidth(i, lastLine, fontSize) {
if (i + 1 < textSplit.length) {
var tmp = lastLine + " " + textSplit[i + 1];
var TextWidth = calculateFontSpace(tmp, fontSize + "px", font).width;
var FieldWidth = width - 2 * borderPadding;
return TextWidth <= FieldWidth;
} else {
return false;
}
};
fontSize++;
FontSize: while (true) {
var text = "";
fontSize--;
var textHeight = calculateFontSpace("3", fontSize + "px", font).height;
var startY = formObject.multiline ? height - fontSize : (height - textHeight) / 2;
startY += lineSpacing;
var startX = -borderPadding;
var lastY = startY;
var firstWordInLine = 0,
lastWordInLine = 0;
var lastLength = 0;
if (fontSize <= 0) {
// In case, the Text doesn't fit at all
fontSize = 12;
text = "(...) Tj\n";
text += "% Width of Text: " + calculateFontSpace(text, "1px").width + ", FieldWidth:" + width + "\n";
break;
}
lastLength = calculateFontSpace(textSplit[0] + " ", fontSize + "px", font).width;
var lastLine = "";
var lineCount = 0;
Line: for (var i in textSplit) {
if (textSplit.hasOwnProperty(i)) {
lastLine += textSplit[i] + " "; // Remove last blank
lastLine = lastLine.substr(lastLine.length - 1) == " " ? lastLine.substr(0, lastLine.length - 1) : lastLine;
var key = parseInt(i);
lastLength = calculateFontSpace(lastLine + " ", fontSize + "px", font).width;
var nextLineIsSmaller = isSmallerThanWidth(key, lastLine, fontSize);
var isLastWord = i >= textSplit.length - 1;
if (nextLineIsSmaller && !isLastWord) {
lastLine += " ";
continue; // Line
} else if (!nextLineIsSmaller && !isLastWord) {
if (!formObject.multiline) {
continue FontSize;
} else {
if ((textHeight + lineSpacing) * (lineCount + 2) + lineSpacing > height) {
// If the Text is higher than the
// FieldObject
continue FontSize;
}
lastWordInLine = key; // go on
}
} else if (isLastWord) {
lastWordInLine = key;
} else {
if (formObject.multiline && (textHeight + lineSpacing) * (lineCount + 2) + lineSpacing > height) {
// If the Text is higher than the FieldObject
continue FontSize;
}
}
var line = "";
for (var x = firstWordInLine; x <= lastWordInLine; x++) {
line += textSplit[x] + " ";
} // Remove last blank
line = line.substr(line.length - 1) == " " ? line.substr(0, line.length - 1) : line; // lastLength -= blankSpace.width;
lastLength = calculateFontSpace(line, fontSize + "px", font).width; // Calculate startX
switch (formObject.Q) {
case 2:
// Right justified
startX = width - lastLength - borderPadding;
break;
case 1:
// Q = 1 := Text-Alignment: Center
startX = (width - lastLength) / 2;
break;
case 0:
default:
startX = borderPadding;
break;
}
text += startX.toFixed(2) + " " + lastY.toFixed(2) + " Td\n";
text += "(" + line + ") Tj\n"; // reset X in PDF
text += -startX.toFixed(2) + " 0 Td\n"; // After a Line, adjust y position
lastY = -(fontSize + lineSpacing);
lastLength = 0;
firstWordInLine = lastWordInLine + 1;
lineCount++;
lastLine = "";
continue Line;
}
}
break;
}
returnValue.text = text;
returnValue.fontSize = fontSize;
return returnValue;
};
/**
* Small workaround for calculating the TextMetric approximately.
*
* @param text
* @param fontsize
* @returns {TextMetrics} (Has Height and Width)
*/
var calculateFontSpace = function calculateFontSpace(text, fontSize, fontType) {
fontType = fontType || "helvetica";
var font = scope.internal.getFont(fontType);
var width = scope.getStringUnitWidth(text, {
font: font,
fontSize: parseFloat(fontSize),
charSpace: 0
}) * parseFloat(fontSize);
var height = scope.getStringUnitWidth("3", {
font: font,
fontSize: parseFloat(fontSize),
charSpace: 0
}) * parseFloat(fontSize) * 1.5;
var result = {
height: height,
width: width
};
return result;
};
var acroformPluginTemplate = {
fields: [],
xForms: [],
/**
* acroFormDictionaryRoot contains information about the AcroForm
* Dictionary 0: The Event-Token, the AcroFormDictionaryCallback has
* 1: The Object ID of the Root
*/
acroFormDictionaryRoot: null,
/**
* After the PDF gets evaluated, the reference to the root has to be
* reset, this indicates, whether the root has already been printed
* out
*/
printedOut: false,
internal: null,
isInitialized: false
};
var annotReferenceCallback = function annotReferenceCallback() {
var fields = scope.internal.acroformPlugin.acroFormDictionaryRoot.Fields;
for (var i in fields) {
if (fields.hasOwnProperty(i)) {
var formObject = fields[i]; // add Annot Reference!
if (formObject.hasAnnotation) {
// If theres an Annotation Widget in the Form Object, put the
// Reference in the /Annot array
createAnnotationReference.call(scope, formObject);
}
}
}
};
var putForm = function putForm(formObject) {
if (scope.internal.acroformPlugin.printedOut) {
scope.internal.acroformPlugin.printedOut = false;
scope.internal.acroformPlugin.acroFormDictionaryRoot = null;
}
if (!scope.internal.acroformPlugin.acroFormDictionaryRoot) {
initializeAcroForm.call(scope);
}
scope.internal.acroformPlugin.acroFormDictionaryRoot.Fields.push(formObject);
};
/**
* Create the Reference to the widgetAnnotation, so that it gets referenced
* in the Annot[] int the+ (Requires the Annotation Plugin)
*/
var createAnnotationReference = function createAnnotationReference(object) {
var options = {
type: "reference",
object: object
};
scope.annotationPlugin.annotations[scope.internal.getPageInfo(object.page).pageNumber].push(options);
}; // Callbacks
var putCatalogCallback = function putCatalogCallback() {
// Put reference to AcroForm to DocumentCatalog
if (typeof scope.internal.acroformPlugin.acroFormDictionaryRoot != "undefined") {
// for safety, shouldn't normally be the case
scope.internal.write("/AcroForm " + scope.internal.acroformPlugin.acroFormDictionaryRoot.objId + " " + 0 + " R");
} else {
console.log("Root missing...");
}
};
/**
* Adds /Acroform X 0 R to Document Catalog, and creates the AcroForm
* Dictionary
*/
var AcroFormDictionaryCallback = function AcroFormDictionaryCallback() {
// Remove event
scope.internal.events.unsubscribe(scope.internal.acroformPlugin.acroFormDictionaryRoot._eventID);
delete scope.internal.acroformPlugin.acroFormDictionaryRoot._eventID;
scope.internal.acroformPlugin.printedOut = true;
};
/**
* Creates the single Fields and writes them into the Document
*
* If fieldArray is set, use the fields that are inside it instead of the
* fields from the AcroRoot (for the FormXObjects...)
*/
var createFieldCallback = function createFieldCallback(fieldArray) {
var standardFields = !fieldArray;
if (!fieldArray) {
// in case there is no fieldArray specified, we want to print out
// the Fields of the AcroForm
// Print out Root
scope.internal.newObjectDeferredBegin(scope.internal.acroformPlugin.acroFormDictionaryRoot.objId);
scope.internal.out(scope.internal.acroformPlugin.acroFormDictionaryRoot.getString());
}
var fieldArray = fieldArray || scope.internal.acroformPlugin.acroFormDictionaryRoot.Kids;
for (var i in fieldArray) {
if (fieldArray.hasOwnProperty(i)) {
var form = fieldArray[i];
var oldRect = form.Rect;
if (form.Rect) {
form.Rect = calculateCoordinates.call(this, form.Rect);
} // Start Writing the Object
scope.internal.newObjectDeferredBegin(form.objId);
var content = form.objId + " 0 obj\n<<\n";
if (_typeof(form) === "object" && typeof form.getContent === "function") {
content += form.getContent();
}
form.Rect = oldRect;
if (form.hasAppearanceStream && !form.appearanceStreamContent) {
// Calculate Appearance
var appearance = calculateAppearanceStream.call(this, form);
content += "/AP << /N " + appearance + " >>\n";
scope.internal.acroformPlugin.xForms.push(appearance);
} // Assume AppearanceStreamContent is a Array with N,R,D (at least
// one of them!)
if (form.appearanceStreamContent) {
content += "/AP << "; // Iterate over N,R and D
for (var k in form.appearanceStreamContent) {
if (form.appearanceStreamContent.hasOwnProperty(k)) {
var value = form.appearanceStreamContent[k];
content += "/" + k + " ";
content += "<< ";
if (Object.keys(value).length >= 1 || Array.isArray(value)) {
// appearanceStream is an Array or Object!
for (var i in value) {
if (value.hasOwnProperty(i)) {
var obj = value[i];
if (typeof obj === "function") {
// if Function is referenced, call it in order
// to get the FormXObject
obj = obj.call(this, form);
}
content += "/" + i + " " + obj + " "; // In case the XForm is already used, e.g. OffState
// of CheckBoxes, don't add it
if (!(scope.internal.acroformPlugin.xForms.indexOf(obj) >= 0)) scope.internal.acroformPlugin.xForms.push(obj);
}
}
} else {
var obj = value;
if (typeof obj === "function") {
// if Function is referenced, call it in order to
// get the FormXObject
obj = obj.call(this, form);
}
content += "/" + i + " " + obj + " \n";
if (!(scope.internal.acroformPlugin.xForms.indexOf(obj) >= 0)) scope.internal.acroformPlugin.xForms.push(obj);
}
content += " >>\n";
}
} // appearance stream is a normal Object..
content += ">>\n";
}
content += ">>\nendobj\n";
scope.internal.out(content);
}
}
if (standardFields) {
createXFormObjectCallback.call(this, scope.internal.acroformPlugin.xForms);
}
};
var createXFormObjectCallback = function createXFormObjectCallback(fieldArray) {
for (var i in fieldArray) {
if (fieldArray.hasOwnProperty(i)) {
var key = i;
var form = fieldArray[i]; // Start Writing the Object
scope.internal.newObjectDeferredBegin(form && form.objId);
var content = "";
if (_typeof(form) === "object" && typeof form.getString === "function") {
content = form.getString();
}
scope.internal.out(content);
delete fieldArray[key];
}
}
};
var initializeAcroForm = function initializeAcroForm() {
if (this.internal !== undefined && (this.internal.acroformPlugin === undefined || this.internal.acroformPlugin.isInitialized === false)) {
scope = this;
AcroFormField.FieldNum = 0;
this.internal.acroformPlugin = JSON.parse(JSON.stringify(acroformPluginTemplate));
if (this.internal.acroformPlugin.acroFormDictionaryRoot) {
// return;
throw new Error("Exception while creating AcroformDictionary");
}
scaleFactor = scope.internal.scaleFactor;
pageHeight = scope.internal.pageSize.getHeight(); // The Object Number of the AcroForm Dictionary
scope.internal.acroformPlugin.acroFormDictionaryRoot = new AcroFormDictionary(); // add Callback for creating the AcroForm Dictionary
scope.internal.acroformPlugin.acroFormDictionaryRoot._eventID = scope.internal.events.subscribe("postPutResources", AcroFormDictionaryCallback);
scope.internal.events.subscribe("buildDocument", annotReferenceCallback); // buildDocument
// Register event, that is triggered when the DocumentCatalog is
// written, in order to add /AcroForm
scope.internal.events.subscribe("putCatalog", putCatalogCallback); // Register event, that creates all Fields
scope.internal.events.subscribe("postPutPages", createFieldCallback);
scope.internal.acroformPlugin.isInitialized = true;
}
};
var arrayToPdfArray = function arrayToPdfArray(array) {
if (Array.isArray(array)) {
var content = " [";
for (var i in array) {
if (array.hasOwnProperty(i)) {
var element = array[i].toString();
content += element;
content += i < array.length - 1 ? " " : "";
}
}
content += "]";
return content;
}
};
var toPdfString = function toPdfString(string) {
string = string || ""; // put Bracket at the Beginning of the String
if (string.indexOf("(") !== 0) {
string = "(" + string;
}
if (string.substring(string.length - 1) != ")") {
string += ")";
}
return string;
}; // ##########################
// Classes
// ##########################
var AcroFormPDFObject = function AcroFormPDFObject() {
// The Object ID in the PDF Object Model
// todo
var _objId;
Object.defineProperty(this, "objId", {
get: function get() {
if (!_objId) {
_objId = scope.internal.newObjectDeferred();
}
if (!_objId) {
console.log("Couldn't create Object ID");
}
return _objId;
},
configurable: false
});
};
AcroFormPDFObject.prototype.toString = function () {
return this.objId + " 0 R";
};
AcroFormPDFObject.prototype.getString = function () {
var res = this.objId + " 0 obj\n<<";
var content = this.getContent();
res += content + ">>\n";
if (this.stream) {
res += "stream\n";
res += this.stream;
res += "\nendstream\n";
}
res += "endobj\n";
return res;
};
AcroFormPDFObject.prototype.getContent = function () {
/**
* Prints out all enumerable Variables from the Object
*
* @param fieldObject
* @returns {string}
*/
var createContentFromFieldObject = function createContentFromFieldObject(fieldObject) {
var content = "";
var keys = Object.keys(fieldObject).filter(function (key) {
return key != "content" && key != "appearanceStreamContent" && key.substring(0, 1) != "_";
});
for (var i in keys) {
if (keys.hasOwnProperty(i)) {
var key = keys[i];
var value = fieldObject[key];
/*
* if (key == 'Rect' && value) { value =
* AcroForm.internal.calculateCoordinates.call(jsPDF.API.acroformPlugin.internal,
* value); }
*/
if (value) {
if (Array.isArray(value)) {
content += "/" + key + " " + arrayToPdfArray(value) + "\n";
} else if (value instanceof AcroFormPDFObject) {
// In case it is a reference to another PDFObject,
// take the referennce number
content += "/" + key + " " + value.objId + " 0 R" + "\n";
} else {
content += "/" + key + " " + value + "\n";
}
}
}
}
return content;
};
var object = "";
object += createContentFromFieldObject(this);
return object;
};
var AcroFormXObject = function AcroFormXObject() {
AcroFormPDFObject.call(this);
this.Type = "/XObject";
this.Subtype = "/Form";
this.FormType = 1;
this.BBox;
this.Matrix;
this.Resources = "2 0 R";
this.PieceInfo;
var _stream;
Object.defineProperty(this, "Length", {
enumerable: true,
get: function get() {
return _stream !== undefined ? _stream.length : 0;
}
});
Object.defineProperty(this, "stream", {
enumerable: false,
set: function set(val) {
_stream = val.trim();
},
get: function get() {
if (_stream) {
return _stream;
} else {
return null;
}
}
});
};
inherit(AcroFormXObject, AcroFormPDFObject); // ##### The Objects, the User can Create:
var AcroFormDictionary = function AcroFormDictionary() {
AcroFormPDFObject.call(this);
var _Kids = [];
Object.defineProperty(this, "Kids", {
enumerable: false,
configurable: true,
get: function get() {
if (_Kids.length > 0) {
return _Kids;
} else {
return;
}
}
});
Object.defineProperty(this, "Fields", {
enumerable: true,
configurable: true,
get: function get() {
return _Kids;
}
}); // Default Appearance
this.DA;
};
inherit(AcroFormDictionary, AcroFormPDFObject); // The Field Object contains the Variables, that every Field needs
// Rectangle for Appearance: lower_left_X, lower_left_Y, width, height
var AcroFormField = function AcroFormField() {
AcroFormPDFObject.call(this);
var _Rect = null;
Object.defineProperty(this, "Rect", {
enumerable: true,
configurable: false,
get: function get() {
if (!_Rect) {
return;
}
var tmp = _Rect; // var calculatedRes =
// AcroForm.internal.calculateCoordinates(_Rect); // do
// later!
return tmp;
},
set: function set(val) {
_Rect = val;
}
});
var _FT = "";
Object.defineProperty(this, "FT", {
enumerable: true,
set: function set(val) {
_FT = val;
},
get: function get() {
return _FT;
}
});
var _F = 4;
Object.defineProperty(this, "F", {
enumerable: true,
set: function set(val) {
_F = val;
},
get: function get() {
return _F;
}
});
/**
* The Partial name of the Field Object. It has to be unique.
*/
var _T = null;
Object.defineProperty(this, "T", {
enumerable: true,
configurable: false,
set: function set(val) {
_T = val;
},
get: function get() {
if (!_T || _T.length < 1) {
if (this instanceof AcroFormChildClass) {
// In case of a Child from a Radio´Group, you don't
// need a FieldName!!!
return;
}
return "(FieldObject" + AcroFormField.FieldNum++ + ")";
}
if (_T.substring(0, 1) == "(" && _T.substring(_T.length - 1)) {
return _T;
}
return "(" + _T + ")";
}
});
var _DA = null; // Defines the default appearance (Needed for variable Text)
Object.defineProperty(this, "DA", {
enumerable: true,
get: function get() {
if (!_DA) {
return;
}
return "(" + _DA + ")";
},
set: function set(val) {
_DA = val;
}
});
var _DV = null; // Defines the default value
Object.defineProperty(this, "DV", {
enumerable: true,
configurable: true,
get: function get() {
if (!_DV) {
return;
}
return _DV;
},
set: function set(val) {
_DV = val;
}
});
var _V = null; // Defines the default value
Object.defineProperty(this, "V", {
enumerable: true,
configurable: true,
get: function get() {
if (!_V) {
return;
}
return _V;
},
set: function set(val) {
_V = val;
}
}); // this.Type = "/Annot";
// this.Subtype = "/Widget";
Object.defineProperty(this, "Type", {
enumerable: true,
get: function get() {
return this.hasAnnotation ? "/Annot" : null;
}
});
Object.defineProperty(this, "Subtype", {
enumerable: true,
get: function get() {
return this.hasAnnotation ? "/Widget" : null;
}
});
/**
*
* @type {Array}
*/
this.BG;
Object.defineProperty(this, "hasAnnotation", {
enumerable: false,
get: function get() {
if (this.Rect || this.BC || this.BG) {
return true;
}
return false;
}
});
Object.defineProperty(this, "hasAppearanceStream", {
enumerable: false,
configurable: true,
writable: true
});
Object.defineProperty(this, "page", {
enumerable: false,
configurable: true,
writable: true
});
};
inherit(AcroFormField, AcroFormPDFObject);
var AcroFormChoiceField = function AcroFormChoiceField() {
AcroFormField.call(this); // Field Type = Choice Field
this.FT = "/Ch"; // options
this.Opt = [];
this.V = "()"; // Top Index
this.TI = 0;
/**
* Defines, whether the
*
* @type {boolean}
*/
var _combo = false;
Object.defineProperty(this, "combo", {
enumerable: false,
get: function get() {
return _combo;
},
set: function set(val) {
_combo = val;
}
});
/**
* Defines, whether the Choice Field is an Edit Field. An Edit Field
* is automatically an Combo Field.
*/
Object.defineProperty(this, "edit", {
enumerable: true,
set: function set(val) {
if (val == true) {
this._edit = true; // ComboBox has to be true
this.combo = true;
} else {
this._edit = false;
}
},
get: function get() {
if (!this._edit) {
return false;
}
return this._edit;
},
configurable: false
});
this.hasAppearanceStream = true;
};
inherit(AcroFormChoiceField, AcroFormField);
var AcroFormListBox = function AcroFormListBox() {
AcroFormChoiceField.call(this);
this.combo = false;
};
inherit(AcroFormListBox, AcroFormChoiceField);
var AcroFormComboBox = function AcroFormComboBox() {
AcroFormListBox.call(this);
this.combo = true;
};
inherit(AcroFormComboBox, AcroFormListBox);
var AcroFormEditBox = function AcroFormEditBox() {
AcroFormComboBox.call(this);
this.edit = true;
};
inherit(AcroFormEditBox, AcroFormComboBox);
var AcroFormButton = function AcroFormButton() {
AcroFormField.call(this);
this.FT = "/Btn"; // this.hasAnnotation = true;
};
inherit(AcroFormButton, AcroFormField);
var AcroFormPushButton = function AcroFormPushButton() {
AcroFormButton.call(this);
var _pushbutton = true;
Object.defineProperty(this, "pushbutton", {
enumerable: false,
get: function get() {
return _pushbutton;
},
set: function set(val) {
_pushbutton = val;
}
});
};
inherit(AcroFormPushButton, AcroFormButton);
var AcroFormRadioButton = function AcroFormRadioButton() {
AcroFormButton.call(this);
var _radio = true;
Object.defineProperty(this, "radio", {
enumerable: false,
get: function get() {
return _radio;
},
set: function set(val) {
_radio = val;
}
});
var _Kids = [];
Object.defineProperty(this, "Kids", {
enumerable: true,
get: function get() {
if (_Kids.length > 0) {
return _Kids;
}
}
});
Object.defineProperty(this, "__Kids", {
get: function get() {
return _Kids;
}
});
var _noToggleToOff;
Object.defineProperty(this, "noToggleToOff", {
enumerable: false,
get: function get() {
return _noToggleToOff;
},
set: function set(val) {
_noToggleToOff = val;
}
}); // this.hasAnnotation = false;
};
inherit(AcroFormRadioButton, AcroFormButton);
/*
* The Child classs of a RadioButton (the radioGroup) -> The single
* Buttons
*/
var AcroFormChildClass = function AcroFormChildClass(parent, name) {
AcroFormField.call(this);
this.Parent = parent; // todo: set AppearanceType as variable that can be set from the
// outside...
this._AppearanceType = AcroFormAppearance.RadioButton.Circle; // The Default appearanceType is the Circle
this.appearanceStreamContent = this._AppearanceType.createAppearanceStream(name); // Set Print in the Annot Flag
this.F = setBitPosition(this.F, 3, 1); // Set AppearanceCharacteristicsDictionary with default appearance
// if field is not interacting with user
this.MK = this._AppearanceType.createMK(); // (8) -> Cross, (1)-> Circle, ()-> nothing
// Default Appearance is Off
this.AS = "/Off"; // + name;
this._Name = name;
};
inherit(AcroFormChildClass, AcroFormField);
AcroFormRadioButton.prototype.setAppearance = function (appearance) {
if (!("createAppearanceStream" in appearance && "createMK" in appearance)) {
console.log("Couldn't assign Appearance to RadioButton. Appearance was Invalid!");
return;
}
for (var i in this.__Kids) {
if (this.__Kids.hasOwnProperty(i)) {
var child = this.__Kids[i];
child.appearanceStreamContent = appearance.createAppearanceStream(child._Name);
child.MK = appearance.createMK();
}
}
};
AcroFormRadioButton.prototype.createOption = function (name) {
var parent = this;
var kidCount = this.__Kids.length; // Create new Child for RadioGroup
var child = new AcroFormChildClass(parent, name); // Add to Parent
this.__Kids.push(child);
jsPDFAPI.addField(child);
return child;
};
/**
* @name AcroFormCheckBox
*
* @memberOf AcroForm
* @function
*/
var AcroFormCheckBox = function AcroFormCheckBox() {
AcroFormButton.call(this);
this.appearanceStreamContent = AcroFormAppearance.CheckBox.createAppearanceStream();
this.MK = AcroFormAppearance.CheckBox.createMK();
this.AS = "/On";
this.V = "/On";
};
inherit(AcroFormCheckBox, AcroFormButton);
var AcroFormTextField = function AcroFormTextField() {
AcroFormField.call(this);
this.DA = AcroFormAppearance.createDefaultAppearanceStream();
this.F = 4;
var _V;
Object.defineProperty(this, "V", {
get: function get() {
if (_V) {
return toPdfString(_V);
} else {
return _V;
}
},
enumerable: true,
set: function set(val) {
_V = val;
}
});
var _DV;
Object.defineProperty(this, "DV", {
get: function get() {
if (_DV) {
return toPdfString(_DV);
} else {
return _DV;
}
},
enumerable: true,
set: function set(val) {
_DV = val;
}
});
var _multiline = false;
Object.defineProperty(this, "multiline", {
enumerable: false,
get: function get() {
return _multiline;
},
set: function set(val) {
_multiline = val;
}
});
/**
* For PDF 1.4
*
* @type {boolean}
*/
var _fileSelect = false;
Object.defineProperty(this, "fileSelect", {
enumerable: false,
get: function get() {
return _fileSelect;
},
set: function set(val) {
_fileSelect = val;
}
});
/**
* For PDF 1.4
*
* @type {boolean}
*/
var _doNotSpellCheck = false;
Object.defineProperty(this, "doNotSpellCheck", {
enumerable: false,
get: function get() {
return _doNotSpellCheck;
},
set: function set(val) {
_doNotSpellCheck = val;
}
});
/**
* For PDF 1.4
*
* @type {boolean}
*/
var _doNotScroll = false;
Object.defineProperty(this, "doNotScroll", {
enumerable: false,
get: function get() {
return _doNotScroll;
},
set: function set(val) {
_doNotScroll = val;
}
});
var _MaxLen = false;
Object.defineProperty(this, "MaxLen", {
enumerable: true,
get: function get() {
return _MaxLen;
},
set: function set(val) {
_MaxLen = val;
}
});
Object.defineProperty(this, "hasAppearanceStream", {
enumerable: false,
get: function get() {
return this.V || this.DV;
}
});
};
inherit(AcroFormTextField, AcroFormField);
var AcroFormPasswordField = function AcroFormPasswordField() {
AcroFormTextField.call(this);
var _password = true;
Object.defineProperty(this, "password", {
enumerable: false,
get: function get() {
return _password;
},
set: function set(val) {
_password = val;
}
});
};
inherit(AcroFormPasswordField, AcroFormTextField); // Contains Methods for creating standard appearances
var AcroFormAppearance = {
CheckBox: {
createAppearanceStream: function createAppearanceStream() {
var appearance = {
N: {
On: AcroFormAppearance.CheckBox.YesNormal
},
D: {
On: AcroFormAppearance.CheckBox.YesPushDown,
Off: AcroFormAppearance.CheckBox.OffPushDown
}
};
return appearance;
},
/**
* If any other icons are needed, the number between the
* brackets can be changed
*
* @returns {string}
*/
createMK: function createMK() {
return "<< /CA (3)>>";
},
/**
* Returns the standard On Appearance for a CheckBox
*
* @returns {AcroFormXObject}
*/
YesPushDown: function YesPushDown(formObject) {
var xobj = createFormXObject(formObject);
var stream = [];
var zapfDingbatsId = scope.internal.getFont("zapfdingbats", "normal").id;
formObject.Q = 1; // set text-alignment as centered
var calcRes = calculateX(formObject, "3", "ZapfDingbats", 50);
stream.push("0.749023 g");
stream.push("0 0 " + AcroFormAppearance.internal.getWidth(formObject).toFixed(2) + " " + AcroFormAppearance.internal.getHeight(formObject).toFixed(2) + " re");
stream.push("f");
stream.push("BMC");
stream.push("q");
stream.push("0 0 1 rg");
stream.push("/" + zapfDingbatsId + " " + calcRes.fontSize.toFixed(2) + " Tf 0 g");
stream.push("BT");
stream.push(calcRes.text);
stream.push("ET");
stream.push("Q");
stream.push("EMC");
xobj.stream = stream.join("\n");
return xobj;
},
YesNormal: function YesNormal(formObject) {
var xobj = createFormXObject(formObject);
var zapfDingbatsId = scope.internal.getFont("zapfdingbats", "normal").id;
var stream = [];
formObject.Q = 1; // set text-alignment as centered
var height = AcroFormAppearance.internal.getHeight(formObject);
var width = AcroFormAppearance.internal.getWidth(formObject);
var calcRes = calculateX(formObject, "3", "ZapfDingbats", height * 0.9);
stream.push("1 g");
stream.push("0 0 " + width.toFixed(2) + " " + height.toFixed(2) + " re");
stream.push("f");
stream.push("q");
stream.push("0 0 1 rg");
stream.push("0 0 " + (width - 1).toFixed(2) + " " + (height - 1).toFixed(2) + " re");
stream.push("W");
stream.push("n");
stream.push("0 g");
stream.push("BT");
stream.push("/" + zapfDingbatsId + " " + calcRes.fontSize.toFixed(2) + " Tf 0 g");
stream.push(calcRes.text);
stream.push("ET");
stream.push("Q");
xobj.stream = stream.join("\n");
return xobj;
},
/**
* Returns the standard Off Appearance for a CheckBox
*
* @returns {AcroFormXObject}
*/
OffPushDown: function OffPushDown(formObject) {
var xobj = createFormXObject(formObject);
var stream = [];
stream.push("0.749023 g");
stream.push("0 0 " + AcroFormAppearance.internal.getWidth(formObject).toFixed(2) + " " + AcroFormAppearance.internal.getHeight(formObject).toFixed(2) + " re");
stream.push("f");
xobj.stream = stream.join("\n");
return xobj;
}
},
RadioButton: {
Circle: {
createAppearanceStream: function createAppearanceStream(name) {
var appearanceStreamContent = {
D: {
Off: AcroFormAppearance.RadioButton.Circle.OffPushDown
},
N: {}
};
appearanceStreamContent.N[name] = AcroFormAppearance.RadioButton.Circle.YesNormal;
appearanceStreamContent.D[name] = AcroFormAppearance.RadioButton.Circle.YesPushDown;
return appearanceStreamContent;
},
createMK: function createMK() {
return "<< /CA (l)>>";
},
YesNormal: function YesNormal(formObject) {
var xobj = createFormXObject(formObject);
var stream = []; // Make the Radius of the Circle relative to min(height,
// width) of formObject
var DotRadius = AcroFormAppearance.internal.getWidth(formObject) <= AcroFormAppearance.internal.getHeight(formObject) ? AcroFormAppearance.internal.getWidth(formObject) / 4 : AcroFormAppearance.internal.getHeight(formObject) / 4; // The Borderpadding...
DotRadius *= 0.9;
var c = AcroFormAppearance.internal.Bezier_C;
/*
* The Following is a Circle created with Bezier-Curves.
*/
stream.push("q");
stream.push("1 0 0 1 " + AcroFormAppearance.internal.getWidth(formObject) / 2 + " " + AcroFormAppearance.internal.getHeight(formObject) / 2 + " cm");
stream.push(DotRadius + " 0 m");
stream.push(DotRadius + " " + DotRadius * c + " " + DotRadius * c + " " + DotRadius + " 0 " + DotRadius + " c");
stream.push("-" + DotRadius * c + " " + DotRadius + " -" + DotRadius + " " + DotRadius * c + " -" + DotRadius + " 0 c");
stream.push("-" + DotRadius + " -" + DotRadius * c + " -" + DotRadius * c + " -" + DotRadius + " 0 -" + DotRadius + " c");
stream.push(DotRadius * c + " -" + DotRadius + " " + DotRadius + " -" + DotRadius * c + " " + DotRadius + " 0 c");
stream.push("f");
stream.push("Q");
xobj.stream = stream.join("\n");
return xobj;
},
YesPushDown: function YesPushDown(formObject) {
var xobj = createFormXObject(formObject);
var stream = [];
var DotRadius = AcroFormAppearance.internal.getWidth(formObject) <= AcroFormAppearance.internal.getHeight(formObject) ? AcroFormAppearance.internal.getWidth(formObject) / 4 : AcroFormAppearance.internal.getHeight(formObject) / 4; // The Borderpadding...
DotRadius *= 0.9; // Save results for later use; no need to waste
// processor ticks on doing math
var k = DotRadius * 2; // var c = AcroFormAppearance.internal.Bezier_C;
var kc = k * AcroFormAppearance.internal.Bezier_C;
var dc = DotRadius * AcroFormAppearance.internal.Bezier_C;
stream.push("0.749023 g");
stream.push("q");
stream.push("1 0 0 1 " + (AcroFormAppearance.internal.getWidth(formObject) / 2).toFixed(2) + " " + (AcroFormAppearance.internal.getHeight(formObject) / 2).toFixed(2) + " cm");
stream.push(k + " 0 m");
stream.push(k + " " + kc + " " + kc + " " + k + " 0 " + k + " c");
stream.push("-" + kc + " " + k + " -" + k + " " + kc + " -" + k + " 0 c");
stream.push("-" + k + " -" + kc + " -" + kc + " -" + k + " 0 -" + k + " c");
stream.push(kc + " -" + k + " " + k + " -" + kc + " " + k + " 0 c");
stream.push("f");
stream.push("Q");
stream.push("0 g");
stream.push("q");
stream.push("1 0 0 1 " + (AcroFormAppearance.internal.getWidth(formObject) / 2).toFixed(2) + " " + (AcroFormAppearance.internal.getHeight(formObject) / 2).toFixed(2) + " cm");
stream.push(DotRadius + " 0 m");
stream.push("" + DotRadius + " " + dc + " " + dc + " " + DotRadius + " 0 " + DotRadius + " c");
stream.push("-" + dc + " " + DotRadius + " -" + DotRadius + " " + dc + " -" + DotRadius + " 0 c");
stream.push("-" + DotRadius + " -" + dc + " -" + dc + " -" + DotRadius + " 0 -" + DotRadius + " c");
stream.push(dc + " -" + DotRadius + " " + DotRadius + " -" + dc + " " + DotRadius + " 0 c");
stream.push("f");
stream.push("Q");
xobj.stream = stream.join("\n");
return xobj;
},
OffPushDown: function OffPushDown(formObject) {
var xobj = createFormXObject(formObject);
var stream = [];
var DotRadius = AcroFormAppearance.internal.getWidth(formObject) <= AcroFormAppearance.internal.getHeight(formObject) ? AcroFormAppearance.internal.getWidth(formObject) / 4 : AcroFormAppearance.internal.getHeight(formObject) / 4; // The Borderpadding...
DotRadius *= 0.9; // Save results for later use; no need to waste
// processor ticks on doing math
var k = DotRadius * 2; // var c = AcroFormAppearance.internal.Bezier_C;
var kc = k * AcroFormAppearance.internal.Bezier_C;
stream.push("0.749023 g");
stream.push("q");
stream.push("1 0 0 1 " + (AcroFormAppearance.internal.getWidth(formObject) / 2).toFixed(2) + " " + (AcroFormAppearance.internal.getHeight(formObject) / 2).toFixed(2) + " cm");
stream.push(k + " 0 m");
stream.push(k + " " + kc + " " + kc + " " + k + " 0 " + k + " c");
stream.push("-" + kc + " " + k + " -" + k + " " + kc + " -" + k + " 0 c");
stream.push("-" + k + " -" + kc + " -" + kc + " -" + k + " 0 -" + k + " c");
stream.push(kc + " -" + k + " " + k + " -" + kc + " " + k + " 0 c");
stream.push("f");
stream.push("Q");
xobj.stream = stream.join("\n");
return xobj;
}
},
Cross: {
/**
* Creates the Actual AppearanceDictionary-References
*
* @param {string} name
* @returns {Object}
* @ignore
*/
createAppearanceStream: function createAppearanceStream(name) {
var appearanceStreamContent = {
D: {
Off: AcroFormAppearance.RadioButton.Cross.OffPushDown
},
N: {}
};
appearanceStreamContent.N[name] = AcroFormAppearance.RadioButton.Cross.YesNormal;
appearanceStreamContent.D[name] = AcroFormAppearance.RadioButton.Cross.YesPushDown;
return appearanceStreamContent;
},
createMK: function createMK() {
return "<< /CA (8)>>";
},
YesNormal: function YesNormal(formObject) {
var xobj = createFormXObject(formObject);
var stream = [];
var cross = AcroFormAppearance.internal.calculateCross(formObject);
stream.push("q");
stream.push("1 1 " + (AcroFormAppearance.internal.getWidth(formObject) - 2).toFixed(2) + " " + (AcroFormAppearance.internal.getHeight(formObject) - 2).toFixed(2) + " re");
stream.push("W");
stream.push("n");
stream.push(cross.x1.x.toFixed(2) + " " + cross.x1.y.toFixed(2) + " m");
stream.push(cross.x2.x.toFixed(2) + " " + cross.x2.y.toFixed(2) + " l");
stream.push(cross.x4.x.toFixed(2) + " " + cross.x4.y.toFixed(2) + " m");
stream.push(cross.x3.x.toFixed(2) + " " + cross.x3.y.toFixed(2) + " l");
stream.push("s");
stream.push("Q");
xobj.stream = stream.join("\n");
return xobj;
},
YesPushDown: function YesPushDown(formObject) {
var xobj = createFormXObject(formObject);
var cross = AcroFormAppearance.internal.calculateCross(formObject);
var stream = [];
stream.push("0.749023 g");
stream.push("0 0 " + AcroFormAppearance.internal.getWidth(formObject).toFixed(2) + " " + AcroFormAppearance.internal.getHeight(formObject).toFixed(2) + " re");
stream.push("f");
stream.push("q");
stream.push("1 1 " + (AcroFormAppearance.internal.getWidth(formObject) - 2).toFixed(2) + " " + (AcroFormAppearance.internal.getHeight(formObject) - 2).toFixed(2) + " re");
stream.push("W");
stream.push("n");
stream.push(cross.x1.x.toFixed(2) + " " + cross.x1.y.toFixed(2) + " m");
stream.push(cross.x2.x.toFixed(2) + " " + cross.x2.y.toFixed(2) + " l");
stream.push(cross.x4.x.toFixed(2) + " " + cross.x4.y.toFixed(2) + " m");
stream.push(cross.x3.x.toFixed(2) + " " + cross.x3.y.toFixed(2) + " l");
stream.push("s");
stream.push("Q");
xobj.stream = stream.join("\n");
return xobj;
},
OffPushDown: function OffPushDown(formObject) {
var xobj = createFormXObject(formObject);
var stream = [];
stream.push("0.749023 g");
stream.push("0 0 " + AcroFormAppearance.internal.getWidth(formObject).toFixed(2) + " " + AcroFormAppearance.internal.getHeight(formObject).toFixed(2) + " re");
stream.push("f");
xobj.stream = stream.join("\n");
return xobj;
}
}
},
/**
* Returns the standard Appearance
*
* @returns {AcroFormXObject}
*/
createDefaultAppearanceStream: function createDefaultAppearanceStream(formObject) {
// Set Helvetica to Standard Font (size: auto)
// Color: Black
return "/F1 0 Tf 0 g";
}
};
AcroFormAppearance.internal = {
Bezier_C: 0.551915024494,
calculateCross: function calculateCross(formObject) {
var min = function min(x, y) {
return x > y ? y : x;
};
var width = AcroFormAppearance.internal.getWidth(formObject);
var height = AcroFormAppearance.internal.getHeight(formObject);
var a = min(width, height);
var cross = {
x1: {
// upperLeft
x: (width - a) / 2,
y: (height - a) / 2 + a // height - borderPadding
},
x2: {
// lowerRight
x: (width - a) / 2 + a,
y: (height - a) / 2 // borderPadding
},
x3: {
// lowerLeft
x: (width - a) / 2,
y: (height - a) / 2 // borderPadding
},
x4: {
// upperRight
x: (width - a) / 2 + a,
y: (height - a) / 2 + a // height - borderPadding
}
};
return cross;
}
};
AcroFormAppearance.internal.getWidth = function (formObject) {
var result = 0;
if (_typeof(formObject) === "object") {
result = scale(formObject.Rect[2]); // (formObject.Rect[2] -
// formObject.Rect[0]) || 0;
}
return result;
};
AcroFormAppearance.internal.getHeight = function (formObject) {
var result = 0;
if (_typeof(formObject) === "object") {
result = scale(formObject.Rect[3]); // (formObject.Rect[1] -
// formObject.Rect[3]) || 0;
}
return result;
}; // Public:
/**
* Add an AcroForm-Field to the {jsPDF}-instance
*
* @memberOf AcroForm
* @name addField
* @param {Object} fieldObject
* @returns {jsPDF}
*/
jsPDFAPI.addField = function (fieldObject) {
initializeAcroForm.call(this); // var opt = parseOptions(fieldObject);
if (fieldObject instanceof AcroFormTextField) {
this.addTextField.call(this, fieldObject);
} else if (fieldObject instanceof AcroFormChoiceField) {
this.addChoiceField.call(this, fieldObject);
} else if (fieldObject instanceof AcroFormButton) {
this.addButton.call(this, fieldObject);
} else if (fieldObject instanceof AcroFormChildClass) {
putForm.call(this, fieldObject);
} else if (fieldObject) {
// try to put..
putForm.call(this, fieldObject);
}
fieldObject.page = scope.internal.getCurrentPageInfo().pageNumber;
return this;
};
/**
* @name addButton
* @param {AcroFormButton}
* @memberOf AcroForm
*/
jsPDFAPI.addButton = function (opts) {
initializeAcroForm.call(this);
var options = opts || new AcroFormField();
options.FT = "/Btn";
options.Ff = calculateFlagsOnOptions(options.Ff, opts, scope.internal.getPDFVersion());
putForm.call(this, options);
};
jsPDFAPI.addTextField = function (opts) {
initializeAcroForm.call(this);
var options = opts || new AcroFormField();
options.FT = "/Tx";
options.Ff = calculateFlagsOnOptions(options.Ff, opts, scope.internal.getPDFVersion()); // Add field
putForm.call(this, options);
};
jsPDFAPI.addChoiceField = function (opts) {
initializeAcroForm.call(this);
var options = opts || new AcroFormField();
options.FT = "/Ch";
options.Ff = calculateFlagsOnOptions(options.Ff, opts, scope.internal.getPDFVersion()); // options.hasAnnotation = true;
// Add field
putForm.call(this, options);
};
if (_typeof(globalObj) == "object") {
globalObj["ChoiceField"] = AcroFormChoiceField;
globalObj["ListBox"] = AcroFormListBox;
globalObj["ComboBox"] = AcroFormComboBox;
globalObj["EditBox"] = AcroFormEditBox;
globalObj["Button"] = AcroFormButton;
globalObj["PushButton"] = AcroFormPushButton;
globalObj["RadioButton"] = AcroFormRadioButton;
globalObj["CheckBox"] = AcroFormCheckBox;
globalObj["TextField"] = AcroFormTextField;
globalObj["PasswordField"] = AcroFormPasswordField; // backwardsCompatibility
globalObj["AcroForm"] = {
Appearance: AcroFormAppearance
};
}
jsPDFAPI.AcroFormChoiceField = AcroFormChoiceField;
jsPDFAPI.AcroFormListBox = AcroFormListBox;
jsPDFAPI.AcroFormComboBox = AcroFormComboBox;
jsPDFAPI.AcroFormEditBox = AcroFormEditBox;
jsPDFAPI.AcroFormButton = AcroFormButton;
jsPDFAPI.AcroFormPushButton = AcroFormPushButton;
jsPDFAPI.AcroFormRadioButton = AcroFormRadioButton;
jsPDFAPI.AcroFormCheckBox = AcroFormCheckBox;
jsPDFAPI.AcroFormTextField = AcroFormTextField;
jsPDFAPI.AcroFormPasswordField = AcroFormPasswordField;
jsPDFAPI.AcroFormAppearance = AcroFormAppearance;
jsPDFAPI.AcroForm = {
ChoiceField: AcroFormChoiceField,
ListBox: AcroFormListBox,
ComboBox: AcroFormComboBox,
EditBox: AcroFormEditBox,
Button: AcroFormButton,
PushButton: AcroFormPushButton,
RadioButton: AcroFormRadioButton,
CheckBox: AcroFormCheckBox,
TextField: AcroFormTextField,
PasswordField: AcroFormPasswordField,
Appearance: AcroFormAppearance
};
})(jsPDF.API, typeof window !== "undefined" && window || typeof global !== "undefined" && global);
/** @license
* jsPDF addImage plugin
* Copyright (c) 2012 Jason Siefken, https://github.com/siefkenj/
* 2013 Chris Dowling, https://github.com/gingerchris
* 2013 Trinh Ho, https://github.com/ineedfat
* 2013 Edwin Alejandro Perez, https://github.com/eaparango
* 2013 Norah Smith, https://github.com/burnburnrocket
* 2014 Diego Casorran, https://github.com/diegocr
* 2014 James Robb, https://github.com/jamesbrobb
*
*
*/
/**
* @name addImage
* @module
*/
(function (jsPDFAPI) {
var namespace = "addImage_";
var imageFileTypeHeaders = {
PNG: [[0x89, 0x50, 0x4e, 0x47]],
TIFF: [[0x4d, 0x4d, 0x00, 0x2a], //Motorola
[0x49, 0x49, 0x2a, 0x00] //Intel
],
JPEG: [[0xff, 0xd8, 0xff, 0xe0, undefined, undefined, 0x4a, 0x46, 0x49, 0x46, 0x00], //JFIF
[0xff, 0xd8, 0xff, 0xe1, undefined, undefined, 0x45, 0x78, 0x69, 0x66, 0x00, 0x00] //Exif
],
JPEG2000: [[0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20]],
GIF87a: [[0x47, 0x49, 0x46, 0x38, 0x37, 0x61]],
GIF89a: [[0x47, 0x49, 0x46, 0x38, 0x39, 0x61]],
BMP: [[0x42, 0x4d], //BM - Windows 3.1x, 95, NT, ... etc.
[0x42, 0x41], //BA - OS/2 struct bitmap array
[0x43, 0x49], //CI - OS/2 struct color icon
[0x43, 0x50], //CP - OS/2 const color pointer
[0x49, 0x43], //IC - OS/2 struct icon
[0x50, 0x54] //PT - OS/2 pointer
]
};
/**
* Recognize filetype of Image by magic-bytes
*
* https://en.wikipedia.org/wiki/List_of_file_signatures
*
* @name getImageFileTypeByImageData
* @public
* @function
* @param {string|arraybuffer} imageData imageData as base64 encoded DataUrl or arraybuffer
* @param {string} format format of file if filetype-recognition fails, e.g. 'JPEG'
*
* @returns {string} filetype of Image
*/
jsPDFAPI.getImageFileTypeByImageData = function (imageData, fallbackFormat) {
fallbackFormat = fallbackFormat || "UNKNOWN";
var i;
var j;
var result = "UNKNOWN";
var headerSchemata;
var compareResult;
var fileType;
if (jsPDFAPI.isArrayBufferView(imageData)) {
imageData = jsPDFAPI.arrayBufferToBinaryString(imageData);
}
for (fileType in imageFileTypeHeaders) {
headerSchemata = imageFileTypeHeaders[fileType];
for (i = 0; i < headerSchemata.length; i += 1) {
compareResult = true;
for (j = 0; j < headerSchemata[i].length; j += 1) {
if (headerSchemata[i][j] === undefined) {
continue;
}
if (headerSchemata[i][j] !== imageData.charCodeAt(j)) {
compareResult = false;
break;
}
}
if (compareResult === true) {
result = fileType;
break;
}
}
}
if (result === "UNKNOWN" && fallbackFormat !== "UNKNOWN") {
console.warn('FileType of Image not recognized. Processing image as "' + fallbackFormat + '".');
result = fallbackFormat;
}
return result;
}; // Image functionality ported from pdf.js
var putImage = function putImage(img) {
var objectNumber = this.internal.newObject(),
out = this.internal.write,
putStream = this.internal.putStream;
img["n"] = objectNumber;
out("<</Type /XObject");
out("/Subtype /Image");
out("/Width " + img["w"]);
out("/Height " + img["h"]);
if (img["cs"] === this.color_spaces.INDEXED) {
out("/ColorSpace [/Indexed /DeviceRGB " + ( // if an indexed png defines more than one colour with transparency, we've created a smask
img["pal"].length / 3 - 1) + " " + ("smask" in img ? objectNumber + 2 : objectNumber + 1) + " 0 R]");
} else {
out("/ColorSpace /" + img["cs"]);
if (img["cs"] === this.color_spaces.DEVICE_CMYK) {
out("/Decode [1 0 1 0 1 0 1 0]");
}
}
out("/BitsPerComponent " + img["bpc"]);
if ("f" in img) {
out("/Filter /" + img["f"]);
}
if ("dp" in img) {
out("/DecodeParms <<" + img["dp"] + ">>");
}
if ("trns" in img && img["trns"].constructor == Array) {
var trns = "",
i = 0,
len = img["trns"].length;
for (; i < len; i++) {
trns += img["trns"][i] + " " + img["trns"][i] + " ";
}
out("/Mask [" + trns + "]");
}
if ("smask" in img) {
out("/SMask " + (objectNumber + 1) + " 0 R");
}
out("/Length " + img["data"].length + ">>");
putStream(img["data"]);
out("endobj"); // Soft mask
if ("smask" in img) {
var dp = "/Predictor " + img["p"] + " /Colors 1 /BitsPerComponent " + img["bpc"] + " /Columns " + img["w"];
var smask = {
w: img["w"],
h: img["h"],
cs: "DeviceGray",
bpc: img["bpc"],
dp: dp,
data: img["smask"]
};
if ("f" in img) smask.f = img["f"];
putImage.call(this, smask);
} //Palette
if (img["cs"] === this.color_spaces.INDEXED) {
this.internal.newObject(); //out('<< /Filter / ' + img['f'] +' /Length ' + img['pal'].length + '>>');
//putStream(zlib.compress(img['pal']));
out("<< /Length " + img["pal"].length + ">>");
putStream(this.arrayBufferToBinaryString(new Uint8Array(img["pal"])));
out("endobj");
}
},
putResourcesCallback = function putResourcesCallback() {
var images = this.internal.collections[namespace + "images"];
for (var i in images) {
putImage.call(this, images[i]);
}
},
putXObjectsDictCallback = function putXObjectsDictCallback() {
var images = this.internal.collections[namespace + "images"],
out = this.internal.write,
image;
for (var i in images) {
image = images[i];
out("/I" + image["i"], image["n"], "0", "R");
}
},
checkCompressValue = function checkCompressValue(value) {
if (value && typeof value === "string") value = value.toUpperCase();
return value in jsPDFAPI.image_compression ? value : jsPDFAPI.image_compression.NONE;
},
getImages = function getImages() {
var images = this.internal.collections[namespace + "images"]; //first run, so initialise stuff
if (!images) {
this.internal.collections[namespace + "images"] = images = {};
this.internal.events.subscribe("putResources", putResourcesCallback);
this.internal.events.subscribe("putXobjectDict", putXObjectsDictCallback);
}
return images;
},
getImageIndex = function getImageIndex(images) {
var imageIndex = 0;
if (images) {
// this is NOT the first time this method is ran on this instance of jsPDF object.
imageIndex = Object.keys ? Object.keys(images).length : function (o) {
var i = 0;
for (var e in o) {
if (o.hasOwnProperty(e)) {
i++;
}
}
return i;
}(images);
}
return imageIndex;
},
notDefined = function notDefined(value) {
return typeof value === "undefined" || value === null || value.length === 0;
},
generateAliasFromData = function generateAliasFromData(data) {
return typeof data === "string" && jsPDFAPI.sHashCode(data);
},
isImageTypeSupported = function isImageTypeSupported(type) {
return typeof jsPDFAPI["process" + type.toUpperCase()] === "function";
},
isDOMElement = function isDOMElement(object) {
return _typeof(object) === "object" && object.nodeType === 1;
},
createDataURIFromElement = function createDataURIFromElement(element, format) {
//if element is an image which uses data url definition, just return the dataurl
if (element.nodeName === "IMG" && element.hasAttribute("src")) {
var src = "" + element.getAttribute("src");
if (src.indexOf("data:image/") === 0) return unescape(src); // only if the user doesn't care about a format
if (!format && /\.png(?:[?#].*)?$/i.test(src)) format = "png";
}
if (element.nodeName === "CANVAS") {
var canvas = element;
} else {
var canvas = document.createElement("canvas");
canvas.width = element.clientWidth || element.width;
canvas.height = element.clientHeight || element.height;
var ctx = canvas.getContext("2d");
if (!ctx) {
throw "addImage requires canvas to be supported by browser.";
}
ctx.drawImage(element, 0, 0, canvas.width, canvas.height);
}
return canvas.toDataURL(("" + format).toLowerCase() == "png" ? "image/png" : "image/jpeg");
},
checkImagesForAlias = function checkImagesForAlias(alias, images) {
var cached_info;
if (images) {
for (var e in images) {
if (alias === images[e].alias) {
cached_info = images[e];
break;
}
}
}
return cached_info;
},
determineWidthAndHeight = function determineWidthAndHeight(w, h, info) {
if (!w && !h) {
w = -96;
h = -96;
}
if (w < 0) {
w = -1 * info["w"] * 72 / w / this.internal.scaleFactor;
}
if (h < 0) {
h = -1 * info["h"] * 72 / h / this.internal.scaleFactor;
}
if (w === 0) {
w = h * info["w"] / info["h"];
}
if (h === 0) {
h = w * info["h"] / info["w"];
}
return [w, h];
},
writeImageToPDF = function writeImageToPDF(x, y, w, h, info, index, images, rotation) {
var dims = determineWidthAndHeight.call(this, w, h, info),
coord = this.internal.getCoordinateString,
vcoord = this.internal.getVerticalCoordinateString;
w = dims[0];
h = dims[1];
images[index] = info;
if (rotation) {
rotation *= Math.PI / 180;
var c = Math.cos(rotation);
var s = Math.sin(rotation); //like in pdf Reference do it 4 digits instead of 2
var f4 = function f4(number) {
return number.toFixed(4);
};
var rotationTransformationMatrix = [f4(c), f4(s), f4(s * -1), f4(c), 0, 0, "cm"];
}
this.internal.write("q"); //Save graphics state
if (rotation) {
this.internal.write([1, "0", "0", 1, coord(x), vcoord(y + h), "cm"].join(" ")); //Translate
this.internal.write(rotationTransformationMatrix.join(" ")); //Rotate
this.internal.write([coord(w), "0", "0", coord(h), "0", "0", "cm"].join(" ")); //Scale
} else {
this.internal.write([coord(w), "0", "0", coord(h), coord(x), vcoord(y + h), "cm"].join(" ")); //Translate and Scale
}
if (this.isAdvancedAPI()) {
// draw image bottom up when in "advanced" API mode
this.internal.write([1, 0, 0, -1, 0, 0, "cm"].join(" "));
}
this.internal.write("/I" + info["i"] + " Do"); //Paint Image
this.internal.write("Q"); //Restore graphics state
};
/**
* COLOR SPACES
*/
jsPDFAPI.color_spaces = {
DEVICE_RGB: "DeviceRGB",
DEVICE_GRAY: "DeviceGray",
DEVICE_CMYK: "DeviceCMYK",
CAL_GREY: "CalGray",
CAL_RGB: "CalRGB",
LAB: "Lab",
ICC_BASED: "ICCBased",
INDEXED: "Indexed",
PATTERN: "Pattern",
SEPARATION: "Separation",
DEVICE_N: "DeviceN"
};
/**
* DECODE METHODS
*/
jsPDFAPI.decode = {
DCT_DECODE: "DCTDecode",
FLATE_DECODE: "FlateDecode",
LZW_DECODE: "LZWDecode",
JPX_DECODE: "JPXDecode",
JBIG2_DECODE: "JBIG2Decode",
ASCII85_DECODE: "ASCII85Decode",
ASCII_HEX_DECODE: "ASCIIHexDecode",
RUN_LENGTH_DECODE: "RunLengthDecode",
CCITT_FAX_DECODE: "CCITTFaxDecode"
};
/**
* IMAGE COMPRESSION TYPES
*/
jsPDFAPI.image_compression = {
NONE: "NONE",
FAST: "FAST",
MEDIUM: "MEDIUM",
SLOW: "SLOW"
};
/**
* @name sHashCode
* @function
* @param {string} str
* @returns {string}
*/
jsPDFAPI.sHashCode = function (str) {
str = str || "";
return Array.prototype.reduce && str.split("").reduce(function (a, b) {
a = (a << 5) - a + b.charCodeAt(0);
return a & a;
}, 0);
};
/**
* @name isString
* @function
* @param {any} object
* @returns {boolean}
*/
jsPDFAPI.isString = function (object) {
return typeof object === "string";
};
/**
* Validates if given String is a valid Base64-String
*
* @name validateStringAsBase64
* @public
* @function
* @param {String} possible Base64-String
*
* @returns {boolean}
*/
jsPDFAPI.validateStringAsBase64 = function (possibleBase64String) {
possibleBase64String = possibleBase64String || "";
var result = true;
if (possibleBase64String.length % 4 !== 0) {
result = false;
}
if (/[A-Za-z0-9\/]+/.test(possibleBase64String.substr(0, possibleBase64String.length - 2)) === false) {
result = false;
}
if (/[A-Za-z0-9\/][A-Za-z0-9+\/]|[A-Za-z0-9+\/]=|==/.test(possibleBase64String.substr(-2)) === false) {
result = false;
}
return result;
};
/**
* Strips out and returns info from a valid base64 data URI
*
* @name extractInfoFromBase64DataURI
* @function
* @param {string} dataUrl a valid data URI of format 'data:[<MIME-type>][;base64],<data>'
* @returns {Array}an Array containing the following
* [0] the complete data URI
* [1] <MIME-type>
* [2] format - the second part of the mime-type i.e 'png' in 'image/png'
* [4] <data>
*/
jsPDFAPI.extractInfoFromBase64DataURI = function (dataURI) {
return /^data:([\w]+?\/([\w]+?));\S*;*base64,(.+)$/g.exec(dataURI);
};
/**
* Check to see if ArrayBuffer is supported
*
* @name supportsArrayBuffer
* @function
* @returns {boolean}
*/
jsPDFAPI.supportsArrayBuffer = function () {
return typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined";
};
/**
* Tests supplied object to determine if ArrayBuffer
*
* @name isArrayBuffer
* @function
* @param {Object} object an Object
*
* @returns {boolean}
*/
jsPDFAPI.isArrayBuffer = function (object) {
if (!this.supportsArrayBuffer()) return false;
return object instanceof ArrayBuffer;
};
/**
* Tests supplied object to determine if it implements the ArrayBufferView (TypedArray) interface
*
* @name isArrayBufferView
* @function
* @param {Object} object an Object
* @returns {boolean}
*/
jsPDFAPI.isArrayBufferView = function (object) {
if (!this.supportsArrayBuffer()) return false;
if (typeof Uint32Array === "undefined") return false;
return object instanceof Int8Array || object instanceof Uint8Array || typeof Uint8ClampedArray !== "undefined" && object instanceof Uint8ClampedArray || object instanceof Int16Array || object instanceof Uint16Array || object instanceof Int32Array || object instanceof Uint32Array || object instanceof Float32Array || object instanceof Float64Array;
};
/**
* Convert the Buffer to a Binary String
*
* @name binaryStringToUint8Array
* @public
* @function
* @param {ArrayBuffer} BinaryString with ImageData
*
* @returns {Uint8Array}
*/
jsPDFAPI.binaryStringToUint8Array = function (binary_string) {
/*
* not sure how efficient this will be will bigger files. Is there a native method?
*/
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes;
};
/**
* Convert the Buffer to a Binary String
*
* @name arrayBufferToBinaryString
* @public
* @function
* @param {ArrayBuffer} ArrayBuffer with ImageData
*
* @returns {String}
*/
jsPDFAPI.arrayBufferToBinaryString = function (buffer) {
if (typeof atob === "function") {
return atob(this.arrayBufferToBase64(buffer));
}
if (typeof TextDecoder === "function") {
var decoder = new TextDecoder("ascii"); // test if the encoding is supported
if (decoder.encoding === "ascii") {
return decoder.decode(buffer);
}
} //Fallback-solution
var data = this.isArrayBuffer(buffer) ? buffer : new Uint8Array(buffer);
var chunkSizeForSlice = 0x5000;
var binary_string = "";
var slicesCount = Math.ceil(data.byteLength / chunkSizeForSlice);
for (var i = 0; i < slicesCount; i++) {
binary_string += String.fromCharCode.apply(null, data.slice(i * chunkSizeForSlice, i * chunkSizeForSlice + chunkSizeForSlice));
}
return binary_string;
};
/**
* Converts an ArrayBuffer directly to base64
*
* Taken from http://jsperf.com/encoding-xhr-image-data/31
*
* Need to test if this is a better solution for larger files
*
* @name arrayBufferToBase64
* @param {arraybuffer} arrayBuffer
* @public
* @function
*
* @returns {string}
*/
jsPDFAPI.arrayBufferToBase64 = function (arrayBuffer) {
var base64 = "";
var encodings = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var bytes = new Uint8Array(arrayBuffer);
var byteLength = bytes.byteLength;
var byteRemainder = byteLength % 3;
var mainLength = byteLength - byteRemainder;
var a, b, c, d;
var chunk; // Main loop deals with bytes in chunks of 3
for (var i = 0; i < mainLength; i = i + 3) {
// Combine the three bytes into a single integer
chunk = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2]; // Use bitmasks to extract 6-bit segments from the triplet
a = (chunk & 16515072) >> 18; // 16515072 = (2^6 - 1) << 18
b = (chunk & 258048) >> 12; // 258048 = (2^6 - 1) << 12
c = (chunk & 4032) >> 6; // 4032 = (2^6 - 1) << 6
d = chunk & 63; // 63 = 2^6 - 1
// Convert the raw binary segments to the appropriate ASCII encoding
base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d];
} // Deal with the remaining bytes and padding
if (byteRemainder == 1) {
chunk = bytes[mainLength];
a = (chunk & 252) >> 2; // 252 = (2^6 - 1) << 2
// Set the 4 least significant bits to zero
b = (chunk & 3) << 4; // 3 = 2^2 - 1
base64 += encodings[a] + encodings[b] + "==";
} else if (byteRemainder == 2) {
chunk = bytes[mainLength] << 8 | bytes[mainLength + 1];
a = (chunk & 64512) >> 10; // 64512 = (2^6 - 1) << 10
b = (chunk & 1008) >> 4; // 1008 = (2^6 - 1) << 4
// Set the 2 least significant bits to zero
c = (chunk & 15) << 2; // 15 = 2^4 - 1
base64 += encodings[a] + encodings[b] + encodings[c] + "=";
}
return base64;
};
/**
*
* @name createImageInfo
* @param {Object} data
* @param {number} wd width
* @param {number} ht height
* @param {Object} cs colorSpace
* @param {number} bpc bits per channel
* @param {any} f
* @param {number} imageIndex
* @param {string} alias
* @param {any} dp
* @param {any} trns
* @param {any} pal
* @param {any} smask
* @param {any} p
* @public
* @function
*
* @returns {Object}
*/
jsPDFAPI.createImageInfo = function (data, wd, ht, cs, bpc, f, imageIndex, alias, dp, trns, pal, smask, p) {
var info = {
alias: alias,
w: wd,
h: ht,
cs: cs,
bpc: bpc,
i: imageIndex,
data: data // n: objectNumber will be added by putImage code
};
if (f) info.f = f;
if (dp) info.dp = dp;
if (trns) info.trns = trns;
if (pal) info.pal = pal;
if (smask) info.smask = smask;
if (p) info.p = p; // predictor parameter for PNG compression
return info;
};
/**
* Adds an Image to the PDF.
*
* @name addImage
* @public
* @function
* @param {string/Image-Element/Canvas-Element/Uint8Array} imageData imageData as base64 encoded DataUrl or Image-HTMLElement or Canvas-HTMLElement
* @param {string} format format of file if filetype-recognition fails, e.g. 'JPEG'
* @param {number} x x Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {number} y y Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {number} width width of the image (in units declared at inception of PDF document)
* @param {number} height height of the Image (in units declared at inception of PDF document)
* @param {string} alias alias of the image (if used multiple times)
* @param {string} compression compression of the generated JPEG, can have the values 'NONE', 'FAST', 'MEDIUM' and 'SLOW'
* @param {number} rotation rotation of the image in degrees (0-359)
*
* @returns jsPDF
*/
jsPDFAPI.addImage = function (imageData, format, x, y, w, h, alias, compression, rotation) {
var tmpImageData = "";
if (typeof format !== "string") {
var tmp = h;
h = w;
w = y;
y = x;
x = format;
format = tmp;
}
if (_typeof(imageData) === "object" && !isDOMElement(imageData) && "imageData" in imageData) {
var options = imageData;
imageData = options.imageData;
format = options.format || format;
x = options.x || x || 0;
y = options.y || y || 0;
w = options.w || w;
h = options.h || h;
alias = options.alias || alias;
compression = options.compression || compression;
rotation = options.rotation || options.angle || rotation;
}
if (typeof imageData === "string") {
imageData = unescape(imageData);
}
if (isNaN(x) || isNaN(y)) {
console.error("jsPDF.addImage: Invalid coordinates", arguments);
throw new Error("Invalid coordinates passed to jsPDF.addImage");
}
var images = getImages.call(this),
info;
if (!(info = checkImagesForAlias(imageData, images))) {
var dataAsBinaryString;
if (isDOMElement(imageData)) imageData = createDataURIFromElement(imageData, format);
if (notDefined(alias)) alias = generateAliasFromData(imageData);
if (!(info = checkImagesForAlias(alias, images))) {
if (this.isString(imageData)) {
tmpImageData = this.convertStringToImageData(imageData);
if (tmpImageData !== "") {
imageData = tmpImageData;
} else {
tmpImageData = this.loadImageFile(imageData);
if (tmpImageData !== undefined) {
imageData = tmpImageData;
}
}
}
format = this.getImageFileTypeByImageData(imageData, format);
if (!isImageTypeSupported(format)) throw new Error("addImage does not support files of type '" + format + "', please ensure that a plugin for '" + format + "' support is added.");
/**
* need to test if it's more efficient to convert all binary strings
* to TypedArray - or should we just leave and process as string?
*/
if (this.supportsArrayBuffer()) {
// no need to convert if imageData is already uint8array
if (!(imageData instanceof Uint8Array)) {
dataAsBinaryString = imageData;
imageData = this.binaryStringToUint8Array(imageData);
}
}
info = this["process" + format.toUpperCase()](imageData, getImageIndex(images), alias, checkCompressValue(compression), dataAsBinaryString);
if (!info) throw new Error("An unkwown error occurred whilst processing the image");
}
}
writeImageToPDF.call(this, x, y, w, h, info, info.i, images, rotation);
return this;
};
/**
* @name convertStringToImageData
* @function
* @param {string} stringData
* @returns {string} binary data
*/
jsPDFAPI.convertStringToImageData = function (stringData) {
var base64Info;
var imageData = "";
if (this.isString(stringData)) {
var base64Info = this.extractInfoFromBase64DataURI(stringData);
if (base64Info !== null) {
if (jsPDFAPI.validateStringAsBase64(base64Info[3])) {
imageData = atob(base64Info[3]); //convert to binary string
}
} else if (jsPDFAPI.validateStringAsBase64(stringData)) {
imageData = atob(stringData);
}
}
return imageData;
};
/**
* JPEG SUPPORT
**/
//takes a string imgData containing the raw bytes of
//a jpeg image and returns [width, height]
//Algorithm from: http://www.64lines.com/jpeg-width-height
var getJpegSize = function getJpegSize(imgData) {
var width, height, numcomponents; // Verify we have a valid jpeg header 0xff,0xd8,0xff,0xe0,?,?,'J','F','I','F',0x00
if (!imgData.charCodeAt(0) === 0xff || !imgData.charCodeAt(1) === 0xd8 || !imgData.charCodeAt(2) === 0xff || !imgData.charCodeAt(3) === 0xe0 || !imgData.charCodeAt(6) === "J".charCodeAt(0) || !imgData.charCodeAt(7) === "F".charCodeAt(0) || !imgData.charCodeAt(8) === "I".charCodeAt(0) || !imgData.charCodeAt(9) === "F".charCodeAt(0) || !imgData.charCodeAt(10) === 0x00) {
throw new Error("getJpegSize requires a binary string jpeg file");
}
var blockLength = imgData.charCodeAt(4) * 256 + imgData.charCodeAt(5);
var i = 4,
len = imgData.length;
while (i < len) {
i += blockLength;
if (imgData.charCodeAt(i) !== 0xff) {
throw new Error("getJpegSize could not find the size of the image");
}
if (imgData.charCodeAt(i + 1) === 0xc0 || //(SOF) Huffman - Baseline DCT
imgData.charCodeAt(i + 1) === 0xc1 || //(SOF) Huffman - Extended sequential DCT
imgData.charCodeAt(i + 1) === 0xc2 || // Progressive DCT (SOF2)
imgData.charCodeAt(i + 1) === 0xc3 || // Spatial (sequential) lossless (SOF3)
imgData.charCodeAt(i + 1) === 0xc4 || // Differential sequential DCT (SOF5)
imgData.charCodeAt(i + 1) === 0xc5 || // Differential progressive DCT (SOF6)
imgData.charCodeAt(i + 1) === 0xc6 || // Differential spatial (SOF7)
imgData.charCodeAt(i + 1) === 0xc7) {
height = imgData.charCodeAt(i + 5) * 256 + imgData.charCodeAt(i + 6);
width = imgData.charCodeAt(i + 7) * 256 + imgData.charCodeAt(i + 8);
numcomponents = imgData.charCodeAt(i + 9);
return [width, height, numcomponents];
} else {
i += 2;
blockLength = imgData.charCodeAt(i) * 256 + imgData.charCodeAt(i + 1);
}
}
},
getJpegSizeFromBytes = function getJpegSizeFromBytes(data) {
var hdr = data[0] << 8 | data[1];
if (hdr !== 0xffd8) throw new Error("Supplied data is not a JPEG");
var len = data.length,
block = (data[4] << 8) + data[5],
pos = 4,
bytes,
width,
height,
numcomponents;
while (pos < len) {
pos += block;
bytes = readBytes(data, pos);
block = (bytes[2] << 8) + bytes[3];
if ((bytes[1] === 0xc0 || bytes[1] === 0xc2) && bytes[0] === 0xff && block > 7) {
bytes = readBytes(data, pos + 5);
width = (bytes[2] << 8) + bytes[3];
height = (bytes[0] << 8) + bytes[1];
numcomponents = bytes[4];
return {
width: width,
height: height,
numcomponents: numcomponents
};
}
pos += 2;
}
throw new Error("getJpegSizeFromBytes could not find the size of the image");
},
readBytes = function readBytes(data, offset) {
return data.subarray(offset, offset + 5);
};
/**
* @ignore
*/
jsPDFAPI.processJPEG = function (data, index, alias, compression, dataAsBinaryString, colorSpace) {
var filter = this.decode.DCT_DECODE,
bpc = 8,
dims;
if (!this.isString(data) && !this.isArrayBuffer(data) && !this.isArrayBufferView(data)) {
return null;
}
if (this.isString(data)) {
dims = getJpegSize(data);
}
if (this.isArrayBuffer(data)) {
data = new Uint8Array(data);
}
if (this.isArrayBufferView(data)) {
dims = getJpegSizeFromBytes(data); // if we already have a stored binary string rep use that
data = dataAsBinaryString || this.arrayBufferToBinaryString(data);
}
if (colorSpace === undefined) {
switch (dims.numcomponents) {
case 1:
colorSpace = this.color_spaces.DEVICE_GRAY;
break;
case 4:
colorSpace = this.color_spaces.DEVICE_CMYK;
break;
default:
case 3:
colorSpace = this.color_spaces.DEVICE_RGB;
break;
}
}
return this.createImageInfo(data, dims.width, dims.height, colorSpace, bpc, filter, index, alias);
};
/**
* @ignore
*/
jsPDFAPI.processJPG = function ()
/*data, index, alias, compression, dataAsBinaryString*/
{
return this.processJPEG.apply(this, arguments);
};
/**
* @name loadImageFile
* @function
* @param {string} path
* @param {boolean} sync
* @param {function} callback
*/
jsPDFAPI.loadImageFile = function (path, sync, callback) {
sync = sync || true;
callback = callback || function () {};
var isNode = Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
var xhrMethod = function xhrMethod(url, sync, callback) {
var req = new XMLHttpRequest();
var byteArray = [];
var i = 0;
var sanitizeUnicode = function sanitizeUnicode(data) {
var dataLength = data.length;
var StringFromCharCode = String.fromCharCode; //Transform Unicode to ASCII
for (i = 0; i < dataLength; i += 1) {
byteArray.push(StringFromCharCode(data.charCodeAt(i) & 0xff));
}
return byteArray.join("");
};
req.open("GET", url, !sync); // XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com]
req.overrideMimeType("text/plain; charset=x-user-defined");
if (sync === false) {
req.onload = function () {
return sanitizeUnicode(this.responseText);
};
}
req.send(null);
if (req.status !== 200) {
console.warn('Unable to load file "' + url + '"');
return;
}
if (sync) {
return sanitizeUnicode(req.responseText);
}
}; //we have a browser and probably no CORS-Problem
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined && (typeof location === "undefined" ? "undefined" : _typeof(location)) === "object" && location.protocol.substr(0, 4) === "http") {
return xhrMethod(path, sync, callback);
}
};
/**
* @name getImageProperties
* @function
* @param {Object} imageData
* @returns {Object}
*/
jsPDFAPI.getImageProperties = function (imageData) {
var info;
var tmpImageData = "";
var format;
if (isDOMElement(imageData)) {
imageData = createDataURIFromElement(imageData);
}
if (this.isString(imageData)) {
tmpImageData = this.convertStringToImageData(imageData);
if (tmpImageData !== "") {
imageData = tmpImageData;
} else {
tmpImageData = this.loadImageFile(imageData);
if (tmpImageData !== undefined) {
imageData = tmpImageData;
}
}
}
format = this.getImageFileTypeByImageData(imageData);
if (!isImageTypeSupported(format)) throw new Error("addImage does not support files of type '" + format + "', please ensure that a plugin for '" + format + "' support is added.");
/**
* need to test if it's more efficient to convert all binary strings
* to TypedArray - or should we just leave and process as string?
*/
if (this.supportsArrayBuffer()) {
// no need to convert if imageData is already uint8array
if (!(imageData instanceof Uint8Array)) {
imageData = this.binaryStringToUint8Array(imageData);
}
}
info = this["process" + format.toUpperCase()](imageData);
if (!info) {
throw new Error("An unkwown error occurred whilst processing the image");
}
return {
fileType: format,
width: info.w,
height: info.h,
colorSpace: info.cs,
compressionMode: info.f,
bitsPerComponent: info.bpc
};
};
})(jsPDF.API);
/**
* @license
* Copyright (c) 2014 Steven Spungin (TwelveTone LLC) steven@twelvetone.tv
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* jsPDF Annotations PlugIn
*
* There are many types of annotations in a PDF document. Annotations are placed
* on a page at a particular location. They are not 'attached' to an object.
* <br />
* This plugin current supports <br />
* <li> Goto Page (set pageNumber and top in options)
* <li> Goto Name (set name and top in options)
* <li> Goto URL (set url in options)
* <p>
* The destination magnification factor can also be specified when goto is a page number or a named destination. (see documentation below)
* (set magFactor in options). XYZ is the default.
* </p>
* <p>
* Links, Text, Popup, and FreeText are supported.
* </p>
* <p>
* Options In PDF spec Not Implemented Yet
* <li> link border
* <li> named target
* <li> page coordinates
* <li> destination page scaling and layout
* <li> actions other than URL and GotoPage
* <li> background / hover actions
* </p>
* @name annotations
* @module
*/
/*
Destination Magnification Factors
See PDF 1.3 Page 386 for meanings and options
[supported]
XYZ (options; left top zoom)
Fit (no options)
FitH (options: top)
FitV (options: left)
[not supported]
FitR
FitB
FitBH
FitBV
*/
(function (jsPDFAPI) {
var annotationPlugin = {
/**
* An array of arrays, indexed by <em>pageNumber</em>.
*/
annotations: [],
f2: function f2(number) {
return number.toFixed(2);
},
notEmpty: function notEmpty(obj) {
if (typeof obj != "undefined") {
if (obj != "") {
return true;
}
}
}
};
jsPDF.API.annotationPlugin = annotationPlugin;
jsPDF.API.events.push(["addPage", function (info) {
this.annotationPlugin.annotations[info.pageNumber] = [];
}]);
jsPDFAPI.events.push(["putPage", function (info) {
//TODO store annotations in pageContext so reorder/remove will not affect them.
var pageAnnos = this.annotationPlugin.annotations[info.pageNumber];
var found = false;
for (var a = 0; a < pageAnnos.length && !found; a++) {
var anno = pageAnnos[a];
switch (anno.type) {
case "link":
if (annotationPlugin.notEmpty(anno.options.url) || annotationPlugin.notEmpty(anno.options.pageNumber)) {
found = true;
break;
}
case "reference":
case "text":
case "freetext":
found = true;
break;
}
}
if (found == false) {
return;
}
this.internal.write("/Annots [");
var f2 = this.annotationPlugin.f2;
var k = this.internal.scaleFactor;
var pageHeight = this.internal.pageSize.getHeight();
var pageInfo = this.internal.getPageInfo(info.pageNumber);
for (var a = 0; a < pageAnnos.length; a++) {
var anno = pageAnnos[a];
switch (anno.type) {
case "reference":
// References to Widget Anotations (for AcroForm Fields)
this.internal.write(" " + anno.object.objId + " 0 R ");
break;
case "text":
// Create a an object for both the text and the popup
var objText = this.internal.newAdditionalObject();
var objPopup = this.internal.newAdditionalObject();
var title = anno.title || "Note";
var rect = "/Rect [" + f2(anno.bounds.x * k) + " " + f2(pageHeight - (anno.bounds.y + anno.bounds.h) * k) + " " + f2((anno.bounds.x + anno.bounds.w) * k) + " " + f2((pageHeight - anno.bounds.y) * k) + "] ";
line = "<</Type /Annot /Subtype /" + "Text" + " " + rect + "/Contents (" + anno.contents + ")";
line += " /Popup " + objPopup.objId + " 0 R";
line += " /P " + pageInfo.objId + " 0 R";
line += " /T (" + title + ") >>";
objText.content = line;
var parent = objText.objId + " 0 R";
var popoff = 30;
var rect = "/Rect [" + f2((anno.bounds.x + popoff) * k) + " " + f2(pageHeight - (anno.bounds.y + anno.bounds.h) * k) + " " + f2((anno.bounds.x + anno.bounds.w + popoff) * k) + " " + f2((pageHeight - anno.bounds.y) * k) + "] "; //var rect2 = "/Rect [" + f2(anno.bounds.x * k) + " " + f2((pageHeight - anno.bounds.y) * k) + " " + f2(anno.bounds.x + anno.bounds.w * k) + " " + f2(pageHeight - (anno.bounds.y + anno.bounds.h) * k) + "] ";
line = "<</Type /Annot /Subtype /" + "Popup" + " " + rect + " /Parent " + parent;
if (anno.open) {
line += " /Open true";
}
line += " >>";
objPopup.content = line;
this.internal.write(objText.objId, "0 R", objPopup.objId, "0 R");
break;
case "freetext":
var rect = "/Rect [" + f2(anno.bounds.x * k) + " " + f2((pageHeight - anno.bounds.y) * k) + " " + f2(anno.bounds.x + anno.bounds.w * k) + " " + f2(pageHeight - (anno.bounds.y + anno.bounds.h) * k) + "] ";
var color = anno.color || "#000000";
line = "<</Type /Annot /Subtype /" + "FreeText" + " " + rect + "/Contents (" + anno.contents + ")";
line += " /DS(font: Helvetica,sans-serif 12.0pt; text-align:left; color:#" + color + ")";
line += " /Border [0 0 0]";
line += " >>";
this.internal.write(line);
break;
case "link":
if (anno.options.name) {
var loc = this.annotations._nameMap[anno.options.name];
anno.options.pageNumber = loc.page;
anno.options.top = loc.y;
} else {
if (!anno.options.top) {
anno.options.top = 0;
}
}
var rect = "/Rect [" + f2(anno.x * k) + " " + f2((pageHeight - anno.y) * k) + " " + f2((anno.x + anno.w) * k) + " " + f2((pageHeight - (anno.y + anno.h)) * k) + "] ";
var line = "";
if (anno.options.url) {
line = "<</Type /Annot /Subtype /Link " + rect + "/Border [0 0 0] /A <</S /URI /URI (" + anno.options.url + ") >>";
} else if (anno.options.pageNumber) {
// first page is 0
var info = this.internal.getPageInfo(anno.options.pageNumber);
line = "<</Type /Annot /Subtype /Link " + rect + "/Border [0 0 0] /Dest [" + info.objId + " 0 R";
anno.options.magFactor = anno.options.magFactor || "XYZ";
switch (anno.options.magFactor) {
case "Fit":
line += " /Fit]";
break;
case "FitH":
//anno.options.top = anno.options.top || f2(pageHeight * k);
line += " /FitH " + anno.options.top + "]";
break;
case "FitV":
anno.options.left = anno.options.left || 0;
line += " /FitV " + anno.options.left + "]";
break;
case "XYZ":
default:
var top = f2((pageHeight - anno.options.top) * k); // || f2(pageHeight * k);
anno.options.left = anno.options.left || 0; // 0 or null zoom will not change zoom factor
if (typeof anno.options.zoom === "undefined") {
anno.options.zoom = 0;
}
line += " /XYZ " + anno.options.left + " " + top + " " + anno.options.zoom + "]";
break;
}
}
if (line != "") {
line += " >>";
this.internal.write(line);
}
break;
}
}
this.internal.write("]");
}]);
/**
* @name createAnnotation
* @function
* @param {Object} options
*/
jsPDFAPI.createAnnotation = function (options) {
switch (options.type) {
case "link":
this.link(options.bounds.x, options.bounds.y, options.bounds.w, options.bounds.h, options);
break;
case "text":
case "freetext":
this.annotationPlugin.annotations[this.internal.getCurrentPageInfo().pageNumber].push(options);
break;
}
};
/**
* Create a link
*
* valid options
* <li> pageNumber or url [required]
* <p>If pageNumber is specified, top and zoom may also be specified</p>
* @name link
* @function
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
* @param {Object} options
*/
jsPDFAPI.link = function (x, y, w, h, options) {
this.annotationPlugin.annotations[this.internal.getCurrentPageInfo().pageNumber].push({
x: x,
y: y,
w: w,
h: h,
options: options,
type: "link"
});
};
/**
* Currently only supports single line text.
* Returns the width of the text/link
*
* @name textWithLink
* @function
* @param {string} text
* @param {number} x
* @param {number} y
* @param {Object} options
* @returns {number} width the width of the text/link
*/
jsPDFAPI.textWithLink = function (text, x, y, options) {
var width = this.getTextWidth(text);
var height = this.internal.getLineHeight() / this.internal.scaleFactor;
this.text(text, x, y); //TODO We really need the text baseline height to do this correctly.
// Or ability to draw text on top, bottom, center, or baseline.
y += height * 0.2;
this.link(x, y - height, width, height, options);
return width;
}; //TODO move into external library
/**
* @name getTextWidth
* @function
* @param {string} text
* @returns {number} txtWidth
*/
jsPDFAPI.getTextWidth = function (text) {
var fontSize = this.internal.getFontSize();
var txtWidth = this.getStringUnitWidth(text) * fontSize / this.internal.scaleFactor;
return txtWidth;
}; //TODO move into external library
/**
* @name getLineHeight
* @function
* @returns {number} lineHeight
*/
jsPDFAPI.getLineHeight = function () {
return this.internal.getLineHeight();
};
return this;
})(jsPDF.API);
/**
* @license
* Copyright (c) 2017 Aras Abbasi
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* jsPDF arabic parser PlugIn
*
* @name arabic
* @module
*/
(function (jsPDFAPI) {
var arLangCodes = {
ar: "Arabic (Standard)",
"ar-DZ": "Arabic (Algeria)",
"ar-BH": "Arabic (Bahrain)",
"ar-EG": "Arabic (Egypt)",
"ar-IQ": "Arabic (Iraq)",
"ar-JO": "Arabic (Jordan)",
"ar-KW": "Arabic (Kuwait)",
"ar-LB": "Arabic (Lebanon)",
"ar-LY": "Arabic (Libya)",
"ar-MA": "Arabic (Morocco)",
"ar-OM": "Arabic (Oman)",
"ar-QA": "Arabic (Qatar)",
"ar-SA": "Arabic (Saudi Arabia)",
"ar-SY": "Arabic (Syria)",
"ar-TN": "Arabic (Tunisia)",
"ar-AE": "Arabic (U.A.E.)",
"ar-YE": "Arabic (Yemen)",
fa: "Persian",
"fa-IR": "Persian/Iran",
ur: "Urdu"
};
var arLangCodesKeys = Object.keys(arLangCodes);
/**
* Arabic shape substitutions: char code => (isolated, final, initial, medial).
*/
var arabicSubst = {
1569: [65152],
1570: [65153, 65154, 65153, 65154],
1571: [65155, 65156, 65155, 65156],
1572: [65157, 65158],
1573: [65159, 65160, 65159, 65160],
1574: [65161, 65162, 65163, 65164],
1575: [65165, 65166, 65165, 65166],
1576: [65167, 65168, 65169, 65170],
1577: [65171, 65172],
1578: [65173, 65174, 65175, 65176],
1579: [65177, 65178, 65179, 65180],
1580: [65181, 65182, 65183, 65184],
1581: [65185, 65186, 65187, 65188],
1582: [65189, 65190, 65191, 65192],
1583: [65193, 65194, 65193],
1584: [65195, 65196, 65195],
1585: [65197, 65198, 65197],
1586: [65199, 65200, 65199],
1587: [65201, 65202, 65203, 65204],
1588: [65205, 65206, 65207, 65208],
1589: [65209, 65210, 65211, 65212],
1590: [65213, 65214, 65215, 65216],
1591: [65217, 65218, 65219, 65220],
1592: [65221, 65222, 65223, 65224],
1593: [65225, 65226, 65227, 65228],
1594: [65229, 65230, 65231, 65232],
1601: [65233, 65234, 65235, 65236],
1602: [65237, 65238, 65239, 65240],
1603: [65241, 65242, 65243, 65244],
1604: [65245, 65246, 65247, 65248],
1605: [65249, 65250, 65251, 65252],
1606: [65253, 65254, 65255, 65256],
1607: [65257, 65258, 65259, 65260],
1608: [65261, 65262, 65261],
1609: [65263, 65264, 64488, 64489],
1610: [65265, 65266, 65267, 65268],
1649: [64336, 64337],
1655: [64477],
1657: [64358, 64359, 64360, 64361],
1658: [64350, 64351, 64352, 64353],
1659: [64338, 64339, 64340, 64341],
1662: [64342, 64343, 64344, 64345],
1663: [64354, 64355, 64356, 64357],
1664: [64346, 64347, 64348, 64349],
1667: [64374, 64375, 64376, 64377],
1668: [64370, 64371, 64372, 64373],
1670: [64378, 64379, 64380, 64381],
1671: [64382, 64383, 64384, 64385],
1672: [64392, 64393],
1676: [64388, 64389],
1677: [64386, 64387],
1678: [64390, 64391],
1681: [64396, 64397],
1688: [64394, 64395, 64394],
1700: [64362, 64363, 64364, 64365],
1702: [64366, 64367, 64368, 64369],
1705: [64398, 64399, 64400, 64401],
1709: [64467, 64468, 64469, 64470],
1711: [64402, 64403, 64404, 64405],
1713: [64410, 64411, 64412, 64413],
1715: [64406, 64407, 64408, 64409],
1722: [64414, 64415],
1723: [64416, 64417, 64418, 64419],
1726: [64426, 64427, 64428, 64429],
1728: [64420, 64421],
1729: [64422, 64423, 64424, 64425],
1733: [64480, 64481],
1734: [64473, 64474],
1735: [64471, 64472],
1736: [64475, 64476],
1737: [64482, 64483],
1739: [64478, 64479],
1740: [64508, 64509, 64510, 64511],
1744: [64484, 64485, 64486, 64487],
1746: [64430, 64431],
1747: [64432, 64433]
};
var arabiclaasubst = {
1570: [65269, 65270, 65269, 65270],
1571: [65271, 65272, 65271, 65272],
1573: [65273, 65274, 65273, 65274],
1575: [65275, 65276, 65275, 65276]
};
var arabicorigsubst = {
1570: [65153, 65154, 65153, 65154],
1571: [65155, 65156, 65155, 65156],
1573: [65159, 65160, 65159, 65160],
1575: [65165, 65166, 65165, 65166]
};
var arabic_diacritics = {
1612: 64606,
// Shadda + Dammatan
1613: 64607,
// Shadda + Kasratan
1614: 64608,
// Shadda + Fatha
1615: 64609,
// Shadda + Damma
1616: 64610 // Shadda + Kasra
};
var alfletter = [1570, 1571, 1573, 1575];
var endedletter = [1569, 1570, 1571, 1572, 1573, 1575, 1577, 1583, 1584, 1585, 1586, 1608, 1688];
var isolatedForm = 0;
var finalForm = 1;
var initialForm = 2;
var medialForm = 3; //private
function isArabicLetter(letter) {
return letter !== undefined && arabicSubst[letter.charCodeAt(0)] !== undefined;
}
function isArabicEndLetter(letter) {
return letter !== undefined && endedletter.indexOf(letter.charCodeAt(0)) >= 0;
}
function isArabicAlfLetter(letter) {
return letter !== undefined && alfletter.indexOf(letter.charCodeAt(0)) >= 0;
}
function arabicLetterHasFinalForm(letter) {
return isArabicLetter(letter) && arabicSubst[letter.charCodeAt(0)].length >= 2;
}
function arabicLetterHasMedialForm(letter) {
return isArabicLetter(letter) && arabicSubst[letter.charCodeAt(0)].length == 4;
}
function isArabicDiacritic(letter) {
return letter !== undefined && arabic_diacritics[letter.charCodeAt(0)] !== undefined;
}
function getCorrectForm(currentChar, beforeChar, nextChar, arabicSubstition) {
if (!isArabicLetter(currentChar)) {
return -1;
}
arabicSubstition = arabicSubstition || {};
arabicSubst = Object.assign(arabicSubst, arabicSubstition);
if (!arabicLetterHasFinalForm(currentChar) || !isArabicLetter(beforeChar) && !isArabicLetter(nextChar) || !isArabicLetter(nextChar) && isArabicEndLetter(beforeChar) || isArabicEndLetter(currentChar) && !isArabicLetter(beforeChar) || isArabicEndLetter(currentChar) && isArabicAlfLetter(beforeChar) || isArabicEndLetter(currentChar) && isArabicEndLetter(beforeChar)) {
arabicSubst = Object.assign(arabicSubst, arabicorigsubst);
return isolatedForm;
}
if (arabicLetterHasMedialForm(currentChar) && isArabicLetter(beforeChar) && !isArabicEndLetter(beforeChar) && isArabicLetter(nextChar) && arabicLetterHasFinalForm(nextChar)) {
arabicSubst = Object.assign(arabicSubst, arabicorigsubst);
return medialForm;
}
if (isArabicEndLetter(currentChar) || !isArabicLetter(nextChar)) {
arabicSubst = Object.assign(arabicSubst, arabicorigsubst);
return finalForm;
}
arabicSubst = Object.assign(arabicSubst, arabicorigsubst);
return initialForm;
}
var commonSubstition = function commonSubstition(character) {
var replacementTable = {
"(": ")",
")": "("
};
return replacementTable[character] || character;
};
/**
* @name processArabic
* @function
* @param {string} text
* @param {boolean} reverse
* @returns {string}
*/
var processArabic = jsPDFAPI.processArabic = function (text, reverse) {
text = text || "";
reverse = reverse || false;
var result = "";
var i = 0;
var position = 0;
var currentLetter = "";
var prevLetter = "";
var nextLetter = "";
var resultingLetter;
var localPrevLetter;
var localCurrentLetter;
var localNextLetter;
for (i = 0; i < text.length; i += 1) {
currentLetter = text[i];
prevLetter = text[i - 1];
nextLetter = text[i + 1];
if (!isArabicLetter(currentLetter)) {
result += reverse ? commonSubstition(currentLetter) : currentLetter;
} else {
if (prevLetter !== undefined && prevLetter.charCodeAt(0) === 1604 && isArabicAlfLetter(currentLetter)) {
localPrevLetter = text[i - 2];
localCurrentLetter = currentLetter;
localNextLetter = text[i + 1];
position = getCorrectForm(localCurrentLetter, localPrevLetter, localNextLetter, arabiclaasubst);
resultingLetter = String.fromCharCode(arabiclaasubst[currentLetter.charCodeAt(0)][position]);
result = result.substr(0, result.length - 1) + resultingLetter;
} else if (prevLetter !== undefined && prevLetter.charCodeAt(0) === 1617 && isArabicDiacritic(currentLetter)) {
localPrevLetter = text[i - 2];
localCurrentLetter = currentLetter;
localNextLetter = text[i + 1];
position = getCorrectForm(localCurrentLetter, localPrevLetter, localNextLetter, arabicorigsubst);
resultingLetter = String.fromCharCode(arabic_diacritics[currentLetter.charCodeAt(0)][position]);
result = result.substr(0, result.length - 1) + resultingLetter;
} else {
position = getCorrectForm(currentLetter, prevLetter, nextLetter, arabicorigsubst);
result += String.fromCharCode(arabicSubst[currentLetter.charCodeAt(0)][position]);
}
}
}
return reverse ? result.split("").reverse().join("") : result;
};
var arabicParserFunction = function arabicParserFunction(args) {
var text = args.text;
var x = args.x;
var y = args.y;
var options = args.options || {};
var mutex = args.mutex || {};
var lang = options.lang;
var tmpText = [];
if (arLangCodesKeys.indexOf(lang) >= 0) {
if (Object.prototype.toString.call(text) === "[object Array]") {
var i = 0;
tmpText = [];
for (i = 0; i < text.length; i += 1) {
if (Object.prototype.toString.call(text[i]) === "[object Array]") {
tmpText.push([processArabic(text[i][0], true), text[i][1], text[i][2]]);
} else {
tmpText.push([processArabic(text[i], true)]);
}
}
args.text = tmpText;
} else {
args.text = processArabic(text, true);
} //force charSpace if not given.
if (options.charSpace === undefined) {
args.options.charSpace = 0;
} //if R2L is true, set it false.
if (options.R2L === true) {
args.options.R2L = false;
}
}
};
jsPDFAPI.events.push(["preProcessText", arabicParserFunction]);
})(jsPDF.API);
/** @license
* jsPDF Autoprint Plugin
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* @name autoprint
* @module
*/
(function (jsPDFAPI) {
/**
* Makes the PDF automatically print. This works in Chrome, Firefox, Acrobat
* Reader.
*
* @name autoPrint
* @function
* @param {Object} options (optional) Set the attribute variant to 'non-conform' (default) or 'javascript' to activate different methods of automatic printing when opening in a PDF-viewer .
* @returns {jsPDF}
* @example
* var doc = new jsPDF();
* doc.text(10, 10, 'This is a test');
* doc.autoPrint({variant: 'non-conform'});
* doc.save('autoprint.pdf');
*/
jsPDFAPI.autoPrint = function (options) {
var refAutoPrintTag;
options = options || {};
options.variant = options.variant || "non-conform";
switch (options.variant) {
case "javascript":
//https://github.com/Rob--W/pdf.js/commit/c676ecb5a0f54677b9f3340c3ef2cf42225453bb
this.addJS("print({});");
break;
case "non-conform":
default:
this.internal.events.subscribe("postPutResources", function () {
refAutoPrintTag = this.internal.newObject();
this.internal.out("<<");
this.internal.out("/S /Named");
this.internal.out("/Type /Action");
this.internal.out("/N /Print");
this.internal.out(">>");
this.internal.out("endobj");
});
this.internal.events.subscribe("putCatalog", function () {
this.internal.out("/OpenAction " + refAutoPrintTag + " 0 R");
});
break;
}
return this;
};
})(jsPDF.API);
/**
* @license
* Copyright (c) 2014 Steven Spungin (TwelveTone LLC) steven@twelvetone.tv
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* jsPDF Canvas PlugIn
* This plugin mimics the HTML5 Canvas
*
* The goal is to provide a way for current canvas users to print directly to a PDF.
* @name canvas
* @module
*/
(function (jsPDFAPI) {
jsPDFAPI.events.push(["initialized", function () {
this.canvas.pdf = this;
}]);
/**
* @name canvas
* @static
* @type {Object}
*/
jsPDFAPI.canvas = {
/**
* @name getContext
* @function
* @param {string} the context type
*/
getContext: function getContext(name) {
this.pdf.context2d._canvas = this;
return this.pdf.context2d;
},
childNodes: [],
style: {},
autoContext2dResizeX: true,
autoContext2dResizeY: true
};
/**
* Width of the canvas
*
* @name width
* @property {number} width
*/
Object.defineProperty(jsPDFAPI.canvas, "width", {
get: function get() {
return this._width;
},
set: function set(value) {
this._width = value;
if (this.autoContext2dResizeX) {
this.getContext("2d").pageWrapX = value + 1;
}
}
});
/**
* Height of the canvas
*
* @name height
* @property {number} height
*/
Object.defineProperty(jsPDFAPI.canvas, "height", {
get: function get() {
return this._height;
},
set: function set(value) {
this._height = value;
if (this.autoContext2dResizeY) {
this.getContext("2d").pageWrapY = value + 1;
}
}
});
return this;
})(jsPDF.API);
/**
* @license
* ====================================================================
* Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com
* 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br
* 2013 Lee Driscoll, https://github.com/lsdriscoll
* 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
* 2014 James Hall, james@parall.ax
* 2014 Diego Casorran, https://github.com/diegocr
*
*
* ====================================================================
*/
/**
* @name cell
* @module
*/
(function (jsPDFAPI) {
/*jslint browser:true */
/*global document: false, jsPDF */
var padding = 3,
margin = 13,
headerFunction,
lastCellPos = {
x: undefined,
y: undefined,
w: undefined,
h: undefined,
ln: undefined
},
pages = 1,
setLastCellPosition = function setLastCellPosition(x, y, w, h, ln) {
lastCellPos = {
x: x,
y: y,
w: w,
h: h,
ln: ln
};
},
getLastCellPosition = function getLastCellPosition() {
return lastCellPos;
},
NO_MARGINS = {
left: 0,
top: 0,
bottom: 0
};
/**
* @name setHeaderFunction
* @function
* @param {function} func
*/
jsPDFAPI.setHeaderFunction = function (func) {
headerFunction = func;
};
/**
* @name getTextDimensions
* @function
* @param {string} txt
* @returns {Object} dimensions
*/
jsPDFAPI.getTextDimensions = function (text, options) {
var fontSize = this.table_font_size || this.internal.getFontSize();
var fontStyle = this.internal.getFont().fontStyle;
options = options || {};
var scaleFactor = options.scaleFactor || this.internal.scaleFactor;
var width = 0;
var amountOfLines = 0;
var height = 0;
var tempWidth = 0;
if (typeof text === "string") {
width = this.getStringUnitWidth(text) * fontSize;
if (width !== 0) {
amountOfLines = 1;
}
} else if (Object.prototype.toString.call(text) === "[object Array]") {
for (var i = 0; i < text.length; i++) {
tempWidth = this.getStringUnitWidth(text[i]) * fontSize;
if (width < tempWidth) {
width = tempWidth;
}
}
if (width !== 0) {
amountOfLines = text.length;
}
} else {
console.error("getTextDimensions expects text-parameter to be of type String or an Array of Strings.");
}
width = width / scaleFactor;
height = amountOfLines * fontSize * 1.15 / scaleFactor;
return {
w: width,
h: height
};
};
/**
* @name cellAddPage
* @function
*/
jsPDFAPI.cellAddPage = function () {
var margins = this.margins || NO_MARGINS;
this.addPage();
setLastCellPosition(margins.left, margins.top, undefined, undefined); //setLastCellPosition(undefined, undefined, undefined, undefined, undefined);
pages += 1;
};
/**
* @name cellInitialize
* @function
*/
jsPDFAPI.cellInitialize = function () {
lastCellPos = {
x: undefined,
y: undefined,
w: undefined,
h: undefined,
ln: undefined
};
pages = 1;
};
/**
* @name cell
* @function
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
* @param {string} txt
* @param {number} ln lineNumber
* @param {string} align
* @return {jsPDF} jsPDF-instance
*/
jsPDFAPI.cell = function (x, y, w, h, txt, ln, align) {
var curCell = getLastCellPosition();
var pgAdded = false; // If this is not the first cell, we must change its position
if (curCell.ln !== undefined) {
if (curCell.ln === ln) {
//Same line
x = curCell.x + curCell.w;
y = curCell.y;
} else {
//New line
var margins = this.margins || NO_MARGINS;
if (curCell.y + curCell.h + h + margin >= this.internal.pageSize.getHeight() - margins.bottom) {
this.cellAddPage();
pgAdded = true;
if (this.printHeaders && this.tableHeaderRow) {
this.printHeaderRow(ln, true);
}
} //We ignore the passed y: the lines may have different heights
y = getLastCellPosition().y + getLastCellPosition().h;
if (pgAdded) y = margin + 10;
}
}
if (txt[0] !== undefined) {
if (this.printingHeaderRow) {
this.rect(x, y, w, h, "FD");
} else {
this.rect(x, y, w, h);
}
if (align === "right") {
if (!(txt instanceof Array)) {
txt = [txt];
}
for (var i = 0; i < txt.length; i++) {
var currentLine = txt[i];
var textSize = this.getStringUnitWidth(currentLine) * this.internal.getFontSize();
this.text(currentLine, x + w - textSize - padding, y + this.internal.getLineHeight() * (i + 1));
}
} else {
this.text(txt, x + padding, y + this.internal.getLineHeight());
}
}
setLastCellPosition(x, y, w, h, ln);
return this;
};
/**
* Return the maximum value from an array
*
* @name arrayMax
* @function
* @param {Array} array
* @param comparisonFn
* @returns {number}
*/
jsPDFAPI.arrayMax = function (array, comparisonFn) {
var max = array[0],
i,
ln,
item;
for (i = 0, ln = array.length; i < ln; i += 1) {
item = array[i];
if (comparisonFn) {
if (comparisonFn(max, item) === -1) {
max = item;
}
} else {
if (item > max) {
max = item;
}
}
}
return max;
};
/**
* Create a table from a set of data.
* @name table
* @function
* @param {Integer} [x] : left-position for top-left corner of table
* @param {Integer} [y] top-position for top-left corner of table
* @param {Object[]} [data] As array of objects containing key-value pairs corresponding to a row of data.
* @param {String[]} [headers] Omit or null to auto-generate headers at a performance cost
* @param {Object} [config.printHeaders] True to print column headers at the top of every page
* @param {Object} [config.autoSize] True to dynamically set the column widths to match the widest cell value
* @param {Object} [config.margins] margin values for left, top, bottom, and width
* @param {Object} [config.fontSize] Integer fontSize to use (optional)
* @returns {jsPDF} jsPDF-instance
*/
jsPDFAPI.table = function (x, y, data, headers, config) {
if (!data) {
throw "No data for PDF table";
}
var headerNames = [],
headerPrompts = [],
header,
i,
ln,
cln,
columnMatrix = {},
columnWidths = {},
columnData,
column,
columnMinWidths = [],
j,
tableHeaderConfigs = [],
model,
jln,
func,
//set up defaults. If a value is provided in config, defaults will be overwritten:
autoSize = false,
printHeaders = true,
fontSize = 12,
margins = NO_MARGINS;
margins.width = this.internal.pageSize.getWidth();
if (config) {
//override config defaults if the user has specified non-default behavior:
if (config.autoSize === true) {
autoSize = true;
}
if (config.printHeaders === false) {
printHeaders = false;
}
if (config.fontSize) {
fontSize = config.fontSize;
}
if (config.css && typeof config.css["font-size"] !== "undefined") {
fontSize = config.css["font-size"] * 16;
}
if (config.margins) {
margins = config.margins;
}
}
/**
* @property {Number} lnMod
* Keep track of the current line number modifier used when creating cells
*/
this.lnMod = 0;
lastCellPos = {
x: undefined,
y: undefined,
w: undefined,
h: undefined,
ln: undefined
}, pages = 1;
this.printHeaders = printHeaders;
this.margins = margins;
this.setFontSize(fontSize);
this.table_font_size = fontSize; // Set header values
if (headers === undefined || headers === null) {
// No headers defined so we derive from data
headerNames = Object.keys(data[0]);
} else if (headers[0] && typeof headers[0] !== "string") {
var px2pt = 0.264583 * 72 / 25.4; // Split header configs into names and prompts
for (i = 0, ln = headers.length; i < ln; i += 1) {
header = headers[i];
headerNames.push(header.name);
headerPrompts.push(header.prompt);
columnWidths[header.name] = header.width * px2pt;
}
} else {
headerNames = headers;
}
if (autoSize) {
// Create a matrix of columns e.g., {column_title: [row1_Record, row2_Record]}
func = function func(rec) {
return rec[header];
};
for (i = 0, ln = headerNames.length; i < ln; i += 1) {
header = headerNames[i];
columnMatrix[header] = data.map(func); // get header width
columnMinWidths.push(this.getTextDimensions(headerPrompts[i] || header, {
scaleFactor: 1
}).w);
column = columnMatrix[header]; // get cell widths
for (j = 0, cln = column.length; j < cln; j += 1) {
columnData = column[j];
columnMinWidths.push(this.getTextDimensions(columnData, {
scaleFactor: 1
}).w);
} // get final column width
columnWidths[header] = jsPDFAPI.arrayMax(columnMinWidths); //have to reset
columnMinWidths = [];
}
} // -- Construct the table
if (printHeaders) {
var lineHeight = this.calculateLineHeight(headerNames, columnWidths, headerPrompts.length ? headerPrompts : headerNames); // Construct the header row
for (i = 0, ln = headerNames.length; i < ln; i += 1) {
header = headerNames[i];
tableHeaderConfigs.push([x, y, columnWidths[header], lineHeight, String(headerPrompts.length ? headerPrompts[i] : header)]);
} // Store the table header config
this.setTableHeaderRow(tableHeaderConfigs); // Print the header for the start of the table
this.printHeaderRow(1, false);
} // Construct the data rows
for (i = 0, ln = data.length; i < ln; i += 1) {
var lineHeight;
model = data[i];
lineHeight = this.calculateLineHeight(headerNames, columnWidths, model);
for (j = 0, jln = headerNames.length; j < jln; j += 1) {
header = headerNames[j];
this.cell(x, y, columnWidths[header], lineHeight, model[header], i + 2, header.align);
}
}
this.lastCellPos = lastCellPos;
this.table_x = x;
this.table_y = y;
return this;
};
/**
* Calculate the height for containing the highest column
*
* @name calculateLineHeight
* @function
* @param {String[]} headerNames is the header, used as keys to the data
* @param {Integer[]} columnWidths is size of each column
* @param {Object[]} model is the line of data we want to calculate the height of
* @returns {number} lineHeight
*/
jsPDFAPI.calculateLineHeight = function (headerNames, columnWidths, model) {
var header,
lineHeight = 0;
for (var j = 0; j < headerNames.length; j++) {
header = headerNames[j];
model[header] = this.splitTextToSize(String(model[header]), columnWidths[header] - padding);
var h = this.internal.getLineHeight() * model[header].length + padding;
if (h > lineHeight) lineHeight = h;
}
return lineHeight;
};
/**
* Store the config for outputting a table header
*
* @name setTableHeaderRow
* @function
* @param {Object[]} config
* An array of cell configs that would define a header row: Each config matches the config used by jsPDFAPI.cell
* except the ln parameter is excluded
*/
jsPDFAPI.setTableHeaderRow = function (config) {
this.tableHeaderRow = config;
};
/**
* Output the store header row
*
* @name printHeaderRow
* @function
* @param {number} lineNumber The line number to output the header at
* @param {boolean} new_page
*/
jsPDFAPI.printHeaderRow = function (lineNumber, new_page) {
if (!this.tableHeaderRow) {
throw "Property tableHeaderRow does not exist.";
}
var tableHeaderCell, tmpArray, i, ln;
this.printingHeaderRow = true;
if (headerFunction !== undefined) {
var position = headerFunction(this, pages);
setLastCellPosition(position[0], position[1], position[2], position[3], -1);
}
this.setFontStyle("bold");
var tempHeaderConf = [];
for (i = 0, ln = this.tableHeaderRow.length; i < ln; i += 1) {
this.setFillColor(200, 200, 200);
tableHeaderCell = this.tableHeaderRow[i];
if (new_page) {
this.margins.top = margin;
tableHeaderCell[1] = this.margins && this.margins.top || 0;
tempHeaderConf.push(tableHeaderCell);
}
tmpArray = [].concat(tableHeaderCell);
this.cell.apply(this, tmpArray.concat(lineNumber));
}
if (tempHeaderConf.length > 0) {
this.setTableHeaderRow(tempHeaderConf);
}
this.setFontStyle("normal");
this.printingHeaderRow = false;
};
})(jsPDF.API);
/**
* jsPDF Context2D PlugIn Copyright (c) 2014 Steven Spungin (TwelveTone LLC) steven@twelvetone.tv
*
* Licensed under the MIT License. http://opensource.org/licenses/mit-license
*/
/**
* TODO implement stroke opacity (refactor from fill() method )
* TODO transform angle and radii parameters
*/
/**
* This plugin mimics the HTML5 Canvas's context2d.
*
* The goal is to provide a way for current canvas implementations to print directly to a PDF.
*
* @name context2d
* @module
*/
(function (jsPDFAPI, globalObj) {
jsPDFAPI.events.push(["initialized", function () {
this.context2d.pdf = this;
this.context2d.internal.pdf = this;
this.context2d.ctx = new context();
this.context2d.ctxStack = [];
this.context2d.path = [];
}]);
jsPDFAPI.context2d = {
/**
* @name pageWrapXEnabled
* @type {boolean}
* @default false
*/
pageWrapXEnabled: false,
/**
* @name pageWrapYEnabled
* @type {boolean}
* @default false
*/
pageWrapYEnabled: false,
/**
* @name pageWrapX
* @type {number}
* @default 9999999
*/
pageWrapX: 9999999,
/**
* @name pageWrapY
* @type {number}
* @default 9999999
*/
pageWrapY: 9999999,
/**
* @name ctx
* @type {Object}
*/
ctx: new context(),
/**
* @name f2
* @type {function}
* @ignore
*/
f2: function f2(number) {
return number.toFixed(2);
},
/**
* Fills the current drawing (path)
*
* @name fill
* @function
* @description The fill() method fills the current drawing (path). The default color is black.
*/
fill: function fill() {
//evenodd or nonzero (default)
var rule = "fill";
this._drawPaths(rule, false);
},
/**
* Actually draws the path you have defined
*
* @name stroke
* @function
* @description The stroke() method actually draws the path you have defined with all those moveTo() and lineTo() methods. The default color is black.
*/
stroke: function stroke() {
var rule = "stroke";
this._drawPaths(rule, false);
},
/**
* Begins a path, or resets the current
*
* @name beginPath
* @function
* @description The beginPath() method begins a path, or resets the current path.
*/
beginPath: function beginPath() {
this._resetPath();
this._beginPath();
},
/**
* Moves the path to the specified point in the canvas, without creating a line
*
* @name moveTo
* @function
* @param x {Number} The x-coordinate of where to move the path to
* @param y {Number} The y-coordinate of where to move the path to
*/
moveTo: function moveTo(x, y) {
x = this._wrapX(x);
y = this._wrapY(y);
var xpt = this._matrix_map_point(this.ctx._transform, [x, y]);
x = xpt[0];
y = xpt[1];
var obj = {
type: "mt",
x: x,
y: y
};
this.path.push(obj);
},
/**
* Creates a path from the current point back to the starting point
*
* @name closePath
* @function
* @description The closePath() method creates a path from the current point back to the starting point.
*/
closePath: function closePath() {
this._closePath();
var obj = {
type: "close"
};
this.path.push(obj);
},
/**
* Adds a new point and creates a line to that point from the last specified point in the canvas
*
* @name lineTo
* @function
* @param x The x-coordinate of where to create the line to
* @param y The y-coordinate of where to create the line to
* @description The lineTo() method adds a new point and creates a line TO that point FROM the last specified point in the canvas (this method does not draw the line).
*/
lineTo: function lineTo(x, y) {
x = this._wrapX(x);
y = this._wrapY(y);
var xpt = this._matrix_map_point(this.ctx._transform, [x, y]);
x = xpt[0];
y = xpt[1];
var obj = {
type: "lt",
x: x,
y: y
};
this.path.push(obj);
},
/**
* Clips a region of any shape and size from the original canvas
*
* @name clip
* @function
* @description The clip() method clips a region of any shape and size from the original canvas.
*/
clip: function clip() {
this._drawPaths(null, true);
},
/**
* Creates a cubic Bézier curve
*
* @name quadraticCurveTo
* @function
* @param cpx {Number} The x-coordinate of the Bézier control point
* @param cpy {Number} The y-coordinate of the Bézier control point
* @param x {Number} The x-coordinate of the ending point
* @param y {Number} The y-coordinate of the ending point
* @description The quadraticCurveTo() method adds a point to the current path by using the specified control points that represent a quadratic Bézier curve.<br /><br /> A quadratic Bézier curve requires two points. The first point is a control point that is used in the quadratic Bézier calculation and the second point is the ending point for the curve. The starting point for the curve is the last point in the current path. If a path does not exist, use the beginPath() and moveTo() methods to define a starting point.
*/
quadraticCurveTo: function quadraticCurveTo(cpx, cpy, x, y) {
var x1 = this._wrapX(cpx);
var y1 = this._wrapY(cpy);
x = this._wrapX(x);
y = this._wrapY(y);
var xpt;
xpt = this._matrix_map_point(this.ctx._transform, [x, y]);
x = xpt[0];
y = xpt[1];
xpt = this._matrix_map_point(this.ctx._transform, [x1, y1]);
x1 = xpt[0];
y1 = xpt[1];
var obj = {
type: "qct",
x1: x1,
y1: y1,
x: x,
y: y
};
this.path.push(obj);
},
/**
* Creates a cubic Bézier curve
*
* @name bezierCurveTo
* @function
* @param cp1x {Number} The x-coordinate of the first Bézier control point
* @param cp1y {Number} The y-coordinate of the first Bézier control point
* @param cp2x {Number} The x-coordinate of the second Bézier control point
* @param cp2y {Number} The y-coordinate of the second Bézier control point
* @param x {Number} The x-coordinate of the ending point
* @param y {Number} The y-coordinate of the ending point
* @description The bezierCurveTo() method adds a point to the current path by using the specified control points that represent a cubic Bézier curve. <br /><br />A cubic bezier curve requires three points. The first two points are control points that are used in the cubic Bézier calculation and the last point is the ending point for the curve. The starting point for the curve is the last point in the current path. If a path does not exist, use the beginPath() and moveTo() methods to define a starting point.
*/
bezierCurveTo: function bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
var x1 = this._wrapX(cp1x);
var y1 = this._wrapY(cp1y);
var x2 = this._wrapX(cp2x);
var y2 = this._wrapY(cp2y);
x = this._wrapX(x);
y = this._wrapY(y);
var xpt;
xpt = this._matrix_map_point(this.ctx._transform, [x, y]);
x = xpt[0];
y = xpt[1];
xpt = this._matrix_map_point(this.ctx._transform, [x1, y1]);
x1 = xpt[0];
y1 = xpt[1];
xpt = this._matrix_map_point(this.ctx._transform, [x2, y2]);
x2 = xpt[0];
y2 = xpt[1];
var obj = {
type: "bct",
x1: x1,
y1: y1,
x2: x2,
y2: y2,
x: x,
y: y
};
this.path.push(obj);
},
/**
* Creates an arc/curve (used to create circles, or parts of circles)
*
* @name arc
* @function
* @param x {Number} The x-coordinate of the center of the circle
* @param y {Number} The y-coordinate of the center of the circle
* @param radius {Number} The radius of the circle
* @param startAngle {Number} The starting angle, in radians (0 is at the 3 o'clock position of the arc's circle)
* @param endAngle {Number} The ending angle, in radians
* @param counterclockwise {Boolean} Optional. Specifies whether the drawing should be counterclockwise or clockwise. False is default, and indicates clockwise, while true indicates counter-clockwise.
* @description The arc() method creates an arc/curve (used to create circles, or parts of circles).
*/
arc: function arc(x, y, radius, startAngle, endAngle, counterclockwise) {
x = this._wrapX(x);
y = this._wrapY(y);
counterclockwise = counterclockwise || false;
if (!this._matrix_is_identity(this.ctx._transform)) {
var xpt = this._matrix_map_point(this.ctx._transform, [x, y]);
x = xpt[0];
y = xpt[1];
var x_radPt0 = this._matrix_map_point(this.ctx._transform, [0, 0]);
var x_radPt = this._matrix_map_point(this.ctx._transform, [0, radius]);
radius = Math.sqrt(Math.pow(x_radPt[0] - x_radPt0[0], 2) + Math.pow(x_radPt[1] - x_radPt0[1], 2));
}
var obj = {
type: "arc",
x: x,
y: y,
radius: radius,
startAngle: startAngle,
endAngle: endAngle,
counterclockwise: counterclockwise
};
this.path.push(obj);
},
/**
* Creates an arc/curve between two tangents
*
* @name arcTo
* @function
* @param x1 {Number} The x-coordinate of the first tangent
* @param y1 {Number} The y-coordinate of the first tangent
* @param x2 {Number} The x-coordinate of the second tangent
* @param y2 {Number} The y-coordinate of the second tangent
* @param radius The radius of the
* @description The arcTo() method creates an arc/curve between two tangents on the canvas.
*/
arcTo: function arcTo(x1, y1, x2, y2, radius) {//TODO needs to be implemented
},
//Rectangles
/**
* Creates a rectangle
*
* @name rect
* @function
* @param x {Number} The x-coordinate of the upper-left corner of the rectangle
* @param y {Number} The y-coordinate of the upper-left corner of the rectangle
* @param w {Number} The width of the rectangle, in pixels
* @param h {Number} The height of the rectangle, in pixels
* @description The rect() method creates a rectangle.
*/
rect: function rect(x, y, w, h) {
this.moveTo(x, y);
this.lineTo(x + w, y);
this.lineTo(x + w, y + h);
this.lineTo(x, y + h);
this.lineTo(x, y);
this.lineTo(x + w, y);
this.lineTo(x, y);
},
/**
* Draws a "filled" rectangle
*
* @name fillRect
* @function
* @param x {Number} The x-coordinate of the upper-left corner of the rectangle
* @param y {Number} The y-coordinate of the upper-left corner of the rectangle
* @param w {Number} The width of the rectangle, in pixels
* @param h {Number} The height of the rectangle, in pixels
* @description The fillRect() method draws a "filled" rectangle. The default color of the fill is black.
*/
fillRect: function fillRect(x, y, w, h) {
if (this._isFillTransparent()) {
return;
}
x = this._wrapX(x);
y = this._wrapY(y);
var xpt1 = this._matrix_map_point(this.ctx._transform, [x, y]);
var xpt2 = this._matrix_map_point(this.ctx._transform, [x + w, y]);
var xpt3 = this._matrix_map_point(this.ctx._transform, [x + w, y + h]);
var xpt4 = this._matrix_map_point(this.ctx._transform, [x, y + h]);
this.pdf.internal.out("q");
this.pdf.setLineCap("butt");
this.pdf.setLineJoin("miter");
var lines = [];
lines.push([xpt2[0] - xpt1[0], xpt2[1] - xpt1[1]]);
lines.push([xpt3[0] - xpt2[0], xpt3[1] - xpt2[1]]);
lines.push([xpt4[0] - xpt3[0], xpt4[1] - xpt3[1]]);
lines.push([xpt1[0] - xpt4[0], xpt1[1] - xpt4[1]]);
lines.push([xpt2[0] - xpt1[0], xpt2[1] - xpt1[1]]);
lines.push([xpt1[0] - xpt2[0], xpt1[1] - xpt2[1]]);
this.pdf.lines(lines, xpt1[0], xpt1[1], null, "F");
this.pdf.internal.out("Q");
},
/**
* Draws a rectangle (no fill)
*
* @name strokeRect
* @function
* @param x {Number} The x-coordinate of the upper-left corner of the rectangle
* @param y {Number} The y-coordinate of the upper-left corner of the rectangle
* @param w {Number} The width of the rectangle, in pixels
* @param h {Number} The height of the rectangle, in pixels
* @description The strokeRect() method draws a rectangle (no fill). The default color of the stroke is black.
*/
strokeRect: function strokeRect(x, y, w, h) {
if (this._isStrokeTransparent()) {
return;
}
x = this._wrapX(x);
y = this._wrapY(y);
var xpt1 = this._matrix_map_point(this.ctx._transform, [x, y]);
var xpt2 = this._matrix_map_point(this.ctx._transform, [x + w, y]);
var xpt3 = this._matrix_map_point(this.ctx._transform, [x + w, y + h]);
var xpt4 = this._matrix_map_point(this.ctx._transform, [x, y + h]);
var lines = [];
lines.push([xpt2[0] - xpt1[0], xpt2[1] - xpt1[1]]);
lines.push([xpt3[0] - xpt2[0], xpt3[1] - xpt2[1]]);
lines.push([xpt4[0] - xpt3[0], xpt4[1] - xpt3[1]]);
lines.push([xpt1[0] - xpt4[0], xpt1[1] - xpt4[1]]);
lines.push([xpt2[0] - xpt1[0], xpt2[1] - xpt1[1]]);
lines.push([xpt1[0] - xpt2[0], xpt1[1] - xpt2[1]]);
this.pdf.lines(lines, xpt1[0], xpt1[1], null, "S");
},
/**
* Clears the specified pixels within a given rectangle
*
* @name clearRect
* @function
* @param x {Number} The x-coordinate of the upper-left corner of the rectangle
* @param y {Number} The y-coordinate of the upper-left corner of the rectangle
* @param w {Number} The width of the rectangle to clear, in pixels
* @param h {Number} The height of the rectangle to clear, in pixels
* @description We cannot clear PDF commands that were already written to PDF, so we use white instead. <br />
* As a special case, read a special flag (ignoreClearRect) and do nothing if it is set.
* This results in all calls to clearRect() to do nothing, and keep the canvas transparent.
* This flag is stored in the save/restore context and is managed the same way as other drawing states.
*
*/
clearRect: function clearRect(x, y, w, h) {
if (this.ctx.ignoreClearRect) {
return;
}
this.save();
this._setFillStyle("#ffffff");
this.fillRect(x, y, w, h);
this.restore();
},
//Other
/**
* Saves the state of the current context
*
* @name save
* @function
*/
save: function save() {
this.pdf.internal.out("q");
this.ctx._fontSize = this.pdf.internal.getFontSize();
var ctx = new context();
ctx.copy(this.ctx);
this.ctxStack.push(this.ctx);
this.ctx = ctx;
},
/**
* Returns previously saved path state and attributes
*
* @name restore
* @function
*/
restore: function restore() {
this.pdf.internal.out("Q");
if (this.ctxStack.length !== 0) {
this.ctx = this.ctxStack.pop();
this._setFillStyle(this.ctx.fillStyle);
this._setStrokeStyle(this.ctx.strokeStyle);
this._setFont(this.ctx.font);
this.pdf.setFontSize(this.ctx._fontSize);
this._setLineCap(this.ctx.lineCap);
this._setLineWidth(this.ctx.lineWidth);
this._setLineJoin(this.ctx.lineJoin);
}
},
// some stubs
/**
* @name createEvent
* @function
*/
createEvent: function createEvent() {
console.log("createEvent not implemented (yet)");
},
/**
* @name toDataURL
* @function
*/
toDataURL: function toDataURL() {
console.log("toDataUrl not implemented (yet)");
},
//helper functions
_beginPath: function _beginPath() {
this.path.push({
type: "begin"
});
},
_closePath: function _closePath() {
var pathBegin = {
x: 0,
y: 0
};
var i = 0;
var len = this.path.length;
for (i = this.path.length - 1; i !== -1; i--) {
if (this.path[i].type === "begin") {
if (_typeof(this.path[i + 1]) === "object" && typeof this.path[i + 1].x === "number") {
pathBegin = {
x: this.path[i + 1].x,
y: this.path[i + 1].y
};
var obj = {
type: "lt",
x: pathBegin.x,
y: pathBegin.y
};
this.path.push(obj);
break;
}
}
} //TODO Repeat second move to get lineJoins correct, maybe only when lineJoin active in _drawPaths
if (_typeof(this.path[i + 2]) === "object" && typeof this.path[i + 2].x === "number") {
this.path.push(JSON.parse(JSON.stringify(this.path[i + 2])));
}
},
_resetPath: function _resetPath() {
this.path = [];
},
/**
* Get the decimal values of r, g, b and a
*
* @name _getRGBA
* @function
* @private
* @ignore
*/
_getRGBA: function _getRGBA(style) {
var r, g, b, a;
if (style.isCanvasGradient === true) {
style = style.getColor();
}
var rgbColor = new RGBColor(style);
if (!style) {
return {
r: 0,
g: 0,
b: 0,
a: 0,
style: style
};
}
if (this.internal.rxTransparent.test(style)) {
r = 0;
g = 0;
b = 0;
a = 0;
} else {
var m = this.internal.rxRgb.exec(style);
if (m != null) {
r = parseInt(m[1]);
g = parseInt(m[2]);
b = parseInt(m[3]);
a = 1;
} else {
m = this.internal.rxRgba.exec(style);
if (m != null) {
r = parseInt(m[1]);
g = parseInt(m[2]);
b = parseInt(m[3]);
a = parseFloat(m[4]);
} else {
a = 1;
if (style.charAt(0) != "#") {
if (rgbColor.ok) {
style = rgbColor.toHex();
} else {
style = "#000000";
}
}
if (style.length === 4) {
r = style.substring(1, 2);
r += r;
g = style.substring(2, 3);
g += g;
b = style.substring(3, 4);
b += b;
} else {
r = style.substring(1, 3);
g = style.substring(3, 5);
b = style.substring(5, 7);
}
r = parseInt(r, 16);
g = parseInt(g, 16);
b = parseInt(b, 16);
}
}
}
return {
r: r,
g: g,
b: b,
a: a,
style: style
};
},
/**
* @name _isFilllTransparent
* @function
* @private
* @ignore
* @returns {Boolean}
*/
_isFillTransparent: function _isFillTransparent() {
return this.ctx._isFillTransparent || this.globalAlpha == 0;
},
/**
* @name _isStrokeTransparent
* @function
* @private
* @ignore
* @returns {Boolean}
*/
_isStrokeTransparent: function _isStrokeTransparent() {
return this.ctx._isStrokeTransparent || this.globalAlpha == 0;
},
/**
* Sets the color, gradient, or pattern used to fill the drawing
*
* @name _setFillStyle
* @function
* @private
* @ignore
*/
_setFillStyle: function _setFillStyle(style) {
var rgba;
rgba = this._getRGBA(style);
this.ctx.fillStyle = style;
this.ctx._isFillTransparent = rgba.a === 0;
this.ctx._fillOpacity = rgba.a;
this.pdf.setFillColor(rgba.r, rgba.g, rgba.b, {
a: rgba.a
});
this.pdf.setTextColor(rgba.r, rgba.g, rgba.b, {
a: rgba.a
});
},
/**
* Sets the color, gradient, or pattern used for strokes
*
* @name _setStrokeStyle
* @function
* @private
* @ignore
*/
_setStrokeStyle: function _setStrokeStyle(style) {
var rgba = this._getRGBA(style);
this.ctx.strokeStyle = rgba.style;
this.ctx._isStrokeTransparent = rgba.a === 0;
this.ctx._strokeOpacity = rgba.a; //TODO jsPDF to handle rgba
if (rgba.a === 0) {
this.pdf.setDrawColor(255, 255, 255);
} else if (rgba.a === 1) {
this.pdf.setDrawColor(rgba.r, rgba.g, rgba.b);
} else {
//this.pdf.setDrawColor(rgba.r, rgba.g, rgba.b, {a: rgba.a});
this.pdf.setDrawColor(rgba.r, rgba.g, rgba.b);
}
},
/**
* Sets font properties for text content
*
* @name _setFont
* @function
* @param {String} The font property uses the same syntax as the CSS font property.
* @private
* @ignore
*/
_setFont: function _setFont(font) {
this.ctx.font = font;
var rx, m; //source: https://stackoverflow.com/a/10136041
rx = /^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\"\'\sa-z]+?)\s*$/i;
m = rx.exec(font);
if (m != null) {
var fontStyle = m[1];
var fontVariant = m[2];
var fontWeight = m[3];
var fontSize = m[4];
var fontSizeUnit = m[5];
var fontFamily = m[6];
} else {
return;
}
if ("px" === fontSizeUnit) {
fontSize = Math.floor(parseFloat(fontSize)); // fontSize = fontSize * 1.25;
} else if ("em" === fontSizeUnit) {
fontSize = Math.floor(parseFloat(fontSize) * this.pdf.getFontSize());
} else {
fontSize = Math.floor(parseFloat(fontSize));
}
this.pdf.setFontSize(fontSize);
var style = "";
if (fontWeight === "bold" || parseInt(fontWeight, 10) >= 700 || fontStyle === "bold") {
style = "bold";
}
if (fontStyle === "italic") {
style += "italic";
}
if (style.length === 0) {
style = "normal";
}
var jsPdfFontName = "";
var parts = fontFamily.toLowerCase().replace(/"|'/g, "").split(/\s*,\s*/);
var fallbackFonts = {
arial: "Helvetica",
verdana: "Helvetica",
helvetica: "Helvetica",
"sans-serif": "Helvetica",
fixed: "Courier",
monospace: "Courier",
terminal: "Courier",
courier: "Courier",
times: "Times",
cursive: "Times",
fantasy: "Times",
serif: "Times"
};
for (var i = 0; i < parts.length; i++) {
if (this.pdf.internal.getFont(parts[i], style, {
noFallback: true,
disableWarning: true
}) !== undefined) {
jsPdfFontName = parts[i];
break;
} else if (style === "bolditalic" && this.pdf.internal.getFont(parts[i], "bold", {
noFallback: true,
disableWarning: true
}) !== undefined) {
jsPdfFontName = parts[i];
style = "bold";
} else if (this.pdf.internal.getFont(parts[i], "normal", {
noFallback: true,
disableWarning: true
}) !== undefined) {
jsPdfFontName = parts[i];
style = "normal";
break;
}
}
if (jsPdfFontName === "") {
for (var i = 0; i < parts.length; i++) {
if (fallbackFonts[parts[i]]) {
jsPdfFontName = fallbackFonts[parts[i]];
break;
}
}
}
jsPdfFontName = jsPdfFontName === "" ? "Times" : jsPdfFontName;
this.pdf.setFont(jsPdfFontName, style);
},
/**
* @name _setTextBaseline
* @function
* @private
* @ignore
*/
_setTextBaseline: function _setTextBaseline(baseline) {
this.ctx.textBaseline = baseline;
},
/**
* @name _getTextBaseline
* @function
* @private
* @ignore
* @returns {Number}
*/
_getTextBaseline: function _getTextBaseline() {
return this.ctx.textBaseline;
},
/**
* @name _setTextAlign
* @function
* @private
* @ignore
*/
_setTextAlign: function _setTextAlign(canvasAlign) {
switch (canvasAlign) {
case "right":
case "end":
this.ctx.textAlign = "right";
break;
case "center":
this.ctx.textAlign = "center";
break;
case "left":
case "start":
default:
this.ctx.textAlign = "left";
break;
}
},
/**
* @name _getTextAlign
* @function
* @private
* @ignore
* @returns {String}
*/
_getTextAlign: function _getTextAlign() {
return this.ctx.textAlign;
},
/**
* Draws "filled" text on the canvas
*
* @name fillText
* @function
* @param text {String} Specifies the text that will be written on the canvas
* @param x {Number} The x coordinate where to start painting the text (relative to the canvas)
* @param y {Number} The y coordinate where to start painting the text (relative to the canvas)
* @param maxWidth {Number} Optional. The maximum allowed width of the text, in pixels
* @description The fillText() method draws filled text on the canvas. The default color of the text is black.
*/
fillText: function fillText(text, x, y, maxWidth) {
if (this._isFillTransparent()) {
return;
}
x = this._wrapX(x);
y = this._wrapY(y);
var xpt = this._matrix_map_point(this.ctx._transform, [x, y]);
x = xpt[0];
y = xpt[1];
var rads = this._matrix_rotation(this.ctx._transform);
var degs = rads * 57.2958; // We only use X axis as scale hint
var scale = 1;
try {
scale = this._matrix_decompose(this._getTransform()).scale[0];
} catch (e) {
console.warn(e);
} // In some cases the transform was very small (5.715760606202283e-17). Most likely a canvg rounding error.
if (scale < 0.01) {
this.pdf.text(text, x, this._getBaseline(y), {
angle: degs,
align: this.textAlign
});
} else {
var oldSize = this.pdf.internal.getFontSize();
this.pdf.setFontSize(oldSize * scale);
this.pdf.text(text, x, this._getBaseline(y), {
angle: degs,
align: this.textAlign
});
this.pdf.setFontSize(oldSize);
}
},
/**
* Draws text on the canvas (no fill)
*
* @name strokeText
* @function
* @param text {String} Specifies the text that will be written on the canvas
* @param x {Number} The x coordinate where to start painting the text (relative to the canvas)
* @param y {Number} The y coordinate where to start painting the text (relative to the canvas)
* @param maxWidth {Number} Optional. The maximum allowed width of the text, in pixels
* @description The strokeText() method draws text (with no fill) on the canvas. The default color of the text is black.
*/
strokeText: function strokeText(text, x, y, maxWidth) {
if (this._isStrokeTransparent()) {
return;
}
x = this._wrapX(x);
y = this._wrapY(y);
var xpt = this._matrix_map_point(this.ctx._transform, [x, y]);
x = xpt[0];
y = xpt[1];
var rads = this._matrix_rotation(this.ctx._transform);
var degs = rads * 57.2958;
var scale = 1; // We only use the X axis as scale hint
try {
scale = this._matrix_decompose(this._getTransform()).scale[0];
} catch (e) {
console.warn(e);
}
if (scale < 0.01) {
this.pdf.text(text, x, this._getBaseline(y), {
angle: degs,
align: this.textAlign,
renderingMode: "stroke"
});
} else {
var oldSize = this.pdf.internal.getFontSize();
this.pdf.setFontSize(oldSize * scale);
this.pdf.text(text, x, this._getBaseline(y), {
angle: degs,
align: this.textAlign,
renderingMode: "stroke"
});
this.pdf.setFontSize(oldSize);
}
},
/**
* Returns an object that contains the width of the specified text
*
* @name measureText
* @function
* @param text {String} The text to be measured
* @description The measureText() method returns an object that contains the width of the specified text, in pixels.
* @returns {Number}
*/
measureText: function measureText(text) {
var pdf = this.pdf;
return {
getWidth: function getWidth() {
var fontSize = pdf.internal.getFontSize();
var txtWidth = pdf.getStringUnitWidth(text) * fontSize / pdf.internal.scaleFactor; // Convert points to pixels
//TODO Use scaleFactor?
txtWidth *= 1.3333;
return txtWidth;
},
get width() {
return this.getWidth(text);
}
};
},
//Line Styles
/**
*
* @name _setLineWidth
* @function
* @private
* @ignore
*/
_setLineWidth: function _setLineWidth(width) {
this.ctx.lineWidth = width;
this.pdf.setLineWidth(width);
},
/**
* @name _setLineCap
* @function
* @private
* @ignore
*/
_setLineCap: function _setLineCap(style) {
this.ctx.lineCap = style;
this.pdf.setLineCap(style);
},
/**
*
* @name _setLineJoin
* @function
* @private
* @ignore
*/
_setLineJoin: function _setLineJoin(style) {
this.ctx.lineJoin = style;
this.pdf.setLineJoin(style);
},
/**
*
* @name _getLineJoin
* @function
* @private
* @ignore
*/
_getLineJoin: function _getLineJoin() {
return this.ctx.lineJoin;
},
/**
*
* @name _wrapX
* @function
* @private
* @ignore
*/
_wrapX: function _wrapX(x) {
if (this.pageWrapXEnabled) {
return x % this.pageWrapX;
} else {
return x;
}
},
/**
* @name _wrapY
* @function
* @private
* @ignore
*/
_wrapY: function _wrapY(y) {
if (this.pageWrapYEnabled) {
this._gotoPage(this._page(y));
return (y - this.lastBreak) % this.pageWrapY;
} else {
return y;
}
},
//Transformations
/**
* Scales the current drawing bigger or smaller
*
* @name scale
* @function
* @param scalewidth {Number} Scales the width of the current drawing (1=100%, 0.5=50%, 2=200%, etc.)
* @param scaleheight {Number} Scales the height of the current drawing (1=100%, 0.5=50%, 2=200%, etc.)
* @description The scale() method scales the current drawing, bigger or smaller.
*/
scale: function scale(scalewidth, scaleheight) {
var matrix = [scalewidth, 0.0, 0.0, scaleheight, 0.0, 0.0];
this.ctx._transform = this._matrix_multiply(this.ctx._transform, matrix);
},
/**
* Rotates the current drawing
*
* @name rotate
* @function
* @param angle {Number} The rotation angle, in radians.
* @description To calculate from degrees to radians: degrees*Math.PI/180. <br />
* Example: to rotate 5 degrees, specify the following: 5*Math.PI/180
*/
rotate: function rotate(angle) {
var matrix = [Math.cos(angle), Math.sin(angle), -Math.sin(angle), Math.cos(angle), 0.0, 0.0];
this.ctx._transform = this._matrix_multiply(this.ctx._transform, matrix);
},
/**
* Remaps the (0,0) position on the canvas
*
* @name translate
* @function
* @param x {Number} The value to add to horizontal (x) coordinates
* @param y {Number} The value to add to vertical (y) coordinates
* @description The translate() method remaps the (0,0) position on the canvas.
*/
translate: function translate(x, y) {
var matrix = [1.0, 0.0, 0.0, 1.0, x, y];
this.ctx._transform = this._matrix_multiply(this.ctx._transform, matrix);
},
/**
* Replaces the current transformation matrix for the drawing
*
* @name transform
* @function
* @param a {Number} Horizontal scaling
* @param b {Number} Horizontal skewing
* @param c {Number} Vertical skewing
* @param d {Number} Vertical scaling
* @param e {Number} Horizontal moving
* @param f {Number} Vertical moving
* @description Each object on the canvas has a current transformation matrix.<br /><br />The transform() method replaces the current transformation matrix. It multiplies the current transformation matrix with the matrix described by:<br /><br /><br /><br />a c e<br /><br />b d f<br /><br />0 0 1<br /><br />In other words, the transform() method lets you scale, rotate, move, and skew the current context.
*/
transform: function transform(a, b, c, d, e, f) {
this.ctx._transform = this._matrix_multiply(this.ctx._transform, [a, b, c, d, e, f]);
},
/**
* Resets the current transform to the identity matrix. Then runs transform()
*
* @name setTransform
* @function
* @param a {Number} Horizontal scaling
* @param b {Number} Horizontal skewing
* @param c {Number} Vertical skewing
* @param d {Number} Vertical scaling
* @param e {Number} Horizontal moving
* @param f {Number} Vertical moving
* @description Each object on the canvas has a current transformation matrix. <br /><br />The setTransform() method resets the current transform to the identity matrix, and then runs transform() with the same arguments.<br /><br />In other words, the setTransform() method lets you scale, rotate, move, and skew the current context.
*/
setTransform: function setTransform(a, b, c, d, e, f) {
this.ctx._transform = [a, b, c, d, e, f];
},
/**
* @name _getTransform
* @function
* @private
* @ignore
*/
_getTransform: function _getTransform() {
return this.ctx._transform;
},
lastBreak: 0,
// Y Position of page breaks.
pageBreaks: [],
/**
* Should only be used if pageWrapYEnabled is true
*
* @name _page
* @function
* @private
* @ignore
* @returns One-based Page Number
*/
_page: function _page(y) {
if (this.pageWrapYEnabled) {
this.lastBreak = 0;
var manualBreaks = 0;
var autoBreaks = 0;
for (var i = 0; i < this.pageBreaks.length; i++) {
if (y >= this.pageBreaks[i]) {
manualBreaks++;
if (this.lastBreak === 0) {
autoBreaks++;
}
var spaceBetweenLastBreak = this.pageBreaks[i] - this.lastBreak;
this.lastBreak = this.pageBreaks[i];
var pagesSinceLastBreak = Math.floor(spaceBetweenLastBreak / this.pageWrapY);
autoBreaks += pagesSinceLastBreak;
}
}
if (this.lastBreak === 0) {
var pagesSinceLastBreak = Math.floor(y / this.pageWrapY) + 1;
autoBreaks += pagesSinceLastBreak;
}
return autoBreaks + manualBreaks;
} else {
return this.pdf.internal.getCurrentPageInfo().pageNumber;
}
},
_gotoPage: function _gotoPage(pageOneBased) {// This is a stub to be overriden if needed
},
/**
* Draws an image, canvas, or video onto the canvas
*
* @function
* @param img {} Specifies the image, canvas, or video element to use
* @param sx {Number} Optional. The x coordinate where to start clipping
* @param sy {Number} Optional. The y coordinate where to start clipping
* @param swidth {Number} Optional. The width of the clipped image
* @param sheight {Number} Optional. The height of the clipped image
* @param x {Number} The x coordinate where to place the image on the canvas
* @param y {Number} The y coordinate where to place the image on the canvas
* @param width {Number} Optional. The width of the image to use (stretch or reduce the image)
* @param height {Number} Optional. The height of the image to use (stretch or reduce the image)
*
*/
drawImage: function drawImage(img, x, y, w, h, x2, y2, w2, h2) {
if (x2 !== undefined) {
x = x2;
y = y2;
w = w2;
h = h2;
}
x = this._wrapX(x);
y = this._wrapY(y);
var xRect = this._matrix_map_rect(this.ctx._transform, {
x: x,
y: y,
w: w,
h: h
});
var xRect2 = this._matrix_map_rect(this.ctx._transform, {
x: x2,
y: y2,
w: w2,
h: h2
}); // TODO implement source clipping and image scaling
var format;
var rx = /data:image\/(\w+).*/i;
var m = rx.exec(img);
if (m != null) {
format = m[1];
} else {
// format = "jpeg";
format = "png";
}
this.pdf.addImage(img, format, xRect.x, xRect.y, xRect.w, xRect.h);
},
/**
* Multiply the first matrix by the second
*
* @name matrix_multiply
* @function
* @param m1
* @param m2
* @returns {Array}
* @private
* @ignore
*/
_matrix_multiply: function _matrix_multiply(m2, m1) {
var sx = m1[0];
var shy = m1[1];
var shx = m1[2];
var sy = m1[3];
var tx = m1[4];
var ty = m1[5];
var t0 = sx * m2[0] + shy * m2[2];
var t2 = shx * m2[0] + sy * m2[2];
var t4 = tx * m2[0] + ty * m2[2] + m2[4];
shy = sx * m2[1] + shy * m2[3];
sy = shx * m2[1] + sy * m2[3];
ty = tx * m2[1] + ty * m2[3] + m2[5];
sx = t0;
shx = t2;
tx = t4;
return [sx, shy, shx, sy, tx, ty];
},
/**
* @name _matrix_rotation
* @function
* @private
* @ignore
*/
_matrix_rotation: function _matrix_rotation(m) {
return Math.atan2(m[2], m[0]);
},
/**
* @name _matrix_decompose
* @function
* @private
* @ignore
*/
_matrix_decompose: function _matrix_decompose(matrix) {
var a = matrix[0];
var b = matrix[1];
var c = matrix[2];
var d = matrix[3];
var scaleX = Math.sqrt(a * a + b * b);
a /= scaleX;
b /= scaleX;
var shear = a * c + b * d;
c -= a * shear;
d -= b * shear;
var scaleY = Math.sqrt(c * c + d * d);
c /= scaleY;
d /= scaleY;
shear /= scaleY;
if (a * d < b * c) {
a = -a;
b = -b;
shear = -shear;
scaleX = -scaleX;
}
return {
scale: [scaleX, 0, 0, scaleY, 0, 0],
translate: [1, 0, 0, 1, matrix[4], matrix[5]],
rotate: [a, b, -b, a, 0, 0],
skew: [1, 0, shear, 1, 0, 0]
};
},
/**
* @name _matrix_map_point
* @function
* @private
* @ignore
*/
_matrix_map_point: function _matrix_map_point(m1, pt) {
var sx = m1[0];
var shy = m1[1];
var shx = m1[2];
var sy = m1[3];
var tx = m1[4];
var ty = m1[5];
var px = pt[0];
var py = pt[1];
var x = px * sx + py * shx + tx;
var y = px * shy + py * sy + ty;
return [x, y];
},
/**
* @name _matrix_map_point_obj
* @function
* @private
* @ignore
*/
_matrix_map_point_obj: function _matrix_map_point_obj(m1, pt) {
var xpt = this._matrix_map_point(m1, [pt.x, pt.y]);
return {
x: xpt[0],
y: xpt[1]
};
},
/**
* @name _matrix_map_rect
* @function
* @private
* @ignore
*/
_matrix_map_rect: function _matrix_map_rect(m1, rect) {
var p1 = this._matrix_map_point(m1, [rect.x, rect.y]);
var p2 = this._matrix_map_point(m1, [rect.x + rect.w, rect.y + rect.h]);
return {
x: p1[0],
y: p1[1],
w: p2[0] - p1[0],
h: p2[1] - p1[1]
};
},
/**
* @name _matrix_is_identity
* @function
* @private
* @ignore
*/
_matrix_is_identity: function _matrix_is_identity(m1) {
if (m1[0] != 1) {
return false;
}
if (m1[1] != 0) {
return false;
}
if (m1[2] != 0) {
return false;
}
if (m1[3] != 1) {
return false;
}
if (m1[4] != 0) {
return false;
}
if (m1[5] != 0) {
return false;
}
return true;
},
/**
* Processes the paths
*
* @function
* @param rule {String}
* @param isClip {Boolean}
* @private
* @ignore
*/
_drawPaths: function _drawPaths(rule, isClip) {
var isStroke = rule === "stroke";
var isFill = !isStroke;
if (isStroke && !isClip && this._isStrokeTransparent()) {
return;
}
if (isFill && !isClip && this._isFillTransparent()) {
return;
}
var v2Support = typeof this.pdf.internal.newObject2 === "function";
var lines;
if (globalObj.outIntercept) {
lines = globalObj.outIntercept.type === "group" ? globalObj.outIntercept.stream : globalObj.outIntercept;
} else {
lines = this.internal.getCurrentPage();
}
var moves = [];
var outInterceptOld = globalObj.outIntercept;
/*
if (v2Support) {
// Blend and Mask
switch (this.ctx.globalCompositeOperation) {
case 'normal':
case 'source-over':
break;
case 'destination-in':
case 'destination-out':
//TODO this need to be added to the current group or page
// define a mask stream
var obj = this.pdf.internal.newStreamObject(); // define a mask state
var obj2 = this.pdf.internal.newObject2();
obj2.push('<</Type /ExtGState');
obj2.push('/SMask <</S /Alpha /G ' + obj.objId + ' 0 R>>'); // /S /Luminosity will need to define color space
obj2.push('>>'); // add mask to page resources
var gsName = 'MASK' + obj2.objId;
this.pdf.internal.addGraphicsState(gsName, obj2.objId);
var instruction = '/' + gsName + ' gs'; // add mask to page, group, or stream
lines.splice(0, 0, 'q');
lines.splice(1, 0, instruction);
lines.push('Q');
globalObj.outIntercept = obj;
break;
default:
var dictionaryEntry = '/' + this.pdf.internal.blendModeMap[this.ctx.globalCompositeOperation.toUpperCase()];
if (dictionaryEntry) {
this.pdf.internal.out(dictionaryEntry + ' gs');
}
break;
}
}
*/
var alpha = this.ctx.globalAlpha;
if (this.ctx._fillOpacity < 1) {
// TODO combine this with global opacity
alpha = this.ctx._fillOpacity;
} //TODO check for an opacity graphics state that was already created
//TODO do not set opacity if current value is already active
/*
if (v2Support) {
var objOpac = this.pdf.internal.newObject2();
objOpac.push('<</Type /ExtGState'); //objOpac.push(this.ctx.globalAlpha + " CA"); // Stroke
//objOpac.push(this.ctx.globalAlpha + " ca"); // Not Stroke
objOpac.push('/CA ' + alpha); // Stroke
objOpac.push('/ca ' + alpha); // Not Stroke
objOpac.push('>>');
var gsName = 'GS_O_' + objOpac.objId;
this.pdf.internal.addGraphicsState(gsName, objOpac.objId);
this.pdf.internal.out('/' + gsName + ' gs');
}
*/
var xPath = this.path;
for (var i = 0; i < xPath.length; i++) {
var pt = xPath[i];
switch (pt.type) {
case "begin":
moves.push({
begin: true
});
break;
case "close":
moves.push({
close: true
});
break;
case "mt":
moves.push({
start: pt,
deltas: [],
abs: []
});
break;
case "lt":
var delta = [pt.x - xPath[i - 1].x, pt.y - xPath[i - 1].y];
var iii = moves.length;
if (iii > 0) {
for (iii; iii > 0; iii--) {
if (moves[iii - 1].close !== true && moves[iii - 1].begin !== true) {
moves[iii - 1].deltas.push(delta);
moves[iii - 1].abs.push(pt);
break;
}
}
}
break;
case "bct":
var delta = [pt.x1 - xPath[i - 1].x, pt.y1 - xPath[i - 1].y, pt.x2 - xPath[i - 1].x, pt.y2 - xPath[i - 1].y, pt.x - xPath[i - 1].x, pt.y - xPath[i - 1].y];
moves[moves.length - 1].deltas.push(delta);
break;
case "qct":
// convert to bezier
var x1 = xPath[i - 1].x + 2.0 / 3.0 * (pt.x1 - xPath[i - 1].x);
var y1 = xPath[i - 1].y + 2.0 / 3.0 * (pt.y1 - xPath[i - 1].y);
var x2 = pt.x + 2.0 / 3.0 * (pt.x1 - pt.x);
var y2 = pt.y + 2.0 / 3.0 * (pt.y1 - pt.y);
var x3 = pt.x;
var y3 = pt.y;
var delta = [x1 - xPath[i - 1].x, y1 - xPath[i - 1].y, x2 - xPath[i - 1].x, y2 - xPath[i - 1].y, x3 - xPath[i - 1].x, y3 - xPath[i - 1].y];
moves[moves.length - 1].deltas.push(delta);
break;
case "arc":
moves.push({
deltas: [],
abs: []
});
moves[moves.length - 1].arc = true;
if (Array.isArray(moves[moves.length - 1].abs)) {
moves[moves.length - 1].abs.push(pt);
}
break;
}
}
var style;
if (!isClip) {
if (isStroke) {
style = "S";
} else {
style = "f";
}
} else {
style = null;
}
for (var i = 0; i < moves.length; i++) {
if (moves[i].begin) ;
if (moves[i].arc) {
if (moves[i].start) {
this.internal.move2(this, moves[i].start.x, moves[i].start.y);
}
var arcs = moves[i].abs;
for (var ii = 0; ii < arcs.length; ii++) {
var arc = arcs[ii]; //TODO lines deltas were getting in here
if (typeof arc.startAngle !== "undefined") {
var start = arc.startAngle * 360 / (2 * Math.PI);
var end = arc.endAngle * 360 / (2 * Math.PI);
var x = arc.x;
var y = arc.y;
this.internal.arc2(this, x, y, arc.radius, start, end, arc.counterclockwise, style, isClip);
} else {
this.internal.line2(c2d, arc.x, arc.y);
}
}
}
if (!moves[i].arc) {
if (moves[i].close !== true && moves[i].begin !== true) {
var x = moves[i].start.x;
var y = moves[i].start.y;
this.pdf.lines(moves[i].deltas, x, y, null, null);
}
}
if (moves[i].close) ;
}
if (style) {
this.pdf.internal.out(style);
}
if (isClip) {
this.pdf.clip();
}
globalObj.outIntercept = outInterceptOld; // if (this.ctx._clip_path.length > 0) {
// lines.push('Q');
// }
},
/*
_pushMask: function () {
var v2Support = typeof this.pdf.internal.newObject2 === 'function';
if (!v2Support) {
console.log('jsPDF v2 not enabled')
return;
}
// define a mask stream
var obj = this.pdf.internal.newStreamObject();
// define a mask state
var obj2 = this.pdf.internal.newObject2();
obj2.push('<</Type /ExtGState');
obj2.push('/SMask <</S /Alpha /G ' + obj.objId + ' 0 R>>'); // /S /Luminosity will need to define color space
obj2.push('>>');
// add mask to page resources
var gsName = 'MASK' + obj2.objId;
this.pdf.internal.addGraphicsState(gsName, obj2.objId);
var instruction = '/' + gsName + ' gs';
this.pdf.internal.out(instruction);
},
*/
_getBaseline: function _getBaseline(y) {
var height = parseInt(this.pdf.internal.getFontSize() / this.pdf.internal.scaleFactor); // TODO Get descent from font descriptor
var descent = height * 0.25;
switch (this.ctx.textBaseline) {
case "bottom":
return y - descent;
case "top":
return y + height;
case "hanging":
return y + height - descent;
case "middle":
return y + height / 2 - descent;
case "ideographic":
// TODO not implemented
return y;
case "alphabetic":
default:
return y;
}
},
createLinearGradient: function createLinearGradient() {
var canvasGradient = function canvasGradient() {};
canvasGradient.colorStops = [];
canvasGradient.addColorStop = function (offset, color) {
this.colorStops.push([offset, color]);
};
canvasGradient.getColor = function () {
if (this.colorStops.length === 0) {
return "#000000";
}
return this.colorStops[0][1];
};
canvasGradient.isCanvasGradient = true;
return canvasGradient;
},
createPattern: function createPattern() {
return this.createLinearGradient();
},
createRadialGradient: function createRadialGradient() {
return this.createLinearGradient();
}
};
var c2d = jsPDFAPI.context2d;
/**
* Sets or returns the color, gradient, or pattern used to fill the drawing
*
* @name fillStyle
* @default #000000
* @property {(color|gradient|pattern)} value The color of the drawing. Default value is #000000<br />
* A gradient object (linear or radial) used to fill the drawing (not supported by context2d)<br />
* A pattern object to use to fill the drawing (not supported by context2d)
*/
Object.defineProperty(c2d, "fillStyle", {
set: function set(value) {
this._setFillStyle(value);
},
get: function get() {
return this.ctx.fillStyle;
}
});
/**
* Sets or returns the color, gradient, or pattern used for strokes
*
* @name strokeStyle
* @default #000000
* @property {color} color A CSS color value that indicates the stroke color of the drawing. Default value is #000000 (not supported by context2d)
* @property {gradient} gradient A gradient object (linear or radial) used to create a gradient stroke (not supported by context2d)
* @property {pattern} pattern A pattern object used to create a pattern stroke (not supported by context2d)
*/
Object.defineProperty(c2d, "strokeStyle", {
set: function set(value) {
this._setStrokeStyle(value);
},
get: function get() {
return this.ctx.strokeStyle;
}
}); //Line Styles
/**
* Sets or returns the style of the end caps for a line
*
* @name lineCap
* @default butt
* @property {(butt|round|square)} lineCap butt A flat edge is added to each end of the line <br/>
* round A rounded end cap is added to each end of the line<br/>
* square A square end cap is added to each end of the line<br/>
*/
Object.defineProperty(c2d, "lineCap", {
set: function set(val) {
this._setLineCap(val);
},
get: function get() {
return this.ctx.lineCap;
}
});
/**
* Sets or returns the current line width
*
* @name lineWidth
* @default 1
* @property {number} lineWidth The current line width, in pixels
*/
Object.defineProperty(c2d, "lineWidth", {
set: function set(value) {
this._setLineWidth(value);
},
get: function get() {
return this.ctx.lineWidth;
}
});
/**
* Sets or returns the type of corner created, when two lines meet
*/
Object.defineProperty(c2d, "lineJoin", {
set: function set(val) {
this._setLineJoin(val);
},
get: function get() {
return this.ctx.lineJoin;
}
});
/**
* Sets or returns the maximum miter length
*/
Object.defineProperty(c2d, "miterLimit", {
set: function set(val) {
this.ctx.miterLimit = val;
},
get: function get() {
return this.ctx.miterLimit;
}
});
Object.defineProperty(c2d, "textBaseline", {
set: function set(value) {
this._setTextBaseline(value);
},
get: function get() {
return this._getTextBaseline();
}
});
Object.defineProperty(c2d, "textAlign", {
set: function set(value) {
this._setTextAlign(value);
},
get: function get() {
return this._getTextAlign();
}
});
Object.defineProperty(c2d, "font", {
set: function set(value) {
this._setFont(value);
},
get: function get() {
return this.ctx.font;
}
});
Object.defineProperty(c2d, "globalCompositeOperation", {
set: function set(value) {
this.ctx.globalCompositeOperation = value;
},
get: function get() {
return this.ctx.globalCompositeOperation;
}
});
Object.defineProperty(c2d, "globalAlpha", {
set: function set(value) {
this.ctx.globalAlpha = value;
},
get: function get() {
return this.ctx.globalAlpha;
}
});
Object.defineProperty(c2d, "canvas", {
get: function get() {
return {
parentNode: false,
style: false
};
}
}); // Not HTML API
Object.defineProperty(c2d, "ignoreClearRect", {
set: function set(value) {
this.ctx.ignoreClearRect = value;
},
get: function get() {
return this.ctx.ignoreClearRect;
}
}); // End Not HTML API
c2d.internal = {};
c2d.internal.rxRgb = /rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/;
c2d.internal.rxRgba = /rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d\.]+)\s*\)/;
c2d.internal.rxTransparent = /transparent|rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*0+\s*\)/; // http://hansmuller-flex.blogspot.com/2011/10/more-about-approximating-circular-arcs.html
c2d.internal.arc = function (c2d, xc, yc, r, a1, a2, counterclockwise, style) {
var k = this.pdf.internal.scaleFactor;
var pageHeight = this.pdf.internal.pageSize.getHeight();
var f2 = this.pdf.internal.f2;
var a1r = a1 * (Math.PI / 180);
var a2r = a2 * (Math.PI / 180);
var curves = this.createArc(r, a1r, a2r, counterclockwise);
for (var i = 0; i < curves.length; i++) {
var curve = curves[i];
if (i === 0) {
this.pdf.internal.out([f2((curve.x1 + xc) * k), f2((pageHeight - (curve.y1 + yc)) * k), "m", f2((curve.x2 + xc) * k), f2((pageHeight - (curve.y2 + yc)) * k), f2((curve.x3 + xc) * k), f2((pageHeight - (curve.y3 + yc)) * k), f2((curve.x4 + xc) * k), f2((pageHeight - (curve.y4 + yc)) * k), "c"].join(" "));
} else {
this.pdf.internal.out([f2((curve.x2 + xc) * k), f2((pageHeight - (curve.y2 + yc)) * k), f2((curve.x3 + xc) * k), f2((pageHeight - (curve.y3 + yc)) * k), f2((curve.x4 + xc) * k), f2((pageHeight - (curve.y4 + yc)) * k), "c"].join(" "));
} //c2d._lastPoint = {x: curve.x1 + xc, y: curve.y1 + yc};
c2d._lastPoint = {
x: xc,
y: yc
}; // f2((curve.x1 + xc) * k), f2((pageHeight - (curve.y1 + yc)) * k), 'm', f2((curve.x2 + xc) * k), f2((pageHeight - (curve.y2 + yc)) * k), f2((curve.x3 + xc) * k), f2((pageHeight - (curve.y3 + yc)) * k), f2((curve.x4 + xc) * k), f2((pageHeight - (curve.y4 + yc)) * k), 'c'
}
if (style !== null) {
this.pdf.internal.out(this.pdf.internal.getStyle(style));
}
};
/**
*
* @param x Edge point X
* @param y Edge point Y
* @param r Radius
* @param a1 start angle
* @param a2 end angle
* @param counterclockwise
* @param style
* @param isClip
*/
c2d.internal.arc2 = function (c2d, x, y, r, a1, a2, counterclockwise, style, isClip) {
// we need to convert from cartesian to polar here methinks.
var centerX = x; // + r;
var centerY = y;
if (!isClip) {
this.arc(c2d, centerX, centerY, r, a1, a2, counterclockwise, style);
} else {
this.arc(c2d, centerX, centerY, r, a1, a2, counterclockwise, null);
this.pdf.clip();
}
};
c2d.internal.move2 = function (c2d, x, y) {
var k = this.pdf.internal.scaleFactor;
var pageHeight = this.pdf.internal.pageSize.getHeight();
var f2 = this.pdf.internal.f2;
this.pdf.internal.out([f2(x * k), f2((pageHeight - y) * k), "m"].join(" "));
c2d._lastPoint = {
x: x,
y: y
};
};
c2d.internal.line2 = function (c2d, dx, dy) {
var k = this.pdf.internal.scaleFactor;
var pageHeight = this.pdf.internal.pageSize.getHeight();
var f2 = this.pdf.internal.f2; //var pt = {x: c2d._lastPoint.x + dx, y: c2d._lastPoint.y + dy};
var pt = {
x: dx,
y: dy
};
this.pdf.internal.out([f2(pt.x * k), f2((pageHeight - pt.y) * k), "l"].join(" ")); //this.pdf.internal.out('f');
c2d._lastPoint = pt;
};
/**
* Return a array of objects that represent bezier curves which approximate the circular arc centered at the origin, from startAngle to endAngle (radians) with the specified radius.
*
* Each bezier curve is an object with four points, where x1,y1 and x4,y4 are the arc's end points and x2,y2 and x3,y3 are the cubic bezier's control points.
*/
c2d.internal.createArc = function (radius, startAngle, endAngle, anticlockwise) {
var EPSILON = 0.00001; // Roughly 1/1000th of a degree, see below
// normalize startAngle, endAngle to [-2PI, 2PI]
var twoPI = Math.PI * 2;
var startAngleN = startAngle;
if (startAngleN < twoPI || startAngleN > twoPI) {
startAngleN = startAngleN % twoPI;
}
var endAngleN = endAngle;
if (endAngleN < twoPI || endAngleN > twoPI) {
endAngleN = endAngleN % twoPI;
} // Compute the sequence of arc curves, up to PI/2 at a time.
// Total arc angle is less than 2PI.
var curves = [];
var piOverTwo = Math.PI / 2.0; //var sgn = (startAngle < endAngle) ? +1 : -1; // clockwise or counterclockwise
var sgn = anticlockwise ? -1 : +1;
var a1 = startAngle;
for (var totalAngle = Math.min(twoPI, Math.abs(endAngleN - startAngleN)); totalAngle > EPSILON;) {
var a2 = a1 + sgn * Math.min(totalAngle, piOverTwo);
curves.push(this.createSmallArc(radius, a1, a2));
totalAngle -= Math.abs(a2 - a1);
a1 = a2;
}
return curves;
};
c2d.internal.getCurrentPage = function () {
return this.pdf.internal.pages[this.pdf.internal.getCurrentPageInfo().pageNumber];
};
/**
* Cubic bezier approximation of a circular arc centered at the origin, from (radians) a1 to a2, where a2-a1 < pi/2. The arc's radius is r.
*
* Returns an object with four points, where x1,y1 and x4,y4 are the arc's end points and x2,y2 and x3,y3 are the cubic bezier's control points.
*
* This algorithm is based on the approach described in: A. Riškus, "Approximation of a Cubic Bezier Curve by Circular Arcs and Vice Versa," Information Technology and Control, 35(4), 2006 pp. 371-378.
*/
c2d.internal.createSmallArc = function (r, a1, a2) {
// Compute all four points for an arc that subtends the same total angle
// but is centered on the X-axis
var a = (a2 - a1) / 2.0;
var x4 = r * Math.cos(a);
var y4 = r * Math.sin(a);
var x1 = x4;
var y1 = -y4;
var q1 = x1 * x1 + y1 * y1;
var q2 = q1 + x1 * x4 + y1 * y4;
var k2 = 4 / 3 * (Math.sqrt(2 * q1 * q2) - q2) / (x1 * y4 - y1 * x4);
var x2 = x1 - k2 * y1;
var y2 = y1 + k2 * x1;
var x3 = x2;
var y3 = -y2; // Find the arc points' actual locations by computing x1,y1 and x4,y4
// and rotating the control points by a + a1
var ar = a + a1;
var cos_ar = Math.cos(ar);
var sin_ar = Math.sin(ar);
return {
x1: r * Math.cos(a1),
y1: r * Math.sin(a1),
x2: x2 * cos_ar - y2 * sin_ar,
y2: x2 * sin_ar + y2 * cos_ar,
x3: x3 * cos_ar - y3 * sin_ar,
y3: x3 * sin_ar + y3 * cos_ar,
x4: r * Math.cos(a2),
y4: r * Math.sin(a2)
};
};
/**
*
* @function
* @constructor
*/
function context() {
this._isStrokeTransparent = false;
this._strokeOpacity = 1;
this.strokeStyle = "#000000";
this.fillStyle = "#000000";
this._isFillTransparent = false;
this._fillOpacity = 1;
this.font = "12pt times";
this.textBaseline = "alphabetic"; // top,bottom,middle,ideographic,alphabetic,hanging
this.textAlign = "left";
this.lineWidth = 1;
this.lineJoin = "miter"; // round, bevel, miter
this.lineCap = "butt"; // butt, round, square
this._transform = [1, 0, 0, 1, 0, 0]; // sx, shy, shx, sy, tx, ty
this.globalCompositeOperation = "normal";
this.globalAlpha = 1.0;
this._clip_path = [];
this.currentPoint = {
x: 0,
y: 0
}; // TODO miter limit //default 10
// Not HTML API
this.ignoreClearRect = false;
this.copy = function (ctx) {
this._isStrokeTransparent = ctx._isStrokeTransparent;
this._strokeOpacity = ctx._strokeOpacity;
this.strokeStyle = ctx.strokeStyle;
this._isFillTransparent = ctx._isFillTransparent;
this._fillOpacity = ctx._fillOpacity;
this.fillStyle = ctx.fillStyle;
this.font = ctx.font;
this.lineWidth = ctx.lineWidth;
this.lineJoin = ctx.lineJoin;
this.lineCap = ctx.lineCap;
this.textBaseline = ctx.textBaseline;
this.textAlign = ctx.textAlign;
this._fontSize = ctx._fontSize;
this._transform = ctx._transform.slice(0);
this.globalCompositeOperation = ctx.globalCompositeOperation;
this.globalAlpha = ctx.globalAlpha;
this._clip_path = ctx._clip_path.slice(0); //TODO deep copy?
this.currentPoint = ctx.currentPoint; // Not HTML API
this.ignoreClearRect = ctx.ignoreClearRect;
};
}
return this;
})(jsPDF.API, typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function("return this")());
/**
* Copyright (c) 2018 Erik Koopmans
* Released under the MIT License.
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* jsPDF html PlugIn
*
* @name html
* @module
*/
(function (jsPDFAPI, global) {
/**
* Determine the type of a variable/object.
*
* @private
* @ignore
*/
var objType = function objType(obj) {
var type = _typeof(obj);
if (type === "undefined") return "undefined";else if (type === "string" || obj instanceof String) return "string";else if (type === "number" || obj instanceof Number) return "number";else if (type === "function" || obj instanceof Function) return "function";else if (!!obj && obj.constructor === Array) return "array";else if (obj && obj.nodeType === 1) return "element";else if (type === "object") return "object";else return "unknown";
};
/**
* Create an HTML element with optional className, innerHTML, and style.
*
* @private
* @ignore
*/
var createElement = function createElement(tagName, opt) {
var el = document.createElement(tagName);
if (opt.className) el.className = opt.className;
if (opt.innerHTML) {
el.innerHTML = opt.innerHTML;
var scripts = el.getElementsByTagName("script");
for (var i = scripts.length; i-- > 0; null) {
scripts[i].parentNode.removeChild(scripts[i]);
}
}
for (var key in opt.style) {
el.style[key] = opt.style[key];
}
return el;
};
/**
* Deep-clone a node and preserve contents/properties.
*
* @private
* @ignore
*/
var cloneNode = function cloneNode(node, javascriptEnabled) {
// Recursively clone the node.
var clone = node.nodeType === 3 ? document.createTextNode(node.nodeValue) : node.cloneNode(false);
for (var child = node.firstChild; child; child = child.nextSibling) {
if (javascriptEnabled === true || child.nodeType !== 1 || child.nodeName !== "SCRIPT") {
clone.appendChild(cloneNode(child, javascriptEnabled));
}
}
if (node.nodeType === 1) {
// Preserve contents/properties of special nodes.
if (node.nodeName === "CANVAS") {
clone.width = node.width;
clone.height = node.height;
clone.getContext("2d").drawImage(node, 0, 0);
} else if (node.nodeName === "TEXTAREA" || node.nodeName === "SELECT") {
clone.value = node.value;
} // Preserve the node's scroll position when it loads.
clone.addEventListener("load", function () {
clone.scrollTop = node.scrollTop;
clone.scrollLeft = node.scrollLeft;
}, true);
} // Return the cloned node.
return clone;
};
/* ----- CONSTRUCTOR ----- */
var Worker = function Worker(opt) {
// Create the root parent for the proto chain, and the starting Worker.
var root = Object.assign(Worker.convert(Promise.resolve()), JSON.parse(JSON.stringify(Worker.template)));
var self = Worker.convert(Promise.resolve(), root); // Set progress, optional settings, and return.
self = self.setProgress(1, Worker, 1, [Worker]);
self = self.set(opt);
return self;
}; // Boilerplate for subclassing Promise.
Worker.prototype = Object.create(Promise.prototype);
Worker.prototype.constructor = Worker; // Converts/casts promises into Workers.
Worker.convert = function convert(promise, inherit) {
// Uses prototypal inheritance to receive changes made to ancestors' properties.
promise.__proto__ = inherit || Worker.prototype;
return promise;
};
Worker.template = {
prop: {
src: null,
container: null,
overlay: null,
canvas: null,
img: null,
pdf: null,
pageSize: null,
callback: function callback() {}
},
progress: {
val: 0,
state: null,
n: 0,
stack: []
},
opt: {
filename: "file.pdf",
margin: [0, 0, 0, 0],
enableLinks: true,
html2canvas: {},
jsPDF: {}
}
};
/* ----- FROM / TO ----- */
Worker.prototype.from = function from(src, type) {
function getType(src) {
switch (objType(src)) {
case "string":
return "string";
case "element":
return src.nodeName.toLowerCase === "canvas" ? "canvas" : "element";
default:
return "unknown";
}
}
return this.then(function from_main() {
type = type || getType(src);
switch (type) {
case "string":
return this.set({
src: createElement("div", {
innerHTML: src
})
});
case "element":
return this.set({
src: src
});
case "canvas":
return this.set({
canvas: src
});
case "img":
return this.set({
img: src
});
default:
return this.error("Unknown source type.");
}
});
};
Worker.prototype.to = function to(target) {
// Route the 'to' request to the appropriate method.
switch (target) {
case "container":
return this.toContainer();
case "canvas":
return this.toCanvas();
case "img":
return this.toImg();
case "pdf":
return this.toPdf();
default:
return this.error("Invalid target.");
}
};
Worker.prototype.toContainer = function toContainer() {
// Set up function prerequisites.
var prereqs = [function checkSrc() {
return this.prop.src || this.error("Cannot duplicate - no source HTML.");
}, function checkPageSize() {
return this.prop.pageSize || this.setPageSize();
}];
return this.thenList(prereqs).then(function toContainer_main() {
// Define the CSS styles for the container and its overlay parent.
var overlayCSS = {
position: "fixed",
overflow: "hidden",
zIndex: 1000,
left: "-100000px",
right: 0,
bottom: 0,
top: 0
};
var containerCSS = {
position: "relative",
display: "inline-block",
width: Math.max(this.prop.src.clientWidth, this.prop.src.scrollWidth, this.prop.src.offsetWidth) + "px",
left: 0,
right: 0,
top: 0,
margin: "auto",
backgroundColor: "white"
}; // Set the overlay to hidden (could be changed in the future to provide a print preview).
var source = cloneNode(this.prop.src, this.opt.html2canvas.javascriptEnabled);
if (source.tagName === "BODY") {
containerCSS.height = Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight) + "px";
}
this.prop.overlay = createElement("div", {
className: "html2pdf__overlay",
style: overlayCSS
});
this.prop.container = createElement("div", {
className: "html2pdf__container",
style: containerCSS
});
this.prop.container.appendChild(source);
this.prop.container.firstChild.appendChild(createElement("div", {
style: {
clear: "both",
border: "0 none transparent",
margin: 0,
padding: 0,
height: 0
}
}));
this.prop.container.style.float = "none";
this.prop.overlay.appendChild(this.prop.container);
document.body.appendChild(this.prop.overlay);
this.prop.container.firstChild.style.position = "relative";
this.prop.container.height = Math.max(this.prop.container.firstChild.clientHeight, this.prop.container.firstChild.scrollHeight, this.prop.container.firstChild.offsetHeight) + "px";
});
};
Worker.prototype.toCanvas = function toCanvas() {
// Set up function prerequisites.
var prereqs = [function checkContainer() {
return document.body.contains(this.prop.container) || this.toContainer();
}]; // Fulfill prereqs then create the canvas.
return this.thenList(prereqs).then(function toCanvas_main() {
// Handle old-fashioned 'onrendered' argument.
var options = Object.assign({}, this.opt.html2canvas);
delete options.onrendered;
if (!this.isHtml2CanvasLoaded()) {
return;
}
return html2canvas(this.prop.container, options);
}).then(function toCanvas_post(canvas) {
// Handle old-fashioned 'onrendered' argument.
var onRendered = this.opt.html2canvas.onrendered || function () {};
onRendered(canvas);
this.prop.canvas = canvas;
document.body.removeChild(this.prop.overlay);
});
};
Worker.prototype.toContext2d = function toContext2d() {
// Set up function prerequisites.
var prereqs = [function checkContainer() {
return document.body.contains(this.prop.container) || this.toContainer();
}]; // Fulfill prereqs then create the canvas.
return this.thenList(prereqs).then(function toContext2d_main() {
// Handle old-fashioned 'onrendered' argument.
var pdf = this.opt.jsPDF;
var options = Object.assign({
async: true,
allowTaint: true,
backgroundColor: "#ffffff",
imageTimeout: 15000,
logging: true,
proxy: null,
removeContainer: true,
foreignObjectRendering: false,
useCORS: false
}, this.opt.html2canvas);
delete options.onrendered;
options.windowHeight = options.windowHeight || 0;
options.windowHeight = options.windowHeight == 0 ? Math.max(this.prop.container.clientHeight, this.prop.container.scrollHeight, this.prop.container.offsetHeight) : options.windowHeight;
if (!this.isHtml2CanvasLoaded()) {
return;
}
return html2canvas(this.prop.container, options);
}).then(function toContext2d_post(canvas) {
// Handle old-fashioned 'onrendered' argument.
var onRendered = this.opt.html2canvas.onrendered || function () {};
onRendered(canvas);
this.prop.canvas = canvas;
document.body.removeChild(this.prop.overlay);
});
};
Worker.prototype.toImg = function toImg() {
// Set up function prerequisites.
var prereqs = [function checkCanvas() {
return this.prop.canvas || this.toCanvas();
}]; // Fulfill prereqs then create the image.
return this.thenList(prereqs).then(function toImg_main() {
var imgData = this.prop.canvas.toDataURL("image/" + this.opt.image.type, this.opt.image.quality);
this.prop.img = document.createElement("img");
this.prop.img.src = imgData;
});
};
Worker.prototype.toPdf = function toPdf() {
// Set up function prerequisites.
var prereqs = [function checkContext2d() {
return this.toContext2d();
} //function checkCanvas() { return this.prop.canvas || this.toCanvas(); }
]; // Fulfill prereqs then create the image.
return this.thenList(prereqs).then(function toPdf_main() {
// Create local copies of frequently used properties.
this.prop.pdf = this.prop.pdf || this.opt.jsPDF;
});
};
/* ----- OUTPUT / SAVE ----- */
Worker.prototype.output = function output(type, options, src) {
// Redirect requests to the correct function (outputPdf / outputImg).
src = src || "pdf";
if (src.toLowerCase() === "img" || src.toLowerCase() === "image") {
return this.outputImg(type, options);
} else {
return this.outputPdf(type, options);
}
};
Worker.prototype.outputPdf = function outputPdf(type, options) {
// Set up function prerequisites.
var prereqs = [function checkPdf() {
return this.prop.pdf || this.toPdf();
}]; // Fulfill prereqs then perform the appropriate output.
return this.thenList(prereqs).then(function outputPdf_main() {
/* Currently implemented output types:
* https://rawgit.com/MrRio/jsPDF/master/docs/jspdf.js.html#line992
* save(options), arraybuffer, blob, bloburi/bloburl,
* datauristring/dataurlstring, dataurlnewwindow, datauri/dataurl
*/
return this.prop.pdf.output(type, options);
});
};
Worker.prototype.outputImg = function outputImg(type, options) {
// Set up function prerequisites.
var prereqs = [function checkImg() {
return this.prop.img || this.toImg();
}]; // Fulfill prereqs then perform the appropriate output.
return this.thenList(prereqs).then(function outputImg_main() {
switch (type) {
case undefined:
case "img":
return this.prop.img;
case "datauristring":
case "dataurlstring":
return this.prop.img.src;
case "datauri":
case "dataurl":
return document.location.href = this.prop.img.src;
default:
throw 'Image output type "' + type + '" is not supported.';
}
});
};
Worker.prototype.isHtml2CanvasLoaded = function () {
var result = typeof global.html2canvas !== "undefined";
if (!result) {
console.error("html2canvas not loaded.");
}
return result;
};
Worker.prototype.save = function save(filename) {
// Set up function prerequisites.
var prereqs = [function checkPdf() {
return this.prop.pdf || this.toPdf();
}];
if (!this.isHtml2CanvasLoaded()) {
return;
} // Fulfill prereqs, update the filename (if provided), and save the PDF.
return this.thenList(prereqs).set(filename ? {
filename: filename
} : null).then(function save_main() {
this.prop.pdf.save(this.opt.filename);
});
};
Worker.prototype.doCallback = function doCallback(filename) {
// Set up function prerequisites.
var prereqs = [function checkPdf() {
return this.prop.pdf || this.toPdf();
}];
if (!this.isHtml2CanvasLoaded()) {
return;
} // Fulfill prereqs, update the filename (if provided), and save the PDF.
return this.thenList(prereqs).then(function doCallback_main() {
this.prop.callback(this.prop.pdf);
});
};
/* ----- SET / GET ----- */
Worker.prototype.set = function set(opt) {
// TODO: Implement ordered pairs?
// Silently ignore invalid or empty input.
if (objType(opt) !== "object") {
return this;
} // Build an array of setter functions to queue.
var fns = Object.keys(opt || {}).map(function (key) {
if (key in Worker.template.prop) {
// Set pre-defined properties.
return function set_prop() {
this.prop[key] = opt[key];
};
} else {
switch (key) {
case "margin":
return this.setMargin.bind(this, opt.margin);
case "jsPDF":
return function set_jsPDF() {
this.opt.jsPDF = opt.jsPDF;
return this.setPageSize();
};
case "pageSize":
return this.setPageSize.bind(this, opt.pageSize);
default:
// Set any other properties in opt.
return function set_opt() {
this.opt[key] = opt[key];
};
}
}
}, this); // Set properties within the promise chain.
return this.then(function set_main() {
return this.thenList(fns);
});
};
Worker.prototype.get = function get(key, cbk) {
return this.then(function get_main() {
// Fetch the requested property, either as a predefined prop or in opt.
var val = key in Worker.template.prop ? this.prop[key] : this.opt[key];
return cbk ? cbk(val) : val;
});
};
Worker.prototype.setMargin = function setMargin(margin) {
return this.then(function setMargin_main() {
// Parse the margin property.
switch (objType(margin)) {
case "number":
margin = [margin, margin, margin, margin];
case "array":
if (margin.length === 2) {
margin = [margin[0], margin[1], margin[0], margin[1]];
}
if (margin.length === 4) {
break;
}
default:
return this.error("Invalid margin array.");
} // Set the margin property, then update pageSize.
this.opt.margin = margin;
}).then(this.setPageSize);
};
Worker.prototype.setPageSize = function setPageSize(pageSize) {
function toPx(val, k) {
return Math.floor(val * k / 72 * 96);
}
return this.then(function setPageSize_main() {
// Retrieve page-size based on jsPDF settings, if not explicitly provided.
pageSize = pageSize || jsPDF.getPageSize(this.opt.jsPDF); // Add 'inner' field if not present.
if (!pageSize.hasOwnProperty("inner")) {
pageSize.inner = {
width: pageSize.width - this.opt.margin[1] - this.opt.margin[3],
height: pageSize.height - this.opt.margin[0] - this.opt.margin[2]
};
pageSize.inner.px = {
width: toPx(pageSize.inner.width, pageSize.k),
height: toPx(pageSize.inner.height, pageSize.k)
};
pageSize.inner.ratio = pageSize.inner.height / pageSize.inner.width;
} // Attach pageSize to this.
this.prop.pageSize = pageSize;
});
};
Worker.prototype.setProgress = function setProgress(val, state, n, stack) {
// Immediately update all progress values.
if (val != null) this.progress.val = val;
if (state != null) this.progress.state = state;
if (n != null) this.progress.n = n;
if (stack != null) this.progress.stack = stack;
this.progress.ratio = this.progress.val / this.progress.state; // Return this for command chaining.
return this;
};
Worker.prototype.updateProgress = function updateProgress(val, state, n, stack) {
// Immediately update all progress values, using setProgress.
return this.setProgress(val ? this.progress.val + val : null, state ? state : null, n ? this.progress.n + n : null, stack ? this.progress.stack.concat(stack) : null);
};
/* ----- PROMISE MAPPING ----- */
Worker.prototype.then = function then(onFulfilled, onRejected) {
// Wrap `this` for encapsulation.
var self = this;
return this.thenCore(onFulfilled, onRejected, function then_main(onFulfilled, onRejected) {
// Update progress while queuing, calling, and resolving `then`.
self.updateProgress(null, null, 1, [onFulfilled]);
return Promise.prototype.then.call(this, function then_pre(val) {
self.updateProgress(null, onFulfilled);
return val;
}).then(onFulfilled, onRejected).then(function then_post(val) {
self.updateProgress(1);
return val;
});
});
};
Worker.prototype.thenCore = function thenCore(onFulfilled, onRejected, thenBase) {
// Handle optional thenBase parameter.
thenBase = thenBase || Promise.prototype.then; // Wrap `this` for encapsulation and bind it to the promise handlers.
var self = this;
if (onFulfilled) {
onFulfilled = onFulfilled.bind(self);
}
if (onRejected) {
onRejected = onRejected.bind(self);
} // Cast self into a Promise to avoid polyfills recursively defining `then`.
var isNative = Promise.toString().indexOf("[native code]") !== -1 && Promise.name === "Promise";
var selfPromise = isNative ? self : Worker.convert(Object.assign({}, self), Promise.prototype); // Return the promise, after casting it into a Worker and preserving props.
var returnVal = thenBase.call(selfPromise, onFulfilled, onRejected);
return Worker.convert(returnVal, self.__proto__);
};
Worker.prototype.thenExternal = function thenExternal(onFulfilled, onRejected) {
// Call `then` and return a standard promise (exits the Worker chain).
return Promise.prototype.then.call(this, onFulfilled, onRejected);
};
Worker.prototype.thenList = function thenList(fns) {
// Queue a series of promise 'factories' into the promise chain.
var self = this;
fns.forEach(function thenList_forEach(fn) {
self = self.thenCore(fn);
});
return self;
};
Worker.prototype["catch"] = function (onRejected) {
// Bind `this` to the promise handler, call `catch`, and return a Worker.
if (onRejected) {
onRejected = onRejected.bind(this);
}
var returnVal = Promise.prototype["catch"].call(this, onRejected);
return Worker.convert(returnVal, this);
};
Worker.prototype.catchExternal = function catchExternal(onRejected) {
// Call `catch` and return a standard promise (exits the Worker chain).
return Promise.prototype["catch"].call(this, onRejected);
};
Worker.prototype.error = function error(msg) {
// Throw the error in the Promise chain.
return this.then(function error_main() {
throw new Error(msg);
});
};
/* ----- ALIASES ----- */
Worker.prototype.using = Worker.prototype.set;
Worker.prototype.saveAs = Worker.prototype.save;
Worker.prototype.export = Worker.prototype.output;
Worker.prototype.run = Worker.prototype.then; // Get dimensions of a PDF page, as determined by jsPDF.
jsPDF.getPageSize = function (orientation, unit, format) {
// Decode options object
if (_typeof(orientation) === "object") {
var options = orientation;
orientation = options.orientation;
unit = options.unit || unit;
format = options.format || format;
} // Default options
unit = unit || "mm";
format = format || "a4";
orientation = ("" + (orientation || "P")).toLowerCase();
var format_as_string = ("" + format).toLowerCase(); // Size in pt of various paper formats
var pageFormats = {
a0: [2383.94, 3370.39],
a1: [1683.78, 2383.94],
a2: [1190.55, 1683.78],
a3: [841.89, 1190.55],
a4: [595.28, 841.89],
a5: [419.53, 595.28],
a6: [297.64, 419.53],
a7: [209.76, 297.64],
a8: [147.4, 209.76],
a9: [104.88, 147.4],
a10: [73.7, 104.88],
b0: [2834.65, 4008.19],
b1: [2004.09, 2834.65],
b2: [1417.32, 2004.09],
b3: [1000.63, 1417.32],
b4: [708.66, 1000.63],
b5: [498.9, 708.66],
b6: [354.33, 498.9],
b7: [249.45, 354.33],
b8: [175.75, 249.45],
b9: [124.72, 175.75],
b10: [87.87, 124.72],
c0: [2599.37, 3676.54],
c1: [1836.85, 2599.37],
c2: [1298.27, 1836.85],
c3: [918.43, 1298.27],
c4: [649.13, 918.43],
c5: [459.21, 649.13],
c6: [323.15, 459.21],
c7: [229.61, 323.15],
c8: [161.57, 229.61],
c9: [113.39, 161.57],
c10: [79.37, 113.39],
dl: [311.81, 623.62],
letter: [612, 792],
"government-letter": [576, 756],
legal: [612, 1008],
"junior-legal": [576, 360],
ledger: [1224, 792],
tabloid: [792, 1224],
"credit-card": [153, 243]
}; // Unit conversion
switch (unit) {
case "pt":
var k = 1;
break;
case "mm":
var k = 72 / 25.4;
break;
case "cm":
var k = 72 / 2.54;
break;
case "in":
var k = 72;
break;
case "px":
var k = 72 / 96;
break;
case "pc":
var k = 12;
break;
case "em":
var k = 12;
break;
case "ex":
var k = 6;
break;
default:
throw "Invalid unit: " + unit;
} // Dimensions are stored as user units and converted to points on output
if (pageFormats.hasOwnProperty(format_as_string)) {
var pageHeight = pageFormats[format_as_string][1] / k;
var pageWidth = pageFormats[format_as_string][0] / k;
} else {
try {
var pageHeight = format[1];
var pageWidth = format[0];
} catch (err) {
throw new Error("Invalid format: " + format);
}
} // Handle page orientation
if (orientation === "p" || orientation === "portrait") {
orientation = "p";
if (pageWidth > pageHeight) {
var tmp = pageWidth;
pageWidth = pageHeight;
pageHeight = tmp;
}
} else if (orientation === "l" || orientation === "landscape") {
orientation = "l";
if (pageHeight > pageWidth) {
var tmp = pageWidth;
pageWidth = pageHeight;
pageHeight = tmp;
}
} else {
throw "Invalid orientation: " + orientation;
} // Return information (k is the unit conversion ratio from pts)
var info = {
width: pageWidth,
height: pageHeight,
unit: unit,
k: k
};
return info;
};
/**
* Generate a PDF from an HTML element or string using.
*
* @name html
* @function
* @param {Element|string} source The source element or HTML string.
* @param {Object=} options An object of optional settings.
* @description The Plugin needs html2canvas from niklasvh
*/
jsPDFAPI.html = function (src, options) {
options = options || {};
options.callback = options.callback || function () {};
options.html2canvas = options.html2canvas || {};
options.html2canvas.canvas = options.html2canvas.canvas || this.canvas;
options.jsPDF = options.jsPDF || this; // Create a new worker with the given options.
var pdf = options.jsPDF;
pdf.annotations = {
_nameMap: [],
createAnnotation: function createAnnotation(href, bounds) {
var x = pdf.context2d._wrapX(bounds.left);
var y = pdf.context2d._wrapY(bounds.top);
var page = pdf.context2d._page(bounds.top);
var options;
var index = href.indexOf("#");
if (index >= 0) {
options = {
name: href.substring(index + 1)
};
} else {
options = {
url: href
};
}
pdf.link(x, y, bounds.right - bounds.left, bounds.bottom - bounds.top, options);
},
setName: function setName(name, bounds) {
var x = pdf.context2d._wrapX(bounds.left);
var y = pdf.context2d._wrapY(bounds.top);
var page = pdf.context2d._page(bounds.top);
this._nameMap[name] = {
page: page,
x: x,
y: y
};
}
};
pdf.context2d._pageBreakAt = function (y) {
this.pageBreaks.push(y);
};
pdf.context2d._gotoPage = function (pageOneBased) {
while (pdf.internal.getNumberOfPages() < pageOneBased) {
pdf.addPage();
}
pdf.setPage(pageOneBased);
};
pdf.context2d.pageWrapYEnabled = true;
pdf.context2d.pageWrapY = pdf.internal.pageSize.getHeight() / pdf.internal.scaleFactor + 1;
pdf.canvas.autoContext2dResizeY = false;
var worker = new Worker(options);
if (!options.worker) {
// If worker is not set to true, perform the traditional 'simple' operation.
return worker.from(src).doCallback();
} else {
// Otherwise, return the worker for new Promise-based operation.
return worker;
}
return this;
};
})(jsPDF.API, typeof window !== "undefined" && window || typeof global !== "undefined" && global);
/**
* @license
* ====================================================================
* Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com
*
*
* ====================================================================
*/
/*global jsPDF */
/**
* jsPDF JavaScript plugin
*
* @name javascript
* @module
*/
(function (jsPDFAPI) {
var jsNamesObj, jsJsObj, text;
/**
* @name addJS
* @function
* @param {string} javascript The javascript to be embedded into the PDF-file.
* @returns {jsPDF}
*/
jsPDFAPI.addJS = function (javascript) {
text = javascript;
this.internal.events.subscribe("postPutResources", function (javascript) {
jsNamesObj = this.internal.newObject();
this.internal.out("<<");
this.internal.out("/Names [(EmbeddedJS) " + (jsNamesObj + 1) + " 0 R]");
this.internal.out(">>");
this.internal.out("endobj");
jsJsObj = this.internal.newObject();
this.internal.out("<<");
this.internal.out("/S /JavaScript");
this.internal.out("/JS (" + text + ")");
this.internal.out(">>");
this.internal.out("endobj");
});
this.internal.events.subscribe("putCatalog", function () {
if (jsNamesObj !== undefined && jsJsObj !== undefined) {
this.internal.out("/Names <</JavaScript " + jsNamesObj + " 0 R>>");
}
});
return this;
};
})(jsPDF.API);
/**
* @license
* Copyright (c) 2014 Steven Spungin (TwelveTone LLC) steven@twelvetone.tv
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* jsPDF Outline PlugIn
*
* Generates a PDF Outline
* @name outline
* @module
*/
(function (jsPDFAPI) {
jsPDFAPI.events.push(["postPutResources", function () {
var pdf = this;
var rx = /^(\d+) 0 obj$/; // Write action goto objects for each page
// this.outline.destsGoto = [];
// for (var i = 0; i < totalPages; i++) {
// var id = pdf.internal.newObject();
// this.outline.destsGoto.push(id);
// pdf.internal.write("<</D[" + (i * 2 + 3) + " 0 R /XYZ null
// null null]/S/GoTo>> endobj");
// }
//
// for (var i = 0; i < dests.length; i++) {
// pdf.internal.write("(page_" + (i + 1) + ")" + dests[i] + " 0
// R");
// }
//
if (this.outline.root.children.length > 0) {
var lines = pdf.outline.render().split(/\r\n/);
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
var m = rx.exec(line);
if (m != null) {
var oid = m[1];
pdf.internal.newObjectDeferredBegin(oid);
}
pdf.internal.write(line);
}
} // This code will write named destination for each page reference
// (page_1, etc)
if (this.outline.createNamedDestinations) {
var totalPages = this.internal.pages.length; // WARNING: this assumes jsPDF starts on page 3 and pageIDs
// follow 5, 7, 9, etc
// Write destination objects for each page
var dests = [];
for (var i = 0; i < totalPages; i++) {
var id = pdf.internal.newObject();
dests.push(id);
var info = pdf.internal.getPageInfo(i + 1);
pdf.internal.write("<< /D[" + info.objId + " 0 R /XYZ null null null]>> endobj");
} // assign a name for each destination
var names2Oid = pdf.internal.newObject();
pdf.internal.write("<< /Names [ ");
for (var i = 0; i < dests.length; i++) {
pdf.internal.write("(page_" + (i + 1) + ")" + dests[i] + " 0 R");
}
pdf.internal.write(" ] >>", "endobj"); // var kids = pdf.internal.newObject();
// pdf.internal.write('<< /Kids [ ' + names2Oid + ' 0 R');
// pdf.internal.write(' ] >>', 'endobj');
var namesOid = pdf.internal.newObject();
pdf.internal.write("<< /Dests " + names2Oid + " 0 R");
pdf.internal.write(">>", "endobj");
}
}]);
jsPDFAPI.events.push(["putCatalog", function () {
var pdf = this;
if (pdf.outline.root.children.length > 0) {
pdf.internal.write("/Outlines", this.outline.makeRef(this.outline.root));
if (this.outline.createNamedDestinations) {
pdf.internal.write("/Names " + namesOid + " 0 R");
} // Open with Bookmarks showing
// pdf.internal.write("/PageMode /UseOutlines");
}
}]);
jsPDFAPI.events.push(["initialized", function () {
var pdf = this;
pdf.outline = {
createNamedDestinations: false,
root: {
children: []
}
};
/**
* Options: pageNumber
*/
pdf.outline.add = function (parent, title, options) {
var item = {
title: title,
options: options,
children: []
};
if (parent == null) {
parent = this.root;
}
parent.children.push(item);
return item;
};
pdf.outline.render = function () {
this.ctx = {};
this.ctx.val = "";
this.ctx.pdf = pdf;
this.genIds_r(this.root);
this.renderRoot(this.root);
this.renderItems(this.root);
return this.ctx.val;
};
pdf.outline.genIds_r = function (node) {
node.id = pdf.internal.newObjectDeferred();
for (var i = 0; i < node.children.length; i++) {
this.genIds_r(node.children[i]);
}
};
pdf.outline.renderRoot = function (node) {
this.objStart(node);
this.line("/Type /Outlines");
if (node.children.length > 0) {
this.line("/First " + this.makeRef(node.children[0]));
this.line("/Last " + this.makeRef(node.children[node.children.length - 1]));
}
this.line("/Count " + this.count_r({
count: 0
}, node));
this.objEnd();
};
pdf.outline.renderItems = function (node) {
for (var i = 0; i < node.children.length; i++) {
var item = node.children[i];
this.objStart(item);
this.line("/Title " + this.makeString(item.title));
this.line("/Parent " + this.makeRef(node));
if (i > 0) {
this.line("/Prev " + this.makeRef(node.children[i - 1]));
}
if (i < node.children.length - 1) {
this.line("/Next " + this.makeRef(node.children[i + 1]));
}
if (item.children.length > 0) {
this.line("/First " + this.makeRef(item.children[0]));
this.line("/Last " + this.makeRef(item.children[item.children.length - 1]));
}
var count = this.count = this.count_r({
count: 0
}, item);
if (count > 0) {
this.line("/Count " + count);
}
if (item.options) {
if (item.options.pageNumber) {
// Explicit Destination
//WARNING this assumes page ids are 3,5,7, etc.
var info = pdf.internal.getPageInfo(item.options.pageNumber);
this.line("/Dest " + "[" + info.objId + " 0 R /XYZ 0 " + this.ctx.pdf.internal.pageSize.getHeight() * this.ctx.pdf.internal.scaleFactor + " 0]"); // this line does not work on all clients (pageNumber instead of page ref)
//this.line('/Dest ' + '[' + (item.options.pageNumber - 1) + ' /XYZ 0 ' + this.ctx.pdf.internal.pageSize.getHeight() + ' 0]');
// Named Destination
// this.line('/Dest (page_' + (item.options.pageNumber) + ')');
// Action Destination
// var id = pdf.internal.newObject();
// pdf.internal.write('<</D[' + (item.options.pageNumber - 1) + ' /XYZ null null null]/S/GoTo>> endobj');
// this.line('/A ' + id + ' 0 R' );
}
}
this.objEnd();
}
for (var i = 0; i < node.children.length; i++) {
var item = node.children[i];
this.renderItems(item);
}
};
pdf.outline.line = function (text) {
this.ctx.val += text + "\r\n";
};
pdf.outline.makeRef = function (node) {
return node.id + " 0 R";
};
pdf.outline.makeString = function (val) {
return "(" + pdf.internal.pdfEscape(val) + ")";
};
pdf.outline.objStart = function (node) {
this.ctx.val += "\r\n" + node.id + " 0 obj" + "\r\n<<\r\n";
};
pdf.outline.objEnd = function (node) {
this.ctx.val += ">> \r\n" + "endobj" + "\r\n";
};
pdf.outline.count_r = function (ctx, node) {
for (var i = 0; i < node.children.length; i++) {
ctx.count++;
this.count_r(ctx, node.children[i]);
}
return ctx.count;
};
}]);
return this;
})(jsPDF.API);
/**
* @license
*
* Copyright (c) 2014 James Robb, https://github.com/jamesbrobb
*
*
* ====================================================================
*/
/**
* jsPDF PNG PlugIn
* @name png_support
* @module
*/
(function (jsPDFAPI) {
/*
* @see http://www.w3.org/TR/PNG-Chunks.html
*
Color Allowed Interpretation
Type Bit Depths
0 1,2,4,8,16 Each pixel is a grayscale sample.
2 8,16 Each pixel is an R,G,B triple.
3 1,2,4,8 Each pixel is a palette index;
a PLTE chunk must appear.
4 8,16 Each pixel is a grayscale sample,
followed by an alpha sample.
6 8,16 Each pixel is an R,G,B triple,
followed by an alpha sample.
*/
/*
* PNG filter method types
*
* @see http://www.w3.org/TR/PNG-Filters.html
* @see http://www.libpng.org/pub/png/book/chapter09.html
*
* This is what the value 'Predictor' in decode params relates to
*
* 15 is "optimal prediction", which means the prediction algorithm can change from line to line.
* In that case, you actually have to read the first byte off each line for the prediction algorthim (which should be 0-4, corresponding to PDF 10-14) and select the appropriate unprediction algorithm based on that byte.
*
0 None
1 Sub
2 Up
3 Average
4 Paeth
*/
var doesNotHavePngJS = function doesNotHavePngJS() {
return typeof PNG !== "function" || typeof FlateStream !== "function";
},
canCompress = function canCompress(value) {
return value !== jsPDFAPI.image_compression.NONE && hasCompressionJS();
},
hasCompressionJS = function hasCompressionJS() {
var inst = typeof Deflater === "function";
if (!inst) throw new Error("requires deflate.js for compression");
return inst;
},
compressBytes = function compressBytes(bytes, lineLength, colorsPerPixel, compression) {
var level = 5,
filter_method = filterUp;
switch (compression) {
case jsPDFAPI.image_compression.FAST:
level = 3;
filter_method = filterSub;
break;
case jsPDFAPI.image_compression.MEDIUM:
level = 6;
filter_method = filterAverage;
break;
case jsPDFAPI.image_compression.SLOW:
level = 9;
filter_method = filterPaeth; //uses to sum to choose best filter for each line
break;
}
bytes = applyPngFilterMethod(bytes, lineLength, colorsPerPixel, filter_method);
var header = new Uint8Array(createZlibHeader(level));
var checksum = adler32(bytes);
var deflate = new Deflater(level);
var a = deflate.append(bytes);
var cBytes = deflate.flush();
var len = header.length + a.length + cBytes.length;
var cmpd = new Uint8Array(len + 4);
cmpd.set(header);
cmpd.set(a, header.length);
cmpd.set(cBytes, header.length + a.length);
cmpd[len++] = checksum >>> 24 & 0xff;
cmpd[len++] = checksum >>> 16 & 0xff;
cmpd[len++] = checksum >>> 8 & 0xff;
cmpd[len++] = checksum & 0xff;
return jsPDFAPI.arrayBufferToBinaryString(cmpd);
},
createZlibHeader = function createZlibHeader(bytes, level) {
/*
* @see http://www.ietf.org/rfc/rfc1950.txt for zlib header
*/
var cm = 8;
var cinfo = Math.LOG2E * Math.log(0x8000) - 8;
var cmf = cinfo << 4 | cm;
var hdr = cmf << 8;
var flevel = Math.min(3, (level - 1 & 0xff) >> 1);
hdr |= flevel << 6;
hdr |= 0; //FDICT
hdr += 31 - hdr % 31;
return [cmf, hdr & 0xff & 0xff];
},
adler32 = function adler32(array, param) {
var adler = 1;
var s1 = adler & 0xffff,
s2 = adler >>> 16 & 0xffff;
var len = array.length;
var tlen;
var i = 0;
while (len > 0) {
tlen = len > param ? param : len;
len -= tlen;
do {
s1 += array[i++];
s2 += s1;
} while (--tlen);
s1 %= 65521;
s2 %= 65521;
}
return (s2 << 16 | s1) >>> 0;
},
applyPngFilterMethod = function applyPngFilterMethod(bytes, lineLength, colorsPerPixel, filter_method) {
var lines = bytes.length / lineLength,
result = new Uint8Array(bytes.length + lines),
filter_methods = getFilterMethods(),
i = 0,
line,
prevLine,
offset;
for (; i < lines; i++) {
offset = i * lineLength;
line = bytes.subarray(offset, offset + lineLength);
if (filter_method) {
result.set(filter_method(line, colorsPerPixel, prevLine), offset + i);
} else {
var j = 0,
len = filter_methods.length,
results = [];
for (; j < len; j++) {
results[j] = filter_methods[j](line, colorsPerPixel, prevLine);
}
var ind = getIndexOfSmallestSum(results.concat());
result.set(results[ind], offset + i);
}
prevLine = line;
}
return result;
},
filterNone = function filterNone(line, colorsPerPixel, prevLine) {
/*var result = new Uint8Array(line.length + 1);
result[0] = 0;
result.set(line, 1);*/
var result = Array.apply([], line);
result.unshift(0);
return result;
},
filterSub = function filterSub(line, colorsPerPixel, prevLine) {
var result = [],
i = 0,
len = line.length,
left;
result[0] = 1;
for (; i < len; i++) {
left = line[i - colorsPerPixel] || 0;
result[i + 1] = line[i] - left + 0x0100 & 0xff;
}
return result;
},
filterUp = function filterUp(line, colorsPerPixel, prevLine) {
var result = [],
i = 0,
len = line.length,
up;
result[0] = 2;
for (; i < len; i++) {
up = prevLine && prevLine[i] || 0;
result[i + 1] = line[i] - up + 0x0100 & 0xff;
}
return result;
},
filterAverage = function filterAverage(line, colorsPerPixel, prevLine) {
var result = [],
i = 0,
len = line.length,
left,
up;
result[0] = 3;
for (; i < len; i++) {
left = line[i - colorsPerPixel] || 0;
up = prevLine && prevLine[i] || 0;
result[i + 1] = line[i] + 0x0100 - (left + up >>> 1) & 0xff;
}
return result;
},
filterPaeth = function filterPaeth(line, colorsPerPixel, prevLine) {
var result = [],
i = 0,
len = line.length,
left,
up,
upLeft,
paeth;
result[0] = 4;
for (; i < len; i++) {
left = line[i - colorsPerPixel] || 0;
up = prevLine && prevLine[i] || 0;
upLeft = prevLine && prevLine[i - colorsPerPixel] || 0;
paeth = paethPredictor(left, up, upLeft);
result[i + 1] = line[i] - paeth + 0x0100 & 0xff;
}
return result;
},
paethPredictor = function paethPredictor(left, up, upLeft) {
var p = left + up - upLeft,
pLeft = Math.abs(p - left),
pUp = Math.abs(p - up),
pUpLeft = Math.abs(p - upLeft);
return pLeft <= pUp && pLeft <= pUpLeft ? left : pUp <= pUpLeft ? up : upLeft;
},
getFilterMethods = function getFilterMethods() {
return [filterNone, filterSub, filterUp, filterAverage, filterPaeth];
},
getIndexOfSmallestSum = function getIndexOfSmallestSum(arrays) {
var i = 0,
len = arrays.length,
sum,
min,
ind;
while (i < len) {
sum = absSum(arrays[i].slice(1));
if (sum < min || !min) {
min = sum;
ind = i;
}
i++;
}
return ind;
},
absSum = function absSum(array) {
var i = 0,
len = array.length,
sum = 0;
while (i < len) {
sum += Math.abs(array[i++]);
}
return sum;
},
getPredictorFromCompression = function getPredictorFromCompression(compression) {
var predictor;
switch (compression) {
case jsPDFAPI.image_compression.FAST:
predictor = 11;
break;
case jsPDFAPI.image_compression.MEDIUM:
predictor = 13;
break;
case jsPDFAPI.image_compression.SLOW:
predictor = 14;
break;
default:
predictor = 12;
break;
}
return predictor;
};
/**
*
* @name processPNG
* @function
* @ignore
*/
jsPDFAPI.processPNG = function (imageData, imageIndex, alias, compression, dataAsBinaryString) {
var colorSpace = this.color_spaces.DEVICE_RGB,
decode = this.decode.FLATE_DECODE,
bpc = 8,
img,
dp,
trns,
colors,
pal,
smask;
/* if(this.isString(imageData)) {
}*/
if (this.isArrayBuffer(imageData)) imageData = new Uint8Array(imageData);
if (this.isArrayBufferView(imageData)) {
if (doesNotHavePngJS()) throw new Error("PNG support requires png.js and zlib.js");
img = new PNG(imageData);
imageData = img.imgData;
bpc = img.bits;
colorSpace = img.colorSpace;
colors = img.colors; //logImg(img);
/*
* colorType 6 - Each pixel is an R,G,B triple, followed by an alpha sample.
*
* colorType 4 - Each pixel is a grayscale sample, followed by an alpha sample.
*
* Extract alpha to create two separate images, using the alpha as a sMask
*/
if ([4, 6].indexOf(img.colorType) !== -1) {
/*
* processes 8 bit RGBA and grayscale + alpha images
*/
if (img.bits === 8) {
var pixels = img.pixelBitlength == 32 ? new Uint32Array(img.decodePixels().buffer) : img.pixelBitlength == 16 ? new Uint16Array(img.decodePixels().buffer) : new Uint8Array(img.decodePixels().buffer),
len = pixels.length,
imgData = new Uint8Array(len * img.colors),
alphaData = new Uint8Array(len),
pDiff = img.pixelBitlength - img.bits,
i = 0,
n = 0,
pixel,
pbl;
for (; i < len; i++) {
pixel = pixels[i];
pbl = 0;
while (pbl < pDiff) {
imgData[n++] = pixel >>> pbl & 0xff;
pbl = pbl + img.bits;
}
alphaData[i] = pixel >>> pbl & 0xff;
}
}
/*
* processes 16 bit RGBA and grayscale + alpha images
*/
if (img.bits === 16) {
var pixels = new Uint32Array(img.decodePixels().buffer),
len = pixels.length,
imgData = new Uint8Array(len * (32 / img.pixelBitlength) * img.colors),
alphaData = new Uint8Array(len * (32 / img.pixelBitlength)),
hasColors = img.colors > 1,
i = 0,
n = 0,
a = 0,
pixel;
while (i < len) {
pixel = pixels[i++];
imgData[n++] = pixel >>> 0 & 0xff;
if (hasColors) {
imgData[n++] = pixel >>> 16 & 0xff;
pixel = pixels[i++];
imgData[n++] = pixel >>> 0 & 0xff;
}
alphaData[a++] = pixel >>> 16 & 0xff;
}
bpc = 8;
}
if (canCompress(compression)) {
imageData = compressBytes(imgData, img.width * img.colors, img.colors, compression);
smask = compressBytes(alphaData, img.width, 1, compression);
} else {
imageData = imgData;
smask = alphaData;
decode = null;
}
}
/*
* Indexed png. Each pixel is a palette index.
*/
if (img.colorType === 3) {
colorSpace = this.color_spaces.INDEXED;
pal = img.palette;
if (img.transparency.indexed) {
var trans = img.transparency.indexed;
var total = 0,
i = 0,
len = trans.length;
for (; i < len; ++i) {
total += trans[i];
}
total = total / 255;
/*
* a single color is specified as 100% transparent (0),
* so we set trns to use a /Mask with that index
*/
if (total === len - 1 && trans.indexOf(0) !== -1) {
trns = [trans.indexOf(0)];
/*
* there's more than one colour within the palette that specifies
* a transparency value less than 255, so we unroll the pixels to create an image sMask
*/
} else if (total !== len) {
var pixels = img.decodePixels(),
alphaData = new Uint8Array(pixels.length),
i = 0,
len = pixels.length;
for (; i < len; i++) {
alphaData[i] = trans[pixels[i]];
}
smask = compressBytes(alphaData, img.width, 1);
}
}
}
var predictor = getPredictorFromCompression(compression);
if (decode === this.decode.FLATE_DECODE) dp = "/Predictor " + predictor + " /Colors " + colors + " /BitsPerComponent " + bpc + " /Columns " + img.width; //remove 'Predictor' as it applies to the type of png filter applied to its IDAT - we only apply with compression
else dp = "/Colors " + colors + " /BitsPerComponent " + bpc + " /Columns " + img.width;
if (this.isArrayBuffer(imageData) || this.isArrayBufferView(imageData)) imageData = this.arrayBufferToBinaryString(imageData);
if (smask && this.isArrayBuffer(smask) || this.isArrayBufferView(smask)) smask = this.arrayBufferToBinaryString(smask);
return this.createImageInfo(imageData, img.width, img.height, colorSpace, bpc, decode, imageIndex, alias, dp, trns, pal, smask, predictor);
}
throw new Error("Unsupported PNG image data, try using JPEG instead.");
};
})(jsPDF.API);
/**
* @license
* Copyright (c) 2017 Aras Abbasi
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* jsPDF gif Support PlugIn
*
* @name gif_support
* @module
*/
(function (jsPDFAPI) {
jsPDFAPI.processGIF89A = function (imageData, imageIndex, alias, compression, dataAsBinaryString) {
var reader = new GifReader(imageData);
var width = reader.width,
height = reader.height;
var qu = 100;
var pixels = [];
reader.decodeAndBlitFrameRGBA(0, pixels);
var rawImageData = {
data: pixels,
width: width,
height: height
};
var encoder = new JPEGEncoder(qu);
var data = encoder.encode(rawImageData, qu);
return jsPDFAPI.processJPEG.call(this, data, imageIndex, alias, compression);
};
jsPDFAPI.processGIF87A = jsPDFAPI.processGIF89A;
})(jsPDF.API);
/**
* Copyright (c) 2018 Aras Abbasi
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* jsPDF bmp Support PlugIn
* @name bmp_support
* @module
*/
(function (jsPDFAPI) {
jsPDFAPI.processBMP = function (imageData, imageIndex, alias, compression, dataAsBinaryString) {
var reader = new BmpDecoder(imageData, false);
var width = reader.width,
height = reader.height;
var qu = 100;
var pixels = reader.getData();
var rawImageData = {
data: pixels,
width: width,
height: height
};
var encoder = new JPEGEncoder(qu);
var data = encoder.encode(rawImageData, qu);
return jsPDFAPI.processJPEG.call(this, data, imageIndex, alias, compression);
};
})(jsPDF.API);
/**
* @license
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* jsPDF setLanguage Plugin
*
* @name setLanguage
* @module
*/
(function (jsPDFAPI) {
/**
* Add Language Tag to the generated PDF
*
* @name setLanguage
* @function
* @param {string} langCode The Language code as ISO-639-1 (e.g. 'en') or as country language code (e.g. 'en-GB').
* @returns {jsPDF}
* @example
* var doc = new jsPDF()
* doc.text(10, 10, 'This is a test')
* doc.setLanguage("en-US")
* doc.save('english.pdf')
*/
jsPDFAPI.setLanguage = function (langCode) {
var langCodes = {
af: "Afrikaans",
sq: "Albanian",
ar: "Arabic (Standard)",
"ar-DZ": "Arabic (Algeria)",
"ar-BH": "Arabic (Bahrain)",
"ar-EG": "Arabic (Egypt)",
"ar-IQ": "Arabic (Iraq)",
"ar-JO": "Arabic (Jordan)",
"ar-KW": "Arabic (Kuwait)",
"ar-LB": "Arabic (Lebanon)",
"ar-LY": "Arabic (Libya)",
"ar-MA": "Arabic (Morocco)",
"ar-OM": "Arabic (Oman)",
"ar-QA": "Arabic (Qatar)",
"ar-SA": "Arabic (Saudi Arabia)",
"ar-SY": "Arabic (Syria)",
"ar-TN": "Arabic (Tunisia)",
"ar-AE": "Arabic (U.A.E.)",
"ar-YE": "Arabic (Yemen)",
an: "Aragonese",
hy: "Armenian",
as: "Assamese",
ast: "Asturian",
az: "Azerbaijani",
eu: "Basque",
be: "Belarusian",
bn: "Bengali",
bs: "Bosnian",
br: "Breton",
bg: "Bulgarian",
my: "Burmese",
ca: "Catalan",
ch: "Chamorro",
ce: "Chechen",
zh: "Chinese",
"zh-HK": "Chinese (Hong Kong)",
"zh-CN": "Chinese (PRC)",
"zh-SG": "Chinese (Singapore)",
"zh-TW": "Chinese (Taiwan)",
cv: "Chuvash",
co: "Corsican",
cr: "Cree",
hr: "Croatian",
cs: "Czech",
da: "Danish",
nl: "Dutch (Standard)",
"nl-BE": "Dutch (Belgian)",
en: "English",
"en-AU": "English (Australia)",
"en-BZ": "English (Belize)",
"en-CA": "English (Canada)",
"en-IE": "English (Ireland)",
"en-JM": "English (Jamaica)",
"en-NZ": "English (New Zealand)",
"en-PH": "English (Philippines)",
"en-ZA": "English (South Africa)",
"en-TT": "English (Trinidad & Tobago)",
"en-GB": "English (United Kingdom)",
"en-US": "English (United States)",
"en-ZW": "English (Zimbabwe)",
eo: "Esperanto",
et: "Estonian",
fo: "Faeroese",
fj: "Fijian",
fi: "Finnish",
fr: "French (Standard)",
"fr-BE": "French (Belgium)",
"fr-CA": "French (Canada)",
"fr-FR": "French (France)",
"fr-LU": "French (Luxembourg)",
"fr-MC": "French (Monaco)",
"fr-CH": "French (Switzerland)",
fy: "Frisian",
fur: "Friulian",
gd: "Gaelic (Scots)",
"gd-IE": "Gaelic (Irish)",
gl: "Galacian",
ka: "Georgian",
de: "German (Standard)",
"de-AT": "German (Austria)",
"de-DE": "German (Germany)",
"de-LI": "German (Liechtenstein)",
"de-LU": "German (Luxembourg)",
"de-CH": "German (Switzerland)",
el: "Greek",
gu: "Gujurati",
ht: "Haitian",
he: "Hebrew",
hi: "Hindi",
hu: "Hungarian",
is: "Icelandic",
id: "Indonesian",
iu: "Inuktitut",
ga: "Irish",
it: "Italian (Standard)",
"it-CH": "Italian (Switzerland)",
ja: "Japanese",
kn: "Kannada",
ks: "Kashmiri",
kk: "Kazakh",
km: "Khmer",
ky: "Kirghiz",
tlh: "Klingon",
ko: "Korean",
"ko-KP": "Korean (North Korea)",
"ko-KR": "Korean (South Korea)",
la: "Latin",
lv: "Latvian",
lt: "Lithuanian",
lb: "Luxembourgish",
mk: "FYRO Macedonian",
ms: "Malay",
ml: "Malayalam",
mt: "Maltese",
mi: "Maori",
mr: "Marathi",
mo: "Moldavian",
nv: "Navajo",
ng: "Ndonga",
ne: "Nepali",
no: "Norwegian",
nb: "Norwegian (Bokmal)",
nn: "Norwegian (Nynorsk)",
oc: "Occitan",
or: "Oriya",
om: "Oromo",
fa: "Persian",
"fa-IR": "Persian/Iran",
pl: "Polish",
pt: "Portuguese",
"pt-BR": "Portuguese (Brazil)",
pa: "Punjabi",
"pa-IN": "Punjabi (India)",
"pa-PK": "Punjabi (Pakistan)",
qu: "Quechua",
rm: "Rhaeto-Romanic",
ro: "Romanian",
"ro-MO": "Romanian (Moldavia)",
ru: "Russian",
"ru-MO": "Russian (Moldavia)",
sz: "Sami (Lappish)",
sg: "Sango",
sa: "Sanskrit",
sc: "Sardinian",
sd: "Sindhi",
si: "Singhalese",
sr: "Serbian",
sk: "Slovak",
sl: "Slovenian",
so: "Somani",
sb: "Sorbian",
es: "Spanish",
"es-AR": "Spanish (Argentina)",
"es-BO": "Spanish (Bolivia)",
"es-CL": "Spanish (Chile)",
"es-CO": "Spanish (Colombia)",
"es-CR": "Spanish (Costa Rica)",
"es-DO": "Spanish (Dominican Republic)",
"es-EC": "Spanish (Ecuador)",
"es-SV": "Spanish (El Salvador)",
"es-GT": "Spanish (Guatemala)",
"es-HN": "Spanish (Honduras)",
"es-MX": "Spanish (Mexico)",
"es-NI": "Spanish (Nicaragua)",
"es-PA": "Spanish (Panama)",
"es-PY": "Spanish (Paraguay)",
"es-PE": "Spanish (Peru)",
"es-PR": "Spanish (Puerto Rico)",
"es-ES": "Spanish (Spain)",
"es-UY": "Spanish (Uruguay)",
"es-VE": "Spanish (Venezuela)",
sx: "Sutu",
sw: "Swahili",
sv: "Swedish",
"sv-FI": "Swedish (Finland)",
"sv-SV": "Swedish (Sweden)",
ta: "Tamil",
tt: "Tatar",
te: "Teluga",
th: "Thai",
tig: "Tigre",
ts: "Tsonga",
tn: "Tswana",
tr: "Turkish",
tk: "Turkmen",
uk: "Ukrainian",
hsb: "Upper Sorbian",
ur: "Urdu",
ve: "Venda",
vi: "Vietnamese",
vo: "Volapuk",
wa: "Walloon",
cy: "Welsh",
xh: "Xhosa",
ji: "Yiddish",
zu: "Zulu"
};
if (this.internal.languageSettings === undefined) {
this.internal.languageSettings = {};
this.internal.languageSettings.isSubscribed = false;
}
if (langCodes[langCode] !== undefined) {
this.internal.languageSettings.languageCode = langCode;
if (this.internal.languageSettings.isSubscribed === false) {
this.internal.events.subscribe("putCatalog", function () {
this.internal.write("/Lang (" + this.internal.languageSettings.languageCode + ")");
});
this.internal.languageSettings.isSubscribed = true;
}
}
return this;
};
})(jsPDF.API);
/** @license
* MIT license.
* Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
* 2014 Diego Casorran, https://github.com/diegocr
*
*
* ====================================================================
*/
/**
* jsPDF split_text_to_size plugin
*
* @name split_text_to_size
* @module
*/
(function (API) {
/**
* Returns an array of length matching length of the 'word' string, with each
* cell occupied by the width of the char in that position.
*
* @name getCharWidthsArray
* @function
* @param {string} text
* @param {Object} options
* @returns {Array}
*/
var getCharWidthsArray = API.getCharWidthsArray = function (text, options) {
options = options || {};
var activeFont = options.font || this.internal.getFont();
var fontSize = options.fontSize || this.internal.getFontSize();
var charSpace = options.charSpace || this.internal.getCharSpace();
var widths = options.widths ? options.widths : activeFont.metadata.Unicode.widths;
var widthsFractionOf = widths.fof ? widths.fof : 1;
var kerning = options.kerning ? options.kerning : activeFont.metadata.Unicode.kerning;
var kerningFractionOf = kerning.fof ? kerning.fof : 1;
var i;
var l;
var char_code;
var prior_char_code = 0; //for kerning
var default_char_width = widths[0] || widthsFractionOf;
var output = [];
for (i = 0, l = text.length; i < l; i++) {
char_code = text.charCodeAt(i);
if (typeof activeFont.metadata.widthOfString === "function") {
output.push((activeFont.metadata.widthOfGlyph(activeFont.metadata.characterToGlyph(char_code)) + charSpace * (1000 / fontSize) || 0) / 1000);
} else {
output.push((widths[char_code] || default_char_width) / widthsFractionOf + (kerning[char_code] && kerning[char_code][prior_char_code] || 0) / kerningFractionOf);
}
prior_char_code = char_code;
}
return output;
};
/**
* Calculate the sum of a number-array
*
* @name getArraySum
* @public
* @function
* @param {Array} array Array of numbers
* @returns {number}
*/
var getArraySum = API.getArraySum = function (array) {
var i = array.length,
output = 0;
while (i) {
i--;
output += array[i];
}
return output;
};
/**
* Returns a widths of string in a given font, if the font size is set as 1 point.
*
* In other words, this is "proportional" value. For 1 unit of font size, the length
* of the string will be that much.
*
* Multiply by font size to get actual width in *points*
* Then divide by 72 to get inches or divide by (72/25.6) to get 'mm' etc.
*
* @name getStringUnitWidth
* @public
* @function
* @param {string} text
* @param {string} options
* @returns {number} result
*/
var getStringUnitWidth = API.getStringUnitWidth = function (text, options) {
options = options || {};
var fontSize = options.fontSize || this.internal.getFontSize();
var font = options.font || this.internal.getFont();
var charSpace = options.charSpace || this.internal.getCharSpace();
var result = 0;
if (typeof font.metadata.widthOfString === "function") {
result = font.metadata.widthOfString(text, fontSize, charSpace) / fontSize;
} else {
result = getArraySum(getCharWidthsArray.apply(this, arguments));
}
return result;
};
/**
returns array of lines
*/
var splitLongWord = function splitLongWord(word, widths_array, firstLineMaxLen, maxLen) {
var answer = []; // 1st, chop off the piece that can fit on the hanging line.
var i = 0,
l = word.length,
workingLen = 0;
while (i !== l && workingLen + widths_array[i] < firstLineMaxLen) {
workingLen += widths_array[i];
i++;
} // this is first line.
answer.push(word.slice(0, i)); // 2nd. Split the rest into maxLen pieces.
var startOfLine = i;
workingLen = 0;
while (i !== l) {
if (workingLen + widths_array[i] > maxLen) {
answer.push(word.slice(startOfLine, i));
workingLen = 0;
startOfLine = i;
}
workingLen += widths_array[i];
i++;
}
if (startOfLine !== i) {
answer.push(word.slice(startOfLine, i));
}
return answer;
}; // Note, all sizing inputs for this function must be in "font measurement units"
// By default, for PDF, it's "point".
var splitParagraphIntoLines = function splitParagraphIntoLines(text, maxlen, options) {
// at this time works only on Western scripts, ones with space char
// separating the words. Feel free to expand.
if (!options) {
options = {};
}
var line = [],
lines = [line],
line_length = options.textIndent || 0,
separator_length = 0,
current_word_length = 0,
word,
widths_array,
words = text.split(" "),
spaceCharWidth = getCharWidthsArray.apply(this, [" ", options])[0],
i,
l,
tmp,
lineIndent;
if (options.lineIndent === -1) {
lineIndent = words[0].length + 2;
} else {
lineIndent = options.lineIndent || 0;
}
if (lineIndent) {
var pad = Array(lineIndent).join(" "),
wrds = [];
words.map(function (wrd) {
wrd = wrd.split(/\s*\n/);
if (wrd.length > 1) {
wrds = wrds.concat(wrd.map(function (wrd, idx) {
return (idx && wrd.length ? "\n" : "") + wrd;
}));
} else {
wrds.push(wrd[0]);
}
});
words = wrds;
lineIndent = getStringUnitWidth.apply(this, [pad, options]);
}
for (i = 0, l = words.length; i < l; i++) {
var force = 0;
word = words[i];
if (lineIndent && word[0] == "\n") {
word = word.substr(1);
force = 1;
}
widths_array = getCharWidthsArray.apply(this, [word, options]);
current_word_length = getArraySum(widths_array);
if (line_length + separator_length + current_word_length > maxlen || force) {
if (current_word_length > maxlen) {
// this happens when you have space-less long URLs for example.
// we just chop these to size. We do NOT insert hiphens
tmp = splitLongWord.apply(this, [word, widths_array, maxlen - (line_length + separator_length), maxlen]); // first line we add to existing line object
line.push(tmp.shift()); // it's ok to have extra space indicator there
// last line we make into new line object
line = [tmp.pop()]; // lines in the middle we apped to lines object as whole lines
while (tmp.length) {
lines.push([tmp.shift()]); // single fragment occupies whole line
}
current_word_length = getArraySum(widths_array.slice(word.length - (line[0] ? line[0].length : 0)));
} else {
// just put it on a new line
line = [word];
} // now we attach new line to lines
lines.push(line);
line_length = current_word_length + lineIndent;
separator_length = spaceCharWidth;
} else {
line.push(word);
line_length += separator_length + current_word_length;
separator_length = spaceCharWidth;
}
}
if (lineIndent) {
var postProcess = function postProcess(ln, idx) {
return (idx ? pad : "") + ln.join(" ");
};
} else {
var postProcess = function postProcess(ln) {
return ln.join(" ");
};
}
return lines.map(postProcess);
};
/**
* Splits a given string into an array of strings. Uses 'size' value
* (in measurement units declared as default for the jsPDF instance)
* and the font's "widths" and "Kerning" tables, where available, to
* determine display length of a given string for a given font.
*
* We use character's 100% of unit size (height) as width when Width
* table or other default width is not available.
*
* @name splitTextToSize
* @public
* @function
* @param {string} text Unencoded, regular JavaScript (Unicode, UTF-16 / UCS-2) string.
* @param {number} size Nominal number, measured in units default to this instance of jsPDF.
* @param {Object} options Optional flags needed for chopper to do the right thing.
* @returns {Array} array Array with strings chopped to size.
*/
API.splitTextToSize = function (text, maxlen, options) {
options = options || {};
var fsize = options.fontSize || this.internal.getFontSize(),
newOptions = function (options) {
var widths = {
0: 1
},
kerning = {};
if (!options.widths || !options.kerning) {
var f = this.internal.getFont(options.fontName, options.fontStyle),
encoding = "Unicode"; // NOT UTF8, NOT UTF16BE/LE, NOT UCS2BE/LE
// Actual JavaScript-native String's 16bit char codes used.
// no multi-byte logic here
if (f.metadata[encoding]) {
return {
widths: f.metadata[encoding].widths || widths,
kerning: f.metadata[encoding].kerning || kerning
};
} else {
return {
font: f.metadata,
fontSize: this.internal.getFontSize(),
charSpace: this.internal.getCharSpace()
};
}
} else {
return {
widths: options.widths,
kerning: options.kerning
};
} // then use default values
return {
widths: widths,
kerning: kerning
};
}.call(this, options); // first we split on end-of-line chars
var paragraphs;
if (Array.isArray(text)) {
paragraphs = text;
} else {
paragraphs = text.split(/\r?\n/);
} // now we convert size (max length of line) into "font size units"
// at present time, the "font size unit" is always 'point'
// 'proportional' means, "in proportion to font size"
var fontUnit_maxLen = 1.0 * this.internal.scaleFactor * maxlen / fsize; // at this time, fsize is always in "points" regardless of the default measurement unit of the doc.
// this may change in the future?
// until then, proportional_maxlen is likely to be in 'points'
// If first line is to be indented (shorter or longer) than maxLen
// we indicate that by using CSS-style "text-indent" option.
// here it's in font units too (which is likely 'points')
// it can be negative (which makes the first line longer than maxLen)
newOptions.textIndent = options.textIndent ? options.textIndent * 1.0 * this.internal.scaleFactor / fsize : 0;
newOptions.lineIndent = options.lineIndent;
var i,
l,
output = [];
for (i = 0, l = paragraphs.length; i < l; i++) {
output = output.concat(splitParagraphIntoLines.apply(this, [paragraphs[i], fontUnit_maxLen, newOptions]));
}
return output;
};
})(jsPDF.API);
/** @license
jsPDF standard_fonts_metrics plugin
* Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
* MIT license.
*
* ====================================================================
*/
/**
* This file adds the standard font metrics to jsPDF.
*
* Font metrics data is reprocessed derivative of contents of
* "Font Metrics for PDF Core 14 Fonts" package, which exhibits the following copyright and license:
*
* Copyright (c) 1989, 1990, 1991, 1992, 1993, 1997 Adobe Systems Incorporated. All Rights Reserved.
*
* This file and the 14 PostScript(R) AFM files it accompanies may be used,
* copied, and distributed for any purpose and without charge, with or without
* modification, provided that all copyright notices are retained; that the AFM
* files are not distributed without this file; that all modifications to this
* file or any of the AFM files are prominently noted in the modified file(s);
* and that this paragraph is not modified. Adobe Systems has no responsibility
* or obligation to support the use of the AFM files.
*
* @name standard_fonts_metrics
* @module
*/
(function (API) {
/*
# reference (Python) versions of 'compress' and 'uncompress'
# only 'uncompress' function is featured lower as JavaScript
# if you want to unit test "roundtrip", just transcribe the reference
# 'compress' function from Python into JavaScript
def compress(data):
keys = '0123456789abcdef'
values = 'klmnopqrstuvwxyz'
mapping = dict(zip(keys, values))
vals = []
for key in data.keys():
value = data[key]
try:
keystring = hex(key)[2:]
keystring = keystring[:-1] + mapping[keystring[-1:]]
except:
keystring = key.join(["'","'"])
#print('Keystring is %s' % keystring)
try:
if value < 0:
valuestring = hex(value)[3:]
numberprefix = '-'
else:
valuestring = hex(value)[2:]
numberprefix = ''
valuestring = numberprefix + valuestring[:-1] + mapping[valuestring[-1:]]
except:
if type(value) == dict:
valuestring = compress(value)
else:
raise Exception("Don't know what to do with value type %s" % type(value))
vals.append(keystring+valuestring)
return '{' + ''.join(vals) + '}'
def uncompress(data):
decoded = '0123456789abcdef'
encoded = 'klmnopqrstuvwxyz'
mapping = dict(zip(encoded, decoded))
sign = +1
stringmode = False
stringparts = []
output = {}
activeobject = output
parentchain = []
keyparts = ''
valueparts = ''
key = None
ending = set(encoded)
i = 1
l = len(data) - 1 # stripping starting, ending {}
while i != l: # stripping {}
# -, {, }, ' are special.
ch = data[i]
i += 1
if ch == "'":
if stringmode:
# end of string mode
stringmode = False
key = ''.join(stringparts)
else:
# start of string mode
stringmode = True
stringparts = []
elif stringmode == True:
#print("Adding %s to stringpart" % ch)
stringparts.append(ch)
elif ch == '{':
# start of object
parentchain.append( [activeobject, key] )
activeobject = {}
key = None
#DEBUG = True
elif ch == '}':
# end of object
parent, key = parentchain.pop()
parent[key] = activeobject
key = None
activeobject = parent
#DEBUG = False
elif ch == '-':
sign = -1
else:
# must be number
if key == None:
#debug("In Key. It is '%s', ch is '%s'" % (keyparts, ch))
if ch in ending:
#debug("End of key")
keyparts += mapping[ch]
key = int(keyparts, 16) * sign
sign = +1
keyparts = ''
else:
keyparts += ch
else:
#debug("In value. It is '%s', ch is '%s'" % (valueparts, ch))
if ch in ending:
#debug("End of value")
valueparts += mapping[ch]
activeobject[key] = int(valueparts, 16) * sign
sign = +1
key = None
valueparts = ''
else:
valueparts += ch
#debug(activeobject)
return output
*/
/**
Uncompresses data compressed into custom, base16-like format.
@public
@function
@param
@returns {Type}
*/
var uncompress = function uncompress(data) {
var decoded = "0123456789abcdef",
encoded = "klmnopqrstuvwxyz",
mapping = {};
for (var i = 0; i < encoded.length; i++) {
mapping[encoded[i]] = decoded[i];
}
var undef,
output = {},
sign = 1,
stringparts,
// undef. will be [] in string mode
activeobject = output,
parentchain = [],
parent_key_pair,
keyparts = "",
valueparts = "",
key,
// undef. will be Truthy when Key is resolved.
datalen = data.length - 1,
// stripping ending }
ch;
i = 1; // stripping starting {
while (i != datalen) {
// - { } ' are special.
ch = data[i];
i += 1;
if (ch == "'") {
if (stringparts) {
// end of string mode
key = stringparts.join("");
stringparts = undef;
} else {
// start of string mode
stringparts = [];
}
} else if (stringparts) {
stringparts.push(ch);
} else if (ch == "{") {
// start of object
parentchain.push([activeobject, key]);
activeobject = {};
key = undef;
} else if (ch == "}") {
// end of object
parent_key_pair = parentchain.pop();
parent_key_pair[0][parent_key_pair[1]] = activeobject;
key = undef;
activeobject = parent_key_pair[0];
} else if (ch == "-") {
sign = -1;
} else {
// must be number
if (key === undef) {
if (mapping.hasOwnProperty(ch)) {
keyparts += mapping[ch];
key = parseInt(keyparts, 16) * sign;
sign = +1;
keyparts = "";
} else {
keyparts += ch;
}
} else {
if (mapping.hasOwnProperty(ch)) {
valueparts += mapping[ch];
activeobject[key] = parseInt(valueparts, 16) * sign;
sign = +1;
key = undef;
valueparts = "";
} else {
valueparts += ch;
}
}
}
} // end while
return output;
}; // encoding = 'Unicode'
// NOT UTF8, NOT UTF16BE/LE, NOT UCS2BE/LE. NO clever BOM behavior
// Actual 16bit char codes used.
// no multi-byte logic here
// Unicode characters to WinAnsiEncoding:
// {402: 131, 8211: 150, 8212: 151, 8216: 145, 8217: 146, 8218: 130, 8220: 147, 8221: 148, 8222: 132, 8224: 134, 8225: 135, 8226: 149, 8230: 133, 8364: 128, 8240:137, 8249: 139, 8250: 155, 710: 136, 8482: 153, 338: 140, 339: 156, 732: 152, 352: 138, 353: 154, 376: 159, 381: 142, 382: 158}
// as you can see, all Unicode chars are outside of 0-255 range. No char code conflicts.
// this means that you can give Win cp1252 encoded strings to jsPDF for rendering directly
// as well as give strings with some (supported by these fonts) Unicode characters and
// these will be mapped to win cp1252
// for example, you can send char code (cp1252) 0x80 or (unicode) 0x20AC, getting "Euro" glyph displayed in both cases.
var encodingBlock = {
codePages: ["WinAnsiEncoding"],
WinAnsiEncoding: uncompress("{19m8n201n9q201o9r201s9l201t9m201u8m201w9n201x9o201y8o202k8q202l8r202m9p202q8p20aw8k203k8t203t8v203u9v2cq8s212m9t15m8w15n9w2dw9s16k8u16l9u17s9z17x8y17y9y}")
},
encodings = {
Unicode: {
Courier: encodingBlock,
"Courier-Bold": encodingBlock,
"Courier-BoldOblique": encodingBlock,
"Courier-Oblique": encodingBlock,
Helvetica: encodingBlock,
"Helvetica-Bold": encodingBlock,
"Helvetica-BoldOblique": encodingBlock,
"Helvetica-Oblique": encodingBlock,
"Times-Roman": encodingBlock,
"Times-Bold": encodingBlock,
"Times-BoldItalic": encodingBlock,
"Times-Italic": encodingBlock // , 'Symbol'
// , 'ZapfDingbats'
}
},
fontMetrics = {
Unicode: {
// all sizing numbers are n/fontMetricsFractionOf = one font size unit
// this means that if fontMetricsFractionOf = 1000, and letter A's width is 476, it's
// width is 476/1000 or 47.6% of its height (regardless of font size)
// At this time this value applies to "widths" and "kerning" numbers.
// char code 0 represents "default" (average) width - use it for chars missing in this table.
// key 'fof' represents the "fontMetricsFractionOf" value
"Courier-Oblique": uncompress("{'widths'{k3w'fof'6o}'kerning'{'fof'-6o}}"),
"Times-BoldItalic": uncompress("{'widths'{k3o2q4ycx2r201n3m201o6o201s2l201t2l201u2l201w3m201x3m201y3m2k1t2l2r202m2n2n3m2o3m2p5n202q6o2r1w2s2l2t2l2u3m2v3t2w1t2x2l2y1t2z1w3k3m3l3m3m3m3n3m3o3m3p3m3q3m3r3m3s3m203t2l203u2l3v2l3w3t3x3t3y3t3z3m4k5n4l4m4m4m4n4m4o4s4p4m4q4m4r4s4s4y4t2r4u3m4v4m4w3x4x5t4y4s4z4s5k3x5l4s5m4m5n3r5o3x5p4s5q4m5r5t5s4m5t3x5u3x5v2l5w1w5x2l5y3t5z3m6k2l6l3m6m3m6n2w6o3m6p2w6q2l6r3m6s3r6t1w6u1w6v3m6w1w6x4y6y3r6z3m7k3m7l3m7m2r7n2r7o1w7p3r7q2w7r4m7s3m7t2w7u2r7v2n7w1q7x2n7y3t202l3mcl4mal2ram3man3mao3map3mar3mas2lat4uau1uav3maw3way4uaz2lbk2sbl3t'fof'6obo2lbp3tbq3mbr1tbs2lbu1ybv3mbz3mck4m202k3mcm4mcn4mco4mcp4mcq5ycr4mcs4mct4mcu4mcv4mcw2r2m3rcy2rcz2rdl4sdm4sdn4sdo4sdp4sdq4sds4sdt4sdu4sdv4sdw4sdz3mek3mel3mem3men3meo3mep3meq4ser2wes2wet2weu2wev2wew1wex1wey1wez1wfl3rfm3mfn3mfo3mfp3mfq3mfr3tfs3mft3rfu3rfv3rfw3rfz2w203k6o212m6o2dw2l2cq2l3t3m3u2l17s3x19m3m}'kerning'{cl{4qu5kt5qt5rs17ss5ts}201s{201ss}201t{cks4lscmscnscoscpscls2wu2yu201ts}201x{2wu2yu}2k{201ts}2w{4qx5kx5ou5qx5rs17su5tu}2x{17su5tu5ou}2y{4qx5kx5ou5qx5rs17ss5ts}'fof'-6ofn{17sw5tw5ou5qw5rs}7t{cksclscmscnscoscps4ls}3u{17su5tu5os5qs}3v{17su5tu5os5qs}7p{17su5tu}ck{4qu5kt5qt5rs17ss5ts}4l{4qu5kt5qt5rs17ss5ts}cm{4qu5kt5qt5rs17ss5ts}cn{4qu5kt5qt5rs17ss5ts}co{4qu5kt5qt5rs17ss5ts}cp{4qu5kt5qt5rs17ss5ts}6l{4qu5ou5qw5rt17su5tu}5q{ckuclucmucnucoucpu4lu}5r{ckuclucmucnucoucpu4lu}7q{cksclscmscnscoscps4ls}6p{4qu5ou5qw5rt17sw5tw}ek{4qu5ou5qw5rt17su5tu}el{4qu5ou5qw5rt17su5tu}em{4qu5ou5qw5rt17su5tu}en{4qu5ou5qw5rt17su5tu}eo{4qu5ou5qw5rt17su5tu}ep{4qu5ou5qw5rt17su5tu}es{17ss5ts5qs4qu}et{4qu5ou5qw5rt17sw5tw}eu{4qu5ou5qw5rt17ss5ts}ev{17ss5ts5qs4qu}6z{17sw5tw5ou5qw5rs}fm{17sw5tw5ou5qw5rs}7n{201ts}fo{17sw5tw5ou5qw5rs}fp{17sw5tw5ou5qw5rs}fq{17sw5tw5ou5qw5rs}7r{cksclscmscnscoscps4ls}fs{17sw5tw5ou5qw5rs}ft{17su5tu}fu{17su5tu}fv{17su5tu}fw{17su5tu}fz{cksclscmscnscoscps4ls}}}"),
"Helvetica-Bold": uncompress("{'widths'{k3s2q4scx1w201n3r201o6o201s1w201t1w201u1w201w3m201x3m201y3m2k1w2l2l202m2n2n3r2o3r2p5t202q6o2r1s2s2l2t2l2u2r2v3u2w1w2x2l2y1w2z1w3k3r3l3r3m3r3n3r3o3r3p3r3q3r3r3r3s3r203t2l203u2l3v2l3w3u3x3u3y3u3z3x4k6l4l4s4m4s4n4s4o4s4p4m4q3x4r4y4s4s4t1w4u3r4v4s4w3x4x5n4y4s4z4y5k4m5l4y5m4s5n4m5o3x5p4s5q4m5r5y5s4m5t4m5u3x5v2l5w1w5x2l5y3u5z3r6k2l6l3r6m3x6n3r6o3x6p3r6q2l6r3x6s3x6t1w6u1w6v3r6w1w6x5t6y3x6z3x7k3x7l3x7m2r7n3r7o2l7p3x7q3r7r4y7s3r7t3r7u3m7v2r7w1w7x2r7y3u202l3rcl4sal2lam3ran3rao3rap3rar3ras2lat4tau2pav3raw3uay4taz2lbk2sbl3u'fof'6obo2lbp3xbq3rbr1wbs2lbu2obv3rbz3xck4s202k3rcm4scn4sco4scp4scq6ocr4scs4mct4mcu4mcv4mcw1w2m2zcy1wcz1wdl4sdm4ydn4ydo4ydp4ydq4yds4ydt4sdu4sdv4sdw4sdz3xek3rel3rem3ren3reo3rep3req5ter3res3ret3reu3rev3rew1wex1wey1wez1wfl3xfm3xfn3xfo3xfp3xfq3xfr3ufs3xft3xfu3xfv3xfw3xfz3r203k6o212m6o2dw2l2cq2l3t3r3u2l17s4m19m3r}'kerning'{cl{4qs5ku5ot5qs17sv5tv}201t{2ww4wy2yw}201w{2ks}201x{2ww4wy2yw}2k{201ts201xs}2w{7qs4qu5kw5os5qw5rs17su5tu7tsfzs}2x{5ow5qs}2y{7qs4qu5kw5os5qw5rs17su5tu7tsfzs}'fof'-6o7p{17su5tu5ot}ck{4qs5ku5ot5qs17sv5tv}4l{4qs5ku5ot5qs17sv5tv}cm{4qs5ku5ot5qs17sv5tv}cn{4qs5ku5ot5qs17sv5tv}co{4qs5ku5ot5qs17sv5tv}cp{4qs5ku5ot5qs17sv5tv}6l{17st5tt5os}17s{2kwclvcmvcnvcovcpv4lv4wwckv}5o{2kucltcmtcntcotcpt4lt4wtckt}5q{2ksclscmscnscoscps4ls4wvcks}5r{2ks4ws}5t{2kwclvcmvcnvcovcpv4lv4wwckv}eo{17st5tt5os}fu{17su5tu5ot}6p{17ss5ts}ek{17st5tt5os}el{17st5tt5os}em{17st5tt5os}en{17st5tt5os}6o{201ts}ep{17st5tt5os}es{17ss5ts}et{17ss5ts}eu{17ss5ts}ev{17ss5ts}6z{17su5tu5os5qt}fm{17su5tu5os5qt}fn{17su5tu5os5qt}fo{17su5tu5os5qt}fp{17su5tu5os5qt}fq{17su5tu5os5qt}fs{17su5tu5os5qt}ft{17su5tu5ot}7m{5os}fv{17su5tu5ot}fw{17su5tu5ot}}}"),
Courier: uncompress("{'widths'{k3w'fof'6o}'kerning'{'fof'-6o}}"),
"Courier-BoldOblique": uncompress("{'widths'{k3w'fof'6o}'kerning'{'fof'-6o}}"),
"Times-Bold": uncompress("{'widths'{k3q2q5ncx2r201n3m201o6o201s2l201t2l201u2l201w3m201x3m201y3m2k1t2l2l202m2n2n3m2o3m2p6o202q6o2r1w2s2l2t2l2u3m2v3t2w1t2x2l2y1t2z1w3k3m3l3m3m3m3n3m3o3m3p3m3q3m3r3m3s3m203t2l203u2l3v2l3w3t3x3t3y3t3z3m4k5x4l4s4m4m4n4s4o4s4p4m4q3x4r4y4s4y4t2r4u3m4v4y4w4m4x5y4y4s4z4y5k3x5l4y5m4s5n3r5o4m5p4s5q4s5r6o5s4s5t4s5u4m5v2l5w1w5x2l5y3u5z3m6k2l6l3m6m3r6n2w6o3r6p2w6q2l6r3m6s3r6t1w6u2l6v3r6w1w6x5n6y3r6z3m7k3r7l3r7m2w7n2r7o2l7p3r7q3m7r4s7s3m7t3m7u2w7v2r7w1q7x2r7y3o202l3mcl4sal2lam3man3mao3map3mar3mas2lat4uau1yav3maw3tay4uaz2lbk2sbl3t'fof'6obo2lbp3rbr1tbs2lbu2lbv3mbz3mck4s202k3mcm4scn4sco4scp4scq6ocr4scs4mct4mcu4mcv4mcw2r2m3rcy2rcz2rdl4sdm4ydn4ydo4ydp4ydq4yds4ydt4sdu4sdv4sdw4sdz3rek3mel3mem3men3meo3mep3meq4ser2wes2wet2weu2wev2wew1wex1wey1wez1wfl3rfm3mfn3mfo3mfp3mfq3mfr3tfs3mft3rfu3rfv3rfw3rfz3m203k6o212m6o2dw2l2cq2l3t3m3u2l17s4s19m3m}'kerning'{cl{4qt5ks5ot5qy5rw17sv5tv}201t{cks4lscmscnscoscpscls4wv}2k{201ts}2w{4qu5ku7mu5os5qx5ru17su5tu}2x{17su5tu5ou5qs}2y{4qv5kv7mu5ot5qz5ru17su5tu}'fof'-6o7t{cksclscmscnscoscps4ls}3u{17su5tu5os5qu}3v{17su5tu5os5qu}fu{17su5tu5ou5qu}7p{17su5tu5ou5qu}ck{4qt5ks5ot5qy5rw17sv5tv}4l{4qt5ks5ot5qy5rw17sv5tv}cm{4qt5ks5ot5qy5rw17sv5tv}cn{4qt5ks5ot5qy5rw17sv5tv}co{4qt5ks5ot5qy5rw17sv5tv}cp{4qt5ks5ot5qy5rw17sv5tv}6l{17st5tt5ou5qu}17s{ckuclucmucnucoucpu4lu4wu}5o{ckuclucmucnucoucpu4lu4wu}5q{ckzclzcmzcnzcozcpz4lz4wu}5r{ckxclxcmxcnxcoxcpx4lx4wu}5t{ckuclucmucnucoucpu4lu4wu}7q{ckuclucmucnucoucpu4lu}6p{17sw5tw5ou5qu}ek{17st5tt5qu}el{17st5tt5ou5qu}em{17st5tt5qu}en{17st5tt5qu}eo{17st5tt5qu}ep{17st5tt5ou5qu}es{17ss5ts5qu}et{17sw5tw5ou5qu}eu{17sw5tw5ou5qu}ev{17ss5ts5qu}6z{17sw5tw5ou5qu5rs}fm{17sw5tw5ou5qu5rs}fn{17sw5tw5ou5qu5rs}fo{17sw5tw5ou5qu5rs}fp{17sw5tw5ou5qu5rs}fq{17sw5tw5ou5qu5rs}7r{cktcltcmtcntcotcpt4lt5os}fs{17sw5tw5ou5qu5rs}ft{17su5tu5ou5qu}7m{5os}fv{17su5tu5ou5qu}fw{17su5tu5ou5qu}fz{cksclscmscnscoscps4ls}}}"),
Symbol: uncompress("{'widths'{k3uaw4r19m3m2k1t2l2l202m2y2n3m2p5n202q6o3k3m2s2l2t2l2v3r2w1t3m3m2y1t2z1wbk2sbl3r'fof'6o3n3m3o3m3p3m3q3m3r3m3s3m3t3m3u1w3v1w3w3r3x3r3y3r3z2wbp3t3l3m5v2l5x2l5z3m2q4yfr3r7v3k7w1o7x3k}'kerning'{'fof'-6o}}"),
Helvetica: uncompress("{'widths'{k3p2q4mcx1w201n3r201o6o201s1q201t1q201u1q201w2l201x2l201y2l2k1w2l1w202m2n2n3r2o3r2p5t202q6o2r1n2s2l2t2l2u2r2v3u2w1w2x2l2y1w2z1w3k3r3l3r3m3r3n3r3o3r3p3r3q3r3r3r3s3r203t2l203u2l3v1w3w3u3x3u3y3u3z3r4k6p4l4m4m4m4n4s4o4s4p4m4q3x4r4y4s4s4t1w4u3m4v4m4w3r4x5n4y4s4z4y5k4m5l4y5m4s5n4m5o3x5p4s5q4m5r5y5s4m5t4m5u3x5v1w5w1w5x1w5y2z5z3r6k2l6l3r6m3r6n3m6o3r6p3r6q1w6r3r6s3r6t1q6u1q6v3m6w1q6x5n6y3r6z3r7k3r7l3r7m2l7n3m7o1w7p3r7q3m7r4s7s3m7t3m7u3m7v2l7w1u7x2l7y3u202l3rcl4mal2lam3ran3rao3rap3rar3ras2lat4tau2pav3raw3uay4taz2lbk2sbl3u'fof'6obo2lbp3rbr1wbs2lbu2obv3rbz3xck4m202k3rcm4mcn4mco4mcp4mcq6ocr4scs4mct4mcu4mcv4mcw1w2m2ncy1wcz1wdl4sdm4ydn4ydo4ydp4ydq4yds4ydt4sdu4sdv4sdw4sdz3xek3rel3rem3ren3reo3rep3req5ter3mes3ret3reu3rev3rew1wex1wey1wez1wfl3rfm3rfn3rfo3rfp3rfq3rfr3ufs3xft3rfu3rfv3rfw3rfz3m203k6o212m6o2dw2l2cq2l3t3r3u1w17s4m19m3r}'kerning'{5q{4wv}cl{4qs5kw5ow5qs17sv5tv}201t{2wu4w1k2yu}201x{2wu4wy2yu}17s{2ktclucmucnu4otcpu4lu4wycoucku}2w{7qs4qz5k1m17sy5ow5qx5rsfsu5ty7tufzu}2x{17sy5ty5oy5qs}2y{7qs4qz5k1m17sy5ow5qx5rsfsu5ty7tufzu}'fof'-6o7p{17sv5tv5ow}ck{4qs5kw5ow5qs17sv5tv}4l{4qs5kw5ow5qs17sv5tv}cm{4qs5kw5ow5qs17sv5tv}cn{4qs5kw5ow5qs17sv5tv}co{4qs5kw5ow5qs17sv5tv}cp{4qs5kw5ow5qs17sv5tv}6l{17sy5ty5ow}do{17st5tt}4z{17st5tt}7s{fst}dm{17st5tt}dn{17st5tt}5o{ckwclwcmwcnwcowcpw4lw4wv}dp{17st5tt}dq{17st5tt}7t{5ow}ds{17st5tt}5t{2ktclucmucnu4otcpu4lu4wycoucku}fu{17sv5tv5ow}6p{17sy5ty5ow5qs}ek{17sy5ty5ow}el{17sy5ty5ow}em{17sy5ty5ow}en{5ty}eo{17sy5ty5ow}ep{17sy5ty5ow}es{17sy5ty5qs}et{17sy5ty5ow5qs}eu{17sy5ty5ow5qs}ev{17sy5ty5ow5qs}6z{17sy5ty5ow5qs}fm{17sy5ty5ow5qs}fn{17sy5ty5ow5qs}fo{17sy5ty5ow5qs}fp{17sy5ty5qs}fq{17sy5ty5ow5qs}7r{5ow}fs{17sy5ty5ow5qs}ft{17sv5tv5ow}7m{5ow}fv{17sv5tv5ow}fw{17sv5tv5ow}}}"),
"Helvetica-BoldOblique": uncompress("{'widths'{k3s2q4scx1w201n3r201o6o201s1w201t1w201u1w201w3m201x3m201y3m2k1w2l2l202m2n2n3r2o3r2p5t202q6o2r1s2s2l2t2l2u2r2v3u2w1w2x2l2y1w2z1w3k3r3l3r3m3r3n3r3o3r3p3r3q3r3r3r3s3r203t2l203u2l3v2l3w3u3x3u3y3u3z3x4k6l4l4s4m4s4n4s4o4s4p4m4q3x4r4y4s4s4t1w4u3r4v4s4w3x4x5n4y4s4z4y5k4m5l4y5m4s5n4m5o3x5p4s5q4m5r5y5s4m5t4m5u3x5v2l5w1w5x2l5y3u5z3r6k2l6l3r6m3x6n3r6o3x6p3r6q2l6r3x6s3x6t1w6u1w6v3r6w1w6x5t6y3x6z3x7k3x7l3x7m2r7n3r7o2l7p3x7q3r7r4y7s3r7t3r7u3m7v2r7w1w7x2r7y3u202l3rcl4sal2lam3ran3rao3rap3rar3ras2lat4tau2pav3raw3uay4taz2lbk2sbl3u'fof'6obo2lbp3xbq3rbr1wbs2lbu2obv3rbz3xck4s202k3rcm4scn4sco4scp4scq6ocr4scs4mct4mcu4mcv4mcw1w2m2zcy1wcz1wdl4sdm4ydn4ydo4ydp4ydq4yds4ydt4sdu4sdv4sdw4sdz3xek3rel3rem3ren3reo3rep3req5ter3res3ret3reu3rev3rew1wex1wey1wez1wfl3xfm3xfn3xfo3xfp3xfq3xfr3ufs3xft3xfu3xfv3xfw3xfz3r203k6o212m6o2dw2l2cq2l3t3r3u2l17s4m19m3r}'kerning'{cl{4qs5ku5ot5qs17sv5tv}201t{2ww4wy2yw}201w{2ks}201x{2ww4wy2yw}2k{201ts201xs}2w{7qs4qu5kw5os5qw5rs17su5tu7tsfzs}2x{5ow5qs}2y{7qs4qu5kw5os5qw5rs17su5tu7tsfzs}'fof'-6o7p{17su5tu5ot}ck{4qs5ku5ot5qs17sv5tv}4l{4qs5ku5ot5qs17sv5tv}cm{4qs5ku5ot5qs17sv5tv}cn{4qs5ku5ot5qs17sv5tv}co{4qs5ku5ot5qs17sv5tv}cp{4qs5ku5ot5qs17sv5tv}6l{17st5tt5os}17s{2kwclvcmvcnvcovcpv4lv4wwckv}5o{2kucltcmtcntcotcpt4lt4wtckt}5q{2ksclscmscnscoscps4ls4wvcks}5r{2ks4ws}5t{2kwclvcmvcnvcovcpv4lv4wwckv}eo{17st5tt5os}fu{17su5tu5ot}6p{17ss5ts}ek{17st5tt5os}el{17st5tt5os}em{17st5tt5os}en{17st5tt5os}6o{201ts}ep{17st5tt5os}es{17ss5ts}et{17ss5ts}eu{17ss5ts}ev{17ss5ts}6z{17su5tu5os5qt}fm{17su5tu5os5qt}fn{17su5tu5os5qt}fo{17su5tu5os5qt}fp{17su5tu5os5qt}fq{17su5tu5os5qt}fs{17su5tu5os5qt}ft{17su5tu5ot}7m{5os}fv{17su5tu5ot}fw{17su5tu5ot}}}"),
ZapfDingbats: uncompress("{'widths'{k4u2k1w'fof'6o}'kerning'{'fof'-6o}}"),
"Courier-Bold": uncompress("{'widths'{k3w'fof'6o}'kerning'{'fof'-6o}}"),
"Times-Italic": uncompress("{'widths'{k3n2q4ycx2l201n3m201o5t201s2l201t2l201u2l201w3r201x3r201y3r2k1t2l2l202m2n2n3m2o3m2p5n202q5t2r1p2s2l2t2l2u3m2v4n2w1t2x2l2y1t2z1w3k3m3l3m3m3m3n3m3o3m3p3m3q3m3r3m3s3m203t2l203u2l3v2l3w4n3x4n3y4n3z3m4k5w4l3x4m3x4n4m4o4s4p3x4q3x4r4s4s4s4t2l4u2w4v4m4w3r4x5n4y4m4z4s5k3x5l4s5m3x5n3m5o3r5p4s5q3x5r5n5s3x5t3r5u3r5v2r5w1w5x2r5y2u5z3m6k2l6l3m6m3m6n2w6o3m6p2w6q1w6r3m6s3m6t1w6u1w6v2w6w1w6x4s6y3m6z3m7k3m7l3m7m2r7n2r7o1w7p3m7q2w7r4m7s2w7t2w7u2r7v2s7w1v7x2s7y3q202l3mcl3xal2ram3man3mao3map3mar3mas2lat4wau1vav3maw4nay4waz2lbk2sbl4n'fof'6obo2lbp3mbq3obr1tbs2lbu1zbv3mbz3mck3x202k3mcm3xcn3xco3xcp3xcq5tcr4mcs3xct3xcu3xcv3xcw2l2m2ucy2lcz2ldl4mdm4sdn4sdo4sdp4sdq4sds4sdt4sdu4sdv4sdw4sdz3mek3mel3mem3men3meo3mep3meq4mer2wes2wet2weu2wev2wew1wex1wey1wez1wfl3mfm3mfn3mfo3mfp3mfq3mfr4nfs3mft3mfu3mfv3mfw3mfz2w203k6o212m6m2dw2l2cq2l3t3m3u2l17s3r19m3m}'kerning'{cl{5kt4qw}201s{201sw}201t{201tw2wy2yy6q-t}201x{2wy2yy}2k{201tw}2w{7qs4qy7rs5ky7mw5os5qx5ru17su5tu}2x{17ss5ts5os}2y{7qs4qy7rs5ky7mw5os5qx5ru17su5tu}'fof'-6o6t{17ss5ts5qs}7t{5os}3v{5qs}7p{17su5tu5qs}ck{5kt4qw}4l{5kt4qw}cm{5kt4qw}cn{5kt4qw}co{5kt4qw}cp{5kt4qw}6l{4qs5ks5ou5qw5ru17su5tu}17s{2ks}5q{ckvclvcmvcnvcovcpv4lv}5r{ckuclucmucnucoucpu4lu}5t{2ks}6p{4qs5ks5ou5qw5ru17su5tu}ek{4qs5ks5ou5qw5ru17su5tu}el{4qs5ks5ou5qw5ru17su5tu}em{4qs5ks5ou5qw5ru17su5tu}en{4qs5ks5ou5qw5ru17su5tu}eo{4qs5ks5ou5qw5ru17su5tu}ep{4qs5ks5ou5qw5ru17su5tu}es{5ks5qs4qs}et{4qs5ks5ou5qw5ru17su5tu}eu{4qs5ks5qw5ru17su5tu}ev{5ks5qs4qs}ex{17ss5ts5qs}6z{4qv5ks5ou5qw5ru17su5tu}fm{4qv5ks5ou5qw5ru17su5tu}fn{4qv5ks5ou5qw5ru17su5tu}fo{4qv5ks5ou5qw5ru17su5tu}fp{4qv5ks5ou5qw5ru17su5tu}fq{4qv5ks5ou5qw5ru17su5tu}7r{5os}fs{4qv5ks5ou5qw5ru17su5tu}ft{17su5tu5qs}fu{17su5tu5qs}fv{17su5tu5qs}fw{17su5tu5qs}}}"),
"Times-Roman": uncompress("{'widths'{k3n2q4ycx2l201n3m201o6o201s2l201t2l201u2l201w2w201x2w201y2w2k1t2l2l202m2n2n3m2o3m2p5n202q6o2r1m2s2l2t2l2u3m2v3s2w1t2x2l2y1t2z1w3k3m3l3m3m3m3n3m3o3m3p3m3q3m3r3m3s3m203t2l203u2l3v1w3w3s3x3s3y3s3z2w4k5w4l4s4m4m4n4m4o4s4p3x4q3r4r4s4s4s4t2l4u2r4v4s4w3x4x5t4y4s4z4s5k3r5l4s5m4m5n3r5o3x5p4s5q4s5r5y5s4s5t4s5u3x5v2l5w1w5x2l5y2z5z3m6k2l6l2w6m3m6n2w6o3m6p2w6q2l6r3m6s3m6t1w6u1w6v3m6w1w6x4y6y3m6z3m7k3m7l3m7m2l7n2r7o1w7p3m7q3m7r4s7s3m7t3m7u2w7v3k7w1o7x3k7y3q202l3mcl4sal2lam3man3mao3map3mar3mas2lat4wau1vav3maw3say4waz2lbk2sbl3s'fof'6obo2lbp3mbq2xbr1tbs2lbu1zbv3mbz2wck4s202k3mcm4scn4sco4scp4scq5tcr4mcs3xct3xcu3xcv3xcw2l2m2tcy2lcz2ldl4sdm4sdn4sdo4sdp4sdq4sds4sdt4sdu4sdv4sdw4sdz3mek2wel2wem2wen2weo2wep2weq4mer2wes2wet2weu2wev2wew1wex1wey1wez1wfl3mfm3mfn3mfo3mfp3mfq3mfr3sfs3mft3mfu3mfv3mfw3mfz3m203k6o212m6m2dw2l2cq2l3t3m3u1w17s4s19m3m}'kerning'{cl{4qs5ku17sw5ou5qy5rw201ss5tw201ws}201s{201ss}201t{ckw4lwcmwcnwcowcpwclw4wu201ts}2k{201ts}2w{4qs5kw5os5qx5ru17sx5tx}2x{17sw5tw5ou5qu}2y{4qs5kw5os5qx5ru17sx5tx}'fof'-6o7t{ckuclucmucnucoucpu4lu5os5rs}3u{17su5tu5qs}3v{17su5tu5qs}7p{17sw5tw5qs}ck{4qs5ku17sw5ou5qy5rw201ss5tw201ws}4l{4qs5ku17sw5ou5qy5rw201ss5tw201ws}cm{4qs5ku17sw5ou5qy5rw201ss5tw201ws}cn{4qs5ku17sw5ou5qy5rw201ss5tw201ws}co{4qs5ku17sw5ou5qy5rw201ss5tw201ws}cp{4qs5ku17sw5ou5qy5rw201ss5tw201ws}6l{17su5tu5os5qw5rs}17s{2ktclvcmvcnvcovcpv4lv4wuckv}5o{ckwclwcmwcnwcowcpw4lw4wu}5q{ckyclycmycnycoycpy4ly4wu5ms}5r{cktcltcmtcntcotcpt4lt4ws}5t{2ktclvcmvcnvcovcpv4lv4wuckv}7q{cksclscmscnscoscps4ls}6p{17su5tu5qw5rs}ek{5qs5rs}el{17su5tu5os5qw5rs}em{17su5tu5os5qs5rs}en{17su5qs5rs}eo{5qs5rs}ep{17su5tu5os5qw5rs}es{5qs}et{17su5tu5qw5rs}eu{17su5tu5qs5rs}ev{5qs}6z{17sv5tv5os5qx5rs}fm{5os5qt5rs}fn{17sv5tv5os5qx5rs}fo{17sv5tv5os5qx5rs}fp{5os5qt5rs}fq{5os5qt5rs}7r{ckuclucmucnucoucpu4lu5os}fs{17sv5tv5os5qx5rs}ft{17ss5ts5qs}fu{17sw5tw5qs}fv{17sw5tw5qs}fw{17ss5ts5qs}fz{ckuclucmucnucoucpu4lu5os5rs}}}"),
"Helvetica-Oblique": uncompress("{'widths'{k3p2q4mcx1w201n3r201o6o201s1q201t1q201u1q201w2l201x2l201y2l2k1w2l1w202m2n2n3r2o3r2p5t202q6o2r1n2s2l2t2l2u2r2v3u2w1w2x2l2y1w2z1w3k3r3l3r3m3r3n3r3o3r3p3r3q3r3r3r3s3r203t2l203u2l3v1w3w3u3x3u3y3u3z3r4k6p4l4m4m4m4n4s4o4s4p4m4q3x4r4y4s4s4t1w4u3m4v4m4w3r4x5n4y4s4z4y5k4m5l4y5m4s5n4m5o3x5p4s5q4m5r5y5s4m5t4m5u3x5v1w5w1w5x1w5y2z5z3r6k2l6l3r6m3r6n3m6o3r6p3r6q1w6r3r6s3r6t1q6u1q6v3m6w1q6x5n6y3r6z3r7k3r7l3r7m2l7n3m7o1w7p3r7q3m7r4s7s3m7t3m7u3m7v2l7w1u7x2l7y3u202l3rcl4mal2lam3ran3rao3rap3rar3ras2lat4tau2pav3raw3uay4taz2lbk2sbl3u'fof'6obo2lbp3rbr1wbs2lbu2obv3rbz3xck4m202k3rcm4mcn4mco4mcp4mcq6ocr4scs4mct4mcu4mcv4mcw1w2m2ncy1wcz1wdl4sdm4ydn4ydo4ydp4ydq4yds4ydt4sdu4sdv4sdw4sdz3xek3rel3rem3ren3reo3rep3req5ter3mes3ret3reu3rev3rew1wex1wey1wez1wfl3rfm3rfn3rfo3rfp3rfq3rfr3ufs3xft3rfu3rfv3rfw3rfz3m203k6o212m6o2dw2l2cq2l3t3r3u1w17s4m19m3r}'kerning'{5q{4wv}cl{4qs5kw5ow5qs17sv5tv}201t{2wu4w1k2yu}201x{2wu4wy2yu}17s{2ktclucmucnu4otcpu4lu4wycoucku}2w{7qs4qz5k1m17sy5ow5qx5rsfsu5ty7tufzu}2x{17sy5ty5oy5qs}2y{7qs4qz5k1m17sy5ow5qx5rsfsu5ty7tufzu}'fof'-6o7p{17sv5tv5ow}ck{4qs5kw5ow5qs17sv5tv}4l{4qs5kw5ow5qs17sv5tv}cm{4qs5kw5ow5qs17sv5tv}cn{4qs5kw5ow5qs17sv5tv}co{4qs5kw5ow5qs17sv5tv}cp{4qs5kw5ow5qs17sv5tv}6l{17sy5ty5ow}do{17st5tt}4z{17st5tt}7s{fst}dm{17st5tt}dn{17st5tt}5o{ckwclwcmwcnwcowcpw4lw4wv}dp{17st5tt}dq{17st5tt}7t{5ow}ds{17st5tt}5t{2ktclucmucnu4otcpu4lu4wycoucku}fu{17sv5tv5ow}6p{17sy5ty5ow5qs}ek{17sy5ty5ow}el{17sy5ty5ow}em{17sy5ty5ow}en{5ty}eo{17sy5ty5ow}ep{17sy5ty5ow}es{17sy5ty5qs}et{17sy5ty5ow5qs}eu{17sy5ty5ow5qs}ev{17sy5ty5ow5qs}6z{17sy5ty5ow5qs}fm{17sy5ty5ow5qs}fn{17sy5ty5ow5qs}fo{17sy5ty5ow5qs}fp{17sy5ty5qs}fq{17sy5ty5ow5qs}7r{5ow}fs{17sy5ty5ow5qs}ft{17sv5tv5ow}7m{5ow}fv{17sv5tv5ow}fw{17sv5tv5ow}}}")
}
};
/*
This event handler is fired when a new jsPDF object is initialized
This event handler appends metrics data to standard fonts within
that jsPDF instance. The metrics are mapped over Unicode character
codes, NOT CIDs or other codes matching the StandardEncoding table of the
standard PDF fonts.
Future:
Also included is the encoding maping table, converting Unicode (UCS-2, UTF-16)
char codes to StandardEncoding character codes. The encoding table is to be used
somewhere around "pdfEscape" call.
*/
API.events.push(["addFont", function (data) {
var font = data.font;
var metrics,
unicode_section,
encoding = "Unicode",
encodingBlock;
metrics = fontMetrics[encoding][font.postScriptName];
if (metrics) {
if (font.metadata[encoding]) {
unicode_section = font.metadata[encoding];
} else {
unicode_section = font.metadata[encoding] = {};
}
unicode_section.widths = metrics.widths;
unicode_section.kerning = metrics.kerning;
}
encodingBlock = encodings[encoding][font.postScriptName];
if (encodingBlock) {
if (font.metadata[encoding]) {
unicode_section = font.metadata[encoding];
} else {
unicode_section = font.metadata[encoding] = {};
}
unicode_section.encoding = encodingBlock;
if (encodingBlock.codePages && encodingBlock.codePages.length) {
font.encoding = encodingBlock.codePages[0];
}
}
}]); // end of adding event handler
})(jsPDF.API);
/**
* @license
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* @name ttfsupport
* @module
*/
(function (jsPDF, global) {
jsPDF.API.events.push(["addFont", function (data) {
var font = data.font;
var instance = data.instance;
if (typeof instance !== "undefined" && instance.existsFileInVFS(font.postScriptName)) {
var file = instance.getFileFromVFS(font.postScriptName);
if (typeof file !== "string") {
throw new Error("Font is not stored as string-data in vFS, import fonts or remove declaration doc.addFont('" + font.postScriptName + "').");
}
font.metadata = jsPDF.API.TTFFont.open(font.postScriptName, font.fontName, file, font.encoding);
font.metadata.Unicode = font.metadata.Unicode || {
encoding: {},
kerning: {},
widths: []
};
font.metadata.glyIdsUsed = [0];
} else if (font.isStandardFont === false) {
throw new Error("Font does not exist in vFS, import fonts or remove declaration doc.addFont('" + font.postScriptName + "').");
}
}]); // end of adding event handler
})(jsPDF, typeof self !== "undefined" && self || typeof global !== "undefined" && global || typeof window !== "undefined" && window || Function("return this")());
/** @license
* Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
*
*
* ====================================================================
*/
/**
* jsPDF SVG plugin
*
* @name svg
* @module
*/
(function (jsPDFAPI) {
/**
* Parses SVG XML and converts only some of the SVG elements into
* PDF elements.
*
* Supports:
* paths
*
* @name addSvg
* @public
* @function
* @param {string} SVG-Data as Text
* @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {number} width of SVG (in units declared at inception of PDF document)
* @param {number} height of SVG (in units declared at inception of PDF document)
* @returns {Object} jsPDF-instance
*/
jsPDFAPI.addSvg = function (svgtext, x, y, w, h) {
// 'this' is _jsPDF object returned when jsPDF is inited (new jsPDF())
var undef;
if (x === undef || y === undef) {
throw new Error("addSVG needs values for 'x' and 'y'");
}
function InjectCSS(cssbody, document) {
var styletag = document.createElement("style");
styletag.type = "text/css";
if (styletag.styleSheet) {
// ie
styletag.styleSheet.cssText = cssbody;
} else {
// others
styletag.appendChild(document.createTextNode(cssbody));
}
document.getElementsByTagName("head")[0].appendChild(styletag);
}
function createWorkerNode(document) {
var frameID = "childframe",
// Date.now().toString() + '_' + (Math.random() * 100).toString()
frame = document.createElement("iframe");
InjectCSS(".jsPDF_sillysvg_iframe {display:none;position:absolute;}", document);
frame.name = frameID;
frame.setAttribute("width", 0);
frame.setAttribute("height", 0);
frame.setAttribute("frameborder", "0");
frame.setAttribute("scrolling", "no");
frame.setAttribute("seamless", "seamless");
frame.setAttribute("class", "jsPDF_sillysvg_iframe");
document.body.appendChild(frame);
return frame;
}
function attachSVGToWorkerNode(svgtext, frame) {
var framedoc = (frame.contentWindow || frame.contentDocument).document;
framedoc.write(svgtext);
framedoc.close();
return framedoc.getElementsByTagName("svg")[0];
}
function convertPathToPDFLinesArgs(path) {
// - starting coordinate pair
// - array of arrays of vector shifts (2-len for line, 6 len for bezier)
// - scale array [horizontal, vertical] ratios
// - style (stroke, fill, both)
var x = parseFloat(path[1]),
y = parseFloat(path[2]),
vectors = [],
position = 3,
len = path.length;
while (position < len) {
if (path[position] === "c") {
vectors.push([parseFloat(path[position + 1]), parseFloat(path[position + 2]), parseFloat(path[position + 3]), parseFloat(path[position + 4]), parseFloat(path[position + 5]), parseFloat(path[position + 6])]);
position += 7;
} else if (path[position] === "l") {
vectors.push([parseFloat(path[position + 1]), parseFloat(path[position + 2])]);
position += 3;
} else {
position += 1;
}
}
return [x, y, vectors];
}
var workernode = createWorkerNode(document),
svgnode = attachSVGToWorkerNode(svgtext, workernode),
scale = [1, 1],
svgw = parseFloat(svgnode.getAttribute("width")),
svgh = parseFloat(svgnode.getAttribute("height"));
if (svgw && svgh) {
// setting both w and h makes image stretch to size.
// this may distort the image, but fits your demanded size
if (w && h) {
scale = [w / svgw, h / svgh];
} // if only one is set, that value is set as max and SVG
// is scaled proportionately.
else if (w) {
scale = [w / svgw, w / svgw];
} else if (h) {
scale = [h / svgh, h / svgh];
}
}
var i,
l,
tmp,
linesargs,
items = svgnode.childNodes;
for (i = 0, l = items.length; i < l; i++) {
tmp = items[i];
if (tmp.tagName && tmp.tagName.toUpperCase() === "PATH") {
linesargs = convertPathToPDFLinesArgs(tmp.getAttribute("d").split(" ")); // path start x coordinate
linesargs[0] = linesargs[0] * scale[0] + x; // where x is upper left X of image
// path start y coordinate
linesargs[1] = linesargs[1] * scale[1] + y; // where y is upper left Y of image
// the rest of lines are vectors. these will adjust with scale value auto.
this.lines.call(this, linesargs[2], // lines
linesargs[0], // starting x
linesargs[1], // starting y
scale);
}
} // clean up
// workernode.parentNode.removeChild(workernode)
return this;
}; //fallback
jsPDFAPI.addSVG = jsPDFAPI.addSvg;
/**
* Parses SVG XML and saves it as image into the PDF.
*
* Depends on canvas-element and canvg
*
* @name addSvgAsImage
* @public
* @function
* @param {string} SVG-Data as Text
* @param {number} x Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param {number} y Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param {number} width of SVG-Image (in units declared at inception of PDF document)
* @param {number} height of SVG-Image (in units declared at inception of PDF document)
* @param {string} alias of SVG-Image (if used multiple times)
* @param {string} compression of the generated JPEG, can have the values 'NONE', 'FAST', 'MEDIUM' and 'SLOW'
* @param {number} rotation of the image in degrees (0-359)
*
* @returns jsPDF jsPDF-instance
*/
jsPDFAPI.addSvgAsImage = function (svg, x, y, w, h, alias, compression, rotation) {
if (isNaN(x) || isNaN(y)) {
console.error("jsPDF.addSvgAsImage: Invalid coordinates", arguments);
throw new Error("Invalid coordinates passed to jsPDF.addSvgAsImage");
}
if (isNaN(w) || isNaN(h)) {
console.error("jsPDF.addSvgAsImage: Invalid measurements", arguments);
throw new Error("Invalid measurements (width and/or height) passed to jsPDF.addSvgAsImage");
}
var canvas = document.createElement("canvas");
canvas.width = w;
canvas.height = h;
var ctx = canvas.getContext("2d");
ctx.fillStyle = "#fff"; /// set white fill style
ctx.fillRect(0, 0, canvas.width, canvas.height); //load a svg snippet in the canvas with id = 'drawingArea'
canvg(canvas, svg, {
ignoreMouse: true,
ignoreAnimation: true,
ignoreDimensions: true,
ignoreClear: true
});
this.addImage(canvas.toDataURL("image/jpeg", 1.0), x, y, w, h, compression, rotation);
return this;
};
})(jsPDF.API);
/**
* @license
* ====================================================================
* Copyright (c) 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br
*
*
* ====================================================================
*/
/**
* jsPDF total_pages plugin
* @name total_pages
* @module
*/
(function (jsPDFAPI) {
/**
* @name putTotalPages
* @function
* @param {string} pageExpression Regular Expression
* @returns {jsPDF} jsPDF-instance
*/
jsPDFAPI.putTotalPages = function (pageExpression) {
var replaceExpression = new RegExp(pageExpression, "g");
for (var n = 1; n <= this.internal.getNumberOfPages(); n++) {
for (var i = 0; i < this.internal.pages[n].length; i++) {
this.internal.pages[n][i] = this.internal.pages[n][i].replace(replaceExpression, this.internal.getNumberOfPages());
}
}
return this;
};
})(jsPDF.API);
/**
* jsPDF viewerPreferences Plugin
* @author Aras Abbasi (github.com/arasabbasi)
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* Adds the ability to set ViewerPreferences and by thus
* controlling the way the document is to be presented on the
* screen or in print.
* @name viewerpreferences
* @module
*/
(function (jsPDFAPI) {
/**
* Set the ViewerPreferences of the generated PDF
*
* @name viewerPreferences
* @function
* @public
* @param {Object} options Array with the ViewerPreferences<br />
* Example: doc.viewerPreferences({"FitWindow":true});<br />
* <br />
* You can set following preferences:<br />
* <br/>
* <b>HideToolbar</b> <i>(boolean)</i><br />
* Default value: false<br />
* <br />
* <b>HideMenubar</b> <i>(boolean)</i><br />
* Default value: false.<br />
* <br />
* <b>HideWindowUI</b> <i>(boolean)</i><br />
* Default value: false.<br />
* <br />
* <b>FitWindow</b> <i>(boolean)</i><br />
* Default value: false.<br />
* <br />
* <b>CenterWindow</b> <i>(boolean)</i><br />
* Default value: false<br />
* <br />
* <b>DisplayDocTitle</b> <i>(boolean)</i><br />
* Default value: false.<br />
* <br />
* <b>NonFullScreenPageMode</b> <i>(string)</i><br />
* Possible values: UseNone, UseOutlines, UseThumbs, UseOC<br />
* Default value: UseNone<br/>
* <br />
* <b>Direction</b> <i>(string)</i><br />
* Possible values: L2R, R2L<br />
* Default value: L2R.<br />
* <br />
* <b>ViewArea</b> <i>(string)</i><br />
* Possible values: MediaBox, CropBox, TrimBox, BleedBox, ArtBox<br />
* Default value: CropBox.<br />
* <br />
* <b>ViewClip</b> <i>(string)</i><br />
* Possible values: MediaBox, CropBox, TrimBox, BleedBox, ArtBox<br />
* Default value: CropBox<br />
* <br />
* <b>PrintArea</b> <i>(string)</i><br />
* Possible values: MediaBox, CropBox, TrimBox, BleedBox, ArtBox<br />
* Default value: CropBox<br />
* <br />
* <b>PrintClip</b> <i>(string)</i><br />
* Possible values: MediaBox, CropBox, TrimBox, BleedBox, ArtBox<br />
* Default value: CropBox.<br />
* <br />
* <b>PrintScaling</b> <i>(string)</i><br />
* Possible values: AppDefault, None<br />
* Default value: AppDefault.<br />
* <br />
* <b>Duplex</b> <i>(string)</i><br />
* Possible values: Simplex, DuplexFlipLongEdge, DuplexFlipShortEdge
* Default value: none<br />
* <br />
* <b>PickTrayByPDFSize</b> <i>(boolean)</i><br />
* Default value: false<br />
* <br />
* <b>PrintPageRange</b> <i>(Array)</i><br />
* Example: [[1,5], [7,9]]<br />
* Default value: as defined by PDF viewer application<br />
* <br />
* <b>NumCopies</b> <i>(Number)</i><br />
* Possible values: 1, 2, 3, 4, 5<br />
* Default value: 1<br />
* <br />
* For more information see the PDF Reference, sixth edition on Page 577
* @param {boolean} doReset True to reset the settings
* @function
* @returns jsPDF jsPDF-instance
* @example
* var doc = new jsPDF()
* doc.text('This is a test', 10, 10)
* doc.viewerPreferences({'FitWindow': true}, true)
* doc.save("viewerPreferences.pdf")
*
* // Example printing 10 copies, using cropbox, and hiding UI.
* doc.viewerPreferences({
* 'HideWindowUI': true,
* 'PrintArea': 'CropBox',
* 'NumCopies': 10
* })
*/
jsPDFAPI.viewerPreferences = function (options, doReset) {
options = options || {};
doReset = doReset || false;
var configuration;
var configurationTemplate = {
HideToolbar: {
defaultValue: false,
value: false,
type: "boolean",
explicitSet: false,
valueSet: [true, false],
pdfVersion: 1.3
},
HideMenubar: {
defaultValue: false,
value: false,
type: "boolean",
explicitSet: false,
valueSet: [true, false],
pdfVersion: 1.3
},
HideWindowUI: {
defaultValue: false,
value: false,
type: "boolean",
explicitSet: false,
valueSet: [true, false],
pdfVersion: 1.3
},
FitWindow: {
defaultValue: false,
value: false,
type: "boolean",
explicitSet: false,
valueSet: [true, false],
pdfVersion: 1.3
},
CenterWindow: {
defaultValue: false,
value: false,
type: "boolean",
explicitSet: false,
valueSet: [true, false],
pdfVersion: 1.3
},
DisplayDocTitle: {
defaultValue: false,
value: false,
type: "boolean",
explicitSet: false,
valueSet: [true, false],
pdfVersion: 1.4
},
NonFullScreenPageMode: {
defaultValue: "UseNone",
value: "UseNone",
type: "name",
explicitSet: false,
valueSet: ["UseNone", "UseOutlines", "UseThumbs", "UseOC"],
pdfVersion: 1.3
},
Direction: {
defaultValue: "L2R",
value: "L2R",
type: "name",
explicitSet: false,
valueSet: ["L2R", "R2L"],
pdfVersion: 1.3
},
ViewArea: {
defaultValue: "CropBox",
value: "CropBox",
type: "name",
explicitSet: false,
valueSet: ["MediaBox", "CropBox", "TrimBox", "BleedBox", "ArtBox"],
pdfVersion: 1.4
},
ViewClip: {
defaultValue: "CropBox",
value: "CropBox",
type: "name",
explicitSet: false,
valueSet: ["MediaBox", "CropBox", "TrimBox", "BleedBox", "ArtBox"],
pdfVersion: 1.4
},
PrintArea: {
defaultValue: "CropBox",
value: "CropBox",
type: "name",
explicitSet: false,
valueSet: ["MediaBox", "CropBox", "TrimBox", "BleedBox", "ArtBox"],
pdfVersion: 1.4
},
PrintClip: {
defaultValue: "CropBox",
value: "CropBox",
type: "name",
explicitSet: false,
valueSet: ["MediaBox", "CropBox", "TrimBox", "BleedBox", "ArtBox"],
pdfVersion: 1.4
},
PrintScaling: {
defaultValue: "AppDefault",
value: "AppDefault",
type: "name",
explicitSet: false,
valueSet: ["AppDefault", "None"],
pdfVersion: 1.6
},
Duplex: {
defaultValue: "",
value: "none",
type: "name",
explicitSet: false,
valueSet: ["Simplex", "DuplexFlipShortEdge", "DuplexFlipLongEdge", "none"],
pdfVersion: 1.7
},
PickTrayByPDFSize: {
defaultValue: false,
value: false,
type: "boolean",
explicitSet: false,
valueSet: [true, false],
pdfVersion: 1.7
},
PrintPageRange: {
defaultValue: "",
value: "",
type: "array",
explicitSet: false,
valueSet: null,
pdfVersion: 1.7
},
NumCopies: {
defaultValue: 1,
value: 1,
type: "integer",
explicitSet: false,
valueSet: null,
pdfVersion: 1.7
}
};
var configurationKeys = Object.keys(configurationTemplate);
var rangeArray = [];
var i = 0;
var j = 0;
var k = 0;
var isValid = true;
var method;
var value;
function arrayContainsElement(array, element) {
var iterator;
var result = false;
for (iterator = 0; iterator < array.length; iterator += 1) {
if (array[iterator] === element) {
result = true;
}
}
return result;
}
if (this.internal.viewerpreferences === undefined) {
this.internal.viewerpreferences = {};
this.internal.viewerpreferences.configuration = JSON.parse(JSON.stringify(configurationTemplate));
this.internal.viewerpreferences.isSubscribed = false;
}
configuration = this.internal.viewerpreferences.configuration;
if (options === "reset" || doReset === true) {
var len = configurationKeys.length;
for (k = 0; k < len; k += 1) {
configuration[configurationKeys[k]].value = configuration[configurationKeys[k]].defaultValue;
configuration[configurationKeys[k]].explicitSet = false;
}
}
if (_typeof(options) === "object") {
for (method in options) {
value = options[method];
if (arrayContainsElement(configurationKeys, method) && value !== undefined) {
if (configuration[method].type === "boolean" && typeof value === "boolean") {
configuration[method].value = value;
} else if (configuration[method].type === "name" && arrayContainsElement(configuration[method].valueSet, value)) {
configuration[method].value = value;
} else if (configuration[method].type === "integer" && Number.isInteger(value)) {
configuration[method].value = value;
} else if (configuration[method].type === "array") {
for (i = 0; i < value.length; i += 1) {
isValid = true;
if (value[i].length === 1 && typeof value[i][0] === "number") {
rangeArray.push(String(value[i]));
} else if (value[i].length > 1) {
for (j = 0; j < value[i].length; j += 1) {
if (typeof value[i][j] !== "number") {
isValid = false;
}
}
if (isValid === true) {
rangeArray.push(String(value[i].join("-")));
}
}
}
configuration[method].value = String(rangeArray);
} else {
configuration[method].value = configuration[method].defaultValue;
}
configuration[method].explicitSet = true;
}
}
}
if (this.internal.viewerpreferences.isSubscribed === false) {
this.internal.events.subscribe("putCatalog", function () {
var pdfDict = [];
var vPref;
for (vPref in configuration) {
if (configuration[vPref].explicitSet === true) {
if (configuration[vPref].type === "name") {
pdfDict.push("/" + vPref + " /" + configuration[vPref].value);
} else {
pdfDict.push("/" + vPref + " " + configuration[vPref].value);
}
}
}
if (pdfDict.length !== 0) {
this.internal.write("/ViewerPreferences\n<<\n" + pdfDict.join("\n") + "\n>>");
}
});
this.internal.viewerpreferences.isSubscribed = true;
}
this.internal.viewerpreferences.configuration = configuration;
return this;
};
})(jsPDF.API);
/** ====================================================================
* jsPDF XMP metadata plugin
* Copyright (c) 2016 Jussi Utunen, u-jussi@suomi24.fi
*
*
* ====================================================================
*/
/*global jsPDF */
/**
* @name xmp_metadata
* @module
*/
(function (jsPDFAPI) {
var xmpmetadata = "";
var xmpnamespaceuri = "";
var metadata_object_number = "";
/**
* Adds XMP formatted metadata to PDF
*
* @name addMetadata
* @function
* @param {String} metadata The actual metadata to be added. The metadata shall be stored as XMP simple value. Note that if the metadata string contains XML markup characters "<", ">" or "&", those characters should be written using XML entities.
* @param {String} namespaceuri Sets the namespace URI for the metadata. Last character should be slash or hash.
* @returns {jsPDF} jsPDF-instance
*/
jsPDFAPI.addMetadata = function (metadata, namespaceuri) {
xmpnamespaceuri = namespaceuri || "http://jspdf.default.namespaceuri/"; //The namespace URI for an XMP name shall not be empty
xmpmetadata = metadata;
this.internal.events.subscribe("postPutResources", function () {
if (!xmpmetadata) {
metadata_object_number = "";
} else {
var xmpmeta_beginning = '<x:xmpmeta xmlns:x="adobe:ns:meta/">';
var rdf_beginning = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:jspdf="' + xmpnamespaceuri + '"><jspdf:metadata>';
var rdf_ending = "</jspdf:metadata></rdf:Description></rdf:RDF>";
var xmpmeta_ending = "</x:xmpmeta>";
var utf8_xmpmeta_beginning = unescape(encodeURIComponent(xmpmeta_beginning));
var utf8_rdf_beginning = unescape(encodeURIComponent(rdf_beginning));
var utf8_metadata = unescape(encodeURIComponent(xmpmetadata));
var utf8_rdf_ending = unescape(encodeURIComponent(rdf_ending));
var utf8_xmpmeta_ending = unescape(encodeURIComponent(xmpmeta_ending));
var total_len = utf8_rdf_beginning.length + utf8_metadata.length + utf8_rdf_ending.length + utf8_xmpmeta_beginning.length + utf8_xmpmeta_ending.length;
metadata_object_number = this.internal.newObject();
this.internal.write("<< /Type /Metadata /Subtype /XML /Length " + total_len + " >>");
this.internal.write("stream");
this.internal.write(utf8_xmpmeta_beginning + utf8_rdf_beginning + utf8_metadata + utf8_rdf_ending + utf8_xmpmeta_ending);
this.internal.write("endstream");
this.internal.write("endobj");
}
});
this.internal.events.subscribe("putCatalog", function () {
if (metadata_object_number) {
this.internal.write("/Metadata " + metadata_object_number + " 0 R");
}
});
return this;
};
})(jsPDF.API);
/**
* @name utf8
* @module
*/
(function (jsPDF, global) {
var jsPDFAPI = jsPDF.API;
/**************************************************/
/* function : toHex */
/* comment : Replace str with a hex string. */
/**************************************************/
function toHex(str) {
var hex = "";
for (var i = 0; i < str.length; i++) {
hex += "" + str.charCodeAt(i).toString(16);
}
return hex;
}
/***************************************************************************************************/
/* function : pdfEscape16 */
/* comment : The character id of a 2-byte string is converted to a hexadecimal number by obtaining */
/* the corresponding glyph id and width, and then adding padding to the string. */
/***************************************************************************************************/
var pdfEscape16 = jsPDFAPI.pdfEscape16 = function (text, font) {
var widths = font.metadata.Unicode.widths;
var padz = ["", "0", "00", "000", "0000"];
var ar = [""];
for (var i = 0, l = text.length, t; i < l; ++i) {
t = font.metadata.characterToGlyph(text.charCodeAt(i));
font.metadata.glyIdsUsed.push(t);
font.metadata.toUnicode[t] = text.charCodeAt(i);
if (widths.indexOf(t) == -1) {
widths.push(t);
widths.push([parseInt(font.metadata.widthOfGlyph(t), 10)]);
}
if (t == "0") {
//Spaces are not allowed in cmap.
return ar.join("");
} else {
t = t.toString(16);
ar.push(padz[4 - t.length], t);
}
}
return ar.join("");
};
var toUnicodeCmap = function toUnicodeCmap(map) {
var code, codes, range, unicode, unicodeMap, _i, _len;
unicodeMap = "/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CIDSystemInfo <<\n /Registry (Adobe)\n /Ordering (UCS)\n /Supplement 0\n>> def\n/CMapName /Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange\n<0000><ffff>\nendcodespacerange";
codes = Object.keys(map).sort(function (a, b) {
return a - b;
});
range = [];
for (_i = 0, _len = codes.length; _i < _len; _i++) {
code = codes[_i];
if (range.length >= 100) {
unicodeMap += "\n" + range.length + " beginbfchar\n" + range.join("\n") + "\nendbfchar";
range = [];
}
unicode = ("0000" + map[code].toString(16)).slice(-4);
code = ("0000" + (+code).toString(16)).slice(-4);
range.push("<" + code + "><" + unicode + ">");
}
if (range.length) {
unicodeMap += "\n" + range.length + " beginbfchar\n" + range.join("\n") + "\nendbfchar\n";
}
unicodeMap += "endcmap\nCMapName currentdict /CMap defineresource pop\nend\nend";
return unicodeMap;
};
var identityHFunction = function identityHFunction(font, out, newObject, putStream) {
if (font.metadata instanceof jsPDF.API.TTFFont && font.encoding === "Identity-H") {
//Tag with Identity-H
var widths = font.metadata.Unicode.widths;
var data = font.metadata.subset.encode(font.metadata.glyIdsUsed, 1);
var pdfOutput = data;
var pdfOutput2 = "";
for (var i = 0; i < pdfOutput.length; i++) {
pdfOutput2 += String.fromCharCode(pdfOutput[i]);
}
var fontTable = newObject();
out("<<");
out("/Length " + pdfOutput2.length);
out("/Length1 " + pdfOutput2.length);
out(">>");
putStream(pdfOutput2);
out("endobj");
var cmap = newObject();
var cmapData = toUnicodeCmap(font.metadata.toUnicode);
out("<<");
out("/Length " + cmapData.length);
out("/Length1 " + cmapData.length);
out(">>");
putStream(cmapData);
out("endobj");
var fontDescriptor = newObject();
out("<<");
out("/Type /FontDescriptor");
out("/FontName /" + font.fontName);
out("/FontFile2 " + fontTable + " 0 R");
out("/FontBBox " + jsPDF.API.PDFObject.convert(font.metadata.bbox));
out("/Flags " + font.metadata.flags);
out("/StemV " + font.metadata.stemV);
out("/ItalicAngle " + font.metadata.italicAngle);
out("/Ascent " + font.metadata.ascender);
out("/Descent " + font.metadata.decender);
out("/CapHeight " + font.metadata.capHeight);
out(">>");
out("endobj");
var DescendantFont = newObject();
out("<<");
out("/Type /Font");
out("/BaseFont /" + font.fontName);
out("/FontDescriptor " + fontDescriptor + " 0 R");
out("/W " + jsPDF.API.PDFObject.convert(widths));
out("/CIDToGIDMap /Identity");
out("/DW 1000");
out("/Subtype /CIDFontType2");
out("/CIDSystemInfo");
out("<<");
out("/Supplement 0");
out("/Registry (Adobe)");
out("/Ordering (" + font.encoding + ")");
out(">>");
out(">>");
out("endobj");
font.objectNumber = newObject();
out("<<");
out("/Type /Font");
out("/Subtype /Type0");
out("/ToUnicode " + cmap + " 0 R");
out("/BaseFont /" + font.fontName);
out("/Encoding /" + font.encoding);
out("/DescendantFonts [" + DescendantFont + " 0 R]");
out(">>");
out("endobj");
font.isAlreadyPutted = true;
}
};
jsPDFAPI.events.push(["putFont", function (args) {
identityHFunction(args.font, args.out, args.newObject, args.putStream);
}]);
var winAnsiEncodingFunction = function winAnsiEncodingFunction(font, out, newObject, putStream) {
if (font.metadata instanceof jsPDF.API.TTFFont && font.encoding === "WinAnsiEncoding") {
//Tag with WinAnsi encoding
var widths = font.metadata.Unicode.widths;
var data = font.metadata.rawData;
var pdfOutput = data;
var pdfOutput2 = "";
for (var i = 0; i < pdfOutput.length; i++) {
pdfOutput2 += String.fromCharCode(pdfOutput[i]);
}
var fontTable = newObject();
putStream({
data: pdfOutput2,
addLength1: true
});
out("endobj");
var cmap = newObject();
var cmapData = toUnicodeCmap(font.metadata.toUnicode);
putStream({
data: cmapData,
addLength1: true
});
out("endobj");
var fontDescriptor = newObject();
out("<<");
out("/Descent " + font.metadata.decender);
out("/CapHeight " + font.metadata.capHeight);
out("/StemV " + font.metadata.stemV);
out("/Type /FontDescriptor");
out("/FontFile2 " + fontTable + " 0 R");
out("/Flags 96");
out("/FontBBox " + jsPDF.API.PDFObject.convert(font.metadata.bbox));
out("/FontName /" + font.fontName);
out("/ItalicAngle " + font.metadata.italicAngle);
out("/Ascent " + font.metadata.ascender);
out(">>");
out("endobj");
font.objectNumber = newObject();
for (var i = 0; i < font.metadata.hmtx.widths.length; i++) {
font.metadata.hmtx.widths[i] = parseInt(font.metadata.hmtx.widths[i] * (1000 / font.metadata.head.unitsPerEm)); //Change the width of Em units to Point units.
}
out("<</Subtype/TrueType/Type/Font/ToUnicode " + cmap + " 0 R/BaseFont/" + font.fontName + "/FontDescriptor " + fontDescriptor + " 0 R" + "/Encoding/" + font.encoding + " /FirstChar 29 /LastChar 255 /Widths " + jsPDF.API.PDFObject.convert(font.metadata.hmtx.widths) + ">>");
out("endobj");
font.isAlreadyPutted = true;
}
};
jsPDFAPI.events.push(["putFont", function (args) {
winAnsiEncodingFunction(args.font, args.out, args.newObject, args.putStream);
}]);
var utf8TextFunction = function utf8TextFunction(args) {
var text = args.text || "";
var x = args.x;
var y = args.y;
var options = args.options || {};
var mutex = args.mutex || {};
var pdfEscape = mutex.pdfEscape;
var activeFontKey = mutex.activeFontKey;
var fonts = mutex.fonts;
var key,
fontSize = mutex.activeFontSize;
var str = "",
s = 0,
cmapConfirm;
var strText = "";
var key = activeFontKey;
var encoding = fonts[key].encoding;
if (fonts[key].encoding !== "Identity-H") {
return {
text: text,
x: x,
y: y,
options: options,
mutex: mutex
};
}
strText = text;
key = activeFontKey;
if (Object.prototype.toString.call(text) === "[object Array]") {
strText = text[0];
}
for (s = 0; s < strText.length; s += 1) {
if (fonts[key].metadata.hasOwnProperty("cmap")) {
cmapConfirm = fonts[key].metadata.cmap.unicode.codeMap[strText[s].charCodeAt(0)];
/*
if (Object.prototype.toString.call(text) === '[object Array]') {
var i = 0;
// for (i = 0; i < text.length; i += 1) {
if (Object.prototype.toString.call(text[s]) === '[object Array]') {
cmapConfirm = fonts[key].metadata.cmap.unicode.codeMap[strText[s][0].charCodeAt(0)]; //Make sure the cmap has the corresponding glyph id
} else {
}
//}
} else {
cmapConfirm = fonts[key].metadata.cmap.unicode.codeMap[strText[s].charCodeAt(0)]; //Make sure the cmap has the corresponding glyph id
}*/
}
if (!cmapConfirm) {
if (strText[s].charCodeAt(0) < 256 && fonts[key].metadata.hasOwnProperty("Unicode")) {
str += strText[s];
} else {
str += "";
}
} else {
str += strText[s];
}
}
var result = "";
if (parseInt(key.slice(1)) < 14 || encoding === "WinAnsiEncoding") {
//For the default 13 font
result = toHex(pdfEscape(str, key));
} else if (encoding === "Identity-H") {
result = pdfEscape16(str, fonts[key]);
}
mutex.isHex = true;
return {
text: result,
x: x,
y: y,
options: options,
mutex: mutex
};
};
var utf8EscapeFunction = function utf8EscapeFunction(parms) {
var text = parms.text || "",
x = parms.x,
y = parms.y,
options = parms.options,
mutex = parms.mutex;
var lang = options.lang;
var tmpText = [];
var args = {
text: text,
x: x,
y: y,
options: options,
mutex: mutex
};
if (Object.prototype.toString.call(text) === "[object Array]") {
var i = 0;
for (i = 0; i < text.length; i += 1) {
if (Object.prototype.toString.call(text[i]) === "[object Array]") {
if (text[i].length === 3) {
tmpText.push([utf8TextFunction(Object.assign({}, args, {
text: text[i][0]
})).text, text[i][1], text[i][2]]);
} else {
tmpText.push(utf8TextFunction(Object.assign({}, args, {
text: text[i]
})).text);
}
} else {
tmpText.push(utf8TextFunction(Object.assign({}, args, {
text: text[i]
})).text);
}
}
parms.text = tmpText;
} else {
parms.text = utf8TextFunction(Object.assign({}, args, {
text: text
})).text;
}
};
jsPDFAPI.events.push(["postProcessText", utf8EscapeFunction]);
})(jsPDF, typeof self !== "undefined" && self || typeof global !== "undefined" && global || typeof window !== "undefined" && window || Function("return this")());
/**
* jsPDF virtual FileSystem functionality
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* Use the vFS to handle files
*
* @name vFS
* @module
*/
(function (jsPDFAPI) {
var vFS = {};
/**
* Check if the file exists in the vFS
*
* @name existsFileInVFS
* @function
* @param {string} Possible filename in the vFS.
* @returns {boolean}
* @example
* doc.existsFileInVFS("someFile.txt");
*/
jsPDFAPI.existsFileInVFS = function (filename) {
return vFS.hasOwnProperty(filename);
};
/**
* Add a file to the vFS
*
* @name addFileToVFS
* @function
* @param {string} filename The name of the file which should be added.
* @param {string} filecontent The content of the file.
* @returns {jsPDF}
* @example
* doc.addFileToVFS("someFile.txt", "BADFACE1");
*/
jsPDFAPI.addFileToVFS = function (filename, filecontent) {
vFS[filename] = filecontent;
return this;
};
/**
* Get the file from the vFS
*
* @name getFileFromVFS
* @function
* @returns {string} The name of the file which gets requested.
* @example
* doc.getFileFromVFS("someFile.txt");
*/
jsPDFAPI.getFileFromVFS = function (filename) {
if (vFS.hasOwnProperty(filename)) {
return vFS[filename];
}
return null;
};
})(jsPDF.API);
/* Blob.js
* A Blob implementation.
* 2014-07-24
*
* By Eli Grey, http://eligrey.com
* By Devin Samarin, https://github.com/dsamarin
* License: X11/MIT
* See https://github.com/eligrey/Blob.js/blob/master/LICENSE.md
*/
/*global self, unescape */
/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
plusplus: true */
/*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */
(function (view) {
view.URL = view.URL || view.webkitURL;
if (view.Blob && view.URL) {
try {
new Blob();
return;
} catch (e) {}
} // Internally we use a BlobBuilder implementation to base Blob off of
// in order to support older browsers that only have BlobBuilder
var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || function (view) {
var get_class = function (object) {
return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
},
FakeBlobBuilder = function BlobBuilder() {
this.data = [];
},
FakeBlob = function Blob(data, type, encoding) {
this.data = data;
this.size = data.length;
this.type = type;
this.encoding = encoding;
},
FBB_proto = FakeBlobBuilder.prototype,
FB_proto = FakeBlob.prototype,
FileReaderSync = view.FileReaderSync,
FileException = function (type) {
this.code = this[this.name = type];
},
file_ex_codes = ("NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR " + "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR").split(" "),
file_ex_code = file_ex_codes.length,
real_URL = view.URL || view.webkitURL || view,
real_create_object_URL = real_URL.createObjectURL,
real_revoke_object_URL = real_URL.revokeObjectURL,
URL = real_URL,
btoa = view.btoa,
atob = view.atob,
ArrayBuffer = view.ArrayBuffer,
Uint8Array = view.Uint8Array,
origin = /^[\w-]+:\/*\[?[\w\.:-]+\]?(?::[0-9]+)?/;
FakeBlob.fake = FB_proto.fake = true;
while (file_ex_code--) {
FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1;
} // Polyfill URL
if (!real_URL.createObjectURL) {
URL = view.URL = function (uri) {
var uri_info = document.createElementNS("http://www.w3.org/1999/xhtml", "a"),
uri_origin;
uri_info.href = uri;
if (!("origin" in uri_info)) {
if (uri_info.protocol.toLowerCase() === "data:") {
uri_info.origin = null;
} else {
uri_origin = uri.match(origin);
uri_info.origin = uri_origin && uri_origin[1];
}
}
return uri_info;
};
}
URL.createObjectURL = function (blob) {
var type = blob.type,
data_URI_header;
if (type === null) {
type = "application/octet-stream";
}
if (blob instanceof FakeBlob) {
data_URI_header = "data:" + type;
if (blob.encoding === "base64") {
return data_URI_header + ";base64," + blob.data;
} else if (blob.encoding === "URI") {
return data_URI_header + "," + decodeURIComponent(blob.data);
}
if (btoa) {
return data_URI_header + ";base64," + btoa(blob.data);
} else {
return data_URI_header + "," + encodeURIComponent(blob.data);
}
} else if (real_create_object_URL) {
return real_create_object_URL.call(real_URL, blob);
}
};
URL.revokeObjectURL = function (object_URL) {
if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) {
real_revoke_object_URL.call(real_URL, object_URL);
}
};
FBB_proto.append = function (data
/*, endings*/
) {
var bb = this.data; // decode data to a binary string
if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) {
var str = "",
buf = new Uint8Array(data),
i = 0,
buf_len = buf.length;
for (; i < buf_len; i++) {
str += String.fromCharCode(buf[i]);
}
bb.push(str);
} else if (get_class(data) === "Blob" || get_class(data) === "File") {
if (FileReaderSync) {
var fr = new FileReaderSync();
bb.push(fr.readAsBinaryString(data));
} else {
// async FileReader won't work as BlobBuilder is sync
throw new FileException("NOT_READABLE_ERR");
}
} else if (data instanceof FakeBlob) {
if (data.encoding === "base64" && atob) {
bb.push(atob(data.data));
} else if (data.encoding === "URI") {
bb.push(decodeURIComponent(data.data));
} else if (data.encoding === "raw") {
bb.push(data.data);
}
} else {
if (typeof data !== "string") {
data += ""; // convert unsupported types to strings
} // decode UTF-16 to binary string
bb.push(unescape(encodeURIComponent(data)));
}
};
FBB_proto.getBlob = function (type) {
if (!arguments.length) {
type = null;
}
return new FakeBlob(this.data.join(""), type, "raw");
};
FBB_proto.toString = function () {
return "[object BlobBuilder]";
};
FB_proto.slice = function (start, end, type) {
var args = arguments.length;
if (args < 3) {
type = null;
}
return new FakeBlob(this.data.slice(start, args > 1 ? end : this.data.length), type, this.encoding);
};
FB_proto.toString = function () {
return "[object Blob]";
};
FB_proto.close = function () {
this.size = 0;
delete this.data;
};
return FakeBlobBuilder;
}(view);
view.Blob = function (blobParts, options) {
var type = options ? options.type || "" : "";
var builder = new BlobBuilder();
if (blobParts) {
for (var i = 0, len = blobParts.length; i < len; i++) {
if (Uint8Array && blobParts[i] instanceof Uint8Array) {
builder.append(blobParts[i].buffer);
} else {
builder.append(blobParts[i]);
}
}
}
var blob = builder.getBlob(type);
if (!blob.slice && blob.webkitSlice) {
blob.slice = blob.webkitSlice;
}
return blob;
};
var getPrototypeOf = Object.getPrototypeOf || function (object) {
return object.__proto__;
};
view.Blob.prototype = getPrototypeOf(new view.Blob());
})(typeof self !== "undefined" && self || typeof window !== "undefined" && window || window.content || window);
/* FileSaver.js
* A saveAs() FileSaver implementation.
* 1.3.2
* 2016-06-16 18:25:19
*
* By Eli Grey, http://eligrey.com
* License: MIT
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
*/
/*global self */
/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
var saveAs = saveAs || function (view) {
if (typeof view === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
return;
}
var doc = view.document // only get URL when necessary in case Blob.js hasn't overridden it yet
,
get_URL = function () {
return view.URL || view.webkitURL || view;
},
save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a"),
can_use_save_link = "download" in save_link,
click = function (node) {
var event = new MouseEvent("click");
node.dispatchEvent(event);
},
is_safari = /constructor/i.test(view.HTMLElement) || view.safari,
is_chrome_ios = /CriOS\/[\d]+/.test(navigator.userAgent),
throw_outside = function (ex) {
(view.setImmediate || view.setTimeout)(function () {
throw ex;
}, 0);
},
force_saveable_type = "application/octet-stream" // the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to
,
arbitrary_revoke_timeout = 1000 * 40 // in ms
,
revoke = function (file) {
var revoker = function () {
if (typeof file === "string") {
// file is an object URL
get_URL().revokeObjectURL(file);
} else {
// file is a File
file.remove();
}
};
setTimeout(revoker, arbitrary_revoke_timeout);
},
dispatch = function (filesaver, event_types, event) {
event_types = [].concat(event_types);
var i = event_types.length;
while (i--) {
var listener = filesaver["on" + event_types[i]];
if (typeof listener === "function") {
try {
listener.call(filesaver, event || filesaver);
} catch (ex) {
throw_outside(ex);
}
}
}
},
auto_bom = function (blob) {
// prepend BOM for UTF-8 XML and text/* types (including HTML)
// note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
return new Blob([String.fromCharCode(0xFEFF), blob], {
type: blob.type
});
}
return blob;
},
FileSaver = function (blob, name, no_auto_bom) {
if (!no_auto_bom) {
blob = auto_bom(blob);
} // First try a.download, then web filesystem, then object URLs
var filesaver = this,
type = blob.type,
force = type === force_saveable_type,
object_url,
dispatch_all = function () {
dispatch(filesaver, "writestart progress write writeend".split(" "));
} // on any filesys errors revert to saving with object URLs
,
fs_error = function () {
if ((is_chrome_ios || force && is_safari) && view.FileReader) {
// Safari doesn't allow downloading of blob urls
var reader = new FileReader();
reader.onloadend = function () {
var url = is_chrome_ios ? reader.result : reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');
var popup = view.open(url, '_blank');
if (!popup) view.location.href = url;
url = undefined; // release reference before dispatching
filesaver.readyState = filesaver.DONE;
dispatch_all();
};
reader.readAsDataURL(blob);
filesaver.readyState = filesaver.INIT;
return;
} // don't create more object URLs than needed
if (!object_url) {
object_url = get_URL().createObjectURL(blob);
}
if (force) {
view.location.href = object_url;
} else {
var opened = view.open(object_url, "_blank");
if (!opened) {
// Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html
view.location.href = object_url;
}
}
filesaver.readyState = filesaver.DONE;
dispatch_all();
revoke(object_url);
};
filesaver.readyState = filesaver.INIT;
if (can_use_save_link) {
object_url = get_URL().createObjectURL(blob);
setTimeout(function () {
save_link.href = object_url;
save_link.download = name;
click(save_link);
dispatch_all();
revoke(object_url);
filesaver.readyState = filesaver.DONE;
});
return;
}
fs_error();
},
FS_proto = FileSaver.prototype,
saveAs = function (blob, name, no_auto_bom) {
return new FileSaver(blob, name || blob.name || "download", no_auto_bom);
}; // IE 10+ (native saveAs)
if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
return function (blob, name, no_auto_bom) {
name = name || blob.name || "download";
if (!no_auto_bom) {
blob = auto_bom(blob);
}
return navigator.msSaveOrOpenBlob(blob, name);
};
}
FS_proto.abort = function () {};
FS_proto.readyState = FS_proto.INIT = 0;
FS_proto.WRITING = 1;
FS_proto.DONE = 2;
FS_proto.error = FS_proto.onwritestart = FS_proto.onprogress = FS_proto.onwrite = FS_proto.onabort = FS_proto.onerror = FS_proto.onwriteend = null;
return saveAs;
}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || window.content); // `self` is undefined in Firefox for Android content script context
// while `this` is nsIContentFrameMessageManager
// with an attribute `content` that corresponds to the window
if (typeof module !== "undefined" && module.exports) {
module.exports.saveAs = saveAs;
} else if (typeof define !== "undefined" && define !== null && define.amd !== null) {
define("FileSaver.js", function () {
return saveAs;
});
}
// (c) Dean McNamee <dean@gmail.com>, 2013.
//
// https://github.com/deanm/omggif
//
//
//
// omggif is a JavaScript implementation of a GIF 89a encoder and decoder,
// including animation and compression. It does not rely on any specific
// underlying system, so should run in the browser, Node, or Plask.
function GifWriter(buf, width, height, gopts) {
var p = 0;
var gopts = gopts === undefined ? {} : gopts;
var loop_count = gopts.loop === undefined ? null : gopts.loop;
var global_palette = gopts.palette === undefined ? null : gopts.palette;
if (width <= 0 || height <= 0 || width > 65535 || height > 65535) throw "Width/Height invalid.";
function check_palette_and_num_colors(palette) {
var num_colors = palette.length;
if (num_colors < 2 || num_colors > 256 || num_colors & num_colors - 1) throw "Invalid code/color length, must be power of 2 and 2 .. 256.";
return num_colors;
} // - Header.
buf[p++] = 0x47;
buf[p++] = 0x49;
buf[p++] = 0x46; // GIF
buf[p++] = 0x38;
buf[p++] = 0x39;
buf[p++] = 0x61; // 89a
// Handling of Global Color Table (palette) and background index.
var gp_num_colors_pow2 = 0;
var background = 0;
if (global_palette !== null) {
var gp_num_colors = check_palette_and_num_colors(global_palette);
while (gp_num_colors >>= 1) ++gp_num_colors_pow2;
gp_num_colors = 1 << gp_num_colors_pow2;
--gp_num_colors_pow2;
if (gopts.background !== undefined) {
background = gopts.background;
if (background >= gp_num_colors) throw "Background index out of range."; // The GIF spec states that a background index of 0 should be ignored, so
// this is probably a mistake and you really want to set it to another
// slot in the palette. But actually in the end most browsers, etc end
// up ignoring this almost completely (including for dispose background).
if (background === 0) throw "Background index explicitly passed as 0.";
}
} // - Logical Screen Descriptor.
// NOTE(deanm): w/h apparently ignored by implementations, but set anyway.
buf[p++] = width & 0xff;
buf[p++] = width >> 8 & 0xff;
buf[p++] = height & 0xff;
buf[p++] = height >> 8 & 0xff; // NOTE: Indicates 0-bpp original color resolution (unused?).
buf[p++] = (global_palette !== null ? 0x80 : 0) | // Global Color Table Flag.
gp_num_colors_pow2; // NOTE: No sort flag (unused?).
buf[p++] = background; // Background Color Index.
buf[p++] = 0; // Pixel aspect ratio (unused?).
// - Global Color Table
if (global_palette !== null) {
for (var i = 0, il = global_palette.length; i < il; ++i) {
var rgb = global_palette[i];
buf[p++] = rgb >> 16 & 0xff;
buf[p++] = rgb >> 8 & 0xff;
buf[p++] = rgb & 0xff;
}
}
if (loop_count !== null) {
// Netscape block for looping.
if (loop_count < 0 || loop_count > 65535) throw "Loop count invalid."; // Extension code, label, and length.
buf[p++] = 0x21;
buf[p++] = 0xff;
buf[p++] = 0x0b; // NETSCAPE2.0
buf[p++] = 0x4e;
buf[p++] = 0x45;
buf[p++] = 0x54;
buf[p++] = 0x53;
buf[p++] = 0x43;
buf[p++] = 0x41;
buf[p++] = 0x50;
buf[p++] = 0x45;
buf[p++] = 0x32;
buf[p++] = 0x2e;
buf[p++] = 0x30; // Sub-block
buf[p++] = 0x03;
buf[p++] = 0x01;
buf[p++] = loop_count & 0xff;
buf[p++] = loop_count >> 8 & 0xff;
buf[p++] = 0x00; // Terminator.
}
var ended = false;
this.addFrame = function (x, y, w, h, indexed_pixels, opts) {
if (ended === true) {
--p;
ended = false;
} // Un-end.
opts = opts === undefined ? {} : opts; // TODO(deanm): Bounds check x, y. Do they need to be within the virtual
// canvas width/height, I imagine?
if (x < 0 || y < 0 || x > 65535 || y > 65535) throw "x/y invalid.";
if (w <= 0 || h <= 0 || w > 65535 || h > 65535) throw "Width/Height invalid.";
if (indexed_pixels.length < w * h) throw "Not enough pixels for the frame size.";
var using_local_palette = true;
var palette = opts.palette;
if (palette === undefined || palette === null) {
using_local_palette = false;
palette = global_palette;
}
if (palette === undefined || palette === null) throw "Must supply either a local or global palette.";
var num_colors = check_palette_and_num_colors(palette); // Compute the min_code_size (power of 2), destroying num_colors.
var min_code_size = 0;
while (num_colors >>= 1) ++min_code_size;
num_colors = 1 << min_code_size; // Now we can easily get it back.
var delay = opts.delay === undefined ? 0 : opts.delay; // From the spec:
// 0 - No disposal specified. The decoder is
// not required to take any action.
// 1 - Do not dispose. The graphic is to be left
// in place.
// 2 - Restore to background color. The area used by the
// graphic must be restored to the background color.
// 3 - Restore to previous. The decoder is required to
// restore the area overwritten by the graphic with
// what was there prior to rendering the graphic.
// 4-7 - To be defined.
// NOTE(deanm): Dispose background doesn't really work, apparently most
// browsers ignore the background palette index and clear to transparency.
var disposal = opts.disposal === undefined ? 0 : opts.disposal;
if (disposal < 0 || disposal > 3) // 4-7 is reserved.
throw "Disposal out of range.";
var use_transparency = false;
var transparent_index = 0;
if (opts.transparent !== undefined && opts.transparent !== null) {
use_transparency = true;
transparent_index = opts.transparent;
if (transparent_index < 0 || transparent_index >= num_colors) throw "Transparent color index.";
}
if (disposal !== 0 || use_transparency || delay !== 0) {
// - Graphics Control Extension
buf[p++] = 0x21;
buf[p++] = 0xf9; // Extension / Label.
buf[p++] = 4; // Byte size.
buf[p++] = disposal << 2 | (use_transparency === true ? 1 : 0);
buf[p++] = delay & 0xff;
buf[p++] = delay >> 8 & 0xff;
buf[p++] = transparent_index; // Transparent color index.
buf[p++] = 0; // Block Terminator.
} // - Image Descriptor
buf[p++] = 0x2c; // Image Seperator.
buf[p++] = x & 0xff;
buf[p++] = x >> 8 & 0xff; // Left.
buf[p++] = y & 0xff;
buf[p++] = y >> 8 & 0xff; // Top.
buf[p++] = w & 0xff;
buf[p++] = w >> 8 & 0xff;
buf[p++] = h & 0xff;
buf[p++] = h >> 8 & 0xff; // NOTE: No sort flag (unused?).
// TODO(deanm): Support interlace.
buf[p++] = using_local_palette === true ? 0x80 | min_code_size - 1 : 0; // - Local Color Table
if (using_local_palette === true) {
for (var i = 0, il = palette.length; i < il; ++i) {
var rgb = palette[i];
buf[p++] = rgb >> 16 & 0xff;
buf[p++] = rgb >> 8 & 0xff;
buf[p++] = rgb & 0xff;
}
}
p = GifWriterOutputLZWCodeStream(buf, p, min_code_size < 2 ? 2 : min_code_size, indexed_pixels);
};
this.end = function () {
if (ended === false) {
buf[p++] = 0x3b; // Trailer.
ended = true;
}
return p;
};
} // Main compression routine, palette indexes -> LZW code stream.
// |index_stream| must have at least one entry.
function GifWriterOutputLZWCodeStream(buf, p, min_code_size, index_stream) {
buf[p++] = min_code_size;
var cur_subblock = p++; // Pointing at the length field.
var clear_code = 1 << min_code_size;
var code_mask = clear_code - 1;
var eoi_code = clear_code + 1;
var next_code = eoi_code + 1;
var cur_code_size = min_code_size + 1; // Number of bits per code.
var cur_shift = 0; // We have at most 12-bit codes, so we should have to hold a max of 19
// bits here (and then we would write out).
var cur = 0;
function emit_bytes_to_buffer(bit_block_size) {
while (cur_shift >= bit_block_size) {
buf[p++] = cur & 0xff;
cur >>= 8;
cur_shift -= 8;
if (p === cur_subblock + 256) {
// Finished a subblock.
buf[cur_subblock] = 255;
cur_subblock = p++;
}
}
}
function emit_code(c) {
cur |= c << cur_shift;
cur_shift += cur_code_size;
emit_bytes_to_buffer(8);
} // I am not an expert on the topic, and I don't want to write a thesis.
// However, it is good to outline here the basic algorithm and the few data
// structures and optimizations here that make this implementation fast.
// The basic idea behind LZW is to build a table of previously seen runs
// addressed by a short id (herein called output code). All data is
// referenced by a code, which represents one or more values from the
// original input stream. All input bytes can be referenced as the same
// value as an output code. So if you didn't want any compression, you
// could more or less just output the original bytes as codes (there are
// some details to this, but it is the idea). In order to achieve
// compression, values greater then the input range (codes can be up to
// 12-bit while input only 8-bit) represent a sequence of previously seen
// inputs. The decompressor is able to build the same mapping while
// decoding, so there is always a shared common knowledge between the
// encoding and decoder, which is also important for "timing" aspects like
// how to handle variable bit width code encoding.
//
// One obvious but very important consequence of the table system is there
// is always a unique id (at most 12-bits) to map the runs. 'A' might be
// 4, then 'AA' might be 10, 'AAA' 11, 'AAAA' 12, etc. This relationship
// can be used for an effecient lookup strategy for the code mapping. We
// need to know if a run has been seen before, and be able to map that run
// to the output code. Since we start with known unique ids (input bytes),
// and then from those build more unique ids (table entries), we can
// continue this chain (almost like a linked list) to always have small
// integer values that represent the current byte chains in the encoder.
// This means instead of tracking the input bytes (AAAABCD) to know our
// current state, we can track the table entry for AAAABC (it is guaranteed
// to exist by the nature of the algorithm) and the next character D.
// Therefor the tuple of (table_entry, byte) is guaranteed to also be
// unique. This allows us to create a simple lookup key for mapping input
// sequences to codes (table indices) without having to store or search
// any of the code sequences. So if 'AAAA' has a table entry of 12, the
// tuple of ('AAAA', K) for any input byte K will be unique, and can be our
// key. This leads to a integer value at most 20-bits, which can always
// fit in an SMI value and be used as a fast sparse array / object key.
// Output code for the current contents of the index buffer.
var ib_code = index_stream[0] & code_mask; // Load first input index.
var code_table = {}; // Key'd on our 20-bit "tuple".
emit_code(clear_code); // Spec says first code should be a clear code.
// First index already loaded, process the rest of the stream.
for (var i = 1, il = index_stream.length; i < il; ++i) {
var k = index_stream[i] & code_mask;
var cur_key = ib_code << 8 | k; // (prev, k) unique tuple.
var cur_code = code_table[cur_key]; // buffer + k.
// Check if we have to create a new code table entry.
if (cur_code === undefined) {
// We don't have buffer + k.
// Emit index buffer (without k).
// This is an inline version of emit_code, because this is the core
// writing routine of the compressor (and V8 cannot inline emit_code
// because it is a closure here in a different context). Additionally
// we can call emit_byte_to_buffer less often, because we can have
// 30-bits (from our 31-bit signed SMI), and we know our codes will only
// be 12-bits, so can safely have 18-bits there without overflow.
// emit_code(ib_code);
cur |= ib_code << cur_shift;
cur_shift += cur_code_size;
while (cur_shift >= 8) {
buf[p++] = cur & 0xff;
cur >>= 8;
cur_shift -= 8;
if (p === cur_subblock + 256) {
// Finished a subblock.
buf[cur_subblock] = 255;
cur_subblock = p++;
}
}
if (next_code === 4096) {
// Table full, need a clear.
emit_code(clear_code);
next_code = eoi_code + 1;
cur_code_size = min_code_size + 1;
code_table = {};
} else {
// Table not full, insert a new entry.
// Increase our variable bit code sizes if necessary. This is a bit
// tricky as it is based on "timing" between the encoding and
// decoder. From the encoders perspective this should happen after
// we've already emitted the index buffer and are about to create the
// first table entry that would overflow our current code bit size.
if (next_code >= 1 << cur_code_size) ++cur_code_size;
code_table[cur_key] = next_code++; // Insert into code table.
}
ib_code = k; // Index buffer to single input k.
} else {
ib_code = cur_code; // Index buffer to sequence in code table.
}
}
emit_code(ib_code); // There will still be something in the index buffer.
emit_code(eoi_code); // End Of Information.
// Flush / finalize the sub-blocks stream to the buffer.
emit_bytes_to_buffer(1); // Finish the sub-blocks, writing out any unfinished lengths and
// terminating with a sub-block of length 0. If we have already started
// but not yet used a sub-block it can just become the terminator.
if (cur_subblock + 1 === p) {
// Started but unused.
buf[cur_subblock] = 0;
} else {
// Started and used, write length and additional terminator block.
buf[cur_subblock] = p - cur_subblock - 1;
buf[p++] = 0;
}
return p;
}
function GifReader(buf) {
var p = 0; // - Header (GIF87a or GIF89a).
if (buf[p++] !== 0x47 || buf[p++] !== 0x49 || buf[p++] !== 0x46 || buf[p++] !== 0x38 || (buf[p++] + 1 & 0xfd) !== 0x38 || buf[p++] !== 0x61) {
throw "Invalid GIF 87a/89a header.";
} // - Logical Screen Descriptor.
var width = buf[p++] | buf[p++] << 8;
var height = buf[p++] | buf[p++] << 8;
var pf0 = buf[p++]; // <Packed Fields>.
var global_palette_flag = pf0 >> 7;
var num_global_colors_pow2 = pf0 & 0x7;
var num_global_colors = 1 << num_global_colors_pow2 + 1;
var background = buf[p++];
buf[p++]; // Pixel aspect ratio (unused?).
var global_palette_offset = null;
if (global_palette_flag) {
global_palette_offset = p;
p += num_global_colors * 3; // Seek past palette.
}
var no_eof = true;
var frames = [];
var delay = 0;
var transparent_index = null;
var disposal = 0; // 0 - No disposal specified.
var loop_count = null;
this.width = width;
this.height = height;
while (no_eof && p < buf.length) {
switch (buf[p++]) {
case 0x21:
// Graphics Control Extension Block
switch (buf[p++]) {
case 0xff:
// Application specific block
// Try if it's a Netscape block (with animation loop counter).
if (buf[p] !== 0x0b || // 21 FF already read, check block size.
// NETSCAPE2.0
buf[p + 1] == 0x4e && buf[p + 2] == 0x45 && buf[p + 3] == 0x54 && buf[p + 4] == 0x53 && buf[p + 5] == 0x43 && buf[p + 6] == 0x41 && buf[p + 7] == 0x50 && buf[p + 8] == 0x45 && buf[p + 9] == 0x32 && buf[p + 10] == 0x2e && buf[p + 11] == 0x30 && // Sub-block
buf[p + 12] == 0x03 && buf[p + 13] == 0x01 && buf[p + 16] == 0) {
p += 14;
loop_count = buf[p++] | buf[p++] << 8;
p++; // Skip terminator.
} else {
// We don't know what it is, just try to get past it.
p += 12;
while (true) {
// Seek through subblocks.
var block_size = buf[p++];
if (block_size === 0) break;
p += block_size;
}
}
break;
case 0xf9:
// Graphics Control Extension
if (buf[p++] !== 0x4 || buf[p + 4] !== 0) throw "Invalid graphics extension block.";
var pf1 = buf[p++];
delay = buf[p++] | buf[p++] << 8;
transparent_index = buf[p++];
if ((pf1 & 1) === 0) transparent_index = null;
disposal = pf1 >> 2 & 0x7;
p++; // Skip terminator.
break;
case 0xfe:
// Comment Extension.
while (true) {
// Seek through subblocks.
var block_size = buf[p++];
if (block_size === 0) break; // console.log(buf.slice(p, p+block_size).toString('ascii'));
p += block_size;
}
break;
default:
throw "Unknown graphic control label: 0x" + buf[p - 1].toString(16);
}
break;
case 0x2c:
// Image Descriptor.
var x = buf[p++] | buf[p++] << 8;
var y = buf[p++] | buf[p++] << 8;
var w = buf[p++] | buf[p++] << 8;
var h = buf[p++] | buf[p++] << 8;
var pf2 = buf[p++];
var local_palette_flag = pf2 >> 7;
var interlace_flag = pf2 >> 6 & 1;
var num_local_colors_pow2 = pf2 & 0x7;
var num_local_colors = 1 << num_local_colors_pow2 + 1;
var palette_offset = global_palette_offset;
var has_local_palette = false;
if (local_palette_flag) {
var has_local_palette = true;
palette_offset = p; // Override with local palette.
p += num_local_colors * 3; // Seek past palette.
}
var data_offset = p;
p++; // codesize
while (true) {
var block_size = buf[p++];
if (block_size === 0) break;
p += block_size;
}
frames.push({
x: x,
y: y,
width: w,
height: h,
has_local_palette: has_local_palette,
palette_offset: palette_offset,
data_offset: data_offset,
data_length: p - data_offset,
transparent_index: transparent_index,
interlaced: !!interlace_flag,
delay: delay,
disposal: disposal
});
break;
case 0x3b:
// Trailer Marker (end of file).
no_eof = false;
break;
default:
throw "Unknown gif block: 0x" + buf[p - 1].toString(16);
break;
}
}
this.numFrames = function () {
return frames.length;
};
this.loopCount = function () {
return loop_count;
};
this.frameInfo = function (frame_num) {
if (frame_num < 0 || frame_num >= frames.length) throw "Frame index out of range.";
return frames[frame_num];
};
this.decodeAndBlitFrameBGRA = function (frame_num, pixels) {
var frame = this.frameInfo(frame_num);
var num_pixels = frame.width * frame.height;
var index_stream = new Uint8Array(num_pixels); // At most 8-bit indices.
GifReaderLZWOutputIndexStream(buf, frame.data_offset, index_stream, num_pixels);
var palette_offset = frame.palette_offset; // NOTE(deanm): It seems to be much faster to compare index to 256 than
// to === null. Not sure why, but CompareStub_EQ_STRICT shows up high in
// the profile, not sure if it's related to using a Uint8Array.
var trans = frame.transparent_index;
if (trans === null) trans = 256; // We are possibly just blitting to a portion of the entire frame.
// That is a subrect within the framerect, so the additional pixels
// must be skipped over after we finished a scanline.
var framewidth = frame.width;
var framestride = width - framewidth;
var xleft = framewidth; // Number of subrect pixels left in scanline.
// Output indicies of the top left and bottom right corners of the subrect.
var opbeg = (frame.y * width + frame.x) * 4;
var opend = ((frame.y + frame.height) * width + frame.x) * 4;
var op = opbeg;
var scanstride = framestride * 4; // Use scanstride to skip past the rows when interlacing. This is skipping
// 7 rows for the first two passes, then 3 then 1.
if (frame.interlaced === true) {
scanstride += (framewidth + framestride) * 4 * 7; // Pass 1.
}
var interlaceskip = 8; // Tracking the row interval in the current pass.
for (var i = 0, il = index_stream.length; i < il; ++i) {
var index = index_stream[i];
if (xleft === 0) {
// Beginning of new scan line
op += scanstride;
xleft = framewidth;
if (op >= opend) {
// Catch the wrap to switch passes when interlacing.
scanstride = framestride + (framewidth + framestride) * 4 * (interlaceskip - 1); // interlaceskip / 2 * 4 is interlaceskip << 1.
op = opbeg + (framewidth + framestride) * (interlaceskip << 1);
interlaceskip >>= 1;
}
}
if (index === trans) {
op += 4;
} else {
var r = buf[palette_offset + index * 3];
var g = buf[palette_offset + index * 3 + 1];
var b = buf[palette_offset + index * 3 + 2];
pixels[op++] = b;
pixels[op++] = g;
pixels[op++] = r;
pixels[op++] = 255;
}
--xleft;
}
}; // I will go to copy and paste hell one day...
this.decodeAndBlitFrameRGBA = function (frame_num, pixels) {
var frame = this.frameInfo(frame_num);
var num_pixels = frame.width * frame.height;
var index_stream = new Uint8Array(num_pixels); // At most 8-bit indices.
GifReaderLZWOutputIndexStream(buf, frame.data_offset, index_stream, num_pixels);
var palette_offset = frame.palette_offset; // NOTE(deanm): It seems to be much faster to compare index to 256 than
// to === null. Not sure why, but CompareStub_EQ_STRICT shows up high in
// the profile, not sure if it's related to using a Uint8Array.
var trans = frame.transparent_index;
if (trans === null) trans = 256; // We are possibly just blitting to a portion of the entire frame.
// That is a subrect within the framerect, so the additional pixels
// must be skipped over after we finished a scanline.
var framewidth = frame.width;
var framestride = width - framewidth;
var xleft = framewidth; // Number of subrect pixels left in scanline.
// Output indicies of the top left and bottom right corners of the subrect.
var opbeg = (frame.y * width + frame.x) * 4;
var opend = ((frame.y + frame.height) * width + frame.x) * 4;
var op = opbeg;
var scanstride = framestride * 4; // Use scanstride to skip past the rows when interlacing. This is skipping
// 7 rows for the first two passes, then 3 then 1.
if (frame.interlaced === true) {
scanstride += (framewidth + framestride) * 4 * 7; // Pass 1.
}
var interlaceskip = 8; // Tracking the row interval in the current pass.
for (var i = 0, il = index_stream.length; i < il; ++i) {
var index = index_stream[i];
if (xleft === 0) {
// Beginning of new scan line
op += scanstride;
xleft = framewidth;
if (op >= opend) {
// Catch the wrap to switch passes when interlacing.
scanstride = framestride + (framewidth + framestride) * 4 * (interlaceskip - 1); // interlaceskip / 2 * 4 is interlaceskip << 1.
op = opbeg + (framewidth + framestride) * (interlaceskip << 1);
interlaceskip >>= 1;
}
}
if (index === trans) {
op += 4;
} else {
var r = buf[palette_offset + index * 3];
var g = buf[palette_offset + index * 3 + 1];
var b = buf[palette_offset + index * 3 + 2];
pixels[op++] = r;
pixels[op++] = g;
pixels[op++] = b;
pixels[op++] = 255;
}
--xleft;
}
};
}
function GifReaderLZWOutputIndexStream(code_stream, p, output, output_length) {
var min_code_size = code_stream[p++];
var clear_code = 1 << min_code_size;
var eoi_code = clear_code + 1;
var next_code = eoi_code + 1;
var cur_code_size = min_code_size + 1; // Number of bits per code.
// NOTE: This shares the same name as the encoder, but has a different
// meaning here. Here this masks each code coming from the code stream.
var code_mask = (1 << cur_code_size) - 1;
var cur_shift = 0;
var cur = 0;
var op = 0; // Output pointer.
var subblock_size = code_stream[p++]; // TODO(deanm): Would using a TypedArray be any faster? At least it would
// solve the fast mode / backing store uncertainty.
// var code_table = Array(4096);
var code_table = new Int32Array(4096); // Can be signed, we only use 20 bits.
var prev_code = null; // Track code-1.
while (true) {
// Read up to two bytes, making sure we always 12-bits for max sized code.
while (cur_shift < 16) {
if (subblock_size === 0) break; // No more data to be read.
cur |= code_stream[p++] << cur_shift;
cur_shift += 8;
if (subblock_size === 1) {
// Never let it get to 0 to hold logic above.
subblock_size = code_stream[p++]; // Next subblock.
} else {
--subblock_size;
}
} // TODO(deanm): We should never really get here, we should have received
// and EOI.
if (cur_shift < cur_code_size) break;
var code = cur & code_mask;
cur >>= cur_code_size;
cur_shift -= cur_code_size; // TODO(deanm): Maybe should check that the first code was a clear code,
// at least this is what you're supposed to do. But actually our encoder
// now doesn't emit a clear code first anyway.
if (code === clear_code) {
// We don't actually have to clear the table. This could be a good idea
// for greater error checking, but we don't really do any anyway. We
// will just track it with next_code and overwrite old entries.
next_code = eoi_code + 1;
cur_code_size = min_code_size + 1;
code_mask = (1 << cur_code_size) - 1; // Don't update prev_code ?
prev_code = null;
continue;
} else if (code === eoi_code) {
break;
} // We have a similar situation as the decoder, where we want to store
// variable length entries (code table entries), but we want to do in a
// faster manner than an array of arrays. The code below stores sort of a
// linked list within the code table, and then "chases" through it to
// construct the dictionary entries. When a new entry is created, just the
// last byte is stored, and the rest (prefix) of the entry is only
// referenced by its table entry. Then the code chases through the
// prefixes until it reaches a single byte code. We have to chase twice,
// first to compute the length, and then to actually copy the data to the
// output (backwards, since we know the length). The alternative would be
// storing something in an intermediate stack, but that doesn't make any
// more sense. I implemented an approach where it also stored the length
// in the code table, although it's a bit tricky because you run out of
// bits (12 + 12 + 8), but I didn't measure much improvements (the table
// entries are generally not the long). Even when I created benchmarks for
// very long table entries the complexity did not seem worth it.
// The code table stores the prefix entry in 12 bits and then the suffix
// byte in 8 bits, so each entry is 20 bits.
var chase_code = code < next_code ? code : prev_code; // Chase what we will output, either {CODE} or {CODE-1}.
var chase_length = 0;
var chase = chase_code;
while (chase > clear_code) {
chase = code_table[chase] >> 8;
++chase_length;
}
var k = chase;
var op_end = op + chase_length + (chase_code !== code ? 1 : 0);
if (op_end > output_length) {
console.log("Warning, gif stream longer than expected.");
return;
} // Already have the first byte from the chase, might as well write it fast.
output[op++] = k;
op += chase_length;
var b = op; // Track pointer, writing backwards.
if (chase_code !== code) // The case of emitting {CODE-1} + k.
output[op++] = k;
chase = chase_code;
while (chase_length--) {
chase = code_table[chase];
output[--b] = chase & 0xff; // Write backwards.
chase >>= 8; // Pull down to the prefix code.
}
if (prev_code !== null && next_code < 4096) {
code_table[next_code++] = prev_code << 8 | k; // TODO(deanm): Figure out this clearing vs code growth logic better. I
// have an feeling that it should just happen somewhere else, for now it
// is awkward between when we grow past the max and then hit a clear code.
// For now just check if we hit the max 12-bits (then a clear code should
// follow, also of course encoded in 12-bits).
if (next_code >= code_mask + 1 && cur_code_size < 12) {
++cur_code_size;
code_mask = code_mask << 1 | 1;
}
}
prev_code = code;
}
if (op !== output_length) {
console.log("Warning, gif stream shorter than expected.");
}
return output;
}
try {
} catch (e) {} // CommonJS.
/*
* Copyright (c) 2012 chick307 <chick307@gmail.com>
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
(function (jsPDF, callback) {
jsPDF.API.adler32cs = callback();
})(jsPDF, function () {
var _hasArrayBuffer = typeof ArrayBuffer === "function" && typeof Uint8Array === "function";
var _Buffer = null,
_isBuffer = function () {
if (!_hasArrayBuffer) return function _isBuffer() {
return false;
};
return function _isBuffer(value) {
return value instanceof ArrayBuffer || _Buffer !== null && value instanceof _Buffer;
};
}();
var _utf8ToBinary = function () {
if (_Buffer !== null) {
return function _utf8ToBinary(utf8String) {
return new _Buffer(utf8String, "utf8").toString("binary");
};
} else {
return function _utf8ToBinary(utf8String) {
return unescape(encodeURIComponent(utf8String));
};
}
}();
var MOD = 65521;
var _update = function _update(checksum, binaryString) {
var a = checksum & 0xffff,
b = checksum >>> 16;
for (var i = 0, length = binaryString.length; i < length; i++) {
a = (a + (binaryString.charCodeAt(i) & 0xff)) % MOD;
b = (b + a) % MOD;
}
return (b << 16 | a) >>> 0;
};
var _updateUint8Array = function _updateUint8Array(checksum, uint8Array) {
var a = checksum & 0xffff,
b = checksum >>> 16;
for (var i = 0, length = uint8Array.length; i < length; i++) {
a = (a + uint8Array[i]) % MOD;
b = (b + a) % MOD;
}
return (b << 16 | a) >>> 0;
};
var exports = {};
var Adler32 = exports.Adler32 = function () {
var ctor = function Adler32(checksum) {
if (!(this instanceof ctor)) {
throw new TypeError("Constructor cannot called be as a function.");
}
if (!isFinite(checksum = checksum == null ? 1 : +checksum)) {
throw new Error("First arguments needs to be a finite number.");
}
this.checksum = checksum >>> 0;
};
var proto = ctor.prototype = {};
proto.constructor = ctor;
ctor.from = function (from) {
from.prototype = proto;
return from;
}(function from(binaryString) {
if (!(this instanceof ctor)) {
throw new TypeError("Constructor cannot called be as a function.");
}
if (binaryString == null) throw new Error("First argument needs to be a string.");
this.checksum = _update(1, binaryString.toString());
});
ctor.fromUtf8 = function (fromUtf8) {
fromUtf8.prototype = proto;
return fromUtf8;
}(function fromUtf8(utf8String) {
if (!(this instanceof ctor)) {
throw new TypeError("Constructor cannot called be as a function.");
}
if (utf8String == null) throw new Error("First argument needs to be a string.");
var binaryString = _utf8ToBinary(utf8String.toString());
this.checksum = _update(1, binaryString);
});
if (_hasArrayBuffer) {
ctor.fromBuffer = function (fromBuffer) {
fromBuffer.prototype = proto;
return fromBuffer;
}(function fromBuffer(buffer) {
if (!(this instanceof ctor)) {
throw new TypeError("Constructor cannot called be as a function.");
}
if (!_isBuffer(buffer)) throw new Error("First argument needs to be ArrayBuffer.");
var array = new Uint8Array(buffer);
return this.checksum = _updateUint8Array(1, array);
});
}
proto.update = function update(binaryString) {
if (binaryString == null) throw new Error("First argument needs to be a string.");
binaryString = binaryString.toString();
return this.checksum = _update(this.checksum, binaryString);
};
proto.updateUtf8 = function updateUtf8(utf8String) {
if (utf8String == null) throw new Error("First argument needs to be a string.");
var binaryString = _utf8ToBinary(utf8String.toString());
return this.checksum = _update(this.checksum, binaryString);
};
if (_hasArrayBuffer) {
proto.updateBuffer = function updateBuffer(buffer) {
if (!_isBuffer(buffer)) throw new Error("First argument needs to be ArrayBuffer.");
var array = new Uint8Array(buffer);
return this.checksum = _updateUint8Array(this.checksum, array);
};
}
proto.clone = function clone() {
return new Adler32(this.checksum);
};
return ctor;
}();
exports.from = function from(binaryString) {
if (binaryString == null) throw new Error("First argument needs to be a string.");
return _update(1, binaryString.toString());
};
exports.fromUtf8 = function fromUtf8(utf8String) {
if (utf8String == null) throw new Error("First argument needs to be a string.");
var binaryString = _utf8ToBinary(utf8String.toString());
return _update(1, binaryString);
};
if (_hasArrayBuffer) {
exports.fromBuffer = function fromBuffer(buffer) {
if (!_isBuffer(buffer)) throw new Error("First argument need to be ArrayBuffer.");
var array = new Uint8Array(buffer);
return _updateUint8Array(1, array);
};
}
return exports;
});
/*
Copyright (c) 2008, Adobe Systems Incorporated
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Adobe Systems Incorporated nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author shaozilee
*
* Bmp format decoder,support 1bit 4bit 8bit 24bit bmp
*
*/
/*
Copyright (c) 2013 Gildas Lormeau. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This program is based on JZlib 1.0.2 ymnk, JCraft,Inc.
* JZlib is based on zlib-1.1.3, so all credit should go authors
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
* and contributors of zlib.
*/
(function (global) {
var MAX_BITS = 15;
var D_CODES = 30;
var BL_CODES = 19;
var LENGTH_CODES = 29;
var LITERALS = 256;
var L_CODES = LITERALS + 1 + LENGTH_CODES;
var HEAP_SIZE = 2 * L_CODES + 1;
var END_BLOCK = 256; // Bit length codes must not exceed MAX_BL_BITS bits
var MAX_BL_BITS = 7; // repeat previous bit length 3-6 times (2 bits of repeat count)
var REP_3_6 = 16; // repeat a zero length 3-10 times (3 bits of repeat count)
var REPZ_3_10 = 17; // repeat a zero length 11-138 times (7 bits of repeat count)
var REPZ_11_138 = 18; // The lengths of the bit length codes are sent in order of decreasing
// probability, to avoid transmitting the lengths for unused bit
// length codes.
var Buf_size = 8 * 2; // JZlib version : "1.0.2"
var Z_DEFAULT_COMPRESSION = -1; // compression strategy
var Z_FILTERED = 1;
var Z_HUFFMAN_ONLY = 2;
var Z_DEFAULT_STRATEGY = 0;
var Z_NO_FLUSH = 0;
var Z_PARTIAL_FLUSH = 1;
var Z_FULL_FLUSH = 3;
var Z_FINISH = 4;
var Z_OK = 0;
var Z_STREAM_END = 1;
var Z_NEED_DICT = 2;
var Z_STREAM_ERROR = -2;
var Z_DATA_ERROR = -3;
var Z_BUF_ERROR = -5; // Tree
// see definition of array dist_code below
var _dist_code = [0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29];
function Tree() {
var that = this; // dyn_tree; // the dynamic tree
// max_code; // largest code with non zero frequency
// stat_desc; // the corresponding static tree
// Compute the optimal bit lengths for a tree and update the total bit
// length
// for the current block.
// IN assertion: the fields freq and dad are set, heap[heap_max] and
// above are the tree nodes sorted by increasing frequency.
// OUT assertions: the field len is set to the optimal bit length, the
// array bl_count contains the frequencies for each bit length.
// The length opt_len is updated; static_len is also updated if stree is
// not null.
function gen_bitlen(s) {
var tree = that.dyn_tree;
var stree = that.stat_desc.static_tree;
var extra = that.stat_desc.extra_bits;
var base = that.stat_desc.extra_base;
var max_length = that.stat_desc.max_length;
var h; // heap index
var n, m; // iterate over the tree elements
var bits; // bit length
var xbits; // extra bits
var f; // frequency
var overflow = 0; // number of elements with bit length too large
for (bits = 0; bits <= MAX_BITS; bits++) s.bl_count[bits] = 0; // In a first pass, compute the optimal bit lengths (which may
// overflow in the case of the bit length tree).
tree[s.heap[s.heap_max] * 2 + 1] = 0; // root of the heap
for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
n = s.heap[h];
bits = tree[tree[n * 2 + 1] * 2 + 1] + 1;
if (bits > max_length) {
bits = max_length;
overflow++;
}
tree[n * 2 + 1] = bits; // We overwrite tree[n*2+1] which is no longer needed
if (n > that.max_code) continue; // not a leaf node
s.bl_count[bits]++;
xbits = 0;
if (n >= base) xbits = extra[n - base];
f = tree[n * 2];
s.opt_len += f * (bits + xbits);
if (stree) s.static_len += f * (stree[n * 2 + 1] + xbits);
}
if (overflow === 0) return; // This happens for example on obj2 and pic of the Calgary corpus
// Find the first bit length which could increase:
do {
bits = max_length - 1;
while (s.bl_count[bits] === 0) bits--;
s.bl_count[bits]--; // move one leaf down the tree
s.bl_count[bits + 1] += 2; // move one overflow item as its brother
s.bl_count[max_length]--; // The brother of the overflow item also moves one step up,
// but this does not affect bl_count[max_length]
overflow -= 2;
} while (overflow > 0);
for (bits = max_length; bits !== 0; bits--) {
n = s.bl_count[bits];
while (n !== 0) {
m = s.heap[--h];
if (m > that.max_code) continue;
if (tree[m * 2 + 1] != bits) {
s.opt_len += (bits - tree[m * 2 + 1]) * tree[m * 2];
tree[m * 2 + 1] = bits;
}
n--;
}
}
} // Reverse the first len bits of a code, using straightforward code (a
// faster
// method would use a table)
// IN assertion: 1 <= len <= 15
function bi_reverse(code, // the value to invert
len // its bit length
) {
var res = 0;
do {
res |= code & 1;
code >>>= 1;
res <<= 1;
} while (--len > 0);
return res >>> 1;
} // Generate the codes for a given tree and bit counts (which need not be
// optimal).
// IN assertion: the array bl_count contains the bit length statistics for
// the given tree and the field len is set for all tree elements.
// OUT assertion: the field code is set for all tree elements of non
// zero code length.
function gen_codes(tree, // the tree to decorate
max_code, // largest code with non zero frequency
bl_count // number of codes at each bit length
) {
var next_code = []; // next code value for each
// bit length
var code = 0; // running code value
var bits; // bit index
var n; // code index
var len; // The distribution counts are first used to generate the code values
// without bit reversal.
for (bits = 1; bits <= MAX_BITS; bits++) {
next_code[bits] = code = code + bl_count[bits - 1] << 1;
} // Check that the bit counts in bl_count are consistent. The last code
// must be all ones.
// Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
// "inconsistent bit counts");
// Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
for (n = 0; n <= max_code; n++) {
len = tree[n * 2 + 1];
if (len === 0) continue; // Now reverse the bits
tree[n * 2] = bi_reverse(next_code[len]++, len);
}
} // Construct one Huffman tree and assigns the code bit strings and lengths.
// Update the total bit length for the current block.
// IN assertion: the field freq is set for all tree elements.
// OUT assertions: the fields len and code are set to the optimal bit length
// and corresponding code. The length opt_len is updated; static_len is
// also updated if stree is not null. The field max_code is set.
that.build_tree = function (s) {
var tree = that.dyn_tree;
var stree = that.stat_desc.static_tree;
var elems = that.stat_desc.elems;
var n, m; // iterate over heap elements
var max_code = -1; // largest code with non zero frequency
var node; // new node being created
// Construct the initial heap, with least frequent element in
// heap[1]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
// heap[0] is not used.
s.heap_len = 0;
s.heap_max = HEAP_SIZE;
for (n = 0; n < elems; n++) {
if (tree[n * 2] !== 0) {
s.heap[++s.heap_len] = max_code = n;
s.depth[n] = 0;
} else {
tree[n * 2 + 1] = 0;
}
} // The pkzip format requires that at least one distance code exists,
// and that at least one bit should be sent even if there is only one
// possible code. So to avoid special checks later on we force at least
// two codes of non zero frequency.
while (s.heap_len < 2) {
node = s.heap[++s.heap_len] = max_code < 2 ? ++max_code : 0;
tree[node * 2] = 1;
s.depth[node] = 0;
s.opt_len--;
if (stree) s.static_len -= stree[node * 2 + 1]; // node is 0 or 1 so it does not have extra bits
}
that.max_code = max_code; // The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
// establish sub-heaps of increasing lengths:
for (n = Math.floor(s.heap_len / 2); n >= 1; n--) s.pqdownheap(tree, n); // Construct the Huffman tree by repeatedly combining the least two
// frequent nodes.
node = elems; // next internal node of the tree
do {
// n = node of least frequency
n = s.heap[1];
s.heap[1] = s.heap[s.heap_len--];
s.pqdownheap(tree, 1);
m = s.heap[1]; // m = node of next least frequency
s.heap[--s.heap_max] = n; // keep the nodes sorted by frequency
s.heap[--s.heap_max] = m; // Create a new node father of n and m
tree[node * 2] = tree[n * 2] + tree[m * 2];
s.depth[node] = Math.max(s.depth[n], s.depth[m]) + 1;
tree[n * 2 + 1] = tree[m * 2 + 1] = node; // and insert the new node in the heap
s.heap[1] = node++;
s.pqdownheap(tree, 1);
} while (s.heap_len >= 2);
s.heap[--s.heap_max] = s.heap[1]; // At this point, the fields freq and dad are set. We can now
// generate the bit lengths.
gen_bitlen(s); // The field len is now set, we can generate the bit codes
gen_codes(tree, that.max_code, s.bl_count);
};
}
Tree._length_code = [0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28];
Tree.base_length = [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 0];
Tree.base_dist = [0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576]; // Mapping from a distance to a distance code. dist is the distance - 1 and
// must not have side effects. _dist_code[256] and _dist_code[257] are never
// used.
Tree.d_code = function (dist) {
return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
}; // extra bits for each length code
Tree.extra_lbits = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]; // extra bits for each distance code
Tree.extra_dbits = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]; // extra bits for each bit length code
Tree.extra_blbits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7];
Tree.bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; // StaticTree
function StaticTree(static_tree, extra_bits, extra_base, elems, max_length) {
var that = this;
that.static_tree = static_tree;
that.extra_bits = extra_bits;
that.extra_base = extra_base;
that.elems = elems;
that.max_length = max_length;
}
StaticTree.static_ltree = [12, 8, 140, 8, 76, 8, 204, 8, 44, 8, 172, 8, 108, 8, 236, 8, 28, 8, 156, 8, 92, 8, 220, 8, 60, 8, 188, 8, 124, 8, 252, 8, 2, 8, 130, 8, 66, 8, 194, 8, 34, 8, 162, 8, 98, 8, 226, 8, 18, 8, 146, 8, 82, 8, 210, 8, 50, 8, 178, 8, 114, 8, 242, 8, 10, 8, 138, 8, 74, 8, 202, 8, 42, 8, 170, 8, 106, 8, 234, 8, 26, 8, 154, 8, 90, 8, 218, 8, 58, 8, 186, 8, 122, 8, 250, 8, 6, 8, 134, 8, 70, 8, 198, 8, 38, 8, 166, 8, 102, 8, 230, 8, 22, 8, 150, 8, 86, 8, 214, 8, 54, 8, 182, 8, 118, 8, 246, 8, 14, 8, 142, 8, 78, 8, 206, 8, 46, 8, 174, 8, 110, 8, 238, 8, 30, 8, 158, 8, 94, 8, 222, 8, 62, 8, 190, 8, 126, 8, 254, 8, 1, 8, 129, 8, 65, 8, 193, 8, 33, 8, 161, 8, 97, 8, 225, 8, 17, 8, 145, 8, 81, 8, 209, 8, 49, 8, 177, 8, 113, 8, 241, 8, 9, 8, 137, 8, 73, 8, 201, 8, 41, 8, 169, 8, 105, 8, 233, 8, 25, 8, 153, 8, 89, 8, 217, 8, 57, 8, 185, 8, 121, 8, 249, 8, 5, 8, 133, 8, 69, 8, 197, 8, 37, 8, 165, 8, 101, 8, 229, 8, 21, 8, 149, 8, 85, 8, 213, 8, 53, 8, 181, 8, 117, 8, 245, 8, 13, 8, 141, 8, 77, 8, 205, 8, 45, 8, 173, 8, 109, 8, 237, 8, 29, 8, 157, 8, 93, 8, 221, 8, 61, 8, 189, 8, 125, 8, 253, 8, 19, 9, 275, 9, 147, 9, 403, 9, 83, 9, 339, 9, 211, 9, 467, 9, 51, 9, 307, 9, 179, 9, 435, 9, 115, 9, 371, 9, 243, 9, 499, 9, 11, 9, 267, 9, 139, 9, 395, 9, 75, 9, 331, 9, 203, 9, 459, 9, 43, 9, 299, 9, 171, 9, 427, 9, 107, 9, 363, 9, 235, 9, 491, 9, 27, 9, 283, 9, 155, 9, 411, 9, 91, 9, 347, 9, 219, 9, 475, 9, 59, 9, 315, 9, 187, 9, 443, 9, 123, 9, 379, 9, 251, 9, 507, 9, 7, 9, 263, 9, 135, 9, 391, 9, 71, 9, 327, 9, 199, 9, 455, 9, 39, 9, 295, 9, 167, 9, 423, 9, 103, 9, 359, 9, 231, 9, 487, 9, 23, 9, 279, 9, 151, 9, 407, 9, 87, 9, 343, 9, 215, 9, 471, 9, 55, 9, 311, 9, 183, 9, 439, 9, 119, 9, 375, 9, 247, 9, 503, 9, 15, 9, 271, 9, 143, 9, 399, 9, 79, 9, 335, 9, 207, 9, 463, 9, 47, 9, 303, 9, 175, 9, 431, 9, 111, 9, 367, 9, 239, 9, 495, 9, 31, 9, 287, 9, 159, 9, 415, 9, 95, 9, 351, 9, 223, 9, 479, 9, 63, 9, 319, 9, 191, 9, 447, 9, 127, 9, 383, 9, 255, 9, 511, 9, 0, 7, 64, 7, 32, 7, 96, 7, 16, 7, 80, 7, 48, 7, 112, 7, 8, 7, 72, 7, 40, 7, 104, 7, 24, 7, 88, 7, 56, 7, 120, 7, 4, 7, 68, 7, 36, 7, 100, 7, 20, 7, 84, 7, 52, 7, 116, 7, 3, 8, 131, 8, 67, 8, 195, 8, 35, 8, 163, 8, 99, 8, 227, 8];
StaticTree.static_dtree = [0, 5, 16, 5, 8, 5, 24, 5, 4, 5, 20, 5, 12, 5, 28, 5, 2, 5, 18, 5, 10, 5, 26, 5, 6, 5, 22, 5, 14, 5, 30, 5, 1, 5, 17, 5, 9, 5, 25, 5, 5, 5, 21, 5, 13, 5, 29, 5, 3, 5, 19, 5, 11, 5, 27, 5, 7, 5, 23, 5];
StaticTree.static_l_desc = new StaticTree(StaticTree.static_ltree, Tree.extra_lbits, LITERALS + 1, L_CODES, MAX_BITS);
StaticTree.static_d_desc = new StaticTree(StaticTree.static_dtree, Tree.extra_dbits, 0, D_CODES, MAX_BITS);
StaticTree.static_bl_desc = new StaticTree(null, Tree.extra_blbits, 0, BL_CODES, MAX_BL_BITS); // Deflate
var MAX_MEM_LEVEL = 9;
var DEF_MEM_LEVEL = 8;
function Config(good_length, max_lazy, nice_length, max_chain, func) {
var that = this;
that.good_length = good_length;
that.max_lazy = max_lazy;
that.nice_length = nice_length;
that.max_chain = max_chain;
that.func = func;
}
var STORED = 0;
var FAST = 1;
var SLOW = 2;
var config_table = [new Config(0, 0, 0, 0, STORED), new Config(4, 4, 8, 4, FAST), new Config(4, 5, 16, 8, FAST), new Config(4, 6, 32, 32, FAST), new Config(4, 4, 16, 16, SLOW), new Config(8, 16, 32, 32, SLOW), new Config(8, 16, 128, 128, SLOW), new Config(8, 32, 128, 256, SLOW), new Config(32, 128, 258, 1024, SLOW), new Config(32, 258, 258, 4096, SLOW)];
var z_errmsg = ["need dictionary", // Z_NEED_DICT
// 2
"stream end", // Z_STREAM_END 1
"", // Z_OK 0
"", // Z_ERRNO (-1)
"stream error", // Z_STREAM_ERROR (-2)
"data error", // Z_DATA_ERROR (-3)
"", // Z_MEM_ERROR (-4)
"buffer error", // Z_BUF_ERROR (-5)
"", // Z_VERSION_ERROR (-6)
""]; // block not completed, need more input or more output
var NeedMore = 0; // block flush performed
var BlockDone = 1; // finish started, need only more output at next deflate
var FinishStarted = 2; // finish done, accept no more input or output
var FinishDone = 3; // preset dictionary flag in zlib header
var PRESET_DICT = 0x20;
var INIT_STATE = 42;
var BUSY_STATE = 113;
var FINISH_STATE = 666; // The deflate compression method
var Z_DEFLATED = 8;
var STORED_BLOCK = 0;
var STATIC_TREES = 1;
var DYN_TREES = 2;
var MIN_MATCH = 3;
var MAX_MATCH = 258;
var MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1;
function smaller(tree, n, m, depth) {
var tn2 = tree[n * 2];
var tm2 = tree[m * 2];
return tn2 < tm2 || tn2 == tm2 && depth[n] <= depth[m];
}
function Deflate() {
var that = this;
var strm; // pointer back to this zlib stream
var status; // as the name implies
// pending_buf; // output still pending
var pending_buf_size; // size of pending_buf
var last_flush; // value of flush param for previous deflate call
var w_size; // LZ77 window size (32K by default)
var w_bits; // log2(w_size) (8..16)
var w_mask; // w_size - 1
var window; // Sliding window. Input bytes are read into the second half of the window,
// and move to the first half later to keep a dictionary of at least wSize
// bytes. With this organization, matches are limited to a distance of
// wSize-MAX_MATCH bytes, but this ensures that IO is always
// performed with a length multiple of the block size. Also, it limits
// the window size to 64K, which is quite useful on MSDOS.
// To do: use the user input buffer as sliding window.
var window_size; // Actual size of window: 2*wSize, except when the user input buffer
// is directly used as sliding window.
var prev; // Link to older string with same hash index. To limit the size of this
// array to 64K, this link is maintained only for the last 32K strings.
// An index in this array is thus a window index modulo 32K.
var head; // Heads of the hash chains or NIL.
var ins_h; // hash index of string to be inserted
var hash_size; // number of elements in hash table
var hash_bits; // log2(hash_size)
var hash_mask; // hash_size-1
// Number of bits by which ins_h must be shifted at each input
// step. It must be such that after MIN_MATCH steps, the oldest
// byte no longer takes part in the hash key, that is:
// hash_shift * MIN_MATCH >= hash_bits
var hash_shift; // Window position at the beginning of the current output block. Gets
// negative when the window is moved backwards.
var block_start;
var match_length; // length of best match
var prev_match; // previous match
var match_available; // set if previous match exists
var strstart; // start of string to insert
var match_start; // start of matching string
var lookahead; // number of valid bytes ahead in window
// Length of the best match at previous step. Matches not greater than this
// are discarded. This is used in the lazy match evaluation.
var prev_length; // To speed up deflation, hash chains are never searched beyond this
// length. A higher limit improves compression ratio but degrades the speed.
var max_chain_length; // Attempt to find a better match only when the current match is strictly
// smaller than this value. This mechanism is used only for compression
// levels >= 4.
var max_lazy_match; // Insert new strings in the hash table only if the match length is not
// greater than this length. This saves time but degrades compression.
// max_insert_length is used only for compression levels <= 3.
var level; // compression level (1..9)
var strategy; // favor or force Huffman coding
// Use a faster search when the previous match is longer than this
var good_match; // Stop searching when current match exceeds this
var nice_match;
var dyn_ltree; // literal and length tree
var dyn_dtree; // distance tree
var bl_tree; // Huffman tree for bit lengths
var l_desc = new Tree(); // desc for literal tree
var d_desc = new Tree(); // desc for distance tree
var bl_desc = new Tree(); // desc for bit length tree
// that.heap_len; // number of elements in the heap
// that.heap_max; // element of largest frequency
// The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
// The same heap array is used to build all trees.
// Depth of each subtree used as tie breaker for trees of equal frequency
that.depth = [];
var l_buf; // index for literals or lengths */
// Size of match buffer for literals/lengths. There are 4 reasons for
// limiting lit_bufsize to 64K:
// - frequencies can be kept in 16 bit counters
// - if compression is not successful for the first block, all input
// data is still in the window so we can still emit a stored block even
// when input comes from standard input. (This can also be done for
// all blocks if lit_bufsize is not greater than 32K.)
// - if compression is not successful for a file smaller than 64K, we can
// even emit a stored file instead of a stored block (saving 5 bytes).
// This is applicable only for zip (not gzip or zlib).
// - creating new Huffman trees less frequently may not provide fast
// adaptation to changes in the input data statistics. (Take for
// example a binary file with poorly compressible code followed by
// a highly compressible string table.) Smaller buffer sizes give
// fast adaptation but have of course the overhead of transmitting
// trees more frequently.
// - I can't count above 4
var lit_bufsize;
var last_lit; // running index in l_buf
// Buffer for distances. To simplify the code, d_buf and l_buf have
// the same number of elements. To use different lengths, an extra flag
// array would be necessary.
var d_buf; // index of pendig_buf
// that.opt_len; // bit length of current block with optimal trees
// that.static_len; // bit length of current block with static trees
var matches; // number of string matches in current block
var last_eob_len; // bit length of EOB code for last block
// Output buffer. bits are inserted starting at the bottom (least
// significant bits).
var bi_buf; // Number of valid bits in bi_buf. All bits above the last valid bit
// are always zero.
var bi_valid; // number of codes at each bit length for an optimal tree
that.bl_count = []; // heap used to build the Huffman trees
that.heap = [];
dyn_ltree = [];
dyn_dtree = [];
bl_tree = [];
function lm_init() {
var i;
window_size = 2 * w_size;
head[hash_size - 1] = 0;
for (i = 0; i < hash_size - 1; i++) {
head[i] = 0;
} // Set the default configuration parameters:
max_lazy_match = config_table[level].max_lazy;
good_match = config_table[level].good_length;
nice_match = config_table[level].nice_length;
max_chain_length = config_table[level].max_chain;
strstart = 0;
block_start = 0;
lookahead = 0;
match_length = prev_length = MIN_MATCH - 1;
match_available = 0;
ins_h = 0;
}
function init_block() {
var i; // Initialize the trees.
for (i = 0; i < L_CODES; i++) dyn_ltree[i * 2] = 0;
for (i = 0; i < D_CODES; i++) dyn_dtree[i * 2] = 0;
for (i = 0; i < BL_CODES; i++) bl_tree[i * 2] = 0;
dyn_ltree[END_BLOCK * 2] = 1;
that.opt_len = that.static_len = 0;
last_lit = matches = 0;
} // Initialize the tree data structures for a new zlib stream.
function tr_init() {
l_desc.dyn_tree = dyn_ltree;
l_desc.stat_desc = StaticTree.static_l_desc;
d_desc.dyn_tree = dyn_dtree;
d_desc.stat_desc = StaticTree.static_d_desc;
bl_desc.dyn_tree = bl_tree;
bl_desc.stat_desc = StaticTree.static_bl_desc;
bi_buf = 0;
bi_valid = 0;
last_eob_len = 8; // enough lookahead for inflate
// Initialize the first block of the first file:
init_block();
} // Restore the heap property by moving down the tree starting at node k,
// exchanging a node with the smallest of its two sons if necessary,
// stopping
// when the heap property is re-established (each father smaller than its
// two sons).
that.pqdownheap = function (tree, // the tree to restore
k // node to move down
) {
var heap = that.heap;
var v = heap[k];
var j = k << 1; // left son of k
while (j <= that.heap_len) {
// Set j to the smallest of the two sons:
if (j < that.heap_len && smaller(tree, heap[j + 1], heap[j], that.depth)) {
j++;
} // Exit if v is smaller than both sons
if (smaller(tree, v, heap[j], that.depth)) break; // Exchange v with the smallest son
heap[k] = heap[j];
k = j; // And continue down the tree, setting j to the left son of k
j <<= 1;
}
heap[k] = v;
}; // Scan a literal or distance tree to determine the frequencies of the codes
// in the bit length tree.
function scan_tree(tree, // the tree to be scanned
max_code // and its largest code of non zero frequency
) {
var n; // iterates over all tree elements
var prevlen = -1; // last emitted length
var curlen; // length of current code
var nextlen = tree[0 * 2 + 1]; // length of next code
var count = 0; // repeat count of the current code
var max_count = 7; // max repeat count
var min_count = 4; // min repeat count
if (nextlen === 0) {
max_count = 138;
min_count = 3;
}
tree[(max_code + 1) * 2 + 1] = 0xffff; // guard
for (n = 0; n <= max_code; n++) {
curlen = nextlen;
nextlen = tree[(n + 1) * 2 + 1];
if (++count < max_count && curlen == nextlen) {
continue;
} else if (count < min_count) {
bl_tree[curlen * 2] += count;
} else if (curlen !== 0) {
if (curlen != prevlen) bl_tree[curlen * 2]++;
bl_tree[REP_3_6 * 2]++;
} else if (count <= 10) {
bl_tree[REPZ_3_10 * 2]++;
} else {
bl_tree[REPZ_11_138 * 2]++;
}
count = 0;
prevlen = curlen;
if (nextlen === 0) {
max_count = 138;
min_count = 3;
} else if (curlen == nextlen) {
max_count = 6;
min_count = 3;
} else {
max_count = 7;
min_count = 4;
}
}
} // Construct the Huffman tree for the bit lengths and return the index in
// bl_order of the last bit length code to send.
function build_bl_tree() {
var max_blindex; // index of last bit length code of non zero freq
// Determine the bit length frequencies for literal and distance trees
scan_tree(dyn_ltree, l_desc.max_code);
scan_tree(dyn_dtree, d_desc.max_code); // Build the bit length tree:
bl_desc.build_tree(that); // opt_len now includes the length of the tree representations, except
// the lengths of the bit lengths codes and the 5+5+4 bits for the
// counts.
// Determine the number of bit length codes to send. The pkzip format
// requires that at least 4 bit length codes be sent. (appnote.txt says
// 3 but the actual value used is 4.)
for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
if (bl_tree[Tree.bl_order[max_blindex] * 2 + 1] !== 0) break;
} // Update opt_len to include the bit length tree and counts
that.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
return max_blindex;
} // Output a byte on the stream.
// IN assertion: there is enough room in pending_buf.
function put_byte(p) {
that.pending_buf[that.pending++] = p;
}
function put_short(w) {
put_byte(w & 0xff);
put_byte(w >>> 8 & 0xff);
}
function putShortMSB(b) {
put_byte(b >> 8 & 0xff);
put_byte(b & 0xff & 0xff);
}
function send_bits(value, length) {
var val,
len = length;
if (bi_valid > Buf_size - len) {
val = value; // bi_buf |= (val << bi_valid);
bi_buf |= val << bi_valid & 0xffff;
put_short(bi_buf);
bi_buf = val >>> Buf_size - bi_valid;
bi_valid += len - Buf_size;
} else {
// bi_buf |= (value) << bi_valid;
bi_buf |= value << bi_valid & 0xffff;
bi_valid += len;
}
}
function send_code(c, tree) {
var c2 = c * 2;
send_bits(tree[c2] & 0xffff, tree[c2 + 1] & 0xffff);
} // Send a literal or distance tree in compressed form, using the codes in
// bl_tree.
function send_tree(tree, // the tree to be sent
max_code // and its largest code of non zero frequency
) {
var n; // iterates over all tree elements
var prevlen = -1; // last emitted length
var curlen; // length of current code
var nextlen = tree[0 * 2 + 1]; // length of next code
var count = 0; // repeat count of the current code
var max_count = 7; // max repeat count
var min_count = 4; // min repeat count
if (nextlen === 0) {
max_count = 138;
min_count = 3;
}
for (n = 0; n <= max_code; n++) {
curlen = nextlen;
nextlen = tree[(n + 1) * 2 + 1];
if (++count < max_count && curlen == nextlen) {
continue;
} else if (count < min_count) {
do {
send_code(curlen, bl_tree);
} while (--count !== 0);
} else if (curlen !== 0) {
if (curlen != prevlen) {
send_code(curlen, bl_tree);
count--;
}
send_code(REP_3_6, bl_tree);
send_bits(count - 3, 2);
} else if (count <= 10) {
send_code(REPZ_3_10, bl_tree);
send_bits(count - 3, 3);
} else {
send_code(REPZ_11_138, bl_tree);
send_bits(count - 11, 7);
}
count = 0;
prevlen = curlen;
if (nextlen === 0) {
max_count = 138;
min_count = 3;
} else if (curlen == nextlen) {
max_count = 6;
min_count = 3;
} else {
max_count = 7;
min_count = 4;
}
}
} // Send the header for a block using dynamic Huffman trees: the counts, the
// lengths of the bit length codes, the literal tree and the distance tree.
// IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
function send_all_trees(lcodes, dcodes, blcodes) {
var rank; // index in bl_order
send_bits(lcodes - 257, 5); // not +255 as stated in appnote.txt
send_bits(dcodes - 1, 5);
send_bits(blcodes - 4, 4); // not -3 as stated in appnote.txt
for (rank = 0; rank < blcodes; rank++) {
send_bits(bl_tree[Tree.bl_order[rank] * 2 + 1], 3);
}
send_tree(dyn_ltree, lcodes - 1); // literal tree
send_tree(dyn_dtree, dcodes - 1); // distance tree
} // Flush the bit buffer, keeping at most 7 bits in it.
function bi_flush() {
if (bi_valid == 16) {
put_short(bi_buf);
bi_buf = 0;
bi_valid = 0;
} else if (bi_valid >= 8) {
put_byte(bi_buf & 0xff);
bi_buf >>>= 8;
bi_valid -= 8;
}
} // Send one empty static block to give enough lookahead for inflate.
// This takes 10 bits, of which 7 may remain in the bit buffer.
// The current inflate code requires 9 bits of lookahead. If the
// last two codes for the previous block (real code plus EOB) were coded
// on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
// the last real code. In this case we send two empty static blocks instead
// of one. (There are no problems if the previous block is stored or fixed.)
// To simplify the code, we assume the worst case of last real code encoded
// on one bit only.
function _tr_align() {
send_bits(STATIC_TREES << 1, 3);
send_code(END_BLOCK, StaticTree.static_ltree);
bi_flush(); // Of the 10 bits for the empty block, we have already sent
// (10 - bi_valid) bits. The lookahead for the last real code (before
// the EOB of the previous block) was thus at least one plus the length
// of the EOB plus what we have just sent of the empty static block.
if (1 + last_eob_len + 10 - bi_valid < 9) {
send_bits(STATIC_TREES << 1, 3);
send_code(END_BLOCK, StaticTree.static_ltree);
bi_flush();
}
last_eob_len = 7;
} // Save the match info and tally the frequency counts. Return true if
// the current block must be flushed.
function _tr_tally(dist, // distance of matched string
lc // match length-MIN_MATCH or unmatched char (if dist==0)
) {
var out_length, in_length, dcode;
that.pending_buf[d_buf + last_lit * 2] = dist >>> 8 & 0xff;
that.pending_buf[d_buf + last_lit * 2 + 1] = dist & 0xff;
that.pending_buf[l_buf + last_lit] = lc & 0xff;
last_lit++;
if (dist === 0) {
// lc is the unmatched char
dyn_ltree[lc * 2]++;
} else {
matches++; // Here, lc is the match length - MIN_MATCH
dist--; // dist = match distance - 1
dyn_ltree[(Tree._length_code[lc] + LITERALS + 1) * 2]++;
dyn_dtree[Tree.d_code(dist) * 2]++;
}
if ((last_lit & 0x1fff) === 0 && level > 2) {
// Compute an upper bound for the compressed length
out_length = last_lit * 8;
in_length = strstart - block_start;
for (dcode = 0; dcode < D_CODES; dcode++) {
out_length += dyn_dtree[dcode * 2] * (5 + Tree.extra_dbits[dcode]);
}
out_length >>>= 3;
if (matches < Math.floor(last_lit / 2) && out_length < Math.floor(in_length / 2)) return true;
}
return last_lit == lit_bufsize - 1; // We avoid equality with lit_bufsize because of wraparound at 64K
// on 16 bit machines and because stored blocks are restricted to
// 64K-1 bytes.
} // Send the block data compressed using the given Huffman trees
function compress_block(ltree, dtree) {
var dist; // distance of matched string
var lc; // match length or unmatched char (if dist === 0)
var lx = 0; // running index in l_buf
var code; // the code to send
var extra; // number of extra bits to send
if (last_lit !== 0) {
do {
dist = that.pending_buf[d_buf + lx * 2] << 8 & 0xff00 | that.pending_buf[d_buf + lx * 2 + 1] & 0xff;
lc = that.pending_buf[l_buf + lx] & 0xff;
lx++;
if (dist === 0) {
send_code(lc, ltree); // send a literal byte
} else {
// Here, lc is the match length - MIN_MATCH
code = Tree._length_code[lc];
send_code(code + LITERALS + 1, ltree); // send the length
// code
extra = Tree.extra_lbits[code];
if (extra !== 0) {
lc -= Tree.base_length[code];
send_bits(lc, extra); // send the extra length bits
}
dist--; // dist is now the match distance - 1
code = Tree.d_code(dist);
send_code(code, dtree); // send the distance code
extra = Tree.extra_dbits[code];
if (extra !== 0) {
dist -= Tree.base_dist[code];
send_bits(dist, extra); // send the extra distance bits
}
} // literal or match pair ?
// Check that the overlay between pending_buf and d_buf+l_buf is
// ok:
} while (lx < last_lit);
}
send_code(END_BLOCK, ltree);
last_eob_len = ltree[END_BLOCK * 2 + 1];
} // Flush the bit buffer and align the output on a byte boundary
function bi_windup() {
if (bi_valid > 8) {
put_short(bi_buf);
} else if (bi_valid > 0) {
put_byte(bi_buf & 0xff);
}
bi_buf = 0;
bi_valid = 0;
} // Copy a stored block, storing first the length and its
// one's complement if requested.
function copy_block(buf, // the input data
len, // its length
header // true if block header must be written
) {
bi_windup(); // align on byte boundary
last_eob_len = 8; // enough lookahead for inflate
if (header) {
put_short(len);
put_short(~len);
}
that.pending_buf.set(window.subarray(buf, buf + len), that.pending);
that.pending += len;
} // Send a stored block
function _tr_stored_block(buf, // input block
stored_len, // length of input block
eof // true if this is the last block for a file
) {
send_bits((STORED_BLOCK << 1) + (eof ? 1 : 0), 3); // send block type
copy_block(buf, stored_len, true); // with header
} // Determine the best encoding for the current block: dynamic trees, static
// trees or store, and output the encoded block to the zip file.
function _tr_flush_block(buf, // input block, or NULL if too old
stored_len, // length of input block
eof // true if this is the last block for a file
) {
var opt_lenb, static_lenb; // opt_len and static_len in bytes
var max_blindex = 0; // index of last bit length code of non zero freq
// Build the Huffman trees unless a stored block is forced
if (level > 0) {
// Construct the literal and distance trees
l_desc.build_tree(that);
d_desc.build_tree(that); // At this point, opt_len and static_len are the total bit lengths
// of
// the compressed block data, excluding the tree representations.
// Build the bit length tree for the above two trees, and get the
// index
// in bl_order of the last bit length code to send.
max_blindex = build_bl_tree(); // Determine the best encoding. Compute first the block length in
// bytes
opt_lenb = that.opt_len + 3 + 7 >>> 3;
static_lenb = that.static_len + 3 + 7 >>> 3;
if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
} else {
opt_lenb = static_lenb = stored_len + 5; // force a stored block
}
if (stored_len + 4 <= opt_lenb && buf != -1) {
// 4: two words for the lengths
// The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
// Otherwise we can't have processed more than WSIZE input bytes
// since
// the last block flush, because compression would have been
// successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
// transform a block into a stored block.
_tr_stored_block(buf, stored_len, eof);
} else if (static_lenb == opt_lenb) {
send_bits((STATIC_TREES << 1) + (eof ? 1 : 0), 3);
compress_block(StaticTree.static_ltree, StaticTree.static_dtree);
} else {
send_bits((DYN_TREES << 1) + (eof ? 1 : 0), 3);
send_all_trees(l_desc.max_code + 1, d_desc.max_code + 1, max_blindex + 1);
compress_block(dyn_ltree, dyn_dtree);
} // The above check is made mod 2^32, for files larger than 512 MB
// and uLong implemented on 32 bits.
init_block();
if (eof) {
bi_windup();
}
}
function flush_block_only(eof) {
_tr_flush_block(block_start >= 0 ? block_start : -1, strstart - block_start, eof);
block_start = strstart;
strm.flush_pending();
} // Fill the window when the lookahead becomes insufficient.
// Updates strstart and lookahead.
//
// IN assertion: lookahead < MIN_LOOKAHEAD
// OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
// At least one byte has been read, or avail_in === 0; reads are
// performed for at least two bytes (required for the zip translate_eol
// option -- not supported here).
function fill_window() {
var n, m;
var p;
var more; // Amount of free space at the end of the window.
do {
more = window_size - lookahead - strstart; // Deal with !@#$% 64K limit:
if (more === 0 && strstart === 0 && lookahead === 0) {
more = w_size;
} else if (more == -1) {
// Very unlikely, but possible on 16 bit machine if strstart ==
// 0
// and lookahead == 1 (input done one byte at time)
more--; // If the window is almost full and there is insufficient
// lookahead,
// move the upper half to the lower one to make room in the
// upper half.
} else if (strstart >= w_size + w_size - MIN_LOOKAHEAD) {
window.set(window.subarray(w_size, w_size + w_size), 0);
match_start -= w_size;
strstart -= w_size; // we now have strstart >= MAX_DIST
block_start -= w_size; // Slide the hash table (could be avoided with 32 bit values
// at the expense of memory usage). We slide even when level ==
// 0
// to keep the hash table consistent if we switch back to level
// > 0
// later. (Using level 0 permanently is not an optimal usage of
// zlib, so we don't care about this pathological case.)
n = hash_size;
p = n;
do {
m = head[--p] & 0xffff;
head[p] = m >= w_size ? m - w_size : 0;
} while (--n !== 0);
n = w_size;
p = n;
do {
m = prev[--p] & 0xffff;
prev[p] = m >= w_size ? m - w_size : 0; // If n is not on any hash chain, prev[n] is garbage but
// its value will never be used.
} while (--n !== 0);
more += w_size;
}
if (strm.avail_in === 0) return; // If there was no sliding:
// strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
// more == window_size - lookahead - strstart
// => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
// => more >= window_size - 2*WSIZE + 2
// In the BIG_MEM or MMAP case (not yet supported),
// window_size == input_size + MIN_LOOKAHEAD &&
// strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
// Otherwise, window_size == 2*WSIZE so more >= 2.
// If there was sliding, more >= WSIZE. So in all cases, more >= 2.
n = strm.read_buf(window, strstart + lookahead, more);
lookahead += n; // Initialize the hash value now that we have some input:
if (lookahead >= MIN_MATCH) {
ins_h = window[strstart] & 0xff;
ins_h = (ins_h << hash_shift ^ window[strstart + 1] & 0xff) & hash_mask;
} // If the whole input has less than MIN_MATCH bytes, ins_h is
// garbage,
// but this is not important since only literal bytes will be
// emitted.
} while (lookahead < MIN_LOOKAHEAD && strm.avail_in !== 0);
} // Copy without compression as much as possible from the input stream,
// return
// the current block state.
// This function does not insert new strings in the dictionary since
// uncompressible data is probably not useful. This function is used
// only for the level=0 compression option.
// NOTE: this function should be optimized to avoid extra copying from
// window to pending_buf.
function deflate_stored(flush) {
// Stored blocks are limited to 0xffff bytes, pending_buf is limited
// to pending_buf_size, and each stored block has a 5 byte header:
var max_block_size = 0xffff;
var max_start;
if (max_block_size > pending_buf_size - 5) {
max_block_size = pending_buf_size - 5;
} // Copy as much as possible from input to output:
while (true) {
// Fill the window as much as possible:
if (lookahead <= 1) {
fill_window();
if (lookahead === 0 && flush == Z_NO_FLUSH) return NeedMore;
if (lookahead === 0) break; // flush the current block
}
strstart += lookahead;
lookahead = 0; // Emit a stored block if pending_buf will be full:
max_start = block_start + max_block_size;
if (strstart === 0 || strstart >= max_start) {
// strstart === 0 is possible when wraparound on 16-bit machine
lookahead = strstart - max_start;
strstart = max_start;
flush_block_only(false);
if (strm.avail_out === 0) return NeedMore;
} // Flush if we may have to slide, otherwise block_start may become
// negative and the data will be gone:
if (strstart - block_start >= w_size - MIN_LOOKAHEAD) {
flush_block_only(false);
if (strm.avail_out === 0) return NeedMore;
}
}
flush_block_only(flush == Z_FINISH);
if (strm.avail_out === 0) return flush == Z_FINISH ? FinishStarted : NeedMore;
return flush == Z_FINISH ? FinishDone : BlockDone;
}
function longest_match(cur_match) {
var chain_length = max_chain_length; // max hash chain length
var scan = strstart; // current string
var match; // matched string
var len; // length of current match
var best_len = prev_length; // best match length so far
var limit = strstart > w_size - MIN_LOOKAHEAD ? strstart - (w_size - MIN_LOOKAHEAD) : 0;
var _nice_match = nice_match; // Stop when cur_match becomes <= limit. To simplify the code,
// we prevent matches with the string of window index 0.
var wmask = w_mask;
var strend = strstart + MAX_MATCH;
var scan_end1 = window[scan + best_len - 1];
var scan_end = window[scan + best_len]; // The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of
// 16.
// It is easy to get rid of this optimization if necessary.
// Do not waste too much time if we already have a good match:
if (prev_length >= good_match) {
chain_length >>= 2;
} // Do not look for matches beyond the end of the input. This is
// necessary
// to make deflate deterministic.
if (_nice_match > lookahead) _nice_match = lookahead;
do {
match = cur_match; // Skip to next match if the match length cannot increase
// or if the match length is less than 2:
if (window[match + best_len] != scan_end || window[match + best_len - 1] != scan_end1 || window[match] != window[scan] || window[++match] != window[scan + 1]) continue; // The check at best_len-1 can be removed because it will be made
// again later. (This heuristic is not always a win.)
// It is not necessary to compare scan[2] and match[2] since they
// are always equal when the other bytes match, given that
// the hash keys are equal and that HASH_BITS >= 8.
scan += 2;
match++; // We check for insufficient lookahead only every 8th comparison;
// the 256th check will be made at strstart+258.
do {} while (window[++scan] == window[++match] && window[++scan] == window[++match] && window[++scan] == window[++match] && window[++scan] == window[++match] && window[++scan] == window[++match] && window[++scan] == window[++match] && window[++scan] == window[++match] && window[++scan] == window[++match] && scan < strend);
len = MAX_MATCH - (strend - scan);
scan = strend - MAX_MATCH;
if (len > best_len) {
match_start = cur_match;
best_len = len;
if (len >= _nice_match) break;
scan_end1 = window[scan + best_len - 1];
scan_end = window[scan + best_len];
}
} while ((cur_match = prev[cur_match & wmask] & 0xffff) > limit && --chain_length !== 0);
if (best_len <= lookahead) return best_len;
return lookahead;
} // Compress as much as possible from the input stream, return the current
// block state.
// This function does not perform lazy evaluation of matches and inserts
// new strings in the dictionary only for unmatched strings or for short
// matches. It is used only for the fast compression options.
function deflate_fast(flush) {
// short hash_head = 0; // head of the hash chain
var hash_head = 0; // head of the hash chain
var bflush; // set if current block must be flushed
while (true) {
// Make sure that we always have enough lookahead, except
// at the end of the input file. We need MAX_MATCH bytes
// for the next match, plus MIN_MATCH bytes to insert the
// string following the next match.
if (lookahead < MIN_LOOKAHEAD) {
fill_window();
if (lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
return NeedMore;
}
if (lookahead === 0) break; // flush the current block
} // Insert the string window[strstart .. strstart+2] in the
// dictionary, and set hash_head to the head of the hash chain:
if (lookahead >= MIN_MATCH) {
ins_h = (ins_h << hash_shift ^ window[strstart + (MIN_MATCH - 1)] & 0xff) & hash_mask; // prev[strstart&w_mask]=hash_head=head[ins_h];
hash_head = head[ins_h] & 0xffff;
prev[strstart & w_mask] = head[ins_h];
head[ins_h] = strstart;
} // Find the longest match, discarding those <= prev_length.
// At this point we have always match_length < MIN_MATCH
if (hash_head !== 0 && (strstart - hash_head & 0xffff) <= w_size - MIN_LOOKAHEAD) {
// To simplify the code, we prevent matches with the string
// of window index 0 (in particular we have to avoid a match
// of the string with itself at the start of the input file).
if (strategy != Z_HUFFMAN_ONLY) {
match_length = longest_match(hash_head);
} // longest_match() sets match_start
}
if (match_length >= MIN_MATCH) {
// check_match(strstart, match_start, match_length);
bflush = _tr_tally(strstart - match_start, match_length - MIN_MATCH);
lookahead -= match_length; // Insert new strings in the hash table only if the match length
// is not too large. This saves time but degrades compression.
if (match_length <= max_lazy_match && lookahead >= MIN_MATCH) {
match_length--; // string at strstart already in hash table
do {
strstart++;
ins_h = (ins_h << hash_shift ^ window[strstart + (MIN_MATCH - 1)] & 0xff) & hash_mask; // prev[strstart&w_mask]=hash_head=head[ins_h];
hash_head = head[ins_h] & 0xffff;
prev[strstart & w_mask] = head[ins_h];
head[ins_h] = strstart; // strstart never exceeds WSIZE-MAX_MATCH, so there are
// always MIN_MATCH bytes ahead.
} while (--match_length !== 0);
strstart++;
} else {
strstart += match_length;
match_length = 0;
ins_h = window[strstart] & 0xff;
ins_h = (ins_h << hash_shift ^ window[strstart + 1] & 0xff) & hash_mask; // If lookahead < MIN_MATCH, ins_h is garbage, but it does
// not
// matter since it will be recomputed at next deflate call.
}
} else {
// No match, output a literal byte
bflush = _tr_tally(0, window[strstart] & 0xff);
lookahead--;
strstart++;
}
if (bflush) {
flush_block_only(false);
if (strm.avail_out === 0) return NeedMore;
}
}
flush_block_only(flush == Z_FINISH);
if (strm.avail_out === 0) {
if (flush == Z_FINISH) return FinishStarted;else return NeedMore;
}
return flush == Z_FINISH ? FinishDone : BlockDone;
} // Same as above, but achieves better compression. We use a lazy
// evaluation for matches: a match is finally adopted only if there is
// no better match at the next window position.
function deflate_slow(flush) {
// short hash_head = 0; // head of hash chain
var hash_head = 0; // head of hash chain
var bflush; // set if current block must be flushed
var max_insert; // Process the input block.
while (true) {
// Make sure that we always have enough lookahead, except
// at the end of the input file. We need MAX_MATCH bytes
// for the next match, plus MIN_MATCH bytes to insert the
// string following the next match.
if (lookahead < MIN_LOOKAHEAD) {
fill_window();
if (lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
return NeedMore;
}
if (lookahead === 0) break; // flush the current block
} // Insert the string window[strstart .. strstart+2] in the
// dictionary, and set hash_head to the head of the hash chain:
if (lookahead >= MIN_MATCH) {
ins_h = (ins_h << hash_shift ^ window[strstart + (MIN_MATCH - 1)] & 0xff) & hash_mask; // prev[strstart&w_mask]=hash_head=head[ins_h];
hash_head = head[ins_h] & 0xffff;
prev[strstart & w_mask] = head[ins_h];
head[ins_h] = strstart;
} // Find the longest match, discarding those <= prev_length.
prev_length = match_length;
prev_match = match_start;
match_length = MIN_MATCH - 1;
if (hash_head !== 0 && prev_length < max_lazy_match && (strstart - hash_head & 0xffff) <= w_size - MIN_LOOKAHEAD) {
// To simplify the code, we prevent matches with the string
// of window index 0 (in particular we have to avoid a match
// of the string with itself at the start of the input file).
if (strategy != Z_HUFFMAN_ONLY) {
match_length = longest_match(hash_head);
} // longest_match() sets match_start
if (match_length <= 5 && (strategy == Z_FILTERED || match_length == MIN_MATCH && strstart - match_start > 4096)) {
// If prev_match is also MIN_MATCH, match_start is garbage
// but we will ignore the current match anyway.
match_length = MIN_MATCH - 1;
}
} // If there was a match at the previous step and the current
// match is not better, output the previous match:
if (prev_length >= MIN_MATCH && match_length <= prev_length) {
max_insert = strstart + lookahead - MIN_MATCH; // Do not insert strings in hash table beyond this.
// check_match(strstart-1, prev_match, prev_length);
bflush = _tr_tally(strstart - 1 - prev_match, prev_length - MIN_MATCH); // Insert in hash table all strings up to the end of the match.
// strstart-1 and strstart are already inserted. If there is not
// enough lookahead, the last two strings are not inserted in
// the hash table.
lookahead -= prev_length - 1;
prev_length -= 2;
do {
if (++strstart <= max_insert) {
ins_h = (ins_h << hash_shift ^ window[strstart + (MIN_MATCH - 1)] & 0xff) & hash_mask; // prev[strstart&w_mask]=hash_head=head[ins_h];
hash_head = head[ins_h] & 0xffff;
prev[strstart & w_mask] = head[ins_h];
head[ins_h] = strstart;
}
} while (--prev_length !== 0);
match_available = 0;
match_length = MIN_MATCH - 1;
strstart++;
if (bflush) {
flush_block_only(false);
if (strm.avail_out === 0) return NeedMore;
}
} else if (match_available !== 0) {
// If there was no match at the previous position, output a
// single literal. If there was a match but the current match
// is longer, truncate the previous match to a single literal.
bflush = _tr_tally(0, window[strstart - 1] & 0xff);
if (bflush) {
flush_block_only(false);
}
strstart++;
lookahead--;
if (strm.avail_out === 0) return NeedMore;
} else {
// There is no previous match to compare with, wait for
// the next step to decide.
match_available = 1;
strstart++;
lookahead--;
}
}
if (match_available !== 0) {
bflush = _tr_tally(0, window[strstart - 1] & 0xff);
match_available = 0;
}
flush_block_only(flush == Z_FINISH);
if (strm.avail_out === 0) {
if (flush == Z_FINISH) return FinishStarted;else return NeedMore;
}
return flush == Z_FINISH ? FinishDone : BlockDone;
}
function deflateReset(strm) {
strm.total_in = strm.total_out = 0;
strm.msg = null; //
that.pending = 0;
that.pending_out = 0;
status = BUSY_STATE;
last_flush = Z_NO_FLUSH;
tr_init();
lm_init();
return Z_OK;
}
that.deflateInit = function (strm, _level, bits, _method, memLevel, _strategy) {
if (!_method) _method = Z_DEFLATED;
if (!memLevel) memLevel = DEF_MEM_LEVEL;
if (!_strategy) _strategy = Z_DEFAULT_STRATEGY; // byte[] my_version=ZLIB_VERSION;
//
// if (!version || version[0] != my_version[0]
// || stream_size != sizeof(z_stream)) {
// return Z_VERSION_ERROR;
// }
strm.msg = null;
if (_level == Z_DEFAULT_COMPRESSION) _level = 6;
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || _method != Z_DEFLATED || bits < 9 || bits > 15 || _level < 0 || _level > 9 || _strategy < 0 || _strategy > Z_HUFFMAN_ONLY) {
return Z_STREAM_ERROR;
}
strm.dstate = that;
w_bits = bits;
w_size = 1 << w_bits;
w_mask = w_size - 1;
hash_bits = memLevel + 7;
hash_size = 1 << hash_bits;
hash_mask = hash_size - 1;
hash_shift = Math.floor((hash_bits + MIN_MATCH - 1) / MIN_MATCH);
window = new Uint8Array(w_size * 2);
prev = [];
head = [];
lit_bufsize = 1 << memLevel + 6; // 16K elements by default
// We overlay pending_buf and d_buf+l_buf. This works since the average
// output size for (length,distance) codes is <= 24 bits.
that.pending_buf = new Uint8Array(lit_bufsize * 4);
pending_buf_size = lit_bufsize * 4;
d_buf = Math.floor(lit_bufsize / 2);
l_buf = (1 + 2) * lit_bufsize;
level = _level;
strategy = _strategy;
return deflateReset(strm);
};
that.deflateEnd = function () {
if (status != INIT_STATE && status != BUSY_STATE && status != FINISH_STATE) {
return Z_STREAM_ERROR;
} // Deallocate in reverse order of allocations:
that.pending_buf = null;
head = null;
prev = null;
window = null; // free
that.dstate = null;
return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
};
that.deflateParams = function (strm, _level, _strategy) {
var err = Z_OK;
if (_level == Z_DEFAULT_COMPRESSION) {
_level = 6;
}
if (_level < 0 || _level > 9 || _strategy < 0 || _strategy > Z_HUFFMAN_ONLY) {
return Z_STREAM_ERROR;
}
if (config_table[level].func != config_table[_level].func && strm.total_in !== 0) {
// Flush the last buffer:
err = strm.deflate(Z_PARTIAL_FLUSH);
}
if (level != _level) {
level = _level;
max_lazy_match = config_table[level].max_lazy;
good_match = config_table[level].good_length;
nice_match = config_table[level].nice_length;
max_chain_length = config_table[level].max_chain;
}
strategy = _strategy;
return err;
};
that.deflateSetDictionary = function (strm, dictionary, dictLength) {
var length = dictLength;
var n,
index = 0;
if (!dictionary || status != INIT_STATE) return Z_STREAM_ERROR;
if (length < MIN_MATCH) return Z_OK;
if (length > w_size - MIN_LOOKAHEAD) {
length = w_size - MIN_LOOKAHEAD;
index = dictLength - length; // use the tail of the dictionary
}
window.set(dictionary.subarray(index, index + length), 0);
strstart = length;
block_start = length; // Insert all strings in the hash table (except for the last two bytes).
// s->lookahead stays null, so s->ins_h will be recomputed at the next
// call of fill_window.
ins_h = window[0] & 0xff;
ins_h = (ins_h << hash_shift ^ window[1] & 0xff) & hash_mask;
for (n = 0; n <= length - MIN_MATCH; n++) {
ins_h = (ins_h << hash_shift ^ window[n + (MIN_MATCH - 1)] & 0xff) & hash_mask;
prev[n & w_mask] = head[ins_h];
head[ins_h] = n;
}
return Z_OK;
};
that.deflate = function (_strm, flush) {
var i, header, level_flags, old_flush, bstate;
if (flush > Z_FINISH || flush < 0) {
return Z_STREAM_ERROR;
}
if (!_strm.next_out || !_strm.next_in && _strm.avail_in !== 0 || status == FINISH_STATE && flush != Z_FINISH) {
_strm.msg = z_errmsg[Z_NEED_DICT - Z_STREAM_ERROR];
return Z_STREAM_ERROR;
}
if (_strm.avail_out === 0) {
_strm.msg = z_errmsg[Z_NEED_DICT - Z_BUF_ERROR];
return Z_BUF_ERROR;
}
strm = _strm; // just in case
old_flush = last_flush;
last_flush = flush; // Write the zlib header
if (status == INIT_STATE) {
header = Z_DEFLATED + (w_bits - 8 << 4) << 8;
level_flags = (level - 1 & 0xff) >> 1;
if (level_flags > 3) level_flags = 3;
header |= level_flags << 6;
if (strstart !== 0) header |= PRESET_DICT;
header += 31 - header % 31;
status = BUSY_STATE;
putShortMSB(header);
} // Flush as much pending output as possible
if (that.pending !== 0) {
strm.flush_pending();
if (strm.avail_out === 0) {
// console.log(" avail_out==0");
// Since avail_out is 0, deflate will be called again with
// more output space, but possibly with both pending and
// avail_in equal to zero. There won't be anything to do,
// but this is not an error situation so make sure we
// return OK instead of BUF_ERROR at next call of deflate:
last_flush = -1;
return Z_OK;
} // Make sure there is something to do and avoid duplicate
// consecutive
// flushes. For repeated and useless calls with Z_FINISH, we keep
// returning Z_STREAM_END instead of Z_BUFF_ERROR.
} else if (strm.avail_in === 0 && flush <= old_flush && flush != Z_FINISH) {
strm.msg = z_errmsg[Z_NEED_DICT - Z_BUF_ERROR];
return Z_BUF_ERROR;
} // User must not provide more input after the first FINISH:
if (status == FINISH_STATE && strm.avail_in !== 0) {
_strm.msg = z_errmsg[Z_NEED_DICT - Z_BUF_ERROR];
return Z_BUF_ERROR;
} // Start a new block or continue the current one.
if (strm.avail_in !== 0 || lookahead !== 0 || flush != Z_NO_FLUSH && status != FINISH_STATE) {
bstate = -1;
switch (config_table[level].func) {
case STORED:
bstate = deflate_stored(flush);
break;
case FAST:
bstate = deflate_fast(flush);
break;
case SLOW:
bstate = deflate_slow(flush);
break;
default:
}
if (bstate == FinishStarted || bstate == FinishDone) {
status = FINISH_STATE;
}
if (bstate == NeedMore || bstate == FinishStarted) {
if (strm.avail_out === 0) {
last_flush = -1; // avoid BUF_ERROR next call, see above
}
return Z_OK; // If flush != Z_NO_FLUSH && avail_out === 0, the next call
// of deflate should use the same flush parameter to make sure
// that the flush is complete. So we don't have to output an
// empty block here, this will be done at next call. This also
// ensures that for a very small output buffer, we emit at most
// one empty block.
}
if (bstate == BlockDone) {
if (flush == Z_PARTIAL_FLUSH) {
_tr_align();
} else {
// FULL_FLUSH or SYNC_FLUSH
_tr_stored_block(0, 0, false); // For a full flush, this empty block will be recognized
// as a special marker by inflate_sync().
if (flush == Z_FULL_FLUSH) {
// state.head[s.hash_size-1]=0;
for (i = 0; i < hash_size
/*-1*/
; i++) // forget history
head[i] = 0;
}
}
strm.flush_pending();
if (strm.avail_out === 0) {
last_flush = -1; // avoid BUF_ERROR at next call, see above
return Z_OK;
}
}
}
if (flush != Z_FINISH) return Z_OK;
return Z_STREAM_END;
};
} // ZStream
function ZStream() {
var that = this;
that.next_in_index = 0;
that.next_out_index = 0; // that.next_in; // next input byte
that.avail_in = 0; // number of bytes available at next_in
that.total_in = 0; // total nb of input bytes read so far
// that.next_out; // next output byte should be put there
that.avail_out = 0; // remaining free space at next_out
that.total_out = 0; // total nb of bytes output so far
// that.msg;
// that.dstate;
}
ZStream.prototype = {
deflateInit: function (level, bits) {
var that = this;
that.dstate = new Deflate();
if (!bits) bits = MAX_BITS;
return that.dstate.deflateInit(that, level, bits);
},
deflate: function (flush) {
var that = this;
if (!that.dstate) {
return Z_STREAM_ERROR;
}
return that.dstate.deflate(that, flush);
},
deflateEnd: function () {
var that = this;
if (!that.dstate) return Z_STREAM_ERROR;
var ret = that.dstate.deflateEnd();
that.dstate = null;
return ret;
},
deflateParams: function (level, strategy) {
var that = this;
if (!that.dstate) return Z_STREAM_ERROR;
return that.dstate.deflateParams(that, level, strategy);
},
deflateSetDictionary: function (dictionary, dictLength) {
var that = this;
if (!that.dstate) return Z_STREAM_ERROR;
return that.dstate.deflateSetDictionary(that, dictionary, dictLength);
},
// Read a new buffer from the current input stream, update the
// total number of bytes read. All deflate() input goes through
// this function so some applications may wish to modify it to avoid
// allocating a large strm->next_in buffer and copying from it.
// (See also flush_pending()).
read_buf: function (buf, start, size) {
var that = this;
var len = that.avail_in;
if (len > size) len = size;
if (len === 0) return 0;
that.avail_in -= len;
buf.set(that.next_in.subarray(that.next_in_index, that.next_in_index + len), start);
that.next_in_index += len;
that.total_in += len;
return len;
},
// Flush as much pending output as possible. All deflate() output goes
// through this function so some applications may wish to modify it
// to avoid allocating a large strm->next_out buffer and copying into it.
// (See also read_buf()).
flush_pending: function () {
var that = this;
var len = that.dstate.pending;
if (len > that.avail_out) len = that.avail_out;
if (len === 0) return; // if (that.dstate.pending_buf.length <= that.dstate.pending_out || that.next_out.length <= that.next_out_index
// || that.dstate.pending_buf.length < (that.dstate.pending_out + len) || that.next_out.length < (that.next_out_index +
// len)) {
// console.log(that.dstate.pending_buf.length + ", " + that.dstate.pending_out + ", " + that.next_out.length + ", " +
// that.next_out_index + ", " + len);
// console.log("avail_out=" + that.avail_out);
// }
that.next_out.set(that.dstate.pending_buf.subarray(that.dstate.pending_out, that.dstate.pending_out + len), that.next_out_index);
that.next_out_index += len;
that.dstate.pending_out += len;
that.total_out += len;
that.avail_out -= len;
that.dstate.pending -= len;
if (that.dstate.pending === 0) {
that.dstate.pending_out = 0;
}
}
}; // Deflater
function Deflater(options) {
var that = this;
var z = new ZStream();
var bufsize = 512;
var flush = Z_NO_FLUSH;
var buf = new Uint8Array(bufsize);
var level = options ? options.level : Z_DEFAULT_COMPRESSION;
if (typeof level == "undefined") level = Z_DEFAULT_COMPRESSION;
z.deflateInit(level);
z.next_out = buf;
that.append = function (data, onprogress) {
var err,
buffers = [],
lastIndex = 0,
bufferIndex = 0,
bufferSize = 0,
array;
if (!data.length) return;
z.next_in_index = 0;
z.next_in = data;
z.avail_in = data.length;
do {
z.next_out_index = 0;
z.avail_out = bufsize;
err = z.deflate(flush);
if (err != Z_OK) throw new Error("deflating: " + z.msg);
if (z.next_out_index) if (z.next_out_index == bufsize) buffers.push(new Uint8Array(buf));else buffers.push(new Uint8Array(buf.subarray(0, z.next_out_index)));
bufferSize += z.next_out_index;
if (onprogress && z.next_in_index > 0 && z.next_in_index != lastIndex) {
onprogress(z.next_in_index);
lastIndex = z.next_in_index;
}
} while (z.avail_in > 0 || z.avail_out === 0);
array = new Uint8Array(bufferSize);
buffers.forEach(function (chunk) {
array.set(chunk, bufferIndex);
bufferIndex += chunk.length;
});
return array;
};
that.flush = function () {
var err,
buffers = [],
bufferIndex = 0,
bufferSize = 0,
array;
do {
z.next_out_index = 0;
z.avail_out = bufsize;
err = z.deflate(Z_FINISH);
if (err != Z_STREAM_END && err != Z_OK) throw new Error("deflating: " + z.msg);
if (bufsize - z.avail_out > 0) buffers.push(new Uint8Array(buf.subarray(0, z.next_out_index)));
bufferSize += z.next_out_index;
} while (z.avail_in > 0 || z.avail_out === 0);
z.deflateEnd();
array = new Uint8Array(bufferSize);
buffers.forEach(function (chunk) {
array.set(chunk, bufferIndex);
bufferIndex += chunk.length;
});
return array;
};
} // 'zip' may not be defined in z-worker and some tests
var env = global.zip || global;
env.Deflater = env._jzlib_Deflater = Deflater;
})(typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function("return this")()); // `self` is undefined in Firefox for Android content script context
// while `this` is nsIContentFrameMessageManager
// with an attribute `content` that corresponds to the window
/**
* A class to parse color values
* @author Stoyan Stefanov <sstoo@gmail.com>
* @link http://www.phpied.com/rgb-color-parser-in-javascript/
* @license Use it if you like it
*/
(function (global) {
function RGBColor(color_string) {
this.ok = false; // strip any leading #
if (color_string.charAt(0) == "#") {
// remove # if any
color_string = color_string.substr(1, 6);
}
color_string = color_string.replace(/ /g, "");
color_string = color_string.toLowerCase();
var channels; // before getting into regexps, try simple matches
// and overwrite the input
var simple_colors = {
aliceblue: "f0f8ff",
antiquewhite: "faebd7",
aqua: "00ffff",
aquamarine: "7fffd4",
azure: "f0ffff",
beige: "f5f5dc",
bisque: "ffe4c4",
black: "000000",
blanchedalmond: "ffebcd",
blue: "0000ff",
blueviolet: "8a2be2",
brown: "a52a2a",
burlywood: "deb887",
cadetblue: "5f9ea0",
chartreuse: "7fff00",
chocolate: "d2691e",
coral: "ff7f50",
cornflowerblue: "6495ed",
cornsilk: "fff8dc",
crimson: "dc143c",
cyan: "00ffff",
darkblue: "00008b",
darkcyan: "008b8b",
darkgoldenrod: "b8860b",
darkgray: "a9a9a9",
darkgreen: "006400",
darkkhaki: "bdb76b",
darkmagenta: "8b008b",
darkolivegreen: "556b2f",
darkorange: "ff8c00",
darkorchid: "9932cc",
darkred: "8b0000",
darksalmon: "e9967a",
darkseagreen: "8fbc8f",
darkslateblue: "483d8b",
darkslategray: "2f4f4f",
darkturquoise: "00ced1",
darkviolet: "9400d3",
deeppink: "ff1493",
deepskyblue: "00bfff",
dimgray: "696969",
dodgerblue: "1e90ff",
feldspar: "d19275",
firebrick: "b22222",
floralwhite: "fffaf0",
forestgreen: "228b22",
fuchsia: "ff00ff",
gainsboro: "dcdcdc",
ghostwhite: "f8f8ff",
gold: "ffd700",
goldenrod: "daa520",
gray: "808080",
green: "008000",
greenyellow: "adff2f",
honeydew: "f0fff0",
hotpink: "ff69b4",
indianred: "cd5c5c",
indigo: "4b0082",
ivory: "fffff0",
khaki: "f0e68c",
lavender: "e6e6fa",
lavenderblush: "fff0f5",
lawngreen: "7cfc00",
lemonchiffon: "fffacd",
lightblue: "add8e6",
lightcoral: "f08080",
lightcyan: "e0ffff",
lightgoldenrodyellow: "fafad2",
lightgrey: "d3d3d3",
lightgreen: "90ee90",
lightpink: "ffb6c1",
lightsalmon: "ffa07a",
lightseagreen: "20b2aa",
lightskyblue: "87cefa",
lightslateblue: "8470ff",
lightslategray: "778899",
lightsteelblue: "b0c4de",
lightyellow: "ffffe0",
lime: "00ff00",
limegreen: "32cd32",
linen: "faf0e6",
magenta: "ff00ff",
maroon: "800000",
mediumaquamarine: "66cdaa",
mediumblue: "0000cd",
mediumorchid: "ba55d3",
mediumpurple: "9370d8",
mediumseagreen: "3cb371",
mediumslateblue: "7b68ee",
mediumspringgreen: "00fa9a",
mediumturquoise: "48d1cc",
mediumvioletred: "c71585",
midnightblue: "191970",
mintcream: "f5fffa",
mistyrose: "ffe4e1",
moccasin: "ffe4b5",
navajowhite: "ffdead",
navy: "000080",
oldlace: "fdf5e6",
olive: "808000",
olivedrab: "6b8e23",
orange: "ffa500",
orangered: "ff4500",
orchid: "da70d6",
palegoldenrod: "eee8aa",
palegreen: "98fb98",
paleturquoise: "afeeee",
palevioletred: "d87093",
papayawhip: "ffefd5",
peachpuff: "ffdab9",
peru: "cd853f",
pink: "ffc0cb",
plum: "dda0dd",
powderblue: "b0e0e6",
purple: "800080",
red: "ff0000",
rosybrown: "bc8f8f",
royalblue: "4169e1",
saddlebrown: "8b4513",
salmon: "fa8072",
sandybrown: "f4a460",
seagreen: "2e8b57",
seashell: "fff5ee",
sienna: "a0522d",
silver: "c0c0c0",
skyblue: "87ceeb",
slateblue: "6a5acd",
slategray: "708090",
snow: "fffafa",
springgreen: "00ff7f",
steelblue: "4682b4",
tan: "d2b48c",
teal: "008080",
thistle: "d8bfd8",
tomato: "ff6347",
turquoise: "40e0d0",
violet: "ee82ee",
violetred: "d02090",
wheat: "f5deb3",
white: "ffffff",
whitesmoke: "f5f5f5",
yellow: "ffff00",
yellowgreen: "9acd32"
};
for (var key in simple_colors) {
if (color_string == key) {
color_string = simple_colors[key];
}
} // emd of simple type-in colors
// array of color definition objects
var color_defs = [{
re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
example: ["rgb(123, 234, 45)", "rgb(255,234,245)"],
process: function (bits) {
return [parseInt(bits[1]), parseInt(bits[2]), parseInt(bits[3])];
}
}, {
re: /^(\w{2})(\w{2})(\w{2})$/,
example: ["#00ff00", "336699"],
process: function (bits) {
return [parseInt(bits[1], 16), parseInt(bits[2], 16), parseInt(bits[3], 16)];
}
}, {
re: /^(\w{1})(\w{1})(\w{1})$/,
example: ["#fb0", "f0f"],
process: function (bits) {
return [parseInt(bits[1] + bits[1], 16), parseInt(bits[2] + bits[2], 16), parseInt(bits[3] + bits[3], 16)];
}
}]; // search through the definitions to find a match
for (var i = 0; i < color_defs.length; i++) {
var re = color_defs[i].re;
var processor = color_defs[i].process;
var bits = re.exec(color_string);
if (bits) {
channels = processor(bits);
this.r = channels[0];
this.g = channels[1];
this.b = channels[2];
this.ok = true;
}
} // validate/cleanup values
this.r = this.r < 0 || isNaN(this.r) ? 0 : this.r > 255 ? 255 : this.r;
this.g = this.g < 0 || isNaN(this.g) ? 0 : this.g > 255 ? 255 : this.g;
this.b = this.b < 0 || isNaN(this.b) ? 0 : this.b > 255 ? 255 : this.b; // some getters
this.toRGB = function () {
return "rgb(" + this.r + ", " + this.g + ", " + this.b + ")";
};
this.toHex = function () {
var r = this.r.toString(16);
var g = this.g.toString(16);
var b = this.b.toString(16);
if (r.length == 1) r = "0" + r;
if (g.length == 1) g = "0" + g;
if (b.length == 1) b = "0" + b;
return "#" + r + g + b;
}; // help
this.getHelpXML = function () {
var examples = new Array(); // add regexps
for (var i = 0; i < color_defs.length; i++) {
var example = color_defs[i].example;
for (var j = 0; j < example.length; j++) {
examples[examples.length] = example[j];
}
} // add type-in colors
for (var sc in simple_colors) {
examples[examples.length] = sc;
}
var xml = document.createElement("ul");
xml.setAttribute("id", "rgbcolor-examples");
for (var i = 0; i < examples.length; i++) {
try {
var list_item = document.createElement("li");
var list_color = new RGBColor(examples[i]);
var example_div = document.createElement("div");
example_div.style.cssText = "margin: 3px; " + "border: 1px solid black; " + "background:" + list_color.toHex() + "; " + "color:" + list_color.toHex();
example_div.appendChild(document.createTextNode("test"));
var list_item_value = document.createTextNode(" " + examples[i] + " -> " + list_color.toRGB() + " -> " + list_color.toHex());
list_item.appendChild(example_div);
list_item.appendChild(list_item_value);
xml.appendChild(list_item);
} catch (e) {}
}
return xml;
};
}
global.RGBColor = RGBColor;
})(typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function("return this")()); // `self` is undefined in Firefox for Android content script context
// while `this` is nsIContentFrameMessageManager
// with an attribute `content` that corresponds to the window
/************************************************
* Title : custom font *
* Start Data : 2017. 01. 22. *
* Comment : TEXT API *
************************************************/
/******************************
* jsPDF extension API Design *
* ****************************/
(function (jsPDF) {
var PLUS = "+".charCodeAt(0);
var SLASH = "/".charCodeAt(0);
var NUMBER = "0".charCodeAt(0);
var LOWER = "a".charCodeAt(0);
var UPPER = "A".charCodeAt(0);
var PLUS_URL_SAFE = "-".charCodeAt(0);
var SLASH_URL_SAFE = "_".charCodeAt(0);
/*****************************************************************/
/* function : b64ToByteArray */
/* comment : Base64 encoded TTF file contents (b64) are decoded */
/* by Byte array and stored. */
/*****************************************************************/
var b64ToByteArray = function (b64) {
var i, j, l, tmp, placeHolders, arr;
if (b64.length % 4 > 0) {
throw new Error("Invalid string. Length must be a multiple of 4");
} // the number of equal signs (place holders)
// if there are two placeholders, than the two characters before it
// represent one byte
// if there is only one, then the three characters before it represent 2 bytes
// this is just a cheap hack to not do indexOf twice
var len = b64.length;
placeHolders = "=" === b64.charAt(len - 2) ? 2 : "=" === b64.charAt(len - 1) ? 1 : 0; // base64 is 4/3 + up to two characters of the original data
arr = new Uint8Array(b64.length * 3 / 4 - placeHolders); // if there are placeholders, only get up to the last complete 4 chars
l = placeHolders > 0 ? b64.length - 4 : b64.length;
var L = 0;
function push(v) {
arr[L++] = v;
}
for (i = 0, j = 0; i < l; i += 4, j += 3) {
tmp = decode(b64.charAt(i)) << 18 | decode(b64.charAt(i + 1)) << 12 | decode(b64.charAt(i + 2)) << 6 | decode(b64.charAt(i + 3));
push((tmp & 0xff0000) >> 16);
push((tmp & 0xff00) >> 8);
push(tmp & 0xff);
}
if (placeHolders === 2) {
tmp = decode(b64.charAt(i)) << 2 | decode(b64.charAt(i + 1)) >> 4;
push(tmp & 0xff);
} else if (placeHolders === 1) {
tmp = decode(b64.charAt(i)) << 10 | decode(b64.charAt(i + 1)) << 4 | decode(b64.charAt(i + 2)) >> 2;
push(tmp >> 8 & 0xff);
push(tmp & 0xff);
}
return arr;
};
/***************************************************************/
/* function : decode */
/* comment : Change the base64 encoded font's content to match */
/* the base64 index value. */
/***************************************************************/
var decode = function (elt) {
var code = elt.charCodeAt(0);
if (code === PLUS || code === PLUS_URL_SAFE) return 62; // '+'
if (code === SLASH || code === SLASH_URL_SAFE) return 63; // '/'
if (code < NUMBER) return -1; //no match
if (code < NUMBER + 10) return code - NUMBER + 26 + 26;
if (code < UPPER + 26) return code - UPPER;
if (code < LOWER + 26) return code - LOWER + 26;
};
jsPDF.API.TTFFont = function () {
/************************************************************************/
/* function : open */
/* comment : Decode the encoded ttf content and create a TTFFont object. */
/************************************************************************/
TTFFont.open = function (filename, name, vfs, encoding) {
var contents;
if (typeof vfs !== "string") {
throw new Error("Invalid argument supplied in TTFFont.open");
}
contents = b64ToByteArray(vfs);
return new TTFFont(contents, name, encoding);
};
/***************************************************************/
/* function : TTFFont gernerator */
/* comment : Decode TTF contents are parsed, Data, */
/* Subset object is created, and registerTTF function is called.*/
/***************************************************************/
function TTFFont(rawData, name, encoding) {
var data;
this.rawData = rawData;
data = this.contents = new Data(rawData);
this.contents.pos = 4;
if (data.readString(4) === "ttcf") {
if (!name) {
throw new Error("Must specify a font name for TTC files.");
}
throw new Error("Font " + name + " not found in TTC file.");
} else {
data.pos = 0;
this.parse();
this.subset = new Subset(this);
this.registerTTF();
}
}
/********************************************************/
/* function : parse */
/* comment : TTF Parses the file contents by each table.*/
/********************************************************/
TTFFont.prototype.parse = function () {
this.directory = new Directory(this.contents);
this.head = new HeadTable(this);
this.name = new NameTable(this);
this.cmap = new CmapTable(this);
this.toUnicode = new Map();
this.hhea = new HheaTable(this);
this.maxp = new MaxpTable(this);
this.hmtx = new HmtxTable(this);
this.post = new PostTable(this);
this.os2 = new OS2Table(this);
this.loca = new LocaTable(this);
this.glyf = new GlyfTable(this);
this.ascender = this.os2.exists && this.os2.ascender || this.hhea.ascender;
this.decender = this.os2.exists && this.os2.decender || this.hhea.decender;
this.lineGap = this.os2.exists && this.os2.lineGap || this.hhea.lineGap;
return this.bbox = [this.head.xMin, this.head.yMin, this.head.xMax, this.head.yMax];
};
/***************************************************************/
/* function : registerTTF */
/* comment : Get the value to assign pdf font descriptors. */
/***************************************************************/
TTFFont.prototype.registerTTF = function () {
var e, hi, low, raw, _ref;
this.scaleFactor = 1000.0 / this.head.unitsPerEm;
this.bbox = function () {
var _i, _len, _ref, _results;
_ref = this.bbox;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
e = _ref[_i];
_results.push(Math.round(e * this.scaleFactor));
}
return _results;
}.call(this);
this.stemV = 0;
if (this.post.exists) {
raw = this.post.italic_angle;
hi = raw >> 16;
low = raw & 0xff;
if (hi & 0x8000 !== 0) {
hi = -((hi ^ 0xffff) + 1);
}
this.italicAngle = +("" + hi + "." + low);
} else {
this.italicAngle = 0;
}
this.ascender = Math.round(this.ascender * this.scaleFactor);
this.decender = Math.round(this.decender * this.scaleFactor);
this.lineGap = Math.round(this.lineGap * this.scaleFactor);
this.capHeight = this.os2.exists && this.os2.capHeight || this.ascender;
this.xHeight = this.os2.exists && this.os2.xHeight || 0;
this.familyClass = (this.os2.exists && this.os2.familyClass || 0) >> 8;
this.isSerif = (_ref = this.familyClass) === 1 || _ref === 2 || _ref === 3 || _ref === 4 || _ref === 5 || _ref === 7;
this.isScript = this.familyClass === 10;
this.flags = 0;
if (this.post.isFixedPitch) {
this.flags |= 1 << 0;
}
if (this.isSerif) {
this.flags |= 1 << 1;
}
if (this.isScript) {
this.flags |= 1 << 3;
}
if (this.italicAngle !== 0) {
this.flags |= 1 << 6;
}
this.flags |= 1 << 5;
if (!this.cmap.unicode) {
throw new Error("No unicode cmap for font");
}
};
TTFFont.prototype.characterToGlyph = function (character) {
var _ref;
return ((_ref = this.cmap.unicode) != null ? _ref.codeMap[character] : void 0) || 0;
};
TTFFont.prototype.widthOfGlyph = function (glyph) {
var scale;
scale = 1000.0 / this.head.unitsPerEm;
return this.hmtx.forGlyph(glyph).advance * scale;
};
TTFFont.prototype.widthOfString = function (string, size, charSpace) {
var charCode, i, scale, width, _i, _ref, charSpace;
string = "" + string;
width = 0;
for (i = _i = 0, _ref = string.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
charCode = string.charCodeAt(i);
width += this.widthOfGlyph(this.characterToGlyph(charCode)) + charSpace * (1000 / size) || 0;
}
scale = size / 1000;
return width * scale;
};
TTFFont.prototype.lineHeight = function (size, includeGap) {
var gap;
if (includeGap == null) {
includeGap = false;
}
gap = includeGap ? this.lineGap : 0;
return (this.ascender + gap - this.decender) / 1000 * size;
};
return TTFFont;
}();
/************************************************************************************************/
/* function : Data */
/* comment : The ttf data decoded and stored in an array is read and written to the Data object.*/
/************************************************************************************************/
var Data = function () {
function Data(data) {
this.data = data != null ? data : [];
this.pos = 0;
this.length = this.data.length;
}
Data.prototype.readByte = function () {
return this.data[this.pos++];
};
Data.prototype.writeByte = function (byte) {
return this.data[this.pos++] = byte;
};
Data.prototype.readUInt32 = function () {
var b1, b2, b3, b4;
b1 = this.readByte() * 0x1000000;
b2 = this.readByte() << 16;
b3 = this.readByte() << 8;
b4 = this.readByte();
return b1 + b2 + b3 + b4;
};
Data.prototype.writeUInt32 = function (val) {
this.writeByte(val >>> 24 & 0xff);
this.writeByte(val >> 16 & 0xff);
this.writeByte(val >> 8 & 0xff);
return this.writeByte(val & 0xff);
};
Data.prototype.readInt32 = function () {
var int;
int = this.readUInt32();
if (int >= 0x80000000) {
return int - 0x100000000;
} else {
return int;
}
};
Data.prototype.writeInt32 = function (val) {
if (val < 0) {
val += 0x100000000;
}
return this.writeUInt32(val);
};
Data.prototype.readUInt16 = function () {
var b1, b2;
b1 = this.readByte() << 8;
b2 = this.readByte();
return b1 | b2;
};
Data.prototype.writeUInt16 = function (val) {
this.writeByte(val >> 8 & 0xff);
return this.writeByte(val & 0xff);
};
Data.prototype.readInt16 = function () {
var int;
int = this.readUInt16();
if (int >= 0x8000) {
return int - 0x10000;
} else {
return int;
}
};
Data.prototype.writeInt16 = function (val) {
if (val < 0) {
val += 0x10000;
}
return this.writeUInt16(val);
};
Data.prototype.readString = function (length) {
var i, ret, _i;
ret = [];
for (i = _i = 0; 0 <= length ? _i < length : _i > length; i = 0 <= length ? ++_i : --_i) {
ret[i] = String.fromCharCode(this.readByte());
}
return ret.join("");
};
Data.prototype.writeString = function (val) {
var i, _i, _ref, _results;
_results = [];
for (i = _i = 0, _ref = val.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
_results.push(this.writeByte(val.charCodeAt(i)));
}
return _results;
};
/*Data.prototype.stringAt = function (pos, length) {
this.pos = pos;
return this.readString(length);
};*/
Data.prototype.readShort = function () {
return this.readInt16();
};
Data.prototype.writeShort = function (val) {
return this.writeInt16(val);
};
Data.prototype.readLongLong = function () {
var b1, b2, b3, b4, b5, b6, b7, b8;
b1 = this.readByte();
b2 = this.readByte();
b3 = this.readByte();
b4 = this.readByte();
b5 = this.readByte();
b6 = this.readByte();
b7 = this.readByte();
b8 = this.readByte();
if (b1 & 0x80) {
return ((b1 ^ 0xff) * 0x100000000000000 + (b2 ^ 0xff) * 0x1000000000000 + (b3 ^ 0xff) * 0x10000000000 + (b4 ^ 0xff) * 0x100000000 + (b5 ^ 0xff) * 0x1000000 + (b6 ^ 0xff) * 0x10000 + (b7 ^ 0xff) * 0x100 + (b8 ^ 0xff) + 1) * -1;
}
return b1 * 0x100000000000000 + b2 * 0x1000000000000 + b3 * 0x10000000000 + b4 * 0x100000000 + b5 * 0x1000000 + b6 * 0x10000 + b7 * 0x100 + b8;
};
Data.prototype.writeLongLong = function (val) {
var high, low;
high = Math.floor(val / 0x100000000);
low = val & 0xffffffff;
this.writeByte(high >> 24 & 0xff);
this.writeByte(high >> 16 & 0xff);
this.writeByte(high >> 8 & 0xff);
this.writeByte(high & 0xff);
this.writeByte(low >> 24 & 0xff);
this.writeByte(low >> 16 & 0xff);
this.writeByte(low >> 8 & 0xff);
return this.writeByte(low & 0xff);
};
Data.prototype.readInt = function () {
return this.readInt32();
};
Data.prototype.writeInt = function (val) {
return this.writeInt32(val);
};
/*Data.prototype.slice = function (start, end) {
return this.data.slice(start, end);
};*/
Data.prototype.read = function (bytes) {
var buf, i, _i;
buf = [];
for (i = _i = 0; 0 <= bytes ? _i < bytes : _i > bytes; i = 0 <= bytes ? ++_i : --_i) {
buf.push(this.readByte());
}
return buf;
};
Data.prototype.write = function (bytes) {
var byte, _i, _len, _results;
_results = [];
for (_i = 0, _len = bytes.length; _i < _len; _i++) {
byte = bytes[_i];
_results.push(this.writeByte(byte));
}
return _results;
};
return Data;
}();
var Directory = function () {
var checksum;
/*****************************************************************************************************/
/* function : Directory generator */
/* comment : Initialize the offset, tag, length, and checksum for each table for the font to be used.*/
/*****************************************************************************************************/
function Directory(data) {
var entry, i, _i, _ref;
this.scalarType = data.readInt();
this.tableCount = data.readShort();
this.searchRange = data.readShort();
this.entrySelector = data.readShort();
this.rangeShift = data.readShort();
this.tables = {};
for (i = _i = 0, _ref = this.tableCount; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
entry = {
tag: data.readString(4),
checksum: data.readInt(),
offset: data.readInt(),
length: data.readInt()
};
this.tables[entry.tag] = entry;
}
}
/********************************************************************************************************/
/* function : encode */
/* comment : It encodes and stores the font table object and information used for the directory object. */
/********************************************************************************************************/
Directory.prototype.encode = function (tables) {
var adjustment, directory, directoryLength, entrySelector, headOffset, log2, offset, rangeShift, searchRange, sum, table, tableCount, tableData, tag;
tableCount = Object.keys(tables).length;
log2 = Math.log(2);
searchRange = Math.floor(Math.log(tableCount) / log2) * 16;
entrySelector = Math.floor(searchRange / log2);
rangeShift = tableCount * 16 - searchRange;
directory = new Data();
directory.writeInt(this.scalarType);
directory.writeShort(tableCount);
directory.writeShort(searchRange);
directory.writeShort(entrySelector);
directory.writeShort(rangeShift);
directoryLength = tableCount * 16;
offset = directory.pos + directoryLength;
headOffset = null;
tableData = [];
for (tag in tables) {
table = tables[tag];
directory.writeString(tag);
directory.writeInt(checksum(table));
directory.writeInt(offset);
directory.writeInt(table.length);
tableData = tableData.concat(table);
if (tag === "head") {
headOffset = offset;
}
offset += table.length;
while (offset % 4) {
tableData.push(0);
offset++;
}
}
directory.write(tableData);
sum = checksum(directory.data);
adjustment = 0xb1b0afba - sum;
directory.pos = headOffset + 8;
directory.writeUInt32(adjustment);
return directory.data;
};
/***************************************************************/
/* function : checksum */
/* comment : Duplicate the table for the tag. */
/***************************************************************/
checksum = function (data) {
var i, sum, tmp, _i, _ref;
data = __slice.call(data);
while (data.length % 4) {
data.push(0);
}
tmp = new Data(data);
sum = 0;
for (i = _i = 0, _ref = data.length; _i < _ref; i = _i += 4) {
sum += tmp.readUInt32();
}
return sum & 0xffffffff;
};
return Directory;
}();
var Table,
__hasProp = {}.hasOwnProperty,
__extends = function (child, parent) {
for (var key in parent) {
if (__hasProp.call(parent, key)) child[key] = parent[key];
}
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor();
child.__super__ = parent.prototype;
return child;
};
/***************************************************************/
/* function : Table */
/* comment : Save info for each table, and parse the table. */
/***************************************************************/
Table = function () {
function Table(file) {
var info;
this.file = file;
info = this.file.directory.tables[this.tag];
this.exists = !!info;
if (info) {
this.offset = info.offset, this.length = info.length;
this.parse(this.file.contents);
}
}
Table.prototype.parse = function () {};
Table.prototype.encode = function () {};
Table.prototype.raw = function () {
if (!this.exists) {
return null;
}
this.file.contents.pos = this.offset;
return this.file.contents.read(this.length);
};
return Table;
}();
var HeadTable = function (_super) {
__extends(HeadTable, _super);
function HeadTable() {
return HeadTable.__super__.constructor.apply(this, arguments);
}
HeadTable.prototype.tag = "head";
HeadTable.prototype.parse = function (data) {
data.pos = this.offset;
this.version = data.readInt();
this.revision = data.readInt();
this.checkSumAdjustment = data.readInt();
this.magicNumber = data.readInt();
this.flags = data.readShort();
this.unitsPerEm = data.readShort();
this.created = data.readLongLong();
this.modified = data.readLongLong();
this.xMin = data.readShort();
this.yMin = data.readShort();
this.xMax = data.readShort();
this.yMax = data.readShort();
this.macStyle = data.readShort();
this.lowestRecPPEM = data.readShort();
this.fontDirectionHint = data.readShort();
this.indexToLocFormat = data.readShort();
return this.glyphDataFormat = data.readShort();
};
HeadTable.prototype.encode = function (indexToLocFormat) {
var table;
table = new Data();
table.writeInt(this.version);
table.writeInt(this.revision);
table.writeInt(this.checkSumAdjustment);
table.writeInt(this.magicNumber);
table.writeShort(this.flags);
table.writeShort(this.unitsPerEm);
table.writeLongLong(this.created);
table.writeLongLong(this.modified);
table.writeShort(this.xMin);
table.writeShort(this.yMin);
table.writeShort(this.xMax);
table.writeShort(this.yMax);
table.writeShort(this.macStyle);
table.writeShort(this.lowestRecPPEM);
table.writeShort(this.fontDirectionHint);
table.writeShort(indexToLocFormat);
table.writeShort(this.glyphDataFormat);
return table.data;
};
return HeadTable;
}(Table);
/************************************************************************************/
/* function : CmapEntry */
/* comment : Cmap Initializes and encodes object information (required by pdf spec).*/
/************************************************************************************/
var CmapEntry = function () {
function CmapEntry(data, offset) {
var code, count, endCode, glyphId, glyphIds, i, idDelta, idRangeOffset, index, saveOffset, segCount, segCountX2, start, startCode, tail, _i, _j, _k, _len;
this.platformID = data.readUInt16();
this.encodingID = data.readShort();
this.offset = offset + data.readInt();
saveOffset = data.pos;
data.pos = this.offset;
this.format = data.readUInt16();
this.length = data.readUInt16();
this.language = data.readUInt16();
this.isUnicode = this.platformID === 3 && this.encodingID === 1 && this.format === 4 || this.platformID === 0 && this.format === 4;
this.codeMap = {};
switch (this.format) {
case 0:
for (i = _i = 0; _i < 256; i = ++_i) {
this.codeMap[i] = data.readByte();
}
break;
case 4:
segCountX2 = data.readUInt16();
segCount = segCountX2 / 2;
data.pos += 6;
endCode = function () {
var _j, _results;
_results = [];
for (i = _j = 0; 0 <= segCount ? _j < segCount : _j > segCount; i = 0 <= segCount ? ++_j : --_j) {
_results.push(data.readUInt16());
}
return _results;
}();
data.pos += 2;
startCode = function () {
var _j, _results;
_results = [];
for (i = _j = 0; 0 <= segCount ? _j < segCount : _j > segCount; i = 0 <= segCount ? ++_j : --_j) {
_results.push(data.readUInt16());
}
return _results;
}();
idDelta = function () {
var _j, _results;
_results = [];
for (i = _j = 0; 0 <= segCount ? _j < segCount : _j > segCount; i = 0 <= segCount ? ++_j : --_j) {
_results.push(data.readUInt16());
}
return _results;
}();
idRangeOffset = function () {
var _j, _results;
_results = [];
for (i = _j = 0; 0 <= segCount ? _j < segCount : _j > segCount; i = 0 <= segCount ? ++_j : --_j) {
_results.push(data.readUInt16());
}
return _results;
}();
count = (this.length - data.pos + this.offset) / 2;
glyphIds = function () {
var _j, _results;
_results = [];
for (i = _j = 0; 0 <= count ? _j < count : _j > count; i = 0 <= count ? ++_j : --_j) {
_results.push(data.readUInt16());
}
return _results;
}();
for (i = _j = 0, _len = endCode.length; _j < _len; i = ++_j) {
tail = endCode[i];
start = startCode[i];
for (code = _k = start; start <= tail ? _k <= tail : _k >= tail; code = start <= tail ? ++_k : --_k) {
if (idRangeOffset[i] === 0) {
glyphId = code + idDelta[i];
} else {
index = idRangeOffset[i] / 2 + (code - start) - (segCount - i);
glyphId = glyphIds[index] || 0;
if (glyphId !== 0) {
glyphId += idDelta[i];
}
}
this.codeMap[code] = glyphId & 0xffff;
}
}
}
data.pos = saveOffset;
}
CmapEntry.encode = function (charmap, encoding) {
var charMap, code, codeMap, codes, delta, deltas, diff, endCode, endCodes, entrySelector, glyphIDs, i, id, indexes, last, map, nextID, offset, old, rangeOffsets, rangeShift, result, searchRange, segCount, segCountX2, startCode, startCodes, startGlyph, subtable, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _len6, _len7, _m, _n, _name, _o, _p, _q;
subtable = new Data();
codes = Object.keys(charmap).sort(function (a, b) {
return a - b;
});
switch (encoding) {
case "macroman":
id = 0;
indexes = function () {
var _i, _results;
_results = [];
for (i = _i = 0; _i < 256; i = ++_i) {
_results.push(0);
}
return _results;
}();
map = {
0: 0
};
codeMap = {};
for (_i = 0, _len = codes.length; _i < _len; _i++) {
code = codes[_i];
if (map[_name = charmap[code]] == null) {
map[_name] = ++id;
}
codeMap[code] = {
old: charmap[code],
new: map[charmap[code]]
};
indexes[code] = map[charmap[code]];
}
subtable.writeUInt16(1);
subtable.writeUInt16(0);
subtable.writeUInt32(12);
subtable.writeUInt16(0);
subtable.writeUInt16(262);
subtable.writeUInt16(0);
subtable.write(indexes);
return result = {
charMap: codeMap,
subtable: subtable.data,
maxGlyphID: id + 1
};
case "unicode":
startCodes = [];
endCodes = [];
nextID = 0;
map = {};
charMap = {};
last = diff = null;
for (_j = 0, _len1 = codes.length; _j < _len1; _j++) {
code = codes[_j];
old = charmap[code];
if (map[old] == null) {
map[old] = ++nextID;
}
charMap[code] = {
old: old,
new: map[old]
};
delta = map[old] - code;
if (last == null || delta !== diff) {
if (last) {
endCodes.push(last);
}
startCodes.push(code);
diff = delta;
}
last = code;
}
if (last) {
endCodes.push(last);
}
endCodes.push(0xffff);
startCodes.push(0xffff);
segCount = startCodes.length;
segCountX2 = segCount * 2;
searchRange = 2 * Math.pow(Math.log(segCount) / Math.LN2, 2);
entrySelector = Math.log(searchRange / 2) / Math.LN2;
rangeShift = 2 * segCount - searchRange;
deltas = [];
rangeOffsets = [];
glyphIDs = [];
for (i = _k = 0, _len2 = startCodes.length; _k < _len2; i = ++_k) {
startCode = startCodes[i];
endCode = endCodes[i];
if (startCode === 0xffff) {
deltas.push(0);
rangeOffsets.push(0);
break;
}
startGlyph = charMap[startCode]["new"];
if (startCode - startGlyph >= 0x8000) {
deltas.push(0);
rangeOffsets.push(2 * (glyphIDs.length + segCount - i));
for (code = _l = startCode; startCode <= endCode ? _l <= endCode : _l >= endCode; code = startCode <= endCode ? ++_l : --_l) {
glyphIDs.push(charMap[code]["new"]);
}
} else {
deltas.push(startGlyph - startCode);
rangeOffsets.push(0);
}
}
subtable.writeUInt16(3);
subtable.writeUInt16(1);
subtable.writeUInt32(12);
subtable.writeUInt16(4);
subtable.writeUInt16(16 + segCount * 8 + glyphIDs.length * 2);
subtable.writeUInt16(0);
subtable.writeUInt16(segCountX2);
subtable.writeUInt16(searchRange);
subtable.writeUInt16(entrySelector);
subtable.writeUInt16(rangeShift);
for (_m = 0, _len3 = endCodes.length; _m < _len3; _m++) {
code = endCodes[_m];
subtable.writeUInt16(code);
}
subtable.writeUInt16(0);
for (_n = 0, _len4 = startCodes.length; _n < _len4; _n++) {
code = startCodes[_n];
subtable.writeUInt16(code);
}
for (_o = 0, _len5 = deltas.length; _o < _len5; _o++) {
delta = deltas[_o];
subtable.writeUInt16(delta);
}
for (_p = 0, _len6 = rangeOffsets.length; _p < _len6; _p++) {
offset = rangeOffsets[_p];
subtable.writeUInt16(offset);
}
for (_q = 0, _len7 = glyphIDs.length; _q < _len7; _q++) {
id = glyphIDs[_q];
subtable.writeUInt16(id);
}
return result = {
charMap: charMap,
subtable: subtable.data,
maxGlyphID: nextID + 1
};
}
};
return CmapEntry;
}();
var CmapTable = function (_super) {
__extends(CmapTable, _super);
function CmapTable() {
return CmapTable.__super__.constructor.apply(this, arguments);
}
CmapTable.prototype.tag = "cmap";
CmapTable.prototype.parse = function (data) {
var entry, i, tableCount, _i;
data.pos = this.offset;
this.version = data.readUInt16();
tableCount = data.readUInt16();
this.tables = [];
this.unicode = null;
for (i = _i = 0; 0 <= tableCount ? _i < tableCount : _i > tableCount; i = 0 <= tableCount ? ++_i : --_i) {
entry = new CmapEntry(data, this.offset);
this.tables.push(entry);
if (entry.isUnicode) {
if (this.unicode == null) {
this.unicode = entry;
}
}
}
return true;
};
/*************************************************************************/
/* function : encode */
/* comment : Encode the cmap table corresponding to the input character. */
/*************************************************************************/
CmapTable.encode = function (charmap, encoding) {
var result, table;
if (encoding == null) {
encoding = "macroman";
}
result = CmapEntry.encode(charmap, encoding);
table = new Data();
table.writeUInt16(0);
table.writeUInt16(1);
result.table = table.data.concat(result.subtable);
return result;
};
return CmapTable;
}(Table);
var HheaTable = function (_super) {
__extends(HheaTable, _super);
function HheaTable() {
return HheaTable.__super__.constructor.apply(this, arguments);
}
HheaTable.prototype.tag = "hhea";
HheaTable.prototype.parse = function (data) {
data.pos = this.offset;
this.version = data.readInt();
this.ascender = data.readShort();
this.decender = data.readShort();
this.lineGap = data.readShort();
this.advanceWidthMax = data.readShort();
this.minLeftSideBearing = data.readShort();
this.minRightSideBearing = data.readShort();
this.xMaxExtent = data.readShort();
this.caretSlopeRise = data.readShort();
this.caretSlopeRun = data.readShort();
this.caretOffset = data.readShort();
data.pos += 4 * 2;
this.metricDataFormat = data.readShort();
return this.numberOfMetrics = data.readUInt16();
};
/*HheaTable.prototype.encode = function (ids) {
var i, table, _i, _ref;
table = new Data;
table.writeInt(this.version);
table.writeShort(this.ascender);
table.writeShort(this.decender);
table.writeShort(this.lineGap);
table.writeShort(this.advanceWidthMax);
table.writeShort(this.minLeftSideBearing);
table.writeShort(this.minRightSideBearing);
table.writeShort(this.xMaxExtent);
table.writeShort(this.caretSlopeRise);
table.writeShort(this.caretSlopeRun);
table.writeShort(this.caretOffset);
for (i = _i = 0, _ref = 4 * 2; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
table.writeByte(0);
}
table.writeShort(this.metricDataFormat);
table.writeUInt16(ids.length);
return table.data;
};*/
return HheaTable;
}(Table);
var OS2Table = function (_super) {
__extends(OS2Table, _super);
function OS2Table() {
return OS2Table.__super__.constructor.apply(this, arguments);
}
OS2Table.prototype.tag = "OS/2";
OS2Table.prototype.parse = function (data) {
var i;
data.pos = this.offset;
this.version = data.readUInt16();
this.averageCharWidth = data.readShort();
this.weightClass = data.readUInt16();
this.widthClass = data.readUInt16();
this.type = data.readShort();
this.ySubscriptXSize = data.readShort();
this.ySubscriptYSize = data.readShort();
this.ySubscriptXOffset = data.readShort();
this.ySubscriptYOffset = data.readShort();
this.ySuperscriptXSize = data.readShort();
this.ySuperscriptYSize = data.readShort();
this.ySuperscriptXOffset = data.readShort();
this.ySuperscriptYOffset = data.readShort();
this.yStrikeoutSize = data.readShort();
this.yStrikeoutPosition = data.readShort();
this.familyClass = data.readShort();
this.panose = function () {
var _i, _results;
_results = [];
for (i = _i = 0; _i < 10; i = ++_i) {
_results.push(data.readByte());
}
return _results;
}();
this.charRange = function () {
var _i, _results;
_results = [];
for (i = _i = 0; _i < 4; i = ++_i) {
_results.push(data.readInt());
}
return _results;
}();
this.vendorID = data.readString(4);
this.selection = data.readShort();
this.firstCharIndex = data.readShort();
this.lastCharIndex = data.readShort();
if (this.version > 0) {
this.ascent = data.readShort();
this.descent = data.readShort();
this.lineGap = data.readShort();
this.winAscent = data.readShort();
this.winDescent = data.readShort();
this.codePageRange = function () {
var _i, _results;
_results = [];
for (i = _i = 0; _i < 2; i = ++_i) {
_results.push(data.readInt());
}
return _results;
}();
if (this.version > 1) {
this.xHeight = data.readShort();
this.capHeight = data.readShort();
this.defaultChar = data.readShort();
this.breakChar = data.readShort();
return this.maxContext = data.readShort();
}
}
};
/*OS2Table.prototype.encode = function () {
return this.raw();
};*/
return OS2Table;
}(Table);
var PostTable = function (_super) {
__extends(PostTable, _super);
function PostTable() {
return PostTable.__super__.constructor.apply(this, arguments);
}
PostTable.prototype.tag = "post";
PostTable.prototype.parse = function (data) {
var i, length, numberOfGlyphs, _i, _results;
data.pos = this.offset;
this.format = data.readInt();
this.italicAngle = data.readInt();
this.underlinePosition = data.readShort();
this.underlineThickness = data.readShort();
this.isFixedPitch = data.readInt();
this.minMemType42 = data.readInt();
this.maxMemType42 = data.readInt();
this.minMemType1 = data.readInt();
this.maxMemType1 = data.readInt();
switch (this.format) {
case 0x00010000:
break;
case 0x00020000:
numberOfGlyphs = data.readUInt16();
this.glyphNameIndex = [];
for (i = _i = 0; 0 <= numberOfGlyphs ? _i < numberOfGlyphs : _i > numberOfGlyphs; i = 0 <= numberOfGlyphs ? ++_i : --_i) {
this.glyphNameIndex.push(data.readUInt16());
}
this.names = [];
_results = [];
while (data.pos < this.offset + this.length) {
length = data.readByte();
_results.push(this.names.push(data.readString(length)));
}
return _results;
break;
case 0x00025000:
numberOfGlyphs = data.readUInt16();
return this.offsets = data.read(numberOfGlyphs);
case 0x00030000:
break;
case 0x00040000:
return this.map = function () {
var _j, _ref, _results1;
_results1 = [];
for (i = _j = 0, _ref = this.file.maxp.numGlyphs; 0 <= _ref ? _j < _ref : _j > _ref; i = 0 <= _ref ? ++_j : --_j) {
_results1.push(data.readUInt32());
}
return _results1;
}.call(this);
}
};
return PostTable;
}(Table);
/*********************************************************************************************************/
/* function : NameEntry */
/* comment : Store copyright information, platformID, encodingID, and languageID in the NameEntry object.*/
/*********************************************************************************************************/
var NameEntry = function () {
function NameEntry(raw, entry) {
this.raw = raw;
this.length = raw.length;
this.platformID = entry.platformID;
this.encodingID = entry.encodingID;
this.languageID = entry.languageID;
}
return NameEntry;
}();
var NameTable = function (_super) {
__extends(NameTable, _super);
function NameTable() {
return NameTable.__super__.constructor.apply(this, arguments);
}
NameTable.prototype.tag = "name";
NameTable.prototype.parse = function (data) {
var count, entries, entry, format, i, name, stringOffset, strings, text, _i, _j, _len, _name;
data.pos = this.offset;
format = data.readShort();
count = data.readShort();
stringOffset = data.readShort();
entries = [];
for (i = _i = 0; 0 <= count ? _i < count : _i > count; i = 0 <= count ? ++_i : --_i) {
entries.push({
platformID: data.readShort(),
encodingID: data.readShort(),
languageID: data.readShort(),
nameID: data.readShort(),
length: data.readShort(),
offset: this.offset + stringOffset + data.readShort()
});
}
strings = {};
for (i = _j = 0, _len = entries.length; _j < _len; i = ++_j) {
entry = entries[i];
data.pos = entry.offset;
text = data.readString(entry.length);
name = new NameEntry(text, entry);
if (strings[_name = entry.nameID] == null) {
strings[_name] = [];
}
strings[entry.nameID].push(name);
}
this.strings = strings;
this.copyright = strings[0];
this.fontFamily = strings[1];
this.fontSubfamily = strings[2];
this.uniqueSubfamily = strings[3];
this.fontName = strings[4];
this.version = strings[5];
try {
this.postscriptName = strings[6][0].raw.replace(/[\x00-\x19\x80-\xff]/g, "");
} catch (e) {
this.postscriptName = strings[4][0].raw.replace(/[\x00-\x19\x80-\xff]/g, "");
}
this.trademark = strings[7];
this.manufacturer = strings[8];
this.designer = strings[9];
this.description = strings[10];
this.vendorUrl = strings[11];
this.designerUrl = strings[12];
this.license = strings[13];
this.licenseUrl = strings[14];
this.preferredFamily = strings[15];
this.preferredSubfamily = strings[17];
this.compatibleFull = strings[18];
return this.sampleText = strings[19];
};
/*NameTable.prototype.encode = function () {
var id, list, nameID, nameTable, postscriptName, strCount, strTable, string, strings, table, val, _i, _len, _ref;
strings = {};
_ref = this.strings;
for (id in _ref) {
val = _ref[id];
strings[id] = val;
}
postscriptName = new NameEntry("" + subsetTag + "+" + this.postscriptName, {
platformID: 1
, encodingID: 0
, languageID: 0
});
strings[6] = [postscriptName];
subsetTag = successorOf(subsetTag);
strCount = 0;
for (id in strings) {
list = strings[id];
if (list != null) {
strCount += list.length;
}
}
table = new Data;
strTable = new Data;
table.writeShort(0);
table.writeShort(strCount);
table.writeShort(6 + 12 * strCount);
for (nameID in strings) {
list = strings[nameID];
if (list != null) {
for (_i = 0, _len = list.length; _i < _len; _i++) {
string = list[_i];
table.writeShort(string.platformID);
table.writeShort(string.encodingID);
table.writeShort(string.languageID);
table.writeShort(nameID);
table.writeShort(string.length);
table.writeShort(strTable.pos);
strTable.writeString(string.raw);
}
}
}
return nameTable = {
postscriptName: postscriptName.raw
, table: table.data.concat(strTable.data)
};
};*/
return NameTable;
}(Table);
var MaxpTable = function (_super) {
__extends(MaxpTable, _super);
function MaxpTable() {
return MaxpTable.__super__.constructor.apply(this, arguments);
}
MaxpTable.prototype.tag = "maxp";
MaxpTable.prototype.parse = function (data) {
data.pos = this.offset;
this.version = data.readInt();
this.numGlyphs = data.readUInt16();
this.maxPoints = data.readUInt16();
this.maxContours = data.readUInt16();
this.maxCompositePoints = data.readUInt16();
this.maxComponentContours = data.readUInt16();
this.maxZones = data.readUInt16();
this.maxTwilightPoints = data.readUInt16();
this.maxStorage = data.readUInt16();
this.maxFunctionDefs = data.readUInt16();
this.maxInstructionDefs = data.readUInt16();
this.maxStackElements = data.readUInt16();
this.maxSizeOfInstructions = data.readUInt16();
this.maxComponentElements = data.readUInt16();
return this.maxComponentDepth = data.readUInt16();
};
/*MaxpTable.prototype.encode = function (ids) {
var table;
table = new Data;
table.writeInt(this.version);
table.writeUInt16(ids.length);
table.writeUInt16(this.maxPoints);
table.writeUInt16(this.maxContours);
table.writeUInt16(this.maxCompositePoints);
table.writeUInt16(this.maxComponentContours);
table.writeUInt16(this.maxZones);
table.writeUInt16(this.maxTwilightPoints);
table.writeUInt16(this.maxStorage);
table.writeUInt16(this.maxFunctionDefs);
table.writeUInt16(this.maxInstructionDefs);
table.writeUInt16(this.maxStackElements);
table.writeUInt16(this.maxSizeOfInstructions);
table.writeUInt16(this.maxComponentElements);
table.writeUInt16(this.maxComponentDepth);
return table.data;
};*/
return MaxpTable;
}(Table);
var HmtxTable = function (_super) {
__extends(HmtxTable, _super);
function HmtxTable() {
return HmtxTable.__super__.constructor.apply(this, arguments);
}
HmtxTable.prototype.tag = "hmtx";
HmtxTable.prototype.parse = function (data) {
var i, last, lsbCount, m, _i, _j, _ref, _results;
data.pos = this.offset;
this.metrics = [];
for (i = _i = 0, _ref = this.file.hhea.numberOfMetrics; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
this.metrics.push({
advance: data.readUInt16(),
lsb: data.readInt16()
});
}
lsbCount = this.file.maxp.numGlyphs - this.file.hhea.numberOfMetrics;
this.leftSideBearings = function () {
var _j, _results;
_results = [];
for (i = _j = 0; 0 <= lsbCount ? _j < lsbCount : _j > lsbCount; i = 0 <= lsbCount ? ++_j : --_j) {
_results.push(data.readInt16());
}
return _results;
}();
this.widths = function () {
var _j, _len, _ref1, _results;
_ref1 = this.metrics;
_results = [];
for (_j = 0, _len = _ref1.length; _j < _len; _j++) {
m = _ref1[_j];
_results.push(m.advance);
}
return _results;
}.call(this);
last = this.widths[this.widths.length - 1];
_results = [];
for (i = _j = 0; 0 <= lsbCount ? _j < lsbCount : _j > lsbCount; i = 0 <= lsbCount ? ++_j : --_j) {
_results.push(this.widths.push(last));
}
return _results;
};
/***************************************************************/
/* function : forGlyph */
/* comment : Returns the advance width and lsb for this glyph. */
/***************************************************************/
HmtxTable.prototype.forGlyph = function (id) {
var metrics;
if (id in this.metrics) {
return this.metrics[id];
}
return metrics = {
advance: this.metrics[this.metrics.length - 1].advance,
lsb: this.leftSideBearings[id - this.metrics.length]
};
};
/*HmtxTable.prototype.encode = function (mapping) {
var id, metric, table, _i, _len;
table = new Data;
for (_i = 0, _len = mapping.length; _i < _len; _i++) {
id = mapping[_i];
metric = this.forGlyph(id);
table.writeUInt16(metric.advance);
table.writeUInt16(metric.lsb);
}
return table.data;
};*/
return HmtxTable;
}(Table);
var __slice = [].slice;
var GlyfTable = function (_super) {
__extends(GlyfTable, _super);
function GlyfTable() {
return GlyfTable.__super__.constructor.apply(this, arguments);
}
GlyfTable.prototype.tag = "glyf";
GlyfTable.prototype.parse = function (data) {
return this.cache = {};
};
GlyfTable.prototype.glyphFor = function (id) {
id = id;
var data, index, length, loca, numberOfContours, raw, xMax, xMin, yMax, yMin;
if (id in this.cache) {
return this.cache[id];
}
loca = this.file.loca;
data = this.file.contents;
index = loca.indexOf(id);
length = loca.lengthOf(id);
if (length === 0) {
return this.cache[id] = null;
}
data.pos = this.offset + index;
raw = new Data(data.read(length));
numberOfContours = raw.readShort();
xMin = raw.readShort();
yMin = raw.readShort();
xMax = raw.readShort();
yMax = raw.readShort();
if (numberOfContours === -1) {
this.cache[id] = new CompoundGlyph(raw, xMin, yMin, xMax, yMax);
} else {
this.cache[id] = new SimpleGlyph(raw, numberOfContours, xMin, yMin, xMax, yMax);
}
return this.cache[id];
};
GlyfTable.prototype.encode = function (glyphs, mapping, old2new) {
var glyph, id, offsets, table, _i, _len;
table = [];
offsets = [];
for (_i = 0, _len = mapping.length; _i < _len; _i++) {
id = mapping[_i];
glyph = glyphs[id];
offsets.push(table.length);
if (glyph) {
table = table.concat(glyph.encode(old2new));
}
}
offsets.push(table.length);
return {
table: table,
offsets: offsets
};
};
return GlyfTable;
}(Table);
var SimpleGlyph = function () {
/**************************************************************************/
/* function : SimpleGlyph */
/* comment : Stores raw, xMin, yMin, xMax, and yMax values for this glyph.*/
/**************************************************************************/
function SimpleGlyph(raw, numberOfContours, xMin, yMin, xMax, yMax) {
this.raw = raw;
this.numberOfContours = numberOfContours;
this.xMin = xMin;
this.yMin = yMin;
this.xMax = xMax;
this.yMax = yMax;
this.compound = false;
}
SimpleGlyph.prototype.encode = function () {
return this.raw.data;
};
return SimpleGlyph;
}();
var CompoundGlyph = function () {
var ARG_1_AND_2_ARE_WORDS, MORE_COMPONENTS, WE_HAVE_AN_X_AND_Y_SCALE, WE_HAVE_A_SCALE, WE_HAVE_A_TWO_BY_TWO;
ARG_1_AND_2_ARE_WORDS = 0x0001;
WE_HAVE_A_SCALE = 0x0008;
MORE_COMPONENTS = 0x0020;
WE_HAVE_AN_X_AND_Y_SCALE = 0x0040;
WE_HAVE_A_TWO_BY_TWO = 0x0080;
/********************************************************************************************************************/
/* function : CompoundGlypg generator */
/* comment : It stores raw, xMin, yMin, xMax, yMax, glyph id, and glyph offset for the corresponding compound glyph.*/
/********************************************************************************************************************/
function CompoundGlyph(raw, xMin, yMin, xMax, yMax) {
var data, flags;
this.raw = raw;
this.xMin = xMin;
this.yMin = yMin;
this.xMax = xMax;
this.yMax = yMax;
this.compound = true;
this.glyphIDs = [];
this.glyphOffsets = [];
data = this.raw;
while (true) {
flags = data.readShort();
this.glyphOffsets.push(data.pos);
this.glyphIDs.push(data.readShort());
if (!(flags & MORE_COMPONENTS)) {
break;
}
if (flags & ARG_1_AND_2_ARE_WORDS) {
data.pos += 4;
} else {
data.pos += 2;
}
if (flags & WE_HAVE_A_TWO_BY_TWO) {
data.pos += 8;
} else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) {
data.pos += 4;
} else if (flags & WE_HAVE_A_SCALE) {
data.pos += 2;
}
}
}
/****************************************************************************************************************/
/* function : CompoundGlypg encode */
/* comment : After creating a table for the characters you typed, you call directory.encode to encode the table.*/
/****************************************************************************************************************/
CompoundGlyph.prototype.encode = function (mapping) {
var i, id, result, _i, _len, _ref;
result = new Data(__slice.call(this.raw.data));
_ref = this.glyphIDs;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
id = _ref[i];
result.pos = this.glyphOffsets[i];
}
return result.data;
};
return CompoundGlyph;
}();
var LocaTable = function (_super) {
__extends(LocaTable, _super);
function LocaTable() {
return LocaTable.__super__.constructor.apply(this, arguments);
}
LocaTable.prototype.tag = "loca";
LocaTable.prototype.parse = function (data) {
var format, i;
data.pos = this.offset;
format = this.file.head.indexToLocFormat;
if (format === 0) {
return this.offsets = function () {
var _i, _ref, _results;
_results = [];
for (i = _i = 0, _ref = this.length; _i < _ref; i = _i += 2) {
_results.push(data.readUInt16() * 2);
}
return _results;
}.call(this);
} else {
return this.offsets = function () {
var _i, _ref, _results;
_results = [];
for (i = _i = 0, _ref = this.length; _i < _ref; i = _i += 4) {
_results.push(data.readUInt32());
}
return _results;
}.call(this);
}
};
LocaTable.prototype.indexOf = function (id) {
return this.offsets[id];
};
LocaTable.prototype.lengthOf = function (id) {
return this.offsets[id + 1] - this.offsets[id];
};
LocaTable.prototype.encode = function (offsets, activeGlyphs) {
var LocaTable = new Uint32Array(this.offsets.length);
var glyfPtr = 0;
var listGlyf = 0;
for (var k = 0; k < LocaTable.length; ++k) {
LocaTable[k] = glyfPtr;
if (listGlyf < activeGlyphs.length && activeGlyphs[listGlyf] == k) {
++listGlyf;
LocaTable[k] = glyfPtr;
var start = this.offsets[k];
var len = this.offsets[k + 1] - start;
if (len > 0) {
glyfPtr += len;
}
}
}
var newLocaTable = new Array(LocaTable.length * 4);
for (var j = 0; j < LocaTable.length; ++j) {
newLocaTable[4 * j + 3] = LocaTable[j] & 0x000000ff;
newLocaTable[4 * j + 2] = (LocaTable[j] & 0x0000ff00) >> 8;
newLocaTable[4 * j + 1] = (LocaTable[j] & 0x00ff0000) >> 16;
newLocaTable[4 * j] = (LocaTable[j] & 0xff000000) >> 24;
}
return newLocaTable;
};
return LocaTable;
}(Table);
/************************************************************************************/
/* function : invert */
/* comment : Change the object's (key: value) to create an object with (value: key).*/
/************************************************************************************/
var invert = function (object) {
var key, ret, val;
ret = {};
for (key in object) {
val = object[key];
ret[val] = key;
}
return ret;
};
/*var successorOf = function (input) {
var added, alphabet, carry, i, index, isUpperCase, last, length, next, result;
alphabet = 'abcdefghijklmnopqrstuvwxyz';
length = alphabet.length;
result = input;
i = input.length;
while (i >= 0) {
last = input.charAt(--i);
if (isNaN(last)) {
index = alphabet.indexOf(last.toLowerCase());
if (index === -1) {
next = last;
carry = true;
}
else {
next = alphabet.charAt((index + 1) % length);
isUpperCase = last === last.toUpperCase();
if (isUpperCase) {
next = next.toUpperCase();
}
carry = index + 1 >= length;
if (carry && i === 0) {
added = isUpperCase ? 'A' : 'a';
result = added + next + result.slice(1);
break;
}
}
}
else {
next = +last + 1;
carry = next > 9;
if (carry) {
next = 0;
}
if (carry && i === 0) {
result = '1' + next + result.slice(1);
break;
}
}
result = result.slice(0, i) + next + result.slice(i + 1);
if (!carry) {
break;
}
}
return result;
};*/
var Subset = function () {
function Subset(font) {
this.font = font;
this.subset = {};
this.unicodes = {};
this.next = 33;
}
/*Subset.prototype.use = function (character) {
var i, _i, _ref;
if (typeof character === 'string') {
for (i = _i = 0, _ref = character.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
this.use(character.charCodeAt(i));
}
return;
}
if (!this.unicodes[character]) {
this.subset[this.next] = character;
return this.unicodes[character] = this.next++;
}
};*/
/*Subset.prototype.encodeText = function (text) {
var char, i, string, _i, _ref;
string = '';
for (i = _i = 0, _ref = text.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
char = this.unicodes[text.charCodeAt(i)];
string += String.fromCharCode(char);
}
return string;
};*/
/***************************************************************/
/* function : generateCmap */
/* comment : Returns the unicode cmap for this font. */
/***************************************************************/
Subset.prototype.generateCmap = function () {
var mapping, roman, unicode, unicodeCmap, _ref;
unicodeCmap = this.font.cmap.tables[0].codeMap;
mapping = {};
_ref = this.subset;
for (roman in _ref) {
unicode = _ref[roman];
mapping[roman] = unicodeCmap[unicode];
}
return mapping;
};
/*Subset.prototype.glyphIDs = function () {
var ret, roman, unicode, unicodeCmap, val, _ref;
unicodeCmap = this.font.cmap.tables[0].codeMap;
ret = [0];
_ref = this.subset;
for (roman in _ref) {
unicode = _ref[roman];
val = unicodeCmap[unicode];
if ((val != null) && __indexOf.call(ret, val) < 0) {
ret.push(val);
}
}
return ret.sort();
};*/
/******************************************************************/
/* function : glyphsFor */
/* comment : Returns simple glyph objects for the input character.*/
/******************************************************************/
Subset.prototype.glyphsFor = function (glyphIDs) {
var additionalIDs, glyph, glyphs, id, _i, _len, _ref;
glyphs = {};
for (_i = 0, _len = glyphIDs.length; _i < _len; _i++) {
id = glyphIDs[_i];
glyphs[id] = this.font.glyf.glyphFor(id);
}
additionalIDs = [];
for (id in glyphs) {
glyph = glyphs[id];
if (glyph != null ? glyph.compound : void 0) {
additionalIDs.push.apply(additionalIDs, glyph.glyphIDs);
}
}
if (additionalIDs.length > 0) {
_ref = this.glyphsFor(additionalIDs);
for (id in _ref) {
glyph = _ref[id];
glyphs[id] = glyph;
}
}
return glyphs;
};
/***************************************************************/
/* function : encode */
/* comment : Encode various tables for the characters you use. */
/***************************************************************/
Subset.prototype.encode = function (glyID, indexToLocFormat) {
var cmap, code, glyf, glyphs, id, ids, loca, new2old, newIDs, nextGlyphID, old2new, oldID, oldIDs, tables, _ref;
cmap = CmapTable.encode(this.generateCmap(), "unicode");
glyphs = this.glyphsFor(glyID);
old2new = {
0: 0
};
_ref = cmap.charMap;
for (code in _ref) {
ids = _ref[code];
old2new[ids.old] = ids["new"];
}
nextGlyphID = cmap.maxGlyphID;
for (oldID in glyphs) {
if (!(oldID in old2new)) {
old2new[oldID] = nextGlyphID++;
}
}
new2old = invert(old2new);
newIDs = Object.keys(new2old).sort(function (a, b) {
return a - b;
});
oldIDs = function () {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = newIDs.length; _i < _len; _i++) {
id = newIDs[_i];
_results.push(new2old[id]);
}
return _results;
}();
glyf = this.font.glyf.encode(glyphs, oldIDs, old2new);
loca = this.font.loca.encode(glyf.offsets, oldIDs);
tables = {
cmap: this.font.cmap.raw(),
glyf: glyf.table,
loca: loca,
hmtx: this.font.hmtx.raw(),
hhea: this.font.hhea.raw(),
maxp: this.font.maxp.raw(),
post: this.font.post.raw(),
name: this.font.name.raw(),
head: this.font.head.encode(indexToLocFormat)
};
if (this.font.os2.exists) {
tables["OS/2"] = this.font.os2.raw();
}
return this.font.directory.encode(tables);
};
return Subset;
}();
jsPDF.API.PDFObject = function () {
var pad;
function PDFObject() {}
pad = function (str, length) {
return (Array(length + 1).join("0") + str).slice(-length);
};
/*****************************************************************************/
/* function : convert */
/* comment :Converts pdf tag's / FontBBox and array values in / W to strings */
/*****************************************************************************/
PDFObject.convert = function (object) {
var e, items, key, out, val;
if (Array.isArray(object)) {
items = function () {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = object.length; _i < _len; _i++) {
e = object[_i];
_results.push(PDFObject.convert(e));
}
return _results;
}().join(" ");
return "[" + items + "]";
} else if (typeof object === "string") {
return "/" + object;
} else if (object != null ? object.isString : void 0) {
return "(" + object + ")";
} else if (object instanceof Date) {
return "(D:" + pad(object.getUTCFullYear(), 4) + pad(object.getUTCMonth(), 2) + pad(object.getUTCDate(), 2) + pad(object.getUTCHours(), 2) + pad(object.getUTCMinutes(), 2) + pad(object.getUTCSeconds(), 2) + "Z)";
} else if ({}.toString.call(object) === "[object Object]") {
out = ["<<"];
for (key in object) {
val = object[key];
out.push("/" + key + " " + PDFObject.convert(val));
}
out.push(">>");
return out.join("\n");
} else {
return "" + object;
}
};
return PDFObject;
}();
})(jsPDF);
// Generated by CoffeeScript 1.4.0
/*
# PNG.js
# Copyright (c) 2011 Devon Govett
# MIT LICENSE
#
#
*/
(function (global) {
var PNG;
PNG = function () {
var APNG_BLEND_OP_SOURCE, APNG_DISPOSE_OP_BACKGROUND, APNG_DISPOSE_OP_PREVIOUS, makeImage, scratchCanvas, scratchCtx;
PNG.load = function (url, canvas, callback) {
var xhr;
if (typeof canvas === "function") {
callback = canvas;
}
xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "arraybuffer";
xhr.onload = function () {
var data, png;
data = new Uint8Array(xhr.response || xhr.mozResponseArrayBuffer);
png = new PNG(data);
if (typeof (canvas != null ? canvas.getContext : void 0) === "function") {
png.render(canvas);
}
return typeof callback === "function" ? callback(png) : void 0;
};
return xhr.send(null);
};
APNG_DISPOSE_OP_BACKGROUND = 1;
APNG_DISPOSE_OP_PREVIOUS = 2;
APNG_BLEND_OP_SOURCE = 0;
function PNG(data) {
var chunkSize, colors, palLen, delayDen, delayNum, frame, i, index, key, section, palShort, text, _i, _j, _ref;
this.data = data;
this.pos = 8;
this.palette = [];
this.imgData = [];
this.transparency = {};
this.animation = null;
this.text = {};
frame = null;
while (true) {
chunkSize = this.readUInt32();
section = function () {
var _i, _results;
_results = [];
for (i = _i = 0; _i < 4; i = ++_i) {
_results.push(String.fromCharCode(this.data[this.pos++]));
}
return _results;
}.call(this).join("");
switch (section) {
case "IHDR":
this.width = this.readUInt32();
this.height = this.readUInt32();
this.bits = this.data[this.pos++];
this.colorType = this.data[this.pos++];
this.compressionMethod = this.data[this.pos++];
this.filterMethod = this.data[this.pos++];
this.interlaceMethod = this.data[this.pos++];
break;
case "acTL":
this.animation = {
numFrames: this.readUInt32(),
numPlays: this.readUInt32() || Infinity,
frames: []
};
break;
case "PLTE":
this.palette = this.read(chunkSize);
break;
case "fcTL":
if (frame) {
this.animation.frames.push(frame);
}
this.pos += 4;
frame = {
width: this.readUInt32(),
height: this.readUInt32(),
xOffset: this.readUInt32(),
yOffset: this.readUInt32()
};
delayNum = this.readUInt16();
delayDen = this.readUInt16() || 100;
frame.delay = 1000 * delayNum / delayDen;
frame.disposeOp = this.data[this.pos++];
frame.blendOp = this.data[this.pos++];
frame.data = [];
break;
case "IDAT":
case "fdAT":
if (section === "fdAT") {
this.pos += 4;
chunkSize -= 4;
}
data = (frame != null ? frame.data : void 0) || this.imgData;
for (i = _i = 0; 0 <= chunkSize ? _i < chunkSize : _i > chunkSize; i = 0 <= chunkSize ? ++_i : --_i) {
data.push(this.data[this.pos++]);
}
break;
case "tRNS":
this.transparency = {};
switch (this.colorType) {
case 3:
palLen = this.palette.length / 3;
this.transparency.indexed = this.read(chunkSize);
if (this.transparency.indexed.length > palLen) throw new Error("More transparent colors than palette size");
/*
* According to the PNG spec trns should be increased to the same size as palette if shorter
*/
//palShort = 255 - this.transparency.indexed.length;
palShort = palLen - this.transparency.indexed.length;
if (palShort > 0) {
for (i = _j = 0; 0 <= palShort ? _j < palShort : _j > palShort; i = 0 <= palShort ? ++_j : --_j) {
this.transparency.indexed.push(255);
}
}
break;
case 0:
this.transparency.grayscale = this.read(chunkSize)[0];
break;
case 2:
this.transparency.rgb = this.read(chunkSize);
}
break;
case "tEXt":
text = this.read(chunkSize);
index = text.indexOf(0);
key = String.fromCharCode.apply(String, text.slice(0, index));
this.text[key] = String.fromCharCode.apply(String, text.slice(index + 1));
break;
case "IEND":
if (frame) {
this.animation.frames.push(frame);
}
this.colors = function () {
switch (this.colorType) {
case 0:
case 3:
case 4:
return 1;
case 2:
case 6:
return 3;
}
}.call(this);
this.hasAlphaChannel = (_ref = this.colorType) === 4 || _ref === 6;
colors = this.colors + (this.hasAlphaChannel ? 1 : 0);
this.pixelBitlength = this.bits * colors;
this.colorSpace = function () {
switch (this.colors) {
case 1:
return "DeviceGray";
case 3:
return "DeviceRGB";
}
}.call(this);
this.imgData = new Uint8Array(this.imgData);
return;
default:
this.pos += chunkSize;
}
this.pos += 4;
if (this.pos > this.data.length) {
throw new Error("Incomplete or corrupt PNG file");
}
}
return;
}
PNG.prototype.read = function (bytes) {
var i, _i, _results;
_results = [];
for (i = _i = 0; 0 <= bytes ? _i < bytes : _i > bytes; i = 0 <= bytes ? ++_i : --_i) {
_results.push(this.data[this.pos++]);
}
return _results;
};
PNG.prototype.readUInt32 = function () {
var b1, b2, b3, b4;
b1 = this.data[this.pos++] << 24;
b2 = this.data[this.pos++] << 16;
b3 = this.data[this.pos++] << 8;
b4 = this.data[this.pos++];
return b1 | b2 | b3 | b4;
};
PNG.prototype.readUInt16 = function () {
var b1, b2;
b1 = this.data[this.pos++] << 8;
b2 = this.data[this.pos++];
return b1 | b2;
};
PNG.prototype.decodePixels = function (data) {
var pixelBytes = this.pixelBitlength / 8;
var fullPixels = new Uint8Array(this.width * this.height * pixelBytes);
var pos = 0;
var _this = this;
if (data == null) {
data = this.imgData;
}
if (data.length === 0) {
return new Uint8Array(0);
}
data = new FlateStream(data);
data = data.getBytes();
function pass(x0, y0, dx, dy) {
var abyte, c, col, i, left, length, p, pa, paeth, pb, pc, pixels, row, scanlineLength, upper, upperLeft, _i, _j, _k, _l, _m;
var w = Math.ceil((_this.width - x0) / dx),
h = Math.ceil((_this.height - y0) / dy);
var isFull = _this.width == w && _this.height == h;
scanlineLength = pixelBytes * w;
pixels = isFull ? fullPixels : new Uint8Array(scanlineLength * h);
length = data.length;
row = 0;
c = 0;
while (row < h && pos < length) {
switch (data[pos++]) {
case 0:
for (i = _i = 0; _i < scanlineLength; i = _i += 1) {
pixels[c++] = data[pos++];
}
break;
case 1:
for (i = _j = 0; _j < scanlineLength; i = _j += 1) {
abyte = data[pos++];
left = i < pixelBytes ? 0 : pixels[c - pixelBytes];
pixels[c++] = (abyte + left) % 256;
}
break;
case 2:
for (i = _k = 0; _k < scanlineLength; i = _k += 1) {
abyte = data[pos++];
col = (i - i % pixelBytes) / pixelBytes;
upper = row && pixels[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes];
pixels[c++] = (upper + abyte) % 256;
}
break;
case 3:
for (i = _l = 0; _l < scanlineLength; i = _l += 1) {
abyte = data[pos++];
col = (i - i % pixelBytes) / pixelBytes;
left = i < pixelBytes ? 0 : pixels[c - pixelBytes];
upper = row && pixels[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes];
pixels[c++] = (abyte + Math.floor((left + upper) / 2)) % 256;
}
break;
case 4:
for (i = _m = 0; _m < scanlineLength; i = _m += 1) {
abyte = data[pos++];
col = (i - i % pixelBytes) / pixelBytes;
left = i < pixelBytes ? 0 : pixels[c - pixelBytes];
if (row === 0) {
upper = upperLeft = 0;
} else {
upper = pixels[(row - 1) * scanlineLength + col * pixelBytes + i % pixelBytes];
upperLeft = col && pixels[(row - 1) * scanlineLength + (col - 1) * pixelBytes + i % pixelBytes];
}
p = left + upper - upperLeft;
pa = Math.abs(p - left);
pb = Math.abs(p - upper);
pc = Math.abs(p - upperLeft);
if (pa <= pb && pa <= pc) {
paeth = left;
} else if (pb <= pc) {
paeth = upper;
} else {
paeth = upperLeft;
}
pixels[c++] = (abyte + paeth) % 256;
}
break;
default:
throw new Error("Invalid filter algorithm: " + data[pos - 1]);
}
if (!isFull) {
var fullPos = ((y0 + row * dy) * _this.width + x0) * pixelBytes;
var partPos = row * scanlineLength;
for (i = 0; i < w; i += 1) {
for (var j = 0; j < pixelBytes; j += 1) fullPixels[fullPos++] = pixels[partPos++];
fullPos += (dx - 1) * pixelBytes;
}
}
row++;
}
}
if (_this.interlaceMethod == 1) {
/*
1 6 4 6 2 6 4 6
7 7 7 7 7 7 7 7
5 6 5 6 5 6 5 6
7 7 7 7 7 7 7 7
3 6 4 6 3 6 4 6
7 7 7 7 7 7 7 7
5 6 5 6 5 6 5 6
7 7 7 7 7 7 7 7
*/
pass(0, 0, 8, 8); // 1
/* NOTE these seem to follow the pattern:
* pass(x, 0, 2*x, 2*x);
* pass(0, x, x, 2*x);
* with x being 4, 2, 1.
*/
pass(4, 0, 8, 8); // 2
pass(0, 4, 4, 8); // 3
pass(2, 0, 4, 4); // 4
pass(0, 2, 2, 4); // 5
pass(1, 0, 2, 2); // 6
pass(0, 1, 1, 2); // 7
} else {
pass(0, 0, 1, 1);
}
return fullPixels;
};
PNG.prototype.decodePalette = function () {
var c, i, length, palette, pos, ret, transparency, _i, _ref, _ref1;
palette = this.palette;
transparency = this.transparency.indexed || [];
ret = new Uint8Array((transparency.length || 0) + palette.length);
pos = 0;
length = palette.length;
c = 0;
for (i = _i = 0, _ref = palette.length; _i < _ref; i = _i += 3) {
ret[pos++] = palette[i];
ret[pos++] = palette[i + 1];
ret[pos++] = palette[i + 2];
ret[pos++] = (_ref1 = transparency[c++]) != null ? _ref1 : 255;
}
return ret;
};
PNG.prototype.copyToImageData = function (imageData, pixels) {
var alpha, colors, data, i, input, j, k, length, palette, v, _ref;
colors = this.colors;
palette = null;
alpha = this.hasAlphaChannel;
if (this.palette.length) {
palette = (_ref = this._decodedPalette) != null ? _ref : this._decodedPalette = this.decodePalette();
colors = 4;
alpha = true;
}
data = imageData.data || imageData;
length = data.length;
input = palette || pixels;
i = j = 0;
if (colors === 1) {
while (i < length) {
k = palette ? pixels[i / 4] * 4 : j;
v = input[k++];
data[i++] = v;
data[i++] = v;
data[i++] = v;
data[i++] = alpha ? input[k++] : 255;
j = k;
}
} else {
while (i < length) {
k = palette ? pixels[i / 4] * 4 : j;
data[i++] = input[k++];
data[i++] = input[k++];
data[i++] = input[k++];
data[i++] = alpha ? input[k++] : 255;
j = k;
}
}
};
PNG.prototype.decode = function () {
var ret;
ret = new Uint8Array(this.width * this.height * 4);
this.copyToImageData(ret, this.decodePixels());
return ret;
};
try {
scratchCanvas = global.document.createElement("canvas");
scratchCtx = scratchCanvas.getContext("2d");
} catch (e) {
return -1;
}
makeImage = function (imageData) {
var img;
scratchCtx.width = imageData.width;
scratchCtx.height = imageData.height;
scratchCtx.clearRect(0, 0, imageData.width, imageData.height);
scratchCtx.putImageData(imageData, 0, 0);
img = new Image();
img.src = scratchCanvas.toDataURL();
return img;
};
PNG.prototype.decodeFrames = function (ctx) {
var frame, i, imageData, pixels, _i, _len, _ref, _results;
if (!this.animation) {
return;
}
_ref = this.animation.frames;
_results = [];
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
frame = _ref[i];
imageData = ctx.createImageData(frame.width, frame.height);
pixels = this.decodePixels(new Uint8Array(frame.data));
this.copyToImageData(imageData, pixels);
frame.imageData = imageData;
_results.push(frame.image = makeImage(imageData));
}
return _results;
};
PNG.prototype.renderFrame = function (ctx, number) {
var frame, frames, prev;
frames = this.animation.frames;
frame = frames[number];
prev = frames[number - 1];
if (number === 0) {
ctx.clearRect(0, 0, this.width, this.height);
}
if ((prev != null ? prev.disposeOp : void 0) === APNG_DISPOSE_OP_BACKGROUND) {
ctx.clearRect(prev.xOffset, prev.yOffset, prev.width, prev.height);
} else if ((prev != null ? prev.disposeOp : void 0) === APNG_DISPOSE_OP_PREVIOUS) {
ctx.putImageData(prev.imageData, prev.xOffset, prev.yOffset);
}
if (frame.blendOp === APNG_BLEND_OP_SOURCE) {
ctx.clearRect(frame.xOffset, frame.yOffset, frame.width, frame.height);
}
return ctx.drawImage(frame.image, frame.xOffset, frame.yOffset);
};
PNG.prototype.animate = function (ctx) {
var doFrame,
frameNumber,
frames,
numFrames,
numPlays,
_ref,
_this = this;
frameNumber = 0;
_ref = this.animation, numFrames = _ref.numFrames, frames = _ref.frames, numPlays = _ref.numPlays;
return (doFrame = function () {
var f, frame;
f = frameNumber++ % numFrames;
frame = frames[f];
_this.renderFrame(ctx, f);
if (numFrames > 1 && frameNumber / numFrames < numPlays) {
return _this.animation._timeout = setTimeout(doFrame, frame.delay);
}
})();
};
PNG.prototype.stopAnimation = function () {
var _ref;
return clearTimeout((_ref = this.animation) != null ? _ref._timeout : void 0);
};
PNG.prototype.render = function (canvas) {
var ctx, data;
if (canvas._png) {
canvas._png.stopAnimation();
}
canvas._png = this;
canvas.width = this.width;
canvas.height = this.height;
ctx = canvas.getContext("2d");
if (this.animation) {
this.decodeFrames(ctx);
return this.animate(ctx);
} else {
data = ctx.createImageData(this.width, this.height);
this.copyToImageData(data, this.decodePixels());
return ctx.putImageData(data, 0, 0);
}
};
return PNG;
}();
global.PNG = PNG;
})(typeof self !== "undefined" && self || typeof window !== "undefined" && window || typeof global !== "undefined" && global || Function('return typeof this === "object" && this.content')() || Function("return this")()); // `self` is undefined in Firefox for Android content script context
// while `this` is nsIContentFrameMessageManager
// with an attribute `content` that corresponds to the window
/*
* Extracted from pdf.js
* https://github.com/andreasgal/pdf.js
*
* Copyright (c) 2011 Mozilla Foundation
*
* Contributors: Andreas Gal <gal@mozilla.com>
* Chris G Jones <cjones@mozilla.com>
* Shaon Barman <shaon.barman@gmail.com>
* Vivien Nicolas <21@vingtetun.org>
* Justin D'Arcangelo <justindarc@gmail.com>
* Yury Delendik
*
*
*/
var DecodeStream = function () {
function constructor() {
this.pos = 0;
this.bufferLength = 0;
this.eof = false;
this.buffer = null;
}
constructor.prototype = {
ensureBuffer: function decodestream_ensureBuffer(requested) {
var buffer = this.buffer;
var current = buffer ? buffer.byteLength : 0;
if (requested < current) return buffer;
var size = 512;
while (size < requested) size <<= 1;
var buffer2 = new Uint8Array(size);
for (var i = 0; i < current; ++i) buffer2[i] = buffer[i];
return this.buffer = buffer2;
},
getByte: function decodestream_getByte() {
var pos = this.pos;
while (this.bufferLength <= pos) {
if (this.eof) return null;
this.readBlock();
}
return this.buffer[this.pos++];
},
getBytes: function decodestream_getBytes(length) {
var pos = this.pos;
if (length) {
this.ensureBuffer(pos + length);
var end = pos + length;
while (!this.eof && this.bufferLength < end) this.readBlock();
var bufEnd = this.bufferLength;
if (end > bufEnd) end = bufEnd;
} else {
while (!this.eof) this.readBlock();
var end = this.bufferLength;
}
this.pos = end;
return this.buffer.subarray(pos, end);
},
lookChar: function decodestream_lookChar() {
var pos = this.pos;
while (this.bufferLength <= pos) {
if (this.eof) return null;
this.readBlock();
}
return String.fromCharCode(this.buffer[this.pos]);
},
getChar: function decodestream_getChar() {
var pos = this.pos;
while (this.bufferLength <= pos) {
if (this.eof) return null;
this.readBlock();
}
return String.fromCharCode(this.buffer[this.pos++]);
},
makeSubStream: function decodestream_makeSubstream(start, length, dict) {
var end = start + length;
while (this.bufferLength <= end && !this.eof) this.readBlock();
return new Stream(this.buffer, start, length, dict);
},
skip: function decodestream_skip(n) {
if (!n) n = 1;
this.pos += n;
},
reset: function decodestream_reset() {
this.pos = 0;
}
};
return constructor;
}();
var FlateStream = function () {
if (typeof Uint32Array === "undefined") {
return undefined;
}
var codeLenCodeMap = new Uint32Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
var lengthDecode = new Uint32Array([0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a, 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f, 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073, 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102]);
var distDecode = new Uint32Array([0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d, 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1, 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01, 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001]);
var fixedLitCodeTab = [new Uint32Array([0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0, 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0, 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0, 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8, 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8, 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8, 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4, 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4, 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4, 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc, 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec, 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc, 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2, 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2, 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2, 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca, 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea, 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da, 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6, 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6, 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6, 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce, 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee, 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de, 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe, 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1, 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1, 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1, 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9, 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9, 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9, 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5, 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5, 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5, 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd, 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed, 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd, 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3, 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3, 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3, 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb, 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb, 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db, 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7, 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7, 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7, 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf, 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef, 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df, 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff]), 9];
var fixedDistCodeTab = [new Uint32Array([0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c, 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000, 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d, 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000]), 5];
function error(e) {
throw new Error(e);
}
function constructor(bytes) {
//var bytes = stream.getBytes();
var bytesPos = 0;
var cmf = bytes[bytesPos++];
var flg = bytes[bytesPos++];
if (cmf == -1 || flg == -1) error("Invalid header in flate stream");
if ((cmf & 0x0f) != 0x08) error("Unknown compression method in flate stream");
if (((cmf << 8) + flg) % 31 != 0) error("Bad FCHECK in flate stream");
if (flg & 0x20) error("FDICT bit set in flate stream");
this.bytes = bytes;
this.bytesPos = bytesPos;
this.codeSize = 0;
this.codeBuf = 0;
DecodeStream.call(this);
}
constructor.prototype = Object.create(DecodeStream.prototype);
constructor.prototype.getBits = function (bits) {
var codeSize = this.codeSize;
var codeBuf = this.codeBuf;
var bytes = this.bytes;
var bytesPos = this.bytesPos;
var b;
while (codeSize < bits) {
if (typeof (b = bytes[bytesPos++]) == "undefined") error("Bad encoding in flate stream");
codeBuf |= b << codeSize;
codeSize += 8;
}
b = codeBuf & (1 << bits) - 1;
this.codeBuf = codeBuf >> bits;
this.codeSize = codeSize -= bits;
this.bytesPos = bytesPos;
return b;
};
constructor.prototype.getCode = function (table) {
var codes = table[0];
var maxLen = table[1];
var codeSize = this.codeSize;
var codeBuf = this.codeBuf;
var bytes = this.bytes;
var bytesPos = this.bytesPos;
while (codeSize < maxLen) {
var b;
if (typeof (b = bytes[bytesPos++]) == "undefined") error("Bad encoding in flate stream");
codeBuf |= b << codeSize;
codeSize += 8;
}
var code = codes[codeBuf & (1 << maxLen) - 1];
var codeLen = code >> 16;
var codeVal = code & 0xffff;
if (codeSize == 0 || codeSize < codeLen || codeLen == 0) error("Bad encoding in flate stream");
this.codeBuf = codeBuf >> codeLen;
this.codeSize = codeSize - codeLen;
this.bytesPos = bytesPos;
return codeVal;
};
constructor.prototype.generateHuffmanTable = function (lengths) {
var n = lengths.length; // find max code length
var maxLen = 0;
for (var i = 0; i < n; ++i) {
if (lengths[i] > maxLen) maxLen = lengths[i];
} // build the table
var size = 1 << maxLen;
var codes = new Uint32Array(size);
for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
for (var val = 0; val < n; ++val) {
if (lengths[val] == len) {
// bit-reverse the code
var code2 = 0;
var t = code;
for (var i = 0; i < len; ++i) {
code2 = code2 << 1 | t & 1;
t >>= 1;
} // fill the table entries
for (var i = code2; i < size; i += skip) codes[i] = len << 16 | val;
++code;
}
}
}
return [codes, maxLen];
};
constructor.prototype.readBlock = function () {
function repeat(stream, array, len, offset, what) {
var repeat = stream.getBits(len) + offset;
while (repeat-- > 0) array[i++] = what;
} // read block header
var hdr = this.getBits(3);
if (hdr & 1) this.eof = true;
hdr >>= 1;
if (hdr == 0) {
// uncompressed block
var bytes = this.bytes;
var bytesPos = this.bytesPos;
var b;
if (typeof (b = bytes[bytesPos++]) == "undefined") error("Bad block header in flate stream");
var blockLen = b;
if (typeof (b = bytes[bytesPos++]) == "undefined") error("Bad block header in flate stream");
blockLen |= b << 8;
if (typeof (b = bytes[bytesPos++]) == "undefined") error("Bad block header in flate stream");
var check = b;
if (typeof (b = bytes[bytesPos++]) == "undefined") error("Bad block header in flate stream");
check |= b << 8;
if (check != (~blockLen & 0xffff)) error("Bad uncompressed block length in flate stream");
this.codeBuf = 0;
this.codeSize = 0;
var bufferLength = this.bufferLength;
var buffer = this.ensureBuffer(bufferLength + blockLen);
var end = bufferLength + blockLen;
this.bufferLength = end;
for (var n = bufferLength; n < end; ++n) {
if (typeof (b = bytes[bytesPos++]) == "undefined") {
this.eof = true;
break;
}
buffer[n] = b;
}
this.bytesPos = bytesPos;
return;
}
var litCodeTable;
var distCodeTable;
if (hdr == 1) {
// compressed block, fixed codes
litCodeTable = fixedLitCodeTab;
distCodeTable = fixedDistCodeTab;
} else if (hdr == 2) {
// compressed block, dynamic codes
var numLitCodes = this.getBits(5) + 257;
var numDistCodes = this.getBits(5) + 1;
var numCodeLenCodes = this.getBits(4) + 4; // build the code lengths code table
var codeLenCodeLengths = Array(codeLenCodeMap.length);
var i = 0;
while (i < numCodeLenCodes) codeLenCodeLengths[codeLenCodeMap[i++]] = this.getBits(3);
var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths); // build the literal and distance code tables
var len = 0;
var i = 0;
var codes = numLitCodes + numDistCodes;
var codeLengths = new Array(codes);
while (i < codes) {
var code = this.getCode(codeLenCodeTab);
if (code == 16) {
repeat(this, codeLengths, 2, 3, len);
} else if (code == 17) {
repeat(this, codeLengths, 3, 3, len = 0);
} else if (code == 18) {
repeat(this, codeLengths, 7, 11, len = 0);
} else {
codeLengths[i++] = len = code;
}
}
litCodeTable = this.generateHuffmanTable(codeLengths.slice(0, numLitCodes));
distCodeTable = this.generateHuffmanTable(codeLengths.slice(numLitCodes, codes));
} else {
error("Unknown block type in flate stream");
}
var buffer = this.buffer;
var limit = buffer ? buffer.length : 0;
var pos = this.bufferLength;
while (true) {
var code1 = this.getCode(litCodeTable);
if (code1 < 256) {
if (pos + 1 >= limit) {
buffer = this.ensureBuffer(pos + 1);
limit = buffer.length;
}
buffer[pos++] = code1;
continue;
}
if (code1 == 256) {
this.bufferLength = pos;
return;
}
code1 -= 257;
code1 = lengthDecode[code1];
var code2 = code1 >> 16;
if (code2 > 0) code2 = this.getBits(code2);
var len = (code1 & 0xffff) + code2;
code1 = this.getCode(distCodeTable);
code1 = distDecode[code1];
code2 = code1 >> 16;
if (code2 > 0) code2 = this.getBits(code2);
var dist = (code1 & 0xffff) + code2;
if (pos + len >= limit) {
buffer = this.ensureBuffer(pos + len);
limit = buffer.length;
}
for (var k = 0; k < len; ++k, ++pos) buffer[pos] = buffer[pos - dist];
}
};
return constructor;
}();
exports.default = jsPDF;
var _default2 = exports.default;
function rewire($stub) {
exports.default = $stub;
}
function restore() {
exports.default = _default2;
}
exports.rewire = rewire;
exports.restore = restore;
Object.defineProperty(exports, '__esModule', { value: true });
})));