mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-08 15:35:50 +01:00
Add an opt-in ImGuiFreeType::RenderShapedText API, guarded by
IMGUI_ENABLE_HARFBUZZ_SHAPING, that shapes a text cluster with HarfBuzz
and renders the resulting (possibly ligature) glyphs. This forms GSUB
ligatures -- ZWJ families (U+1F468 U+200D U+1F469 ...) and regional-
indicator flags (U+1F1EB U+1F1F7 -> 🇫🇷) -- that ImFont::RenderText
cannot, because RenderText is codepoint-by-codepoint and never consults
the font's GSUB table.
Implementation (all in misc/freetype/imgui_freetype.cpp, guarded):
- an hb_font_t* per FT_Face (hb_ft_font_create in InitFont, destroyed in
CloseFont);
- a per-(src,baked) shaped-glyph cache (ImVector<ImFontGlyph> +
ImGuiStorage glyph-index -> cache slot) for ligature glyphs that have
no Unicode codepoint and so cannot live in ImFontBaked's
codepoint-indexed tables;
- ImGui_ImplFreeType_BakeGlyphByID: bake a glyph by its FT glyph INDEX
(skipping FT_Get_Char_Index) on demand, pack+blit into the atlas, set
UVs/Colored, cache it;
- ImGuiFreeType::RenderShapedText: hb_shape the cluster, then for each
shaped glyph bake-by-ID and emit a quad with the shaped advance,
mirroring RenderText's mid-frame texture-growth retry (cmd_count).
The existing RenderText hot path is untouched: this is a separate opt-in
API for renderers that need ligatures (e.g. a TUI cell grid that draws
emoji clusters). Compiled with and without IMGUI_ENABLE_HARFBUZZ_SHAPING;
without it the shaping code is absent and the build is identical to
today's FreeType builder.
Requires HarfBuzz headers + lib when IMGUI_ENABLE_HARFBUZZ_SHAPING is
defined.
misc/cpp/ InputText() wrappers for C++ standard library (STL) type: std::string. This is also an example of how you may wrap your own similar types. misc/debuggers/ Helper files for popular debuggers (Visual Studio, GDB, LLDB). e.g. With the .natvis file, types like ImVector<> will be displayed nicely in Visual Studio debugger. misc/fonts/ Fonts loading/merging instructions (e.g. How to handle glyph ranges, how to merge icons fonts). Command line tool "binary_to_compressed_c" to create compressed arrays to embed data in source code. Suggested fonts and links. misc/freetype/ Font atlas builder/rasterizer using FreeType instead of stb_truetype. Benefit from better FreeType rasterization, in particular for small fonts. misc/single_file/ Single-file header stub. We use this to validate compiling all *.cpp files in a same compilation unit. Users of that technique (also called "Unity builds") can generally provide this themselves, so we don't really recommend you use this in your projects.