@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.
- package/.vscode/tasks.json +17 -0
- package/CHANGELOG.md +83 -128
- package/LICENSE +22 -22
- package/README.md +188 -681
- package/build/fonts/Cairo/Cairo-Black.ttf +0 -0
- package/build/fonts/Cairo/Cairo-Bold.ttf +0 -0
- package/build/fonts/Cairo/Cairo-ExtraLight.ttf +0 -0
- package/build/fonts/Cairo/Cairo-Light.ttf +0 -0
- package/build/fonts/Cairo/Cairo-Regular.ttf +0 -0
- package/build/fonts/Cairo/Cairo-SemiBold.ttf +0 -0
- package/build/fonts/Cairo.js +27 -0
- package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
- package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
- package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/build/fonts/Roboto.js +27 -0
- package/build/pdfmake.js +63736 -71285
- 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 +11 -7
- package/build-vfs.js +44 -44
- package/fonts/Cairo/Cairo-Black.ttf +0 -0
- package/fonts/Cairo/Cairo-Bold.ttf +0 -0
- package/fonts/Cairo/Cairo-ExtraLight.ttf +0 -0
- package/fonts/Cairo/Cairo-Light.ttf +0 -0
- package/fonts/Cairo/Cairo-Regular.ttf +0 -0
- package/fonts/Cairo/Cairo-SemiBold.ttf +0 -0
- package/fonts/Cairo.js +8 -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/index.js +26 -26
- package/package.json +42 -39
- package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -9
- package/src/3rd-party/svg-to-pdfkit/source.js +229 -36
- package/src/3rd-party/svg-to-pdfkit.js +3 -3
- package/src/OutputDocument.js +64 -0
- package/src/OutputDocumentServer.js +32 -0
- package/src/PDFDocument.js +174 -0
- package/src/PageSize.js +53 -0
- package/src/Renderer.js +445 -0
- package/src/TextBreaker.js +168 -0
- package/src/TextInlines.js +263 -0
- package/src/URLResolver.js +43 -0
- package/src/base.js +70 -0
- package/src/browser-extensions/OutputDocumentBrowser.js +80 -0
- package/src/browser-extensions/fonts/Cairo.js +27 -0
- package/src/browser-extensions/fonts/Roboto.js +27 -0
- package/src/browser-extensions/index.js +61 -0
- package/src/browser-extensions/pdfMake.js +1 -355
- 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 +154 -157
- package/src/docMeasure.js +802 -810
- package/src/docPreprocessor.js +306 -273
- package/src/documentContext.js +345 -340
- package/src/elementWriter.js +736 -411
- package/src/helpers/node.js +136 -0
- package/src/helpers/tools.js +44 -0
- package/src/helpers/variableType.js +50 -0
- package/src/index.js +16 -0
- package/src/layoutBuilder.js +1393 -1197
- package/src/line.js +122 -104
- package/src/pageElementWriter.js +187 -174
- package/src/printer.js +370 -727
- package/src/qrEnc.js +796 -791
- package/src/rtlUtils.js +500 -485
- package/src/standardPageSizes.js +52 -54
- package/src/styleContextStack.js +208 -138
- package/src/svgMeasure.js +109 -70
- package/src/tableLayouts.js +100 -0
- package/src/tableProcessor.js +620 -606
- package/src/textDecorator.js +175 -157
- package/src/virtual-fs.js +66 -0
- package/standard-fonts/Courier.js +8 -0
- package/standard-fonts/Helvetica.js +8 -0
- package/standard-fonts/Symbol.js +5 -0
- package/standard-fonts/Times.js +8 -0
- package/standard-fonts/ZapfDingbats.js +5 -0
- package/index.html +0 -396
- package/src/browser-extensions/URLBrowserResolver.js +0 -96
- package/src/browser-extensions/virtual-fs.js +0 -55
- package/src/fontProvider.js +0 -68
- package/src/helpers.js +0 -138
- package/src/imageMeasure.js +0 -62
- package/src/pdfKitEngine.js +0 -21
- package/src/textTools.js +0 -391
- package/src/traversalTracker.js +0 -47
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { isNumber, isString } 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
|
+
|
|
48
|
+
function processSingleMargins(node, currentMargin, defaultMargin = 0) {
|
|
49
|
+
if (node.marginLeft !== undefined || node.marginTop !== undefined || node.marginRight !== undefined || node.marginBottom !== undefined) {
|
|
50
|
+
return [
|
|
51
|
+
node.marginLeft ?? currentMargin[0] ?? defaultMargin,
|
|
52
|
+
node.marginTop ?? currentMargin[1] ?? defaultMargin,
|
|
53
|
+
node.marginRight ?? currentMargin[2] ?? defaultMargin,
|
|
54
|
+
node.marginBottom ?? currentMargin[3] ?? defaultMargin
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
return currentMargin;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function flattenStyleArray(styleArray, styleStack, visited = new Set()) {
|
|
61
|
+
styleArray = Array.isArray(styleArray) ? styleArray : [styleArray];
|
|
62
|
+
|
|
63
|
+
// style is not valid array of strings
|
|
64
|
+
if (!styleArray.every(item => isString(item))) {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let flattenedStyles = {};
|
|
69
|
+
for (let index = 0; index < styleArray.length; index++) {
|
|
70
|
+
let styleName = styleArray[index];
|
|
71
|
+
let style = styleStack.styleDictionary[styleName];
|
|
72
|
+
|
|
73
|
+
// style not found
|
|
74
|
+
if (style === undefined) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (visited.has(styleName)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
visited.add(styleName);
|
|
83
|
+
|
|
84
|
+
if (style.extends !== undefined) {
|
|
85
|
+
flattenedStyles = { ...flattenStyleArray(style.extends, styleStack, visited), ...flattenedStyles };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (style.margin !== undefined) {
|
|
89
|
+
flattenedStyles = { margin : convertMargin(style.margin) };
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
flattenedStyles = { margin: processSingleMargins(style, flattenedStyles.margin ?? {}, undefined) };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return flattenedStyles;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function convertMargin(margin) {
|
|
100
|
+
if (isNumber(margin)) {
|
|
101
|
+
margin = [margin, margin, margin, margin];
|
|
102
|
+
} else if (Array.isArray(margin)) {
|
|
103
|
+
if (margin.length === 2) {
|
|
104
|
+
margin = [margin[0], margin[1], margin[0], margin[1]];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return margin;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let margin = [undefined, undefined, undefined, undefined];
|
|
111
|
+
|
|
112
|
+
if (node.style) {
|
|
113
|
+
let styleArray = Array.isArray(node.style) ? node.style : [node.style];
|
|
114
|
+
let flattenedStyleArray = flattenStyleArray(styleArray, styleStack);
|
|
115
|
+
|
|
116
|
+
if (flattenedStyleArray) {
|
|
117
|
+
margin = processSingleMargins(flattenedStyleArray, margin);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (flattenedStyleArray.margin) {
|
|
121
|
+
margin = convertMargin(flattenedStyleArray.margin);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
margin = processSingleMargins(node, margin);
|
|
126
|
+
|
|
127
|
+
if (node.margin !== undefined) {
|
|
128
|
+
margin = convertMargin(node.margin);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (margin[0] === undefined && margin[1] === undefined && margin[2] === undefined && margin[3] === undefined) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return margin;
|
|
136
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
}
|
|
40
|
+
|
|
41
|
+
export function convertToDynamicContent(staticContent) {
|
|
42
|
+
return () => // copy to new object
|
|
43
|
+
JSON.parse(JSON.stringify(staticContent));
|
|
44
|
+
}
|
|
@@ -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)) && !Number.isNaN(variable);
|
|
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();
|