Commit Graph
3 Commits
Author SHA1 Message Date
kiwi4boy 14b2ebb7c2 craft-rtf: one index lookup per insert, and no key String for a known author
`Interned::insert` looked the key up and then inserted it, two probes for a
new key. It now goes through `HashMap::entry`, one probe either way, and
counts that probe itself, so the tests count what the index does.

`author()` built a `String` key on every call. It now looks the author up
borrowed first, and allocates only for a new one.

Review on #1467.
2026-11-14 21:24:56 -05:00
kiwi4boy 74495a579a craft-rtf: look up fonts, colours and authors through an index (#1466)
Both writers found each run's font and colour by scanning the table so far
(write.rs `Tables`, doc/export.rs `Tables` and `author` for `\revtbl`), so
a document with n distinct fonts or colours took O(n²) comparisons. 3,000
runs with their own font and colour took 18,006,000 steps in the small
writer and 13,498,500 in the word-model writer.

Each table stays a Vec, in first-use order, so the output is unchanged.
`Interned` adds a map from key to place beside it: the colour, the font
name lowercased (as `eq_ignore_ascii_case` matched), or the trimmed author.

Tests count lookups through a test-only counter, as PdfCraft's own RTF
writer does: at most four per run for 3,000 runs in each writer, and font
names still match without regard to ASCII case.
2026-11-14 21:04:34 -05:00
Dylan M. Taylor 7fe902292f craft-rtf: WordCraft's RTF reader and writer on craft-wordmodel and craft-flow (feature doc)
craft-rtf: WordCraft's RTF reader and writer on craft-wordmodel and craft-flow (feature doc)

* Add craft-wordmodel: WordCraft's document model without its editing code

WordCraft's crates/doc (wordcraft-doc, at 07f97737) moved as it is, so the DOCX,
RTF, ODT and other text-format crates can read into and write from one model.
Module paths, type names and serde attributes are unchanged: an app that
re-exports the crate keeps its native file format.

Left in the app: range editing (edit.rs), IME text and equation editing. Not
model, and already in craft-libs: code pages (craft-rtf), the ZIP entry-count
check (craft-opc), the compound-file guard (craft-cfb). The paragraph walks
moved to walk.rs and the unit helpers of wordcraft-geom to geom.rs.

* craft-wordmodel: math_tree, the arguments of an equation node and a walk over its runs

The DOCX reader and writer walk an equation's runs. The walk and the child
accessors it uses were in WordCraft's equation editor (math_edit.rs), which
stays in the app; they are structure, not editing.

* craft-wordmodel: keep the document operations (edit.rs) with the model

The DOCX and RTF readers use them: alternative-format chunks are merged into
a document with adopt_blocks, and a reader formats ranges with format_range
and inserts objects. They operate on the document, not on a view, so they
belong beside it. The tests that drove them come back with them; the
paragraph walks stay in walk.rs and edit re-exports them.

base64 0.23, as WordCraft and craft-offcrypto use.

* Add craft-flow: the flow model the text formats map to, on craft-wordmodel

WordCraft's crates/formats/src/model (07f97737) moved as it is: Flow,
FBlock, Para, Inline, Fmt, tables and cells, pictures, to_doc and
from_doc, picture sniffing, colours, base64 and the Dropped report. Only
the paths changed (wordcraft_doc is craft_wordmodel); the report helpers
are public so the format crates can call them; the image re-encoding
helper stays with WordCraft's RTF writer.

* wip: WordCraft's RTF interpreter, as it is

* Take main's side of files outside craft-rtf

* craft-rtf: WordCraft's RTF reader and writer as they are at wordcraft 07f97737

crates/formats/src/rtf.rs and crates/formats/src/rtf/, unchanged and not yet
compiled (no module declares them), so the next commit shows only what the
move changes.

* craft-rtf: WordCraft's RTF reader and writer as craft_rtf::doc (feature doc)

On craft-flow and craft-wordmodel, with this crate's code pages
(craft-codepage), dates and escaping in place of WordCraft's copies, and
craft-metafile's metafile sniffing. A picture in a format RTF cannot carry is
re-encoded as PNG with a bounded decode (100 megapixels, 512 MiB), as
WordCraft's picture decoder bounded it.

The 76 tests moved with it.
2026-11-11 22:44:19 -05:00