summaryrefslogtreecommitdiff
path: root/fw
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2024-09-04 22:32:28 +0200
committerUros Majstorovic <majstor@majstor.org>2024-09-04 22:32:28 +0200
commit2947da180404b758dedd42cb189ffc5734d4daa2 (patch)
treecade773d28a2ff923f7609a7e334e828c558e34b /fw
parentd23bf86e83d58b84431cef73936227c39ac7d33e (diff)
eve fonts improvement
Diffstat (limited to 'fw')
-rw-r--r--fw/fe310/eos/eve/eve_font.c27
-rw-r--r--fw/fe310/eos/eve/eve_font.h5
-rw-r--r--fw/fe310/eos/eve/widget/label.c2
-rw-r--r--fw/fe310/eos/eve/widget/strw.c12
-rw-r--r--fw/fe310/eos/eve/widget/textw.c14
5 files changed, 42 insertions, 18 deletions
diff --git a/fw/fe310/eos/eve/eve_font.c b/fw/fe310/eos/eve/eve_font.c
index cde0a17..4e149f2 100644
--- a/fw/fe310/eos/eve/eve_font.c
+++ b/fw/fe310/eos/eve/eve_font.c
@@ -19,7 +19,7 @@ int eve_font_ch_w(EVEFont *font, ucp_t ch) {
return EVE_ERR;
}
-int eve_font_str_w(EVEFont *font, utf8_t *str, int *str_w, size_t *str_len) {
+static int 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;
@@ -43,7 +43,7 @@ int eve_font_str_w(EVEFont *font, utf8_t *str, int *str_w, size_t *str_len) {
return EVE_OK;
}
-int eve_font_buf_w(EVEFont *font, utf8_t *buf, size_t buf_len, int *str_w, size_t *str_len) {
+static int 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;
@@ -67,6 +67,29 @@ int eve_font_buf_w(EVEFont *font, utf8_t *buf, size_t buf_len, int *str_w, size_
return EVE_OK;
}
+int eve_font_verify(EVEFont *font, utf8_t *str, int *str_w, size_t *str_len) {
+ int rv;
+
+ rv = font_str_w(font, str, str_w, str_len);
+ return rv;
+}
+
+int eve_font_str_w(EVEFont *font, utf8_t *str) {
+ int str_w, rv;
+
+ rv = font_str_w(font, str, &str_w, NULL);
+ if (rv < 0) return rv;
+ return str_w;
+}
+
+int eve_font_buf_w(EVEFont *font, utf8_t *str, size_t buf_len) {
+ int buf_w, rv;
+
+ rv = font_buf_w(font, str, buf_len, &buf_w, NULL);
+ if (rv < 0) return rv;
+ return buf_w;
+}
+
uint8_t eve_font_h(EVEFont *font) {
return font->h;
}
diff --git a/fw/fe310/eos/eve/eve_font.h b/fw/fe310/eos/eve/eve_font.h
index c384877..7787f6c 100644
--- a/fw/fe310/eos/eve/eve_font.h
+++ b/fw/fe310/eos/eve/eve_font.h
@@ -11,6 +11,7 @@ typedef struct EVEFont {
void eve_font_init(EVEFont *font, uint8_t font_id);
int eve_font_ch_w(EVEFont *font, ucp_t ch);
-int eve_font_str_w(EVEFont *font, utf8_t *str, int *str_w, size_t *str_len);
-int eve_font_buf_w(EVEFont *font, utf8_t *buf, size_t buf_len, int *str_w, size_t *str_len);
+int eve_font_verify(EVEFont *font, utf8_t *str, int *str_w, size_t *str_len);
+int eve_font_str_w(EVEFont *font, utf8_t *str);
+int eve_font_buf_w(EVEFont *font, utf8_t *str, size_t buf_len);
uint8_t eve_font_h(EVEFont *font);
diff --git a/fw/fe310/eos/eve/widget/label.c b/fw/fe310/eos/eve/widget/label.c
index bf99051..43c710c 100644
--- a/fw/fe310/eos/eve/widget/label.c
+++ b/fw/fe310/eos/eve/widget/label.c
@@ -17,7 +17,7 @@ void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title) {
memset(label, 0, sizeof(EVELabel));
if (g) label->g = *g;
- rv = eve_font_str_w(font, label->title, &title_w, &title_len);
+ rv = eve_font_verify(font, label->title, &title_w, &title_len);
if (rv) title[title_len] = '\0';
label->font = font;
diff --git a/fw/fe310/eos/eve/widget/strw.c b/fw/fe310/eos/eve/widget/strw.c
index 873e017..1b2e131 100644
--- a/fw/fe310/eos/eve/widget/strw.c
+++ b/fw/fe310/eos/eve/widget/strw.c
@@ -34,14 +34,14 @@ void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEFont *fon
memset(widget, 0, sizeof(EVEStrWidget));
eve_widget_init(_widget, EVE_WIDGET_TYPE_STR, g, page, eve_strw_draw, eve_strw_touch, eve_strw_putc);
- widget->font = font;
rv = utf8_verify(str, str_size, &str_len);
if (rv) str[str_len] = '\0';
- rv = eve_font_str_w(font, str, &str_w, &str_len);
+ rv = eve_font_verify(font, str, &str_w, &str_len);
if (rv) str[str_len] = '\0';
+ widget->font = font;
widget->str = str;
widget->str_size = str_size;
widget->str_len = str_len;
@@ -56,7 +56,7 @@ int eve_strw_update(EVEStrWidget *widget) {
rv = utf8_verify(widget->str, widget->str_size, &str_len);
if (rv) widget->str[str_len] = '\0';
- rv = eve_font_str_w(widget->font, widget->str, &str_w, &str_len);
+ rv = eve_font_verify(widget->font, widget->str, &str_w, &str_len);
if (rv) widget->str[str_len] = '\0';
widget->str_len = str_len;
@@ -368,7 +368,7 @@ void eve_strw_putc(void *w, int c) {
if (cursor2->on) {
del_c = c2->ch - c1->ch;
- eve_font_buf_w(widget->font, str, del_c, &del_w, NULL);
+ del_w = eve_font_buf_w(widget->font, str, del_c);
if ((c == CH_CTRLX) || (c == CH_CTRLC)) {
eve_clipb_push(str, del_c);
if (c == CH_CTRLC) return;
@@ -387,8 +387,8 @@ void eve_strw_putc(void *w, int c) {
clipb = eve_clipb_get();
if (clipb) {
rv = utf8_verify(clipb, EVE_CLIPB_SIZE_BUF, &clipb_len);
- if (!rv) rv = eve_font_str_w(widget->font, clipb, &ins_w, NULL);
- if (rv) {
+ if (!rv) ins_w = eve_font_str_w(widget->font, clipb);
+ if (rv || (ins_w < 0)) {
clipb = NULL;
clipb_len = 0;
ins_w = 0;
diff --git a/fw/fe310/eos/eve/widget/textw.c b/fw/fe310/eos/eve/widget/textw.c
index f85d1e0..86343a5 100644
--- a/fw/fe310/eos/eve/widget/textw.c
+++ b/fw/fe310/eos/eve/widget/textw.c
@@ -37,14 +37,14 @@ void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *f
memset(widget, 0, sizeof(EVETextWidget));
eve_widget_init(_widget, EVE_WIDGET_TYPE_TEXT, g, page, eve_textw_draw, eve_textw_touch, eve_textw_putc);
- widget->font = font;
rv = utf8_verify(text, text_size, &text_len);
if (rv) text[text_len] = '\0';
- rv = eve_font_str_w(font, text, NULL, &text_len);
+ rv = eve_font_verify(font, text, NULL, &text_len);
if (rv) text[text_len] = '\0';
+ widget->font = font;
widget->text = text;
widget->text_size = text_size;
widget->text_len = text_len;
@@ -59,10 +59,10 @@ int eve_textw_update(EVETextWidget *widget) {
int rv;
rv = utf8_verify(widget->text, widget->text_size, &text_len);
- if (rv != UTF_OK) widget->text[text_len] = '\0';
+ if (rv) widget->text[text_len] = '\0';
- rv = eve_font_str_w(widget->font, widget->text, NULL, &text_len);
- if (rv != UTF_OK) widget->text[text_len] = '\0';
+ rv = eve_font_verify(widget->font, widget->text, NULL, &text_len);
+ if (rv) widget->text[text_len] = '\0';
memset(widget->line, 0xff, widget->line_size * sizeof(uint16_t));
eve_textw_text_update(widget, 0, 0);
@@ -399,8 +399,8 @@ void eve_textw_putc(void *w, int c) {
clipb = eve_clipb_get();
if (clipb) {
rv = utf8_verify(clipb, EVE_CLIPB_SIZE_BUF, &clipb_len);
- if (!rv) rv = eve_font_str_w(widget->font, clipb, &ch_w, NULL);
- if (rv) {
+ if (!rv) ch_w = eve_font_str_w(widget->font, clipb);
+ if (rv || (ch_w < 0)) {
clipb = NULL;
clipb_len = 0;
ch_w = 0;