summaryrefslogtreecommitdiffhomepage
path: root/src/rtext.c
diff options
context:
space:
mode:
authorRay <[email protected]>2023-12-03 20:17:16 +0100
committerRay <[email protected]>2023-12-03 20:17:16 +0100
commita016b4ded23f653da45679f36fcb5ffca6a5f6a0 (patch)
tree8ebd386156a47339dcebf6dede50c99d218a271a /src/rtext.c
parent84ae189953bffaf1cc24168e647fb100bf26a74d (diff)
downloadraylib-a016b4ded23f653da45679f36fcb5ffca6a5f6a0.tar.gz
raylib-a016b4ded23f653da45679f36fcb5ffca6a5f6a0.zip
REVIEWED: `LoadFontData()`, load image only if glyph has been found in font
Diffstat (limited to 'src/rtext.c')
-rw-r--r--src/rtext.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/rtext.c b/src/rtext.c
index dd7c83f3..802b02b9 100644
--- a/src/rtext.c
+++ b/src/rtext.c
@@ -604,7 +604,6 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
// Fill fontChars in case not provided externally
// NOTE: By default we fill glyphCount consecutively, starting at 32 (Space)
-
if (codepoints == NULL)
{
codepoints = (int *)RL_MALLOC(codepointCount*sizeof(int));
@@ -612,7 +611,7 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
genFontChars = true;
}
- chars = (GlyphInfo *)RL_MALLOC(codepointCount*sizeof(GlyphInfo));
+ chars = (GlyphInfo *)RL_CALLOC(codepointCount, sizeof(GlyphInfo));
// NOTE: Using simple packaging, one char after another
for (int i = 0; i < codepointCount; i++)
@@ -630,16 +629,19 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
else if (ch != 32) chars[i].image.data = stbtt_GetCodepointSDF(&fontInfo, scaleFactor, ch, FONT_SDF_CHAR_PADDING, FONT_SDF_ON_EDGE_VALUE, FONT_SDF_PIXEL_DIST_SCALE, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY);
else chars[i].image.data = NULL;
- stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL);
- chars[i].advanceX = (int)((float)chars[i].advanceX*scaleFactor);
+ if (chars[i].image.data != NULL) // Glyph data has been found in the font
+ {
+ stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL);
+ chars[i].advanceX = (int)((float)chars[i].advanceX*scaleFactor);
- // Load characters images
- chars[i].image.width = chw;
- chars[i].image.height = chh;
- chars[i].image.mipmaps = 1;
- chars[i].image.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
+ // Load characters images
+ chars[i].image.width = chw;
+ chars[i].image.height = chh;
+ chars[i].image.mipmaps = 1;
+ chars[i].image.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
- chars[i].offsetY += (int)((float)ascent*scaleFactor);
+ chars[i].offsetY += (int)((float)ascent*scaleFactor);
+ }
// NOTE: We create an empty image for space character, it could be further required for atlas packing
if (ch == 32)