REVIEWED: GenImageFontAtlas(), scale image to fit all characters, in case it fails size estimation #5542

This commit is contained in:
Ray 2026-02-17 18:45:14 +01:00
parent e8ce00dc0b
commit 97023def48

View File

@ -796,7 +796,7 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
if (glyphs == NULL)
{
TRACELOG(LOG_WARNING, "FONT: Provided chars info not valid, returning empty image atlas");
TRACELOG(LOG_WARNING, "FONT: Provided glyphs info not valid, returning empty image atlas");
return atlas;
}
@ -881,16 +881,17 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
if (offsetY > (atlas.height - fontSize - padding))
{
for (int j = i + 1; j < glyphCount; j++)
{
TRACELOG(LOG_WARNING, "FONT: Failed to package character (0x%02x)", glyphs[j].value);
// Make sure remaining recs contain valid data
recs[j].x = 0;
recs[j].y = 0;
recs[j].width = 0;
recs[j].height = 0;
}
break; // Break for() loop, stop processing glyphs
TRACELOG(LOG_WARNING, "FONT: Updating atlas size to fit all characters");
// TODO: Increment atlas size (atlas.height*2) and continue adding glyphs
int updatedAtlasHeight = atlas.height*2;
int updatedAtlasDataSize = atlas.width*atlas.height;
unsigned char *updatedAtlasData = (unsigned char *)RL_CALLOC(updatedAtlasDataSize, 1);
memcpy(updatedAtlasData, atlas.data, atlasDataSize);
RL_FREE(atlas.data);
atlas.height = updatedAtlasHeight;
atlasDataSize = updatedAtlasDataSize;
}
}
@ -967,7 +968,7 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
}
}
}
else TRACELOG(LOG_WARNING, "FONT: Failed to package character (0x%02x)", glyphs[i].value);
else TRACELOG(LOG_WARNING, "FONT: Failed to package glyph (0x%02x)", glyphs[i].value);
}
RL_FREE(rects);