abstract-document 18.0.5 → 18.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/CHANGELOG.md +22 -0
- package/lib/abstract-document/primitives/layout-foundation-color.d.ts +2 -7
- package/lib/abstract-document/primitives/layout-foundation-color.d.ts.map +1 -1
- package/lib/abstract-document/primitives/layout-foundation-color.js +18 -11
- package/lib/abstract-document/primitives/layout-foundation-color.js.map +1 -1
- package/lib/abstract-document/primitives/layout-foundation.d.ts +2 -7
- package/lib/abstract-document/primitives/layout-foundation.d.ts.map +1 -1
- package/lib/abstract-document/primitives/layout-foundation.js +20 -13
- package/lib/abstract-document/primitives/layout-foundation.js.map +1 -1
- package/lib/abstract-document/styles/table-cell-style.js +5 -3
- package/lib/abstract-document/styles/table-cell-style.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render.js +20 -17
- package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.js +21 -11
- package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.d.ts +2 -2
- package/lib/abstract-document-exporters/pdf/paginate.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.js +13 -12
- package/lib/abstract-document-exporters/pdf/paginate.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.js +14 -11
- package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js +26 -5
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js +97 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js.map +1 -1
- package/lib/abstract-document-xml/xsd-template/styles.d.ts +9 -5
- package/lib/abstract-document-xml/xsd-template/styles.d.ts.map +1 -1
- package/lib/abstract-document-xml/xsd-template/styles.js +34 -0
- package/lib/abstract-document-xml/xsd-template/styles.js.map +1 -1
- package/lib/abstract-document-xml/xsd-template/xsd-template.d.ts +2 -2
- package/lib/abstract-document-xml/xsd-template/xsd-template.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/abstract-document/primitives/layout-foundation-color.ts +20 -19
- package/src/abstract-document/primitives/layout-foundation.ts +22 -21
- package/src/abstract-document/styles/table-cell-style.ts +3 -3
- package/src/abstract-document-exporters/docx2/render.ts +20 -17
- package/src/abstract-document-exporters/pdf/measure.ts +23 -11
- package/src/abstract-document-exporters/pdf/paginate.ts +15 -14
- package/src/abstract-document-exporters/pdf/render.ts +14 -11
- package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +29 -5
- package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +97 -1
- package/src/abstract-document-xml/xsd-template/styles.ts +39 -1
|
@@ -72,9 +72,10 @@ function createDocument(doc: AD.AbstractDoc.AbstractDoc): Document {
|
|
|
72
72
|
function renderSection(section: AD.Section.Section, parentResources: AD.Resources.Resources): ISectionOptions {
|
|
73
73
|
const pageWidth = AD.PageStyle.getWidth(section.page.style);
|
|
74
74
|
const pageHeight = AD.PageStyle.getHeight(section.page.style);
|
|
75
|
+
const pageContentMargins = AD.LayoutFoundation.orDefault(section.page.style.contentMargins);
|
|
75
76
|
|
|
76
77
|
const contentAvailableWidth =
|
|
77
|
-
pageWidth - (
|
|
78
|
+
pageWidth - (pageContentMargins.left + pageContentMargins.right);
|
|
78
79
|
|
|
79
80
|
const resources = AD.Resources.mergeResources([parentResources, section]);
|
|
80
81
|
|
|
@@ -117,12 +118,12 @@ function renderSection(section: AD.Section.Section, parentResources: AD.Resource
|
|
|
117
118
|
section.page.style.orientation === "Landscape" ? PageOrientation.LANDSCAPE : PageOrientation.PORTRAIT,
|
|
118
119
|
},
|
|
119
120
|
margin: {
|
|
120
|
-
bottom:
|
|
121
|
-
top:
|
|
122
|
-
right:
|
|
123
|
-
left:
|
|
124
|
-
header:
|
|
125
|
-
footer:
|
|
121
|
+
bottom: pageContentMargins.bottom * abstractDocPixelToDocxDXARatio,
|
|
122
|
+
top: pageContentMargins.top * abstractDocPixelToDocxDXARatio,
|
|
123
|
+
right: pageContentMargins.right * abstractDocPixelToDocxDXARatio,
|
|
124
|
+
left: pageContentMargins.left * abstractDocPixelToDocxDXARatio,
|
|
125
|
+
header: pageContentMargins.top * abstractDocPixelToDocxDXARatio,
|
|
126
|
+
footer: pageContentMargins.bottom * abstractDocPixelToDocxDXARatio,
|
|
126
127
|
},
|
|
127
128
|
},
|
|
128
129
|
},
|
|
@@ -214,6 +215,7 @@ function renderTable(
|
|
|
214
215
|
table.styleName,
|
|
215
216
|
resources
|
|
216
217
|
) as AD.TableStyle.TableStyle;
|
|
218
|
+
const styleMargins = AD.LayoutFoundation.orDefault(style.margins);
|
|
217
219
|
|
|
218
220
|
if (table.children.length === 0) {
|
|
219
221
|
return undefined;
|
|
@@ -237,10 +239,10 @@ function renderTable(
|
|
|
237
239
|
? AlignmentType.RIGHT
|
|
238
240
|
: AlignmentType.CENTER,
|
|
239
241
|
margins: {
|
|
240
|
-
top:
|
|
241
|
-
bottom:
|
|
242
|
-
left:
|
|
243
|
-
right:
|
|
242
|
+
top: styleMargins.top * abstractDocPixelToDocxDXARatio,
|
|
243
|
+
bottom: styleMargins.bottom * abstractDocPixelToDocxDXARatio,
|
|
244
|
+
left: styleMargins.left * abstractDocPixelToDocxDXARatio,
|
|
245
|
+
right: styleMargins.right * abstractDocPixelToDocxDXARatio,
|
|
244
246
|
},
|
|
245
247
|
width: {
|
|
246
248
|
type: WidthType.DXA,
|
|
@@ -310,8 +312,8 @@ function renderCell(
|
|
|
310
312
|
resources
|
|
311
313
|
) as AD.TableCellStyle.TableCellStyle;
|
|
312
314
|
|
|
313
|
-
const stylePadding =
|
|
314
|
-
const styleBorders =
|
|
315
|
+
const stylePadding = AD.LayoutFoundation.orDefault(style.padding);
|
|
316
|
+
const styleBorders = AD.LayoutFoundation.orDefault(style.borders);
|
|
315
317
|
|
|
316
318
|
return new TableCell({
|
|
317
319
|
verticalAlign:
|
|
@@ -522,6 +524,7 @@ function renderParagraph(
|
|
|
522
524
|
paragraph.styleName,
|
|
523
525
|
resources
|
|
524
526
|
) as AD.ParagraphStyle.ParagraphStyle;
|
|
527
|
+
const styleMargins = AD.LayoutFoundation.orDefault(style.margins);
|
|
525
528
|
|
|
526
529
|
return new Paragraph({
|
|
527
530
|
keepNext: keepNext,
|
|
@@ -535,12 +538,12 @@ function renderParagraph(
|
|
|
535
538
|
undefined,
|
|
536
539
|
|
|
537
540
|
spacing: {
|
|
538
|
-
before: Math.max(
|
|
539
|
-
after: Math.max(
|
|
541
|
+
before: Math.max(styleMargins.top, 0) * abstractDocPixelToDocxDXARatio,
|
|
542
|
+
after: Math.max(styleMargins.bottom, 0) * abstractDocPixelToDocxDXARatio,
|
|
540
543
|
},
|
|
541
544
|
indent: {
|
|
542
|
-
left: Math.max(
|
|
543
|
-
right: Math.max(
|
|
545
|
+
left: Math.max(styleMargins.left, 0) * abstractDocPixelToDocxDXARatio,
|
|
546
|
+
right: Math.max(styleMargins.right, 0) * abstractDocPixelToDocxDXARatio,
|
|
544
547
|
},
|
|
545
548
|
children: paragraph.children.map((atom) => renderAtom(resources, style.textStyle, atom)),
|
|
546
549
|
});
|
|
@@ -49,8 +49,10 @@ function measureSection(
|
|
|
49
49
|
const pageHeight = AD.PageStyle.getHeight(section.page.style);
|
|
50
50
|
const resources = AD.Resources.mergeResources([section, parentResources]);
|
|
51
51
|
|
|
52
|
+
const pageContentMargins = AD.LayoutFoundation.orDefault(section.page.style.contentMargins);
|
|
53
|
+
|
|
52
54
|
const totalContentAvailableWidth =
|
|
53
|
-
pageWidth - (
|
|
55
|
+
pageWidth - (pageContentMargins.left + pageContentMargins.right);
|
|
54
56
|
const contentAvailableWidth =
|
|
55
57
|
totalContentAvailableWidth / section.page.style.columnLayout.columnCount -
|
|
56
58
|
section.page.style.columnLayout.columnGap * (section.page.style.columnLayout.columnCount - 1);
|
|
@@ -58,12 +60,12 @@ function measureSection(
|
|
|
58
60
|
const sectionSizes = children.map((e) => measureSectionElement(pdfKit, resources, contentAvailableSize, e));
|
|
59
61
|
|
|
60
62
|
const headerAvailableWidth =
|
|
61
|
-
pageWidth - (
|
|
63
|
+
pageWidth - (pageContentMargins.left + pageContentMargins.right);
|
|
62
64
|
const headerAvailableSize = AD.Size.create(headerAvailableWidth, pageHeight);
|
|
63
65
|
const headerSizes = header.map((e) => measureSectionElement(pdfKit, resources, headerAvailableSize, e));
|
|
64
66
|
|
|
65
67
|
const footerAvailableWidth =
|
|
66
|
-
pageWidth - (
|
|
68
|
+
pageWidth - (pageContentMargins.left + pageContentMargins.right);
|
|
67
69
|
const footerAvailableSize = AD.Size.create(footerAvailableWidth, pageHeight);
|
|
68
70
|
const footerSizes = footer.map((e) => measureSectionElement(pdfKit, resources, footerAvailableSize, e));
|
|
69
71
|
|
|
@@ -76,7 +78,8 @@ function measureSection(
|
|
|
76
78
|
[firstPageHeaderAndFooters.footer, firstPageHeaderAndFooters.footerMargins],
|
|
77
79
|
];
|
|
78
80
|
const firstPageHeaderAndFooterSizes = firstPageHeaderAndFootersExtracted.reduce((prev, [sections, margins]) => {
|
|
79
|
-
const
|
|
81
|
+
const defMargins = AD.LayoutFoundation.orDefault(margins);
|
|
82
|
+
const availabelWidth = pageWidth - (defMargins.left + defMargins.right);
|
|
80
83
|
const availableSizes = AD.Size.create(availabelWidth, pageHeight);
|
|
81
84
|
return [...prev, ...sections.map((e) => measureSectionElement(pdfKit, resources, availableSizes, e))];
|
|
82
85
|
}, []);
|
|
@@ -124,11 +127,12 @@ function measureParagraph(
|
|
|
124
127
|
paragraph.styleName,
|
|
125
128
|
resources
|
|
126
129
|
) as AD.ParagraphStyle.ParagraphStyle;
|
|
127
|
-
const
|
|
128
|
-
const
|
|
130
|
+
const styleMargins = AD.LayoutFoundation.orDefault(style.margins);
|
|
131
|
+
const contentAvailableWidth = availableSize.width - (styleMargins.left + styleMargins.right);
|
|
132
|
+
const contentAvailableHeight = availableSize.height - (styleMargins.top + styleMargins.bottom);
|
|
129
133
|
const contentAvailableSize = AD.Size.create(contentAvailableWidth, contentAvailableHeight);
|
|
130
134
|
|
|
131
|
-
let paragraphHeight =
|
|
135
|
+
let paragraphHeight = styleMargins.top + styleMargins.bottom;
|
|
132
136
|
let desiredSizes = new Map<any, AD.Size.Size>();
|
|
133
137
|
|
|
134
138
|
const rows: Array<Array<AD.Atom.Atom>> = [];
|
|
@@ -243,7 +247,8 @@ export function measureTable(
|
|
|
243
247
|
table.styleName,
|
|
244
248
|
resources
|
|
245
249
|
) as AD.TableStyle.TableStyle;
|
|
246
|
-
const
|
|
250
|
+
const styleMargins = AD.LayoutFoundation.orDefault(style.margins);
|
|
251
|
+
const tableAvailableWidth = availableSize.width - (styleMargins.left + styleMargins.right);
|
|
247
252
|
const numInfinityColumns = table.columnWidths.filter((w) => !isFinite(w)).length;
|
|
248
253
|
const fixedColumnsWidth = table.columnWidths.filter((w) => isFinite(w)).reduce((a, b) => a + b, 0);
|
|
249
254
|
const infinityWidth = (tableAvailableWidth - fixedColumnsWidth) / numInfinityColumns;
|
|
@@ -261,8 +266,15 @@ export function measureTable(
|
|
|
261
266
|
resources
|
|
262
267
|
) as AD.TableCellStyle.TableCellStyle;
|
|
263
268
|
const cellWidth = columnWidths.slice(column, column + cell.columnSpan).reduce((a, b) => a + b, 0);
|
|
264
|
-
const
|
|
269
|
+
//const cellStylePadding2 = cellStyle.padding ?? AD.LayoutFoundation.create();
|
|
265
270
|
|
|
271
|
+
const cellStylePadding = {
|
|
272
|
+
top: cellStyle.padding?.top ?? 0,
|
|
273
|
+
bottom: cellStyle.padding?.bottom ?? 0,
|
|
274
|
+
left: cellStyle.padding?.left ?? 0,
|
|
275
|
+
right: cellStyle.padding?.right ?? 0,
|
|
276
|
+
};
|
|
277
|
+
|
|
266
278
|
const contentAvailableWidth = cellWidth - (cellStylePadding.left + cellStylePadding.right);
|
|
267
279
|
let cellDesiredHeight = cellStylePadding.top + cellStylePadding.bottom;
|
|
268
280
|
|
|
@@ -311,8 +323,8 @@ export function measureTable(
|
|
|
311
323
|
|
|
312
324
|
const desiredWidth = table.columnWidths.some((w) => !isFinite(w))
|
|
313
325
|
? availableSize.width
|
|
314
|
-
: table.columnWidths.reduce((a, b) => a + b,
|
|
315
|
-
let desiredHeight =
|
|
326
|
+
: table.columnWidths.reduce((a, b) => a + b, styleMargins.left + styleMargins.right);
|
|
327
|
+
let desiredHeight = styleMargins.top + styleMargins.bottom;
|
|
316
328
|
for (let i = 0; i < rows.length; i++) {
|
|
317
329
|
const row = rows[i];
|
|
318
330
|
const rowHeight = minRowHeights[i];
|
|
@@ -266,8 +266,8 @@ export function getHeaderAndFooter(
|
|
|
266
266
|
): {
|
|
267
267
|
readonly header: Array<AD.SectionElement.SectionElement>;
|
|
268
268
|
readonly footer: Array<AD.SectionElement.SectionElement>;
|
|
269
|
-
readonly headerMargins: AD.LayoutFoundation.LayoutFoundation
|
|
270
|
-
readonly footerMargins: AD.LayoutFoundation.LayoutFoundation
|
|
269
|
+
readonly headerMargins: Required<AD.LayoutFoundation.LayoutFoundation>;
|
|
270
|
+
readonly footerMargins: Required<AD.LayoutFoundation.LayoutFoundation>;
|
|
271
271
|
} {
|
|
272
272
|
const FIRST_PAGE = 1;
|
|
273
273
|
const EVEN_PAGE = 0;
|
|
@@ -280,12 +280,12 @@ export function getHeaderAndFooter(
|
|
|
280
280
|
return {
|
|
281
281
|
footer: normalFooter ? section.page.footer : section.page.frontFooter,
|
|
282
282
|
header: normalHeader ? section.page.header : section.page.frontHeader,
|
|
283
|
-
headerMargins: normalHeader
|
|
283
|
+
headerMargins: AD.LayoutFoundation.orDefault(normalHeader
|
|
284
284
|
? section.page.style.headerMargins
|
|
285
|
-
: section.page.style.firstPageHeaderMargins ?? section.page.style.headerMargins,
|
|
286
|
-
footerMargins: normalFooter
|
|
285
|
+
: section.page.style.firstPageHeaderMargins ?? section.page.style.headerMargins),
|
|
286
|
+
footerMargins: AD.LayoutFoundation.orDefault(normalFooter
|
|
287
287
|
? section.page.style.footerMargins
|
|
288
|
-
: section.page.style.firstPageFooterMargins ?? section.page.style.footerMargins,
|
|
288
|
+
: section.page.style.firstPageFooterMargins ?? section.page.style.footerMargins),
|
|
289
289
|
};
|
|
290
290
|
}
|
|
291
291
|
case pageNo === 0:
|
|
@@ -295,8 +295,8 @@ export function getHeaderAndFooter(
|
|
|
295
295
|
return {
|
|
296
296
|
header: section.page.header,
|
|
297
297
|
footer: section.page.footer,
|
|
298
|
-
headerMargins: section.page.style.headerMargins,
|
|
299
|
-
footerMargins: section.page.style.footerMargins,
|
|
298
|
+
headerMargins: AD.LayoutFoundation.orDefault(section.page.style.headerMargins),
|
|
299
|
+
footerMargins: AD.LayoutFoundation.orDefault(section.page.style.footerMargins),
|
|
300
300
|
};
|
|
301
301
|
}
|
|
302
302
|
}
|
|
@@ -308,6 +308,7 @@ function getPageContentRect(
|
|
|
308
308
|
pageNo: number
|
|
309
309
|
): AD.Rect.Rect {
|
|
310
310
|
const style = section.page.style;
|
|
311
|
+
const styleContentMargins = AD.LayoutFoundation.orDefault(style.contentMargins);
|
|
311
312
|
const pageWidth = AD.PageStyle.getWidth(style);
|
|
312
313
|
const pageHeight = AD.PageStyle.getHeight(style);
|
|
313
314
|
|
|
@@ -328,10 +329,10 @@ function getPageContentRect(
|
|
|
328
329
|
}
|
|
329
330
|
headerY += headerMargins.bottom;
|
|
330
331
|
|
|
331
|
-
const rectX =
|
|
332
|
-
const rectY = headerY +
|
|
333
|
-
const rectWidth = pageWidth - (
|
|
334
|
-
const rectHeight = pageHeight - headerHeight - footerHeight -
|
|
332
|
+
const rectX = styleContentMargins.left;
|
|
333
|
+
const rectY = headerY + styleContentMargins.top;
|
|
334
|
+
const rectWidth = pageWidth - (styleContentMargins.left + styleContentMargins.right);
|
|
335
|
+
const rectHeight = pageHeight - headerHeight - footerHeight - styleContentMargins.top - styleContentMargins.bottom;
|
|
335
336
|
return AD.Rect.create(rectX, rectY, rectWidth, rectHeight);
|
|
336
337
|
}
|
|
337
338
|
|
|
@@ -343,11 +344,11 @@ function getLeadingAndTrailingSpace(
|
|
|
343
344
|
const { noTopBottomMargin } = section.page.style;
|
|
344
345
|
|
|
345
346
|
const first = elements[0];
|
|
346
|
-
const firstMargins = first && getSectionElementMargin(resources, first);
|
|
347
|
+
const firstMargins = first && AD.LayoutFoundation.orDefault(getSectionElementMargin(resources, first));
|
|
347
348
|
const leadingSpace = firstMargins && noTopBottomMargin ? firstMargins.top : 0;
|
|
348
349
|
|
|
349
350
|
const last = elements.length > 0 ? elements[elements.length - 1] : undefined;
|
|
350
|
-
const lastMargins = last && getSectionElementMargin(resources, last);
|
|
351
|
+
const lastMargins = last && AD.LayoutFoundation.orDefault(getSectionElementMargin(resources, last));
|
|
351
352
|
const trailingSpace = lastMargins && noTopBottomMargin ? lastMargins.bottom : 0;
|
|
352
353
|
|
|
353
354
|
return [leadingSpace, trailingSpace];
|
|
@@ -190,8 +190,9 @@ function renderGroup(
|
|
|
190
190
|
finalRect: AD.Rect.Rect,
|
|
191
191
|
group: AD.Group.Group
|
|
192
192
|
): void {
|
|
193
|
-
const
|
|
194
|
-
const
|
|
193
|
+
const styleMargins = AD.LayoutFoundation.orDefault(group.style.margins);
|
|
194
|
+
const finalX = finalRect.x + styleMargins.left;
|
|
195
|
+
const startY = finalRect.y + styleMargins.top;
|
|
195
196
|
let y = startY;
|
|
196
197
|
for (const element of group.children) {
|
|
197
198
|
const elementSize = getDesiredSize(element, desiredSizes);
|
|
@@ -223,7 +224,8 @@ function renderParagraph(
|
|
|
223
224
|
paragraph.styleName,
|
|
224
225
|
resources
|
|
225
226
|
) as AD.ParagraphStyle.ParagraphStyle;
|
|
226
|
-
const
|
|
227
|
+
const styleMargins = AD.LayoutFoundation.orDefault(style.margins);
|
|
228
|
+
const availableWidth = finalRect.width - (styleMargins.left + styleMargins.right);
|
|
227
229
|
|
|
228
230
|
let rows: Array<Array<AD.Atom.Atom>> = [];
|
|
229
231
|
let currentRow: Array<AD.Atom.Atom> = [];
|
|
@@ -286,7 +288,7 @@ function renderParagraph(
|
|
|
286
288
|
rows.push(currentRow);
|
|
287
289
|
}
|
|
288
290
|
|
|
289
|
-
let y = finalRect.y +
|
|
291
|
+
let y = finalRect.y + styleMargins.top;
|
|
290
292
|
const alignment = parseAlignment(style.alignment);
|
|
291
293
|
const newRows = rowsSplit(rows, availableWidth, desiredSizes, alignment);
|
|
292
294
|
const { newDesiredSizes, combinedRows } = rowsCombineTextRuns(
|
|
@@ -310,12 +312,12 @@ function renderParagraph(
|
|
|
310
312
|
let x = finalRect.x;
|
|
311
313
|
|
|
312
314
|
if (style.alignment === "Start" || style.alignment === "Justify") {
|
|
313
|
-
x +=
|
|
315
|
+
x += styleMargins.left;
|
|
314
316
|
} else if (style.alignment === "End") {
|
|
315
|
-
x -=
|
|
317
|
+
x -= styleMargins.right;
|
|
316
318
|
}
|
|
317
319
|
|
|
318
|
-
if (row.length > 1 || row[0].type === "Image" || row[0].type === "TextRun") {
|
|
320
|
+
if (row.length > 1 || row[0].type === "Image" || row[0].type === "TextRun" || row[0].type === "TextField") {
|
|
319
321
|
// Using continued with alignment "center" or "right" is broken:
|
|
320
322
|
// https://github.com/foliojs/pdfkit/issues/240
|
|
321
323
|
// Therefore we have to position it ourself
|
|
@@ -737,12 +739,13 @@ function renderTable(
|
|
|
737
739
|
table.styleName,
|
|
738
740
|
resources
|
|
739
741
|
) as AD.TableStyle.TableStyle;
|
|
742
|
+
const styleMargins = AD.LayoutFoundation.orDefault(style.margins);
|
|
740
743
|
const availableWidth = finalRect.width;
|
|
741
|
-
let y = finalRect.y +
|
|
744
|
+
let y = finalRect.y + styleMargins.top;
|
|
742
745
|
const rows = [...table.headerRows, ...table.children];
|
|
743
746
|
for (let [index, row] of rows.entries()) {
|
|
744
747
|
const rowSize = getDesiredSize(row, desiredSizes);
|
|
745
|
-
let x = finalRect.x +
|
|
748
|
+
let x = finalRect.x + styleMargins.left;
|
|
746
749
|
if (style.alignment === "Center") x += 0.5 * (availableWidth - rowSize.width);
|
|
747
750
|
else if (style.alignment === "Right") x += availableWidth - rowSize.width;
|
|
748
751
|
const rowRect = AD.Rect.create(x, y, rowSize.width, rowSize.height);
|
|
@@ -812,8 +815,8 @@ function renderCell(
|
|
|
812
815
|
pdf.rect(finalRect.x, finalRect.y, finalRect.width, finalRect.height).fill(style.background);
|
|
813
816
|
}
|
|
814
817
|
|
|
815
|
-
const borders = style.borders
|
|
816
|
-
const padding = style.padding
|
|
818
|
+
const borders = AD.LayoutFoundation.orDefault(style.borders);
|
|
819
|
+
const padding = AD.LayoutFoundation.orDefault(style.padding);
|
|
817
820
|
|
|
818
821
|
let x = finalRect.x + padding.left;
|
|
819
822
|
const availableHeight = finalRect.height;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { addResources, merge } from "../../abstract-document/abstract-doc.js";
|
|
2
2
|
import { AbstractDoc } from "../../abstract-document/index.js";
|
|
3
|
+
import * as StyleKey from "../../abstract-document/styles/style-key.js";
|
|
3
4
|
import { Resources } from "../../abstract-document/resources.js";
|
|
4
5
|
import { ADCreatorFn, creators, propsCreators } from "./creator.js";
|
|
5
6
|
import { parseHandlebarsXml, parseMustacheXml, type XmlElement } from "handlebars-xml";
|
|
@@ -47,7 +48,8 @@ export function abstractDocXml(
|
|
|
47
48
|
const xml =
|
|
48
49
|
rendered === "Mustache" ? parseMustacheXml(template, data, partials) : parseHandlebarsXml(template, data, partials);
|
|
49
50
|
const [imageUrls, fontFamilies, styleNames] = extractImageFontsStyleNames(xml);
|
|
50
|
-
|
|
51
|
+
const doc = abstractDocXmlRecursive(creators(styleNames), xml[0]!);
|
|
52
|
+
return [doc, imageUrls, fontFamilies];
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
function abstractDocXmlRecursive(
|
|
@@ -63,7 +65,7 @@ function abstractDocXmlRecursive(
|
|
|
63
65
|
if (childName === "StyleNames") {
|
|
64
66
|
props.styles = abstractDocXmlRecursive(creators, childElement);
|
|
65
67
|
} else if (childName === "StyleName" && childElement.attributes && childElement.attributes.name) {
|
|
66
|
-
const styleName = childElement.attributes.name;
|
|
68
|
+
const styleName = StyleKey.create(childElement.attributes.type, childElement.attributes.name);
|
|
67
69
|
const style = abstractDocXmlRecursive(creators, childElement);
|
|
68
70
|
props[styleName] = style;
|
|
69
71
|
} else if (childName.startsWith(childName.charAt(0).toUpperCase())) {
|
|
@@ -98,10 +100,11 @@ function abstractDocXmlRecursive(
|
|
|
98
100
|
//
|
|
99
101
|
const obj = creator(allProps, children) as { [k: string]: unknown };
|
|
100
102
|
|
|
101
|
-
for (const propName of Object.keys(allProps)) {
|
|
102
|
-
const propsCreator = allProps[propName] && propsCreators[propName] ? propsCreators[propName] : undefined;
|
|
103
|
+
for (const propName of Object.keys(allProps).sort((a, b) => a.length - b.length)) {
|
|
104
|
+
const propsCreator = allProps[propName] !== undefined && propsCreators[propName] ? propsCreators[propName] : undefined;
|
|
103
105
|
if (propsCreator) {
|
|
104
|
-
|
|
106
|
+
const attributeName = getSuffixedAttributeBaseName(propsCreator.name) ?? propsCreator.name;
|
|
107
|
+
obj[attributeName] = propsCreator(allProps, children);
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
110
|
|
|
@@ -148,6 +151,27 @@ function abstractDocXmlRecursive(
|
|
|
148
151
|
return obj;
|
|
149
152
|
}
|
|
150
153
|
|
|
154
|
+
function getSuffixedAttributeBaseName(attributeName: string): string | undefined {
|
|
155
|
+
const suffixRemoved = (() => {
|
|
156
|
+
const suffixes = ["Top", "Bottom", "Left", "Right"];
|
|
157
|
+
for(const suffix of suffixes) {
|
|
158
|
+
if(attributeName.endsWith(suffix)) {
|
|
159
|
+
return attributeName.slice(0, -suffix.length);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return undefined;
|
|
163
|
+
})();
|
|
164
|
+
|
|
165
|
+
const actualLookup: Record<string, string> = {
|
|
166
|
+
border: "borders",
|
|
167
|
+
margin: "margins",
|
|
168
|
+
padding: "padding",
|
|
169
|
+
borderColor: "borderColors",
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return actualLookup[suffixRemoved ?? ""];
|
|
173
|
+
}
|
|
174
|
+
|
|
151
175
|
function extractImageFontsStyleNames(
|
|
152
176
|
xmlElement: ReadonlyArray<XmlElement>,
|
|
153
177
|
styleNames: Record<string, string> = {},
|
|
@@ -70,7 +70,7 @@ export const propsCreators: Record<string, ADCreatorFn> = {
|
|
|
70
70
|
const fixedStyles: Record<string, Record<string, string | number>> = {};
|
|
71
71
|
if (props.styles) {
|
|
72
72
|
Object.keys(props.styles).forEach((key: string) => {
|
|
73
|
-
fixedStyles[
|
|
73
|
+
fixedStyles[key] = { ...props.styles[key] };
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -137,6 +137,30 @@ export const propsCreators: Record<string, ADCreatorFn> = {
|
|
|
137
137
|
});
|
|
138
138
|
return borders;
|
|
139
139
|
},
|
|
140
|
+
borderTop: (props: { readonly borderTop: string }): unknown => {
|
|
141
|
+
const allProps = props as Record<string, unknown>;
|
|
142
|
+
const borders: { top?: number, bottom?: number, left?: number, right?: number } = allProps.borders ?? {};
|
|
143
|
+
borders.top = Number(props.borderTop);
|
|
144
|
+
return borders;
|
|
145
|
+
},
|
|
146
|
+
borderBottom: (props: { readonly borderBottom: string }): unknown => {
|
|
147
|
+
const allProps = props as Record<string, unknown>;
|
|
148
|
+
const borders: { top?: number, bottom?: number, left?: number, right?: number } = allProps.borders ?? {};
|
|
149
|
+
borders.bottom = Number(props.borderBottom);
|
|
150
|
+
return borders;
|
|
151
|
+
},
|
|
152
|
+
borderLeft: (props: { readonly borderLeft: string }): unknown => {
|
|
153
|
+
const allProps = props as Record<string, unknown>;
|
|
154
|
+
const borders: { top?: number, bottom?: number, left?: number, right?: number } = allProps.borders ?? {};
|
|
155
|
+
borders.left = Number(props.borderLeft);
|
|
156
|
+
return borders;
|
|
157
|
+
},
|
|
158
|
+
borderRight: (props: { readonly borderRight: string }): unknown => {
|
|
159
|
+
const allProps = props as Record<string, unknown>;
|
|
160
|
+
const borders: { top?: number, bottom?: number, left?: number, right?: number } = allProps.borders ?? {};
|
|
161
|
+
borders.right = Number(props.borderRight);
|
|
162
|
+
return borders;
|
|
163
|
+
},
|
|
140
164
|
padding: (props: { readonly padding: string }): unknown => {
|
|
141
165
|
const padding: { [k: string]: number } = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
142
166
|
|
|
@@ -179,6 +203,30 @@ export const propsCreators: Record<string, ADCreatorFn> = {
|
|
|
179
203
|
});
|
|
180
204
|
return padding;
|
|
181
205
|
},
|
|
206
|
+
paddingTop: (props: { readonly paddingTop: string }): unknown => {
|
|
207
|
+
const allProps = props as Record<string, unknown>;
|
|
208
|
+
const padding: { top?: number, bottom?: number, left?: number, right?: number } = allProps.padding ?? {};
|
|
209
|
+
padding.top = Number(props.paddingTop);
|
|
210
|
+
return padding;
|
|
211
|
+
},
|
|
212
|
+
paddingBottom: (props: { readonly paddingBottom: string }): unknown => {
|
|
213
|
+
const allProps = props as Record<string, unknown>;
|
|
214
|
+
const padding: { top?: number, bottom?: number, left?: number, right?: number } = allProps.padding ?? {};
|
|
215
|
+
padding.bottom = Number(props.paddingBottom);
|
|
216
|
+
return padding;
|
|
217
|
+
},
|
|
218
|
+
paddingLeft: (props: { readonly paddingLeft: string }): unknown => {
|
|
219
|
+
const allProps = props as Record<string, unknown>;
|
|
220
|
+
const padding: { top?: number, bottom?: number, left?: number, right?: number } = allProps.padding ?? {};
|
|
221
|
+
padding.left = Number(props.paddingLeft);
|
|
222
|
+
return padding;
|
|
223
|
+
},
|
|
224
|
+
paddingRight: (props: { readonly paddingRight: string }): unknown => {
|
|
225
|
+
const allProps = props as Record<string, unknown>;
|
|
226
|
+
const padding: { top?: number, bottom?: number, left?: number, right?: number } = allProps.padding ?? {};
|
|
227
|
+
padding.right = Number(props.paddingRight);
|
|
228
|
+
return padding;
|
|
229
|
+
},
|
|
182
230
|
margins: (props: { readonly margins: string }): unknown => {
|
|
183
231
|
const margins: { [k: string]: number } = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
184
232
|
const propMargins = props.margins.toString().split(" ");
|
|
@@ -219,6 +267,30 @@ export const propsCreators: Record<string, ADCreatorFn> = {
|
|
|
219
267
|
});
|
|
220
268
|
return margins;
|
|
221
269
|
},
|
|
270
|
+
marginTop: (props: { readonly marginTop: string }): unknown => {
|
|
271
|
+
const allProps = props as Record<string, unknown>;
|
|
272
|
+
const margins: { top?: number, bottom?: number, left?: number, right?: number } = allProps.margins ?? {};
|
|
273
|
+
margins.top = Number(props.marginTop);
|
|
274
|
+
return margins;
|
|
275
|
+
},
|
|
276
|
+
marginBottom: (props: { readonly marginBottom: string }): unknown => {
|
|
277
|
+
const allProps = props as Record<string, unknown>;
|
|
278
|
+
const margins: { top?: number, bottom?: number, left?: number, right?: number } = allProps.margins ?? {};
|
|
279
|
+
margins.bottom = Number(props.marginBottom);
|
|
280
|
+
return margins;
|
|
281
|
+
},
|
|
282
|
+
marginLeft: (props: { readonly marginLeft: string }): unknown => {
|
|
283
|
+
const allProps = props as Record<string, unknown>;
|
|
284
|
+
const margins: { top?: number, bottom?: number, left?: number, right?: number } = allProps.margins ?? {};
|
|
285
|
+
margins.left = Number(props.marginLeft);
|
|
286
|
+
return margins;
|
|
287
|
+
},
|
|
288
|
+
marginRight: (props: { readonly marginRight: string }): unknown => {
|
|
289
|
+
const allProps = props as Record<string, unknown>;
|
|
290
|
+
const margins: { top?: number, bottom?: number, left?: number, right?: number } = allProps.margins ?? {};
|
|
291
|
+
margins.right = Number(props.marginRight);
|
|
292
|
+
return margins;
|
|
293
|
+
},
|
|
222
294
|
borderColors: (props: { readonly borderColors: string }): unknown => {
|
|
223
295
|
const borderColors: { [k: string]: string } = { top: "", right: "", bottom: "", left: "" };
|
|
224
296
|
props.borderColors.split(" ").forEach((item: string, index) => {
|
|
@@ -241,6 +313,30 @@ export const propsCreators: Record<string, ADCreatorFn> = {
|
|
|
241
313
|
});
|
|
242
314
|
return borderColors;
|
|
243
315
|
},
|
|
316
|
+
borderColorTop: (props: { readonly borderColorTop: string }): unknown => {
|
|
317
|
+
const allProps = props as Record<string, unknown>;
|
|
318
|
+
const margins: { top?: string, bottom?: string, left?: string, right?: string } = allProps.borderColors ?? {};
|
|
319
|
+
margins.top = props.borderColorTop;
|
|
320
|
+
return margins;
|
|
321
|
+
},
|
|
322
|
+
borderColorBottom: (props: { readonly borderColorBottom: string }): unknown => {
|
|
323
|
+
const allProps = props as Record<string, unknown>;
|
|
324
|
+
const boderColors: { top?: string, bottom?: string, left?: string, right?: string } = allProps.borderColors ?? {};
|
|
325
|
+
boderColors.bottom = props.borderColorBottom;
|
|
326
|
+
return boderColors;
|
|
327
|
+
},
|
|
328
|
+
borderColorLeft: (props: { readonly borderColorLeft: string }): unknown => {
|
|
329
|
+
const allProps = props as Record<string, unknown>;
|
|
330
|
+
const boderColors: { top?: string, bottom?: string, left?: string, right?: string } = allProps.borderColors ?? {};
|
|
331
|
+
boderColors.left = props.borderColorLeft;
|
|
332
|
+
return boderColors;
|
|
333
|
+
},
|
|
334
|
+
borderColorRight: (props: { readonly borderColorRight: string }): unknown => {
|
|
335
|
+
const allProps = props as Record<string, unknown>;
|
|
336
|
+
const boderColors: { top?: string, bottom?: string, left?: string, right?: string } = allProps.borderColors ?? {};
|
|
337
|
+
boderColors.right = props.borderColorRight;
|
|
338
|
+
return boderColors;
|
|
339
|
+
},
|
|
244
340
|
};
|
|
245
341
|
|
|
246
342
|
const zero = AI.createPoint(0, 0);
|
|
@@ -4,7 +4,39 @@ export const StyleNames = `<xs:complexType name="StyleNames">
|
|
|
4
4
|
</xs:sequence>
|
|
5
5
|
</xs:complexType>`;
|
|
6
6
|
|
|
7
|
+
export const paddingAttributes = `
|
|
8
|
+
<xs:attribute name="paddingTop" type="xs:decimal"/>
|
|
9
|
+
<xs:attribute name="paddingRight" type="xs:decimal"/>
|
|
10
|
+
<xs:attribute name="paddingBottom" type="xs:decimal"/>
|
|
11
|
+
<xs:attribute name="paddingLeft" type="xs:decimal"/>
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export const bordersAttributes = `
|
|
15
|
+
<xs:attribute name="borderTop" type="xs:decimal"/>
|
|
16
|
+
<xs:attribute name="borderRight" type="xs:decimal"/>
|
|
17
|
+
<xs:attribute name="borderBottom" type="xs:decimal"/>
|
|
18
|
+
<xs:attribute name="borderLeft" type="xs:decimal"/>
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export const marginsAttributes = `
|
|
22
|
+
<xs:attribute name="marginTop" type="xs:decimal"/>
|
|
23
|
+
<xs:attribute name="marginRight" type="xs:decimal"/>
|
|
24
|
+
<xs:attribute name="marginBottom" type="xs:decimal"/>
|
|
25
|
+
<xs:attribute name="marginLeft" type="xs:decimal"/>
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
export const borderColorsAttributes = `
|
|
29
|
+
<xs:attribute name="borderColorTop" type="xs:string"/>
|
|
30
|
+
<xs:attribute name="borderColorRight" type="xs:string"/>
|
|
31
|
+
<xs:attribute name="borderColorBottom" type="xs:string"/>
|
|
32
|
+
<xs:attribute name="borderColorLeft" type="xs:string"/>
|
|
33
|
+
`;
|
|
34
|
+
|
|
7
35
|
export const StyleName = `<xs:complexType name="StyleName">
|
|
36
|
+
${borderColorsAttributes}
|
|
37
|
+
${marginsAttributes}
|
|
38
|
+
${bordersAttributes}
|
|
39
|
+
${paddingAttributes}
|
|
8
40
|
<xs:attribute name="name" type="xs:string" use="required" />
|
|
9
41
|
<xs:attribute name="type" use="required">
|
|
10
42
|
<xs:annotation>
|
|
@@ -76,6 +108,7 @@ export const StyleName = `<xs:complexType name="StyleName">
|
|
|
76
108
|
</xs:complexType>`;
|
|
77
109
|
|
|
78
110
|
export const groupStyle = `<xs:complexType name="GroupStyle">
|
|
111
|
+
${marginsAttributes}
|
|
79
112
|
<xs:annotation>
|
|
80
113
|
<xs:documentation>Group style</xs:documentation>
|
|
81
114
|
</xs:annotation>
|
|
@@ -92,6 +125,9 @@ export const groupStyle = `<xs:complexType name="GroupStyle">
|
|
|
92
125
|
</xs:complexType>`;
|
|
93
126
|
|
|
94
127
|
export const tableCellStyle = `<xs:complexType name="TableCellStyle">
|
|
128
|
+
${paddingAttributes}
|
|
129
|
+
${bordersAttributes}
|
|
130
|
+
${borderColorsAttributes}
|
|
95
131
|
<xs:annotation>
|
|
96
132
|
<xs:documentation>Table cell style</xs:documentation>
|
|
97
133
|
</xs:annotation>
|
|
@@ -136,6 +172,7 @@ export const tableCellStyle = `<xs:complexType name="TableCellStyle">
|
|
|
136
172
|
</xs:complexType>`;
|
|
137
173
|
|
|
138
174
|
export const tableStyle = `<xs:complexType name="TableStyle">
|
|
175
|
+
${marginsAttributes}
|
|
139
176
|
<xs:annotation>
|
|
140
177
|
<xs:documentation>Table style</xs:documentation>
|
|
141
178
|
</xs:annotation>
|
|
@@ -167,6 +204,7 @@ export const tableStyle = `<xs:complexType name="TableStyle">
|
|
|
167
204
|
</xs:complexType>`;
|
|
168
205
|
|
|
169
206
|
export const paragraphStyle = `<xs:complexType name="ParagraphStyle">
|
|
207
|
+
${paddingAttributes}
|
|
170
208
|
<xs:annotation>
|
|
171
209
|
<xs:documentation>Paragraph style</xs:documentation>
|
|
172
210
|
</xs:annotation>
|
|
@@ -281,4 +319,4 @@ export const layoutFoundation = `<xs:complexType name="LayoutFoundation">
|
|
|
281
319
|
export const pageColumnLayout = `<xs:complexType name="PageColumnLayout">
|
|
282
320
|
<xs:attribute name="columnCount" type="xs:decimal" />
|
|
283
321
|
<xs:attribute name="columnGap" type="xs:decimal" />
|
|
284
|
-
</xs:complexType>`;
|
|
322
|
+
</xs:complexType>`;
|