adafruit / Adafruit-GFX-Library

Adafruit GFX graphics core Arduino library, this is the 'core' class that all our other graphics libraries derive from
https://learn.adafruit.com/adafruit-gfx-graphics-library
Other
2.37k stars 1.54k forks source link

Degree symbol with TomThumb font #144

Open inrepublica opened 6 years ago

inrepublica commented 6 years ago

I'm trying to use TomThumb with my little project. I use a wemos d1 mini pro (ESP8266) and the wemos OLED shield (64*48 SSD1306). Here is my project -> my project

When i use the default font no problem degree symbol is used:

  display.setFont();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,10);
  display.print(t);display.print("\xA7");display.print(" ");display.print(h);display.print("%");

But when i use the tomthumb font, nothing is displayed:

display.setFont(&TomThumb);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,47);
display.print(t);display.print("\xB0");display.print(" ");display.print(h);display.print("%");
display.display();

image

Sorry for my bad english ;-(

baryluk commented 6 years ago

FYI. There is TomThumb in the official repos, so try including that. And before including, make sure to do

#define TOMTHUMB_USE_EXTENDED 1

it will use a bit more space, but give you some more characters, including degree symbol.

I still do not know why there is a vertical line below degree symbol tho.

romainreignier commented 6 years ago

I have tried to print extended characters from TomThumb font too. After modifying the TomThumb.h to change from:

#define TOMTHUMB_USE_EXTENDED 0

to

#define TOMTHUMB_USE_EXTENDED 1

I did not get any character print for extended values. Does anyone have the same issue?

See the picture of the following code:

  display.setFont(&TomThumb);
  display.setTextWrap(true);
  for(int i = 32; i < 256; ++i)
  {
    display.print(i);
    display.print(": '");
    display.write(i);
    display.print("', ");
  }
  display.display();

img_20180819_141135

baryluk commented 5 years ago

I have tried to print extended characters from TomThumb font too. After modifying the TomThumb.h to change from:

#define TOMTHUMB_USE_EXTENDED 0

to

#define TOMTHUMB_USE_EXTENDED 1

I did not get any character print for extended values. Does anyone have the same issue?

Try also changing last line of TomThumb.h file from 0x7F to 0xFF (or higher, i.e. 0xFFFD, if you need even more extended fonts from this set. I am not sure how they look up in this table, but I am assuming using binary search).

https://github.com/adafruit/Adafruit-GFX-Library/blob/master/Fonts/TomThumb.h#L474

Spartrap commented 3 weeks ago

This is an old thread but as the situation is still the same, I'll add some remarks:

Here is a snippet I use to fix it:

// the TomThumb font is shipped with Adafruit GFX, and is the only official font that has extended characters
// but it's somewhat quirky: it misses chars from 0x7E to 0xA1.
// It also has a dozen extra chars above 0xff that I didn't bother to add except for the Euro symbol
if (applyTomThumbShift) {
  out = (unsigned char *)output;
  while (*out) {
    if (*out > 0xA0U)
      if (*out == 0xA4U)
         *out = 0xEAU; // add Euro char €
       else
         *out -= 0x22U; // shift the codepoint to make up for the gap
    else if (*out > 0x7EU)
      *out = 0x20U; // missing characters. Convert to space.
    out++;
  }
}

Also, as mentioned, on top of the TOMTHUMB_USE_EXTENDED flag, you have to modify the last line of TomThumb.h :

const GFXfont TomThumb PROGMEM = {(uint8_t )TomThumbBitmaps, (GFXglyph )TomThumbGlyphs, 0x20, 0xEA, 6};

HIH.