yofi icon indicating copy to clipboard operation
yofi copied to clipboard

Add font fallback or warning

Open nonetrix opened this issue 2 years ago • 7 comments

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 avatar Feb 13 '22 03:02 nonetrix

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

nonetrix avatar Feb 13 '22 03:02 nonetrix

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?

l4l avatar Feb 15 '22 18:02 l4l

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

WhyNotHugo avatar Feb 19 '22 14:02 WhyNotHugo

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.

l4l avatar Feb 20 '22 12:02 l4l

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.

WhyNotHugo avatar Feb 20 '22 13:02 WhyNotHugo

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()

l4l avatar Feb 20 '22 14:02 l4l

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!

WuerfelDev avatar Sep 03 '23 21:09 WuerfelDev