Skip to content

Commit e7288dc

Browse files
authored
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
2 parents bc4d907 + 65881f0 commit e7288dc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/core/editor/pdf_editor.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,24 @@ class DocumentData {
5252
}
5353
}
5454

55+
class XRefWrapper {
56+
constructor(entries) {
57+
this.entries = entries;
58+
}
59+
60+
fetch(ref) {
61+
return ref instanceof Ref ? this.entries[ref.num] : ref;
62+
}
63+
}
64+
5565
class PDFEditor {
5666
constructor({ useObjectStreams = true, title = "", author = "" } = {}) {
5767
this.hasSingleFile = false;
5868
this.currentDocument = null;
5969
this.oldPages = [];
6070
this.newPages = [];
6171
this.xref = [null];
72+
this.xrefWrapper = new XRefWrapper(this.xref);
6273
this.newRefCount = 1;
6374
[this.rootRef, this.rootDict] = this.newDict;
6475
[this.infoRef, this.infoDict] = this.newDict;
@@ -173,9 +184,11 @@ class PDFEditor {
173184
let dict;
174185
if (obj instanceof BaseStream) {
175186
({ dict } = obj = obj.getOriginalStream().clone());
187+
dict.xref = this.xrefWrapper;
176188
} else if (obj instanceof Dict) {
177189
if (mustClone) {
178190
obj = obj.clone();
191+
obj.xref = this.xrefWrapper;
179192
}
180193
dict = obj;
181194
}

0 commit comments

Comments
 (0)