Files
genoffice/packages/pdf2docx/tests/bank-statement-repro.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

71 lines
3.3 KiB
TypeScript

/**
* Borderless bank-statement layout (alpha feedback): every transaction
* prints one value row (dates, description, amounts) followed by several
* 1-unit description continuation lines (reference-number stacks). The
* run-strength gate used to take its median over ALL run rows, so two
* absorbed continuations collapsed it, absorption stopped, and the whole
* region fell back to scrambled flow text. Strength is judged over the
* anchor rows only.
*/
import { describe, expect, it } from 'vitest'
import { clusterCombiningMarks, groupIntoLines } from '../src/analyze/lines'
import { detectStreamTables } from '../src/analyze/stream'
import { splitIntoUnits } from '../src/analyze/units'
import type { PageShapes, PdfChar, TableBlock } from '../src/ir'
import { mkText } from './helpers/chars'
const shapesOf = (): PageShapes => ({ strokes: [], fills: [], ignoredPaths: 0 })
const unitsOf = (chars: PdfChar[]) => splitIntoUnits(groupIntoLines(clusterCombiningMarks(chars)))
const cellText = (table: TableBlock, r: number, c: number): string =>
table.rows[r]![c]!.blocks.map((b) =>
b.lines.map((l) => l.spans.map((s) => s.text).join('')).join(' '),
).join(' ')
/** right-aligned text: place so it ends at x1 (0.5 em per Latin glyph) */
function rightText(text: string, x1: number, y: number): PdfChar[] {
return mkText(text, x1 - text.length * 5, { y }).chars
}
/** two transactions, each a 5-unit value row plus three continuation lines */
function statement(): PdfChar[] {
const chars: PdfChar[] = []
chars.push(...mkText('03 AUG', 40, { y: 730 }).chars)
chars.push(...mkText('03 AUG', 95, { y: 730 }).chars)
chars.push(...mkText('COMM/COMM IN LIEU', 150, { y: 730 }).chars)
chars.push(...rightText('23.63', 430, 730))
chars.push(...rightText('6,717,284.65', 610, 730))
chars.push(...mkText('CT0039810817M001', 150, { y: 715 }).chars)
chars.push(...mkText('SGTT260731808027', 150, { y: 700 }).chars)
chars.push(...mkText('*MDSUSER 000003045', 150, { y: 685 }).chars)
chars.push(...mkText('03 AUG', 40, { y: 670 }).chars)
chars.push(...mkText('03 AUG', 95, { y: 670 }).chars)
chars.push(...mkText('CALL A/C WDL', 150, { y: 670 }).chars)
chars.push(...rightText('2,251,200.18', 430, 670))
chars.push(...rightText('4,466,084.47', 610, 670))
return chars
}
describe('detectStreamTables: bank statement with wrapped description stacks', () => {
it('keeps the run alive across several absorbed continuation rows', () => {
const { tables } = detectStreamTables(unitsOf(statement()), shapesOf())
expect(tables).toHaveLength(1)
const table = tables[0]!
expect(table.confidence).toBeGreaterThanOrEqual(0.5)
expect(table.rows).toHaveLength(5)
expect(table.rows[0]).toHaveLength(5)
// value rows land in their columns…
expect(cellText(table, 0, 0)).toBe('03 AUG')
expect(cellText(table, 0, 2)).toBe('COMM/COMM IN LIEU')
expect(cellText(table, 0, 3)).toBe('23.63')
expect(cellText(table, 0, 4)).toBe('6,717,284.65')
expect(cellText(table, 4, 3)).toBe('2,251,200.18')
// …and the reference stack stays inside the description column
expect(cellText(table, 1, 2)).toBe('CT0039810817M001')
expect(cellText(table, 2, 2)).toBe('SGTT260731808027')
expect(cellText(table, 3, 2)).toBe('*MDSUSER 000003045')
expect(cellText(table, 1, 0)).toBe('')
expect(cellText(table, 1, 3)).toBe('')
})
})