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
@@ -0,0 +1,79 @@
1
+ import xmldoc from 'xmldoc';
2
+
3
+ /**
4
+ * Strip unit postfix, parse number, but return undefined instead of NaN for bad input
5
+ *
6
+ * @param {string} textVal
7
+ * @returns {?number}
8
+ */
9
+ const stripUnits = textVal => {
10
+ var n = parseFloat(textVal);
11
+ if (typeof n !== 'number' || isNaN(n)) {
12
+ return undefined;
13
+ }
14
+ return n;
15
+ };
16
+
17
+ /**
18
+ * Make sure it's valid XML and the root tage is <svg/>, returns xmldoc DOM
19
+ *
20
+ * @param {string} svgString
21
+ * @returns {object}
22
+ */
23
+ const parseSVG = (svgString) => {
24
+ var doc;
25
+
26
+ try {
27
+ doc = new xmldoc.XmlDocument(svgString);
28
+ } catch (err) {
29
+ throw new Error('SVGMeasure: ' + err);
30
+ }
31
+
32
+ if (doc.name !== "svg") {
33
+ throw new Error('SVGMeasure: expected <svg> document');
34
+ }
35
+
36
+ return doc;
37
+ };
38
+
39
+ class SVGMeasure {
40
+ constructor() {
41
+
42
+ }
43
+
44
+ measureSVG(svgString) {
45
+ let doc = parseSVG(svgString);
46
+
47
+ let docWidth = stripUnits(doc.attr.width);
48
+ let docHeight = stripUnits(doc.attr.height);
49
+
50
+ if ((docWidth === undefined || docHeight === undefined) && typeof doc.attr.viewBox === 'string') {
51
+ let viewBoxParts = doc.attr.viewBox.split(/[,\s]+/);
52
+ if (viewBoxParts.length !== 4) {
53
+ throw new Error("Unexpected svg viewbox format, should have 4 entries but found: '" + doc.attr.viewBox + "'");
54
+ }
55
+ if (docWidth === undefined) {
56
+ docWidth = stripUnits(viewBoxParts[2]);
57
+ }
58
+ if (docHeight === undefined) {
59
+ docHeight = stripUnits(viewBoxParts[3]);
60
+ }
61
+ }
62
+
63
+ return {
64
+ width: docWidth,
65
+ height: docHeight
66
+ };
67
+ }
68
+
69
+ writeDimensions(svgString, dimensions) {
70
+ let doc = parseSVG(svgString);
71
+
72
+ doc.attr.width = "" + dimensions.width;
73
+ doc.attr.height = "" + dimensions.height;
74
+
75
+ return doc.toString();
76
+ }
77
+ }
78
+
79
+ export default SVGMeasure;
@@ -0,0 +1,216 @@
1
+ import { isString, isValue } from './helpers/variableType';
2
+
3
+ /**
4
+ * Used for style inheritance and style overrides
5
+ */
6
+ class StyleContextStack {
7
+
8
+ /**
9
+ * @param {object} styleDictionary named styles dictionary
10
+ * @param {object} defaultStyle optional default style definition
11
+ */
12
+ constructor(styleDictionary, defaultStyle = {}) {
13
+ this.styleDictionary = styleDictionary;
14
+ this.defaultStyle = defaultStyle;
15
+ this.styleOverrides = [];
16
+ }
17
+
18
+ /**
19
+ * Creates cloned version of current stack
20
+ *
21
+ * @returns {StyleContextStack} current stack snapshot
22
+ */
23
+ clone() {
24
+ let stack = new StyleContextStack(this.styleDictionary, this.defaultStyle);
25
+
26
+ this.styleOverrides.forEach(item => {
27
+ stack.styleOverrides.push(item);
28
+ });
29
+
30
+ return stack;
31
+ }
32
+
33
+ /**
34
+ * Pushes style-name or style-overrides-object onto the stack for future evaluation
35
+ *
36
+ * @param {string|object} styleNameOrOverride style-name (referring to styleDictionary) or
37
+ * a new dictionary defining overriding properties
38
+ */
39
+ push(styleNameOrOverride) {
40
+ this.styleOverrides.push(styleNameOrOverride);
41
+ }
42
+
43
+ /**
44
+ * Removes last style-name or style-overrides-object from the stack
45
+ *
46
+ * @param {number} howMany optional number of elements to be popped (if not specified,
47
+ * one element will be removed from the stack)
48
+ */
49
+ pop(howMany = 1) {
50
+ while (howMany-- > 0) {
51
+ this.styleOverrides.pop();
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Creates a set of named styles or/and a style-overrides-object based on the item,
57
+ * pushes those elements onto the stack for future evaluation and returns the number
58
+ * of elements pushed, so they can be easily poped then.
59
+ *
60
+ * @param {object} item - an object with optional style property and/or style overrides
61
+ * @returns {number} the number of items pushed onto the stack
62
+ */
63
+ autopush(item) {
64
+ if (isString(item)) {
65
+ return 0;
66
+ }
67
+
68
+ let styleNames = [];
69
+
70
+ if (item.style) {
71
+ if (Array.isArray(item.style)) {
72
+ styleNames = item.style;
73
+ } else {
74
+ styleNames = [item.style];
75
+ }
76
+ }
77
+
78
+ for (let i = 0, l = styleNames.length; i < l; i++) {
79
+ this.push(styleNames[i]);
80
+ }
81
+
82
+ let styleProperties = [
83
+ 'font',
84
+ 'fontSize',
85
+ 'fontFeatures',
86
+ 'bold',
87
+ 'italics',
88
+ 'alignment',
89
+ 'color',
90
+ 'columnGap',
91
+ 'fillColor',
92
+ 'fillOpacity',
93
+ 'decoration',
94
+ 'decorationStyle',
95
+ 'decorationColor',
96
+ 'background',
97
+ 'lineHeight',
98
+ 'characterSpacing',
99
+ 'noWrap',
100
+ 'markerColor',
101
+ 'leadingIndent',
102
+ 'sup',
103
+ 'sub'
104
+ //'tableCellPadding'
105
+ // 'cellBorder',
106
+ // 'headerCellBorder',
107
+ // 'oddRowCellBorder',
108
+ // 'evenRowCellBorder',
109
+ // 'tableBorder'
110
+ ];
111
+ let styleOverrideObject = {};
112
+ let pushStyleOverrideObject = false;
113
+
114
+ styleProperties.forEach(key => {
115
+ if (isValue(item[key])) {
116
+ styleOverrideObject[key] = item[key];
117
+ pushStyleOverrideObject = true;
118
+ }
119
+ });
120
+
121
+ if (pushStyleOverrideObject) {
122
+ this.push(styleOverrideObject);
123
+ }
124
+
125
+ return styleNames.length + (pushStyleOverrideObject ? 1 : 0);
126
+ }
127
+
128
+ /**
129
+ * Automatically pushes elements onto the stack, using autopush based on item,
130
+ * executes callback and then pops elements back. Returns value returned by callback
131
+ *
132
+ * @param {object} item - an object with optional style property and/or style overrides
133
+ * @param {Function} callback to be called between autopush and pop
134
+ * @returns {object} value returned by callback
135
+ */
136
+ auto(item, callback) {
137
+ let pushedItems = this.autopush(item);
138
+ let result = callback();
139
+
140
+ if (pushedItems > 0) {
141
+ this.pop(pushedItems);
142
+ }
143
+
144
+ return result;
145
+ }
146
+
147
+ /**
148
+ * Evaluates stack and returns value of a named property
149
+ *
150
+ * @param {string} property - property name
151
+ * @returns {?any} property value or null if not found
152
+ */
153
+ getProperty(property) {
154
+ if (this.styleOverrides) {
155
+ for (let i = this.styleOverrides.length - 1; i >= 0; i--) {
156
+ let item = this.styleOverrides[i];
157
+
158
+ if (isString(item)) { // named-style-override
159
+ let style = this.styleDictionary[item];
160
+ if (style && isValue(style[property])) {
161
+ return style[property];
162
+ }
163
+ } else if (isValue(item[property])) { // style-overrides-object
164
+ return item[property];
165
+ }
166
+ }
167
+ }
168
+
169
+ return this.defaultStyle && this.defaultStyle[property];
170
+ }
171
+
172
+ /**
173
+ * @param {object} item
174
+ * @param {StyleContextStack} styleContextStack
175
+ * @param {string} property
176
+ * @param {any} defaultValue
177
+ * @returns {any}
178
+ */
179
+ static getStyleProperty(item, styleContextStack, property, defaultValue) {
180
+ let value;
181
+
182
+ if (isValue(item[property])) { // item defines this property
183
+ return item[property];
184
+ }
185
+
186
+ if (!styleContextStack) {
187
+ return defaultValue;
188
+ }
189
+
190
+ styleContextStack.auto(item, () => {
191
+ value = styleContextStack.getProperty(property);
192
+ });
193
+
194
+ return isValue(value) ? value : defaultValue;
195
+ }
196
+
197
+ /**
198
+ * @param {object} source
199
+ * @param {object} destination
200
+ * @returns {object}
201
+ */
202
+ static copyStyle(source = {}, destination = {}) {
203
+ // TODO: default style to source
204
+
205
+ for (let key in source) {
206
+ if (key != 'text' && source.hasOwnProperty(key)) {
207
+ destination[key] = source[key];
208
+ }
209
+ }
210
+
211
+ return destination;
212
+ }
213
+
214
+ }
215
+
216
+ export default StyleContextStack;