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
package/src/textTools.js DELETED
@@ -1,373 +0,0 @@
1
- 'use strict';
2
-
3
- var isString = require('./helpers').isString;
4
- var isNumber = require('./helpers').isNumber;
5
- var isObject = require('./helpers').isObject;
6
- var isArray = require('./helpers').isArray;
7
- var isUndefined = require('./helpers').isUndefined;
8
- var LineBreaker = require('@foliojs-fork/linebreak');
9
-
10
- var LEADING = /^(\s)+/g;
11
- var TRAILING = /(\s)+$/g;
12
-
13
- /**
14
- * Creates an instance of TextTools - text measurement utility
15
- *
16
- * @constructor
17
- * @param {FontProvider} fontProvider
18
- */
19
- function TextTools(fontProvider) {
20
- this.fontProvider = fontProvider;
21
- }
22
-
23
- /**
24
- * Converts an array of strings (or inline-definition-objects) into a collection
25
- * of inlines and calculated minWidth/maxWidth.
26
- * and their min/max widths
27
- * @param {Object} textArray - an array of inline-definition-objects (or strings)
28
- * @param {Object} styleContextStack current style stack
29
- * @return {Object} collection of inlines, minWidth, maxWidth
30
- */
31
- TextTools.prototype.buildInlines = function (textArray, styleContextStack) {
32
- var measured = measure(this.fontProvider, textArray, styleContextStack);
33
-
34
- var minWidth = 0,
35
- maxWidth = 0,
36
- currentLineWidth;
37
-
38
- measured.forEach(function (inline) {
39
- minWidth = Math.max(minWidth, inline.width - inline.leadingCut - inline.trailingCut);
40
-
41
- if (!currentLineWidth) {
42
- currentLineWidth = { width: 0, leadingCut: inline.leadingCut, trailingCut: 0 };
43
- }
44
-
45
- currentLineWidth.width += inline.width;
46
- currentLineWidth.trailingCut = inline.trailingCut;
47
-
48
- maxWidth = Math.max(maxWidth, getTrimmedWidth(currentLineWidth));
49
-
50
- if (inline.lineEnd) {
51
- currentLineWidth = null;
52
- }
53
- });
54
-
55
- if (getStyleProperty({}, styleContextStack, 'noWrap', false)) {
56
- minWidth = maxWidth;
57
- }
58
-
59
- return {
60
- items: measured,
61
- minWidth: minWidth,
62
- maxWidth: maxWidth
63
- };
64
-
65
- function getTrimmedWidth(item) {
66
- return Math.max(0, item.width - item.leadingCut - item.trailingCut);
67
- }
68
- };
69
-
70
- /**
71
- * Returns size of the specified string (without breaking it) using the current style
72
- * @param {String} text text to be measured
73
- * @param {Object} styleContextStack current style stack
74
- * @return {Object} size of the specified string
75
- */
76
- TextTools.prototype.sizeOfString = function (text, styleContextStack) {
77
- text = text ? text.toString().replace(/\t/g, ' ') : '';
78
-
79
- //TODO: refactor - extract from measure
80
- var fontName = getStyleProperty({}, styleContextStack, 'font', 'Roboto');
81
- var fontSize = getStyleProperty({}, styleContextStack, 'fontSize', 12);
82
- var fontFeatures = getStyleProperty({}, styleContextStack, 'fontFeatures', null);
83
- var bold = getStyleProperty({}, styleContextStack, 'bold', false);
84
- var italics = getStyleProperty({}, styleContextStack, 'italics', false);
85
- var lineHeight = getStyleProperty({}, styleContextStack, 'lineHeight', 1);
86
- var characterSpacing = getStyleProperty({}, styleContextStack, 'characterSpacing', 0);
87
-
88
- var font = this.fontProvider.provideFont(fontName, bold, italics);
89
-
90
- return {
91
- width: widthOfString(text, font, fontSize, characterSpacing, fontFeatures),
92
- height: font.lineHeight(fontSize) * lineHeight,
93
- fontSize: fontSize,
94
- lineHeight: lineHeight,
95
- ascender: font.ascender / 1000 * fontSize,
96
- descender: font.descender / 1000 * fontSize
97
- };
98
- };
99
-
100
- /**
101
- * Returns size of the specified rotated string (without breaking it) using the current style
102
- *
103
- * @param {string} text text to be measured
104
- * @param {number} angle
105
- * @param {object} styleContextStack current style stack
106
- * @returns {object} size of the specified string
107
- */
108
- TextTools.prototype.sizeOfRotatedText = function (text, angle, styleContextStack) {
109
- var angleRad = angle * Math.PI / -180;
110
- var size = this.sizeOfString(text, styleContextStack);
111
- return {
112
- width: Math.abs(size.height * Math.sin(angleRad)) + Math.abs(size.width * Math.cos(angleRad)),
113
- height: Math.abs(size.width * Math.sin(angleRad)) + Math.abs(size.height * Math.cos(angleRad))
114
- };
115
- }
116
-
117
- TextTools.prototype.widthOfString = function (text, font, fontSize, characterSpacing, fontFeatures) {
118
- return widthOfString(text, font, fontSize, characterSpacing, fontFeatures);
119
- };
120
-
121
- function splitWords(text, noWrap) {
122
- var results = [];
123
- text = text.replace(/\t/g, ' ');
124
-
125
- if (noWrap) {
126
- results.push({ text: text });
127
- return results;
128
- }
129
-
130
- var breaker = new LineBreaker(text);
131
- var last = 0;
132
- var bk;
133
-
134
- while (bk = breaker.nextBreak()) {
135
- var word = text.slice(last, bk.position);
136
-
137
- if (bk.required || word.match(/\r?\n$|\r$/)) { // new line
138
- word = word.replace(/\r?\n$|\r$/, '');
139
- results.push({ text: word, lineEnd: true });
140
- } else {
141
- results.push({ text: word });
142
- }
143
-
144
- last = bk.position;
145
- }
146
-
147
- return results;
148
- }
149
-
150
- function copyStyle(source, destination) {
151
- destination = destination || {};
152
- source = source || {}; //TODO: default style
153
-
154
- for (var key in source) {
155
- if (key != 'text' && source.hasOwnProperty(key)) {
156
- destination[key] = source[key];
157
- }
158
- }
159
-
160
- return destination;
161
- }
162
-
163
- function normalizeTextArray(array, styleContextStack) {
164
- function flatten(array) {
165
- return array.reduce(function (prev, cur) {
166
- var current = isArray(cur.text) ? flatten(cur.text) : cur;
167
- var more = [].concat(current).some(Array.isArray);
168
- return prev.concat(more ? flatten(current) : current);
169
- }, []);
170
- }
171
-
172
- function getOneWord(index, words, noWrap) {
173
- if (isUndefined(words[index])) {
174
- return null;
175
- }
176
-
177
- if (words[index].lineEnd) {
178
- return null;
179
- }
180
-
181
- var word = words[index].text;
182
-
183
- if (noWrap) {
184
- var tmpWords = splitWords(normalizeString(word), false);
185
- if (isUndefined(tmpWords[tmpWords.length - 1])) {
186
- return null;
187
- }
188
- word = tmpWords[tmpWords.length - 1].text;
189
- }
190
-
191
- return word;
192
- }
193
-
194
- var results = [];
195
-
196
- if (!isArray(array)) {
197
- array = [array];
198
- }
199
-
200
- array = flatten(array);
201
-
202
- var lastWord = null;
203
- for (var i = 0, l = array.length; i < l; i++) {
204
- var item = array[i];
205
- var style = null;
206
- var words;
207
-
208
- var noWrap = getStyleProperty(item || {}, styleContextStack, 'noWrap', false);
209
- if (isObject(item)) {
210
- if (item._textRef && item._textRef._textNodeRef.text) {
211
- item.text = item._textRef._textNodeRef.text;
212
- }
213
- words = splitWords(normalizeString(item.text), noWrap);
214
- style = copyStyle(item);
215
- } else {
216
- words = splitWords(normalizeString(item), noWrap);
217
- }
218
-
219
- if (lastWord && words.length) {
220
- var firstWord = getOneWord(0, words, noWrap);
221
-
222
- var wrapWords = splitWords(normalizeString(lastWord + firstWord), false);
223
- if (wrapWords.length === 1) {
224
- results[results.length - 1].noNewLine = true;
225
- }
226
- }
227
-
228
- for (var i2 = 0, l2 = words.length; i2 < l2; i2++) {
229
- var result = {
230
- text: words[i2].text
231
- };
232
-
233
- if (words[i2].lineEnd) {
234
- result.lineEnd = true;
235
- }
236
-
237
- copyStyle(style, result);
238
-
239
- results.push(result);
240
- }
241
-
242
- lastWord = null;
243
- if (i + 1 < l) {
244
- lastWord = getOneWord(words.length - 1, words, noWrap);
245
- }
246
- }
247
-
248
- return results;
249
- }
250
-
251
- function normalizeString(value) {
252
- if (value === undefined || value === null) {
253
- return '';
254
- } else if (isNumber(value)) {
255
- return value.toString();
256
- } else if (isString(value)) {
257
- return value;
258
- } else {
259
- return value.toString();
260
- }
261
- }
262
-
263
- function getStyleProperty(item, styleContextStack, property, defaultValue) {
264
- var value;
265
-
266
- if (item[property] !== undefined && item[property] !== null) {
267
- // item defines this property
268
- return item[property];
269
- }
270
-
271
- if (!styleContextStack) {
272
- return defaultValue;
273
- }
274
-
275
- styleContextStack.auto(item, function () {
276
- value = styleContextStack.getProperty(property);
277
- });
278
-
279
- if (value !== null && value !== undefined) {
280
- return value;
281
- } else {
282
- return defaultValue;
283
- }
284
- }
285
-
286
- function measure(fontProvider, textArray, styleContextStack) {
287
- var normalized = normalizeTextArray(textArray, styleContextStack);
288
-
289
- if (normalized.length) {
290
- var leadingIndent = getStyleProperty(normalized[0], styleContextStack, 'leadingIndent', 0);
291
-
292
- if (leadingIndent) {
293
- normalized[0].leadingCut = -leadingIndent;
294
- normalized[0].leadingIndent = leadingIndent;
295
- }
296
- }
297
-
298
- normalized.forEach(function (item) {
299
- var fontName = getStyleProperty(item, styleContextStack, 'font', 'Roboto');
300
- var fontSize = getStyleProperty(item, styleContextStack, 'fontSize', 12);
301
- var fontFeatures = getStyleProperty(item, styleContextStack, 'fontFeatures', null);
302
- var bold = getStyleProperty(item, styleContextStack, 'bold', false);
303
- var italics = getStyleProperty(item, styleContextStack, 'italics', false);
304
- var color = getStyleProperty(item, styleContextStack, 'color', 'black');
305
- var decoration = getStyleProperty(item, styleContextStack, 'decoration', null);
306
- var decorationColor = getStyleProperty(item, styleContextStack, 'decorationColor', null);
307
- var decorationStyle = getStyleProperty(item, styleContextStack, 'decorationStyle', null);
308
- var background = getStyleProperty(item, styleContextStack, 'background', null);
309
- var lineHeight = getStyleProperty(item, styleContextStack, 'lineHeight', 1);
310
- var characterSpacing = getStyleProperty(item, styleContextStack, 'characterSpacing', 0);
311
- var link = getStyleProperty(item, styleContextStack, 'link', null);
312
- var linkToPage = getStyleProperty(item, styleContextStack, 'linkToPage', null);
313
- var linkToDestination = getStyleProperty(item, styleContextStack, 'linkToDestination', null);
314
- var noWrap = getStyleProperty(item, styleContextStack, 'noWrap', null);
315
- var preserveLeadingSpaces = getStyleProperty(item, styleContextStack, 'preserveLeadingSpaces', false);
316
- var preserveTrailingSpaces = getStyleProperty(item, styleContextStack, 'preserveTrailingSpaces', false);
317
- var opacity = getStyleProperty(item, styleContextStack, 'opacity', 1);
318
- var sup = getStyleProperty(item, styleContextStack, 'sup', false);
319
- var sub = getStyleProperty(item, styleContextStack, 'sub', false);
320
-
321
- if ((sup || sub) && item.fontSize === undefined) {
322
- // font size reduction taken from here: https://en.wikipedia.org/wiki/Subscript_and_superscript#Desktop_publishing
323
- fontSize *= 0.58
324
- }
325
-
326
- var font = fontProvider.provideFont(fontName, bold, italics);
327
-
328
- item.width = widthOfString(item.text, font, fontSize, characterSpacing, fontFeatures);
329
- item.height = font.lineHeight(fontSize) * lineHeight;
330
-
331
- if (!item.leadingCut) {
332
- item.leadingCut = 0;
333
- }
334
-
335
- var leadingSpaces;
336
- if (!preserveLeadingSpaces && (leadingSpaces = item.text.match(LEADING))) {
337
- item.leadingCut += widthOfString(leadingSpaces[0], font, fontSize, characterSpacing, fontFeatures);
338
- }
339
-
340
- var trailingSpaces;
341
- if (!preserveTrailingSpaces && (trailingSpaces = item.text.match(TRAILING))) {
342
- item.trailingCut = widthOfString(trailingSpaces[0], font, fontSize, characterSpacing, fontFeatures);
343
- } else {
344
- item.trailingCut = 0;
345
- }
346
-
347
- item.alignment = getStyleProperty(item, styleContextStack, 'alignment', 'left');
348
- item.font = font;
349
- item.fontSize = fontSize;
350
- item.fontFeatures = fontFeatures;
351
- item.characterSpacing = characterSpacing;
352
- item.color = color;
353
- item.decoration = decoration;
354
- item.decorationColor = decorationColor;
355
- item.decorationStyle = decorationStyle;
356
- item.background = background;
357
- item.link = link;
358
- item.linkToPage = linkToPage;
359
- item.linkToDestination = linkToDestination;
360
- item.noWrap = noWrap;
361
- item.opacity = opacity;
362
- item.sup = sup;
363
- item.sub = sub;
364
- });
365
-
366
- return normalized;
367
- }
368
-
369
- function widthOfString(text, font, fontSize, characterSpacing, fontFeatures) {
370
- return font.widthOfString(text, fontSize, fontFeatures) + ((characterSpacing || 0) * (text.length - 1));
371
- }
372
-
373
- module.exports = TextTools;
@@ -1,47 +0,0 @@
1
- 'use strict';
2
-
3
- function TraversalTracker() {
4
- this.events = {};
5
- }
6
-
7
- TraversalTracker.prototype.startTracking = function (event, callback) {
8
- var callbacks = this.events[event] || (this.events[event] = []);
9
-
10
- if (callbacks.indexOf(callback) < 0) {
11
- callbacks.push(callback);
12
- }
13
- };
14
-
15
- TraversalTracker.prototype.stopTracking = function (event, callback) {
16
- var callbacks = this.events[event];
17
-
18
- if (!callbacks) {
19
- return;
20
- }
21
-
22
- var index = callbacks.indexOf(callback);
23
- if (index >= 0) {
24
- callbacks.splice(index, 1);
25
- }
26
- };
27
-
28
- TraversalTracker.prototype.emit = function (event) {
29
- var args = Array.prototype.slice.call(arguments, 1);
30
- var callbacks = this.events[event];
31
-
32
- if (!callbacks) {
33
- return;
34
- }
35
-
36
- callbacks.forEach(function (callback) {
37
- callback.apply(this, args);
38
- });
39
- };
40
-
41
- TraversalTracker.prototype.auto = function (event, callback, innerFunction) {
42
- this.startTracking(event, callback);
43
- innerFunction();
44
- this.stopTracking(event, callback);
45
- };
46
-
47
- module.exports = TraversalTracker;