mfont 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mfont/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ """
2
+ 快速加载字体工具
3
+
4
+ - mfont.load_font - 加载 LXGW 字体
5
+ - mfont.load_font.load_heiti() # 加载方正黑体
6
+ - mfont.load_font.reset_font() # 重新加载 LXGW 字体
7
+ - mfont.load_font.switch(xxx) # 加载本地字体
8
+
9
+ """
10
+
11
+ __version__ = "0.1.0"
Binary file
Binary file
mfont/load_font.py ADDED
@@ -0,0 +1,44 @@
1
+ from pathlib import Path
2
+
3
+ import matplotlib
4
+ from matplotlib import font_manager
5
+
6
+
7
+ FONT_DIR = Path(__file__).parent / "fonts"
8
+
9
+ def _auto_configure(debug: bool=False):
10
+ # font_dir_path = get_font_ttf_path()
11
+ font_files = font_manager.findSystemFonts(fontpaths=str(FONT_DIR))
12
+ FONT_NAME = "LXGW WenKai GB Lite"
13
+
14
+ if debug:
15
+ # 开发模式,打印字体名
16
+ for fpath in font_files:
17
+ fp = font_manager.FontProperties(fname=fpath)
18
+ print(fp.get_name())
19
+ font_manager.fontManager.addfont(fpath)
20
+ FONT_NAME = fp.get_name()
21
+ else:
22
+ # 正式模式,只加载指定字体
23
+ for fpath in font_files:
24
+ font_manager.fontManager.addfont(fpath)
25
+
26
+
27
+ matplotlib.rc('font', family=FONT_NAME)
28
+ matplotlib.rc('axes', unicode_minus=False)
29
+
30
+ def switch(fpath: str|Path):
31
+ fp = font_manager.FontProperties(fname=fpath)
32
+ font_manager.fontManager.addfont(path=fpath)
33
+
34
+ matplotlib.rc('font', family=fp.get_name())
35
+
36
+ def reset_font():
37
+ _auto_configure()
38
+
39
+ def load_heiti():
40
+ FONT_NAME = "FZHei-B01S"
41
+ matplotlib.rc('font', family=FONT_NAME)
42
+
43
+ _auto_configure()
44
+
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: mfont
3
+ Version: 0.1.0
4
+ Summary: 简洁的 matplotlib 中文字体加载工具
5
+ Author: zsiven
6
+ Author-email:
7
+ Requires-Python: >=3.11
8
+ Requires-Dist: matplotlib
9
+ Dynamic: author
10
+ Dynamic: requires-dist
11
+ Dynamic: requires-python
12
+ Dynamic: summary
@@ -0,0 +1,8 @@
1
+ mfont/__init__.py,sha256=XZdwC-TmCMYKTSM_KBOqCMXcXnp_5LYriA0SygDFUCU,260
2
+ mfont/load_font.py,sha256=_LD1qTqJrLpWievEyuhHmi8jFnw4Qj8XzL1MYUHo7Wk,1166
3
+ mfont/fonts/FangZhengHeiTiJianTi-1.ttf,sha256=gWf1rYgUA8D2eELsQqzvmEmnYn5YCJeClc-yriMv3tk,2990476
4
+ mfont/fonts/LXGWWenKaiGBLite-Regular.ttf,sha256=r3MYtPcreG5_mJycf1v-rkiNKLJKC8qML2_xD_qzwS0,14125640
5
+ mfont-0.1.0.dist-info/METADATA,sha256=G8Rcfn-RmaX8A9qjKazwbOYzlJJbjI879bKlk-uB-O8,265
6
+ mfont-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ mfont-0.1.0.dist-info/top_level.txt,sha256=xtGLQA1Ayf4ZjD8uBGxmQxxOq1_8SoHVP94NCM6vISY,6
8
+ mfont-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ mfont