From 138458b1278ea82e6a4e3a9daab0120f0e951662 Mon Sep 17 00:00:00 2001 From: Steffen Becker Date: Mon, 10 Aug 2026 19:54:48 +0000 Subject: [PATCH] fix: a run keeps the size its block does not supply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A list item is measured against the default paragraph style, but it renders at its own style's size — so a 12pt run under an 11pt ListParagraph was suppressed as "the style supplies it" and came out 11pt. Runs are now measured against the size the block actually gives them. The guidance document: 15 of 16 pages start on the same line, from 1. --- src/lib/import/CLAUDE.md | 1 + src/lib/import/odt.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/import/CLAUDE.md b/src/lib/import/CLAUDE.md index 589baed..f6e456f 100644 --- a/src/lib/import/CLAUDE.md +++ b/src/lib/import/CLAUDE.md @@ -15,6 +15,7 @@ The **Open .odt** button (`App.svelte`) parses an uploaded file with `importOdt( `fo:line-height` is stored as the ODF percentage itself (115% → `1.15`, as both DOCX paths and the export use it) and suppressed against the block's own style, so a 100% under a 115% style stays as direct formatting. +- **A run is measured against the block's own size**, not the yardstick's: a list item whose style sets 11pt would otherwise drop every 12pt run as "the style supplies it" and render it at 11 (`convertParaLike`, `runDefaults`). - **The yardstick is the style the block can name.** Only a **body** block carries a `styleName`, so a paragraph in a cell or a text box is measured against the *default* paragraph style instead of its own — otherwise everything its style provides is suppressed as "the style will supply it" and nothing ever does (a Word caption in a text box arrived without its italic or its colour). - **Default suppression** keeps round trips (editor → LibreOffice → editor) from accreting explicit attrs: values matching the editor's defaults (12pt body, `HEADING_STYLE_OVERRIDES` sizes/margins, **0 paragraph spacing**, list margin 0, Times New Roman/Liberation Serif, `#000000` text) are imported as `null`/no mark, with small tolerances for producer unit rounding (pt↔cm↔twips). This is why the editor's defaults must equal Word's/LibreOffice's (below) — an editor-only default is indistinguishable from a failed style resolution and silently lands in every imported document. - **Mapping:** `text:h` → heading (level clamped to `MAX_HEADING_LEVEL`), per-depth `text:list-level-style-*` defs decide bullet vs ordered and `listStyleType` (reverse lookup `orderedTypeFromFormat`), tables handle covered cells / `number-columns-repeated` / header rows / colspans / cell shading (`StyleResolver.cellBackgroundColor` → `backgroundColor`) / cell borders (`StyleResolver.cellBorders` + `borderAttrFromOdf` → the per-side border attrs) / table margins (`tableMargins` reads the table style's `fo:margin-*`, `style:width`/`style:rel-width` and `table:align` against `Ctx.contentWidthCm` — so a table narrower than the text width stays narrow instead of being stretched; DOCX does the same from `w:tblInd` + the `w:tblGrid`/`w:tblW` width), `text:s`/`text:tab`/`text:line-break` become spaces/`\t`/`hardBreak`, `draw:frame`/`draw:image` → an `image` node (`convertFrame`: bytes read from the zip's `Pictures/` entry into a data-URI, `svg:width`/`-height` cm → px, `svg:title` → `alt`, `draw:transform` rotate → `rotation`; a non-`as-char` anchor or a graphic style's `style:wrap` → floating `wrap` mode via `StyleResolver.graphicProps` — an **explicit `as-char` anchor is always inline**: LibreOffice's named Graphics style carries a `style:wrap` that would otherwise float every inherited frame), text fields keep their stored value. **Text boxes / shapes** (`convertDrawElement`): `draw:frame`+`draw:text-box` → a `textBox` node (`convertTextBoxFrame`: height = `fo:min-height` else `svg:height`; fill/stroke read straight from `graphicProps`' `draw:fill(-color)`/`draw:stroke`/`svg:stroke-*`, values equal to the editor defaults suppressed, none → explicit `null`); `draw:rect`/`draw:ellipse`/`draw:custom-shape` with a rect/round-rectangle/ellipse preset → a `textBox` with the matching `shapeKind` (`convertShape`; other presets → "Unsupported shapes were removed"). A box is a block node but its frame sits inside a `text:p`, so converted boxes ride `Ctx.pendingBlocks` and `convertBlocks` flushes them after the anchor paragraph (dropping our own export's empty anchor); in cells/other boxes their blocks are unwrapped in place with a warning. The DOCX importer mirrors all of this (`convertWpsShape` for DrawingML `wps:wsp` — probed before the image `a:blip` path, `convertPict` for legacy VML; Word's `mc:AlternateContent` uses only the `mc:Choice` branch so the VML fallback can't double-import). diff --git a/src/lib/import/odt.ts b/src/lib/import/odt.ts index fbd8068..964cd5f 100644 --- a/src/lib/import/odt.ts +++ b/src/lib/import/odt.ts @@ -1231,7 +1231,14 @@ function convertParaLike(el: Element, ctx: Ctx, kind: BlockKind, boldByDefault = // the resolver's own walk rather than the flattened paraProps. const stops = formatTabStops(resolver.tabStops(styleName)); if (stops) attrs.tabStops = stops; - const content = convertInline(el, ctx, baseTextProps, defaults, false); + // A run inherits the block's own size (attrs.fontSize below), not the default style's, + // so that is what it is measured against — else a list item whose style sets 11pt drops + // every 12pt run as "the style supplies it" and renders them at 11. + const markSizePt = lengthToPt(baseTextProps['fo:font-size']); + const runDefaults = markSizePt != null && Math.abs(markSizePt - defaults.fontSizePt) > 0.05 + ? { ...defaults, fontSizePt: markSizePt } + : defaults; + const content = convertInline(el, ctx, baseTextProps, runDefaults, false); // A box lifted out of a paragraph that held nothing else replaces it in the flow, so // it takes that paragraph's own space above and below — resolved, not the direct half: