@digicole/pdfmake-rtl 1.2.0 → 2.1.1

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 (100) hide show
  1. package/.vscode/tasks.json +17 -0
  2. package/CHANGELOG.md +83 -128
  3. package/LICENSE +22 -22
  4. package/README.md +188 -681
  5. package/build/fonts/Cairo/Cairo-Black.ttf +0 -0
  6. package/build/fonts/Cairo/Cairo-Bold.ttf +0 -0
  7. package/build/fonts/Cairo/Cairo-ExtraLight.ttf +0 -0
  8. package/build/fonts/Cairo/Cairo-Light.ttf +0 -0
  9. package/build/fonts/Cairo/Cairo-Regular.ttf +0 -0
  10. package/build/fonts/Cairo/Cairo-SemiBold.ttf +0 -0
  11. package/build/fonts/Cairo.js +27 -0
  12. package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
  13. package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
  14. package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  15. package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
  16. package/build/fonts/Roboto.js +27 -0
  17. package/build/pdfmake.js +63736 -71285
  18. package/build/pdfmake.js.map +1 -1
  19. package/build/pdfmake.min.js +2 -2
  20. package/build/pdfmake.min.js.map +1 -1
  21. package/build/standard-fonts/Courier.js +27 -0
  22. package/build/standard-fonts/Helvetica.js +27 -0
  23. package/build/standard-fonts/Symbol.js +21 -0
  24. package/build/standard-fonts/Times.js +27 -0
  25. package/build/standard-fonts/ZapfDingbats.js +21 -0
  26. package/build/vfs_fonts.js +11 -7
  27. package/build-vfs.js +44 -44
  28. package/fonts/Cairo/Cairo-Black.ttf +0 -0
  29. package/fonts/Cairo/Cairo-Bold.ttf +0 -0
  30. package/fonts/Cairo/Cairo-ExtraLight.ttf +0 -0
  31. package/fonts/Cairo/Cairo-Light.ttf +0 -0
  32. package/fonts/Cairo/Cairo-Regular.ttf +0 -0
  33. package/fonts/Cairo/Cairo-SemiBold.ttf +0 -0
  34. package/fonts/Cairo.js +8 -0
  35. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  36. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  37. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  38. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  39. package/fonts/Roboto.js +8 -0
  40. package/index.js +26 -26
  41. package/package.json +42 -39
  42. package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -9
  43. package/src/3rd-party/svg-to-pdfkit/source.js +229 -36
  44. package/src/3rd-party/svg-to-pdfkit.js +3 -3
  45. package/src/OutputDocument.js +64 -0
  46. package/src/OutputDocumentServer.js +32 -0
  47. package/src/PDFDocument.js +174 -0
  48. package/src/PageSize.js +53 -0
  49. package/src/Renderer.js +445 -0
  50. package/src/TextBreaker.js +168 -0
  51. package/src/TextInlines.js +263 -0
  52. package/src/URLResolver.js +43 -0
  53. package/src/base.js +70 -0
  54. package/src/browser-extensions/OutputDocumentBrowser.js +80 -0
  55. package/src/browser-extensions/fonts/Cairo.js +27 -0
  56. package/src/browser-extensions/fonts/Roboto.js +27 -0
  57. package/src/browser-extensions/index.js +61 -0
  58. package/src/browser-extensions/pdfMake.js +1 -355
  59. package/src/browser-extensions/standard-fonts/Courier.js +27 -0
  60. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
  61. package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
  62. package/src/browser-extensions/standard-fonts/Times.js +27 -0
  63. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
  64. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  65. package/src/columnCalculator.js +154 -157
  66. package/src/docMeasure.js +802 -810
  67. package/src/docPreprocessor.js +306 -273
  68. package/src/documentContext.js +345 -340
  69. package/src/elementWriter.js +736 -411
  70. package/src/helpers/node.js +136 -0
  71. package/src/helpers/tools.js +44 -0
  72. package/src/helpers/variableType.js +50 -0
  73. package/src/index.js +16 -0
  74. package/src/layoutBuilder.js +1393 -1197
  75. package/src/line.js +122 -104
  76. package/src/pageElementWriter.js +187 -174
  77. package/src/printer.js +370 -727
  78. package/src/qrEnc.js +796 -791
  79. package/src/rtlUtils.js +500 -485
  80. package/src/standardPageSizes.js +52 -54
  81. package/src/styleContextStack.js +208 -138
  82. package/src/svgMeasure.js +109 -70
  83. package/src/tableLayouts.js +100 -0
  84. package/src/tableProcessor.js +620 -606
  85. package/src/textDecorator.js +175 -157
  86. package/src/virtual-fs.js +66 -0
  87. package/standard-fonts/Courier.js +8 -0
  88. package/standard-fonts/Helvetica.js +8 -0
  89. package/standard-fonts/Symbol.js +5 -0
  90. package/standard-fonts/Times.js +8 -0
  91. package/standard-fonts/ZapfDingbats.js +5 -0
  92. package/index.html +0 -396
  93. package/src/browser-extensions/URLBrowserResolver.js +0 -96
  94. package/src/browser-extensions/virtual-fs.js +0 -55
  95. package/src/fontProvider.js +0 -68
  96. package/src/helpers.js +0 -138
  97. package/src/imageMeasure.js +0 -62
  98. package/src/pdfKitEngine.js +0 -21
  99. package/src/textTools.js +0 -391
  100. package/src/traversalTracker.js +0 -47
