mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-04 22:49:54 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ced13fe531 | ||
|
|
7a7a568d9a | ||
|
|
57d2fbc541 | ||
|
|
428b75079b |
@@ -0,0 +1,38 @@
|
||||
ZGlmZiAtLWdpdCBhL2NyYXRlcy91aS1jb250cmFjdC9zcmMvcnVudGltZS93aW5kb3dzL2hvc3Qu
|
||||
cnMgYi9jcmF0ZXMvdWktY29udHJhY3Qvc3JjL3J1bnRpbWUvd2luZG93cy9ob3N0LnJzCmluZGV4
|
||||
IGYwMDg2OTU4Mi4uNjU0YjQzMTE5IDEwMDY0NAotLS0gYS9jcmF0ZXMvdWktY29udHJhY3Qvc3Jj
|
||||
L3J1bnRpbWUvd2luZG93cy9ob3N0LnJzCisrKyBiL2NyYXRlcy91aS1jb250cmFjdC9zcmMvcnVu
|
||||
dGltZS93aW5kb3dzL2hvc3QucnMKQEAgLTM1NCw2ICszNTQsMTggQEAgaW1wbCBXaW5kb3dIb3N0
|
||||
IHsKICAgICAgICAgUGVyVmlld3BvcnQ6OjxSZWNvcmQ+Ojp3aXRoKCZzZWxmLmN0eCwgVmlld3Bv
|
||||
cnRJZDo6Uk9PVCwgfHJlY29yZHwgcmVjb3JkLm5hdGl2ZS5jbG9uZSgpKT8ucmF3X2hhbmRsZSgp
|
||||
CiAgICAgfQogCisgICAgLy8vIFRoZSBXaW4zMiBIV05EIG9mIHRoZSBnaXZlbiB2aWV3cG9ydCdz
|
||||
IHdpbmRvdywgZm9yIG93bmluZyBhIG5hdGl2ZSBkaWFsb2cuIFJldHVybnMKKyAgICAvLy8gYE5v
|
||||
bmVgIGlmIHRoZSB2aWV3cG9ydCBoYXMgbm8gbmF0aXZlIHdpbmRvdyBoYW5kbGUuCisgICAgcHVi
|
||||
IGZuIG5hdGl2ZV93aW5kb3dfaGFuZGxlKCZzZWxmLCB2aWV3cG9ydDogVmlld3BvcnRJZCkgLT4g
|
||||
T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gpLCByZWNvcmQuc2VhcmNoZWQsIHJlY29yZC5mYWN0cykpOwo=
|
||||
@@ -0,0 +1,36 @@
|
||||
name: Verify WordCraft printer Properties
|
||||
on:
|
||||
push:
|
||||
branches: [verify/wordcraft-windows-properties-4859]
|
||||
permissions:
|
||||
contents: read
|
||||
jobs:
|
||||
properties:
|
||||
runs-on: windows-latest
|
||||
timeout-minutes: 120
|
||||
env:
|
||||
CARGO_INCREMENTAL: 0
|
||||
CARGO_PROFILE_TEST_DEBUG: 0
|
||||
CARGO_PROFILE_DEV_DEBUG: 0
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
|
||||
- uses: storytold/craft-common-actions/actions/checkout-craft-fonts@58848078cd09e3ca182891a8b76ee979f1eb6e1c
|
||||
with:
|
||||
ref: b076417b5880bd4154bd22f00695b1d28c6bea83
|
||||
- name: Apply the staged native window owner accessor to the locked library revision
|
||||
shell: python
|
||||
run: |
|
||||
import base64, json, pathlib, subprocess
|
||||
graph = json.loads(subprocess.check_output(["cargo", "metadata", "--locked", "--format-version", "1", "--filter-platform", "x86_64-pc-windows-msvc"]))
|
||||
package, = (p for p in graph["packages"] if p["name"] == "craft-ui-contract")
|
||||
crate = pathlib.Path(package["manifest_path"]).parent
|
||||
framework = pathlib.Path(subprocess.check_output(["git", "rev-parse", "--show-toplevel"], cwd=crate, text=True).strip())
|
||||
head = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=framework, text=True).strip()
|
||||
assert head == "d73e274a01408ef433a291a667e6014937d72165", head
|
||||
patch = base64.b64decode(pathlib.Path(".github/qa/native-viewport-owner.patch.b64").read_bytes())
|
||||
subprocess.run(["git", "apply", "--check"], cwd=framework, input=patch, check=True)
|
||||
subprocess.run(["git", "apply"], cwd=framework, input=patch, check=True)
|
||||
- name: Check both Properties regressions on Windows
|
||||
run: cargo test --locked -p wordcraft-ui-egui --lib printer_properties_ -- --nocapture
|
||||
- name: Compile the real Windows driver dialog and its native window owner
|
||||
run: cargo check --locked -p wordcraft
|
||||
@@ -107,6 +107,7 @@ impl App {
|
||||
embed::before_ui(ui.ctx(), frame);
|
||||
}
|
||||
self.app.ui(ui);
|
||||
self.app.show_print_properties(ui.ctx());
|
||||
self.panels.pump_with(self.app.dialog_host_mut(), frame);
|
||||
}
|
||||
|
||||
@@ -243,6 +244,11 @@ fn services(spool: Spool, intake: FileIntake, nightly: bool) -> Services {
|
||||
let make_default_app: Option<MakeDefault> = None;
|
||||
Services {
|
||||
print: Some(spool),
|
||||
#[cfg(windows)]
|
||||
print_properties: Some(Box::new(|job, ctx, viewport| {
|
||||
let owner = WindowHost::of(ctx).native_window_handle(viewport).ok_or("the print window has no native owner")?;
|
||||
craft::print::driver_settings_dialog(job, Some(owner.get())).map_err(|error| error.to_string())
|
||||
})),
|
||||
templates_dir: wordcraft_control_key::settings_dir().map(|d| d.join("Templates")),
|
||||
make_default_app,
|
||||
intake: Some(intake),
|
||||
|
||||
@@ -111,6 +111,7 @@ impl WordApp {
|
||||
fonts_frames: 0,
|
||||
clipboard_published: false,
|
||||
printing: Default::default(),
|
||||
pending_print_properties: None,
|
||||
print_feedback_seen: None,
|
||||
print_gen: 0,
|
||||
updates_rt: updates_ui::Runtime::default(),
|
||||
|
||||
@@ -823,7 +823,15 @@ impl WordApp {
|
||||
// Native printing submits the selected queue on a worker; the browser owns its dialog.
|
||||
"ui.printSettings" => {
|
||||
let discover = self.services.print.as_ref().map(craft::print::spool::Spool::discoverer);
|
||||
return Some(printing::settings(&mut self.printing, p, discover.as_ref()));
|
||||
let result = printing::settings(&mut self.printing, p, discover.as_ref()).map(|mut status| {
|
||||
self.print.driver_properties.select_queue(printing::printer_name(&self.printing.settings));
|
||||
if let Some(error) = self.properties_error() {
|
||||
status["ready"] = json!(false);
|
||||
status["detail"] = json!(error);
|
||||
}
|
||||
status
|
||||
});
|
||||
return Some(result);
|
||||
}
|
||||
"ui.printPage" => return Some(printing::print_page(self, p)),
|
||||
"ui.print" | "ui.printSubmit" => return Some(self.print_to_system(p)),
|
||||
|
||||
@@ -415,6 +415,7 @@ pub struct WordApp {
|
||||
/// Only a successfully published copy may reuse this window's private fragment.
|
||||
pub clipboard_published: bool,
|
||||
pub printing: printing::State,
|
||||
pending_print_properties: Option<printing::PropertiesRequest>,
|
||||
print_feedback_seen: Option<printing::Feedback>,
|
||||
/// Which job message is current: bumped when a job starts and whenever the message changes,
|
||||
/// so a window can tell a new result from one it already said even when the text is the same.
|
||||
|
||||
@@ -96,6 +96,8 @@ impl PrintSettings {
|
||||
pub struct PrintPage {
|
||||
/// What gets printed.
|
||||
pub settings: PrintSettings,
|
||||
/// Settings accepted in the selected queue's driver for this print draft.
|
||||
pub(crate) driver_properties: crate::printing::DriverProperties,
|
||||
/// The generation (`WordApp::print_gen`) of the job result this window has already said, in
|
||||
/// its status bar or on this page: a result of the same text from a later job is another one.
|
||||
pub(crate) said: Option<u64>,
|
||||
@@ -122,7 +124,15 @@ impl PrintPage {
|
||||
|
||||
impl Default for PrintPage {
|
||||
fn default() -> Self {
|
||||
PrintPage { settings: PrintSettings::default(), said: None, hidden: None, opened_in: None, view: PrintPage::fit_view(), layout: None }
|
||||
PrintPage {
|
||||
settings: PrintSettings::default(),
|
||||
driver_properties: Default::default(),
|
||||
said: None,
|
||||
hidden: None,
|
||||
opened_in: None,
|
||||
view: PrintPage::fit_view(),
|
||||
layout: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,6 +242,7 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
|
||||
let opened = cx.appeared() && app.print.opened_in != Some(frame);
|
||||
if opened {
|
||||
app.print.opened_in = Some(frame);
|
||||
app.print.driver_properties.discard_accepted_settings();
|
||||
}
|
||||
let result = |m: &Option<crate::printing::Feedback>| {
|
||||
matches!(
|
||||
@@ -253,7 +264,7 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
|
||||
// Shown here, so the next opening needn't repeat it.
|
||||
app.print.said = result(&message).then_some(generation);
|
||||
}
|
||||
let ready = !chooses || app.printing.ready();
|
||||
let ready = !chooses || (app.printing.ready() && app.properties_error().is_none());
|
||||
// The row takes the page, so the preview beside the settings column fills the room left (production: the
|
||||
// preview takes the page's height beside a 380 pt column).
|
||||
Row::new().fill().gap(Gap::Section).show(ui, |ui, _| {
|
||||
@@ -278,7 +289,7 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
|
||||
pub(crate) fn print_requested(app: &mut WordApp, _ctx: &egui::Context) {
|
||||
let chooses = app.services.print.as_ref().is_some_and(|spool| spool.chooses_printer());
|
||||
let can_print = app.services.print.is_some();
|
||||
if can_print && (!chooses || app.printing.ready()) {
|
||||
if can_print && (!chooses || (app.printing.ready() && app.properties_error().is_none())) {
|
||||
let params = app.print.settings.params();
|
||||
let _ = app.run("ui.print", params);
|
||||
}
|
||||
@@ -297,6 +308,18 @@ fn settings(app: &mut WordApp, ui: &mut Ui, lay: &Arc<DocLayout>, hide_message:
|
||||
if let Some(discover) = app.services.print.as_ref().map(|spool| spool.discoverer()) {
|
||||
app.printing.run(ui, &discover);
|
||||
}
|
||||
if app.services.print_properties.is_some() {
|
||||
let queue = crate::printing::printer_name(&app.printing.settings);
|
||||
app.print.driver_properties.select_queue(queue);
|
||||
if clicked(
|
||||
&Button::new(tl!("Printer Properties…")).enabled(app.printing.ready() && !queue.is_empty()).id_salt("printer-properties").show(ui),
|
||||
) {
|
||||
crate::printing::request_properties(app, ui.ctx());
|
||||
}
|
||||
if let Some(error) = app.properties_error() {
|
||||
Text::new(error.to_owned()).tone(Tone::Bad).show(ui);
|
||||
}
|
||||
}
|
||||
if let Some(message) = app.printing.message.as_ref().filter(|_| !hide_message) {
|
||||
Text::new(crate::printing::feedback(message, |label| crate::i18n::t(label).to_owned())).show(ui);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::print_page::{NO_SCALING, ORIENTATIONS, PAGES_PER_SHEET, PARITIES, Pri
|
||||
/// Metadata for the app-owned commands. Inspecting it never discovers printers or submits.
|
||||
pub fn commands(app: &crate::WordApp) -> Vec<Value> {
|
||||
let enabled = match &app.services.print {
|
||||
Some(spool) if spool.chooses_printer() => app.printing.ready(),
|
||||
Some(spool) if spool.chooses_printer() => app.printing.ready() && app.properties_error().is_none(),
|
||||
Some(_) => true,
|
||||
None => false,
|
||||
};
|
||||
@@ -236,6 +236,108 @@ pub(crate) fn printer_name(settings: &Settings) -> &str {
|
||||
}
|
||||
}
|
||||
|
||||
/// Driver data belongs to this window's print draft and must never enter command JSON.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct DriverProperties {
|
||||
settings: Option<(u64, craft::print::DriverSettings)>,
|
||||
feedback: Option<(u64, String, String)>,
|
||||
}
|
||||
|
||||
impl DriverProperties {
|
||||
pub(crate) fn discard_accepted_settings(&mut self) {
|
||||
self.settings = None;
|
||||
}
|
||||
|
||||
pub(crate) fn select_queue(&mut self, queue: &str) {
|
||||
self.settings = self.settings.take().filter(|(_, settings)| settings.printer() == queue);
|
||||
self.feedback = self.feedback.take().filter(|(_, printer, _)| printer == queue);
|
||||
}
|
||||
|
||||
fn take_for(self, document: u64, queue: Option<&str>) -> Option<craft::print::DriverSettings> {
|
||||
self.settings.filter(|(doc, settings)| *doc == document && queue == Some(settings.printer())).map(|(_, settings)| settings)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct PropertiesRequest {
|
||||
window: u64,
|
||||
document: u64,
|
||||
viewport: egui::ViewportId,
|
||||
queue: String,
|
||||
}
|
||||
|
||||
pub(crate) fn request_properties(app: &mut crate::WordApp, ctx: &egui::Context) {
|
||||
let queue = printer_name(&app.printing.settings);
|
||||
if queue.is_empty() || !app.printing.ready() || app.services.print_properties.is_none() {
|
||||
return;
|
||||
}
|
||||
app.pending_print_properties = Some(PropertiesRequest {
|
||||
window: app.windows.shown(),
|
||||
document: app.session.document_id(),
|
||||
viewport: craft::ui::runtime::windows::WindowHost::of(ctx).current(),
|
||||
queue: queue.to_owned(),
|
||||
});
|
||||
}
|
||||
|
||||
impl crate::WordApp {
|
||||
pub(crate) fn properties_error(&self) -> Option<&str> {
|
||||
let (document, printer, message) = self.print.driver_properties.feedback.as_ref()?;
|
||||
(*document == self.session.document_id() && printer == printer_name(&self.printing.settings)).then_some(message.as_str())
|
||||
}
|
||||
|
||||
/// Lets the host present a requested Windows dialog after the frame. The viewport and
|
||||
/// document that asked keep their own draft, even if another window was drawn last.
|
||||
pub fn show_print_properties(&mut self, ctx: &egui::Context) {
|
||||
let Some(request) = self.pending_print_properties.take() else { return };
|
||||
let previous = self.windows.shown();
|
||||
if self.enter_window(request.window) {
|
||||
self.open_print_properties(ctx, request);
|
||||
self.enter_window(previous);
|
||||
}
|
||||
}
|
||||
|
||||
fn open_print_properties(&mut self, ctx: &egui::Context, request: PropertiesRequest) {
|
||||
if !self.ui.backstage
|
||||
|| self.ui.backstage_page != "print"
|
||||
|| self.session.document_id() != request.document
|
||||
|| !self.printing.ready()
|
||||
|| printer_name(&self.printing.settings) != request.queue
|
||||
{
|
||||
return;
|
||||
}
|
||||
let Some(open) = self.services.print_properties.as_ref() else { return };
|
||||
let mut job = job_of(&self.printing.settings, self.print.settings.collate, Vec::new());
|
||||
job.driver_settings = self
|
||||
.print
|
||||
.driver_properties
|
||||
.settings
|
||||
.as_ref()
|
||||
.filter(|(doc, settings)| *doc == request.document && settings.printer() == request.queue)
|
||||
.map(|(_, settings)| settings.clone());
|
||||
let result = open(&mut job, ctx, request.viewport).and_then(|accepted| {
|
||||
if !accepted {
|
||||
return Ok(None);
|
||||
}
|
||||
job.driver_settings
|
||||
.filter(|settings| settings.printer() == request.queue)
|
||||
.map(Some)
|
||||
.ok_or_else(|| tl!("The driver did not return settings for the selected printer.").to_owned())
|
||||
});
|
||||
match result {
|
||||
Ok(Some(settings)) => {
|
||||
self.print.driver_properties.settings = Some((request.document, settings));
|
||||
self.print.driver_properties.feedback = None;
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(error) => {
|
||||
let message = crate::i18n::fmt(tl!("Could not open printer properties: {error}"), &[("error", &error)]);
|
||||
self.print.driver_properties.feedback = Some((request.document, request.queue, message.clone()));
|
||||
self.status(message);
|
||||
}
|
||||
}
|
||||
ctx.request_repaint_of(request.viewport);
|
||||
}
|
||||
}
|
||||
|
||||
/// The spooler's job for `settings`: the app's choices, shrink-to-fit paper and the options list.
|
||||
// PLAN: assumed `craft::print` is reachable from ui-egui (the Job is built here, as apps/wordcraft/src/print.rs did).
|
||||
fn job_of(settings: &Settings, collate: bool, options: Vec<(String, String)>) -> craft::print::Job {
|
||||
@@ -268,6 +370,9 @@ pub fn submit(app: &mut crate::WordApp, params: &Value) -> Result<Value, String>
|
||||
return Ok(json!({"saveAsPdf": true}));
|
||||
}
|
||||
let chooses = spool.chooses_printer();
|
||||
if chooses && let Some(error) = app.properties_error() {
|
||||
return Err(error.to_owned());
|
||||
}
|
||||
if chooses && !app.printing.ready() {
|
||||
return Err("Select an available printer in File > Print before submitting.".into());
|
||||
}
|
||||
@@ -334,7 +439,12 @@ pub fn submit(app: &mut crate::WordApp, params: &Value) -> Result<Value, String>
|
||||
} else {
|
||||
print_options.push(("orientation-requested".into(), "3".into()));
|
||||
}
|
||||
let receiver = spool.submit(bytes, job_of(&settings, collate, print_options));
|
||||
let mut job = job_of(&settings, collate, print_options);
|
||||
let properties = std::mem::take(&mut app.print.driver_properties);
|
||||
if app.ui.backstage && app.ui.backstage_page == "print" {
|
||||
job.driver_settings = properties.take_for(app.session.document_id(), job.printer.as_deref());
|
||||
}
|
||||
let receiver = spool.submit(bytes, job);
|
||||
app.printing.begin(receiver).map_err(|_| "A print job is already being submitted.".to_owned())?;
|
||||
app.print_feedback_seen = None;
|
||||
app.print_gen = app.print_gen.wrapping_add(1);
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
/// Shows the selected printer's driver dialog, owned by the requesting viewport.
|
||||
pub type PrintProperties = Box<dyn Fn(&mut craft::print::Job, &egui::Context, egui::ViewportId) -> Result<bool, String>>;
|
||||
|
||||
/// Platform services injected by the host. Files, the clipboard, animations and preferences
|
||||
/// reach the app through the framework's host, not through here.
|
||||
#[derive(Default)]
|
||||
@@ -5,6 +8,8 @@ pub struct Services {
|
||||
/// Printing: the print job layer over the host's jobs (desktop printers, the browser's print
|
||||
/// dialog on the web).
|
||||
pub print: Option<craft::print::spool::Spool>,
|
||||
/// Windows: per-job printer properties. The host resolves the viewport's native owner.
|
||||
pub print_properties: Option<PrintProperties>,
|
||||
/// Web: told whether the document has unsaved changes after each pass, for the browser's
|
||||
/// leave-page guard (`beforeunload` runs between frames and can't ask the app).
|
||||
pub on_dirty: Option<Box<dyn Fn(bool)>>,
|
||||
|
||||
@@ -30,6 +30,7 @@ enum Reply {
|
||||
struct Recorder {
|
||||
reply: Arc<Mutex<Reply>>,
|
||||
sent: Arc<Mutex<Vec<Vec<u8>>>>,
|
||||
job_options: Arc<Mutex<Vec<craft::print::Job>>>,
|
||||
cancels: Arc<AtomicUsize>,
|
||||
held: Arc<Mutex<Vec<mpsc::Sender<()>>>>,
|
||||
never_sent: bool,
|
||||
@@ -42,6 +43,7 @@ impl Recorder {
|
||||
Recorder {
|
||||
reply: Arc::new(Mutex::new(reply)),
|
||||
sent: Arc::default(),
|
||||
job_options: Arc::default(),
|
||||
cancels: Arc::default(),
|
||||
held: Arc::default(),
|
||||
never_sent: true,
|
||||
@@ -101,8 +103,9 @@ impl SpoolBackend for Recorder {
|
||||
)
|
||||
}
|
||||
|
||||
fn prepare(&self, pdf: Vec<u8>, _job: craft::print::Job) -> Pending {
|
||||
fn prepare(&self, pdf: Vec<u8>, job: craft::print::Job) -> Pending {
|
||||
self.sent.lock().unwrap().push(pdf);
|
||||
self.job_options.lock().unwrap().push(job);
|
||||
let reply = self.reply.lock().unwrap().clone();
|
||||
let (keep, wait) = mpsc::channel::<()>();
|
||||
if matches!(reply, Reply::Hold) {
|
||||
@@ -537,6 +540,105 @@ fn print_page_harness(message: Option<Feedback>, rec: &Recorder) -> egui_kittest
|
||||
h
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn printer_properties_open_for_the_selected_queue_and_apply_to_one_submission() {
|
||||
let rec = Recorder::new(Reply::Sent).with_printers(["Test queue", "Second queue"]);
|
||||
let mut h = print_page_harness(None, &rec);
|
||||
let opened = Arc::new(AtomicUsize::new(0));
|
||||
let seen = opened.clone();
|
||||
h.state_mut().services.print_properties = Some(Box::new(move |job, _, owner| {
|
||||
assert_eq!(owner, egui::ViewportId::ROOT);
|
||||
assert_eq!(job.printer.as_deref(), Some("Test queue"));
|
||||
let mut bytes = vec![0; 160];
|
||||
bytes[68..70].copy_from_slice(&156u16.to_le_bytes());
|
||||
bytes[70..72].copy_from_slice(&4u16.to_le_bytes());
|
||||
bytes[156..].copy_from_slice(&[1, 2, 3, 4]);
|
||||
let native = craft::print::rgb::DevMode::from_bytes(bytes).unwrap();
|
||||
job.driver_settings = Some(craft::print::DriverSettings::new("Test queue", native));
|
||||
seen.fetch_add(1, Ordering::SeqCst);
|
||||
Ok(true)
|
||||
}));
|
||||
let ctx = h.ctx.clone();
|
||||
let open = || By::new().role(egui::accesskit::Role::Button).label("Printer Properties…");
|
||||
h.state_mut().run("file.print", json!({})).unwrap();
|
||||
h.run_steps(3);
|
||||
h.query(open()).expect("the selected printer has a Properties button").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(opened.load(Ordering::SeqCst), 0, "the host owns the native dialog");
|
||||
h.state_mut().show_print_properties(&ctx);
|
||||
assert_eq!(opened.load(Ordering::SeqCst), 1);
|
||||
assert_eq!(rec.sent_count(), 0, "opening Properties does not print");
|
||||
|
||||
h.state_mut().run("ui.printSubmit", json!({})).unwrap();
|
||||
h.state_mut().poll_printing(&ctx);
|
||||
h.state_mut().run("file.print", json!({})).unwrap();
|
||||
h.run_steps(3);
|
||||
h.state_mut().run("ui.printSubmit", json!({})).unwrap();
|
||||
h.state_mut().poll_printing(&ctx);
|
||||
h.state_mut().run("file.print", json!({})).unwrap();
|
||||
h.run_steps(3);
|
||||
h.query(open()).expect("the selected printer has a Properties button").click();
|
||||
h.run_steps(3);
|
||||
h.state_mut().show_print_properties(&ctx);
|
||||
h.state_mut().run("ui.printSettings", json!({"printer": "Second queue"})).unwrap();
|
||||
h.state_mut().run("ui.printSubmit", json!({})).unwrap();
|
||||
h.state_mut().poll_printing(&ctx);
|
||||
h.state_mut().run("ui.printSettings", json!({"printer": "Test queue"})).unwrap();
|
||||
h.state_mut().run("ui.printSubmit", json!({})).unwrap();
|
||||
|
||||
let jobs = rec.job_options.lock().unwrap();
|
||||
let [first, second, third, fourth] = jobs.as_slice() else { panic!("expected four jobs") };
|
||||
let properties = first.driver_settings.as_ref().expect("the first job carries the accepted properties");
|
||||
assert_eq!(properties.printer(), "Test queue");
|
||||
assert!(properties.dev_mode().to_hex().ends_with("01020304"), "the private driver fields reach the job");
|
||||
assert_eq!(second.printer.as_deref(), Some("Test queue"));
|
||||
assert!(second.driver_settings.is_none(), "the settings were for one submission");
|
||||
assert_eq!(third.printer.as_deref(), Some("Second queue"));
|
||||
assert!(third.driver_settings.is_none(), "properties do not follow a printer change");
|
||||
assert!(fourth.driver_settings.is_none(), "switching back does not recover the former properties");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn printer_properties_failure_blocks_print_until_the_driver_returns_matching_settings() {
|
||||
let rec = Recorder::new(Reply::Sent).with_printers(["Test queue", "Second queue"]);
|
||||
let mut h = print_page_harness(None, &rec);
|
||||
h.state_mut().run("file.print", json!({})).unwrap();
|
||||
h.run_steps(3);
|
||||
let ctx = h.ctx.clone();
|
||||
let attempts = AtomicUsize::new(0);
|
||||
h.state_mut().services.print_properties = Some(Box::new(move |job, _, _| match attempts.fetch_add(1, Ordering::SeqCst) {
|
||||
0 => Err("driver unavailable".into()),
|
||||
1 => Ok(false),
|
||||
2 => Ok(true),
|
||||
attempt => {
|
||||
let mut bytes = vec![0; 156];
|
||||
bytes[68..70].copy_from_slice(&156u16.to_le_bytes());
|
||||
let native = craft::print::rgb::DevMode::from_bytes(bytes).unwrap();
|
||||
let queue = if attempt == 3 { "Second queue" } else { "Test queue" };
|
||||
job.driver_settings = Some(craft::print::DriverSettings::new(queue, native));
|
||||
Ok(true)
|
||||
}
|
||||
}));
|
||||
for attempt in 0..5 {
|
||||
crate::printing::request_properties(h.state_mut(), &ctx);
|
||||
h.state_mut().show_print_properties(&ctx);
|
||||
if attempt < 4 {
|
||||
if attempt == 0 {
|
||||
leave_and_reopen_print(&mut h);
|
||||
}
|
||||
let settings = h.state_mut().run("ui.printSettings", json!({})).unwrap();
|
||||
assert_eq!(settings["ready"], false);
|
||||
assert!(h.state_mut().run("ui.printSubmit", json!({})).is_err());
|
||||
crate::print_page::print_requested(h.state_mut(), &ctx);
|
||||
assert_eq!(rec.sent_count(), 0);
|
||||
}
|
||||
}
|
||||
assert_eq!(h.state_mut().run("ui.printSettings", json!({})).unwrap()["ready"], true);
|
||||
h.state_mut().run("ui.printSubmit", json!({})).unwrap();
|
||||
assert_eq!(rec.sent_count(), 1);
|
||||
assert_eq!(rec.job_options.lock().unwrap()[0].driver_settings.as_ref().unwrap().printer(), "Test queue");
|
||||
}
|
||||
|
||||
/// A job message that arrives without the app's own `print_feedback` acting on it (a submitted job
|
||||
/// would close the Print page); what the window has said is set by the test.
|
||||
fn set_print_message(h: &mut egui_kittest::Harness<'_, WordApp>, message: Option<Feedback>) {
|
||||
|
||||
@@ -153,6 +153,7 @@ impl WordApp {
|
||||
search_cache: _,
|
||||
fonts_frames: _,
|
||||
printing: _,
|
||||
pending_print_properties: _,
|
||||
print_feedback_seen: _,
|
||||
print_gen: _,
|
||||
font_generation: _,
|
||||
|
||||
@@ -12,7 +12,7 @@ pens, microphones (Dictate) and speakers (Read Aloud), and displays.
|
||||
|
||||
| Hardware | Word | WordCraft macOS | Windows | Linux / BSD | Web | Parity | Hours |
|
||||
|---|---|---|---|---|---|---|---|
|
||||
| Printers: native print dialog, printer choice, copies, duplex, page ranges, tray, scaling | ✅ (`WordPDE.plugin` print-dialog extension on Mac) | 🟡 Direct CUPS printing; printer, copies, collation, duplex, ranges, grayscale, scale to paper size, N-up and booklets; on every desktop the PDF sent to the printer leaves out link annotations, which the spooler can't fit to the paper; Save these pages as PDF keeps them (#4734) | 🟡 Direct spooler printing; printer, copies, collation, duplex, ranges, grayscale, scale to paper size, N-up and booklets; on every desktop the PDF sent to the printer leaves out link annotations, which the spooler can't fit to the paper; Save these pages as PDF keeps them (#4734) | 🟡 Direct spooler printing; printer, copies, collation, duplex, ranges, grayscale, scale to paper size, N-up and booklets; on every desktop the PDF sent to the printer leaves out link annotations, which the spooler can't fit to the paper; Save these pages as PDF keeps them (#4734) | ✅ browser print dialog (#209) | 35% | 5–8 |
|
||||
| Printers: native print dialog, printer choice, copies, duplex, page ranges, tray, scaling | ✅ (`WordPDE.plugin` print-dialog extension on Mac) | 🟡 Direct CUPS printing; printer, copies, collation, duplex, ranges, grayscale, scale to paper size, N-up and booklets; on every desktop the PDF sent to the printer leaves out link annotations, which the spooler can't fit to the paper; Save these pages as PDF keeps them (#4734) | 🟡 Direct spooler printing and per-job printer-driver properties (#7665); printer, copies, collation, duplex, ranges, grayscale, scale to paper size, N-up and booklets; on every desktop the PDF sent to the printer leaves out link annotations, which the spooler can't fit to the paper; Save these pages as PDF keeps them (#4734) | 🟡 Direct spooler printing; printer, copies, collation, duplex, ranges, grayscale, scale to paper size, N-up and booklets; on every desktop the PDF sent to the printer leaves out link annotations, which the spooler can't fit to the paper; Save these pages as PDF keeps them (#4734) | ✅ browser print dialog (#209) | 35% | 5–8 |
|
||||
| GPU rendering, HiDPI/Retina, pixel-aligned text | ✅ | ✅ wgpu + vello_cpu rasteriser, whole-pixel text (#110, #165) | ✅ DirectX 12 default (#50), OpenGL when DirectX 12 has no GPU driver (#316) or on 32-bit; startup crash on Intel UHD (#170) | ✅ (soft text on KDE at some zooms, #140) | ✅ | 80% | 3–5 (bugs) |
|
||||
| Pen / stylus: ink, pressure, eraser, ink to shape/math | ✅ (Draw tab, `InkRender.bundle`) | 🟡 ink, stroke eraser, Ink to Shape incl. one- and two-stroke arrows with open or closed heads (#307, #395); pressure and Ink to Math missing | 🟡 same | 🟡 same | 🟡 same | 50% | (Draw tab, 15–25) |
|
||||
| Multiple monitors, per-monitor DPI, remembered window position, a window that fits its screen | ✅ | ✅ (#38, #76, #1215) | ✅ (winit DPI fix pending, #155) | ✅ | — | 85% | 1 |
|
||||
|
||||
Reference in New Issue
Block a user