mirror of
				https://github.com/raysan5/raylib.git
				synced 2025-11-03 17:24:25 +00:00 
			
		
		
		
	Corrected issue with text measure on Latin-1 chars
Considering chars inputs come in UTF8 form!
This commit is contained in:
		
							
								
								
									
										19
									
								
								src/text.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/text.c
									
									
									
									
									
								
							@@ -935,13 +935,30 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
 | 
			
		||||
    float textHeight = (float)font.baseSize;
 | 
			
		||||
    float scaleFactor = fontSize/(float)font.baseSize;
 | 
			
		||||
 | 
			
		||||
    unsigned char letter = 0;       // Current character
 | 
			
		||||
    int index = 0;                  // Index position in sprite font
 | 
			
		||||
    
 | 
			
		||||
    for (int i = 0; i < len; i++)
 | 
			
		||||
    {
 | 
			
		||||
        lenCounter++;
 | 
			
		||||
        
 | 
			
		||||
        if (text[i] != '\n')
 | 
			
		||||
        {
 | 
			
		||||
            int index = GetGlyphIndex(font, (int)text[i]);
 | 
			
		||||
            if ((unsigned char)text[i] == 0xc2)         // UTF-8 encoding identification
 | 
			
		||||
            {
 | 
			
		||||
                // Support UTF-8 encoded values from [0xc2 0x80] -> [0xc2 0xbf](¿)
 | 
			
		||||
                letter = (unsigned char)text[i + 1];
 | 
			
		||||
                index = GetGlyphIndex(font, (int)letter);
 | 
			
		||||
                i++;
 | 
			
		||||
            }
 | 
			
		||||
            else if ((unsigned char)text[i] == 0xc3)    // UTF-8 encoding identification
 | 
			
		||||
            {
 | 
			
		||||
                // Support UTF-8 encoded values from [0xc3 0x80](À) -> [0xc3 0xbf](ÿ)
 | 
			
		||||
                letter = (unsigned char)text[i + 1];
 | 
			
		||||
                index = GetGlyphIndex(font, (int)letter + 64);
 | 
			
		||||
                i++;
 | 
			
		||||
            }
 | 
			
		||||
            else index = GetGlyphIndex(font, (unsigned char)text[i]);
 | 
			
		||||
 | 
			
		||||
            if (font.chars[index].advanceX != 0) textWidth += font.chars[index].advanceX;
 | 
			
		||||
            else textWidth += (font.chars[index].rec.width + font.chars[index].offsetX);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user