package/src/line.js CHANGED
@@ -1,104 +1,122 @@
1
- 'use strict';
2
-
3
- /**
4
- * Creates an instance of Line
5
- *
6
- * @constructor
7
- * @this {Line}
8
- * @param {Number} Maximum width this line can have
9
- */
10
- function Line(maxWidth) {
11
- this.maxWidth = maxWidth;
12
- this.leadingCut = 0;
13
- this.trailingCut = 0;
14
- this.inlineWidths = 0;
15
- this.inlines = [];
16
- }
17
-
18
- Line.prototype.getAscenderHeight = function () {
19
- var y = 0;
20
-
21
- this.inlines.forEach(function (inline) {
22
- y = Math.max(y, inline.font.ascender / 1000 * inline.fontSize);
23
- });
24
- return y;
25
- };
26
-
27
- Line.prototype.hasEnoughSpaceForInline = function (inline, nextInlines) {
28
- nextInlines = nextInlines || [];
29
-
30
- if (this.inlines.length === 0) {
31
- return true;
32
- }
33
- if (this.newLineForced) {
34
- return false;
35
- }
36
-
37
- var inlineWidth = inline.width;
38
- var inlineTrailingCut = inline.trailingCut || 0;
39
- if (inline.noNewLine) {
40
- for (var i = 0, l = nextInlines.length; i < l; i++) {
41
- var nextInline = nextInlines[i];
42
- inlineWidth += nextInline.width;
43
- inlineTrailingCut += nextInline.trailingCut || 0;
44
- if (!nextInline.noNewLine) {
45
- break;
46
- }
47
- }
48
- }
49
-
50
- return (this.inlineWidths + inlineWidth - this.leadingCut - inlineTrailingCut) <= this.maxWidth;
51
- };
52
-
53
- Line.prototype.addInline = function (inline) {
54
- if (this.inlines.length === 0) {
55
- this.leadingCut = inline.leadingCut || 0;
56
- }
57
- this.trailingCut = inline.trailingCut || 0;
58
-
59
- // For RTL text, we'll position inlines from right to left
60
- // The actual RTL positioning will be handled in the alignment phase
61
- inline.x = this.inlineWidths - this.leadingCut;
62
-
63
- this.inlines.push(inline);
64
- this.inlineWidths += inline.width;
65
-
66
- if (inline.lineEnd) {
67
- this.newLineForced = true;
68
- }
69
- };
70
-
71
- Line.prototype.getWidth = function () {
72
- return this.inlineWidths - this.leadingCut - this.trailingCut;
73
- };
74
-
75
- Line.prototype.getAvailableWidth = function () {
76
- return this.maxWidth - this.getWidth();
77
- };
78
-
79
- /**
80
- * Returns line height
81
- * @return {Number}
82
- */
83
- Line.prototype.getHeight = function () {
84
- var max = 0;
85
-
86
- this.inlines.forEach(function (item) {
87
- max = Math.max(max, item.height || 0);
88
- });
89
-
90
- return max;
91
- };
92
-
93
- /**
94
- * Check if this line should be rendered RTL
95
- * @return {Boolean}
96
- */
97
- Line.prototype.isRTL = function () {
98
- // Check if any inline in this line is marked as RTL
99
- return this.inlines.some(function (inline) {
100
- return inline.isRTL || inline.direction === 'rtl';
101
- });
102
- };
103
-
104
- module.exports = Line;
1
+ class Line {
2
+ /**
3
+ * @param {number} maxWidth Maximum width this line can have
4
+ */
5
+ constructor(maxWidth) {
6
+ this.maxWidth = maxWidth;
7
+ this.leadingCut = 0;
8
+ this.trailingCut = 0;
9
+ this.inlineWidths = 0;
10
+ this.inlines = [];
11
+ }
12
+
13
+ /**
14
+ * @param {object} inline
15
+ */
16
+ addInline(inline) {
17
+ if (this.inlines.length === 0) {
18
+ this.leadingCut = inline.leadingCut || 0;
19
+ }
20
+ this.trailingCut = inline.trailingCut || 0;
21
+
22
+ inline.x = this.inlineWidths - this.leadingCut;
23
+
24
+ this.inlines.push(inline);
25
+ this.inlineWidths += inline.width;
26
+
27
+ if (inline.lineEnd) {
28
+ this.newLineForced = true;
29
+ }
30
+ }
31
+
32
+ /**
33
+ * @returns {number}
34
+ */
35
+ getHeight() {
36
+ let max = 0;
37
+
38
+ this.inlines.forEach(item => {
39
+ max = Math.max(max, item.height || 0);
40
+ });
41
+
42
+ return max;
43
+ }
44
+
45
+ /**
46
+ * @returns {number}
47
+ */
48
+ getAscenderHeight() {
49
+ let y = 0;
50
+
51
+ this.inlines.forEach(inline => {
52
+ y = Math.max(y, inline.font.ascender / 1000 * inline.fontSize);
53
+ });
54
+
55
+ return y;
56
+ }
57
+
58
+ /**
59
+ * @returns {number}
60
+ */
61
+ getWidth() {
62
+ return this.inlineWidths - this.leadingCut - this.trailingCut;
63
+ }
64
+
65
+ /**
66
+ * @returns {number}
67
+ */
68
+ getAvailableWidth() {
69
+ return this.maxWidth - this.getWidth();
70
+ }
71
+
72
+ /**
73
+ * @param {object} inline
74
+ * @param {Array} nextInlines
75
+ * @returns {boolean}
76
+ */
77
+ hasEnoughSpaceForInline(inline, nextInlines = []) {
78
+ if (this.inlines.length === 0) {
79
+ return true;
80
+ }
81
+ if (this.newLineForced) {
82
+ return false;
83
+ }
84
+
85
+ let inlineWidth = inline.width;
86
+ let inlineTrailingCut = inline.trailingCut || 0;
87
+ if (inline.noNewLine) {
88
+ for (let i = 0, l = nextInlines.length; i < l; i++) {
89
+ let nextInline = nextInlines[i];
90
+ inlineWidth += nextInline.width;
91
+ inlineTrailingCut += nextInline.trailingCut || 0;
92
+ if (!nextInline.noNewLine) {
93
+ break;
94
+ }
95
+ }
96
+ }
97
+
98
+ return (this.inlineWidths + inlineWidth - this.leadingCut - inlineTrailingCut) <= this.maxWidth;
99
+ }
100
+
101
+ /**
102
+ * Check if this line should be rendered RTL
103
+ * @returns {boolean}
104
+ */
105
+ isRTL() {
106
+ return this.inlines.some(inline => inline.isRTL || inline.direction === 'rtl');
107
+ }
108
+
109
+ clone() {
110
+ let result = new Line(this.maxWidth);
111
+
112
+ for (let key in this) {
113
+ if (this.hasOwnProperty(key)) {
114
+ result[key] = this[key];
115
+ }
116
+ }
117
+
118
+ return result;
119
+ }
120
+ }
121
+
122
+ export default Line;
@@ -1,174 +1,187 @@
1
- 'use strict';
2
-
3
- var isUndefined = require('./helpers').isUndefined;
4
- var ElementWriter = require('./elementWriter');
5
-
6
- /**
7
- * Creates an instance of PageElementWriter - an extended ElementWriter
8
- * which can handle:
9
- * - page-breaks (it adds new pages when there's not enough space left),
10
- * - repeatable fragments (like table-headers, which are repeated everytime
11
- * a page-break occurs)
12
- * - transactions (used for unbreakable-blocks when we want to make sure
13
- * whole block will be rendered on the same page)
14
- */
15
- function PageElementWriter(context, tracker) {
16
- this.transactionLevel = 0;
17
- this.repeatables = [];
18
- this.tracker = tracker;
19
- this.writer = new ElementWriter(context, tracker);
20
- }
21
-
22
- function fitOnPage(self, addFct) {
23
- var position = addFct(self);
24
- if (!position) {
25
- self.moveToNextPage();
26
- position = addFct(self);
27
- }
28
- return position;
29
- }
30
-
31
- PageElementWriter.prototype.addLine = function (line, dontUpdateContextPosition, index) {
32
- return fitOnPage(this, function (self) {
33
- return self.writer.addLine(line, dontUpdateContextPosition, index);
34
- });
35
- };
36
-
37
- PageElementWriter.prototype.addImage = function (image, index) {
38
- return fitOnPage(this, function (self) {
39
- return self.writer.addImage(image, index);
40
- });
41
- };
42
-
43
- PageElementWriter.prototype.addSVG = function (image, index) {
44
- return fitOnPage(this, function (self) {
45
- return self.writer.addSVG(image, index);
46
- });
47
- };
48
-
49
- PageElementWriter.prototype.addQr = function (qr, index) {
50
- return fitOnPage(this, function (self) {
51
- return self.writer.addQr(qr, index);
52
- });
53
- };
54
-
55
- PageElementWriter.prototype.addVector = function (vector, ignoreContextX, ignoreContextY, index, forcePage) {
56
- return this.writer.addVector(vector, ignoreContextX, ignoreContextY, index, forcePage);
57
- };
58
-
59
- PageElementWriter.prototype.beginClip = function (width, height) {
60
- return this.writer.beginClip(width, height);
61
- };
62
-
63
- PageElementWriter.prototype.endClip = function () {
64
- return this.writer.endClip();
65
- };
66
-
67
- PageElementWriter.prototype.alignCanvas = function (node) {
68
- this.writer.alignCanvas(node);
69
- };
70
-
71
- PageElementWriter.prototype.addFragment = function (fragment, useBlockXOffset, useBlockYOffset, dontUpdateContextPosition) {
72
- if (!this.writer.addFragment(fragment, useBlockXOffset, useBlockYOffset, dontUpdateContextPosition)) {
73
- this.moveToNextPage();
74
- this.writer.addFragment(fragment, useBlockXOffset, useBlockYOffset, dontUpdateContextPosition);
75
- }
76
- };
77
-
78
- PageElementWriter.prototype.moveToNextPage = function (pageOrientation) {
79
-
80
- var nextPage = this.writer.context.moveToNextPage(pageOrientation);
81
-
82
- // moveToNextPage is called multiple times for table, because is called for each column
83
- // and repeatables are inserted only in the first time. If columns are used, is needed
84
- // call for table in first column and then for table in the second column (is other repeatables).
85
- this.repeatables.forEach(function (rep) {
86
- if (isUndefined(rep.insertedOnPages[this.writer.context.page])) {
87
- rep.insertedOnPages[this.writer.context.page] = true;
88
- this.writer.addFragment(rep, true);
89
- } else {
90
- this.writer.context.moveDown(rep.height);
91
- }
92
- }, this);
93
-
94
- this.writer.tracker.emit('pageChanged', {
95
- prevPage: nextPage.prevPage,
96
- prevY: nextPage.prevY,
97
- y: this.writer.context.y
98
- });
99
- };
100
-
101
- PageElementWriter.prototype.beginUnbreakableBlock = function (width, height) {
102
- if (this.transactionLevel++ === 0) {
103
- this.originalX = this.writer.context.x;
104
- this.writer.pushContext(width, height);
105
- }
106
- };
107
-
108
- PageElementWriter.prototype.commitUnbreakableBlock = function (forcedX, forcedY) {
109
- if (--this.transactionLevel === 0) {
110
- var unbreakableContext = this.writer.context;
111
- this.writer.popContext();
112
-
113
- var nbPages = unbreakableContext.pages.length;
114
- if (nbPages > 0) {
115
- // no support for multi-page unbreakableBlocks
116
- var fragment = unbreakableContext.pages[0];
117
- fragment.xOffset = forcedX;
118
- fragment.yOffset = forcedY;
119
-
120
- //TODO: vectors can influence height in some situations
121
- if (nbPages > 1) {
122
- // on out-of-context blocs (headers, footers, background) height should be the whole DocumentContext height
123
- if (forcedX !== undefined || forcedY !== undefined) {
124
- fragment.height = unbreakableContext.getCurrentPage().pageSize.height - unbreakableContext.pageMargins.top - unbreakableContext.pageMargins.bottom;
125
- } else {
126
- fragment.height = this.writer.context.getCurrentPage().pageSize.height - this.writer.context.pageMargins.top - this.writer.context.pageMargins.bottom;
127
- for (var i = 0, l = this.repeatables.length; i < l; i++) {
128
- fragment.height -= this.repeatables[i].height;
129
- }
130
- }
131
- } else {
132
- fragment.height = unbreakableContext.y;
133
- }
134
-
135
- if (forcedX !== undefined || forcedY !== undefined) {
136
- this.writer.addFragment(fragment, true, true, true);
137
- } else {
138
- this.addFragment(fragment);
139
- }
140
- }
141
- }
142
- };
143
-
144
- PageElementWriter.prototype.currentBlockToRepeatable = function () {
145
- var unbreakableContext = this.writer.context;
146
- var rep = { items: [] };
147
-
148
- unbreakableContext.pages[0].items.forEach(function (item) {
149
- rep.items.push(item);
150
- });
151
-
152
- rep.xOffset = this.originalX;
153
-
154
- //TODO: vectors can influence height in some situations
155
- rep.height = unbreakableContext.y;
156
-
157
- rep.insertedOnPages = [];
158
-
159
- return rep;
160
- };
161
-
162
- PageElementWriter.prototype.pushToRepeatables = function (rep) {
163
- this.repeatables.push(rep);
164
- };
165
-
166
- PageElementWriter.prototype.popFromRepeatables = function () {
167
- this.repeatables.pop();
168
- };
169
-
170
- PageElementWriter.prototype.context = function () {
171
- return this.writer.context;
172
- };
173
-
174
- module.exports = PageElementWriter;
1
+ import ElementWriter from './ElementWriter';
2
+ import { normalizePageSize, normalizePageMargin } from './PageSize';
3
+ import DocumentContext from './DocumentContext';
4
+
5
+ /**
6
+ * An extended ElementWriter which can handle:
7
+ * - page-breaks (it adds new pages when there's not enough space left),
8
+ * - repeatable fragments (like table-headers, which are repeated everytime
9
+ * a page-break occurs)
10
+ * - transactions (used for unbreakable-blocks when we want to make sure
11
+ * whole block will be rendered on the same page)
12
+ */
13
+ class PageElementWriter extends ElementWriter {
14
+
15
+ /**
16
+ * @param {DocumentContext} context
17
+ */
18
+ constructor(context) {
19
+ super(context);
20
+ this.transactionLevel = 0;
21
+ this.repeatables = [];
22
+ }
23
+
24
+ addLine(line, dontUpdateContextPosition, index) {
25
+ return this._fitOnPage(() => super.addLine(line, dontUpdateContextPosition, index));
26
+ }
27
+
28
+ addImage(image, index) {
29
+ return this._fitOnPage(() => super.addImage(image, index));
30
+ }
31
+
32
+ addCanvas(image, index) {
33
+ return this._fitOnPage(() => super.addCanvas(image, index));
34
+ }
35
+
36
+ addSVG(image, index) {
37
+ return this._fitOnPage(() => super.addSVG(image, index));
38
+ }
39
+
40
+ addQr(qr, index) {
41
+ return this._fitOnPage(() => super.addQr(qr, index));
42
+ }
43
+
44
+ addAttachment(attachment, index) {
45
+ return this._fitOnPage(() => super.addAttachment(attachment, index));
46
+ }
47
+
48
+ addVector(vector, ignoreContextX, ignoreContextY, index, forcePage) {
49
+ return super.addVector(vector, ignoreContextX, ignoreContextY, index, forcePage);
50
+ }
51
+
52
+ beginClip(width, height) {
53
+ return super.beginClip(width, height);
54
+ }
55
+
56
+ endClip() {
57
+ return super.endClip();
58
+ }
59
+
60
+ beginVerticalAlignment(verticalAlignment) {
61
+ return super.beginVerticalAlignment(verticalAlignment);
62
+ }
63
+
64
+ endVerticalAlignment(verticalAlignment) {
65
+ return super.endVerticalAlignment(verticalAlignment);
66
+ }
67
+
68
+ addFragment(fragment, useBlockXOffset, useBlockYOffset, dontUpdateContextPosition) {
69
+ return this._fitOnPage(() => super.addFragment(fragment, useBlockXOffset, useBlockYOffset, dontUpdateContextPosition));
70
+ }
71
+
72
+ moveToNextPage(pageOrientation) {
73
+ let nextPage = this.context().moveToNextPage(pageOrientation);
74
+
75
+ // moveToNextPage is called multiple times for table, because is called for each column
76
+ // and repeatables are inserted only in the first time. If columns are used, is needed
77
+ // call for table in first column and then for table in the second column (is other repeatables).
78
+ this.repeatables.forEach(function (rep) {
79
+ if (rep.insertedOnPages[this.context().page] === undefined) {
80
+ rep.insertedOnPages[this.context().page] = true;
81
+ this.addFragment(rep, true);
82
+ } else {
83
+ this.context().moveDown(rep.height);
84
+ }
85
+ }, this);
86
+
87
+ this.emit('pageChanged', {
88
+ prevPage: nextPage.prevPage,
89
+ prevY: nextPage.prevY,
90
+ y: this.context().y
91
+ });
92
+ }
93
+
94
+ addPage(pageSize, pageOrientation, pageMargin, customProperties = {}) {
95
+ let prevPage = this.page;
96
+ let prevY = this.y;
97
+
98
+ this.context().addPage(normalizePageSize(pageSize, pageOrientation), normalizePageMargin(pageMargin), customProperties);
99
+
100
+ this.emit('pageChanged', {
101
+ prevPage: prevPage,
102
+ prevY: prevY,
103
+ y: this.context().y
104
+ });
105
+ }
106
+
107
+ beginUnbreakableBlock(width, height) {
108
+ if (this.transactionLevel++ === 0) {
109
+ this.originalX = this.context().x;
110
+ this.pushContext(width, height);
111
+ }
112
+ }
113
+
114
+ commitUnbreakableBlock(forcedX, forcedY) {
115
+ if (--this.transactionLevel === 0) {
116
+ let unbreakableContext = this.context();
117
+ this.popContext();
118
+
119
+ let nbPages = unbreakableContext.pages.length;
120
+ if (nbPages > 0) {
121
+ // no support for multi-page unbreakableBlocks
122
+ let fragment = unbreakableContext.pages[0];
123
+ fragment.xOffset = forcedX;
124
+ fragment.yOffset = forcedY;
125
+
126
+ //TODO: vectors can influence height in some situations
127
+ if (nbPages > 1) {
128
+ // on out-of-context blocs (headers, footers, background) height should be the whole DocumentContext height
129
+ if (forcedX !== undefined || forcedY !== undefined) {
130
+ fragment.height = unbreakableContext.getCurrentPage().pageSize.height - unbreakableContext.pageMargins.top - unbreakableContext.pageMargins.bottom;
131
+ } else {
132
+ fragment.height = this.context().getCurrentPage().pageSize.height - this.context().pageMargins.top - this.context().pageMargins.bottom;
133
+ for (let i = 0, l = this.repeatables.length; i < l; i++) {
134
+ fragment.height -= this.repeatables[i].height;
135
+ }
136
+ }
137
+ } else {
138
+ fragment.height = unbreakableContext.y;
139
+ }
140
+
141
+ if (forcedX !== undefined || forcedY !== undefined) {
142
+ super.addFragment(fragment, true, true, true);
143
+ } else {
144
+ this.addFragment(fragment);
145
+ }
146
+ }
147
+ }
148
+ }
149
+
150
+ currentBlockToRepeatable() {
151
+ let unbreakableContext = this.context();
152
+ let rep = { items: [] };
153
+
154
+ unbreakableContext.pages[0].items.forEach(item => {
155
+ rep.items.push(item);
156
+ });
157
+
158
+ rep.xOffset = this.originalX;
159
+
160
+ //TODO: vectors can influence height in some situations
161
+ rep.height = unbreakableContext.y;
162
+
163
+ rep.insertedOnPages = [];
164
+
165
+ return rep;
166
+ }
167
+
168
+ pushToRepeatables(rep) {
169
+ this.repeatables.push(rep);
170
+ }
171
+
172
+ popFromRepeatables() {
173
+ this.repeatables.pop();
174
+ }
175
+
176
+ _fitOnPage(addFct) {
177
+ let position = addFct();
178
+ if (!position) {
179
+ this.moveToNextPage();
180
+ position = addFct();
181
+ }
182
+ return position;
183
+ }
184
+
185
+ }
186
+
187
+ export default PageElementWriter;