diff --git a/src/core/evaluator.js b/src/core/evaluator.js index cda5f7df7e0073..a6ebd12b1869f8 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -4404,8 +4404,10 @@ class TranslatedFont { const fontResources = this.dict.get("Resources") || resources; const charProcOperatorList = Object.create(null); - const isEmptyBBox = - !translatedFont.bbox || isArrayEqual(translatedFont.bbox, [0, 0, 0, 0]); + const fontBBox = Util.normalizeRect(translatedFont.bbox || [0, 0, 0, 0]), + width = fontBBox[2] - fontBBox[0], + height = fontBBox[3] - fontBBox[1]; + const fontBBoxSize = Math.hypot(width, height); for (const key of charProcs.getKeys()) { loadCharProcsPromise = loadCharProcsPromise.then(() => { @@ -4426,7 +4428,7 @@ class TranslatedFont { // colour-related parameters) in the graphics state; // any use of such operators shall be ignored." if (operatorList.fnArray[0] === OPS.setCharWidthAndBounds) { - this._removeType3ColorOperators(operatorList, isEmptyBBox); + this._removeType3ColorOperators(operatorList, fontBBoxSize); } charProcOperatorList[key] = operatorList.getIR(); @@ -4454,7 +4456,7 @@ class TranslatedFont { /** * @private */ - _removeType3ColorOperators(operatorList, isEmptyBBox = false) { + _removeType3ColorOperators(operatorList, fontBBoxSize = NaN) { if ( typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || TESTING") @@ -4467,12 +4469,19 @@ class TranslatedFont { const charBBox = Util.normalizeRect(operatorList.argsArray[0].slice(2)), width = charBBox[2] - charBBox[0], height = charBBox[3] - charBBox[1]; + const charBBoxSize = Math.hypot(width, height); if (width === 0 || height === 0) { // Skip the d1 operator when its bounds are bogus (fixes issue14953.pdf). operatorList.fnArray.splice(0, 1); operatorList.argsArray.splice(0, 1); - } else if (isEmptyBBox) { + } else if ( + fontBBoxSize === 0 || + Math.round(charBBoxSize / fontBBoxSize) >= 10 + ) { + // Override the fontBBox when it's undefined/empty, or when it's at least + // (approximately) one order of magnitude smaller than the charBBox + // (fixes issue14999_reduced.pdf). if (!this._bbox) { this._bbox = [Infinity, Infinity, -Infinity, -Infinity]; } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 5d1d18e7374ccd..1081abba8b72c0 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -121,6 +121,7 @@ !issue13916.pdf !issue14023.pdf !issue14438.pdf +!issue14999_reduced.pdf !bad-PageLabels.pdf !decodeACSuccessive.pdf !issue13003.pdf @@ -328,6 +329,7 @@ !bug903856.pdf !issue14618.pdf !bug850854.pdf +!issue14999_reduced.pdf !issue12810.pdf !bug866395.pdf !issue12010_reduced.pdf diff --git a/test/pdfs/issue14999_reduced.pdf b/test/pdfs/issue14999_reduced.pdf new file mode 100644 index 00000000000000..52bc44a3344815 Binary files /dev/null and b/test/pdfs/issue14999_reduced.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 10529d872913d9..81fb2d0a841182 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -2848,6 +2848,12 @@ "link": false, "type": "text" }, + { "id": "issue14999", + "file": "pdfs/issue14999_reduced.pdf", + "md5": "a4e664e734f6869aa66245e72d448874", + "rounds": 1, + "type": "text" + }, { "id": "issue6901-eq", "file": "pdfs/issue6901.pdf", "md5": "1a0604b1a7a3aaf2162b425a9a84230b",