Skip to content

Same font size is wildly different between different fonts #9063

@TellowKrinkle

Description

@TellowKrinkle

Version/Branch of Dear ImGui:

Version 1.92.3

Back-ends:

Custom (PCSX2)

Compiler, OS:

macOS + Apple Clang 17

Full config/build information:

No response

Details:

My Issue/Question:

I'm trying to use system fonts instead of bundling font files for different languages (especially CJK, which tend to be rather large), which means using different fonts on different operating systems. For Japanese, I'm attempting to use Hiragino Sans W3 on macOS and Noto Sans JP Regular on Linux.

The problem is just changing the font changes the text size by a factor of 1.5, even though we're telling imgui to render with the same size each time. The cause seems to be imgui using FT_SIZE_REQUEST_TYPE_REAL_DIM when selecting a size:

req.type = (bd_font_data->UserFlags & ImGuiFreeTypeLoaderFlags_Bitmap) ? FT_SIZE_REQUEST_TYPE_NOMINAL : FT_SIZE_REQUEST_TYPE_REAL_DIM;

This option scales the font by its ascender - descender, meaning that the actual font size may not match what was requested of imgui.

Both Japanese fonts seem to want a line height of ~1.5em, but they go about this in different ways. On FT_FaceRec, Hiragino has an ascender of .88 and a descender of -.12, totaling exactly 1em, but has height set to 1.5em. Noto Sans JP has an ascender of 1.16, descender of -.288, and height of 1.448em (which is exactly equal to ascender + descender). As a result, if you request 37 point font, you end up with 37 point Hiragino but 26 point Noto Sans JP, which aren't even close in size. You can also see this with the "PCSX2 について" along the bottom, where "PCSX2" is rendered with Roboto (which has had its 37-point request turned into 32-point), and has a completely different size from the "について" rendered with either of the two Japanese fonts.

imgui should probably at least have an option to use the requested point size, instead of scaling it based on some font metrics that may be completely arbitrary.

Screenshots/Video:

Hiragino Sans:

Image

Noto Sans JP:

Image

Minimal, Complete and Verifiable Example code:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions