abstract-document 11.0.0 → 11.0.2
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 +6 -0
- package/lib/abstract-document-exporters/pdf/font.d.ts +1 -1
- package/lib/abstract-document-exporters/pdf/font.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.js +19 -19
- package/lib/abstract-document-exporters/pdf/font.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.d.ts +4 -3
- package/lib/abstract-document-exporters/pdf/measure.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.js +24 -24
- package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.d.ts +2 -1
- package/lib/abstract-document-exporters/pdf/paginate.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.js +3 -7
- package/lib/abstract-document-exporters/pdf/paginate.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.d.ts +2 -1
- package/lib/abstract-document-exporters/pdf/render-image.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.js +2 -8
- package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.d.ts +3 -2
- package/lib/abstract-document-exporters/pdf/render.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.js +26 -36
- package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
- package/package.json +3 -3
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Group.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Header and footer.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Header → footer.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed hyperlink and textrun.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed hyperlink → textrun.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed textrun and images.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed textrun → images.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple images.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple tables.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Center alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with End alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Start alignment that linebreaks.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Start alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Page numbering.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table colSpan and rowSpan.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table colSpan → rowSpan.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table without rows.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single hyperlink.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single image.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Center alignment that linebreaks.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Center alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with End alignment that linebreaks.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with End alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Start alignment that linebreaks.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Start alignment.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/hello with Arial font.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/hello.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/letter-dimensions.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/page-orientation-landscape.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/page-orientation-portrait.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/tocSeparator.docx +0 -0
- package/src/abstract-document-exporters/__tests__/docx2/tmp/world.docx +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position group.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position header and footer.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position paragraph.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position section in group.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position section in table.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position table.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group Paragraphs.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group Tables.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group no keeptogether.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Group too big for one page.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Header and footer.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Hyperlink internal linktarget.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Hyperlink internal.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Manual line break.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Manual line breaks empty lines.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun no underline.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun with underline.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed textrun and images.pdf and b/package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed textrun → images.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple images overflow.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple images.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Center alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with End alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Start alignment that linebreaks.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Start alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Page numbering.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table row that doesnt fit page.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table single row.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with group.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with header 2.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with header.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin bottom.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin top single table.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin top.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with rowSpan multipages.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with rowSpan.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table all auto.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table all fix.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table background.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table cell padding of image.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table cell padding of text.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table center alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table colSpan and rowSpan.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table minimal row height.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table mix auto fix.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table padding.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table right alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table row alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table text alignment in cell with wrapping.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table text alignment in cell.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with default colored borders.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with header.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with multi colored borders.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with single colored borders.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single date.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single figure.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink centered.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink no underline.pdf +17 -19
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink right aligned.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image from URL.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color hex.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color name.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color url.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg dasharray.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image.pdf +0 -0
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline alphabetic.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline bottom.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline hanging.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline middle.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline top.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Center alignment that linebreaks.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Center alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with End alignment that linebreaks.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with End alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Justify alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Start alignment that linebreaks.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Start alignment.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with super and subscripts.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/Table of content separator.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/hello with roman font.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/hello.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/pagebreak.pdf +2 -2
- package/src/abstract-document-exporters/__tests__/pdf/tmp/world.pdf +2 -2
- package/src/abstract-document-exporters/pdf/font.ts +19 -20
- package/src/abstract-document-exporters/pdf/measure.ts +34 -30
- package/src/abstract-document-exporters/pdf/paginate.ts +15 -14
- package/src/abstract-document-exporters/pdf/render-image.ts +4 -7
- package/src/abstract-document-exporters/pdf/render.ts +72 -54
|
@@ -3,29 +3,28 @@ import { TextFontWeight } from "../../abstract-document/styles/text-style";
|
|
|
3
3
|
import { getResources } from "../shared/get_resources";
|
|
4
4
|
|
|
5
5
|
export function registerFonts(
|
|
6
|
-
registerFont: (fontName: string, fontSource: AD.Font.FontSource) => void,
|
|
6
|
+
registerFont: (fontName: string, fontSource: AD.Font.FontSource, fontFamily?: string) => void,
|
|
7
7
|
document: AD.AbstractDoc.AbstractDoc
|
|
8
8
|
): void {
|
|
9
9
|
const resources = getResources(document);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
10
|
+
for (const [fontName, font] of Object.entries(resources.fonts ?? {})) {
|
|
11
|
+
// Required
|
|
12
|
+
registerFont(fontName, font.normal);
|
|
13
|
+
registerFont(fontName + "-Bold", font.bold);
|
|
14
|
+
registerFont(fontName + "-Oblique", font.italic);
|
|
15
|
+
registerFont(fontName + "-Italic", font.italic);
|
|
16
|
+
registerFont(fontName + "-BoldOblique", font.boldItalic);
|
|
17
|
+
registerFont(fontName + "-BoldItalic", font.boldItalic);
|
|
18
|
+
// Optional
|
|
19
|
+
registerFont(fontName + "-Light", font.light || font.normal);
|
|
20
|
+
registerFont(fontName + "-Medium", font.medium || font.normal);
|
|
21
|
+
registerFont(fontName + "-ExtraBold", font.extraBold || font.bold);
|
|
22
|
+
registerFont(fontName + "-LightOblique", font.lightItalic || font.normal);
|
|
23
|
+
registerFont(fontName + "-LightItalic", font.lightItalic || font.normal);
|
|
24
|
+
registerFont(fontName + "-MediumOblique", font.mediumItalic || font.italic);
|
|
25
|
+
registerFont(fontName + "-MediumItalic", font.mediumItalic || font.italic);
|
|
26
|
+
registerFont(fontName + "-ExtraBoldItalic", font.extraBoldItalic || font.boldItalic);
|
|
27
|
+
registerFont(fontName + "-ExtraBoldOblique", font.extraBoldItalic || font.boldItalic);
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
|
|
@@ -5,26 +5,30 @@ import { registerFonts, getFontNameStyle } from "./font";
|
|
|
5
5
|
|
|
6
6
|
//tslint:disable:no-any variable-name
|
|
7
7
|
|
|
8
|
-
export function measure(
|
|
9
|
-
let pdf = new
|
|
8
|
+
export function measure(pdfKit: PDFKit.PDFDocument, document: AD.AbstractDoc.AbstractDoc): Map<any, AD.Size.Size> {
|
|
9
|
+
let pdf = new pdfKit();
|
|
10
10
|
registerFonts((fontName: string, fontSource: AD.Font.FontSource) => pdf.registerFont(fontName, fontSource), document);
|
|
11
11
|
return mergeMaps(document.children.map((s) => measureSection(pdf, document, s)));
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function measurePages(
|
|
15
|
-
|
|
15
|
+
pdfKit: PDFKit.PDFDocument,
|
|
16
16
|
document: AD.AbstractDoc.AbstractDoc,
|
|
17
17
|
pages: ReadonlyArray<Page>
|
|
18
18
|
): Map<any, AD.Size.Size> {
|
|
19
|
-
let pdf = new
|
|
20
|
-
registerFonts(
|
|
19
|
+
let pdf = new pdfKit();
|
|
20
|
+
registerFonts(
|
|
21
|
+
(fontName: string, fontSource: AD.Font.FontSource, fontFamily: string) =>
|
|
22
|
+
pdf.registerFont(fontName, fontSource, fontFamily),
|
|
23
|
+
document
|
|
24
|
+
);
|
|
21
25
|
return mergeMaps(
|
|
22
26
|
pages.map((page) => measureSection(pdf, document, page.section, page.header, page.footer, page.elements))
|
|
23
27
|
);
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
function measureSection(
|
|
27
|
-
|
|
31
|
+
pdfKit: PDFKit.PDFDocument,
|
|
28
32
|
parentResources: AD.Resources.Resources,
|
|
29
33
|
section: AD.Section.Section,
|
|
30
34
|
separateHeader?: ReadonlyArray<AD.SectionElement.SectionElement>,
|
|
@@ -42,23 +46,23 @@ function measureSection(
|
|
|
42
46
|
const contentAvailableWidth =
|
|
43
47
|
pageWidth - (section.page.style.contentMargins.left + section.page.style.contentMargins.right);
|
|
44
48
|
const contentAvailableSize = AD.Size.create(contentAvailableWidth, pageHeight);
|
|
45
|
-
const sectionSizes = children.map((e) => measureSectionElement(
|
|
49
|
+
const sectionSizes = children.map((e) => measureSectionElement(pdfKit, resources, contentAvailableSize, e));
|
|
46
50
|
|
|
47
51
|
const headerAvailableWidth =
|
|
48
52
|
pageWidth - (section.page.style.headerMargins.left + section.page.style.headerMargins.right);
|
|
49
53
|
const headerAvailableSize = AD.Size.create(headerAvailableWidth, pageHeight);
|
|
50
|
-
const headerSizes = header.map((e) => measureSectionElement(
|
|
54
|
+
const headerSizes = header.map((e) => measureSectionElement(pdfKit, resources, headerAvailableSize, e));
|
|
51
55
|
|
|
52
56
|
const footerAvailableWidth =
|
|
53
57
|
pageWidth - (section.page.style.footerMargins.left + section.page.style.footerMargins.right);
|
|
54
58
|
const footerAvailableSize = AD.Size.create(footerAvailableWidth, pageHeight);
|
|
55
|
-
const footerSizes = footer.map((e) => measureSectionElement(
|
|
59
|
+
const footerSizes = footer.map((e) => measureSectionElement(pdfKit, resources, footerAvailableSize, e));
|
|
56
60
|
|
|
57
61
|
return mergeMaps([...sectionSizes, ...headerSizes, ...footerSizes]);
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
function measureSectionElement(
|
|
61
|
-
pdf:
|
|
65
|
+
pdf: PDFKit.PDFDocument,
|
|
62
66
|
parentResources: AD.Resources.Resources,
|
|
63
67
|
availableSize: AD.Size.Size,
|
|
64
68
|
element: AD.SectionElement.SectionElement
|
|
@@ -85,7 +89,7 @@ function measurePageBreak(availableSize: AD.Size.Size, pageBreak: AD.PageBreak.P
|
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
function measureParagraph(
|
|
88
|
-
|
|
92
|
+
pdfKit: PDFKit.PDFDocument,
|
|
89
93
|
resources: AD.Resources.Resources,
|
|
90
94
|
availableSize: AD.Size.Size,
|
|
91
95
|
paragraph: AD.Paragraph.Paragraph
|
|
@@ -129,7 +133,7 @@ function measureParagraph(
|
|
|
129
133
|
hasAtomImage = true;
|
|
130
134
|
}
|
|
131
135
|
const atomSize = measureAtom(
|
|
132
|
-
|
|
136
|
+
pdfKit,
|
|
133
137
|
resources,
|
|
134
138
|
style.textStyle,
|
|
135
139
|
contentAvailableSize,
|
|
@@ -154,7 +158,7 @@ function measureParagraph(
|
|
|
154
158
|
} else if (hasAtomImage) {
|
|
155
159
|
paragraphHeight += desiredHeight + currentRowHeight;
|
|
156
160
|
} else {
|
|
157
|
-
paragraphHeight +=
|
|
161
|
+
paragraphHeight += pdfKit.heightOfString(concatenatedText, {
|
|
158
162
|
width: textOptions && textOptions.lineBreak === false ? Infinity : availableSize.width,
|
|
159
163
|
...textOptions,
|
|
160
164
|
});
|
|
@@ -192,7 +196,7 @@ function getBiggestStyle(
|
|
|
192
196
|
}
|
|
193
197
|
|
|
194
198
|
export function measureTable(
|
|
195
|
-
|
|
199
|
+
pdfKit: PDFKit.PDFDocument,
|
|
196
200
|
resources: AD.Resources.Resources,
|
|
197
201
|
availableSize: AD.Size.Size,
|
|
198
202
|
table: AD.Table.Table
|
|
@@ -228,7 +232,7 @@ export function measureTable(
|
|
|
228
232
|
|
|
229
233
|
for (let element of cell.children) {
|
|
230
234
|
const elementAvailableSize = AD.Size.create(contentAvailableWidth, Infinity);
|
|
231
|
-
const elementSizes = measureSectionElement(
|
|
235
|
+
const elementSizes = measureSectionElement(pdfKit, resources, elementAvailableSize, element);
|
|
232
236
|
elementSizes.forEach((v, k) => desiredSizes.set(k, v));
|
|
233
237
|
const elementSize = getDesiredSize(element, desiredSizes);
|
|
234
238
|
if (!AD.Position.isPositionAbsolute(element)) {
|
|
@@ -290,13 +294,13 @@ export function measureTable(
|
|
|
290
294
|
}
|
|
291
295
|
|
|
292
296
|
function measureGroup(
|
|
293
|
-
|
|
297
|
+
pdfKit: PDFKit.PDFDocument,
|
|
294
298
|
resources: AD.Resources.Resources,
|
|
295
299
|
availableSize: AD.Size.Size,
|
|
296
300
|
keepTogether: AD.Group.Group
|
|
297
301
|
): Map<any, AD.Size.Size> {
|
|
298
302
|
let desiredSizes = mergeMaps(
|
|
299
|
-
keepTogether.children.map((e) => measureSectionElement(
|
|
303
|
+
keepTogether.children.map((e) => measureSectionElement(pdfKit, resources, availableSize, e))
|
|
300
304
|
);
|
|
301
305
|
let desiredHeight = keepTogether.children.reduce(
|
|
302
306
|
(sum, e) => sum + (AD.Position.isPositionAbsolute(e) ? 0 : getDesiredSize(e, desiredSizes).height),
|
|
@@ -307,7 +311,7 @@ function measureGroup(
|
|
|
307
311
|
}
|
|
308
312
|
|
|
309
313
|
function measureAtom(
|
|
310
|
-
|
|
314
|
+
pdfKit: PDFKit.PDFDocument,
|
|
311
315
|
resources: AD.Resources.Resources,
|
|
312
316
|
textStyle: AD.TextStyle.TextStyle,
|
|
313
317
|
availableSize: AD.Size.Size,
|
|
@@ -316,17 +320,17 @@ function measureAtom(
|
|
|
316
320
|
): AD.Size.Size {
|
|
317
321
|
switch (atom.type) {
|
|
318
322
|
case "TextRun":
|
|
319
|
-
return measureTextRun(
|
|
323
|
+
return measureTextRun(pdfKit, resources, textStyle, atom, availableSize);
|
|
320
324
|
case "TextField":
|
|
321
|
-
return measureTextField(
|
|
325
|
+
return measureTextField(pdfKit, resources, textStyle, atom, availableSize);
|
|
322
326
|
case "Image":
|
|
323
327
|
return measureImage(availableSize, atom);
|
|
324
328
|
case "HyperLink":
|
|
325
|
-
return measureHyperLink(
|
|
329
|
+
return measureHyperLink(pdfKit, resources, textStyle, atom, availableSize);
|
|
326
330
|
case "TocSeparator":
|
|
327
|
-
return measureTocSeparator(
|
|
331
|
+
return measureTocSeparator(pdfKit, textStyle, availableSize, availableRowSpace);
|
|
328
332
|
case "LineBreak":
|
|
329
|
-
return measureLineBreak(
|
|
333
|
+
return measureLineBreak(pdfKit, resources, textStyle, availableSize);
|
|
330
334
|
case "LinkTarget":
|
|
331
335
|
return {
|
|
332
336
|
width: availableSize.width,
|
|
@@ -338,12 +342,12 @@ function measureAtom(
|
|
|
338
342
|
}
|
|
339
343
|
|
|
340
344
|
function measureLineBreak(
|
|
341
|
-
|
|
345
|
+
pdfKit: PDFKit.PDFDocument,
|
|
342
346
|
resources: AD.Resources.Resources,
|
|
343
347
|
textStyle: AD.TextStyle.TextStyle,
|
|
344
348
|
availableSize: AD.Size.Size
|
|
345
349
|
): AD.Size.Size {
|
|
346
|
-
const textSize = measureText(
|
|
350
|
+
const textSize = measureText(pdfKit, "A", textStyle, availableSize);
|
|
347
351
|
return {
|
|
348
352
|
height: textSize.height,
|
|
349
353
|
width: 0,
|
|
@@ -351,7 +355,7 @@ function measureLineBreak(
|
|
|
351
355
|
}
|
|
352
356
|
|
|
353
357
|
function measureTextRun(
|
|
354
|
-
pdf:
|
|
358
|
+
pdf: PDFKit.PDFDocument,
|
|
355
359
|
resources: AD.Resources.Resources,
|
|
356
360
|
textStyle: AD.TextStyle.TextStyle,
|
|
357
361
|
textRun: AD.TextRun.TextRun,
|
|
@@ -369,7 +373,7 @@ function measureTextRun(
|
|
|
369
373
|
}
|
|
370
374
|
|
|
371
375
|
function measureHyperLink(
|
|
372
|
-
pdf:
|
|
376
|
+
pdf: PDFKit.PDFDocument,
|
|
373
377
|
resources: AD.Resources.Resources,
|
|
374
378
|
textStyle: AD.TextStyle.TextStyle,
|
|
375
379
|
hyperLink: AD.HyperLink.HyperLink,
|
|
@@ -386,7 +390,7 @@ function measureHyperLink(
|
|
|
386
390
|
}
|
|
387
391
|
|
|
388
392
|
function measureTextField(
|
|
389
|
-
pdf:
|
|
393
|
+
pdf: PDFKit.PDFDocument,
|
|
390
394
|
resources: AD.Resources.Resources,
|
|
391
395
|
textStyle: AD.TextStyle.TextStyle,
|
|
392
396
|
textField: AD.TextField.TextField,
|
|
@@ -412,7 +416,7 @@ function measureTextField(
|
|
|
412
416
|
}
|
|
413
417
|
|
|
414
418
|
function measureTocSeparator(
|
|
415
|
-
pdf:
|
|
419
|
+
pdf: PDFKit.PDFDocument,
|
|
416
420
|
textStyle: AD.TextStyle.TextStyle,
|
|
417
421
|
availableSize: AD.Size.Size,
|
|
418
422
|
availableRowSpace: number
|
|
@@ -431,7 +435,7 @@ function measureImage(availableSize: AD.Size.Size, image: AD.Image.Image): AD.Si
|
|
|
431
435
|
}
|
|
432
436
|
|
|
433
437
|
function measureText(
|
|
434
|
-
pdf:
|
|
438
|
+
pdf: PDFKit.PDFDocument,
|
|
435
439
|
text: string,
|
|
436
440
|
textStyle: AD.TextStyle.TextStyle,
|
|
437
441
|
availableSize: AD.Size.Size
|
|
@@ -3,8 +3,6 @@ import { getResources } from "../shared/get_resources";
|
|
|
3
3
|
import { registerFonts } from "./font";
|
|
4
4
|
import { measureTable } from "./measure";
|
|
5
5
|
|
|
6
|
-
/* tslint:disable:no-any */
|
|
7
|
-
|
|
8
6
|
export interface Page {
|
|
9
7
|
readonly pageNo: number;
|
|
10
8
|
readonly namedDestionations: ReadonlyArray<string>;
|
|
@@ -17,19 +15,18 @@ export interface Page {
|
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
export function paginate(
|
|
20
|
-
pdfKit:
|
|
18
|
+
pdfKit: PDFKit.PDFDocument,
|
|
21
19
|
document: AD.AbstractDoc.AbstractDoc,
|
|
22
20
|
desiredSizes: Map<any, AD.Size.Size>
|
|
23
21
|
): ReadonlyArray<Page> {
|
|
24
22
|
const resources = getResources(document);
|
|
25
|
-
let pdf = new pdfKit({
|
|
26
|
-
compress: false,
|
|
27
|
-
autoFirstPage: false,
|
|
28
|
-
bufferPages: true,
|
|
29
|
-
}) as any;
|
|
30
|
-
|
|
31
|
-
registerFonts((fontName: string, fontSource: AD.Font.FontSource) => pdf.registerFont(fontName, fontSource), document);
|
|
23
|
+
let pdf = new pdfKit({ compress: false, autoFirstPage: false, bufferPages: true });
|
|
32
24
|
|
|
25
|
+
registerFonts(
|
|
26
|
+
(fontName: string, fontSource: AD.Font.FontSource, fontFamily: string) =>
|
|
27
|
+
pdf.registerFont(fontName, fontSource, fontFamily),
|
|
28
|
+
document
|
|
29
|
+
);
|
|
33
30
|
let pages = new Array<Page>();
|
|
34
31
|
for (let section of document.children) {
|
|
35
32
|
const previousPage = pages.length > 0 ? pages[pages.length - 1] : undefined;
|
|
@@ -40,7 +37,7 @@ export function paginate(
|
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
function splitSection(
|
|
43
|
-
pdfKit:
|
|
40
|
+
pdfKit: PDFKit.PDFDocument,
|
|
44
41
|
document: AD.AbstractDoc.AbstractDoc,
|
|
45
42
|
parentResources: AD.Resources.Resources,
|
|
46
43
|
desiredSizes: Map<{}, AD.Size.Size>,
|
|
@@ -138,7 +135,7 @@ function splitSection(
|
|
|
138
135
|
}
|
|
139
136
|
|
|
140
137
|
function splitTable(
|
|
141
|
-
pdfKit:
|
|
138
|
+
pdfKit: PDFKit.PDFDocument,
|
|
142
139
|
document: AD.AbstractDoc.AbstractDoc,
|
|
143
140
|
resources: AD.Resources.Resources,
|
|
144
141
|
desiredSizes: Map<{}, AD.Size.Size>,
|
|
@@ -370,7 +367,7 @@ function getDesiredSize(element: {}, desiredSizes: Map<{}, AD.Size.Size>): AD.Si
|
|
|
370
367
|
}
|
|
371
368
|
|
|
372
369
|
function splitTableAt(
|
|
373
|
-
pdfKit:
|
|
370
|
+
pdfKit: PDFKit.PDFDocument,
|
|
374
371
|
document: AD.AbstractDoc.AbstractDoc,
|
|
375
372
|
resources: AD.Resources.Resources,
|
|
376
373
|
desiredSizes: Map<{}, AD.Size.Size>,
|
|
@@ -420,7 +417,11 @@ function splitTableAt(
|
|
|
420
417
|
|
|
421
418
|
const availableSize = getDesiredSize(table, desiredSizes);
|
|
422
419
|
let pdf = new pdfKit();
|
|
423
|
-
registerFonts(
|
|
420
|
+
registerFonts(
|
|
421
|
+
(fontName: string, fontSource: AD.Font.FontSource, fontFamily: string) =>
|
|
422
|
+
pdf.registerFont(fontName, fontSource, fontFamily),
|
|
423
|
+
document
|
|
424
|
+
);
|
|
424
425
|
const headSizes = measureTable(pdf, resources, availableSize, tableHead);
|
|
425
426
|
const tailSizes = measureTable(pdf, resources, availableSize, tableTail);
|
|
426
427
|
|
|
@@ -6,13 +6,11 @@ import { getFontNameStyle, getFontName, isFontAvailable } from "./font";
|
|
|
6
6
|
|
|
7
7
|
export function renderImage(
|
|
8
8
|
resources: AD.Resources.Resources,
|
|
9
|
-
|
|
10
|
-
pdf: any,
|
|
9
|
+
pdf: PDFKit.PDFDocument,
|
|
11
10
|
finalRect: AD.Rect.Rect,
|
|
12
11
|
textStyle: AD.TextStyle.TextStyle,
|
|
13
12
|
image: AD.Image.Image
|
|
14
|
-
|
|
15
|
-
): any {
|
|
13
|
+
): void {
|
|
16
14
|
const aImage = image.imageResource.abstractImage;
|
|
17
15
|
const position = AD.Point.create(finalRect.x, finalRect.y);
|
|
18
16
|
const scaleX = finalRect.width / aImage.size.width;
|
|
@@ -26,8 +24,7 @@ export function renderImage(
|
|
|
26
24
|
|
|
27
25
|
function abstractComponentToPdf(
|
|
28
26
|
resources: AD.Resources.Resources,
|
|
29
|
-
|
|
30
|
-
pdf: any,
|
|
27
|
+
pdf: PDFKit.PDFDocument,
|
|
31
28
|
component: AbstractImage.Component,
|
|
32
29
|
textStyle: AD.TextStyle.TextStyle
|
|
33
30
|
): void {
|
|
@@ -213,6 +210,6 @@ function colorToOpacity(color: AbstractImage.Color): number {
|
|
|
213
210
|
return color.a / 255;
|
|
214
211
|
}
|
|
215
212
|
|
|
216
|
-
function colorToRgb(color: AbstractImage.Color):
|
|
213
|
+
function colorToRgb(color: AbstractImage.Color): [number, number, number] {
|
|
217
214
|
return [color.r, color.g, color.b];
|
|
218
215
|
}
|