diff --git a/src/core/evaluator.js b/src/core/evaluator.js index ddf6bbbe7..f94f57443 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -2575,19 +2575,26 @@ class PartialEvaluator { ]; } - function compareWithLastPosition() { + function compareWithLastPosition(glyphWidth) { const currentTransform = getCurrentTextTransform(); let posX = currentTransform[4]; let posY = currentTransform[5]; - const shiftedX = posX - viewBox[0]; - const shiftedY = posY - viewBox[1]; - - if ( - shiftedX < 0 || - shiftedX > viewBox[2] || - shiftedY < 0 || - shiftedY > viewBox[3] + // Check if the glyph is in the viewbox. + if (textState.font && textState.font.vertical) { + if ( + posX < viewBox[0] || + posX > viewBox[2] || + posY + glyphWidth < viewBox[1] || + posY > viewBox[3] + ) { + return false; + } + } else if ( + posX + glyphWidth < viewBox[0] || + posX > viewBox[2] || + posY < viewBox[1] || + posY > viewBox[3] ) { return false; } @@ -2837,8 +2844,16 @@ class PartialEvaluator { continue; } - if (!category.isZeroWidthDiacritic && !compareWithLastPosition()) { - // The glyph is not in page so just skip it. + if ( + !category.isZeroWidthDiacritic && + !compareWithLastPosition(scaledDim) + ) { + // The glyph is not in page so just skip it but move the cursor. + if (!font.vertical) { + textState.translateTextMatrix(scaledDim * textState.textHScale, 0); + } else { + textState.translateTextMatrix(0, scaledDim); + } continue; } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index f8d8573f5..c59d30dbf 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -586,3 +586,4 @@ !issue16224.pdf !issue16278.pdf !copy_paste_ligatures.pdf +!issue16316.pdf diff --git a/test/pdfs/issue16316.pdf b/test/pdfs/issue16316.pdf new file mode 100755 index 000000000..1719dfa3c Binary files /dev/null and b/test/pdfs/issue16316.pdf differ diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index cf817b328..2ab1a8ebc 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -2668,6 +2668,20 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`) await loadingTask.destroy(); }); + it("gets text content with a specific view box", async function () { + const loadingTask = getDocument(buildGetDocumentParams("issue16316.pdf")); + const pdfDoc = await loadingTask.promise; + const pdfPage = await pdfDoc.getPage(1); + const { items } = await pdfPage.getTextContent({ + disableNormalization: true, + }); + const text = mergeText(items); + + expect(text).toEqual("Experimentation,"); + + await loadingTask.destroy(); + }); + it("gets empty structure tree", async function () { const tree = await page.getStructTree();