Skip to content

Commit

Permalink
Merge pull request mozilla#15659 from sxyuan/system-font-name-fix
Browse files Browse the repository at this point in the history
[api-minor] Propagate the translated font name to TextContentItem for system fonts
  • Loading branch information
Snuffleupagus authored Nov 8, 2022
2 parents 7e5008f + 36fb5c1 commit f744956
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2872,7 +2872,7 @@ class PartialEvaluator {
width: 0,
height: 0,
transform: getCurrentTextTransform(),
fontName: textState.font.loadedName,
fontName: textState.loadedName,
hasEOL: true,
});
}
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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();
});

Expand Down

0 comments on commit f744956

Please # to comment.