font: improve tag collection

main
Dominik Madarász 2024-02-08 15:34:39 +01:00
parent 76dcaa51f0
commit bea30c6e12
4 changed files with 20 additions and 13 deletions

View File

@ -10,6 +10,7 @@ int main() {
#define FONT_JAPANESE FONT_FACE4 #define FONT_JAPANESE FONT_FACE4
#define FONT_MONOSPACE FONT_FACE5 #define FONT_MONOSPACE FONT_FACE5
#define FONT_WHITE FONT_COLOR1
#define FONT_GRAY FONT_COLOR2 #define FONT_GRAY FONT_COLOR2
#define FONT_ORANGE FONT_COLOR3 #define FONT_ORANGE FONT_COLOR3
#define FONT_LIME FONT_COLOR4 #define FONT_LIME FONT_COLOR4
@ -139,7 +140,7 @@ int main() {
{ {
vec2 pos = vec2(1990,820); vec2 pos = vec2(1990,820);
ddraw_push_2d(); 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); font_goto(pos.x, pos.y);
vec2 size=font_rect(txt); vec2 size=font_rect(txt);
font_metrics_t m=font_metrics(txt); font_metrics_t m=font_metrics(txt);

View File

@ -363957,15 +363957,17 @@ vec2 font_print_rect(const char *text, vec4 rect) {
if (num_newlines > 1) { if (num_newlines > 1) {
vec2 text_dims = font_rect(text); vec2 text_dims = font_rect(text);
char tags[4] = {0}; char tags[4] = {0};
for (int i = 0, t = 0, end = strlen(text); i < end; ++i) { int t=0;
char ch = text[i]; while (*text) {
char ch = *text;
if( (ch >= 1 && ch <= 6) || if( (ch >= 1 && ch <= 6) ||
(ch >= 0x1a && ch <= 0x1f) || (ch >= 0x1a && ch <= 0x1f) ||
(ch >= 0x10 && ch <= 0x19)) { (ch >= 0x10 && ch <= 0x19)) {
tags[t++] = ch; tags[t++] = ch;
++text;
} }
else break;
++text;
if (t == 3) break; if (t == 3) break;
} }

View File

@ -2399,15 +2399,17 @@ vec2 font_print_rect(const char *text, vec4 rect) {
if (num_newlines > 1) { if (num_newlines > 1) {
vec2 text_dims = font_rect(text); vec2 text_dims = font_rect(text);
char tags[4] = {0}; char tags[4] = {0};
for (int i = 0, t = 0, end = strlen(text); i < end; ++i) { int t=0;
char ch = text[i]; while (*text) {
char ch = *text;
if( (ch >= 1 && ch <= 6) || if( (ch >= 1 && ch <= 6) ||
(ch >= 0x1a && ch <= 0x1f) || (ch >= 0x1a && ch <= 0x1f) ||
(ch >= 0x10 && ch <= 0x19)) { (ch >= 0x10 && ch <= 0x19)) {
tags[t++] = ch; tags[t++] = ch;
++text;
} }
else break;
++text;
if (t == 3) break; if (t == 3) break;
} }

View File

@ -11097,15 +11097,17 @@ vec2 font_print_rect(const char *text, vec4 rect) {
if (num_newlines > 1) { if (num_newlines > 1) {
vec2 text_dims = font_rect(text); vec2 text_dims = font_rect(text);
char tags[4] = {0}; char tags[4] = {0};
for (int i = 0, t = 0, end = strlen(text); i < end; ++i) { int t=0;
char ch = text[i]; while (*text) {
char ch = *text;
if( (ch >= 1 && ch <= 6) || if( (ch >= 1 && ch <= 6) ||
(ch >= 0x1a && ch <= 0x1f) || (ch >= 0x1a && ch <= 0x1f) ||
(ch >= 0x10 && ch <= 0x19)) { (ch >= 0x10 && ch <= 0x19)) {
tags[t++] = ch; tags[t++] = ch;
++text;
} }
else break;
++text;
if (t == 3) break; if (t == 3) break;
} }