Skip to content

Commit

Permalink
Merge pull request #16439 from calixteman/issue14755
Browse files Browse the repository at this point in the history
Flush the current chunk when the font changed because of a restore op (issue #14755)
  • Loading branch information
calixteman authored May 18, 2023
2 parents a24d5b6 + 3091e70 commit e8537e4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2991,6 +2991,8 @@ class PartialEvaluator {
if (!preprocessor.read(operation)) {
break;
}

const previousState = textState;
textState = stateManager.state;
const fn = operation.fn;
args = operation.args;
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,4 @@
!issue14565.pdf
!multiline.pdf
!bug1825002.pdf
!issue14755.pdf
Binary file added test/pdfs/issue14755.pdf
Binary file not shown.
37 changes: 37 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

1 comment on commit e8537e4

@sebastianwl60
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Please sign in to comment.