imgui_freetype: fixed a packing issue which in some occurrences would prevent large amount of glyphs from being packed correctly. (#5788, #5829)

This seemingly innocuous change sursingly had very large side-effects of completly breaking packing for the test font mentioned in above issue. Not even sure why tbh. New code matches what stb_truetype's stbtt_PackBegin() does.
This commit is contained in:
ocornut 2023-01-04 15:17:21 +01:00
parent 9c1dac3ff0
commit 9150c23c04
2 changed files with 4 additions and 1 deletions

View File

@ -67,6 +67,8 @@ Other changes:
- Misc: added GetItemID() in public API. It is not often expected that you would use this, - Misc: added GetItemID() in public API. It is not often expected that you would use this,
but it is useful for Shortcut() and upcoming owner-aware input functions which wants to but it is useful for Shortcut() and upcoming owner-aware input functions which wants to
be implemented with public API. be implemented with public API.
- Fonts: imgui_freetype: fixed a packing issue which in some occurrences would prevent large
amount of glyphs from being packed correctly. (#5788, #5829)
- Fonts: added a 'void* UserData' field in ImFontAtlas, as a convenience for use by - Fonts: added a 'void* UserData' field in ImFontAtlas, as a convenience for use by
applications using multiple font atlases. applications using multiple font atlases.
- Demo: added "Inputs->Shortcut Routing" section. - Demo: added "Inputs->Shortcut Routing" section.

View File

@ -6,6 +6,7 @@
// CHANGELOG // CHANGELOG
// (minor and older changes stripped away, please see git history for details) // (minor and older changes stripped away, please see git history for details)
// 2023/01/04: fixed a packing issue which in some occurrences would prevent large amount of glyphs from being packed correctly.
// 2021/08/23: fixed crash when FT_Render_Glyph() fails to render a glyph and returns NULL. // 2021/08/23: fixed crash when FT_Render_Glyph() fails to render a glyph and returns NULL.
// 2021/03/05: added ImGuiFreeTypeBuilderFlags_Bitmap to load bitmap glyphs. // 2021/03/05: added ImGuiFreeTypeBuilderFlags_Bitmap to load bitmap glyphs.
// 2021/03/02: set 'atlas->TexPixelsUseColors = true' to help some backends with deciding of a prefered texture format. // 2021/03/02: set 'atlas->TexPixelsUseColors = true' to help some backends with deciding of a prefered texture format.
@ -586,7 +587,7 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u
ImVector<stbrp_node> pack_nodes; ImVector<stbrp_node> pack_nodes;
pack_nodes.resize(num_nodes_for_packing_algorithm); pack_nodes.resize(num_nodes_for_packing_algorithm);
stbrp_context pack_context; stbrp_context pack_context;
stbrp_init_target(&pack_context, atlas->TexWidth, TEX_HEIGHT_MAX, pack_nodes.Data, pack_nodes.Size); stbrp_init_target(&pack_context, atlas->TexWidth - atlas->TexGlyphPadding, TEX_HEIGHT_MAX - atlas->TexGlyphPadding, pack_nodes.Data, pack_nodes.Size);
ImFontAtlasBuildPackCustomRects(atlas, &pack_context); ImFontAtlasBuildPackCustomRects(atlas, &pack_context);
// 6. Pack each source font. No rendering yet, we are working with rectangles in an infinitely tall texture at this point. // 6. Pack each source font. No rendering yet, we are working with rectangles in an infinitely tall texture at this point.