documents.js 1.102.2 → 2.0.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/README.md +8 -5
- package/dist/convert/composition.cjs +15 -4
- package/dist/convert/composition.js +15 -4
- package/dist/convert/convert.cjs +6 -3
- package/dist/convert/convert.js +6 -3
- package/dist/convert/from-package.cjs +179 -2
- package/dist/convert/from-package.d.cts +3 -2
- package/dist/convert/from-package.d.ts +3 -2
- package/dist/convert/from-package.js +179 -3
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/layout/drawing.cjs +71 -9
- package/dist/layout/drawing.d.cts +8 -3
- package/dist/layout/drawing.d.ts +8 -3
- package/dist/layout/drawing.js +71 -10
- package/dist/layout/engine.cjs +55 -43
- package/dist/layout/engine.d.cts +2 -1
- package/dist/layout/engine.d.ts +2 -1
- package/dist/layout/engine.js +57 -45
- package/dist/layout/reconstruct.cjs +259 -104
- package/dist/layout/reconstruct.js +259 -104
- package/dist/layout/shared.cjs +47 -2
- package/dist/layout/shared.d.cts +15 -4
- package/dist/layout/shared.d.ts +15 -4
- package/dist/layout/shared.js +44 -4
- package/dist/layout/sheets.cjs +18 -13
- package/dist/layout/sheets.d.cts +4 -2
- package/dist/layout/sheets.d.ts +4 -2
- package/dist/layout/sheets.js +20 -16
- package/dist/layout/slides.cjs +35 -31
- package/dist/layout/slides.d.cts +3 -2
- package/dist/layout/slides.d.ts +3 -2
- package/dist/layout/slides.js +37 -33
- package/dist/layout/text-layout.cjs +2 -1
- package/dist/layout/text-layout.d.cts +14 -3
- package/dist/layout/text-layout.d.ts +14 -3
- package/dist/layout/text-layout.js +2 -1
- package/package.json +5 -5
package/dist/layout/engine.cjs
CHANGED
|
@@ -51,20 +51,26 @@ function layoutParagraphFlow(paragraph, section, pages, state, contentLeftXDown,
|
|
|
51
51
|
lines.forEach((line, lineIndex) => {
|
|
52
52
|
const lineHeightPt = require_layout_shared.lineNaturalHeightPt(line, measurer, fallbackRun) * (paragraph.lineSpacing ?? 1);
|
|
53
53
|
ensureRoom(state, section, pages, lineHeightPt, contentBottomYDown);
|
|
54
|
+
const pageIndex = pages.length;
|
|
54
55
|
const baselineYDown = state.cursorYDown + line.ascentPt;
|
|
55
56
|
const firstLineIndentPt = lineIndex === 0 ? paragraph.indentFirstLinePt ?? 0 : 0;
|
|
56
57
|
const alignOffsetPt = require_layout_shared.alignmentOffsetPt(paragraph.alignment, paragraphWidthPt, line.widthPt);
|
|
57
58
|
const justifyGapsPt = paragraph.alignment === "justify" && lineIndex < lines.length - 1 ? require_layout_shared.justifyLineGapsPt(line, paragraphWidthPt, measurer) : void 0;
|
|
58
|
-
if (lineIndex === 0 && paragraph.list !== void 0)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
if (lineIndex === 0 && paragraph.list !== void 0) {
|
|
60
|
+
const markerText = listMarkerText(paragraph.list, listCounters);
|
|
61
|
+
const markerItem = {
|
|
62
|
+
kind: "text",
|
|
63
|
+
text: markerText,
|
|
64
|
+
xPt: paragraphLeftXDown - LIST_INDENT_STEP_PT,
|
|
65
|
+
yPt: section.pageSize.heightPt - baselineYDown,
|
|
66
|
+
font: fallbackRun.font,
|
|
67
|
+
sizePt: fallbackRun.sizePt,
|
|
68
|
+
color: fallbackRun.color,
|
|
69
|
+
sourcePath: paragraph.sourcePath
|
|
70
|
+
};
|
|
71
|
+
state.items.push(markerItem);
|
|
72
|
+
require_layout_shared.stampFrame(paragraph, pageIndex, require_layout_shared.textBoxForFragment(markerItem, measurer.widthOfTextAtSize(markerText, fallbackRun.font, fallbackRun.sizePt), line.ascentPt, line.descentPt));
|
|
73
|
+
}
|
|
68
74
|
line.fragments.forEach((fragment, fragmentIndex) => {
|
|
69
75
|
const xPt = paragraphLeftXDown + firstLineIndentPt + alignOffsetPt + fragment.xOffsetPt + (justifyGapsPt?.[fragmentIndex] ?? 0);
|
|
70
76
|
const yPt = section.pageSize.heightPt - baselineYDown;
|
|
@@ -80,6 +86,7 @@ function layoutParagraphFlow(paragraph, section, pages, state, contentLeftXDown,
|
|
|
80
86
|
sourcePath: fragment.sourcePath
|
|
81
87
|
};
|
|
82
88
|
state.items.push(textItem);
|
|
89
|
+
require_layout_shared.stampFragmentFrame(paragraph.runs, fragment, pageIndex, textItem, measurer, line);
|
|
83
90
|
if (fragment.hyperlink !== void 0) {
|
|
84
91
|
const fragmentWidthPt = measurer.widthOfTextAtSize(fragment.text, fragment.font, fragment.sizePt);
|
|
85
92
|
const link = {
|
|
@@ -98,7 +105,7 @@ function layoutParagraphFlow(paragraph, section, pages, state, contentLeftXDown,
|
|
|
98
105
|
});
|
|
99
106
|
state.cursorYDown += paragraph.spacingAfterPt ?? 0;
|
|
100
107
|
}
|
|
101
|
-
function layoutParagraphInCell(paragraph, cellLeftXDown, cellWidthPt, startYDown, pageHeightPt, measurer, out, listCounters) {
|
|
108
|
+
function layoutParagraphInCell(paragraph, cellLeftXDown, cellWidthPt, startYDown, pageHeightPt, pageIndex, measurer, out, listCounters) {
|
|
102
109
|
let cursorYDown = startYDown + (paragraph.spacingBeforePt ?? 0);
|
|
103
110
|
const effectiveRuns = require_layout_shared.effectiveStyledRuns(paragraph.runs, 1, require_layout_shared.headingStyleFor(paragraph.styleId));
|
|
104
111
|
const fallbackRun = effectiveRuns[0];
|
|
@@ -112,18 +119,23 @@ function layoutParagraphInCell(paragraph, cellLeftXDown, cellWidthPt, startYDown
|
|
|
112
119
|
const firstLineIndentPt = lineIndex === 0 ? paragraph.indentFirstLinePt ?? 0 : 0;
|
|
113
120
|
const alignOffsetPt = require_layout_shared.alignmentOffsetPt(paragraph.alignment, paragraphWidthPt, line.widthPt);
|
|
114
121
|
const justifyGapsPt = paragraph.alignment === "justify" && lineIndex < lines.length - 1 ? require_layout_shared.justifyLineGapsPt(line, paragraphWidthPt, measurer) : void 0;
|
|
115
|
-
if (lineIndex === 0 && paragraph.list !== void 0)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
if (lineIndex === 0 && paragraph.list !== void 0) {
|
|
123
|
+
const markerText = listMarkerText(paragraph.list, listCounters);
|
|
124
|
+
const markerItem = {
|
|
125
|
+
kind: "text",
|
|
126
|
+
text: markerText,
|
|
127
|
+
xPt: paragraphLeftXDown - LIST_INDENT_STEP_PT,
|
|
128
|
+
yPt: pageHeightPt - baselineYDown,
|
|
129
|
+
font: fallbackRun.font,
|
|
130
|
+
sizePt: fallbackRun.sizePt,
|
|
131
|
+
color: fallbackRun.color,
|
|
132
|
+
sourcePath: paragraph.sourcePath
|
|
133
|
+
};
|
|
134
|
+
out.push(markerItem);
|
|
135
|
+
require_layout_shared.stampFrame(paragraph, pageIndex, require_layout_shared.textBoxForFragment(markerItem, measurer.widthOfTextAtSize(markerText, fallbackRun.font, fallbackRun.sizePt), line.ascentPt, line.descentPt));
|
|
136
|
+
}
|
|
125
137
|
line.fragments.forEach((fragment, fragmentIndex) => {
|
|
126
|
-
|
|
138
|
+
const textItem = {
|
|
127
139
|
kind: "text",
|
|
128
140
|
text: fragment.text,
|
|
129
141
|
xPt: paragraphLeftXDown + firstLineIndentPt + alignOffsetPt + fragment.xOffsetPt + (justifyGapsPt?.[fragmentIndex] ?? 0),
|
|
@@ -133,7 +145,9 @@ function layoutParagraphInCell(paragraph, cellLeftXDown, cellWidthPt, startYDown
|
|
|
133
145
|
color: fragment.color,
|
|
134
146
|
underline: fragment.underline,
|
|
135
147
|
sourcePath: fragment.sourcePath
|
|
136
|
-
}
|
|
148
|
+
};
|
|
149
|
+
out.push(textItem);
|
|
150
|
+
require_layout_shared.stampFragmentFrame(paragraph.runs, fragment, pageIndex, textItem, measurer, line);
|
|
137
151
|
});
|
|
138
152
|
cursorYDown += lineHeightPt;
|
|
139
153
|
});
|
|
@@ -145,6 +159,7 @@ function layoutTableFlow(table, section, pages, state, contentLeftXDown, content
|
|
|
145
159
|
for (const row of table.rows) {
|
|
146
160
|
const rowHeightPt = row.heightPt ?? require_layout_shared.estimateRowHeightPt(row, measurer, table.columnWidthsPt, scale);
|
|
147
161
|
ensureRoom(state, section, pages, rowHeightPt, contentBottomYDown);
|
|
162
|
+
const pageIndex = pages.length;
|
|
148
163
|
let cellXDown = contentLeftXDown;
|
|
149
164
|
let colIndex = 0;
|
|
150
165
|
for (const cell of row.cells) {
|
|
@@ -157,21 +172,20 @@ function layoutTableFlow(table, section, pages, state, contentLeftXDown, content
|
|
|
157
172
|
heightPt: rowHeightPt
|
|
158
173
|
};
|
|
159
174
|
const cellSourcePath = cell.sourcePath ?? table.sourcePath;
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
175
|
+
const cellFrame = require_model_geometry.flipY(cellFrameYDown, section.pageSize.heightPt);
|
|
176
|
+
require_layout_shared.stampFrame(cell, pageIndex, cellFrame);
|
|
177
|
+
if (cell.background !== void 0) state.items.push({
|
|
178
|
+
kind: "rect",
|
|
179
|
+
xPt: cellFrame.xPt,
|
|
180
|
+
yPt: cellFrame.yPt,
|
|
181
|
+
widthPt: cellFrame.widthPt,
|
|
182
|
+
heightPt: cellFrame.heightPt,
|
|
183
|
+
fill: cell.background,
|
|
184
|
+
sourcePath: cellSourcePath
|
|
185
|
+
});
|
|
172
186
|
if (cell.borders !== void 0) require_layout_shared.pushCellBorderLines(cell.borders, cellFrameYDown, section.pageSize.heightPt, cellSourcePath, state.items);
|
|
173
187
|
let cellCursorYDown = state.cursorYDown;
|
|
174
|
-
for (const block of cell.blocks) if (block.kind === "paragraph") cellCursorYDown = layoutParagraphInCell(block, cellXDown, cellWidthPt, cellCursorYDown, section.pageSize.heightPt, measurer, state.items, listCounters);
|
|
188
|
+
for (const block of cell.blocks) if (block.kind === "paragraph") cellCursorYDown = layoutParagraphInCell(block, cellXDown, cellWidthPt, cellCursorYDown, section.pageSize.heightPt, pageIndex, measurer, state.items, listCounters);
|
|
175
189
|
cellXDown += cellWidthPt;
|
|
176
190
|
colIndex += span;
|
|
177
191
|
}
|
|
@@ -197,6 +211,7 @@ function layoutImageFlow(block, section, pages, state, contentLeftXDown, content
|
|
|
197
211
|
sourcePath: block.sourcePath
|
|
198
212
|
};
|
|
199
213
|
state.items.push(imageItem);
|
|
214
|
+
require_layout_shared.stampFrame(block, pages.length, flippedFrame);
|
|
200
215
|
state.cursorYDown += block.heightPt;
|
|
201
216
|
}
|
|
202
217
|
function layoutFormulaFallback(block, section, pages, state, contentLeftXDown, contentWidthPt, contentBottomYDown, measurer, listCounters) {
|
|
@@ -233,6 +248,7 @@ function layoutFormulaFlow(block, section, pages, state, contentLeftXDown, conte
|
|
|
233
248
|
yPt: flippedFrame.yPt,
|
|
234
249
|
box
|
|
235
250
|
});
|
|
251
|
+
require_layout_shared.stampFrame(block, pages.length, flippedFrame);
|
|
236
252
|
state.cursorYDown += box.heightPt;
|
|
237
253
|
}
|
|
238
254
|
function paginateSection(section, measurer, images, pages, options, formulas, listCounters) {
|
|
@@ -255,13 +271,9 @@ function convertWordprocessingToLayout(doc, options) {
|
|
|
255
271
|
const listCounters = /* @__PURE__ */ new Map();
|
|
256
272
|
for (const section of doc.sections) paginateSection(section, options.measurer, images, pages, options, formulas, listCounters);
|
|
257
273
|
return {
|
|
258
|
-
document:
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
pages,
|
|
262
|
-
images
|
|
263
|
-
},
|
|
264
|
-
formulas
|
|
274
|
+
document: require_layout_shared.layoutDocumentOf(doc.metadata, pages, images),
|
|
275
|
+
formulas,
|
|
276
|
+
pages: require_layout_shared.packagePagesOf(pages)
|
|
265
277
|
};
|
|
266
278
|
}
|
|
267
279
|
//#endregion
|
package/dist/layout/engine.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContentDocument, LayoutDocument, MathFontMetrics, PositionedFormula, TextMeasurer } from "document-schema.js";
|
|
1
|
+
import { ContentDocument, LayoutDocument, MathFontMetrics, PageSize, PositionedFormula, TextMeasurer } from "document-schema.js";
|
|
2
2
|
//#region src/layout/engine.d.ts
|
|
3
3
|
interface EngineLayoutOptions {
|
|
4
4
|
readonly measurer: TextMeasurer;
|
|
@@ -7,6 +7,7 @@ interface EngineLayoutOptions {
|
|
|
7
7
|
interface WordprocessingLayoutResult {
|
|
8
8
|
readonly document: LayoutDocument;
|
|
9
9
|
readonly formulas: readonly PositionedFormula[];
|
|
10
|
+
readonly pages: readonly PageSize[];
|
|
10
11
|
}
|
|
11
12
|
type WordprocessingContentDocument = Extract<ContentDocument, {
|
|
12
13
|
kind: 'wordprocessing';
|
package/dist/layout/engine.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContentDocument, LayoutDocument, MathFontMetrics, PositionedFormula, TextMeasurer } from "document-schema.js";
|
|
1
|
+
import { ContentDocument, LayoutDocument, MathFontMetrics, PageSize, PositionedFormula, TextMeasurer } from "document-schema.js";
|
|
2
2
|
//#region src/layout/engine.d.ts
|
|
3
3
|
interface EngineLayoutOptions {
|
|
4
4
|
readonly measurer: TextMeasurer;
|
|
@@ -7,6 +7,7 @@ interface EngineLayoutOptions {
|
|
|
7
7
|
interface WordprocessingLayoutResult {
|
|
8
8
|
readonly document: LayoutDocument;
|
|
9
9
|
readonly formulas: readonly PositionedFormula[];
|
|
10
|
+
readonly pages: readonly PageSize[];
|
|
10
11
|
}
|
|
11
12
|
type WordprocessingContentDocument = Extract<ContentDocument, {
|
|
12
13
|
kind: 'wordprocessing';
|
package/dist/layout/engine.js
CHANGED
|
@@ -2,8 +2,8 @@ import { flipY } from "../model/geometry.js";
|
|
|
2
2
|
import { formulaOfBlock, formulaPlaceholderText } from "../model/formula.js";
|
|
3
3
|
import { layoutFormula } from "../mathml/layout.js";
|
|
4
4
|
import { wrapRunsToWidth } from "./text-layout.js";
|
|
5
|
-
import { alignmentOffsetPt, effectiveStyledRuns, estimateRowHeightPt, formulaSizePtForFrame, headingStyleFor, justifyLineGapsPt, lineNaturalHeightPt, pushCellBorderLines, registerImage, sumColumnWidthsPt } from "./shared.js";
|
|
6
|
-
import { COLOR_BLACK
|
|
5
|
+
import { alignmentOffsetPt, effectiveStyledRuns, estimateRowHeightPt, formulaSizePtForFrame, headingStyleFor, justifyLineGapsPt, layoutDocumentOf, lineNaturalHeightPt, packagePagesOf, pushCellBorderLines, registerImage, stampFragmentFrame, stampFrame, sumColumnWidthsPt, textBoxForFragment } from "./shared.js";
|
|
6
|
+
import { COLOR_BLACK } from "document-schema.js";
|
|
7
7
|
import { parseListNumId } from "markdown-codec";
|
|
8
8
|
//#region src/layout/engine.ts
|
|
9
9
|
const LIST_INDENT_STEP_PT = 18;
|
|
@@ -50,20 +50,26 @@ function layoutParagraphFlow(paragraph, section, pages, state, contentLeftXDown,
|
|
|
50
50
|
lines.forEach((line, lineIndex) => {
|
|
51
51
|
const lineHeightPt = lineNaturalHeightPt(line, measurer, fallbackRun) * (paragraph.lineSpacing ?? 1);
|
|
52
52
|
ensureRoom(state, section, pages, lineHeightPt, contentBottomYDown);
|
|
53
|
+
const pageIndex = pages.length;
|
|
53
54
|
const baselineYDown = state.cursorYDown + line.ascentPt;
|
|
54
55
|
const firstLineIndentPt = lineIndex === 0 ? paragraph.indentFirstLinePt ?? 0 : 0;
|
|
55
56
|
const alignOffsetPt = alignmentOffsetPt(paragraph.alignment, paragraphWidthPt, line.widthPt);
|
|
56
57
|
const justifyGapsPt = paragraph.alignment === "justify" && lineIndex < lines.length - 1 ? justifyLineGapsPt(line, paragraphWidthPt, measurer) : void 0;
|
|
57
|
-
if (lineIndex === 0 && paragraph.list !== void 0)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
if (lineIndex === 0 && paragraph.list !== void 0) {
|
|
59
|
+
const markerText = listMarkerText(paragraph.list, listCounters);
|
|
60
|
+
const markerItem = {
|
|
61
|
+
kind: "text",
|
|
62
|
+
text: markerText,
|
|
63
|
+
xPt: paragraphLeftXDown - LIST_INDENT_STEP_PT,
|
|
64
|
+
yPt: section.pageSize.heightPt - baselineYDown,
|
|
65
|
+
font: fallbackRun.font,
|
|
66
|
+
sizePt: fallbackRun.sizePt,
|
|
67
|
+
color: fallbackRun.color,
|
|
68
|
+
sourcePath: paragraph.sourcePath
|
|
69
|
+
};
|
|
70
|
+
state.items.push(markerItem);
|
|
71
|
+
stampFrame(paragraph, pageIndex, textBoxForFragment(markerItem, measurer.widthOfTextAtSize(markerText, fallbackRun.font, fallbackRun.sizePt), line.ascentPt, line.descentPt));
|
|
72
|
+
}
|
|
67
73
|
line.fragments.forEach((fragment, fragmentIndex) => {
|
|
68
74
|
const xPt = paragraphLeftXDown + firstLineIndentPt + alignOffsetPt + fragment.xOffsetPt + (justifyGapsPt?.[fragmentIndex] ?? 0);
|
|
69
75
|
const yPt = section.pageSize.heightPt - baselineYDown;
|
|
@@ -79,6 +85,7 @@ function layoutParagraphFlow(paragraph, section, pages, state, contentLeftXDown,
|
|
|
79
85
|
sourcePath: fragment.sourcePath
|
|
80
86
|
};
|
|
81
87
|
state.items.push(textItem);
|
|
88
|
+
stampFragmentFrame(paragraph.runs, fragment, pageIndex, textItem, measurer, line);
|
|
82
89
|
if (fragment.hyperlink !== void 0) {
|
|
83
90
|
const fragmentWidthPt = measurer.widthOfTextAtSize(fragment.text, fragment.font, fragment.sizePt);
|
|
84
91
|
const link = {
|
|
@@ -97,7 +104,7 @@ function layoutParagraphFlow(paragraph, section, pages, state, contentLeftXDown,
|
|
|
97
104
|
});
|
|
98
105
|
state.cursorYDown += paragraph.spacingAfterPt ?? 0;
|
|
99
106
|
}
|
|
100
|
-
function layoutParagraphInCell(paragraph, cellLeftXDown, cellWidthPt, startYDown, pageHeightPt, measurer, out, listCounters) {
|
|
107
|
+
function layoutParagraphInCell(paragraph, cellLeftXDown, cellWidthPt, startYDown, pageHeightPt, pageIndex, measurer, out, listCounters) {
|
|
101
108
|
let cursorYDown = startYDown + (paragraph.spacingBeforePt ?? 0);
|
|
102
109
|
const effectiveRuns = effectiveStyledRuns(paragraph.runs, 1, headingStyleFor(paragraph.styleId));
|
|
103
110
|
const fallbackRun = effectiveRuns[0];
|
|
@@ -111,18 +118,23 @@ function layoutParagraphInCell(paragraph, cellLeftXDown, cellWidthPt, startYDown
|
|
|
111
118
|
const firstLineIndentPt = lineIndex === 0 ? paragraph.indentFirstLinePt ?? 0 : 0;
|
|
112
119
|
const alignOffsetPt = alignmentOffsetPt(paragraph.alignment, paragraphWidthPt, line.widthPt);
|
|
113
120
|
const justifyGapsPt = paragraph.alignment === "justify" && lineIndex < lines.length - 1 ? justifyLineGapsPt(line, paragraphWidthPt, measurer) : void 0;
|
|
114
|
-
if (lineIndex === 0 && paragraph.list !== void 0)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
if (lineIndex === 0 && paragraph.list !== void 0) {
|
|
122
|
+
const markerText = listMarkerText(paragraph.list, listCounters);
|
|
123
|
+
const markerItem = {
|
|
124
|
+
kind: "text",
|
|
125
|
+
text: markerText,
|
|
126
|
+
xPt: paragraphLeftXDown - LIST_INDENT_STEP_PT,
|
|
127
|
+
yPt: pageHeightPt - baselineYDown,
|
|
128
|
+
font: fallbackRun.font,
|
|
129
|
+
sizePt: fallbackRun.sizePt,
|
|
130
|
+
color: fallbackRun.color,
|
|
131
|
+
sourcePath: paragraph.sourcePath
|
|
132
|
+
};
|
|
133
|
+
out.push(markerItem);
|
|
134
|
+
stampFrame(paragraph, pageIndex, textBoxForFragment(markerItem, measurer.widthOfTextAtSize(markerText, fallbackRun.font, fallbackRun.sizePt), line.ascentPt, line.descentPt));
|
|
135
|
+
}
|
|
124
136
|
line.fragments.forEach((fragment, fragmentIndex) => {
|
|
125
|
-
|
|
137
|
+
const textItem = {
|
|
126
138
|
kind: "text",
|
|
127
139
|
text: fragment.text,
|
|
128
140
|
xPt: paragraphLeftXDown + firstLineIndentPt + alignOffsetPt + fragment.xOffsetPt + (justifyGapsPt?.[fragmentIndex] ?? 0),
|
|
@@ -132,7 +144,9 @@ function layoutParagraphInCell(paragraph, cellLeftXDown, cellWidthPt, startYDown
|
|
|
132
144
|
color: fragment.color,
|
|
133
145
|
underline: fragment.underline,
|
|
134
146
|
sourcePath: fragment.sourcePath
|
|
135
|
-
}
|
|
147
|
+
};
|
|
148
|
+
out.push(textItem);
|
|
149
|
+
stampFragmentFrame(paragraph.runs, fragment, pageIndex, textItem, measurer, line);
|
|
136
150
|
});
|
|
137
151
|
cursorYDown += lineHeightPt;
|
|
138
152
|
});
|
|
@@ -144,6 +158,7 @@ function layoutTableFlow(table, section, pages, state, contentLeftXDown, content
|
|
|
144
158
|
for (const row of table.rows) {
|
|
145
159
|
const rowHeightPt = row.heightPt ?? estimateRowHeightPt(row, measurer, table.columnWidthsPt, scale);
|
|
146
160
|
ensureRoom(state, section, pages, rowHeightPt, contentBottomYDown);
|
|
161
|
+
const pageIndex = pages.length;
|
|
147
162
|
let cellXDown = contentLeftXDown;
|
|
148
163
|
let colIndex = 0;
|
|
149
164
|
for (const cell of row.cells) {
|
|
@@ -156,21 +171,20 @@ function layoutTableFlow(table, section, pages, state, contentLeftXDown, content
|
|
|
156
171
|
heightPt: rowHeightPt
|
|
157
172
|
};
|
|
158
173
|
const cellSourcePath = cell.sourcePath ?? table.sourcePath;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
174
|
+
const cellFrame = flipY(cellFrameYDown, section.pageSize.heightPt);
|
|
175
|
+
stampFrame(cell, pageIndex, cellFrame);
|
|
176
|
+
if (cell.background !== void 0) state.items.push({
|
|
177
|
+
kind: "rect",
|
|
178
|
+
xPt: cellFrame.xPt,
|
|
179
|
+
yPt: cellFrame.yPt,
|
|
180
|
+
widthPt: cellFrame.widthPt,
|
|
181
|
+
heightPt: cellFrame.heightPt,
|
|
182
|
+
fill: cell.background,
|
|
183
|
+
sourcePath: cellSourcePath
|
|
184
|
+
});
|
|
171
185
|
if (cell.borders !== void 0) pushCellBorderLines(cell.borders, cellFrameYDown, section.pageSize.heightPt, cellSourcePath, state.items);
|
|
172
186
|
let cellCursorYDown = state.cursorYDown;
|
|
173
|
-
for (const block of cell.blocks) if (block.kind === "paragraph") cellCursorYDown = layoutParagraphInCell(block, cellXDown, cellWidthPt, cellCursorYDown, section.pageSize.heightPt, measurer, state.items, listCounters);
|
|
187
|
+
for (const block of cell.blocks) if (block.kind === "paragraph") cellCursorYDown = layoutParagraphInCell(block, cellXDown, cellWidthPt, cellCursorYDown, section.pageSize.heightPt, pageIndex, measurer, state.items, listCounters);
|
|
174
188
|
cellXDown += cellWidthPt;
|
|
175
189
|
colIndex += span;
|
|
176
190
|
}
|
|
@@ -196,6 +210,7 @@ function layoutImageFlow(block, section, pages, state, contentLeftXDown, content
|
|
|
196
210
|
sourcePath: block.sourcePath
|
|
197
211
|
};
|
|
198
212
|
state.items.push(imageItem);
|
|
213
|
+
stampFrame(block, pages.length, flippedFrame);
|
|
199
214
|
state.cursorYDown += block.heightPt;
|
|
200
215
|
}
|
|
201
216
|
function layoutFormulaFallback(block, section, pages, state, contentLeftXDown, contentWidthPt, contentBottomYDown, measurer, listCounters) {
|
|
@@ -232,6 +247,7 @@ function layoutFormulaFlow(block, section, pages, state, contentLeftXDown, conte
|
|
|
232
247
|
yPt: flippedFrame.yPt,
|
|
233
248
|
box
|
|
234
249
|
});
|
|
250
|
+
stampFrame(block, pages.length, flippedFrame);
|
|
235
251
|
state.cursorYDown += box.heightPt;
|
|
236
252
|
}
|
|
237
253
|
function paginateSection(section, measurer, images, pages, options, formulas, listCounters) {
|
|
@@ -254,13 +270,9 @@ function convertWordprocessingToLayout(doc, options) {
|
|
|
254
270
|
const listCounters = /* @__PURE__ */ new Map();
|
|
255
271
|
for (const section of doc.sections) paginateSection(section, options.measurer, images, pages, options, formulas, listCounters);
|
|
256
272
|
return {
|
|
257
|
-
document:
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
pages,
|
|
261
|
-
images
|
|
262
|
-
},
|
|
263
|
-
formulas
|
|
273
|
+
document: layoutDocumentOf(doc.metadata, pages, images),
|
|
274
|
+
formulas,
|
|
275
|
+
pages: packagePagesOf(pages)
|
|
264
276
|
};
|
|
265
277
|
}
|
|
266
278
|
//#endregion
|