Skip to content

Commit 93dde8b

Browse files
Merge pull request #68 from markwal/master
Make custom fonts work on ESP8266 as well
2 parents 987e912 + 0f2f325 commit 93dde8b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Adafruit_GFX.cpp

100644100755
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ POSSIBILITY OF SUCH DAMAGE.
3535
#include "glcdfont.c"
3636
#ifdef __AVR__
3737
#include <avr/pgmspace.h>
38+
#define pgm_read_pointer(addr) ((void *)pgm_read_word(addr))
3839
#elif defined(ESP8266)
3940
#include <pgmspace.h>
41+
#define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr))
4042
#else
4143
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
4244
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
45+
#define pgm_read_pointer(addr) ((void *)pgm_read_word(addr))
4346
#endif
4447

4548
#ifndef min
@@ -474,7 +477,7 @@ void Adafruit_GFX::write(uint8_t c) {
474477
uint8_t first = pgm_read_byte(&gfxFont->first);
475478
if((c >= first) && (c <= (uint8_t)pgm_read_byte(&gfxFont->last))) {
476479
uint8_t c2 = c - pgm_read_byte(&gfxFont->first);
477-
GFXglyph *glyph = &(((GFXglyph *)pgm_read_word(&gfxFont->glyph))[c2]);
480+
GFXglyph *glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c2]);
478481
uint8_t w = pgm_read_byte(&glyph->width),
479482
h = pgm_read_byte(&glyph->height);
480483
if((w > 0) && (h > 0)) { // Is there an associated bitmap?
@@ -533,8 +536,8 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
533536
// directly with 'bad' characters of font may cause mayhem!
534537

535538
c -= pgm_read_byte(&gfxFont->first);
536-
GFXglyph *glyph = &(((GFXglyph *)pgm_read_word(&gfxFont->glyph))[c]);
537-
uint8_t *bitmap = (uint8_t *)pgm_read_word(&gfxFont->bitmap);
539+
GFXglyph *glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]);
540+
uint8_t *bitmap = (uint8_t *)pgm_read_pointer(&gfxFont->bitmap);
538541

539542
uint16_t bo = pgm_read_word(&glyph->bitmapOffset);
540543
uint8_t w = pgm_read_byte(&glyph->width),
@@ -690,7 +693,7 @@ void Adafruit_GFX::getTextBounds(char *str, int16_t x, int16_t y,
690693
if(c != '\r') { // Not a carriage return, is normal char
691694
if((c >= first) && (c <= last)) { // Char present in current font
692695
c -= first;
693-
glyph = &(((GFXglyph *)pgm_read_word(&gfxFont->glyph))[c]);
696+
glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]);
694697
gw = pgm_read_byte(&glyph->width);
695698
gh = pgm_read_byte(&glyph->height);
696699
xa = pgm_read_byte(&glyph->xAdvance);
@@ -779,7 +782,7 @@ void Adafruit_GFX::getTextBounds(const __FlashStringHelper *str,
779782
if(c != '\r') { // Not a carriage return, is normal char
780783
if((c >= first) && (c <= last)) { // Char present in current font
781784
c -= first;
782-
glyph = &(((GFXglyph *)pgm_read_word(&gfxFont->glyph))[c]);
785+
glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]);
783786
gw = pgm_read_byte(&glyph->width);
784787
gh = pgm_read_byte(&glyph->height);
785788
xa = pgm_read_byte(&glyph->xAdvance);

0 commit comments

Comments
 (0)