CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.62k stars 4.17k forks source link

Properly hint text and improve font rendering. #76420

Closed CLIDragon closed 2 weeks ago

CLIDragon commented 1 month ago

Is your feature request related to a problem? Please describe.

I think this screenshot makes the problem pretty clear. We are unable to detect the actual cap height of the text, leading to text being off centre. image

Additionally, there is an extra 1px of space before and 3px of space after text (drawn in purple). This is the natural spacing embedded in the font, and it would be nice to remove it. Screenshot 2024-09-14 175153

Solution you would like.

Change the current font rendering stack so that we can support autodetecting the cap height for different fonts and adjusting as necessary See https://github.com/CleverRaven/Cataclysm-DDA/pull/76404#issuecomment-2350813614 for initial direction.

Describe alternatives you have considered.

Hand adjusting text in all user-visible UIs. Unfortunately, this breaks if the user changes the font, the font size, the font height, the font width, the font rendering mode, etc.

Additional context

Naming this issue was hard. The scope is strange, and I feel like the current label isn't very clear about what the actual goal is. I certainly didn't start this with the goal of rewriting the font renderer, but I guess that's what I am doing now.

db48x commented 1 month ago

Luckily we don’t have to completely rewrite the whole renderer, we can just swap over to using Freetype. ImGui even provides instructions, we just have to get around to it.

See also #73728, and #73120.

CLIDragon commented 1 month ago

I tried following the provided link to include ImGui, but build fails with the following error:

ImGui-lib-vcpkg-static-Release-x64.lib(imgui_draw.obj) : error LNK2019: unresolved external symbol "struct ImFontBuilderIO const * __cdecl ImGuiFreeType::GetBuilderForFreeType(void)" (?GetBuilderForFreeType@ImGuiFreeType@@YAPEBUImFontBuilderIO@@XZ) referenced in function "public: bool __cdecl ImFontAtlas::Build(void)" (?Build@ImFontAtlas@@QEAA_NXZ)

Which is strange given that building imgui by itself succeeds.

whirm commented 1 month ago

Is this issue (not computing the right height) also causing the wrong vertical dimensions for pop-up windows, cropping content?

This is on Wayland (Sway) on 2024-09-12-1816 build.

2024-09-15T08:22:48,887212788+02:00 2024-09-15T08:29:24,672152633+02:00

db48x commented 1 month ago

No, that was #75698

db48x commented 1 month ago

Screenshot from 2024-09-18 10-27-55

Ignore the window on the left; that’s just for testing.

db48x commented 1 month ago

Screenshot from 2024-09-18 10-37-09