pdfmake 0.2.4 → 0.3.0-beta.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.
Files changed (128) hide show
  1. package/CHANGELOG.md +10 -27
  2. package/README.md +11 -7
  3. package/build/pdfmake.js +44733 -42435
  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/fonts/Roboto/Roboto-Italic.ttf +0 -0
  15. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  16. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  17. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  18. package/fonts/Roboto.js +8 -0
  19. package/js/3rd-party/svg-to-pdfkit/source.js +4301 -0
  20. package/js/3rd-party/svg-to-pdfkit.js +11 -0
  21. package/js/DocMeasure.js +758 -0
  22. package/js/DocPreprocessor.js +291 -0
  23. package/js/DocumentContext.js +306 -0
  24. package/js/ElementWriter.js +400 -0
  25. package/js/LayoutBuilder.js +840 -0
  26. package/js/Line.js +125 -0
  27. package/js/OutputDocument.js +86 -0
  28. package/js/OutputDocumentServer.js +34 -0
  29. package/js/PDFDocument.js +190 -0
  30. package/js/PageElementWriter.js +165 -0
  31. package/js/PageSize.js +88 -0
  32. package/js/Printer.js +300 -0
  33. package/js/Renderer.js +463 -0
  34. package/js/SVGMeasure.js +89 -0
  35. package/js/StyleContextStack.js +206 -0
  36. package/js/TableProcessor.js +590 -0
  37. package/js/TextBreaker.js +182 -0
  38. package/js/TextDecorator.js +181 -0
  39. package/js/TextInlines.js +248 -0
  40. package/js/URLResolver.js +82 -0
  41. package/js/base.js +69 -0
  42. package/js/browser-extensions/OutputDocumentBrowser.js +131 -0
  43. package/js/browser-extensions/URLBrowserResolver.js +94 -0
  44. package/js/browser-extensions/fonts/Roboto.js +42 -0
  45. package/js/browser-extensions/index.js +70 -0
  46. package/js/browser-extensions/pdfMake.js +17 -0
  47. package/js/browser-extensions/standard-fonts/Courier.js +42 -0
  48. package/js/browser-extensions/standard-fonts/Helvetica.js +42 -0
  49. package/js/browser-extensions/standard-fonts/Symbol.js +27 -0
  50. package/js/browser-extensions/standard-fonts/Times.js +42 -0
  51. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +27 -0
  52. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  53. package/js/columnCalculator.js +142 -0
  54. package/js/helpers/node.js +122 -0
  55. package/js/helpers/tools.js +48 -0
  56. package/js/helpers/variableType.js +52 -0
  57. package/js/index.js +21 -0
  58. package/js/qrEnc.js +810 -0
  59. package/js/standardPageSizes.js +57 -0
  60. package/js/tableLayouts.js +127 -0
  61. package/js/virtual-fs.js +77 -0
  62. package/package.json +26 -22
  63. package/src/3rd-party/svg-to-pdfkit.js +2 -2
  64. package/src/DocMeasure.js +703 -0
  65. package/src/DocPreprocessor.js +264 -0
  66. package/src/DocumentContext.js +309 -0
  67. package/src/ElementWriter.js +394 -0
  68. package/src/LayoutBuilder.js +821 -0
  69. package/src/Line.js +114 -0
  70. package/src/OutputDocument.js +78 -0
  71. package/src/OutputDocumentServer.js +26 -0
  72. package/src/PDFDocument.js +174 -0
  73. package/src/PageElementWriter.js +160 -0
  74. package/src/PageSize.js +53 -0
  75. package/src/Printer.js +277 -0
  76. package/src/Renderer.js +405 -0
  77. package/src/SVGMeasure.js +79 -0
  78. package/src/StyleContextStack.js +216 -0
  79. package/src/TableProcessor.js +558 -0
  80. package/src/TextBreaker.js +149 -0
  81. package/src/TextDecorator.js +161 -0
  82. package/src/TextInlines.js +223 -0
  83. package/src/URLResolver.js +72 -0
  84. package/src/base.js +61 -0
  85. package/src/browser-extensions/OutputDocumentBrowser.js +117 -0
  86. package/src/browser-extensions/URLBrowserResolver.js +49 -53
  87. package/src/browser-extensions/fonts/Roboto.js +27 -0
  88. package/src/browser-extensions/index.js +55 -0
  89. package/src/browser-extensions/pdfMake.js +10 -282
  90. package/src/browser-extensions/standard-fonts/Courier.js +27 -0
  91. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
  92. package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
  93. package/src/browser-extensions/standard-fonts/Times.js +27 -0
  94. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
  95. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  96. package/src/columnCalculator.js +29 -32
  97. package/src/helpers/node.js +110 -0
  98. package/src/helpers/tools.js +39 -0
  99. package/src/helpers/variableType.js +39 -0
  100. package/src/index.js +16 -0
  101. package/src/qrEnc.js +15 -10
  102. package/src/standardPageSizes.js +1 -3
  103. package/src/tableLayouts.js +100 -0
  104. package/src/virtual-fs.js +66 -0
  105. package/standard-fonts/Courier.js +8 -0
  106. package/standard-fonts/Helvetica.js +9 -0
  107. package/standard-fonts/Symbol.js +5 -0
  108. package/standard-fonts/Times.js +8 -0
  109. package/standard-fonts/ZapfDingbats.js +5 -0
  110. package/src/browser-extensions/virtual-fs.js +0 -55
  111. package/src/docMeasure.js +0 -807
  112. package/src/docPreprocessor.js +0 -255
  113. package/src/documentContext.js +0 -314
  114. package/src/elementWriter.js +0 -322
  115. package/src/fontProvider.js +0 -68
  116. package/src/helpers.js +0 -126
  117. package/src/imageMeasure.js +0 -51
  118. package/src/layoutBuilder.js +0 -807
  119. package/src/line.js +0 -91
  120. package/src/pageElementWriter.js +0 -174
  121. package/src/pdfKitEngine.js +0 -21
  122. package/src/printer.js +0 -705
  123. package/src/styleContextStack.js +0 -179
  124. package/src/svgMeasure.js +0 -70
  125. package/src/tableProcessor.js +0 -561
  126. package/src/textDecorator.js +0 -157
  127. package/src/textTools.js +0 -373
  128. 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,314 +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.endingCell = null;
23
-
24
- this.tracker = new TraversalTracker();
25
-
26
- this.backgroundLength = [];
27
-
28
- this.addPage(pageSize);
29
- }
30
-
31
- DocumentContext.prototype.beginColumnGroup = function () {
32
- this.snapshots.push({
33
- x: this.x,
34
- y: this.y,
35
- availableHeight: this.availableHeight,
36
- availableWidth: this.availableWidth,
37
- page: this.page,
38
- bottomMost: {
39
- x: this.x,
40
- y: this.y,
41
- availableHeight: this.availableHeight,
42
- availableWidth: this.availableWidth,
43
- page: this.page
44
- },
45
- endingCell: this.endingCell,
46
- lastColumnWidth: this.lastColumnWidth
47
- });
48
-
49
- this.lastColumnWidth = 0;
50
- };
51
-
52
- DocumentContext.prototype.beginColumn = function (width, offset, endingCell) {
53
- var saved = this.snapshots[this.snapshots.length - 1];
54
-
55
- this.calculateBottomMost(saved);
56
-
57
- this.endingCell = endingCell;
58
- this.page = saved.page;
59
- this.x = this.x + this.lastColumnWidth + (offset || 0);
60
- this.y = saved.y;
61
- this.availableWidth = width; //saved.availableWidth - offset;
62
- this.availableHeight = saved.availableHeight;
63
-
64
- this.lastColumnWidth = width;
65
- };
66
-
67
- DocumentContext.prototype.calculateBottomMost = function (destContext) {
68
- if (this.endingCell) {
69
- this.saveContextInEndingCell(this.endingCell);
70
- this.endingCell = null;
71
- } else {
72
- destContext.bottomMost = bottomMostContext(this, destContext.bottomMost);
73
- }
74
- };
75
-
76
- DocumentContext.prototype.markEnding = function (endingCell) {
77
- this.page = endingCell._columnEndingContext.page;
78
- this.x = endingCell._columnEndingContext.x;
79
- this.y = endingCell._columnEndingContext.y;
80
- this.availableWidth = endingCell._columnEndingContext.availableWidth;
81
- this.availableHeight = endingCell._columnEndingContext.availableHeight;
82
- this.lastColumnWidth = endingCell._columnEndingContext.lastColumnWidth;
83
- };
84
-
85
- DocumentContext.prototype.saveContextInEndingCell = function (endingCell) {
86
- endingCell._columnEndingContext = {
87
- page: this.page,
88
- x: this.x,
89
- y: this.y,
90
- availableHeight: this.availableHeight,
91
- availableWidth: this.availableWidth,
92
- lastColumnWidth: this.lastColumnWidth
93
- };
94
- };
95
-
96
- DocumentContext.prototype.completeColumnGroup = function (height) {
97
- var saved = this.snapshots.pop();
98
-
99
- this.calculateBottomMost(saved);
100
-
101
- this.endingCell = null;
102
- this.x = saved.x;
103
-
104
- var y = saved.bottomMost.y;
105
- if (height) {
106
- if (saved.page === saved.bottomMost.page) {
107
- if ((saved.y + height) > y) {
108
- y = saved.y + height;
109
- }
110
- } else {
111
- y += height;
112
- }
113
- }
114
-
115
- this.y = y;
116
- this.page = saved.bottomMost.page;
117
- this.availableWidth = saved.availableWidth;
118
- this.availableHeight = saved.bottomMost.availableHeight;
119
- if (height) {
120
- this.availableHeight -= (y - saved.bottomMost.y);
121
- }
122
- this.lastColumnWidth = saved.lastColumnWidth;
123
- };
124
-
125
- DocumentContext.prototype.addMargin = function (left, right) {
126
- this.x += left;
127
- this.availableWidth -= left + (right || 0);
128
- };
129
-
130
- DocumentContext.prototype.moveDown = function (offset) {
131
- this.y += offset;
132
- this.availableHeight -= offset;
133
-
134
- return this.availableHeight > 0;
135
- };
136
-
137
- DocumentContext.prototype.initializePage = function () {
138
- this.y = this.pageMargins.top;
139
- this.availableHeight = this.getCurrentPage().pageSize.height - this.pageMargins.top - this.pageMargins.bottom;
140
- this.pageSnapshot().availableWidth = this.getCurrentPage().pageSize.width - this.pageMargins.left - this.pageMargins.right;
141
- };
142
-
143
- DocumentContext.prototype.pageSnapshot = function () {
144
- if (this.snapshots[0]) {
145
- return this.snapshots[0];
146
- } else {
147
- return this;
148
- }
149
- };
150
-
151
- DocumentContext.prototype.moveTo = function (x, y) {
152
- if (x !== undefined && x !== null) {
153
- this.x = x;
154
- this.availableWidth = this.getCurrentPage().pageSize.width - this.x - this.pageMargins.right;
155
- }
156
- if (y !== undefined && y !== null) {
157
- this.y = y;
158
- this.availableHeight = this.getCurrentPage().pageSize.height - this.y - this.pageMargins.bottom;
159
- }
160
- };
161
-
162
- DocumentContext.prototype.moveToRelative = function (x, y) {
163
- if (x !== undefined && x !== null) {
164
- this.x = this.x + x;
165
- }
166
- if (y !== undefined && y !== null) {
167
- this.y = this.y + y;
168
- }
169
- };
170
-
171
- DocumentContext.prototype.beginDetachedBlock = function () {
172
- this.snapshots.push({
173
- x: this.x,
174
- y: this.y,
175
- availableHeight: this.availableHeight,
176
- availableWidth: this.availableWidth,
177
- page: this.page,
178
- endingCell: this.endingCell,
179
- lastColumnWidth: this.lastColumnWidth
180
- });
181
- };
182
-
183
- DocumentContext.prototype.endDetachedBlock = function () {
184
- var saved = this.snapshots.pop();
185
-
186
- this.x = saved.x;
187
- this.y = saved.y;
188
- this.availableWidth = saved.availableWidth;
189
- this.availableHeight = saved.availableHeight;
190
- this.page = saved.page;
191
- this.endingCell = saved.endingCell;
192
- this.lastColumnWidth = saved.lastColumnWidth;
193
- };
194
-
195
- function pageOrientation(pageOrientationString, currentPageOrientation) {
196
- if (pageOrientationString === undefined) {
197
- return currentPageOrientation;
198
- } else if (isString(pageOrientationString) && (pageOrientationString.toLowerCase() === 'landscape')) {
199
- return 'landscape';
200
- } else {
201
- return 'portrait';
202
- }
203
- }
204
-
205
- var getPageSize = function (currentPage, newPageOrientation) {
206
-
207
- newPageOrientation = pageOrientation(newPageOrientation, currentPage.pageSize.orientation);
208
-
209
- if (newPageOrientation !== currentPage.pageSize.orientation) {
210
- return {
211
- orientation: newPageOrientation,
212
- width: currentPage.pageSize.height,
213
- height: currentPage.pageSize.width
214
- };
215
- } else {
216
- return {
217
- orientation: currentPage.pageSize.orientation,
218
- width: currentPage.pageSize.width,
219
- height: currentPage.pageSize.height
220
- };
221
- }
222
-
223
- };
224
-
225
-
226
- DocumentContext.prototype.moveToNextPage = function (pageOrientation) {
227
- var nextPageIndex = this.page + 1;
228
-
229
- var prevPage = this.page;
230
- var prevY = this.y;
231
-
232
- var createNewPage = nextPageIndex >= this.pages.length;
233
- if (createNewPage) {
234
- var currentAvailableWidth = this.availableWidth;
235
- var currentPageOrientation = this.getCurrentPage().pageSize.orientation;
236
-
237
- var pageSize = getPageSize(this.getCurrentPage(), pageOrientation);
238
- this.addPage(pageSize);
239
-
240
- if (currentPageOrientation === pageSize.orientation) {
241
- this.availableWidth = currentAvailableWidth;
242
- }
243
- } else {
244
- this.page = nextPageIndex;
245
- this.initializePage();
246
- }
247
-
248
- return {
249
- newPageCreated: createNewPage,
250
- prevPage: prevPage,
251
- prevY: prevY,
252
- y: this.y
253
- };
254
- };
255
-
256
-
257
- DocumentContext.prototype.addPage = function (pageSize) {
258
- var page = { items: [], pageSize: pageSize };
259
- this.pages.push(page);
260
- this.backgroundLength.push(0);
261
- this.page = this.pages.length - 1;
262
- this.initializePage();
263
-
264
- this.tracker.emit('pageAdded');
265
-
266
- return page;
267
- };
268
-
269
- DocumentContext.prototype.getCurrentPage = function () {
270
- if (this.page < 0 || this.page >= this.pages.length) {
271
- return null;
272
- }
273
-
274
- return this.pages[this.page];
275
- };
276
-
277
- DocumentContext.prototype.getCurrentPosition = function () {
278
- var pageSize = this.getCurrentPage().pageSize;
279
- var innerHeight = pageSize.height - this.pageMargins.top - this.pageMargins.bottom;
280
- var innerWidth = pageSize.width - this.pageMargins.left - this.pageMargins.right;
281
-
282
- return {
283
- pageNumber: this.page + 1,
284
- pageOrientation: pageSize.orientation,
285
- pageInnerHeight: innerHeight,
286
- pageInnerWidth: innerWidth,
287
- left: this.x,
288
- top: this.y,
289
- verticalRatio: ((this.y - this.pageMargins.top) / innerHeight),
290
- horizontalRatio: ((this.x - this.pageMargins.left) / innerWidth)
291
- };
292
- };
293
-
294
- function bottomMostContext(c1, c2) {
295
- var r;
296
-
297
- if (c1.page > c2.page) {
298
- r = c1;
299
- } else if (c2.page > c1.page) {
300
- r = c2;
301
- } else {
302
- r = (c1.y > c2.y) ? c1 : c2;
303
- }
304
-
305
- return {
306
- page: r.page,
307
- x: r.x,
308
- y: r.y,
309
- availableHeight: r.availableHeight,
310
- availableWidth: r.availableWidth
311
- };
312
- }
313
-
314
- module.exports = DocumentContext;