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
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) {
|
|
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,7 +24,7 @@ function buildColumnWidths(columns, availableWidth) {
|
|
|
25
24
|
}
|
|
26
25
|
});
|
|
27
26
|
|
|
28
|
-
fixedColumns.forEach(
|
|
27
|
+
fixedColumns.forEach(col => {
|
|
29
28
|
// width specified as %
|
|
30
29
|
if (isString(col.width) && /\d+%/.test(col.width)) {
|
|
31
30
|
col.width = parseFloat(col.width) * initial_availableWidth / 100;
|
|
@@ -42,43 +41,43 @@ function buildColumnWidths(columns, availableWidth) {
|
|
|
42
41
|
// http://www.freesoft.org/CIE/RFC/1942/18.htm
|
|
43
42
|
// http://www.w3.org/TR/CSS2/tables.html#width-layout
|
|
44
43
|
// http://dev.w3.org/csswg/css3-tables-algorithms/Overview.src.htm
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
let minW = autoMin + starMaxMin * starColumns.length;
|
|
45
|
+
let maxW = autoMax + starMaxMax * starColumns.length;
|
|
47
46
|
if (minW >= availableWidth) {
|
|
48
47
|
// case 1 - there's no way to fit all columns within available width
|
|
49
48
|
// that's actually pretty bad situation with PDF as we have no horizontal scroll
|
|
50
49
|
// no easy workaround (unless we decide, in the future, to split single words)
|
|
51
50
|
// currently we simply use minWidths for all columns
|
|
52
|
-
autoColumns.forEach(
|
|
51
|
+
autoColumns.forEach(col => {
|
|
53
52
|
col._calcWidth = col._minWidth;
|
|
54
53
|
});
|
|
55
54
|
|
|
56
|
-
starColumns.forEach(
|
|
55
|
+
starColumns.forEach(col => {
|
|
57
56
|
col._calcWidth = starMaxMin; // starMaxMin already contains padding
|
|
58
57
|
});
|
|
59
58
|
} else {
|
|
60
59
|
if (maxW < availableWidth) {
|
|
61
60
|
// case 2 - we can fit rest of the table within available space
|
|
62
|
-
autoColumns.forEach(
|
|
61
|
+
autoColumns.forEach(col => {
|
|
63
62
|
col._calcWidth = col._maxWidth;
|
|
64
63
|
availableWidth -= col._calcWidth;
|
|
65
64
|
});
|
|
66
65
|
} else {
|
|
67
66
|
// maxW is too large, but minW fits within available width
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
let W = availableWidth - minW;
|
|
68
|
+
let D = maxW - minW;
|
|
70
69
|
|
|
71
|
-
autoColumns.forEach(
|
|
72
|
-
|
|
70
|
+
autoColumns.forEach(col => {
|
|
71
|
+
let d = col._maxWidth - col._minWidth;
|
|
73
72
|
col._calcWidth = col._minWidth + d * W / D;
|
|
74
73
|
availableWidth -= col._calcWidth;
|
|
75
74
|
});
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
if (starColumns.length > 0) {
|
|
79
|
-
|
|
78
|
+
let starSize = availableWidth / starColumns.length;
|
|
80
79
|
|
|
81
|
-
starColumns.forEach(
|
|
80
|
+
starColumns.forEach(col => {
|
|
82
81
|
col._calcWidth = starSize;
|
|
83
82
|
});
|
|
84
83
|
}
|
|
@@ -95,13 +94,12 @@ function isStarColumn(column) {
|
|
|
95
94
|
|
|
96
95
|
//TODO: refactor and reuse in measureTable
|
|
97
96
|
function measureMinMax(columns) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
var starCount = 0;
|
|
97
|
+
let result = { min: 0, max: 0 };
|
|
98
|
+
let maxStar = { min: 0, max: 0 };
|
|
99
|
+
let starCount = 0;
|
|
102
100
|
|
|
103
|
-
for (
|
|
104
|
-
|
|
101
|
+
for (let i = 0, l = columns.length; i < l; i++) {
|
|
102
|
+
let c = columns[i];
|
|
105
103
|
|
|
106
104
|
if (isStarColumn(c)) {
|
|
107
105
|
maxStar.min = Math.max(maxStar.min, c._minWidth);
|
|
@@ -126,9 +124,8 @@ function measureMinMax(columns) {
|
|
|
126
124
|
|
|
127
125
|
/**
|
|
128
126
|
* Calculates column widths
|
|
129
|
-
* @private
|
|
130
127
|
*/
|
|
131
|
-
|
|
128
|
+
export default {
|
|
132
129
|
buildColumnWidths: buildColumnWidths,
|
|
133
130
|
measureMinMax: measureMinMax,
|
|
134
131
|
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,39 @@
|
|
|
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 isObject(variable) {
|
|
22
|
+
return (variable !== null) && !Array.isArray(variable) && !isString(variable) && !isNumber(variable) && (typeof variable === 'object');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {any} variable
|
|
27
|
+
* @returns {boolean}
|
|
28
|
+
*/
|
|
29
|
+
export function isEmptyObject(variable) {
|
|
30
|
+
return isObject(variable) && (Object.keys(variable).length === 0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {any} variable
|
|
35
|
+
* @returns {boolean}
|
|
36
|
+
*/
|
|
37
|
+
export function isValue(variable) {
|
|
38
|
+
return (variable !== undefined) && (variable !== null);
|
|
39
|
+
}
|
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;
|
|
@@ -784,6 +789,6 @@ function measure(node) {
|
|
|
784
789
|
return node;
|
|
785
790
|
}
|
|
786
791
|
|
|
787
|
-
|
|
792
|
+
export default {
|
|
788
793
|
measure: measure
|
|
789
|
-
};
|
|
794
|
+
};
|
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
|
+
};
|
|
@@ -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();
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function VirtualFileSystem() {
|
|
4
|
-
this.fileSystem = {};
|
|
5
|
-
this.dataSystem = {};
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
VirtualFileSystem.prototype.existsSync = function (filename) {
|
|
9
|
-
filename = fixFilename(filename);
|
|
10
|
-
return typeof this.fileSystem[filename] !== 'undefined'
|
|
11
|
-
|| typeof this.dataSystem[filename] !== 'undefined';
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
VirtualFileSystem.prototype.readFileSync = function (filename, options) {
|
|
15
|
-
filename = fixFilename(filename);
|
|
16
|
-
|
|
17
|
-
var dataContent = this.dataSystem[filename];
|
|
18
|
-
if (typeof dataContent === 'string' && options === 'utf8') {
|
|
19
|
-
return dataContent;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (dataContent) {
|
|
23
|
-
return new Buffer(dataContent, typeof dataContent === 'string' ? 'base64' : undefined);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var content = this.fileSystem[filename];
|
|
27
|
-
if (content) {
|
|
28
|
-
return content;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
throw 'File \'' + filename + '\' not found in virtual file system';
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
VirtualFileSystem.prototype.writeFileSync = function (filename, content) {
|
|
35
|
-
this.fileSystem[fixFilename(filename)] = content;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
VirtualFileSystem.prototype.bindFS = function (data) {
|
|
39
|
-
this.dataSystem = data || {};
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
function fixFilename(filename) {
|
|
44
|
-
if (filename.indexOf(__dirname) === 0) {
|
|
45
|
-
filename = filename.substring(__dirname.length);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (filename.indexOf('/') === 0) {
|
|
49
|
-
filename = filename.substring(1);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return filename;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = new VirtualFileSystem();
|