Skip to content

Commit

Permalink
Improve text selection accuracy by using the real font family
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wangchuan.93 committed Dec 16, 2024
1 parent 8985d80 commit 3e4eb16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions src/display/font_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3e4eb16

Please sign in to comment.