Commit Graph
58 Commits
Author SHA1 Message Date
FredApps eafb26acde Merge pull request #3063 from yoriswind/codex/3056-vml-object-hyperlinks
Preserve VML hyperlinks through grouped drawings
2026-11-27 23:07:33 +01:00
ruchirguitarandClaude Opus 5.5 5b571e5254 Write history on for app-made links and cut settings merge back to w: compat cases
Review of storytold/craft-libs#3361 (bflatastic):

1. Links that didn't come from a .docx file lost w:history="1". Replace
   CharProps::link_history: Option<bool> with Option<LinkHistory>
   (Off, Omitted), set only by the .docx reader. None, which every
   other link has and which the reader also gives a link with history
   on, is written as w:history="1", as main does, so such a link reads
   back unchanged. Text with no value takes the history of the link it
   is in, so typing into a link doesn't split it. New test: a link made
   with a CharProps patch saves with w:history="1". main's
   picture_links test is back to expecting w:history="1".

2. settings_merge.rs is main's file plus a short merge_compat for the
   w:-prefixed cases real files have: the owned switches come from the
   generated part at their CT_Compat position, compatibilityMode is
   replaced, added or removed, and a block left empty goes. The rest
   (aliased and rebound prefixes, Strict and r:* relationship markup,
   escaped names, BOMs and comments, vendor markup on switches) is
   kept with its 22 tests on the fork branch
   docx-settings-merge-hardening (079da658b) for a later PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 20:00:47 +05:30
ruchirguitarandClaude Opus 5.5 079da658b3 Keep vendor markup on deduplicated switches and drop bare compat blocks and all relationship attributes
- An enabled compat switch that appears more than once now keeps the
  occurrences carrying markup the model doesn't write (e.g. x:vendor)
  and drops only plain duplicates; with none, the first stays.
- A bare self-closing <w:compat/> follows the empty-block rule, like
  <w:compat></w:compat>; one with unmodeled attributes is still kept.
- Compat retention and pruning treat every attribute in the
  relationship namespace (r:embed, r:link, ...) as a reference, not
  only r:id; vendor attributes of the same local name stay.

Each change has a regression test that fails without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 17:32:06 +05:30
Codex 830521eb00 Match DOCX settings reader semantics and retain disabled switch extensions 2026-11-27 06:16:59 +05:30
Codex 0e05fddc5b Merge upstream main and retain both DOCX settings regression suites 2026-11-27 06:12:09 +05:30
yoriswind 593288bd99 Integrate nested drawing hyperlinks with current document models 2026-11-26 12:18:38 -08:00
FredApps 4315241e5c Merge branch 'main' into docx-revision-date-utc 2026-11-26 10:22:53 +01:00
ruchirguitar 18d3d383c3 style(docx): format settings_merge.rs 2026-11-25 00:31:02 +05:30
ruchirguitar c0024b06a9 fix(docx): preserve compat block namespaces and handle whitespace in on-off (#3308, #3305) 2026-11-25 00:29:48 +05:30
ruchirguitar 7f16b42210 fix(docx): address CodeRabbit review feedback on settings merge and ruby links
- Copy link_history in read_ruby alongside link, preserving None when omitted.
- Include w:compat opening tag in settings merge NsReader reconstruction to preserve namespaces declared on w:compat.
- Normalize attribute values using normalized_value() before comparing name and uri.
- Update GEN test fixture w:uri to standard Microsoft Word URI.
- Add regression tests covering w:compat-level namespace declarations and escaped attribute entities.
2026-11-24 21:25:20 +05:30
ruchirguitar a12bea6ada fix(docx): preserve absent compatibilityMode and hyperlink history (#3308, #3305)
- Fix #3308: Represent absent compatibilityMode as Option<u32> (None = omitted). Do not synthesize <w:compatSetting w:name="compatibilityMode"> or empty <w:compat> when omitted from input. In merged settings, support removing compatibilityMode across paired tags, alternate quotes, whitespace, and foreign vendor elements.
- Fix #3305: Retain authored presence and boolean value of w:history on <w:hyperlink> (Option<bool>) from read to write, defaulting newly authored links to 1.
- Add comprehensive unit and integration tests across craft-docx, craft-wordmodel, and craft-doc-binary.
2026-11-24 21:08:17 +05:30
RickiNano be8e501ffc craft-docx: read and write w16du:dateUtc on tracked changes (#3206)
Word writes a tracked change's w:date in local wall-clock time, so two
changes an hour apart in the hour the clocks go back over get one w:date,
and the reader, which groups revisions by kind, author and date, read
them back as one change. Revision now keeps the change's UTC time
(MS-DOCX 2.12.2.1 dateUtc): the reader reads it and groups by it too, and
the writer writes it beside w:date (dropped with Remove date and time).
The w16du namespace is declared on body parts and listed in mc:Ignorable.
2026-11-23 20:00:17 +01:00
yoriswind 23b2328fe5 fix(docx): import hyperlink relationship constants 2026-11-22 07:12:11 -08:00
yoriswind 6a46b44449 fix(docx): preserve object and nested group hyperlinks 2026-11-22 07:04:49 -08:00
dotCooCoo c27195aa8e Merge main into fix/docx-hide-proofing-errors 2026-11-21 14:10:33 -08:00
FredApps d042b09745 Merge pull request #2510 from OPUZZLES/opuzzles/docx-picture-soft-edge-roundtrip
DOCX: preserve imported picture soft edges
2026-11-20 13:09:33 +07:00
FredApps 9867c5ac13 Merge pull request #2347 from OPUZZLES/opuzzles/docx-screentips
craft-docx: preserve bounded hyperlink ScreenTips
2026-11-20 12:54:14 +07:00
FredApps e956256f1d Merge pull request #2349 from OPUZZLES/opuzzles/docx-mail-merge
Preserve external DOCX mail-merge source relationships
2026-11-20 12:51:44 +07:00
Rees 8eae257cf3 DOCX #2532: preserve imported picture soft edges 2026-11-20 05:59:01 +01:00
Mex 14718ae0c1 DOCX: save the current zoom when merging settings 2026-11-19 22:31:00 +01:00
Rees aa89df6814 Preserve external DOCX mail-merge source relationships 2026-11-19 09:21:13 +01:00
Rees a2df846270 craft-docx: preserve bounded hyperlink ScreenTips 2026-11-19 09:09:49 +01:00
Kevin Joseph 041bafa259 craft-docx: keep a table style's w:tblInd on read and save (#2196)
* 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.
2026-11-18 15:35:42 -05:00
Kevin Joseph 0c3793eadd craft-docx: theme font slots survive a save (#2197)
* 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
2026-11-18 15:35:36 -05:00
ARCandARC da69193a2f fix(docx): write and read a turned object's effect extent as Word does (#2227)
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>
2026-11-18 15:35:16 -05:00
dotCooCoo c8087dd0dd Merge main into fix/docx-hide-proofing-errors 2026-11-17 13:26:47 -08:00
dotCooCoo e0b78f7404 Merge main into fix/docx-hide-proofing-errors 2026-11-16 21:09:02 -08:00
FredApps cc22854ea4 Preserve ODF lookahead and stacking normalization together 2026-11-17 04:59:07 +01:00
FredApps 0dbd888f3c Integrate page background preservation with stacking normalization 2026-11-17 04:12:46 +01:00
dotCooCoo 48219efdaf Merge main into fix/docx-hide-proofing-errors 2026-11-16 18:34:28 -08:00
Hamza Naveed 76fc04feee craft-docx: relate the bibliography store from the main part, not the package (#1835) 2026-11-16 21:30:40 -05:00
keithcsqueensu 738bf6fafe docx: write a font table naming the fonts a document uses (#1948) 2026-11-16 21:29:43 -05:00
FredApps 1612dd35b9 Integrate current drawing readers and preserve retained OLE stacking 2026-11-17 03:11:41 +01:00
Dylan M. Taylor 4992583846 Merge pull request #1898 from StDenis1980/tinta/upstream-application-name
docx: set_application_name for apps that embed the writer
2026-11-16 19:16:04 -05:00
Dylan M. Taylor 09cae32c45 Merge pull request #1776 from vangel76/fix/gutter-at-top
The "gutter at top" page setting in Word files is now read and saved
2026-11-16 16:11:33 -05:00
FredApps d60d1b0a45 Merge pull request #1868 from tsw2k/fix/docx-frame-shape
craft-docx: a frame preset shape is a border with a hole
2026-11-16 16:24:26 +01:00
FredApps dd3015c678 wordmodel: keep the kashida length of a justified paragraph (#1875)
* 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.
2026-11-16 10:23:22 -05:00
FredApps c5f217e765 craft-docx: a shape's VML fallback takes its anchor's relativeHeight
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).
2026-11-16 16:10:03 +01:00
FredApps bb965ed3c9 Merge remote-tracking branch 'origin/main' into t1729 2026-11-16 16:09:39 +01:00
StDenis1980andClaude Opus 5.5 0b0e5accd5 docx: set_application_name for apps that embed the writer
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>
2026-11-16 14:37:37 +01:00
Dylan M. TaylorandAndy Ching 046a7229af fix(docx): integrate VML fallbacks without breaking linked text-box stories (#1864)
* 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>
2026-11-16 08:16:40 -05:00
tsw2k 8b876291a1 craft-docx: a frame preset shape is a border with a hole
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.
2026-11-16 11:46:35 +00:00
Andy Ching 5033f10bf2 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`.
2026-11-16 15:51:31 +08:00
Andy Ching 489f3cbc12 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.
2026-11-16 15:32:11 +08:00
Andy Ching 741192a57c 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
2026-11-16 15:15:06 +08:00
Dylan M. Taylor d9e56e3f7c Merge pull request #1290 from vangel76/feat/docx-chart-axis-series
DOCX charts keep axis and series formatting
2026-11-15 18:30:37 -05:00
vangel76andClaude Sonnet 5.5 1ea162df26 DOCX: make the gutter-at-top tests check the order and False/FALSE
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>
2026-11-16 00:17:26 +01:00
vangel76andClaude Sonnet 5.5 fc808abd49 DOCX: read and write the "gutter at top" setting (w:gutterAtTop)
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>
2026-11-16 00:12:22 +01:00
Diego Guerini 5f453efa9a craft-docx: a relativeHeight of 0 stays the lowest stacking order
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.
2026-11-15 20:10:47 +01:00
dotCooCoo 23ebdc7089 Merge main into fix/docx-hide-proofing-errors 2026-11-14 13:33:19 -08:00