pdfmake-acroforms 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +21 -0
  3. package/README.md +75 -0
  4. package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
  5. package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
  6. package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  7. package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
  8. package/build/fonts/Roboto.js +27 -0
  9. package/build/pdfmake.js +67806 -0
  10. package/build/pdfmake.js.map +1 -0
  11. package/build/pdfmake.min.js +3 -0
  12. package/build/pdfmake.min.js.map +1 -0
  13. package/build/standard-fonts/Courier.js +27 -0
  14. package/build/standard-fonts/Helvetica.js +27 -0
  15. package/build/standard-fonts/Symbol.js +21 -0
  16. package/build/standard-fonts/Times.js +27 -0
  17. package/build/standard-fonts/ZapfDingbats.js +21 -0
  18. package/build/vfs_fonts.js +6 -0
  19. package/build-vfs.js +44 -0
  20. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  21. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  22. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  23. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  24. package/fonts/Roboto.js +8 -0
  25. package/js/3rd-party/svg-to-pdfkit/source.js +3823 -0
  26. package/js/3rd-party/svg-to-pdfkit.js +7 -0
  27. package/js/DocMeasure.js +675 -0
  28. package/js/DocPreprocessor.js +258 -0
  29. package/js/DocumentContext.js +310 -0
  30. package/js/ElementWriter.js +399 -0
  31. package/js/LayoutBuilder.js +1202 -0
  32. package/js/Line.js +101 -0
  33. package/js/OutputDocument.js +64 -0
  34. package/js/OutputDocumentServer.js +29 -0
  35. package/js/PDFDocument.js +145 -0
  36. package/js/PageElementWriter.js +164 -0
  37. package/js/PageSize.js +74 -0
  38. package/js/Printer.js +288 -0
  39. package/js/Renderer.js +513 -0
  40. package/js/SVGMeasure.js +92 -0
  41. package/js/StyleContextStack.js +191 -0
  42. package/js/TableProcessor.js +562 -0
  43. package/js/TextBreaker.js +179 -0
  44. package/js/TextDecorator.js +152 -0
  45. package/js/TextInlines.js +212 -0
  46. package/js/URLResolver.js +43 -0
  47. package/js/base.js +59 -0
  48. package/js/browser-extensions/OutputDocumentBrowser.js +82 -0
  49. package/js/browser-extensions/fonts/Roboto.js +38 -0
  50. package/js/browser-extensions/index.js +53 -0
  51. package/js/browser-extensions/pdfMake.js +3 -0
  52. package/js/browser-extensions/standard-fonts/Courier.js +38 -0
  53. package/js/browser-extensions/standard-fonts/Helvetica.js +38 -0
  54. package/js/browser-extensions/standard-fonts/Symbol.js +23 -0
  55. package/js/browser-extensions/standard-fonts/Times.js +38 -0
  56. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +23 -0
  57. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  58. package/js/columnCalculator.js +148 -0
  59. package/js/helpers/node.js +122 -0
  60. package/js/helpers/tools.js +46 -0
  61. package/js/helpers/variableType.js +59 -0
  62. package/js/index.js +15 -0
  63. package/js/qrEnc.js +721 -0
  64. package/js/standardPageSizes.js +56 -0
  65. package/js/tableLayouts.js +98 -0
  66. package/js/virtual-fs.js +60 -0
  67. package/package.json +94 -0
  68. package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -0
  69. package/src/3rd-party/svg-to-pdfkit/source.js +2745 -0
  70. package/src/3rd-party/svg-to-pdfkit.js +3 -0
  71. package/src/DocMeasure.js +768 -0
  72. package/src/DocPreprocessor.js +289 -0
  73. package/src/DocumentContext.js +345 -0
  74. package/src/ElementWriter.js +468 -0
  75. package/src/LayoutBuilder.js +1366 -0
  76. package/src/Line.js +108 -0
  77. package/src/OutputDocument.js +64 -0
  78. package/src/OutputDocumentServer.js +32 -0
  79. package/src/PDFDocument.js +178 -0
  80. package/src/PageElementWriter.js +191 -0
  81. package/src/PageSize.js +53 -0
  82. package/src/Printer.js +306 -0
  83. package/src/Renderer.js +546 -0
  84. package/src/SVGMeasure.js +109 -0
  85. package/src/StyleContextStack.js +208 -0
  86. package/src/TableProcessor.js +620 -0
  87. package/src/TextBreaker.js +181 -0
  88. package/src/TextDecorator.js +175 -0
  89. package/src/TextInlines.js +229 -0
  90. package/src/URLResolver.js +43 -0
  91. package/src/base.js +70 -0
  92. package/src/browser-extensions/OutputDocumentBrowser.js +80 -0
  93. package/src/browser-extensions/fonts/Roboto.js +27 -0
  94. package/src/browser-extensions/index.js +55 -0
  95. package/src/browser-extensions/pdfMake.js +1 -0
  96. package/src/browser-extensions/standard-fonts/Courier.js +27 -0
  97. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
  98. package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
  99. package/src/browser-extensions/standard-fonts/Times.js +27 -0
  100. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
  101. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  102. package/src/columnCalculator.js +154 -0
  103. package/src/helpers/node.js +134 -0
  104. package/src/helpers/tools.js +44 -0
  105. package/src/helpers/variableType.js +50 -0
  106. package/src/index.js +16 -0
  107. package/src/qrEnc.js +796 -0
  108. package/src/standardPageSizes.js +52 -0
  109. package/src/tableLayouts.js +100 -0
  110. package/src/virtual-fs.js +66 -0
  111. package/standard-fonts/Courier.js +8 -0
  112. package/standard-fonts/Helvetica.js +8 -0
  113. package/standard-fonts/Symbol.js +5 -0
  114. package/standard-fonts/Times.js +8 -0
  115. package/standard-fonts/ZapfDingbats.js +5 -0
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _source = _interopRequireDefault(require("./svg-to-pdfkit/source.js"));
6
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
7
+ var _default = exports.default = _source.default;
@@ -0,0 +1,675 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _TextInlines = _interopRequireDefault(require("./TextInlines"));
6
+ var _StyleContextStack = _interopRequireDefault(require("./StyleContextStack"));
7
+ var _columnCalculator = _interopRequireDefault(require("./columnCalculator"));
8
+ var _tableLayouts = require("./tableLayouts");
9
+ var _variableType = require("./helpers/variableType");
10
+ var _node = require("./helpers/node");
11
+ var _tools = require("./helpers/tools");
12
+ var _qrEnc = _interopRequireDefault(require("./qrEnc.js"));
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ class DocMeasure {
15
+ constructor(pdfDocument, styleDictionary, defaultStyle, svgMeasure, tableLayouts) {
16
+ this.pdfDocument = pdfDocument;
17
+ this.textInlines = new _TextInlines.default(pdfDocument);
18
+ this.styleStack = new _StyleContextStack.default(styleDictionary, defaultStyle);
19
+ this.svgMeasure = svgMeasure;
20
+ this.tableLayouts = tableLayouts;
21
+ this.autoImageIndex = 1;
22
+ }
23
+
24
+ /**
25
+ * Measures all nodes and sets min/max-width properties required for the second
26
+ * layout-pass.
27
+ *
28
+ * @param {object} docStructure document-definition-object
29
+ * @returns {object} document-measurement-object
30
+ */
31
+ measureDocument(docStructure) {
32
+ return this.measureNode(docStructure);
33
+ }
34
+ measureBlock(node) {
35
+ return this.measureNode(node);
36
+ }
37
+ measureNode(node) {
38
+ return this.styleStack.auto(node, () => {
39
+ // TODO: refactor + rethink whether this is the proper way to handle margins
40
+ node._margin = (0, _node.getNodeMargin)(node, this.styleStack);
41
+ if (node.section) {
42
+ return extendMargins(this.measureSection(node));
43
+ } else if (node.columns) {
44
+ return extendMargins(this.measureColumns(node));
45
+ } else if (node.stack) {
46
+ return extendMargins(this.measureVerticalContainer(node));
47
+ } else if (node.ul) {
48
+ return extendMargins(this.measureUnorderedList(node));
49
+ } else if (node.ol) {
50
+ return extendMargins(this.measureOrderedList(node));
51
+ } else if (node.table) {
52
+ return extendMargins(this.measureTable(node));
53
+ } else if (node.text !== undefined) {
54
+ return extendMargins(this.measureLeaf(node));
55
+ } else if (node.toc) {
56
+ return extendMargins(this.measureToc(node));
57
+ } else if (node.image) {
58
+ return extendMargins(this.measureImage(node));
59
+ } else if (node.svg) {
60
+ return extendMargins(this.measureSVG(node));
61
+ } else if (node.canvas) {
62
+ return extendMargins(this.measureCanvas(node));
63
+ } else if (node.qr) {
64
+ return extendMargins(this.measureQr(node));
65
+ } else if (node.attachment) {
66
+ return extendMargins(this.measureAttachment(node));
67
+ } else if (node.acroform) {
68
+ return extendMargins(this.measureAcroForm(node));
69
+ } else {
70
+ throw new Error(`Unrecognized document structure: ${(0, _node.stringifyNode)(node)}`);
71
+ }
72
+ });
73
+ function extendMargins(node) {
74
+ let margin = node._margin;
75
+ if (margin) {
76
+ node._minWidth += margin[0] + margin[2];
77
+ node._maxWidth += margin[0] + margin[2];
78
+ }
79
+ return node;
80
+ }
81
+ }
82
+ measureImageWithDimensions(node, dimensions) {
83
+ if (node.fit) {
84
+ let factor = dimensions.width / dimensions.height > node.fit[0] / node.fit[1] ? node.fit[0] / dimensions.width : node.fit[1] / dimensions.height;
85
+ node._width = node._minWidth = node._maxWidth = dimensions.width * factor;
86
+ node._height = dimensions.height * factor;
87
+ } else if (node.cover) {
88
+ node._width = node._minWidth = node._maxWidth = node.cover.width;
89
+ node._height = node._minHeight = node._maxHeight = node.cover.height;
90
+ } else {
91
+ let ratio = dimensions.width / dimensions.height;
92
+ node._width = node._minWidth = node._maxWidth = node.width || (node.height ? node.height * ratio : dimensions.width);
93
+ node._height = node.height || (node.width ? node.width / ratio : dimensions.height);
94
+ if ((0, _variableType.isNumber)(node.maxWidth) && node.maxWidth < node._width) {
95
+ node._width = node._minWidth = node._maxWidth = node.maxWidth;
96
+ node._height = node._width * dimensions.height / dimensions.width;
97
+ }
98
+ if ((0, _variableType.isNumber)(node.maxHeight) && node.maxHeight < node._height) {
99
+ node._height = node.maxHeight;
100
+ node._width = node._minWidth = node._maxWidth = node._height * dimensions.width / dimensions.height;
101
+ }
102
+ if ((0, _variableType.isNumber)(node.minWidth) && node.minWidth > node._width) {
103
+ node._width = node._minWidth = node._maxWidth = node.minWidth;
104
+ node._height = node._width * dimensions.height / dimensions.width;
105
+ }
106
+ if ((0, _variableType.isNumber)(node.minHeight) && node.minHeight > node._height) {
107
+ node._height = node.minHeight;
108
+ node._width = node._minWidth = node._maxWidth = node._height * dimensions.width / dimensions.height;
109
+ }
110
+ }
111
+ node._alignment = this.styleStack.getProperty('alignment');
112
+ }
113
+ convertIfBase64Image(node) {
114
+ if (/^data:image\/(jpeg|jpg|png);base64,/.test(node.image)) {
115
+ // base64 image
116
+ let label = `$$pdfmake$$${this.autoImageIndex++}`;
117
+ this.pdfDocument.images[label] = node.image;
118
+ node.image = label;
119
+ }
120
+ }
121
+ measureImage(node) {
122
+ this.convertIfBase64Image(node);
123
+ let image = this.pdfDocument.provideImage(node.image);
124
+ let imageSize = {
125
+ width: image.width,
126
+ height: image.height
127
+ };
128
+
129
+ // If EXIF orientation calls for it, swap width and height
130
+ if (image.orientation > 4) {
131
+ imageSize = {
132
+ width: image.height,
133
+ height: image.width
134
+ };
135
+ }
136
+ this.measureImageWithDimensions(node, imageSize);
137
+ return node;
138
+ }
139
+ measureSVG(node) {
140
+ let dimensions = this.svgMeasure.measureSVG(node.svg);
141
+ this.measureImageWithDimensions(node, dimensions);
142
+ node.font = this.styleStack.getProperty('font');
143
+
144
+ // SVG requires a defined width and height
145
+ if (!(0, _variableType.isNumber)(node._width) && !(0, _variableType.isNumber)(node._height)) {
146
+ throw new Error('SVG is missing defined width and height.');
147
+ } else if (!(0, _variableType.isNumber)(node._width)) {
148
+ throw new Error('SVG is missing defined width.');
149
+ } else if (!(0, _variableType.isNumber)(node._height)) {
150
+ throw new Error('SVG is missing defined height.');
151
+ }
152
+
153
+ // scale SVG based on final dimension
154
+ node.svg = this.svgMeasure.writeDimensions(node.svg, {
155
+ width: node._width,
156
+ height: node._height
157
+ });
158
+ return node;
159
+ }
160
+ measureLeaf(node) {
161
+ if (node._textRef && node._textRef._textNodeRef.text) {
162
+ node.text = node._textRef._textNodeRef.text;
163
+ }
164
+
165
+ // Make sure style properties of the node itself are considered when building inlines.
166
+ // We could also just pass [node] to buildInlines, but that fails for bullet points.
167
+ let styleStack = this.styleStack.clone();
168
+ styleStack.push(node);
169
+ let data = this.textInlines.buildInlines(node.text, styleStack);
170
+ node._inlines = data.items;
171
+ node._minWidth = data.minWidth;
172
+ node._maxWidth = data.maxWidth;
173
+ return node;
174
+ }
175
+ measureToc(node) {
176
+ if (node.toc.title) {
177
+ node.toc.title = this.measureNode(node.toc.title);
178
+ }
179
+ if (node.toc._items.length > 0) {
180
+ let body = [];
181
+ let textStyle = node.toc.textStyle || {};
182
+ let numberStyle = node.toc.numberStyle || textStyle;
183
+ let textMargin = node.toc.textMargin || [0, 0, 0, 0];
184
+ if (node.toc.sortBy === 'title') {
185
+ node.toc._items.sort((a, b) => {
186
+ return a._textNodeRef.text.localeCompare(b._textNodeRef.text, node.toc.sortLocale);
187
+ });
188
+ }
189
+ for (let i = 0, l = node.toc._items.length; i < l; i++) {
190
+ let item = node.toc._items[i];
191
+ let lineStyle = item._textNodeRef.tocStyle || textStyle;
192
+ let lineMargin = item._textNodeRef.tocMargin || textMargin;
193
+ let lineNumberStyle = item._textNodeRef.tocNumberStyle || numberStyle;
194
+ let destination = (0, _node.getNodeId)(item._nodeRef);
195
+ body.push([{
196
+ text: item._textNodeRef.text,
197
+ linkToDestination: destination,
198
+ alignment: 'left',
199
+ style: lineStyle,
200
+ margin: lineMargin
201
+ }, {
202
+ text: '00000',
203
+ linkToDestination: destination,
204
+ alignment: 'right',
205
+ _tocItemRef: item._nodeRef,
206
+ style: lineNumberStyle,
207
+ margin: [0, lineMargin[1], 0, lineMargin[3]]
208
+ }]);
209
+ if (node.toc.outlines) {
210
+ item._textNodeRef.outline = item._textNodeRef.outline || true;
211
+ }
212
+ }
213
+ node.toc._table = {
214
+ table: {
215
+ dontBreakRows: true,
216
+ widths: ['*', 'auto'],
217
+ body: body
218
+ },
219
+ layout: 'noBorders'
220
+ };
221
+ node.toc._table = this.measureNode(node.toc._table);
222
+ }
223
+ return node;
224
+ }
225
+ measureVerticalContainer(node) {
226
+ let items = node.stack;
227
+ node._minWidth = 0;
228
+ node._maxWidth = 0;
229
+ for (let i = 0, l = items.length; i < l; i++) {
230
+ items[i] = this.measureNode(items[i]);
231
+ node._minWidth = Math.max(node._minWidth, items[i]._minWidth);
232
+ node._maxWidth = Math.max(node._maxWidth, items[i]._maxWidth);
233
+ }
234
+ return node;
235
+ }
236
+ gapSizeForList() {
237
+ return this.textInlines.sizeOfText('9. ', this.styleStack);
238
+ }
239
+ buildUnorderedMarker(item, styleStack, gapSize, type) {
240
+ function buildDisc(gapSize, color) {
241
+ // TODO: ascender-based calculations
242
+ let radius = gapSize.fontSize / 6;
243
+ return {
244
+ canvas: [{
245
+ x: radius,
246
+ y: gapSize.height / gapSize.lineHeight + gapSize.descender - gapSize.fontSize / 3,
247
+ r1: radius,
248
+ r2: radius,
249
+ type: 'ellipse',
250
+ color: color
251
+ }]
252
+ };
253
+ }
254
+ function buildSquare(gapSize, color) {
255
+ // TODO: ascender-based calculations
256
+ let size = gapSize.fontSize / 3;
257
+ return {
258
+ canvas: [{
259
+ x: 0,
260
+ y: gapSize.height / gapSize.lineHeight + gapSize.descender - gapSize.fontSize / 3 - size / 2,
261
+ h: size,
262
+ w: size,
263
+ type: 'rect',
264
+ color: color
265
+ }]
266
+ };
267
+ }
268
+ function buildCircle(gapSize, color) {
269
+ // TODO: ascender-based calculations
270
+ let radius = gapSize.fontSize / 6;
271
+ return {
272
+ canvas: [{
273
+ x: radius,
274
+ y: gapSize.height / gapSize.lineHeight + gapSize.descender - gapSize.fontSize / 3,
275
+ r1: radius,
276
+ r2: radius,
277
+ type: 'ellipse',
278
+ lineColor: color
279
+ }]
280
+ };
281
+ }
282
+ let marker;
283
+ let color = _StyleContextStack.default.getStyleProperty(item, styleStack, 'markerColor', undefined) || styleStack.getProperty('color') || 'black';
284
+ switch (type) {
285
+ case 'circle':
286
+ marker = buildCircle(gapSize, color);
287
+ break;
288
+ case 'square':
289
+ marker = buildSquare(gapSize, color);
290
+ break;
291
+ case 'none':
292
+ marker = {};
293
+ break;
294
+ case 'disc':
295
+ default:
296
+ marker = buildDisc(gapSize, color);
297
+ break;
298
+ }
299
+ marker._minWidth = marker._maxWidth = gapSize.width;
300
+ marker._minHeight = marker._maxHeight = gapSize.height;
301
+ return marker;
302
+ }
303
+ buildOrderedMarker(item, counter, styleStack, type, separator) {
304
+ function prepareAlpha(counter) {
305
+ function toAlpha(num) {
306
+ return (num >= 26 ? toAlpha((num / 26 >> 0) - 1) : '') + 'abcdefghijklmnopqrstuvwxyz'[num % 26 >> 0];
307
+ }
308
+ if (counter < 1) {
309
+ return counter.toString();
310
+ }
311
+ return toAlpha(counter - 1);
312
+ }
313
+ function prepareRoman(counter) {
314
+ if (counter < 1 || counter > 4999) {
315
+ return counter.toString();
316
+ }
317
+ let num = counter;
318
+ let lookup = {
319
+ M: 1000,
320
+ CM: 900,
321
+ D: 500,
322
+ CD: 400,
323
+ C: 100,
324
+ XC: 90,
325
+ L: 50,
326
+ XL: 40,
327
+ X: 10,
328
+ IX: 9,
329
+ V: 5,
330
+ IV: 4,
331
+ I: 1
332
+ };
333
+ let roman = '';
334
+ for (let i in lookup) {
335
+ while (num >= lookup[i]) {
336
+ roman += i;
337
+ num -= lookup[i];
338
+ }
339
+ }
340
+ return roman;
341
+ }
342
+ function prepareDecimal(counter) {
343
+ return counter.toString();
344
+ }
345
+ let counterText;
346
+ switch (type) {
347
+ case 'none':
348
+ counterText = null;
349
+ break;
350
+ case 'upper-alpha':
351
+ counterText = prepareAlpha(counter).toUpperCase();
352
+ break;
353
+ case 'lower-alpha':
354
+ counterText = prepareAlpha(counter);
355
+ break;
356
+ case 'upper-roman':
357
+ counterText = prepareRoman(counter);
358
+ break;
359
+ case 'lower-roman':
360
+ counterText = prepareRoman(counter).toLowerCase();
361
+ break;
362
+ case 'decimal':
363
+ default:
364
+ counterText = prepareDecimal(counter);
365
+ break;
366
+ }
367
+ if (counterText === null) {
368
+ return {};
369
+ }
370
+ if (separator) {
371
+ if (Array.isArray(separator)) {
372
+ if (separator[0]) {
373
+ counterText = separator[0] + counterText;
374
+ }
375
+ if (separator[1]) {
376
+ counterText += separator[1];
377
+ }
378
+ counterText += ' ';
379
+ } else {
380
+ counterText += `${separator} `;
381
+ }
382
+ }
383
+ let markerColor = _StyleContextStack.default.getStyleProperty(item, styleStack, 'markerColor', undefined) || styleStack.getProperty('color') || 'black';
384
+ let textArray = {
385
+ text: counterText,
386
+ color: markerColor
387
+ };
388
+ return {
389
+ _inlines: this.textInlines.buildInlines(textArray, styleStack).items
390
+ };
391
+ }
392
+ measureUnorderedList(node) {
393
+ let style = this.styleStack.clone();
394
+ let items = node.ul;
395
+ node.type = node.type || 'disc';
396
+ node._gapSize = this.gapSizeForList();
397
+ node._minWidth = 0;
398
+ node._maxWidth = 0;
399
+ for (let i = 0, l = items.length; i < l; i++) {
400
+ let item = items[i] = this.measureNode(items[i]);
401
+ if (!item.ol && !item.ul) {
402
+ item.listMarker = this.buildUnorderedMarker(item, style, node._gapSize, item.listType || node.type);
403
+ }
404
+ node._minWidth = Math.max(node._minWidth, items[i]._minWidth + node._gapSize.width);
405
+ node._maxWidth = Math.max(node._maxWidth, items[i]._maxWidth + node._gapSize.width);
406
+ }
407
+ return node;
408
+ }
409
+ measureOrderedList(node) {
410
+ let style = this.styleStack.clone();
411
+ let items = node.ol;
412
+ node.type = node.type || 'decimal';
413
+ node.separator = node.separator || '.';
414
+ node.reversed = node.reversed || false;
415
+ if (!(0, _variableType.isNumber)(node.start)) {
416
+ node.start = node.reversed ? items.length : 1;
417
+ }
418
+ node._gapSize = this.gapSizeForList();
419
+ node._minWidth = 0;
420
+ node._maxWidth = 0;
421
+ let counter = node.start;
422
+ for (let i = 0, l = items.length; i < l; i++) {
423
+ let item = items[i] = this.measureNode(items[i]);
424
+ if (!item.ol && !item.ul) {
425
+ let counterValue = (0, _variableType.isNumber)(item.counter) ? item.counter : counter;
426
+ item.listMarker = this.buildOrderedMarker(item, counterValue, style, item.listType || node.type, node.separator);
427
+ if (item.listMarker._inlines) {
428
+ node._gapSize.width = Math.max(node._gapSize.width, item.listMarker._inlines[0].width);
429
+ }
430
+ if (node.reversed) {
431
+ counter--;
432
+ } else {
433
+ counter++;
434
+ }
435
+ }
436
+ node._minWidth = Math.max(node._minWidth, items[i]._minWidth);
437
+ node._maxWidth = Math.max(node._maxWidth, items[i]._maxWidth);
438
+ }
439
+ node._minWidth += node._gapSize.width;
440
+ node._maxWidth += node._gapSize.width;
441
+ for (let i = 0, l = items.length; i < l; i++) {
442
+ let item = items[i];
443
+ if (!item.ol && !item.ul) {
444
+ item.listMarker._minWidth = item.listMarker._maxWidth = node._gapSize.width;
445
+ }
446
+ }
447
+ return node;
448
+ }
449
+ measureSection(node) {
450
+ // TODO: properties
451
+
452
+ node.section = this.measureNode(node.section);
453
+ return node;
454
+ }
455
+ measureColumns(node) {
456
+ let columns = node.columns;
457
+ node._gap = this.styleStack.getProperty('columnGap') || 0;
458
+ for (let i = 0, l = columns.length; i < l; i++) {
459
+ columns[i] = this.measureNode(columns[i]);
460
+ }
461
+ let measures = _columnCalculator.default.measureMinMax(columns);
462
+ let numGaps = columns.length > 0 ? columns.length - 1 : 0;
463
+ node._minWidth = measures.min + node._gap * numGaps;
464
+ node._maxWidth = measures.max + node._gap * numGaps;
465
+ return node;
466
+ }
467
+ measureTable(node) {
468
+ extendTableWidths(node);
469
+ node._layout = getLayout(this.tableLayouts);
470
+ node._offsets = getOffsets(node._layout);
471
+ let colSpans = [];
472
+ let col;
473
+ let row;
474
+ let cols;
475
+ let rows;
476
+ for (col = 0, cols = node.table.body[0].length; col < cols; col++) {
477
+ let c = node.table.widths[col];
478
+ c._minWidth = 0;
479
+ c._maxWidth = 0;
480
+ for (row = 0, rows = node.table.body.length; row < rows; row++) {
481
+ let rowData = node.table.body[row];
482
+ let data = rowData[col];
483
+ if (data === undefined) {
484
+ throw new Error(`Malformed table row, a cell is undefined.\nRow index: ${row}\nColumn index: ${col}\nRow data: ${(0, _node.stringifyNode)(rowData)}`);
485
+ }
486
+ if (data === null) {
487
+ // transform to object
488
+ data = '';
489
+ }
490
+ if (!data._span) {
491
+ data = rowData[col] = this.styleStack.auto(data, measureCb(this, data));
492
+ if (data.colSpan && data.colSpan > 1) {
493
+ markSpans(rowData, col, data.colSpan);
494
+ colSpans.push({
495
+ col: col,
496
+ span: data.colSpan,
497
+ minWidth: data._minWidth,
498
+ maxWidth: data._maxWidth
499
+ });
500
+ } else {
501
+ c._minWidth = Math.max(c._minWidth, data._minWidth);
502
+ c._maxWidth = Math.max(c._maxWidth, data._maxWidth);
503
+ }
504
+ }
505
+ if (data.rowSpan && data.rowSpan > 1) {
506
+ markVSpans(node.table, row, col, data.rowSpan);
507
+ }
508
+ }
509
+ }
510
+ extendWidthsForColSpans();
511
+ let measures = _columnCalculator.default.measureMinMax(node.table.widths);
512
+ node._minWidth = measures.min + node._offsets.total;
513
+ node._maxWidth = measures.max + node._offsets.total;
514
+ return node;
515
+ function measureCb(_this, data) {
516
+ return () => {
517
+ if ((0, _variableType.isObject)(data)) {
518
+ data.fillColor = _this.styleStack.getProperty('fillColor');
519
+ data.fillOpacity = _this.styleStack.getProperty('fillOpacity');
520
+ }
521
+ return _this.measureNode(data);
522
+ };
523
+ }
524
+ function getLayout(tableLayouts) {
525
+ let layout = node.layout;
526
+ if ((0, _variableType.isString)(layout)) {
527
+ layout = tableLayouts[layout];
528
+ }
529
+ return (0, _tools.pack)(_tableLayouts.defaultTableLayout, layout);
530
+ }
531
+ function getOffsets(layout) {
532
+ let offsets = [];
533
+ let totalOffset = 0;
534
+ let prevRightPadding = 0;
535
+ for (let i = 0, l = node.table.widths.length; i < l; i++) {
536
+ let lOffset = prevRightPadding + layout.vLineWidth(i, node) + layout.paddingLeft(i, node);
537
+ offsets.push(lOffset);
538
+ totalOffset += lOffset;
539
+ prevRightPadding = layout.paddingRight(i, node);
540
+ }
541
+ totalOffset += prevRightPadding + layout.vLineWidth(node.table.widths.length, node);
542
+ return {
543
+ total: totalOffset,
544
+ offsets: offsets
545
+ };
546
+ }
547
+ function extendWidthsForColSpans() {
548
+ let q;
549
+ let j;
550
+ for (let i = 0, l = colSpans.length; i < l; i++) {
551
+ let span = colSpans[i];
552
+ let currentMinMax = getMinMax(span.col, span.span, node._offsets);
553
+ let minDifference = span.minWidth - currentMinMax.minWidth;
554
+ let maxDifference = span.maxWidth - currentMinMax.maxWidth;
555
+ if (minDifference > 0) {
556
+ q = minDifference / span.span;
557
+ for (j = 0; j < span.span; j++) {
558
+ node.table.widths[span.col + j]._minWidth += q;
559
+ }
560
+ }
561
+ if (maxDifference > 0) {
562
+ q = maxDifference / span.span;
563
+ for (j = 0; j < span.span; j++) {
564
+ node.table.widths[span.col + j]._maxWidth += q;
565
+ }
566
+ }
567
+ }
568
+ }
569
+ function getMinMax(col, span, offsets) {
570
+ let result = {
571
+ minWidth: 0,
572
+ maxWidth: 0
573
+ };
574
+ for (let i = 0; i < span; i++) {
575
+ result.minWidth += node.table.widths[col + i]._minWidth + (i ? offsets.offsets[col + i] : 0);
576
+ result.maxWidth += node.table.widths[col + i]._maxWidth + (i ? offsets.offsets[col + i] : 0);
577
+ }
578
+ return result;
579
+ }
580
+ function markSpans(rowData, col, span) {
581
+ for (let i = 1; i < span; i++) {
582
+ rowData[col + i] = {
583
+ _span: true,
584
+ _minWidth: 0,
585
+ _maxWidth: 0,
586
+ rowSpan: rowData[col].rowSpan
587
+ };
588
+ }
589
+ }
590
+ function markVSpans(table, row, col, span) {
591
+ for (let i = 1; i < span; i++) {
592
+ table.body[row + i][col] = {
593
+ _span: true,
594
+ _minWidth: 0,
595
+ _maxWidth: 0,
596
+ fillColor: table.body[row][col].fillColor,
597
+ fillOpacity: table.body[row][col].fillOpacity
598
+ };
599
+ }
600
+ }
601
+ function extendTableWidths(node) {
602
+ if (!node.table.widths) {
603
+ node.table.widths = 'auto';
604
+ }
605
+ if ((0, _variableType.isString)(node.table.widths)) {
606
+ node.table.widths = [node.table.widths];
607
+ while (node.table.widths.length < node.table.body[0].length) {
608
+ node.table.widths.push(node.table.widths[node.table.widths.length - 1]);
609
+ }
610
+ }
611
+ for (let i = 0, l = node.table.widths.length; i < l; i++) {
612
+ let w = node.table.widths[i];
613
+ if ((0, _variableType.isNumber)(w) || (0, _variableType.isString)(w)) {
614
+ node.table.widths[i] = {
615
+ width: w
616
+ };
617
+ }
618
+ }
619
+ }
620
+ }
621
+ measureCanvas(node) {
622
+ let w = 0;
623
+ let h = 0;
624
+ for (let i = 0, l = node.canvas.length; i < l; i++) {
625
+ let vector = node.canvas[i];
626
+ switch (vector.type) {
627
+ case 'ellipse':
628
+ w = Math.max(w, vector.x + vector.r1);
629
+ h = Math.max(h, vector.y + vector.r2);
630
+ break;
631
+ case 'rect':
632
+ w = Math.max(w, vector.x + vector.w);
633
+ h = Math.max(h, vector.y + vector.h);
634
+ break;
635
+ case 'line':
636
+ w = Math.max(w, vector.x1, vector.x2);
637
+ h = Math.max(h, vector.y1, vector.y2);
638
+ break;
639
+ case 'polyline':
640
+ for (let i2 = 0, l2 = vector.points.length; i2 < l2; i2++) {
641
+ w = Math.max(w, vector.points[i2].x);
642
+ h = Math.max(h, vector.points[i2].y);
643
+ }
644
+ break;
645
+ }
646
+ }
647
+ node._minWidth = node._maxWidth = w;
648
+ node._minHeight = node._maxHeight = h;
649
+ node._alignment = this.styleStack.getProperty('alignment');
650
+ return node;
651
+ }
652
+ measureQr(node) {
653
+ node = _qrEnc.default.measure(node);
654
+ node._alignment = this.styleStack.getProperty('alignment');
655
+ return node;
656
+ }
657
+ measureAttachment(node) {
658
+ node._width = node.width || 7;
659
+ node._height = node.height || 18;
660
+ return node;
661
+ }
662
+ measureAcroForm(node) {
663
+ node._minWidth = 10;
664
+ node._minHeight = 10;
665
+ let font = _StyleContextStack.default.getStyleProperty(node, this.styleStack, 'font', 'Roboto');
666
+ let bold = _StyleContextStack.default.getStyleProperty(node, this.styleStack, 'bold', false);
667
+ let italics = _StyleContextStack.default.getStyleProperty(node, this.styleStack, 'italics', false);
668
+ node.font = font;
669
+ node.bold = bold;
670
+ node.italics = italics;
671
+ node.alignment = _StyleContextStack.default.getStyleProperty(node, this.styleStack, 'alignment', 'left');
672
+ return node;
673
+ }
674
+ }
675
+ var _default = exports.default = DocMeasure;