mirror of
https://github.com/storytold/deckcraft.git
synced 2026-11-20 09:04:51 +00:00
pptx: validate enclosing mainSeq id on onBegin timing exemption
This commit is contained in:
1 parent
e4e6f4da3b
commit
fc6a3c4dbd
2 files changed
+54
-22
No files matched your search
@@ -65,11 +65,38 @@ struct Found<'a> {
|
||||
#[derive(Clone, Copy)]
|
||||
struct At {
|
||||
trigger: Option<u32>,
|
||||
main_seq_id: Option<u32>,
|
||||
group: usize,
|
||||
offset: u32,
|
||||
deferred: bool,
|
||||
}
|
||||
|
||||
/// Returns whether `st` (`p:stCondLst`) is PowerPoint's automatic main-sequence step wrapper:
|
||||
/// `<p:cond delay="indefinite"/>` paired only with `<p:cond evt="onBegin" delay="0"><p:tn val="{main_seq_id}"/></p:cond>`
|
||||
/// referencing the immediate enclosing `mainSeq` `<p:cTn>`.
|
||||
fn is_main_seq_auto(st: &El, main_seq_id: Option<u32>) -> bool {
|
||||
let Some(ms_id) = main_seq_id else {
|
||||
return false;
|
||||
};
|
||||
let is_indefinite = |d: &El| {
|
||||
d.attr("evt").is_none()
|
||||
&& d.attr("delay").map(str::trim) == Some("indefinite")
|
||||
&& d.child("tgtEl").is_none()
|
||||
&& d.child("tn").is_none()
|
||||
&& d.child("rtn").is_none()
|
||||
};
|
||||
let is_main_seq_on_begin = |d: &El| {
|
||||
d.attr("evt") == Some("onBegin")
|
||||
&& d.attr("delay").map(str::trim) == Some("0")
|
||||
&& d.child("tgtEl").is_none()
|
||||
&& d.child("rtn").is_none()
|
||||
&& d.child("tn").and_then(|tn| tn.u32("val")) == Some(ms_id)
|
||||
};
|
||||
st.children_named("cond").any(is_indefinite)
|
||||
&& st.children_named("cond").any(is_main_seq_on_begin)
|
||||
&& st.children_named("cond").all(|d| is_indefinite(d) || is_main_seq_on_begin(d))
|
||||
}
|
||||
|
||||
fn collect<'a>(e: &'a El, at: At, groups: &mut usize, out: &mut Vec<Found<'a>>, depth: usize) {
|
||||
if depth > 64 || out.len() > 10_000 {
|
||||
return;
|
||||
@@ -86,29 +113,25 @@ fn collect<'a>(e: &'a El, at: At, groups: &mut usize, out: &mut Vec<Found<'a>>,
|
||||
&& ctn.attr("nodeType") == Some("interactiveSeq")
|
||||
{
|
||||
at.trigger = ctn.path(&["stCondLst", "cond", "tgtEl", "spTgt"]).and_then(|s| s.u32("spid"));
|
||||
at.main_seq_id = None;
|
||||
}
|
||||
if c.is("cTn")
|
||||
&& let Some(st) = c.child("stCondLst")
|
||||
{
|
||||
let is_main_seq_auto = st.children_named("cond").any(|d| d.attr("delay").map(str::trim) == Some("indefinite"))
|
||||
&& st.children_named("cond").any(|d| {
|
||||
d.attr("evt") == Some("onBegin")
|
||||
&& d.attr("delay").map(str::trim) == Some("0")
|
||||
&& d.child("tgtEl").is_none()
|
||||
&& d.child("rtn").is_none()
|
||||
});
|
||||
if !is_main_seq_auto && defers_start(st) {
|
||||
at.deferred = true;
|
||||
}
|
||||
if let Some(cond) = st.child("cond") {
|
||||
if cond.attr("delay").map(str::trim) == Some("indefinite") {
|
||||
*groups += 1;
|
||||
at.group = *groups;
|
||||
at.offset = 0;
|
||||
} else {
|
||||
at.offset = at.offset.saturating_add(ms_attr(cond, "delay").unwrap_or(0));
|
||||
if c.is("cTn") {
|
||||
let is_main_seq = c.attr("nodeType") == Some("mainSeq");
|
||||
if let Some(st) = c.child("stCondLst") {
|
||||
if !(!is_main_seq && !at.deferred && is_main_seq_auto(st, at.main_seq_id)) && defers_start(st) {
|
||||
at.deferred = true;
|
||||
}
|
||||
if let Some(cond) = st.child("cond") {
|
||||
if cond.attr("delay").map(str::trim) == Some("indefinite") {
|
||||
*groups += 1;
|
||||
at.group = *groups;
|
||||
at.offset = 0;
|
||||
} else {
|
||||
at.offset = at.offset.saturating_add(ms_attr(cond, "delay").unwrap_or(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
at.main_seq_id = if is_main_seq && !at.deferred { c.u32("id") } else { None };
|
||||
}
|
||||
collect(c, at, groups, out, depth + 1);
|
||||
}
|
||||
@@ -293,7 +316,7 @@ pub fn media_settings(timing: &El, ctx: &IdCtx, shapes: &mut [Shape]) {
|
||||
let root_deferred = timing.path(&["tnLst", "par", "cTn", "stCondLst"]).is_some_and(defers_start);
|
||||
if !root_deferred && let Some(tn) = timing.child("tnLst") {
|
||||
let mut found = vec![];
|
||||
collect(tn, At { trigger: None, group: 0, offset: 0, deferred: false }, &mut 0, &mut found, 0);
|
||||
collect(tn, At { trigger: None, main_seq_id: None, group: 0, offset: 0, deferred: false }, &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") || f.deferred {
|
||||
@@ -321,7 +344,7 @@ pub fn animations(imp: &mut Imp, part: &Part, ctx: &IdCtx, timing: &El, shapes:
|
||||
let _ = (imp, part);
|
||||
let Some(tn) = timing.child("tnLst") else { return vec![] };
|
||||
let mut found = vec![];
|
||||
collect(tn, At { trigger: None, group: 0, offset: 0, deferred: false }, &mut 0, &mut found, 0);
|
||||
collect(tn, At { trigger: None, main_seq_id: None, group: 0, offset: 0, deferred: false }, &mut 0, &mut found, 0);
|
||||
// Paragraph builds (`bldP`) by (spid, grpId) -> whether `build="p"`.
|
||||
let bld_p: std::collections::HashMap<(u32, String), bool> = timing
|
||||
.child("bldLst")
|
||||
|
||||
@@ -182,6 +182,15 @@ fn media_only_slide_exports_and_round_trips_video_and_audio_timing_nodes() {
|
||||
});
|
||||
assert!(main_seq_play[0].autoplay, "main-sequence automatic Play effect sets autoplay");
|
||||
|
||||
// An `indefinite` + `onBegin delay="0"` condition whose `<p:tn>` references a different
|
||||
// click-dependent time node rather than the enclosing `mainSeq` must stay deferred.
|
||||
let non_main_seq_tn_play = self::clips(|v, _| {
|
||||
format!(
|
||||
r#"<p:seq concurrent="1" nextAc="seek"><p:cTn id="2" dur="indefinite" nodeType="mainSeq"><p:childTnLst><p:par><p:cTn id="99" fill="hold"><p:stCondLst><p:cond delay="indefinite"/></p:stCondLst><p:childTnLst><p:par><p:cTn id="100" fill="hold"><p:stCondLst><p:cond evt="onClick" delay="0"/></p:stCondLst></p:cTn></p:par></p:childTnLst></p:cTn></p:par><p:par><p:cTn id="3" fill="hold"><p:stCondLst><p:cond delay="indefinite"/><p:cond evt="onBegin" delay="0"><p:tn val="99"/></p:cond></p:stCondLst><p:childTnLst><p:par><p:cTn id="4" fill="hold"><p:stCondLst><p:cond delay="0"/></p:stCondLst><p:childTnLst><p:par><p:cTn id="5" presetID="1" presetClass="mediacall" presetSubtype="0" fill="hold" nodeType="withEffect"><p:stCondLst><p:cond delay="0"/></p:stCondLst><p:childTnLst><p:cmd type="call" cmd="playFrom(0.0)"><p:cBhvr><p:cTn id="6" dur="1" fill="hold"/><p:tgtEl><p:spTgt spid="{v}"/></p:tgtEl></p:cBhvr></p:cmd></p:childTnLst></p:cTn></p:par></p:childTnLst></p:cTn></p:par></p:childTnLst></p:cTn></p:par></p:childTnLst></p:cTn></p:seq><p:video><p:cMediaNode><p:cTn id="7" fill="hold"><p:stCondLst><p:cond delay="indefinite"/></p:stCondLst></p:cTn><p:tgtEl><p:spTgt spid="{v}"/></p:tgtEl></p:cMediaNode></p:video>"#
|
||||
)
|
||||
});
|
||||
assert!(!non_main_seq_tn_play[0].autoplay, "onBegin referencing non-mainSeq click-dependent node is not autoplay");
|
||||
|
||||
// Command-based Play beneath an onClick or onEnd ancestor must not set autoplay.
|
||||
let deferred_cmd_play = self::clips(|v, a| {
|
||||
format!(
|
||||
|
||||
Reference in new issue
Block a user