diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 8d999d47581eb8..b52de0610ddacd 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -2991,6 +2991,8 @@ class PartialEvaluator { if (!preprocessor.read(operation)) { break; } + + const previousState = textState; textState = stateManager.state; const fn = operation.fn; args = operation.args; @@ -3362,6 +3364,16 @@ class PartialEvaluator { }); } break; + case OPS.restore: + if ( + previousState && + (previousState.font !== textState.font || + previousState.fontSize !== textState.fontSize || + previousState.fontName !== textState.fontName) + ) { + flushTextContentItem(); + } + break; } // switch if (textContent.items.length >= sink.desiredSize) { // Wait for ready, if we reach highWaterMark. diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 96ac967d7611d3..fd859146bf1f10 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -592,3 +592,4 @@ !issue14565.pdf !multiline.pdf !bug1825002.pdf +!issue14755.pdf diff --git a/test/pdfs/issue14755.pdf b/test/pdfs/issue14755.pdf new file mode 100644 index 00000000000000..cf5b77aa0fc39e Binary files /dev/null and b/test/pdfs/issue14755.pdf differ diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 9ddc8fef7b24cc..c6e184bf082407 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -2682,6 +2682,44 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`) await loadingTask.destroy(); }); + it("check that a chunk is pushed when font is restored", async function () { + const loadingTask = getDocument(buildGetDocumentParams("issue14755.pdf")); + const pdfDoc = await loadingTask.promise; + const pdfPage = await pdfDoc.getPage(1); + const { items } = await pdfPage.getTextContent({ + disableNormalization: true, + }); + expect(items).toEqual([ + jasmine.objectContaining({ + str: "ABC", + dir: "ltr", + width: 20.56, + height: 10, + transform: [10, 0, 0, 10, 100, 100], + hasEOL: false, + }), + jasmine.objectContaining({ + str: "DEF", + dir: "ltr", + width: 20, + height: 10, + transform: [10, 0, 0, 10, 120, 100], + hasEOL: false, + }), + jasmine.objectContaining({ + str: "GHI", + dir: "ltr", + width: 17.78, + height: 10, + transform: [10, 0, 0, 10, 140, 100], + hasEOL: false, + }), + ]); + expect(items[0].fontName).toMatch(/^g_d(\d+)_f1$/); + expect(items[1].fontName).toMatch(/^g_d(\d+)_f2$/); + expect(items[2].fontName).toMatch(/^g_d(\d+)_f1$/); + }); + it("gets empty structure tree", async function () { const tree = await page.getStructTree();