diff --git a/src/raylib.h b/src/raylib.h index 96dc316aec9c..9ebfbf110ec8 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1474,8 +1474,10 @@ RLAPI int GetPixelDataSize(int width, int height, int format); // G RLAPI Font GetFontDefault(void); // Get the default Font RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM) RLAPI Font LoadFontEx(const char *fileName, int fontSize, const int *codepoints, int codepointCount); // Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character set, font size is provided in pixels height +RLAPI Font LoadFontExBitmap(const char *fileName, int fontSize, const int *codepoints, int codepointCount); // Load font from file with bitmap glyphs (no anti-aliasing for TTF/OTF) RLAPI Font LoadFontFromImage(Image image, Color key, int firstChar); // Load font from Image (XNA style) RLAPI Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, const int *codepoints, int codepointCount); // Load font from memory buffer, fileType refers to extension: i.e. '.ttf' +RLAPI Font LoadFontFromMemoryBitmap(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, const int *codepoints, int codepointCount); // Load font from memory buffer with bitmap glyphs (no anti-aliasing for TTF/OTF) RLAPI bool IsFontValid(Font font); // Check if a font is valid (font data loaded, WARNING: GPU texture not checked) RLAPI GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSize, const int *codepoints, int codepointCount, int type, int *glyphCount); // Load font data for further use RLAPI Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyphCount, int fontSize, int padding, int packMethod); // Generate image font atlas using chars info diff --git a/src/rtext.c b/src/rtext.c index c17fbe9bf1d1..63f3b50cdcc1 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -423,6 +423,22 @@ Font LoadFontEx(const char *fileName, int fontSize, const int *codepoints, int c return font; } +Font LoadFontExBitmap(const char *fileName, int fontSize, const int *codepoints, int codepointCount) +{ + Font font = { 0 }; + int dataSize = 0; + unsigned char *fileData = LoadFileData(fileName, &dataSize); + + if (fileData != NULL) + { + font = LoadFontFromMemoryBitmap(GetFileExtension(fileName), fileData, dataSize, + fontSize, codepoints, codepointCount); + UnloadFileData(fileData); + } + + return font; +} + // Load an Image font file (XNA style) Font LoadFontFromImage(Image image, Color key, int firstChar) { @@ -548,8 +564,9 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) return font; } -// Load font from memory buffer, fileType refers to extension: i.e. ".ttf" -Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, const int *codepoints, int codepointCount) +static Font LoadFontFromMemoryInternal(const char *fileType, const unsigned char *fileData, int dataSize, + int fontSize, const int *codepoints, int codepointCount, + bool antialias) { Font font = { 0 }; @@ -563,14 +580,21 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int if (TextIsEqual(fileExtLower, ".ttf") || TextIsEqual(fileExtLower, ".otf")) { - font.glyphs = LoadFontData(fileData, dataSize, font.baseSize, codepoints, (codepointCount > 0)? codepointCount : 95, FONT_DEFAULT, &font.glyphCount); + int fontType = antialias ? FONT_DEFAULT : FONT_BITMAP; + + font.glyphs = LoadFontData(fileData, dataSize, font.baseSize, + codepoints, + (codepointCount > 0)? codepointCount : 95, + fontType, + &font.glyphCount); } else #endif #if defined(SUPPORT_FILEFORMAT_BDF) if (TextIsEqual(fileExtLower, ".bdf")) { - font.glyphs = LoadFontDataBDF(fileData, dataSize, codepoints, (codepointCount > 0)? codepointCount : 95, &font.baseSize); + font.glyphs = LoadFontDataBDF(fileData, dataSize, codepoints, + (codepointCount > 0)? codepointCount : 95, &font.baseSize); font.glyphCount = (codepointCount > 0)? codepointCount : 95; } else @@ -584,7 +608,8 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int { font.glyphPadding = FONT_TTF_DEFAULT_CHARS_PADDING; - Image atlas = GenImageFontAtlas(font.glyphs, &font.recs, font.glyphCount, font.baseSize, font.glyphPadding, 0); + Image atlas = GenImageFontAtlas(font.glyphs, &font.recs, font.glyphCount, + font.baseSize, font.glyphPadding, 0); if (isGpuReady) font.texture = LoadTextureFromImage(atlas); // Update glyphs[i].image to use alpha, required to be used on ImageDrawText() @@ -596,7 +621,8 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int UnloadImage(atlas); - TRACELOG(LOG_INFO, "FONT: Data loaded successfully (%i pixel size | %i glyphs)", font.baseSize, font.glyphCount); + TRACELOG(LOG_INFO, "FONT: Data loaded successfully (%i pixel size | %i glyphs)", + font.baseSize, font.glyphCount); } else font = GetFontDefault(); #else @@ -606,6 +632,23 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int return font; } +// Load font from memory buffer, fileType refers to extension: i.e. ".ttf" +Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, + int fontSize, const int *codepoints, int codepointCount) +{ + return LoadFontFromMemoryInternal(fileType, fileData, dataSize, + fontSize, codepoints, codepointCount, + true); // AA ON +} + +Font LoadFontFromMemoryBitmap(const char *fileType, const unsigned char *fileData, int dataSize, + int fontSize, const int *codepoints, int codepointCount) +{ + return LoadFontFromMemoryInternal(fileType, fileData, dataSize, + fontSize, codepoints, codepointCount, + false); // AA OFF +} + // Check if a font is valid (font data loaded) // WARNING: GPU texture not checked bool IsFontValid(Font font)