Skip to content

Commit

Permalink
Merge pull request #1 from TadeuszKarpinski/enable-utf-8
Browse files Browse the repository at this point in the history
Add option to get charBounds of UTF-8 glyphs
  • Loading branch information
DoomHammer authored Feb 29, 2024
2 parents 3941d5a + 30904a6 commit b603151
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions Adafruit_GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ void Adafruit_GFX::setFont(const GFXfont *f) {
@param maxy Pointer to maximum Y coord, passed in AND returned.
*/
/**************************************************************************/
void Adafruit_GFX::charBounds(unsigned char c, int16_t *x, int16_t *y,
void Adafruit_GFX::charBounds(uint16_t c, int16_t *x, int16_t *y,
int16_t *minx, int16_t *miny, int16_t *maxx,
int16_t *maxy) {

Expand Down Expand Up @@ -1511,7 +1511,7 @@ void Adafruit_GFX::getTextBounds(const char *str, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w,
uint16_t *h) {

uint8_t c; // Current character
uint16_t c; // Current character
int16_t minx = 0x7FFF, miny = 0x7FFF, maxx = -1, maxy = -1; // Bound rect
// Bound rect is intentionally initialized inverted, so 1st char sets it

Expand All @@ -1520,6 +1520,14 @@ void Adafruit_GFX::getTextBounds(const char *str, int16_t x, int16_t y,
*w = *h = 0; // Initial size is zero

while ((c = *str++)) {
if (_utf8) {
c = decodeUTF8(c);
} else {
c = (uint16_t)c;
}
if (c == 0) {
continue;
}
// charBounds() modifies x/y to advance for each character,
// and min/max x/y are updated to incrementally build bounding rect.
charBounds(c, &x, &y, &minx, &miny, &maxx, &maxy);
Expand Down
2 changes: 1 addition & 1 deletion Adafruit_GFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class Adafruit_GFX : public Print {
int16_t getCursorY(void) const { return cursor_y; };

protected:
void charBounds(unsigned char c, int16_t *x, int16_t *y, int16_t *minx,
void charBounds(uint16_t c, int16_t *x, int16_t *y, int16_t *minx,
int16_t *miny, int16_t *maxx, int16_t *maxy);
int16_t WIDTH; ///< This is the 'raw' display width - never changes
int16_t HEIGHT; ///< This is the 'raw' display height - never changes
Expand Down

0 comments on commit b603151

Please sign in to comment.