Skip to content

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

M12: Compare panel filters text changes and visual differences (gap 21)

Marco Arnulfo9f536c9efd2d
diff --git a/crates/ui-egui/src/compare_ui.rs b/crates/ui-egui/src/compare_ui.rs
index f9c1cbcee..c3f37e502 100644
--- a/crates/ui-egui/src/compare_ui.rs
+++ b/crates/ui-egui/src/compare_ui.rs
@@ -24,6 +24,10 @@ pub struct CompareState {
pub leader: usize,
/// Each half's scroll offset last frame, to tell which one moved.
pub prev_scroll: [egui::Vec2; 2],
+ /// Show: whether the list and the shading include the text changes and the visual
+ /// differences (Acrobat's Filter).
+ pub show_text: bool,
+ pub show_visual: bool,
}
/// Visual differences are shaded orange.
@@ -36,6 +40,7 @@ pub enum PanelAction {
Report,
Clear,
SideBySide(bool),
+ Show { text: bool, visual: bool },
}
pub fn colour(kind: Kind) -> Color32 {
@@ -106,6 +111,14 @@ pub(crate) fn panel(ui: &mut egui::Ui, t: &Tokens, state: &Option<CompareState>,
ui.painter().rect_filled(dot, egui::CornerRadius::same(2), VISUAL);
ui.label(crate::i18n::fmt(tl!("{n} {kind}"), &[("n", &s.visual.len().to_string()), ("kind", tl!("Visual"))]));
});
+ ui.horizontal(|ui| {
+ ui.label(tl!("Show:"));
+ let (mut text, mut visual) = (s.show_text, s.show_visual);
+ let text_changed = ui.add(widgets::checkbox(&mut text, tl!("Text"))).changed();
+ if ui.add(widgets::checkbox(&mut visual, tl!("Visual"))).changed() || text_changed {
+ action = Some(PanelAction::Show { text, visual });
+ }
+ });
ui.add_space(6.0);
// Side by side, or the new file alone.
ui.horizontal(|ui| {
@@ -129,7 +142,7 @@ pub(crate) fn panel(ui: &mut egui::Ui, t: &Tokens, state: &Option<CompareState>,
}
});
ui.separator();
- for (i, ch) in c.changes.iter().enumerate().take(2000) {
+ for (i, ch) in c.changes.iter().enumerate().filter(|_| s.show_text).take(2000) {
let text = match ch.kind {
Kind::Replaced => format!("\"{}\" → \"{}\"", ch.old.text, ch.new.text),
Kind::Inserted => format!("+ \"{}\"", ch.new.text),
@@ -170,38 +183,6 @@ impl PdfCraftApp {
match self.session.compare(old, new) {
Ok(result) => {
let visual = self.session.compare_visual(old, new, 72.0).unwrap_or_default();
- self.views[i].compare_marks = result
- .changes
- .iter()
- .flat_map(|ch| ch.new.rects.iter().map(move |r| (ch.new.page, r.map(|v| v as f32), colour(ch.kind))))
- .collect();
- // Visual differences not already covered by a text change.
- let text_marks = self.views[i].compare_marks.clone();
- for (p, r) in &visual {
- let r = r.map(|v| v as f32);
- let covered = text_marks.iter().any(|(mp, m, _)| *mp == *p && m[0] <= r[2] && r[0] <= m[2] && m[1] <= r[3] && r[1] <= m[3]);
- if !covered {
- self.views[i].compare_marks.push((*p, r, VISUAL));
- }
- }
- // The old file's pages too: what was deleted or replaced, and the visual
- // differences, so both versions read with their own shading.
- if let Some(oi) = self.views.iter().position(|v| v.id == old) {
- let mut marks: Vec<(usize, [f32; 4], Color32)> = result
- .changes
- .iter()
- .filter(|ch| ch.kind != Kind::Inserted)
- .flat_map(|ch| ch.old.rects.iter().map(move |r| (ch.old.page, r.map(|v| v as f32), colour(ch.kind))))
- .collect();
- for (p, r) in &visual {
- let r = r.map(|v| v as f32);
- let covered = marks.iter().any(|(mp, m, _)| *mp == *p && m[0] <= r[2] && r[0] <= m[2] && m[1] <= r[3] && r[1] <= m[3]);
- if !covered {
- marks.push((*p, r, VISUAL));
- }
- }
- self.views[oi].compare_marks = marks;
- }
let n = result.changes.len();
// Side by side when the old version is open in a tab and the window has the room.
let side_by_side = self.views.iter().any(|v| v.id == old) && self.ctx.as_ref().is_none_or(|c| c.content_rect().width() >= 1000.0);
@@ -214,7 +195,10 @@ impl PdfCraftApp {
side_by_side,
leader: 1,
prev_scroll: [egui::Vec2::ZERO; 2],
+ show_text: true,
+ show_visual: true,
});
+ self.shade_compare(i);
self.right = Some(RightPanel::Compare);
self.notify(if n == 0 {
tl!("The text is the same").to_string()
@@ -252,6 +236,11 @@ impl PdfCraftApp {
s.side_by_side = on;
s.leader = 1;
}
+ PanelAction::Show { text, visual } => {
+ s.show_text = text;
+ s.show_visual = visual;
+ self.shade_compare(index);
+ }
PanelAction::Mark => match self.session.mark_differences(old, new) {
Ok(n) => {
if let Some(info) = self.session.get(new).map(|d| d.info.clone()) {
@@ -285,6 +274,50 @@ impl PdfCraftApp {
}
}
+impl PdfCraftApp {
+ /// Shade the comparison on the new file's pages (view `index`) and, when it is open, the old
+ /// file's, with the kinds of change the filter shows.
+ fn shade_compare(&mut self, index: usize) {
+ let Some(s) = self.compare.as_ref() else { return };
+ let old = s.old;
+ let (old_marks, new_marks) = (shading(s, true), shading(s, false));
+ if let Some(v) = self.views.get_mut(index) {
+ v.compare_marks = new_marks;
+ }
+ if let Some(v) = self.views.iter_mut().find(|v| v.id == old) {
+ v.compare_marks = old_marks;
+ }
+ }
+}
+
+/// One half's shading: its side of the text changes (the old file has no side of an insertion)
+/// and the visual differences no text change there covers, so both versions read with their own
+/// shading. Hidden kinds are left out after the overlap test, so hiding the text does not uncover
+/// the visual differences a text change explains.
+fn shading(s: &CompareState, old: bool) -> Vec<(usize, [f32; 4], Color32)> {
+ let overlaps = |p: usize, r: [f32; 4], marks: &[(usize, [f32; 4], Color32)]| {
+ marks.iter().any(|(mp, m, _)| *mp == p && m[0] <= r[2] && r[0] <= m[2] && m[1] <= r[3] && r[1] <= m[3])
+ };
+ let mut text = Vec::new();
+ for ch in s.result.changes.iter().filter(|ch| !(old && ch.kind == Kind::Inserted)) {
+ let side = if old { &ch.old } else { &ch.new };
+ text.extend(side.rects.iter().map(|r| (side.page, r.map(|v| v as f32), colour(ch.kind))));
+ }
+ let mut visual = Vec::new();
+ for (p, r) in &s.visual {
+ let r = r.map(|v| v as f32);
+ // The old file's half also skips a region overlapping one it already shades.
+ if !overlaps(*p, r, &text) && !(old && overlaps(*p, r, &visual)) {
+ visual.push((*p, r, VISUAL));
+ }
+ }
+ let mut out = if s.show_text { text } else { Vec::new() };
+ if s.show_visual {
+ out.extend(visual);
+ }
+ out
+}
+
/// The two halves of a side-by-side comparison, as view indexes (old, new), when the active
/// document is the new file of a comparison shown side by side and the old file is open too.
pub(crate) fn side_by_side(app: &PdfCraftApp, index: usize) -> Option<(usize, usize)> {
diff --git a/crates/ui-egui/tests/compare.rs b/crates/ui-egui/tests/compare.rs
index e735668a1..27fbb853f 100644
--- a/crates/ui-egui/tests/compare.rs
+++ b/crates/ui-egui/tests/compare.rs
@@ -59,6 +59,68 @@ fn compare_two_versions() {
assert_eq!(h.state().session.get(h.state().active_ids().unwrap().1).unwrap().name, "Compare Report.pdf");
}
+/// Two versions whose differences are of both kinds: a replaced word (text) and a rectangle
+/// drawn far below the text (visual only, no text change explains it).
+fn text_and_visual_versions() -> (Vec<u8>, Vec<u8>) {
+ let mut s = Session::new();
+ let v1 = s.create_from_text("t", "Delivery within five days. Returns accepted.").unwrap().to_vec();
+ let text = s.create_from_text("t", "Delivery within three days. Returns accepted.").unwrap();
+ let id = s.open("v2.pdf", None, text, None).unwrap();
+ let square = pdfcraft_engine::Shape::Rectangle { rect: [100.0, 80.0, 300.0, 200.0] };
+ let style = pdfcraft_engine::Style::default_for(&square);
+ let new = pdfcraft_engine::NewAnnotation { page: 0, shape: square, style, contents: String::new(), author: "Ada".into() };
+ s.apply(id, pdfcraft_engine::Edit::AddAnnotation(new)).unwrap();
+ (v1, s.save_bytes(id).unwrap().to_vec())
+}
+
+/// The Compare panel's Show: Text / Visual filter hides that kind of change from the list and
+/// from the shading on both halves, and brings it back.
+#[test]
+fn compare_filters_hide_text_or_visual_changes() {
+ let (v1, v2) = text_and_visual_versions();
+ let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
+ let mut app = PdfCraftApp::new();
+ app.set_option("language", "en").unwrap();
+ app.open_bytes("v1.pdf", None, v1.clone()).unwrap();
+ app.open_bytes("v2.pdf", None, v2.clone()).unwrap();
+ app
+ });
+ h.run_steps(4);
+ h.state_mut().compare_old = h.state().views.first().map(|v| v.id);
+ h.state_mut().run_compare();
+ h.run_steps(3);
+ let new_i = h.state().active_ids().unwrap().0;
+ let old_i = h.state().views.iter().position(|v| v.id == h.state().compare.as_ref().unwrap().old).unwrap();
+ // Visual differences are shaded orange (compare_ui::VISUAL), text changes in their kind's colour.
+ let visual = egui::Color32::from_rgb(0xF0, 0x8C, 0x1A);
+ let kinds = |h: &Harness<'_, PdfCraftApp>, i: usize| {
+ let marks = &h.state().views[i].compare_marks;
+ (marks.iter().filter(|m| m.2 != visual).count(), marks.iter().filter(|m| m.2 == visual).count())
+ };
+ let (text_new, visual_new) = kinds(&h, new_i);
+ let (text_old, visual_old) = kinds(&h, old_i);
+ assert!(text_new > 0 && visual_new > 0, "the fixture has both kinds on the new file: {text_new} text, {visual_new} visual");
+ assert!(text_old > 0 && visual_old > 0, "and on the old file: {text_old} text, {visual_old} visual");
+ h.get_by_label("\"five\" → \"three\"");
+
+ h.get_by_label("Text").click();
+ h.run_steps(2);
+ assert!(h.query_by_label("\"five\" → \"three\"").is_none(), "text changes leave the list");
+ assert_eq!(kinds(&h, new_i), (0, visual_new), "and the new file's shading");
+ assert_eq!(kinds(&h, old_i), (0, visual_old), "and the old file's");
+
+ h.get_by_label("Visual").click();
+ h.run_steps(2);
+ assert_eq!(kinds(&h, new_i), (0, 0));
+ assert_eq!(kinds(&h, old_i), (0, 0));
+
+ h.get_by_label("Text").click();
+ h.run_steps(2);
+ h.get_by_label("\"five\" → \"three\"");
+ assert_eq!(kinds(&h, new_i), (text_new, 0), "text back, visual still hidden");
+ assert_eq!(kinds(&h, old_i), (text_old, 0));
+}
+
/// Writes a screenshot of the Compare panel when PDFCRAFT_SHOT is set (for review).
#[test]
fn compare_panel_screenshot() {
diff --git a/docs/gaps.md b/docs/gaps.md
index 2682d090a..4b8637f27 100644
--- a/docs/gaps.md
+++ b/docs/gaps.md
@@ -49,7 +49,7 @@ update the numbers.
| 18 | Print production tools absent | feature | 25–45 | [target-app-parity.md](target-app-parity.md) |
| 19 | Preferences mostly missing | UI/UX | 15–25 | [ui-parity.md](ui-parity.md) |
| 20 | Scanners, GPU page rendering, pen pressure, Read Out Loud | hardware | 25–50 | [hardware-parity.md](hardware-parity.md) |
-| 21 | Compare: no side-by-side view or filters | feature | 10–20 | [target-app-parity.md](target-app-parity.md) |
+| 21 | Compare: filters by Acrobat's finer kinds of change, page ranges, scanned documents | feature | 8–16 | [target-app-parity.md](target-app-parity.md) |
| 22 | PDF 2.0 extras, linearization, Arlington validation | spec | 20–35 | [pdf-spec-parity.md](pdf-spec-parity.md) |
| 23 | Local AI provider (summarize, ask, alt text, redaction suggestions) | AI | 20–40 | [target-app-parity.md](target-app-parity.md) |
| 24 | Checklist not diffed against Acrobat's own menus | measurement | 4–8 | [target-app-parity.md](target-app-parity.md) |
@@ -350,11 +350,14 @@ update the numbers.
the CPU and uploaded); pressure-sensitive ink; platform text-to-speech.
- **Estimate:** 25–50 h; scanners need hardware. **Doc:** [hardware-parity.md](hardware-parity.md).
-### 21. Compare: no side-by-side view or filters
+### 21. Compare: filters by Acrobat's finer kinds of change, page ranges, scanned documents
-- **Missing:** synchronised side-by-side view, filters by change type, page ranges, scanned
- documents.
-- **Estimate:** 10–20 h. **Doc:** [target-app-parity.md](target-app-parity.md).
+- **Done:** the synchronised side-by-side view; the Compare panel's Show: Text / Visual filter
+ hides either kind from the list and the shading.
+- **Missing:** telling images, annotations, formatting and background/header-footer changes apart
+ (all of them are Visual today), scrolling the two halves by matching content rather than by
+ offset, page ranges, scanned documents.
+- **Estimate:** 8–16 h. **Doc:** [target-app-parity.md](target-app-parity.md).
### 22. PDF 2.0 extras, linearization, Arlington validation
@@ -382,6 +385,7 @@ update the numbers.
| Date | Change | Summary |
|---|---|---|
+| 2026-10-15 | minor | Gap 21: the side-by-side view had already shipped; the Compare panel filters text changes and visual differences. Estimate 10–20 h → 8–16 h |
| 2026-10-15 | minor | Gap 12: the text oracle scores reading order as well as word F1, which is a bag of words and cannot see order; the first measurement separated 18 improvements from 6 regressions in a change F1 called unchanged on 26 of 29 files. Estimates unchanged. |
| 2026-10-14 | minor | M1: raw-deflate fallback preserves decoding-limit errors in strict and tolerant decoding; synthetic filter and COS stream regressions. Estimates unchanged. |
| 2026-10-15 | patch | Gap 24: record localization and installers as partial (unusable Chinese, Telugu and Arabic; unsigned Linux packages) |
diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md
index 9119063e2..636229300 100644
--- a/docs/target-app-parity.md
+++ b/docs/target-app-parity.md
@@ -209,7 +209,7 @@ full parity in that area.
| K Optimize and standards | 58 | 15 | 10 | 34.5% | 20% | 65–115 | Reduce File Size and the Optimizer (images, discards, clean-up, space audit); PDF/A-2b/3b verify and convert (partial). Missing: Preflight (profiles, fixups, reports), PDF/A-1/4 and a/u levels, PDF/X, PDF/UA, PDF/E, PDF/VT, transparency flattening, font unembedding, monochrome JBIG2/CCITT |
| L Print | 39 | 15 | 1 | 39.7% | 35% | 30–55 | Acrobat's sizing, n-up, booklet, poster, comments & forms, preview, print-ready PDF, CUPS on macOS/Linux, the Windows spooler (#756) and the browser's print dialog on the web. Missing: print as image, PostScript, all print-production tools (output preview, separations, ink manager, printer marks, colour conversion) |
| M Accessibility | 61 | 38 | 1 | 63.1% | 30% | 40–70 | Accessibility Checker (all 32 rules, report, fixes), alternate text, title and language. Missing: autotag, Tags/Order/Content panels, Reading Order tool, artifact marking, table editor, Read Out Loud, full keyboard operation of the app, screen-reader audit |
-| N Automation, preferences, misc | 75 | 20 | 5 | 30.0% | 35% | 25–45 | CLI, MCP, UI control channel, 141 automation tools, Action Wizard (run, create), compare (text, visual, report). Missing: most Preferences pages, side-by-side compare, Action Wizard management, custom commands, AI providers, rich media/3D, hosted web app |
+| N Automation, preferences, misc | 75 | 20 | 5 | 30.0% | 35% | 25–45 | CLI, MCP, UI control channel, 141 automation tools, Action Wizard (run, create), compare (text, visual, report, side by side, Text/Visual filter). Missing: most Preferences pages, Acrobat's finer compare filters, Action Wizard management, custom commands, AI providers, rich media/3D, hosted web app |
| **All** | **808** | **423** | **74** | **56.9%** | **≈ 49%** | **610–1,100** | Plus 175–325 h of cross-cutting work (dimension table) |
Shipped features rest on thin evidence: 141 of 423 cite exactly one test, and only a handful cite
diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml
index d8fbe77dd..186b907ec 100644
--- a/parity/acrobat-features.toml
+++ b/parity/acrobat-features.toml
@@ -9189,11 +9189,11 @@ title = "Filter changes by type (text, images, formatting)"
area = "N"
tier = "P2"
milestone = "M12"
-status = "planned"
-commands = []
+status = "partial"
+commands = ["doc.compare"]
tools = []
-evidence = []
-notes = ""
+evidence = ["crates/ui-egui/tests/compare.rs::compare_filters_hide_text_or_visual_changes"]
+notes = "The Compare panel's Show: Text / Visual checkboxes (both on after Compare files) hide that kind of change from the list and from the shading on both halves of a side-by-side view, and bring it back; hiding the text does not uncover the visual differences a text change explains. The counts, Mark as comments and Report… still cover every change. Still missing against Acrobat's Filter menu: telling images, annotations, formatting and background/header-footer changes apart (the comparison finds text changes and pixel differences only, so those all fall under Visual), and Acrobat's defaults with annotations, formatting and background off. Headless: doc_compare returns every change with its kind, so an agent filters the result itself."
[[feature]]
id = "misc.compare-page-ranges"