int utox_draw_text_multiline_within_box(int x, int y, /* x, y of the top left corner of the box */ int right, int top, int bottom, uint16_t lineheight, const char_t *data, uint16_t length, /* text, and length of the text*/ uint16_t h, uint16_t hlen, uint16_t mark, uint16_t marklen, _Bool multiline ) { uint32_t c1, c2; _Bool greentext = 0, link = 0, draw = y + lineheight >= top; int xc = x; char_t *a = data, *b = a, *end = a + length; while(1) { if(a != end) { if(*a == '>' && (a == data || *(a - 1) == '\n')) { c1 = setcolor(COLOR_MAIN_QUOTETEXT); greentext = 1; } if((a == data || *(a - 1) == '\n' || *(a - 1) == ' ') && ((end - a >= 7 && memcmp(a, "http://", 7) == 0) || (end - a >= 8 && memcmp(a, "https://", 8) == 0))) { c2 = setcolor(COLOR_MAIN_URLTEXT); link = 1; } if(a == data || *(a - 1) == '\n') { char_t *r = a; while (r != end && *r != '\n') { r++; } if (*(r - 1) == '<') { if (greentext) { setcolor(COLOR_MAIN_REDTEXT); } else { greentext = 1; c1 = setcolor(COLOR_MAIN_REDTEXT); } } } } if(a == end || *a == ' ' || *a == '\n') { int count = a - b, w = textwidth(b, count); while(x + w > right) { if(multiline && x == xc) { int fit = textfit(b, count, right - x); if(draw) { drawtexth(x, y, b, fit, b - data, h, hlen, lineheight); drawtextmark(x, y, b, fit, b - data, mark, marklen, lineheight); } count -= fit; b += fit; y += lineheight; draw = (y + lineheight >= top && y < bottom); } else if(!multiline) { int fit = textfit(b, count, right - x); if(draw) { drawtexth(x, y, b, fit, b - data, h, hlen, lineheight); drawtextmark(x, y, b, fit, b - data, mark, marklen, lineheight); } return y + lineheight; } else { y += lineheight; draw = (y + lineheight >= top && y < bottom); int l = utf8_len(b); count -= l; b += l; } x = xc; w = textwidth(b, count); } if(draw) { drawtexth(x, y, b, count, b - data, h, hlen, lineheight); drawtextmark(x, y, b, count, b - data, mark, marklen, lineheight); } x += w; b = a; if(link) { setcolor(c2); link = 0; } if(a == end) { if(greentext) { setcolor(c1); greentext = 0; } break; } if(*a == '\n') { if(greentext) { setcolor(c1); greentext = 0; } y += lineheight; draw = (y + lineheight >= top && y < bottom); b += utf8_len(b); x = xc; } } a += utf8_len(a); } return y + lineheight; }
int drawtextmultiline(int x, int right, int y, int top, int bottom, uint16_t lineheight, char_t *data, uint16_t length, uint16_t h, uint16_t hlen, _Bool multiline) { uint32_t c; _Bool greentext = 0, draw = y + lineheight >= top; int xc = x; char_t *a = data, *b = a, *end = a + length; while(1) { if(a != end && *a == '>' && (a == data || *a == '\n')) { c = setcolor(RGB(0, 128, 0)); greentext = 1; } if(a == end || *a == ' ' || *a == '\n') { int count = a - b, w = textwidth(b, count); while(x + w > right) { if(multiline && x == xc) { int fit = textfit(b, count, right - x); if(draw) { drawtexth(x, y, b, fit, b - data, h, hlen, lineheight); } count -= fit; b += fit; y += lineheight; draw = (y + lineheight >= top && y < bottom); } else if(!multiline) { int fit = textfit(b, count, right - x); if(draw) { drawtexth(x, y, b, fit, b - data, h, hlen, lineheight); } return y + lineheight; } else { y += lineheight; draw = (y + lineheight >= top && y < bottom); int l = utf8_len(b); count -= l; b += l; } x = xc; w = textwidth(b, count); } if(draw) { drawtexth(x, y, b, count, b - data, h, hlen, lineheight); } x += w; b = a; if(a == end) { if(greentext) { setcolor(c); greentext = 0; } break; } if(*a == '\n') { if(greentext) { setcolor(c); greentext = 0; } y += lineheight; draw = (y + lineheight >= top && y < bottom); b += utf8_len(b); x = xc; } } a += utf8_len(a); } return y + lineheight; }