mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-20 16:24:29 +00:00
REVIEWED: GenImageFontAtlas(), scale image to fit all characters, in case it fails size estimation #5542
This commit is contained in:
parent
e8ce00dc0b
commit
97023def48
25
src/rtext.c
25
src/rtext.c
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user