From 7efed56b664d3caf8af01ae017fb3585123997f6 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 9 May 2020 12:38:33 +0200 Subject: [PATCH] Added [text] flag: SUPPORT_TEXT_MANIPULATION --- src/config.h | 6 ++- src/text.c | 147 +++++++++++++++++++++++++-------------------------- 2 files changed, 78 insertions(+), 75 deletions(-) diff --git a/src/config.h b/src/config.h index 7650e08c1..5b28a934b 100644 --- a/src/config.h +++ b/src/config.h @@ -102,7 +102,7 @@ // Support procedural image generation functionality (gradient, spot, perlin-noise, cellular) #define SUPPORT_IMAGE_GENERATION 1 // Support multiple image editing functions to scale, adjust colors, flip, draw on images, crop... -// If not defined only three image editing functions supported: ImageFormat(), ImageCrop(), ImageToPOT() +// If not defined, still some functions are supported: ImageFormat(), ImageCrop(), ImageToPOT() #define SUPPORT_IMAGE_MANIPULATION 1 // Support drawing on image (software rendering) #define SUPPORT_IMAGE_DRAWING 1 @@ -117,6 +117,10 @@ #define SUPPORT_FILEFORMAT_FNT 1 #define SUPPORT_FILEFORMAT_TTF 1 +// Support text management functions +// If not defined, still some functions are supported: TextLength(), TextFormat() +#define SUPPORT_TEXT_MANIPULATION 1 + //------------------------------------------------------------------------------------ // Module: models - Configuration Flags //------------------------------------------------------------------------------------ diff --git a/src/text.c b/src/text.c index 8439472d8..f5331ee09 100644 --- a/src/text.c +++ b/src/text.c @@ -1093,40 +1093,6 @@ int GetGlyphIndex(Font font, int codepoint) //---------------------------------------------------------------------------------- // Text strings management functions //---------------------------------------------------------------------------------- - -// Copy one string to another, returns bytes copied -int TextCopy(char *dst, const char *src) -{ - int bytes = 0; - - if (dst != NULL) - { - while (*src != '\0') - { - *dst = *src; - dst++; - src++; - - bytes++; - } - - *dst = '\0'; - } - - return bytes; -} - -// Check if two text string are equal -// REQUIRES: strcmp() -bool TextIsEqual(const char *text1, const char *text2) -{ - bool result = false; - - if (strcmp(text1, text2) == 0) result = true; - - return result; -} - // Get text length in bytes, check for \0 character unsigned int TextLength(const char *text) { @@ -1166,6 +1132,40 @@ const char *TextFormat(const char *text, ...) return currentBuffer; } +#if defined(SUPPORT_TEXT_MANIPULATION) +// Copy one string to another, returns bytes copied +int TextCopy(char *dst, const char *src) +{ + int bytes = 0; + + if (dst != NULL) + { + while (*src != '\0') + { + *dst = *src; + dst++; + src++; + + bytes++; + } + + *dst = '\0'; + } + + return bytes; +} + +// Check if two text string are equal +// REQUIRES: strcmp() +bool TextIsEqual(const char *text1, const char *text2) +{ + bool result = false; + + if (strcmp(text1, text2) == 0) result = true; + + return result; +} + // Get a piece of a text string const char *TextSubtext(const char *text, int position, int length) { @@ -1457,6 +1457,44 @@ char *TextToUtf8(int *codepoints, int length) return text; } +// Encode codepoint into utf8 text (char array length returned as parameter) +RLAPI const char *CodepointToUtf8(int codepoint, int *byteLength) +{ + static char utf8[6] = { 0 }; + int length = 0; + + if (codepoint <= 0x7f) + { + utf8[0] = (char)codepoint; + length = 1; + } + else if (codepoint <= 0x7ff) + { + utf8[0] = (char)(((codepoint >> 6) & 0x1f) | 0xc0); + utf8[1] = (char)((codepoint & 0x3f) | 0x80); + length = 2; + } + else if (codepoint <= 0xffff) + { + utf8[0] = (char)(((codepoint >> 12) & 0x0f) | 0xe0); + utf8[1] = (char)(((codepoint >> 6) & 0x3f) | 0x80); + utf8[2] = (char)((codepoint & 0x3f) | 0x80); + length = 3; + } + else if (codepoint <= 0x10ffff) + { + utf8[0] = (char)(((codepoint >> 18) & 0x07) | 0xf0); + utf8[1] = (char)(((codepoint >> 12) & 0x3f) | 0x80); + utf8[2] = (char)(((codepoint >> 6) & 0x3f) | 0x80); + utf8[3] = (char)((codepoint & 0x3f) | 0x80); + length = 4; + } + + *byteLength = length; + + return utf8; +} + // Get all codepoints in a string, codepoints count returned by parameters int *GetCodepoints(const char *text, int *count) { @@ -1498,7 +1536,7 @@ int GetCodepointsCount(const char *text) return len; } - +#endif // SUPPORT_TEXT_MANIPULATION // Returns next codepoint in a UTF8 encoded text, scanning until '\0' is found // When a invalid UTF8 byte is encountered we exit as soon as possible and a '?'(0x3f) codepoint is returned @@ -1612,45 +1650,6 @@ int GetNextCodepoint(const char *text, int *bytesProcessed) return code; } -// Encode codepoint into utf8 text (char array length returned as parameter) -RLAPI const char *CodepointToUtf8(int codepoint, int *byteLength) -{ - static char utf8[6] = { 0 }; - int length = 0; - - if (codepoint <= 0x7f) - { - utf8[0] = (char)codepoint; - length = 1; - } - else if (codepoint <= 0x7ff) - { - utf8[0] = (char)(((codepoint >> 6) & 0x1f) | 0xc0); - utf8[1] = (char)((codepoint & 0x3f) | 0x80); - length = 2; - } - else if (codepoint <= 0xffff) - { - utf8[0] = (char)(((codepoint >> 12) & 0x0f) | 0xe0); - utf8[1] = (char)(((codepoint >> 6) & 0x3f) | 0x80); - utf8[2] = (char)((codepoint & 0x3f) | 0x80); - length = 3; - } - else if (codepoint <= 0x10ffff) - { - utf8[0] = (char)(((codepoint >> 18) & 0x07) | 0xf0); - utf8[1] = (char)(((codepoint >> 12) & 0x3f) | 0x80); - utf8[2] = (char)(((codepoint >> 6) & 0x3f) | 0x80); - utf8[3] = (char)((codepoint & 0x3f) | 0x80); - length = 4; - } - - *byteLength = length; - - return utf8; -} -//---------------------------------------------------------------------------------- - //---------------------------------------------------------------------------------- // Module specific Functions Definition //----------------------------------------------------------------------------------