[doc] Editor core: document model, exact undo, .pictor format, text layout, display list, tiny-skia render, bitmap tools, SVG import, PNG/JPG/SVG/PDF export; worker doc.open and doc.import_svg

This commit is contained in:
2026-11-17 10:07:12 +01:00
parent e46cbe3547
commit 17db54fdbf
26 changed files with 6589 additions and 7 deletions
+62 -2
View File
@@ -37,10 +37,18 @@ script exit 1, and the feature that needs it waits (the brief: "it never gets a
| tempfile | 3 | MIT OR Apache-2.0 | save (and tests) | temporary files next to the target |
| sha2 | 0.11 | MIT OR Apache-2.0 | worker, tests | hashes for fixtures and the fetch scripts' self-check |
| getrandom | 0.4 | MIT OR Apache-2.0 | pdf | the OS random generator, for the AES-256 file key of a password-protected PDF |
| flate2 | 1 (dev) | MIT OR Apache-2.0 | pdf tests | building compressed hostile fixtures (a deflate bomb) |
| flate2 | 1 | MIT OR Apache-2.0 | doc (and pdf tests) | compressing PDF export streams; building compressed hostile fixtures (a deflate bomb) |
| windows | 0.62 | MIT OR Apache-2.0 | raster (Windows only), worker | WIC (HEIC), MFTEnumEx (is an HEVC decoder installed?), Job Objects |
| rqrr | 0.11 (dev) | (MIT OR Apache-2.0) AND ISC | qr tests | decoding generated codes back (ISC: see above) |
| proptest | 1 (dev) | MIT OR Apache-2.0 | tests | property tests |
| tiny-skia | 0.12 | BSD-3-Clause | doc | the core's 2D painter: PNG/JPG export, thumbnails, brush dabs, the fidelity reference |
| usvg | 0.50 | Apache-2.0 OR MIT | doc | SVG import into vector layers (text as outlines); brings fontdb and the same ttf-parser |
| fontdb | 0.24 | MIT | doc | the system font list (C:\Windows\Fonts, the per-user fonts folder) and the fonts inside a .pictor |
| rustybuzz | 0.20 | MIT | doc | text shaping (a harfbuzz port in safe Rust) |
| ttf-parser | 0.25 | MIT OR Apache-2.0 | doc | glyph outlines, metrics and the OS/2 fsType embedding flags |
| pdf-writer | 0.15 | MIT OR Apache-2.0 | doc | PDF export of a document: vectors, shadings, images with SMask, Type 0 fonts with ToUnicode |
| subsetter | 0.2 | MIT OR Apache-2.0 | doc | subsetting the embedded fonts of a PDF export (TrueType and CFF) |
| zip | 8 | MIT | doc | reading and writing .pictor files (deflate only, no default features) |
## Binaries (fetched, never in git)
@@ -86,7 +94,7 @@ support depends on pdfium, which the brief chose).
Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
<!-- deps:begin -->
176 crates; 0 outside the allowed set.
228 crates; 0 outside the allowed set.
| Crate | Version | Licence | Allowed |
| :-- | :-- | :-- | :-- |
@@ -95,8 +103,11 @@ Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
| alloc-no-stdlib | 2.0.4 | BSD-3-Clause | yes |
| alloc-stdlib | 0.2.4 | BSD-3-Clause | yes |
| android_system_properties | 0.1.6 | MIT OR Apache-2.0 | yes |
| arrayref | 0.3.9 | BSD-2-Clause | yes |
| arrayvec | 0.7.8 | MIT OR Apache-2.0 | yes |
| autocfg | 1.5.1 | Apache-2.0 OR MIT | yes |
| base64 | 0.22.1 | MIT OR Apache-2.0 | yes |
| base64 | 0.23.1 | MIT OR Apache-2.0 | yes |
| bit-set | 0.11.1 | Apache-2.0 OR MIT | yes |
| bit-vec | 0.10.2 | Apache-2.0 OR MIT | yes |
| bitflags | 2.13.2 | MIT OR Apache-2.0 | yes |
@@ -107,6 +118,7 @@ Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
| brotli-decompressor | 5.0.3 | BSD-3-Clause/MIT | yes |
| bumpalo | 3.20.4 | MIT OR Apache-2.0 | yes |
| bytemuck | 1.25.2 | Zlib OR Apache-2.0 OR MIT | yes |
| bytemuck_derive | 1.12.1 | Zlib OR Apache-2.0 OR MIT | yes |
| byteorder | 1.5.0 | Unlicense OR MIT | yes |
| byteorder-lite | 0.1.0 | Unlicense OR MIT | yes |
| bytes | 1.12.1 | MIT | yes |
@@ -122,12 +134,14 @@ Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
| console_log | 1.1.0 | MIT/Apache-2.0 | yes |
| const-oid | 0.10.3 | Apache-2.0 OR MIT | yes |
| core_detect | 1.0.0 | MIT/Apache-2.0 | yes |
| core_maths | 0.1.1 | MIT | yes |
| core-foundation-sys | 0.8.7 | MIT OR Apache-2.0 | yes |
| cpubits | 0.1.1 | MIT OR Apache-2.0 | yes |
| cpufeatures | 0.3.1 | MIT OR Apache-2.0 | yes |
| crc32fast | 1.5.5 | MIT OR Apache-2.0 | yes |
| crunchy | 0.2.4 | MIT | yes |
| crypto-common | 0.2.2 | MIT OR Apache-2.0 | yes |
| data-url | 0.3.2 | MIT OR Apache-2.0 | yes |
| digest | 0.11.3 | MIT OR Apache-2.0 | yes |
| docx-rs | 0.4.22 | MIT | yes |
| ecb | 0.2.1 | MIT OR Apache-2.0 | yes |
@@ -135,13 +149,19 @@ Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
| encoding_rs | 0.8.44 | (Apache-2.0 OR MIT) AND BSD-3-Clause | yes |
| equivalent | 1.0.3 | Apache-2.0 OR MIT | yes |
| errno | 0.3.15 | MIT OR Apache-2.0 | yes |
| euclid | 0.22.14 | MIT OR Apache-2.0 | yes |
| fastrand | 2.5.0 | Apache-2.0 OR MIT | yes |
| fax | 0.2.7 | MIT | yes |
| fdeflate | 0.3.7 | MIT OR Apache-2.0 | yes |
| find-msvc-tools | 0.1.15 | MIT OR Apache-2.0 | yes |
| flate2 | 1.1.11 | MIT OR Apache-2.0 | yes |
| float-cmp | 0.9.0 | MIT | yes |
| fnv | 1.0.7 | Apache-2.0 / MIT | yes |
| foldhash | 0.2.0 | Zlib | yes |
| font-types | 0.11.3 | MIT OR Apache-2.0 | yes |
| font-types | 0.12.7 | MIT OR Apache-2.0 | yes |
| fontconfig-parser | 0.5.8 | MIT | yes |
| fontdb | 0.24.0 | MIT | yes |
| futures-core | 0.3.34 | MIT OR Apache-2.0 | yes |
| futures-task | 0.3.34 | MIT OR Apache-2.0 | yes |
| futures-util | 0.3.34 | MIT OR Apache-2.0 | yes |
@@ -151,12 +171,14 @@ Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
| getrandom | 0.4.3 | MIT OR Apache-2.0 | yes |
| gif | 0.14.2 | MIT OR Apache-2.0 | yes |
| half | 2.7.1 | MIT OR Apache-2.0 | yes |
| harfrust | 0.15.0 | MIT | yes |
| hashbrown | 0.17.1 | MIT OR Apache-2.0 | yes |
| hybrid-array | 0.4.15 | MIT OR Apache-2.0 | yes |
| iana-time-zone | 0.1.65 | MIT OR Apache-2.0 | yes |
| iana-time-zone-haiku | 0.1.2 | MIT OR Apache-2.0 | yes |
| image | 0.25.10 | MIT OR Apache-2.0 | yes |
| image-webp | 0.2.4 | MIT OR Apache-2.0 | yes |
| imagesize | 0.15.0 | MIT | yes |
| img-parts | 0.4.2 | MIT OR Apache-2.0 | yes |
| indexmap | 2.14.2 | Apache-2.0 OR MIT | yes |
| inout | 0.2.6 | MIT OR Apache-2.0 | yes |
@@ -164,8 +186,10 @@ Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
| itoa | 1.0.19 | MIT OR Apache-2.0 | yes |
| js-sys | 0.3.107 | MIT OR Apache-2.0 | yes |
| kamadak-exif | 0.6.2 | BSD-2-Clause | yes |
| kurbo | 0.13.1 | Apache-2.0 OR MIT | yes |
| libc | 0.2.191 | MIT OR Apache-2.0 | yes |
| libloading | 0.9.1 | ISC | yes |
| libm | 0.2.16 | MIT | yes |
| linux-raw-sys | 0.12.1 | Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT | yes |
| log | 0.4.35 | MIT OR Apache-2.0 | yes |
| lopdf | 0.47.0 | MIT | yes |
@@ -173,6 +197,7 @@ Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
| maybe-owned | 0.3.4 | MIT OR Apache-2.0 | yes |
| md-5 | 0.11.0 | MIT OR Apache-2.0 | yes |
| memchr | 2.8.3 | Unlicense OR MIT | yes |
| memmap2 | 0.9.12 | MIT OR Apache-2.0 | yes |
| miniz_oxide | 0.8.9 | MIT OR Zlib OR Apache-2.0 | yes |
| miniz_oxide | 0.9.1 | MIT OR Zlib OR Apache-2.0 | yes |
| moxcms | 0.8.1 | BSD-3-Clause OR Apache-2.0 | yes |
@@ -181,10 +206,13 @@ Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
| nom | 8.0.0 | MIT | yes |
| num-traits | 0.2.19 | MIT OR Apache-2.0 | yes |
| once_cell | 1.21.4 | MIT OR Apache-2.0 | yes |
| pdf-writer | 0.15.0 | MIT OR Apache-2.0 | yes |
| pdfium-render | 0.9.5 | MIT OR Apache-2.0 | yes |
| pico-args | 0.5.0 | MIT | yes |
| pin-project-lite | 0.2.17 | Apache-2.0 OR MIT | yes |
| piston-float | 1.0.1 | MIT | yes |
| png | 0.18.1 | MIT OR Apache-2.0 | yes |
| polycool | 0.4.0 | MIT OR Apache-2.0 | yes |
| proc-macro-crate | 3.5.0 | MIT OR Apache-2.0 | yes |
| proc-macro2 | 1.0.107 | MIT OR Apache-2.0 | yes |
| proptest | 1.12.0 | MIT OR Apache-2.0 | yes |
@@ -199,11 +227,18 @@ Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
| rand_core | 0.10.1 | MIT OR Apache-2.0 | yes |
| rand_xorshift | 0.5.0 | MIT OR Apache-2.0 | yes |
| rangemap | 1.8.0 | MIT/Apache-2.0 | yes |
| read-fonts | 0.39.2 | MIT OR Apache-2.0 | yes |
| read-fonts | 0.46.0 | MIT OR Apache-2.0 | yes |
| regex-syntax | 0.8.11 | MIT OR Apache-2.0 | yes |
| roxmltree | 0.20.0 | MIT OR Apache-2.0 | yes |
| roxmltree | 0.21.2 | MIT OR Apache-2.0 | yes |
| rqrr | 0.11.0 | (MIT OR Apache-2.0) AND ISC | yes |
| rustc-hash | 2.1.3 | Apache-2.0 OR MIT | yes |
| rustix | 1.1.6 | Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT | yes |
| rustversion | 1.0.23 | MIT OR Apache-2.0 | yes |
| rusty-fork | 0.3.1 | MIT/Apache-2.0 | yes |
| rustybuzz | 0.20.1 | MIT | yes |
| ryu | 1.0.23 | Apache-2.0 OR BSL-1.0 | yes |
| scopeguard | 1.2.0 | MIT OR Apache-2.0 | yes |
| serde | 1.0.229 | MIT OR Apache-2.0 | yes |
| serde_core | 1.0.229 | MIT OR Apache-2.0 | yes |
@@ -213,29 +248,48 @@ Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
| shlex | 2.0.1 | MIT OR Apache-2.0 | yes |
| simd-adler32 | 0.3.10 | MIT | yes |
| simdutf8 | 0.1.5 | MIT OR Apache-2.0 | yes |
| simplecss | 0.2.2 | Apache-2.0 OR MIT | yes |
| siphasher | 1.0.4 | MIT OR Apache-2.0 | yes |
| skrifa | 0.42.1 | MIT OR Apache-2.0 | yes |
| skrifa | 0.49.0 | MIT OR Apache-2.0 | yes |
| slab | 0.4.12 | MIT | yes |
| slotmap | 1.1.1 | Zlib | yes |
| smallvec | 1.16.5 | MIT OR Apache-2.0 | yes |
| stable_deref_trait | 1.2.1 | MIT OR Apache-2.0 | yes |
| strict-num | 0.1.1 | MIT | yes |
| stringprep | 0.1.5 | MIT/Apache-2.0 | yes |
| subsetter | 0.2.6 | MIT OR Apache-2.0 | yes |
| svgtypes | 0.16.2 | Apache-2.0 OR MIT | yes |
| syn | 2.0.119 | MIT OR Apache-2.0 | yes |
| syn | 3.0.10 | MIT OR Apache-2.0 | yes |
| synstructure | 0.14.0 | MIT | yes |
| tempfile | 3.27.0 | MIT OR Apache-2.0 | yes |
| thiserror | 2.0.21 | MIT OR Apache-2.0 | yes |
| thiserror-impl | 2.0.21 | MIT OR Apache-2.0 | yes |
| tiff | 0.11.3 | MIT | yes |
| tiny-skia | 0.12.0 | BSD-3-Clause | yes |
| tiny-skia-path | 0.12.0 | BSD-3-Clause | yes |
| tinyvec | 1.13.3 | Zlib OR Apache-2.0 OR MIT | yes |
| tokio | 1.54.1 | MIT | yes |
| toml_datetime | 1.1.3+spec-1.1.0 | MIT OR Apache-2.0 | yes |
| toml_edit | 0.25.19+spec-1.1.0 | MIT OR Apache-2.0 | yes |
| toml_parser | 1.1.5+spec-1.1.0 | MIT OR Apache-2.0 | yes |
| ttf-parser | 0.25.1 | MIT OR Apache-2.0 | yes |
| typed-path | 0.12.4 | MIT OR Apache-2.0 | yes |
| typenum | 1.20.1 | MIT OR Apache-2.0 | yes |
| unarray | 0.1.4 | MIT OR Apache-2.0 | yes |
| unicode-bidi | 0.3.18 | MIT OR Apache-2.0 | yes |
| unicode-bidi-mirroring | 0.4.0 | MIT/Apache-2.0 | yes |
| unicode-ccc | 0.4.0 | MIT/Apache-2.0 | yes |
| unicode-ident | 1.0.27 | (MIT OR Apache-2.0) AND Unicode-3.0 | yes |
| unicode-normalization | 0.1.26 | (MIT OR Apache-2.0) AND Unicode-3.0 | yes |
| unicode-properties | 0.1.5 | (MIT OR Apache-2.0) AND Unicode-3.0 | yes |
| unicode-script | 0.5.9 | MIT OR Apache-2.0 | yes |
| unicode-vo | 0.1.0 | MIT/Apache-2.0 | yes |
| usvg | 0.50.0 | Apache-2.0 OR MIT | yes |
| utf16string | 0.2.0 | MIT OR Apache-2.0 | yes |
| vecmath | 1.0.0 | MIT | yes |
| version_check | 0.9.5 | MIT/Apache-2.0 | yes |
| wait-timeout | 0.2.1 | MIT/Apache-2.0 | yes |
| wasm-bindgen | 0.2.130 | MIT OR Apache-2.0 | yes |
| wasm-bindgen-futures | 0.4.80 | MIT OR Apache-2.0 | yes |
@@ -258,8 +312,14 @@ Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
| windows-sys | 0.61.2 | MIT OR Apache-2.0 | yes |
| windows-threading | 0.2.1 | MIT OR Apache-2.0 | yes |
| winnow | 1.0.5 | MIT | yes |
| write-fonts | 0.48.1 | MIT OR Apache-2.0 | yes |
| xmlwriter | 0.1.0 | MIT | yes |
| yoke | 0.8.4 | Unicode-3.0 | yes |
| yoke-derive | 0.8.4 | Unicode-3.0 | yes |
| zerocopy | 0.8.63 | BSD-2-Clause OR Apache-2.0 OR MIT | yes |
| zerocopy-derive | 0.8.63 | BSD-2-Clause OR Apache-2.0 OR MIT | yes |
| zerofrom | 0.1.8 | Unicode-3.0 | yes |
| zerofrom-derive | 0.1.8 | Unicode-3.0 | yes |
| zip | 8.6.0 | MIT | yes |
| zlib-rs | 0.6.8 | Zlib | yes |
| zmij | 1.0.23 | MIT | yes |
+58 -1
View File
@@ -63,6 +63,61 @@ XObjects, inline images, clipping, shadings, Type 3 fonts), and any gap leaves t
(`crates/pdf/tests/redaction.rs`) check pdfium text extraction, a lopdf scan of every string, name and stream (raw
and decompressed), and a raw byte grep.
## The .pictor document (crates/doc), format 1
A `.pictor` file is a zip:
| Entry | What |
| :-- | :-- |
| `document.json` | the document (below), compressed |
| `assets/<id>.png` | the pixels of each bitmap layer and placed picture, RGBA, stored (PNG is already compressed) |
| `fonts/<sha256>.ttf` / `.otf` | the fonts the document uses whose licence allows embedding (OS/2 `fsType` installable or editable) |
`document.json` (every length in points, 1/72 in; a document made from an image has 1 pt = 1 px):
```
{ "format": 1, "next_id": 12,
"pages": [ { "id": 1, "width": 595.276, "height": 841.89, "margins": [t, r, b, l], "guides": [{"vertical": true, "at": 297.6}],
"background": [255, 255, 255, 255] | null,
"layers": [ { "id": 2, "name": "Layer 1", "visible": true, "locked": false, "opacity": 1,
"kind": "vector", "objects": [ … ] }
| { …, "kind": "bitmap", "asset": "b3", "x": 0, "y": 0, "w": 800, "h": 600 }
| { …, "kind": "group", "layers": [ … ] } ] } ],
"assets": [ { "id": "b3", "width": 800, "height": 600 } ],
"fonts": [ { "family": "Georgia", "weight": 700, "italic": false, "file": "fonts/<sha256>.ttf" } ] }
```
An object is `{ "id", "name", "transform": [a, b, c, d, e, f], "opacity", "visible", "locked", "fill", "stroke",
"shape" }` with `shape.type` one of `rect {w, h, radius}`, `ellipse {w, h}`, `line {x1, y1, x2, y2, arrow_start,
arrow_end}`, `path {d}` (absolute or relative M L H V C Q Z; no arcs), `text {w, text, style}` (style: `family,
weight, italic, size, color, align` left / center / right / justify, `line_height` as a multiple of the size,
`letter_spacing` in points), `image {asset, w, h, crop {x, y, w, h}}` (the whole picture's place inside the frame)
or `group {objects}`. A paint is `{"type": "solid", "color": [r, g, b, a]}`, `linear {x1, y1, x2, y2, stops}` or
`radial {cx, cy, r, stops}` with coordinates as fractions of the shape's box; a stroke is `{paint, width, dash, cap,
join}`. Colours are sRGB with straight alpha.
**Reading is strict** (`format::read`, `Limits`): at most 4096 entries; every entry name relative, without `..`,
`\`, `:` or empty parts, no directories or links (refused even when unused); entries are read by known name, never
extracted; `document.json` at most 64 MB and any entry 256 MB, the whole 1 GB, and no entry over 1 MB may expand
more than 1000×; the declared size must be the real one; `format` is read first and a newer one is refused
("made by a newer Pictor"); ids unique and below `next_id`, numbers finite, pages 1–14 400 pt, opacities 0–1, paths
parsed, nesting at most 32 deep; every picture at most 100 MP (400 MP together), decoded with its declared size as
the limit, and every asset a layer or object refers to must be present. A font must parse.
**Undo** is an operation log (`ops::Op`, `ops::History`): insert / remove / set a page, layer or object, replace an
object, patch an asset's pixels, put an asset, a batch. Applying an operation returns its exact inverse.
**Rendering** goes through one display list (`display::build`): fills, strokes, images (with a clip), glyph runs
(glyph outlines in font units, defined once) and opacity groups. The core paints it with tiny-skia; the app's
canvas painter follows the same rules; the PDF and SVG exports walk it too.
**PDF export** (`export::pdf`): pdf-writer; vectors as paths, gradients as shading patterns (a gradient's stops
share one alpha, their average), opacity as ExtGState alpha or an isolated transparency group, pictures as
FlateDecode RGB with an SMask, text as Type 0 fonts (Identity-H, CIDs are the subset's glyph ids, CIDToGIDMap
Identity) with a ToUnicode map and widths, so the layout's positions are kept with TJ adjustments; a font whose
`fsType` is restricted or bitmap-only is refused with its name and the reason; fonts that forbid subsetting are
embedded whole. Each page's MediaBox is its exact size.
## The worker protocol (crates/worker), version 1
`pictor-worker.exe` reads one JSON object per line on stdin and answers one per line on stdout. Its first line is
@@ -75,7 +130,7 @@ and decompressed), and a raw byte grep.
```
Error kinds: `needs_password`, `wrong_password`, `damaged`, `unsupported`, `too_large`, `codec_missing`, `invalid`,
`io`, `exists`, `not_open`, `cannot_reach_target`, `engine_missing`; the client adds `timed_out`,
`io`, `exists`, `not_open`, `newer` (a .pictor from a newer Pictor), `cannot_reach_target`, `engine_missing`; the client adds `timed_out`,
`out_of_memory`, `crashed` and `spawn`. `message` is a plain sentence for the user.
| Operation | Arguments | Result |
@@ -98,6 +153,8 @@ Error kinds: `needs_password`, `wrong_password`, `damaged`, `unsupported`, `too_
| `image.probe` | `path` | `format`, `width`, `height`, `has_alpha`, `frames`, `bytes` |
| `image.thumb` | `path`, `max` | `png`, original `width`, `height` |
| `image.convert` | `input`, `output`, `format`, `quality?`, `crop?`, `rotate?`, `resize?`, `preset?`, `target_bytes?`, `overwrite?` | `path`, `bytes`, `format`, `width`, `height` |
| `doc.open` | `input`, `output` | `path`, `pages`, `format` (a clean .pictor of the worker's making at `output`) |
| `doc.import_svg` | `input`, `output` | `path`, `width`, `height` (the SVG as a one-page .pictor; text as outlines) |
| `image.heif_support` | — | `support` |
| `meta.read` | `path` | `report` (items by group), `groups` (with labels) |
| `meta.strip` | `input`, `output`, `overwrite?` | `path`, `removed` |