pdfmake 0.2.13 → 0.3.0-beta.10

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 (136) hide show
  1. package/CHANGELOG.md +23 -41
  2. package/README.md +11 -7
  3. package/build/pdfmake.js +22291 -23202
  4. package/build/pdfmake.js.map +1 -1
  5. package/build/pdfmake.min.js +2 -2
  6. package/build/pdfmake.min.js.map +1 -1
  7. package/build/standard-fonts/Courier.js +27 -0
  8. package/build/standard-fonts/Helvetica.js +27 -0
  9. package/build/standard-fonts/Symbol.js +21 -0
  10. package/build/standard-fonts/Times.js +27 -0
  11. package/build/standard-fonts/ZapfDingbats.js +21 -0
  12. package/build/vfs_fonts.js +2 -2
  13. package/build-vfs.js +2 -2
  14. package/eslint.config.mjs +52 -0
  15. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  16. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  17. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  18. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  19. package/fonts/Roboto.js +8 -0
  20. package/js/3rd-party/svg-to-pdfkit/source.js +3626 -0
  21. package/js/3rd-party/svg-to-pdfkit.js +7 -0
  22. package/js/DocMeasure.js +626 -0
  23. package/js/DocPreprocessor.js +238 -0
  24. package/js/DocumentContext.js +288 -0
  25. package/js/ElementWriter.js +342 -0
  26. package/js/LayoutBuilder.js +881 -0
  27. package/js/Line.js +105 -0
  28. package/js/OutputDocument.js +76 -0
  29. package/js/OutputDocumentServer.js +27 -0
  30. package/js/PDFDocument.js +144 -0
  31. package/js/PageElementWriter.js +140 -0
  32. package/js/PageSize.js +74 -0
  33. package/js/Printer.js +291 -0
  34. package/js/Renderer.js +375 -0
  35. package/js/SVGMeasure.js +69 -0
  36. package/js/StyleContextStack.js +164 -0
  37. package/js/TableProcessor.js +524 -0
  38. package/js/TextBreaker.js +139 -0
  39. package/js/TextDecorator.js +143 -0
  40. package/js/TextInlines.js +206 -0
  41. package/js/URLResolver.js +73 -0
  42. package/js/base.js +52 -0
  43. package/js/browser-extensions/OutputDocumentBrowser.js +118 -0
  44. package/js/browser-extensions/URLBrowserResolver.js +76 -0
  45. package/js/browser-extensions/fonts/Roboto.js +38 -0
  46. package/js/browser-extensions/index.js +53 -0
  47. package/js/browser-extensions/pdfMake.js +3 -0
  48. package/js/browser-extensions/standard-fonts/Courier.js +38 -0
  49. package/js/browser-extensions/standard-fonts/Helvetica.js +38 -0
  50. package/js/browser-extensions/standard-fonts/Symbol.js +23 -0
  51. package/js/browser-extensions/standard-fonts/Times.js +38 -0
  52. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +23 -0
  53. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  54. package/js/columnCalculator.js +148 -0
  55. package/js/helpers/node.js +98 -0
  56. package/js/helpers/tools.js +40 -0
  57. package/js/helpers/variableType.js +59 -0
  58. package/js/index.js +15 -0
  59. package/js/qrEnc.js +721 -0
  60. package/js/standardPageSizes.js +56 -0
  61. package/js/tableLayouts.js +98 -0
  62. package/js/virtual-fs.js +60 -0
  63. package/package.json +34 -28
  64. package/src/3rd-party/svg-to-pdfkit.js +2 -2
  65. package/src/DocMeasure.js +707 -0
  66. package/src/DocPreprocessor.js +264 -0
  67. package/src/DocumentContext.js +324 -0
  68. package/src/ElementWriter.js +405 -0
  69. package/src/LayoutBuilder.js +997 -0
  70. package/src/Line.js +114 -0
  71. package/src/OutputDocument.js +78 -0
  72. package/src/OutputDocumentServer.js +26 -0
  73. package/src/PDFDocument.js +174 -0
  74. package/src/PageElementWriter.js +160 -0
  75. package/src/PageSize.js +53 -0
  76. package/src/Printer.js +306 -0
  77. package/src/Renderer.js +405 -0
  78. package/src/SVGMeasure.js +79 -0
  79. package/src/StyleContextStack.js +175 -0
  80. package/src/TableProcessor.js +580 -0
  81. package/src/TextBreaker.js +149 -0
  82. package/src/TextDecorator.js +161 -0
  83. package/src/TextInlines.js +223 -0
  84. package/src/URLResolver.js +77 -0
  85. package/src/base.js +61 -0
  86. package/src/browser-extensions/OutputDocumentBrowser.js +117 -0
  87. package/src/browser-extensions/URLBrowserResolver.js +45 -57
  88. package/src/browser-extensions/fonts/Roboto.js +27 -0
  89. package/src/browser-extensions/index.js +55 -0
  90. package/src/browser-extensions/pdfMake.js +1 -329
  91. package/src/browser-extensions/standard-fonts/Courier.js +27 -0
  92. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
  93. package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
  94. package/src/browser-extensions/standard-fonts/Times.js +27 -0
  95. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
  96. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  97. package/src/columnCalculator.js +35 -38
  98. package/src/helpers/node.js +110 -0
  99. package/src/helpers/tools.js +39 -0
  100. package/src/helpers/variableType.js +50 -0
  101. package/src/index.js +16 -0
  102. package/src/qrEnc.js +15 -10
  103. package/src/standardPageSizes.js +1 -3
  104. package/src/tableLayouts.js +100 -0
  105. package/src/virtual-fs.js +66 -0
  106. package/standard-fonts/Courier.js +8 -0
  107. package/standard-fonts/Helvetica.js +9 -0
  108. package/standard-fonts/Symbol.js +5 -0
  109. package/standard-fonts/Times.js +8 -0
  110. package/standard-fonts/ZapfDingbats.js +5 -0
  111. package/.idea/codeStyles/Project.xml +0 -7
  112. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  113. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  114. package/.idea/misc.xml +0 -6
  115. package/.idea/modules.xml +0 -8
  116. package/.idea/pdfmake.iml +0 -11
  117. package/.idea/vcs.xml +0 -6
  118. package/src/browser-extensions/virtual-fs.js +0 -55
  119. package/src/docMeasure.js +0 -810
  120. package/src/docPreprocessor.js +0 -255
  121. package/src/documentContext.js +0 -328
  122. package/src/elementWriter.js +0 -333
  123. package/src/fontProvider.js +0 -68
  124. package/src/helpers.js +0 -138
  125. package/src/imageMeasure.js +0 -55
  126. package/src/layoutBuilder.js +0 -989
  127. package/src/line.js +0 -91
  128. package/src/pageElementWriter.js +0 -174
  129. package/src/pdfKitEngine.js +0 -21
  130. package/src/printer.js +0 -710
  131. package/src/styleContextStack.js +0 -138
  132. package/src/svgMeasure.js +0 -70
  133. package/src/tableProcessor.js +0 -584
  134. package/src/textDecorator.js +0 -157
  135. package/src/textTools.js +0 -373
  136. package/src/traversalTracker.js +0 -47
