From e5fcdeda041831cb326f1d1963c0651b78041788 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Fri, 12 Jun 2020 00:51:04 +0200 Subject: implemented font metrics --- code/fe310/eos/eve/eve.c | 26 ++++++++++++++++++++++++-- code/fe310/eos/eve/eve.h | 3 +++ code/fe310/eos/eve/screen/font.c | 9 ++++++++- code/fe310/eos/eve/screen/font.h | 3 ++- code/fe310/eos/eve/widget/text.c | 12 ++++++------ 5 files changed, 43 insertions(+), 10 deletions(-) (limited to 'code/fe310/eos/eve') diff --git a/code/fe310/eos/eve/eve.c b/code/fe310/eos/eve/eve.c index 0ab5427..1db5744 100644 --- a/code/fe310/eos/eve/eve.c +++ b/code/fe310/eos/eve/eve.c @@ -70,6 +70,28 @@ void eve_write32(uint32_t addr, uint32_t data) { eve_spi_cs_clear(); } +void eve_readb(uint32_t addr, uint8_t *b, size_t size) { + int i; + + eve_spi_cs_set(); + eve_spi_xchg32(addr << 8, 0); + for (i=0; iid = font_id; + font->w = eve_read32(p + 136); + font->h = eve_read32(p + 140); + eve_readb(p, font->w_ch, 128); } uint16_t eve_font_string_width(EVEFont *font, char *s) { uint16_t r = 0; while (*s) { - r += font->w[*s]; + r += font->w_ch[*s]; s++; } return r; diff --git a/code/fe310/eos/eve/screen/font.h b/code/fe310/eos/eve/screen/font.h index 24b745e..a46c942 100644 --- a/code/fe310/eos/eve/screen/font.h +++ b/code/fe310/eos/eve/screen/font.h @@ -2,8 +2,9 @@ typedef struct EVEFont { uint8_t id; - uint8_t w[128]; + uint8_t w; uint8_t h; + uint8_t w_ch[128]; } EVEFont; void eve_font_init(EVEFont *font, uint8_t font_id); diff --git a/code/fe310/eos/eve/widget/text.c b/code/fe310/eos/eve/widget/text.c index 834729f..ae83656 100644 --- a/code/fe310/eos/eve/widget/text.c +++ b/code/fe310/eos/eve/widget/text.c @@ -284,7 +284,7 @@ void eve_textw_putc(void *_page, int c) { switch (c) { case CH_BS: if (cursor1->ch > 0) { - cursor1->x -= widget->font->w[*(text - 1)]; + cursor1->x -= widget->font->w_ch[*(text - 1)]; memmove(text - 1, text, widget->text_len - cursor1->ch + 1); widget->text_len--; cursor1->ch--; @@ -300,7 +300,7 @@ void eve_textw_putc(void *_page, int c) { break; default: if (widget->text_len < (widget->text_size - 1)) { - cursor1->x += widget->font->w[c]; + cursor1->x += widget->font->w_ch[c]; memmove(text + 1, text, widget->text_len - cursor1->ch + 1); *text = c; widget->text_len++; @@ -345,7 +345,7 @@ int eve_textw_update(EVETextWidget *widget, EVEPage *page, uint16_t line) { line_b = LINE_EMPTY; for (i=LINE_START(widget, line); itext_size; i++) { ch = widget->text[i]; - ch_w = widget->font->w[ch]; + ch_w = widget->font->w_ch[ch]; if (ch <= 0x20) { if ((ch == '\n') || (ch == '\0')) { if (widget->line[line] == i) return line; @@ -406,7 +406,7 @@ void eve_textw_cursor_update(EVETextWidget *widget, EVETextCursor *cursor) { x = 0; for (i=LINE_START(widget, cursor->line); iline); i++) { if (cursor->ch == i) break; - x += widget->font->w[widget->text[i]]; + x += widget->font->w_ch[widget->text[i]]; } cursor->x = x; } @@ -430,12 +430,12 @@ void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t _x = 0; _d = x; for (i=LINE_START(widget, cursor->line); iline); i++) { - _x += widget->font->w[widget->text[i]]; + _x += widget->font->w_ch[widget->text[i]]; if (_x >= x) { if (_x - x < _d) { i++; } else { - _x -= widget->font->w[widget->text[i]]; + _x -= widget->font->w_ch[widget->text[i]]; } break; } else { -- cgit v1.2.3