hoffstadt / DearPyGui

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

Custom fonts appear blurry on high dpi monitors #1380

Open west-rynes opened 2 years ago

west-rynes commented 2 years ago

Version: 1.0.2 Operating System: macOS 10.15.7

My Issue

Custom loaded fonts appear somewhat blurry. This seems to be a regression from previous dearpygui versions 0.6 when loading fonts. I don't have a non high DPI monitor to check but @Pcothren mentioned he had seen this issue on high DPI but not regular monitors.

Screenshots

font_issue

I know it looks like a small issue, but the whole interface ends up looking slightly blurry. Even for larger fonts the edges are soft. Perhaps for the high dpi scaling non-integer scaling is happening? Oddly the horizontal direction seems to be more blurred than the vertical dimension.

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg
import dearpygui

dpg.create_context()

with dpg.font_registry():
    # Download font here: https://fonts.google.com/specimen/Open+Sans
    font = dpg.add_font("OpenSans-Regular.ttf", 15, tag="ttf-font"
    )

with dpg.window(label="Fonts") as main_window:
    dpg.add_text(default_value=f"DPG  {dearpygui.__version__}: default font.")
    dpg.add_text(default_value=f"DPG  {dearpygui.__version__}: custom ttf font.")
    dpg.bind_item_font(dpg.last_item(), "ttf-font")

dpg.create_viewport()
dpg.setup_dearpygui()
dpg.set_primary_window(main_window, True) # Should fill viewport but does not on macOS
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
hoffstadt commented 2 years ago

We are aware of this issue! Trying to address it still by allowing users to specify the font rasterizer!

west-rynes commented 2 years ago

I can fix this issue if I just double the size of the fonts & then set the font scale to 0.5. The fonts then look great! Maybe this helps to figure out an easy fix for the main code? But this is a current work around to make things look nice.


import dearpygui.dearpygui as dpg
import dearpygui

dpg.create_context()

with dpg.font_registry():
    # Download font here: https://fonts.google.com/specimen/Open+Sans
    font = dpg.add_font("OpenSans-Regular.ttf", 15*2, tag="ttf-font")

with dpg.window(label="Fonts") as main_window:
    dpg.add_text(default_value=f"DPG  {dearpygui.__version__}: default font.")
    dpg.add_text(default_value=f"DPG  {dearpygui.__version__}: custom ttf font.")
    dpg.bind_item_font(dpg.last_item(), "ttf-font")
    dpg.set_global_font_scale(0.5)

dpg.create_viewport()
dpg.setup_dearpygui()
dpg.set_primary_window(main_window, True) # Should fill viewport but does not on macOS
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
hoffstadt commented 2 years ago

@kuchi That is actually the same recommended fix we will need to do internally!

DataExplorerUser commented 2 years ago

On Windows, using "double the size of the fonts & then set the font scale to 0.5" in combination with the following code has been reported to work well.

import ctypes
...

# Include the following code before showing the viewport/calling `dearpygui.dearpygui.show_viewport`.
ctypes.windll.shcore.SetProcessDpiAwareness(2)

Thanks to Atlamillias for the tip!

asuradoll commented 9 months ago

On Windows, using "double the size of the fonts & then set the font scale to 0.5" in combination with the following code has been reported to work well.

import ctypes
...

# Include the following code before showing the viewport/calling `dearpygui.dearpygui.show_viewport`.
ctypes.windll.shcore.SetProcessDpiAwareness(2)

Thanks to Atlamillias for the tip!

Thank you so much