mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-03 22:41:09 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
609105b401 | ||
|
|
f17e0582dc | ||
|
|
16cb262983 | ||
|
|
cf091013e6 | ||
|
|
c29124a389 | ||
|
|
e4c99e2d6f | ||
|
|
c33deedb94 |
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Reuse the shared scheduler setup through validation of its private file queue.
|
||||
shared=shared-print/crates/print/examples/print_acceptance/cups_capture.sh
|
||||
anchor='timeout 20s "$harness" list | tee "$results/discovery.log"'
|
||||
grep -Fxq "$anchor" "$shared"
|
||||
awk -v anchor="$anchor" '$0 == anchor { exit } { print }' "$shared" >"$RUNNER_TEMP/deckcraft-cups-setup.sh"
|
||||
source "$RUNNER_TEMP/deckcraft-cups-setup.sh" "$1" "$PWD/deckcraft-print-output"
|
||||
|
||||
timeout 20s lpadmin -h "$CUPS_SERVER" -d "$queue"
|
||||
test -z "$(timeout 10s lpstat -W all -o "$queue")"
|
||||
sudo -n test ! -e "$capture"
|
||||
sudo -n install -m 0600 /dev/null "$capture"
|
||||
|
||||
DECKCRAFT_PRIVATE_CUPS=1 timeout 90s "$harness" --test-threads=1 --nocapture print 2>&1 | tee "$results/ui-tests.log"
|
||||
for test in \
|
||||
print_from_quick_access_opens_settings_and_job_feedback_survives_leaving \
|
||||
print_previews_pages_and_prints_a_pdf \
|
||||
direct_print_reports_the_spooler_failure_and_keeps_the_viewer \
|
||||
direct_print_to_private_cups_from_quick_access; do
|
||||
grep -Eq "^test .*::${test} \\.\\.\\. (ok|DECKCRAFT_RECEIPT=)" "$results/ui-tests.log"
|
||||
done
|
||||
mapfile -t receipts < <(sed -nE 's/^.*DECKCRAFT_RECEIPT=(craft-print-capture-[0-9]+)$/\1/p' "$results/ui-tests.log")
|
||||
[[ ${#receipts[@]} == 1 ]]
|
||||
job_id=${receipts[0]}
|
||||
|
||||
for elapsed in {1..60}; do
|
||||
timeout 10s lpstat -W completed -o "$queue" >"$results/completed-jobs.log"
|
||||
if awk -v id="$job_id" '$1 == id { seen=1 } END { exit !seen }' "$results/completed-jobs.log" && sudo -n test -s "$capture"; then
|
||||
sudo -n cat -- "$capture" >"$results/captured.pdf"
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
timeout 10s lpstat -W all -o "$queue" >"$results/all-jobs.log"
|
||||
[[ $(awk '{print $1}' "$results/all-jobs.log") == "$job_id" ]]
|
||||
pdfinfo "$results/captured.pdf" >"$results/captured.pdfinfo"
|
||||
grep -Eq '^Pages: +2$' "$results/captured.pdfinfo"
|
||||
pdftoppm -r 36 "$results/captured.pdf" "$results/page"
|
||||
python3 - "$results" <<'PY' | tee "$results/page-order.log"
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
root = pathlib.Path(sys.argv[1])
|
||||
for n, expected in enumerate(((224, 32, 32), (32, 64, 224)), 1):
|
||||
magic, width, height, maximum, pixels = (root / f"page-{n}.ppm").read_bytes().split(maxsplit=4)
|
||||
w, h = int(width), int(height)
|
||||
assert magic == b"P6" and maximum == b"255" and len(pixels) == 3*w*h
|
||||
offset = 3 * ((h//2) * w + w//2)
|
||||
actual = tuple(pixels[offset:offset+3])
|
||||
assert all(abs(a-e) <= 25 for a, e in zip(actual, expected)), (n, actual, expected)
|
||||
print(f"Page {n}: center RGB {actual}, expected {expected}")
|
||||
PY
|
||||
(cd "$results" && sha256sum captured.pdf) | tee "$results/sha256.txt"
|
||||
@@ -0,0 +1,46 @@
|
||||
name: DeckCraft Linux print queue output
|
||||
on:
|
||||
push:
|
||||
branches: [verify/deckcraft-print-queue-output-4859]
|
||||
permissions:
|
||||
contents: read
|
||||
jobs:
|
||||
print:
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
CARGO_PROFILE_DEV_DEBUG: '0'
|
||||
CARGO_PROFILE_TEST_DEBUG: '0'
|
||||
CARGO_INCREMENTAL: '0'
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
|
||||
with:
|
||||
repository: storytold/craft-libs
|
||||
ref: fa63a22393bb03f40e33accbffa67c51465ee327
|
||||
path: shared-print
|
||||
persist-credentials: false
|
||||
- uses: storytold/craft-common-actions/actions/checkout-craft-fonts@58848078cd09e3ca182891a8b76ee979f1eb6e1c
|
||||
with:
|
||||
ref: 37827adc41fd165f9a9234ac40f94dbad353aa69
|
||||
- uses: storytold/craft-common-actions/actions/install-apt-packages@58848078cd09e3ca182891a8b76ee979f1eb6e1c
|
||||
with:
|
||||
packages: >-
|
||||
libasound2-dev libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev
|
||||
libgl1-mesa-dev cups-daemon cups-client cups-filters poppler-utils
|
||||
- name: Build the native UI tests
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cargo test --locked -p deckcraft-ui-egui --lib --no-run --message-format json > "$RUNNER_TEMP/deckcraft-build.jsonl"
|
||||
binary=$(jq -er 'select(.reason == "compiler-artifact" and .profile.test and .target.name == "deckcraft_ui_egui" and .executable) | .executable' "$RUNNER_TEMP/deckcraft-build.jsonl")
|
||||
echo "DECKCRAFT_TEST_BINARY=$binary" >> "$GITHUB_ENV"
|
||||
- name: Exercise Print and check the captured pages
|
||||
run: bash .github/qa/measure-print-queue-output.sh "$DECKCRAFT_TEST_BINARY"
|
||||
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
|
||||
if: always()
|
||||
with:
|
||||
name: deckcraft-print-output
|
||||
path: deckcraft-print-output/
|
||||
if-no-files-found: warn
|
||||
Generated
-1
@@ -2469,7 +2469,6 @@ name = "deckcraft-engine"
|
||||
version = "0.20.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-metafile",
|
||||
"craft-mime",
|
||||
"deckcraft-anim",
|
||||
"deckcraft-color",
|
||||
|
||||
@@ -22,7 +22,7 @@ log = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
craft = { workspace = true, features = ["web-api", "web-host", "platform-browser"] }
|
||||
craft = { workspace = true, features = ["web-api", "web-host", "platform-browser", "print"] }
|
||||
# `wgpu` pulls egui-wgpu's defaults: WebGPU plus the WebGL2 fallback.
|
||||
eframe = { workspace = true, features = ["default_fonts", "wgpu", "accesskit"] }
|
||||
wasm-bindgen = "0.2"
|
||||
|
||||
@@ -90,6 +90,7 @@ pub fn start() {
|
||||
}
|
||||
let mut app = SlideApp::new(&cc.egui_ctx, platform).map_err(|error| std::io::Error::other(error.to_string()))?;
|
||||
app.services.presenter = crate::presenter::opener(&cc.egui_ctx);
|
||||
app.services.browser_print = Some(Box::new(craft::print::browser::print_pdf));
|
||||
// In host mode the parent sends the presentation to edit; no sample meanwhile.
|
||||
if app_bridge.is_some() {
|
||||
if let Err(e) = app.start_for_host() {
|
||||
|
||||
@@ -15,7 +15,7 @@ craft-nightly = { workspace = true }
|
||||
deckcraft-engine = { workspace = true }
|
||||
deckcraft-ui-egui = { workspace = true }
|
||||
deckcraft-media = { workspace = true }
|
||||
craft = { workspace = true, features = ["ui-app", "window", "gpu-startup", "quit", "dialogs", "platform", "platform-clipboard-system", "automation", "settings", "font-catalog"] }
|
||||
craft = { workspace = true, features = ["ui-app", "window", "gpu-startup", "quit", "dialogs", "platform", "platform-clipboard-system", "automation", "settings", "font-catalog", "print"] }
|
||||
# `clipboard` is the OS clipboard (Ctrl+C/X/V with other apps). Without it egui simulates one inside
|
||||
# the app; the egui 0.37 migration (#1350) dropped it from this list.
|
||||
eframe = { workspace = true, features = ["default_fonts", "wgpu", "accesskit", "clipboard", "links", "wayland", "x11"] }
|
||||
|
||||
@@ -268,6 +268,10 @@ fn report_launch_profile_error(error: &str) {
|
||||
pub(crate) const LOG_DIR: &str = "logs";
|
||||
|
||||
fn main() -> eframe::Result {
|
||||
#[cfg(windows)]
|
||||
if let Some(code) = craft::print::spool::isolated::helper_main() {
|
||||
std::process::exit(code);
|
||||
}
|
||||
let Some(arguments) = prepare_launch() else { return Ok(()) };
|
||||
let nightly = launch_profile::current().is_nightly();
|
||||
// Nightly session health: the record names this window's owner and survives an abnormal end.
|
||||
@@ -433,6 +437,7 @@ fn main() -> eframe::Result {
|
||||
}
|
||||
}
|
||||
let mut app = SlideApp::new(ctx, platform)?;
|
||||
app.enable_direct_print();
|
||||
if !nightly {
|
||||
// Nightly is managed by ArtCraft Launcher: no self-update prompt or stable feed.
|
||||
app.enable_update_checks();
|
||||
|
||||
@@ -40,7 +40,7 @@ pub use interact::{Click, HitShape, Target};
|
||||
pub use mesh::{MeshVertex, layer_mesh};
|
||||
pub use morph::{MorphFrame, MorphPath, MorphText, morph_crop, morph_frame, morph_pairs, morph_xfrm};
|
||||
pub use path::{MotionPath, default_path};
|
||||
pub use show::{LinkJump, ShowAction, ShowState, looping, safe_url, show_order};
|
||||
pub use show::{LinkJump, ShowAction, ShowState, safe_url, show_order};
|
||||
pub use timeline::{EffectTiming, Sequence, StepStamp, Timeline, TriggerPlay};
|
||||
pub use transition::{DEFAULT_ASPECT, Layer, Source, transition_frame, transition_layers, uses_slide_parts};
|
||||
|
||||
|
||||
+10
-45
@@ -117,7 +117,7 @@ fn custom_indices(pres: &Presentation, name: &str) -> Option<Vec<usize>> {
|
||||
if order.is_empty() { None } else { Some(order) }
|
||||
}
|
||||
|
||||
pub fn looping(pres: &Presentation) -> bool {
|
||||
fn looping(pres: &Presentation) -> bool {
|
||||
pres.show.loop_until_esc || pres.show.show_type == "kiosk"
|
||||
}
|
||||
|
||||
@@ -236,54 +236,19 @@ impl ShowState {
|
||||
}
|
||||
|
||||
fn next_index(&self, pres: &Presentation) -> Option<usize> {
|
||||
self.visible_step(pres, self.slide, true, 1)
|
||||
let order = self.visit(pres);
|
||||
match order.iter().position(|&i| i == self.slide) {
|
||||
Some(p) => order.get(p + 1).copied(),
|
||||
None => order.iter().copied().find(|&i| i > self.slide),
|
||||
}
|
||||
}
|
||||
|
||||
fn prev_index(&self, pres: &Presentation) -> Option<usize> {
|
||||
self.visible_step(pres, self.slide, false, 1)
|
||||
}
|
||||
|
||||
/// Show the end screen without advancing a step (the pointer wheel past the last visible
|
||||
/// slide). A later forward input leaves the show through the end screen's own handling.
|
||||
pub fn end(&mut self) {
|
||||
self.ended = true;
|
||||
self.playing = false;
|
||||
}
|
||||
|
||||
/// `steps` slides after (`forward`) or before `from` in this show's visible order (the custom
|
||||
/// show or range, hidden slides skipped), without entering them; `None` when the order ends
|
||||
/// first. The pointer wheel turns slides through this, so it skips hidden slides as ←/→ do.
|
||||
pub fn visible_step(&self, pres: &Presentation, from: usize, forward: bool, steps: usize) -> Option<usize> {
|
||||
self.visible_step_in(pres, from, forward, steps, false)
|
||||
}
|
||||
|
||||
/// Like [`Self::visible_step`], but stops at the first/last visible slide instead of running
|
||||
/// past it: one fast wheel gesture lands on the end slide rather than leaving the order.
|
||||
pub fn visible_step_clamped(&self, pres: &Presentation, from: usize, forward: bool, steps: usize) -> Option<usize> {
|
||||
self.visible_step_in(pres, from, forward, steps, true)
|
||||
}
|
||||
|
||||
fn visible_step_in(&self, pres: &Presentation, from: usize, forward: bool, steps: usize, clamp: bool) -> Option<usize> {
|
||||
if steps == 0 {
|
||||
return None;
|
||||
}
|
||||
let order = self.visit(pres);
|
||||
// A `from` that is not in the order (a hidden slide opened by number) reaches the
|
||||
// nearest visible slide in the direction, which counts as the first step.
|
||||
let (start, used) = match order.iter().position(|&i| i == from) {
|
||||
Some(p) => (p, 0),
|
||||
None if forward => (order.iter().position(|&i| i > from)?, 1),
|
||||
None => (order.iter().rposition(|&i| i < from)?, 1),
|
||||
};
|
||||
let rest = steps.saturating_sub(used);
|
||||
let q = if forward {
|
||||
if clamp { start.saturating_add(rest).min(order.len().checked_sub(1)?) } else { start.checked_add(rest)? }
|
||||
} else if clamp {
|
||||
start.saturating_sub(rest)
|
||||
} else {
|
||||
start.checked_sub(rest)?
|
||||
};
|
||||
order.get(q).copied()
|
||||
match order.iter().position(|&i| i == self.slide) {
|
||||
Some(p) => p.checked_sub(1).and_then(|q| order.get(q).copied()),
|
||||
None => order.iter().copied().rev().find(|&i| i < self.slide),
|
||||
}
|
||||
}
|
||||
|
||||
/// Click / → / Space: finish the playing step, else play the next step, else go to the next slide.
|
||||
|
||||
@@ -763,21 +763,6 @@ fn show_skips_hidden_slides() {
|
||||
assert_eq!(s.goto(&p, 99), ShowAction::None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wheel_step_from_a_hidden_slide_counts_its_first_visible_neighbour() {
|
||||
// A hidden slide opened by number is not in the show order; the nearest visible slide in the
|
||||
// direction is the first step, and the rest of the notches still apply.
|
||||
let mut p = pres(5);
|
||||
Arc::make_mut(&mut p.slides[1]).hidden = true;
|
||||
let s = ShowState::new(&p);
|
||||
assert_eq!(s.visible_step_clamped(&p, 1, true, 2), Some(3));
|
||||
assert_eq!(s.visible_step_clamped(&p, 1, false, 2), Some(0));
|
||||
assert_eq!(s.visible_step(&p, 1, true, 2), Some(3));
|
||||
// Clamped steps stop at the ends of the visible order.
|
||||
assert_eq!(s.visible_step_clamped(&p, 4, true, 3), Some(4));
|
||||
assert_eq!(s.visible_step_clamped(&p, 0, false, 3), Some(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_remembers_a_slide_was_reached_by_going_back() {
|
||||
// #1531: the UI plays the left slide's transition reversed only for Back.
|
||||
|
||||
@@ -10,8 +10,6 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
craft-mime = { workspace = true }
|
||||
# Tells EMF from WMF when a picture is inserted (#2392).
|
||||
craft-metafile = { workspace = true }
|
||||
deckcraft-geom = { workspace = true }
|
||||
deckcraft-color = { workspace = true }
|
||||
deckcraft-model = { workspace = true }
|
||||
@@ -34,7 +32,6 @@ chrono = { workspace = true }
|
||||
[dev-dependencies]
|
||||
deckcraft-anim = { workspace = true }
|
||||
zip = { workspace = true }
|
||||
craft-metafile = { workspace = true, features = ["write"] }
|
||||
|
||||
# The browser clock for comment timestamps (wasm has no std::time::SystemTime).
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
|
||||
@@ -33,12 +33,6 @@ pub fn content_type(name: &str, bytes: &[u8]) -> &'static str {
|
||||
"image/bmp"
|
||||
} else if bytes.starts_with(b"II*\0") || bytes.starts_with(b"MM\0*") {
|
||||
"image/tiff"
|
||||
} else if let Some(kind) = craft_metafile::sniff(bytes) {
|
||||
// The MIME types the PPTX writer saves as `.emf` / `.wmf` parts (#2392).
|
||||
match kind {
|
||||
craft_metafile::Kind::Emf => "image/x-emf",
|
||||
craft_metafile::Kind::Wmf => "image/x-wmf",
|
||||
}
|
||||
} else if bytes.starts_with(b"fLaC") {
|
||||
"audio/flac"
|
||||
} else if bytes.starts_with(b"OggS") {
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
//! Standalone EMF and WMF files inserted as pictures (#2392).
|
||||
|
||||
use std::io::{Cursor, Read};
|
||||
|
||||
use craft_metafile::write::{Op, emf, wmf};
|
||||
use deckcraft_engine::Session;
|
||||
use deckcraft_engine::cmd::base64_encode;
|
||||
use deckcraft_geom::{KurboShape as _, Rect};
|
||||
use deckcraft_model::{ShapeId, ShapeKind};
|
||||
use serde_json::json;
|
||||
|
||||
/// Two solid rectangles, red at the top left and blue at the bottom right, on a 200 x 100 pt
|
||||
/// picture.
|
||||
fn two_rects() -> (Vec<Op>, Rect) {
|
||||
let fill = |r: Rect, rgb: [u8; 3]| Op::Fill { path: r.to_path(0.1), even_odd: false, rgb };
|
||||
(
|
||||
vec![fill(Rect::new(0.0, 0.0, 100.0, 50.0), [0xC7, 0x30, 0x40]), fill(Rect::new(100.0, 50.0, 200.0, 100.0), [0x20, 0x70, 0xD0])],
|
||||
Rect::new(0.0, 0.0, 200.0, 100.0),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn standalone_emf_and_wmf_files_insert_as_pictures_and_save_as_metafile_parts() {
|
||||
let (ops, region) = two_rects();
|
||||
let emf = emf(&ops, region, "DeckCraft", "two rects").expect("EMF");
|
||||
let wmf = wmf(&ops, region).expect("WMF").bytes;
|
||||
for (name, bytes, ext) in [("source.emf", emf, "emf"), ("source.wmf", wmf, "wmf")] {
|
||||
let mut s = Session::with_new();
|
||||
let rect = [200.0, 120.0, 480.0, 270.0];
|
||||
let r = s.execute("insert.picture", &json!({"data": base64_encode(&bytes), "name": name, "rect": rect})).expect(name);
|
||||
let id = ShapeId(r["id"].as_u64().expect("id") as u32);
|
||||
let doc = &s.doc().expect("doc").doc;
|
||||
let sh = doc.slides.iter().flat_map(|sl| &sl.shapes).find(|sh| sh.id == id).expect("inserted shape");
|
||||
let ShapeKind::Picture { fill } = &sh.kind else { panic!("{name} is a picture: {:?}", sh.kind) };
|
||||
let x = sh.xfrm.expect("xfrm");
|
||||
assert_eq!([x.x, x.y, x.w, x.h], rect, "{name} sits at the requested bounds");
|
||||
assert_eq!(doc.media(fill.media).expect("media").data.as_slice(), bytes.as_slice(), "{name} is embedded as given");
|
||||
|
||||
// Saved as a metafile part, and read back as the same picture.
|
||||
let pptx = deckcraft_pptx::export(doc).expect("export");
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(&pptx)).expect("zip");
|
||||
let part = z.file_names().find(|n| n.starts_with("ppt/media/") && n.ends_with(&format!(".{ext}"))).map(str::to_string);
|
||||
let part = part.unwrap_or_else(|| panic!("{name} is saved as a .{ext} part: {:?}", z.file_names().collect::<Vec<_>>()));
|
||||
let mut saved = Vec::new();
|
||||
z.by_name(&part).expect("part").read_to_end(&mut saved).expect("read");
|
||||
assert_eq!(saved, bytes, "{part} holds the file's bytes");
|
||||
let back = deckcraft_pptx::import(&pptx).expect("import");
|
||||
let reopened = back
|
||||
.slides
|
||||
.iter()
|
||||
.flat_map(|sl| &sl.shapes)
|
||||
.find(|sh| matches!(&sh.kind, ShapeKind::Picture { fill } if back.media(fill.media).is_some_and(|m| *m.data == bytes)));
|
||||
let reopened = reopened.unwrap_or_else(|| panic!("{name} reopens as a picture"));
|
||||
let x = reopened.xfrm.expect("reopened xfrm");
|
||||
let near = |a: f64, b: f64| (a - b).abs() < 0.01;
|
||||
assert!(
|
||||
near(x.x, rect[0]) && near(x.y, rect[1]) && near(x.w, rect[2]) && near(x.h, rect[3]),
|
||||
"{name} reopens at the requested bounds: {:?}",
|
||||
[x.x, x.y, x.w, x.h]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,2 @@
|
||||
mod chart_native;
|
||||
mod insert_metafile;
|
||||
mod show_clicks;
|
||||
|
||||
+15
-39
@@ -376,15 +376,18 @@ Then wave"
|
||||
);
|
||||
}
|
||||
|
||||
/// 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();
|
||||
/// 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();
|
||||
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
|
||||
}
|
||||
@@ -395,39 +398,12 @@ fn file_with_character_runs(n: usize) -> Vec<u8> {
|
||||
);
|
||||
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);
|
||||
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");
|
||||
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);
|
||||
}
|
||||
|
||||
/// A slide naming a master that doesn't exist falls back to the first main master, every time. The
|
||||
|
||||
@@ -28,7 +28,7 @@ log = { workspace = true }
|
||||
web-time = { workspace = true }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
craft = { workspace = true, features = ["update"] }
|
||||
craft = { workspace = true, features = ["update", "print"] }
|
||||
craft-update = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -195,6 +195,10 @@ impl SlideApp {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
print_previews: Default::default(),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
print_spool: None,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
print_receipt: None,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
updates_rt: Default::default(),
|
||||
selpane: Default::default(),
|
||||
align_to: None,
|
||||
@@ -220,6 +224,12 @@ impl SlideApp {
|
||||
self.print_previews.cleanup();
|
||||
}
|
||||
|
||||
/// Installs the system print spool for the native desktop shell.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn enable_direct_print(&mut self) {
|
||||
self.print_spool = Some(craft::print::spool::Spool::new(self.host.jobs_shared().clone()));
|
||||
}
|
||||
|
||||
/// Holds the close request until dirty presentations have passed the closing guard.
|
||||
pub fn close_decision(&mut self) -> embed::CloseDecision {
|
||||
let dirty: Vec<_> = self.session.documents().iter().filter(|doc| doc.is_dirty()).map(|doc| doc.uid).collect();
|
||||
@@ -248,11 +258,32 @@ impl SlideApp {
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
if let Some(spool) = self.print_spool.take() {
|
||||
spool.shutdown();
|
||||
}
|
||||
self.start_pending_update();
|
||||
self.cleanup_print_previews();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn poll_print_receipt(&mut self, ctx: &egui::Context) {
|
||||
use std::sync::mpsc::TryRecvError;
|
||||
|
||||
let Some((printer, receipt)) = &self.print_receipt else { return };
|
||||
let status = match receipt.try_recv() {
|
||||
Ok(Ok(message)) => format!("Sent to {printer}: {message}"),
|
||||
Ok(Err(error)) => format!("Couldn't print: {error}"),
|
||||
Err(TryRecvError::Disconnected) => "Couldn't confirm whether the print job reached the printer".into(),
|
||||
Err(TryRecvError::Empty) => {
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(200));
|
||||
return;
|
||||
}
|
||||
};
|
||||
self.print_receipt = None;
|
||||
self.set_status(status);
|
||||
}
|
||||
|
||||
/// Displays a transient message in the status bar.
|
||||
pub fn set_status(&mut self, msg: impl Into<String>) {
|
||||
self.status = Some((msg.into(), self.clock.now() * 1000.0));
|
||||
@@ -375,6 +406,8 @@ impl SlideApp {
|
||||
if !Self::root_viewport_admitted(ctx) {
|
||||
return;
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
self.poll_print_receipt(ctx);
|
||||
self.tick_hidden_show(ctx, web_time::Instant::now());
|
||||
if WindowHost::of(ctx).injected_idle() {
|
||||
self.drain_intake(ctx);
|
||||
|
||||
@@ -58,7 +58,7 @@ pub static UI_COMMANDS: &[UiCommand] = &[
|
||||
UiCommand {
|
||||
id: "app.print",
|
||||
label: "Print",
|
||||
params: "{layout?, perPage?, slides?, includeHidden?, frame?, paper?: letter|a4|legal|a3, orientation?: portrait|landscape}",
|
||||
params: "{layout?, perPage?, slides?, includeHidden?, frame?, paper?: letter|a4|legal|a3, orientation?: portrait|landscape} (no options opens desktop print settings when a system spooler is installed)",
|
||||
},
|
||||
UiCommand { id: "app.about", label: "About DeckCraft", params: "{}" },
|
||||
UiCommand { id: "app.checkUpdates", label: "Check for Updates…", params: "{}" },
|
||||
|
||||
@@ -275,6 +275,11 @@ impl SlideApp {
|
||||
if self.session.active().is_none() {
|
||||
return Err("nothing to print: no presentation is open".into());
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if self.print_spool.is_some() && (p.is_null() || p.as_object().is_some_and(|args| args.is_empty())) {
|
||||
self.open_backstage(backstage::Page::Print);
|
||||
return Ok(json!({"printed": false, "page": "print"}));
|
||||
}
|
||||
return Ok(json!({"printed": self.print_pdf(p.clone())}));
|
||||
}
|
||||
"app.about" => self.open_dialog("about", p.clone()),
|
||||
|
||||
@@ -257,14 +257,24 @@ impl SlideApp {
|
||||
self.submit_save(uid, None, files, &suggested, false, instance)
|
||||
}
|
||||
|
||||
/// File › Print: DeckCraft prints through a PDF. On the desktop the PDF (with the Print page's
|
||||
/// layout, slides and options) is written to the temporary folder and opened in the system's
|
||||
/// PDF viewer, which has the printers; on the web it downloads.
|
||||
/// File › Print: use the same PDF layout, slides and options with the host's available route.
|
||||
/// The browser opens its print dialog when installed. Other hosts open their viewer or export.
|
||||
pub fn print_pdf(&mut self, params: Value) -> bool {
|
||||
if self.session.active().is_none() {
|
||||
return false;
|
||||
}
|
||||
let Some(active) = self.session.active() else { return false };
|
||||
let params = if params.is_object() { params } else { json!({}) };
|
||||
if let Some(print) = self.services.browser_print.as_mut() {
|
||||
let result = deckcraft_engine::cmd::file::pdf_bytes(&active.doc, ¶ms).map_err(|e| e.to_string()).and_then(|bytes| print(&bytes));
|
||||
match result {
|
||||
Ok(()) => {
|
||||
self.set_status("Opening the browser print dialog");
|
||||
return true;
|
||||
}
|
||||
Err(error) => {
|
||||
self.set_status(format!("Couldn't open the browser print dialog: {error}"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if !self.host.files().browser_saves() {
|
||||
return self.print_preview(params);
|
||||
@@ -272,6 +282,13 @@ impl SlideApp {
|
||||
self.export_as("pdf", params)
|
||||
}
|
||||
|
||||
/// The Print page's "Open as PDF instead": the print PDF in the system's PDF viewer.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn print_pdf_viewer(&mut self, params: Value) -> bool {
|
||||
let params = if params.is_object() { params } else { json!({}) };
|
||||
self.print_preview(params)
|
||||
}
|
||||
|
||||
/// Writes the print PDF to a private temporary file and opens it in the system's PDF viewer.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn print_preview(&mut self, mut params: Value) -> bool {
|
||||
|
||||
@@ -206,6 +206,9 @@ pub struct Backstage {
|
||||
pub print_landscape: bool,
|
||||
/// Zero-based page displayed by the print preview.
|
||||
pub preview_page: usize,
|
||||
/// Desktop: printing straight to a printer from the Print page.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub direct_print: print::DirectPrint,
|
||||
/// The selected export task.
|
||||
pub export: ExportTask,
|
||||
/// Export › Change File Type / Save As: the chosen type (an [`SAVE_TYPES`] id).
|
||||
@@ -237,6 +240,8 @@ impl Backstage {
|
||||
print_paper: "letter",
|
||||
print_landscape: false,
|
||||
preview_page: 0,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
direct_print: print::DirectPrint::default(),
|
||||
export: ExportTask::Pdf,
|
||||
file_type: "pptx",
|
||||
handouts_per_page: 3,
|
||||
|
||||
@@ -21,6 +21,8 @@ use craft::ui::primitives::{ContentPainterCx, DocRun, DocText, PaintShape};
|
||||
use craft::ui::style::{Corners, DataColor, SurfaceKind, TypeRole};
|
||||
use craft::ui::text::TextField;
|
||||
use egui::{Color32, Rect, Shape, Stroke, StrokeKind, pos2, vec2};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// The slides the Print page prints, in order (0-based).
|
||||
@@ -94,15 +96,33 @@ pub(super) fn print(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: &
|
||||
let mut range_changed = false;
|
||||
Stack::new().wrap_width(WrapWidth::Column).show(ui, |ui, _| {
|
||||
let good_range = slides.as_ref().is_ok_and(|slides| !slides.is_empty());
|
||||
let detail = if app.host.files().can_pick() {
|
||||
"DeckCraft prints through a PDF: it opens in your PDF viewer, where you choose the printer."
|
||||
} else {
|
||||
"DeckCraft prints through a PDF: it downloads, ready to print from your browser or PDF viewer."
|
||||
};
|
||||
if task_row(ui, Icon::Print, "Print", "Print", detail, good_range)
|
||||
&& let Ok(slides) = &slides
|
||||
{
|
||||
app.print_pdf(print_params(bs, slides));
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let direct = app.print_spool.is_some();
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let direct = false;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if direct {
|
||||
direct_print(app, ui, bs, &doc, slides.as_ref().ok().filter(|slides| !slides.is_empty()));
|
||||
}
|
||||
if !direct {
|
||||
let browser = app.services.browser_print.is_some();
|
||||
let detail = if browser {
|
||||
"Opens the browser print dialog for the selected slides."
|
||||
} else {
|
||||
"DeckCraft prints through a PDF, ready to open in your browser or PDF viewer."
|
||||
};
|
||||
if task_row(ui, Icon::Print, "Print", "Print", detail, good_range)
|
||||
&& let Ok(slides) = &slides
|
||||
{
|
||||
app.print_pdf(print_params(bs, slides));
|
||||
}
|
||||
if browser
|
||||
&& let Ok(slides) = &slides
|
||||
&& !slides.is_empty()
|
||||
&& Link::new("Export PDF instead").show(ui).clicked()
|
||||
{
|
||||
app.export_as("pdf", print_params(bs, slides));
|
||||
}
|
||||
}
|
||||
Text::new("Settings").role(TypeRole::Heading).show(ui);
|
||||
FieldGroup::new("Settings").show(ui, |ui, _| {
|
||||
@@ -388,3 +408,89 @@ pub(super) fn export(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs:
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Printing straight to a printer: the spooler's printers, the chosen one, copies, and the job
|
||||
/// being sent on a worker thread.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
type PrinterDiscovery = Rc<std::sync::mpsc::Receiver<Vec<craft::print::Printer>>>;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DirectPrint {
|
||||
printers: Option<Vec<craft::print::Printer>>,
|
||||
discovery: Option<PrinterDiscovery>,
|
||||
printer: String,
|
||||
copies: String,
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl Default for DirectPrint {
|
||||
fn default() -> Self {
|
||||
DirectPrint { printers: None, discovery: None, printer: String::new(), copies: "1".into() }
|
||||
}
|
||||
}
|
||||
|
||||
/// Desktop Print sends the prepared PDF to the shared spooler. "Open as PDF instead" keeps the
|
||||
/// PDF viewer route, including queues whose sign-in requires the system viewer.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn direct_print(app: &mut SlideApp, ui: &mut Ui, bs: &mut Backstage, doc: &deckcraft_model::Presentation, slides: Option<&Vec<usize>>) {
|
||||
let Some(spool) = app.print_spool.clone() else { return };
|
||||
let dp = &mut bs.direct_print;
|
||||
if dp.printers.is_none() {
|
||||
let discovery = dp.discovery.get_or_insert_with(|| Rc::new(spool.discover()));
|
||||
match discovery.try_recv() {
|
||||
Ok(printers) => {
|
||||
dp.printer = printers.iter().find(|p| p.default).or(printers.first()).map(|p| p.name.clone()).unwrap_or_default();
|
||||
dp.printers = Some(printers);
|
||||
dp.discovery = None;
|
||||
}
|
||||
Err(std::sync::mpsc::TryRecvError::Empty) => ui.ctx().request_repaint_after(std::time::Duration::from_millis(200)),
|
||||
Err(std::sync::mpsc::TryRecvError::Disconnected) => {
|
||||
dp.printers = Some(Vec::new());
|
||||
dp.discovery = None;
|
||||
app.set_status("Couldn't find printers");
|
||||
}
|
||||
}
|
||||
}
|
||||
let copies = dp.copies.trim().parse::<u32>().ok().filter(|c| (1..=999).contains(c));
|
||||
let sending = app.print_receipt.is_some();
|
||||
let ready = slides.is_some() && !sending && !dp.printer.is_empty() && copies.is_some();
|
||||
let detail = if sending { "Sending the job to the printer…" } else { "Sends the slides straight to the printer chosen below." };
|
||||
if task_row(ui, Icon::Print, "Print", "Print", detail, ready)
|
||||
&& let (Some(slides), Some(copies)) = (slides, copies)
|
||||
{
|
||||
match deckcraft_engine::cmd::file::pdf_bytes(doc, &print_params(bs, slides)) {
|
||||
Ok(bytes) => {
|
||||
let dp = &mut bs.direct_print;
|
||||
let title = app.session.active().map(|d| d.title()).unwrap_or_else(|| "DeckCraft".into());
|
||||
let job = craft::print::Job { printer: Some(dp.printer.clone()), copies, collate: true, title, ..Default::default() };
|
||||
app.print_receipt = Some((dp.printer.clone(), spool.submit(bytes, job)));
|
||||
ui.ctx().request_repaint();
|
||||
app.set_status(format!("Sending to {}…", dp.printer));
|
||||
}
|
||||
Err(e) => app.set_status(format!("Couldn't make the pages to print: {e}")),
|
||||
}
|
||||
}
|
||||
let dp = &mut bs.direct_print;
|
||||
let names: Vec<String> = dp.printers.iter().flatten().map(|p| p.name.clone()).collect();
|
||||
FieldGroup::new("Printer").show(ui, |ui, _| {
|
||||
if dp.discovery.is_some() {
|
||||
Text::new("Finding printers…").shade(Shade::Muted).show(ui);
|
||||
} else if names.is_empty() {
|
||||
Text::new("No printers found.").shade(Shade::Muted).show(ui);
|
||||
} else {
|
||||
let entries: Vec<_> = names.iter().map(|n| Entry::new(n.clone(), n.clone())).collect();
|
||||
Field::new("Printer").show(ui, |ui, _| {
|
||||
Select::new("Printer", Bind::bound(&mut dp.printer), &entries).show(ui);
|
||||
});
|
||||
}
|
||||
Field::new("Copies").show(ui, |ui, _| {
|
||||
TextField::new("Copies", Bind::bound(&mut dp.copies)).show(ui);
|
||||
});
|
||||
});
|
||||
if Link::new("Open as PDF instead").show(ui).clicked()
|
||||
&& let Some(slides) = slides
|
||||
{
|
||||
app.print_pdf_viewer(print_params(bs, slides));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,6 +618,114 @@ fn print_previews_pages_and_prints_a_pdf() {
|
||||
assert!(std::fs::read(printed).unwrap().starts_with(b"%PDF"));
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn direct_print_reports_the_spooler_failure_and_keeps_the_viewer() {
|
||||
use craft::print::spool::{Pending, Spool, SpoolBackend};
|
||||
use craft::print::{Error, Job, Printer};
|
||||
|
||||
struct RejectingPrinter;
|
||||
|
||||
impl SpoolBackend for RejectingPrinter {
|
||||
fn printers(&self) -> Option<Vec<Printer>> {
|
||||
Some(vec![Printer { name: "Test printer".into(), default: true, description: String::new(), two_sided: None }])
|
||||
}
|
||||
|
||||
fn prepare(&self, pdf: Vec<u8>, job: Job) -> Pending {
|
||||
assert!(pdf.starts_with(b"%PDF"));
|
||||
assert_eq!(job.printer.as_deref(), Some("Test printer"));
|
||||
Pending {
|
||||
cancel: Box::new(|| true),
|
||||
run: Box::new(|| Err(Error::Spool("test queue refused the print job".into()))),
|
||||
waits_after_cancel: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut h = new_app();
|
||||
h.state_mut().print_spool = Some(Spool::with_backend(Arc::new(craft::host::InlineJobs), Arc::new(RejectingPrinter)));
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::P);
|
||||
h.run_steps(3);
|
||||
page_button(&h, "Print").click();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().status.as_ref().is_some_and(|(message, _)| message.contains("test queue refused the print job")));
|
||||
assert!(h.query_by_label("Open as PDF instead").is_some());
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn print_from_quick_access_opens_settings_and_job_feedback_survives_leaving() {
|
||||
let mut h = new_app();
|
||||
h.state_mut().enable_direct_print();
|
||||
h.state_mut().run("app.qat", json!({"add": "app.print", "label": "Print"})).unwrap();
|
||||
let index = h.state().ui.qat.iter().position(|q| q.id == "app.print").unwrap();
|
||||
assert!(crate::qat::run_index(h.state_mut(), index));
|
||||
assert_eq!(page(&h), Some(Page::Print));
|
||||
assert!(h.state().print_receipt.is_none());
|
||||
|
||||
let (sender, receiver) = std::sync::mpsc::channel();
|
||||
h.state_mut().print_receipt = Some(("Studio printer".into(), receiver));
|
||||
h.state_mut().run("app.backstage", json!({"on": false})).unwrap();
|
||||
assert_eq!(page(&h), None);
|
||||
sender.send(Err("queue rejected these sheets".into())).unwrap();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().print_receipt.is_none());
|
||||
assert!(h.state().status.as_ref().is_some_and(|(message, _)| message.contains("queue rejected these sheets")));
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn direct_print_to_private_cups_from_quick_access() {
|
||||
use std::os::unix::fs::FileTypeExt as _;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
if std::env::var("DECKCRAFT_PRIVATE_CUPS").as_deref() != Ok("1") {
|
||||
return;
|
||||
}
|
||||
let server = PathBuf::from(std::env::var_os("CUPS_SERVER").expect("private CUPS socket"));
|
||||
let state_dir = server.parent().and_then(Path::parent).expect("private CUPS state directory");
|
||||
assert!(server.ends_with("socket/cups.sock"));
|
||||
assert!(state_dir.starts_with("/run/cups") || state_dir.starts_with("/var/spool/cups"));
|
||||
assert!(state_dir.file_name().unwrap().to_string_lossy().starts_with("craft-print-acceptance."));
|
||||
assert!(std::fs::metadata(server).unwrap().file_type().is_socket());
|
||||
let queue = "craft-print-capture";
|
||||
|
||||
let mut session = Session::with_new();
|
||||
session.execute("design.background", &json!({"index": 0, "color": "#e02020"})).unwrap();
|
||||
session.execute("slide.new", &json!({"layout": "blank"})).unwrap();
|
||||
session.execute("design.background", &json!({"index": 1, "color": "#2040e0"})).unwrap();
|
||||
let mut h = harness(session, Arc::new(ScriptedFiles::new()));
|
||||
h.state_mut().enable_direct_print();
|
||||
h.state_mut().run("app.qat", json!({"add": "app.print", "label": "QA Quick Print"})).unwrap();
|
||||
h.run_steps(3);
|
||||
h.get_by_label("QA Quick Print").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(page(&h), Some(Page::Print));
|
||||
assert!(h.state().print_receipt.is_none());
|
||||
|
||||
let deadline = Instant::now() + Duration::from_secs(20);
|
||||
while page_button(&h, "Print").accesskit_node().is_disabled() {
|
||||
assert!(Instant::now() < deadline, "Print never became ready on the private queue");
|
||||
std::thread::sleep(Duration::from_millis(20));
|
||||
h.step();
|
||||
}
|
||||
page_button(&h, "Print").click();
|
||||
h.step();
|
||||
h.state_mut().run("app.backstage", json!({"on": false})).unwrap();
|
||||
assert_eq!(page(&h), None);
|
||||
|
||||
let deadline = Instant::now() + Duration::from_secs(20);
|
||||
while h.state().print_receipt.is_some() {
|
||||
assert!(Instant::now() < deadline, "the native Spool did not finish");
|
||||
std::thread::sleep(Duration::from_millis(20));
|
||||
h.step();
|
||||
}
|
||||
let (status, _) = h.state().status.as_ref().expect("print job feedback");
|
||||
let receipt = status.strip_prefix(&format!("Sent to {queue}: request id is {queue}-")).unwrap_or_else(|| panic!("{status}"));
|
||||
assert!(receipt.parse::<u32>().is_ok_and(|id| id > 0), "{status}");
|
||||
println!("DECKCRAFT_RECEIPT={queue}-{receipt}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn print_slides_follow_the_settings() {
|
||||
let mut s = Session::with_new();
|
||||
|
||||
@@ -122,6 +122,26 @@ fn host_exports_and_print_are_copies() {
|
||||
assert_eq!(path(app).as_deref(), Some("deck.pptx"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn browser_print_preserves_settings_and_reports_setup_failure() {
|
||||
let (mut h, got) = host_app(false);
|
||||
let app = h.state_mut();
|
||||
app.open_from_host(Some("deck.pptx"), &pptx(3));
|
||||
let params = json!({"slides": [1], "layout": "notes", "frame": true, "paper": "a4", "orientation": "landscape"});
|
||||
let expected = deckcraft_engine::cmd::file::pdf_bytes(&app.session.active().unwrap().doc, ¶ms).unwrap();
|
||||
let mut opened = false;
|
||||
app.services.browser_print = Some(Box::new(move |bytes| {
|
||||
assert_eq!(bytes, expected);
|
||||
if std::mem::replace(&mut opened, true) { Err("print frame unavailable".into()) } else { Ok(()) }
|
||||
}));
|
||||
assert!(app.print_pdf(params.clone()));
|
||||
assert!(!app.print_pdf(params.clone()));
|
||||
assert!(calls(&got).is_empty(), "a print error must not trigger an export");
|
||||
assert!(app.status.as_ref().is_some_and(|(message, _)| message.contains("print frame unavailable")));
|
||||
assert!(app.export_as("pdf", params));
|
||||
assert_eq!(calls(&got), [("deck.pdf".into(), false)], "the user can still explicitly export");
|
||||
}
|
||||
|
||||
/// The page not getting the file is a failed save: the presentation keeps its changes.
|
||||
#[test]
|
||||
fn a_host_save_that_fails_leaves_the_presentation_unsaved() {
|
||||
|
||||
@@ -222,6 +222,11 @@ pub struct SlideApp {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
print_previews: craft::platform::temp::TempFiles,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
print_spool: Option<craft::print::spool::Spool>,
|
||||
/// The printer and its pending receipt outlive the File > Print view.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
print_receipt: Option<(String, std::sync::mpsc::Receiver<Result<String, String>>)>,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
updates_rt: updates_ui::Runtime,
|
||||
/// Selection pane: folded groups and the Shift-run anchor.
|
||||
pub selpane: selpane::State,
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
/// The browser-owned connection to the presenter window.
|
||||
/// Hands a prepared PDF to the browser's print dialog.
|
||||
pub type BrowserPrint = Box<dyn FnMut(&[u8]) -> Result<(), String>>;
|
||||
|
||||
/// Browser-owned services.
|
||||
#[derive(Default)]
|
||||
pub struct Services {
|
||||
/// Presenter popup link; absent on native hosts.
|
||||
pub presenter: Option<Box<dyn craft::web_host::link::WindowLink>>,
|
||||
/// Absent on hosts that cannot open the browser print dialog.
|
||||
pub browser_print: Option<BrowserPrint>,
|
||||
}
|
||||
|
||||
@@ -82,11 +82,6 @@ pub struct Show {
|
||||
notes_px: f32,
|
||||
timings: Vec<(usize, f64)>,
|
||||
last_move: f64,
|
||||
/// Leftover fraction of a discrete wheel line. High-resolution and free-spin wheels send
|
||||
/// fractions of a line, so the delta accumulates here and each whole line is one slide.
|
||||
wheel_carry: f32,
|
||||
/// A discrete wheel line was handled this frame, so the canvas tool must not turn the page too.
|
||||
wheel_taken: bool,
|
||||
pub ended: bool,
|
||||
/// The slide whose media was last started (auto-play runs once per visit).
|
||||
media_slide: Option<usize>,
|
||||
@@ -237,8 +232,6 @@ impl Show {
|
||||
notes_px: NOTES_DEFAULT,
|
||||
timings: vec![],
|
||||
last_move: 0.0,
|
||||
wheel_carry: 0.0,
|
||||
wheel_taken: false,
|
||||
ended: false,
|
||||
media_slide: None,
|
||||
last_viewed: None,
|
||||
|
||||
@@ -775,18 +775,9 @@ fn a_first_animation_after_or_with_previous_plays_when_the_slide_appears() {
|
||||
|
||||
/// A running show on the first of three slides, with presenter view off.
|
||||
fn show_of_three() -> egui_kittest::Harness<'static, SlideApp> {
|
||||
show_of_with_hidden(3, &[])
|
||||
}
|
||||
|
||||
/// A running show on the first of `slides`, with `hidden` slides hidden.
|
||||
fn show_of_with_hidden(slides: usize, hidden: &[usize]) -> egui_kittest::Harness<'static, SlideApp> {
|
||||
let mut session = deckcraft_engine::Session::with_new();
|
||||
for _ in 1..slides {
|
||||
session.execute("slide.new", &json!({})).unwrap();
|
||||
}
|
||||
for &i in hidden {
|
||||
session.execute("slide.hide", &json!({"index": i, "hidden": true})).unwrap();
|
||||
}
|
||||
session.execute("slide.new", &json!({})).unwrap();
|
||||
session.execute("slide.new", &json!({})).unwrap();
|
||||
let mut harness =
|
||||
harness_with(session, Services::default(), egui_kittest::Harness::builder().with_size(vec2(1000.0, 700.0)).with_step_dt(1.0 / 60.0), |_| {});
|
||||
harness.state_mut().ui.presenter_view = false;
|
||||
@@ -833,184 +824,10 @@ fn ctrl_wheel_zooms_the_show_and_the_plain_wheel_turns_the_page() {
|
||||
assert!((show.view.zoom - fit).abs() < fit * 1e-3);
|
||||
|
||||
show_wheel(&mut h, centre, -3.0, egui::Modifiers::NONE);
|
||||
// #1724: a -3.0 wheel event is three lines, so three slides (clamped to the last of three).
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 2, "the plain wheel turns the page");
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 1, "the plain wheel turns the page");
|
||||
}
|
||||
}
|
||||
|
||||
/// #1724: two discrete wheel notches inside the trackpad's old 0.35 s cooldown turn two slides.
|
||||
/// One notch is one slide; the second notch must not be dropped by a gesture gate.
|
||||
#[test]
|
||||
fn two_wheel_notches_inside_the_trackpad_cooldown_turn_two_slides() {
|
||||
let mut h = show_of_three();
|
||||
let centre = pos2(500.0, 350.0);
|
||||
let notch = |harness: &mut egui_kittest::Harness<'static, SlideApp>, steps: usize| {
|
||||
harness.input_mut().events.push(egui::Event::PointerMoved(centre));
|
||||
harness.input_mut().events.push(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Line,
|
||||
delta: vec2(0.0, -1.0),
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Wheel,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
});
|
||||
harness.run_steps(steps);
|
||||
};
|
||||
notch(&mut h, 4);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 1, "one notch turns one slide");
|
||||
notch(&mut h, 4);
|
||||
assert_eq!(
|
||||
h.state().show.as_ref().expect("still showing").state.slide,
|
||||
2,
|
||||
"a second notch inside the old trackpad cooldown still turns the next slide"
|
||||
);
|
||||
}
|
||||
|
||||
/// #1724: on the end screen a discrete wheel notch keeps the old semantics: forward exits
|
||||
/// the show, back resumes the last slide instead of jumping.
|
||||
#[test]
|
||||
fn wheel_on_the_end_screen_exits_forward_and_resumes_back() {
|
||||
let mut h = show_of_three();
|
||||
let centre = pos2(500.0, 350.0);
|
||||
let line = |harness: &mut egui_kittest::Harness<'static, SlideApp>, y: f32| {
|
||||
harness.input_mut().events.push(egui::Event::PointerMoved(centre));
|
||||
harness.input_mut().events.push(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Line,
|
||||
delta: vec2(0.0, y),
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Wheel,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
});
|
||||
harness.run_steps(4);
|
||||
};
|
||||
line(&mut h, -1.0);
|
||||
line(&mut h, -1.0);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 2);
|
||||
line(&mut h, -1.0);
|
||||
assert!(h.state().show.as_ref().expect("still showing").ended, "past the last slide: the end screen");
|
||||
// Back resumes the last slide instead of jumping to the one before it.
|
||||
line(&mut h, 1.0);
|
||||
let show = h.state().show.as_ref().expect("still showing");
|
||||
assert!(!show.ended, "a backward notch leaves the end screen");
|
||||
assert_eq!(show.state.slide, 2, "it resumes the last slide");
|
||||
// Forward past the end again, then a forward notch exits.
|
||||
line(&mut h, -1.0);
|
||||
assert!(h.state().show.as_ref().expect("still showing").ended);
|
||||
line(&mut h, -1.0);
|
||||
assert!(h.state().show.is_none(), "a forward notch on the end screen exits the show");
|
||||
}
|
||||
|
||||
/// Backward from an end screen reached on a hidden tail resumes the last visible slide, not the
|
||||
/// hidden slide the show was left on.
|
||||
#[test]
|
||||
fn wheel_back_on_an_end_screen_from_a_hidden_tail_resumes_the_last_visible_slide() {
|
||||
let mut h = show_of_with_hidden(4, &[3]);
|
||||
let doc = h.state().session.active().unwrap().doc.clone();
|
||||
h.state_mut().show.as_mut().unwrap().state.goto(&doc, 3);
|
||||
h.run_steps(2);
|
||||
show_wheel(&mut h, pos2(500.0, 350.0), -1.0, egui::Modifiers::NONE);
|
||||
assert!(h.state().show.as_ref().expect("still showing").ended, "the hidden tail has no forward slide");
|
||||
show_wheel(&mut h, pos2(500.0, 350.0), 1.0, egui::Modifiers::NONE);
|
||||
let show = h.state().show.as_ref().expect("still showing");
|
||||
assert!(!show.ended, "a backward notch leaves the end screen");
|
||||
assert_eq!(show.state.slide, 2, "it resumes the last visible slide, not the hidden one");
|
||||
}
|
||||
|
||||
/// A looping show wraps a forward wheel notch from the last visible slide to the first instead
|
||||
/// of entering the end screen.
|
||||
#[test]
|
||||
fn wheel_forward_on_the_last_slide_wraps_in_a_looping_show() {
|
||||
let mut h = show_of_three();
|
||||
let st = h.state_mut().session.active_mut().unwrap();
|
||||
std::sync::Arc::make_mut(&mut st.doc).show.loop_until_esc = true;
|
||||
let centre = pos2(500.0, 350.0);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 2);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
let show = h.state().show.as_ref().expect("still showing");
|
||||
assert!(!show.ended, "the looping show does not end");
|
||||
assert_eq!(show.state.slide, 0, "it wraps to the first visible slide");
|
||||
}
|
||||
|
||||
/// The wheel turns slides through the show's visible order, so a hidden slide is skipped as
|
||||
/// ←/→ skip it instead of opening it through `ShowState::goto`.
|
||||
#[test]
|
||||
fn a_wheel_notch_skips_a_hidden_slide() {
|
||||
let mut h = show_of_with_hidden(3, &[1]);
|
||||
let centre = pos2(500.0, 350.0);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 2, "the hidden middle slide is skipped");
|
||||
show_wheel(&mut h, centre, 1.0, egui::Modifiers::NONE);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 0, "back also skips it");
|
||||
}
|
||||
|
||||
/// Two notches in one frame are applied in the order they arrived: a backward then a forward
|
||||
/// notch at the first slide still moves forward (a signed net would cancel them out).
|
||||
#[test]
|
||||
fn a_backward_then_forward_notch_in_one_frame_still_moves_forward() {
|
||||
let mut h = show_of_three();
|
||||
let centre = pos2(500.0, 350.0);
|
||||
h.input_mut().events.push(egui::Event::PointerMoved(centre));
|
||||
for y in [1.0_f32, -1.0] {
|
||||
h.input_mut().events.push(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Line,
|
||||
delta: vec2(0.0, y),
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Wheel,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
});
|
||||
}
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 1, "the forward notch still moves one slide");
|
||||
}
|
||||
|
||||
/// A backward notch with two lines on the end screen resumes the last slide and still steps one
|
||||
/// more back, matching the per-line contract of the ordinary-slide path.
|
||||
#[test]
|
||||
fn two_backward_lines_on_the_end_screen_reach_the_penultimate_slide() {
|
||||
let mut h = show_of_three();
|
||||
let centre = pos2(500.0, 350.0);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
assert!(h.state().show.as_ref().expect("still showing").ended, "at the end screen");
|
||||
show_wheel(&mut h, centre, 2.0, egui::Modifiers::NONE);
|
||||
let show = h.state().show.as_ref().expect("still showing");
|
||||
assert!(!show.ended, "two backward lines leave the end screen");
|
||||
assert_eq!(show.state.slide, 1, "the last slide then one more back");
|
||||
}
|
||||
|
||||
/// A hidden slide after the last visible one has no forward neighbour; a notch there still shows
|
||||
/// the end screen instead of doing nothing.
|
||||
#[test]
|
||||
fn a_forward_notch_on_a_hidden_slide_after_the_last_visible_ones_ends_the_show() {
|
||||
let mut h = show_of_with_hidden(4, &[3]);
|
||||
let doc = h.state().session.active().unwrap().doc.clone();
|
||||
h.state_mut().show.as_mut().unwrap().state.goto(&doc, 3);
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 3);
|
||||
show_wheel(&mut h, pos2(500.0, 350.0), -1.0, egui::Modifiers::NONE);
|
||||
assert!(h.state().show.as_ref().expect("still showing").ended, "no visible slide ahead: the end screen");
|
||||
}
|
||||
|
||||
/// A completed forward wheel notch past the last slide reaches the end screen and then exits,
|
||||
/// the same way a trackpad flick does; a partial line still does nothing.
|
||||
#[test]
|
||||
fn a_forward_wheel_notch_past_the_last_slide_reaches_the_end_screen() {
|
||||
let mut h = show_of_three();
|
||||
let centre = pos2(500.0, 350.0);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 2);
|
||||
// A partial line on the last slide does not end the show.
|
||||
show_wheel(&mut h, centre, -0.4, egui::Modifiers::NONE);
|
||||
assert!(!h.state().show.as_ref().expect("still showing").ended, "a partial notch does not reach the end screen");
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
assert!(h.state().show.as_ref().expect("still showing").ended, "a completed forward notch reaches the end screen");
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
assert!(h.state().show.is_none(), "forward on the end screen exits the show");
|
||||
}
|
||||
|
||||
/// A zoom at the top of the letterboxed slide keeps the slide over the fitted picture, as production's zoom window
|
||||
/// stays on the slide: its top edge stays at the picture's, not pushed up to the window's.
|
||||
#[test]
|
||||
@@ -1436,7 +1253,7 @@ fn remote_presenter_uses_the_audience_state_and_closes_with_the_show() {
|
||||
let mut session = deckcraft_engine::Session::with_new();
|
||||
session.execute("slide.new", &json!({})).unwrap();
|
||||
session.execute("slide.new", &json!({})).unwrap();
|
||||
let services = Services { presenter: Some(Box::new(Mock(bridge.clone()))) };
|
||||
let services = Services { presenter: Some(Box::new(Mock(bridge.clone()))), ..Default::default() };
|
||||
let mut h = harness_with(session, services, egui_kittest::Harness::builder().with_size(vec2(1000.0, 700.0)), |_| {});
|
||||
h.state_mut().ui.presenter_view = true;
|
||||
h.run_steps(3);
|
||||
|
||||
@@ -112,7 +112,6 @@ impl CanvasTool for ShowTool<'_> {
|
||||
if !self.show.zoomed
|
||||
&& !self.show.pen
|
||||
&& !self.show.grid
|
||||
&& !self.show.wheel_taken
|
||||
&& let Some(wheel) = space.wheel()
|
||||
&& !wheel.zooms
|
||||
{
|
||||
|
||||
@@ -143,12 +143,6 @@ fn canvas_pass(app: &mut SlideApp, ui: &mut Ui, bcx: &mut BodyCx<'_>, show: &mut
|
||||
if show.reading {
|
||||
bars::show(ui, show, p.doc, p.room, p.now);
|
||||
}
|
||||
// A discrete mouse-wheel notch turns one slide per line at once; point-based trackpad
|
||||
// gestures keep the canvas's own page turn.
|
||||
show.wheel_taken = false;
|
||||
if !show.pen && !show.zoomed {
|
||||
wheel_lines(&ctx, show, p.doc, out);
|
||||
}
|
||||
let mut media_wake = None;
|
||||
with_env(
|
||||
ui,
|
||||
@@ -226,98 +220,6 @@ fn canvas_pass(app: &mut SlideApp, ui: &mut Ui, bcx: &mut BodyCx<'_>, show: &mut
|
||||
media_wake
|
||||
}
|
||||
|
||||
/// Discrete wheel input must not share the trackpad's gesture gate. Keep every completed line in
|
||||
/// the order it arrived, including several notches in one frame, so movement at a boundary is not
|
||||
/// lost: a backward then forward notch at the first slide still moves forward. High-resolution
|
||||
/// and free-spin wheels send fractions of a line, accumulated in `show.wheel_carry`; a change of
|
||||
/// direction drops the leftover. The line events are taken out of the frame so the canvas's own
|
||||
/// wheel navigation does not turn the page a second time.
|
||||
fn wheel_lines(ctx: &egui::Context, show: &mut Show, doc: &Presentation, out: &mut Out) {
|
||||
// A multi-pass layout replays the frame's events; only the pass that is kept may move slides,
|
||||
// but every pass must take the lines out so the canvas does not also turn the page.
|
||||
let act = !ctx.will_discard();
|
||||
let mut steps = Vec::new();
|
||||
let mut handled = false;
|
||||
ctx.input_mut(|input| {
|
||||
let slides = doc.slides.len();
|
||||
input.events.retain(|event| {
|
||||
let egui::Event::MouseWheel { unit, delta, modifiers, .. } = event else { return true };
|
||||
if !matches!(unit, egui::MouseWheelUnit::Line | egui::MouseWheelUnit::Page)
|
||||
|| modifiers.ctrl
|
||||
|| modifiers.command
|
||||
|| modifiers.shift
|
||||
|| !delta.y.is_finite()
|
||||
|| delta.y == 0.0
|
||||
|| delta.y.abs() < delta.x.abs()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if act {
|
||||
if show.wheel_carry * delta.y < 0.0 {
|
||||
show.wheel_carry = 0.0;
|
||||
}
|
||||
show.wheel_carry += delta.y;
|
||||
// The small slack keeps sums such as 10 × 0.1 from falling just short of a line.
|
||||
let whole = (show.wheel_carry.abs() + 1e-4).floor();
|
||||
show.wheel_carry -= whole.copysign(show.wheel_carry);
|
||||
let count = whole.min(slides as f32) as usize;
|
||||
if count > 0 {
|
||||
steps.push(if delta.y < 0.0 { count as i32 } else { -(count as i32) });
|
||||
}
|
||||
}
|
||||
handled = true;
|
||||
false
|
||||
});
|
||||
});
|
||||
show.wheel_taken = handled;
|
||||
if !handled || !act {
|
||||
return;
|
||||
}
|
||||
// Each line is applied in arrival order against the state the preceding line left.
|
||||
for by in steps {
|
||||
let count = by.unsigned_abs() as usize;
|
||||
if show.ended {
|
||||
if by > 0 {
|
||||
out.keep = false;
|
||||
break;
|
||||
}
|
||||
show.ended = false;
|
||||
// Resume the last visible slide, even when the show ended from a hidden tail.
|
||||
let Some(target) = show.state.last_index(doc) else { continue };
|
||||
out.actions.push(show.state.goto(doc, target));
|
||||
if count > 1
|
||||
&& let Some(target) = show.state.visible_step_clamped(doc, target, false, count - 1)
|
||||
{
|
||||
out.actions.push(show.state.goto(doc, target));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let forward = by > 0;
|
||||
match show.state.visible_step_clamped(doc, show.state.slide, forward, count) {
|
||||
Some(target) if target != show.state.slide => out.actions.push(show.state.goto(doc, target)),
|
||||
Some(_) | None if forward => {
|
||||
// A looping show wraps from its last visible slide to the first instead of ending.
|
||||
if deckcraft_anim::looping(doc)
|
||||
&& let Some(first) = show.state.first_index(doc)
|
||||
{
|
||||
out.actions.push(show.state.goto(doc, first));
|
||||
if count > 1
|
||||
&& let Some(target) = show.state.visible_step_clamped(doc, first, true, count - 1)
|
||||
{
|
||||
out.actions.push(show.state.goto(doc, target));
|
||||
}
|
||||
} else {
|
||||
// A notch that cannot move forward shows the end screen instead of being
|
||||
// swallowed, as a trackpad flick past the last slide does.
|
||||
show.state.end();
|
||||
show.ended = true;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The slide's rect on screen when fitted to `rect`, as the unzoomed show draws it.
|
||||
fn fitted_picture(rect: Rect, target: &ViewTarget, zoom: &ShowZoomInputs<'_>) -> Rect {
|
||||
let mut view = CanvasView::new(rect, Point::ZERO, 1.0);
|
||||
|
||||
Reference in New Issue
Block a user