[rtext] Adjust font atlas area calculation so padding area is not underestimated at small font sizes. (#3719)

This commit is contained in:
Tim Romero
2024-01-10 12:34:04 -08:00
committed by GitHub
parent be78255bea
commit 2c124c96df

View File

@@ -725,7 +725,7 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
for (int i = 0; i < glyphCount; i++) for (int i = 0; i < glyphCount; i++)
{ {
if (glyphs[i].image.width > maxGlyphWidth) maxGlyphWidth = glyphs[i].image.width; if (glyphs[i].image.width > maxGlyphWidth) maxGlyphWidth = glyphs[i].image.width;
totalWidth += glyphs[i].image.width + 4*padding; totalWidth += glyphs[i].image.width + 2*padding;
} }
//#define SUPPORT_FONT_ATLAS_SIZE_CONSERVATIVE //#define SUPPORT_FONT_ATLAS_SIZE_CONSERVATIVE
@@ -743,8 +743,9 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
atlas.width = imageSize; // Atlas bitmap width atlas.width = imageSize; // Atlas bitmap width
atlas.height = imageSize; // Atlas bitmap height atlas.height = imageSize; // Atlas bitmap height
#else #else
int paddedFontSize = fontSize + 2*padding;
// No need for a so-conservative atlas generation // No need for a so-conservative atlas generation
float totalArea = totalWidth*fontSize*1.2f; float totalArea = totalWidth*paddedFontSize*1.2f;
float imageMinSize = sqrtf(totalArea); float imageMinSize = sqrtf(totalArea);
int imageSize = (int)powf(2, ceilf(logf(imageMinSize)/logf(2))); int imageSize = (int)powf(2, ceilf(logf(imageMinSize)/logf(2)));