Просмотр исходного кода

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

pull/5574/head
Ray 4 дней назад
Родитель
Сommit
97023def48
1 измененных файлов: 13 добавлений и 12 удалений
  1. +13
    -12
      src/rtext.c

+ 13
- 12
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);

Загрузка…
Отмена
Сохранить