Print: a kept paper the new printer lists at a built-in size becomes that size

When the new printer listed the chosen paper at a size within half a
point of one of the dialog's own papers, the Size row kept the
`printer:<keyword>` choice, but the new Size list offers that paper
under the built-in id instead. The row then held a choice the list did
not contain, and the list was rebuilt and repainted on every frame. The
row now switches to the built-in paper the list offers.
This commit is contained in:
dotCooCoo committed 2026-12-01 22:04:15 -08:00
1 parent ee898bd9fe
commit d54e2cf55b
2 files changed
+47 -6

No files matched your search

+11 -6
View File
@@ -512,24 +512,29 @@ fn serve(app: &mut VectorcraftApp, ctx: &egui::Context, dialogs: &WindowDialogs,
ctx.request_repaint();
}
// A paper the new printer doesn't list, or lists under the same keyword at another size, becomes a custom size of
// the same Width and Height.
// the same Width and Height. One the new printer lists at the size of one of the dialog's own papers becomes that
// paper, the choice the new list offers for it.
if papers_changed
&& media.starts_with(PRINTER_PAPER)
&& let Some(s) = on(dialogs, |p| {
&& let Some((id, s)) = on(dialogs, |p| {
let fields = p.fields_mut();
if printer_paper(fields, &open.papers.1).is_some_and(|new| chosen.as_ref().is_none_or(|old| same_size(old, new))) {
return None;
if let Some(new) = printer_paper(fields, &open.papers.1)
&& chosen.as_ref().is_none_or(|old| same_size(old, new))
{
let own = own_media_of(new)?;
fields.set("media", own.id());
return Some((own.id().to_string(), settings(fields)));
}
if let Some(paper) = &chosen {
fields.set("width", paper.width);
fields.set("height", paper.height);
}
fields.set("media", Media::Custom.id());
Some(settings(fields))
Some((Media::Custom.id().to_string(), settings(fields)))
})
.flatten()
{
media = Media::Custom.id().to_string();
media = id;
d.settings = s;
}
if papers_changed || (!media.is_empty() && !open.media.contains(&media)) {
+36
View File
@@ -444,6 +444,42 @@ fn a_paper_keyword_another_printer_lists_at_another_size_becomes_a_custom_size()
assert_eq!((f["width"].as_f64(), f["height"].as_f64()), (Some(153.0), Some(243.0)), "{f}");
}
/// Two printers list a paper named Wide: Near at 611.2 × 792 points, Far at 611.6 × 792, within half a point of Letter.
struct NearLetter;
impl PrintService for NearLetter {
fn printers(&mut self) -> Vec<Printer> {
vec![Printer::new("Near").is_default(true), Printer::new("Far")]
}
fn print(&mut self, job: &PrintJob) -> Result<String, String> {
MockPrint(Jobs::default()).print(job)
}
fn papers(&mut self, printer: &str, _fresh: bool) -> Papers {
let width = if printer == "Far" { 611.6 } else { 611.2 };
Papers::Ready(vec![crate::print::Paper { key: "Wide".into(), label: "Wide".into(), width, height: 792.0 }])
}
}
#[test]
fn a_kept_paper_the_new_printer_lists_at_a_built_in_size_becomes_that_size() {
let services = Services { print: Some(Box::new(NearLetter)), ..Default::default() };
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
app.run("file.new", json!({"width": 120, "height": 90})).unwrap();
app.run("file.print", json!({})).unwrap();
pump(&mut app);
set(&mut app, "media", json!("printer:Wide"));
pump(&mut app);
// Far's Wide is within half a point of Near's and of Letter, and its Size list offers it as Letter.
set(&mut app, "printer", json!("Far"));
pump(&mut app);
pump(&mut app);
let f = fields(&app);
assert_eq!(f["media"], "letter", "{f}");
assert!(try_set(&mut app, "media", json!("printer:Wide")).is_err(), "the Size list offers Letter in its place");
}
/// Card lists a CR80 card; Twin's driver answers with the same CR80 once `ready` is set.
struct PendingTwin(Rc<Cell<bool>>);