0
0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-18 17:11:23 +01:00

Fonts: fixed handling of ImFontConfig::FontDataOwnedByAtlas = false which did erroneously make a copy of the font data. (#9086)

Amend 815168c7e
+ Added explicit casts for intent/clarity when passing to stb_truetype/freetype.
This commit is contained in:
ocornut
2025-11-24 15:39:41 +01:00
parent 5f82275ba1
commit 98636f4a23
3 changed files with 8 additions and 9 deletions

View File

@@ -3052,12 +3052,6 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg_in)
font->Sources.push_back(font_cfg);
ImFontAtlasBuildUpdatePointers(this); // Pointers to Sources are otherwise dangling after we called Sources.push_back().
if (font_cfg->FontDataOwnedByAtlas == false)
{
font_cfg->FontDataOwnedByAtlas = true;
font_cfg->FontData = ImMemdup(font_cfg->FontData, (size_t)font_cfg->FontDataSize);
}
// Sanity check
// We don't round cfg.SizePixels yet as relative size of merged fonts are used afterwards.
if (font_cfg->GlyphExcludeRanges != NULL)
@@ -4583,14 +4577,14 @@ static bool ImGui_ImplStbTrueType_FontSrcInit(ImFontAtlas* atlas, ImFontConfig*
IM_ASSERT(src->FontLoaderData == NULL);
// Initialize helper structure for font loading and verify that the TTF/OTF data is correct
const int font_offset = stbtt_GetFontOffsetForIndex((unsigned char*)src->FontData, src->FontNo);
const int font_offset = stbtt_GetFontOffsetForIndex((const unsigned char*)src->FontData, src->FontNo);
if (font_offset < 0)
{
IM_DELETE(bd_font_data);
IM_ASSERT_USER_ERROR(0, "stbtt_GetFontOffsetForIndex(): FontData is incorrect, or FontNo cannot be found.");
return false;
}
if (!stbtt_InitFont(&bd_font_data->FontInfo, (unsigned char*)src->FontData, font_offset))
if (!stbtt_InitFont(&bd_font_data->FontInfo, (const unsigned char*)src->FontData, font_offset))
{
IM_DELETE(bd_font_data);
IM_ASSERT_USER_ERROR(0, "stbtt_InitFont(): failed to parse FontData. It is correct and complete? Check FontDataSize.");