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.
- package/CHANGELOG.md +10 -27
- package/README.md +11 -7
- package/build/pdfmake.js +44733 -42435
- package/build/pdfmake.js.map +1 -1
- package/build/pdfmake.min.js +2 -2
- package/build/pdfmake.min.js.map +1 -1
- package/build/standard-fonts/Courier.js +27 -0
- package/build/standard-fonts/Helvetica.js +27 -0
- package/build/standard-fonts/Symbol.js +21 -0
- package/build/standard-fonts/Times.js +27 -0
- package/build/standard-fonts/ZapfDingbats.js +21 -0
- package/build/vfs_fonts.js +2 -2
- package/build-vfs.js +2 -2
- package/fonts/Roboto/Roboto-Italic.ttf +0 -0
- package/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
- package/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/fonts/Roboto.js +8 -0
- package/js/3rd-party/svg-to-pdfkit/source.js +4301 -0
- package/js/3rd-party/svg-to-pdfkit.js +11 -0
- package/js/DocMeasure.js +758 -0
- package/js/DocPreprocessor.js +291 -0
- package/js/DocumentContext.js +306 -0
- package/js/ElementWriter.js +400 -0
- package/js/LayoutBuilder.js +840 -0
- package/js/Line.js +125 -0
- package/js/OutputDocument.js +86 -0
- package/js/OutputDocumentServer.js +34 -0
- package/js/PDFDocument.js +190 -0
- package/js/PageElementWriter.js +165 -0
- package/js/PageSize.js +88 -0
- package/js/Printer.js +300 -0
- package/js/Renderer.js +463 -0
- package/js/SVGMeasure.js +89 -0
- package/js/StyleContextStack.js +206 -0
- package/js/TableProcessor.js +590 -0
- package/js/TextBreaker.js +182 -0
- package/js/TextDecorator.js +181 -0
- package/js/TextInlines.js +248 -0
- package/js/URLResolver.js +82 -0
- package/js/base.js +69 -0
- package/js/browser-extensions/OutputDocumentBrowser.js +131 -0
- package/js/browser-extensions/URLBrowserResolver.js +94 -0
- package/js/browser-extensions/fonts/Roboto.js +42 -0
- package/js/browser-extensions/index.js +70 -0
- package/js/browser-extensions/pdfMake.js +17 -0
- package/js/browser-extensions/standard-fonts/Courier.js +42 -0
- package/js/browser-extensions/standard-fonts/Helvetica.js +42 -0
- package/js/browser-extensions/standard-fonts/Symbol.js +27 -0
- package/js/browser-extensions/standard-fonts/Times.js +42 -0
- package/js/browser-extensions/standard-fonts/ZapfDingbats.js +27 -0
- package/js/browser-extensions/virtual-fs-cjs.js +3 -0
- package/js/columnCalculator.js +142 -0
- package/js/helpers/node.js +122 -0
- package/js/helpers/tools.js +48 -0
- package/js/helpers/variableType.js +52 -0
- package/js/index.js +21 -0
- package/js/qrEnc.js +810 -0
- package/js/standardPageSizes.js +57 -0
- package/js/tableLayouts.js +127 -0
- package/js/virtual-fs.js +77 -0
- package/package.json +26 -22
- package/src/3rd-party/svg-to-pdfkit.js +2 -2
- package/src/DocMeasure.js +703 -0
- package/src/DocPreprocessor.js +264 -0
- package/src/DocumentContext.js +309 -0
- package/src/ElementWriter.js +394 -0
- package/src/LayoutBuilder.js +821 -0
- package/src/Line.js +114 -0
- package/src/OutputDocument.js +78 -0
- package/src/OutputDocumentServer.js +26 -0
- package/src/PDFDocument.js +174 -0
- package/src/PageElementWriter.js +160 -0
- package/src/PageSize.js +53 -0
- package/src/Printer.js +277 -0
- package/src/Renderer.js +405 -0
- package/src/SVGMeasure.js +79 -0
- package/src/StyleContextStack.js +216 -0
- package/src/TableProcessor.js +558 -0
- package/src/TextBreaker.js +149 -0
- package/src/TextDecorator.js +161 -0
- package/src/TextInlines.js +223 -0
- package/src/URLResolver.js +72 -0
- package/src/base.js +61 -0
- package/src/browser-extensions/OutputDocumentBrowser.js +117 -0
- package/src/browser-extensions/URLBrowserResolver.js +49 -53
- package/src/browser-extensions/fonts/Roboto.js +27 -0
- package/src/browser-extensions/index.js +55 -0
- package/src/browser-extensions/pdfMake.js +10 -282
- package/src/browser-extensions/standard-fonts/Courier.js +27 -0
- package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
- package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
- package/src/browser-extensions/standard-fonts/Times.js +27 -0
- package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
- package/src/browser-extensions/virtual-fs-cjs.js +1 -0
- package/src/columnCalculator.js +29 -32
- package/src/helpers/node.js +110 -0
- package/src/helpers/tools.js +39 -0
- package/src/helpers/variableType.js +39 -0
- package/src/index.js +16 -0
- package/src/qrEnc.js +15 -10
- package/src/standardPageSizes.js +1 -3
- package/src/tableLayouts.js +100 -0
- package/src/virtual-fs.js +66 -0
- package/standard-fonts/Courier.js +8 -0
- package/standard-fonts/Helvetica.js +9 -0
- package/standard-fonts/Symbol.js +5 -0
- package/standard-fonts/Times.js +8 -0
- package/standard-fonts/ZapfDingbats.js +5 -0
- package/src/browser-extensions/virtual-fs.js +0 -55
- package/src/docMeasure.js +0 -807
- package/src/docPreprocessor.js +0 -255
- package/src/documentContext.js +0 -314
- package/src/elementWriter.js +0 -322
- package/src/fontProvider.js +0 -68
- package/src/helpers.js +0 -126
- package/src/imageMeasure.js +0 -51
- package/src/layoutBuilder.js +0 -807
- package/src/line.js +0 -91
- package/src/pageElementWriter.js +0 -174
- package/src/pdfKitEngine.js +0 -21
- package/src/printer.js +0 -705
- package/src/styleContextStack.js +0 -179
- package/src/svgMeasure.js +0 -70
- package/src/tableProcessor.js +0 -561
- package/src/textDecorator.js +0 -157
- package/src/textTools.js +0 -373
- 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;
|