Pictures and shapes anchored in a .docx often landed in the wrong place:
the reader folded every margin-relative position into "margin", ignored
<wp:align>, and kept only distL as the distance from text. Floats in
headers, footers and table cells were not drawn at all.
Document model (doc):
- Anchor gains the left/right/top/bottom/inside/outside margin areas,
the anchor character and the anchor line
- Float gains h_align/v_align (FloatAlign: start, center, end, inside,
outside), which take precedence over the offsets, and separate
dist_top/dist_bottom (dist stays the left/right distance)
DOCX (docx): read and write wp:align, every relativeFrom value and
distT/distB/distL/distR.
Layout (layout):
- float_rect positions against each reference area, with alignment
- floats in headers, footers, table cells and text boxes are placed,
drawn (behind-text ones under the text) and wrapped around; headers
and footers get a page frame so page-relative floats land in page
coordinates, also when the header's height is measured for the body
top
- a paragraph's first line pushed below a top-and-bottom float is drawn
(and hit-tested) where it was laid out
- floats follow their paragraph to a new column or page, and are placed
at the paragraph's actual top (space before counted once, contextual
spacing respected)
- wrap areas use each distance as given; the old 9pt minimum is gone, so
a float with distance 0 now touches its text as in Word
- a list item's label is counted once (Ctx::next_label) and passed into
every layout of its paragraph (Ctx::para_labelled), so laying it out
again around floats doesn't advance the list counters twice; a
paragraph whose top moved is only laid out again when the page has
something to wrap around
Engine: switching an inline object to a wrapping style gives it Word's
default 9pt side distance; the position presets clear any alignment.
Approximations: inside/outside margins and alignments ignore mirrored
margins (treated as left/right); character- and line-relative positions
fall back to the column and the paragraph top.
Tests: docx fixture and round trip for alignment, reference areas and
distances; layout tests for alignment, the pushed-down first line,
floats moving to page two (with space before), header and cell floats,
header floats not changing the body top, hostile distances, and list
items counted once when laid out again (contextual spacing, page break
before, beside a float in a table cell).
Co-authored-by: Oliver Zieschang <4963183+naxvog@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
* #147: wire Picture Format UI for inserted pictures
* #147: fix Picture Format state bugs from review (alt/crop buffers, undo coalescing, pending target, tab fallback)
* #147: review round 2 (cancel pending change on next action, alt media check, drag-only undo join)
---------
Co-authored-by: Tony <gittonyp@gmail.com>