فهرست منبع

Corrected issue with wrong text measuring

Ray 6 سال پیش
والد
کامیت
528e164ac5
1فایلهای تغییر یافته به همراه5 افزوده شده و 4 حذف شده
  1. 5 4
      src/text.c

+ 5 - 4
src/text.c

@@ -833,8 +833,8 @@ void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
 void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint)
 {
     int length = strlen(text);
-    int textOffsetX = 0;        // Offset between characters
     int textOffsetY = 0;        // Required for line break!
+    float textOffsetX = 0.0f;   // Offset between characters
     float scaleFactor = 0.0f;
 
     int letter = 0;             // Current character
@@ -856,7 +856,7 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f
         {
             // NOTE: Fixed line spacing of 1.5 lines
             textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor);
-            textOffsetX = 0;
+            textOffsetX = 0.0f;
         }
         else
         {
@@ -869,8 +869,8 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f
                                         font.chars[index].rec.height*scaleFactor }, (Vector2){ 0, 0 }, 0.0f, tint);
             }
 
-            if (font.chars[index].advanceX == 0) textOffsetX += (int)(font.chars[index].rec.width*scaleFactor + spacing);
-            else textOffsetX += (int)(font.chars[index].advanceX*scaleFactor + spacing);
+            if (font.chars[index].advanceX == 0) textOffsetX += ((float)font.chars[index].rec.width*scaleFactor + spacing);
+            else textOffsetX += ((float)font.chars[index].advanceX*scaleFactor + spacing);
         }
     }
 }
@@ -1053,6 +1053,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
         
         int next = 1;
         letter = GetNextCodepoint(&text[i], &next);
+
         // NOTE: normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
         // but we need to draw all of the bad bytes using the '?' symbol so to not skip any we set `next = 1`
         if(letter == 0x3f) next = 1;