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,157 +0,0 @@
1
- 'use strict';
2
-
3
- var isArray = require('./helpers').isArray;
4
- var isPattern = require('./helpers').isPattern;
5
- var getPattern = require('./helpers').getPattern;
6
-
7
- function groupDecorations(line) {
8
- var groups = [], currentGroup = null;
9
- for (var i = 0, l = line.inlines.length; i < l; i++) {
10
- var inline = line.inlines[i];
11
- var decoration = inline.decoration;
12
- if (!decoration) {
13
- currentGroup = null;
14
- continue;
15
- }
16
- if (!isArray(decoration)) {
17
- decoration = [decoration];
18
- }
19
- var color = inline.decorationColor || inline.color || 'black';
20
- var style = inline.decorationStyle || 'solid';
21
- for (var ii = 0, ll = decoration.length; ii < ll; ii++) {
22
- var decorationItem = decoration[ii];
23
- if (!currentGroup || decorationItem !== currentGroup.decoration ||
24
- style !== currentGroup.decorationStyle || color !== currentGroup.decorationColor) {
25
-
26
- currentGroup = {
27
- line: line,
28
- decoration: decorationItem,
29
- decorationColor: color,
30
- decorationStyle: style,
31
- inlines: [inline]
32
- };
33
- groups.push(currentGroup);
34
- } else {
35
- currentGroup.inlines.push(inline);
36
- }
37
- }
38
- }
39
-
40
- return groups;
41
- }
42
-
43
- function drawDecoration(group, x, y, pdfKitDoc) {
44
- function maxInline() {
45
- var max = 0;
46
- for (var i = 0, l = group.inlines.length; i < l; i++) {
47
- var inline = group.inlines[i];
48
- max = inline.fontSize > max ? i : max;
49
- }
50
- return group.inlines[max];
51
- }
52
- function width() {
53
- var sum = 0;
54
- for (var i = 0, l = group.inlines.length; i < l; i++) {
55
- var justifyShift = (group.inlines[i].justifyShift || 0);
56
- sum += group.inlines[i].width + justifyShift;
57
- }
58
- return sum;
59
- }
60
- var firstInline = group.inlines[0],
61
- biggerInline = maxInline(),
62
- totalWidth = width(),
63
- lineAscent = group.line.getAscenderHeight(),
64
- ascent = biggerInline.font.ascender / 1000 * biggerInline.fontSize,
65
- height = biggerInline.height,
66
- descent = height - ascent;
67
-
68
- var lw = 0.5 + Math.floor(Math.max(biggerInline.fontSize - 8, 0) / 2) * 0.12;
69
-
70
- switch (group.decoration) {
71
- case 'underline':
72
- y += lineAscent + descent * 0.45;
73
- break;
74
- case 'overline':
75
- y += lineAscent - (ascent * 0.85);
76
- break;
77
- case 'lineThrough':
78
- y += lineAscent - (ascent * 0.25);
79
- break;
80
- default:
81
- throw 'Unknown decoration : ' + group.decoration;
82
- }
83
- pdfKitDoc.save();
84
-
85
- if (group.decorationStyle === 'double') {
86
- var gap = Math.max(0.5, lw * 2);
87
- pdfKitDoc.fillColor(group.decorationColor)
88
- .rect(x + firstInline.x, y - lw / 2, totalWidth, lw / 2).fill()
89
- .rect(x + firstInline.x, y + gap - lw / 2, totalWidth, lw / 2).fill();
90
- } else if (group.decorationStyle === 'dashed') {
91
- var nbDashes = Math.ceil(totalWidth / (3.96 + 2.84));
92
- var rdx = x + firstInline.x;
93
- pdfKitDoc.rect(rdx, y, totalWidth, lw).clip();
94
- pdfKitDoc.fillColor(group.decorationColor);
95
- for (var i = 0; i < nbDashes; i++) {
96
- pdfKitDoc.rect(rdx, y - lw / 2, 3.96, lw).fill();
97
- rdx += 3.96 + 2.84;
98
- }
99
- } else if (group.decorationStyle === 'dotted') {
100
- var nbDots = Math.ceil(totalWidth / (lw * 3));
101
- var rx = x + firstInline.x;
102
- pdfKitDoc.rect(rx, y, totalWidth, lw).clip();
103
- pdfKitDoc.fillColor(group.decorationColor);
104
- for (var ii = 0; ii < nbDots; ii++) {
105
- pdfKitDoc.rect(rx, y - lw / 2, lw, lw).fill();
106
- rx += (lw * 3);
107
- }
108
- } else if (group.decorationStyle === 'wavy') {
109
- var sh = 0.7, sv = 1;
110
- var nbWaves = Math.ceil(totalWidth / (sh * 2)) + 1;
111
- var rwx = x + firstInline.x - 1;
112
- pdfKitDoc.rect(x + firstInline.x, y - sv, totalWidth, y + sv).clip();
113
- pdfKitDoc.lineWidth(0.24);
114
- pdfKitDoc.moveTo(rwx, y);
115
- for (var iii = 0; iii < nbWaves; iii++) {
116
- pdfKitDoc.bezierCurveTo(rwx + sh, y - sv, rwx + sh * 2, y - sv, rwx + sh * 3, y)
117
- .bezierCurveTo(rwx + sh * 4, y + sv, rwx + sh * 5, y + sv, rwx + sh * 6, y);
118
- rwx += sh * 6;
119
- }
120
- pdfKitDoc.stroke(group.decorationColor);
121
- } else {
122
- pdfKitDoc.fillColor(group.decorationColor)
123
- .rect(x + firstInline.x, y - lw / 2, totalWidth, lw)
124
- .fill();
125
- }
126
- pdfKitDoc.restore();
127
- }
128
-
129
- function drawDecorations(line, x, y, pdfKitDoc) {
130
- var groups = groupDecorations(line);
131
- for (var i = 0, l = groups.length; i < l; i++) {
132
- drawDecoration(groups[i], x, y, pdfKitDoc);
133
- }
134
- }
135
-
136
- function drawBackground(line, x, y, patterns, pdfKitDoc) {
137
- var height = line.getHeight();
138
- for (var i = 0, l = line.inlines.length; i < l; i++) {
139
- var inline = line.inlines[i];
140
- if (!inline.background) {
141
- continue;
142
- }
143
- var color = inline.background;
144
- if (isPattern(inline.background)) {
145
- color = getPattern(inline.background, patterns);
146
- }
147
- var justifyShift = (inline.justifyShift || 0);
148
- pdfKitDoc.fillColor(color)
149
- .rect(x + inline.x - justifyShift, y, inline.width + justifyShift, height)
150
- .fill();
151
- }
152
- }
153
-
154
- module.exports = {
155
- drawBackground: drawBackground,
156
- drawDecorations: drawDecorations
157
- };
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;