mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-20 20:49:17 -05:00
REVIEWED: GenImageFontAtlas(), scale image to fit all characters, in case it fails size estimation #5542
This commit is contained in:
25
src/rtext.c
25
src/rtext.c
@ -796,7 +796,7 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
|
|||||||
|
|
||||||
if (glyphs == NULL)
|
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;
|
return atlas;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -881,16 +881,17 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
|
|||||||
|
|
||||||
if (offsetY > (atlas.height - fontSize - padding))
|
if (offsetY > (atlas.height - fontSize - padding))
|
||||||
{
|
{
|
||||||
for (int j = i + 1; j < glyphCount; j++)
|
TRACELOG(LOG_WARNING, "FONT: Updating atlas size to fit all characters");
|
||||||
{
|
|
||||||
TRACELOG(LOG_WARNING, "FONT: Failed to package character (0x%02x)", glyphs[j].value);
|
// TODO: Increment atlas size (atlas.height*2) and continue adding glyphs
|
||||||
// Make sure remaining recs contain valid data
|
int updatedAtlasHeight = atlas.height*2;
|
||||||
recs[j].x = 0;
|
int updatedAtlasDataSize = atlas.width*atlas.height;
|
||||||
recs[j].y = 0;
|
unsigned char *updatedAtlasData = (unsigned char *)RL_CALLOC(updatedAtlasDataSize, 1);
|
||||||
recs[j].width = 0;
|
|
||||||
recs[j].height = 0;
|
memcpy(updatedAtlasData, atlas.data, atlasDataSize);
|
||||||
}
|
RL_FREE(atlas.data);
|
||||||
break; // Break for() loop, stop processing glyphs
|
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);
|
RL_FREE(rects);
|
||||||
|
|||||||
Reference in New Issue
Block a user