@wirabyte/w-pdfmaker 0.0.0-stage → 1.0.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/CHANGELOG.md +47 -0
- package/LICENSE +22 -0
- package/NOTICE.md +39 -0
- package/README.md +106 -2
- 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 +103161 -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 +9 -0
- package/build/standard-fonts/Helvetica.js +9 -0
- package/build/standard-fonts/Symbol.js +9 -0
- package/build/standard-fonts/Times.js +9 -0
- package/build/standard-fonts/ZapfDingbats.js +9 -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/fonts/THSarabunIT9/LICENSE.txt +7 -0
- package/fonts/THSarabunIT9/THSarabunIT9-Bold.ttf +0 -0
- package/fonts/THSarabunIT9/THSarabunIT9-BoldItalic.ttf +0 -0
- package/fonts/THSarabunIT9/THSarabunIT9-Italic.ttf +0 -0
- package/fonts/THSarabunIT9/THSarabunIT9.ttf +0 -0
- package/fonts/THSarabunNew/COPYING.GPLv2 +339 -0
- package/fonts/THSarabunNew/LICENSE.txt +13 -0
- package/fonts/THSarabunNew/THSarabunNew-Bold.ttf +0 -0
- package/fonts/THSarabunNew/THSarabunNew-BoldItalic.ttf +0 -0
- package/fonts/THSarabunNew/THSarabunNew-Italic.ttf +0 -0
- package/fonts/THSarabunNew/THSarabunNew.ttf +0 -0
- package/index.d.ts +167 -0
- package/interfaces.d.ts +2779 -0
- package/js/DocMeasure.js +695 -0
- package/js/DocPreprocessor.js +263 -0
- package/js/DocumentContext.js +563 -0
- package/js/ElementWriter.js +488 -0
- package/js/LayoutBuilder.js +1525 -0
- package/js/Line.js +105 -0
- package/js/OutputDocument.js +73 -0
- package/js/OutputDocumentServer.js +34 -0
- package/js/PDFDocument.js +322 -0
- package/js/PageElementWriter.js +302 -0
- package/js/PageSize.js +74 -0
- package/js/Printer.js +275 -0
- package/js/Renderer.js +439 -0
- package/js/SVGMeasure.js +94 -0
- package/js/StyleContextStack.js +191 -0
- package/js/TableProcessor.js +658 -0
- package/js/TextBreaker.js +164 -0
- package/js/TextDecorator.js +164 -0
- package/js/TextInlines.js +212 -0
- package/js/URLResolver.js +122 -0
- package/js/base.js +125 -0
- package/js/browser-extensions/OutputDocumentBrowser.js +82 -0
- package/js/browser-extensions/fonts/Roboto.js +38 -0
- package/js/browser-extensions/fonts/thai.js +28 -0
- package/js/browser-extensions/index.js +88 -0
- package/js/browser-extensions/pageUrls.js +79 -0
- package/js/browser-extensions/pdfMake.js +3 -0
- package/js/browser-extensions/standard-fonts/Courier.js +20 -0
- package/js/browser-extensions/standard-fonts/Helvetica.js +20 -0
- package/js/browser-extensions/standard-fonts/Symbol.js +17 -0
- package/js/browser-extensions/standard-fonts/Times.js +20 -0
- package/js/browser-extensions/standard-fonts/ZapfDingbats.js +17 -0
- package/js/browser-extensions/virtual-fs-cjs.js +3 -0
- package/js/columnCalculator.js +159 -0
- package/js/helpers/node.js +122 -0
- package/js/helpers/tools.js +46 -0
- package/js/helpers/variableType.js +59 -0
- package/js/imageFallback.js +23 -0
- package/js/index.js +45 -0
- package/js/mergeStamp.js +194 -0
- package/js/pageNumbering.js +48 -0
- package/js/qrEnc.js +721 -0
- package/js/standardPageSizes.js +56 -0
- package/js/tableLayouts.js +98 -0
- package/js/thai.js +201 -0
- package/js/virtual-fs.js +82 -0
- package/package.json +93 -4
- package/skills/w-pdfmaker/SKILL.md +171 -0
- package/skills/w-pdfmaker/references/browser.md +36 -0
- package/skills/w-pdfmaker/references/document-definition.md +241 -0
- package/skills/w-pdfmaker/references/images.md +90 -0
- package/skills/w-pdfmaker/references/merge-stamp.md +94 -0
- package/skills/w-pdfmaker/references/thai.md +67 -0
- package/src/DocMeasure.js +780 -0
- package/src/DocPreprocessor.js +293 -0
- package/src/DocumentContext.js +605 -0
- package/src/ElementWriter.js +550 -0
- package/src/LayoutBuilder.js +1689 -0
- package/src/Line.js +114 -0
- package/src/OutputDocument.js +75 -0
- package/src/OutputDocumentServer.js +38 -0
- package/src/PDFDocument.js +352 -0
- package/src/PageElementWriter.js +343 -0
- package/src/PageSize.js +53 -0
- package/src/Printer.js +289 -0
- package/src/Renderer.js +468 -0
- package/src/SVGMeasure.js +109 -0
- package/src/StyleContextStack.js +208 -0
- package/src/TableProcessor.js +719 -0
- package/src/TextBreaker.js +166 -0
- package/src/TextDecorator.js +191 -0
- package/src/TextInlines.js +229 -0
- package/src/URLResolver.js +122 -0
- package/src/base.js +143 -0
- package/src/browser-extensions/OutputDocumentBrowser.js +80 -0
- package/src/browser-extensions/fonts/Roboto.js +27 -0
- package/src/browser-extensions/fonts/thai.js +23 -0
- package/src/browser-extensions/index.js +91 -0
- package/src/browser-extensions/pageUrls.js +67 -0
- package/src/browser-extensions/pdfMake.js +1 -0
- package/src/browser-extensions/standard-fonts/Courier.js +25 -0
- package/src/browser-extensions/standard-fonts/Helvetica.js +25 -0
- package/src/browser-extensions/standard-fonts/Symbol.js +17 -0
- package/src/browser-extensions/standard-fonts/Times.js +25 -0
- package/src/browser-extensions/standard-fonts/ZapfDingbats.js +17 -0
- package/src/browser-extensions/virtual-fs-cjs.js +1 -0
- package/src/columnCalculator.js +160 -0
- package/src/helpers/node.js +134 -0
- package/src/helpers/tools.js +44 -0
- package/src/helpers/variableType.js +50 -0
- package/src/imageFallback.js +18 -0
- package/src/index.js +45 -0
- package/src/mergeStamp.js +132 -0
- package/src/pageNumbering.js +45 -0
- package/src/qrEnc.js +796 -0
- package/src/standardPageSizes.js +52 -0
- package/src/tableLayouts.js +100 -0
- package/src/thai.js +170 -0
- package/src/virtual-fs.js +92 -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,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _default = exports.default = {
|
|
6
|
+
'4A0': [4767.87, 6740.79],
|
|
7
|
+
'2A0': [3370.39, 4767.87],
|
|
8
|
+
A0: [2383.94, 3370.39],
|
|
9
|
+
A1: [1683.78, 2383.94],
|
|
10
|
+
A2: [1190.55, 1683.78],
|
|
11
|
+
A3: [841.89, 1190.55],
|
|
12
|
+
A4: [595.28, 841.89],
|
|
13
|
+
A5: [419.53, 595.28],
|
|
14
|
+
A6: [297.64, 419.53],
|
|
15
|
+
A7: [209.76, 297.64],
|
|
16
|
+
A8: [147.40, 209.76],
|
|
17
|
+
A9: [104.88, 147.40],
|
|
18
|
+
A10: [73.70, 104.88],
|
|
19
|
+
B0: [2834.65, 4008.19],
|
|
20
|
+
B1: [2004.09, 2834.65],
|
|
21
|
+
B2: [1417.32, 2004.09],
|
|
22
|
+
B3: [1000.63, 1417.32],
|
|
23
|
+
B4: [708.66, 1000.63],
|
|
24
|
+
B5: [498.90, 708.66],
|
|
25
|
+
B6: [354.33, 498.90],
|
|
26
|
+
B7: [249.45, 354.33],
|
|
27
|
+
B8: [175.75, 249.45],
|
|
28
|
+
B9: [124.72, 175.75],
|
|
29
|
+
B10: [87.87, 124.72],
|
|
30
|
+
C0: [2599.37, 3676.54],
|
|
31
|
+
C1: [1836.85, 2599.37],
|
|
32
|
+
C2: [1298.27, 1836.85],
|
|
33
|
+
C3: [918.43, 1298.27],
|
|
34
|
+
C4: [649.13, 918.43],
|
|
35
|
+
C5: [459.21, 649.13],
|
|
36
|
+
C6: [323.15, 459.21],
|
|
37
|
+
C7: [229.61, 323.15],
|
|
38
|
+
C8: [161.57, 229.61],
|
|
39
|
+
C9: [113.39, 161.57],
|
|
40
|
+
C10: [79.37, 113.39],
|
|
41
|
+
RA0: [2437.80, 3458.27],
|
|
42
|
+
RA1: [1729.13, 2437.80],
|
|
43
|
+
RA2: [1218.90, 1729.13],
|
|
44
|
+
RA3: [864.57, 1218.90],
|
|
45
|
+
RA4: [609.45, 864.57],
|
|
46
|
+
SRA0: [2551.18, 3628.35],
|
|
47
|
+
SRA1: [1814.17, 2551.18],
|
|
48
|
+
SRA2: [1275.59, 1814.17],
|
|
49
|
+
SRA3: [907.09, 1275.59],
|
|
50
|
+
SRA4: [637.80, 907.09],
|
|
51
|
+
EXECUTIVE: [521.86, 756.00],
|
|
52
|
+
FOLIO: [612.00, 936.00],
|
|
53
|
+
LEGAL: [612.00, 1008.00],
|
|
54
|
+
LETTER: [612.00, 792.00],
|
|
55
|
+
TABLOID: [792.00, 1224.00]
|
|
56
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.tableLayouts = exports.defaultTableLayout = void 0;
|
|
5
|
+
/*eslint no-unused-vars: ["error", {"args": "none"}]*/
|
|
6
|
+
|
|
7
|
+
const tableLayouts = exports.tableLayouts = {
|
|
8
|
+
noBorders: {
|
|
9
|
+
hLineWidth(i) {
|
|
10
|
+
return 0;
|
|
11
|
+
},
|
|
12
|
+
vLineWidth(i) {
|
|
13
|
+
return 0;
|
|
14
|
+
},
|
|
15
|
+
paddingLeft(i) {
|
|
16
|
+
return i && 4 || 0;
|
|
17
|
+
},
|
|
18
|
+
paddingRight(i, node) {
|
|
19
|
+
return i < node.table.widths.length - 1 ? 4 : 0;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
headerLineOnly: {
|
|
23
|
+
hLineWidth(i, node) {
|
|
24
|
+
if (i === 0 || i === node.table.body.length) {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
return i === node.table.headerRows ? 2 : 0;
|
|
28
|
+
},
|
|
29
|
+
vLineWidth(i) {
|
|
30
|
+
return 0;
|
|
31
|
+
},
|
|
32
|
+
paddingLeft(i) {
|
|
33
|
+
return i === 0 ? 0 : 8;
|
|
34
|
+
},
|
|
35
|
+
paddingRight(i, node) {
|
|
36
|
+
return i === node.table.widths.length - 1 ? 0 : 8;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
lightHorizontalLines: {
|
|
40
|
+
hLineWidth(i, node) {
|
|
41
|
+
if (i === 0 || i === node.table.body.length) {
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
return i === node.table.headerRows ? 2 : 1;
|
|
45
|
+
},
|
|
46
|
+
vLineWidth(i) {
|
|
47
|
+
return 0;
|
|
48
|
+
},
|
|
49
|
+
hLineColor(i) {
|
|
50
|
+
return i === 1 ? 'black' : '#aaa';
|
|
51
|
+
},
|
|
52
|
+
paddingLeft(i) {
|
|
53
|
+
return i === 0 ? 0 : 8;
|
|
54
|
+
},
|
|
55
|
+
paddingRight(i, node) {
|
|
56
|
+
return i === node.table.widths.length - 1 ? 0 : 8;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const defaultTableLayout = exports.defaultTableLayout = {
|
|
61
|
+
hLineWidth(i, node) {
|
|
62
|
+
return 1;
|
|
63
|
+
},
|
|
64
|
+
vLineWidth(i, node) {
|
|
65
|
+
return 1;
|
|
66
|
+
},
|
|
67
|
+
hLineColor(i, node) {
|
|
68
|
+
return 'black';
|
|
69
|
+
},
|
|
70
|
+
vLineColor(i, node) {
|
|
71
|
+
return 'black';
|
|
72
|
+
},
|
|
73
|
+
hLineStyle(i, node) {
|
|
74
|
+
return null;
|
|
75
|
+
},
|
|
76
|
+
vLineStyle(i, node) {
|
|
77
|
+
return null;
|
|
78
|
+
},
|
|
79
|
+
paddingLeft(i, node) {
|
|
80
|
+
return 4;
|
|
81
|
+
},
|
|
82
|
+
paddingRight(i, node) {
|
|
83
|
+
return 4;
|
|
84
|
+
},
|
|
85
|
+
paddingTop(i, node) {
|
|
86
|
+
return 2;
|
|
87
|
+
},
|
|
88
|
+
paddingBottom(i, node) {
|
|
89
|
+
return 2;
|
|
90
|
+
},
|
|
91
|
+
fillColor(i, node) {
|
|
92
|
+
return null;
|
|
93
|
+
},
|
|
94
|
+
fillOpacity(i, node) {
|
|
95
|
+
return 1;
|
|
96
|
+
},
|
|
97
|
+
defaultBorder: true
|
|
98
|
+
};
|
package/js/thai.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.DEFAULT_FONT = void 0;
|
|
5
|
+
exports.actualTextRuns = actualTextRuns;
|
|
6
|
+
exports.distributeLine = distributeLine;
|
|
7
|
+
exports.lineBreaks = lineBreaks;
|
|
8
|
+
exports.needsActualText = needsActualText;
|
|
9
|
+
exports.thaiFonts = thaiFonts;
|
|
10
|
+
exports.withThaiDefaults = withThaiDefaults;
|
|
11
|
+
var _linebreak = require("linebreak");
|
|
12
|
+
// w-pdfmaker: Thai support kept in one file so upstream merges only touch short call sites.
|
|
13
|
+
|
|
14
|
+
const THAI = /[-]/;
|
|
15
|
+
const hasSegmenter = typeof Intl !== 'undefined' && typeof Intl.Segmenter === 'function';
|
|
16
|
+
const thaiWords = hasSegmenter ? new Intl.Segmenter('th', {
|
|
17
|
+
granularity: 'word'
|
|
18
|
+
}) : null;
|
|
19
|
+
const graphemes = hasSegmenter ? new Intl.Segmenter('th', {
|
|
20
|
+
granularity: 'grapheme'
|
|
21
|
+
}) : null;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Line break opportunities: UAX #14 from linebreak, plus breaks between Thai words
|
|
25
|
+
* (UAX #14 has no Thai dictionary, so a Thai run would otherwise be one unbreakable word).
|
|
26
|
+
*
|
|
27
|
+
* @param {string} text
|
|
28
|
+
* @returns {Array<{position: number, required: boolean}>}
|
|
29
|
+
*/
|
|
30
|
+
function lineBreaks(text) {
|
|
31
|
+
const breaks = new Map();
|
|
32
|
+
const breaker = new _linebreak.LineBreaker(text);
|
|
33
|
+
let bk;
|
|
34
|
+
while (bk = breaker.nextBreak()) {
|
|
35
|
+
breaks.set(bk.position, bk.required);
|
|
36
|
+
}
|
|
37
|
+
if (thaiWords && THAI.test(text)) {
|
|
38
|
+
for (const {
|
|
39
|
+
index,
|
|
40
|
+
segment
|
|
41
|
+
} of thaiWords.segment(text)) {
|
|
42
|
+
const end = index + segment.length;
|
|
43
|
+
if (end < text.length && THAI.test(text[end - 1]) && THAI.test(text[end]) && !breaks.has(end)) {
|
|
44
|
+
breaks.set(end, false);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return Array.from(breaks, ([position, required]) => ({
|
|
49
|
+
position,
|
|
50
|
+
required
|
|
51
|
+
})).sort((a, b) => a.position - b.position);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* alignment: 'distribute' (like Thai Distributed in Word): spread the free space evenly between
|
|
56
|
+
* grapheme clusters instead of between words. Clusters keep vowels and tone marks on their consonant,
|
|
57
|
+
* which PDF character spacing (Tc) would not.
|
|
58
|
+
*
|
|
59
|
+
* @param {object} line
|
|
60
|
+
* @param {number} availableWidth
|
|
61
|
+
*/
|
|
62
|
+
function distributeLine(line, availableWidth) {
|
|
63
|
+
const extra = availableWidth - line.getWidth();
|
|
64
|
+
// Like justify, a single-inline line (e.g. an ordered list marker "10. ") is not spread.
|
|
65
|
+
if (!graphemes || line.inlines.length < 2 || line.newLineForced || line.lastLineInParagraph || extra <= 0.01) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const pieces = [];
|
|
69
|
+
line.inlines.forEach(inline => {
|
|
70
|
+
const parts = typeof inline.text === 'string' && !inline._pageNodeRef ? Array.from(graphemes.segment(inline.text), g => g.segment) : [];
|
|
71
|
+
if (parts.length <= 1) {
|
|
72
|
+
pieces.push(inline);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const widths = parts.map(part => inline.font.widthOfString(part, inline.fontSize, inline.fontFeatures));
|
|
76
|
+
const total = widths.reduce((a, b) => a + b, 0);
|
|
77
|
+
const scale = total > 0 ? inline.width / total : 0;
|
|
78
|
+
let x = inline.x;
|
|
79
|
+
parts.forEach((part, i) => {
|
|
80
|
+
pieces.push(Object.assign({}, inline, {
|
|
81
|
+
text: part,
|
|
82
|
+
x: x,
|
|
83
|
+
width: widths[i] * scale
|
|
84
|
+
}));
|
|
85
|
+
x += widths[i] * scale;
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// A gap goes before every cluster with width between the first and last visible one:
|
|
90
|
+
// trimmed leading/trailing whitespace and zero-width clusters (e.g. ZWSP) get none.
|
|
91
|
+
const visible = pieces.map(piece => piece.text.trim() !== '');
|
|
92
|
+
const first = visible.indexOf(true);
|
|
93
|
+
const last = visible.lastIndexOf(true);
|
|
94
|
+
const takesGap = i => i > first && i <= last && pieces[i].width > 0;
|
|
95
|
+
const slots = pieces.filter((piece, i) => takesGap(i)).length;
|
|
96
|
+
if (!slots) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
let offset = 0;
|
|
100
|
+
pieces.forEach((piece, i) => {
|
|
101
|
+
const shift = takesGap(i) ? extra / slots : 0;
|
|
102
|
+
offset += shift;
|
|
103
|
+
piece.x += offset;
|
|
104
|
+
if (i > first) {
|
|
105
|
+
piece.justifyShift = shift;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
line.inlines = pieces;
|
|
109
|
+
}
|
|
110
|
+
const DEFAULT_FONT = exports.DEFAULT_FONT = 'THSarabunNew';
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Descriptors of the bundled Thai fonts (fonts/<family>/<family>[-Style].ttf).
|
|
114
|
+
*
|
|
115
|
+
* @param {string} dir path of the fonts folder (Node) or '' for virtual file system keys (browser)
|
|
116
|
+
* @returns {object}
|
|
117
|
+
*/
|
|
118
|
+
function thaiFonts(dir) {
|
|
119
|
+
const family = name => ({
|
|
120
|
+
normal: `${dir}${name}/${name}.ttf`,
|
|
121
|
+
bold: `${dir}${name}/${name}-Bold.ttf`,
|
|
122
|
+
italics: `${dir}${name}/${name}-Italic.ttf`,
|
|
123
|
+
bolditalics: `${dir}${name}/${name}-BoldItalic.ttf`
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
THSarabunNew: family('THSarabunNew'),
|
|
127
|
+
THSarabunIT9: family('THSarabunIT9')
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Thai defaults for the document: the bundled Thai font when no font is picked (pdfmake would use Roboto),
|
|
133
|
+
* skipped when that font is not registered (e.g. setFonts() replaced all fonts), and 16pt for the bundled
|
|
134
|
+
* Thai fonts when no size is set (Thai official documents use 16pt; pdfmake would use 12).
|
|
135
|
+
*
|
|
136
|
+
* @param {object} docDefinition
|
|
137
|
+
* @param {object} fonts registered fonts
|
|
138
|
+
* @returns {object}
|
|
139
|
+
*/
|
|
140
|
+
function withThaiDefaults(docDefinition, fonts) {
|
|
141
|
+
const style = Object.assign({}, docDefinition.defaultStyle);
|
|
142
|
+
if (!style.font && fonts && fonts[DEFAULT_FONT]) {
|
|
143
|
+
style.font = DEFAULT_FONT;
|
|
144
|
+
}
|
|
145
|
+
if (style.fontSize === undefined && (style.font === 'THSarabunNew' || style.font === 'THSarabunIT9')) {
|
|
146
|
+
style.fontSize = 16;
|
|
147
|
+
}
|
|
148
|
+
const defaultStyle = docDefinition.defaultStyle || {};
|
|
149
|
+
if (style.font === defaultStyle.font && style.fontSize === defaultStyle.fontSize) {
|
|
150
|
+
return docDefinition;
|
|
151
|
+
}
|
|
152
|
+
return Object.assign({}, docDefinition, {
|
|
153
|
+
defaultStyle: style
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* fontkit shapes SARA AM (U+0E33) as NIKHAHIT + SARA AA glyphs, so viewers copy and search "ํา".
|
|
159
|
+
* Text containing it gets an ActualText span with the original string.
|
|
160
|
+
*
|
|
161
|
+
* @param {string} text
|
|
162
|
+
* @returns {boolean}
|
|
163
|
+
*/
|
|
164
|
+
function needsActualText(text) {
|
|
165
|
+
return typeof text === 'string' && text.includes('ำ');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Splits text into the grapheme clusters that contain SARA AM and the text between them, so only
|
|
170
|
+
* those clusters get an ActualText span. MuPDF matches ActualText against the glyphs and, at a
|
|
171
|
+
* character with no glyph of its own (ำ), outputs the rest of the ActualText and then the following
|
|
172
|
+
* glyphs again: a span over "จำนวน" copies as "จำนวนนวน", a span over "จำ" copies correctly.
|
|
173
|
+
* Thai shaping does not cross cluster boundaries, so drawing the parts separately looks the same.
|
|
174
|
+
*
|
|
175
|
+
* @param {string} text
|
|
176
|
+
* @returns {Array<{text: string, actual: boolean}>}
|
|
177
|
+
*/
|
|
178
|
+
function actualTextRuns(text) {
|
|
179
|
+
if (!graphemes) {
|
|
180
|
+
return [{
|
|
181
|
+
text,
|
|
182
|
+
actual: true
|
|
183
|
+
}];
|
|
184
|
+
}
|
|
185
|
+
const runs = [];
|
|
186
|
+
for (const {
|
|
187
|
+
segment
|
|
188
|
+
} of graphemes.segment(text)) {
|
|
189
|
+
const actual = segment.includes('ำ');
|
|
190
|
+
const last = runs[runs.length - 1];
|
|
191
|
+
if (last && !last.actual && !actual) {
|
|
192
|
+
last.text += segment;
|
|
193
|
+
} else {
|
|
194
|
+
runs.push({
|
|
195
|
+
text: segment,
|
|
196
|
+
actual
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return runs;
|
|
201
|
+
}
|
package/js/virtual-fs.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = exports.VirtualFileSystem = void 0;
|
|
5
|
+
const normalizeFilename = filename => {
|
|
6
|
+
if (filename.indexOf(__dirname) === 0) {
|
|
7
|
+
filename = filename.substring(__dirname.length);
|
|
8
|
+
}
|
|
9
|
+
if (filename.indexOf('/') === 0) {
|
|
10
|
+
filename = filename.substring(1);
|
|
11
|
+
}
|
|
12
|
+
return filename;
|
|
13
|
+
};
|
|
14
|
+
class VirtualFileSystem {
|
|
15
|
+
constructor(parent = null) {
|
|
16
|
+
this.storage = {};
|
|
17
|
+
this.parent = parent;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {string} filename
|
|
22
|
+
* @returns {boolean}
|
|
23
|
+
*/
|
|
24
|
+
existsSync(filename) {
|
|
25
|
+
if (typeof filename !== 'string') {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
if (this.parent && this.parent.existsSync(filename)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
const normalizedFilename = normalizeFilename(filename);
|
|
32
|
+
return typeof this.storage[normalizedFilename] !== 'undefined';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {string} filename
|
|
37
|
+
* @param {?string|?object} options
|
|
38
|
+
* @returns {string|Buffer}
|
|
39
|
+
*/
|
|
40
|
+
readFileSync(filename, options) {
|
|
41
|
+
if (this.parent && this.parent.existsSync(filename)) {
|
|
42
|
+
return this.parent.readFileSync(filename, options);
|
|
43
|
+
}
|
|
44
|
+
const normalizedFilename = normalizeFilename(filename);
|
|
45
|
+
const encoding = typeof options === 'object' ? options.encoding : options;
|
|
46
|
+
if (!this.existsSync(normalizedFilename)) {
|
|
47
|
+
throw new Error(`File '${normalizedFilename}' not found in virtual file system`);
|
|
48
|
+
}
|
|
49
|
+
const buffer = this.storage[normalizedFilename];
|
|
50
|
+
if (encoding) {
|
|
51
|
+
return buffer.toString(encoding);
|
|
52
|
+
}
|
|
53
|
+
return buffer;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {string} filename
|
|
58
|
+
* @param {string|Buffer} content
|
|
59
|
+
* @param {?string|?object} options
|
|
60
|
+
*/
|
|
61
|
+
writeFileSync(filename, content, options) {
|
|
62
|
+
const normalizedFilename = normalizeFilename(filename);
|
|
63
|
+
const encoding = typeof options === 'object' ? options.encoding : options;
|
|
64
|
+
if (!content && !options) {
|
|
65
|
+
throw new Error('No content');
|
|
66
|
+
}
|
|
67
|
+
this.storage[normalizedFilename] = encoding || typeof content === 'string' ? Buffer.from(content, encoding) : content;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {string} filename
|
|
72
|
+
*/
|
|
73
|
+
unlinkSync(filename) {
|
|
74
|
+
const normalizedFilename = normalizeFilename(filename);
|
|
75
|
+
if (typeof this.storage[normalizedFilename] === 'undefined') {
|
|
76
|
+
throw new Error(`File '${normalizedFilename}' not found in virtual file system`);
|
|
77
|
+
}
|
|
78
|
+
delete this.storage[normalizedFilename];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.VirtualFileSystem = VirtualFileSystem;
|
|
82
|
+
var _default = exports.default = new VirtualFileSystem();
|
package/package.json
CHANGED
|
@@ -1,6 +1,95 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirabyte/w-pdfmaker",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "pdfmake 0.3 fork with built-in Thai support (word breaking, distributed alignment, copyable SARA AM)",
|
|
5
|
+
"main": "js/index.js",
|
|
6
|
+
"esnext": "src/index.js",
|
|
7
|
+
"browser": "build/pdfmake.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"directories": {
|
|
10
|
+
"test": "tests"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@cantoo/pdf-lib": "^2.11.1",
|
|
14
|
+
"@noble/hashes": "^2.4.0",
|
|
15
|
+
"@pdfmake/svg-to-pdfkit": "~0.2.0",
|
|
16
|
+
"@types/node": "*",
|
|
17
|
+
"@types/pdfkit": "*",
|
|
18
|
+
"linebreak": "^2.0.0",
|
|
19
|
+
"pdfkit": "^0.21.0",
|
|
20
|
+
"xmldoc": "^2.0.3"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@babel/cli": "^7.29.7",
|
|
24
|
+
"@babel/core": "^7.29.7",
|
|
25
|
+
"@babel/preset-env": "^7.29.7",
|
|
26
|
+
"@eslint/js": "^10.0.1",
|
|
27
|
+
"babel-loader": "^10.1.1",
|
|
28
|
+
"brfs": "^2.0.2",
|
|
29
|
+
"buffer": "^6.0.3",
|
|
30
|
+
"core-js": "^3.49.0",
|
|
31
|
+
"eslint": "^10.4.1",
|
|
32
|
+
"eslint-plugin-jsdoc": "^62.9.0",
|
|
33
|
+
"expose-loader": "^5.0.1",
|
|
34
|
+
"file-saver": "^2.0.5",
|
|
35
|
+
"globals": "^17.6.0",
|
|
36
|
+
"mocha": "^11.7.6",
|
|
37
|
+
"npm-run-all": "^4.1.5",
|
|
38
|
+
"process": "^0.11.10",
|
|
39
|
+
"rewire": "^9.0.1",
|
|
40
|
+
"shx": "^0.4.0",
|
|
41
|
+
"sinon": "^22.0.0",
|
|
42
|
+
"source-map-loader": "^5.0.0",
|
|
43
|
+
"string-replace-webpack-plugin": "^0.1.3",
|
|
44
|
+
"terser-webpack-plugin": "^5.6.1",
|
|
45
|
+
"typescript": "^5.9.3",
|
|
46
|
+
"webpack": "^5.107.2",
|
|
47
|
+
"webpack-cli": "^7.0.3"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=20.19.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"test": "run-s build mocha lint test:types",
|
|
54
|
+
"build": "run-s build:clean build:node build:browser build:standard-fonts build:fonts build:vfs",
|
|
55
|
+
"build:clean": "shx rm -rf js build",
|
|
56
|
+
"build:node": "babel src --out-dir js",
|
|
57
|
+
"build:browser": "webpack",
|
|
58
|
+
"build:vfs": "node build-vfs.js \"./fonts/Roboto\"",
|
|
59
|
+
"build:examples": "node build-examples.js",
|
|
60
|
+
"build:standard-fonts": "node build-standard-fonts.js",
|
|
61
|
+
"build:fonts": "shx mkdir -p build/fonts && shx mkdir -p build/fonts/Roboto && shx cp -r fonts/Roboto/*.* build/fonts/Roboto && brfs \"./src/browser-extensions/fonts/Roboto.js\" > build/fonts/Roboto.js",
|
|
62
|
+
"lint": "eslint \"./src/**/*.js\" \"./tests/**/*.js\" \"./examples/**/*.js\" \"./standard-fonts/**/*.js\" \"./fonts/**/*.js\"",
|
|
63
|
+
"mocha": "mocha --reporter spec \"./tests/**/*.spec.js\"",
|
|
64
|
+
"test:types": "tsc -p tests/types",
|
|
65
|
+
"playground": "node dev-playground/server.js"
|
|
66
|
+
},
|
|
67
|
+
"repository": {
|
|
68
|
+
"type": "git",
|
|
69
|
+
"url": "git+https://github.com/Wirabyte/w-pdfmaker.git"
|
|
70
|
+
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
73
|
+
},
|
|
74
|
+
"keywords": [
|
|
75
|
+
"pdf",
|
|
76
|
+
"javascript",
|
|
77
|
+
"printing",
|
|
78
|
+
"layout"
|
|
79
|
+
],
|
|
80
|
+
"author": "Wirabyte",
|
|
81
|
+
"license": "MIT",
|
|
82
|
+
"bugs": {
|
|
83
|
+
"url": "https://github.com/Wirabyte/w-pdfmaker/issues"
|
|
84
|
+
},
|
|
85
|
+
"homepage": "https://github.com/Wirabyte/w-pdfmaker",
|
|
86
|
+
"config": {
|
|
87
|
+
"blanket": {
|
|
88
|
+
"pattern": "src",
|
|
89
|
+
"data-cover-never": [
|
|
90
|
+
"node_modules",
|
|
91
|
+
"tests"
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|