mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-08 19:51:32 +00:00
## What changed Word stores paragraph indents (`w:ind` left/start, right/end, hanging, firstLine) in 16 signed bits and paragraph spacing (`w:spacing` before/after) in 16 unsigned bits. A file that writes a larger plain integer is read by Word modulo 2^16: `w:left="66256"` is a 720-twip (0.5") indent in Word. We read the full value, so such a paragraph was indented by about 46 inches and its text was pushed off the page. - `crates/docx/src/units.rs`: new `tw_i16` / `tw_u16` readers. A plain integer keeps its low 16 bits (two's complement for indents, so 66256 -> 720 and 65535 -> -1); values with a unit or a fraction read as before. - `crates/docx/src/read/props.rs` and `read/styles.rs` use them for `w:ind` and `w:spacing` before/after, in direct and style formatting. - In-range values read exactly as before. ## Testing - `crates/docx/tests/it/twips_wrap.rs`: synthetic documents with out-of-range indents and spacing in paragraph and style properties check the wrapped values; in-range values and values with units are unchanged. - Unit tests for the two readers; `cargo xtask ci` passes. Found by a real-file corpus comparison against Word's own PDFs: a file whose indents exceed 16 bits shows its text on the page in Word and off the page here. Co-authored-by: tpawley2001 <268951182+tpawley2001@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Martin Ball <martin.ball@ucscaregroup.co.uk>