diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/text.c | 37 | ||||
-rw-r--r-- | src/text.h | 7 |
2 files changed, 44 insertions, 0 deletions
@@ -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) { @@ -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); |