`o:allowincell="f"` on a VML shape anchored in a body table cell now sets
`Float::outside_cell`, as `layoutInCell="0"` already does for DrawingML.
Word places such a shape outside its cell, and the cell's text does not wrap
around it. Without the attribute, or with it on, the shape stays in its cell.
The writer already saved `o:allowincell` from `outside_cell`, so the setting
now survives open and save.
Review fixes: a file with an empty w:tblGrid keeps the inch per column it had; a cell narrower
than the narrowest column counts as that column before a span shares out what it lacks, so the
span keeps its width; a span cut off at the last column the reader keeps sizes its kept columns
by their share and gives the rest to no other column.
Template libraries write tables with no w:tblGrid. The reader gave every column an inch, so such a
table came out at the wrong width whatever its cells asked for. Word rebuilds the grid from the
cells on opening: each column as wide as the widest w:tcW among the cells that occupy it alone, a
spanning cell's width shared among the columns no cell sizes, what it still lacks going to its
last column, an inch for a column nothing sizes, never narrower than 26 twips. The rules were
measured on the grids Word saves for synthetic tables. A row after w:gridBefore starts at its
own column.
Moved from storytold/wordcraft#1630, whose reader half had no file left there after #6603.
* craft-docx: keep a table style's w:tblInd on read and save
A table style's own indent was dropped on read, so it was gone on save.
pandoc's Table style sets it to 0, and Word for Mac places a table whose
style chain sets no indent about 5.4 pt further right than one set to 0.
craft-wordmodel gains TableStyleParts::indent, merged through basedOn.
The reader takes a dxa indent (nil is 0; pct and auto set none) and the
writer emits it in schema order, 0 included.
Part of storytold/wordcraft#5767.
* craft-docx: a table style's w:tblInd without w:w is 0
CT_TblWidth's w:w defaults to 0, so the style resets a based-on style's
indent instead of inheriting it. The test helper now fails when a saved
style is missing rather than matching an empty string.
* craft-docx: the tblInd override test checks the base sets an indent
Without it the test would pass if the reader dropped the base style's
indent, since there would be nothing to override.
* craft-docx: theme font slots survive a save
w:rFonts' w:eastAsiaTheme and w:cstheme slots are kept on read and written
back. Word picks the East Asian and complex-script fonts through them, so
dropping them changed which font Word used for East Asian punctuation and
its line breaks. The Latin slots (w:asciiTheme, w:hAnsiTheme) are kept when
the run's font came from them and written back only while they still name
that font in the document's theme, so a font chosen later is not hidden.
craft-wordmodel: a one-byte ThemeFont and CharProps font_ascii_theme,
font_hansi_theme, font_ea_theme and font_cs_theme. Overlaying a named font
without its slot clears the slot; minus keeps a slot whose font stays.
Ported from storytold/wordcraft#5772.
* craft-docx: keep the theme's East Asian and script fonts; exact slot replacement
The saved theme wrote empty a:ea and a:cs faces and no per-script fonts, so
a kept w:eastAsiaTheme or w:cstheme slot named no font in Word. The reader
now keeps the theme's ea, cs and a:font script entries (THEME_FONTS) and
the writer puts them back.
craft-wordmodel: a named font replaces both Latin slots with its own, so a
patch with one slot no longer leaves the other stale. minus keeps a font
equal to the base's when its slots differ, so a font that clears the
base's slots still clears them when overlaid. latin_slot compares the
theme face without cloning it.
* craft-docx: theme fonts keep faces and scripts apart; limit only usable scripts
THEME_FONTS lines now say whether they hold a default face (a:ea, a:cs) or a
per-script font, so an a:font script="cs" is no longer written back as the
a:cs face. The 256-entry limit applies to usable per-script fonts only, so
empty default faces no longer push the last one out.
A test pins down Latin slots that name different faces: the model has one
Latin font, so only the slot that still names it is written.
* craft-docx: a long theme script id never pushes out one font resolution uses
The kept per-script fonts count script ids of 8 characters or fewer (the
ones font resolution takes) and longer ones (language tags such as
zh-Hant-TW) apart, 256 each, so a long one can't use up the place of a
mapping resolution keeps.
* craft-docx: THEME_FONTS names both per-script caps
* craft-docx: a DOCX border without w:sz is an eighth of a point
* craft-docx: a table border without w:sz is width 0, and ODT and RTF keep it
A table, cell or table-style border without w:sz gives the same output in
Word as w:sz="0" and takes no room; read as half a point, rows below a
pandoc table's header rule moved down half a point. PropCtx::table_borders
now reads it as 0, as PropCtx::borders does since #1488.
ODT and RTF have no border that is drawn and takes no room, so a drawn
width-0 cell side is written at Border::THINNEST instead of being dropped.
Where two ODT cells share an edge, a line with a width wins over a width-0
one, whichever cell states it.
Table half of storytold/wordcraft#5764.
---------
Co-authored-by: Nghiathan13 <201675788+Nghiathan13@users.noreply.github.com>
The VML reader took a shape's outline from its stroked and strokecolor
attributes only, so a v:stroke child with on="f" or opacity="0" was
ignored and the shape got a black 0.75 pt outline. Google Docs writes
its horizontal rules this way (a 0.05 pt v:rect with a transparent
stroke): Word shows nothing, and after a save every rule became a
visible line.
Each stroke property (on, color, opacity, endcap) now resolves as Word
does: the shape's own v:stroke, then the shape's attribute (stroked,
strokecolor), then the same two on its shapetype. A fully transparent
line is kept as a shape without an outline, and freeforms take the
resolved opacity, inherited ones included. Opacity is read in all three
forms a file can use (0, 0% and 65536ths such as 0f).
Moved from storytold/wordcraft#3829, where it was reviewed, now that
the DOCX reader lives here.
Co-authored-by: ARC <261443955+arc-uri-el@users.noreply.github.com>
From 45° up to 135° and from 225° up to 315°, Word measures the room a
turned object's rotated bounds take against its frame with width and
height exchanged, so a quarter turn records no effect extent. craft-docx
measured it against the unturned frame, so saving a picture turned 90°
wrote half the difference between its sides as negative top and bottom
extents, which Word draws as a crop, and the text after it moves up.
Reading had the same mismatch the other way: a picture Word turned 60°
gained phantom effects room above and below.
Float::effect_spin_pad gives the overhang in Word's measure, choosing the
frame from the angle as it is saved (60000ths of a degree), so an angle
such as 44.999996° is measured as the 45° it is written as. The docx
reader and both writers use it; a bare turn (Float::is_bare_turn) still
records none, and layout keeps spin_pad and line_pad.
The test reads and saves a 254 x 337 pt picture with the extents Word
for Microsoft 365 (build 16.0.20527) writes at 60° and 90° and on both
sides of each boundary (44/45, 134/135, 224/225, 314/315), and reads the
saved file back. Two existing tests asserted the old values and now use
Word's.
Moved from storytold/wordcraft#3828, where it was reviewed, now that the
DOCX reader and writer live here.
Co-authored-by: ARC <261443955+arc-uri-el@users.noreply.github.com>
* 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>