imgui icon indicating copy to clipboard operation
imgui copied to clipboard

imgui_freetype: Can not use CBDT/CBLC font

Open llxiaoyuan opened this issue 1 year ago • 6 comments

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

llxiaoyuan avatar Nov 28 '24 16:11 llxiaoyuan

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

ocornut avatar Nov 28 '24 16:11 ocornut

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 https://github.com/sammycage/lunasvg/issues/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 avatar Nov 29 '24 07:11 pthom

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.

pthom avatar Nov 29 '24 08:11 pthom

How to directly load png maps to characters

llxiaoyuan avatar Nov 29 '24 09:11 llxiaoyuan

AddCustomRectFontGlyph is a good way?

llxiaoyuan avatar Nov 29 '24 09:11 llxiaoyuan

AddCustomRectFontGlyph is a good way?

Yes. But notice this issue, you need to mark the glyph as colored: https://github.com/ocornut/imgui/issues/8133#issuecomment-2462312266

ocornut avatar Dec 02 '24 12:12 ocornut