summaryrefslogtreecommitdiffstats
path: root/src/text.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/text.c')
-rw-r--r--src/text.c37
1 files changed, 37 insertions, 0 deletions
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 <stdlib.h>
+#include <png.h>
+
+#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)
{