diff --git a/demos/01-font.c b/demos/01-font.c index af81a74..c21bb1b 100644 --- a/demos/01-font.c +++ b/demos/01-font.c @@ -127,7 +127,7 @@ int main() { { vec2 pos = vec2(1490,820); ddraw_push_2d(); - char *txt = FONT_JUSTIFY FONT_MIDDLE "This is the first line.\nAnd now the second line.\nYou can do a third great line, too!\n"; + char *txt = FONT_JUSTIFY FONT_MIDDLE "This is the first line.\nAnd now the second line.\nYou can do a third great line, too!\nNow this is a very long line aaaaaaaaaa!\n"; font_goto(pos.x, pos.y); vec2 size=font_rect(txt); font_metrics_t m=font_metrics(txt); @@ -139,7 +139,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.\nYou can do a third great line, too!\n"; + 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"; 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 ca31611..5c46322 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -363956,11 +363956,8 @@ vec2 font_print_rect(const char *text, vec4 rect) { if (num_newlines > 1) { vec2 text_dims = font_rect(text); - array(char *) lines = strsplit(text, "\n"); char tags[4] = {0}; for (int i = 0, t = 0, end = strlen(text); i < end; ++i) { - if (t == 4) break; - char ch = text[i]; if( (ch >= 1 && ch <= 6) || @@ -363969,7 +363966,10 @@ vec2 font_print_rect(const char *text, vec4 rect) { tags[t++] = ch; ++text; } + + if (t == 3) break; } + array(char *) lines = strsplit(text, "\n"); if (b) { gotoxy.y += (rect.w - text_dims.y); } @@ -363988,12 +363988,7 @@ vec2 font_print_rect(const char *text, vec4 rect) { float words_space = 0.0f; array(char *) words = strsplit(lines[i], " "); for (int k = 0; k < array_count(words); ++k) { - if (!strlen(words[k])) { - array_erase_slow(words, k); - --k; - } else { - words_space += font_rect(words[k]).x; - } + words_space += font_rect(words[k]).x; } if (array_count(words) == 0) { gotoxy.y += text_rect.y; @@ -364013,7 +364008,7 @@ vec2 font_print_rect(const char *text, vec4 rect) { font_draw_ex(line, gotoxy, NULL, font_draw_cmd); } - gotoxy.y += text_rect.y; + gotoxy.y += text_rect.y; } return text_dims; } else { diff --git a/engine/split/v4k_font.c b/engine/split/v4k_font.c index de3e26c..66eec2e 100644 --- a/engine/split/v4k_font.c +++ b/engine/split/v4k_font.c @@ -2398,11 +2398,8 @@ vec2 font_print_rect(const char *text, vec4 rect) { if (num_newlines > 1) { vec2 text_dims = font_rect(text); - array(char *) lines = strsplit(text, "\n"); char tags[4] = {0}; for (int i = 0, t = 0, end = strlen(text); i < end; ++i) { - if (t == 4) break; - char ch = text[i]; if( (ch >= 1 && ch <= 6) || @@ -2411,7 +2408,10 @@ vec2 font_print_rect(const char *text, vec4 rect) { tags[t++] = ch; ++text; } + + if (t == 3) break; } + array(char *) lines = strsplit(text, "\n"); if (b) { gotoxy.y += (rect.w - text_dims.y); } @@ -2430,12 +2430,7 @@ vec2 font_print_rect(const char *text, vec4 rect) { float words_space = 0.0f; array(char *) words = strsplit(lines[i], " "); for (int k = 0; k < array_count(words); ++k) { - if (!strlen(words[k])) { - array_erase_slow(words, k); - --k; - } else { - words_space += font_rect(words[k]).x; - } + words_space += font_rect(words[k]).x; } if (array_count(words) == 0) { gotoxy.y += text_rect.y; @@ -2455,7 +2450,7 @@ vec2 font_print_rect(const char *text, vec4 rect) { font_draw_ex(line, gotoxy, NULL, font_draw_cmd); } - gotoxy.y += text_rect.y; + gotoxy.y += text_rect.y; } return text_dims; } else { diff --git a/engine/v4k.c b/engine/v4k.c index a1365fe..efc6c0f 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -11096,11 +11096,8 @@ vec2 font_print_rect(const char *text, vec4 rect) { if (num_newlines > 1) { vec2 text_dims = font_rect(text); - array(char *) lines = strsplit(text, "\n"); char tags[4] = {0}; for (int i = 0, t = 0, end = strlen(text); i < end; ++i) { - if (t == 4) break; - char ch = text[i]; if( (ch >= 1 && ch <= 6) || @@ -11109,7 +11106,10 @@ vec2 font_print_rect(const char *text, vec4 rect) { tags[t++] = ch; ++text; } + + if (t == 3) break; } + array(char *) lines = strsplit(text, "\n"); if (b) { gotoxy.y += (rect.w - text_dims.y); } @@ -11128,12 +11128,7 @@ vec2 font_print_rect(const char *text, vec4 rect) { float words_space = 0.0f; array(char *) words = strsplit(lines[i], " "); for (int k = 0; k < array_count(words); ++k) { - if (!strlen(words[k])) { - array_erase_slow(words, k); - --k; - } else { - words_space += font_rect(words[k]).x; - } + words_space += font_rect(words[k]).x; } if (array_count(words) == 0) { gotoxy.y += text_rect.y; @@ -11153,7 +11148,7 @@ vec2 font_print_rect(const char *text, vec4 rect) { font_draw_ex(line, gotoxy, NULL, font_draw_cmd); } - gotoxy.y += text_rect.y; + gotoxy.y += text_rect.y; } return text_dims; } else {