langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
51.9k stars 7.53k forks source link

The Chinese font is not available in the chart tool #10777

Open luzhiyong1996 opened 22 hours ago

luzhiyong1996 commented 22 hours ago

Self Checks

Dify version

0.11.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

The api/core/tools/provider/builtin/chart/chart.py an error occurred in the set chinese font that could not be obtained

def set_chinese_font():
    font_list = [
        "PingFang SC",
        "SimHei",
        "Microsoft YaHei",
        "STSong",
        "SimSun",
        "Arial Unicode MS",
        "Noto Sans CJK SC",
        "Noto Sans CJK JP",
    ]

    for font in font_list:
        if font in fontManager.ttflist:
            chinese_font = FontProperties(font)
            if chinese_font.get_name() == font:
                return chinese_font

    return FontProperties()

✔️ Expected Behavior

Should be modified as:

def set_chinese_font():
    font_list = [
        "PingFang SC",
        "SimHei",
        "Microsoft YaHei",
        "STSong",
        "SimSun",
        "Arial Unicode MS",
        "Noto Sans CJK SC",
        "Noto Sans CJK JP",
    ]
    for font in font_list:
        if font in [fontInfo.name for fontInfo in fontManager.ttflist]:
            chinese_font = FontProperties(font)
            if chinese_font.get_name() == font:
                return chinese_font

    return FontProperties()

❌ Actual Behavior

No response

dosubot[bot] commented 21 hours ago

@luzhiyong1996 Hello there! I'm here to help you with any bugs, questions, or contributions. Let me know how I can assist you while we wait for a human maintainer.

There are two similar discussions regarding the issue of Chinese characters not being displayed correctly on the axes of charts generated by the chart creation tool in Dify. You can find these discussions here and here [1][2].

Regarding your issue, it seems like the problem is with the way the set_chinese_font function checks for available fonts. Your suggested modification to use [fontInfo.name for fontInfo in fontManager.ttflist] instead of font in fontManager.ttflist is a good approach. This change ensures that the function checks the names of the fonts in the ttflist, which should help in correctly identifying and setting the Chinese font.

To continue talking to Dosu, mention @dosu.

hjlarry commented 20 hours ago

You are right, feel free to submit a PR :)