From 3b24b144705775fa91984847d9f0aa4fc7f3a626 Mon Sep 17 00:00:00 2001 From: Steffen Becker Date: Fri, 14 Aug 2026 12:31:11 +0200 Subject: [PATCH] feat: lines and arrows, which both importers used to drop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two endpoints rather than a box: no text, no fill, and the diagonal of the frame with `flipV` picking which one. The three kinds share their preset names, since the heads a file declares are what tell them apart. ODF gives a line its own element and its heads a named marker, which needs the draw: prefix declared in styles.xml — undeclared, the file does not parse at all. Word keeps the frame and flips it. --- CHANGELOG.md | 3 +- docs/architecture/frames.md | 25 ++++++++ src/lib/components/ShapePicker.svelte | 11 +++- src/lib/editor/extensions/textBox.ts | 64 ++++++++++++++++++--- src/lib/export/docx.ts | 20 +++++-- src/lib/export/odt.ts | 36 +++++++++++- src/lib/i18n/locales/de.ts | 3 + src/lib/i18n/locales/en.ts | 3 + src/lib/import/docx.ts | 9 ++- src/lib/import/odt.ts | 26 ++++++++- src/lib/utils/shapes.ts | 83 ++++++++++++++++++++++++++- src/styles/editor.css | 8 +++ tests/roundtrip.test.ts | 48 +++++++++++++++- tests/unit/shape-lines.test.ts | 44 ++++++++++++++ tests/unit/shapes.test.ts | 14 +++-- 15 files changed, 367 insertions(+), 30 deletions(-) create mode 100644 tests/unit/shape-lines.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 76ccd57..0f80ceb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ - Formulas in a cell (LibreOffice's Table ▸ Formula, Word's Layout ▸ Formula): `=SUM(ABOVE)`, `=AVERAGE(A1:A3)`, `=A1*2` — SUM, PRODUCT, AVERAGE, MIN, MAX, COUNT, ABS, INT, SIGN, MOD and ROUND over cell references, ranges and Word's directions, with arithmetic and parentheses. A formula cell shows its result on the field shade both word processors use and recomputes as the cells it reads change, a formula reading another formula included. It rides the cell as ODF's `table:formula` in LibreOffice's own language (`ooow:sum `, a direction resolved to the range it stands for) with the result cached as `office:value`, and as Word's `=` field inside the cell — both re-read - Number recognition (LibreOffice's Table ▸ Number Recognition): with it on, a cell whose text reads as a number is rewritten in the document language's number format when the cursor leaves it — `007,50` becomes `7,5`. **Off** by default, as it is in LibreOffice, and the parsing a formula does is independent of it, exactly as there - Table border control (Word/LibreOffice-style): per-side cell borders with presets (all / outside / inside / single edges / none), line width and color; buttons show active states matching the current pen and toggle borders off; round-trips to ODF `fo:border-*` and DOCX `w:tcBorders` +- Lines and arrows (shape gallery: line, arrow, double arrow), which both importers used to drop: two endpoints rather than a box, so they hold no text, run across the frame's diagonal and take an arrow head that scales with the pen. The three kinds share their preset names on purpose — the heads a file declares are what tell them apart, so a Word `straightConnector1` with no heads opens as a plain line. ODF gets its own `` plus the one named `Arrow` marker LibreOffice itself writes; Word gets the `line` preset with `flipV` and `a:headEnd`/`a:tailEnd`. Verified against LibreOffice: the same three lines render identically from the .odt, the .docx and the editor - Images: inline or floating with text wrap (left / right / top-bottom), resize handles, rotation, live size badge; insert via toolbar, drag-and-drop, or paste. A floating frame is placed by the file's own offsets, and two top-and-bottom frames set against opposite ends of the text share one band, side by side - A CMYK JPEG's embedded ICC profile is dropped on import: Chromium colour-manages through it where LibreOffice and Word convert naively, which turned a contract's logo from vivid blue to dull teal and its black to grey. It also removes what is often most of the file (a 757 KB logo → 102 KB, easing the localStorage ceiling below) - EMF metafiles are drawn (`import/emf.ts`): the picture is rebuilt as SVG from the metafile's own records — paths, filled shapes, text with its font and colour, embedded bitmaps — so a plot pasted out of MATLAB or Excel arrives as a picture instead of a placeholder @@ -143,7 +144,7 @@ The gap against Word/LibreOffice, most valuable first. Reviewed 2026-08-14. **Content an imported document loses** - Charts are **drawn** from the file (`import/chart.ts`: DrawingML `chartN.xml` and ODF `chart:chart`), but as a picture, not a chart object — a re-export carries the drawing and the numbers behind it are no longer editable. The same holds for an **EMF** metafile (`import/emf.ts`): it is drawn, but as the SVG picture it was rebuilt into, and only from the record set a plot consists of — a hatched brush, a clipping region or a rotated bitmap is skipped. **WMF/SVM** metafiles and OLE objects still keep their box and a placeholder label, and export writes that back out: WMF is a different (16-bit) record format, SVM is StarOffice-proprietary, and an OLE object cannot be rendered without its application -- Shapes with no text area of their own: lines, arrows as a *line* rather than a block arrow, connectors and freeform curves — they are two endpoints, not a box, and ODF gives each its own element (`draw:line`, `draw:polyline`) rather than a `draw:custom-shape` preset. Rotated shape text (`w:bodyPr vert`) too. All dropped on import with a warning +- Connectors that attach to other shapes, and freeform curves — a connector is an anchoring model rather than a shape, and a freeform needs a drawing tool. Rotated shape text (`w:bodyPr vert`) too. All still dropped on import with a warning **Missing while writing** - One colour for every tracked change, where both word processors give each author their own — and no reviewing pane listing the revisions the way the comments pane lists comments diff --git a/docs/architecture/frames.md b/docs/architecture/frames.md index 61b99df..cea94c5 100644 --- a/docs/architecture/frames.md +++ b/docs/architecture/frames.md @@ -28,3 +28,28 @@ Adding a shape is one entry in `SHAPES` — no icon, no export branch, no import - An importer maps the file's `draw:type`/`prst` back through the same table; `shapeFromOdfType`/`shapeFromPrst` return **null** for a preset we can't draw, which is what makes the warning possible instead of flattening it to a rectangle. + +## Lines and arrows + +`line`, `lineArrow` and `lineDoubleArrow` are **two endpoints, not a box**: they hold no +text (the paragraph the schema requires is hidden and never exported), take no fill, and +run across the frame's diagonal — `flipV` picking which one, the single flag Word's +`flipV` and ODF's own endpoint order both come down to. They are drawn in the frame's +**real pixels** (`linePaths`), not the stretched 0…100 box a polygon uses: an arrow head +has to keep its shape however flat the frame is, and the head scales with the pen +(`arrowHeadPx`, floored so a hairline still shows one). + +The three share their `odf`/`prst` names, because **the heads are what tell them apart**: +both importers read the heads a file declares and `lineKindFor` names the kind, so a +`straightConnector1` with no heads is a plain line and a `line` preset with both is a +double arrow. + +- **ODF** gives a line its own element — ``, no width or + height — and its heads are a **named marker**, so `applyTextBoxes` also writes the one + `` definition into `styles.xml`, LibreOffice's own name + and path. It goes in only when a line asks for it, and needs `ensureDrawNamespaces`: + an undeclared `draw:` prefix there makes the whole file unreadable. +- **DOCX** keeps the frame and flips it (``), the heads riding the + shape's `` as `a:headEnd`/`a:tailEnd`, and writes no `wps:txbx` at all. +- **Not covered**: connectors that attach to other shapes, and freeform curves. Both are + still dropped with a warning — a connector is an anchoring model, not a shape. diff --git a/src/lib/components/ShapePicker.svelte b/src/lib/components/ShapePicker.svelte index 9533562..007cfbb 100644 --- a/src/lib/components/ShapePicker.svelte +++ b/src/lib/components/ShapePicker.svelte @@ -1,5 +1,5 @@