mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-03 22:41:09 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67de44a803 | ||
|
|
577ada30b4 | ||
|
|
75c29c27db | ||
|
|
e7b67fb029 | ||
|
|
6c068ffc30 | ||
|
|
7a51671ebd | ||
|
|
d5741616c1 | ||
|
|
877e6db673 | ||
|
|
b697455ea7 | ||
|
|
5c179822d9 |
@@ -5,23 +5,23 @@ version: 'v0.0.3'
|
||||
workflows:
|
||||
'.github/workflows/ci.yml':
|
||||
- 'actions/[email protected]'
|
||||
- 'step-security/[email protected]2.4'
|
||||
- 'step-security/[email protected]3.0'
|
||||
'.github/workflows/freebsd.yml': []
|
||||
'.github/workflows/house-rules.yml': []
|
||||
'.github/workflows/lockfile.yml':
|
||||
- 'actions/[email protected]'
|
||||
- 'step-security/[email protected]2.4'
|
||||
- 'step-security/[email protected]3.0'
|
||||
'.github/workflows/nightly-dispatch.yml': []
|
||||
'.github/workflows/nightly-macos.yml':
|
||||
- 'actions/[email protected]'
|
||||
- 'step-security/[email protected]2.4'
|
||||
- 'step-security/[email protected]3.0'
|
||||
'.github/workflows/nightly-sign.yml': []
|
||||
'.github/workflows/nightly.yml': []
|
||||
'.github/workflows/nix.yml': []
|
||||
'.github/workflows/notify-services.yml': []
|
||||
'.github/workflows/packaging-lint.yml':
|
||||
- 'actions/[email protected]'
|
||||
- 'step-security/[email protected]2.4'
|
||||
- 'step-security/[email protected]3.0'
|
||||
'.github/workflows/release.yml': []
|
||||
'.github/workflows/sonarcloud.yml': []
|
||||
'.github/workflows/windows-arm64.yml': []
|
||||
@@ -31,8 +31,8 @@ dependencies:
|
||||
commit: 'sha1-3d3c42e5aac5ba805825da76410c181273ba90b1'
|
||||
owner_id: 44036562
|
||||
repo_id: 197814629
|
||||
'step-security/[email protected]2.4':
|
||||
ref: 'v2.22.4'
|
||||
commit: 'sha1-1d88384fd173af6ecb012dfd0264a306b711241a'
|
||||
'step-security/[email protected]3.0':
|
||||
ref: 'v2.23.0'
|
||||
commit: 'sha1-aebdcf6156ab6691adf63218240e476564a1ed4c'
|
||||
owner_id: 88700172
|
||||
repo_id: 422287306
|
||||
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
CRAFT_FONTS_REF: 37827adc41fd165f9a9234ac40f94dbad353aa69
|
||||
steps:
|
||||
- name: Harden runner
|
||||
uses: step-security/[email protected]2.4
|
||||
uses: step-security/[email protected]3.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
- name: Check out craft-fonts
|
||||
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- name: Harden runner
|
||||
uses: step-security/[email protected]2.4
|
||||
uses: step-security/[email protected]3.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
- uses: actions/[email protected]
|
||||
|
||||
@@ -36,7 +36,7 @@ jobs:
|
||||
RUST_BACKTRACE: 1
|
||||
steps:
|
||||
- name: Harden runner
|
||||
uses: step-security/[email protected]2.4
|
||||
uses: step-security/[email protected]3.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
- uses: actions/[email protected]
|
||||
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Harden runner
|
||||
uses: step-security/[email protected]2.4
|
||||
uses: step-security/[email protected]3.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
- uses: actions/[email protected]
|
||||
@@ -58,7 +58,7 @@ jobs:
|
||||
contents: read
|
||||
steps:
|
||||
- name: Harden runner
|
||||
uses: step-security/[email protected]2.4
|
||||
uses: step-security/[email protected]3.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
- uses: actions/[email protected]
|
||||
|
||||
+39
-15
@@ -376,18 +376,15 @@ Then wave"
|
||||
);
|
||||
}
|
||||
|
||||
/// Text with very many formatting runs is laid into runs in about linear time. Each lookup used to
|
||||
/// scan the run starts from the beginning, so the cost grew with runs²: in a debug build these 640k
|
||||
/// one-character runs (about 6 MB of file) took 75 s that way, and take about 2 s with binary search.
|
||||
#[test]
|
||||
fn many_character_runs_are_not_quadratic() {
|
||||
const N: usize = 640_000;
|
||||
let text: String = (0..N).map(|i| if i % 2 == 0 { 'a' } else { '\u{0B}' }).collect();
|
||||
/// A text box holding `n` one-character formatting runs (a character and a line break, alternating),
|
||||
/// as a legacy .ppt file.
|
||||
fn file_with_character_runs(n: usize) -> Vec<u8> {
|
||||
let text: String = (0..n).map(|i| if i % 2 == 0 { 'a' } else { '\u{0B}' }).collect();
|
||||
let mut style = vec![];
|
||||
style.extend_from_slice(&(N as u32 + 1).to_le_bytes());
|
||||
style.extend_from_slice(&(n as u32 + 1).to_le_bytes());
|
||||
style.extend_from_slice(&0u16.to_le_bytes());
|
||||
style.extend_from_slice(&0u32.to_le_bytes()); // a paragraph exception with no fields
|
||||
for _ in 0..=N {
|
||||
for _ in 0..=n {
|
||||
style.extend_from_slice(&1u32.to_le_bytes());
|
||||
style.extend_from_slice(&0u32.to_le_bytes()); // a character exception with no fields
|
||||
}
|
||||
@@ -398,12 +395,39 @@ fn many_character_runs_are_not_quadratic() {
|
||||
);
|
||||
let slide = container(rt::SLIDE, 0, &[slide_atom(1, MASTER_ID, 0x7), drawing(None, &[shape])]);
|
||||
let (cu, doc, pics) = streams_of(0xE391_C05F, 1, slide, None);
|
||||
let bytes = crate::cfb::build(&[("Current User", &cu), ("PowerPoint Document", &doc), ("Pictures", &pics)]);
|
||||
let t = std::time::Instant::now();
|
||||
let p = crate::import(&bytes).unwrap();
|
||||
assert!(t.elapsed() < std::time::Duration::from_secs(20), "{:?}", t.elapsed());
|
||||
let runs = &p.slides[0].shapes[0].text.as_ref().unwrap().paragraphs[0].runs;
|
||||
assert_eq!(runs.iter().filter(|r| r.kind == RunKind::Break).count(), N / 2);
|
||||
crate::cfb::build(&[("Current User", &cu), ("PowerPoint Document", &doc), ("Pictures", &pics)])
|
||||
}
|
||||
|
||||
/// Text with very many formatting runs is laid into runs in about linear time. Each lookup used to
|
||||
/// scan the run starts from the beginning, so the cost grew with runs²: 640k one-character runs
|
||||
/// (about 6 MB of file) took 75 s that way in a debug build, and about 2 s with binary search.
|
||||
///
|
||||
/// The test compares two sizes in the same process instead of timing one against a fixed limit, so
|
||||
/// a slow or busy host (the FreeBSD CI VM took 20 to 31 s for the 640k file, mostly in the kernel,
|
||||
/// where a quiet one takes 2 s) slows both alike. Four times the runs take about four times as long
|
||||
/// when the work is linear and sixteen times as long when it is quadratic. Each size is the best of
|
||||
/// three imports, so a stall in one of them doesn't decide the result.
|
||||
#[test]
|
||||
fn many_character_runs_are_not_quadratic() {
|
||||
const SMALL: usize = 40_000;
|
||||
const LARGE: usize = 4 * SMALL;
|
||||
let best_of_three = |n: usize| {
|
||||
let bytes = file_with_character_runs(n);
|
||||
let mut best = std::time::Duration::MAX;
|
||||
let mut breaks = 0;
|
||||
for _ in 0..3 {
|
||||
let t = std::time::Instant::now();
|
||||
let p = crate::import(&bytes).unwrap();
|
||||
best = best.min(t.elapsed());
|
||||
let runs = &p.slides[0].shapes[0].text.as_ref().unwrap().paragraphs[0].runs;
|
||||
breaks = runs.iter().filter(|r| r.kind == RunKind::Break).count();
|
||||
}
|
||||
(best, breaks)
|
||||
};
|
||||
let (small, small_breaks) = best_of_three(SMALL);
|
||||
let (large, large_breaks) = best_of_three(LARGE);
|
||||
assert_eq!((small_breaks, large_breaks), (SMALL / 2, LARGE / 2));
|
||||
assert!(large < small * 10, "{LARGE} runs took {large:?}, {SMALL} runs took {small:?}: more than 10x for 4x the runs");
|
||||
}
|
||||
|
||||
/// A slide naming a master that doesn't exist falls back to the first main master, every time. The
|
||||
|
||||
@@ -125,7 +125,16 @@ pub(crate) struct BackKey {
|
||||
struct Transition {
|
||||
/// The slide left behind, whose shapes Morph matches.
|
||||
from: Option<usize>,
|
||||
/// The time of the key press. A hidden show, which draws nothing, expires the transition
|
||||
/// from it.
|
||||
start: f64,
|
||||
/// Where the drawn transition's clock starts: the frame after the first one (see `progress`),
|
||||
/// because rendering the new slide and the transition's pictures can take longer than the
|
||||
/// whole transition (#1385). `None` until then.
|
||||
clock: Option<f64>,
|
||||
/// The first frame of the transition has been drawn: the new slide and the pictures the
|
||||
/// transition needs exist, so the time they took is not part of the transition.
|
||||
primed: bool,
|
||||
kind: String,
|
||||
option: String,
|
||||
dur: f64,
|
||||
@@ -134,6 +143,20 @@ struct Transition {
|
||||
reverse: bool,
|
||||
}
|
||||
|
||||
impl Transition {
|
||||
/// How far the transition has come at frame time `now`, from 0 to 1. The first frame is the
|
||||
/// one that renders the new slide and the transition's pictures and the second one starts the
|
||||
/// clock, so a slow render never eats the transition's duration (#1385).
|
||||
fn progress(&mut self, now: f64) -> f64 {
|
||||
if !self.primed {
|
||||
self.primed = true;
|
||||
return 0.0;
|
||||
}
|
||||
let clock = *self.clock.get_or_insert(now);
|
||||
((now - clock) / self.dur.max(0.01)).clamp(0.0, 1.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// A copy of the show's clock origins for regressions that must not depend on wall time.
|
||||
#[cfg(test)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@@ -230,7 +253,7 @@ impl Show {
|
||||
.map(|t| (t.kind.clone(), t.option.clone(), t.duration_ms as f64 / 1000.0))
|
||||
.unwrap_or(("none".into(), String::new(), 0.0));
|
||||
self.trans = if kind != "none" && dur > 0.0 && !doc.show.without_animation {
|
||||
Some(Transition { from, start: now, kind, option, dur, reverse: false })
|
||||
Some(Transition { from, start: now, clock: None, primed: false, kind, option, dur, reverse: false })
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -443,7 +466,7 @@ impl Show {
|
||||
// reversed Morph.
|
||||
let reverse = back && kind != "morph";
|
||||
self.trans = if kind != "none" && dur > 0.0 && !doc.show.without_animation {
|
||||
Some(Transition { from, start: now, kind, option, dur, reverse })
|
||||
Some(Transition { from, start: now, clock: None, primed: false, kind, option, dur, reverse })
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
@@ -493,8 +493,8 @@ fn prepare_transition(
|
||||
store: &TextureStore<FrameKey>,
|
||||
frame: &mut PaintFrame,
|
||||
) {
|
||||
let Some(tr) = &show.trans else { return };
|
||||
let p = ((now - tr.start) / tr.dur.max(0.01)).clamp(0.0, 1.0);
|
||||
let Some(tr) = &mut show.trans else { return };
|
||||
let p = tr.progress(now);
|
||||
if p >= 1.0 {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -625,6 +625,29 @@ fn animations_start_after_the_slides_transition() {
|
||||
assert_eq!(show.clock_snapshot().step_start, 10.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_slow_first_frame_does_not_use_up_the_transition() {
|
||||
// #1385: the clock started at the key press, so rendering the new slide for longer than the
|
||||
// transition's duration showed the next slide with no transition at all.
|
||||
let mut s = deckcraft_engine::Session::with_new();
|
||||
s.execute("slide.new", &json!({})).unwrap();
|
||||
s.execute("transition.set", &json!({"kind": "fade", "index": 1, "duration": 500})).unwrap();
|
||||
let doc = s.active().unwrap().doc.clone();
|
||||
let mut show = Show::new(&doc, 0, false, false);
|
||||
assert!(show.apply(ShowAction::Slide(1), &doc, 10.0));
|
||||
let tr = show.trans.as_mut().expect("the fade plays");
|
||||
assert!((tr.dur - 0.5).abs() < 1e-9);
|
||||
// The first frame renders for two seconds; it still shows the start of the transition.
|
||||
assert_eq!(tr.progress(10.0), 0.0);
|
||||
// The frame after it starts the clock.
|
||||
assert_eq!(tr.progress(12.0), 0.0);
|
||||
assert!((tr.progress(12.25) - 0.5).abs() < 1e-9);
|
||||
assert_eq!(tr.progress(12.5), 1.0);
|
||||
assert_eq!(tr.progress(20.0), 1.0);
|
||||
// A hidden show still expires it from the key press.
|
||||
assert_eq!(tr.start, 10.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn going_back_plays_the_left_slides_transition_reversed() {
|
||||
// #1531: Back plays the transition of the slide being left, in reverse.
|
||||
|
||||
Reference in New Issue
Block a user