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

Weird behaviour on missing font #263

Closed
erf opened this issue Sep 9, 2020 · 6 comments
Closed

Weird behaviour on missing font #263

erf opened this issue Sep 9, 2020 · 6 comments
Labels
bug Something isn't working

Comments

@erf
Copy link
Contributor

erf commented Sep 9, 2020

Describe the bug

I had configured .wezterm.lua to load the Fira Code font with: font = wezterm.font("Fira Code")

However i had uninstalled the font which caused some very weird visual bugs and long startup time.

Environment (please complete the following information):

  • OS: macOS
  • Version: 20200909-002054-4c9af461

To Reproduce

Open wezterm with the following configuration and with the font missing.

Configuration

font = wezterm.font("Fira Code")

Expected behavior

I would expect it to behave more gracefully and use the default font, with perhaps a message that the font is missing.

Screenshots

Screenshot 2020-09-09 at 18 52 43

Additional context

@erf erf added the bug Something isn't working label Sep 9, 2020
@wez
Copy link
Owner

wez commented Sep 27, 2020

What's happening here is that one of the implicit emoji fallback fonts is being used as the source of the cell metrics. Emoji fonts tend to have large dimensions because they're typically embedding bitmaps. Because the emoji fallback precedes a textual fallback the cells are oversized and yet still able to include text glyphs from a later fallback.

@erf
Copy link
Contributor Author

erf commented Sep 27, 2020

I see. But is this the best fallback font? The cells seem VERY large. Could a more regular sized font be used?

@wez
Copy link
Owner

wez commented Sep 27, 2020

I'm still thinking about how best to resolve this; there are a couple of things to ponder:

  • If we can reliably tell that a font is an emoji font then we should probably filter it out for this metric calculation
  • If none of the explicitly specified fonts were found, could we use the system default?
  • Some config options prevent using system default fonts and only look in user specified dirs, so the system default font may not actually work
  • I'm wondering if wezterm should bundle eg: JetBrains Mono to use as an embedded default font so that there is a consistent default experience on all platforms.

@erf
Copy link
Contributor Author

erf commented Sep 27, 2020

Do you really have to check for / use an emoji font? If it's just a fallback font (in case you configured something wrong), maybe a textual font is good enough? Although you'd have to deal with / display emojis as text / error. Bundle a default font sounds like a good idea, especially if the system default font doesn't work, or just always default to a bundled font if the one in config is missing. The Jetbrains Mono sounds like a decent choice. Or perhaps Fira Mono, as it's in a few top-programmer-font lists that i've seen (and i really like it ;). Btw is there a way to show a notification / alert to tell the user that the configuration is wrong?

@wez
Copy link
Owner

wez commented Sep 30, 2020

Re: JetBrains Mono vs Fira Code, I did take a closer look at them both and personally I find JetBrains Mono to have a slight edge over Fira Code. They're both pretty similar, but a few of the characters in JetBrains look better to me, so I'd prefer that to be the default/fallback experience.

wez added a commit that referenced this issue Sep 30, 2020
These serve two purposes:

* Provide a consistent default font for new installations,
  that happens to show off ligature and color emoji support
  out of the box.
* Provide a reasonable fallback in case the configuration is broken

Both fonts are distributed under the terms of the OFL 1.1.

refs: #263
wez added a commit that referenced this issue Oct 3, 2020
There was a flaw in processing the built-ins; because we searched
the built-ins as part of the font dir step we'd satisfy matching
the default fallback from the in-memory fonts and it would accidentally
take precedence over the fonts provided by the system font locator.

This commit makes an explicit additional (final) step to search
the built in fonts.

refs: #263
wez added a commit that referenced this issue Oct 11, 2020
In this scenario:

```lua
local wezterm = require "wezterm"

return {
  font_size = 12.0,
  font_dirs = {"/home/wez/.fonts"},
  font_locator = "ConfigDirsOnly",
  font = wezterm.font_with_fallback({
    -- this is an invalid font
     "does not exist",
    "Noto Color Emoji",
  }),
}
```

we'd take the metrics from the emoji font and the cell size would
be crazy huge.

With this change we filter out "outliers" based on the approximate
pixel size for a font given its size and dpi.  If a fallback position
is significantly larger or smaller than the theoretical size then
we skip it when considering the metrics.

The result of this is that with the above configuration we end up
with `{"Noto Color Emoji", "JetBrains Mono"}` as the font order;
most of the textual glyphs will render from `JetBrains Mono` but
the number glyphs prefer the `Noto Color Emoji` renditions which
are typically double width.  While the terminal looks a bit
cartoonish as a result of that selection, the sizes are much more
reasonable compared to the screenshot in #263.

refs: #263
@wez wez closed this as completed in ba09677 Oct 11, 2020
Riatre pushed a commit to Riatre/wezterm-shell-integration that referenced this issue Jan 8, 2023
These serve two purposes:

* Provide a consistent default font for new installations,
  that happens to show off ligature and color emoji support
  out of the box.
* Provide a reasonable fallback in case the configuration is broken

Both fonts are distributed under the terms of the OFL 1.1.

refs: wez/wezterm#263
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants