Skip to content

Commit 39c2bb8

Browse files
committed
getTextBounds counts the last line width too
In the default 5x7 font handling, the last line isn't considered when determining the longest line. Also, for the same reason, when there is only one line, getTextBounds returns 65535 as the width.
1 parent 987e912 commit 39c2bb8

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Adafruit_GFX.cpp

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ void Adafruit_GFX::getTextBounds(char *str, int16_t x, int16_t y,
748748
}
749749
// End of string
750750
if(lineWidth) y += textsize * 8; // Add height of last (or only) line
751+
if(lineWidth > maxWidth) maxWidth = lineWidth; // Is the last or only line the widest?
751752
*w = maxWidth - 1; // Don't include last interchar x gap
752753
*h = y - *y1;
753754

@@ -837,6 +838,7 @@ void Adafruit_GFX::getTextBounds(const __FlashStringHelper *str,
837838
}
838839
// End of string
839840
if(lineWidth) y += textsize * 8; // Add height of last (or only) line
841+
if(lineWidth > maxWidth) maxWidth = lineWidth; // Is the last or only line the widest?
840842
*w = maxWidth - 1; // Don't include last interchar x gap
841843
*h = y - *y1;
842844

0 commit comments

Comments
 (0)