From f2d4ecc0cccb04e69622c3b1aa9e6885ebecf562 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 18 May 2023 17:22:42 +0200 Subject: [PATCH] Flush the current chunk when the font changed because of a restore op (issue #14755) --- src/core/evaluator.js | 12 ++++++++++++ test/pdfs/.gitignore | 1 + test/pdfs/issue14755.pdf | Bin 0 -> 751 bytes test/unit/api_spec.js | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 test/pdfs/issue14755.pdf 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 0000000000000000000000000000000000000000..cf5b77aa0fc39e82f7d832d3012258c7babe34d8 GIT binary patch literal 751 zcmbtS(N4lJ6n*bk+!qpk(6$>xmJkvLOpF>4_C|attl$W)x)p?`4hc#R3QRVJ}PSu~3!1eI3oL8oFjd@B9jl?Q+ia;C z3DW$h1RVk;7;g7b=WF{0VTcB$Ewp-PQ37-dDIi(lTev4l;o>$LTqYYBCF~O%$vcp| zhBO?-6$xHQNw%BP-T1!l$7E}>I^%tzR}6>E#Bo6<2>bvLKCBSj7vx7Mz+up8ASv;7 zokE_(w9lXp#(N6+9!}*93NhXqvW3dFx}bz-*^h=UpBjVrtqK@NrwZ#15%?i%wMNhJ EFZy)F%>V!Z literal 0 HcmV?d00001 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();