pdfmake 0.3.0-beta.7 → 0.3.0-beta.9
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 +12 -0
- package/build/pdfmake.js +74624 -74406
- package/build/pdfmake.js.map +1 -1
- package/build/pdfmake.min.js +2 -2
- package/build/pdfmake.min.js.map +1 -1
- package/js/3rd-party/svg-to-pdfkit.js +1 -1
- package/js/DocMeasure.js +7 -8
- package/js/DocumentContext.js +6 -13
- package/js/ElementWriter.js +1 -1
- package/js/LayoutBuilder.js +53 -3
- package/js/OutputDocumentServer.js +1 -1
- package/js/PDFDocument.js +1 -1
- package/js/PageElementWriter.js +1 -1
- package/js/PageSize.js +1 -1
- package/js/Printer.js +1 -1
- package/js/Renderer.js +1 -1
- package/js/SVGMeasure.js +1 -1
- package/js/StyleContextStack.js +4 -20
- package/js/TableProcessor.js +17 -6
- package/js/TextBreaker.js +1 -1
- package/js/TextInlines.js +1 -1
- package/js/URLResolver.js +1 -1
- package/js/base.js +1 -1
- package/js/browser-extensions/OutputDocumentBrowser.js +1 -1
- package/js/browser-extensions/index.js +1 -1
- package/js/columnCalculator.js +22 -3
- package/js/helpers/variableType.js +12 -0
- package/package.json +1 -1
- package/src/DocMeasure.js +7 -6
- package/src/DocumentContext.js +6 -13
- package/src/LayoutBuilder.js +52 -2
- package/src/StyleContextStack.js +3 -44
- package/src/TableProcessor.js +22 -6
- package/src/columnCalculator.js +24 -3
- package/src/helpers/variableType.js +11 -0
package/src/StyleContextStack.js
CHANGED
|
@@ -79,50 +79,9 @@ class StyleContextStack {
|
|
|
79
79
|
this.push(styleNames[i]);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
'fontFeatures',
|
|
86
|
-
'bold',
|
|
87
|
-
'italics',
|
|
88
|
-
'alignment',
|
|
89
|
-
'color',
|
|
90
|
-
'columnGap',
|
|
91
|
-
'fillColor',
|
|
92
|
-
'fillOpacity',
|
|
93
|
-
'decoration',
|
|
94
|
-
'decorationStyle',
|
|
95
|
-
'decorationColor',
|
|
96
|
-
'background',
|
|
97
|
-
'lineHeight',
|
|
98
|
-
'characterSpacing',
|
|
99
|
-
'noWrap',
|
|
100
|
-
'markerColor',
|
|
101
|
-
'leadingIndent',
|
|
102
|
-
'sup',
|
|
103
|
-
'sub'
|
|
104
|
-
//'tableCellPadding'
|
|
105
|
-
// 'cellBorder',
|
|
106
|
-
// 'headerCellBorder',
|
|
107
|
-
// 'oddRowCellBorder',
|
|
108
|
-
// 'evenRowCellBorder',
|
|
109
|
-
// 'tableBorder'
|
|
110
|
-
];
|
|
111
|
-
let styleOverrideObject = {};
|
|
112
|
-
let pushStyleOverrideObject = false;
|
|
113
|
-
|
|
114
|
-
styleProperties.forEach(key => {
|
|
115
|
-
if (isValue(item[key])) {
|
|
116
|
-
styleOverrideObject[key] = item[key];
|
|
117
|
-
pushStyleOverrideObject = true;
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
if (pushStyleOverrideObject) {
|
|
122
|
-
this.push(styleOverrideObject);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return styleNames.length + (pushStyleOverrideObject ? 1 : 0);
|
|
82
|
+
// rather than spend significant time making a styleOverrideObject, just add item
|
|
83
|
+
this.push(item);
|
|
84
|
+
return styleNames.length + 1;
|
|
126
85
|
}
|
|
127
86
|
|
|
128
87
|
/**
|
package/src/TableProcessor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ColumnCalculator from './columnCalculator';
|
|
2
|
-
import { isNumber } from './helpers/variableType';
|
|
2
|
+
import { isNumber, isPositiveInteger } from './helpers/variableType';
|
|
3
3
|
|
|
4
4
|
class TableProcessor {
|
|
5
5
|
constructor(tableNode) {
|
|
@@ -95,18 +95,34 @@ class TableProcessor {
|
|
|
95
95
|
this.layout = tableNode._layout;
|
|
96
96
|
|
|
97
97
|
availableWidth = writer.context().availableWidth - this.offsets.total;
|
|
98
|
-
ColumnCalculator.buildColumnWidths(tableNode.table.widths, availableWidth);
|
|
98
|
+
ColumnCalculator.buildColumnWidths(tableNode.table.widths, availableWidth, this.offsets.total, tableNode);
|
|
99
99
|
|
|
100
100
|
this.tableWidth = tableNode._offsets.total + getTableInnerContentWidth();
|
|
101
101
|
this.rowSpanData = prepareRowSpanData();
|
|
102
102
|
this.cleanUpRepeatables = false;
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
// headersRows and rowsWithoutPageBreak (headerRows + keepWithHeaderRows)
|
|
105
|
+
this.headerRows = 0;
|
|
106
|
+
this.rowsWithoutPageBreak = 0;
|
|
107
|
+
|
|
108
|
+
const headerRows = tableNode.table.headerRows;
|
|
109
|
+
|
|
110
|
+
if (isPositiveInteger(headerRows)) {
|
|
111
|
+
this.headerRows = headerRows;
|
|
112
|
+
|
|
113
|
+
if (this.headerRows > tableNode.table.body.length) {
|
|
114
|
+
throw new Error(`Too few rows in the table. Property headerRows requires at least ${this.headerRows}, contains only ${tableNode.table.body.length}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this.rowsWithoutPageBreak = this.headerRows;
|
|
118
|
+
|
|
119
|
+
const keepWithHeaderRows = tableNode.table.keepWithHeaderRows;
|
|
120
|
+
|
|
121
|
+
if (isPositiveInteger(keepWithHeaderRows)) {
|
|
122
|
+
this.rowsWithoutPageBreak += keepWithHeaderRows;
|
|
123
|
+
}
|
|
107
124
|
}
|
|
108
125
|
|
|
109
|
-
this.rowsWithoutPageBreak = this.headerRows + (tableNode.table.keepWithHeaderRows || 0);
|
|
110
126
|
this.dontBreakRows = tableNode.table.dontBreakRows || false;
|
|
111
127
|
|
|
112
128
|
if (this.rowsWithoutPageBreak) {
|
package/src/columnCalculator.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isString } from './helpers/variableType';
|
|
2
2
|
|
|
3
|
-
function buildColumnWidths(columns, availableWidth) {
|
|
3
|
+
function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode) {
|
|
4
4
|
let autoColumns = [];
|
|
5
5
|
let autoMin = 0;
|
|
6
6
|
let autoMax = 0;
|
|
@@ -24,10 +24,31 @@ function buildColumnWidths(columns, availableWidth) {
|
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
fixedColumns.forEach(col => {
|
|
27
|
+
fixedColumns.forEach((col, colIndex) => {
|
|
28
28
|
// width specified as %
|
|
29
29
|
if (isString(col.width) && /\d+%/.test(col.width)) {
|
|
30
|
-
|
|
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;
|
|
31
52
|
}
|
|
32
53
|
if (col.width < (col._minWidth) && col.elasticWidth) {
|
|
33
54
|
col._calcWidth = col._minWidth;
|
|
@@ -14,6 +14,17 @@ export function isNumber(variable) {
|
|
|
14
14
|
return (typeof variable === 'number') || (variable instanceof Number);
|
|
15
15
|
}
|
|
16
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
|
+
|
|
17
28
|
/**
|
|
18
29
|
* @param {any} variable
|
|
19
30
|
* @returns {boolean}
|