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.
- package/CHANGELOG.md +23 -41
- package/README.md +11 -7
- package/build/pdfmake.js +22291 -23202
- 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/eslint.config.mjs +52 -0
- 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 +3626 -0
- package/js/3rd-party/svg-to-pdfkit.js +7 -0
- package/js/DocMeasure.js +626 -0
- package/js/DocPreprocessor.js +238 -0
- package/js/DocumentContext.js +288 -0
- package/js/ElementWriter.js +342 -0
- package/js/LayoutBuilder.js +881 -0
- package/js/Line.js +105 -0
- package/js/OutputDocument.js +76 -0
- package/js/OutputDocumentServer.js +27 -0
- package/js/PDFDocument.js +144 -0
- package/js/PageElementWriter.js +140 -0
- package/js/PageSize.js +74 -0
- package/js/Printer.js +291 -0
- package/js/Renderer.js +375 -0
- package/js/SVGMeasure.js +69 -0
- package/js/StyleContextStack.js +164 -0
- package/js/TableProcessor.js +524 -0
- package/js/TextBreaker.js +139 -0
- package/js/TextDecorator.js +143 -0
- package/js/TextInlines.js +206 -0
- package/js/URLResolver.js +73 -0
- package/js/base.js +52 -0
- package/js/browser-extensions/OutputDocumentBrowser.js +118 -0
- package/js/browser-extensions/URLBrowserResolver.js +76 -0
- package/js/browser-extensions/fonts/Roboto.js +38 -0
- package/js/browser-extensions/index.js +53 -0
- package/js/browser-extensions/pdfMake.js +3 -0
- package/js/browser-extensions/standard-fonts/Courier.js +38 -0
- package/js/browser-extensions/standard-fonts/Helvetica.js +38 -0
- package/js/browser-extensions/standard-fonts/Symbol.js +23 -0
- package/js/browser-extensions/standard-fonts/Times.js +38 -0
- package/js/browser-extensions/standard-fonts/ZapfDingbats.js +23 -0
- package/js/browser-extensions/virtual-fs-cjs.js +3 -0
- package/js/columnCalculator.js +148 -0
- package/js/helpers/node.js +98 -0
- package/js/helpers/tools.js +40 -0
- package/js/helpers/variableType.js +59 -0
- package/js/index.js +15 -0
- package/js/qrEnc.js +721 -0
- package/js/standardPageSizes.js +56 -0
- package/js/tableLayouts.js +98 -0
- package/js/virtual-fs.js +60 -0
- package/package.json +34 -28
- package/src/3rd-party/svg-to-pdfkit.js +2 -2
- package/src/DocMeasure.js +707 -0
- package/src/DocPreprocessor.js +264 -0
- package/src/DocumentContext.js +324 -0
- package/src/ElementWriter.js +405 -0
- package/src/LayoutBuilder.js +997 -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 +306 -0
- package/src/Renderer.js +405 -0
- package/src/SVGMeasure.js +79 -0
- package/src/StyleContextStack.js +175 -0
- package/src/TableProcessor.js +580 -0
- package/src/TextBreaker.js +149 -0
- package/src/TextDecorator.js +161 -0
- package/src/TextInlines.js +223 -0
- package/src/URLResolver.js +77 -0
- package/src/base.js +61 -0
- package/src/browser-extensions/OutputDocumentBrowser.js +117 -0
- package/src/browser-extensions/URLBrowserResolver.js +45 -57
- package/src/browser-extensions/fonts/Roboto.js +27 -0
- package/src/browser-extensions/index.js +55 -0
- package/src/browser-extensions/pdfMake.js +1 -329
- 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 +35 -38
- package/src/helpers/node.js +110 -0
- package/src/helpers/tools.js +39 -0
- package/src/helpers/variableType.js +50 -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/.idea/codeStyles/Project.xml +0 -7
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/pdfmake.iml +0 -11
- package/.idea/vcs.xml +0 -6
- package/src/browser-extensions/virtual-fs.js +0 -55
- package/src/docMeasure.js +0 -810
- package/src/docPreprocessor.js +0 -255
- package/src/documentContext.js +0 -328
- package/src/elementWriter.js +0 -333
- package/src/fontProvider.js +0 -68
- package/src/helpers.js +0 -138
- package/src/imageMeasure.js +0 -55
- package/src/layoutBuilder.js +0 -989
- package/src/line.js +0 -91
- package/src/pageElementWriter.js +0 -174
- package/src/pdfKitEngine.js +0 -21
- package/src/printer.js +0 -710
- package/src/styleContextStack.js +0 -138
- package/src/svgMeasure.js +0 -70
- package/src/tableProcessor.js +0 -584
- package/src/textDecorator.js +0 -157
- package/src/textTools.js +0 -373
- package/src/traversalTracker.js +0 -47
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
|
|
3
|
+
var fontContainer = {
|
|
4
|
+
vfs: {
|
|
5
|
+
'data/Helvetica.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica.afm', 'utf8'), encoding: 'utf8' },
|
|
6
|
+
'data/Helvetica-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica-Bold.afm', 'utf8'), encoding: 'utf8' },
|
|
7
|
+
'data/Helvetica-Oblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica-Oblique.afm', 'utf8'), encoding: 'utf8' },
|
|
8
|
+
'data/Helvetica-BoldOblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica-BoldOblique.afm', 'utf8'), encoding: 'utf8' }
|
|
9
|
+
},
|
|
10
|
+
fonts: {
|
|
11
|
+
Helvetica: {
|
|
12
|
+
normal: 'Helvetica',
|
|
13
|
+
bold: 'Helvetica-Bold',
|
|
14
|
+
italics: 'Helvetica-Oblique',
|
|
15
|
+
bolditalics: 'Helvetica-BoldOblique'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : this;
|
|
21
|
+
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
22
|
+
_global.pdfMake.addFontContainer(fontContainer);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (typeof module !== 'undefined') {
|
|
26
|
+
module.exports = fontContainer;
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
|
|
3
|
+
var fontContainer = {
|
|
4
|
+
vfs: {
|
|
5
|
+
'data/Symbol.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Symbol.afm', 'utf8'), encoding: 'utf8' }
|
|
6
|
+
},
|
|
7
|
+
fonts: {
|
|
8
|
+
Symbol: {
|
|
9
|
+
normal: 'Symbol'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : this;
|
|
15
|
+
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
16
|
+
_global.pdfMake.addFontContainer(fontContainer);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (typeof module !== 'undefined') {
|
|
20
|
+
module.exports = fontContainer;
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
|
|
3
|
+
var fontContainer = {
|
|
4
|
+
vfs: {
|
|
5
|
+
'data/Times-Roman.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-Roman.afm', 'utf8'), encoding: 'utf8' },
|
|
6
|
+
'data/Times-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-Bold.afm', 'utf8'), encoding: 'utf8' },
|
|
7
|
+
'data/Times-Italic.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-Italic.afm', 'utf8'), encoding: 'utf8' },
|
|
8
|
+
'data/Times-BoldItalic.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-BoldItalic.afm', 'utf8'), encoding: 'utf8' }
|
|
9
|
+
},
|
|
10
|
+
fonts: {
|
|
11
|
+
Times: {
|
|
12
|
+
normal: 'Times-Roman',
|
|
13
|
+
bold: 'Times-Bold',
|
|
14
|
+
italics: 'Times-Italic',
|
|
15
|
+
bolditalics: 'Times-BoldItalic'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : this;
|
|
21
|
+
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
22
|
+
_global.pdfMake.addFontContainer(fontContainer);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (typeof module !== 'undefined') {
|
|
26
|
+
module.exports = fontContainer;
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
|
|
3
|
+
var fontContainer = {
|
|
4
|
+
vfs: {
|
|
5
|
+
'data/ZapfDingbats.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/ZapfDingbats.afm', 'utf8'), encoding: 'utf8' }
|
|
6
|
+
},
|
|
7
|
+
fonts: {
|
|
8
|
+
ZapfDingbats: {
|
|
9
|
+
normal: 'ZapfDingbats'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : this;
|
|
15
|
+
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
16
|
+
_global.pdfMake.addFontContainer(fontContainer);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (typeof module !== 'undefined') {
|
|
20
|
+
module.exports = fontContainer;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../virtual-fs').default;
|
package/src/columnCalculator.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var isString = require('./helpers').isString;
|
|
1
|
+
import { isString } from './helpers/variableType';
|
|
4
2
|
|
|
5
3
|
function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
let autoColumns = [];
|
|
5
|
+
let autoMin = 0;
|
|
6
|
+
let autoMax = 0;
|
|
7
|
+
let starColumns = [];
|
|
8
|
+
let starMaxMin = 0;
|
|
9
|
+
let starMaxMax = 0;
|
|
10
|
+
let fixedColumns = [];
|
|
11
|
+
let initial_availableWidth = availableWidth;
|
|
12
|
+
|
|
13
|
+
columns.forEach(column => {
|
|
15
14
|
if (isAutoColumn(column)) {
|
|
16
15
|
autoColumns.push(column);
|
|
17
16
|
autoMin += column._minWidth;
|
|
@@ -25,16 +24,16 @@ function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode)
|
|
|
25
24
|
}
|
|
26
25
|
});
|
|
27
26
|
|
|
28
|
-
fixedColumns.forEach(
|
|
27
|
+
fixedColumns.forEach((col, colIndex) => {
|
|
29
28
|
// width specified as %
|
|
30
29
|
if (isString(col.width) && /\d+%/.test(col.width)) {
|
|
31
30
|
// In tables we have to take into consideration the reserved width for paddings and borders
|
|
32
|
-
|
|
31
|
+
let reservedWidth = 0;
|
|
33
32
|
if (tableNode) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
const paddingLeft = tableNode._layout.paddingLeft(colIndex, tableNode);
|
|
34
|
+
const paddingRight = tableNode._layout.paddingRight(colIndex, tableNode);
|
|
35
|
+
const borderLeft = tableNode._layout.vLineWidth(colIndex, tableNode);
|
|
36
|
+
const borderRight = tableNode._layout.vLineWidth(colIndex + 1, tableNode);
|
|
38
37
|
if (colIndex === 0) {
|
|
39
38
|
// first column assumes whole borderLeft and half of border right
|
|
40
39
|
reservedWidth = paddingLeft + paddingRight + borderLeft + (borderRight / 2);
|
|
@@ -48,7 +47,7 @@ function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode)
|
|
|
48
47
|
reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + (borderRight / 2);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
|
|
50
|
+
const totalAvailableWidth = initial_availableWidth + offsetTotal;
|
|
52
51
|
col.width = (parseFloat(col.width) * totalAvailableWidth / 100) - reservedWidth;
|
|
53
52
|
}
|
|
54
53
|
if (col.width < (col._minWidth) && col.elasticWidth) {
|
|
@@ -63,43 +62,43 @@ function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode)
|
|
|
63
62
|
// http://www.freesoft.org/CIE/RFC/1942/18.htm
|
|
64
63
|
// http://www.w3.org/TR/CSS2/tables.html#width-layout
|
|
65
64
|
// http://dev.w3.org/csswg/css3-tables-algorithms/Overview.src.htm
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
let minW = autoMin + starMaxMin * starColumns.length;
|
|
66
|
+
let maxW = autoMax + starMaxMax * starColumns.length;
|
|
68
67
|
if (minW >= availableWidth) {
|
|
69
68
|
// case 1 - there's no way to fit all columns within available width
|
|
70
69
|
// that's actually pretty bad situation with PDF as we have no horizontal scroll
|
|
71
70
|
// no easy workaround (unless we decide, in the future, to split single words)
|
|
72
71
|
// currently we simply use minWidths for all columns
|
|
73
|
-
autoColumns.forEach(
|
|
72
|
+
autoColumns.forEach(col => {
|
|
74
73
|
col._calcWidth = col._minWidth;
|
|
75
74
|
});
|
|
76
75
|
|
|
77
|
-
starColumns.forEach(
|
|
76
|
+
starColumns.forEach(col => {
|
|
78
77
|
col._calcWidth = starMaxMin; // starMaxMin already contains padding
|
|
79
78
|
});
|
|
80
79
|
} else {
|
|
81
80
|
if (maxW < availableWidth) {
|
|
82
81
|
// case 2 - we can fit rest of the table within available space
|
|
83
|
-
autoColumns.forEach(
|
|
82
|
+
autoColumns.forEach(col => {
|
|
84
83
|
col._calcWidth = col._maxWidth;
|
|
85
84
|
availableWidth -= col._calcWidth;
|
|
86
85
|
});
|
|
87
86
|
} else {
|
|
88
87
|
// maxW is too large, but minW fits within available width
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
let W = availableWidth - minW;
|
|
89
|
+
let D = maxW - minW;
|
|
91
90
|
|
|
92
|
-
autoColumns.forEach(
|
|
93
|
-
|
|
91
|
+
autoColumns.forEach(col => {
|
|
92
|
+
let d = col._maxWidth - col._minWidth;
|
|
94
93
|
col._calcWidth = col._minWidth + d * W / D;
|
|
95
94
|
availableWidth -= col._calcWidth;
|
|
96
95
|
});
|
|
97
96
|
}
|
|
98
97
|
|
|
99
98
|
if (starColumns.length > 0) {
|
|
100
|
-
|
|
99
|
+
let starSize = availableWidth / starColumns.length;
|
|
101
100
|
|
|
102
|
-
starColumns.forEach(
|
|
101
|
+
starColumns.forEach(col => {
|
|
103
102
|
col._calcWidth = starSize;
|
|
104
103
|
});
|
|
105
104
|
}
|
|
@@ -116,13 +115,12 @@ function isStarColumn(column) {
|
|
|
116
115
|
|
|
117
116
|
//TODO: refactor and reuse in measureTable
|
|
118
117
|
function measureMinMax(columns) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
var starCount = 0;
|
|
118
|
+
let result = { min: 0, max: 0 };
|
|
119
|
+
let maxStar = { min: 0, max: 0 };
|
|
120
|
+
let starCount = 0;
|
|
123
121
|
|
|
124
|
-
for (
|
|
125
|
-
|
|
122
|
+
for (let i = 0, l = columns.length; i < l; i++) {
|
|
123
|
+
let c = columns[i];
|
|
126
124
|
|
|
127
125
|
if (isStarColumn(c)) {
|
|
128
126
|
maxStar.min = Math.max(maxStar.min, c._minWidth);
|
|
@@ -147,9 +145,8 @@ function measureMinMax(columns) {
|
|
|
147
145
|
|
|
148
146
|
/**
|
|
149
147
|
* Calculates column widths
|
|
150
|
-
* @private
|
|
151
148
|
*/
|
|
152
|
-
|
|
149
|
+
export default {
|
|
153
150
|
buildColumnWidths: buildColumnWidths,
|
|
154
151
|
measureMinMax: measureMinMax,
|
|
155
152
|
isAutoColumn: isAutoColumn,
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { isNumber } from './variableType';
|
|
2
|
+
|
|
3
|
+
function fontStringify(key, val) {
|
|
4
|
+
if (key === 'font') {
|
|
5
|
+
return 'font';
|
|
6
|
+
}
|
|
7
|
+
return val;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Convert node to readable string
|
|
12
|
+
*
|
|
13
|
+
* @param {object} node
|
|
14
|
+
* @returns {string}
|
|
15
|
+
*/
|
|
16
|
+
export function stringifyNode(node) {
|
|
17
|
+
return JSON.stringify(node, fontStringify);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {object} node
|
|
22
|
+
* @returns {?string}
|
|
23
|
+
*/
|
|
24
|
+
export function getNodeId(node) {
|
|
25
|
+
if (node.id) {
|
|
26
|
+
return node.id;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (Array.isArray(node.text)) {
|
|
30
|
+
for (let n of node.text) {
|
|
31
|
+
let nodeId = getNodeId(n);
|
|
32
|
+
if (nodeId) {
|
|
33
|
+
return nodeId;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {object} node
|
|
43
|
+
* @param {object} styleStack object is instance of PDFDocument
|
|
44
|
+
* @returns {?Array}
|
|
45
|
+
*/
|
|
46
|
+
export function getNodeMargin(node, styleStack) {
|
|
47
|
+
function processSingleMargins(node, currentMargin) {
|
|
48
|
+
if (node.marginLeft || node.marginTop || node.marginRight || node.marginBottom) {
|
|
49
|
+
return [
|
|
50
|
+
node.marginLeft || currentMargin[0] || 0,
|
|
51
|
+
node.marginTop || currentMargin[1] || 0,
|
|
52
|
+
node.marginRight || currentMargin[2] || 0,
|
|
53
|
+
node.marginBottom || currentMargin[3] || 0
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
return currentMargin;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function flattenStyleArray(styleArray, styleStack) {
|
|
60
|
+
let flattenedStyles = {};
|
|
61
|
+
for (let i = styleArray.length - 1; i >= 0; i--) {
|
|
62
|
+
let styleName = styleArray[i];
|
|
63
|
+
let style = styleStack.styleDictionary[styleName];
|
|
64
|
+
for (let key in style) {
|
|
65
|
+
if (style.hasOwnProperty(key)) {
|
|
66
|
+
flattenedStyles[key] = style[key];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return flattenedStyles;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function convertMargin(margin) {
|
|
74
|
+
if (isNumber(margin)) {
|
|
75
|
+
margin = [margin, margin, margin, margin];
|
|
76
|
+
} else if (Array.isArray(margin)) {
|
|
77
|
+
if (margin.length === 2) {
|
|
78
|
+
margin = [margin[0], margin[1], margin[0], margin[1]];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return margin;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let margin = [undefined, undefined, undefined, undefined];
|
|
85
|
+
|
|
86
|
+
if (node.style) {
|
|
87
|
+
let styleArray = Array.isArray(node.style) ? node.style : [node.style];
|
|
88
|
+
let flattenedStyleArray = flattenStyleArray(styleArray, styleStack);
|
|
89
|
+
|
|
90
|
+
if (flattenedStyleArray) {
|
|
91
|
+
margin = processSingleMargins(flattenedStyleArray, margin);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (flattenedStyleArray.margin) {
|
|
95
|
+
margin = convertMargin(flattenedStyleArray.margin);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
margin = processSingleMargins(node, margin);
|
|
100
|
+
|
|
101
|
+
if (node.margin) {
|
|
102
|
+
margin = convertMargin(node.margin);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (margin[0] === undefined && margin[1] === undefined && margin[2] === undefined && margin[3] === undefined) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return margin;
|
|
110
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function pack(...args) {
|
|
2
|
+
let result = {};
|
|
3
|
+
|
|
4
|
+
for (let i = 0, l = args.length; i < l; i++) {
|
|
5
|
+
let obj = args[i];
|
|
6
|
+
|
|
7
|
+
if (obj) {
|
|
8
|
+
for (let key in obj) {
|
|
9
|
+
if (obj.hasOwnProperty(key)) {
|
|
10
|
+
result[key] = obj[key];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function offsetVector(vector, x, y) {
|
|
20
|
+
switch (vector.type) {
|
|
21
|
+
case 'ellipse':
|
|
22
|
+
case 'rect':
|
|
23
|
+
vector.x += x;
|
|
24
|
+
vector.y += y;
|
|
25
|
+
break;
|
|
26
|
+
case 'line':
|
|
27
|
+
vector.x1 += x;
|
|
28
|
+
vector.x2 += x;
|
|
29
|
+
vector.y1 += y;
|
|
30
|
+
vector.y2 += y;
|
|
31
|
+
break;
|
|
32
|
+
case 'polyline':
|
|
33
|
+
for (let i = 0, l = vector.points.length; i < l; i++) {
|
|
34
|
+
vector.points[i].x += x;
|
|
35
|
+
vector.points[i].y += y;
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {any} variable
|
|
3
|
+
* @returns {boolean}
|
|
4
|
+
*/
|
|
5
|
+
export function isString(variable) {
|
|
6
|
+
return (typeof variable === 'string') || (variable instanceof String);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {any} variable
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
13
|
+
export function isNumber(variable) {
|
|
14
|
+
return (typeof variable === 'number') || (variable instanceof Number);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {any} variable
|
|
19
|
+
* @returns {boolean}
|
|
20
|
+
*/
|
|
21
|
+
export function isPositiveInteger(variable) {
|
|
22
|
+
if (!isNumber(variable) || !Number.isInteger(variable) || variable <= 0) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {any} variable
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
32
|
+
export function isObject(variable) {
|
|
33
|
+
return (variable !== null) && !Array.isArray(variable) && !isString(variable) && !isNumber(variable) && (typeof variable === 'object');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {any} variable
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
40
|
+
export function isEmptyObject(variable) {
|
|
41
|
+
return isObject(variable) && (Object.keys(variable).length === 0);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {any} variable
|
|
46
|
+
* @returns {boolean}
|
|
47
|
+
*/
|
|
48
|
+
export function isValue(variable) {
|
|
49
|
+
return (variable !== undefined) && (variable !== null);
|
|
50
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const pdfmakeBase = require('./base').default;
|
|
2
|
+
const OutputDocumentServer = require('./OutputDocumentServer').default;
|
|
3
|
+
const URLResolver = require('./URLResolver').default;
|
|
4
|
+
|
|
5
|
+
class pdfmake extends pdfmakeBase {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.urlResolver = new URLResolver(this.virtualfs);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
_transformToDocument(doc) {
|
|
12
|
+
return new OutputDocumentServer(doc);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = new pdfmake();
|
package/src/qrEnc.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/*eslint no-unused-vars: ["error", {"args": "none"}]*/
|
|
2
2
|
/*eslint no-redeclare: "off"*/
|
|
3
|
+
/*eslint no-throw-literal: "off"*/
|
|
3
4
|
|
|
4
5
|
'use strict';
|
|
5
6
|
/* qr.js -- QR code generator in Javascript (revision 2011-01-19)
|
|
@@ -355,7 +356,7 @@ var calculateecc = function (poly, genpoly) {
|
|
|
355
356
|
var polylen = poly.length, genpolylen = genpoly.length;
|
|
356
357
|
for (var i = 0; i < genpolylen; ++i)
|
|
357
358
|
modulus.push(0);
|
|
358
|
-
for (var i = 0; i < polylen;
|
|
359
|
+
for (var i = 0; i < polylen;) {
|
|
359
360
|
var quotient = GF256_INVMAP[modulus[i++]];
|
|
360
361
|
if (quotient >= 0) {
|
|
361
362
|
for (var j = 0; j < genpolylen; ++j) {
|
|
@@ -483,7 +484,7 @@ var makebasematrix = function (ver) {
|
|
|
483
484
|
}
|
|
484
485
|
}
|
|
485
486
|
|
|
486
|
-
return {matrix: matrix, reserved: reserved};
|
|
487
|
+
return { matrix: matrix, reserved: reserved };
|
|
487
488
|
};
|
|
488
489
|
|
|
489
490
|
// fills the data portion (i.e. unmarked in reserved) of the matrix with given
|
|
@@ -590,7 +591,7 @@ var evaluatematrix = function (matrix) {
|
|
|
590
591
|
|
|
591
592
|
// evaluate the current row
|
|
592
593
|
groups = [0]; // the first empty group of white
|
|
593
|
-
for (var j = 0; j < n;
|
|
594
|
+
for (var j = 0; j < n;) {
|
|
594
595
|
var k;
|
|
595
596
|
for (k = 0; j < n && row[j]; ++k)
|
|
596
597
|
++j;
|
|
@@ -603,7 +604,7 @@ var evaluatematrix = function (matrix) {
|
|
|
603
604
|
|
|
604
605
|
// evaluate the current column
|
|
605
606
|
groups = [0];
|
|
606
|
-
for (var j = 0; j < n;
|
|
607
|
+
for (var j = 0; j < n;) {
|
|
607
608
|
var k;
|
|
608
609
|
for (k = 0; j < n && matrix[j][i]; ++k)
|
|
609
610
|
++j;
|
|
@@ -677,10 +678,14 @@ var generate = function (data, ver, mode, ecclevel, mask) {
|
|
|
677
678
|
//
|
|
678
679
|
|
|
679
680
|
function generateFrame(data, options) {
|
|
680
|
-
var MODES = {
|
|
681
|
-
'
|
|
682
|
-
|
|
683
|
-
|
|
681
|
+
var MODES = {
|
|
682
|
+
'numeric': MODE_NUMERIC, 'alphanumeric': MODE_ALPHANUMERIC,
|
|
683
|
+
'octet': MODE_OCTET
|
|
684
|
+
};
|
|
685
|
+
var ECCLEVELS = {
|
|
686
|
+
'L': ECCLEVEL_L, 'M': ECCLEVEL_M, 'Q': ECCLEVEL_Q,
|
|
687
|
+
'H': ECCLEVEL_H
|
|
688
|
+
};
|
|
684
689
|
|
|
685
690
|
options = options || {};
|
|
686
691
|
var ver = options.version || -1;
|
|
@@ -786,6 +791,6 @@ function measure(node) {
|
|
|
786
791
|
return node;
|
|
787
792
|
}
|
|
788
793
|
|
|
789
|
-
|
|
794
|
+
export default {
|
|
790
795
|
measure: measure
|
|
791
|
-
};
|
|
796
|
+
};
|
package/src/standardPageSizes.js
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*eslint no-unused-vars: ["error", {"args": "none"}]*/
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
tableLayouts,
|
|
5
|
+
defaultTableLayout
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const tableLayouts = {
|
|
9
|
+
noBorders: {
|
|
10
|
+
hLineWidth(i) {
|
|
11
|
+
return 0;
|
|
12
|
+
},
|
|
13
|
+
vLineWidth(i) {
|
|
14
|
+
return 0;
|
|
15
|
+
},
|
|
16
|
+
paddingLeft(i) {
|
|
17
|
+
return i && 4 || 0;
|
|
18
|
+
},
|
|
19
|
+
paddingRight(i, node) {
|
|
20
|
+
return (i < node.table.widths.length - 1) ? 4 : 0;
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
headerLineOnly: {
|
|
24
|
+
hLineWidth(i, node) {
|
|
25
|
+
if (i === 0 || i === node.table.body.length) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
return (i === node.table.headerRows) ? 2 : 0;
|
|
29
|
+
},
|
|
30
|
+
vLineWidth(i) {
|
|
31
|
+
return 0;
|
|
32
|
+
},
|
|
33
|
+
paddingLeft(i) {
|
|
34
|
+
return i === 0 ? 0 : 8;
|
|
35
|
+
},
|
|
36
|
+
paddingRight(i, node) {
|
|
37
|
+
return (i === node.table.widths.length - 1) ? 0 : 8;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
lightHorizontalLines: {
|
|
41
|
+
hLineWidth(i, node) {
|
|
42
|
+
if (i === 0 || i === node.table.body.length) {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
return (i === node.table.headerRows) ? 2 : 1;
|
|
46
|
+
},
|
|
47
|
+
vLineWidth(i) {
|
|
48
|
+
return 0;
|
|
49
|
+
},
|
|
50
|
+
hLineColor(i) {
|
|
51
|
+
return i === 1 ? 'black' : '#aaa';
|
|
52
|
+
},
|
|
53
|
+
paddingLeft(i) {
|
|
54
|
+
return i === 0 ? 0 : 8;
|
|
55
|
+
},
|
|
56
|
+
paddingRight(i, node) {
|
|
57
|
+
return (i === node.table.widths.length - 1) ? 0 : 8;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const defaultTableLayout = {
|
|
63
|
+
hLineWidth(i, node) {
|
|
64
|
+
return 1;
|
|
65
|
+
},
|
|
66
|
+
vLineWidth(i, node) {
|
|
67
|
+
return 1;
|
|
68
|
+
},
|
|
69
|
+
hLineColor(i, node) {
|
|
70
|
+
return 'black';
|
|
71
|
+
},
|
|
72
|
+
vLineColor(i, node) {
|
|
73
|
+
return 'black';
|
|
74
|
+
},
|
|
75
|
+
hLineStyle(i, node) {
|
|
76
|
+
return null;
|
|
77
|
+
},
|
|
78
|
+
vLineStyle(i, node) {
|
|
79
|
+
return null;
|
|
80
|
+
},
|
|
81
|
+
paddingLeft(i, node) {
|
|
82
|
+
return 4;
|
|
83
|
+
},
|
|
84
|
+
paddingRight(i, node) {
|
|
85
|
+
return 4;
|
|
86
|
+
},
|
|
87
|
+
paddingTop(i, node) {
|
|
88
|
+
return 2;
|
|
89
|
+
},
|
|
90
|
+
paddingBottom(i, node) {
|
|
91
|
+
return 2;
|
|
92
|
+
},
|
|
93
|
+
fillColor(i, node) {
|
|
94
|
+
return null;
|
|
95
|
+
},
|
|
96
|
+
fillOpacity(i, node) {
|
|
97
|
+
return 1;
|
|
98
|
+
},
|
|
99
|
+
defaultBorder: true
|
|
100
|
+
};
|