font: small improvements

main
Dominik Madarász 2024-02-08 15:17:00 +01:00
parent 87d1439207
commit 64994fe27a
4 changed files with 17 additions and 32 deletions

View File

@ -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);

View File

@ -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,13 +363988,8 @@ 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;
}
}
if (array_count(words) == 0) {
gotoxy.y += text_rect.y;
continue;

View File

@ -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,13 +2430,8 @@ 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;
}
}
if (array_count(words) == 0) {
gotoxy.y += text_rect.y;
continue;

View File

@ -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,13 +11128,8 @@ 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;
}
}
if (array_count(words) == 0) {
gotoxy.y += text_rect.y;
continue;