diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-07-17 18:39:56 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-07-17 18:39:56 (EDT) |
commit | 19dc715f75ab52e32f4fa369246877fd6d3b208c (patch) | |
tree | 74e0e224609237f94188cbad70d43885b7ac5c44 | |
parent | 7fc0d5367622770593312c4244dff9ccf46e6b03 (diff) |
text_render(): New function
-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); |