Merge branch 'ppt95' into ppt95-text

# Conflicts:
#	crates/ppt-binary/README.md
#	crates/ppt-binary/src/ppt95.rs
#	crates/ppt-binary/src/ppt95/tests.rs
This commit is contained in:
kiwi4boy
2026-11-20 00:37:32 -05:00
3 changed files with 62 additions and 10 deletions
+3 -1
View File
@@ -41,7 +41,9 @@ one feature per file, and the public [MS-PPT] numbering where the records keep i
So far a PowerPoint 95 file imports with its slide size, its masters (each the caller's default
master wearing the file's colour scheme, and its background when that isn't the scheme's), and
its slides in order with their master, layout type and, when a slide doesn't follow the master's,
its own background: a solid colour, or none when the slide's background has no fill. Slides hold
its own background: a solid colour, or none when the slide's background has no fill. A slide also
says whether it shows the master's objects and whether it uses the master's colour scheme or its
own. Slides hold
their placeholders (title, body, centred title, subtitle, and the date, footer and slide number)
and text boxes, each with its box and its text: the text's anchoring (top, middle or bottom, and
whether it's centred across) and word wrap, paragraphs with their level, alignment (justified
+12 -3
View File
@@ -164,18 +164,25 @@ struct Page<'a> {
master_id: u32,
/// The [MS-PPT] `SlideLayoutType` number.
layout: Option<u32>,
/// The slide box's flags (1005 +16, +17, +20): whether the slide shows the master's objects,
/// uses the master's colour scheme and uses the master's background. A missing box follows.
follow_objects: bool,
follow_scheme: bool,
follow_background: bool,
scheme: Option<Scheme>,
}
fn page(rec: Rec<'_>) -> Page<'_> {
let atom = rec.child(rt::SLIDE_ATOM);
let flag = |at: usize| rec.child(rt::SLIDE_BOX).and_then(|b| b.u8(at)).is_none_or(|f| f != 0);
Page {
rec,
id: atom.and_then(|a| a.u32(0)).unwrap_or(0),
master_id: atom.and_then(|a| a.u32(4)).unwrap_or(0),
layout: rec.child(rt::LAYOUT).and_then(|l| l.u32(0)),
follow_background: rec.child(rt::SLIDE_BOX).and_then(|b| b.u8(20)).is_none_or(|f| f != 0),
follow_objects: flag(16),
follow_scheme: flag(17),
follow_background: flag(20),
scheme: rec.child(rt::SCHEME).and_then(|s| s.child(rt::COLOR_SCHEME)).map(|s| scheme_of(&s)),
}
}
@@ -374,14 +381,16 @@ pub fn convert(document: &Rec, app: &dyn Defaults) -> Presentation {
let Some((kinds, first)) = layouts.get(index) else { continue };
let kind: Option<LayoutType> = s.layout.map(layout_kind);
let Some(layout) = kind.and_then(|k| kinds.iter().find(|(lk, _)| *lk == k).map(|(_, id)| *id)).or(*first) else { continue };
let scheme = s.scheme.unwrap_or(master_scheme);
// A slide following the master's scheme holds a copy of it; its own is used only when it
// doesn't follow.
let scheme = if s.follow_scheme { master_scheme } else { s.scheme.unwrap_or(master_scheme) };
let background = if s.follow_background { None } else { background(&s.rec, &scheme).map(|fill| Background::Fill { fill }) };
let Some(id) = p.alloc_id() else { break };
let mut shapes = vec![];
for o in objects(&s.rec).filter_map(|r| object(&r, &env, &scheme, size)) {
shapes.extend(shape(&mut p, o));
}
p.slides.push(Arc::new(Slide { id: SlideId(id), layout, background, shapes, show_master_shapes: true, ..Default::default() }));
p.slides.push(Arc::new(Slide { id: SlideId(id), layout, background, shapes, show_master_shapes: s.follow_objects, ..Default::default() }));
}
p
}
+47 -6
View File
@@ -49,10 +49,11 @@ fn background_shape(fill: [u8; 4], filled: bool) -> Vec<u8> {
container(rt::SHAPE, 0x1C, &[geometry, rec(rt::FORMAT, 1, 0, &format)])
}
/// The slide box: the slide rectangle, then whether it follows the master background.
fn slide_box(follow_background: bool) -> Vec<u8> {
/// The slide box: the slide rectangle, then whether it follows the master's objects, scheme and
/// background.
fn slide_box(objects: bool, scheme: bool, background: bool) -> Vec<u8> {
let mut b = le32(&[(-2880i32) as u32, (-2160i32) as u32, 2880, 2160]);
b.extend_from_slice(&[1, 1, 0, 0, u8::from(follow_background), 0, 0, 0]);
b.extend_from_slice(&[u8::from(objects), u8::from(scheme), 0, 0, u8::from(background), 0, 0, 0]);
rec(rt::SLIDE_BOX, 1, 0, &b)
}
@@ -60,6 +61,8 @@ struct SlideSpec {
id: u32,
master: u32,
layout: u32,
follow_objects: bool,
follow_scheme: bool,
follow_background: bool,
fill: [u8; 4],
filled: bool,
@@ -70,7 +73,18 @@ struct SlideSpec {
impl SlideSpec {
fn new(id: u32, layout: u32) -> SlideSpec {
SlideSpec { id, master: MASTER, layout, follow_background: true, fill: [0, 0, 0, 0], filled: true, scheme: DEFAULT, objects: vec![] }
SlideSpec {
id,
master: MASTER,
layout,
follow_objects: true,
follow_scheme: true,
follow_background: true,
fill: [0, 0, 0, 0],
filled: true,
scheme: DEFAULT,
objects: vec![],
}
}
}
@@ -80,7 +94,7 @@ fn slide(s: &SlideSpec) -> Vec<u8> {
0x10,
&[
rec(rt::SLIDE_ATOM, 0, 0, &le32(&[s.id, s.master])),
slide_box(s.follow_background),
slide_box(s.follow_objects, s.follow_scheme, s.follow_background),
rec(rt::LAYOUT, 1, 0, &le32(&[s.layout, 0, 0])),
container(rt::SCHEME, 0x78, &[scheme_atom(0, s.scheme)]),
background_shape(s.fill, s.filled),
@@ -99,7 +113,7 @@ fn master_with(id: u32, scheme: [u32; 8], fill: [u8; 4], objects: &[Vec<u8>]) ->
0x10,
&[
rec(rt::SLIDE_ATOM, 0, 0, &le32(&[id, 0])),
slide_box(true),
slide_box(true, true, true),
// A scheme preset, which isn't the master's scheme.
scheme_atom(0x37, [0x0000FF, 0xFFFFFF, 0, 0xFFFF00, 0xFF9900, 0x00FFFF, 0xFF0033, 0x969696]),
rec(rt::LAYOUT, 1, 0, &[1, 0, 0, 0, 1, 2, 6, 8, 7, 0, 0, 0]),
@@ -317,7 +331,9 @@ fn placeholder_95(kind: u8, size: u8, index: u32, bx: [i32; 4], text: Option<Vec
/// `master_objects`.
fn deck_of(objects: Vec<Vec<u8>>, master_objects: &[Vec<u8>]) -> Presentation {
let mut s = SlideSpec::new(0x100, 16);
// A slide with its own scheme, as PowerPoint 95 marks one: not following the master's.
s.scheme[3] = 0x112233;
s.follow_scheme = false;
s.objects = objects;
import(&stream_of(document_atom(5760, 4320, 1), &[slide(&s)], &[master_with(MASTER, DEFAULT, [0; 4], master_objects)])).unwrap()
}
@@ -483,6 +499,7 @@ fn a_slide_that_doesnt_follow_the_master_keeps_its_background() {
// A scheme slot (4, fills) of the slide's own scheme.
let mut slot = SlideSpec::new(0x101, 16);
slot.follow_background = false;
slot.follow_scheme = false;
slot.fill = [0, 0, 0, 4];
slot.scheme[4] = 0x123456;
// Following the master, its own background shape is not used.
@@ -498,6 +515,26 @@ fn a_slide_that_doesnt_follow_the_master_keeps_its_background() {
assert_eq!(p.slides[3].background, Some(Background::Fill { fill: Fill::None }));
}
/// The slide box's flags at +16 and +17 (seen in PowerPoint 95's files: turning the master's
/// objects off on a slide clears +16; giving one slide its own colour scheme clears +17): a slide
/// that follows the master's scheme takes the master's colours, not the copy it holds.
#[test]
fn slides_follow_the_masters_objects_and_scheme() {
let mut own = SlideSpec::new(0x100, 16);
(own.follow_objects, own.follow_scheme, own.follow_background) = (false, false, false);
own.fill = [0, 0, 0, 0];
own.scheme[0] = 0x112233;
let mut follows = SlideSpec::new(0x101, 16);
follows.follow_background = false;
follows.fill = [0, 0, 0, 0];
follows.scheme[0] = 0x445566;
let p = deck(&[own, follows]);
assert!(!p.slides[0].show_master_shapes);
assert!(p.slides[1].show_master_shapes);
assert_eq!(p.slides[0].background, solid(0x11, 0x22, 0x33), "its own scheme");
assert_eq!(p.slides[1].background, solid(0xFF, 0xFF, 0xFF), "the master's scheme, not its copy");
}
/// Damaged input never panics or grows without bound: every word set to hostile values,
/// truncations, deep nesting and huge counts.
#[test]
@@ -928,6 +965,10 @@ fn check_sample(name: &str, p: &Presentation) {
}
"layout3" => assert_eq!(layout_kind(p, 1), LayoutType::TwoContent),
"background" => assert_eq!(p.slides[0].background, solid(0xFF, 0, 0)),
// FollowMasterObjects turned off on the slide.
"nomasterobj" => assert!(!p.slides[0].show_master_shapes),
// The Slide Color Scheme dialog's Apply (this slide only): the slide keeps its own scheme.
"schemeapply" => assert!(p.slides[0].show_master_shapes),
"bullets" | "indent3" => {
assert_eq!(body_of(&shapes(1)[0]).text(), "Head");
assert_eq!(paras(1, 1).iter().map(|p| p.level).collect::<Vec<_>>(), [0, 1, 0], "{name}");