1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

[Debugger] Add some info about substitution font

When pdfBug is true, the substitution font is used in the text layer in order
to be able to know what is the font really used thanks to the devtools.
And to be sure that fonts are loaded, the font cache isn't cleaned up when
the debugger is active.
This commit is contained in:
Calixte Denizet 2023-10-05 10:19:07 +02:00
parent b4cd8ad215
commit 7851c0da8d
5 changed files with 41 additions and 18 deletions

View file

@ -2427,13 +2427,17 @@ class PartialEvaluator {
const { font, loadedName } = textState;
if (!seenStyles.has(loadedName)) {
seenStyles.add(loadedName);
textContent.styles[loadedName] = {
fontFamily: font.fallbackName,
ascent: font.ascent,
descent: font.descent,
vertical: font.vertical,
};
if (self.options.fontExtraProperties && font.systemFontInfo) {
const style = textContent.styles[loadedName];
style.fontSubstitution = font.systemFontInfo.css;
style.fontSubstitutionLoadedName = font.systemFontInfo.loadedName;
}
}
textContentItem.fontName = loadedName;

View file

@ -80,7 +80,7 @@ class FontLoader {
}
}
async loadSystemFont(info) {
async loadSystemFont({ systemFontInfo: info, _inspectFont }) {
if (!info || this.#systemFonts.has(info.loadedName)) {
return;
}
@ -96,6 +96,7 @@ class FontLoader {
try {
await fontFace.load();
this.#systemFonts.add(loadedName);
_inspectFont?.(info);
} catch {
warn(
`Cannot load system font: ${info.baseFontName}, installing it could help to improve PDF rendering.`
@ -119,7 +120,7 @@ class FontLoader {
font.attached = true;
if (font.systemFontInfo) {
await this.loadSystemFont(font.systemFontInfo);
await this.loadSystemFont(font);
return;
}

View file

@ -172,9 +172,12 @@ function appendText(task, geom, styles) {
if (style.vertical) {
angle += Math.PI / 2;
}
const fontFamily =
(task._fontInspectorEnabled && style.fontSubstitution) || style.fontFamily;
const fontHeight = Math.hypot(tx[2], tx[3]);
const fontAscent =
fontHeight * getAscent(style.fontFamily, task._isOffscreenCanvasSupported);
fontHeight * getAscent(fontFamily, task._isOffscreenCanvasSupported);
let left, top;
if (angle === 0) {
@ -198,7 +201,7 @@ function appendText(task, geom, styles) {
divStyle.top = `${scaleFactorStr}${top.toFixed(2)}px)`;
}
divStyle.fontSize = `${scaleFactorStr}${fontHeight.toFixed(2)}px)`;
divStyle.fontFamily = style.fontFamily;
divStyle.fontFamily = fontFamily;
textDivProperties.fontSize = fontHeight;
@ -212,7 +215,8 @@ function appendText(task, geom, styles) {
// `fontName` is only used by the FontInspector, and we only use `dataset`
// here to make the font name available in the debugger.
if (task._fontInspectorEnabled) {
textDiv.dataset.fontName = geom.fontName;
textDiv.dataset.fontName =
style.fontSubstitutionLoadedName || geom.fontName;
}
if (angle !== 0) {
textDivProperties.angle = angle * (180 / Math.PI);