diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d10087..a753f55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,7 +60,6 @@ jobs: libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev \ libxkbcommon-dev \ libssl-dev \ - libcups2-dev \ mesa-vulkan-drivers vulkan-tools - name: Clippy diff --git a/CHANGELOG.md b/CHANGELOG.md index 65adada..5237241 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,22 @@ library), **rsdm** (a PyDM-style EPICS display layer built on rsplot), and ## [Unreleased] +### Changed + +- **rsplot**: the toolbar Print action no longer depends on the `printers` + crate, so a default build links no CUPS library (`-lcups`) and needs no + `libcups2-dev` at build time. Printer enumeration and job submission now shell + out to the `lpstat` / `lp` command-line tools. Printing works wherever those + are on `PATH` (CUPS on Linux/macOS); on platforms without them (e.g. Windows) + the printer list is empty and the print action reports no destination + (`print_graph` returns `Ok(false)`). The public `print_graph` / + `print_graph_to` signatures are unchanged. + +### Removed + +- **rsplot**: the `printers` crate dependency (and its transitive CUPS / + `libcups` build requirement). + ## [0.5.5] - 2026-07-18 ### Changed diff --git a/Cargo.toml b/Cargo.toml index a65fb3b..85a766d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,10 +45,6 @@ rfd = "0.17" # System clipboard for the toolbar Copy action (set_image with the wgpu readback RGBA). # Default features; the `image` crate it pulls is already in the tree via egui-winit. arboard = "3.6" -# Submit the rasterized figure PNG to the default system printer for the -# toolbar Print action (mirrors silx PrintAction printing a PNG bitmap via -# QPrinter). Wraps CUPS on unix / winspool on windows. -printers = "2.3.0" # Fast slice median for the median-filter analysis action (silx MedianFilterAction # / silx.math.medianfilter). The crate's `Medianf64::medf_unchecked` gives the silx # selection (sorted[n/2]) for the odd, NaN-free windows that dominate; the even / diff --git a/src/lib.rs b/src/lib.rs index 45abe6a..d3eaf1b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,10 @@ pub mod core; pub mod render; pub mod widget; +/// System-printer enumeration and spooling via the `lp` / `lpstat` CLI tools, +/// used by the toolbar Print action (no CUPS link dependency). +pub(crate) mod print_cli; + pub use crate::core::backend::{ Backend, CurveColor, CurveSpec, ImagePixelsSpec, ImageSpec, ItemHandle, MarkerSpec, PickResult, ShapeSpec, TriangleSpec, diff --git a/src/print_cli.rs b/src/print_cli.rs new file mode 100644 index 0000000..6564052 --- /dev/null +++ b/src/print_cli.rs @@ -0,0 +1,63 @@ +//! System-printer enumeration and spooling via the CUPS / BSD command-line +//! tools (`lpstat`, `lp`), replacing the `printers` crate so a default build +//! links no CUPS library (`-lcups`) and needs no `libcups2-dev` at build time. +//! +//! Printing is best-effort: it depends on `lp` / `lpstat` being on `PATH` +//! (CUPS on Linux/macOS). Where they are absent — e.g. Windows, or a machine +//! with no print system — enumeration returns an empty list and there is no +//! default printer, which the callers already treat as "no destination" +//! (`print_graph` → `Ok(false)`, the dialog → "No printers found"). No process +//! is spawned until the user actually prints. + +use std::path::Path; +use std::process::Command; + +/// The available system printer destinations, from `lpstat -e` (one name per +/// line). Any failure — `lpstat` missing, no print system, non-zero exit — +/// yields an empty list; callers treat that as "no printers found". +pub(crate) fn system_printers() -> Vec { + let Ok(out) = Command::new("lpstat").arg("-e").output() else { + return Vec::new(); + }; + if !out.status.success() { + return Vec::new(); + } + String::from_utf8_lossy(&out.stdout) + .lines() + .map(str::trim) + .filter(|line| !line.is_empty()) + .map(str::to_owned) + .collect() +} + +/// The system default destination, parsed from `lpstat -d` +/// ("system default destination: NAME"), or `None` when there is no default — +/// "no system default destination" — or `lpstat` is unavailable. +pub(crate) fn default_printer() -> Option { + let out = Command::new("lpstat").arg("-d").output().ok()?; + if !out.status.success() { + return None; + } + // Only the "…: NAME" form names a default; the no-default line has no colon. + let text = String::from_utf8_lossy(&out.stdout); + let name = text.trim().split_once(':')?.1.trim(); + (!name.is_empty()).then(|| name.to_owned()) +} + +/// Spool an already-rendered file to `printer` via `lp -d `. Returns +/// `Ok(())` when the job is queued; `Err(message)` when `lp` is missing or the +/// submission fails (unknown printer, spooler down). The job is queued, not +/// waited on, mirroring the fire-and-forget submit the `printers` crate did. +pub(crate) fn spool_file(path: &Path, printer: &str) -> Result<(), String> { + let out = Command::new("lp") + .arg("-d") + .arg(printer) + .arg(path) + .output() + .map_err(|e| format!("lp not available: {e}"))?; + if out.status.success() { + Ok(()) + } else { + Err(String::from_utf8_lossy(&out.stderr).trim().to_owned()) + } +} diff --git a/src/widget/high_level.rs b/src/widget/high_level.rs index efc7f8d..5cbb74e 100644 --- a/src/widget/high_level.rs +++ b/src/widget/high_level.rs @@ -8405,10 +8405,10 @@ impl PlotWidget { /// (`_plotAsPNG`) and draws that bitmap onto the printer via /// `QPainter`/`QPrinter` — not vector graphics. Here the figure is rasterized /// to a temp PNG via [`Self::save_graph`] (the only public figure-encoding - /// entry point), then submitted to the default printer with the - /// [`printers`] crate. Returns `Ok(true)` when a print job was queued, - /// `Ok(false)` when no default printer is available (the silx - /// `getDefaultPrinter` analogue). + /// entry point), then spooled to the default printer via the `lp` + /// command-line tool (see [`crate::print_cli`]). Returns `Ok(true)` when a + /// print job was queued, `Ok(false)` when there is no default printer (the + /// silx `getDefaultPrinter` analogue — `lpstat -d` reports none). /// /// The GPU readback and the printer submission are untested native shims (a /// real printer / spooler is required); the rasterization step reuses the @@ -8418,7 +8418,7 @@ impl PlotWidget { /// that routes to [`Self::print_graph_to`]; this method is the /// dialog-less direct path to the default printer. pub fn print_graph(&self, size: (u32, u32)) -> Result { - let Some(printer) = printers::get_default_printer() else { + let Some(printer) = crate::print_cli::default_printer() else { return Ok(false); }; self.print_to_printer(&printer, size) @@ -8429,30 +8429,26 @@ impl PlotWidget { /// `Ok(false)` when no printer of that name exists (e.g. it disappeared /// between the dialog opening and the click). pub fn print_graph_to(&self, printer_name: &str, size: (u32, u32)) -> Result { - let Some(printer) = printers::get_printer_by_name(printer_name) else { + if !crate::print_cli::system_printers() + .iter() + .any(|p| p == printer_name) + { return Ok(false); - }; - self.print_to_printer(&printer, size) + } + self.print_to_printer(printer_name, size) } /// Single submit owner for both print entry points: rasterize to a temp - /// PNG, hand the file to `printer`, and always remove the temp file. - fn print_to_printer( - &self, - printer: &printers::common::base::printer::Printer, - size: (u32, u32), - ) -> Result { + /// PNG, hand the file to `lp -d `, and always remove the temp file. + fn print_to_printer(&self, printer: &str, size: (u32, u32)) -> Result { // Rasterize to a temp PNG, then hand the file to the printer. save_graph // is the only public figure-encoding entry point (it writes a PNG file), // and silx prints a PNG bitmap, so PNG is the faithful intermediate. let path = print_temp_png_path(&std::env::temp_dir(), std::process::id()); self.save_graph(&path, size)?; - let submit = printer.print_file( - &path.to_string_lossy(), - printers::common::base::job::PrinterJobOptions::none(), - ); + let submit = crate::print_cli::spool_file(&path, printer); let _ = std::fs::remove_file(&path); - submit.map_err(|e| SaveError::Readback(format!("print submit: {}", e.message)))?; + submit.map_err(|e| SaveError::Readback(format!("print submit: {e}")))?; Ok(true) } diff --git a/src/widget/print_dialog.rs b/src/widget/print_dialog.rs index 4544a16..bef0e5f 100644 --- a/src/widget/print_dialog.rs +++ b/src/widget/print_dialog.rs @@ -82,12 +82,12 @@ impl PrintDialog { self.open = true; } - /// Open the dialog over the live system printer list (native enumeration, + /// Open the dialog over the live system printer list (`lpstat` enumeration, /// untestable shim — the list/selection logic it feeds is [`Self::open_with`]). pub fn open_with_system_printers(&mut self) { - let printers = printers::get_printers(); - let names = printers.iter().map(|p| p.system_name.clone()).collect(); - let default = printers.iter().position(|p| p.is_default); + let names = crate::print_cli::system_printers(); + let default = + crate::print_cli::default_printer().and_then(|d| names.iter().position(|n| *n == d)); self.open_with(names, default); }