Merge pull request #18844 from calixteman/bug1922063

Use Calibri and Lucida Console, when it's possible, in place of sans-serif and monospaced (bug 1922063)
This commit is contained in:
Tim van der Meij 2024-10-06 12:52:58 +02:00 committed by GitHub
commit 8b73b828b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 3 deletions

View File

@ -16,7 +16,13 @@
/** @typedef {import("./display_utils").PageViewport} PageViewport */ /** @typedef {import("./display_utils").PageViewport} PageViewport */
/** @typedef {import("./api").TextContent} TextContent */ /** @typedef {import("./api").TextContent} TextContent */
import { AbortException, Util, warn } from "../shared/util.js"; import {
AbortException,
FeatureTest,
shadow,
Util,
warn,
} from "../shared/util.js";
import { setLayerDimensions } from "./display_utils.js"; import { setLayerDimensions } from "./display_utils.js";
/** /**
@ -152,6 +158,24 @@ class TextLayer {
} }
} }
static get fontFamilyMap() {
const { isWindows, isFirefox } = FeatureTest.platform;
return shadow(
this,
"fontFamilyMap",
new Map([
[
"sans-serif",
`${isWindows && isFirefox ? "Calibri, " : ""}sans-serif`,
],
[
"monospace",
`${isWindows && isFirefox ? "Lucida Console, " : ""}monospace`,
],
])
);
}
/** /**
* Render the textLayer. * Render the textLayer.
* @returns {Promise} * @returns {Promise}
@ -300,9 +324,12 @@ class TextLayer {
angle += Math.PI / 2; angle += Math.PI / 2;
} }
const fontFamily = let fontFamily =
(this.#fontInspectorEnabled && style.fontSubstitution) || (this.#fontInspectorEnabled && style.fontSubstitution) ||
style.fontFamily; style.fontFamily;
// Workaround for bug 1922063.
fontFamily = TextLayer.fontFamilyMap.get(fontFamily) || fontFamily;
const fontHeight = Math.hypot(tx[2], tx[3]); const fontHeight = Math.hypot(tx[2], tx[3]);
const fontAscent = const fontAscent =
fontHeight * TextLayer.#getAscent(fontFamily, this.#lang); fontHeight * TextLayer.#getAscent(fontFamily, this.#lang);

View File

@ -636,9 +636,18 @@ class FeatureTest {
) { ) {
return shadow(this, "platform", { return shadow(this, "platform", {
isMac: navigator.platform.includes("Mac"), isMac: navigator.platform.includes("Mac"),
isWindows: navigator.platform.includes("Win"),
isFirefox:
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
(typeof navigator?.userAgent === "string" &&
navigator.userAgent.includes("Firefox")),
}); });
} }
return shadow(this, "platform", { isMac: false }); return shadow(this, "platform", {
isMac: false,
isWindows: false,
isFirefox: false,
});
} }
static get isCSSRoundSupported() { static get isCSSRoundSupported() {