Gap 19: ODT frames take their anchor and place from their style

A frame that doesn't state its anchor or position now takes them from
its graphic style chain (ODF lets `style:graphic-properties` carry
`text:anchor-type`, `svg:x` and `svg:y`).

LibreOffice's business card template relies on this:
- its Labels style holds the card in line;
- its Graphics style puts the credit at the top of the page.

WordCraft had floated the card, so a save scrambled the layout and added
a page.

Across the 125-document corpus, no document now changes page count
through a save (3 did), and the round-trip pixel difference falls from
333k to 241k. gaps.md row 19 and the ROADMAP log are updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GBVQLyDnrG8Tn1yDQcUabC
This commit is contained in:
Claude
2026-11-02 12:51:36 +00:00
parent 3164c33c28
commit 2f08e8bb01
5 changed files with 33 additions and 4 deletions
+3 -1
View File
File diff suppressed because one or more lines are too long
+14 -1
View File
@@ -60,6 +60,11 @@ pub(super) struct Graphic {
/// Which way a text box's text runs (§20.404 `style:writing-mode`; LibreOffice's upward
/// `bt-lr` is its own `loext:writing-mode`).
vert: Option<wordcraft_doc::props::TextVert>,
/// The anchor and position a style gives frames that state none (§20.299 `text:anchor-type`,
/// `svg:x`, `svg:y` in `style:graphic-properties`: LibreOffice's label and Graphics styles).
anchor: Option<String>,
x: Option<String>,
y: Option<String>,
}
/// A `fo:clip` value, `rect(top, right, bottom, left)` (commas or spaces between; `auto` is 0):
@@ -160,6 +165,9 @@ impl Graphic {
}
}),
contour_mode: s("style:wrap-contour-mode"),
anchor: s("text:anchor-type"),
x: s("svg:x"),
y: s("svg:y"),
}
}
@@ -193,6 +201,9 @@ impl Graphic {
self.wrap_contour = self.wrap_contour.or(parent.wrap_contour);
self.vert = self.vert.or(parent.vert);
fill(&mut self.contour_mode, &parent.contour_mode);
fill(&mut self.anchor, &parent.anchor);
fill(&mut self.x, &parent.x);
fill(&mut self.y, &parent.y);
self.grow = self.grow.or(parent.grow);
fill(&mut self.dash, &parent.dash);
fill(&mut self.gradient, &parent.gradient);
@@ -277,7 +288,9 @@ impl Graphic {
/// `svg:y`) with graphic style placement `g`. A frame in line with the text (`as-char`, or no
/// anchor stated) doesn't float.
pub(super) fn float_of(anchor: Option<&str>, x: Option<&str>, y: Option<&str>, g: &Graphic) -> Float {
let anchor = anchor.map(str::trim);
// What the frame leaves unsaid, its style says.
let anchor = anchor.or(g.anchor.as_deref()).map(str::trim);
let (x, y) = (x.or(g.x.as_deref()), y.or(g.y.as_deref()));
if matches!(anchor, None | Some("as-char")) {
return Float::default();
}
@@ -75,6 +75,18 @@ fn a_page_anchored_frames_paragraph_relations_are_the_pages() {
assert_eq!((f.h_rel, f.v_rel), (Anchor::Column, Anchor::Line));
}
#[test]
fn a_frames_style_gives_the_anchor_and_place_it_leaves_unsaid() {
// LibreOffice's business card: the Labels style holds the card in line, Graphics puts the
// credit at the top of the page; neither frame says so itself.
let f = float(&open(r#"text:anchor-type="page" svg:x="1in" svg:y="0.5in" style:wrap="run-through""#, ""));
assert_eq!((f.h_rel, f.v_rel, f.x, f.y), (Anchor::Page, Anchor::Page, 72.0, 36.0));
assert_eq!(float(&open(r#"text:anchor-type="as-char""#, "")).wrap, Wrap::Inline);
// The frame's own anchor and place win.
let f = float(&open(r#"text:anchor-type="page" svg:x="1in""#, r#"text:anchor-type="paragraph" svg:x="2in""#));
assert_eq!((f.h_rel, f.x), (Anchor::Paragraph, 144.0));
}
#[test]
fn floating_pictures_round_trip() {
for (graphic, frame) in [
File diff suppressed because one or more lines are too long
+2 -1
View File
File diff suppressed because one or more lines are too long