@@ -1,255 +0,0 @@
1
- 'use strict';
2
-
3
- var isString = require('./helpers').isString;
4
- var isNumber = require('./helpers').isNumber;
5
- var isBoolean = require('./helpers').isBoolean;
6
- var isArray = require('./helpers').isArray;
7
- var isUndefined = require('./helpers').isUndefined;
8
- var fontStringify = require('./helpers').fontStringify;
9
-
10
- function DocPreprocessor() {
11
-
12
- }
13
-
14
- DocPreprocessor.prototype.preprocessDocument = function (docStructure) {
15
- this.parentNode = null;
16
- this.tocs = [];
17
- this.nodeReferences = [];
18
- return this.preprocessNode(docStructure);
19
- };
20
-
21
- DocPreprocessor.prototype.preprocessNode = function (node) {
22
- // expand shortcuts and casting values
23
- if (isArray(node)) {
24
- node = { stack: node };
25
- } else if (isString(node)) {
26
- node = { text: node };
27
- } else if (isNumber(node) || isBoolean(node)) {
28
- node = { text: node.toString() };
29
- } else if (node === undefined || node === null) {
30
- node = { text: '' };
31
- } else if (Object.keys(node).length === 0) { // empty object
32
- node = { text: '' };
33
- } else if ('text' in node && (node.text === undefined || node.text === null)) {
34
- node.text = '';
35
- }
36
-
37
- if (node.columns) {
38
- return this.preprocessColumns(node);
39
- } else if (node.stack) {
40
- return this.preprocessVerticalContainer(node);
41
- } else if (node.ul) {
42
- return this.preprocessList(node);
43
- } else if (node.ol) {
44
- return this.preprocessList(node);
45
- } else if (node.table) {
46
- return this.preprocessTable(node);
47
- } else if (node.text !== undefined) {
48
- return this.preprocessText(node);
49
- } else if (node.toc) {
50
- return this.preprocessToc(node);
51
- } else if (node.image) {
52
- return this.preprocessImage(node);
53
- } else if (node.svg) {
54
- return this.preprocessSVG(node);
55
- } else if (node.canvas) {
56
- return this.preprocessCanvas(node);
57
- } else if (node.qr) {
58
- return this.preprocessQr(node);
59
- } else if (node.pageReference || node.textReference) {
60
- return this.preprocessText(node);
61
- } else {
62
- throw 'Unrecognized document structure: ' + JSON.stringify(node, fontStringify);
63
- }
64
- };
65
-
66
- DocPreprocessor.prototype.preprocessColumns = function (node) {
67
- var columns = node.columns;
68
-
69
- for (var i = 0, l = columns.length; i < l; i++) {
70
- columns[i] = this.preprocessNode(columns[i]);
71
- }
72
-
73
- return node;
74
- };
75
-
76
- DocPreprocessor.prototype.preprocessVerticalContainer = function (node) {
77
- var items = node.stack;
78
-
79
- for (var i = 0, l = items.length; i < l; i++) {
80
- items[i] = this.preprocessNode(items[i]);
81
- }
82
-
83
- return node;
84
- };
85
-
86
- DocPreprocessor.prototype.preprocessList = function (node) {
87
- var items = node.ul || node.ol;
88
-
89
- for (var i = 0, l = items.length; i < l; i++) {
90
- items[i] = this.preprocessNode(items[i]);
91
- }
92
-
93
- return node;
94
- };
95
-
96
- DocPreprocessor.prototype.preprocessTable = function (node) {
97
- var col, row, cols, rows;
98
-
99
- for (col = 0, cols = node.table.body[0].length; col < cols; col++) {
100
- for (row = 0, rows = node.table.body.length; row < rows; row++) {
101
- var rowData = node.table.body[row];
102
- var data = rowData[col];
103
- if (data !== undefined) {
104
- if (data === null) { // transform to object
105
- data = '';
106
- }
107
- if (!data._span) {
108
- rowData[col] = this.preprocessNode(data);
109
- }
110
- }
111
- }
112
- }
113
-
114
- return node;
115
- };
116
-
117
- DocPreprocessor.prototype.preprocessText = function (node) {
118
- if (node.tocItem) {
119
- if (!isArray(node.tocItem)) {
120
- node.tocItem = [node.tocItem];
121
- }
122
-
123
- for (var i = 0, l = node.tocItem.length; i < l; i++) {
124
- if (!isString(node.tocItem[i])) {
125
- node.tocItem[i] = '_default_';
126
- }
127
-
128
- var tocItemId = node.tocItem[i];
129
-
130
- if (!this.tocs[tocItemId]) {
131
- this.tocs[tocItemId] = { toc: { _items: [], _pseudo: true } };
132
- }
133
-
134
- if (!node.id) {
135
- node.id = 'toc-' + tocItemId + '-' + this.tocs[tocItemId].toc._items.length;
136
- }
137
-
138
- var tocItemRef = {
139
- _nodeRef: this._getNodeForNodeRef(node),
140
- _textNodeRef: node
141
- };
142
- this.tocs[tocItemId].toc._items.push(tocItemRef);
143
- }
144
- }
145
-
146
- if (node.id) {
147
- if (this.nodeReferences[node.id]) {
148
- if (!this.nodeReferences[node.id]._pseudo) {
149
- throw "Node id '" + node.id + "' already exists";
150
- }
151
-
152
- this.nodeReferences[node.id]._nodeRef = this._getNodeForNodeRef(node);
153
- this.nodeReferences[node.id]._textNodeRef = node;
154
- this.nodeReferences[node.id]._pseudo = false;
155
- } else {
156
- this.nodeReferences[node.id] = {
157
- _nodeRef: this._getNodeForNodeRef(node),
158
- _textNodeRef: node
159
- };
160
- }
161
- }
162
-
163
- if (node.pageReference) {
164
- if (!this.nodeReferences[node.pageReference]) {
165
- this.nodeReferences[node.pageReference] = {
166
- _nodeRef: {},
167
- _textNodeRef: {},
168
- _pseudo: true
169
- };
170
- }
171
- node.text = '00000';
172
- node.linkToDestination = node.pageReference;
173
- node._pageRef = this.nodeReferences[node.pageReference];
174
- }
175
-
176
- if (node.textReference) {
177
- if (!this.nodeReferences[node.textReference]) {
178
- this.nodeReferences[node.textReference] = { _nodeRef: {}, _pseudo: true };
179
- }
180
-
181
- node.text = '';
182
- node.linkToDestination = node.textReference;
183
- node._textRef = this.nodeReferences[node.textReference];
184
- }
185
-
186
- if (node.text && node.text.text) {
187
- node.text = [this.preprocessNode(node.text)];
188
- } else if (isArray(node.text)) {
189
- var isSetParentNode = false;
190
- if (this.parentNode === null) {
191
- this.parentNode = node;
192
- isSetParentNode = true;
193
- }
194
-
195
- for (var i = 0, l = node.text.length; i < l; i++) {
196
- node.text[i] = this.preprocessNode(node.text[i]);
197
- }
198
-
199
- if (isSetParentNode) {
200
- this.parentNode = null;
201
- }
202
- }
203
-
204
- return node;
205
- };
206
-
207
- DocPreprocessor.prototype.preprocessToc = function (node) {
208
- if (!node.toc.id) {
209
- node.toc.id = '_default_';
210
- }
211
-
212
- node.toc.title = node.toc.title ? this.preprocessNode(node.toc.title) : null;
213
- node.toc._items = [];
214
-
215
- if (this.tocs[node.toc.id]) {
216
- if (!this.tocs[node.toc.id].toc._pseudo) {
217
- throw "TOC '" + node.toc.id + "' already exists";
218
- }
219
-
220
- node.toc._items = this.tocs[node.toc.id].toc._items;
221
- }
222
-
223
- this.tocs[node.toc.id] = node;
224
-
225
- return node;
226
- };
227
-
228
- DocPreprocessor.prototype.preprocessImage = function (node) {
229
- if (!isUndefined(node.image.type) && !isUndefined(node.image.data) && (node.image.type === 'Buffer') && isArray(node.image.data)) {
230
- node.image = Buffer.from(node.image.data);
231
- }
232
- return node;
233
- };
234
-
235
- DocPreprocessor.prototype.preprocessSVG = function (node) {
236
- return node;
237
- };
238
-
239
- DocPreprocessor.prototype.preprocessCanvas = function (node) {
240
- return node;
241
- };
242
-
243
- DocPreprocessor.prototype.preprocessQr = function (node) {
244
- return node;
245
- };
246
-
247
- DocPreprocessor.prototype._getNodeForNodeRef = function (node) {
248
- if (this.parentNode) {
249
- return this.parentNode;
250
- }
251
-
252
- return node;
253
- };
254
-
255
- module.exports = DocPreprocessor;
@@ -1,328 +0,0 @@
1
- 'use strict';
2
-
3
- var TraversalTracker = require('./traversalTracker');
4
- var isString = require('./helpers').isString;
5
-
6
- /**
7
- * Creates an instance of DocumentContext - a store for current x, y positions and available width/height.
8
- * It facilitates column divisions and vertical sync
9
- */
10
- function DocumentContext(pageSize, pageMargins) {
11
- this.pages = [];
12
-
13
- this.pageMargins = pageMargins;
14
-
15
- this.x = pageMargins.left;
16
- this.availableWidth = pageSize.width - pageMargins.left - pageMargins.right;
17
- this.availableHeight = 0;
18
- this.page = -1;
19
-
20
- this.snapshots = [];
21
-
22
- this.tracker = new TraversalTracker();
23
-
24
- this.backgroundLength = [];
25
-
26
- this.addPage(pageSize);
27
- }
28
-
29
- DocumentContext.prototype.beginColumnGroup = function (marginXTopParent) {
30
- this.snapshots.push({
31
- x: this.x,
32
- y: this.y,
33
- availableHeight: this.availableHeight,
34
- availableWidth: this.availableWidth,
35
- page: this.page,
36
- bottomMost: {
37
- x: this.x,
38
- y: this.y,
39
- availableHeight: this.availableHeight,
40
- availableWidth: this.availableWidth,
41
- page: this.page
42
- },
43
- lastColumnWidth: this.lastColumnWidth
44
- });
45
-
46
- this.lastColumnWidth = 0;
47
- if (marginXTopParent) {
48
- this.marginXTopParent = marginXTopParent;
49
- }
50
- };
51
-
52
- DocumentContext.prototype.resetMarginXTopParent = function () {
53
- this.marginXTopParent = null;
54
- };
55
-
56
- DocumentContext.prototype.beginColumn = function (width, offset, endingCell) {
57
- var saved = this.snapshots[this.snapshots.length - 1];
58
-
59
- this.calculateBottomMost(saved, endingCell);
60
-
61
- this.page = saved.page;
62
- this.x = this.x + this.lastColumnWidth + (offset || 0);
63
- this.y = saved.y;
64
- this.availableWidth = width; //saved.availableWidth - offset;
65
- this.availableHeight = saved.availableHeight;
66
-
67
- this.lastColumnWidth = width;
68
- };
69
-
70
- DocumentContext.prototype.calculateBottomMost = function (destContext, endingCell) {
71
- if (endingCell) {
72
- this.saveContextInEndingCell(endingCell);
73
- } else {
74
- destContext.bottomMost = bottomMostContext(this, destContext.bottomMost);
75
- }
76
- };
77
-
78
- DocumentContext.prototype.markEnding = function (endingCell, originalXOffset, discountY) {
79
- this.page = endingCell._columnEndingContext.page;
80
- this.x = endingCell._columnEndingContext.x + originalXOffset;
81
- this.y = endingCell._columnEndingContext.y - discountY;
82
- this.availableWidth = endingCell._columnEndingContext.availableWidth;
83
- this.availableHeight = endingCell._columnEndingContext.availableHeight;
84
- this.lastColumnWidth = endingCell._columnEndingContext.lastColumnWidth;
85
- };
86
-
87
- DocumentContext.prototype.saveContextInEndingCell = function (endingCell) {
88
- endingCell._columnEndingContext = {
89
- page: this.page,
90
- x: this.x,
91
- y: this.y,
92
- availableHeight: this.availableHeight,
93
- availableWidth: this.availableWidth,
94
- lastColumnWidth: this.lastColumnWidth
95
- };
96
- };
97
-
98
- DocumentContext.prototype.completeColumnGroup = function (height, endingCell) {
99
- var saved = this.snapshots.pop();
100
-
101
- this.calculateBottomMost(saved, endingCell);
102
-
103
- this.x = saved.x;
104
-
105
- var y = saved.bottomMost.y;
106
- if (height) {
107
- if (saved.page === saved.bottomMost.page) {
108
- if ((saved.y + height) > y) {
109
- y = saved.y + height;
110
- }
111
- } else {
112
- y += height;
113
- }
114
- }
115
-
116
- this.y = y;
117
- this.page = saved.bottomMost.page;
118
- this.availableWidth = saved.availableWidth;
119
- this.availableHeight = saved.bottomMost.availableHeight;
120
- if (height) {
121
- this.availableHeight -= (y - saved.bottomMost.y);
122
- }
123
- this.lastColumnWidth = saved.lastColumnWidth;
124
- };
125
-
126
- DocumentContext.prototype.addMargin = function (left, right) {
127
- this.x += left;
128
- this.availableWidth -= left + (right || 0);
129
- };
130
-
131
- DocumentContext.prototype.moveDown = function (offset) {
132
- this.y += offset;
133
- this.availableHeight -= offset;
134
-
135
- return this.availableHeight > 0;
136
- };
137
-
138
- DocumentContext.prototype.initializePage = function () {
139
- this.y = this.pageMargins.top;
140
- this.availableHeight = this.getCurrentPage().pageSize.height - this.pageMargins.top - this.pageMargins.bottom;
141
- const { pageCtx, isSnapshot } = this.pageSnapshot();
142
- pageCtx.availableWidth = this.getCurrentPage().pageSize.width - this.pageMargins.left - this.pageMargins.right;
143
- if (isSnapshot && this.marginXTopParent) {
144
- pageCtx.availableWidth -= this.marginXTopParent[0];
145
- pageCtx.availableWidth -= this.marginXTopParent[1];
146
- }
147
- };
148
-
149
- DocumentContext.prototype.pageSnapshot = function () {
150
- if (this.snapshots[0]) {
151
- return { pageCtx: this.snapshots[0], isSnapshot: true };
152
- } else {
153
- return { pageCtx: this, isSnapshot: false };
154
- }
155
- };
156
-
157
- DocumentContext.prototype.moveTo = function (x, y) {
158
- if (x !== undefined && x !== null) {
159
- this.x = x;
160
- this.availableWidth = this.getCurrentPage().pageSize.width - this.x - this.pageMargins.right;
161
- }
162
- if (y !== undefined && y !== null) {
163
- this.y = y;
164
- this.availableHeight = this.getCurrentPage().pageSize.height - this.y - this.pageMargins.bottom;
165
- }
166
- };
167
-
168
- DocumentContext.prototype.moveToRelative = function (x, y) {
169
- if (x !== undefined && x !== null) {
170
- this.x = this.x + x;
171
- }
172
- if (y !== undefined && y !== null) {
173
- this.y = this.y + y;
174
- }
175
- };
176
-
177
- DocumentContext.prototype.beginDetachedBlock = function () {
178
- this.snapshots.push({
179
- x: this.x,
180
- y: this.y,
181
- availableHeight: this.availableHeight,
182
- availableWidth: this.availableWidth,
183
- page: this.page,
184
- lastColumnWidth: this.lastColumnWidth
185
- });
186
- };
187
-
188
- DocumentContext.prototype.endDetachedBlock = function () {
189
- var saved = this.snapshots.pop();
190
-
191
- this.x = saved.x;
192
- this.y = saved.y;
193
- this.availableWidth = saved.availableWidth;
194
- this.availableHeight = saved.availableHeight;
195
- this.page = saved.page;
196
- this.lastColumnWidth = saved.lastColumnWidth;
197
- };
198
-
199
- function pageOrientation(pageOrientationString, currentPageOrientation) {
200
- if (pageOrientationString === undefined) {
201
- return currentPageOrientation;
202
- } else if (isString(pageOrientationString) && (pageOrientationString.toLowerCase() === 'landscape')) {
203
- return 'landscape';
204
- } else {
205
- return 'portrait';
206
- }
207
- }
208
-
209
- var getPageSize = function (currentPage, newPageOrientation) {
210
-
211
- newPageOrientation = pageOrientation(newPageOrientation, currentPage.pageSize.orientation);
212
-
213
- if (newPageOrientation !== currentPage.pageSize.orientation) {
214
- return {
215
- orientation: newPageOrientation,
216
- width: currentPage.pageSize.height,
217
- height: currentPage.pageSize.width
218
- };
219
- } else {
220
- return {
221
- orientation: currentPage.pageSize.orientation,
222
- width: currentPage.pageSize.width,
223
- height: currentPage.pageSize.height
224
- };
225
- }
226
-
227
- };
228
-
229
-
230
- DocumentContext.prototype.moveToNextPage = function (pageOrientation) {
231
- var nextPageIndex = this.page + 1;
232
-
233
- var prevPage = this.page;
234
- var prevY = this.y;
235
-
236
- // If we are in a column group
237
- if (this.snapshots.length > 0) {
238
- var lastSnapshot = this.snapshots[this.snapshots.length - 1];
239
- // We have to update prevY accordingly by also taking into consideration
240
- // the 'y' of cells that don't break page
241
- if (lastSnapshot.bottomMost && lastSnapshot.bottomMost.y) {
242
- prevY = Math.max(this.y, lastSnapshot.bottomMost.y);
243
- }
244
- }
245
-
246
- var createNewPage = nextPageIndex >= this.pages.length;
247
- if (createNewPage) {
248
- var currentAvailableWidth = this.availableWidth;
249
- var currentPageOrientation = this.getCurrentPage().pageSize.orientation;
250
-
251
- var pageSize = getPageSize(this.getCurrentPage(), pageOrientation);
252
- this.addPage(pageSize);
253
-
254
- if (currentPageOrientation === pageSize.orientation) {
255
- this.availableWidth = currentAvailableWidth;
256
- }
257
- } else {
258
- this.page = nextPageIndex;
259
- this.initializePage();
260
- }
261
-
262
- return {
263
- newPageCreated: createNewPage,
264
- prevPage: prevPage,
265
- prevY: prevY,
266
- y: this.y
267
- };
268
- };
269
-
270
-
271
- DocumentContext.prototype.addPage = function (pageSize) {
272
- var page = { items: [], pageSize: pageSize };
273
- this.pages.push(page);
274
- this.backgroundLength.push(0);
275
- this.page = this.pages.length - 1;
276
- this.initializePage();
277
-
278
- this.tracker.emit('pageAdded');
279
-
280
- return page;
281
- };
282
-
283
- DocumentContext.prototype.getCurrentPage = function () {
284
- if (this.page < 0 || this.page >= this.pages.length) {
285
- return null;
286
- }
287
-
288
- return this.pages[this.page];
289
- };
290
-
291
- DocumentContext.prototype.getCurrentPosition = function () {
292
- var pageSize = this.getCurrentPage().pageSize;
293
- var innerHeight = pageSize.height - this.pageMargins.top - this.pageMargins.bottom;
294
- var innerWidth = pageSize.width - this.pageMargins.left - this.pageMargins.right;
295
-
296
- return {
297
- pageNumber: this.page + 1,
298
- pageOrientation: pageSize.orientation,
299
- pageInnerHeight: innerHeight,
300
- pageInnerWidth: innerWidth,
301
- left: this.x,
302
- top: this.y,
303
- verticalRatio: ((this.y - this.pageMargins.top) / innerHeight),
304
- horizontalRatio: ((this.x - this.pageMargins.left) / innerWidth)
305
- };
306
- };
307
-
308
- function bottomMostContext(c1, c2) {
309
- var r;
310
-
311
- if (c1.page > c2.page) {
312
- r = c1;
313
- } else if (c2.page > c1.page) {
314
- r = c2;
315
- } else {
316
- r = (c1.y > c2.y) ? c1 : c2;
317
- }
318
-
319
- return {
320
- page: r.page,
321
- x: r.x,
322
- y: r.y,
323
- availableHeight: r.availableHeight,
324
- availableWidth: r.availableWidth
325
- };
326
- }
327
-
328
- module.exports = DocumentContext;