Skip to content

Commit 8b73b82

Browse files
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)
2 parents 7eee86e + a45e4a3 commit 8b73b82

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/display/text_layer.js

+29-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
/** @typedef {import("./display_utils").PageViewport} PageViewport */
1717
/** @typedef {import("./api").TextContent} TextContent */
1818

19-
import { AbortException, Util, warn } from "../shared/util.js";
19+
import {
20+
AbortException,
21+
FeatureTest,
22+
shadow,
23+
Util,
24+
warn,
25+
} from "../shared/util.js";
2026
import { setLayerDimensions } from "./display_utils.js";
2127

2228
/**
@@ -152,6 +158,24 @@ class TextLayer {
152158
}
153159
}
154160

161+
static get fontFamilyMap() {
162+
const { isWindows, isFirefox } = FeatureTest.platform;
163+
return shadow(
164+
this,
165+
"fontFamilyMap",
166+
new Map([
167+
[
168+
"sans-serif",
169+
`${isWindows && isFirefox ? "Calibri, " : ""}sans-serif`,
170+
],
171+
[
172+
"monospace",
173+
`${isWindows && isFirefox ? "Lucida Console, " : ""}monospace`,
174+
],
175+
])
176+
);
177+
}
178+
155179
/**
156180
* Render the textLayer.
157181
* @returns {Promise}
@@ -300,9 +324,12 @@ class TextLayer {
300324
angle += Math.PI / 2;
301325
}
302326

303-
const fontFamily =
327+
let fontFamily =
304328
(this.#fontInspectorEnabled && style.fontSubstitution) ||
305329
style.fontFamily;
330+
331+
// Workaround for bug 1922063.
332+
fontFamily = TextLayer.fontFamilyMap.get(fontFamily) || fontFamily;
306333
const fontHeight = Math.hypot(tx[2], tx[3]);
307334
const fontAscent =
308335
fontHeight * TextLayer.#getAscent(fontFamily, this.#lang);

src/shared/util.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,18 @@ class FeatureTest {
636636
) {
637637
return shadow(this, "platform", {
638638
isMac: navigator.platform.includes("Mac"),
639+
isWindows: navigator.platform.includes("Win"),
640+
isFirefox:
641+
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
642+
(typeof navigator?.userAgent === "string" &&
643+
navigator.userAgent.includes("Firefox")),
639644
});
640645
}
641-
return shadow(this, "platform", { isMac: false });
646+
return shadow(this, "platform", {
647+
isMac: false,
648+
isWindows: false,
649+
isFirefox: false,
650+
});
642651
}
643652

644653
static get isCSSRoundSupported() {

0 commit comments

Comments
 (0)