Getting the default font sometimes fails
meskarune opened this issue · 4 comments
Oh my system I have Noto Sans Regular as my default. However when I run this:
convert -list font | awk "{ a[NR] = \$2 } /family: $(fc-match sans -f "%{family}\n")/ { print a[NR-1]; exit }"
I get "Noto-Sans-Adlam-Regular" which is incorrect. It should be "Noto-Sans-Regular"
The bug in the awk script needs to get figured out.
oof, fontconfig stuff
I imagine that it's probably something related to fontconfig 2.13, since that's been... buggy, at times.
@PandorasFox yes, it actually did turn out to be an annoying font config issues lmao.
After some investigation it turns out it the problem is fc-match having very liberal matching and will return things that even partially match. I'm honestly not sure how to get around that. I have "Noto Sans" set as my default font, but fc-match returns "Noto Sans Adlam" as the first match, rather than an exact match.
I have a similar problem. fc-match
returns too much:
$ fc-match sans -f "%{family}\n"
NotoSans Nerd Font,NotoSans NF
Running the subsequent command with only one of these is fine:
$ convert -list font | awk "{ a[NR] = \$2 } /family: NotoSans Nerd Font/ { print a[NR-1]; exit }"
NotoSans-NF-Cond
But the original command, where both values are used, remains empty.
This might be a bit more robust:
fc-match sans -f "%{family}\n" | tr ',' '\n' | while read fontLine; do convert -list font | awk "{ a[NR] = \$2 } /family: $fontLine/ { print a[NR-1]; exit }"; done | head -n1
It essentially tries all comma-separated font families that fc-match
returned.
Here's a patch, should I open a PR for it?
diff --git a/i3lock-fancy b/i3lock-fancy
index d35b977..36cc583 100755
--- a/i3lock-fancy
+++ b/i3lock-fancy
@@ -6,7 +6,7 @@ set -o errexit -o noclobber -o nounset
hue=(-level "0%,100%,0.6")
effect=(-filter Gaussian -resize 20% -define "filter:sigma=1.5" -resize 500.5%)
# default system sans-serif font
-font=$(convert -list font | awk "{ a[NR] = \$2 } /family: $(fc-match sans -f "%{family}\n")/ { print a[NR-1]; exit }")
+font=$(fc-match sans -f "%{family}\n" | tr ',' '\n' | while read fontLine; do convert -list font | awk "{ a[NR] = \$2 } /family: $fontLine/ { print a[NR-1]; exit }"; done | head -n1)
image=$(mktemp --suffix=.png)
shot=(import -silent -window root)
desktop=""
@@ -22,7 +22,7 @@ options="Options:
-p, --pixelate Pixelate the background instead of blur, runs faster.
- -f <fontname>, --font <fontname> Set a custom font.
+ -f <fontname>, --font <fontname> Set a custom font. (Default: ${font})
-t <text>, --text <text> Set a custom text prompt.
I just noticed that this is a different problem than the original one.