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

Do not use "font metrics ... -fixed" in monospace detection #1421

Merged
merged 1 commit into from
Nov 6, 2023
Merged
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
10 changes: 4 additions & 6 deletions porcupine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,10 +895,8 @@ def _is_monospace(font_family: str) -> bool:
if "emoji" in font_family.lower():
return False

# Let's first ask Tcl whether the font is fixed. This is fastest but
# returns the wrong result for some fonts that are not actually monospace.
if not tcl_interpreter.call("font", "metrics", (font_family, "12"), "-fixed"):
return False
# We can't use "font metrics ... -fixed" because it is sometimes wrong.
# https://github.com/Akuli/porcupine/issues/1368

# In non-monospace fonts, i is very narrow and m is very wide.
# Also, make sure that bolding or italic doesn't change the width.
Expand All @@ -923,7 +921,7 @@ def _get_monospace_font_families() -> list[str]:
cache = json.load(file)

# all_families stored to cache in case user installs more fonts
if cache["version"] == 2 and cache["all_families"] == all_families:
if cache["version"] == 3 and cache["all_families"] == all_families:
_log.debug(f"Taking list of monospace families from {cache_path}")
return cache["monospace_families"]

Expand All @@ -939,7 +937,7 @@ def _get_monospace_font_families() -> list[str]:
with cache_path.open("w") as file:
json.dump(
{
"version": 2,
"version": 3,
"all_families": all_families,
"monospace_families": monospace_families,
},
Expand Down
Loading