Commit Graph
56 Commits
Author SHA1 Message Date
keithcsqueensu 738bf6fafe docx: write a font table naming the fonts a document uses (#1948) 2026-11-16 21:29:43 -05: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 68cc642520 Merge pull request #1791 from vangel76/feat/6820-chartex-placeholder
Office 2016 charts with a text-only fallback keep their size instead of collapsing the pages
2026-11-16 16:12:25 -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
Dylan M. Taylor 443a2b05ff docx: preserve partial table margins in current and tracked properties (#1924) 2026-11-16 15:51:23 -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 8ee8316213 Merge pull request #1652 from D13GOOOO/docx-locked-canvas
craft-docx: read a DrawingML locked canvas as a group of its members (wordcraft#5060)
2026-11-16 16:12:08 +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
Diego Guerini ce8ab5cc6d craft-docx: a locked canvas's paragraph falls back on its level's alignment and the list style's defaults; bold or italic set off stays off 2026-11-16 08:52:44 +01: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
vangel76andClaude Sonnet 5.5 5e3632533f DOCX: read the placeholder chart title from its text, leave the frame unfilled
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>
2026-11-16 02:18:25 +01:00
vangel76andClaude Sonnet 5.5 e76bf4bad4 DOCX: an Office 2016 chart with a text-only fallback keeps its size as a placeholder
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>
2026-11-16 02:04:08 +01: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 6fde933469 craft-docx: read a DrawingML locked canvas as a group of its members
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.
2026-11-15 18:01:57 +01:00
vangel76andClaude Sonnet 5.5 b4463c6203 docx charts: outline unfilled bars, honour no-fill areas, keep source-linked label formats
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 13:30:44 +01:00
vangel76andClaude Sonnet 5.5 8761999c9b docx charts: automatic marker colour, data label positions, horizontal axis titles
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>
2026-11-15 01:19:18 +01:00
vangel76andClaude Sonnet 5.5 396402940c docx charts: marker symbols and sizes, data label formats, upward axis titles
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>
2026-11-15 01:06:12 +01:00
batistalucasv 80ed9665e7 craft-docx: preserve w:numberingChange without active list and raise w:original bound 2026-11-14 15:25:54 -03:00
vangel76andClaude Sonnet 5.5 0edccaf1bc docx: category gridlines follow line and area points when the axis crosses mid
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 18:59:56 +01:00
vangel76andClaude Sonnet 5.5 40d27e4ede docx: bar category labels start after the axis title strip
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 18:59:56 +01:00
vangel76andClaude Sonnet 5.5 e1cd8b5e01 docx: no_fill wins over a stored series colour
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 18:58:38 +01:00
vangel76andClaude Sonnet 5.5 4d8273712e docx: count chart axis format characters like the model
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>
2026-11-14 18:58:38 +01:00
Dylan M. Taylor 7ad4765ee5 Merge pull request #1325 from storytold/codex/docx-level-presence
docx: retain explicitly defined numbering levels
2026-11-14 11:48:48 -05:00
Dylan M. Taylor 874c94f2b1 Merge pull request #1311 from pakiat/fix/field-results-complex-script
craft-docx: a field's Thai result takes the complex-script formatting only where Word does
2026-11-14 11:43:58 -05:00
Dylan M. Taylor 5c8e1b0d82 docx: retain explicit numbering level presence 2026-11-14 15:10:43 +00:00
Naxvog 5f67d91eee craft-docx: a file with no default table style gives its tables no cell margins
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.
2026-11-14 15:27:22 +01:00
Dylan M. Taylor 8097ede0ff Resolve DOCX migration conflict with current main 2026-11-14 13:29:23 +00:00
Dylan M. Taylor 6d19bb44f3 fix(docx): preserve Normal inference compatibility 2026-11-14 13:25:25 +00:00
Dylan M. Taylor 90d20fd39f fix(docx): keep default Normal for fresh documents 2026-11-14 13:25:25 +00:00
Dylan M. Taylor 00fdde1f06 docx: retain explicit nondefault Normal on write 2026-11-14 13:25:25 +00:00
Dylan M. Taylor a94c1a386a Respect on-valued default paragraph styles 2026-11-14 13:25:25 +00:00
Dylan M. Taylor 15740f3083 fix(docx): mark declared Normal as the default 2026-11-14 13:25:13 +00:00
Dylan M. Taylor 4baa7d81ca fix(docx): ignore overrides without a list level 2026-11-14 10:57:01 +00:00
Dylan M. Taylor 7ac384839d fix(docx): ignore malformed list levels 2026-11-14 10:45:23 +00:00
pakiatandClaude Opus 5.5 24907cbd7a craft-wordmodel: mark runs as Word draws them in the model, for every reader
StyleSheet::mark_runs_as_word_draws_them moves from the DOCX reader into the model, unchanged, so the .doc reader can apply the same rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 10:41:38 +00:00
vangel76andClaude Sonnet 5.5 b6a2df0c1d docx: chart axis and series formatting
Add the series formatting (fill, line, markers, smooth, labels, number
format) and the category/value axis formatting (title, bounds, number
format, gridlines, tick labels, axis line) to the chart model, and read
and write them in the DOCX chart part. GraphicItem::Text gets an angle
for the rotated vertical axis title. With none of the new fields set the
chart part is written as before.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 11:27:03 +01:00
pakiatandClaude Opus 5.5 0e83ef6d51 craft-docx: Thai text outside a complex-script run takes the run's own font and size, as in Word
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>
2026-11-14 09:33:37 +00:00
Dylan M. Taylor 506610767b Merge pull request #1266 from storytold/codex/docx-measure-clamp
docx: clamp large measurements in f64
2026-11-14 02:21:06 -05:00
Dylan M. Taylor f5ccaba5d3 Merge pull request #1265 from storytold/codex/docx-notes-fallback
docx: read conventional footnote and endnote parts
2026-11-14 02:20:44 -05:00
Dylan M. Taylor 9ea7a82027 fix(docx,wordmodel): preserve style revisions, lnNumType countBy guard, and deterministic Paragraph Debug 2026-11-14 06:11:36 +00:00
Dylan M. Taylor d2fd4fb09e Clamp OOXML measurements before f32 conversion 2026-11-14 04:54:11 +00:00
Dylan M. Taylor 0559e4214e Read conventional footnote and endnote parts 2026-11-14 04:48:57 +00:00
Dylan M. Taylor 7f59e8f3f5 fix(docx): preserve case-insensitive main part fallback 2026-11-14 03:04:54 +00:00