diff --git a/crates/pptx/src/read/timing.rs b/crates/pptx/src/read/timing.rs
index 37a7ccb53..58d7457db 100644
--- a/crates/pptx/src/read/timing.rs
+++ b/crates/pptx/src/read/timing.rs
@@ -213,7 +213,6 @@ pub fn media_settings(timing: &El, ctx: &IdCtx, shapes: &mut [Shape]) {
}
let mut deferred = deferred;
if e.is("cTn")
- && e.attr("nodeType") != Some("tmRoot")
&& let Some(st) = e.child("stCondLst")
{
let is_auto_begin = |c: &El| {
@@ -257,6 +256,12 @@ pub fn media_settings(timing: &El, ctx: &IdCtx, shapes: &mut [Shape]) {
if cm.child("cTn").and_then(|c| c.attr("repeatCount")) == Some("indefinite") {
clip.loop_play = true;
}
+ if cm.child("cTn").and_then(|c| c.attr("fill")) == Some("remove") {
+ clip.rewind = true;
+ }
+ if cm.u32("numSld").is_some_and(|n| n > 1) {
+ clip.play_across_slides = true;
+ }
if !deferred && cm.path(&["cTn", "stCondLst", "cond"]).is_some_and(|c| c.attr("evt").is_none() && c.attr("delay").map(str::trim) == Some("0"))
{
clip.autoplay = true;
@@ -265,6 +270,41 @@ pub fn media_settings(timing: &El, ctx: &IdCtx, shapes: &mut [Shape]) {
clip.full_screen = true;
}
}
+ let root_deferred = timing.path(&["tnLst", "par", "cTn", "stCondLst"]).is_some_and(|st| {
+ let is_auto_begin = |c: &El| {
+ c.attr("evt") == Some("onBegin")
+ && c.attr("delay").map(str::trim) == Some("0")
+ && c.child("tgtEl").is_none()
+ && c.child("tn").is_none()
+ && c.child("rtn").is_none()
+ };
+ let has_on_begin = st.children_named("cond").any(is_auto_begin);
+ st.children_named("cond")
+ .any(|c| (c.attr("evt").is_some() && !is_auto_begin(c)) || (!has_on_begin && c.attr("delay").map(str::trim) != Some("0")))
+ });
+ if !root_deferred && let Some(tn) = timing.child("tnLst") {
+ let mut found = vec![];
+ collect(tn, At { trigger: None, group: 0, offset: 0 }, &mut 0, &mut found, 0);
+ for f in found.into_iter().filter(|f| f.trigger.is_none()) {
+ let c = f.ctn;
+ if c.attr("nodeType") == Some("clickEffect") {
+ break;
+ }
+ let class = AnimClass::from_xml(c.attr("presetClass").unwrap_or("entr"));
+ let preset = c.u32("presetID").unwrap_or(0);
+ let effect = maps::effect_for_preset(class, preset).unwrap_or_else(|| maps::fallback_effect(class));
+ let delay = c.path(&["stCondLst", "cond"]).and_then(|d| ms_attr(d, "delay")).unwrap_or(0);
+ if class == AnimClass::Media
+ && effect == "play"
+ && f.offset == 0
+ && delay == 0
+ && let Some(id) = c.find("spTgt").and_then(|t| t.u32("spid")).and_then(|s| ctx.lookup(s))
+ && let Some(ShapeKind::Media(clip)) = find_shape_mut(shapes, id).map(|s| &mut s.kind)
+ {
+ clip.autoplay = true;
+ }
+ }
+ }
}
/// Flatten the timing tree into the Animation Pane list.
diff --git a/crates/pptx/src/write/timing.rs b/crates/pptx/src/write/timing.rs
index 766e3abad..4442109af 100644
--- a/crates/pptx/src/write/timing.rs
+++ b/crates/pptx/src/write/timing.rs
@@ -779,7 +779,13 @@ fn collect_media<'a>(shapes: &'a [Shape], idmap: &IdMap) -> Vec<(u32, &'a deckcr
let mut media = Vec::new();
deckcraft_model::walk(shapes, &mut |shape, _| {
if let ShapeKind::Media(clip) = &shape.kind
- && (clip.autoplay || (clip.volume - 1.0).abs() > 1e-6 || clip.hide_while_not_playing || clip.loop_play || clip.full_screen)
+ && (clip.autoplay
+ || (clip.volume - 1.0).abs() > 1e-6
+ || clip.hide_while_not_playing
+ || clip.loop_play
+ || clip.rewind
+ || clip.play_across_slides
+ || clip.full_screen)
&& let Some(spid) = idmap.get(shape.id)
{
media.push((spid, clip));
@@ -798,8 +804,18 @@ fn write_media_node(w: &mut W, ids: &mut Ids, spid: u32, clip: &deckcraft_model:
if clip.hide_while_not_playing {
cm = cm.a("showWhenStopped", 0);
}
+ if clip.play_across_slides {
+ cm = cm.a("numSld", 999);
+ }
w.open("p:cMediaNode", cm);
- w.open("p:cTn", A::new().a("id", ids.next()).a("fill", "hold").a("display", 0).o("repeatCount", clip.loop_play.then_some("indefinite")));
+ w.open(
+ "p:cTn",
+ A::new()
+ .a("id", ids.next())
+ .a("fill", if clip.rewind { "remove" } else { "hold" })
+ .a("display", 0)
+ .o("repeatCount", clip.loop_play.then_some("indefinite")),
+ );
w.open0("p:stCondLst");
w.empty("p:cond", A::new().a("delay", if clip.autoplay { "0" } else { "indefinite" }));
w.close("p:stCondLst");
diff --git a/crates/pptx/tests/it/media_timing.rs b/crates/pptx/tests/it/media_timing.rs
index 1d2430370..1274d8dd5 100644
--- a/crates/pptx/tests/it/media_timing.rs
+++ b/crates/pptx/tests/it/media_timing.rs
@@ -128,6 +128,8 @@ fn media_only_slide_exports_and_round_trips_video_and_audio_timing_nodes() {
volume: 0.75,
hide_while_not_playing: true,
loop_play: true,
+ rewind: true,
+ play_across_slides: true,
full_screen: true,
..Default::default()
}),
@@ -151,8 +153,32 @@ fn media_only_slide_exports_and_round_trips_video_and_audio_timing_nodes() {
})
.collect();
assert_eq!(clips.len(), 2);
- assert!(clips[0].video && clips[0].autoplay && clips[0].hide_while_not_playing && clips[0].loop_play && clips[0].full_screen);
+ assert!(
+ clips[0].video
+ && clips[0].autoplay
+ && clips[0].hide_while_not_playing
+ && clips[0].loop_play
+ && clips[0].rewind
+ && clips[0].play_across_slides
+ && clips[0].full_screen
+ );
assert!((clips[0].volume - 0.75).abs() < 1e-4);
- assert!(!clips[1].video && !clips[1].autoplay && clips[1].loop_play && !clips[1].hide_while_not_playing && !clips[1].full_screen);
+ assert!(
+ !clips[1].video
+ && !clips[1].autoplay
+ && clips[1].loop_play
+ && !clips[1].rewind
+ && !clips[1].play_across_slides
+ && !clips[1].hide_while_not_playing
+ && !clips[1].full_screen
+ );
assert_eq!(clips[1].volume, 0.0);
+
+ // Main-sequence automatic Play (mediacall) effect with indefinite media node also sets autoplay.
+ let main_seq_play = self::clips(|v, _| {
+ format!(
+ r#""#
+ )
+ });
+ assert!(main_seq_play[0].autoplay, "main-sequence automatic Play effect sets autoplay");
}
diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md
index 70b74f7e1..67707cded 100644
--- a/docs/file-format-parity.md
+++ b/docs/file-format-parity.md
@@ -92,7 +92,7 @@ the round trip even though DeckCraft doesn't model it.
| Charts (`cx:` chartex: waterfall, funnel, treemap, sunburst, histogram, Pareto, box) | yes | yes | Unchanged parts kept, with their embedded workbook (#335); edited and new ones written from the model with a plain-chart fallback. Treemap and sunburst hierarchy levels kept; region maps kept, drawn as tiles (no map geometry) |
| SmartArt (`dgm`) | the drawing part as a group (text laid out on its `dsp:txXfrm` rectangle), and the outline from the data model (Text Pane) | as a diagram: data model from the outline; layout, quick style and colour parts (the file's own kept until the layout is switched); the group as the cached drawing | DeckCraft's layout definitions are simple; a diagram without a cached drawing isn't drawn. SmartArt kept only as XML, without its relationship parts, still loses the drawing and data parts (#203) |
| Equations (OMML, `a14:m`) | no | no | PR #55 open |
-| Audio / video (`p14:media`, trim, fades, bookmarks) | yes | partly | Playback options lost on save (#74) |
+| Audio / video (`p14:media`, trim, fades, bookmarks, playback options) | yes | yes | Volume, mute, autoplay, loop, rewind, play across slides, hide while not playing and full screen round-trip (`media_timing.rs`) |
| Ink (`contentPart`) | yes | as a group of freeform lines | PowerPoint sees shapes, not ink |
| Transitions incl. p14/p15 (Vortex, Morph…) | all 48 | all 48 | `every_transition_kind_round_trips` |
| Animations: timing tree, build paragraphs, triggers, motion paths | yes (flattened to the Animation Pane list) | yes (rebuilt) | `every_animation_effect_survives`; repeat, triggers, bounce end and rewind kept |