-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysfiles.py
More file actions
36 lines (31 loc) · 1.17 KB
/
sysfiles.py
File metadata and controls
36 lines (31 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'''
Operations about system files.
'''
import os.path as osp
import matplotlib.font_manager as mfm
import sys
def systemFontPath():
'Return the path of system font'
return osp.dirname(mfm.findSystemFonts()[0])
def addPath(filename):
'Return the path of filename in system font directory'
return osp.join(systemFontPath(), filename)
def defaultFont():
'Return a default monospace font path'
fnlist = [osp.basename(font) for font in mfm.findSystemFonts()]
expected = ['simsun.ttc', 'simkai.ttf', 'simhei.ttf']
for fn in expected:
if fn in fnlist:
return addPath(fn)
return mfm.findSystemFonts()[0] # Just assume it works lol
def fontExist(filename):
'Return True if filename exists in system font directory'
return osp.exists(addPath(filename))
def hanFont():
'Return the expected font for Chinese characters. By default it should be ./fonts/SourceHanSerifSC-Regular.otf'
if osp.exists('./fonts/SourceHanSerifSC-Regular.otf'):
return './fonts/SourceHanSerifSC-Regular.otf'
elif fontExist('SourceHanSerifSC-Regular.otf'):
return addPath('SourceHanSerifSC-Regular.otf')
else:
return defaultFont()