abstract-document 20.0.3 → 20.1.0
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 +4 -0
- package/README.md +3 -3
- package/lib/abstract-document/abstract-doc.d.ts.map +1 -1
- package/lib/abstract-document/abstract-doc.js +2 -2
- package/lib/abstract-document/atoms/atom.d.ts +3 -3
- package/lib/abstract-document/atoms/atom.d.ts.map +1 -1
- package/lib/abstract-document/atoms/line-break.d.ts +1 -1
- package/lib/abstract-document/atoms/line-break.d.ts.map +1 -1
- package/lib/abstract-document/atoms/line-break.js +1 -1
- package/lib/abstract-document/atoms/line-break.js.map +1 -1
- package/lib/abstract-document/atoms/link-target.js +1 -1
- package/lib/abstract-document/atoms/text-run.d.ts.map +1 -1
- package/lib/abstract-document/atoms/text-run.js +1 -0
- package/lib/abstract-document/atoms/text-run.js.map +1 -1
- package/lib/abstract-document/default-styles.d.ts.map +1 -1
- package/lib/abstract-document/default-styles.js.map +1 -1
- package/lib/abstract-document/markdown/markdown.d.ts.map +1 -1
- package/lib/abstract-document/markdown/markdown.js +5 -5
- package/lib/abstract-document/markdown/markdown.js.map +1 -1
- package/lib/abstract-document/numberings/numbering-definition.d.ts +2 -2
- package/lib/abstract-document/numberings/numbering-definition.d.ts.map +1 -1
- package/lib/abstract-document/numberings/numbering-format.d.ts.map +1 -1
- package/lib/abstract-document/numberings/numbering-level-definition.js +2 -2
- package/lib/abstract-document/page/master-page.d.ts +1 -1
- package/lib/abstract-document/page/master-page.d.ts.map +1 -1
- package/lib/abstract-document/page/master-page.js +1 -1
- package/lib/abstract-document/page/master-page.js.map +1 -1
- package/lib/abstract-document/page/section.d.ts +1 -1
- package/lib/abstract-document/page/section.d.ts.map +1 -1
- package/lib/abstract-document/page/section.js +2 -2
- package/lib/abstract-document/page/section.js.map +1 -1
- package/lib/abstract-document/primitives/font.d.ts +1 -1
- package/lib/abstract-document/primitives/font.d.ts.map +1 -1
- package/lib/abstract-document/primitives/font.js +1 -1
- package/lib/abstract-document/primitives/font.js.map +1 -1
- package/lib/abstract-document/primitives/layout-foundation-color.d.ts.map +1 -1
- package/lib/abstract-document/primitives/layout-foundation-color.js +4 -4
- package/lib/abstract-document/primitives/layout-foundation-color.js.map +1 -1
- package/lib/abstract-document/primitives/layout-foundation.d.ts.map +1 -1
- package/lib/abstract-document/primitives/layout-foundation.js +1 -1
- package/lib/abstract-document/primitives/layout-foundation.js.map +1 -1
- package/lib/abstract-document/primitives/point.js +1 -1
- package/lib/abstract-document/resources.d.ts +4 -3
- package/lib/abstract-document/resources.d.ts.map +1 -1
- package/lib/abstract-document/resources.js +4 -4
- package/lib/abstract-document/resources.js.map +1 -1
- package/lib/abstract-document/section-elements/group.d.ts +1 -1
- package/lib/abstract-document/section-elements/group.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/group.js +2 -2
- package/lib/abstract-document/section-elements/group.js.map +1 -1
- package/lib/abstract-document/section-elements/page-break.d.ts +2 -2
- package/lib/abstract-document/section-elements/page-break.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/page-break.js +1 -2
- package/lib/abstract-document/section-elements/page-break.js.map +1 -1
- package/lib/abstract-document/section-elements/paragraph.d.ts +2 -2
- package/lib/abstract-document/section-elements/paragraph.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/paragraph.js +2 -2
- package/lib/abstract-document/section-elements/paragraph.js.map +1 -1
- package/lib/abstract-document/section-elements/section-element.d.ts +1 -1
- package/lib/abstract-document/section-elements/section-element.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/section-element.js.map +1 -1
- package/lib/abstract-document/section-elements/table.d.ts +1 -1
- package/lib/abstract-document/section-elements/table.d.ts.map +1 -1
- package/lib/abstract-document/section-elements/table.js +2 -2
- package/lib/abstract-document/section-elements/table.js.map +1 -1
- package/lib/abstract-document/styles/group-style.js +3 -3
- package/lib/abstract-document/styles/page-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/page-style.js +3 -7
- package/lib/abstract-document/styles/page-style.js.map +1 -1
- package/lib/abstract-document/styles/paragraph-style.d.ts +1 -1
- package/lib/abstract-document/styles/paragraph-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/paragraph-style.js +5 -5
- package/lib/abstract-document/styles/paragraph-style.js.map +1 -1
- package/lib/abstract-document/styles/style.d.ts.map +1 -1
- package/lib/abstract-document/styles/style.js.map +1 -1
- package/lib/abstract-document/styles/table-cell-style.d.ts +1 -1
- package/lib/abstract-document/styles/table-cell-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/table-cell-style.js +7 -7
- package/lib/abstract-document/styles/table-cell-style.js.map +1 -1
- package/lib/abstract-document/styles/table-style.d.ts +1 -1
- package/lib/abstract-document/styles/table-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/table-style.js +2 -2
- package/lib/abstract-document/styles/table-style.js.map +1 -1
- package/lib/abstract-document/styles/text-style.d.ts.map +1 -1
- package/lib/abstract-document/styles/text-style.js +17 -22
- package/lib/abstract-document/styles/text-style.js.map +1 -1
- package/lib/abstract-document/table/table-cell.js +2 -2
- package/lib/abstract-document/table/table-row.d.ts +2 -3
- package/lib/abstract-document/table/table-row.d.ts.map +1 -1
- package/lib/abstract-document/table/table-row.js +2 -3
- package/lib/abstract-document/table/table-row.js.map +1 -1
- package/lib/abstract-document/types.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/document-container.d.ts +5 -5
- package/lib/abstract-document-exporters/docx/document-container.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/document-container.js +14 -13
- package/lib/abstract-document-exporters/docx/document-container.js.map +1 -1
- package/lib/abstract-document-exporters/docx/docx-constants.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/docx-constants.js +1 -4
- package/lib/abstract-document-exporters/docx/docx-constants.js.map +1 -1
- package/lib/abstract-document-exporters/docx/ref-container.d.ts +8 -10
- package/lib/abstract-document-exporters/docx/ref-container.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/ref-container.js +34 -35
- package/lib/abstract-document-exporters/docx/ref-container.js.map +1 -1
- package/lib/abstract-document-exporters/docx/string-utils.d.ts +2 -1
- package/lib/abstract-document-exporters/docx/string-utils.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/string-utils.js +6 -6
- package/lib/abstract-document-exporters/docx/string-utils.js.map +1 -1
- package/lib/abstract-document-exporters/docx/xml-writer.d.ts +12 -33
- package/lib/abstract-document-exporters/docx/xml-writer.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/xml-writer.js +243 -248
- package/lib/abstract-document-exporters/docx/xml-writer.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.d.ts +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.js +5 -17
- package/lib/abstract-document-exporters/docx2/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx2/render.js +37 -43
- package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.js +14 -14
- package/lib/abstract-document-exporters/pdf/font.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/header-footer.d.ts +8 -0
- package/lib/abstract-document-exporters/pdf/header-footer.d.ts.map +1 -0
- package/lib/abstract-document-exporters/pdf/header-footer.js +31 -0
- package/lib/abstract-document-exporters/pdf/header-footer.js.map +1 -0
- package/lib/abstract-document-exporters/pdf/measure.d.ts +4 -4
- package/lib/abstract-document-exporters/pdf/measure.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.js +31 -32
- package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/page.d.ts +15 -0
- package/lib/abstract-document-exporters/pdf/page.d.ts.map +1 -0
- package/lib/abstract-document-exporters/pdf/page.js +2 -0
- package/lib/abstract-document-exporters/pdf/page.js.map +1 -0
- package/lib/abstract-document-exporters/pdf/paginate.d.ts +2 -20
- package/lib/abstract-document-exporters/pdf/paginate.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.js +8 -44
- package/lib/abstract-document-exporters/pdf/paginate.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.js +10 -36
- package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.js +25 -35
- package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.d.ts +4 -3
- package/lib/abstract-document-exporters/pdf/render.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.js +60 -49
- package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/std-fonts.js +2 -2
- package/lib/abstract-document-exporters/pdf/std-fonts.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/textRunRow.d.ts +3 -3
- package/lib/abstract-document-exporters/pdf/textRunRow.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/textRunRow.js +26 -20
- package/lib/abstract-document-exporters/pdf/textRunRow.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/update-refs.d.ts +1 -1
- package/lib/abstract-document-exporters/pdf/update-refs.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/update-refs.js +3 -2
- package/lib/abstract-document-exporters/pdf/update-refs.js.map +1 -1
- package/lib/abstract-document-exporters/shared/get_resources.d.ts.map +1 -1
- package/lib/abstract-document-exporters/shared/get_resources.js.map +1 -1
- package/lib/abstract-document-jsx/index.d.ts +2 -3
- package/lib/abstract-document-jsx/index.d.ts.map +1 -1
- package/lib/abstract-document-jsx/index.js +10 -6
- package/lib/abstract-document-jsx/index.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts +3 -7
- 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 +6 -4
- 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 +8 -4
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js +4 -8
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js.map +1 -1
- package/lib/abstract-document-xml/xsd-template/xsd-template.js +2 -2
- package/lib/abstract-document-xml/xsd-template/xsd-template.js.map +1 -1
- package/package.json +21 -21
- package/src/abstract-document/abstract-doc.ts +6 -6
- package/src/abstract-document/atoms/atom.ts +3 -3
- package/src/abstract-document/atoms/line-break.ts +1 -1
- package/src/abstract-document/atoms/link-target.ts +1 -1
- package/src/abstract-document/atoms/text-run.ts +1 -0
- package/src/abstract-document/default-styles.ts +1 -1
- package/src/abstract-document/markdown/markdown.ts +7 -7
- package/src/abstract-document/numberings/numbering-definition.ts +2 -2
- package/src/abstract-document/numberings/numbering-format.ts +1 -7
- package/src/abstract-document/numberings/numbering-level-definition.ts +2 -2
- package/src/abstract-document/page/master-page.ts +2 -2
- package/src/abstract-document/page/section.ts +3 -3
- package/src/abstract-document/primitives/font.ts +1 -12
- package/src/abstract-document/primitives/layout-foundation-color.ts +5 -8
- package/src/abstract-document/primitives/layout-foundation.ts +2 -5
- package/src/abstract-document/primitives/point.ts +1 -1
- package/src/abstract-document/resources.ts +9 -14
- package/src/abstract-document/section-elements/group.ts +3 -3
- package/src/abstract-document/section-elements/page-break.ts +2 -3
- package/src/abstract-document/section-elements/paragraph.ts +4 -4
- package/src/abstract-document/section-elements/section-element.ts +1 -1
- package/src/abstract-document/section-elements/table.ts +3 -3
- package/src/abstract-document/styles/group-style.ts +3 -3
- package/src/abstract-document/styles/page-style.ts +3 -7
- package/src/abstract-document/styles/paragraph-style.ts +6 -14
- package/src/abstract-document/styles/style.ts +1 -5
- package/src/abstract-document/styles/table-cell-style.ts +8 -18
- package/src/abstract-document/styles/table-style.ts +3 -8
- package/src/abstract-document/styles/text-style.ts +31 -36
- package/src/abstract-document/table/table-cell.ts +2 -2
- package/src/abstract-document/table/table-row.ts +3 -4
- package/src/abstract-document/types.ts +0 -1
- package/src/abstract-document-exporters/docx/document-container.ts +24 -13
- package/src/abstract-document-exporters/docx/docx-constants.ts +2 -6
- package/src/abstract-document-exporters/docx/ref-container.ts +48 -41
- package/src/abstract-document-exporters/docx/string-utils.ts +6 -10
- package/src/abstract-document-exporters/docx/xml-writer.ts +261 -265
- package/src/abstract-document-exporters/docx2/render-image.ts +16 -50
- package/src/abstract-document-exporters/docx2/render.ts +68 -121
- package/src/abstract-document-exporters/pdf/font.ts +27 -32
- package/src/abstract-document-exporters/pdf/header-footer.ts +43 -0
- package/src/abstract-document-exporters/pdf/measure.ts +52 -103
- package/src/abstract-document-exporters/pdf/page.ts +16 -0
- package/src/abstract-document-exporters/pdf/paginate.ts +29 -120
- package/src/abstract-document-exporters/pdf/pre-process.ts +13 -48
- package/src/abstract-document-exporters/pdf/render-image.ts +30 -47
- package/src/abstract-document-exporters/pdf/render.ts +84 -128
- package/src/abstract-document-exporters/pdf/std-fonts.ts +2 -2
- package/src/abstract-document-exporters/pdf/textRunRow.ts +100 -77
- package/src/abstract-document-exporters/pdf/update-refs.ts +10 -33
- package/src/abstract-document-exporters/shared/get_resources.ts +4 -4
- package/src/abstract-document-jsx/index.ts +38 -26
- package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +23 -35
- package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +17 -29
- package/src/abstract-document-xml/abstract-doc-of-xml/custom-elements.tsx +8 -30
- package/src/abstract-document-xml/xsd-template/styles.ts +1 -1
- package/src/abstract-document-xml/xsd-template/xsd-template.ts +2 -2
- package/lib/abstract-document/table/text-row.d.ts +0 -2
- package/lib/abstract-document/table/text-row.d.ts.map +0 -1
- package/lib/abstract-document/table/text-row.js +0 -2
- package/lib/abstract-document/table/text-row.js.map +0 -1
- package/lib/abstract-document-exporters/docx/docx-document-renderer.d.ts +0 -2
- package/lib/abstract-document-exporters/docx/docx-document-renderer.d.ts.map +0 -1
- package/lib/abstract-document-exporters/docx/docx-document-renderer.js +0 -1085
- package/lib/abstract-document-exporters/docx/docx-document-renderer.js.map +0 -1
- package/src/abstract-document/table/text-row.ts +0 -0
- package/src/abstract-document-exporters/docx/docx-document-renderer.ts +0 -1084
|
@@ -1,34 +1,21 @@
|
|
|
1
1
|
import * as AD from "../../abstract-document/index.js";
|
|
2
2
|
import { getResources } from "../shared/get_resources.js";
|
|
3
3
|
import { registerFonts } from "./font.js";
|
|
4
|
+
import { getHeaderAndFooter } from "./header-footer.js";
|
|
4
5
|
import { measureTable } from "./measure.js";
|
|
5
|
-
|
|
6
|
-
export interface PageColumn {
|
|
7
|
-
readonly elements: ReadonlyArray<AD.SectionElement.SectionElement>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface Page {
|
|
11
|
-
readonly pageNo: number;
|
|
12
|
-
readonly namedDestionations: ReadonlyArray<string>;
|
|
13
|
-
readonly pageOptions: any;
|
|
14
|
-
readonly section: AD.Section.Section;
|
|
15
|
-
readonly contentRect: AD.Rect.Rect;
|
|
16
|
-
readonly columns: ReadonlyArray<PageColumn>;
|
|
17
|
-
readonly header: ReadonlyArray<AD.SectionElement.SectionElement>;
|
|
18
|
-
readonly footer: ReadonlyArray<AD.SectionElement.SectionElement>;
|
|
19
|
-
}
|
|
6
|
+
import type { Page, PageColumn } from "./page.js";
|
|
20
7
|
|
|
21
8
|
export function paginate(
|
|
22
9
|
pdfKit: PDFKit.PDFDocument,
|
|
23
10
|
document: AD.AbstractDoc.AbstractDoc,
|
|
24
|
-
desiredSizes: Map<
|
|
11
|
+
desiredSizes: Map<object, AD.Size.Size>
|
|
25
12
|
): ReadonlyArray<Page> {
|
|
26
13
|
const resources = getResources(document);
|
|
27
14
|
const pdf = new pdfKit({ compress: false, autoFirstPage: false, bufferPages: true });
|
|
28
15
|
|
|
29
16
|
registerFonts((fontName: string, fontSource: AD.Font.FontSource) => pdf.registerFont(fontName, fontSource), document);
|
|
30
17
|
const pages = new Array<Page>();
|
|
31
|
-
for (
|
|
18
|
+
for (const section of document.children) {
|
|
32
19
|
const previousPage = pages.length > 0 ? pages[pages.length - 1] : undefined;
|
|
33
20
|
pages.push(...paginateSection(pdfKit, document, resources, desiredSizes, previousPage, section));
|
|
34
21
|
}
|
|
@@ -40,7 +27,7 @@ function paginateSection(
|
|
|
40
27
|
pdfKit: PDFKit.PDFDocument,
|
|
41
28
|
document: AD.AbstractDoc.AbstractDoc,
|
|
42
29
|
parentResources: AD.Resources.Resources,
|
|
43
|
-
desiredSizes: Map<
|
|
30
|
+
desiredSizes: Map<object, AD.Size.Size>,
|
|
44
31
|
previousPage: Page | undefined,
|
|
45
32
|
section: AD.Section.Section
|
|
46
33
|
): Array<Page> {
|
|
@@ -97,7 +84,7 @@ function paginateSection(
|
|
|
97
84
|
elements.length
|
|
98
85
|
);
|
|
99
86
|
|
|
100
|
-
const tableSplit: AD.Table.Table
|
|
87
|
+
const tableSplit: Array<AD.Table.Table> = [];
|
|
101
88
|
if (tableHead) {
|
|
102
89
|
elements.push(tableHead);
|
|
103
90
|
tableSplit.push(tableHead);
|
|
@@ -139,7 +126,7 @@ function splitTable(
|
|
|
139
126
|
pdfKit: PDFKit.PDFDocument,
|
|
140
127
|
document: AD.AbstractDoc.AbstractDoc,
|
|
141
128
|
resources: AD.Resources.Resources,
|
|
142
|
-
desiredSizes: Map<
|
|
129
|
+
desiredSizes: Map<object, AD.Size.Size>,
|
|
143
130
|
table: AD.Table.Table,
|
|
144
131
|
elementsHeight: number,
|
|
145
132
|
availableHeight: number,
|
|
@@ -147,7 +134,7 @@ function splitTable(
|
|
|
147
134
|
): [AD.Table.Table | undefined, AD.Table.Table | undefined] {
|
|
148
135
|
let tableHead = undefined;
|
|
149
136
|
let tableRest = undefined;
|
|
150
|
-
elementsHeight += table.style.margins.top
|
|
137
|
+
elementsHeight += table.style.margins.top ?? 0;
|
|
151
138
|
if (table.headerRows.length > 0) {
|
|
152
139
|
const headerSize = table.headerRows.reduce((acc, row) => (acc += getDesiredSize(row, desiredSizes).height), 0);
|
|
153
140
|
elementsHeight += headerSize;
|
|
@@ -164,14 +151,7 @@ function splitTable(
|
|
|
164
151
|
return [undefined, table];
|
|
165
152
|
}
|
|
166
153
|
|
|
167
|
-
const [newTableHead, newTableRest] = splitTableAt(
|
|
168
|
-
pdfKit,
|
|
169
|
-
document,
|
|
170
|
-
resources,
|
|
171
|
-
desiredSizes,
|
|
172
|
-
table,
|
|
173
|
-
Math.max(rowIndex, 1)
|
|
174
|
-
);
|
|
154
|
+
const [newTableHead, newTableRest] = splitTableAt(pdfKit, document, resources, desiredSizes, table, Math.max(rowIndex, 1));
|
|
175
155
|
|
|
176
156
|
if (newTableHead.children.length > 0) {
|
|
177
157
|
tableHead = newTableHead;
|
|
@@ -193,7 +173,7 @@ function splitTable(
|
|
|
193
173
|
|
|
194
174
|
function createPage(
|
|
195
175
|
resources: AD.Resources.Resources,
|
|
196
|
-
desiredSizes: Map<
|
|
176
|
+
desiredSizes: Map<object, AD.Size.Size>,
|
|
197
177
|
previousPage: Page | undefined,
|
|
198
178
|
section: AD.Section.Section,
|
|
199
179
|
columns: ReadonlyArray<PageColumn>,
|
|
@@ -202,7 +182,7 @@ function createPage(
|
|
|
202
182
|
const style = section.page.style;
|
|
203
183
|
const pageWidth = AD.PageStyle.getWidth(style);
|
|
204
184
|
const pageHeight = AD.PageStyle.getHeight(style);
|
|
205
|
-
const layout = style.orientation === "Landscape" ? "landscape" : "portrait";
|
|
185
|
+
const layout: "landscape" | "portrait" = style.orientation === "Landscape" ? "landscape" : "portrait";
|
|
206
186
|
const pageOptions = {
|
|
207
187
|
size: [pageWidth, pageHeight],
|
|
208
188
|
layout: layout,
|
|
@@ -235,18 +215,14 @@ function createPage(
|
|
|
235
215
|
const [columnLeadingSpace] = getLeadingAndTrailingSpace(resources, section, elements);
|
|
236
216
|
leadingSpace = Math.min(leadingSpace ?? columnLeadingSpace, columnLeadingSpace);
|
|
237
217
|
}
|
|
238
|
-
leadingSpace
|
|
218
|
+
leadingSpace ??= 0;
|
|
239
219
|
const contentRect = AD.Rect.create(rect.x, rect.y - leadingSpace, rect.width, rect.height + leadingSpace);
|
|
240
220
|
|
|
241
221
|
const frontHeader =
|
|
242
|
-
section.page.frontHeader === undefined || section.page.frontHeader.length === 0
|
|
243
|
-
? section.page.header
|
|
244
|
-
: section.page.frontHeader;
|
|
222
|
+
section.page.frontHeader === undefined || section.page.frontHeader.length === 0 ? section.page.header : section.page.frontHeader;
|
|
245
223
|
|
|
246
224
|
const frontFooter =
|
|
247
|
-
section.page.frontFooter === undefined || section.page.frontFooter.length === 0
|
|
248
|
-
? section.page.footer
|
|
249
|
-
: section.page.frontFooter;
|
|
225
|
+
section.page.frontFooter === undefined || section.page.frontFooter.length === 0 ? section.page.footer : section.page.frontFooter;
|
|
250
226
|
|
|
251
227
|
return {
|
|
252
228
|
pageNo: pageNo,
|
|
@@ -260,70 +236,18 @@ function createPage(
|
|
|
260
236
|
};
|
|
261
237
|
}
|
|
262
238
|
|
|
263
|
-
|
|
264
|
-
section: AD.Section.Section,
|
|
265
|
-
pageNo: number
|
|
266
|
-
): {
|
|
267
|
-
readonly header: Array<AD.SectionElement.SectionElement>;
|
|
268
|
-
readonly footer: Array<AD.SectionElement.SectionElement>;
|
|
269
|
-
readonly headerMargins: Required<AD.LayoutFoundation.LayoutFoundation>;
|
|
270
|
-
readonly footerMargins: Required<AD.LayoutFoundation.LayoutFoundation>;
|
|
271
|
-
} {
|
|
272
|
-
const FIRST_PAGE = 1;
|
|
273
|
-
const EVEN_PAGE = 0;
|
|
274
|
-
const ODD_PAGE = 1;
|
|
275
|
-
switch (true) {
|
|
276
|
-
//first page
|
|
277
|
-
case pageNo === FIRST_PAGE: {
|
|
278
|
-
const normalHeader = section.page.frontHeader === undefined || section.page.frontHeader.length === 0;
|
|
279
|
-
const normalFooter = section.page.frontFooter === undefined || section.page.frontFooter.length === 0;
|
|
280
|
-
return {
|
|
281
|
-
footer: normalFooter ? section.page.footer : section.page.frontFooter,
|
|
282
|
-
header: normalHeader ? section.page.header : section.page.frontHeader,
|
|
283
|
-
headerMargins: AD.LayoutFoundation.orDefault(normalHeader
|
|
284
|
-
? section.page.style.headerMargins
|
|
285
|
-
: section.page.style.firstPageHeaderMargins ?? section.page.style.headerMargins),
|
|
286
|
-
footerMargins: AD.LayoutFoundation.orDefault(normalFooter
|
|
287
|
-
? section.page.style.footerMargins
|
|
288
|
-
: section.page.style.firstPageFooterMargins ?? section.page.style.footerMargins),
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
case pageNo === 0:
|
|
292
|
-
case pageNo % 2 === EVEN_PAGE:
|
|
293
|
-
case pageNo % 2 === ODD_PAGE:
|
|
294
|
-
default: {
|
|
295
|
-
return {
|
|
296
|
-
header: section.page.header,
|
|
297
|
-
footer: section.page.footer,
|
|
298
|
-
headerMargins: AD.LayoutFoundation.orDefault(section.page.style.headerMargins),
|
|
299
|
-
footerMargins: AD.LayoutFoundation.orDefault(section.page.style.footerMargins),
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function getPageContentRect(
|
|
306
|
-
desiredSizes: Map<{}, AD.Size.Size>,
|
|
307
|
-
section: AD.Section.Section,
|
|
308
|
-
pageNo: number
|
|
309
|
-
): AD.Rect.Rect {
|
|
239
|
+
function getPageContentRect(desiredSizes: Map<object, AD.Size.Size>, section: AD.Section.Section, pageNo: number): AD.Rect.Rect {
|
|
310
240
|
const style = section.page.style;
|
|
311
241
|
const styleContentMargins = AD.LayoutFoundation.orDefault(style.contentMargins);
|
|
312
242
|
const pageWidth = AD.PageStyle.getWidth(style);
|
|
313
243
|
const pageHeight = AD.PageStyle.getHeight(style);
|
|
314
244
|
|
|
315
245
|
const { header, footer, headerMargins, footerMargins } = getHeaderAndFooter(section, pageNo);
|
|
316
|
-
const headerHeight = header.reduce(
|
|
317
|
-
|
|
318
|
-
headerMargins.top + headerMargins.bottom
|
|
319
|
-
);
|
|
320
|
-
const footerHeight = footer.reduce(
|
|
321
|
-
(prev, curr) => prev + getDesiredSize(curr, desiredSizes).height,
|
|
322
|
-
footerMargins.top + footerMargins.bottom
|
|
323
|
-
);
|
|
246
|
+
const headerHeight = header.reduce((prev, curr) => prev + getDesiredSize(curr, desiredSizes).height, headerMargins.top + headerMargins.bottom);
|
|
247
|
+
const footerHeight = footer.reduce((prev, curr) => prev + getDesiredSize(curr, desiredSizes).height, footerMargins.top + footerMargins.bottom);
|
|
324
248
|
|
|
325
249
|
let headerY = headerMargins.top;
|
|
326
|
-
for (
|
|
250
|
+
for (const element of header) {
|
|
327
251
|
const elementSize = getDesiredSize(element, desiredSizes);
|
|
328
252
|
headerY += elementSize.height;
|
|
329
253
|
}
|
|
@@ -376,10 +300,7 @@ function getSectionElementMargin(
|
|
|
376
300
|
}
|
|
377
301
|
}
|
|
378
302
|
|
|
379
|
-
function getParagraphMargins(
|
|
380
|
-
resources: AD.Resources.Resources,
|
|
381
|
-
paragraph: AD.Paragraph.Paragraph
|
|
382
|
-
): AD.LayoutFoundation.LayoutFoundation {
|
|
303
|
+
function getParagraphMargins(resources: AD.Resources.Resources, paragraph: AD.Paragraph.Paragraph): AD.LayoutFoundation.LayoutFoundation {
|
|
383
304
|
const style = AD.Resources.getStyle(
|
|
384
305
|
undefined,
|
|
385
306
|
paragraph.style,
|
|
@@ -390,10 +311,7 @@ function getParagraphMargins(
|
|
|
390
311
|
return style.margins;
|
|
391
312
|
}
|
|
392
313
|
|
|
393
|
-
function getGroupMargins(
|
|
394
|
-
resources: AD.Resources.Resources,
|
|
395
|
-
group: AD.Group.Group
|
|
396
|
-
): AD.LayoutFoundation.LayoutFoundation {
|
|
314
|
+
function getGroupMargins(resources: AD.Resources.Resources, group: AD.Group.Group): AD.LayoutFoundation.LayoutFoundation {
|
|
397
315
|
const first = group.children.length > 0 ? group.children[0] : undefined;
|
|
398
316
|
const last = group.children.length > 0 ? group.children[group.children.length - 1] : undefined;
|
|
399
317
|
const firstMargin = first && getSectionElementMargin(resources, first);
|
|
@@ -413,21 +331,12 @@ function getGroupMargins(
|
|
|
413
331
|
}
|
|
414
332
|
}
|
|
415
333
|
|
|
416
|
-
function getTableMargins(
|
|
417
|
-
|
|
418
|
-
table: AD.Table.Table
|
|
419
|
-
): AD.LayoutFoundation.LayoutFoundation {
|
|
420
|
-
const style = AD.Resources.getStyle(
|
|
421
|
-
undefined,
|
|
422
|
-
table.style,
|
|
423
|
-
"TableStyle",
|
|
424
|
-
table.styleName,
|
|
425
|
-
resources
|
|
426
|
-
) as AD.TableStyle.TableStyle;
|
|
334
|
+
function getTableMargins(resources: AD.Resources.Resources, table: AD.Table.Table): AD.LayoutFoundation.LayoutFoundation {
|
|
335
|
+
const style = AD.Resources.getStyle(undefined, table.style, "TableStyle", table.styleName, resources) as AD.TableStyle.TableStyle;
|
|
427
336
|
return style.margins;
|
|
428
337
|
}
|
|
429
338
|
|
|
430
|
-
function getDesiredSize(element:
|
|
339
|
+
function getDesiredSize(element: object, desiredSizes: Map<object, AD.Size.Size>): AD.Size.Size {
|
|
431
340
|
const size = desiredSizes.get(element);
|
|
432
341
|
if (size) {
|
|
433
342
|
return size;
|
|
@@ -439,14 +348,14 @@ function splitTableAt(
|
|
|
439
348
|
pdfKit: PDFKit.PDFDocument,
|
|
440
349
|
document: AD.AbstractDoc.AbstractDoc,
|
|
441
350
|
resources: AD.Resources.Resources,
|
|
442
|
-
desiredSizes: Map<
|
|
351
|
+
desiredSizes: Map<object, AD.Size.Size>,
|
|
443
352
|
table: AD.Table.Table,
|
|
444
353
|
splitIndex: number
|
|
445
354
|
): [AD.Table.Table, AD.Table.Table] {
|
|
446
355
|
//Push row/cells to head table while splitting rowspan
|
|
447
|
-
const headRows: AD.TableRow.TableRow
|
|
356
|
+
const headRows: Array<AD.TableRow.TableRow> = [];
|
|
448
357
|
for (const [rowIndex, row] of table.children.slice(0, splitIndex).entries()) {
|
|
449
|
-
const newRow: AD.TableCell.TableCell
|
|
358
|
+
const newRow: Array<AD.TableCell.TableCell> = [];
|
|
450
359
|
for (const cell of row.children) {
|
|
451
360
|
//If this cell would span over the split index
|
|
452
361
|
if (rowIndex + (cell.rowSpan || 1) - 1 >= splitIndex) {
|
|
@@ -463,13 +372,13 @@ function splitTableAt(
|
|
|
463
372
|
//while keeping the remaining rowspan which was calculated
|
|
464
373
|
//in the pre-process step
|
|
465
374
|
const splitRow = table.children[splitIndex];
|
|
466
|
-
const firstTailRow: AD.TableCell.TableCell
|
|
375
|
+
const firstTailRow: Array<AD.TableCell.TableCell> = [];
|
|
467
376
|
for (const cell of splitRow.children) {
|
|
468
377
|
firstTailRow.push({ ...cell, dummy: false });
|
|
469
378
|
}
|
|
470
379
|
|
|
471
380
|
// Push the rest of the rows to tail table
|
|
472
|
-
const tailRows: AD.TableRow.TableRow
|
|
381
|
+
const tailRows: Array<AD.TableRow.TableRow> = [{ ...splitRow, children: firstTailRow }];
|
|
473
382
|
tailRows.push(...table.children.slice(splitIndex + 1));
|
|
474
383
|
|
|
475
384
|
//Create tables and remeasure them
|
|
@@ -485,7 +394,7 @@ function splitTableAt(
|
|
|
485
394
|
};
|
|
486
395
|
|
|
487
396
|
const availableSize = getDesiredSize(table, desiredSizes);
|
|
488
|
-
|
|
397
|
+
const pdf = new pdfKit();
|
|
489
398
|
registerFonts((fontName: string, fontSource: AD.Font.FontSource) => pdf.registerFont(fontName, fontSource), document);
|
|
490
399
|
const headSizes = measureTable(pdf, resources, availableSize, tableHead);
|
|
491
400
|
const tailSizes = measureTable(pdf, resources, availableSize, tableTail);
|
|
@@ -2,34 +2,7 @@ import { exhaustiveCheck } from "ts-exhaustive-check";
|
|
|
2
2
|
import * as AD from "../../abstract-document/index.js";
|
|
3
3
|
import * as TextStyle from "../../abstract-document/styles/text-style.js";
|
|
4
4
|
|
|
5
|
-
const alphabet = [
|
|
6
|
-
"a",
|
|
7
|
-
"b",
|
|
8
|
-
"c",
|
|
9
|
-
"d",
|
|
10
|
-
"e",
|
|
11
|
-
"f",
|
|
12
|
-
"g",
|
|
13
|
-
"h",
|
|
14
|
-
"i",
|
|
15
|
-
"j",
|
|
16
|
-
"k",
|
|
17
|
-
"l",
|
|
18
|
-
"m",
|
|
19
|
-
"n",
|
|
20
|
-
"o",
|
|
21
|
-
"p",
|
|
22
|
-
"q",
|
|
23
|
-
"r",
|
|
24
|
-
"s",
|
|
25
|
-
"t",
|
|
26
|
-
"u",
|
|
27
|
-
"v",
|
|
28
|
-
"w",
|
|
29
|
-
"x",
|
|
30
|
-
"y",
|
|
31
|
-
"z",
|
|
32
|
-
];
|
|
5
|
+
const alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
|
|
33
6
|
|
|
34
7
|
const _numberingLevelItems = new Map<string, number>();
|
|
35
8
|
|
|
@@ -84,10 +57,7 @@ function preProcessSectionElement(
|
|
|
84
57
|
}
|
|
85
58
|
}
|
|
86
59
|
|
|
87
|
-
function preProcessParagraph(
|
|
88
|
-
paragraph: AD.Paragraph.Paragraph,
|
|
89
|
-
resources: AD.Resources.Resources
|
|
90
|
-
): Array<AD.SectionElement.SectionElement> {
|
|
60
|
+
function preProcessParagraph(paragraph: AD.Paragraph.Paragraph, resources: AD.Resources.Resources): Array<AD.SectionElement.SectionElement> {
|
|
91
61
|
const adjustedParagraphs = adjustParagraph(paragraph);
|
|
92
62
|
if (paragraph.numbering === undefined || !resources.numberingDefinitions) {
|
|
93
63
|
return adjustedParagraphs;
|
|
@@ -101,7 +71,7 @@ function preProcessParagraph(
|
|
|
101
71
|
if (numbering === "Unordered") {
|
|
102
72
|
numberText = "-";
|
|
103
73
|
} else {
|
|
104
|
-
for (
|
|
74
|
+
for (const levelDefinition of levelDefinitions.filter((l) => l.level > level)) {
|
|
105
75
|
_numberingLevelItems.delete(numbering + "_" + levelDefinition.level.toString());
|
|
106
76
|
}
|
|
107
77
|
|
|
@@ -112,20 +82,20 @@ function preProcessParagraph(
|
|
|
112
82
|
} else if (!_numberingLevelItems.has(key)) {
|
|
113
83
|
_numberingLevelItems.set(key, levelDefinitions[level].start);
|
|
114
84
|
} else if (append !== true) {
|
|
115
|
-
_numberingLevelItems.set(key, (_numberingLevelItems.get(key)
|
|
85
|
+
_numberingLevelItems.set(key, (_numberingLevelItems.get(key) ?? 0) + 1);
|
|
116
86
|
}
|
|
117
87
|
|
|
118
|
-
for (
|
|
88
|
+
for (const levelDefinition of levelDefinitions.filter((l) => l.level <= level)) {
|
|
119
89
|
const numberingLevel = numbering + "_" + levelDefinition.level.toString();
|
|
120
|
-
const currentNumber = _numberingLevelItems.get(numberingLevel)
|
|
90
|
+
const currentNumber = _numberingLevelItems.get(numberingLevel) ?? 0;
|
|
121
91
|
const levelText = generateLevelText(levelDefinition.format, currentNumber);
|
|
122
92
|
const levelKey = "%" + (levelDefinition.level + 1).toString();
|
|
123
93
|
numberText = numberText.replace(levelKey, levelText);
|
|
124
94
|
}
|
|
125
95
|
}
|
|
126
96
|
|
|
127
|
-
|
|
128
|
-
|
|
97
|
+
const rows: Array<AD.TableRow.TableRow> = [];
|
|
98
|
+
const children: Array<AD.TableCell.TableCell> = [];
|
|
129
99
|
|
|
130
100
|
children.push(AD.TableCell.create());
|
|
131
101
|
|
|
@@ -183,7 +153,8 @@ function adjustParagraph(paragraph: AD.Paragraph.Paragraph): Array<AD.SectionEle
|
|
|
183
153
|
if (child.type === "TextRun") {
|
|
184
154
|
// Pdfkit will automatically split texts on "\n", which would not match with out measuring.
|
|
185
155
|
// Fix this by replacing "\n" with a LineBreak
|
|
186
|
-
|
|
156
|
+
// oxlint-disable-next-line typescript/no-unnecessary-type-conversion -- text isn't always a string at runtime
|
|
157
|
+
const text = String(child.text);
|
|
187
158
|
const lines = text.split("\n");
|
|
188
159
|
|
|
189
160
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -310,7 +281,7 @@ function toChar(num: number): string {
|
|
|
310
281
|
function preProcessTable(table: AD.Table.Table, resources: AD.Resources.Resources): AD.SectionElement.SectionElement {
|
|
311
282
|
const processedHeaders = [];
|
|
312
283
|
const processedChildren = [];
|
|
313
|
-
|
|
284
|
+
const rowSpans: Map<number, AD.TableCell.TableCell> = new Map();
|
|
314
285
|
if (table.headerRows) {
|
|
315
286
|
for (const row of table.headerRows) {
|
|
316
287
|
const header = preProcessTableRow(row, rowSpans, resources);
|
|
@@ -378,16 +349,10 @@ function preProcessTableRow(
|
|
|
378
349
|
|
|
379
350
|
function preProcessTableCell(c: AD.TableCell.TableCell, resources: AD.Resources.Resources): AD.TableCell.TableCell {
|
|
380
351
|
const children = c.children.flatMap((e) => preProcessSectionElement(e, resources));
|
|
381
|
-
return AD.TableCell.create(
|
|
382
|
-
{ styleName: c.styleName, columnSpan: c.columnSpan, rowSpan: c.rowSpan, style: c.style },
|
|
383
|
-
children
|
|
384
|
-
);
|
|
352
|
+
return AD.TableCell.create({ styleName: c.styleName, columnSpan: c.columnSpan, rowSpan: c.rowSpan, style: c.style }, children);
|
|
385
353
|
}
|
|
386
354
|
|
|
387
|
-
function preProcessGroup(
|
|
388
|
-
group: AD.Group.Group,
|
|
389
|
-
parentResources: AD.Resources.Resources
|
|
390
|
-
): Array<AD.SectionElement.SectionElement> {
|
|
355
|
+
function preProcessGroup(group: AD.Group.Group, parentResources: AD.Resources.Resources): Array<AD.SectionElement.SectionElement> {
|
|
391
356
|
const children = group.children.flatMap((e) => preProcessSectionElement(e, parentResources));
|
|
392
357
|
if (group.keepTogether || AD.Resources.hasResources(group) || group.style.position === "absolute") {
|
|
393
358
|
return [
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type * as AbstractImage from "abstract-image";
|
|
2
2
|
import svgToPdfKit from "svg-to-pdfkit";
|
|
3
3
|
import * as AD from "../../abstract-document/index.js";
|
|
4
|
-
import { getFontNameStyle, getFontName, isFontAvailable } from "./font.js";
|
|
5
4
|
import { rawSvgPrefix, toBase64 } from "../shared/base-64.js";
|
|
5
|
+
import { getFontNameStyle, getFontName, isFontAvailable } from "./font.js";
|
|
6
6
|
|
|
7
7
|
export function renderImage(
|
|
8
8
|
resources: AD.Resources.Resources,
|
|
@@ -17,7 +17,7 @@ export function renderImage(
|
|
|
17
17
|
const firstComp = ai.components[0];
|
|
18
18
|
const resource =
|
|
19
19
|
!ai.size.width && !ai.size.height && firstComp?.type === "binaryimage" && firstComp.data.type === "url"
|
|
20
|
-
? resources.imageResources?.[firstComp.data.url] ?? image.imageResource
|
|
20
|
+
? (resources.imageResources?.[firstComp.data.url] ?? image.imageResource)
|
|
21
21
|
: image.imageResource;
|
|
22
22
|
|
|
23
23
|
const position = AD.Point.create(finalRect.x, finalRect.y);
|
|
@@ -34,18 +34,9 @@ export function renderImage(
|
|
|
34
34
|
const drawnH = imgH * scale;
|
|
35
35
|
|
|
36
36
|
const offsetX =
|
|
37
|
-
image.horizontalAlignment === "Center"
|
|
38
|
-
? (rect.width - drawnW) / 2
|
|
39
|
-
: image.horizontalAlignment === "Right"
|
|
40
|
-
? rect.width - drawnW
|
|
41
|
-
: 0;
|
|
37
|
+
image.horizontalAlignment === "Center" ? (rect.width - drawnW) / 2 : image.horizontalAlignment === "Right" ? rect.width - drawnW : 0;
|
|
42
38
|
|
|
43
|
-
const offsetY =
|
|
44
|
-
image.verticalAlignment === "Center"
|
|
45
|
-
? (rect.height - drawnH) / 2
|
|
46
|
-
: image.verticalAlignment === "Bottom"
|
|
47
|
-
? rect.height - drawnH
|
|
48
|
-
: 0;
|
|
39
|
+
const offsetY = image.verticalAlignment === "Center" ? (rect.height - drawnH) / 2 : image.verticalAlignment === "Bottom" ? rect.height - drawnH : 0;
|
|
49
40
|
|
|
50
41
|
pdf.save();
|
|
51
42
|
pdf.translate(position.x + offsetX, position.y + offsetY).scale(scale);
|
|
@@ -68,7 +59,7 @@ function abstractComponentToPdf(
|
|
|
68
59
|
case "group":
|
|
69
60
|
component.children.forEach((c) => abstractComponentToPdf(resources, pdf, c, textStyle, circuitBreaker, accScale));
|
|
70
61
|
break;
|
|
71
|
-
case "binaryimage":
|
|
62
|
+
case "binaryimage": {
|
|
72
63
|
const format = component.format.toLowerCase();
|
|
73
64
|
const w = component.bottomRight.x - component.topLeft.x;
|
|
74
65
|
const h = component.bottomRight.y - component.topLeft.y;
|
|
@@ -86,13 +77,7 @@ function abstractComponentToPdf(
|
|
|
86
77
|
);
|
|
87
78
|
pdf.restore();
|
|
88
79
|
} else if (component.data.url.startsWith(rawSvgPrefix)) {
|
|
89
|
-
addWithSvgToPdfKit(
|
|
90
|
-
decodeURIComponent(component.data.url.slice(rawSvgPrefix.length)),
|
|
91
|
-
component,
|
|
92
|
-
pdf,
|
|
93
|
-
resources,
|
|
94
|
-
textStyle
|
|
95
|
-
);
|
|
80
|
+
addWithSvgToPdfKit(decodeURIComponent(component.data.url.slice(rawSvgPrefix.length)), component, pdf, resources, textStyle);
|
|
96
81
|
} else {
|
|
97
82
|
const match = /^data:.+?;base64,(.*)$/.exec(component.data.url);
|
|
98
83
|
if (match) {
|
|
@@ -112,6 +97,7 @@ function abstractComponentToPdf(
|
|
|
112
97
|
addWithSvgToPdfKit(new TextDecoder().decode(component.data.bytes), component, pdf, resources, textStyle);
|
|
113
98
|
}
|
|
114
99
|
break;
|
|
100
|
+
}
|
|
115
101
|
case "subimage": {
|
|
116
102
|
const scaleX = component.size.width / (component.image.size.width || 1);
|
|
117
103
|
const scaleY = component.size.height / (component.image.size.height || 1);
|
|
@@ -119,9 +105,7 @@ function abstractComponentToPdf(
|
|
|
119
105
|
|
|
120
106
|
pdf.save();
|
|
121
107
|
pdf.translate(component.topLeft.x, component.topLeft.y).scale(scale);
|
|
122
|
-
component.image.components.forEach((c) =>
|
|
123
|
-
abstractComponentToPdf(resources, pdf, c, textStyle, circuitBreaker, accScale * scale)
|
|
124
|
-
);
|
|
108
|
+
component.image.components.forEach((c) => abstractComponentToPdf(resources, pdf, c, textStyle, circuitBreaker, accScale * scale));
|
|
125
109
|
pdf.restore();
|
|
126
110
|
break;
|
|
127
111
|
}
|
|
@@ -147,7 +131,7 @@ function abstractComponentToPdf(
|
|
|
147
131
|
applyStrokeDashStyle(pdf, component.strokeDashStyle);
|
|
148
132
|
pdf.stroke(colorToRgb(component.strokeColor));
|
|
149
133
|
break;
|
|
150
|
-
case "text":
|
|
134
|
+
case "text": {
|
|
151
135
|
const font = getFontName(component.fontFamily, component.fontWeight, component.italic);
|
|
152
136
|
if (component.clockwiseRotationDegrees !== 0) {
|
|
153
137
|
pdf.save();
|
|
@@ -159,17 +143,9 @@ function abstractComponentToPdf(
|
|
|
159
143
|
const stringWidth = pdf.widthOfString(component.text);
|
|
160
144
|
const stringHeight = pdf.currentLineHeight();
|
|
161
145
|
const dx =
|
|
162
|
-
component.horizontalGrowthDirection === "left"
|
|
163
|
-
? -stringWidth
|
|
164
|
-
: component.horizontalGrowthDirection === "uniform"
|
|
165
|
-
? -stringWidth * 0.5
|
|
166
|
-
: 0;
|
|
146
|
+
component.horizontalGrowthDirection === "left" ? -stringWidth : component.horizontalGrowthDirection === "uniform" ? -stringWidth * 0.5 : 0;
|
|
167
147
|
const dy =
|
|
168
|
-
component.verticalGrowthDirection === "up"
|
|
169
|
-
? -stringHeight
|
|
170
|
-
: component.verticalGrowthDirection === "uniform"
|
|
171
|
-
? -stringHeight * 0.5
|
|
172
|
-
: 0;
|
|
148
|
+
component.verticalGrowthDirection === "up" ? -stringHeight : component.verticalGrowthDirection === "uniform" ? -stringHeight * 0.5 : 0;
|
|
173
149
|
pdf
|
|
174
150
|
.font(font)
|
|
175
151
|
.fontSize(component.fontSize)
|
|
@@ -179,7 +155,8 @@ function abstractComponentToPdf(
|
|
|
179
155
|
pdf.restore();
|
|
180
156
|
}
|
|
181
157
|
break;
|
|
182
|
-
|
|
158
|
+
}
|
|
159
|
+
case "ellipse": {
|
|
183
160
|
const width = component.bottomRight.x - component.topLeft.x;
|
|
184
161
|
const height = component.bottomRight.y - component.topLeft.y;
|
|
185
162
|
const centerX = component.topLeft.x + width * 0.5;
|
|
@@ -192,6 +169,7 @@ function abstractComponentToPdf(
|
|
|
192
169
|
applyStrokeDashStyle(pdf, component.strokeDashStyle);
|
|
193
170
|
pdf.fillAndStroke(colorToRgb(component.fillColor), colorToRgb(component.strokeColor));
|
|
194
171
|
break;
|
|
172
|
+
}
|
|
195
173
|
case "polygon":
|
|
196
174
|
pdf
|
|
197
175
|
.lineWidth(component.strokeThickness)
|
|
@@ -201,7 +179,7 @@ function abstractComponentToPdf(
|
|
|
201
179
|
applyStrokeDashStyle(pdf, component.strokeDashStyle);
|
|
202
180
|
pdf.fillAndStroke(colorToRgb(component.fillColor), colorToRgb(component.strokeColor));
|
|
203
181
|
break;
|
|
204
|
-
case "rectangle":
|
|
182
|
+
case "rectangle": {
|
|
205
183
|
const rWidth = component.bottomRight.x - component.topLeft.x;
|
|
206
184
|
const rHeight = component.bottomRight.y - component.topLeft.y;
|
|
207
185
|
pdf
|
|
@@ -212,6 +190,7 @@ function abstractComponentToPdf(
|
|
|
212
190
|
applyStrokeDashStyle(pdf, component.strokeDashStyle);
|
|
213
191
|
pdf.fillAndStroke(colorToRgb(component.fillColor), colorToRgb(component.strokeColor));
|
|
214
192
|
break;
|
|
193
|
+
}
|
|
215
194
|
default:
|
|
216
195
|
break;
|
|
217
196
|
}
|
|
@@ -232,15 +211,17 @@ function addWithSvgToPdfKit(
|
|
|
232
211
|
let index = 0;
|
|
233
212
|
while (true) {
|
|
234
213
|
index = svgUpdated.indexOf(t, index);
|
|
235
|
-
if (index === -1)
|
|
236
|
-
|
|
237
|
-
|
|
214
|
+
if (index === -1) {
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
const indexStart = svgUpdated.indexOf('"', index);
|
|
218
|
+
const indexEnd = svgUpdated.indexOf('"', indexStart + 1);
|
|
238
219
|
index = indexEnd;
|
|
239
220
|
|
|
240
221
|
const color = svgUpdated.substring(indexStart, indexEnd);
|
|
241
|
-
if (color !== color.toLowerCase() && color.toLowerCase().indexOf("url(") === -1)
|
|
242
|
-
svgUpdated =
|
|
243
|
-
|
|
222
|
+
if (color !== color.toLowerCase() && color.toLowerCase().indexOf("url(") === -1) {
|
|
223
|
+
svgUpdated = svgUpdated.substring(0, indexStart) + color.toLowerCase() + svgUpdated.substring(indexEnd, svgUpdated.length);
|
|
224
|
+
}
|
|
244
225
|
}
|
|
245
226
|
});
|
|
246
227
|
|
|
@@ -248,9 +229,11 @@ function addWithSvgToPdfKit(
|
|
|
248
229
|
let index = 0;
|
|
249
230
|
while (true) {
|
|
250
231
|
index = svgUpdated.indexOf(t, index);
|
|
251
|
-
if (index === -1)
|
|
252
|
-
|
|
253
|
-
|
|
232
|
+
if (index === -1) {
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
const indexStart = svgUpdated.indexOf('"', index) + 1;
|
|
236
|
+
const indexEnd = svgUpdated.indexOf('"', indexStart);
|
|
254
237
|
index = indexEnd;
|
|
255
238
|
|
|
256
239
|
let dasharray = svgUpdated.substring(indexStart, indexEnd);
|
|
@@ -428,5 +411,5 @@ function applyStrokeDashStyle(pdf: PDFKit.PDFDocument, dashStyle: AbstractImage.
|
|
|
428
411
|
}
|
|
429
412
|
}
|
|
430
413
|
|
|
431
|
-
(pdf as { dash: (length: number | ReadonlyArray<number>, option:
|
|
414
|
+
(pdf as { dash: (length: number | ReadonlyArray<number>, option: { phase: number }) => PDFKit.PDFDocument }).dash(dashes, { phase: phase });
|
|
432
415
|
}
|