From 4cecb920bfb5ab9c7dba17c9ac1bfac793b68928 Mon Sep 17 00:00:00 2001 From: David Tillotson Date: Thu, 11 Feb 2021 23:16:47 +0000 Subject: [PATCH] Adjusted font_data in graphics lib code to enable different height fonts --- libraries/pico_graphics/font_data.cpp | 2 ++ libraries/pico_graphics/pico_graphics.cpp | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libraries/pico_graphics/font_data.cpp b/libraries/pico_graphics/font_data.cpp index cfb3cca7..8e507c5f 100644 --- a/libraries/pico_graphics/font_data.cpp +++ b/libraries/pico_graphics/font_data.cpp @@ -1,5 +1,7 @@ #include +uint8_t font_height = 6; + uint8_t font_data[96][6] = { {0x00,0x00,0x00,0x00,0x00,0x00}, // {0x2e,0x00,0x00,0x00,0x00,0x00}, // ! diff --git a/libraries/pico_graphics/pico_graphics.cpp b/libraries/pico_graphics/pico_graphics.cpp index ed822f42..8c781dd7 100644 --- a/libraries/pico_graphics/pico_graphics.cpp +++ b/libraries/pico_graphics/pico_graphics.cpp @@ -2,6 +2,7 @@ extern uint8_t font_data[96][6]; extern uint8_t character_widths[96]; +extern uint8_t font_height; namespace pimoroni { @@ -106,13 +107,13 @@ namespace pimoroni { void PicoGraphics::character(const char c, const Point &p, uint8_t scale) { uint8_t char_index = c - 32; - Rect char_bounds(p.x, p.y, character_widths[char_index] * scale, 6 * scale); + Rect char_bounds(p.x, p.y, character_widths[char_index] * scale, font_height * scale); if(!clip.intersects(char_bounds)) return; const uint8_t *d = &font_data[char_index][0]; for(uint8_t cx = 0; cx < character_widths[char_index]; cx++) { - for(uint8_t cy = 0; cy < 6; cy++) { + for(uint8_t cy = 0; cy < font_height; cy++) { if((1U << cy) & *d) { rectangle(Rect(p.x + (cx * scale), p.y + (cy * scale), scale, scale)); } @@ -143,7 +144,7 @@ namespace pimoroni { // move to the next line if(co != 0 && co + word_width > (uint32_t)wrap) { co = 0; - lo += 7 * scale; + lo += (font_height + 1) * scale; } // draw word @@ -315,8 +316,8 @@ namespace pimoroni { }else{ // steep version int32_t s = std::abs(dy); // number of steps - int32_t sy = dy < 0 ? -1 : 1; // x step value - int32_t sx = (dx << 16) / s; // y step value in fixed 16:16 + int32_t sy = dy < 0 ? -1 : 1; // y step value + int32_t sx = (dx << 16) / s; // x step value in fixed 16:16 int32_t y = p1.y; int32_t x = p1.x << 16; while(s--) { @@ -326,4 +327,4 @@ namespace pimoroni { } } } -} \ No newline at end of file +}