From 7fc0d5367622770593312c4244dff9ccf46e6b03 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Wed, 17 Jul 2019 18:34:39 -0400 Subject: font_render(): New function --- diff --git a/src/font.c b/src/font.c index c198943..c2300b5 100644 --- a/src/font.c +++ b/src/font.c @@ -27,6 +27,10 @@ #include +#define FONT_H(f) ((size_t) (f)->desc.height) +#define FONT_W(f) ((size_t) (f)->desc.width) +#define CHAR_PIXEL(f, c, x, y) (((((c) * FONT_H(f)) + (y)) * FONT_W(f)) + (x)) + struct font { const struct font_desc desc; }; @@ -66,3 +70,27 @@ font_get_height(struct font *font) { return font->desc.height; } + +void +font_render(struct font *font, png_const_colorp fg, png_const_colorp bg, + char ch, png_bytepp rows, int row, int col) +{ + size_t y; + size_t r; + size_t x; + size_t c; + + for (y = 0, r = row * FONT_H(font); y < FONT_H(font); ++y, ++r) { + for (x = 0, c = col * FONT_W(font); x < FONT_W(font); ++x, ++c){ + if (CHAR_PIXEL(font, ch, x, y)) { + *(&rows[r][c] + 0) = fg->red; + *(&rows[r][c] + 1) = fg->green; + *(&rows[r][c] + 2) = fg->blue; + } else { + *(&rows[r][c] + 0) = bg->red; + *(&rows[r][c] + 1) = bg->green; + *(&rows[r][c] + 2) = bg->blue; + } + } + } +} diff --git a/src/font.h b/src/font.h index 0e22c55..ee3942e 100644 --- a/src/font.h +++ b/src/font.h @@ -19,8 +19,8 @@ * along with fbcon2png. If not, see . */ -#ifndef FONT_H -#define FONT_H +#ifndef FONT_H_ +#define FONT_H_ #include @@ -35,4 +35,8 @@ font_get_width(struct font *font) __attribute__((pure)); int font_get_height(struct font *font) __attribute__((pure)); -#endif /* FONT_H */ +void +font_render(struct font *font, png_const_colorp fg, png_const_colorp bg, + char ch, png_bytepp rows, int row, int col); + +#endif /* FONT_H_ */ -- cgit v0.9.1