diff --git a/legacy/gen/font.inc b/legacy/gen/font.inc index e14089597..20a2ed555 100644 --- a/legacy/gen/font.inc +++ b/legacy/gen/font.inc @@ -1,35 +1,3 @@ - /* 0x00 _ */ (uint8_t *)"\x01\x00", - /* 0x01 _ */ (uint8_t *)"\x01\x00", - /* 0x02 _ */ (uint8_t *)"\x01\x00", - /* 0x03 _ */ (uint8_t *)"\x01\x00", - /* 0x04 _ */ (uint8_t *)"\x01\x00", - /* 0x05 _ */ (uint8_t *)"\x01\x00", - /* 0x06 _ */ (uint8_t *)"\x07\x18\x1c\x0e\x18\x30\x40\x80", - /* 0x07 _ */ (uint8_t *)"\x01\x00", - /* 0x08 _ */ (uint8_t *)"\x01\x00", - /* 0x09 _ */ (uint8_t *)"\x01\x00", - /* 0x0a _ */ (uint8_t *)"\x01\x00", - /* 0x0b _ */ (uint8_t *)"\x01\x00", - /* 0x0c _ */ (uint8_t *)"\x01\x00", - /* 0x0d _ */ (uint8_t *)"\x01\x00", - /* 0x0e _ */ (uint8_t *)"\x01\x00", - /* 0x0f _ */ (uint8_t *)"\x01\x00", - /* 0x10 _ */ (uint8_t *)"\x01\x00", - /* 0x11 _ */ (uint8_t *)"\x01\x00", - /* 0x12 _ */ (uint8_t *)"\x01\x00", - /* 0x13 _ */ (uint8_t *)"\x01\x00", - /* 0x14 _ */ (uint8_t *)"\x01\x00", - /* 0x15 _ */ (uint8_t *)"\x07\x44\xee\x7c\x38\x7c\xee\x44", - /* 0x16 _ */ (uint8_t *)"\x01\x00", - /* 0x17 _ */ (uint8_t *)"\x01\x00", - /* 0x18 _ */ (uint8_t *)"\x01\x00", - /* 0x19 _ */ (uint8_t *)"\x01\x00", - /* 0x1a _ */ (uint8_t *)"\x01\x00", - /* 0x1b _ */ (uint8_t *)"\x01\x00", - /* 0x1c _ */ (uint8_t *)"\x01\x00", - /* 0x1d _ */ (uint8_t *)"\x01\x00", - /* 0x1e _ */ (uint8_t *)"\x01\x00", - /* 0x1f _ */ (uint8_t *)"\x01\x00", /* 0x20 */ (uint8_t *)"\x01\x00", /* 0x21 ! */ (uint8_t *)"\x02\xfa\xfa", /* 0x22 " */ (uint8_t *)"\x03\xc0\x00\xc0", diff --git a/legacy/gen/fontfixed.inc b/legacy/gen/fontfixed.inc index 823d4b0a1..68d72aefa 100644 --- a/legacy/gen/fontfixed.inc +++ b/legacy/gen/fontfixed.inc @@ -1,35 +1,3 @@ - /* 0x00 _ */ (uint8_t *)"\x01\x00", - /* 0x01 _ */ (uint8_t *)"\x01\x00", - /* 0x02 _ */ (uint8_t *)"\x01\x00", - /* 0x03 _ */ (uint8_t *)"\x01\x00", - /* 0x04 _ */ (uint8_t *)"\x01\x00", - /* 0x05 _ */ (uint8_t *)"\x01\x00", - /* 0x06 _ */ (uint8_t *)"\x07\x18\x1c\x0e\x18\x30\x40\x80", - /* 0x07 _ */ (uint8_t *)"\x01\x00", - /* 0x08 _ */ (uint8_t *)"\x01\x00", - /* 0x09 _ */ (uint8_t *)"\x01\x00", - /* 0x0a _ */ (uint8_t *)"\x01\x00", - /* 0x0b _ */ (uint8_t *)"\x01\x00", - /* 0x0c _ */ (uint8_t *)"\x01\x00", - /* 0x0d _ */ (uint8_t *)"\x01\x00", - /* 0x0e _ */ (uint8_t *)"\x01\x00", - /* 0x0f _ */ (uint8_t *)"\x01\x00", - /* 0x10 _ */ (uint8_t *)"\x01\x00", - /* 0x11 _ */ (uint8_t *)"\x01\x00", - /* 0x12 _ */ (uint8_t *)"\x01\x00", - /* 0x13 _ */ (uint8_t *)"\x01\x00", - /* 0x14 _ */ (uint8_t *)"\x01\x00", - /* 0x15 _ */ (uint8_t *)"\x07\x44\xee\x7c\x38\x7c\xee\x44", - /* 0x16 _ */ (uint8_t *)"\x01\x00", - /* 0x17 _ */ (uint8_t *)"\x01\x00", - /* 0x18 _ */ (uint8_t *)"\x01\x00", - /* 0x19 _ */ (uint8_t *)"\x01\x00", - /* 0x1a _ */ (uint8_t *)"\x01\x00", - /* 0x1b _ */ (uint8_t *)"\x01\x00", - /* 0x1c _ */ (uint8_t *)"\x01\x00", - /* 0x1d _ */ (uint8_t *)"\x01\x00", - /* 0x1e _ */ (uint8_t *)"\x01\x00", - /* 0x1f _ */ (uint8_t *)"\x01\x00", /* 0x20 */ (uint8_t *)"\x01\x00", /* 0x21 ! */ (uint8_t *)"\x03\x60\xfa\x60", /* 0x22 " */ (uint8_t *)"\x05\x00\xe0\x00\xe0\x00", diff --git a/legacy/gen/fonts.c b/legacy/gen/fonts.c index 8e801953c..c41114b1a 100644 --- a/legacy/gen/fonts.c +++ b/legacy/gen/fonts.c @@ -1,6 +1,8 @@ #include "fonts.h" -const uint8_t *const font_data[2][128] = { +#define FONTS 2 + +const uint8_t *const font_data[FONTS][128 - 32] = { { #include "font.inc" }, @@ -9,8 +11,11 @@ const uint8_t *const font_data[2][128] = { }, }; -int fontCharWidth(int font, uint8_t c) { return font_data[font][c & 0x7f][0]; } - -const uint8_t *fontCharData(int font, uint8_t c) { - return font_data[font][c & 0x7f] + 1; +int fontCharWidth(uint8_t font, uint8_t c) { + return (c < 0x20 || c >= 0x80) ? 0 : font_data[font % FONTS][c - 32][0]; +} + +const uint8_t *fontCharData(uint8_t font, uint8_t c) { + return (c < 0x20 || c >= 0x80) ? (const uint8_t *)"" + : font_data[font % FONTS][c - 32] + 1; } diff --git a/legacy/gen/fonts.h b/legacy/gen/fonts.h index d08188f05..6d691aed0 100644 --- a/legacy/gen/fonts.h +++ b/legacy/gen/fonts.h @@ -8,9 +8,9 @@ #define FONT_FIXED 1 #define FONT_DOUBLE 0x80 -extern const uint8_t *const font_data[2][128]; +extern const uint8_t *const font_data[2][128 - 32]; -int fontCharWidth(int font, uint8_t c); -const uint8_t *fontCharData(int font, uint8_t c); +int fontCharWidth(uint8_t font, uint8_t c); +const uint8_t *fontCharData(uint8_t font, uint8_t c); #endif diff --git a/legacy/gen/fonts/font.png b/legacy/gen/fonts/font.png index a3d26a98e..d9ba1a843 100644 Binary files a/legacy/gen/fonts/font.png and b/legacy/gen/fonts/font.png differ diff --git a/legacy/gen/fonts/fontfixed.png b/legacy/gen/fonts/fontfixed.png index 50c77f7a4..e39e9674b 100644 Binary files a/legacy/gen/fonts/fontfixed.png and b/legacy/gen/fonts/fontfixed.png differ diff --git a/legacy/gen/fonts/generate.py b/legacy/gen/fonts/generate.py index 463d73e63..f23c0be52 100755 --- a/legacy/gen/fonts/generate.py +++ b/legacy/gen/fonts/generate.py @@ -23,7 +23,7 @@ def convert(imgfile, outfile): img = Img(imgfile) cur = "" with open(outfile, "w") as f: - for i in range(128): + for i in range(128 - 32): x = (i % 16) * 10 y = (i // 16) * 10 cur = "" @@ -32,7 +32,8 @@ def convert(imgfile, outfile): x += 1 cur += "\\x%02x" % int(val, 2) cur = "\\x%02x" % (len(cur) // 4) + cur - ch = chr(i) if i >= 32 and i <= 126 else "_" + i += 32 + ch = "_" if (i == 127) else chr(i) f.write('\t/* 0x%02x %c */ (uint8_t *)"%s",\n' % (i, ch, cur)) diff --git a/legacy/oled.c b/legacy/oled.c index 70928bb12..2f6528b9e 100644 --- a/legacy/oled.c +++ b/legacy/oled.c @@ -241,7 +241,7 @@ void oledSetBuffer(uint8_t *buf) { memcpy(_oledbuffer, buf, sizeof(_oledbuffer)); } -void oledDrawChar(int x, int y, char c, int font) { +void oledDrawChar(int x, int y, char c, uint8_t font) { if (x >= OLED_WIDTH || y >= OLED_HEIGHT || y <= -FONT_HEIGHT) { return; } @@ -304,7 +304,7 @@ static uint8_t convert_char(const char a) { return 0; } -int oledStringWidth(const char *text, int font) { +int oledStringWidth(const char *text, uint8_t font) { if (!text) return 0; int space = (font & FONT_DOUBLE) ? 2 : 1; int l = 0; @@ -317,7 +317,7 @@ int oledStringWidth(const char *text, int font) { return l; } -void oledDrawString(int x, int y, const char *text, int font) { +void oledDrawString(int x, int y, const char *text, uint8_t font) { if (!text) return; int l = 0; int space = (font & FONT_DOUBLE) ? 2 : 1; @@ -330,12 +330,12 @@ void oledDrawString(int x, int y, const char *text, int font) { } } -void oledDrawStringCenter(int x, int y, const char *text, int font) { +void oledDrawStringCenter(int x, int y, const char *text, uint8_t font) { x = x - oledStringWidth(text, font) / 2; oledDrawString(x, y, text, font); } -void oledDrawStringRight(int x, int y, const char *text, int font) { +void oledDrawStringRight(int x, int y, const char *text, uint8_t font) { x -= oledStringWidth(text, font); oledDrawString(x, y, text, font); } diff --git a/legacy/oled.h b/legacy/oled.h index 114e76c27..3b883175c 100644 --- a/legacy/oled.h +++ b/legacy/oled.h @@ -43,12 +43,11 @@ bool oledGetPixel(int x, int y); void oledDrawPixel(int x, int y); void oledClearPixel(int x, int y); void oledInvertPixel(int x, int y); -void oledDrawChar(int x, int y, char c, int zoom); -int oledStringWidth(const char *text, int font); - -void oledDrawString(int x, int y, const char *text, int font); -void oledDrawStringCenter(int x, int y, const char *text, int font); -void oledDrawStringRight(int x, int y, const char *text, int font); +void oledDrawChar(int x, int y, char c, uint8_t font); +int oledStringWidth(const char *text, uint8_t font); +void oledDrawString(int x, int y, const char *text, uint8_t font); +void oledDrawStringCenter(int x, int y, const char *text, uint8_t font); +void oledDrawStringRight(int x, int y, const char *text, uint8_t font); void oledDrawBitmap(int x, int y, const BITMAP *bmp); void oledInvert(int x1, int y1, int x2, int y2); void oledBox(int x1, int y1, int x2, int y2, bool set);