From bea30c6e12a005f89ec619c331dc4798f7c76cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Thu, 8 Feb 2024 15:34:39 +0100 Subject: [PATCH] font: improve tag collection --- demos/01-font.c | 3 ++- engine/joint/v4k.h | 10 ++++++---- engine/split/v4k_font.c | 10 ++++++---- engine/v4k.c | 10 ++++++---- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/demos/01-font.c b/demos/01-font.c index c21bb1b..d70cba9 100644 --- a/demos/01-font.c +++ b/demos/01-font.c @@ -10,6 +10,7 @@ int main() { #define FONT_JAPANESE FONT_FACE4 #define FONT_MONOSPACE FONT_FACE5 + #define FONT_WHITE FONT_COLOR1 #define FONT_GRAY FONT_COLOR2 #define FONT_ORANGE FONT_COLOR3 #define FONT_LIME FONT_COLOR4 @@ -139,7 +140,7 @@ int main() { { vec2 pos = vec2(1990,820); ddraw_push_2d(); - char *txt = FONT_RIGHT FONT_BOTTOM "This is the first line.\nAnd now the second line.\n \nYou can do a third great line, too!\n"; + char *txt = FONT_RIGHT FONT_BOTTOM FONT_WHITE "This is the first line.\n" FONT_LIME "And now the second line.\n" FONT_WHITE "You can do a third great line, too!\n"; font_goto(pos.x, pos.y); vec2 size=font_rect(txt); font_metrics_t m=font_metrics(txt); diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index 5c46322..b54ef1a 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -363957,16 +363957,18 @@ vec2 font_print_rect(const char *text, vec4 rect) { if (num_newlines > 1) { vec2 text_dims = font_rect(text); char tags[4] = {0}; - for (int i = 0, t = 0, end = strlen(text); i < end; ++i) { - char ch = text[i]; + int t=0; + while (*text) { + char ch = *text; if( (ch >= 1 && ch <= 6) || (ch >= 0x1a && ch <= 0x1f) || (ch >= 0x10 && ch <= 0x19)) { tags[t++] = ch; - ++text; } - + else break; + ++text; + if (t == 3) break; } array(char *) lines = strsplit(text, "\n"); diff --git a/engine/split/v4k_font.c b/engine/split/v4k_font.c index 66eec2e..dab347a 100644 --- a/engine/split/v4k_font.c +++ b/engine/split/v4k_font.c @@ -2399,16 +2399,18 @@ vec2 font_print_rect(const char *text, vec4 rect) { if (num_newlines > 1) { vec2 text_dims = font_rect(text); char tags[4] = {0}; - for (int i = 0, t = 0, end = strlen(text); i < end; ++i) { - char ch = text[i]; + int t=0; + while (*text) { + char ch = *text; if( (ch >= 1 && ch <= 6) || (ch >= 0x1a && ch <= 0x1f) || (ch >= 0x10 && ch <= 0x19)) { tags[t++] = ch; - ++text; } - + else break; + ++text; + if (t == 3) break; } array(char *) lines = strsplit(text, "\n"); diff --git a/engine/v4k.c b/engine/v4k.c index efc6c0f..dd68e72 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -11097,16 +11097,18 @@ vec2 font_print_rect(const char *text, vec4 rect) { if (num_newlines > 1) { vec2 text_dims = font_rect(text); char tags[4] = {0}; - for (int i = 0, t = 0, end = strlen(text); i < end; ++i) { - char ch = text[i]; + int t=0; + while (*text) { + char ch = *text; if( (ch >= 1 && ch <= 6) || (ch >= 0x1a && ch <= 0x1f) || (ch >= 0x10 && ch <= 0x19)) { tags[t++] = ch; - ++text; } - + else break; + ++text; + if (t == 3) break; } array(char *) lines = strsplit(text, "\n");