Merge branch 'master' into font-size-points-option
This commit is contained in:
commit
0615d4a336
59 changed files with 579 additions and 2685 deletions
42
src/rtext.c
42
src/rtext.c
|
|
@ -58,8 +58,8 @@
|
|||
#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2 -> Only DrawTextPro()
|
||||
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
#include <stdio.h> // Required for: vsprintf()
|
||||
#include <string.h> // Required for: strcmp(), strstr(), strncpy() [Used in TextReplace()], sscanf() [Used in LoadBMFont()]
|
||||
#include <stdio.h> // Required for: vsprintf(), snprintf()
|
||||
#include <string.h> // Required for: strcmp(), strstr(), strncpy(), sscanf() [Used in LoadBMFont()]
|
||||
#include <stdarg.h> // Required for: va_list, va_start(), vsprintf(), va_end() [Used in TextFormat()]
|
||||
#include <ctype.h> // Required for: toupper(), tolower() [Used in TextToUpper(), TextToLower()]
|
||||
|
||||
|
|
@ -539,7 +539,7 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int
|
|||
Font font = { 0 };
|
||||
|
||||
char fileExtLower[16] = { 0 };
|
||||
strncpy(fileExtLower, TextToLower(fileType), 16 - 1);
|
||||
snprintf(fileExtLower, 16, "%s", TextToLower(fileType));
|
||||
|
||||
font.baseSize = fontSize;
|
||||
font.glyphPadding = 0;
|
||||
|
|
@ -1043,7 +1043,7 @@ bool ExportFontAsCode(Font font, const char *fileName)
|
|||
|
||||
// Get file name from path
|
||||
char fileNamePascal[256] = { 0 };
|
||||
strncpy(fileNamePascal, TextToPascal(GetFileNameWithoutExt(fileName)), 256 - 1);
|
||||
snprintf(fileNamePascal, 256, "%s", TextToPascal(GetFileNameWithoutExt(fileName)));
|
||||
|
||||
// Get font atlas image and size, required to estimate code file size
|
||||
// NOTE: This mechanism is highly coupled to raylib
|
||||
|
|
@ -1545,7 +1545,7 @@ char **LoadTextLines(const char *text, int *count)
|
|||
if ((text[i] == '\n') || (text[i] == '\0'))
|
||||
{
|
||||
lines[l] = (char *)RL_CALLOC(lineLen + 1, 1);
|
||||
strncpy(lines[l], &text[i - lineLen], lineLen);
|
||||
memcpy(lines[l], &text[i - lineLen], lineLen);
|
||||
lineLen = 0;
|
||||
l++;
|
||||
}
|
||||
|
|
@ -1712,7 +1712,7 @@ const char *TextSubtext(const char *text, int position, int length)
|
|||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||
|
||||
if (text != NULL)
|
||||
if ((text != NULL) && (position >= 0) && (length > 0))
|
||||
{
|
||||
int textLength = TextLength(text);
|
||||
|
||||
|
|
@ -1768,8 +1768,8 @@ char *GetTextBetween(const char *text, const char *begin, const char *end)
|
|||
{
|
||||
endIndex += (beginIndex + beginLen);
|
||||
int len = (endIndex - beginIndex - beginLen);
|
||||
if (len < (MAX_TEXT_BUFFER_LENGTH - 1)) strncpy(buffer, text + beginIndex + beginLen, len);
|
||||
else strncpy(buffer, text + beginIndex + beginLen, MAX_TEXT_BUFFER_LENGTH - 1);
|
||||
if (len < (MAX_TEXT_BUFFER_LENGTH - 1)) memcpy(buffer, text + beginIndex + beginLen, len);
|
||||
else snprintf(buffer, MAX_TEXT_BUFFER_LENGTH, "%s", text + beginIndex + beginLen);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1777,7 +1777,7 @@ char *GetTextBetween(const char *text, const char *begin, const char *end)
|
|||
}
|
||||
|
||||
// Replace text string
|
||||
// REQUIRES: strstr(), strncpy()
|
||||
// REQUIRES: strstr(), memcpy()
|
||||
// NOTE: Limited text replace functionality, using static string
|
||||
char *TextReplace(const char *text, const char *search, const char *replacement)
|
||||
{
|
||||
|
|
@ -1834,7 +1834,7 @@ char *TextReplace(const char *text, const char *search, const char *replacement)
|
|||
|
||||
// Copy remaind text part after replacement to result (pointed by moving temp)
|
||||
// NOTE: Text pointer internal copy has been updated along the process
|
||||
strncpy(tempPtr, text, TextLength(text));
|
||||
memcpy(tempPtr, text, TextLength(text));
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "Text with replacement is longer than internal buffer, use TextReplaceAlloc()");
|
||||
}
|
||||
|
|
@ -1843,7 +1843,7 @@ char *TextReplace(const char *text, const char *search, const char *replacement)
|
|||
}
|
||||
|
||||
// Replace text string
|
||||
// REQUIRES: strstr(), strncpy()
|
||||
// REQUIRES: strstr(), memcpy()
|
||||
// WARNING: Allocated memory must be manually freed
|
||||
char *TextReplaceAlloc(const char *text, const char *search, const char *replacement)
|
||||
{
|
||||
|
|
@ -1900,7 +1900,7 @@ char *TextReplaceAlloc(const char *text, const char *search, const char *replace
|
|||
|
||||
// Copy remaind text part after replacement to result (pointed by moving temp)
|
||||
// NOTE: Text pointer internal copy has been updated along the process
|
||||
strncpy(temp, text, TextLength(text));
|
||||
memcpy(temp, text, TextLength(text));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1988,10 +1988,11 @@ char *TextInsert(const char *text, const char *insert, int position)
|
|||
{
|
||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||
int textLen = TextLength(text);
|
||||
|
||||
if ((text != NULL) && (insert != NULL))
|
||||
if ((text != NULL) && (insert != NULL) && (position >= 0))
|
||||
{
|
||||
int textLen = TextLength(text);
|
||||
if (position > textLen) position = textLen; // End of text string
|
||||
int insertLen = TextLength(insert);
|
||||
|
||||
if ((textLen + insertLen) < (MAX_TEXT_BUFFER_LENGTH - 1))
|
||||
|
|
@ -2000,7 +2001,7 @@ char *TextInsert(const char *text, const char *insert, int position)
|
|||
|
||||
for (int i = 0; i < position; i++) buffer[i] = text[i];
|
||||
for (int i = position; i < insertLen + position; i++) buffer[i] = insert[i - position];
|
||||
for (int i = (insertLen + position); i < (textLen + insertLen); i++) buffer[i] = text[i];
|
||||
for (int i = (insertLen + position); i < (textLen + insertLen); i++) buffer[i] = text[i - insertLen];
|
||||
|
||||
buffer[textLen + insertLen] = '\0'; // Add EOL
|
||||
}
|
||||
|
|
@ -2015,17 +2016,18 @@ char *TextInsert(const char *text, const char *insert, int position)
|
|||
char *TextInsertAlloc(const char *text, const char *insert, int position)
|
||||
{
|
||||
char *result = NULL;
|
||||
int textLen = TextLength(text);
|
||||
|
||||
if ((text != NULL) && (insert != NULL))
|
||||
if ((text != NULL) && (insert != NULL) && (position >= 0))
|
||||
{
|
||||
int textLen = TextLength(text);
|
||||
if (position > textLen) position = textLen; // End of text string
|
||||
int insertLen = TextLength(insert);
|
||||
|
||||
result = (char *)RL_MALLOC(textLen + insertLen + 1);
|
||||
|
||||
for (int i = 0; i < position; i++) result[i] = text[i];
|
||||
for (int i = position; i < insertLen + position; i++) result[i] = insert[i - position];
|
||||
for (int i = (insertLen + position); i < (textLen + insertLen); i++) result[i] = text[i];
|
||||
for (int i = position; i < (insertLen + position); i++) result[i] = insert[i - position];
|
||||
for (int i = (insertLen + position); i < (textLen + insertLen); i++) result[i] = text[i - insertLen];
|
||||
|
||||
result[textLen + insertLen] = '\0'; // Add EOL
|
||||
}
|
||||
|
|
@ -2049,7 +2051,7 @@ char *TextJoin(char **textList, int count, const char *delimiter)
|
|||
int textLength = TextLength(textList[i]);
|
||||
|
||||
// Make sure joined text could fit inside MAX_TEXT_BUFFER_LENGTH
|
||||
if ((totalLength + textLength) < MAX_TEXT_BUFFER_LENGTH)
|
||||
if ((totalLength + textLength + delimiterLen) < MAX_TEXT_BUFFER_LENGTH)
|
||||
{
|
||||
memcpy(textPtr, textList[i], textLength);
|
||||
totalLength += textLength;
|
||||
|
|
|
|||
Loading…
Reference in a new issue