craft-ppt-binary: say unknown master placeholders are left out; match each outline to its own polygon

The module doc said a placeholder of an unknown type keeps its text as a
text box, which is true on slides only: the master leaves it out.

check_outlines let two shapes match the same rendered polygon, so two
shapes moved onto one place still passed. Each shape now takes a polygon
of its own.
This commit is contained in:
kiwi4boy committed 2026-11-20 17:07:40 -05:00
1 parent b24ed4e42a
commit 92e4cab2d3
2 files changed
+10 -5

No files matched your search

+4 -3
View File
@@ -37,9 +37,10 @@
//! cap.
//!
//! PowerPoint 95 numbers placeholders its own way: on the master 1 title, 2 body, 6 date, 7 slide
//! number and 8 footer; on slides 0x0C title, 0x0D body, 0x0F centred title and 0x10 subtitle. A
//! placeholder of any other type keeps its text as a text box. The master's placeholders place the
//! caller's default master's, and the footer row places every layout's, as the PowerPoint 97 path
//! number and 8 footer; on slides 0x0C title, 0x0D body, 0x0F centred title and 0x10 subtitle. On a
//! slide, a placeholder of any other type keeps its text as a text box; on the master it is left
//! out. The master's placeholders place the caller's default master's, and the footer row places
//! every layout's, as the PowerPoint 97 path
//! does.
//!
//! A picture is a shape naming one of the document's pictures, which are Windows metafiles; its
+6 -2
View File
@@ -2808,11 +2808,13 @@ fn the_wmf_reader_stays_in_each_record() {
}
/// For a sample with a rendering beside it (`<case>.wmf`), each shape on its first slide with a
/// straight outline matches a polygon PowerPoint 95 drew. The number of shapes checked.
/// straight outline matches a polygon PowerPoint 95 drew, each a polygon of its own: two shapes
/// moved onto one place don't both match it. The number of shapes checked.
fn check_outlines(name: &str, p: &Presentation, wmf: &[u8]) -> usize {
let polygons = wmf_polygons(wmf, p.slide_size);
let Some(slide) = p.slides.first() else { return 0 };
let mut checked = 0;
let mut used = vec![false; polygons.len()];
for s in &slide.shapes {
let Some(corners) = outline_corners(s) else { continue };
// A dashed line is drawn dash by dash.
@@ -2821,7 +2823,9 @@ fn check_outlines(name: &str, p: &Presentation, wmf: &[u8]) -> usize {
}
let width = s.line.as_ref().and_then(|l| l.width).unwrap_or(1.0);
let near = polygons.iter().min_by_key(|poly| poly.len().abs_diff(corners.len()));
assert!(polygons.iter().any(|poly| outline_matches(&corners, poly, width)), "{name}: {corners:?} is not drawn; nearest {near:?}");
let hit = (0..polygons.len()).find(|&i| !used[i] && outline_matches(&corners, &polygons[i], width));
let Some(i) = hit else { panic!("{name}: {corners:?} is not drawn, or only where another shape is; nearest {near:?}") };
used[i] = true;
checked += 1;
}
checked