* wordmodel: keep the kashida length of a justified paragraph
ST_Jc lowKashida, mediumKashida and highKashida were all read as
Align::Justify, so the length was lost. ParaProps and ResolvedPara now
keep it; a direct both/justify cancels an inherited length. The DOCX
reader and writer round-trip the three values.
* docx: keep a style's kashida length when writing justify
w:jc encodes alignment and kashida together. A paragraph or style
with Align::Justify and kashida unset still inherits a length from
the style chain; writing "both" would read back as Some(Kashida::None)
and cancel it. Use the resolved length in that case.
An app that ships the writer under its own name names itself in docProps/app.xml
(<Application>); "WordCraft" until set.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* craft-docx: write Word 2010 shapes inside mc:AlternateContent with a VML fallback
A shape was written as a bare `wps:wsp` in `w:drawing`. Word 2007, and
Word 2000-2003 with the Office Compatibility Pack, don't know `wps` and
refuse the whole file. Word writes such shapes in `mc:AlternateContent`.
`write_shape` now guards the drawing with `mc:Choice Requires="wps"` and,
for rectangles, text boxes, rounded rectangles and ellipses, adds an
`mc:Fallback` with the shape as VML: size, position, z-order, wrapping,
fill, outline and the text box's text (copied from the choice's output,
so the story isn't written twice). Other kinds get no fallback; an old
reader skips that shape and still opens the file.
Refs storytold/wordcraft#6849
* craft-docx: guard a shape only when it gets a VML fallback; keep more in the fallback
A shape guarded by `mc:AlternateContent` with no fallback is skipped by
a reader that doesn't know `wps`, and dropped on that reader's next save:
worse than refusing the file. Such shapes are written bare again; only
shapes with a VML form are guarded.
The VML fallback also keeps the shape's own stacking order (a floating
object in its text box moved `self.z` on), its wrap distances, its hidden
flag and its text box's text direction.
* craft-docx: keep behind-text shapes' order in the VML fallback
A behind-text shape's fallback `z-index` was the negated `z`, which
reverses the order of overlapping behind-text shapes. It is now `z`
shifted below zero within signed 32-bit range, so a higher `z` still
stacks higher; other shapes' `z-index` is capped at `i32::MAX`.
* fix(docx): preserve linked text boxes without an incomplete VML fallback
---------
Co-authored-by: Andy Ching <53651198+andyching168@users.noreply.github.com>
Moves the format part of storytold/wordcraft#6162 into craft-wordmodel,
craft-docx, craft-flow and craft-odf, where WordCraft's DOCX and ODT I/O now
live (#778).
A DrawingML `prstGeom frame` (a letterhead's page border) was read as a
rectangle, so its fill covered the whole page behind the text. It is now
ShapeKind::Frame, its border width read from `adj1` (capped, as a rounded
rectangle's corner is) and written back as the same preset.
connector::frame_width gives the border in points. Formats with no frame
shape (ODT and the other flow formats) get the freeform it draws: its
outline and, wound the other way, its hole, so the hole stays empty under
either fill rule.
A behind-text shape's fallback `z-index` was the negated `z`, which
reverses the order of overlapping behind-text shapes. It is now `z`
shifted below zero within signed 32-bit range, so a higher `z` still
stacks higher; other shapes' `z-index` is capped at `i32::MAX`.
A shape guarded by `mc:AlternateContent` with no fallback is skipped by
a reader that doesn't know `wps`, and dropped on that reader's next save:
worse than refusing the file. Such shapes are written bare again; only
shapes with a VML form are guarded.
The VML fallback also keeps the shape's own stacking order (a floating
object in its text box moved `self.z` on), its wrap distances, its hidden
flag and its text box's text direction.
A shape was written as a bare `wps:wsp` in `w:drawing`. Word 2007, and
Word 2000-2003 with the Office Compatibility Pack, don't know `wps` and
refuse the whole file. Word writes such shapes in `mc:AlternateContent`.
`write_shape` now guards the drawing with `mc:Choice Requires="wps"` and,
for rectangles, text boxes, rounded rectangles and ellipses, adds an
`mc:Fallback` with the shape as VML: size, position, z-order, wrapping,
fill, outline and the text box's text (copied from the choice's output,
so the story isn't written twice). Other kinds get no fallback; an old
reader skips that shape and still opens the file.
Refs storytold/wordcraft#6849
Take the title of an Office 2016 chart from its rich text (all runs) or its text data, and draw the placeholder frame without a fill so it does not become a white box on a coloured page. The run-fallback test is a guard and says so.
Part of storytold/wordcraft#6820
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
read_chartex_alternate built the chart object only from a picture fallback. With a fallback
that holds only text (for example "Chart not available."), it returned None and the reader
used the fallback words, so the chart's 432 x 252 pt frame was never reserved and the pages
collapsed.
Now such a chart becomes a Chart graphic of the choice's wp:extent, drawn as the same kind of
placeholder unsupported classic charts get (frame, title, chart type), with the choice and
fallback kept so saving writes them back unchanged. A fallback that holds runs or paragraphs
is still read as before, because the writer puts the fallback inside the object's own run.
The frame reading at the top of read_drawing moves into drawing_frame so both paths share it.
Part of storytold/wordcraft#6820
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The merge unit test compared Options, and its generated part had no
w:mirrorMargins, so the order check proved nothing; put the element in
and look the positions up. Add the False and FALSE spellings to the
value test.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The reader ignored w:gutterAtTop in settings.xml (it was only carried
through on save), so an app using the model could not tell that Word adds
the gutter to the top margin instead of the left one. Add
Settings::gutter_at_top (document-wide, off by default), read it with the
shared on/off helper, write it after w:mirrorMargins and before
w:attachedTemplate, and make the settings merge treat it as a modelled
child so turning it off removes it.
Tests: round trip and default off, every on/off spelling, merge into a
settings part from another writer (keep, remove, insert in schema order).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Word 2007 writes shapes, pictures and WordArt in a drawing as an
lc:lockedCanvas (ECMA-376 Part 1 20.3.2.1) in compatibility mode. Only
its first picture was read; its shapes and their text were dropped. The
canvas is now rewritten as the wpg group the reader already handles,
its DrawingML text as text-box paragraphs with their run formatting.
Moved from storytold/wordcraft#5067 (wordcraft#5060), whose DOCX reader
now lives here.
Port of storytold/wordcraft#3821, whose reader code moved here with storytold/wordcraft#6603. Word's 0.08" cell margin comes from the Normal Table default table style; without a default table style a table that sets no margins (and whose style sets none) has zero margins. The zeros are kept as the table's own, also for the old properties of a tblPrChange, so they survive saving. w:default="on" now marks a default style too.
Measured in Word for Windows: Thai text as a field's result follows the rule ordinary text does. mark_runs_as_word_draws_them counts the result of a field kept as one object as the text of its run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moved from the DOCX part of storytold/wordcraft#6244. Runs are marked with what Word counts as complex script (the run, its paragraph style chain, its table style and the run defaults, not a character style). StyleSheet::table_cells_chr works out a table's cell run formatting once; ResolvedChar gains cs_off.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* 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.
* craft-docx: WordCraft's crates/docx as it is at wordcraft 07f97737
The source, unchanged, so the next commit shows only what the move changes.
This commit does not build on its own (it still names wordcraft-doc and
wordcraft-geom, and is not a workspace member yet).
* craft-docx: on craft-wordmodel, craft-opc, craft-xml and craft-offcrypto
- The package (zip reading, part names, relationships, content types,
zip writing) is craft-opc's; the module keeps WordCraft's bookkeeping
(passthrough keys, the embedded-part manifest) and its own Rel/Rels shape.
- Parts are parsed with craft-xml's canonical names (the Strict drawing
names and mc:Choice/@Requires through its hooks), then given the tree
shape the reader was written against.
- Encryption and Restrict Editing hashes are craft-offcrypto's; this crate
maps its errors and the w:documentProtection attributes.
- wordcraft-doc is craft-wordmodel; wordcraft-geom's helpers are its geom.
Tests that covered what now lives in craft-opc and craft-offcrypto are left to
those crates; the DIFAT regression is craft-cfb's. Test-only zip use follows
zip 9's fallible names. The attribute-cap test times the read only.
* craft-docx: DrawingML colours through craft-drawingml
Preset colours and the colour transforms of a:srgbClr, a:schemeClr and the
other colour elements are craft-drawingml's (craft_drawingml::color::preset,
ColorTransform, apply); opacity stays here, in percent.
craft-drawingml's preset table takes WordCraft's names (19 more, and the
dk/lt/grey spellings) and is case-insensitive, as WordCraft's was.
Two behaviours change, both to what craft-drawingml and LibreOffice do:
- a:tint and a:shade mix in linear light, not in sRGB bytes (a 50% shade of
64 128 192 is 44 92 140, not 32 64 96); two tests are updated;
- the transforms WordCraft ignored (hueMod, hueOff, satOff, comp, inv, gray,
redMod, greenMod, blueMod) are applied.
* craft-drawingml: test the preset names in any case and their dk/lt spellings
* 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.
* craft-docx: WordCraft's crates/docx as it is at wordcraft 07f97737
The source, unchanged, so the next commit shows only what the move changes.
This commit does not build on its own (it still names wordcraft-doc and
wordcraft-geom, and is not a workspace member yet).
* craft-docx: on craft-wordmodel, craft-opc, craft-xml and craft-offcrypto
- The package (zip reading, part names, relationships, content types,
zip writing) is craft-opc's; the module keeps WordCraft's bookkeeping
(passthrough keys, the embedded-part manifest) and its own Rel/Rels shape.
- Parts are parsed with craft-xml's canonical names (the Strict drawing
names and mc:Choice/@Requires through its hooks), then given the tree
shape the reader was written against.
- Encryption and Restrict Editing hashes are craft-offcrypto's; this crate
maps its errors and the w:documentProtection attributes.
- wordcraft-doc is craft-wordmodel; wordcraft-geom's helpers are its geom.
Tests that covered what now lives in craft-opc and craft-offcrypto are left to
those crates; the DIFAT regression is craft-cfb's. Test-only zip use follows
zip 9's fallible names. The attribute-cap test times the read only.