From 9b8c1fadc2fa2d58619e311c1dc14ea77b6996b3 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 3 Oct 2024 18:21:29 +0200 Subject: [PATCH] Use Calibri and Lucida Console, when it's possible, in place of sans-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. --- src/display/text_layer.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/display/text_layer.js b/src/display/text_layer.js index 2f72b712ef71f5..11fb7200045639 100644 --- a/src/display/text_layer.js +++ b/src/display/text_layer.js @@ -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);