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).
This commit is contained in:
FredApps committed 2026-11-16 16:10:03 +01:00
1 parent bb965ed3c9
commit c5f217e765
5 files changed
+12 -4

No files matched your search

+3
View File
@@ -120,6 +120,9 @@ pub(crate) struct Writer<'d> {
/// Stored stacking orders written as other `relativeHeight`s (see [`stacking`]); empty: each
/// as its own.
zmap: BTreeMap<u32, u32>,
/// The `relativeHeight` the last `wp:anchor` was written with, which a shape's VML fallback
/// gives as its `z-index`.
anchor_z: u32,
/// Note part id → file note id, in first-reference order.
footnotes: Vec<u32>,
endnotes: Vec<u32>,
+1
View File
@@ -33,6 +33,7 @@ pub(crate) fn write_parts(doc: &Document, flavor: Flavor) -> Result<Vec<(String,
shape_ids: std::collections::HashSet::new(),
z: 0,
zmap: BTreeMap::new(),
anchor_z: 0,
footnotes: Vec::new(),
endnotes: Vec::new(),
hf: Vec::new(),
+1
View File
@@ -273,6 +273,7 @@ impl Writer<'_> {
self.z = self.z.saturating_add(1);
self.z
};
self.anchor_z = z;
let behind = if float.wrap == Wrap::BehindText { "1" } else { "0" };
w.open(
"wp:anchor",
+3 -2
View File
@@ -398,8 +398,9 @@ impl Writer<'_> {
}
let float = &float;
self.drawing_open(w, DrawingInfo { float, size: (*sw, *sh), docpr: &docpr, name: &name, alt: o.alt_text(), link: link.as_deref() });
// This shape's stacking order: floating objects in its text box move `self.z` on.
let z = self.z;
// This shape's stacking order, as its anchor gave it: floating objects in its text box
// write anchors of their own.
let z = self.anchor_z;
w.empty("wp:cNvGraphicFramePr", &[]);
w.open("a:graphic", &[]);
w.open("a:graphicData", &[("uri", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape")]);
+4 -2
View File
@@ -107,7 +107,8 @@ fn the_fallback_keeps_order_visibility_and_direction() {
// is copied into the outer one's text, so it comes after it).
let tb = xml.find(r#"<v:textbox style="layout-flow:vertical;mso-layout-flow-alt:bottom-to-top">"#).expect("the outer box's text, turned");
let rect = &xml[xml[..tb].rfind("<v:rect ").expect("its v:rect")..tb];
assert!(rect.contains("z-index:10;"), "{rect}");
// Its anchor's `relativeHeight`: the stored order, one less (see `Float::z`).
assert!(rect.contains("z-index:9;"), "{rect}");
assert!(rect.contains("visibility:hidden"), "{rect}");
}
@@ -134,7 +135,8 @@ fn behind_text_shapes_keep_their_order() {
.collect();
got.sort_unstable();
let low = -(1i64 << 31);
assert_eq!(got, vec![low + 10, low + 20, -1], "{xml}");
// The anchors' `relativeHeight`s (one less than `z`), the top one past `i32::MAX` kept at -1.
assert_eq!(got, vec![low + 9, low + 19, -1], "{xml}");
}
/// A shape VML has no simple form for stays a bare `wps:wsp`: guarded without a fallback, an old