Commit Graph
14 Commits
Author SHA1 Message Date
Dylan M. Taylor 95d118a095 Merge pull request #1287 from vangel76/feat/rtf-rtl-paragraphs
RTF keeps right-to-left paragraph direction
2026-11-15 18:24:29 -05:00
vangel76andClaude Sonnet 5.5 51a35cecb7 flow: keep the old paragraph direction in the tracked formatting-change snapshot
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 13:27:34 +01:00
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
vangel76andClaude Sonnet 5.5 537d61a60f rtf: read \ql and \qr after \rtlpar as start and end
The model's paragraph alignment is logical (start/end) in right-to-left
paragraphs, but the reader mapped \ql/\qr straight to left/right. For a
\rtlpar paragraph that mirrored the alignment compared to Word.

Word reads a side word that follows \rtlpar as start/end, and one that comes
before it as plain left/right (checked black-box by saving RTF variants to
DOCX). So \rtlpar\qr is start (no explicit alignment), \rtlpar\ql is end, and
\qr\rtlpar is end. The writer already puts the alignment before \rtlpar, so
its output keeps its meaning and is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 01:05:40 +01:00
vangel76andClaude Sonnet 5.5 d869560911 rtf: keep direction words in old paragraph formatting
\rtlpar, \ltrpar, \rtldir and \ltrdir are paragraph formatting words, so
\oldpprops holds them and a tracked direction change keeps the old direction.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 22:01:59 +01:00
vangel76andClaude Sonnet 5.5 376fa26e4c rtf: read paragraph direction from stylesheet entries
A style's \rtlpar/\ltrpar (and \rtldir/\ltrdir) is stored with the style and
found through \sbasedon. A paragraph in the style gets it unless it sets its own
direction; \pard drops the direct direction and the style's stays.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 22:01:59 +01:00
Dylan M. Taylor 4fa98367f8 rtf: preserve legacy invalid Unicode handling 2026-11-14 11:10:12 +00:00
vangel76andClaude Sonnet 5.5 a528fa7430 rtf: keep right-to-left paragraph direction
Read \rtlpar/\rtldir and \ltrpar/\ltrdir into the paragraph's bidi flag
and write \rtlpar for right-to-left paragraphs. The flow paragraph
carries the direction between the document and the RTF reader/writer.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 11:23:04 +01: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
Dylan M. Taylor db762f02f9 craft-rtf, craft-webp: restore the outlook and vp8 features later squash merges dropped (#1072)
#991 (craft-codepage) was squash-merged from a branch that predated #961 and carried its older
crates/rtf/Cargo.toml, dropping the outlook feature, its craft-mime dependency and the proptest
dev-dependency; the outlook module was left behind an undefined cfg. #1028 did the same to
crates/webp/Cargo.toml after #1021, dropping the vp8 feature and its craft-video dependency.
2026-11-11 21:30:17 -05:00
Dylan M. Taylor c516452b47 craft-codepage: one table per legacy code page, for craft-rtf, craft-dxf and craft-mime (#991)
craft-rtf and craft-dxf each carried tables for DOS 437, 737, 850, 852 and
857 (and craft-rtf one for 866). They are now one set in craft-codepage,
which takes craft-rtf's codepage module (Windows and Mac tables, OEM glyphs,
font charsets) and craft-dxf's DOS tables. craft_rtf::codepage re-exports it
unchanged; craft-dxf keeps its $DWGCODEPAGE names and Decoder and looks the
DOS tables up there.

Every byte of every code page either crate decodes is unchanged: the
public decoders of both crates were dumped over all 256 bytes of each page
(and the East Asian pairs) before and after, and the dumps are identical.

craft-mime now reads the DOS pages by their IANA names (IBM437, cp850,
ibm-852, 857...), which it read as UTF-8 before.
2026-11-11 20:17:35 -05:00
Dylan M. TaylorandMartin Ball 53e1717523 craft-rtf: Outlook compressed RTF and body text, from MailCraft (#961)
The outlook feature adds MailCraft's reader of PidTagRtfCompressed
([MS-OXRTFCP]) and of the text and encapsulated HTML ([MS-OXRTFEX]) of the
RTF inside, from crates/pst/src/rtf.rs at a44a450. Font charsets use this
crate's charset_code_page table; code pages are decoded by craft-mime.

Co-authored-by: Martin Ball <98639962+benandez@users.noreply.github.com>
2026-11-11 19:25:27 -05:00
Dylan M. TaylorandSimon Koch-Sultan 9ab7768771 Add craft-rtf: RTF tokenizer, code pages, and a reader and writer for a small model (#890)
* Add craft-rtf: RTF tokenizer, text decoding, and a reader and writer for a small model

The tokenizing rules, code pages, multibyte decoding, dates and escaping come
from WordCraft's RTF reader and writer. The model (paragraphs with outline
level and indent, character formatting, tables) covers what DesignCraft's text
import, DeckCraft's outline import and export and PdfCraft's export use.

An unpaired UTF-16 surrogate in \u reads as U+FFFD and a high surrogate pairs
only with the very next \u, as storytold/wordcraft#6105 describes for Word.

* craft-rtf: a symbol font's bytes are its own codes

A font with \fcharset2 (Symbol, Wingdings) has no letters: a byte from 0x80
reads as U+F000 + the byte instead of a letter of the document's code page.
The symbol page applies to body text only, a symbol default font's page does
not apply to text in a font chosen with \f, \plain makes the default font's
page current again, and a code page an entry names with \cpg is kept.

Ported from storytold/wordcraft#6014.

* craft-rtf: alignment, indents, spacing, superscript and subscript; NUL is not text

The model and both directions gain what DesignCraft's RTF export writes:
\ql \qc \qr \qj, \ri, \fi, \sb, \sa, \super, \sub, \nosupersub.
A \u0 or \'00 no longer puts a NUL into the text.

---------

Co-authored-by: Simon Koch-Sultan <126534658+scks1@users.noreply.github.com>
2026-11-11 17:26:57 -05:00