mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-15 13:45:54 +08:00
fix: chart tool chinese font display and raise error (#11058)
This commit is contained in:
parent
2e00829b1e
commit
56e361ac44
@ -1,3 +1,4 @@
|
|||||||
|
import matplotlib
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from matplotlib.font_manager import FontProperties, fontManager
|
from matplotlib.font_manager import FontProperties, fontManager
|
||||||
|
|
||||||
@ -5,7 +6,7 @@ from core.tools.provider.builtin_tool_provider import BuiltinToolProviderControl
|
|||||||
|
|
||||||
|
|
||||||
def set_chinese_font():
|
def set_chinese_font():
|
||||||
font_list = [
|
to_find_fonts = [
|
||||||
"PingFang SC",
|
"PingFang SC",
|
||||||
"SimHei",
|
"SimHei",
|
||||||
"Microsoft YaHei",
|
"Microsoft YaHei",
|
||||||
@ -15,16 +16,16 @@ def set_chinese_font():
|
|||||||
"Noto Sans CJK SC",
|
"Noto Sans CJK SC",
|
||||||
"Noto Sans CJK JP",
|
"Noto Sans CJK JP",
|
||||||
]
|
]
|
||||||
|
installed_fonts = frozenset(fontInfo.name for fontInfo in fontManager.ttflist)
|
||||||
for font in font_list:
|
for font in to_find_fonts:
|
||||||
if font in fontManager.ttflist:
|
if font in installed_fonts:
|
||||||
chinese_font = FontProperties(font)
|
return FontProperties(font)
|
||||||
if chinese_font.get_name() == font:
|
|
||||||
return chinese_font
|
|
||||||
|
|
||||||
return FontProperties()
|
return FontProperties()
|
||||||
|
|
||||||
|
|
||||||
|
# use non-interactive backend to prevent `RuntimeError: main thread is not in main loop`
|
||||||
|
matplotlib.use("Agg")
|
||||||
# use a business theme
|
# use a business theme
|
||||||
plt.style.use("seaborn-v0_8-darkgrid")
|
plt.style.use("seaborn-v0_8-darkgrid")
|
||||||
plt.rcParams["axes.unicode_minus"] = False
|
plt.rcParams["axes.unicode_minus"] = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user