Adafruit font system uses other ascii code table?

I try to build bw pixel fonts with some tools:
https://oleddisplay.squix.ch/
https://tchapi.github.io/Adafruit-GFX-Font-Customiser/

The last one ist the official GFX-Font Customizer for Adafruits own pixel fonts. This editor shows me the following char:

The Ascii-Code of this char should be 0xF6 = 246. But this font don't show this character if I display texts with "ö" inside (for example with the GxEPD2 library and display.print). So I checked the char value. I wonder if I get 195 and not 246. What is the problem? Why the Adafruit font system don't match with the code table that the Arduino IDE (or the hardware, ESP32) uses?

void setup() {
  Serial.begin(115200);
  String test = "ö";
  int code = test.charAt(0);
  Serial.println(code); // returns 195, should be 246 (0xF6)
}

void loop() {}

Maybe the string? Are strings stored in unicode format? But if I use chars, the same problem happens:

void setup() {
  Serial.begin(115200);
  char text[] = "äöüÄÖÜß";
  for (int index = 0; index < 7; index++) {
    int code = text[index];
    Serial.println(code);
  }
}

void loop() {}

output:
195 (ä)
164 (ö)
195 (ü)
182 (Ä)
195 (Ö)
188 (Ü)
195 (ß)

Why every second char value is 195? Now I'm totally confused. Does the char type use more than 1 byte per character?

The real question is: how does the Arduino IDE treat extended ASCII characters?

The Adafruit forum would be a better place to ask about Adafruit fonts and graphics.

Try

Serial.println(strlen(text));

Then read about UTF-8 encoding

Because Arduino IDE uses utf8 encoding with two-bytes chars.

Adafruit itself doesn't support a UTF8 code page, you need to encode your text from UTF8 to upper half of ASCII table before printing.

My quick and dirty workaround for the font functionalites of GxEPD2 (or Adafruit GFX) is to replace the unicode stored characters (äöü) with the old ASCII mapping. Then the string is no longer readable or printable, but display.print(text) works as expected with the used font:

#include <GxEPD2_BW.h>

void ReplaceUmlauts(String &text) {
  char mychar;
  mychar = 228; text.replace("ä", String(mychar));
  mychar = 246; text.replace("ö", String(mychar));
  mychar = 252; text.replace("ü", String(mychar));
  mychar = 196; text.replace("Ä", String(mychar));
  mychar = 214; text.replace("Ö", String(mychar));
  mychar = 220; text.replace("Ü", String(mychar));
  mychar = 223; text.replace("ß", String(mychar));
}

void setup() {
...
  String mystring = "Eine ältere Möhre auf dem Öfchen";
  ReplaceUmlauts(mystring); // Replace Unicode Umlauts with old ASCII values
  display.setCursor(10, 10);
  display.print(text);
...
}

It would be better to look chars 195 in text and replace it and next char to the "old ASCII" one.

See my function to recode UTF8 Cyrillic code page:

int utf8_cyr(char* dest, const unsigned char* src) {
  
  uint16_t i, j;
  for ( i =0, j =0; src[i]; i++) {
   if ((src[i] == 0xD0 )&& src[i+1])  { dest[j++] = src[++i] - 0x10;}
    else if ((src[i] == 0xD1 )&& src[i+1]) {dest[j++] = src[++i] + 0x30;  }
    else dest[j++] = src[i];
  }
  dest[j] ='\0';
  return j;
}

And of course there is GxEPD2_U8G2_Fonts_Example, if you open your eyes wide enough.

It seems this example uses specific font files...

Two of the many fonts u8g2 provides, yes.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.