summaryrefslogtreecommitdiff
path: root/code/fe310/eos/eve/screen
diff options
context:
space:
mode:
Diffstat (limited to 'code/fe310/eos/eve/screen')
-rw-r--r--code/fe310/eos/eve/screen/font.c38
-rw-r--r--code/fe310/eos/eve/screen/font.h5
-rw-r--r--code/fe310/eos/eve/screen/form.c1
-rw-r--r--code/fe310/eos/eve/screen/page.c1
4 files changed, 34 insertions, 11 deletions
diff --git a/code/fe310/eos/eve/screen/font.c b/code/fe310/eos/eve/screen/font.c
index 6fc7d39..da02983 100644
--- a/code/fe310/eos/eve/screen/font.c
+++ b/code/fe310/eos/eve/screen/font.c
@@ -1,6 +1,8 @@
#include <stdlib.h>
#include "eve.h"
+#include "unicode.h"
+
#include "font.h"
void eve_font_init(EVEFont *font, uint8_t font_id) {
@@ -14,23 +16,41 @@ void eve_font_init(EVEFont *font, uint8_t font_id) {
eve_readb(p, font->w_ch, 128);
}
-uint16_t eve_font_str_w(EVEFont *font, char *s) {
+uint8_t eve_font_ch_w(EVEFont *font, utf32_t ch) {
+ if (ch < 128) return font->w_ch[ch];
+ return 0;
+}
+
+uint16_t eve_font_str_w(EVEFont *font, utf8_t *str) {
uint16_t r = 0;
+ utf32_t ch;
+ uint8_t ch_w;
+ uint8_t ch_l;
- while (*s) {
- r += font->w_ch[*s];
- s++;
+ if (str == NULL) return 0;
+
+ while (*str) {
+ ch_l = utf8_dec(str, &ch);
+ ch_w = eve_font_ch_w(font, ch);
+ r += ch_w;
+ str += ch_l;
}
return r;
}
-uint16_t eve_font_buf_w(EVEFont *font, char *buf, uint16_t buf_len) {
- int i;
+uint16_t eve_font_buf_w(EVEFont *font, utf8_t *buf, uint16_t buf_len) {
+ int i = 0;
uint16_t r = 0;
-
- for (i=0; i<buf_len; i++) {
- r += font->w_ch[*(buf + i)];
+ utf32_t ch;
+ uint8_t ch_w;
+ uint8_t ch_l;
+
+ while (i < buf_len) {
+ ch_l = utf8_dec(buf + i, &ch);
+ ch_w = eve_font_ch_w(font, ch);
+ r += ch_w;
+ i += ch_l;
}
return r;
diff --git a/code/fe310/eos/eve/screen/font.h b/code/fe310/eos/eve/screen/font.h
index 525e669..aff038c 100644
--- a/code/fe310/eos/eve/screen/font.h
+++ b/code/fe310/eos/eve/screen/font.h
@@ -8,6 +8,7 @@ typedef struct EVEFont {
} EVEFont;
void eve_font_init(EVEFont *font, uint8_t font_id);
-uint16_t eve_font_str_w(EVEFont *font, char *s);
-uint16_t eve_font_buf_w(EVEFont *font, char *buf, uint16_t buf_len);
+uint8_t eve_font_ch_w(EVEFont *font, utf32_t ch);
+uint16_t eve_font_str_w(EVEFont *font, utf8_t *str);
+uint16_t eve_font_buf_w(EVEFont *font, utf8_t *buf, uint16_t buf_len);
uint8_t eve_font_h(EVEFont *font);
diff --git a/code/fe310/eos/eve/screen/form.c b/code/fe310/eos/eve/screen/form.c
index 096cfa3..f7d37ee 100644
--- a/code/fe310/eos/eve/screen/form.c
+++ b/code/fe310/eos/eve/screen/form.c
@@ -3,6 +3,7 @@
#include "eve.h"
#include "eve_kbd.h"
+#include "unicode.h"
#include "screen.h"
#include "window.h"
diff --git a/code/fe310/eos/eve/screen/page.c b/code/fe310/eos/eve/screen/page.c
index 7631c95..f54056c 100644
--- a/code/fe310/eos/eve/screen/page.c
+++ b/code/fe310/eos/eve/screen/page.c
@@ -3,6 +3,7 @@
#include "eve.h"
#include "eve_kbd.h"
+#include "unicode.h"
#include "screen.h"
#include "window.h"