diff --git a/.gitignore b/.gitignore index c4a2124..0c622a4 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ __pycache__ # 字体 /fonts +/utils/fonts *.ttc *.ttf *.otf diff --git a/fonts.sh b/utils/fonts.sh similarity index 100% rename from fonts.sh rename to utils/fonts.sh diff --git a/utils/plot.py b/utils/plot.py index 7456e9c..88ffe14 100644 --- a/utils/plot.py +++ b/utils/plot.py @@ -7,11 +7,38 @@ import os import sys +fonts_list = ['SimSun.ttc', 'TimesNewRoman.ttf'] # 字体列表 +fonts_suffix = ['ttc', 'ttf', 'otf'] # 字体后缀 + + # 创建字体库 -def add_fronts(fonts_file): +def add_fronts(fonts_file="./fonts.sh"): os.system(f'bash {fonts_file}') print(f'字体文件加载完成!') -# if __name__ == "__main__": -# add_fronts("../fonts.sh") \ No newline at end of file +# 判断字体文件 +def is_fonts(fonts_dir): + if (os.path.isdir(fonts_dir)): + # 如果字体库存在 + fonts_flag = 0 # 判别标志 + f_list = os.listdir(fonts_dir) # 本地字体库 + for i in fonts_list: + if (i not in f_list): + # 字体不存在 + fonts_flag = 1 + if (fonts_flag == 1): + # 字体不存在 + print(f'字体不存在,正在加载。。。') + add_fronts() # 创建字体库 + else: + print(f'{fonts_list}字体已存在!') + else: + # 字体库不存在,创建字体库 + print(f'字体库不存在,正在创建。。。') + add_fronts() # 创建字体库 + + +if __name__ == "__main__": + # add_fronts("./fonts.sh") + is_fonts("./fonts")