File tree Expand file tree Collapse file tree 2 files changed +66
-2
lines changed
Expand file tree Collapse file tree 2 files changed +66
-2
lines changed Original file line number Diff line number Diff line change 99import argparse
1010import subprocess
1111
12+ # Common system font locations to try when a font file is not found locally
13+ COMMON_FONT_DIRS = [
14+ '/usr/share/fonts' ,
15+ '/usr/local/share/fonts' ,
16+ os .path .expanduser ('~/.local/share/fonts' ),
17+ os .path .expanduser ('~/.fonts' ),
18+ ]
19+
1220class Source (object ):
1321 def __init__ (self , d ):
1422 self .file = d ['file' ]
1523 if not os .path .exists (self .file ):
16- self .file = os .path .join (os .path .dirname (sys .argv [0 ]), self .file )
24+ # First try relative to the script directory (previous behavior)
25+ candidate = os .path .join (os .path .dirname (sys .argv [0 ]), self .file )
26+ if os .path .exists (candidate ):
27+ self .file = candidate
28+ else :
29+ # Fallback: search common system font directories for a matching basename
30+ name = os .path .basename (self .file )
31+ found = None
32+ for font_dir in COMMON_FONT_DIRS :
33+ if not font_dir :
34+ continue
35+ font_dir = os .path .expanduser (font_dir )
36+ if not os .path .isdir (font_dir ):
37+ continue
38+ for root , _ , files in os .walk (font_dir ):
39+ for f in files :
40+ if f .lower () == name .lower ():
41+ found = os .path .join (root , f )
42+ break
43+ if found :
44+ break
45+ if found :
46+ break
47+ if found :
48+ self .file = found
1749 self .range = d .get ('range' )
1850 self .symbols = d .get ('symbols' )
1951
Original file line number Diff line number Diff line change 99import argparse
1010import subprocess
1111
12+ # Common system font locations to try when a font file is not found locally
13+ COMMON_FONT_DIRS = [
14+ '/usr/share/fonts' ,
15+ '/usr/local/share/fonts' ,
16+ os .path .expanduser ('~/.local/share/fonts' ),
17+ os .path .expanduser ('~/.fonts' ),
18+ ]
19+
1220class Source (object ):
1321 def __init__ (self , d ):
1422 self .file = d ['file' ]
1523 if not os .path .exists (self .file ):
16- self .file = os .path .join (os .path .dirname (sys .argv [0 ]), self .file )
24+ # First try relative to the script directory (previous behavior)
25+ candidate = os .path .join (os .path .dirname (sys .argv [0 ]), self .file )
26+ if os .path .exists (candidate ):
27+ self .file = candidate
28+ else :
29+ # Fallback: search common system font directories for a matching basename
30+ name = os .path .basename (self .file )
31+ found = None
32+ for font_dir in COMMON_FONT_DIRS :
33+ if not font_dir :
34+ continue
35+ font_dir = os .path .expanduser (font_dir )
36+ if not os .path .isdir (font_dir ):
37+ continue
38+ for root , _ , files in os .walk (font_dir ):
39+ for f in files :
40+ if f .lower () == name .lower ():
41+ found = os .path .join (root , f )
42+ break
43+ if found :
44+ break
45+ if found :
46+ break
47+ if found :
48+ self .file = found
1749 self .range = d .get ('range' )
1850 self .symbols = d .get ('symbols' )
1951
You can’t perform that action at this time.
0 commit comments