Skip to content

Commit

Permalink
Use Calibri and Lucida Console, when it's possible, in place of sans-…
Browse files Browse the repository at this point in the history
…serif and monospaced (bug 1922063)

A recent change in Firefox induced too much difference between the text widths computed in using a Canvas
and the ones computed by the text layout engine when rendering the text layer. Consequently, the
text selection can be bad on Windows with some fonts like Arial or Consolas.
This patch is a workaround to try to use in first place some fonts which don't have the problem.
  • Loading branch information
calixteman committed Oct 3, 2024
1 parent 4fb3adf commit 9b8c1fa
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/display/text_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,16 @@ class TextLayer {
angle += Math.PI / 2;
}

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

// Workaround for bug 1922063.
if (fontFamily === "sans-serif") {
fontFamily = "Calibri, sans serif";
} else if (fontFamily === "monospace") {
fontFamily = "Lucida Console, monospace";
}
const fontHeight = Math.hypot(tx[2], tx[3]);
const fontAscent =
fontHeight * TextLayer.#getAscent(fontFamily, this.#lang);
Expand Down

0 comments on commit 9b8c1fa

Please sign in to comment.