Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Perspective Crop: W and H follow the Point/Pica Size preference (#7135)

David Mann2f038c5eb234
diff --git a/crates/ui-egui/src/crop_size.rs b/crates/ui-egui/src/crop_size.rs
index b30cdd8c4..d450ff06a 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 c44b54dc4..3c61bcaf3 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) {