From c17f147be95e7490e5207c747add2da1cc8b167f Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 6 Feb 2019 12:13:17 -0800 Subject: A variety of displayio improvements This changes a number of things in displayio: * Introduces BuiltinFont and Glyph so the built in font can be used by libraries. For boards with a font it is available as board.TERMINAL_FONT. Fixes #1172 * Remove _load_row from Bitmap in favor of bitmap[] access. Index can be x/y tuple or overall index. Fixes #1191 * Add width and height properties to Bitmap. * Add insert and [] access to Group. Fixes #1518 * Add index param to pop on Group. * Terminal no longer takes unicode character info. It takes a BuiltinFont instead. * Fix Terminal's handling of [###D vt100 commands used when up arrowing into repl history. * Add x and y positions to Group plus scale as well. * Add bitmap accessor for BuiltinFont --- shared-module/terminalio/Terminal.c | 32 ++++++++++++++------------------ shared-module/terminalio/Terminal.h | 4 ++-- 2 files changed, 16 insertions(+), 20 deletions(-) (limited to 'shared-module/terminalio') diff --git a/shared-module/terminalio/Terminal.c b/shared-module/terminalio/Terminal.c index 6734fa30e..85bbee293 100644 --- a/shared-module/terminalio/Terminal.c +++ b/shared-module/terminalio/Terminal.c @@ -27,14 +27,14 @@ #include "shared-module/terminalio/Terminal.h" #include "shared-module/displayio/__init__.h" +#include "shared-module/displayio/BuiltinFont.h" #include "shared-bindings/displayio/TileGrid.h" -void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, displayio_tilegrid_t* tilegrid, const uint8_t* unicode_characters, size_t unicode_characters_len) { +void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, displayio_tilegrid_t* tilegrid, const displayio_builtinfont_t* font) { self->cursor_x = 0; self->cursor_y = 0; + self->font = font; self->tilegrid = tilegrid; - self->unicode_characters = unicode_characters; - self->unicode_characters_len = unicode_characters_len; self->first_row = 0; } @@ -47,10 +47,10 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con // Always handle ASCII. if (c < 128) { if (c >= 0x20 && c <= 0x7e) { - common_hal_displayio_textgrid_set_tile(self->tilegrid, self->cursor_x, self->cursor_y, c - 0x20); + uint8_t tile_index = displayio_builtinfont_get_glyph_index(self->font, c); + common_hal_displayio_textgrid_set_tile(self->tilegrid, self->cursor_x, self->cursor_y, tile_index); self->cursor_x++; - } - if (c == '\r') { + } else if (c == '\r') { self->cursor_x = 0; } else if (c == '\n') { self->cursor_y++; @@ -76,6 +76,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con n = n * 10 + (i[j] - '0'); } else { c = i[j]; + break; } } if (c == 'D') { @@ -84,23 +85,18 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con } else { self->cursor_x -= n; } - i += j; } + i += j + 1; + continue; } } } } else { - // Do a linear search of the mapping for unicode. - const byte* j = self->unicode_characters; - uint8_t k = 0; - while (j < self->unicode_characters + self->unicode_characters_len) { - unichar potential_c = utf8_get_char(j); - j = utf8_next_char(j); - if (c == potential_c) { - common_hal_displayio_textgrid_set_tile(self->tilegrid, self->cursor_x, self->cursor_y, 0x7f - 0x20 + k); - self->cursor_x++; - break; - } + uint8_t tile_index = displayio_builtinfont_get_glyph_index(self->font, c); + if (tile_index != 0xff) { + common_hal_displayio_textgrid_set_tile(self->tilegrid, self->cursor_x, self->cursor_y, tile_index); + self->cursor_x++; + } } if (self->cursor_x >= self->tilegrid->width_in_tiles) { diff --git a/shared-module/terminalio/Terminal.h b/shared-module/terminalio/Terminal.h index fe9dcf0c4..145b42f3f 100644 --- a/shared-module/terminalio/Terminal.h +++ b/shared-module/terminalio/Terminal.h @@ -31,15 +31,15 @@ #include #include "py/obj.h" +#include "shared-module/displayio/BuiltinFont.h" #include "shared-module/displayio/TileGrid.h" typedef struct { mp_obj_base_t base; + const displayio_builtinfont_t* font; uint16_t cursor_x; uint16_t cursor_y; displayio_tilegrid_t* tilegrid; - const byte* unicode_characters; - uint16_t unicode_characters_len; uint16_t first_row; } terminalio_terminal_obj_t; -- cgit v1.2.3