Files
craft-libs/crates/docx
aiongg ac3dfd1f53 Merge storytold main into next (17 Nov sync)
storytold main 83cb1133dd (291 commits) into the integration head bab1a99b85; 47 conflicted files.

- Domain test files (metafile, prepress, pdf plates, settings store, heif, media-testkit, atomic): tests next cut stay cut; tests new on main are kept, as trials where the crate's test target runs trials.
- atomic: main's group-bits test and Faulty::set_group go to src/tests.rs. audio: main's GSM and SBC oracles join tests/main.rs. cms constructors, pdf knockout_backdrop and testing_pdf join their crates' one test binary; timeline's preflight tests become src/preflight_tests.rs trials.
- update: main's changes to detect, install (linux, macos) and the tests land in next's split modules. The app's own offer is inspected on a thread of its own, picked up by tick's polling; settle_for_tests settles offers too. Later on a ready update drops the close it asked for. updater_pin_tests.rs stays deleted; its new pin test is in tests/it/update.rs.
- craft-color: main added a different crate at crates/color (the colour tags of compositor and display frames); it is next's craft-color module `tags`, re-exported at the root.
- Old crates/ui (combo, docking, testing, README) and keymap's ui/view.rs stay deleted; main's new crates/ui/src/testing files are dropped with them.
- New crates in the craft facade: ai, control, dds, frame, ipc, media-source, palette, press-print, score, ssip. testkit and xtask are listed outside it.
- Cargo.lock: the union of both locks, resolved by cargo metadata. Workflow: main's nextest Windows leg, with next's --keep-going clippy.
2026-11-17 12:44:52 +00:00
..

craft-docx

DOCX (ECMA-376 / ISO/IEC 29500 WordprocessingML) read and written, on the craft-wordmodel document model. Also Word XML Documents (Flat OPC, one .xml file holding the whole package) and Word 2003 XML, password-protected packages and Restrict Editing password hashes.

It is WordCraft's DOCX crate, moved onto the shared crates: craft-opc for the package, craft-xml for parsing, craft-offcrypto for encryption, craft-wordmodel for the model.

use craft_wordmodel::Document;

let doc = Document::from_text("Hello\nWorld");
let bytes = craft_docx::write(&doc).unwrap();
let back = craft_docx::read(&bytes).unwrap();
assert_eq!(back.plain_text(craft_wordmodel::StoryRef::Body), doc.plain_text(craft_wordmodel::StoryRef::Body));

Reading

  • read(bytes), read_with(bytes, &ReadOptions { password, chunks }), read_with_password.
  • read_xml(bytes): a Word XML Document or a Word 2003 XML Document, told apart by its root.
  • package_title(reader, max_part): the title in docProps/core.xml, inflating only that part.

The reader is lenient (unknown markup is skipped, bad numbers fall back to defaults) and bounded:

Limit Value
ZIP entries 20,000 (checked before the archive is indexed)
One part 256 MiB
All parts 512 MiB, counting entries that fail their checksum
XML nesting 256 open elements
XML elements 8,000,000 in one part
Attributes 1,024 on one element
Word XML file 1 GiB

Markup the model does not hold is kept in Document::passthrough and the kept markup, and written back as it was read.

Writing

write(doc), write_as(doc, Flavor) for .docx, .docm, .dotx and .dotm; write_flat and write_wordml2003 for the XML forms; encrypt for a password.

Equations (OMML) are read and written by craft_math::omml.

Not here yet

  • DrawingML (a:) shape fills, lines, custom geometry and colours are still read with this crate's own code; they move to craft-drawingml.