diff --git a/src/core/font_substitutions.js b/src/core/font_substitutions.js index 9ad26b707dc6e6..c22976ba20f209 100644 --- a/src/core/font_substitutions.js +++ b/src/core/font_substitutions.js @@ -419,6 +419,10 @@ function getFontSubstitution( baseFontName, standardFontName ) { + if (baseFontName.startsWith("InvalidPDFjsFont_")) { + return null; + } + // It's possible to have a font name with spaces, commas or dashes, hence we // just replace them by a dash. baseFontName = normalizeFontName(baseFontName); diff --git a/src/core/xref.js b/src/core/xref.js index 6c32f6ee40b576..37c0449bd25e2f 100644 --- a/src/core/xref.js +++ b/src/core/xref.js @@ -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 clean the cache 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) { diff --git a/test/driver.js b/test/driver.js index 6a0fa4513f2f7f..6e4ae0393a3bc7 100644 --- a/test/driver.js +++ b/test/driver.js @@ -656,6 +656,12 @@ class Driver { if (!task.annotationStorage) { throw new Error("Missing `annotationStorage` entry."); } + if (task.loadAnnotations) { + for (let num = 1; num <= doc.numPages; num++) { + const page = await doc.getPage(num); + await page.getAnnotations({ intent: "display" }); + } + } doc.annotationStorage.setAll(task.annotationStorage); const data = await doc.saveDocument(); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index d63f3d7d9d2038..ce8b9fa1b46bea 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -619,3 +619,4 @@ !issue17069.pdf !issue17215.pdf !bug1863910.pdf +!bug1865341.pdf diff --git a/test/pdfs/bug1865341.pdf b/test/pdfs/bug1865341.pdf new file mode 100755 index 00000000000000..0574cbe0109439 Binary files /dev/null and b/test/pdfs/bug1865341.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index de05cc03e3e9cc..375ef75d7c3e11 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -8381,5 +8381,26 @@ "link": true, "type": "eq", "annotations": true + }, + { + "id": "bug1865341", + "file": "pdfs/bug1865341.pdf", + "md5": "e241b6d1dc493df73e77e3eeabc71721", + "rounds": 1, + "type": "eq", + "save": true, + "print": true, + "loadAnnotations": true, + "annotationStorage": { + "pdfjs_internal_editor_0": { + "annotationType": 3, + "color": [255, 0, 0], + "fontSize": 10, + "value": "Załącznik", + "pageIndex": 0, + "rect": [ 238, 629, 287, 649], + "rotation": 0 + } + } } ]