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

imgui_freetype: Can not use CBDT/CBLC font #8190

Open
llxiaoyuan opened this issue Nov 28, 2024 · 6 comments
Open

imgui_freetype: Can not use CBDT/CBLC font #8190

llxiaoyuan opened this issue Nov 28, 2024 · 6 comments

Comments

@llxiaoyuan
Copy link

llxiaoyuan commented Nov 28, 2024

Version/Branch of Dear ImGui:

Version 1.XX, Branch: XXX (master/docking/etc.)

Back-ends:

imgui_impl_dx11_cpp + imgui_impl_dx11.cpp

Compiler, OS:

win10

Full config/build information:

Details:

I used the FREETYPE_LUNASVG flag to load TwitterColorEmoji-SVGinOT.ttf and noto-untouchedsvg.ttf, but I still cannot load AppleColorEmoji.ttf.
Can CBDT/CBLC color font format be supported? Or is there a way to convert CBDT/CBLC to SVG format?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

@ocornut
Copy link
Owner

ocornut commented Nov 28, 2024

Maybe @pthom would know?
Try PlutoSVG instead it seems more up to date than LunaSVG.

@ocornut ocornut changed the title can not use CBDT/CBLC font imgui_freetype: Can not use CBDT/CBLC font Nov 28, 2024
@pthom
Copy link
Contributor

pthom commented Nov 29, 2024

Hi,

Looking at https://learn.microsoft.com/en-us/typography/opentype/spec/cbdt , we see:

Images for each individual glyph may be stored as straight PNG data, as specified in ISO/IEC 15948. Only the following chunks are allowed in such PNG data: IHDR, PLTE, tRNS, sRGB, IDAT, and IEND. If other chunks are present, the behavior is undefined. The image data must be in the sRGB colorspace, regardless of color information that could be present in other chunks in the PNG data. The individual images must have the same size as expected by the table in the bitmap metrics.

So, this font is actually a combination of PNG files. It likely scales poorly.

Using PlutoSVG or LunaSVG will not help in loading png data.

Or is there a way to convert CBDT/CBLC to SVG format?

I Don't know, but PNG is not a vector format, so it is unlikely. I don't even understand why it ended up being accepted as a viable font format.

As an alternative, I would recommend using a colored SVG font, such as NotoColorEmoji-Regular.ttf

See sammycage/lunasvg#150 where an issue when loading this font was solved in ImGui. You will need to define IMGUI_ENABLE_FREETYPE_PLUTOSVG , as mentioned in https://github.com/ocornut/imgui/blob/master/misc/freetype/README.md

@pthom
Copy link
Contributor

pthom commented Nov 29, 2024

And as far as your specific font is concerned, you would need to enable PNG support in freetype. I'm not sure it will be enough, though. I failed displaying glyphs from this particular font on my side, even with png support in freetype.

@llxiaoyuan
Copy link
Author

How to directly load png maps to characters

@llxiaoyuan
Copy link
Author

AddCustomRectFontGlyph is a good way?

@ocornut
Copy link
Owner

ocornut commented Dec 2, 2024

AddCustomRectFontGlyph is a good way?

Yes. But notice this issue, you need to mark the glyph as colored:
#8133 (comment)

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

No branches or pull requests

3 participants