Skip to content

[FIX] fixed CJK characters rendering as □ in graphs#2768

Open
EVE-Rangeen wants to merge 1 commit into
pyfa-org:masterfrom
EVE-Rangeen:fix-nameDisplayOnChart
Open

[FIX] fixed CJK characters rendering as □ in graphs#2768
EVE-Rangeen wants to merge 1 commit into
pyfa-org:masterfrom
EVE-Rangeen:fix-nameDisplayOnChart

Conversation

@EVE-Rangeen
Copy link
Copy Markdown

Summary

Graph labels and legends showed tofu (□) for Chinese, Japanese, and Korean text when using localized pyfa clients. The wx UI rendered CJK text correctly, but Matplotlib defaulted to DejaVu Sans, which lacks CJK characters.
Before Fix
152c477e119e6204edec7129760d901c
After Fix
cc1ebedfdd6e9c802cbb1c9e4579c235134100cd5a0b675fee2df7a6ad840ea23b97b819d180a4153e13f780d4952763

This PR adds a small Matplotlib font setup module and applies it when the graph canvas initializes Matplotlib. It builds a prioritized font stack from the system GUI font and common platform CJK fonts.
Detailed fonts per platform see below:

    if system == 'Windows':
   # Windows platform
        candidates.extend([
            'Microsoft YaHei', 'Microsoft JhengHei', 'SimHei', 'SimSun',
            'Malgun Gothic', 'Gulim', 'Dotum', 'Batang',
            'Yu Gothic', 'Meiryo', 'Arial Unicode MS',
        ])
    elif system == 'Darwin':
   # MacOS platform
        candidates.extend([
            'Apple SD Gothic Neo', 'AppleGothic', 'PingFang SC', 'PingFang TC',
            'Hiragino Sans GB', 'Hiragino Sans', 'Heiti SC', 'Arial Unicode MS',
        ])
    else:
   # Linux platform
        candidates.extend([
            'NanumGothic', 'UnDotum', 'WenQuanYi Micro Hei', 'WenQuanYi Zen Hei',
            'Droid Sans Fallback',
        ])
   # DejaVu Sans (Default Matplotlib font as final fallback font) for English letters, numbers, and symbols.
     candidates.append('DejaVu Sans')   

Then assigns it to font.family so Matplotlib 3.6+ can fall back per glyph. Hence mixed legend text also works (e.g. Chinese shipname in Japanese/Korean GUI), see above.

Changes

  • Add graphs/mpl_fonts.py with configure_matplotlib_font()
  • Call it from graphs/gui/canvasPanel.py after mpl.use('wxagg')

##P.S.
I did some manual tests myself on windows, it looks pretty good, but I dont have any macOS or linux device, so I cant test on these platforms

…t display correctly on graph

Configures Matplotlib font fallback stack to include available system CJK fonts.
This ensures Chinese, Japanese, and Korean characters render correctly in graphs.
@EVE-Rangeen
Copy link
Copy Markdown
Author

I checked this failed check is due to wxPython wheel download timeout. And i cant rerun as the check dependent has not completed. :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant