Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve text selection accuracy by using the real font family #19230

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we need the original font to create a text layer, we need to preserve the font face here.
This may increase memory usage but can improve rendering speed when resizing, as we don’t need to load the font again.

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