From cf2272ee2b25fb6b9814d314027c610db1b1f511 Mon Sep 17 00:00:00 2001 From: "wangchuan.93" Date: Mon, 16 Dec 2024 20:40:30 +0800 Subject: [PATCH] Improve text selection accuracy by using the real font family Enhanced the text layer creation process by using the real font family instead of the fallback font name. This change ensures that text selection is more accurate. fixes: #19207 --- src/core/evaluator.js | 2 +- src/display/font_loader.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 84cce0b28a9a2..c21def8850ae1 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -2526,7 +2526,7 @@ class PartialEvaluator { if (!seenStyles.has(loadedName)) { seenStyles.add(loadedName); textContent.styles[loadedName] = { - fontFamily: font.fallbackName, + fontFamily: loadedName, ascent: font.ascent, descent: font.descent, vertical: font.vertical, diff --git a/src/display/font_loader.js b/src/display/font_loader.js index 8c24e6ad722d3..b8c96ee3c1921 100644 --- a/src/display/font_loader.js +++ b/src/display/font_loader.js @@ -66,10 +66,12 @@ class FontLoader { } clear() { - for (const nativeFontFace of this.nativeFontFaces) { - this._document.fonts.delete(nativeFontFace); + const fontFacesToRemove = new Set(this.nativeFontFaces); + for (const font of fontFacesToRemove) { + if (!this._document.fonts.has(font)) { + this.nativeFontFaces.delete(font); + } } - this.nativeFontFaces.clear(); this.#systemFonts.clear(); if (this.styleElement) {