-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy patheendraadschema.js
10561 lines (10521 loc) · 578 KB
/
eendraadschema.js
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
/*** Eendraadschema ***
=== Community edition ===
Copyright (C) 2019-2025 Ivan Goethals GPLv3
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
The source code of this community edition is hosted on Github at
https://github.com/igoethal/eendraadschema.
=== Exclusive license ===
Notwithstanding the above, the original and sole author of this edition,
Ivan Goethals, reserves the exclusive right to create derivative works of
this software and distribute them under different licensing terms, including
but not limited to proprietary licenses. This includes the ability to develop
and offer a hosted edition with additional features not available in the
community edition. This right does not extend to derivative works produced by
others based on this community edition.
=== Embedded content ===
== Pako.js ==
This program uses the Pako.js entropy coding library. Pako is released under
an MIT license by Andrey Tupitsin and Vitaly Puzrin. For more information on
Pako and the full license text, please visit https://github.com/nodeca/pako
== Zlib ==
Pako implements ZLib in javascript. Zlib is released under the ZLIB License.
See https://www.zlib.net/zlib_license.html
== jsPDF ==
This program uses the jsPDF library to transform SVG images into PDF files.
The jsPDF license is as follows
Copyright
(c) 2010-2021 James Hall, https://github.com/MrRio/jsPDF
(c) 2015-2021 yWorks GmbH, https://www.yworks.com/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
function deepClone(obj) {
var _out = new obj.constructor;
var getType = function (n) {
return Object.prototype.toString.call(n).slice(8, -1);
};
for (var _key in obj) {
if (obj.hasOwnProperty(_key)) {
_out[_key] = getType(obj[_key]) === 'Object' || getType(obj[_key]) === 'Array' ? deepClone(obj[_key]) : obj[_key];
}
}
return _out;
}
/**
* Returns true if the current mode is a development mode.
* This is determined by the presence of a 'dev' parameter in the URL.
*
* @returns {boolean} True if this is a development mode, false otherwise.
*/
function isDevMode() {
try {
var urlParams = new URLSearchParams(window.location.search);
return urlParams.has('dev');
}
catch (error) {
console.error('Error checking for dev mode:', error);
return false;
}
}
// Function for length of a string in 8 bit bytes
var byteSize = function (str) { return new Blob([str]).size; };
function contains(a, obj) {
for (var i = 0; i < a.length; i++) {
if (a[i] === obj) {
return true;
}
}
return false;
}
function isInt(value) {
return !isNaN(value) &&
parseInt(value) == value &&
!isNaN(parseInt(value, 10));
}
function svgTextWidth(input, fontsize, options) {
if (fontsize === void 0) { fontsize = 10; }
if (options === void 0) { options = ''; }
var div = document.createElement('div');
div.innerHTML = '<svg width="1000" height="20"><text x="0" y="10" style="text-anchor:start" font-family="Arial, Helvetica, sans-serif" font-size="' + Number(fontsize) + '" ' + options + '>' + input + '</text></svg>';
var tryoutdiv = document.body;
/*if (document.getElementById("configsection").style.display === 'block') {
tryoutdiv = document.getElementById("configsection") as HTMLElement;
} else if (document.getElementById("outerdiv").style.display === 'block') {
tryoutdiv = document.getElementById("outerdiv") as HTMLElement;
} else {
tryoutdiv = document.getElementById("right_col_inner") as HTMLElement;
}*/
tryoutdiv.appendChild(div);
var width = div.children[0].children[0].getBBox().width;
tryoutdiv.removeChild(div);
return (Math.ceil(width));
}
function flattenSVG(SVGstruct, shiftx, shifty, node, overflowright) {
if (overflowright === void 0) { overflowright = 0; }
if (node == 0)
structure.print_table.pagemarkers.clear();
var str = "";
var X = new XMLSerializer();
var parser = new DOMParser();
var outstruct = SVGstruct;
if (SVGstruct.localName == "svg") {
if (outstruct.attributes.getNamedItem("x")) { // make SVG a 0,0 element
shiftx += parseFloat(outstruct.attributes.getNamedItem("x").nodeValue);
outstruct.attributes.getNamedItem("x").nodeValue = 0;
}
if (outstruct.attributes.getNamedItem("y")) { // make SVG a 0,0 element
shifty += parseFloat(outstruct.attributes.getNamedItem("y").nodeValue);
outstruct.attributes.getNamedItem("y").nodeValue = 0;
}
for (var i = 0; i < SVGstruct.children.length; i++) {
str = str.concat(flattenSVG(SVGstruct.children[i], shiftx, shifty, node + 1), "\n");
}
if (node <= 0) {
if (outstruct.attributes.getNamedItem("width")) { // make SVG a 0,0 element
str = '<svg id="EDSSVG" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" transform="scale(1,1)" width="' + (parseInt(outstruct.attributes.getNamedItem("width").nodeValue) + overflowright) +
'" height="' + (outstruct.attributes.getNamedItem("height").nodeValue) + '">' + str + '</svg>';
}
else {
str = '<svg>' + str + '</svg>';
}
}
}
else {
if (SVGstruct.localName == "line") {
if (shiftx != 0) {
outstruct.attributes.getNamedItem("x1").nodeValue = parseFloat(outstruct.attributes.getNamedItem("x1").nodeValue) + shiftx;
outstruct.attributes.getNamedItem("x2").nodeValue = parseFloat(outstruct.attributes.getNamedItem("x2").nodeValue) + shiftx;
}
if (shifty != 0) {
outstruct.attributes.getNamedItem("y1").nodeValue = parseFloat(outstruct.attributes.getNamedItem("y1").nodeValue) + shifty;
outstruct.attributes.getNamedItem("y2").nodeValue = parseFloat(outstruct.attributes.getNamedItem("y2").nodeValue) + shifty;
}
}
if (SVGstruct.localName == "use") {
if (shiftx != 0) {
outstruct.attributes.getNamedItem("x").nodeValue = parseFloat(outstruct.attributes.getNamedItem("x").nodeValue) + shiftx;
}
if (shifty != 0) {
outstruct.attributes.getNamedItem("y").nodeValue = parseFloat(outstruct.attributes.getNamedItem("y").nodeValue) + shifty;
}
}
if (SVGstruct.localName == "rect") {
if (shiftx != 0) {
outstruct.attributes.getNamedItem("x").nodeValue = parseFloat(outstruct.attributes.getNamedItem("x").nodeValue) + shiftx;
}
if (shifty != 0) {
outstruct.attributes.getNamedItem("y").nodeValue = parseFloat(outstruct.attributes.getNamedItem("y").nodeValue) + shifty;
}
}
if (SVGstruct.localName == "circle") {
if (shiftx != 0) {
outstruct.attributes.getNamedItem("cx").nodeValue = parseFloat(outstruct.attributes.getNamedItem("cx").nodeValue) + shiftx;
}
if (shifty != 0) {
outstruct.attributes.getNamedItem("cy").nodeValue = parseFloat(outstruct.attributes.getNamedItem("cy").nodeValue) + shifty;
}
}
if (SVGstruct.localName == "text") {
outstruct.attributes.getNamedItem("x").nodeValue = parseFloat(outstruct.attributes.getNamedItem("x").nodeValue) + shiftx;
outstruct.attributes.getNamedItem("y").nodeValue = parseFloat(outstruct.attributes.getNamedItem("y").nodeValue) + shifty;
if (outstruct.attributes.getNamedItem("transform")) {
if (outstruct.attributes.getNamedItem("transform").value.includes('rotate')) {
outstruct.attributes.getNamedItem("transform").value = "rotate(-90 " +
outstruct.attributes.getNamedItem("x").nodeValue + "," +
outstruct.attributes.getNamedItem("y").nodeValue + ")";
}
else {
outstruct.attributes.getNamedItem("transform").value = "scale(-1,1) translate(-" +
outstruct.attributes.getNamedItem("x").nodeValue * 2 + ",0)";
}
}
}
if (SVGstruct.localName == "polygon") {
var polystr_out = "";
var polystr_in = outstruct.attributes.getNamedItem("points").nodeValue;
var splitted_in = polystr_in.split(" ");
for (var countstr = 0; countstr < splitted_in.length; countstr++) {
var points_in = splitted_in[countstr].split(",");
polystr_out += (points_in[0] * 1 + shiftx) + ',' + (points_in[1] * 1 + shifty);
if (countstr < splitted_in.length - 1) {
polystr_out += ' ';
}
}
outstruct.attributes.getNamedItem("points").nodeValue = polystr_out;
}
str = X.serializeToString(outstruct);
//remove all the xmlns tags
var regex = /xmlns="[^"]+"/g;
str = str.replace(regex, '');
}
structure.print_table.pagemarkers.addMarker(node, shiftx);
return str;
}
function flattenSVGfromString(xmlstr, overflowright) {
if (overflowright === void 0) { overflowright = 0; }
var str = "";
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xmlstr, "text/xml"); //important to use "text/xml"
str = flattenSVG(xmlDoc.childNodes[0], 0, 0, 0, overflowright);
return str;
}
function htmlspecialchars(my_input) {
var returnstr;
if (typeof (my_input) == 'undefined')
returnstr = "";
else
returnstr = my_input.toString();
var map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
return returnstr.replace(/[&<>"']/g, function (m) { return map[m]; });
}
function browser_ie_detected() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
var trident = ua.indexOf('Trident/');
if ((msie > 0) || (trident > 0))
return true;
else
return false;
}
var randomId = (function () {
var counters = {};
return function (prefix) {
if (prefix === void 0) { prefix = "Rnd_"; }
if (!(prefix in counters)) {
counters[prefix] = 0;
}
var value = counters[prefix];
counters[prefix]++;
return "".concat(prefix).concat(value.toString());
};
})();
var Session = /** @class */ (function () {
function Session() {
this.sessionKey = 'SessionJS';
this.newUser = false;
var storedSessionId = localStorage.getItem(this.sessionKey);
if (storedSessionId) {
this.sessionId = storedSessionId;
}
else {
this.sessionId = this.generateRandomBase64String(22);
localStorage.setItem(this.sessionKey, this.sessionId);
this.newUser = true;
}
}
Session.prototype.generateRandomBase64String = function (length) {
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var result = '';
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
var randomIndex = Math.floor(Math.random() * charactersLength);
result += characters[randomIndex];
}
return result;
};
Session.prototype.getSessionId = function () {
return this.sessionId;
};
Session.prototype.isNewUser = function () {
return this.newUser;
};
return Session;
}());
var SVGelement = /** @class */ (function () {
function SVGelement() {
this.data = "";
this.xleft = 0;
this.xright = 0;
this.xrightmin = 0;
this.yup = 0;
this.ydown = 0;
}
return SVGelement;
}());
/**
* Manages the addition and removal of event listeners on HTML elements.
*/
var EventManager = /** @class */ (function () {
function EventManager() {
this.listeners = [];
}
/**
* Adds an event listener to a specified HTML element. If a listener of the same
* type already exists on the element, it is removed before adding the new one.
*
* @param element - The HTML element to attach the event listener to.
* @param type - The type of the event.
* @param listener - The event listener function or object.
*/
EventManager.prototype.addEventListener = function (element, type, listener) {
var existingListenerIndex = this.listeners.findIndex(function (l) { return l.element === element && l.type === type; });
if (existingListenerIndex !== -1) {
var existingListener = this.listeners[existingListenerIndex];
element.removeEventListener(type, existingListener.listener);
this.listeners.splice(existingListenerIndex, 1);
}
this.listeners.push({ element: element, type: type, listener: listener });
element.addEventListener(type, listener);
this.cleanup(); // Before we proceed, remove all listeners for elements that no longer exist
};
/**
* Removes all event listeners managed by this EventManager instance.
*/
EventManager.prototype.removeAllEventListeners = function () {
this.listeners.forEach(function (_a) {
var element = _a.element, type = _a.type, listener = _a.listener;
element.removeEventListener(type, listener);
});
this.listeners = [];
};
/**
* Disposes of the EventManager by removing all event listeners.
*/
EventManager.prototype.dispose = function () {
this.removeAllEventListeners();
};
/**
* Removes all listeners for which the HTML element no longer exists.
*/
EventManager.prototype.cleanup = function () {
this.listeners = this.listeners.filter(function (_a) {
var element = _a.element, type = _a.type, listener = _a.listener;
if (!document.contains(element)) {
element.removeEventListener(type, listener);
return false;
}
return true;
});
};
return EventManager;
}());
/**
* A class to handle a list of potential page breaks or markers in the form {depth,xpos} with depth how nested
* they are (lower depth is better to include a page break) and xpos the location in pixels in the SVG where
* the break could be added
*/
var MarkerList = /** @class */ (function () {
function MarkerList() {
this.markers = [];
}
/**
* Clear the list of markers
*/
MarkerList.prototype.clear = function () {
this.markers = [];
};
/**
* Add a marker to the markerlist.
* If the same marker already exists, no new one will be added.
* @param depth - The depth of the marker, or how nested it is (lower depth is better for page breaks).
* @param xpos - The x-coordinate position of the marker.
*/
MarkerList.prototype.addMarker = function (depth, xpos) {
// Check if the marker already exists
var exists = this.markers.some(function (marker) { return marker.depth === depth && marker.xpos === xpos; });
if (!exists) {
this.markers.push({ depth: depth, xpos: xpos });
}
};
/**
* Sorts the markers by their x-coordinate position in ascending order.
*/
MarkerList.prototype.sort = function () {
this.markers.sort(function (a, b) { return a.xpos - b.xpos; });
};
/**
* Looks for the marker in the half-open internal (minx, maxx] with the lowest possible depth.
* If multiple markers exist with the same depth, the one with the highest xpos is returned.
* If no suitable marker is found, a dummy {depth=null, xpos=maxx} is returned.
* @param minx - Minimal x for any markers that will be considered.
* @param maxx - Maximal x for any markers that will be considered.
* @returns The marker with the lowest depth (and highest xpos if multiple exist) or a dummy marker if none are found.
*/
MarkerList.prototype.findMinDepth = function (minx, maxx) {
// Filter markers within the range
var filteredMarkers = this.markers.filter(function (marker) { return marker.xpos > minx && marker.xpos <= maxx; });
if (filteredMarkers.length === 0) {
return { depth: null, xpos: maxx }; // No markers in the specified range so we just take the maximum
}
// Find the marker with the lowest depth, if multiple exist with the same depth, take the one with the highest xpos
return filteredMarkers.reduce(function (minDepthMarker, marker) {
if (marker.depth < minDepthMarker.depth ||
(marker.depth === minDepthMarker.depth && marker.xpos > minDepthMarker.xpos)) {
return marker;
}
return minDepthMarker;
}, filteredMarkers[0]);
};
return MarkerList;
}());
/**
* Store information on what part of the SVG lands on one specific page
* The height is the final height in number of pixels
* The start and stop are the x-locations in pixels of the part of the total SVG that needs to land on this particular page
*/
var Page_Info = /** @class */ (function () {
function Page_Info() {
this.height = 0;
this.start = 0;
this.stop = 0;
}
return Page_Info;
}());
/**
* Stores all information about pagination and how pages will be printed.
* Can perform automatic pagination or ask the user to paginate.
*
* We don't use private variables in this class as we want to serialize it (JSON)
*/
var Print_Table = /** @class */ (function () {
/**
* Initialize list of pages (foresee at least 1 page) and pagemarkers
*/
function Print_Table() {
this.height = 0; //How high is the SVG that will be printed in pixels
this.maxwidth = 0; //What is the width of the SVG that will be printed in pixels and therefore the maximum printing width
this.displaypage = 0;
this.enableAutopage = true; //Flag to indicate if automatic pagination is used or not
this.pages = new Array();
this.pages.push(new Page_Info());
this.pagemarkers = new MarkerList;
}
/**
* Set papersize to either "A4" or "A3"
* @param papersize - A string, if it is neither "A4" or "A3", the papersize will default to "A4".
*/
Print_Table.prototype.setPaperSize = function (papersize) {
this.papersize = (papersize === "A3" ? "A3" : "A4");
};
/**
* Get papersize. If papersize was not yet defined, it is forced to "A4"
* @returns The papersize, either "A3" or "A4"
*/
Print_Table.prototype.getPaperSize = function () {
if (!this.papersize)
this.papersize = "A4";
return (this.papersize);
};
/**
* Set displayheight of all pages to height
* @param height - Height in pixels
*/
Print_Table.prototype.setHeight = function (height) {
this.height = height;
this.pages.forEach(function (page) { page.height = height; });
};
/**
* Get displayheight
* @returns Height in pixels
*/
Print_Table.prototype.getHeight = function () {
return (this.height);
};
/**
* Set modevertical to either "alles" (meaning we show the full height of the page) or "kies" meaning the user can choose
* @param more - Either "alles" or "kies"
*/
Print_Table.prototype.setModeVertical = function (mode) {
this.modevertical = (mode === "kies" ? "kies" : "alles");
this.forceCorrectFigures();
};
/**
* Get modevertical
* @returns either "alles" or "kies"
*/
Print_Table.prototype.getModeVertical = function () {
this.forceCorrectFigures();
return (this.modevertical);
};
/**
* Checks that all start and stop position of pages are valid
* For instance, the startx position should never be higher than the stopx.
* In addition, the SVG always goes from left to right over the pages so the startx
* of a new page cannot be lower than the stopx of the page before.
*/
Print_Table.prototype.forceCorrectFigures = function () {
var _this = this;
if (!this.modevertical) {
this.modevertical = "alles";
}
switch (this.modevertical) {
case "kies":
this.starty = Math.min(Math.max(0, this.starty), this.height);
this.stopy = Math.min(Math.max(this.starty, this.stopy), this.height);
break;
default:
this.starty = 0;
this.stopy = this.height;
}
this.pages[this.pages.length - 1].stop = this.maxwidth;
this.pages.forEach(function (page, index) {
if (page.stop < 0)
page.stop = 0;
if (page.start < 0)
page.start = 0;
if (index > 0) {
page.start = _this.pages[index - 1].stop;
}
if (page.stop > _this.maxwidth) {
_this.pages[_this.pages.length - 1].stop = _this.maxwidth;
}
if (page.start > page.stop) {
page.start = page.stop;
}
});
};
/**
* Sets the maximum width of the SVG to be displayed.
* As a general rule this equals the width of the SVG itself in pixels
* @param maxwidth
*/
Print_Table.prototype.setMaxWidth = function (maxwidth) {
this.maxwidth = maxwidth;
this.forceCorrectFigures();
};
/**
* Gets the maximum width that can be displayed or printed
* @returns maxwidth, as a general rule this equals the width of the SVG itsef in pixels
*/
Print_Table.prototype.getMaxWidth = function () {
return (this.maxwidth);
};
/**
* Returns the starty position of the page that will be displayed or printed
* @returns starty
*/
Print_Table.prototype.getstarty = function () {
this.forceCorrectFigures();
return (this.starty);
};
/**
* Returns the stopy position of the page that will be displayed or printed
* @returns stopy
*/
Print_Table.prototype.getstopy = function () {
this.forceCorrectFigures();
return (this.stopy);
};
/**
* Sets the starty position of the page that will be displayed or printed
* @param starty
*/
Print_Table.prototype.setstarty = function (starty) {
this.starty = starty;
this.forceCorrectFigures;
};
/**
* Sets the stopy position of the page that will be displayed or printed
* @param starty
*/
Print_Table.prototype.setstopy = function (stopy) {
this.stopy = stopy;
this.forceCorrectFigures;
};
/**
* Sets the stopx position of one specific page to a desired value.
* The function calls forceCorrectFigures() afterwards to ensure the natural flow of pages (left to right)
* is respected. Note that stopx in the underlying Page_Info object is called stop and we cannot change that
* anymore as the classes are used for serialization.
* @param page - page number for which we want to set the stopx (starts counting at zero)
* @param stop - stopx position to set
*/
Print_Table.prototype.setStop = function (page, stop) {
if (page > 0) {
if (stop < this.pages[page - 1].stop)
stop = this.pages[page - 1].stop;
}
if (page < this.pages.length - 1) {
if (stop > this.pages[page + 1].stop)
stop = this.pages[page + 1].stop;
}
if (stop > this.maxwidth)
stop = this.maxwidth;
this.pages[page].stop = stop;
this.forceCorrectFigures();
};
/**
* Automatically create pages based on pagemarkers
*/
Print_Table.prototype.autopage = function () {
/* Autopage uses some ratio's determined by the useful SVG drawing size on the PDF. This depends on the margins configured in print.js
At present all of this is still hard-coded. Should become a function of print.js
A4
Height: 210-20-30-5-5 --> 150
Width: 297-20 --> 277
Ratio: 1.8467
A3
Height: 297-20-30-5-5 --> 237
Width: 420-20 --> 400
Ratio: 1.6878
*/
var _this = this;
//First set all pages to maximum to avoid that we bump into boundaries
this.pages.forEach(function (page, index) {
page.stop = _this.maxwidth;
});
var height = this.getstopy() - this.getstarty();
var maxsvgwidth = height * (this.getPaperSize() == "A3" ? 1.6878 : 1.8467);
var minsvgwidth = 3 / 4 * maxsvgwidth;
var page = 0;
var pos = 0;
if (maxsvgwidth > 0) {
while ((this.maxwidth - pos) > maxsvgwidth) { // The undivided part still does not fit on a page
pos = this.pagemarkers.findMinDepth(pos + minsvgwidth, pos + maxsvgwidth).xpos;
while (this.pages.length < page + 2)
this.addPage();
this.setStop(page, pos);
page++;
}
}
// The last page stops at the maximum size of the SVG
this.setStop(page, this.maxwidth);
// Delete unneeded pages at the end
for (var i = this.pages.length - 1; i > page; i--) {
this.deletePage(i);
}
};
/**
* Add a page
*/
Print_Table.prototype.addPage = function () {
var page_info;
page_info = new Page_Info();
page_info.height = this.height;
page_info.start = this.pages[this.pages.length - 1].stop;
page_info.stop = this.maxwidth;
this.pages.push(page_info);
};
/**
* Remove a page
* @param page - number of the page to be removed, starting at 0
*/
Print_Table.prototype.deletePage = function (page) {
if (page == 0) {
this.pages[1].start = 0;
}
else {
this.pages[page - 1].stop = this.pages[page].stop;
}
this.pages.splice(page, 1);
};
/**
* Display a Select box to choose papersize (A3 or A4)
* The table is displayed in the HTMLElement div that is given as a parameter to the function.
* If any manipulation is done by the user that would require redrawing the print preview, the redrawCallBack function is executed
* from within this function
* @param div - Existing HTMLElement where the table will be inserted
* @param redrawCallBack - Callback function that ensures everything that needs to be redrawn is redrawn
*/
Print_Table.prototype.insertHTMLselectPaperSize = function (div, redrawCallBack) {
var _this = this;
var select = document.createElement('select');
select.id = 'select_papersize_input';
var optionA4 = document.createElement('option');
optionA4.value = 'A4';
optionA4.textContent = 'A4';
var optionA3 = document.createElement('option');
optionA3.value = 'A3';
optionA3.textContent = 'A3';
if (this.papersize == "A3")
optionA3.selected = true;
else
optionA4.selected = true;
select.appendChild(optionA4);
select.appendChild(optionA3);
select.onchange = function (event) {
_this.setPaperSize(event.target.value);
redrawCallBack();
};
div.appendChild(select);
};
/**
* Display a Select box to choose dpi (300 or 600)
* The table is displayed in the HTMLElement div that is given as a parameter to the function.
* If any manipulation is done by the user that would require redrawing the print preview, the redrawCallBack function is executed
* from within this function
* @param div - Existing HTMLElement where the table will be inserted
* @param redrawCallBack - Callback function that ensures everything that needs to be redrawn is redrawn
*/
Print_Table.prototype.insertHTMLselectdpi = function (div, redrawCallBack) {
var select = document.createElement('select');
select.id = "select_dpi_input";
var option300 = document.createElement('option');
option300.value = '300';
option300.textContent = '300dpi (standaard)';
var option600 = document.createElement('option');
option600.value = '600';
option600.textContent = '600dpi (beter maar trager)';
if (typeof (structure.properties.dpi) == 'undefined')
structure.properties.dpi = 300;
if (structure.properties.dpi == 600)
option600.selected = true;
else
option300.selected = true;
select.appendChild(option300);
select.appendChild(option600);
select.onchange = function (event) {
structure.properties.dpi = parseInt(event.target.value, 0);
};
div.appendChild(select);
};
/**
* Display a Check box to decide if one wants to use autopage or not.
* If autopage is enabled, we also recalculate the page boundaries
* The checkbox is displayed in the HTMLElement div that is given as a parameter to the function.
* If any manipulation is done by the user that would require redrawing the print preview, the redrawCallBack function is executed
* from within this function
* @param div - Existing HTMLElement where the table will be inserted
* @param redrawCallBack - Callback function that ensures everything that needs to be redrawn is redrawn
*/
Print_Table.prototype.insertHTMLcheckAutopage = function (div, redrawCallBack) {
var _this = this;
var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.id = 'autopage';
checkbox.name = 'autopage';
var label = document.createElement('label');
label.htmlFor = 'autopage';
label.textContent = "Handmatig over pagina's verdelen";
if (this.enableAutopage) {
this.setModeVertical("alles");
this.autopage();
}
else {
checkbox.checked = true;
}
div.append(checkbox);
div.append(label);
checkbox.onchange = function (event) {
_this.enableAutopage = !event.target.checked;
redrawCallBack();
};
};
/**
* Display a select box to choose the vertical mode.
* If vertical mode is "kies", we also display input boxes to choose the starty and stopy positions.
* The checkbox is displayed in the HTMLElement div that is given as a parameter to the function.
* If any manipulation is done by the user that would require redrawing the print preview, the redrawCallBack function is executed
* from within this function
* @param div - Existing HTMLElement where the table will be inserted
* @param redrawCallBack - Callback function that ensures everything that needs to be redrawn is redrawn
*/
Print_Table.prototype.insertHTMLchooseVerticals = function (div, redrawCallBack) {
var _this = this;
var outstr = "";
switch (this.modevertical) {
case "kies":
outstr += 'Hoogte <select id="select_modeVertical"><option value="alles">Alles (standaard)</option><option value="kies" selected="Selected">Kies (expert)</option></select>';
outstr += ' StartY ';
outstr += '<input size="4" id="input_starty" type="number" min="0" step="1" max="' + this.getHeight() + '" value="' + this.getstarty() + '">';
outstr += ' StopY ';
outstr += '<input size="4" id="input_stopy" type="number" min="0" step="1" max="' + this.getHeight() + '" value="' + this.getstopy() + '">';
break;
case "alles":
default:
outstr += 'Hoogte <select id="select_modeVertical"><option value="alles">Alles (standaard)</option><option value="kies">Kies (expert)</option></select>';
}
div.insertAdjacentHTML('beforeend', outstr);
document.getElementById('select_modeVertical').onchange = function (event) {
_this.setModeVertical(event.target.value);
redrawCallBack();
};
if (this.modevertical == "kies") {
document.getElementById('input_starty').onchange = function (event) {
var starty = parseInt(event.target.value);
if (isNaN(starty))
starty = 0;
_this.setstarty(starty);
_this.forceCorrectFigures();
redrawCallBack();
};
document.getElementById('input_stopy').onchange = function (event) {
var stopy = parseInt(event.target.value);
if (isNaN(stopy))
stopy = _this.getHeight();
;
_this.setstopy(stopy);
_this.forceCorrectFigures();
redrawCallBack();
};
}
};
/**
* Display a button to force auto-pagination even when in manual mode
* @param div - Existing HTMLElement where the table will be inserted
* @param redrawCallBack - Callback function that ensures everything that needs to be redrawn is redrawn
*/
Print_Table.prototype.insertHTMLsuggestXposButton = function (div, redrawCallBack) {
var _this = this;
var button = document.createElement('button');
button.innerText = 'Suggereer X-posities';
div.append(button);
button.onclick = function () {
_this.autopage();
redrawCallBack();
};
};
/**
* Display a table where the user can choose start and stop positions for the x-coordinates in the SVG of each individual page
* The table is displayed in the HTMLElement div that is given as a parameter to the function.
* If any manipulation is done by the user that would require redrawing the print preview, the redrawCallBack function is executed
* from within this function
* @param div - Existing HTMLElement where the table will be inserted
* @param redrawCallBack - Callback function that ensures everything that needs to be redrawn is redrawn
*/
Print_Table.prototype.insertHTMLposxTable = function (div, redrawCallBack) {
var _this = this;
if (structure.print_table.enableAutopage)
this.autopage();
var outstr = "";
var pagenum;
outstr += '<table border="1" cellpadding="3">';
outstr += '<tr><th align="center">Pagina</th><th align="center">Startx</th><th align"center">Stopx</th><th align"left">Acties</th></tr>';
for (pagenum = 0; pagenum < this.pages.length; pagenum++) {
outstr += '<tr><td align=center>' + (pagenum + 1) + '</td><td align=center>' + this.pages[pagenum].start + '</td><td align=center>';
if (pagenum != this.pages.length - 1) {
outstr += '<input size="5" id="input_stop_' + pagenum + '" type="number" min="' + this.pages[pagenum].start
+ '" step="1" max="' + this.maxwidth + '" value="' + this.pages[pagenum].stop + '">';
}
else {
outstr += this.pages[pagenum].stop.toString();
}
outstr += '</td><td align=left>';
if (pagenum == this.pages.length - 1) {
outstr += '<button style="background-color:green;" id="Btn_Addpage">▼</button>';
}
if (this.pages.length > 1) {
outstr += '<button style="background-color:red;" id="Btn_Deletepage_' + pagenum + '">♻</button>';
}
outstr += '</td></tr>';
}
outstr += "</table>";
div.insertAdjacentHTML('beforeend', outstr);
document.getElementById('Btn_Addpage').onclick = function () {
_this.addPage();
redrawCallBack();
};
document.querySelectorAll('button[id^="Btn_Deletepage_"]').forEach(function (button) {
var match = button.id.match(/Btn_Deletepage_(\d+)/);
if (match) {
var page_1 = parseInt(match[1]);
button.onclick = function () {
_this.deletePage(page_1);
redrawCallBack();
};
}
});
document.querySelectorAll('input[id^="input_stop_"]').forEach(function (input) {
input.addEventListener('change', function (event) {
var match = event.target.id.match(/input_stop_(\d+)/);
if (match) {
var page = parseInt(match[1]);
var stop_1 = parseInt(event.target.value);
_this.setStop(page, stop_1);
redrawCallBack();
}
});
});
};
return Print_Table;
}());
function HLDisplayPage() {
structure.print_table.displaypage = parseInt(document.getElementById("id_select_page").value) - 1;
printsvg();
}
function dosvgdownload() {
var prtContent = document.getElementById("printsvgarea").innerHTML;
var filename = document.getElementById("dosvgname").value;
download_by_blob(prtContent, filename, 'data:image/svg+xml;charset=utf-8'); //Was text/plain
}
function getPrintSVGWithoutAddress(outSVG, page) {
if (page === void 0) { page = structure.print_table.displaypage; }
var scale = 1;
var startx = structure.print_table.pages[page].start;