summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-07-17 23:16:34 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-07-17 23:16:34 (EDT)
commit9875de422d9878b4fbc0e8a8dc408bf1b3a91434 (patch)
treee16e0af697891f9bd4954f28ff7da80424067cee /src
parent4aa7fce693904721d89aa92ed01b89266e3bed1a (diff)
text_set_width(), text_set_height(): New functions
And fill in all the remaining rows in text_render().
Diffstat (limited to 'src')
-rw-r--r--src/main.c2
-rw-r--r--src/text.c19
-rw-r--r--src/text.h6
3 files changed, 25 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index a48fd67..9fb84e1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -36,6 +36,8 @@ main(int argc, char **argv)
font = font_find(argv[1]);
text = text_new(argv[2]);
+ text_set_width(text, 80);
+ text_set_height(text, 25);
image = image_new("test.png");
image_render(image, text, font);
text_destroy(&text);
diff --git a/src/text.c b/src/text.c
index b7b569a..dea3259 100644
--- a/src/text.c
+++ b/src/text.c
@@ -96,6 +96,18 @@ text_get_height(struct text *text)
return text->height;
}
+size_t
+text_set_width(struct text *text, size_t width)
+{
+ return text->width = MAX(text->width, width);
+}
+
+size_t
+text_set_height(struct text *text, size_t height)
+{
+ return text->height = MAX(text->height, height);
+}
+
void
text_render(struct text *text, struct font *font, png_bytepp rows)
{
@@ -142,8 +154,11 @@ text_render(struct text *text, struct font *font, png_bytepp rows)
++string;
}
}
- for (; col < text->width; ++col) {
- font_render(font, &fg, &bg, ' ', rows, row, col);
+ for (; row < text->height; ++row) {
+ for (; col < text->width; ++col) {
+ font_render(font, &fg, &bg, ' ', rows, row, col);
+ }
+ col = 0;
}
free(string_start);
diff --git a/src/text.h b/src/text.h
index 86da775..9c581d6 100644
--- a/src/text.h
+++ b/src/text.h
@@ -37,6 +37,12 @@ text_get_width(struct text *text) __attribute__((pure));
size_t
text_get_height(struct text *text) __attribute__((pure));
+size_t
+text_set_width(struct text *text, size_t width);
+
+size_t
+text_set_height(struct text *text, size_t height);
+
void
text_render(struct text *text, struct font *font, png_bytepp rows);