main's gate fails here for every pull request: `!(r < 1.0 || r > 359.0)` is
exactly what `manual_range_contains` rejects. Express the same range as
`(1.0..=359.0).contains(&r)`.
* 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.
Main's VML fallback (#1864) read the writer's z counter after the anchor was written. That counter now only counts objects without a stored order, so a stored order's fallback got the wrong z-index. The anchor's relativeHeight is now kept in anchor_z for the fallback, and the wps_fallback tests expect the written relativeHeight (one less than Float::z).
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>
Float::z kept relativeHeight as read, so a file's 0, the lowest order a
file can give, read as 0, "none", which stacks above every object. z is
now one more than the file's (as ODF's draw:z-index is read), and
Float::stack gives the stacking key. The writer writes stored orders one
less, numbers objects made in the app above every stored one, and
numbers the stored ones again from Word's first order when u32::MAX
leaves no room above them. Document::stacking_orders counts every story
saved with the document, the glossary's building blocks included.
Moved from storytold/wordcraft#2655 (wordcraft#2638), whose DOCX reader
and writer now live here.
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.
Word draws markers without their own fill in the automatic palette colour of the
series index, not the explicit line colour. Line and scatter data labels sit to
the right of the point unless c:dLblPos says t, b, l, r or ctr. A vertical-axis
title with rot="0" stays horizontal, wrapped into a strip of at most a quarter of
the chart width, instead of being forced to -90 degrees.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A chart file carried three things that were read but not drawn like Word:
- c:marker/c:symbol was ignored (every marker was a circle): squares, diamonds,
triangles, x, plus, star, dash and dot are drawn now, in the series' c:size;
unknown names fall back to a circle, sizes are clamped to 2..72 points.
- c:dLbls/c:numFmt (not linked to the source) now formats the data labels, on
the series or on the chart type; over-long codes are ignored.
- The vertical axis title is turned -90 degrees (reading upwards) as Word does,
or 90 when the file's bodyPr rot says so. It was always +90.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The reader counted UTF-8 bytes against 255 while the model keeps 128 characters,
so a CJK axis format was written and then dropped on reading. Use MAX_FMT.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.