mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 08:15:29 +00:00
craft-odf: a group member's stored stacking order counts for the unset draw:z-index (wordcraft#2638)
unset_z_index only looked at the floating objects' orders, so a group member without a stored order could be written below a member that has one. It now also walks the groups' members.
This commit is contained in:
1 parent
f8388e2293
commit
cccb00b6b4
2 files changed
+53
-2
No files matched your search
@@ -454,9 +454,36 @@ pub(crate) fn z_index(float: Option<&Float>, unset: u32) -> u32 {
|
||||
}
|
||||
|
||||
/// The `draw:z-index` the objects of `doc` without a stored order take: past the highest stored
|
||||
/// one (a stored order is one more than its `draw:z-index`), 0 when none has one.
|
||||
/// one (a stored order is one more than its `draw:z-index`), 0 when none has one. A group's
|
||||
/// members are written with their own orders too, so theirs count as well as the floating
|
||||
/// objects' ([`craft_wordmodel::Document::stacking_orders`]).
|
||||
pub(crate) fn unset_z_index(doc: &craft_wordmodel::Document) -> u32 {
|
||||
doc.stacking_orders().0.last().copied().unwrap_or(0)
|
||||
use craft_wordmodel::para::{GroupChild, InlineObject};
|
||||
fn members(children: &[GroupChild], depth: usize, top: &mut u32) {
|
||||
for c in children {
|
||||
if let Some((_, _, f)) = c.obj.frame() {
|
||||
*top = (*top).max(f.z);
|
||||
}
|
||||
if let InlineObject::Group { children, .. } = &c.obj
|
||||
&& depth < craft_flow::MAX_GROUP_DEPTH
|
||||
{
|
||||
members(children, depth + 1, top);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut top = doc.stacking_orders().0.last().copied().unwrap_or(0);
|
||||
for blocks in std::iter::once(&doc.body).chain(doc.parts.values().map(|p| &p.blocks)) {
|
||||
for b in blocks {
|
||||
craft_wordmodel::walk::each_para(b, 0, &mut |p| {
|
||||
for o in &p.objects {
|
||||
if let InlineObject::Group { children, .. } = o {
|
||||
members(children, 0, &mut top);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
top
|
||||
}
|
||||
|
||||
/// How far a frame `h` points tall in line with the text is raised from standing on the
|
||||
|
||||
@@ -397,6 +397,30 @@ fn an_object_made_here_is_written_above_the_stored_orders() {
|
||||
assert_eq!(z, ["3", "4"], "{content}");
|
||||
}
|
||||
|
||||
/// A group's members are written with their own stacking orders, so a member without one (made
|
||||
/// in WordCraft) goes above a member's stored order too, not just above the floating objects'.
|
||||
#[test]
|
||||
fn an_object_made_here_is_written_above_the_group_members_stored_orders() {
|
||||
let content = format!(
|
||||
r#"<office:document-content {NS_T} {NS_D}><office:body><office:text><text:p><draw:g text:anchor-type="paragraph"><draw:rect svg:width="1in" svg:height="1in" svg:x="0in" svg:y="0in"/><draw:ellipse svg:width="1in" svg:height="1in" svg:x="1in" svg:y="0in"/></draw:g>Text beside.</text:p></office:text></office:body></office:document-content>"#
|
||||
);
|
||||
let mut d = import(&zip_of(&[("content.xml", content.as_bytes())])).unwrap();
|
||||
// The group stored at the bottom, its first member stored above it, its second made here.
|
||||
d.objects_mut(&|o| matches!(o, InlineObject::Group { .. }), &mut |o| {
|
||||
let InlineObject::Group { float, children, .. } = o else { return };
|
||||
float.z = 1;
|
||||
let wrap = float.wrap;
|
||||
for (c, z) in children.iter_mut().zip([4, 0]) {
|
||||
if let Some(f) = c.obj.float_mut() {
|
||||
(f.wrap, f.z) = (wrap, z);
|
||||
}
|
||||
}
|
||||
});
|
||||
let content = crate::text::tests::entry(&crate::text::tests::export_model(&d).unwrap(), "content.xml");
|
||||
let z: Vec<&str> = content.split(r#"draw:z-index=""#).skip(1).filter_map(|s| s.split('"').next()).collect();
|
||||
assert_eq!(z, ["0", "3", "4"], "the group's, the stored member's, the member made here above it: {content}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_frame_anchored_to_a_page_stays_on_that_page() {
|
||||
// LibreOffice's page-anchored frames name their page. Written without it, a frame on page 3
|
||||
|
||||
Reference in new issue
Block a user