Debian Codegraph @

source/util/find_font

raw
1 #! /bin/sh
2
3 # find a ttf file by exact name match (case insensitive). Tries font-config
4 # scripts if available, and otherwise falls back on some hard-coded
5 # directories. If the exact match isn't available at all, no output.
6
7 # some hard-coded font directories to check. Note: if you are using
8 # font-config with other directories, you don't need to edit this -- that case
9 # is handled by the `fc-list` call below.
10 FONTDIRS="/usr/share/fonts /usr/local/share/fonts /usr/*/lib/X11/fonts"
11
12 name=$1
13 [ "$name" ] || { echo "Usage: $0 <fontname.ttf>" >&2; exit 100; }
14
15 {
16 {
17 # check font-config directories. This call should print out exactly
18 # matching filenames, and is prioritized by the `head` part of the
19 # call below; the outer find is pretty trivial for this case. (The
20 # -L may be necessary in some systems, though.) This part requires
21 # an exact match to $name (in contrast to, e.g., an fc-match call.)
22 # Also, the outer 2>/dev/null eliminates this call if fc-list isn't
23 # present at all.
24 fc-list -f "%{file}\n" | grep -Fi "/$name"
25
26 # as a backup, check the hard-coded directories above. This relies on
27 # the somewhat elaborate `find` call below to actually get a name
28 # matching $name. These dirs may be redundant with fontconfig dirs,
29 # but that is ok.
30 # XX is this necessary any more?
31 for dir in $FONTDIRS; do
32 [ -d "$dir" ] && echo "$dir"
33 done
34 } | xargs -I% find -L % \( -type f -o -type l \) -iname "$name" -print \
35 | head -n1
36 } 2>/dev/null