diff options
Diffstat (limited to 'fw/fe310/eos/eve/eve_font.c')
-rw-r--r-- | fw/fe310/eos/eve/eve_font.c | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/fw/fe310/eos/eve/eve_font.c b/fw/fe310/eos/eve/eve_font.c index 81df143..cde0a17 100644 --- a/fw/fe310/eos/eve/eve_font.c +++ b/fw/fe310/eos/eve/eve_font.c @@ -14,44 +14,57 @@ void eve_font_init(EVEFont *font, uint8_t font_id) { eve_readb(p, font->w_ch, 128); } -uint8_t eve_font_ch_w(EVEFont *font, ucp_t ch) { +int eve_font_ch_w(EVEFont *font, ucp_t ch) { if (ch < 128) return font->w_ch[ch]; - return 0; + return EVE_ERR; } -uint16_t eve_font_str_w(EVEFont *font, utf8_t *str) { +int eve_font_str_w(EVEFont *font, utf8_t *str, int *str_w, size_t *str_len) { uint16_t r = 0; + size_t len = 0; ucp_t ch; - uint8_t ch_w; - uint8_t ch_l; + int ch_w; + int ch_l; - if (str == NULL) return 0; - - while (*str) { - ch_l = utf8_dec(str, &ch); + while (str[len]) { + ch_l = utf8_dec(str + len, &ch); ch_w = eve_font_ch_w(font, ch); + if (ch_w < 0) { + if (str_w) *str_w = r; + if (str_len) *str_len = len; + return EVE_ERR; + } r += ch_w; - str += ch_l; + len += ch_l; } - return r; + if (str_w) *str_w = r; + if (str_len) *str_len = len; + return EVE_OK; } -uint16_t eve_font_buf_w(EVEFont *font, utf8_t *buf, uint16_t buf_len) { - int i = 0; +int eve_font_buf_w(EVEFont *font, utf8_t *buf, size_t buf_len, int *str_w, size_t *str_len) { uint16_t r = 0; + size_t len = 0; ucp_t ch; - uint8_t ch_w; - uint8_t ch_l; + int ch_w; + int ch_l; - while (i < buf_len) { - ch_l = utf8_dec(buf + i, &ch); + while (len < buf_len) { + ch_l = utf8_dec(buf + len, &ch); ch_w = eve_font_ch_w(font, ch); + if (ch_w < 0) { + if (str_w) *str_w = r; + if (str_len) *str_len = len; + return EVE_ERR; + } r += ch_w; - i += ch_l; + len += ch_l; } - return r; + if (str_w) *str_w = r; + if (str_len) *str_len = len; + return EVE_OK; } uint8_t eve_font_h(EVEFont *font) { |