Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

feat(edit): expose image crop ownership to frontends

FredApps43ad4bf418e3
diff --git a/crates/automation/src/dispatch.rs b/crates/automation/src/dispatch.rs
index 6ce2500e0..d3a60d7ff 100644
--- a/crates/automation/src/dispatch.rs
+++ b/crates/automation/src/dispatch.rs
@@ -386,7 +386,7 @@ impl Automation {
let (u, v) = (info.user_to_view(rect[0] as f32, rect[1] as f32), info.user_to_view(rect[2] as f32, rect[3] as f32));
[r(u[0].min(v[0])), r(u[1].min(v[1])), r(u[0].max(v[0])), r(u[1].max(v[1]))]
});
- json!({ "visible_rect": visible, "image": i + 1, "rect": [r(u[0].min(v[0])), r(u[1].min(v[1])), r(u[0].max(v[0])), r(u[1].max(v[1]))], "pixels": [im.width, im.height], "name": im.name, "kind": if im.is_form { "form" } else { "image" } })
+ json!({ "visible_rect": visible, "has_editor_crop": im.has_editor_crop(), "image": i + 1, "rect": [r(u[0].min(v[0])), r(u[1].min(v[1])), r(u[0].max(v[0])), r(u[1].max(v[1]))], "pixels": [im.width, im.height], "name": im.name, "kind": if im.is_form { "form" } else { "image" } })
})
.collect();
json!({ "page": page + 1, "count": list.len(), "images": list })
diff --git a/crates/edit/src/images.rs b/crates/edit/src/images.rs
index 8310cbf96..3cda30738 100644
--- a/crates/edit/src/images.rs
+++ b/crates/edit/src/images.rs
@@ -52,6 +52,11 @@ pub struct PageImage {
}
impl PageImage {
+ /// Whether an active clip was written by PdfCraft's image crop tool.
+ pub fn has_editor_crop(&self) -> bool {
+ self.clips.iter().any(|clip| clip.app_crop)
+ }
+
/// Whether a user-space point belongs to the placed artwork and every active clip.
pub fn contains(&self, point: [f64; 2]) -> bool {
if !point.iter().all(|v| v.is_finite()) {