@digicole/pdfmake-rtl 1.2.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.vscode/tasks.json +17 -0
  2. package/CHANGELOG.md +83 -128
  3. package/LICENSE +22 -22
  4. package/README.md +188 -681
  5. package/build/fonts/Cairo/Cairo-Black.ttf +0 -0
  6. package/build/fonts/Cairo/Cairo-Bold.ttf +0 -0
  7. package/build/fonts/Cairo/Cairo-ExtraLight.ttf +0 -0
  8. package/build/fonts/Cairo/Cairo-Light.ttf +0 -0
  9. package/build/fonts/Cairo/Cairo-Regular.ttf +0 -0
  10. package/build/fonts/Cairo/Cairo-SemiBold.ttf +0 -0
  11. package/build/fonts/Cairo.js +27 -0
  12. package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
  13. package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
  14. package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  15. package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
  16. package/build/fonts/Roboto.js +27 -0
  17. package/build/pdfmake.js +63736 -71285
  18. package/build/pdfmake.js.map +1 -1
  19. package/build/pdfmake.min.js +2 -2
  20. package/build/pdfmake.min.js.map +1 -1
  21. package/build/standard-fonts/Courier.js +27 -0
  22. package/build/standard-fonts/Helvetica.js +27 -0
  23. package/build/standard-fonts/Symbol.js +21 -0
  24. package/build/standard-fonts/Times.js +27 -0
  25. package/build/standard-fonts/ZapfDingbats.js +21 -0
  26. package/build/vfs_fonts.js +11 -7
  27. package/build-vfs.js +44 -44
  28. package/fonts/Cairo/Cairo-Black.ttf +0 -0
  29. package/fonts/Cairo/Cairo-Bold.ttf +0 -0
  30. package/fonts/Cairo/Cairo-ExtraLight.ttf +0 -0
  31. package/fonts/Cairo/Cairo-Light.ttf +0 -0
  32. package/fonts/Cairo/Cairo-Regular.ttf +0 -0
  33. package/fonts/Cairo/Cairo-SemiBold.ttf +0 -0
  34. package/fonts/Cairo.js +8 -0
  35. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  36. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  37. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  38. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  39. package/fonts/Roboto.js +8 -0
  40. package/index.js +26 -26
  41. package/package.json +42 -39
  42. package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -9
  43. package/src/3rd-party/svg-to-pdfkit/source.js +229 -36
  44. package/src/3rd-party/svg-to-pdfkit.js +3 -3
  45. package/src/OutputDocument.js +64 -0
  46. package/src/OutputDocumentServer.js +32 -0
  47. package/src/PDFDocument.js +174 -0
  48. package/src/PageSize.js +53 -0
  49. package/src/Renderer.js +445 -0
  50. package/src/TextBreaker.js +168 -0
  51. package/src/TextInlines.js +263 -0
  52. package/src/URLResolver.js +43 -0
  53. package/src/base.js +70 -0
  54. package/src/browser-extensions/OutputDocumentBrowser.js +80 -0
  55. package/src/browser-extensions/fonts/Cairo.js +27 -0
  56. package/src/browser-extensions/fonts/Roboto.js +27 -0
  57. package/src/browser-extensions/index.js +61 -0
  58. package/src/browser-extensions/pdfMake.js +1 -355
  59. package/src/browser-extensions/standard-fonts/Courier.js +27 -0
  60. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
  61. package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
  62. package/src/browser-extensions/standard-fonts/Times.js +27 -0
  63. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
  64. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  65. package/src/columnCalculator.js +154 -157
  66. package/src/docMeasure.js +802 -810
  67. package/src/docPreprocessor.js +306 -273
  68. package/src/documentContext.js +345 -340
  69. package/src/elementWriter.js +736 -411
  70. package/src/helpers/node.js +136 -0
  71. package/src/helpers/tools.js +44 -0
  72. package/src/helpers/variableType.js +50 -0
  73. package/src/index.js +16 -0
  74. package/src/layoutBuilder.js +1393 -1197
  75. package/src/line.js +122 -104
  76. package/src/pageElementWriter.js +187 -174
  77. package/src/printer.js +370 -727
  78. package/src/qrEnc.js +796 -791
  79. package/src/rtlUtils.js +500 -485
  80. package/src/standardPageSizes.js +52 -54
  81. package/src/styleContextStack.js +208 -138
  82. package/src/svgMeasure.js +109 -70
  83. package/src/tableLayouts.js +100 -0
  84. package/src/tableProcessor.js +620 -606
  85. package/src/textDecorator.js +175 -157
  86. package/src/virtual-fs.js +66 -0
  87. package/standard-fonts/Courier.js +8 -0
  88. package/standard-fonts/Helvetica.js +8 -0
  89. package/standard-fonts/Symbol.js +5 -0
  90. package/standard-fonts/Times.js +8 -0
  91. package/standard-fonts/ZapfDingbats.js +5 -0
  92. package/index.html +0 -396
  93. package/src/browser-extensions/URLBrowserResolver.js +0 -96
  94. package/src/browser-extensions/virtual-fs.js +0 -55
  95. package/src/fontProvider.js +0 -68
  96. package/src/helpers.js +0 -138
  97. package/src/imageMeasure.js +0 -62
  98. package/src/pdfKitEngine.js +0 -21
  99. package/src/textTools.js +0 -391
  100. package/src/traversalTracker.js +0 -47
