mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 17:48:07 +02:00
[Editor] Avoid conflicts between new persistent refs and the ones created when saving (bug 1865341)
When a pdf as a FreeText without appearance, we use a fake font in order to render it and that leads to create few new refs for the font. But then when we're saving, we create some new refs which start at the same number as the previous created ones. Consequently, when saving we're using some wrong objects (like a font) to check if we're able to render the newly added FreeText. In order to fix this bug, we just remove the persistent refs (which are only used when rendering/printing) during the saving.
This commit is contained in:
parent
795c63e400
commit
ae5828c968
6 changed files with 52 additions and 0 deletions
|
@ -44,6 +44,7 @@ class XRef {
|
|||
this._pendingRefs = new RefSet();
|
||||
this._newPersistentRefNum = null;
|
||||
this._newTemporaryRefNum = null;
|
||||
this._persistentRefsCache = null;
|
||||
}
|
||||
|
||||
getNewPersistentRef(obj) {
|
||||
|
@ -63,6 +64,19 @@ class XRef {
|
|||
// stream.
|
||||
if (this._newTemporaryRefNum === null) {
|
||||
this._newTemporaryRefNum = this.entries.length || 1;
|
||||
if (this._newPersistentRefNum) {
|
||||
this._persistentRefsCache = new Map();
|
||||
for (
|
||||
let i = this._newTemporaryRefNum;
|
||||
i < this._newPersistentRefNum;
|
||||
i++
|
||||
) {
|
||||
// We *temporarily* clear the cache, see `resetNewTemporaryRef` below,
|
||||
// to avoid any conflict with the refs created during saving.
|
||||
this._persistentRefsCache.set(i, this._cacheMap.get(i));
|
||||
this._cacheMap.delete(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ref.get(this._newTemporaryRefNum++, 0);
|
||||
}
|
||||
|
@ -70,6 +84,12 @@ class XRef {
|
|||
resetNewTemporaryRef() {
|
||||
// Called once saving is finished.
|
||||
this._newTemporaryRefNum = null;
|
||||
if (this._persistentRefsCache) {
|
||||
for (const [num, obj] of this._persistentRefsCache) {
|
||||
this._cacheMap.set(num, obj);
|
||||
}
|
||||
}
|
||||
this._persistentRefsCache = null;
|
||||
}
|
||||
|
||||
setStartXRef(startXRef) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue