diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 8d999d475..b52de0610 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 96ac967d7..fd859146b 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 000000000..cf5b77aa0 --- /dev/null +++ b/test/pdfs/issue14755.pdf @@ -0,0 +1,35 @@ +%PDF-2.0 +1 0 obj <> +endobj +2 0 obj <> +endobj +3 0 obj<> +endobj +4 0 obj<>>> +endobj +5 0 obj<> +endobj +6 0 obj<> +endobj +7 0 obj +<> +stream +BT /F1 10 Tf 100 100 Td (ABC)Tj ET +q BT /F2 10 Tf 120 100 Td (DEF)Tj ET Q +BT 140 100 Td (GHI)Tj ET +endstream +endobj +xref +0 8 +0000000000 65535 f +0000000009 00000 n +0000000056 00000 n +0000000111 00000 n +0000000212 00000 n +0000000260 00000 n +0000000327 00000 n +0000000394 00000 n +trailer <> +startxref +539 +%%EOF \ No newline at end of file diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 9ddc8fef7..c6487c105 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -2682,6 +2682,43 @@ 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).toEqual(items[2].fontName); + expect(items[1].fontName).not.toEqual(items[0].fontName); + }); + it("gets empty structure tree", async function () { const tree = await page.getStructTree();