summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/text.c37
-rw-r--r--src/text.h7
2 files changed, 44 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)
{
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 <png.h>
+
+#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);