summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/text.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/text.c b/src/text.c
index 695d5aa..cb777e4 100644
--- a/src/text.c
+++ b/src/text.c
@@ -22,6 +22,7 @@
#include "text.h"
#include <stdlib.h>
+#include <string.h>
#include <png.h>
@@ -97,14 +98,20 @@ text_get_height(struct text *text)
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;
+ char *string_start;
+ char *string;
+ size_t row;
+ size_t col;
+ png_color fg = {255, 255, 255};
+ png_color bg = { 0, 0, 0};
+
+ string_start = calloc(strlen(text->string) + 1, sizeof(*text->string));
+ if (!string_start) {
+ return;
+ }
+ memcpy(string_start, text->string, strlen(text->string) + 1);
+ string = string_start;
row = 0;
col = 0;
while (string && *string) {
@@ -131,6 +138,8 @@ text_render(struct text *text, struct font *font, png_bytepp rows)
for (; col < text->width; ++col) {
font_render(font, &fg, &bg, ' ', rows, row, col);
}
+
+ free(string_start);
}
struct text *