diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 77a3d0de4..b651e9c62 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -4679,8 +4679,15 @@ class TranslatedFont { // not execute any operators that set the colour (or other // colour-related parameters) in the graphics state; // any use of such operators shall be ignored." - if (operatorList.fnArray[0] === OPS.setCharWidthAndBounds) { - this.#removeType3ColorOperators(operatorList, fontBBoxSize); + switch (operatorList.fnArray[0]) { + case OPS.setCharWidthAndBounds: + this.#removeType3ColorOperators(operatorList, fontBBoxSize); + break; + case OPS.setCharWidth: + if (!fontBBoxSize) { + this.#guessType3FontBBox(operatorList); + } + break; } charProcOperatorList[key] = operatorList.getIR(); @@ -4728,13 +4735,7 @@ class TranslatedFont { // 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]; - } - this._bbox[0] = Math.min(this._bbox[0], charBBox[0]); - this._bbox[1] = Math.min(this._bbox[1], charBBox[1]); - this._bbox[2] = Math.max(this._bbox[2], charBBox[2]); - this._bbox[3] = Math.max(this._bbox[3], charBBox[3]); + this.#computeCharBBox(charBBox); } let i = 0, @@ -4787,6 +4788,37 @@ class TranslatedFont { i++; } } + + #guessType3FontBBox(operatorList) { + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) { + assert( + operatorList.fnArray[0] === OPS.setCharWidth, + "Type3 glyph shall start with the d0 operator." + ); + } + + let i = 1; + const ii = operatorList.length; + while (i < ii) { + switch (operatorList.fnArray[i]) { + case OPS.constructPath: + const minMax = operatorList.argsArray[i][2]; + // Override the fontBBox when it's undefined/empty (fixes 19624.pdf). + this.#computeCharBBox(minMax); + break; + } + i++; + } + } + + #computeCharBBox(bbox) { + this._bbox ||= [Infinity, Infinity, -Infinity, -Infinity]; + + this._bbox[0] = Math.min(this._bbox[0], bbox[0]); + this._bbox[1] = Math.min(this._bbox[1], bbox[1]); + this._bbox[2] = Math.max(this._bbox[2], bbox[2]); + this._bbox[3] = Math.max(this._bbox[3], bbox[3]); + } } class StateManager { diff --git a/test/pdfs/issue19624.pdf.link b/test/pdfs/issue19624.pdf.link new file mode 100644 index 000000000..a66a576e5 --- /dev/null +++ b/test/pdfs/issue19624.pdf.link @@ -0,0 +1 @@ +https://github.com/user-attachments/files/19126771/okm2500682934750615600.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 52e7d8b38..bfa914535 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -3921,6 +3921,15 @@ "link": true, "type": "eq" }, + { + "id": "issue19624-text", + "file": "pdfs/issue19624.pdf", + "md5": "087ac2141dbfa218be833efcc143925a", + "rounds": 1, + "link": true, + "firstPage": 2, + "type": "text" + }, { "id": "issue1127-text", "file": "pdfs/issue1127.pdf",