diff --git a/locales/ar-SA/opencadstudio.ftl b/locales/ar-SA/opencadstudio.ftl index 589948d59..4922acddb 100644 --- a/locales/ar-SA/opencadstudio.ftl +++ b/locales/ar-SA/opencadstudio.ftl @@ -5277,8 +5277,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = دمج الخطوط المتداخلة .object-lineweights = سماكات خطوط الكائنات diff --git a/locales/bg-BG/opencadstudio.ftl b/locales/bg-BG/opencadstudio.ftl index b146c39cd..b1d6543c3 100644 --- a/locales/bg-BG/opencadstudio.ftl +++ b/locales/bg-BG/opencadstudio.ftl @@ -5265,8 +5265,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Обедини припокриващи се линии .object-lineweights = Дебелини на линии на обект diff --git a/locales/cs-CZ/opencadstudio.ftl b/locales/cs-CZ/opencadstudio.ftl index 32a532052..0025b1c1e 100644 --- a/locales/cs-CZ/opencadstudio.ftl +++ b/locales/cs-CZ/opencadstudio.ftl @@ -5262,8 +5262,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Sloučit překrývající se čáry .object-lineweights = Tloušťky čar objektů diff --git a/locales/de-DE/opencadstudio.ftl b/locales/de-DE/opencadstudio.ftl index 2dbb00c46..bae058f6d 100644 --- a/locales/de-DE/opencadstudio.ftl +++ b/locales/de-DE/opencadstudio.ftl @@ -5263,8 +5263,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Zusammenführung überlappender Leitungen .object-lineweights = Objektliniengewichte diff --git a/locales/el-GR/opencadstudio.ftl b/locales/el-GR/opencadstudio.ftl index 316dde7d7..59a2d29d0 100644 --- a/locales/el-GR/opencadstudio.ftl +++ b/locales/el-GR/opencadstudio.ftl @@ -5265,8 +5265,6 @@ plot = .this-printer-reports-no-driver-options = Ο εκτυπωτής δεν αναφέρει επιλογές driver. .could-not-read-the-printer-s-options-error = Αδυναμία ανάγνωσης των επιλογών του εκτυπωτή: __ocs_fmt_0__ .reading-the-printer-s-options = Ανάγνωση των επιλογών του εκτυπωτή… - .printing-preferences-saved-for-printer = Οι προτιμήσεις εκτύπωσης αποθηκεύτηκαν για τον εκτυπωτή __ocs_fmt_0__. - .printing-preferences-unchanged = Οι προτιμήσεις εκτύπωσης δεν άλλαξαν. .printer-properties = Ιδιότητες εκτυπωτή .merge-overlapping-lines = Συγχώνευση επικαλυπτόμενων γραμμών .object-lineweights = Πάχη γραμμών αντικειμένων diff --git a/locales/en-US/opencadstudio.ftl b/locales/en-US/opencadstudio.ftl index a8ba7fc41..91437ec33 100644 --- a/locales/en-US/opencadstudio.ftl +++ b/locales/en-US/opencadstudio.ftl @@ -5266,8 +5266,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Merge overlapping lines .object-lineweights = Object lineweights diff --git a/locales/es-ES/opencadstudio.ftl b/locales/es-ES/opencadstudio.ftl index 788932a08..5dca45375 100644 --- a/locales/es-ES/opencadstudio.ftl +++ b/locales/es-ES/opencadstudio.ftl @@ -5265,8 +5265,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Fusionar líneas solapadas .object-lineweights = Grosores de línea de objetos diff --git a/locales/fi-FI/opencadstudio.ftl b/locales/fi-FI/opencadstudio.ftl index cb6892d0c..3d4ef2aa2 100644 --- a/locales/fi-FI/opencadstudio.ftl +++ b/locales/fi-FI/opencadstudio.ftl @@ -5264,8 +5264,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Yhdistä päällekkäiset rivit .object-lineweights = Objektin viivan painot diff --git a/locales/fr-FR/opencadstudio.ftl b/locales/fr-FR/opencadstudio.ftl index e89501078..96d7719fe 100644 --- a/locales/fr-FR/opencadstudio.ftl +++ b/locales/fr-FR/opencadstudio.ftl @@ -5265,8 +5265,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Fusionner les lignes qui se chevauchent .object-lineweights = Poids de ligne d'objet diff --git a/locales/hi-IN/opencadstudio.ftl b/locales/hi-IN/opencadstudio.ftl index 4cb65b077..0abdf81ba 100644 --- a/locales/hi-IN/opencadstudio.ftl +++ b/locales/hi-IN/opencadstudio.ftl @@ -5253,8 +5253,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = मर्ज ओवरलैपिंग लाइन .object-lineweights = ऑब्जेक्ट लाइनवेट diff --git a/locales/hu-HU/opencadstudio.ftl b/locales/hu-HU/opencadstudio.ftl index a4f12329d..85300b635 100644 --- a/locales/hu-HU/opencadstudio.ftl +++ b/locales/hu-HU/opencadstudio.ftl @@ -5264,8 +5264,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Egyesítse az átfedő vonalakat .object-lineweights = Objektumvonalvastagságok diff --git a/locales/it-IT/opencadstudio.ftl b/locales/it-IT/opencadstudio.ftl index 6ddc5324c..2c04ca5e6 100644 --- a/locales/it-IT/opencadstudio.ftl +++ b/locales/it-IT/opencadstudio.ftl @@ -5264,8 +5264,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Unisci linee sovrapposte .object-lineweights = Spessori linea degli oggetti diff --git a/locales/ja-JP/opencadstudio.ftl b/locales/ja-JP/opencadstudio.ftl index 7b7c5d080..4b497ac77 100644 --- a/locales/ja-JP/opencadstudio.ftl +++ b/locales/ja-JP/opencadstudio.ftl @@ -5253,8 +5253,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = 重複線を結合 .object-lineweights = オブジェクトの線の太さ diff --git a/locales/ko-KR/opencadstudio.ftl b/locales/ko-KR/opencadstudio.ftl index ef8c2cf6b..01341ea71 100644 --- a/locales/ko-KR/opencadstudio.ftl +++ b/locales/ko-KR/opencadstudio.ftl @@ -5264,8 +5264,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = 겹치는 선 병합 .object-lineweights = 객체 선가중치 diff --git a/locales/nl-NL/opencadstudio.ftl b/locales/nl-NL/opencadstudio.ftl index 27308747e..8ff5aaeb7 100644 --- a/locales/nl-NL/opencadstudio.ftl +++ b/locales/nl-NL/opencadstudio.ftl @@ -5263,8 +5263,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Overlaplijnen samenvoegen .object-lineweights = Objectlijndiktes diff --git a/locales/pl-PL/opencadstudio.ftl b/locales/pl-PL/opencadstudio.ftl index d1cd1b3d6..623f12ea9 100644 --- a/locales/pl-PL/opencadstudio.ftl +++ b/locales/pl-PL/opencadstudio.ftl @@ -5264,8 +5264,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Połącz nakładające się linie .object-lineweights = Szerokości linii obiektu diff --git a/locales/pt-BR/opencadstudio.ftl b/locales/pt-BR/opencadstudio.ftl index 0ab66e7d7..d05fbec11 100644 --- a/locales/pt-BR/opencadstudio.ftl +++ b/locales/pt-BR/opencadstudio.ftl @@ -5265,8 +5265,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Mesclar linhas sobrepostas .object-lineweights = Espessuras de linha dos objetos diff --git a/locales/ru-RU/opencadstudio.ftl b/locales/ru-RU/opencadstudio.ftl index 0e25649a3..3db803682 100644 --- a/locales/ru-RU/opencadstudio.ftl +++ b/locales/ru-RU/opencadstudio.ftl @@ -5266,8 +5266,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Слияние пересекающихся линий .object-lineweights = Весы для объектов diff --git a/locales/tr-TR/opencadstudio.ftl b/locales/tr-TR/opencadstudio.ftl index 3822f9ea4..8489c67bf 100644 --- a/locales/tr-TR/opencadstudio.ftl +++ b/locales/tr-TR/opencadstudio.ftl @@ -5205,8 +5205,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = Çakışan çizgileri birleştir .object-lineweights = Nesne çizgi kalınlıkları diff --git a/locales/zh-CN/opencadstudio.ftl b/locales/zh-CN/opencadstudio.ftl index 5208a0465..5cea5147d 100644 --- a/locales/zh-CN/opencadstudio.ftl +++ b/locales/zh-CN/opencadstudio.ftl @@ -5248,8 +5248,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = 合并重叠线 .object-lineweights = 对象线宽 diff --git a/locales/zh-TW/opencadstudio.ftl b/locales/zh-TW/opencadstudio.ftl index c82db139c..20195cd14 100644 --- a/locales/zh-TW/opencadstudio.ftl +++ b/locales/zh-TW/opencadstudio.ftl @@ -5260,8 +5260,6 @@ plot = .this-printer-reports-no-driver-options = This printer reports no driver options. .could-not-read-the-printer-s-options-error = Could not read the printer's options: __ocs_fmt_0__ .reading-the-printer-s-options = Reading the printer's options… - .printing-preferences-saved-for-printer = Printing preferences saved for __ocs_fmt_0__. - .printing-preferences-unchanged = Printing preferences unchanged. .printer-properties = Printer properties .merge-overlapping-lines = 合併重疊線 .object-lineweights = 物件線寬 diff --git a/src/app/update/file.rs b/src/app/update/file.rs index 8a8f4ea93..1b8ce9da2 100644 --- a/src/app/update/file.rs +++ b/src/app/update/file.rs @@ -4416,9 +4416,9 @@ impl OpenCADStudio { /// /// On CUPS platforms (Linux, macOS) the driver's options are listed in an /// in-line editor and applied to every job for that printer through - /// `lp -o`. On Windows the driver's own document-properties sheet is - /// shown and its result stored as the printer's preferences, which the - /// print job honours. Without a named printer, or where the options + /// `lp -o`. On Windows the system opens the driver's own printing + /// preferences in its own process, and the print job honours what the + /// user saves there. Without a named printer, or where the options /// cannot be listed, the platform's printer settings open instead. fn on_printer_properties(&mut self) -> Task { // "Default" is a real printer: its preferences sheet is the one to @@ -4429,12 +4429,18 @@ impl OpenCADStudio { .clone() .or_else(|| self.plot_dialog.default_printer.clone()); let Some(printer) = chosen.filter(|_| !self.plot_dialog.to_file) else { - self.open_printer_settings_fallback(); + self.open_printer_settings(None); return Task::none(); }; #[cfg(target_os = "windows")] { - return self.edit_windows_printer_preferences(printer); + // The driver's sheet is modal: it pumps messages itself until the + // user closes it. Hosted on our event-loop thread it starves the + // loop it is sharing, so the window stops painting and a core + // spins. The system's own preferences process pumps its own + // messages instead, which leaves ours free. + self.open_printer_settings(Some(&printer)); + return Task::none(); } #[allow(unreachable_code)] { @@ -4456,40 +4462,11 @@ impl OpenCADStudio { } } - /// The driver's document-properties sheet, owned by the main window so - /// it sits on top of the plot dialog. - #[cfg(target_os = "windows")] - fn edit_windows_printer_preferences(&mut self, printer: String) -> Task { - let Some(window) = self.main_window else { - self.open_printer_settings_fallback(); - return Task::none(); - }; - iced::window::run(window, move |w| { - use iced::window::raw_window_handle::RawWindowHandle; - let owner = match w.window_handle().ok().map(|h| h.as_raw()) { - Some(RawWindowHandle::Win32(handle)) => handle.hwnd.get(), - _ => 0, - }; - match crate::io::print_to_printer::edit_printer_preferences(&printer, owner) { - Ok(true) => Ok(crate::tf!("Printing preferences saved for {printer}.").into_owned()), - Ok(false) => Ok(crate::t!("Printing preferences unchanged.").into_owned()), - Err(error) => Err(error), - } - }) - .then(|result| { - Task::done(Message::BackgroundIoFinished( - result.map(|message| message), - false, - )) - }) - } - - /// The platform's printer settings surface: a settings panel on Linux, - /// the printers control panel on Windows, System Settings on macOS. - fn open_printer_settings_fallback(&mut self) { - match crate::io::print_to_printer::open_printer_properties( - self.plot_dialog.printer.as_deref(), - ) { + /// The platform's printer settings surface: the driver's printing + /// preferences for `printer`, or — without one — a settings panel on + /// Linux, the printers control panel on Windows, System Settings on macOS. + fn open_printer_settings(&mut self, printer: Option<&str>) { + match crate::io::print_to_printer::open_printer_properties(printer) { Ok(()) => self .command_line .push_info(crate::t!("Opened printer properties.").as_ref()), diff --git a/src/io/print_to_printer.rs b/src/io/print_to_printer.rs index 4e58e88c0..2c4d7721c 100644 --- a/src/io/print_to_printer.rs +++ b/src/io/print_to_printer.rs @@ -1593,6 +1593,25 @@ mod printer_properties_tests { } } + /// `printui` parses the raw command line itself, so a name that reaches it + /// split over several arguments matches no printer and it exits 0 without + /// drawing anything — a failure with nothing to show the user. The name + /// has to stay a single argument, directly after `/n`. The verb matters + /// too: `/e` is printing preferences, `/p` the device's admin sheet. + #[cfg(target_os = "windows")] + #[test] + fn windows_preferences_keep_the_printer_name_in_one_argument() { + for name in ["Office Printer", "Wide Format Plotter 1200", "Εκτυπωτής γραφείου"] { + let (program, args) = printer_properties_command(Some(name)); + assert_eq!(program, "rundll32.exe"); + assert!(args.contains(&"/e".to_string()), "{args:?} must ask for preferences"); + assert!(!args.contains(&"/p".to_string()), "{args:?} must not ask for properties"); + let flag = args.iter().position(|arg| arg == "/n").expect("/n introduces the name"); + assert_eq!(args.get(flag + 1).map(String::as_str), Some(name), "{args:?}"); + assert_eq!(args.iter().filter(|arg| arg.as_str() == name).count(), 1); + } + } + #[cfg(target_os = "macos")] #[test] fn macos_opens_print_settings() { @@ -1797,89 +1816,6 @@ pub fn open_desktop_printer_settings(printer: Option<&str>) -> Result<(), String .map_err(|error| format!("Could not open printer settings: {error}")) } -/// Show the driver's own document-properties sheet for `printer`, owned by -/// the window `owner` (an `HWND`, 0 for none), and on OK store the result as -/// the user's printing preferences for that printer — which is what the -/// print job then honours. Returns `Ok(false)` when the user cancelled. -#[cfg(target_os = "windows")] -pub fn edit_printer_preferences(printer: &str, owner: isize) -> Result { - use windows_sys::Win32::Graphics::Gdi::DEVMODEW; - use windows_sys::Win32::Graphics::Printing::{ - ClosePrinter, DocumentPropertiesW, OpenPrinterW, SetPrinterW, PRINTER_HANDLE, - PRINTER_INFO_9W, - }; - // winspool.h: DM_OUT_BUFFER = DM_COPY, DM_IN_PROMPT = DM_PROMPT, - // DM_IN_BUFFER = DM_MODIFY. - const DM_OUT_BUFFER: u32 = 2; - const DM_IN_PROMPT: u32 = 4; - const DM_IN_BUFFER: u32 = 8; - const IDOK: i32 = 1; - - let name: Vec = printer.encode_utf16().chain(std::iter::once(0)).collect(); - let mut handle = PRINTER_HANDLE { - Value: std::ptr::null_mut(), - }; - // SAFETY: `name` is NUL-terminated and outlives the call; a null default - // asks for PRINTER_ACCESS_USE, enough for per-user preferences. - if unsafe { OpenPrinterW(name.as_ptr(), &mut handle, std::ptr::null()) } == 0 { - return Err(format!("Could not open printer \"{printer}\"")); - } - let owner = owner as windows_sys::Win32::Foundation::HWND; - let outcome = (|| { - // SAFETY: with null buffers the call only reports the DEVMODE size. - let size = unsafe { - DocumentPropertiesW(owner, handle, name.as_ptr(), std::ptr::null_mut(), std::ptr::null(), 0) - }; - if size <= 0 { - return Err(format!("Printer \"{printer}\" reports no document properties")); - } - // DEVMODEW is u16-aligned; a u16 buffer keeps the cast sound. - let words = (size as usize).div_ceil(2); - let mut current = vec![0u16; words]; - let mut edited = vec![0u16; words]; - // SAFETY: both buffers hold `size` bytes as the driver requested. - let fetched = unsafe { - DocumentPropertiesW( - owner, - handle, - name.as_ptr(), - current.as_mut_ptr().cast::(), - std::ptr::null(), - DM_OUT_BUFFER, - ) - }; - if fetched < 0 { - return Err(format!("Could not read the preferences of \"{printer}\"")); - } - edited.copy_from_slice(¤t); - // SAFETY: as above; DM_IN_PROMPT runs the driver's modal sheet. - let response = unsafe { - DocumentPropertiesW( - owner, - handle, - name.as_ptr(), - edited.as_mut_ptr().cast::(), - current.as_ptr().cast::(), - DM_IN_BUFFER | DM_IN_PROMPT | DM_OUT_BUFFER, - ) - }; - if response != IDOK { - return Ok(false); - } - let info = PRINTER_INFO_9W { - pDevMode: edited.as_mut_ptr().cast::(), - }; - // SAFETY: level 9 takes a PRINTER_INFO_9W; the DEVMODE outlives the call. - if unsafe { SetPrinterW(handle, 9, (&info as *const PRINTER_INFO_9W).cast::(), 0) } == 0 { - return Err(format!("Could not save the preferences of \"{printer}\"")); - } - Ok(true) - })(); - // SAFETY: `handle` came from OpenPrinterW above. - unsafe { ClosePrinter(handle) }; - outcome -} - #[cfg(test)] mod driver_option_tests { use super::*; diff --git a/src/locale_catalog.rs b/src/locale_catalog.rs index b09da7810..c9167776a 100644 --- a/src/locale_catalog.rs +++ b/src/locale_catalog.rs @@ -1504,8 +1504,6 @@ pub(super) fn message_attribute(source: &str) -> Option<(&'static str, &'static "This printer reports no driver options." => Some(("plot", "this-printer-reports-no-driver-options")), "Could not read the printer's options: {error}" => Some(("plot", "could-not-read-the-printer-s-options-error")), "Reading the printer's options…" => Some(("plot", "reading-the-printer-s-options")), - "Printing preferences saved for {printer}." => Some(("plot", "printing-preferences-saved-for-printer")), - "Printing preferences unchanged." => Some(("plot", "printing-preferences-unchanged")), "Printer properties" => Some(("plot", "printer-properties")), "Layout renamed: '{old_name}' → '{new_name}'" => Some(("common", "layout-renamed-old-name-new-name")), "Layouts" => Some(("layout", "layouts")),