Propagate the translated font name to TextContentItems.

This allows font data for system fonts to be looked up in the
PDFObjects.
This commit is contained in:
Samuel Yuan 2022-11-03 16:19:23 -07:00
parent eda51d1dcc
commit 36fb5c1e2b
2 changed files with 10 additions and 4 deletions

View File

@ -2430,8 +2430,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);
@ -2544,6 +2543,7 @@ class PartialEvaluator {
});
})
.then(function (translated) {
textState.loadedName = translated.loadedName;
textState.font = translated.font;
textState.fontMatrix =
translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
@ -2877,7 +2877,7 @@ class PartialEvaluator {
width: 0,
height: 0,
transform: getCurrentTextTransform(),
fontName: textState.font.loadedName,
fontName: textState.loadedName,
hasEOL: true,
});
}
@ -4607,6 +4607,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();
});