summaryrefslogtreecommitdiffhomepage
path: root/src/text.c
diff options
context:
space:
mode:
authorRay <[email protected]>2020-02-27 13:19:58 +0100
committerRay <[email protected]>2020-02-27 13:19:58 +0100
commitb029fb6d319eaceab334312f56be0bf4f8e8535e (patch)
tree2014e9a5273a7591a15fb0f2a334a30fc794322b /src/text.c
parent245ba2a152c078e1154fb74b2ba224029f2c0a93 (diff)
downloadraylib-b029fb6d319eaceab334312f56be0bf4f8e8535e.tar.gz
raylib-b029fb6d319eaceab334312f56be0bf4f8e8535e.zip
REDESIGNED: LoadFontEx()
Using new file I/O ABI
Diffstat (limited to 'src/text.c')
-rw-r--r--src/text.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/src/text.c b/src/text.c
index fccb0198..f890442e 100644
--- a/src/text.c
+++ b/src/text.c
@@ -333,11 +333,11 @@ Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int charsCou
{
Font font = { 0 };
+#if defined(SUPPORT_FILEFORMAT_TTF)
font.baseSize = fontSize;
font.charsCount = (charsCount > 0)? charsCount : 95;
font.chars = LoadFontData(fileName, font.baseSize, fontChars, font.charsCount, FONT_DEFAULT);
-#if defined(SUPPORT_FILEFORMAT_TTF)
if (font.chars != NULL)
{
Image atlas = GenImageFontAtlas(font.chars, &font.recs, font.charsCount, font.baseSize, 2, 0);
@@ -354,7 +354,6 @@ Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int charsCou
}
else font = GetFontDefault();
#else
- UnloadFont(font);
font = GetFontDefault();
#endif
@@ -498,24 +497,16 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c
#if defined(SUPPORT_FILEFORMAT_TTF)
// Load font data (including pixel data) from TTF file
- // NOTE: Loaded information should be enough to generate font image atlas,
- // using any packaging method
- FILE *fontFile = fopen(fileName, "rb"); // Load font file
-
- if (fontFile != NULL)
+ // NOTE: Loaded information should be enough to generate
+ // font image atlas, using any packaging method
+ int dataSize = 0;
+ unsigned char *fileData = LoadFileData(fileName, &dataSize);
+
+ if (fileData != NULL)
{
- fseek(fontFile, 0, SEEK_END);
- long size = ftell(fontFile); // Get file size
- fseek(fontFile, 0, SEEK_SET); // Reset file pointer
-
- unsigned char *fontBuffer = (unsigned char *)RL_MALLOC(size);
-
- fread(fontBuffer, size, 1, fontFile);
- fclose(fontFile);
-
// Init font for data reading
stbtt_fontinfo fontInfo;
- if (!stbtt_InitFont(&fontInfo, fontBuffer, 0)) TRACELOG(LOG_WARNING, "Failed to init font!");
+ if (!stbtt_InitFont(&fontInfo, fileData, 0)) TRACELOG(LOG_WARNING, "Failed to init font!");
// Calculate font scale factor
float scaleFactor = stbtt_ScaleForPixelHeight(&fontInfo, (float)fontSize);
@@ -595,12 +586,9 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c
*/
}
- RL_FREE(fontBuffer);
+ RL_FREE(fileData);
if (genFontChars) RL_FREE(fontChars);
}
- else TRACELOG(LOG_WARNING, "[%s] TTF file could not be opened", fileName);
-#else
- TRACELOG(LOG_WARNING, "[%s] TTF support is disabled", fileName);
#endif
return chars;