pdfmake-acroforms 0.3.4
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 +60 -0
- package/LICENSE +21 -0
- package/README.md +75 -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 +67806 -0
- package/build/pdfmake.js.map +1 -0
- package/build/pdfmake.min.js +3 -0
- package/build/pdfmake.min.js.map +1 -0
- 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 +6 -0
- package/build-vfs.js +44 -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 +3823 -0
- package/js/3rd-party/svg-to-pdfkit.js +7 -0
- package/js/DocMeasure.js +675 -0
- package/js/DocPreprocessor.js +258 -0
- package/js/DocumentContext.js +310 -0
- package/js/ElementWriter.js +399 -0
- package/js/LayoutBuilder.js +1202 -0
- package/js/Line.js +101 -0
- package/js/OutputDocument.js +64 -0
- package/js/OutputDocumentServer.js +29 -0
- package/js/PDFDocument.js +145 -0
- package/js/PageElementWriter.js +164 -0
- package/js/PageSize.js +74 -0
- package/js/Printer.js +288 -0
- package/js/Renderer.js +513 -0
- package/js/SVGMeasure.js +92 -0
- package/js/StyleContextStack.js +191 -0
- package/js/TableProcessor.js +562 -0
- package/js/TextBreaker.js +179 -0
- package/js/TextDecorator.js +152 -0
- package/js/TextInlines.js +212 -0
- package/js/URLResolver.js +43 -0
- package/js/base.js +59 -0
- package/js/browser-extensions/OutputDocumentBrowser.js +82 -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 +122 -0
- package/js/helpers/tools.js +46 -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 +94 -0
- package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -0
- package/src/3rd-party/svg-to-pdfkit/source.js +2745 -0
- package/src/3rd-party/svg-to-pdfkit.js +3 -0
- package/src/DocMeasure.js +768 -0
- package/src/DocPreprocessor.js +289 -0
- package/src/DocumentContext.js +345 -0
- package/src/ElementWriter.js +468 -0
- package/src/LayoutBuilder.js +1366 -0
- package/src/Line.js +108 -0
- package/src/OutputDocument.js +64 -0
- package/src/OutputDocumentServer.js +32 -0
- package/src/PDFDocument.js +178 -0
- package/src/PageElementWriter.js +191 -0
- package/src/PageSize.js +53 -0
- package/src/Printer.js +306 -0
- package/src/Renderer.js +546 -0
- package/src/SVGMeasure.js +109 -0
- package/src/StyleContextStack.js +208 -0
- package/src/TableProcessor.js +620 -0
- package/src/TextBreaker.js +181 -0
- package/src/TextDecorator.js +175 -0
- package/src/TextInlines.js +229 -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/Roboto.js +27 -0
- package/src/browser-extensions/index.js +55 -0
- package/src/browser-extensions/pdfMake.js +1 -0
- 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 -0
- package/src/helpers/node.js +134 -0
- package/src/helpers/tools.js +44 -0
- package/src/helpers/variableType.js +50 -0
- package/src/index.js +16 -0
- package/src/qrEnc.js +796 -0
- package/src/standardPageSizes.js +52 -0
- 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 +8 -0
- package/standard-fonts/Symbol.js +5 -0
- package/standard-fonts/Times.js +8 -0
- package/standard-fonts/ZapfDingbats.js +5 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import OutputDocument from '../OutputDocument';
|
|
2
|
+
import { saveAs } from 'file-saver';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @returns {Window}
|
|
6
|
+
*/
|
|
7
|
+
const openWindow = () => {
|
|
8
|
+
// we have to open the window immediately and store the reference
|
|
9
|
+
// otherwise popup blockers will stop us
|
|
10
|
+
let win = window.open('', '_blank');
|
|
11
|
+
if (win === null) {
|
|
12
|
+
throw new Error('Open PDF in new window blocked by browser');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return win;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
class OutputDocumentBrowser extends OutputDocument {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @returns {Promise<Blob>}
|
|
22
|
+
*/
|
|
23
|
+
async getBlob() {
|
|
24
|
+
const buffer = await this.getBuffer();
|
|
25
|
+
return new Blob([buffer], { type: 'application/pdf' });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} filename
|
|
30
|
+
* @returns {Promise}
|
|
31
|
+
*/
|
|
32
|
+
async download(filename = 'file.pdf') {
|
|
33
|
+
const blob = await this.getBlob();
|
|
34
|
+
saveAs(blob, filename);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {Window} win
|
|
39
|
+
* @returns {Promise}
|
|
40
|
+
*/
|
|
41
|
+
async open(win = null) {
|
|
42
|
+
if (!win) {
|
|
43
|
+
win = openWindow();
|
|
44
|
+
}
|
|
45
|
+
const blob = await this.getBlob();
|
|
46
|
+
try {
|
|
47
|
+
let urlCreator = window.URL || window.webkitURL;
|
|
48
|
+
let pdfUrl = urlCreator.createObjectURL(blob);
|
|
49
|
+
win.location.href = pdfUrl;
|
|
50
|
+
|
|
51
|
+
/* temporarily disabled
|
|
52
|
+
if (win === window) {
|
|
53
|
+
return;
|
|
54
|
+
} else {
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
if (win.window === null) { // is closed by AdBlock
|
|
57
|
+
window.location.href = pdfUrl; // open in actual window
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}, 500);
|
|
61
|
+
}
|
|
62
|
+
*/
|
|
63
|
+
} catch (e) {
|
|
64
|
+
win.close();
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {Window} win
|
|
71
|
+
* @returns {Promise}
|
|
72
|
+
*/
|
|
73
|
+
async print(win = null) {
|
|
74
|
+
const stream = await this.getStream();
|
|
75
|
+
stream.setOpenActionAsPrint();
|
|
76
|
+
await this.open(win);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default OutputDocumentBrowser;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
|
|
3
|
+
var fontContainer = {
|
|
4
|
+
vfs: {
|
|
5
|
+
'Roboto-Regular.ttf': { data: fs.readFileSync(__dirname + '/../../../fonts/Roboto/Roboto-Regular.ttf', 'base64'), encoding: 'base64' },
|
|
6
|
+
'Roboto-Medium.ttf': { data: fs.readFileSync(__dirname + '/../../../fonts/Roboto/Roboto-Medium.ttf', 'base64'), encoding: 'base64' },
|
|
7
|
+
'Roboto-Italic.ttf': { data: fs.readFileSync(__dirname + '/../../../fonts/Roboto/Roboto-Italic.ttf', 'base64'), encoding: 'base64' },
|
|
8
|
+
'Roboto-MediumItalic.ttf': { data: fs.readFileSync(__dirname + '/../../../fonts/Roboto/Roboto-MediumItalic.ttf', 'base64'), encoding: 'base64' }
|
|
9
|
+
},
|
|
10
|
+
fonts: {
|
|
11
|
+
Roboto: {
|
|
12
|
+
normal: 'Roboto-Regular.ttf',
|
|
13
|
+
bold: 'Roboto-Medium.ttf',
|
|
14
|
+
italics: 'Roboto-Italic.ttf',
|
|
15
|
+
bolditalics: 'Roboto-MediumItalic.ttf'
|
|
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,55 @@
|
|
|
1
|
+
import pdfmakeBase from '../base';
|
|
2
|
+
import OutputDocumentBrowser from './OutputDocumentBrowser';
|
|
3
|
+
import URLResolver from '../URLResolver';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import configurator from 'core-js/configurator';
|
|
6
|
+
|
|
7
|
+
// core-js: Polyfills will be used only if natives completely unavailable.
|
|
8
|
+
configurator({
|
|
9
|
+
useNative: ['Promise']
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
let defaultClientFonts = {
|
|
13
|
+
Roboto: {
|
|
14
|
+
normal: 'Roboto-Regular.ttf',
|
|
15
|
+
bold: 'Roboto-Medium.ttf',
|
|
16
|
+
italics: 'Roboto-Italic.ttf',
|
|
17
|
+
bolditalics: 'Roboto-MediumItalic.ttf'
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
class pdfmake extends pdfmakeBase {
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.urlResolver = () => new URLResolver(this.virtualfs);
|
|
25
|
+
this.fonts = defaultClientFonts;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
addFontContainer(fontContainer) {
|
|
29
|
+
this.addVirtualFileSystem(fontContainer.vfs);
|
|
30
|
+
this.addFonts(fontContainer.fonts);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
addVirtualFileSystem(vfs) {
|
|
34
|
+
for (let key in vfs) {
|
|
35
|
+
if (vfs.hasOwnProperty(key)) {
|
|
36
|
+
let data;
|
|
37
|
+
let encoding;
|
|
38
|
+
if (typeof vfs[key] === 'object') {
|
|
39
|
+
data = vfs[key].data;
|
|
40
|
+
encoding = vfs[key].encoding || 'base64';
|
|
41
|
+
} else {
|
|
42
|
+
data = vfs[key];
|
|
43
|
+
encoding = 'base64';
|
|
44
|
+
}
|
|
45
|
+
fs.writeFileSync(key, data, encoding);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_transformToDocument(doc) {
|
|
51
|
+
return new OutputDocumentBrowser(doc);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default new pdfmake();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./index').default;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
|
|
3
|
+
var fontContainer = {
|
|
4
|
+
vfs: {
|
|
5
|
+
'data/Courier.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier.afm', 'utf8'), encoding: 'utf8' },
|
|
6
|
+
'data/Courier-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier-Bold.afm', 'utf8'), encoding: 'utf8' },
|
|
7
|
+
'data/Courier-Oblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier-Oblique.afm', 'utf8'), encoding: 'utf8' },
|
|
8
|
+
'data/Courier-BoldOblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier-BoldOblique.afm', 'utf8'), encoding: 'utf8' }
|
|
9
|
+
},
|
|
10
|
+
fonts: {
|
|
11
|
+
Courier: {
|
|
12
|
+
normal: 'Courier',
|
|
13
|
+
bold: 'Courier-Bold',
|
|
14
|
+
italics: 'Courier-Oblique',
|
|
15
|
+
bolditalics: 'Courier-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,27 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
|
|
3
|
+
var fontContainer = {
|
|
4
|
+
vfs: {
|
|
5
|
+
'data/Helvetica.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica.afm', 'utf8'), encoding: 'utf8' },
|
|
6
|
+
'data/Helvetica-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica-Bold.afm', 'utf8'), encoding: 'utf8' },
|
|
7
|
+
'data/Helvetica-Oblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica-Oblique.afm', 'utf8'), encoding: 'utf8' },
|
|
8
|
+
'data/Helvetica-BoldOblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/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/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/pdfkit/js/data/Times-Roman.afm', 'utf8'), encoding: 'utf8' },
|
|
6
|
+
'data/Times-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-Bold.afm', 'utf8'), encoding: 'utf8' },
|
|
7
|
+
'data/Times-Italic.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-Italic.afm', 'utf8'), encoding: 'utf8' },
|
|
8
|
+
'data/Times-BoldItalic.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/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/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;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { isString } from './helpers/variableType';
|
|
2
|
+
|
|
3
|
+
function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode) {
|
|
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 => {
|
|
14
|
+
if (isAutoColumn(column)) {
|
|
15
|
+
autoColumns.push(column);
|
|
16
|
+
autoMin += column._minWidth;
|
|
17
|
+
autoMax += column._maxWidth;
|
|
18
|
+
} else if (isStarColumn(column)) {
|
|
19
|
+
starColumns.push(column);
|
|
20
|
+
starMaxMin = Math.max(starMaxMin, column._minWidth);
|
|
21
|
+
starMaxMax = Math.max(starMaxMax, column._maxWidth);
|
|
22
|
+
} else {
|
|
23
|
+
fixedColumns.push(column);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
fixedColumns.forEach((col, colIndex) => {
|
|
28
|
+
// width specified as %
|
|
29
|
+
if (isString(col.width) && /\d+%/.test(col.width)) {
|
|
30
|
+
// In tables we have to take into consideration the reserved width for paddings and borders
|
|
31
|
+
let reservedWidth = 0;
|
|
32
|
+
if (tableNode) {
|
|
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);
|
|
37
|
+
if (colIndex === 0) {
|
|
38
|
+
// first column assumes whole borderLeft and half of border right
|
|
39
|
+
reservedWidth = paddingLeft + paddingRight + borderLeft + (borderRight / 2);
|
|
40
|
+
|
|
41
|
+
} else if (colIndex === fixedColumns.length - 1) {
|
|
42
|
+
// last column assumes whole borderRight and half of border left
|
|
43
|
+
reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + borderRight;
|
|
44
|
+
|
|
45
|
+
} else {
|
|
46
|
+
// Columns in the middle assume half of each border
|
|
47
|
+
reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + (borderRight / 2);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const totalAvailableWidth = initial_availableWidth + offsetTotal;
|
|
51
|
+
col.width = (parseFloat(col.width) * totalAvailableWidth / 100) - reservedWidth;
|
|
52
|
+
}
|
|
53
|
+
if (col.width < (col._minWidth) && col.elasticWidth) {
|
|
54
|
+
col._calcWidth = col._minWidth;
|
|
55
|
+
} else {
|
|
56
|
+
col._calcWidth = col.width;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
availableWidth -= col._calcWidth;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// http://www.freesoft.org/CIE/RFC/1942/18.htm
|
|
63
|
+
// http://www.w3.org/TR/CSS2/tables.html#width-layout
|
|
64
|
+
// http://dev.w3.org/csswg/css3-tables-algorithms/Overview.src.htm
|
|
65
|
+
let minW = autoMin + starMaxMin * starColumns.length;
|
|
66
|
+
let maxW = autoMax + starMaxMax * starColumns.length;
|
|
67
|
+
if (minW >= availableWidth) {
|
|
68
|
+
// case 1 - there's no way to fit all columns within available width
|
|
69
|
+
// that's actually pretty bad situation with PDF as we have no horizontal scroll
|
|
70
|
+
// no easy workaround (unless we decide, in the future, to split single words)
|
|
71
|
+
// currently we simply use minWidths for all columns
|
|
72
|
+
autoColumns.forEach(col => {
|
|
73
|
+
col._calcWidth = col._minWidth;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
starColumns.forEach(col => {
|
|
77
|
+
col._calcWidth = starMaxMin; // starMaxMin already contains padding
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
if (maxW < availableWidth) {
|
|
81
|
+
// case 2 - we can fit rest of the table within available space
|
|
82
|
+
autoColumns.forEach(col => {
|
|
83
|
+
col._calcWidth = col._maxWidth;
|
|
84
|
+
availableWidth -= col._calcWidth;
|
|
85
|
+
});
|
|
86
|
+
} else {
|
|
87
|
+
// maxW is too large, but minW fits within available width
|
|
88
|
+
let W = availableWidth - minW;
|
|
89
|
+
let D = maxW - minW;
|
|
90
|
+
|
|
91
|
+
autoColumns.forEach(col => {
|
|
92
|
+
let d = col._maxWidth - col._minWidth;
|
|
93
|
+
col._calcWidth = col._minWidth + d * W / D;
|
|
94
|
+
availableWidth -= col._calcWidth;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (starColumns.length > 0) {
|
|
99
|
+
let starSize = availableWidth / starColumns.length;
|
|
100
|
+
|
|
101
|
+
starColumns.forEach(col => {
|
|
102
|
+
col._calcWidth = starSize;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function isAutoColumn(column) {
|
|
109
|
+
return column.width === 'auto';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function isStarColumn(column) {
|
|
113
|
+
return column.width === null || column.width === undefined || column.width === '*' || column.width === 'star';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//TODO: refactor and reuse in measureTable
|
|
117
|
+
function measureMinMax(columns) {
|
|
118
|
+
let result = { min: 0, max: 0 };
|
|
119
|
+
let maxStar = { min: 0, max: 0 };
|
|
120
|
+
let starCount = 0;
|
|
121
|
+
|
|
122
|
+
for (let i = 0, l = columns.length; i < l; i++) {
|
|
123
|
+
let c = columns[i];
|
|
124
|
+
|
|
125
|
+
if (isStarColumn(c)) {
|
|
126
|
+
maxStar.min = Math.max(maxStar.min, c._minWidth);
|
|
127
|
+
maxStar.max = Math.max(maxStar.max, c._maxWidth);
|
|
128
|
+
starCount++;
|
|
129
|
+
} else if (isAutoColumn(c)) {
|
|
130
|
+
result.min += c._minWidth;
|
|
131
|
+
result.max += c._maxWidth;
|
|
132
|
+
} else {
|
|
133
|
+
result.min += ((c.width !== undefined && c.width) || c._minWidth);
|
|
134
|
+
result.max += ((c.width !== undefined && c.width) || c._maxWidth);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (starCount) {
|
|
139
|
+
result.min += starCount * maxStar.min;
|
|
140
|
+
result.max += starCount * maxStar.max;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Calculates column widths
|
|
148
|
+
*/
|
|
149
|
+
export default {
|
|
150
|
+
buildColumnWidths: buildColumnWidths,
|
|
151
|
+
measureMinMax: measureMinMax,
|
|
152
|
+
isAutoColumn: isAutoColumn,
|
|
153
|
+
isStarColumn: isStarColumn
|
|
154
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
if (style.extends !== undefined) {
|
|
83
|
+
flattenedStyles = { ...flattenedStyles, ...flattenStyleArray(style.extends, styleStack, new Set([...visited, styleName])) };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (style.margin !== undefined) {
|
|
87
|
+
flattenedStyles = { margin: convertMargin(style.margin) };
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
flattenedStyles = { margin: processSingleMargins(style, flattenedStyles.margin ?? {}, undefined) };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return flattenedStyles;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function convertMargin(margin) {
|
|
98
|
+
if (isNumber(margin)) {
|
|
99
|
+
margin = [margin, margin, margin, margin];
|
|
100
|
+
} else if (Array.isArray(margin)) {
|
|
101
|
+
if (margin.length === 2) {
|
|
102
|
+
margin = [margin[0], margin[1], margin[0], margin[1]];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return margin;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let margin = [undefined, undefined, undefined, undefined];
|
|
109
|
+
|
|
110
|
+
if (node.style) {
|
|
111
|
+
let styleArray = Array.isArray(node.style) ? node.style : [node.style];
|
|
112
|
+
let flattenedStyleArray = flattenStyleArray(styleArray, styleStack);
|
|
113
|
+
|
|
114
|
+
if (flattenedStyleArray) {
|
|
115
|
+
margin = processSingleMargins(flattenedStyleArray, margin);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (flattenedStyleArray.margin) {
|
|
119
|
+
margin = convertMargin(flattenedStyleArray.margin);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
margin = processSingleMargins(node, margin);
|
|
124
|
+
|
|
125
|
+
if (node.margin !== undefined) {
|
|
126
|
+
margin = convertMargin(node.margin);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (margin[0] === undefined && margin[1] === undefined && margin[2] === undefined && margin[3] === undefined) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return margin;
|
|
134
|
+
}
|
|
@@ -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
|
+
}
|