@flowaccount/pdfmake 1.0.5-staging.0 → 1.0.6-staging.2
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.
- package/LICENSE +21 -21
- package/README.md +297 -297
- package/build/pdfmake.js +49709 -49954
- package/build/pdfmake.min.js +2 -2
- package/build/pdfmake.min.js.map +1 -1
- package/build/vfs_fonts.js +6 -6
- package/package.json +110 -110
- package/src/3rd-party/svg-to-pdfkit.js +3 -3
- package/src/browser-extensions/URLBrowserResolver.js +96 -96
- package/src/browser-extensions/pdfMake.js +361 -361
- package/src/browser-extensions/tokenizer-shim.js +15 -15
- package/src/browser-extensions/virtual-fs.js +55 -55
- package/src/columnCalculator.js +157 -157
- package/src/docMeasure.js +831 -831
- package/src/docPreprocessor.js +277 -277
- package/src/documentContext.js +383 -383
- package/src/elementWriter.js +442 -434
- package/src/fontProvider.js +68 -68
- package/src/helpers.js +138 -138
- package/src/imageMeasure.js +70 -70
- package/src/layoutBuilder.js +1998 -1770
- package/src/line.js +91 -91
- package/src/pageElementWriter.js +362 -362
- package/src/pdfKitEngine.js +21 -21
- package/src/printer.js +1191 -1191
- package/src/qrEnc.js +790 -790
- package/src/standardPageSizes.js +54 -54
- package/src/styleContextStack.js +138 -138
- package/src/svgMeasure.js +70 -70
- package/src/tableProcessor.js +791 -789
- package/src/textDecorator.js +157 -157
- package/src/textTools.js +442 -442
- package/src/traversalTracker.js +47 -47
package/src/elementWriter.js
CHANGED
|
@@ -1,434 +1,442 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var Line = require('./line');
|
|
4
|
-
var isNumber = require('./helpers').isNumber;
|
|
5
|
-
var pack = require('./helpers').pack;
|
|
6
|
-
var offsetVector = require('./helpers').offsetVector;
|
|
7
|
-
var DocumentContext = require('./documentContext');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates an instance of ElementWriter - a line/vector writer, which adds
|
|
11
|
-
* elements to current page and sets their positions based on the context
|
|
12
|
-
*/
|
|
13
|
-
function ElementWriter(context, tracker) {
|
|
14
|
-
this.context = context;
|
|
15
|
-
this.contextStack = [];
|
|
16
|
-
this.tracker = tracker;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function addPageItem(page, item, index) {
|
|
20
|
-
if (index === null || index === undefined || index < 0 || index > page.items.length) {
|
|
21
|
-
page.items.push(item);
|
|
22
|
-
} else {
|
|
23
|
-
page.items.splice(index, 0, item);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
ElementWriter.prototype.addLine = function (line, dontUpdateContextPosition, index) {
|
|
28
|
-
var height = line.getHeight();
|
|
29
|
-
var context = this.context;
|
|
30
|
-
var page = context.getCurrentPage(),
|
|
31
|
-
position = this.getCurrentPositionOnPage();
|
|
32
|
-
|
|
33
|
-
if (context.availableHeight < height || !page) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
line.x = context.x + (line.x || 0);
|
|
38
|
-
line.y = context.y + (line.y || 0);
|
|
39
|
-
|
|
40
|
-
this.alignLine(line);
|
|
41
|
-
|
|
42
|
-
addPageItem(page, {
|
|
43
|
-
type: 'line',
|
|
44
|
-
item: line
|
|
45
|
-
}, index);
|
|
46
|
-
this.tracker.emit('lineAdded', line);
|
|
47
|
-
|
|
48
|
-
if (!dontUpdateContextPosition) {
|
|
49
|
-
context.moveDown(height);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return position;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
ElementWriter.prototype.alignLine = function (line) {
|
|
56
|
-
var width = this.context.availableWidth;
|
|
57
|
-
var lineWidth = line.getWidth();
|
|
58
|
-
|
|
59
|
-
var alignment = line.inlines && line.inlines.length > 0 && line.inlines[0].alignment;
|
|
60
|
-
|
|
61
|
-
var offset = 0;
|
|
62
|
-
switch (alignment) {
|
|
63
|
-
case 'right':
|
|
64
|
-
offset = width - lineWidth;
|
|
65
|
-
break;
|
|
66
|
-
case 'center':
|
|
67
|
-
offset = (width - lineWidth) / 2;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (offset) {
|
|
72
|
-
line.x = (line.x || 0) + offset;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (alignment === 'justify' &&
|
|
76
|
-
!line.newLineForced &&
|
|
77
|
-
!line.lastLineInParagraph &&
|
|
78
|
-
line.inlines.length > 1) {
|
|
79
|
-
var additionalSpacing = (width - lineWidth) / (line.inlines.length - 1);
|
|
80
|
-
|
|
81
|
-
for (var i = 1, l = line.inlines.length; i < l; i++) {
|
|
82
|
-
offset = i * additionalSpacing;
|
|
83
|
-
|
|
84
|
-
line.inlines[i].x += offset;
|
|
85
|
-
line.inlines[i].justifyShift = additionalSpacing;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
ElementWriter.prototype.addImage = function (image, index, type) {
|
|
91
|
-
var context = this.context;
|
|
92
|
-
var page = context.getCurrentPage(),
|
|
93
|
-
position = this.getCurrentPositionOnPage();
|
|
94
|
-
|
|
95
|
-
if (!page || (image.absolutePosition === undefined && context.availableHeight < image._height && page.items.length > 0)) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (image._x === undefined) {
|
|
100
|
-
image._x = image.x || 0;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
image.x = context.x + image._x;
|
|
104
|
-
image.y = context.y;
|
|
105
|
-
|
|
106
|
-
this.alignImage(image);
|
|
107
|
-
|
|
108
|
-
addPageItem(page, {
|
|
109
|
-
type: type || 'image',
|
|
110
|
-
item: image
|
|
111
|
-
}, index);
|
|
112
|
-
|
|
113
|
-
context.moveDown(image._height);
|
|
114
|
-
|
|
115
|
-
return position;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
ElementWriter.prototype.addSVG = function (image, index) {
|
|
119
|
-
return this.addImage(image, index, 'svg');
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
ElementWriter.prototype.addQr = function (qr, index) {
|
|
123
|
-
var context = this.context;
|
|
124
|
-
var page = context.getCurrentPage(),
|
|
125
|
-
position = this.getCurrentPositionOnPage();
|
|
126
|
-
|
|
127
|
-
if (!page || (qr.absolutePosition === undefined && context.availableHeight < qr._height)) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (qr._x === undefined) {
|
|
132
|
-
qr._x = qr.x || 0;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
qr.x = context.x + qr._x;
|
|
136
|
-
qr.y = context.y;
|
|
137
|
-
|
|
138
|
-
this.alignImage(qr);
|
|
139
|
-
|
|
140
|
-
for (var i = 0, l = qr._canvas.length; i < l; i++) {
|
|
141
|
-
var vector = qr._canvas[i];
|
|
142
|
-
vector.x += qr.x;
|
|
143
|
-
vector.y += qr.y;
|
|
144
|
-
this.addVector(vector, true, true, index);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
context.moveDown(qr._height);
|
|
148
|
-
|
|
149
|
-
return position;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
ElementWriter.prototype.alignImage = function (image) {
|
|
153
|
-
var width = this.context.availableWidth;
|
|
154
|
-
var imageWidth = image._minWidth;
|
|
155
|
-
var offset = 0;
|
|
156
|
-
switch (image._alignment) {
|
|
157
|
-
case 'right':
|
|
158
|
-
offset = width - imageWidth;
|
|
159
|
-
break;
|
|
160
|
-
case 'center':
|
|
161
|
-
offset = (width - imageWidth) / 2;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (offset) {
|
|
166
|
-
image.x = (image.x || 0) + offset;
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
ElementWriter.prototype.alignCanvas = function (node) {
|
|
171
|
-
var width = this.context.availableWidth;
|
|
172
|
-
var canvasWidth = node._minWidth;
|
|
173
|
-
var offset = 0;
|
|
174
|
-
switch (node._alignment) {
|
|
175
|
-
case 'right':
|
|
176
|
-
offset = width - canvasWidth;
|
|
177
|
-
break;
|
|
178
|
-
case 'center':
|
|
179
|
-
offset = (width - canvasWidth) / 2;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
if (offset) {
|
|
183
|
-
node.canvas.forEach(function (vector) {
|
|
184
|
-
offsetVector(vector, offset, 0);
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
ElementWriter.prototype.addVector = function (vector, ignoreContextX, ignoreContextY, index, forcePage) {
|
|
190
|
-
var context = this.context;
|
|
191
|
-
var page = context.getCurrentPage();
|
|
192
|
-
if (isNumber(forcePage)) {
|
|
193
|
-
page = context.pages[forcePage];
|
|
194
|
-
}
|
|
195
|
-
var position = this.getCurrentPositionOnPage();
|
|
196
|
-
|
|
197
|
-
if (page) {
|
|
198
|
-
offsetVector(vector, ignoreContextX ? 0 : context.x, ignoreContextY ? 0 : context.y);
|
|
199
|
-
addPageItem(page, {
|
|
200
|
-
type: 'vector',
|
|
201
|
-
item: vector
|
|
202
|
-
}, index);
|
|
203
|
-
return position;
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
ElementWriter.prototype.beginClip = function (width, height) {
|
|
208
|
-
var ctx = this.context;
|
|
209
|
-
var page = ctx.getCurrentPage();
|
|
210
|
-
page.items.push({
|
|
211
|
-
type: 'beginClip',
|
|
212
|
-
item: { x: ctx.x, y: ctx.y, width: width, height: height }
|
|
213
|
-
});
|
|
214
|
-
return true;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
ElementWriter.prototype.endClip = function () {
|
|
218
|
-
var ctx = this.context;
|
|
219
|
-
var page = ctx.getCurrentPage();
|
|
220
|
-
page.items.push({
|
|
221
|
-
type: 'endClip'
|
|
222
|
-
});
|
|
223
|
-
return true;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
function cloneLine(line) {
|
|
227
|
-
var result = new Line(line.maxWidth);
|
|
228
|
-
|
|
229
|
-
for (var key in line) {
|
|
230
|
-
if (line.hasOwnProperty(key)) {
|
|
231
|
-
result[key] = line[key];
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return result;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
ElementWriter.prototype.addFragment = function (block, useBlockXOffset, useBlockYOffset, dontUpdateContextPosition, isFooter) {
|
|
239
|
-
var ctx = this.context;
|
|
240
|
-
var page = ctx.getCurrentPage();
|
|
241
|
-
|
|
242
|
-
if (!useBlockXOffset && block.height > ctx.availableHeight) {
|
|
243
|
-
return false;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
var
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
var style = (colSpec.style || {});
|
|
259
|
-
var lw = style.lineWidth != null ? style.lineWidth : 0.5;
|
|
260
|
-
var lc = style.color || '#000000';
|
|
261
|
-
var dashCfg = style.dash;
|
|
262
|
-
var includeOuter = colSpec.includeOuter !== false;
|
|
263
|
-
var startIndex = includeOuter ? 0 : 1;
|
|
264
|
-
var endIndex = includeOuter ? rawWidths.length : rawWidths.length - 1;
|
|
265
|
-
|
|
266
|
-
for (var ci = startIndex; ci < endIndex; ci++) {
|
|
267
|
-
var xGuide = ctx.x + rawWidths[ci] - 0.25;
|
|
268
|
-
page.items.push({
|
|
269
|
-
type: 'vector',
|
|
270
|
-
item: {
|
|
271
|
-
type: 'line',
|
|
272
|
-
x1: xGuide,
|
|
273
|
-
y1: gapTopY,
|
|
274
|
-
x2: xGuide,
|
|
275
|
-
y2: gapTopY + gapHeight,
|
|
276
|
-
lineWidth: lw,
|
|
277
|
-
lineColor: lc,
|
|
278
|
-
dash: dashCfg ? {
|
|
279
|
-
length: dashCfg.length,
|
|
280
|
-
space: dashCfg.space != null ? dashCfg.space : dashCfg.gap
|
|
281
|
-
} : undefined,
|
|
282
|
-
_footerGuideLine: true
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
ctx.moveDown(gapHeight);
|
|
289
|
-
}
|
|
290
|
-
} else if(isFooter){
|
|
291
|
-
ctx.moveDown(ctx.availableHeight - block.height);
|
|
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
|
-
page
|
|
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
|
-
ElementWriter.prototype.
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
var
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Line = require('./line');
|
|
4
|
+
var isNumber = require('./helpers').isNumber;
|
|
5
|
+
var pack = require('./helpers').pack;
|
|
6
|
+
var offsetVector = require('./helpers').offsetVector;
|
|
7
|
+
var DocumentContext = require('./documentContext');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of ElementWriter - a line/vector writer, which adds
|
|
11
|
+
* elements to current page and sets their positions based on the context
|
|
12
|
+
*/
|
|
13
|
+
function ElementWriter(context, tracker) {
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.contextStack = [];
|
|
16
|
+
this.tracker = tracker;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function addPageItem(page, item, index) {
|
|
20
|
+
if (index === null || index === undefined || index < 0 || index > page.items.length) {
|
|
21
|
+
page.items.push(item);
|
|
22
|
+
} else {
|
|
23
|
+
page.items.splice(index, 0, item);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
ElementWriter.prototype.addLine = function (line, dontUpdateContextPosition, index) {
|
|
28
|
+
var height = line.getHeight();
|
|
29
|
+
var context = this.context;
|
|
30
|
+
var page = context.getCurrentPage(),
|
|
31
|
+
position = this.getCurrentPositionOnPage();
|
|
32
|
+
|
|
33
|
+
if (context.availableHeight < height || !page) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
line.x = context.x + (line.x || 0);
|
|
38
|
+
line.y = context.y + (line.y || 0);
|
|
39
|
+
|
|
40
|
+
this.alignLine(line);
|
|
41
|
+
|
|
42
|
+
addPageItem(page, {
|
|
43
|
+
type: 'line',
|
|
44
|
+
item: line
|
|
45
|
+
}, index);
|
|
46
|
+
this.tracker.emit('lineAdded', line);
|
|
47
|
+
|
|
48
|
+
if (!dontUpdateContextPosition) {
|
|
49
|
+
context.moveDown(height);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return position;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
ElementWriter.prototype.alignLine = function (line) {
|
|
56
|
+
var width = this.context.availableWidth;
|
|
57
|
+
var lineWidth = line.getWidth();
|
|
58
|
+
|
|
59
|
+
var alignment = line.inlines && line.inlines.length > 0 && line.inlines[0].alignment;
|
|
60
|
+
|
|
61
|
+
var offset = 0;
|
|
62
|
+
switch (alignment) {
|
|
63
|
+
case 'right':
|
|
64
|
+
offset = width - lineWidth;
|
|
65
|
+
break;
|
|
66
|
+
case 'center':
|
|
67
|
+
offset = (width - lineWidth) / 2;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (offset) {
|
|
72
|
+
line.x = (line.x || 0) + offset;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (alignment === 'justify' &&
|
|
76
|
+
!line.newLineForced &&
|
|
77
|
+
!line.lastLineInParagraph &&
|
|
78
|
+
line.inlines.length > 1) {
|
|
79
|
+
var additionalSpacing = (width - lineWidth) / (line.inlines.length - 1);
|
|
80
|
+
|
|
81
|
+
for (var i = 1, l = line.inlines.length; i < l; i++) {
|
|
82
|
+
offset = i * additionalSpacing;
|
|
83
|
+
|
|
84
|
+
line.inlines[i].x += offset;
|
|
85
|
+
line.inlines[i].justifyShift = additionalSpacing;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
ElementWriter.prototype.addImage = function (image, index, type) {
|
|
91
|
+
var context = this.context;
|
|
92
|
+
var page = context.getCurrentPage(),
|
|
93
|
+
position = this.getCurrentPositionOnPage();
|
|
94
|
+
|
|
95
|
+
if (!page || (image.absolutePosition === undefined && context.availableHeight < image._height && page.items.length > 0)) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (image._x === undefined) {
|
|
100
|
+
image._x = image.x || 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
image.x = context.x + image._x;
|
|
104
|
+
image.y = context.y;
|
|
105
|
+
|
|
106
|
+
this.alignImage(image);
|
|
107
|
+
|
|
108
|
+
addPageItem(page, {
|
|
109
|
+
type: type || 'image',
|
|
110
|
+
item: image
|
|
111
|
+
}, index);
|
|
112
|
+
|
|
113
|
+
context.moveDown(image._height);
|
|
114
|
+
|
|
115
|
+
return position;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
ElementWriter.prototype.addSVG = function (image, index) {
|
|
119
|
+
return this.addImage(image, index, 'svg');
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
ElementWriter.prototype.addQr = function (qr, index) {
|
|
123
|
+
var context = this.context;
|
|
124
|
+
var page = context.getCurrentPage(),
|
|
125
|
+
position = this.getCurrentPositionOnPage();
|
|
126
|
+
|
|
127
|
+
if (!page || (qr.absolutePosition === undefined && context.availableHeight < qr._height)) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (qr._x === undefined) {
|
|
132
|
+
qr._x = qr.x || 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
qr.x = context.x + qr._x;
|
|
136
|
+
qr.y = context.y;
|
|
137
|
+
|
|
138
|
+
this.alignImage(qr);
|
|
139
|
+
|
|
140
|
+
for (var i = 0, l = qr._canvas.length; i < l; i++) {
|
|
141
|
+
var vector = qr._canvas[i];
|
|
142
|
+
vector.x += qr.x;
|
|
143
|
+
vector.y += qr.y;
|
|
144
|
+
this.addVector(vector, true, true, index);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
context.moveDown(qr._height);
|
|
148
|
+
|
|
149
|
+
return position;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
ElementWriter.prototype.alignImage = function (image) {
|
|
153
|
+
var width = this.context.availableWidth;
|
|
154
|
+
var imageWidth = image._minWidth;
|
|
155
|
+
var offset = 0;
|
|
156
|
+
switch (image._alignment) {
|
|
157
|
+
case 'right':
|
|
158
|
+
offset = width - imageWidth;
|
|
159
|
+
break;
|
|
160
|
+
case 'center':
|
|
161
|
+
offset = (width - imageWidth) / 2;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (offset) {
|
|
166
|
+
image.x = (image.x || 0) + offset;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
ElementWriter.prototype.alignCanvas = function (node) {
|
|
171
|
+
var width = this.context.availableWidth;
|
|
172
|
+
var canvasWidth = node._minWidth;
|
|
173
|
+
var offset = 0;
|
|
174
|
+
switch (node._alignment) {
|
|
175
|
+
case 'right':
|
|
176
|
+
offset = width - canvasWidth;
|
|
177
|
+
break;
|
|
178
|
+
case 'center':
|
|
179
|
+
offset = (width - canvasWidth) / 2;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
if (offset) {
|
|
183
|
+
node.canvas.forEach(function (vector) {
|
|
184
|
+
offsetVector(vector, offset, 0);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
ElementWriter.prototype.addVector = function (vector, ignoreContextX, ignoreContextY, index, forcePage) {
|
|
190
|
+
var context = this.context;
|
|
191
|
+
var page = context.getCurrentPage();
|
|
192
|
+
if (isNumber(forcePage)) {
|
|
193
|
+
page = context.pages[forcePage];
|
|
194
|
+
}
|
|
195
|
+
var position = this.getCurrentPositionOnPage();
|
|
196
|
+
|
|
197
|
+
if (page) {
|
|
198
|
+
offsetVector(vector, ignoreContextX ? 0 : context.x, ignoreContextY ? 0 : context.y);
|
|
199
|
+
addPageItem(page, {
|
|
200
|
+
type: 'vector',
|
|
201
|
+
item: vector
|
|
202
|
+
}, index);
|
|
203
|
+
return position;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
ElementWriter.prototype.beginClip = function (width, height) {
|
|
208
|
+
var ctx = this.context;
|
|
209
|
+
var page = ctx.getCurrentPage();
|
|
210
|
+
page.items.push({
|
|
211
|
+
type: 'beginClip',
|
|
212
|
+
item: { x: ctx.x, y: ctx.y, width: width, height: height }
|
|
213
|
+
});
|
|
214
|
+
return true;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
ElementWriter.prototype.endClip = function () {
|
|
218
|
+
var ctx = this.context;
|
|
219
|
+
var page = ctx.getCurrentPage();
|
|
220
|
+
page.items.push({
|
|
221
|
+
type: 'endClip'
|
|
222
|
+
});
|
|
223
|
+
return true;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
function cloneLine(line) {
|
|
227
|
+
var result = new Line(line.maxWidth);
|
|
228
|
+
|
|
229
|
+
for (var key in line) {
|
|
230
|
+
if (line.hasOwnProperty(key)) {
|
|
231
|
+
result[key] = line[key];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
ElementWriter.prototype.addFragment = function (block, useBlockXOffset, useBlockYOffset, dontUpdateContextPosition, isFooter) {
|
|
239
|
+
var ctx = this.context;
|
|
240
|
+
var page = ctx.getCurrentPage();
|
|
241
|
+
|
|
242
|
+
if (!useBlockXOffset && block.height > ctx.availableHeight) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// draw line for inline image template
|
|
247
|
+
if (isFooter && block._footerGapOption && block._footerGapOption.enabled) {
|
|
248
|
+
var gapHeight = ctx.availableHeight - block.height;
|
|
249
|
+
if (gapHeight > 0) {
|
|
250
|
+
var gapTopY = ctx.y;
|
|
251
|
+
var colSpec = block._footerGapOption.columns || null;
|
|
252
|
+
if (colSpec) {
|
|
253
|
+
var rawWidths = colSpec.content.vLines || [];
|
|
254
|
+
|
|
255
|
+
if (rawWidths && rawWidths.length > 1) {
|
|
256
|
+
var span = rawWidths[rawWidths.length - 1];
|
|
257
|
+
if (span <= 0) span = 1;
|
|
258
|
+
var style = (colSpec.style || {});
|
|
259
|
+
var lw = style.lineWidth != null ? style.lineWidth : 0.5;
|
|
260
|
+
var lc = style.color || '#000000';
|
|
261
|
+
var dashCfg = style.dash;
|
|
262
|
+
var includeOuter = colSpec.includeOuter !== false;
|
|
263
|
+
var startIndex = includeOuter ? 0 : 1;
|
|
264
|
+
var endIndex = includeOuter ? rawWidths.length : rawWidths.length - 1;
|
|
265
|
+
|
|
266
|
+
for (var ci = startIndex; ci < endIndex; ci++) {
|
|
267
|
+
var xGuide = ctx.x + rawWidths[ci] - 0.25;
|
|
268
|
+
page.items.push({
|
|
269
|
+
type: 'vector',
|
|
270
|
+
item: {
|
|
271
|
+
type: 'line',
|
|
272
|
+
x1: xGuide,
|
|
273
|
+
y1: gapTopY,
|
|
274
|
+
x2: xGuide,
|
|
275
|
+
y2: gapTopY + gapHeight,
|
|
276
|
+
lineWidth: lw,
|
|
277
|
+
lineColor: lc,
|
|
278
|
+
dash: dashCfg ? {
|
|
279
|
+
length: dashCfg.length,
|
|
280
|
+
space: dashCfg.space != null ? dashCfg.space : dashCfg.gap
|
|
281
|
+
} : undefined,
|
|
282
|
+
_footerGuideLine: true
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
ctx.moveDown(gapHeight);
|
|
289
|
+
}
|
|
290
|
+
} else if(isFooter){
|
|
291
|
+
ctx.moveDown(ctx.availableHeight - block.height);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Handle _footerGapOption positioning without isFooter (for breakable footer stacks)
|
|
295
|
+
if (!isFooter && block._footerGapOption && block._footerGapOption.enabled) {
|
|
296
|
+
var breakableGapHeight = ctx.availableHeight - block.height;
|
|
297
|
+
if (breakableGapHeight > 0) {
|
|
298
|
+
ctx.moveDown(breakableGapHeight);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
block.items.forEach(function (item) {
|
|
303
|
+
switch (item.type) {
|
|
304
|
+
case 'line':
|
|
305
|
+
var l = cloneLine(item.item);
|
|
306
|
+
|
|
307
|
+
if (l._node) {
|
|
308
|
+
l._node.positions[0].pageNumber = ctx.page + 1;
|
|
309
|
+
}
|
|
310
|
+
l.x = (l.x || 0) + (useBlockXOffset ? (block.xOffset || 0) : ctx.x);
|
|
311
|
+
l.y = (l.y || 0) + (useBlockYOffset ? (block.yOffset || 0) : ctx.y);
|
|
312
|
+
|
|
313
|
+
page.items.push({
|
|
314
|
+
type: 'line',
|
|
315
|
+
item: l
|
|
316
|
+
});
|
|
317
|
+
break;
|
|
318
|
+
|
|
319
|
+
case 'vector':
|
|
320
|
+
var v = pack(item.item);
|
|
321
|
+
|
|
322
|
+
offsetVector(v, useBlockXOffset ? (block.xOffset || 0) : ctx.x, useBlockYOffset ? (block.yOffset || 0) : ctx.y);
|
|
323
|
+
if (v._isFillColorFromUnbreakable) {
|
|
324
|
+
// If the item is a fillColor from an unbreakable block
|
|
325
|
+
// We have to add it at the beginning of the items body array of the page
|
|
326
|
+
delete v._isFillColorFromUnbreakable;
|
|
327
|
+
const endOfBackgroundItemsIndex = ctx.backgroundLength[ctx.page];
|
|
328
|
+
page.items.splice(endOfBackgroundItemsIndex, 0, {
|
|
329
|
+
type: 'vector',
|
|
330
|
+
item: v
|
|
331
|
+
});
|
|
332
|
+
} else {
|
|
333
|
+
page.items.push({
|
|
334
|
+
type: 'vector',
|
|
335
|
+
item: v
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
break;
|
|
339
|
+
|
|
340
|
+
case 'image':
|
|
341
|
+
case 'svg':
|
|
342
|
+
case 'beginVerticalAlign':
|
|
343
|
+
case 'endVerticalAlign':
|
|
344
|
+
case 'beginClip':
|
|
345
|
+
case 'endClip':
|
|
346
|
+
var it = pack(item.item);
|
|
347
|
+
it.x = (it.x || 0) + (useBlockXOffset ? (block.xOffset || 0) : ctx.x);
|
|
348
|
+
it.y = (it.y || 0) + (useBlockYOffset ? (block.yOffset || 0) : ctx.y);
|
|
349
|
+
|
|
350
|
+
page.items.push({
|
|
351
|
+
type: item.type,
|
|
352
|
+
item: it
|
|
353
|
+
});
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
if (!dontUpdateContextPosition) {
|
|
359
|
+
ctx.moveDown(block.height);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return true;
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Pushes the provided context onto the stack or creates a new one
|
|
367
|
+
*
|
|
368
|
+
* pushContext(context) - pushes the provided context and makes it current
|
|
369
|
+
* pushContext(width, height) - creates and pushes a new context with the specified width and height
|
|
370
|
+
* pushContext() - creates a new context for unbreakable blocks (with current availableWidth and full-page-height)
|
|
371
|
+
*/
|
|
372
|
+
ElementWriter.prototype.pushContext = function (contextOrWidth, height) {
|
|
373
|
+
if (contextOrWidth === undefined) {
|
|
374
|
+
height = this.context.getCurrentPage().height - this.context.pageMargins.top - this.context.pageMargins.bottom;
|
|
375
|
+
contextOrWidth = this.context.availableWidth;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (isNumber(contextOrWidth)) {
|
|
379
|
+
if (this.context._footerGapOption) {
|
|
380
|
+
contextOrWidth = new DocumentContext({width: contextOrWidth, height: height}, {left: 0, right: 0, top: 0, bottom: 0}, this.context._footerGapOption);
|
|
381
|
+
} else {
|
|
382
|
+
contextOrWidth = new DocumentContext({ width: contextOrWidth, height: height }, { left: 0, right: 0, top: 0, bottom: 0 });
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
this.contextStack.push(this.context);
|
|
387
|
+
this.context = contextOrWidth;
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
ElementWriter.prototype.popContext = function () {
|
|
391
|
+
this.context = this.contextStack.pop();
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
ElementWriter.prototype.getCurrentPositionOnPage = function () {
|
|
395
|
+
return (this.contextStack[0] || this.context).getCurrentPosition();
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
ElementWriter.prototype.beginClip = function (width, height) {
|
|
399
|
+
var ctx = this.context;
|
|
400
|
+
var page = ctx.getCurrentPage();
|
|
401
|
+
var item = {
|
|
402
|
+
type: 'beginClip',
|
|
403
|
+
item: { x: ctx.x, y: ctx.y, width: width, height: height }
|
|
404
|
+
};
|
|
405
|
+
page.items.push(item);
|
|
406
|
+
return item;
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
ElementWriter.prototype.endClip = function () {
|
|
410
|
+
var ctx = this.context;
|
|
411
|
+
var page = ctx.getCurrentPage();
|
|
412
|
+
var item = {
|
|
413
|
+
type: 'endClip'
|
|
414
|
+
};
|
|
415
|
+
page.items.push(item);
|
|
416
|
+
return item;
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
ElementWriter.prototype.beginVerticalAlign = function (verticalAlign) {
|
|
420
|
+
var ctx = this.context;
|
|
421
|
+
var page = ctx.getCurrentPage();
|
|
422
|
+
var item = {
|
|
423
|
+
type: 'beginVerticalAlign',
|
|
424
|
+
item: { verticalAlign: verticalAlign }
|
|
425
|
+
};
|
|
426
|
+
page.items.push(item);
|
|
427
|
+
return item;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
ElementWriter.prototype.endVerticalAlign = function (verticalAlign) {
|
|
431
|
+
var ctx = this.context;
|
|
432
|
+
var page = ctx.getCurrentPage();
|
|
433
|
+
var item = {
|
|
434
|
+
type: 'endVerticalAlign',
|
|
435
|
+
item: { verticalAlign: verticalAlign }
|
|
436
|
+
};
|
|
437
|
+
page.items.push(item);
|
|
438
|
+
return item;
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
module.exports = ElementWriter;
|