package/src/helpers.js DELETED
@@ -1,138 +0,0 @@
1
- 'use strict';
2
-
3
- function isString(variable) {
4
- return typeof variable === 'string' || variable instanceof String;
5
- }
6
-
7
- function isNumber(variable) {
8
- return typeof variable === 'number' || variable instanceof Number;
9
- }
10
-
11
- function isBoolean(variable) {
12
- return typeof variable === 'boolean';
13
- }
14
-
15
- function isArray(variable) {
16
- return Array.isArray(variable);
17
- }
18
-
19
- function isFunction(variable) {
20
- return typeof variable === 'function';
21
- }
22
-
23
- function isObject(variable) {
24
- return variable !== null && typeof variable === 'object';
25
- }
26
-
27
- function isNull(variable) {
28
- return variable === null;
29
- }
30
-
31
- function isUndefined(variable) {
32
- return variable === undefined;
33
- }
34
-
35
- /**
36
- * @param {any} variable
37
- * @returns {boolean}
38
- */
39
- function isPositiveInteger(variable) {
40
- if (!isNumber(variable) || !Number.isInteger(variable) || variable <= 0) {
41
- return false;
42
- }
43
- return true;
44
- }
45
-
46
- function pack() {
47
- var result = {};
48
-
49
- for (var i = 0, l = arguments.length; i < l; i++) {
50
- var obj = arguments[i];
51
-
52
- if (obj) {
53
- for (var key in obj) {
54
- if (obj.hasOwnProperty(key)) {
55
- result[key] = obj[key];
56
- }
57
- }
58
- }
59
- }
60
-
61
- return result;
62
- }
63
-
64
- function offsetVector(vector, x, y) {
65
- switch (vector.type) {
66
- case 'ellipse':
67
- case 'rect':
68
- vector.x += x;
69
- vector.y += y;
70
- break;
71
- case 'line':
72
- vector.x1 += x;
73
- vector.x2 += x;
74
- vector.y1 += y;
75
- vector.y2 += y;
76
- break;
77
- case 'polyline':
78
- for (var i = 0, l = vector.points.length; i < l; i++) {
79
- vector.points[i].x += x;
80
- vector.points[i].y += y;
81
- }
82
- break;
83
- }
84
- }
85
-
86
- function fontStringify(key, val) {
87
- if (key === 'font') {
88
- return 'font';
89
- }
90
- return val;
91
- }
92
-
93
- function getNodeId(node) {
94
- if (node.id) {
95
- return node.id;
96
- }
97
-
98
- if (isArray(node.text)) {
99
- for (var i = 0, l = node.text.length; i < l; i++) {
100
- var n = node.text[i];
101
- var nodeId = getNodeId(n);
102
- if (nodeId) {
103
- return nodeId;
104
- }
105
- }
106
- }
107
-
108
- return null;
109
- }
110
-
111
- function isPattern(color) {
112
- return isArray(color) && color.length === 2;
113
- }
114
-
115
- // converts from a [<pattern name>, <color>] as used by pdfmake
116
- // into [<pattern object>, <color>] as used by pdfkit
117
- // (the pattern has to be registered in the doc definition of course)
118
- function getPattern(color, patterns) {
119
- return [patterns[color[0]], color[1]];
120
- }
121
-
122
- module.exports = {
123
- isString: isString,
124
- isNumber: isNumber,
125
- isBoolean: isBoolean,
126
- isArray: isArray,
127
- isFunction: isFunction,
128
- isObject: isObject,
129
- isNull: isNull,
130
- isUndefined: isUndefined,
131
- isPositiveInteger: isPositiveInteger,
132
- pack: pack,
133
- fontStringify: fontStringify,
134
- offsetVector: offsetVector,
135
- getNodeId: getNodeId,
136
- isPattern: isPattern,
137
- getPattern: getPattern
138
- };
@@ -1,62 +0,0 @@
1
- 'use strict';
2
-
3
- var fs = require('fs');
4
-
5
- function ImageMeasure(pdfKitDoc, imageDictionary) {
6
- this.pdfKitDoc = pdfKitDoc;
7
- this.imageDictionary = imageDictionary || {};
8
- }
9
-
10
- ImageMeasure.prototype.measureImage = function (src) {
11
- var image;
12
- var that = this;
13
-
14
- if (!this.pdfKitDoc._imageRegistry[src]) {
15
- try {
16
- image = this.pdfKitDoc.openImage(realImageSrc(src));
17
- if (!image) {
18
- throw 'No image';
19
- }
20
- } catch (error) {
21
- throw 'Invalid image: ' + error.toString() + '\nImages dictionary should contain dataURL entries (or local file paths in node.js)';
22
- }
23
- image.embed(this.pdfKitDoc);
24
- this.pdfKitDoc._imageRegistry[src] = image;
25
- } else {
26
- image = this.pdfKitDoc._imageRegistry[src];
27
- }
28
-
29
- var imageSize = { width: image.width, height: image.height };
30
-
31
- // If EXIF orientation calls for it, swap width and height
32
- if (image.orientation > 4) {
33
- imageSize = { width: image.height, height: image.width };
34
- }
35
-
36
- return imageSize;
37
-
38
- function realImageSrc(src) {
39
- var img = that.imageDictionary[src];
40
-
41
- if (!img) {
42
- return src;
43
- }
44
-
45
- if (typeof img === 'object') {
46
- throw 'Not supported image definition: ' + JSON.stringify(img);
47
- }
48
-
49
- if (fs.existsSync(img)) {
50
- return fs.readFileSync(img);
51
- }
52
-
53
- var index = img.indexOf('base64,');
54
- if (index < 0) {
55
- return that.imageDictionary[src];
56
- }
57
-
58
- return Buffer.from(img.substring(index + 7), 'base64');
59
- }
60
- };
61
-
62
- module.exports = ImageMeasure;
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- function _interopDefault(ex) {
4
- return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex;
5
- }
6
-
7
- var PdfKit = _interopDefault(require('@foliojs-fork/pdfkit'));
8
-
9
- function getEngineInstance() {
10
- return PdfKit;
11
- }
12
-
13
- function createPdfDocument(options) {
14
- options = options || {};
15
- return new PdfKit(options);
16
- }
17
-
18
- module.exports = {
19
- getEngineInstance: getEngineInstance,
20
- createPdfDocument: createPdfDocument
21
- };
package/src/textTools.js DELETED
@@ -1,391 +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
- var rtlUtils = require('./rtlUtils');
10
-
11
- var LEADING = /^(\s)+/g;
12
- var TRAILING = /(\s)+$/g;
13
-
14
- /**
15
- * Creates an instance of TextTools - text measurement utility
16
- *
17
- * @constructor
18
- * @param {FontProvider} fontProvider
19
- */
20
- function TextTools(fontProvider) {
21
- this.fontProvider = fontProvider;
22
- }
23
-
24
- /**
25
- * Converts an array of strings (or inline-definition-objects) into a collection
26
- * of inlines and calculated minWidth/maxWidth.
27
- * and their min/max widths
28
- * @param {Object} textArray - an array of inline-definition-objects (or strings)
29
- * @param {Object} styleContextStack current style stack
30
- * @return {Object} collection of inlines, minWidth, maxWidth
31
- */
32
- TextTools.prototype.buildInlines = function (textArray, styleContextStack) {
33
- var measured = measure(this.fontProvider, textArray, styleContextStack);
34
-
35
- var minWidth = 0,
36
- maxWidth = 0,
37
- currentLineWidth;
38
-
39
- measured.forEach(function (inline) {
40
- minWidth = Math.max(minWidth, inline.width - inline.leadingCut - inline.trailingCut);
41
-
42
- if (!currentLineWidth) {
43
- currentLineWidth = { width: 0, leadingCut: inline.leadingCut, trailingCut: 0 };
44
- }
45
-
46
- currentLineWidth.width += inline.width;
47
- currentLineWidth.trailingCut = inline.trailingCut;
48
-
49
- maxWidth = Math.max(maxWidth, getTrimmedWidth(currentLineWidth));
50
-
51
- if (inline.lineEnd) {
52
- currentLineWidth = null;
53
- }
54
- });
55
-
56
- if (getStyleProperty({}, styleContextStack, 'noWrap', false)) {
57
- minWidth = maxWidth;
58
- }
59
-
60
- return {
61
- items: measured,
62
- minWidth: minWidth,
63
- maxWidth: maxWidth
64
- };
65
-
66
- function getTrimmedWidth(item) {
67
- return Math.max(0, item.width - item.leadingCut - item.trailingCut);
68
- }
69
- };
70
-
71
- /**
72
- * Returns size of the specified string (without breaking it) using the current style
73
- * @param {String} text text to be measured
74
- * @param {Object} styleContextStack current style stack
75
- * @return {Object} size of the specified string
76
- */
77
- TextTools.prototype.sizeOfString = function (text, styleContextStack) {
78
- text = text ? text.toString().replace(/\t/g, ' ') : '';
79
-
80
- //TODO: refactor - extract from measure
81
- var fontName = getStyleProperty({}, styleContextStack, 'font', 'Roboto');
82
- var fontSize = getStyleProperty({}, styleContextStack, 'fontSize', 12);
83
- var fontFeatures = getStyleProperty({}, styleContextStack, 'fontFeatures', null);
84
- var bold = getStyleProperty({}, styleContextStack, 'bold', false);
85
- var italics = getStyleProperty({}, styleContextStack, 'italics', false);
86
- var lineHeight = getStyleProperty({}, styleContextStack, 'lineHeight', 1);
87
- var characterSpacing = getStyleProperty({}, styleContextStack, 'characterSpacing', 0);
88
-
89
- var font = this.fontProvider.provideFont(fontName, bold, italics);
90
-
91
- return {
92
- width: widthOfString(text, font, fontSize, characterSpacing, fontFeatures),
93
- height: font.lineHeight(fontSize) * lineHeight,
94
- fontSize: fontSize,
95
- lineHeight: lineHeight,
96
- ascender: font.ascender / 1000 * fontSize,
97
- descender: font.descender / 1000 * fontSize
98
- };
99
- };
100
-
101
- /**
102
- * Returns size of the specified rotated string (without breaking it) using the current style
103
- *
104
- * @param {string} text text to be measured
105
- * @param {number} angle
106
- * @param {object} styleContextStack current style stack
107
- * @returns {object} size of the specified string
108
- */
109
- TextTools.prototype.sizeOfRotatedText = function (text, angle, styleContextStack) {
110
- var angleRad = angle * Math.PI / -180;
111
- var size = this.sizeOfString(text, styleContextStack);
112
- return {
113
- width: Math.abs(size.height * Math.sin(angleRad)) + Math.abs(size.width * Math.cos(angleRad)),
114
- height: Math.abs(size.width * Math.sin(angleRad)) + Math.abs(size.height * Math.cos(angleRad))
115
- };
116
- };
117
-
118
- TextTools.prototype.widthOfString = function (text, font, fontSize, characterSpacing, fontFeatures) {
119
- return widthOfString(text, font, fontSize, characterSpacing, fontFeatures);
120
- };
121
-
122
- function splitWords(text, noWrap) {
123
- var results = [];
124
- text = text.replace(/\t/g, ' ');
125
-
126
- if (noWrap) {
127
- results.push({ text: text });
128
- return results;
129
- }
130
-
131
- var breaker = new LineBreaker(text);
132
- var last = 0;
133
- var bk;
134
-
135
- while (bk = breaker.nextBreak()) {
136
- var word = text.slice(last, bk.position);
137
-
138
- if (bk.required || word.match(/\r?\n$|\r$/)) { // new line
139
- word = word.replace(/\r?\n$|\r$/, '');
140
- results.push({ text: word, lineEnd: true });
141
- } else {
142
- results.push({ text: word });
143
- }
144
-
145
- last = bk.position;
146
- }
147
-
148
- return results;
149
- }
150
-
151
- function copyStyle(source, destination) {
152
- destination = destination || {};
153
- source = source || {}; //TODO: default style
154
-
155
- for (var key in source) {
156
- if (key != 'text' && source.hasOwnProperty(key)) {
157
- destination[key] = source[key];
158
- }
159
- }
160
-
161
- return destination;
162
- }
163
-
164
- function normalizeTextArray(array, styleContextStack) {
165
- function flatten(array) {
166
- return array.reduce(function (prev, cur) {
167
- var current = isArray(cur.text) ? flatten(cur.text) : cur;
168
- var more = [].concat(current).some(Array.isArray);
169
- return prev.concat(more ? flatten(current) : current);
170
- }, []);
171
- }
172
-
173
- function getOneWord(index, words, noWrap) {
174
- if (isUndefined(words[index])) {
175
- return null;
176
- }
177
-
178
- if (words[index].lineEnd) {
179
- return null;
180
- }
181
-
182
- var word = words[index].text;
183
-
184
- if (noWrap) {
185
- var tmpWords = splitWords(normalizeString(word), false);
186
- if (isUndefined(tmpWords[tmpWords.length - 1])) {
187
- return null;
188
- }
189
- word = tmpWords[tmpWords.length - 1].text;
190
- }
191
-
192
- return word;
193
- }
194
-
195
- var results = [];
196
-
197
- if (!isArray(array)) {
198
- array = [array];
199
- }
200
-
201
- array = flatten(array);
202
-
203
- var lastWord = null;
204
- for (var i = 0, l = array.length; i < l; i++) {
205
- var item = array[i];
206
- var style = null;
207
- var words;
208
-
209
- var noWrap = getStyleProperty(item || {}, styleContextStack, 'noWrap', false);
210
- if (isObject(item)) {
211
- if (item._textRef && item._textRef._textNodeRef.text) {
212
- item.text = item._textRef._textNodeRef.text;
213
- }
214
- words = splitWords(normalizeString(item.text), noWrap);
215
- style = copyStyle(item);
216
- } else {
217
- words = splitWords(normalizeString(item), noWrap);
218
- }
219
-
220
- if (lastWord && words.length) {
221
- var firstWord = getOneWord(0, words, noWrap);
222
-
223
- var wrapWords = splitWords(normalizeString(lastWord + firstWord), false);
224
- if (wrapWords.length === 1) {
225
- results[results.length - 1].noNewLine = true;
226
- }
227
- }
228
-
229
- for (var i2 = 0, l2 = words.length; i2 < l2; i2++) {
230
- var result = {
231
- text: words[i2].text
232
- };
233
-
234
- if (words[i2].lineEnd) {
235
- result.lineEnd = true;
236
- }
237
-
238
- copyStyle(style, result);
239
-
240
- results.push(result);
241
- }
242
-
243
- lastWord = null;
244
- if (i + 1 < l) {
245
- lastWord = getOneWord(words.length - 1, words, noWrap);
246
- }
247
- }
248
-
249
- return results;
250
- }
251
-
252
- function normalizeString(value) {
253
- if (value === undefined || value === null) {
254
- return '';
255
- } else if (isNumber(value)) {
256
- return value.toString();
257
- } else if (isString(value)) {
258
- return value;
259
- } else {
260
- return value.toString();
261
- }
262
- }
263
-
264
- function getStyleProperty(item, styleContextStack, property, defaultValue) {
265
- var value;
266
-
267
- if (item[property] !== undefined && item[property] !== null) {
268
- // item defines this property
269
- return item[property];
270
- }
271
-
272
- if (!styleContextStack) {
273
- return defaultValue;
274
- }
275
-
276
- styleContextStack.auto(item, function () {
277
- value = styleContextStack.getProperty(property);
278
- });
279
-
280
- if (value !== null && value !== undefined) {
281
- return value;
282
- } else {
283
- return defaultValue;
284
- }
285
- }
286
-
287
- function measure(fontProvider, textArray, styleContextStack) {
288
- var normalized = normalizeTextArray(textArray, styleContextStack);
289
-
290
- if (normalized.length) {
291
- var leadingIndent = getStyleProperty(normalized[0], styleContextStack, 'leadingIndent', 0);
292
-
293
- if (leadingIndent) {
294
- normalized[0].leadingCut = -leadingIndent;
295
- normalized[0].leadingIndent = leadingIndent;
296
- }
297
- }
298
-
299
- normalized.forEach(function (item) {
300
- var fontName = getStyleProperty(item, styleContextStack, 'font', 'Roboto');
301
- var fontSize = getStyleProperty(item, styleContextStack, 'fontSize', 12);
302
- var fontFeatures = getStyleProperty(item, styleContextStack, 'fontFeatures', null);
303
- var bold = getStyleProperty(item, styleContextStack, 'bold', false);
304
- var italics = getStyleProperty(item, styleContextStack, 'italics', false);
305
- var color = getStyleProperty(item, styleContextStack, 'color', 'black');
306
- var decoration = getStyleProperty(item, styleContextStack, 'decoration', null);
307
- var decorationColor = getStyleProperty(item, styleContextStack, 'decorationColor', null);
308
- var decorationStyle = getStyleProperty(item, styleContextStack, 'decorationStyle', null);
309
- var background = getStyleProperty(item, styleContextStack, 'background', null);
310
- var lineHeight = getStyleProperty(item, styleContextStack, 'lineHeight', 1);
311
- var characterSpacing = getStyleProperty(item, styleContextStack, 'characterSpacing', 0);
312
- var link = getStyleProperty(item, styleContextStack, 'link', null);
313
- var linkToPage = getStyleProperty(item, styleContextStack, 'linkToPage', null);
314
- var linkToDestination = getStyleProperty(item, styleContextStack, 'linkToDestination', null);
315
- var noWrap = getStyleProperty(item, styleContextStack, 'noWrap', null);
316
- var preserveLeadingSpaces = getStyleProperty(item, styleContextStack, 'preserveLeadingSpaces', false);
317
- var preserveTrailingSpaces = getStyleProperty(item, styleContextStack, 'preserveTrailingSpaces', false);
318
- var opacity = getStyleProperty(item, styleContextStack, 'opacity', 1);
319
- var sup = getStyleProperty(item, styleContextStack, 'sup', false);
320
- var sub = getStyleProperty(item, styleContextStack, 'sub', false);
321
-
322
- // RTL Support
323
- var direction = getStyleProperty(item, styleContextStack, 'direction', null);
324
-
325
- if ((sup || sub) && item.fontSize === undefined) {
326
- // font size reduction taken from here: https://en.wikipedia.org/wiki/Subscript_and_superscript#Desktop_publishing
327
- fontSize *= 0.58;
328
- }
329
-
330
- var font = fontProvider.provideFont(fontName, bold, italics);
331
-
332
- // Process RTL text if needed
333
- var originalText = item.text;
334
- var rtlResult = rtlUtils.processRTLText(originalText, direction);
335
- item.text = rtlResult.text;
336
- item.isRTL = rtlResult.isRTL;
337
- item.direction = rtlResult.isRTL ? 'rtl' : 'ltr';
338
-
339
-
340
- item.width = widthOfString(item.text, font, fontSize, characterSpacing, fontFeatures);
341
- item.height = font.lineHeight(fontSize) * lineHeight;
342
-
343
- if (!item.leadingCut) {
344
- item.leadingCut = 0;
345
- }
346
-
347
- var leadingSpaces;
348
- if (!preserveLeadingSpaces && (leadingSpaces = item.text.match(LEADING))) {
349
- item.leadingCut += widthOfString(leadingSpaces[0], font, fontSize, characterSpacing, fontFeatures);
350
- }
351
-
352
- var trailingSpaces;
353
- if (!preserveTrailingSpaces && (trailingSpaces = item.text.match(TRAILING))) {
354
- item.trailingCut = widthOfString(trailingSpaces[0], font, fontSize, characterSpacing, fontFeatures);
355
- } else {
356
- item.trailingCut = 0;
357
- }
358
-
359
- item.alignment = getStyleProperty(item, styleContextStack, 'alignment', 'left');
360
-
361
- // For RTL text, if no explicit alignment is set, default to 'right'
362
- if (item.isRTL && item.alignment === 'left' && !getStyleProperty(item, styleContextStack, 'alignment', null)) {
363
- item.alignment = 'right';
364
- }
365
-
366
- item.font = font;
367
- item.fontSize = fontSize;
368
- item.fontFeatures = fontFeatures;
369
- item.characterSpacing = characterSpacing;
370
- item.color = color;
371
- item.decoration = decoration;
372
- item.decorationColor = decorationColor;
373
- item.decorationStyle = decorationStyle;
374
- item.background = background;
375
- item.link = link;
376
- item.linkToPage = linkToPage;
377
- item.linkToDestination = linkToDestination;
378
- item.noWrap = noWrap;
379
- item.opacity = opacity;
380
- item.sup = sup;
381
- item.sub = sub;
382
- });
383
-
384
- return normalized;
385
- }
386
-
387
- function widthOfString(text, font, fontSize, characterSpacing, fontFeatures) {
388
- return font.widthOfString(text, fontSize, fontFeatures) + ((characterSpacing || 0) * (text.length - 1));
389
- }
390
-
391
- 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;