mirror of
				https://github.com/raysan5/raylib.git
				synced 2025-10-26 12:27:01 +00:00 
			
		
		
		
	ADDED: GetCodepoints()
Get the unicode equivalent characters (as int array) from a UTF-8 text array... maybe this function is renamed to be clearer to users...
This commit is contained in:
		| @@ -1188,8 +1188,8 @@ RLAPI void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontS | |||||||
| RLAPI int MeasureText(const char *text, int fontSize);                                      // Measure string width for default font | RLAPI int MeasureText(const char *text, int fontSize);                                      // Measure string width for default font | ||||||
| RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing);    // Measure string size for Font | RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing);    // Measure string size for Font | ||||||
| RLAPI int GetGlyphIndex(Font font, int character);                                          // Get index position for a unicode character on font | RLAPI int GetGlyphIndex(Font font, int character);                                          // Get index position for a unicode character on font | ||||||
| RLAPI int GetNextCodepoint(const char *text, int *bytesProcessed);                          // Returns next codepoint in a UTF8 encoded string | RLAPI int GetNextCodepoint(const char *text, int *bytesProcessed);                          // Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure | ||||||
|                                                                                             // NOTE: 0x3f('?') is returned on failure | RLAPI int *GetCodepoints(const char *text, int *count);                                     // Get all codepoints in a string, codepoints count returned by parameters | ||||||
|  |  | ||||||
| // Text strings management functions | // Text strings management functions | ||||||
| // NOTE: Some strings allocate memory internally for returned strings, just be careful! | // NOTE: Some strings allocate memory internally for returned strings, just be careful! | ||||||
|   | |||||||
							
								
								
									
										22
									
								
								src/text.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/text.c
									
									
									
									
									
								
							| @@ -65,6 +65,8 @@ | |||||||
| //---------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------- | ||||||
| #define MAX_TEXT_BUFFER_LENGTH  1024        // Size of internal static buffers of some Text*() functions | #define MAX_TEXT_BUFFER_LENGTH  1024        // Size of internal static buffers of some Text*() functions | ||||||
|  |  | ||||||
|  | #define MAX_TEXT_UNICODE_CHARS   512        // Maximum number of unicode codepoints | ||||||
|  |  | ||||||
| //---------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------- | ||||||
| // Types and Structures Definition | // Types and Structures Definition | ||||||
| //---------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------- | ||||||
| @@ -869,6 +871,26 @@ int GetNextCodepoint(const char *text, int *bytesProcessed) | |||||||
|     return code; |     return code; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Get all codepoints in a string, codepoints count returned by parameters | ||||||
|  | int *GetCodepoints(const char *text, int *count) | ||||||
|  | { | ||||||
|  |     static int codepoints[MAX_TEXT_UNICODE_CHARS] = { 0 }; | ||||||
|  |     memset(codepoints, 0, MAX_TEXT_UNICODE_CHARS*sizeof(int)); | ||||||
|  |      | ||||||
|  |     int bytesProcessed = 0; | ||||||
|  |     int textLength = strlen(text); | ||||||
|  |     int codepointsCount = 0; | ||||||
|  |  | ||||||
|  |     for (int i = 0; i < textLength; codepointsCount++) | ||||||
|  |     { | ||||||
|  |         codepoints[codepointsCount] = GetNextCodepoint(text + i, &bytesProcessed); | ||||||
|  |         i += bytesProcessed; | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     return codepoints; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| // Draw text (using default font) | // Draw text (using default font) | ||||||
| // NOTE: fontSize work like in any drawing program but if fontSize is lower than font-base-size, then font-base-size is used | // NOTE: fontSize work like in any drawing program but if fontSize is lower than font-base-size, then font-base-size is used | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ray
					Ray