Break text chunks only if the base font is different

It fixes #20956.
This commit is contained in:
Calixte Denizet 2026-03-23 11:36:16 +01:00 committed by calixteman
parent 484518614d
commit 2e3d79e616
No known key found for this signature in database
GPG Key ID: 0C5442631EE0691F
2 changed files with 9 additions and 22 deletions

View File

@ -2962,8 +2962,10 @@ class PartialEvaluator {
function buildTextContentItem({ chars, extraSpacing }) { function buildTextContentItem({ chars, extraSpacing }) {
if ( if (
currentTextState !== textState && 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(); flushTextContentItem();
currentTextState = textState.clone(); currentTextState = textState.clone();

View File

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