Files
genoffice/packages/pdf2docx/tests/stitch.test.ts
T
merrick-2002andGenOffice d24c964a3e Sync snapshot (2026-09-09) (#271)
- **New app: GenOffice HTML.** Open, edit and generate .html pages: a source pane with a sandboxed live preview, click-to-select elements with a floating toolbar and style panel, device-size preview, image tools and a present mode. AI generates whole pages from a brief with style directions and offers page-wide Restyle, Theme and Summarize. Export to Word runs locally through the built-in html2docx converter (native, editable OOXML; no print-to-PDF detour).
- **AI:** separate BYOK providers for web search, image generation and image/video analysis; new Codex App Server provider; Ask AI quotes the selected text and keeps it highlighted while it runs; custom AI panel text size; blocked requests retry through the Chromium network stack.
- **App:** global AutoSave setting shared by every editor; AI panel text size and chat spellcheck toggles (genoffice#249); Czech (cs) UI locale (genoffice#259); Save As defaults to the document's folder; PDF export no longer aborts on CJK file paths on Windows.
- **Docs:** Export as HTML; comments and replies edit in place from the comments pane; the caret can leave a trailing table (genoffice#266); spellcheck re-marks text as soon as it is re-enabled; AI edits are character-precise on partial selections; zoom keeps the scroll position; pasting a cell from Sheets takes the destination font.
- **Sheets:** Find no longer freezes on wide or streamed grids; Replace searches as you type; cached values of external-workbook formulas are kept instead of #ERROR! (genoffice#235); "number stored as text" is a warning, not an error (genoffice#236); paste repeats into the target range like Excel; filter criteria survive save/reopen; saves retry when Windows locks the file; many Excel-fidelity fixes for column widths, row heights, charts, slicers, number formats and CJK fonts.
- **Slides:** PDF export works for large presentations (genoffice#264); EMF/WMF picture fonts and East Asian theme fonts resolve correctly; decks with missing layouts or embedded styles still open; outline-only pie slices render.
- **PDF:** highlight and underline geometry aligns with the text; Shift+arrows extend the selection instead of paging.
- **Markdown:** Find and replace (Ctrl+F / Ctrl+H) (genoffice#253); mermaid code blocks render as diagrams (genoffice#263); better print quality.
- Thanks to community contributors @GoodScholar, @aniruddhaadak80 and @Sun8854, and to @hanyscz, @qgzln, @zyp997, @bisslot, @krakotay and @Ben03151 for the reports.

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-09-09 18:19:13 +08:00

121 lines
3.9 KiB
TypeScript

/** P32: cross-page paragraph stitching (mid-paragraph source page boundaries). */
import { describe, expect, it } from 'vitest'
import { stitchCrossPageParagraphs } from '../src/pipeline'
import type { IrPage, Line, Span, TextBlock } from '../src/ir'
import type { Rect } from '../src/geometry'
const H = 800
const mkLine = (x0: number, x1: number, topY: number, text = 'x', fontSize = 12): Line => {
const box: Rect = { x0, x1, y0: topY - fontSize, y1: topY }
const span: Span = {
text,
box,
fontSize,
fontFamily: 'Helvetica',
bold: false,
italic: false,
color: '000000',
dir: 'ltr',
script: 'latin',
}
return { spans: [span], box, baseline: topY - fontSize * 0.8, endsWithHyphen: false }
}
const mkBlock = (lines: Line[], over: Partial<TextBlock> = {}): TextBlock => ({
kind: 'text',
box: lines
.map((l) => l.box)
.reduce((a, b) => ({
x0: Math.min(a.x0, b.x0),
y0: Math.min(a.y0, b.y0),
x1: Math.max(a.x1, b.x1),
y1: Math.max(a.y1, b.y1),
})),
align: 'left',
firstLineIndentPt: 0,
dir: 'ltr',
lines,
...over,
})
const mkPage = (index: number, blocks: TextBlock[]): IrPage =>
({
index,
widthPt: 600,
heightPt: H,
rotation: 0,
blocks,
degraded: false,
scanned: false,
}) as IrPage
/** near-full page: one paragraph spanning most of the height, full-width tail */
const fullTail = () => mkBlock([mkLine(50, 550, 760), mkLine(50, 550, 100), mkLine(50, 548, 80)])
describe('stitchCrossPageParagraphs (P32)', () => {
it('keeps the boundary hard when either page pins art to the page (P35)', () => {
const panel = {
kind: 'image' as const,
box: { x0: 0, y0: 0, x1: 200, y1: H },
data: new Uint8Array(0),
mime: 'image/png' as const,
pixelWidth: 2,
pixelHeight: 2,
}
for (const decorate of [
(prev: IrPage) => (prev.bgPanels = [panel]),
(_prev: IrPage, cur: IrPage) => (cur.bgPanels = [panel]),
(_prev: IrPage, cur: IrPage) =>
(cur.bgRender = {
data: new Uint8Array(0),
mime: 'image/png',
pixelWidth: 2,
pixelHeight: 2,
}),
]) {
const prev = mkPage(0, [fullTail()])
const cur = mkPage(1, [
mkBlock([mkLine(50, 400, 760, 'cont')]),
mkBlock([mkLine(50, 300, 700)]),
])
decorate(prev, cur)
stitchCrossPageParagraphs([prev, cur])
expect(cur.flowsFromPrev).toBeUndefined()
expect(cur.blocks).toHaveLength(2)
}
})
it('stitches a mid-paragraph boundary and marks the page', () => {
const prev = mkPage(0, [fullTail()])
const cur = mkPage(1, [
mkBlock([mkLine(50, 400, 760, 'cont')]),
mkBlock([mkLine(50, 300, 700)]),
])
stitchCrossPageParagraphs([prev, cur])
expect(cur.flowsFromPrev).toBe(true)
expect(prev.blocks[0]!.kind === 'text' && (prev.blocks[0] as TextBlock).lines).toHaveLength(4)
expect(cur.blocks).toHaveLength(1)
})
it('keeps the break when the tail line is short (finished paragraph)', () => {
const prev = mkPage(0, [
mkBlock([mkLine(50, 550, 760), mkLine(50, 550, 100), mkLine(50, 200, 80)]),
])
const cur = mkPage(1, [mkBlock([mkLine(50, 400, 760)])])
stitchCrossPageParagraphs([prev, cur])
expect(cur.flowsFromPrev).toBeUndefined()
})
it('keeps the break on an underfull earlier page', () => {
const prev = mkPage(0, [mkBlock([mkLine(50, 550, 760), mkLine(50, 548, 740)])])
const cur = mkPage(1, [mkBlock([mkLine(50, 400, 760)])])
stitchCrossPageParagraphs([prev, cur])
expect(cur.flowsFromPrev).toBeUndefined()
})
it('keeps the break when the continuation is indented (new paragraph)', () => {
const prev = mkPage(0, [fullTail()])
const cur = mkPage(1, [mkBlock([mkLine(50, 400, 760)], { firstLineIndentPt: 20 })])
stitchCrossPageParagraphs([prev, cur])
expect(cur.flowsFromPrev).toBeUndefined()
})
})