Skip to content

Commit

Permalink
Flush the current chunk when the font changed because of a restore op…
Browse files Browse the repository at this point in the history
… (issue mozilla#14755)
  • Loading branch information
calixteman committed May 18, 2023
1 parent 356f3cf commit f2d4ecc
Show file tree
Hide file tree
Showing 4 changed files with 51 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.
38 changes: 38 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit f2d4ecc

Please sign in to comment.