Update rtext.c

This commit is contained in:
Ray 2023-12-15 18:26:49 +01:00
parent 0236236934
commit 5fa5f31b91

View File

@ -2078,35 +2078,12 @@ static Font LoadBMFont(const char *fileName)
if (readVars < 1) { UnloadFileText(fileText); return font; } // No glyphCount read if (readVars < 1) { UnloadFileText(fileText); return font; } // No glyphCount read
// Compose correct path using route of .fnt file (fileName) and imFileName // Load all required images for further compose
char **imPath;
char *lastSlash = NULL;
imPath = (char **)RL_CALLOC(MAX_FONT_IMAGE_PAGES, sizeof(char *));
for (int i = 0; i < pageCount; i++)
{
lastSlash = strrchr(fileName, '/');
if (lastSlash == NULL) lastSlash = strrchr(fileName, '\\');
if (lastSlash != NULL)
{
// NOTE: We need some extra space to avoid memory corruption on next allocations!
imPath[i] = (char *)RL_CALLOC(TextLength(fileName) - TextLength(lastSlash) + TextLength(imFileName[i]) + 4, 1);
memcpy(imPath[i], fileName, TextLength(fileName) - TextLength(lastSlash) + 1);
memcpy(imPath[i] + TextLength(fileName) - TextLength(lastSlash) + 1, imFileName[i], TextLength(imFileName[i]));
}
else imPath[i] = imFileName[i];
TRACELOGD(" > Image loading path: %s", imPath[i]);
}
// Resize and ReDraw Font Image
Image fullFont = LoadImage(imPath[0]);;
Image *imFonts = (Image *)RL_CALLOC(pageCount, sizeof(Image)); // Font atlases, multiple images Image *imFonts = (Image *)RL_CALLOC(pageCount, sizeof(Image)); // Font atlases, multiple images
for (int i = 0; i < pageCount; i++) for (int i = 0; i < pageCount; i++)
{ {
imFonts[i] = LoadImage(imPath[i]); imFonts[i] = LoadImage(TextFormat("%s/%s", GetDirectoryPath(fileName), imFileName[i]));
if (imFonts[i].format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) if (imFonts[i].format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE)
{ {
@ -2128,11 +2105,10 @@ static Font LoadBMFont(const char *fileName)
UnloadImage(imFonts[i]); UnloadImage(imFonts[i]);
imFonts[i] = imFontAlpha; imFonts[i] = imFontAlpha;
} }
if (lastSlash != NULL) RL_FREE(imPath[i]);
} }
fullFont = imFonts[0]; Image fullFont = imFonts[0];
for (int i = 1; i < pageCount; i++) UnloadImage(imFonts[i]);
// If multiple atlas, then merge atlas // If multiple atlas, then merge atlas
// NOTE: WARNING: This process could be really slow! // NOTE: WARNING: This process could be really slow!
@ -2197,8 +2173,6 @@ static Font LoadBMFont(const char *fileName)
} }
else TRACELOG(LOG_INFO, "FONT: [%s] Font loaded successfully (%i glyphs)", fileName, font.glyphCount); else TRACELOG(LOG_INFO, "FONT: [%s] Font loaded successfully (%i glyphs)", fileName, font.glyphCount);
RL_FREE(imPath);
return font; return font;
} }