forked from 1b-agent/opencadstudio-upstream
feat(plot): printer driver properties and a roomier plot dialog
Properties… next to the printer used to open the CUPS web interface in a browser. It now edits the driver options of the *selected* printer the way LibreOffice's Properties… does, without leaving the plot dialog: - CUPS platforms (Linux, any desktop; macOS): an in-line editor lists the printer's PPD options as `lpoptions -l` reports them — media type, colour mode, quality, duplex, trays, scaling — with readable choice labels, Reset / Cancel / Apply. Apply keeps only the choices that differ from the driver defaults, per printer, in the plot config, and every job for that printer passes them as `lp -o key=value`. Where CUPS cannot answer, the desktop's printer settings panel opens instead of a browser. - Windows: the driver's document-properties sheet (`DocumentPropertiesW` with prompt, owned by the main window) and, on OK, the result stored as the user's printing preferences for that printer (`SetPrinter` level 9), which the job honours. `printui /e` (printing preferences) replaces the device-properties sheet as the fallback. The desktop print portal was tried first and dropped: GTK 4's print dialog loses the preselected printer when the default queue is listed before it, so the dialog always opened on the wrong printer. Dialog layout: the modal grows to 940×620; Printer / plotter and Paper size share a line with their pickers (long queue and media names now fit); Copies + Properties… and Custom… sit beneath; the custom-sheet editor labels each margin (Left / Right, Top / Bottom) and shows the unit. Also recognises `none_device`, AutoCAD's stored spelling for "no plotter", and writes it back unchanged. Tests: `lpoptions` parsing and keyword humanising, the editor flow (load, stale answer ignored, set, apply, remember, reset, error, cancel), device name round-trips including `none_device`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5e271e2dbb
commit
737666b894
29 files changed
+1000
-103
No files matched your search
+18
-3
@@ -22,8 +22,10 @@ use std::sync::{Arc, Mutex, OnceLock};
|
||||
|
||||
/// AutoCAD's plotter configuration name for PDF output.
|
||||
pub const PDF_DEVICE_NAME: &str = "DWG To PDF.pc3";
|
||||
/// AutoCAD's spelling for "no plotter assigned".
|
||||
/// AutoCAD's spelling for "no plotter assigned" in the plot dialog…
|
||||
pub const NO_DEVICE_NAME: &str = "None";
|
||||
/// …and the name it actually stores in the drawing for that choice.
|
||||
const NO_DEVICE_STORED_NAME: &str = "none_device";
|
||||
/// The label older Open CAD Studio builds wrote into drawings for PDF output.
|
||||
/// Recognised on read so those drawings keep plotting to PDF, and always
|
||||
/// rewritten with [`PDF_DEVICE_NAME`] on save.
|
||||
@@ -44,7 +46,7 @@ impl PlotDevice {
|
||||
/// The name AutoCAD would store for this device.
|
||||
pub fn canonical_name(&self) -> String {
|
||||
match self {
|
||||
PlotDevice::None => NO_DEVICE_NAME.to_string(),
|
||||
PlotDevice::None => NO_DEVICE_STORED_NAME.to_string(),
|
||||
PlotDevice::Pdf => PDF_DEVICE_NAME.to_string(),
|
||||
PlotDevice::Printer(name) => name.clone(),
|
||||
}
|
||||
@@ -61,6 +63,10 @@ impl PlotDevice {
|
||||
if name.is_empty() || name.eq_ignore_ascii_case(NO_DEVICE_NAME) {
|
||||
return (PlotDevice::None, false);
|
||||
}
|
||||
if name.eq_ignore_ascii_case(NO_DEVICE_STORED_NAME) {
|
||||
// AutoCAD's own spelling: keep it rather than rewriting it.
|
||||
return (PlotDevice::None, true);
|
||||
}
|
||||
if name == LEGACY_PDF_LABEL {
|
||||
return (PlotDevice::Pdf, false);
|
||||
}
|
||||
@@ -387,7 +393,8 @@ mod tests {
|
||||
#[test]
|
||||
fn canonical_names_follow_autocad() {
|
||||
assert_eq!(PlotDevice::Pdf.canonical_name(), "DWG To PDF.pc3");
|
||||
assert_eq!(PlotDevice::None.canonical_name(), "None");
|
||||
// What AutoCAD writes for "None" in its plot dialog.
|
||||
assert_eq!(PlotDevice::None.canonical_name(), "none_device");
|
||||
assert_eq!(
|
||||
PlotDevice::Printer("L3270".into()).canonical_name(),
|
||||
"L3270"
|
||||
@@ -401,6 +408,14 @@ mod tests {
|
||||
PlotDevice::from_stored_name("None"),
|
||||
(PlotDevice::None, false)
|
||||
);
|
||||
assert_eq!(
|
||||
PlotDevice::from_stored_name("none_device"),
|
||||
(PlotDevice::None, true)
|
||||
);
|
||||
assert_eq!(
|
||||
PlotDevice::from_stored_name("NONE_DEVICE"),
|
||||
(PlotDevice::None, true)
|
||||
);
|
||||
assert_eq!(
|
||||
PlotDevice::from_stored_name("Save to PDF file…"),
|
||||
(PlotDevice::Pdf, false)
|
||||
|
||||
Reference in new issue
Block a user