Merge pull request #15659 from sxyuan/system-font-name-fix

[api-minor] Propagate the translated font name to TextContentItem for system fonts
This commit is contained in:
Jonas Jenwald 2022-11-08 21:56:49 +01:00 committed by GitHub
commit f7449563ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -2425,8 +2425,7 @@ class PartialEvaluator {
if (textContentItem.initialized) {
return textContentItem;
}
const font = textState.font,
loadedName = font.loadedName;
const { font, loadedName } = textState;
if (!seenStyles.has(loadedName)) {
seenStyles.add(loadedName);
@ -2539,6 +2538,7 @@ class PartialEvaluator {
});
})
.then(function (translated) {
textState.loadedName = translated.loadedName;
textState.font = translated.font;
textState.fontMatrix =
translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
@ -2872,7 +2872,7 @@ class PartialEvaluator {
width: 0,
height: 0,
transform: getCurrentTextTransform(),
fontName: textState.font.loadedName,
fontName: textState.loadedName,
hasEOL: true,
});
}
@ -4602,6 +4602,7 @@ class TextState {
this.ctm = new Float32Array(IDENTITY_MATRIX);
this.fontName = null;
this.fontSize = 0;
this.loadedName = null;
this.font = null;
this.fontMatrix = FONT_IDENTITY_MATRIX;
this.textMatrix = IDENTITY_MATRIX.slice();

View File

@ -2244,7 +2244,7 @@ page 1 / 3`);
const pdfPage = await pdfDoc.getPage(1);
const { items, styles } = await pdfPage.getTextContent();
expect(items.length).toEqual(1);
// Font name will a random object id.
// Font name will be a random object id.
const fontName = items[0].fontName;
expect(Object.keys(styles)).toEqual([fontName]);
@ -2266,6 +2266,11 @@ page 1 / 3`);
vertical: false,
});
// Wait for font data to be loaded so we can check that the font names
// match.
await pdfPage.getOperatorList();
expect(pdfPage.commonObjs.has(fontName)).toEqual(true);
await loadingTask.destroy();
});