Day 3 (V2): the editor's document (crates/doc), .pictor, exports, SVG import #4

Open
mnovak wants to merge 0 commits from feature/editor into main
Owner

Day 3 (V2) core: crates/doc, the editor's document. Design: the app's docs/03_editor.md; format: docs/FORMATS.md ("The .pictor document").

What

  • Model (pages → layers: vector / bitmap / group; objects: rect, ellipse, line/arrow, path, text box, image with crop, group; paints with gradients; strokes) in points.
  • Operations with exact inverses and an unlimited history (ops).
  • .pictor read/write (format): zip with document.json, PNG assets and embeddable fonts; strict, capped reading; newer formats refused with their message.
  • Text (text): fontdb system fonts + document fonts, rustybuzz shaping with per-character fallback, line breaking, alignment incl. justify, letter spacing; OS/2 fsType read.
  • Display list (display) and the tiny-skia painter (render): glyphs as outlines defined once; opacity groups.
  • Bitmap tools (bitmap): brush/eraser (soft dabs, no build-up), pencil, fill and wand (scanline flood), rect/lasso masks, delete/copy, adjustments (brightness, contrast, levels, hue/saturation, invert, blur, sharpen), clone stamp, matte; edit returns the exact undo patch.
  • Exports (export): PNG at a scale, JPG on white, SVG with real <text>, PDF with pdf-writer (vectors, shading patterns, ExtGState/transparency groups, images with SMask, Type 0 fonts subset with subsetter, ToUnicode, exact MediaBox). Restricted or bitmap-only fonts are refused with the font's name and the reason.
  • SVG import (svg, usvg) and the worker ops doc.open (outside .pictor → a clean copy) and doc.import_svg.

Tests (186 in the workspace, all green; clippy 0; deps.mjs 228 crates, 0 not allowed)

  • Mandatory 1 tests/format.rs (9): round trip of the fixtures, zip slip and odd names, a 300 MB bomb and a 1000× ratio, a 50 000² picture, 5000 entries, missing/wrong assets, broken JSON and lies, newer format.
  • Mandatory 2 tests/undo.rs: proptest, 256 cases of up to 60 random edits (objects, text, layers, pages, pixel patches, groups, assets) → as many undos give the original, as many redos the edited document; a failing batch leaves nothing.
  • Mandatory 3 (core half) tests/export.rs: text extractable in reading order (Czech letters), A4 at 595.276 × 841.89, a second page at its own size; pdfium's render of each fixture's PDF within 3/255 of the core's render; PNG/JPG sizes; SVG parses and keeps text. (The canvas half is in the app.)
  • Mandatory 4 tests/fonts.rs: fsType restricted and bitmap-only refused with name and reason; installable, print and editable embedded.
  • tests/render.rs, tests/bitmap.rs (incl. the wand taking a stroke's soft edge), worker tests/hostile_doc.rs, path and word unit tests.

Self-review

  • Text layout runs on every display-list build (no cache): fine for a CV (~3000 glyphs, a few ms), would want a per-object cache for long documents.
  • PDF gradients share one alpha across stops (the average); varying-alpha gradients are approximated. Documented.
  • The PDF writer keeps everything in memory and writes one shared resource dictionary for all pages and forms: simple, slightly larger files.
  • FontBook caches outlines without a limit for the process's life; bounded in practice by the fonts in use.
  • RTL scripts are shaped left to right; not supported (documented gap).
  • fixtures is a public module so the app's fidelity test can render the same documents.
Day 3 (V2) core: `crates/doc`, the editor's document. Design: the app's `docs/03_editor.md`; format: `docs/FORMATS.md` ("The .pictor document"). ## What - **Model** (pages → layers: vector / bitmap / group; objects: rect, ellipse, line/arrow, path, text box, image with crop, group; paints with gradients; strokes) in points. - **Operations with exact inverses** and an unlimited history (`ops`). - **.pictor** read/write (`format`): zip with document.json, PNG assets and embeddable fonts; strict, capped reading; newer formats refused with their message. - **Text** (`text`): fontdb system fonts + document fonts, rustybuzz shaping with per-character fallback, line breaking, alignment incl. justify, letter spacing; OS/2 fsType read. - **Display list** (`display`) and the **tiny-skia painter** (`render`): glyphs as outlines defined once; opacity groups. - **Bitmap tools** (`bitmap`): brush/eraser (soft dabs, no build-up), pencil, fill and wand (scanline flood), rect/lasso masks, delete/copy, adjustments (brightness, contrast, levels, hue/saturation, invert, blur, sharpen), clone stamp, matte; `edit` returns the exact undo patch. - **Exports** (`export`): PNG at a scale, JPG on white, SVG with real `<text>`, PDF with pdf-writer (vectors, shading patterns, ExtGState/transparency groups, images with SMask, Type 0 fonts subset with subsetter, ToUnicode, exact MediaBox). Restricted or bitmap-only fonts are refused with the font's name and the reason. - **SVG import** (`svg`, usvg) and the worker ops `doc.open` (outside .pictor → a clean copy) and `doc.import_svg`. ## Tests (186 in the workspace, all green; clippy 0; `deps.mjs` 228 crates, 0 not allowed) - Mandatory 1 `tests/format.rs` (9): round trip of the fixtures, zip slip and odd names, a 300 MB bomb and a 1000× ratio, a 50 000² picture, 5000 entries, missing/wrong assets, broken JSON and lies, newer format. - Mandatory 2 `tests/undo.rs`: proptest, 256 cases of up to 60 random edits (objects, text, layers, pages, pixel patches, groups, assets) → as many undos give the original, as many redos the edited document; a failing batch leaves nothing. - Mandatory 3 (core half) `tests/export.rs`: text extractable in reading order (Czech letters), A4 at 595.276 × 841.89, a second page at its own size; pdfium's render of each fixture's PDF within 3/255 of the core's render; PNG/JPG sizes; SVG parses and keeps text. (The canvas half is in the app.) - Mandatory 4 `tests/fonts.rs`: fsType restricted and bitmap-only refused with name and reason; installable, print and editable embedded. - `tests/render.rs`, `tests/bitmap.rs` (incl. the wand taking a stroke's soft edge), worker `tests/hostile_doc.rs`, `path` and `word` unit tests. ## Self-review - Text layout runs on every display-list build (no cache): fine for a CV (~3000 glyphs, a few ms), would want a per-object cache for long documents. - PDF gradients share one alpha across stops (the average); varying-alpha gradients are approximated. Documented. - The PDF writer keeps everything in memory and writes one shared resource dictionary for all pages and forms: simple, slightly larger files. - `FontBook` caches outlines without a limit for the process's life; bounded in practice by the fonts in use. - RTL scripts are shaped left to right; not supported (documented gap). - `fixtures` is a public module so the app's fidelity test can render the same documents.
mnovak added 3 commits 2026-11-17 11:29:05 +01:00
This branch is already included in the target branch. There is nothing to merge.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feature/editor:feature/editor
git checkout feature/editor
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mnovak/Pictor-public#4