PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Merge PR #3674: M8: applying redactions drops structure-tree references to the comments and fields it removes (#2874)
aiongg69ef1c18e64a
diff --cc crates/redact/src/sanitize.rsindex bafa769bd,f5dbc503d..5395d7fe7--- a/crates/redact/src/sanitize.rs+++ b/crates/redact/src/sanitize.rs@@@ -280,17 -274,12 +280,14 @@@ pub fn remove_hidden(doc: &mut Documentlet mut done = Vec::new();// Content first (it needs the layers and the form still in place).let (text, layers) = (which.contains(&Hidden::HiddenText), which.contains(&Hidden::HiddenLayers));- if (text && count(Hidden::HiddenText) > 0) || (layers && count(Hidden::HiddenLayers) > 0) {- content_pass(doc, text, layers, true)?;- }+ let retained_off_layers = if (text && count(Hidden::HiddenText) > 0) || (layers && count(Hidden::HiddenLayers) > 0) {+ content_pass(doc, text, layers, true)?.1+ } else {+ std::collections::HashSet::new()+ };// Every annotation the pages list now: whatever is no longer listed at the end (flattened// widgets included) leaves the structure tree too.- let listed = |doc: &Document| -> std::collections::HashSet<ObjRef> {- pdfcraft_model::pages(doc).iter().flat_map(|p| annots_of(doc, &p.dict)).filter_map(|a| a.as_ref()).collect()- };- let listed_before = listed(doc);+ let listed_before = listed_annotations(doc);if which.contains(&Hidden::FormFields) && count(Hidden::FormFields) > 0 {// Fields without appearances get one first, so their values stay visible.for f in pdfcraft_forms::fields(doc) {