Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts: added IMGUI_DISABLE_DEFAULT_FONTS macro. #8161

Closed

Conversation

Demonese
Copy link
Contributor

Summary

As of now, we can disable the demo (IMGUI_DISABLE_DEMO_WINDOWS) and debugging tools (IMGUI_DISABLE_DEBUG_TOOLS) to reduce executable size.

I noticed that it's common to load high-quality vector fonts from the OS font library. Default font (ProggyClean) performs best at 13px and gets blurry at other sizes. So we can add a macro IMGUI_DISABLE_DEFAULT_FONTS to disable it.

Test

Tested with example_win32_directx11.

IMGUI_DISABLE_DEMO_WINDOWS and IMGUI_DISABLE_DEBUG_TOOLS are defined.

IMGUI_DISABLE_DEFAULT_FONTS defined size (in bytes)
NO 214,016 (100.0%)
YES 200,192 (93.54%)
dir
D:\imgui\build\Release>dir
 驱动器 D 中的卷是 Data
 卷的序列号是 C0C4-4173

D:\imgui\build\Release 的目录

2024/11/19 03:20 <DIR> .
2024/11/19 02:37 <DIR> ..
2024/11/19 02:30 214,016 example_win32_d3d11.with.exe
2024/11/19 02:31 200,192 example_win32_d3d11.without.exe

@ocornut
Copy link
Owner

ocornut commented Nov 18, 2024

I'll merge this at some point.

Some notes:

  • the data is bigger than it should because we're using base85 encoding which was (weirdly) chosen to space on source code space rather than binary space. I've been expecting to remove support for base85 in an upcoming update. This will take 2-3 kb less binary space.
  • "and gets blurry at other sizes" it only gets blurry because we rasterize at 13 px and upscale with bilinear filtering. If you rasterize already scaled, even at uneven sizes, it will keep looking blocky. I don't mean it will look great but it'll be blocky. An upcoming update to make fonts easier to scale will facilitate seeing this.

@ocornut
Copy link
Owner

ocornut commented Nov 20, 2024

Thank you, I have merged this with minor changes as 5ae3dd5.
The define is now called IMGUI_DISABLE_DEFAULT_FONT.
I have removed the #ifdef in the Build() function: this way AddFontDefault() IS called if no fonts have been added and user will get the better assert.

@ocornut ocornut closed this Nov 20, 2024
ocornut added a commit that referenced this pull request Nov 20, 2024
…pace (~12kb to 9.5kb). (#8161)

Encoding as char to ensure compatibility with big endian (#81)
@ocornut
Copy link
Owner

ocornut commented Nov 20, 2024

I also pushed d0e870a to change the font to not use base85 so it is down to 9.5 KB.

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

Successfully merging this pull request may close these issues.

2 participants