@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
@@ -1,157 +1,175 @@
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
- };
1
+ import { isNumber } from './helpers/variableType';
2
+
3
+ const groupDecorations = line => {
4
+ let groups = [];
5
+ let currentGroup = null;
6
+ for (let i = 0, l = line.inlines.length; i < l; i++) {
7
+ let inline = line.inlines[i];
8
+ let decoration = inline.decoration;
9
+ if (!decoration) {
10
+ currentGroup = null;
11
+ continue;
12
+ }
13
+ if (!Array.isArray(decoration)) {
14
+ decoration = [decoration];
15
+ }
16
+ let color = inline.decorationColor || inline.color || 'black';
17
+ let style = inline.decorationStyle || 'solid';
18
+ let thickness = isNumber(inline.decorationThickness) ? inline.decorationThickness : null;
19
+ for (let ii = 0, ll = decoration.length; ii < ll; ii++) {
20
+ let decorationItem = decoration[ii];
21
+ if (!currentGroup || decorationItem !== currentGroup.decoration ||
22
+ style !== currentGroup.decorationStyle || color !== currentGroup.decorationColor) {
23
+
24
+ currentGroup = {
25
+ line: line,
26
+ decoration: decorationItem,
27
+ decorationColor: color,
28
+ decorationStyle: style,
29
+ decorationThickness: thickness,
30
+ inlines: [inline]
31
+ };
32
+ groups.push(currentGroup);
33
+ } else {
34
+ currentGroup.inlines.push(inline);
35
+ }
36
+ }
37
+ }
38
+
39
+ return groups;
40
+ };
41
+
42
+ class TextDecorator {
43
+
44
+ constructor(pdfDocument) {
45
+ this.pdfDocument = pdfDocument;
46
+ }
47
+
48
+ drawBackground(line, x, y) {
49
+ let height = line.getHeight();
50
+ for (let i = 0, l = line.inlines.length; i < l; i++) {
51
+ let inline = line.inlines[i];
52
+ if (!inline.background) {
53
+ continue;
54
+ }
55
+
56
+ let color = inline.background;
57
+ let patternColor = this.pdfDocument.providePattern(inline.background);
58
+ if (patternColor !== null) {
59
+ color = patternColor;
60
+ }
61
+
62
+ let justifyShift = (inline.justifyShift || 0);
63
+ this.pdfDocument.fillColor(color)
64
+ .rect(x + inline.x - justifyShift, y, inline.width + justifyShift, height)
65
+ .fill();
66
+ }
67
+ }
68
+
69
+ drawDecorations(line, x, y) {
70
+ let groups = groupDecorations(line);
71
+ for (let i = 0, l = groups.length; i < l; i++) {
72
+ this._drawDecoration(groups[i], x, y);
73
+ }
74
+ }
75
+
76
+ _drawDecoration(group, x, y) {
77
+ const maxInline = () => {
78
+ let max = 0;
79
+ for (let i = 0, l = group.inlines.length; i < l; i++) {
80
+ let inline = group.inlines[i];
81
+ max = inline.fontSize > max ? i : max;
82
+ }
83
+ return group.inlines[max];
84
+ };
85
+
86
+ const width = () => {
87
+ let sum = 0;
88
+ for (let i = 0, l = group.inlines.length; i < l; i++) {
89
+ let justifyShift = (group.inlines[i].justifyShift || 0);
90
+ sum += group.inlines[i].width + justifyShift;
91
+ }
92
+ return sum;
93
+ };
94
+
95
+ let firstInline = group.inlines[0];
96
+ let biggerInline = maxInline();
97
+ let totalWidth = width();
98
+ let lineAscent = group.line.getAscenderHeight();
99
+ let ascent = biggerInline.font.ascender / 1000 * biggerInline.fontSize;
100
+ let height = biggerInline.height;
101
+ let descent = height - ascent;
102
+
103
+ let lw = isNumber(group.decorationThickness)
104
+ ? group.decorationThickness
105
+ : 0.5 + Math.floor(Math.max(biggerInline.fontSize - 8, 0) / 2) * 0.12;
106
+
107
+ switch (group.decoration) {
108
+ case 'underline':
109
+ y += lineAscent + descent * 0.45;
110
+ break;
111
+ case 'overline':
112
+ y += lineAscent - (ascent * 0.85);
113
+ break;
114
+ case 'lineThrough':
115
+ y += lineAscent - (ascent * 0.25);
116
+ break;
117
+ default:
118
+ throw new Error(`Unknown decoration : ${group.decoration}`);
119
+ }
120
+
121
+ if (group.inlines[0].sup) {
122
+ y -= group.inlines[0].fontSize * 0.75;
123
+ }
124
+ if (group.inlines[0].sub) {
125
+ y += group.inlines[0].fontSize * 0.35;
126
+ }
127
+
128
+ this.pdfDocument.save();
129
+
130
+ if (group.decorationStyle === 'double') {
131
+ let gap = Math.max(0.5, lw, biggerInline.fontSize * 0.15);
132
+ this.pdfDocument.fillColor(group.decorationColor)
133
+ .rect(x + firstInline.x, y - lw / 2, totalWidth, lw / 2).fill()
134
+ .rect(x + firstInline.x, y + gap - lw / 2, totalWidth, lw / 2).fill();
135
+ } else if (group.decorationStyle === 'dashed') {
136
+ let nbDashes = Math.ceil(totalWidth / (3.96 + 2.84));
137
+ let rdx = x + firstInline.x;
138
+ this.pdfDocument.rect(rdx, y, totalWidth, lw).clip();
139
+ this.pdfDocument.fillColor(group.decorationColor);
140
+ for (let i = 0; i < nbDashes; i++) {
141
+ this.pdfDocument.rect(rdx, y - lw / 2, 3.96, lw).fill();
142
+ rdx += 3.96 + 2.84;
143
+ }
144
+ } else if (group.decorationStyle === 'dotted') {
145
+ let nbDots = Math.ceil(totalWidth / (lw * 3));
146
+ let rx = x + firstInline.x;
147
+ this.pdfDocument.rect(rx, y, totalWidth, lw).clip();
148
+ this.pdfDocument.fillColor(group.decorationColor);
149
+ for (let i = 0; i < nbDots; i++) {
150
+ this.pdfDocument.rect(rx, y - lw / 2, lw, lw).fill();
151
+ rx += (lw * 3);
152
+ }
153
+ } else if (group.decorationStyle === 'wavy') {
154
+ let sh = 0.7, sv = 1;
155
+ let nbWaves = Math.ceil(totalWidth / (sh * 2)) + 1;
156
+ let rwx = x + firstInline.x - 1;
157
+ this.pdfDocument.rect(x + firstInline.x, y - sv, totalWidth, y + sv).clip();
158
+ this.pdfDocument.lineWidth(lw / 3);
159
+ this.pdfDocument.moveTo(rwx, y);
160
+ for (let i = 0; i < nbWaves; i++) {
161
+ this.pdfDocument.bezierCurveTo(rwx + sh, y - sv, rwx + sh * 2, y - sv, rwx + sh * 3, y)
162
+ .bezierCurveTo(rwx + sh * 4, y + sv, rwx + sh * 5, y + sv, rwx + sh * 6, y);
163
+ rwx += sh * 6;
164
+ }
165
+ this.pdfDocument.stroke(group.decorationColor);
166
+ } else {
167
+ this.pdfDocument.fillColor(group.decorationColor)
168
+ .rect(x + firstInline.x, y - lw / 2, totalWidth, lw)
169
+ .fill();
170
+ }
171
+ this.pdfDocument.restore();
172
+ }
173
+ }
174
+
175
+ export default TextDecorator;
@@ -0,0 +1,66 @@
1
+ const normalizeFilename = filename => {
2
+ if (filename.indexOf(__dirname) === 0) {
3
+ filename = filename.substring(__dirname.length);
4
+ }
5
+
6
+ if (filename.indexOf('/') === 0) {
7
+ filename = filename.substring(1);
8
+ }
9
+
10
+ return filename;
11
+ };
12
+
13
+ class VirtualFileSystem {
14
+ constructor() {
15
+ this.storage = {};
16
+ }
17
+
18
+ /**
19
+ * @param {string} filename
20
+ * @returns {boolean}
21
+ */
22
+ existsSync(filename) {
23
+ const normalizedFilename = normalizeFilename(filename);
24
+ return typeof this.storage[normalizedFilename] !== 'undefined';
25
+ }
26
+
27
+ /**
28
+ * @param {string} filename
29
+ * @param {?string|?object} options
30
+ * @returns {string|Buffer}
31
+ */
32
+ readFileSync(filename, options) {
33
+ const normalizedFilename = normalizeFilename(filename);
34
+ const encoding = typeof options === 'object' ? options.encoding : options;
35
+
36
+ if (!this.existsSync(normalizedFilename)) {
37
+ throw new Error(`File '${normalizedFilename}' not found in virtual file system`);
38
+ }
39
+
40
+ const buffer = this.storage[normalizedFilename];
41
+ if (encoding) {
42
+ return buffer.toString(encoding);
43
+ }
44
+
45
+ return buffer;
46
+ }
47
+
48
+ /**
49
+ * @param {string} filename
50
+ * @param {string|Buffer} content
51
+ * @param {?string|?object} options
52
+ */
53
+ writeFileSync(filename, content, options) {
54
+ const normalizedFilename = normalizeFilename(filename);
55
+ const encoding = typeof options === 'object' ? options.encoding : options;
56
+
57
+ if (!content && !options) {
58
+ throw new Error('No content');
59
+ }
60
+
61
+ this.storage[normalizedFilename] = encoding || typeof content === 'string' ? new Buffer(content, encoding) : content;
62
+ }
63
+
64
+ }
65
+
66
+ export default new VirtualFileSystem();
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ Courier: {
3
+ normal: 'Courier',
4
+ bold: 'Courier-Bold',
5
+ italics: 'Courier-Oblique',
6
+ bolditalics: 'Courier-BoldOblique'
7
+ }
8
+ };
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ Helvetica: {
3
+ normal: 'Helvetica',
4
+ bold: 'Helvetica-Bold',
5
+ italics: 'Helvetica-Oblique',
6
+ bolditalics: 'Helvetica-BoldOblique'
7
+ }
8
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ Symbol: {
3
+ normal: 'Symbol'
4
+ }
5
+ };
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ Times: {
3
+ normal: 'Times-Roman',
4
+ bold: 'Times-Bold',
5
+ italics: 'Times-Italic',
6
+ bolditalics: 'Times-BoldItalic'
7
+ }
8
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ ZapfDingbats: {
3
+ normal: 'ZapfDingbats'
4
+ }
5
+ };