Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 49 additions & 6 deletions src/rtext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 };

Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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)
Expand Down
Loading