hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en
MIT License
13.03k stars 678 forks source link

Error loading font for Chinese path #2297

Open monkeycc opened 7 months ago

monkeycc commented 7 months ago

ttf_path E:\中文\config\ttf\MiSans-Regular.ttf

ttf_path = r"E:\中文\config\ttf\MiSans-Regular.ttf"
with dpg.font_registry():
    with dpg.font(
            ttf_path, 40, default_font=True
    ) as default_font:
        dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Full)

dpg.bind_font(default_font)

Exception: Error: [1000] Message:       Font file could not be found

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\anaconda3\envs\gui\lib\site-packages\dearpygui\dearpygui.py", line 1905, in font_registry
    yield widget
  File "e:\code\main.py", line 440, in run
    ttf_path, 40, default_font=True
  File "E:\anaconda3\envs\gui\lib\contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "E:\anaconda3\envs\gui\lib\site-packages\dearpygui\dearpygui.py", line 1878, in font
    widget = internal_dpg.add_font(file, size, label=label, user_data=user_data, use_internal_label=use_internal_label, tag=tag, pixel_snapH=pixel_snapH, parent=parent, **kwargs)
SystemError: <built-in function add_font> returned a result with an error set

During handling of the above exception, another exception occurred:

Exception: Error: [1009] Message:       No container to pop.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "e:/code/main.py", line 15, in <module>
    main(parent)
  File "e:/code/main.py", line 11, in main
    dbok.run(dizhi)
  File "e:\code\main.py", line 445, in run
    dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Full)
  File "E:\anaconda3\envs\gui\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "E:\anaconda3\envs\gui\lib\site-packages\dearpygui\dearpygui.py", line 1907, in font_registry
    internal_dpg.pop_container_stack()
SystemError: <built-in function pop_container_stack> returned a result with an error set

How to solve it ?

v-ein commented 7 months ago

This error occurs because DPG tries to interpret a UTF-8 string as an ANSI string. Unfortunately there's no workaround because further in the code, the same string is treated as UTF-8.

Here's what happens:

v-ein commented 4 months ago

Just curious, why are you closing it as completed? I believe the issue still exists and needs a fix.

monkeycc commented 4 months ago

Thank you, I thought nobody paid attention to this issue anymore