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

Add font fallback or warning #83

Open
nonetrix opened this issue Feb 13, 2022 · 7 comments
Open

Add font fallback or warning #83

nonetrix opened this issue Feb 13, 2022 · 7 comments

Comments

@nonetrix
Copy link

If you run yofi and do not have the default font installed it does this
lol
After changing font in config with font = "/usr/share/fonts/noto/NotoSansDisplay-Thin.ttf"
lol

@nonetrix
Copy link
Author

This is probably completely unrelated but I'm running NVIDIA proprietary driver and that's only just now started working on other compositors that are not GNOME or KDE

@l4l
Copy link
Owner

l4l commented Feb 15, 2022

If default font (DejaVu Sans Mono) is not installed/found then yofi will panic with the corresponding message. The issue seems rendering related (perhaps related #46 & #82). Do you use pre-built 0.1.5 version or another one?

@WhyNotHugo
Copy link

WhyNotHugo commented Feb 19, 2022

How about using the system-ui family name as a fallback font?

It's a special family name that maps to the font configured for system ui elements (usually Cantarell by default on Linux).

Out of the box with no config I get this very unusual choice of a font:

image

@l4l
Copy link
Owner

l4l commented Feb 20, 2022

What's the system-ui you are talking about? Tried both fontconfig and rust-fontconfig and the family name isn't found. I'm thinking about either providing a hardcoded list of well-known fonts, or simply embedding one into the final binary.

Also I figured out that the default font is not really Deja Vu Sans for fontdue (default backend), but just the first found font without any filter.

@WhyNotHugo
Copy link

WhyNotHugo commented Feb 20, 2022

What's the system-ui you are talking about?

It's a family name. It resolves to whatever font is configured for system ui elements on the local setup. It's kinda like monospace, which is not an actual font, but actually resolves to the default monospace font on the system.

My bad though there's no dash in it, it's actually system ui:

$ fc-match "monospace"
FantasqueSansMono-Regular.otf: "Fantasque Sans Mono" "Regular"

$ fc-match "system-ui"  # Wrong name
OpenSans-Regular.ttf: "Open Sans" "Regular"

$ fc-match "system ui"  # Actual system ui font
Cantarell-VF.otf: "Cantarell" "Regular"

It's a pretty safe fallback because rather than providing a font and expecting the user to have that installed, it picks something that's locally installed.

@l4l
Copy link
Owner

l4l commented Feb 20, 2022

This one unfortunately doesn't work for rust-fontconfig, you may try it with smth like this:

fn main() {
    use rust_fontconfig::*;
    let path = FcFontCache::build().query(&FcPattern {
        familiy: Some("monospace".into()),
        ..Default::default()
    }).unwrap();
    dbg!(path);
}

or either via yofi:

diff --git a/src/font/fdue.rs b/src/font/fdue.rs
index 3b19c35..86f1853 100644
--- a/src/font/fdue.rs
+++ b/src/font/fdue.rs
@@ -96,7 +96,10 @@ impl Font {
 impl FontBackend for Font {
     fn default() -> Self {
         FONTCONFIG_CACHE
-            .query(&FcPattern::default())
+            .query(&FcPattern {
+                family: Some("system ui".into()),
+                ..Default::default()
+            })
             .map(Font::from_fc_path)
             .unwrap()
             .unwrap()

@WuerfelDev
Copy link

I had the same issue (AUR yofi-bin package). Now that I've read that rust-fontconfig got dropped, it would be great if this could be addressed again.
Also thanks for your efforts, l4l!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants