From 6024b8e05b7780e9c7ffd31a9323f83d5a8665c7 Mon Sep 17 00:00:00 2001 From: Soutekh Date: Mon, 21 Jun 2021 18:24:28 +0200 Subject: [PATCH] fix text wrapping --- src/text.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/text.c b/src/text.c index e18afe41e..138fc2aed 100644 --- a/src/text.c +++ b/src/text.c @@ -929,9 +929,10 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f int glyphWidth = 0; if (codepoint != '\n') { - glyphWidth = (font.chars[index].advanceX == 0)? - (int)(font.recs[index].width*scaleFactor + spacing): - (int)(font.chars[index].advanceX*scaleFactor + spacing); + glyphWidth = (font.chars[index].advanceX == 0) ? (int)(font.recs[index].width) : (int)(font.chars[index].advanceX); + + if (i + 1 < length) + glyphWidth = glyphWidth * scaleFactor + spacing; } // NOTE: When wordWrap is ON we first measure how much of the text we can draw before going outside of the rec container @@ -945,7 +946,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f // Ref: http://jkorpela.fi/chars/spaces.html if ((codepoint == ' ') || (codepoint == '\t') || (codepoint == '\n')) endLine = i; - if ((textOffsetX + glyphWidth + 1) >= rec.width) + if ((textOffsetX + glyphWidth) > rec.width) { endLine = (endLine < 1)? i : endLine; if (i == endLine) endLine -= codepointByteCount; @@ -985,7 +986,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f } else { - if (!wordWrap && ((textOffsetX + glyphWidth + 1) >= rec.width)) + if (!wordWrap && ((textOffsetX + glyphWidth) > rec.width)) { textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor); textOffsetX = 0;