mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 04:58:07 +00:00
pdf-workflows-w10: net change of 2 commits
- pdf-workflows-w10: written (committed by the lead: the run's own commit failed while gpg was locked after a reboot) - pdf-workflows-w10: review fixes (review-1)
This commit is contained in:
@@ -193,6 +193,21 @@ pub struct TextNotice {
|
||||
pub redrawn_elsewhere: bool,
|
||||
}
|
||||
|
||||
/// A measurement of how the file's bytes are spent, owning what it reads so it can run off the UI thread
|
||||
/// ([`Document::space_audit_job`]).
|
||||
pub struct SpaceAuditJob {
|
||||
/// The document as the editor holds it; `None` when the document can't be read for editing.
|
||||
cos: Option<pdfcraft_cos::Document>,
|
||||
size: u64,
|
||||
}
|
||||
|
||||
impl SpaceAuditJob {
|
||||
/// The measurement [`Document::audit_space`] makes; empty when the document can't be read for editing.
|
||||
pub fn run(self) -> Vec<optimize::SpaceUse> {
|
||||
self.cos.map(|cos| optimize::audit_space(&cos, self.size)).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for TextNotice {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let ch = format!("\"{}\" (U+{:04X})", self.ch.escape_debug(), u32::from(self.ch));
|
||||
@@ -290,6 +305,11 @@ impl Document {
|
||||
self.editor.as_ref().map(|e| optimize::audit_space(&e.cos, self.bytes.len() as u64)).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// [`Self::audit_space`] as a job over a copy of the document's state, to run in the background.
|
||||
pub fn space_audit_job(&self) -> SpaceAuditJob {
|
||||
SpaceAuditJob { cos: self.editor.as_ref().map(|e| e.cos.clone()), size: self.bytes.len() as u64 }
|
||||
}
|
||||
|
||||
/// The backdrop `page` (0-based) paints itself, which hides a background (Add Background).
|
||||
pub fn page_backdrop(&self, page: usize) -> Option<pdfcraft_edit::Backdrop> {
|
||||
self.editor.as_ref().and_then(|e| pdfcraft_edit::page_backdrop(&e.cos, page).ok().flatten())
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,66 @@
|
||||
//! The app's rules for one optimization at a time and the exclusion with Enhance scanned file, driven as a user fires the commands.
|
||||
//!
|
||||
//! PLAN: `mod optimize;` belongs in `tests/it/main.rs` (pdf-shell-w9's hunk). The held host is assumed
|
||||
//! `support::held_app(jobs: Arc<ManualJobs>) -> PdfCraftApp` (a `PdfCraftApp::with_host` over a host with `ManualJobs`, pdf-hub-w1 L-71) and
|
||||
//! `support::shown_notice(&Harness) -> Option<String>` (pdf-chrome-w9).
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft::host::ManualJobs;
|
||||
use egui_kittest::Harness;
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
|
||||
use crate::support;
|
||||
|
||||
/// A harness whose jobs wait until the test steps them, with a document open and the answer to Reduce's "where to save" given.
|
||||
fn held() -> (Arc<ManualJobs>, Harness<'static, PdfCraftApp>) {
|
||||
let jobs = Arc::new(ManualJobs::new());
|
||||
let queue = jobs.clone();
|
||||
let out = std::env::temp_dir().join(format!("pdfcraft-optimize-held-{}.pdf", std::process::id()));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_eframe(move |_cc| {
|
||||
let mut app = support::held_app(queue);
|
||||
app.set_option("language", "en").unwrap();
|
||||
app.open_bytes("notes.txt", None, b"hello".to_vec()).unwrap();
|
||||
app.save_override = Some(out.to_string_lossy().into_owned());
|
||||
app
|
||||
});
|
||||
h.run_steps(2);
|
||||
(jobs, h)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_second_run_is_refused_while_one_is_going() {
|
||||
let (jobs, mut h) = held();
|
||||
assert!(h.state_mut().execute("optimize.reduce"));
|
||||
h.run_steps(2);
|
||||
assert!(h.state().optimize_run.is_some(), "the first run is going");
|
||||
assert!(h.state_mut().execute("optimize.reduce"));
|
||||
h.run_steps(2);
|
||||
assert!(support::shown_notice(&h).is_some(), "the second run is refused with a notice");
|
||||
assert!(jobs.run_next(), "the first run's job is kept");
|
||||
assert!(!jobs.run_next(), "and no second job was queued");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enhancing_scans_refuses_optimizing() {
|
||||
let (_jobs, mut h) = held();
|
||||
h.state_mut().start_scan_clean();
|
||||
h.run_steps(2);
|
||||
assert!(h.state().scan_clean_run.is_some(), "the enhancement is going");
|
||||
assert!(h.state_mut().execute("optimize.reduce"));
|
||||
h.run_steps(2);
|
||||
assert!(support::shown_notice(&h).is_some());
|
||||
assert!(h.state().optimize_run.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn optimizing_refuses_enhancing_scans() {
|
||||
let (_jobs, mut h) = held();
|
||||
assert!(h.state_mut().execute("optimize.reduce"));
|
||||
h.run_steps(2);
|
||||
assert!(h.state().optimize_run.is_some(), "the run is going");
|
||||
h.state_mut().start_scan_clean();
|
||||
h.run_steps(2);
|
||||
assert!(support::shown_notice(&h).is_some());
|
||||
assert!(h.state().scan_clean_run.is_none());
|
||||
}
|
||||
Reference in New Issue
Block a user