PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
M7: Cut, Redact, Create Link and Recognize Text in the picture menu; keep the menu open (#1621)
philip-tam7aac682ef889
diff --git a/ATTRIBUTION.toml b/ATTRIBUTION.tomlindex bee3f01af..12d3e7820 100644--- a/ATTRIBUTION.toml+++ b/ATTRIBUTION.toml@@ -7,7 +7,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Greek UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "66aecafe992d9f1bd6cbfd2152b2aa17af77e6fed93aca5042b5756fae564cb9"+sha256 = "82a6d3b48da75024afd3261e2c2a30d2f8b45da5448b6018ad5b35d489d2c7bb"# ATTRIBUTION.toml: one entry per asset (AGENTS.md §1). The source of truth for provenance and licences.# ATTRIBUTION.md is generated from this file: `cargo xtask assets --write`. Checked by `cargo xtask assets` (part of `xtask ci`).@@ -30,7 +30,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Simplified Chinese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "407bef213cf599815142fa917e6e0126270979796f9e7a9819c1884d761a32e6"+sha256 = "1d8134aad27f74186b0df2f6257ee51b0955a69597de5ca86cf4013ab98f7da9"[[asset]]path = "crates/ui-egui/src/i18n/zh-hant.tsv"@@ -41,7 +41,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Traditional Chinese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "052d78606b5a03776e7bbfc277ed1ac08622b91b882e64c039c0283adfb5fb75"+sha256 = "1a5a956aabe5746a0768497cb4e6568622a5ab70b8d429f745c33dda977a8fca"[[asset]]path = "crates/ui-egui/src/i18n/cs.tsv"@@ -52,7 +52,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Czech UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "a4e587d787cb49c8e553b136e83441f7132569011dd5e8aedcd9bab5de5f0ba2"+sha256 = "5a29fe0c99e7116a2aab2387be553bb95b59ce450afc2546a04949a68dcf4f31"[[asset]]path = "crates/ui-egui/src/i18n/pt-br.tsv"@@ -63,7 +63,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Brazilian Portuguese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "3101724a510ee4b91cb3ebd44164061b789ed74dc9142c13fd316efd11353ae4"+sha256 = "09c3f837fefbe0774e9b21a40d74b93ab3671bb143f141e8cb212c92d91e4733"[[asset]]path = "crates/ui-egui/src/i18n/es.tsv"@@ -74,7 +74,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Spanish UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "0b349ab77ac8679cce6c13abb7dafbb2a8f19eb523d09573255e28d6e919ec05"+sha256 = "31ae2ecf486e132ad085b4ec415416263ee1e5e7461ec4dd4e778bf628fefcf9"[[asset]]path = "crates/ui-egui/src/i18n/fr.tsv"@@ -85,7 +85,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "French UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "3548fa14b5eb68370a81e9cdf17156f40a5b7a10a4d9771b11f9a88cb63b6f3a"+sha256 = "fb7f392472e9ffbd7f8492d52b14c8e6bdd28655415869eefbcd1af43178d4c2"[[asset]]path = "crates/ui-egui/src/i18n/de.tsv"@@ -96,7 +96,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "German UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "3441b5c753be2e317aed4bb0e69fdbcd995cc2069977363c55f82b791064043c"+sha256 = "85576c18721874113d92c8ee477e5a92d43d898f042ec5104bc3ee18336ef2a7"[[asset]]path = "crates/ui-egui/src/i18n/te.tsv"@@ -107,7 +107,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Telugu UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "ddb7d9af7883e417fef04e24acef23fea1736c38d362303ab951056ccb3e4473"+sha256 = "1f65ce25add0ffd6dbb9ea25e1bac1f78604265547b1995a7a43e573e303fc7b"[[asset]]path = "crates/ui-egui/src/i18n/it.tsv"@@ -118,7 +118,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Italian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "8ce577e9405d987b0b78b89c43f9e02f5c03b300c75a22a6cb1f53d84352d1b3"+sha256 = "c1a5a6d120bec8eaa8e60a5eb7f805aaf846f8ae0facf04a5a61da769dc6672c"[[asset]]path = "crates/ui-egui/src/i18n/pl.tsv"@@ -129,7 +129,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Polish UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "bbbce91dc8b5ceccaa7c224560a96cf6ba473dc8774cd3a705ac766e8142c203"+sha256 = "06cfe4f2dcdf970aa4269658930885c2536dfc3a1b5391fccc626232fd01b3de"[[asset]]path = "crates/ui-egui/src/i18n/ru.tsv"@@ -140,7 +140,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Russian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "434d3c5d0cde05d62f93ee136bc1cd6e1051e316af354f235a5479fcf23c4c42"+sha256 = "ca6e03bf5a37b39c7e7870e2c52f9c9fd88ec13324296926f0c2853675b155c3"[[asset]]path = "crates/ui-egui/src/i18n/hu.tsv"@@ -151,7 +151,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Hungarian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "267701ae34f1f0333846d2adcfdd01e2cfd2aa78a45b57cad417ee7b91adcef9"+sha256 = "b0dcd01ae69d702740e6732b77b7ae8d192c4f789be9d3c5128bfa745ce07527"[[asset]]path = "crates/ui-egui/src/i18n/bg.tsv"@@ -162,7 +162,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Bulgarian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "d38888203419c3fd635a0eb8a38cb6253ee47f3e3b90b388e545661f1f3cdc65"+sha256 = "75b42fcb55a4518ba2057a2dfe29cd4b3718c26a0e1a3c83101a19201d9542ce"[[asset]]path = "crates/ui-egui/src/i18n/kk.tsv"@@ -173,7 +173,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Kazakh UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "c714b39eafc7a292a4f592255a9f1a82522921c52775ef267e283099aeae7697"+sha256 = "c9986f1b5a19f8fa3b431229e56bae73715d138e6507b0b7c314483029109585"[[asset]]path = "crates/ui-egui/src/i18n/ja.tsv"@@ -184,7 +184,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Japanese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "ddde7f7703c2b906256cb5f58bc9b841dd6351deee6cd24d35349c6e548181de"+sha256 = "ef3156aab103af5bd99efac444a3e085ef50f9a5786c8c4f34aa5f384d2f028e"[[asset]]path = "crates/ui-egui/src/i18n/uk.tsv"@@ -195,7 +195,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Ukrainian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "b7bbccc4562d55cb71276ee408fe4106172c03874b4f7c106ede65bcbcd40082"+sha256 = "13ee22f546e669cbde325343c3c1474c89932bc49342f02da3059047865007f0"[[asset]]path = "crates/ui-egui/src/i18n/ar.tsv"@@ -206,7 +206,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Arabic UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "89875f19640a31f0e577d68f37a7652ebf28a2a0b9d646a9be2ee6d933839eb2"+sha256 = "79b7ecd15533611107700c32cf9faf6ce1041c41244e5fe82c783d964d0492f7"[[asset]]path = "crates/ui-egui/src/i18n/tr.tsv"@@ -217,7 +217,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Turkish UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "9aaa392d37a93f93e354082c8b677d558df5df1d92b46951ec7a587f8fc93776"+sha256 = "116784d4457a2cff2018e2652cc537a924f365012409547cbbaac3409c315c22"[[asset]]path = "crates/ui-egui/src/i18n/lt.tsv"@@ -228,7 +228,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Lithuanian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "6568a24e04e407c75840d8119e55411431f4a6f774b3565ff9ee7d7c79a75e00"+sha256 = "581a77647ccd0f002decdb430bcda1a7dfa90d3d2948fe6a12b33251e5edd318"[[asset]]@@ -240,7 +240,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Vietnamese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "78c0b206ca69f255d80abd18f32a8eeaac397660928256cfed568d897cd9554c"+sha256 = "949a3e933149eaf4fad17fb6711ec38b134858d0c434bdf1c38125bf7ead9855"[[asset]]path = "assets/icons/accessibility.svg"@@ -3363,7 +3363,7 @@ licence = "MIT OR Apache-2.0"licence_file = "LICENSE-MIT"kind = "translation"usage = "Slovene UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"-sha256 = "68722b7edd99436f46e786536ca11f03ce4131748e720f460bae9a621252ebcd"+sha256 = "5ca7e04c805f8ae8bee1b81f6c5e6263dddd1673ef003ec5c90c1b87b4bfd9ba"[[asset]]path = "vendor/vello_common/assets/probe.png"diff --git a/ROADMAP.md b/ROADMAP.mdindex b23c200bf..0a54ad02a 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -156,6 +156,7 @@ Ranked; detail and the full milestone table in [docs/roadmap.md](docs/roadmap.md| 8 | 1.0 polish: performance, right-to-left, missing languages, keyboard-only (M14) | 55–95 |## Progress log+- **2026-10-12 (M7, picture right-click menu):** The Edit text & images menu of a picture gains Cut Image, Redact Image (a redaction mark over the picture, applied from Redact a PDF), Create Link… and Recognize Text… (for that page), in all 21 catalogs. The menu was drawn only while the pointer was over the picture, so its items outside the picture (most of a logo's menu, and Delete below a page) could not be clicked; an open menu now stays drawn. Still missing from Acrobat's menu: Arrange (bring to front, send backward), Remove crop, Draw freehand and Edit image using… (opening an external editor).- **2026-10-12 (M2, inline-image boundaries):** Unfiltered inline images with known sample layouts keep pixel bytes that look like the `EI` terminator when content is rewritten. Regression tests cover row padding, colour-space and parameter aliases, masks and malformed sizes; classic and packed saved PDFs retain the pixels in independent readers and renderers. Filtered and resource-defined layouts retain the existing tolerant heuristic. Estimates unchanged.- **2026-10-12 (M3, drawing markups):** While a comment is being drawn, the pointer in a band along any edge of the view (or just past it) scrolls the view up, down, left or right, so points beyond what is shown can be reached. A polygon, cloud or run of connected lines takes back its last point with Backspace, Delete or Undo (the first point's removal cancels it). Edge scrolling has unit tests of its maths only; it has not been exercised end to end in the app by an automated test.- **2026-10-12 (gap 6, #1319, #1305, #1324):** Editing an XFA form keeps a radio item's stored text when it contains a space, so a later layout still selects it. Replace Pages on a split selection replaces those pages and leaves the gap; editing the dialog range still replaces the span. Marking a figure decorative rewrites only that figure's content stream, so a header, added text and unknown stream entries stay. Estimates unchanged.diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 9be5842b2..c2e6e8201 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -3699,8 +3699,17 @@ pub fn document_area(app: &mut PdfCraftApp, index: usize, ui: &mut egui::Ui) {match image_action {Some(crate::edit_text_ui::ImageAction::Replace(page, index)) => app.replace_page_image_dialog(page, index),Some(crate::edit_text_ui::ImageAction::Save(page, index)) => app.save_page_image(page, index),- Some(crate::edit_text_ui::ImageAction::Copy(page, index)) => app.copy_page_image(page, index),+ Some(crate::edit_text_ui::ImageAction::Copy(page, index)) => {+ app.copy_page_image(page, index);+ }Some(crate::edit_text_ui::ImageAction::CopyFile(page, index)) => app.copy_page_image_file(page, index),+ Some(crate::edit_text_ui::ImageAction::Cut(page, image)) => {+ app.views[index].image_selection = None;+ app.cut_page_image(page, image);+ }+ Some(crate::edit_text_ui::ImageAction::Redact(page, index)) => app.redact_page_image(page, index),+ Some(crate::edit_text_ui::ImageAction::Link(page, index)) => app.link_page_image(page, index),+ Some(crate::edit_text_ui::ImageAction::Recognize(page)) => app.recognize_text_on_page(page),None => {}}if let Some(why) = refused {diff --git a/crates/ui-egui/src/content_ui.rs b/crates/ui-egui/src/content_ui.rsindex a2b62e45a..52f8e3cb4 100644--- a/crates/ui-egui/src/content_ui.rs+++ b/crates/ui-egui/src/content_ui.rs@@ -688,12 +688,12 @@ impl crate::PdfCraftApp {}/// Copy Image: image `index` on `page`, at its own resolution, to the clipboard.- pub(crate) fn copy_page_image(&mut self, page: usize, index: usize) {- let Some((_, id)) = self.active_ids() else { return };+ pub(crate) fn copy_page_image(&mut self, page: usize, index: usize) -> bool {+ let Some((_, id)) = self.active_ids() else { return false };if !self.may_copy(id) {- return;+ return false;}- let Some(pixels) = self.session.get(id).map(|d| d.page_image_rgba(page, index)) else { return };+ let Some(pixels) = self.session.get(id).map(|d| d.page_image_rgba(page, index)) else { return false };let copied = pixels.and_then(|(w, h, rgba)| {#[cfg(not(target_arch = "wasm32"))]if self.system_clipboard {@@ -708,11 +708,57 @@ impl crate::PdfCraftApp {Ok((w, h))});match copied {- Ok((w, h)) => self.notify_fmt("The image has been copied ({w} × {h} pixels)", &[("w", &w.to_string()), ("h", &h.to_string())]),- Err(e) => self.notify_fmt("Couldn't copy the image: {e}", &[("e", &e)]),+ Ok((w, h)) => {+ self.notify_fmt("The image has been copied ({w} × {h} pixels)", &[("w", &w.to_string()), ("h", &h.to_string())]);+ true+ }+ Err(e) => {+ self.notify_fmt("Couldn't copy the image: {e}", &[("e", &e)]);+ false+ }+ }+ }++ /// The picture's visible box on its page, in user space.+ fn page_image_box(&self, page: usize, index: usize) -> Option<[f64; 4]> {+ let (_, id) = self.active_ids()?;+ let image = self.session.get(id)?.page_images(page).into_iter().nth(index)?;+ Some(image.visible_rect.unwrap_or(image.rect))+ }++ /// Cut: copy the picture, and only when that worked take it off the page (one undo step).+ pub(crate) fn cut_page_image(&mut self, page: usize, index: usize) {+ if self.copy_page_image(page, index) {+ self.apply_edit(Edit::EditPageImage { page, index, change: pdfcraft_engine::ImageEdit::Delete });}}+ /// Redact image: a redaction mark over the whole picture. It is applied, like any mark, from+ /// Redact a PDF.+ pub(crate) fn redact_page_image(&mut self, page: usize, index: usize) {+ let Some(rect) = self.page_image_box(page, index) else { return };+ let author = self.comment_prefs.author.clone();+ let mark = self.redact_prefs.mark(page, vec![pdfcraft_engine::rect_quad(rect)], &author);+ if self.apply_edit(mark) {+ self.notify_tr("The image is marked for redaction. Apply it with Redact a PDF");+ }+ }++ /// Create link: the link properties for a new link over the picture.+ pub(crate) fn link_page_image(&mut self, page: usize, index: usize) {+ if let Some(rect) = self.page_image_box(page, index) {+ self.open_link_props(page, Some(rect), None);+ }+ }++ /// Recognize text: the Recognize Text dialog, set to this page.+ pub fn recognize_text_on_page(&mut self, page: usize) {+ self.ocr_draft.pages = crate::ocr_ui::OcrPages::Range;+ self.ocr_draft.from = page + 1;+ self.ocr_draft.to = page + 1;+ self.dialog = Some(crate::Dialog::RecognizeText);+ }+/// Click an image field: pick a picture for it.pub fn choose_field_image(&mut self, name: &str) {#[cfg(not(target_arch = "wasm32"))]diff --git a/crates/ui-egui/src/edit_text_ui.rs b/crates/ui-egui/src/edit_text_ui.rsindex d06cb7c8f..3c0c18a5e 100644--- a/crates/ui-egui/src/edit_text_ui.rs+++ b/crates/ui-egui/src/edit_text_ui.rs@@ -575,6 +575,14 @@ pub(crate) enum ImageAction {Save(usize, usize),Copy(usize, usize),CopyFile(usize, usize),+ /// Copy the picture, then remove it from the page.+ Cut(usize, usize),+ /// Mark the picture for redaction (applied later from Redact a PDF).+ Redact(usize, usize),+ /// Create a link over the picture.+ Link(usize, usize),+ /// Open Recognize Text for the picture's page.+ Recognize(usize),}fn user_box(xf: &PageXform, info: &DocInfo, page: usize, r: Rect) -> [f64; 4] {@@ -759,6 +767,22 @@ pub(crate) fn image_input(if !allow_interaction {return false;}+ // An open menu stays drawn wherever the pointer is: most of its items lie outside the picture+ // (a logo is smaller than its menu), and a menu that is not drawn for a frame cannot be clicked.+ // Only a menu opened by a right-click on the picture: one opened over text or empty page while+ // a picture stays selected is the page's own menu.+ let menu_key = resp.id.with("image-menu");+ if resp.secondary_clicked() {+ ui.ctx().data_mut(|d| d.insert_temp(menu_key, false));+ }+ let mut menu_drawn = false;+ if let Some(sel) = selected+ && resp.context_menu_opened()+ && ui.ctx().data(|d| d.get_temp::<bool>(menu_key)).unwrap_or(false)+ {+ resp.context_menu(|ui| image_menu(ui, page, sel, images, view, action));+ menu_drawn = true;+ }let Some(p) = hover_pos.filter(|p| xf.rect.contains(*p)) else { return false };let Some(hit) = boxes.iter().enumerate().rposition(|(i, b)| b.contains(p) && image_contains(i, p)) else { return false };if selected != Some(hit) {@@ -775,65 +799,95 @@ pub(crate) fn image_input(if resp.clicked() || resp.secondary_clicked() {view.image_selection = Some(ImageSelection { page, index: hit, drag: None, crop: None });}- if selected == Some(hit) {- resp.context_menu(|ui| {- use pdfcraft_engine::ImageEdit as E;- let items: [(&str, Option<E>); 4] = [- (tl!("Rotate Clockwise"), Some(E::Rotate(1))),- (tl!("Rotate Counterclockwise"), Some(E::Rotate(3))),- (tl!("Flip Horizontal"), Some(E::Flip { horizontal: true })),- (tl!("Flip Vertical"), Some(E::Flip { horizontal: false })),- ];- for (label, change) in items {- if ui.button(label).clicked() {- view.pending_edit = change.map(|c| Edit::EditPageImage { page, index: hit, change: c });- ui.close();- }- }- // Crop: the handles trim instead of resizing until Done.- if ui.button(tl!("Crop Image")).clicked() {- if let (Some(s), Some(im)) = (view.image_selection.as_mut(), images.get(hit)) {- s.crop = Some(CropMode::new(im.visible_rect.unwrap_or(im.rect)));- }- ui.close();- }- let cropped =- images.get(hit).is_some_and(|im| im.visible_rect.is_some_and(|v| v.iter().zip(im.rect.iter()).any(|(a, b)| (a - b).abs() > 0.01)));- if ui.add_enabled(cropped, egui::Button::new(tl!("Remove Crop"))).clicked() {- if let Some(im) = images.get(hit) {- view.pending_edit = Some(Edit::EditPageImage { page, index: hit, change: E::Crop(im.rect) });- }- ui.close();- }- let raster = images.get(hit).is_some_and(|image| !image.is_form);- if ui.add_enabled(raster, egui::Button::new(tl!("Replace Image…"))).clicked() {- *action = Some(ImageAction::Replace(page, hit));- ui.close();- }- if ui.add_enabled(raster, egui::Button::new(tl!("Save Image As…"))).clicked() {- *action = Some(ImageAction::Save(page, hit));- ui.close();- }- // Copying also finds the picture inside grouped Form artwork.- if ui.button(tl!("Copy Image")).clicked() {- *action = Some(ImageAction::Copy(page, hit));- ui.close();- }- if ui.button(tl!("Copy Image in Original Format")).clicked() {- *action = Some(ImageAction::CopyFile(page, hit));- ui.close();- }- ui.separator();- if ui.button(tl!("Delete")).clicked() {- view.image_selection = None;- view.pending_edit = Some(Edit::EditPageImage { page, index: hit, change: E::Delete });- ui.close();- }- });+ if resp.secondary_clicked() {+ ui.ctx().data_mut(|d| d.insert_temp(menu_key, true));+ }+ if selected == Some(hit) && !menu_drawn {+ resp.context_menu(|ui| image_menu(ui, page, hit, images, view, action));}true}+/// The right-click menu of the picture `hit` (its rotate, flip, replace, copy, cut, redact, link,+/// recognize and delete items).+fn image_menu(+ ui: &mut egui::Ui,+ page: usize,+ hit: usize,+ images: &[pdfcraft_engine::PageImage],+ view: &mut DocView,+ action: &mut Option<ImageAction>,+) {+ use pdfcraft_engine::ImageEdit as E;+ let items: [(&str, Option<E>); 4] = [+ (tl!("Rotate Clockwise"), Some(E::Rotate(1))),+ (tl!("Rotate Counterclockwise"), Some(E::Rotate(3))),+ (tl!("Flip Horizontal"), Some(E::Flip { horizontal: true })),+ (tl!("Flip Vertical"), Some(E::Flip { horizontal: false })),+ ];+ for (label, change) in items {+ if ui.button(label).clicked() {+ view.pending_edit = change.map(|c| Edit::EditPageImage { page, index: hit, change: c });+ ui.close();+ }+ }+ // Crop: the handles trim instead of resizing until Done.+ if ui.button(tl!("Crop Image")).clicked() {+ if let (Some(s), Some(im)) = (view.image_selection.as_mut(), images.get(hit)) {+ s.crop = Some(CropMode::new(im.visible_rect.unwrap_or(im.rect)));+ }+ ui.close();+ }+ let cropped = images.get(hit).is_some_and(|im| im.visible_rect.is_some_and(|v| v.iter().zip(im.rect.iter()).any(|(a, b)| (a - b).abs() > 0.01)));+ if ui.add_enabled(cropped, egui::Button::new(tl!("Remove Crop"))).clicked() {+ if let Some(im) = images.get(hit) {+ view.pending_edit = Some(Edit::EditPageImage { page, index: hit, change: E::Crop(im.rect) });+ }+ ui.close();+ }+ let raster = images.get(hit).is_some_and(|image| !image.is_form);+ if ui.add_enabled(raster, egui::Button::new(tl!("Replace Image…"))).clicked() {+ *action = Some(ImageAction::Replace(page, hit));+ ui.close();+ }+ if ui.add_enabled(raster, egui::Button::new(tl!("Save Image As…"))).clicked() {+ *action = Some(ImageAction::Save(page, hit));+ ui.close();+ }+ // Cutting and copying also find the picture inside grouped Form artwork.+ if ui.button(tl!("Cut Image")).clicked() {+ *action = Some(ImageAction::Cut(page, hit));+ ui.close();+ }+ if ui.button(tl!("Copy Image")).clicked() {+ *action = Some(ImageAction::Copy(page, hit));+ ui.close();+ }+ if ui.button(tl!("Copy Image in Original Format")).clicked() {+ *action = Some(ImageAction::CopyFile(page, hit));+ ui.close();+ }+ ui.separator();+ if ui.button(tl!("Redact Image")).clicked() {+ *action = Some(ImageAction::Redact(page, hit));+ ui.close();+ }+ if ui.button(tl!("Create Link…")).clicked() {+ *action = Some(ImageAction::Link(page, hit));+ ui.close();+ }+ if ui.button(tl!("Recognize Text…")).clicked() {+ *action = Some(ImageAction::Recognize(page));+ ui.close();+ }+ ui.separator();+ if ui.button(tl!("Delete")).clicked() {+ view.image_selection = None;+ view.pending_edit = Some(Edit::EditPageImage { page, index: hit, change: E::Delete });+ ui.close();+ }+}+/// Open `block` on `page` in the inline editor. The box's geometry and source are read from the/// `lines` handed in, so callers pass the document's current inventory.#[allow(clippy::too_many_arguments)]diff --git a/crates/ui-egui/src/i18n/ar.tsv b/crates/ui-egui/src/i18n/ar.tsvindex d86ab4d66..041a1332a 100644--- a/crates/ui-egui/src/i18n/ar.tsv+++ b/crates/ui-egui/src/i18n/ar.tsv@@ -2378,6 +2378,10 @@ animation effects Off معطّلةThe linked PDF opened, but its named destination was not applied. فُتح ملف PDF المرتبط، لكن لم تُطبَّق وجهته المسماة.The linked PDF opened, but its page destination was out of range. فُتح ملف PDF المرتبط، لكن وجهة الصفحة خارج النطاق.Local cross-PDF links require the desktop app تتطلب الروابط المحلية بين ملفات PDF تطبيق سطح المكتب+ Cut Image قص الصورة+ Redact Image حجب الصورة+ Create Link… إنشاء رابط…+ Recognize Text… التعرف على النص…Minimize تصغيرMaximize تكبيرRestore استعادةdiff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsvindex 398506098..5334c39e9 100644--- a/crates/ui-egui/src/i18n/bg.tsv+++ b/crates/ui-egui/src/i18n/bg.tsv@@ -2320,6 +2320,10 @@ animation effects Off ИзключениThe linked PDF opened, but its named destination was not applied. Свързаният PDF се отвори, но именуваната му цел не беше приложена.The linked PDF opened, but its page destination was out of range. Свързаният PDF се отвори, но целевата му страница е извън обхвата.Local cross-PDF links require the desktop app Локалните връзки между PDF файлове изискват настолното приложение+ Cut Image Изрежи изображението+ Redact Image Заличи изображението+ Create Link… Създай връзка…+ Recognize Text… Разпознаване на текст…Minimize МинимизиранеMaximize МаксимизиранеRestore Възстановяванеdiff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex bd18db1d9..9e62f7f34 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -2431,6 +2431,10 @@ animation effects Off VypnutoThe linked PDF opened, but its named destination was not applied. Odkazovaný PDF se otevřel, ale jeho pojmenovaný cíl nebyl použit.The linked PDF opened, but its page destination was out of range. Odkazovaný PDF se otevřel, ale cílová stránka je mimo rozsah.Local cross-PDF links require the desktop app Místní odkazy mezi soubory PDF vyžadují desktopovou aplikaci+ Cut Image Vyjmout obrázek+ Redact Image Začernit obrázek+ Create Link… Vytvořit odkaz…+ Recognize Text… Rozpoznat text…Minimize MinimalizovatMaximize MaximalizovatRestore Obnovitdiff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex eaf011aa6..29439a186 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -2358,6 +2358,10 @@ animation effects Off AusThe linked PDF opened, but its named destination was not applied. Die verknüpfte PDF wurde geöffnet, aber ihr benanntes Ziel wurde nicht angewendet.The linked PDF opened, but its page destination was out of range. Die verknüpfte PDF wurde geöffnet, aber ihr Seitenziel liegt außerhalb des Bereichs.Local cross-PDF links require the desktop app Lokale Verknüpfungen zwischen PDFs erfordern die Desktop-App+ Cut Image Bild ausschneiden+ Redact Image Bild schwärzen+ Create Link… Link erstellen…+ Recognize Text… Text erkennen…Minimize MinimierenMaximize MaximierenRestore Wiederherstellendiff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsvindex 511582357..36a1d9909 100644--- a/crates/ui-egui/src/i18n/el.tsv+++ b/crates/ui-egui/src/i18n/el.tsv@@ -2367,6 +2367,10 @@ animation effects Off ΑνενεργάLocal cross-PDF links require the desktop app Οι τοπικοί σύνδεσμοι μεταξύ PDF απαιτούν την εφαρμογή υπολογιστήThe existing action will be preserved. Η υπάρχουσα ενέργεια θα διατηρηθεί.This form's scripts are turned off because one ran too long. Reopen the document to run them again. Τα σενάρια αυτής της φόρμας είναι απενεργοποιημένα, επειδή ένα από αυτά εκτελούνταν για πολύ ώρα. Ανοίξτε ξανά το έγγραφο για να εκτελεστούν ξανά.+ Cut Image Αποκοπή εικόνας+ Redact Image Απόκρυψη ευαίσθητου περιεχομένου εικόνας+ Create Link… Δημιουργία συνδέσμου…+ Recognize Text… Αναγνώριση κειμένου…Minimize ΕλαχιστοποίησηMaximize ΜεγιστοποίησηRestore Επαναφοράdiff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex fc8b85013..62cbf95fe 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -2497,6 +2497,10 @@ animation effects Off DesactivadosThe linked PDF opened, but its page destination was out of range. El PDF vinculado se abrió, pero su página de destino está fuera de rango.Local cross-PDF links require the desktop app Los enlaces locales entre PDF requieren la aplicación de escritorioThe existing action will be preserved. Se conservará la acción existente.+ Cut Image Cortar imagen+ Redact Image Censurar imagen+ Create Link… Crear enlace…+ Recognize Text… Reconocer texto…Minimize MinimizarMaximize MaximizarRestore Restaurardiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex c63e4f69c..208f5d2c2 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -2357,6 +2357,10 @@ animation effects Off DésactivésThe linked PDF opened, but its named destination was not applied. Le PDF lié s'est ouvert, mais sa destination nommée n'a pas été appliquée.The linked PDF opened, but its page destination was out of range. Le PDF lié s'est ouvert, mais sa page de destination est hors limites.Local cross-PDF links require the desktop app Les liens locaux entre PDF nécessitent l'application de bureau+ Cut Image Couper l'image+ Redact Image Biffer l'image+ Create Link… Créer un lien…+ Recognize Text… Reconnaître le texte…Minimize RéduireMaximize AgrandirRestore Restaurerdiff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsvindex 416479ae4..fe31b0e7a 100644--- a/crates/ui-egui/src/i18n/hu.tsv+++ b/crates/ui-egui/src/i18n/hu.tsv@@ -2356,6 +2356,10 @@ animation effects Off KiThe linked PDF opened, but its named destination was not applied. A hivatkozott PDF megnyílt, de a nevesített cél nem lett alkalmazva.The linked PDF opened, but its page destination was out of range. A hivatkozott PDF megnyílt, de a céloldal a tartományon kívül esik.Local cross-PDF links require the desktop app A PDF-ek közötti helyi hivatkozásokhoz az asztali alkalmazás szükséges+ Cut Image Kép kivágása+ Redact Image Kép kitakarása+ Create Link… Hivatkozás létrehozása…+ Recognize Text… Szövegfelismerés…Minimize MinimalizálásMaximize MaximalizálásRestore Visszaállításdiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex 2b39ba31e..0cda1c323 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -2366,6 +2366,10 @@ animation effects Off DisattivatiThe linked PDF opened, but its named destination was not applied. Il PDF collegato è stato aperto, ma la sua destinazione con nome non è stata applicata.The linked PDF opened, but its page destination was out of range. Il PDF collegato è stato aperto, ma la pagina di destinazione è fuori intervallo.Local cross-PDF links require the desktop app I collegamenti locali tra PDF richiedono l'app desktop+ Cut Image Taglia immagine+ Redact Image Oscura immagine+ Create Link… Crea collegamento…+ Recognize Text… Riconosci testo…Minimize Riduci a iconaMaximize IngrandisciRestore Ripristinadiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 66d313455..48bcb8f25 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -2357,6 +2357,10 @@ animation effects Off オフThe linked PDF opened, but its named destination was not applied. リンク先の PDF を開きましたが、名前付き移動先は適用されませんでした。The linked PDF opened, but its page destination was out of range. リンク先の PDF を開きましたが、移動先のページが範囲外です。Local cross-PDF links require the desktop app PDF 間のローカルリンクにはデスクトップアプリが必要です+ Cut Image 画像を切り取り+ Redact Image 画像を墨消し+ Create Link… リンクを作成…+ Recognize Text… テキストを認識…Minimize 最小化Maximize 最大化Restore 元のサイズに戻すdiff --git a/crates/ui-egui/src/i18n/kk.tsv b/crates/ui-egui/src/i18n/kk.tsvindex 0807d286a..13a9f6729 100644--- a/crates/ui-egui/src/i18n/kk.tsv+++ b/crates/ui-egui/src/i18n/kk.tsv@@ -2355,6 +2355,10 @@ animation effects Off ӨшіруліThe linked PDF opened, but its named destination was not applied. Байланысты PDF ашылды, бірақ оның аталған мақсаты қолданылмады.The linked PDF opened, but its page destination was out of range. Байланысты PDF ашылды, бірақ оның мақсатты беті ауқымнан тыс.Local cross-PDF links require the desktop app PDF файлдары арасындағы жергілікті сілтемелер үшін жұмыс үстелі қолданбасы қажет+ Cut Image Суретті кесу+ Redact Image Суретті жасыру+ Create Link… Сілтеме жасау…+ Recognize Text… Мәтінді тану…Minimize ЖиюMaximize ЖаюRestore Қалпына келтіруdiff --git a/crates/ui-egui/src/i18n/lt.tsv b/crates/ui-egui/src/i18n/lt.tsvindex 7294ac679..165163d31 100644--- a/crates/ui-egui/src/i18n/lt.tsv+++ b/crates/ui-egui/src/i18n/lt.tsv@@ -2601,6 +2601,10 @@ key Esc Esckey Home Homekey End Endkey Space Tarpas+ Cut Image Iškirpti paveikslėlį+ Redact Image Pašalinti konfidencialią informaciją iš paveikslėlio+ Create Link… Kurti saitą…+ Recognize Text… Atpažinti tekstą…Minimize SumažintiMaximize IšdidintiRestore Atkurtidiff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsvindex 07d1afcd0..5cc409360 100644--- a/crates/ui-egui/src/i18n/pl.tsv+++ b/crates/ui-egui/src/i18n/pl.tsv@@ -2337,6 +2337,10 @@ animation effects Off WyłączoneLocal cross-PDF links require the desktop app Lokalne łącza między plikami PDF wymagają aplikacji komputerowejThe existing action will be preserved. Istniejąca akcja zostanie zachowana.This form's scripts are turned off because one ran too long. Reopen the document to run them again. Skrypty tego formularza są wyłączone, ponieważ jeden z nich działał zbyt długo. Otwórz dokument ponownie, aby znów je uruchomić.+ Cut Image Wytnij obraz+ Redact Image Utajnij obraz+ Create Link… Utwórz łącze…+ Recognize Text… Rozpoznaj tekst…Minimize ZminimalizujMaximize ZmaksymalizujRestore Przywróćdiff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex 6f231083e..8756fa94e 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -2371,6 +2371,10 @@ animation effects Off DesativadosThe linked PDF opened, but its named destination was not applied. O PDF vinculado foi aberto, mas seu destino nomeado não foi aplicado.The linked PDF opened, but its page destination was out of range. O PDF vinculado foi aberto, mas sua página de destino está fora do intervalo.Local cross-PDF links require the desktop app Links locais entre PDFs exigem o aplicativo para desktop+ Cut Image Recortar imagem+ Redact Image Ocultar dados da imagem+ Create Link… Criar link…+ Recognize Text… Reconhecer texto…Minimize MinimizarMaximize MaximizarRestore Restaurardiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex e829baa60..d9fe1a98b 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -2270,6 +2270,10 @@ animation effects Off ВыклThe linked PDF opened, but its named destination was not applied. Связанный PDF открыт, но его именованное назначение не применено.The linked PDF opened, but its page destination was out of range. Связанный PDF открыт, но страница назначения вне допустимого диапазона.Local cross-PDF links require the desktop app Локальные ссылки между PDF работают только в настольном приложении+ Cut Image Вырезать изображение+ Redact Image Скрыть изображение+ Create Link… Создать ссылку…+ Recognize Text… Распознать текст…Minimize СвернутьMaximize РазвернутьRestore Восстановитьdiff --git a/crates/ui-egui/src/i18n/sl.tsv b/crates/ui-egui/src/i18n/sl.tsvindex 96c41876e..d59de3df8 100644--- a/crates/ui-egui/src/i18n/sl.tsv+++ b/crates/ui-egui/src/i18n/sl.tsv@@ -2362,6 +2362,10 @@ animation effects Off IzklopljeniThe linked PDF opened, but its named destination was not applied. Povezani PDF se je odprl, vendar njegov poimenovani cilj ni bil uporabljen.The linked PDF opened, but its page destination was out of range. Povezani PDF se je odprl, vendar je ciljna stran zunaj obsega.Local cross-PDF links require the desktop app Lokalne povezave med PDF-ji zahtevajo namizno aplikacijo+ Cut Image Izreži sliko+ Redact Image Počrni sliko+ Create Link… Ustvari povezavo…+ Recognize Text… Prepoznaj besedilo…Minimize PomanjšajMaximize PovečajRestore Obnovidiff --git a/crates/ui-egui/src/i18n/te.tsv b/crates/ui-egui/src/i18n/te.tsvindex a7b63f80f..ea10d7991 100644--- a/crates/ui-egui/src/i18n/te.tsv+++ b/crates/ui-egui/src/i18n/te.tsv@@ -2270,6 +2270,10 @@ animation effects Off ఆఫ్Local cross-PDF links require the desktop app PDFల మధ్య స్థానిక లింక్లకు డెస్క్టాప్ యాప్ అవసరంThe existing action will be preserved. ఉన్న చర్య అలాగే ఉంచబడుతుంది.This form's scripts are turned off because one ran too long. Reopen the document to run them again. ఒక స్క్రిప్ట్ చాలా సేపు నడిచినందున ఈ ఫారమ్ స్క్రిప్ట్లు ఆపివేయబడ్డాయి. వాటిని మళ్లీ నడపడానికి పత్రాన్ని మళ్లీ తెరవండి.+ Cut Image చిత్రాన్ని కత్తిరించు+ Redact Image చిత్రాన్ని రెడాక్ట్ చేయి+ Create Link… లింక్ సృష్టించు…+ Recognize Text… టెక్స్ట్ను గుర్తించు…Minimize కనిష్ఠీకరించుMaximize గరిష్ఠీకరించుRestore పునరుద్ధరించుdiff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsvindex 35355b935..31fce37c8 100644--- a/crates/ui-egui/src/i18n/tr.tsv+++ b/crates/ui-egui/src/i18n/tr.tsv@@ -2353,6 +2353,10 @@ animation effects Off KapalıThe linked PDF opened, but its named destination was not applied. Bağlantılı PDF açıldı, ancak adlandırılmış hedefi uygulanmadı.The linked PDF opened, but its page destination was out of range. Bağlantılı PDF açıldı, ancak sayfa hedefi aralık dışında.Local cross-PDF links require the desktop app PDF'ler arası yerel bağlantılar masaüstü uygulamasını gerektirir+ Cut Image Resmi Kes+ Redact Image Resmi karart+ Create Link… Bağlantı oluştur…+ Recognize Text… Metni Tanı…Minimize KüçültMaximize BüyütRestore Geri yüklediff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex 6e079a938..db6e7b0ff 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -2379,6 +2379,10 @@ animation effects Off ВимкненоThe linked PDF opened, but its named destination was not applied. Пов’язаний PDF відкрито, але його іменоване призначення не застосовано.The linked PDF opened, but its page destination was out of range. Пов’язаний PDF відкрито, але сторінка призначення поза межами діапазону.Local cross-PDF links require the desktop app Локальні посилання між PDF працюють лише в настільному застосунку+ Cut Image Вирізати зображення+ Redact Image Вилучити вміст зображення+ Create Link… Створити посилання…+ Recognize Text… Розпізнати текст…Minimize ЗгорнутиMaximize РозгорнутиRestore Відновитиdiff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsvindex 1cc3b3e63..d35f95151 100644--- a/crates/ui-egui/src/i18n/vi.tsv+++ b/crates/ui-egui/src/i18n/vi.tsv@@ -2609,3 +2609,7 @@ key Space SpaceFind untagged content Tìm nội dung chưa được gắn thẻNo untagged content was found. Không tìm thấy nội dung nào chưa được gắn thẻ.Found {n} untagged content problems. Đã tìm thấy {n} vấn đề về nội dung chưa được gắn thẻ.+ Cut Image Cắt hình ảnh+ Redact Image Xóa nội dung nhạy cảm của hình ảnh+ Create Link… Tạo liên kết…+ Recognize Text… Nhận dạng văn bản…diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex c1b438ada..72b0cd30a 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -2321,6 +2321,10 @@ animation effects Off 关The linked PDF opened, but its named destination was not applied. 已打开链接的 PDF,但未应用其命名目标。The linked PDF opened, but its page destination was out of range. 已打开链接的 PDF,但其页面目标超出范围。Local cross-PDF links require the desktop app PDF 之间的本地链接需要桌面应用+ Cut Image 剪切图像+ Redact Image 密文图像+ Create Link… 创建链接…+ Recognize Text… 识别文本…Minimize 最小化Maximize 最大化Restore 还原diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 6752ffdca..668952554 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -2233,6 +2233,10 @@ animation effects Off 關The linked PDF opened, but its page destination was out of range. 已開啟連結的 PDF,但其頁面目的地超出範圍。Local cross-PDF links require the desktop app PDF 之間的本機連結需要桌面應用程式The existing action will be preserved. 將保留現有動作。+ Cut Image 剪下圖片+ Redact Image 遮蔽圖片+ Create Link… 建立連結…+ Recognize Text… 辨識文字…Minimize 最小化Maximize 最大化Restore 還原diff --git a/crates/ui-egui/tests/viewer.rs b/crates/ui-egui/tests/viewer.rsindex 06e22fe3b..077553c71 100644--- a/crates/ui-egui/tests/viewer.rs+++ b/crates/ui-egui/tests/viewer.rs@@ -1297,12 +1297,17 @@ fn the_scroll_speed_preference_scales_mouse_wheel_notches() {/// A 40 × 30 picture (one red corner) and a harness showing a PDF of it.fn picture_harness() -> (image::RgbaImage, Harness<'static, PdfCraftApp>) {+ picture_harness_sized(egui::vec2(1400.0, 900.0))+}++/// [`picture_harness`] in a window of this size.+fn picture_harness_sized(size: egui::Vec2) -> (image::RgbaImage, Harness<'static, PdfCraftApp>) {let mut px = image::RgbaImage::from_pixel(40, 30, image::Rgba([10, 200, 30, 255]));px.put_pixel(0, 0, image::Rgba([255, 0, 0, 255]));let mut png = std::io::Cursor::new(Vec::new());image::DynamicImage::ImageRgba8(px.clone()).write_to(&mut png, image::ImageFormat::Png).unwrap();let pdf = pdfcraft_engine::Session::new().create_from_images(&[("p.png".into(), png.into_inner())]).unwrap();- let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {+ let mut h = Harness::builder().with_size(size).build_eframe(move |_cc| {let mut app = PdfCraftApp::new();app.set_option("language", "en").unwrap();app.open_bytes("pic.pdf", None, pdf.to_vec()).unwrap();@@ -1417,6 +1422,91 @@ fn a_picture_inside_form_artwork_under_text_is_selected_and_copied() {let png = image::load_from_memory_with_format(&bytes, image::ImageFormat::Png).unwrap().into_rgba8();assert_eq!(png.into_raw(), vec![255, 0, 0, 255, 0, 0, 255, 255]);}++/// A picture in Edit text & images, right-clicked so its menu is open (in a tall window, so the+/// whole menu is on screen).+fn picture_menu() -> (image::RgbaImage, Harness<'static, PdfCraftApp>) {+ let (px, mut h) = picture_harness_sized(egui::vec2(1400.0, 1500.0));+ h.state_mut().set_option("quick", "edit-text").unwrap();+ h.run_steps(3);+ let i = h.state().active.unwrap();+ let at = h.state().views[i].page_screen_rect(0).expect("on screen").center();+ h.hover_at(at);+ h.run_steps(1);+ h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });+ h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });+ h.run_steps(3);+ (px, h)+}++fn picture_count(h: &Harness<'static, PdfCraftApp>) -> usize {+ let s = h.state();+ s.session.get(s.active_ids().unwrap().1).unwrap().page_images(0).len()+}++#[test]+fn the_picture_menu_cuts_a_picture_to_the_clipboard_and_removes_it() {+ let (px, mut h) = picture_menu();+ assert_eq!(picture_count(&h), 1);+ h.get_by_label("Cut Image").click();+ h.run_steps(3);+ let (w, hgt, rgba) = h.state().last_copied_image.clone().expect("the image was copied first");+ assert_eq!((w, hgt), (40, 30));+ assert_eq!(rgba, px.into_raw());+ assert_eq!(picture_count(&h), 0, "then taken off the page");+ h.state_mut().undo();+ h.run_steps(2);+ assert_eq!(picture_count(&h), 1, "one undo step puts it back");+}++#[test]+fn the_picture_menu_marks_a_picture_for_redaction() {+ let (_, mut h) = picture_menu();+ let marks = |h: &Harness<'static, PdfCraftApp>| {+ let s = h.state();+ s.session.get(s.active_ids().unwrap().1).unwrap().redaction_marks()+ };+ assert_eq!(marks(&h), 0);+ h.get_by_label("Redact Image").click();+ h.run_steps(3);+ assert_eq!(marks(&h), 1);+ assert_eq!(picture_count(&h), 1, "marked, not yet removed: Redact a PDF applies it");+}++#[test]+fn the_picture_menu_opens_link_properties_and_recognize_text_for_the_picture() {+ let (_, mut h) = picture_menu();+ h.get_by_label("Create Link…").click();+ h.run_steps(3);+ assert!(matches!(h.state().dialog, Some(pdfcraft_ui_egui::Dialog::LinkProps)));+ let draft = h.state().link_draft.clone().expect("the link draft");+ assert_eq!(draft.page, 0);+ assert!(draft.rect[2] > draft.rect[0] && draft.rect[3] > draft.rect[1], "over the picture: {:?}", draft.rect);++ let (_, mut h) = picture_menu();+ h.get_by_label("Recognize Text…").click();+ h.run_steps(3);+ assert!(matches!(h.state().dialog, Some(pdfcraft_ui_egui::Dialog::RecognizeText)));+ let d = &h.state().ocr_draft;+ assert_eq!((format!("{:?}", d.pages), d.from, d.to), ("Range".to_string(), 1, 1));+}++/// The menu is longer than the picture is tall, so most items lie outside it: the pointer moving+/// onto them must not close the menu (it used to be drawn only while the pointer was over the+/// picture, so Delete and the items below the page could not be clicked).+#[test]+fn every_item_of_the_picture_menu_can_be_clicked_outside_the_picture() {+ let (_, mut h) = picture_menu();+ let s = h.state();+ let page = s.views[s.active.unwrap()].page_screen_rect(0).expect("on screen");+ let delete = h.get_by_label("Delete").rect();+ assert!(delete.center().y > page.bottom(), "Delete lies below the page: {delete:?} vs {page:?}");+ assert_eq!(picture_count(&h), 1);+ h.get_by_label("Delete").click();+ h.run_steps(3);+ assert_eq!(picture_count(&h), 0);+}+#[test]fn mouse_wheel_scrolls_while_selecting_text() {let mut h = harness();