Skip to content

Commit

Permalink
Merge pull request #18844 from calixteman/bug1922063
Browse files Browse the repository at this point in the history
Use Calibri and Lucida Console, when it's possible, in place of sans-serif and monospaced (bug 1922063)
  • Loading branch information
timvandermeij authored Oct 6, 2024
2 parents 7eee86e + a45e4a3 commit 8b73b82
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
31 changes: 29 additions & 2 deletions src/display/text_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
/** @typedef {import("./display_utils").PageViewport} PageViewport */
/** @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";

/**
Expand Down Expand Up @@ -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.
* @returns {Promise}
Expand Down Expand Up @@ -300,9 +324,12 @@ class TextLayer {
angle += Math.PI / 2;
}

const fontFamily =
let fontFamily =
(this.#fontInspectorEnabled && style.fontSubstitution) ||
style.fontFamily;

// Workaround for bug 1922063.
fontFamily = TextLayer.fontFamilyMap.get(fontFamily) || fontFamily;
const fontHeight = Math.hypot(tx[2], tx[3]);
const fontAscent =
fontHeight * TextLayer.#getAscent(fontFamily, this.#lang);
Expand Down
11 changes: 10 additions & 1 deletion src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,18 @@ class FeatureTest {
) {
return shadow(this, "platform", {
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() {
Expand Down

0 comments on commit 8b73b82

Please sign in to comment.