From 19dc715f75ab52e32f4fa369246877fd6d3b208c Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Wed, 17 Jul 2019 18:39:56 -0400 Subject: text_render(): New function --- diff --git a/src/text.c b/src/text.c index d418f57..2ae5a66 100644 --- a/src/text.c +++ b/src/text.c @@ -23,6 +23,10 @@ #include +#include + +#include "font.h" + #define MAX(a, b) (((a) > (b)) ? (a) : (b)) struct text { @@ -82,6 +86,39 @@ text_get_height(struct text *text) return text->height; } +void +text_render(struct text *text, struct font *font, png_bytepp rows) +{ + const char *string; + size_t row; + size_t col; + png_color fg = {255, 255, 255}; + png_color bg = { 0, 0, 0}; + + string = text->string; + + row = 0; + col = 0; + while (string && *string) { + if (*string == 0x1B && *(string + 1) == '[') { /* CSI */ + string += 2; + for (; *string >= 0x30 && *string <= 0x3F; ++string); + for (; *string >= 0x20 && *string <= 0x2F; ++string); + if (*string >= 0x40 && *string <= 0x7E) { + ++string; + } + } else if (*string == '\n') { + col = 0; + ++row; + ++string; + } else { + font_render(font, &fg, &bg, *string, rows, row, col); + ++col; + ++string; + } + } +} + struct text * text_destroy(struct text **text_p) { diff --git a/src/text.h b/src/text.h index 0671bb6..e3596c3 100644 --- a/src/text.h +++ b/src/text.h @@ -22,6 +22,10 @@ #ifndef TEXT_H #define TEXT_H +#include + +#include "font.h" + struct text; struct text * @@ -33,6 +37,9 @@ text_get_width(struct text *text) __attribute__((pure)); int text_get_height(struct text *text) __attribute__((pure)); +void +text_render(struct text *text, struct font *font, png_bytepp rows); + struct text * text_destroy(struct text **text_p); -- cgit v0.9.1