Merge pull request #20957 from calixteman/issue20956

Break text chunks only if the base font is different
This commit is contained in:
calixteman 2026-03-26 22:24:23 +01:00 committed by GitHub
commit 018c1539dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 22 deletions

View File

@ -2962,8 +2962,10 @@ class PartialEvaluator {
function buildTextContentItem({ chars, extraSpacing }) {
if (
currentTextState !== textState &&
(currentTextState.fontName !== textState.fontName ||
currentTextState.fontSize !== textState.fontSize)
(currentTextState.fontSize !== textState.fontSize ||
(currentTextState.fontName !== textState.fontName &&
(currentTextState.font.name !== textState.font.name ||
currentTextState.font.vertical !== textState.font.vertical)))
) {
flushTextContentItem();
currentTextState = textState.clone();

View File

@ -4027,34 +4027,19 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
const { items } = await pdfPage.getTextContent({
disableNormalization: true,
});
// The pdf has 3 different fonts but with the same underlying font data
// so we have finally one chunk.
expect(items).toEqual([
jasmine.objectContaining({
str: "ABC",
str: "ABCDEFGHI",
dir: "ltr",
width: 20.56,
width: 57.779999999999994,
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);
await loadingTask.destroy();
});
it("gets text content with word spacing (issue 20319)", async function () {