Merge pull request #20431 from calixteman/split_merge_p4

Add a wrapper for the new xref in order to be able to get some values from cloned dictionaries
This commit is contained in:
calixteman 2025-11-11 21:47:42 +01:00 committed by GitHub
commit e7288dca8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -52,6 +52,16 @@ class DocumentData {
} }
} }
class XRefWrapper {
constructor(entries) {
this.entries = entries;
}
fetch(ref) {
return ref instanceof Ref ? this.entries[ref.num] : ref;
}
}
class PDFEditor { class PDFEditor {
constructor({ useObjectStreams = true, title = "", author = "" } = {}) { constructor({ useObjectStreams = true, title = "", author = "" } = {}) {
this.hasSingleFile = false; this.hasSingleFile = false;
@ -59,6 +69,7 @@ class PDFEditor {
this.oldPages = []; this.oldPages = [];
this.newPages = []; this.newPages = [];
this.xref = [null]; this.xref = [null];
this.xrefWrapper = new XRefWrapper(this.xref);
this.newRefCount = 1; this.newRefCount = 1;
[this.rootRef, this.rootDict] = this.newDict; [this.rootRef, this.rootDict] = this.newDict;
[this.infoRef, this.infoDict] = this.newDict; [this.infoRef, this.infoDict] = this.newDict;
@ -173,9 +184,11 @@ class PDFEditor {
let dict; let dict;
if (obj instanceof BaseStream) { if (obj instanceof BaseStream) {
({ dict } = obj = obj.getOriginalStream().clone()); ({ dict } = obj = obj.getOriginalStream().clone());
dict.xref = this.xrefWrapper;
} else if (obj instanceof Dict) { } else if (obj instanceof Dict) {
if (mustClone) { if (mustClone) {
obj = obj.clone(); obj = obj.clone();
obj.xref = this.xrefWrapper;
} }
dict = obj; dict = obj;
} }