From 2f038c5eb234a70ba3f3259875066d3abf1e5fc8 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 17 Oct 2026 19:37:40 +0200 Subject: [PATCH] Perspective Crop: W and H follow the Point/Pica Size preference (#7135) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit size_params converted points at a hard-coded 72 per inch. It now uses Preferences › Point/Pica Size, as the rulers, the type tools and the Crop tool do. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/crop_size.rs | 16 ++++++++++++++++ crates/ui-egui/src/perspective_crop_ui.rs | 6 ++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/crop_size.rs b/crates/ui-egui/src/crop_size.rs index b30cdd8c4a..d450ff06a0 100644 --- a/crates/ui-egui/src/crop_size.rs +++ b/crates/ui-egui/src/crop_size.rs @@ -530,4 +530,20 @@ mod tests { let o: ToolOptions = serde_json::from_str(r#"{"crop_ratio": "1:1"}"#).unwrap(); assert_eq!((o.crop_width.as_str(), o.crop_resolution_unit.as_str()), ("", PX_PER_IN)); } + + /// Perspective Crop's W and H follow Preferences › Point/Pica Size, as the Crop tool's do. + #[test] + fn perspective_crop_points_follow_the_point_size_preference() { + let doc = Document::with_background("p", Size::new(200, 150), ColorMode::Rgb, SampleType::U8, Color::WHITE); + let mut s = photocraft_engine::Session::new(); + s.add_document(doc, None); + let mut app = PhotocraftApp::new(s, crate::Services::default()); + app.session.edit_prefs(|p| p.units_and_rulers.point_size = photocraft_engine::prefs::PointSize::Traditional); + let o = &mut app.ui.tool_options; + (o.crop_width, o.crop_height, o.crop_resolution) = ("7227 pt".into(), "100 px".into(), "72".into()); + o.crop_resolution_unit = PX_PER_IN.into(); + let mut p = json!({}); + crate::perspective_crop_ui::size_params(&app, &mut p); + assert_eq!((p["width"].as_f64(), p["height"].as_f64()), (Some(7200.0), Some(100.0)), "{p}"); + } } diff --git a/crates/ui-egui/src/perspective_crop_ui.rs b/crates/ui-egui/src/perspective_crop_ui.rs index c44b54dc4a..3c61bcaf30 100644 --- a/crates/ui-egui/src/perspective_crop_ui.rs +++ b/crates/ui-egui/src/perspective_crop_ui.rs @@ -157,13 +157,15 @@ fn drag_to(app: &mut PhotocraftApp, p: [f64; 2]) { /// `image.perspectiveCrop`'s size params from W, H and the resolution (the Crop tool's fields): /// lengths in physical units convert at the typed resolution, else the document's. -fn size_params(app: &PhotocraftApp, p: &mut Value) { +pub(crate) fn size_params(app: &PhotocraftApp, p: &mut Value) { let o = &app.ui.tool_options; let res = crate::crop_size::resolution_ppi(o); let dpi = res.unwrap_or_else(|| app.session.active().map_or(72.0, |st| f64::from(st.doc.resolution_dpi))); + // Points and picas per Preferences › Point/Pica Size. + let pt_per_in = app.session.prefs().units_and_rulers.point_size.per_inch(); let px = |text: &str| { let (v, u) = crate::crop_size::parse_length(text, Unit::Pixels)?; - let px = u.to_px(v, dpi, 0.0, 72.0).round(); + let px = u.to_px(v, dpi, 0.0, pt_per_in).round(); (px.is_finite() && px >= 1.0).then_some(px) }; if let Some(w) = px(&o.crop_width) {