mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-10 10:20:32 -06:00
Merge origin/main into feat/jbig2-run-allowance
This commit is contained in:
@@ -8,6 +8,15 @@ use super::{
|
||||
};
|
||||
use crate::{EditNotice, MarkKind};
|
||||
|
||||
/// Whether the edit, or any edit inside a batch, deletes pages.
|
||||
fn deletes_pages(edit: &Edit) -> bool {
|
||||
match edit {
|
||||
Edit::DeletePages { .. } => true,
|
||||
Edit::Batch { edits, .. } => edits.iter().any(deletes_pages),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
impl Session {
|
||||
/// Apply an edit. On success the previous state is undoable and the view data is refreshed.
|
||||
pub fn apply(&mut self, id: DocId, edit: Edit) -> Result<(), EditError> {
|
||||
@@ -163,6 +172,11 @@ impl Session {
|
||||
// Signed documents are only ever saved incrementally: an edit that needs a full rewrite
|
||||
// (applying redactions, changing security, sanitizing) would invalidate the signatures.
|
||||
// So does any edit to a file rebuilt from object headers: it has no chain to append to.
|
||||
// Deleted pages remain in earlier incremental revisions (#3407), so rewrite
|
||||
// unsigned files in full. Signed files must retain their signed bytes.
|
||||
if !signed && deletes_pages(&edit) {
|
||||
next.require_full_save();
|
||||
}
|
||||
let rewrites = |c: &pdfcraft_cos::Document| c.full_save_required() || c.encryption_changed();
|
||||
if signed && ((rewrites(&next) && !rewrites(&editor.cos)) || (next.is_modified() && next.revisions().is_empty())) {
|
||||
return Err(EditError::SignedRewrite(edit.label().to_string()));
|
||||
@@ -399,6 +413,7 @@ impl Session {
|
||||
| Edit::DeleteContent { .. }
|
||||
| Edit::ReplaceImage { .. }
|
||||
| Edit::PasteContent { .. }
|
||||
| Edit::EditPageImage { .. }
|
||||
) || matches!(e, Edit::MoveObjects { objects, .. } if objects.iter().any(|o| o.kind == ObjectKind::Added))
|
||||
});
|
||||
let touches_marks = edit.is_none_or(|e| {
|
||||
|
||||
Reference in New Issue
Block a user