diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2020-07-17 20:29:41 +0200 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2020-07-17 20:29:41 +0200 |
| commit | 4a239ede79c43cf22e8f769a4ea086687a65c3f0 (patch) | |
| tree | 5b1e651dc4188f541fdcd5d85d1e6c0521f93200 /src/draw_qrcode.cpp | |
| parent | 097db5fa9f57a77866be60ef8d8d39beef882639 (diff) | |
use u8g2 for font rendering, as they support fonts with umlauts
Diffstat (limited to 'src/draw_qrcode.cpp')
| -rw-r--r-- | src/draw_qrcode.cpp | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/draw_qrcode.cpp b/src/draw_qrcode.cpp index 594e47c..1d2edc8 100644 --- a/src/draw_qrcode.cpp +++ b/src/draw_qrcode.cpp @@ -1,10 +1,12 @@ #include <GxEPD2_BW.h> -#include <Fonts/FreeSansBold9pt7b.h> -#include <Fonts/FreeSans9pt7b.h> +#include <U8g2_for_Adafruit_GFX.h> #include <qrcode.h> #define BLOCK_WIDTH 4 +extern GxEPD2_GFX_BASE_CLASS &get_display(); +extern U8G2_FOR_ADAFRUIT_GFX u8g2Fonts; + static uint16_t sizes[] = { 17, 32, 53, 78, 106, 134, 154, 192, 230, }; @@ -28,7 +30,7 @@ static int version_for_len(int length) { return -1; } -int draw_qrcode(GxEPD2_GFX_BASE_CLASS &display, int16_t x, int16_t y, String &text) { +int draw_qrcode(int16_t x, int16_t y, String &text) { QRCode qrcode; int version = version_for_len(text.length()); if (version <= 0) @@ -46,13 +48,13 @@ int draw_qrcode(GxEPD2_GFX_BASE_CLASS &display, int16_t x, int16_t y, String &te if (!qrcode_getModule(&qrcode, row, col)) { continue; } - display.fillRect(x + BLOCK_WIDTH * row, y + BLOCK_WIDTH * col, BLOCK_WIDTH, BLOCK_WIDTH, GxEPD_BLACK); + get_display().fillRect(x + BLOCK_WIDTH * row, y + BLOCK_WIDTH * col, BLOCK_WIDTH, BLOCK_WIDTH, GxEPD_BLACK); } } return qrcode.size * BLOCK_WIDTH + 8 * BLOCK_WIDTH; } -void draw_qrcode_wlan(GxEPD2_GFX_BASE_CLASS &display, int16_t x, int16_t y, const char *ssid, const char *psk) { +void draw_qrcode_wlan(int16_t x, int16_t y, const char *ssid, const char *psk) { String ssid_str = String(ssid); String psk_str = String(psk); escape_strings(ssid_str); @@ -67,28 +69,28 @@ void draw_qrcode_wlan(GxEPD2_GFX_BASE_CLASS &display, int16_t x, int16_t y, cons wifi_str += ";P:" + psk_str + ";T:WPA;;"; } - int size = draw_qrcode(display, x, y, wifi_str); + int size = draw_qrcode(x, y, wifi_str); /* draw text */ - int16_t x2, y2; uint16_t w, h; + h = 10; /* assume 10px height */ String text_ssid = String("SSID:"); String text_psk = String("PSK:"); - display.setFont(&FreeSansBold9pt7b); - display.getTextBounds(text_ssid, 0, 0, &x2, &y2, &w, &h); - display.setCursor(x, y + size + h); - display.print(text_ssid); - display.setFont(&FreeSans9pt7b); - display.setCursor(x + w, y + size + h); - display.print(" " + ssid_str); + u8g2Fonts.setFont(u8g2_font_helvB10_tf); + w = u8g2Fonts.getUTF8Width(text_ssid.c_str()); + u8g2Fonts.setCursor(x, y + size + h); + u8g2Fonts.print(text_ssid); + u8g2Fonts.setFont(u8g2_font_helvR10_tf); + u8g2Fonts.setCursor(x + w, y + size + h); + u8g2Fonts.print(" " + ssid_str); if (psk_str.length() > 0) { - display.setFont(&FreeSansBold9pt7b); - display.setCursor(x, y + size + 2 * h + 10); - display.print(text_psk); - display.setFont(&FreeSans9pt7b); - display.setCursor(x + w, y + size + 2 * h + 10); - display.print(" " + psk_str); + u8g2Fonts.setFont(u8g2_font_helvB10_tf); + u8g2Fonts.setCursor(x, y + size + 2 * h + 10); + u8g2Fonts.print(text_psk); + u8g2Fonts.setFont(u8g2_font_helvR10_tf); + u8g2Fonts.setCursor(x + w, y + size + 2 * h + 10); + u8g2Fonts.print(" " + psk_str); } } |
