Files
genoffice/apps/docs/tests/run-letter-spacing.test.ts
T
merrick-2002andGenOffice 6d9b6812dd Sync snapshot (2026-08-23) (#130)
- Convert scanned PDFs to editable text with local OCR, running through the operating system's own engine on macOS and Windows
- Add a much richer AI workflow to Docs, PDF, and Markdown: selection-scoped questions, batched edits, character-level edits, comment and tracked-change awareness, citations back to the source block, and in-document image generation
- Let Slides open the same presentation in a second window and edit it from both
- Improve PDF to Excel table recovery: tables spanning pages merge into one worksheet, and label/value grids and rule-less statement bands become real rows
- Fix a large wave of Word layout fidelity in Docs, Excel parity in Sheets, and PowerPoint import fidelity in Slides

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-08-23 23:10:02 +08:00

50 lines
1.6 KiB
TypeScript

/**
* w:spacing / w:w on runs must reach the static render paths (textboxes,
* header/footer DOM) as letter-spacing — PDF converters express word gaps as
* whitespace-only runs with negative w:spacing.
*/
import { describe, expect, it } from 'vitest'
import { DOMSerializer } from '@tiptap/pm/model'
import type { TextboxDisplay } from '@genoffice/docx-engine'
import { renderTextboxSpec } from '../src/renderer/editor/protected-render'
import { runLetterSpacingCss } from '../src/renderer/line-metrics'
const render = (spec: unknown): HTMLElement =>
DOMSerializer.renderSpec(document, spec as never).dom as HTMLElement
describe('runLetterSpacingCss', () => {
it('converts w:spacing twips to pt', () => {
expect(runLetterSpacingCss({ text: ' ', charSpacingTwips: -49 })).toBe('-2.45pt')
})
it('combines w:spacing and w:w into one calc()', () => {
expect(runLetterSpacingCss({ text: 'A', charSpacingTwips: 20, charScalePct: 105 })).toBe(
'calc(1pt + 0.026em)',
)
})
it('returns null without either property', () => {
expect(runLetterSpacingCss({ text: 'A' })).toBeNull()
})
})
describe('static textbox render', () => {
it('emits letter-spacing on spaced runs', () => {
const box: TextboxDisplay = {
paras: [
{
runs: [
{ text: 'END' },
{ text: ' ', charSpacingTwips: -49 },
{ text: 'OF', charScalePct: 105 },
],
},
],
}
const spans = [...render(renderTextboxSpec(box)).querySelectorAll('span')].filter(
(s) => !s.children.length,
)
expect(spans.map((s) => s.style.letterSpacing)).toEqual(['', '-2.45pt', '0.026em'])
})
})