Skip to content

Commit

Permalink
Merge pull request #68 from markwal/master
Browse files Browse the repository at this point in the history
Make custom fonts work on ESP8266 as well
  • Loading branch information
PaintYourDragon committed Jan 6, 2016
2 parents 987e912 + 0f2f325 commit 93dde8b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Adafruit_GFX.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ POSSIBILITY OF SUCH DAMAGE.
#include "glcdfont.c"
#ifdef __AVR__
#include <avr/pgmspace.h>
#define pgm_read_pointer(addr) ((void *)pgm_read_word(addr))
#elif defined(ESP8266)
#include <pgmspace.h>
#define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr))
#else
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
#define pgm_read_pointer(addr) ((void *)pgm_read_word(addr))
#endif

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

c -= pgm_read_byte(&gfxFont->first);
GFXglyph *glyph = &(((GFXglyph *)pgm_read_word(&gfxFont->glyph))[c]);
uint8_t *bitmap = (uint8_t *)pgm_read_word(&gfxFont->bitmap);
GFXglyph *glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]);
uint8_t *bitmap = (uint8_t *)pgm_read_pointer(&gfxFont->bitmap);

uint16_t bo = pgm_read_word(&glyph->bitmapOffset);
uint8_t w = pgm_read_byte(&glyph->width),
Expand Down Expand Up @@ -690,7 +693,7 @@ void Adafruit_GFX::getTextBounds(char *str, int16_t x, int16_t y,
if(c != '\r') { // Not a carriage return, is normal char
if((c >= first) && (c <= last)) { // Char present in current font
c -= first;
glyph = &(((GFXglyph *)pgm_read_word(&gfxFont->glyph))[c]);
glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]);
gw = pgm_read_byte(&glyph->width);
gh = pgm_read_byte(&glyph->height);
xa = pgm_read_byte(&glyph->xAdvance);
Expand Down Expand Up @@ -779,7 +782,7 @@ void Adafruit_GFX::getTextBounds(const __FlashStringHelper *str,
if(c != '\r') { // Not a carriage return, is normal char
if((c >= first) && (c <= last)) { // Char present in current font
c -= first;
glyph = &(((GFXglyph *)pgm_read_word(&gfxFont->glyph))[c]);
glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]);
gw = pgm_read_byte(&glyph->width);
gh = pgm_read_byte(&glyph->height);
xa = pgm_read_byte(&glyph->xAdvance);
Expand Down

0 comments on commit 93dde8b

Please sign in to comment.