Update C sources
This commit is contained in:
parent
e08c4cd054
commit
3327fcaf9f
22 changed files with 14167 additions and 10920 deletions
|
@ -34,7 +34,7 @@
|
|||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2013-2024 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2013-2025 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
|
@ -161,6 +161,10 @@ extern void LoadFontDefault(void)
|
|||
{
|
||||
#define BIT_CHECK(a,b) ((a) & (1u << (b)))
|
||||
|
||||
// check to see if we have allready allocated the font for an image, and if we don't need to upload, then just return
|
||||
if (defaultFont.glyphs != NULL && !isGpuReady)
|
||||
return;
|
||||
|
||||
// NOTE: Using UTF-8 encoding table for Unicode U+0000..U+00FF Basic Latin + Latin-1 Supplement
|
||||
// Ref: http://www.utf8-chartable.de/unicode-utf8-table.pl
|
||||
|
||||
|
@ -247,13 +251,28 @@ extern void LoadFontDefault(void)
|
|||
// we must consider data as little-endian order (alpha + gray)
|
||||
((unsigned short *)imFont.data)[i + j] = 0xffff;
|
||||
}
|
||||
else ((unsigned short *)imFont.data)[i + j] = 0x00ff;
|
||||
else
|
||||
{
|
||||
((unsigned char *)imFont.data)[(i + j)*sizeof(short)] = 0xff;
|
||||
((unsigned char *)imFont.data)[(i + j)*sizeof(short) + 1] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (isGpuReady) defaultFont.texture = LoadTextureFromImage(imFont);
|
||||
if (isGpuReady)
|
||||
{
|
||||
defaultFont.texture = LoadTextureFromImage(imFont);
|
||||
|
||||
// we have already loaded the font glyph data an image, and the GPU is ready, we are done
|
||||
// if we don't do this, we will leak memory by reallocating the glyphs and rects
|
||||
if (defaultFont.glyphs != NULL)
|
||||
{
|
||||
UnloadImage(imFont);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Reconstruct charSet using charsWidth[], charsHeight, charsDivisor, glyphCount
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -278,7 +297,7 @@ extern void LoadFontDefault(void)
|
|||
|
||||
testPosX += (int)(defaultFont.recs[i].width + (float)charsDivisor);
|
||||
|
||||
if (testPosX >= defaultFont.texture.width)
|
||||
if (testPosX >= imFont.width)
|
||||
{
|
||||
currentLine++;
|
||||
currentPosX = 2*charsDivisor + charsWidth[i];
|
||||
|
@ -312,6 +331,9 @@ extern void UnloadFontDefault(void)
|
|||
if (isGpuReady) UnloadTexture(defaultFont.texture);
|
||||
RL_FREE(defaultFont.glyphs);
|
||||
RL_FREE(defaultFont.recs);
|
||||
defaultFont.glyphCount = 0;
|
||||
defaultFont.glyphs = NULL;
|
||||
defaultFont.recs = NULL;
|
||||
}
|
||||
#endif // SUPPORT_DEFAULT_FONT
|
||||
|
||||
|
@ -985,7 +1007,7 @@ bool ExportFontAsCode(Font font, const char *fileName)
|
|||
byteCount += sprintf(txtData + byteCount, "// more info and bugs-report: github.com/raysan5/raylib //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// feedback and support: ray[at]raylib.com //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// Copyright (c) 2018-2024 Ramon Santamaria (@raysan5) //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// Copyright (c) 2018-2025 Ramon Santamaria (@raysan5) //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// ---------------------------------------------------------------------------------- //\n");
|
||||
byteCount += sprintf(txtData + byteCount, "// //\n");
|
||||
|
@ -1071,7 +1093,7 @@ bool ExportFontAsCode(Font font, const char *fileName)
|
|||
byteCount += sprintf(txtData + byteCount, " Image imFont = { fontImageData_%s, %i, %i, 1, %i };\n\n", styleName, image.width, image.height, image.format);
|
||||
#endif
|
||||
byteCount += sprintf(txtData + byteCount, " // Load texture from image\n");
|
||||
byteCount += sprintf(txtData + byteCount, " if (isGpuReady) font.texture = LoadTextureFromImage(imFont);\n");
|
||||
byteCount += sprintf(txtData + byteCount, " font.texture = LoadTextureFromImage(imFont);\n");
|
||||
#if defined(SUPPORT_COMPRESSED_FONT_ATLAS)
|
||||
byteCount += sprintf(txtData + byteCount, " UnloadImage(imFont); // Uncompressed data can be unloaded from memory\n\n");
|
||||
#endif
|
||||
|
@ -1282,7 +1304,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
|
|||
{
|
||||
Vector2 textSize = { 0 };
|
||||
|
||||
if ((isGpuReady && (font.texture.id == 0)) ||
|
||||
if ((isGpuReady && (font.texture.id == 0)) ||
|
||||
(text == NULL) || (text[0] == '\0')) return textSize; // Security check
|
||||
|
||||
int size = TextLength(text); // Get size in bytes of text
|
||||
|
@ -1339,6 +1361,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
|
|||
int GetGlyphIndex(Font font, int codepoint)
|
||||
{
|
||||
int index = 0;
|
||||
if (!IsFontValid(font)) return index;
|
||||
|
||||
#define SUPPORT_UNORDERED_CHARSET
|
||||
#if defined(SUPPORT_UNORDERED_CHARSET)
|
||||
|
@ -1535,27 +1558,27 @@ const char *TextSubtext(const char *text, int position, int length)
|
|||
|
||||
if (position >= textLength)
|
||||
{
|
||||
position = textLength - 1;
|
||||
length = 0;
|
||||
return buffer; //First char is already '\0' by memset
|
||||
}
|
||||
|
||||
if (length >= textLength) length = textLength;
|
||||
int maxLength = textLength - position;
|
||||
if (length > maxLength) length = maxLength;
|
||||
if (length >= MAX_TEXT_BUFFER_LENGTH) length = MAX_TEXT_BUFFER_LENGTH - 1;
|
||||
|
||||
// NOTE: Alternative: memcpy(buffer, text + position, length)
|
||||
|
||||
for (int c = 0 ; c < length ; c++)
|
||||
{
|
||||
*(buffer + c) = *(text + position);
|
||||
text++;
|
||||
buffer[c] = text[position + c];
|
||||
}
|
||||
|
||||
*(buffer + length) = '\0';
|
||||
buffer[length] = '\0';
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// Replace text string
|
||||
// REQUIRES: strlen(), strstr(), strncpy(), strcpy()
|
||||
// REQUIRES: strstr(), strncpy(), strcpy()
|
||||
// WARNING: Allocated memory must be manually freed
|
||||
char *TextReplace(const char *text, const char *replace, const char *by)
|
||||
{
|
||||
|
@ -1624,7 +1647,7 @@ char *TextInsert(const char *text, const char *insert, int position)
|
|||
|
||||
// Join text strings with delimiter
|
||||
// REQUIRES: memset(), memcpy()
|
||||
const char *TextJoin(const char **textList, int count, const char *delimiter)
|
||||
char *TextJoin(char **textList, int count, const char *delimiter)
|
||||
{
|
||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||
|
@ -1658,7 +1681,7 @@ const char *TextJoin(const char **textList, int count, const char *delimiter)
|
|||
|
||||
// Split string into multiple strings
|
||||
// REQUIRES: memset()
|
||||
const char **TextSplit(const char *text, char delimiter, int *count)
|
||||
char **TextSplit(const char *text, char delimiter, int *count)
|
||||
{
|
||||
// NOTE: Current implementation returns a copy of the provided string with '\0' (string end delimiter)
|
||||
// inserted between strings defined by "delimiter" parameter. No memory is dynamically allocated,
|
||||
|
@ -1666,7 +1689,7 @@ const char **TextSplit(const char *text, char delimiter, int *count)
|
|||
// 1. Maximum number of possible split strings is set by MAX_TEXTSPLIT_COUNT
|
||||
// 2. Maximum size of text to split is MAX_TEXT_BUFFER_LENGTH
|
||||
|
||||
static const char *result[MAX_TEXTSPLIT_COUNT] = { NULL };
|
||||
static char *result[MAX_TEXTSPLIT_COUNT] = { NULL };
|
||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||
|
||||
|
@ -1722,7 +1745,7 @@ int TextFindIndex(const char *text, const char *find)
|
|||
// Get upper case version of provided string
|
||||
// WARNING: Limited functionality, only basic characters set
|
||||
// TODO: Support UTF-8 diacritics to upper-case, check codepoints
|
||||
const char *TextToUpper(const char *text)
|
||||
char *TextToUpper(const char *text)
|
||||
{
|
||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||
|
@ -1741,7 +1764,7 @@ const char *TextToUpper(const char *text)
|
|||
|
||||
// Get lower case version of provided string
|
||||
// WARNING: Limited functionality, only basic characters set
|
||||
const char *TextToLower(const char *text)
|
||||
char *TextToLower(const char *text)
|
||||
{
|
||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||
|
@ -1760,7 +1783,7 @@ const char *TextToLower(const char *text)
|
|||
|
||||
// Get Pascal case notation version of provided string
|
||||
// WARNING: Limited functionality, only basic characters set
|
||||
const char *TextToPascal(const char *text)
|
||||
char *TextToPascal(const char *text)
|
||||
{
|
||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||
|
@ -1788,7 +1811,7 @@ const char *TextToPascal(const char *text)
|
|||
|
||||
// Get snake case notation version of provided string
|
||||
// WARNING: Limited functionality, only basic characters set
|
||||
const char *TextToSnake(const char *text)
|
||||
char *TextToSnake(const char *text)
|
||||
{
|
||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = {0};
|
||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||
|
@ -1816,7 +1839,7 @@ const char *TextToSnake(const char *text)
|
|||
|
||||
// Get Camel case notation version of provided string
|
||||
// WARNING: Limited functionality, only basic characters set
|
||||
const char *TextToCamel(const char *text)
|
||||
char *TextToCamel(const char *text)
|
||||
{
|
||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = {0};
|
||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||
|
@ -1910,7 +1933,7 @@ void UnloadCodepoints(int *codepoints)
|
|||
int GetCodepointCount(const char *text)
|
||||
{
|
||||
unsigned int length = 0;
|
||||
char *ptr = (char *)&text[0];
|
||||
const char *ptr = text;
|
||||
|
||||
while (*ptr != '\0')
|
||||
{
|
||||
|
@ -2324,9 +2347,9 @@ static Font LoadBMFont(const char *fileName)
|
|||
// Convert hexadecimal to decimal (single digit)
|
||||
static unsigned char HexToInt(char hex)
|
||||
{
|
||||
if (hex >= '0' && hex <= '9') return hex - '0';
|
||||
else if (hex >= 'a' && hex <= 'f') return hex - 'a' + 10;
|
||||
else if (hex >= 'A' && hex <= 'F') return hex - 'A' + 10;
|
||||
if ((hex >= '0') && (hex <= '9')) return hex - '0';
|
||||
else if ((hex >= 'a') && (hex <= 'f')) return hex - 'a' + 10;
|
||||
else if ((hex >= 'A') && (hex <= 'F')) return hex - 'A' + 10;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue