aboutsummaryrefslogtreecommitdiff
path: root/host/font.c
diff options
context:
space:
mode:
authorjaseg <jaseg@jaseg.net>2014-03-07 00:49:16 +0100
committerjaseg <jaseg@jaseg.net>2014-03-07 00:49:16 +0100
commitd16223fd257ccc1d7060e372eb3d950cf68f8d37 (patch)
tree6484e177faff92ed77b2f91acaadaba33131b44d /host/font.c
parent7878aa1d455ab24d0336fc68eb09f726bcba10b2 (diff)
downloadmatelight-d16223fd257ccc1d7060e372eb3d950cf68f8d37.tar.gz
matelight-d16223fd257ccc1d7060e372eb3d950cf68f8d37.tar.bz2
matelight-d16223fd257ccc1d7060e372eb3d950cf68f8d37.zip
Modified text rendering to something frame based
Diffstat (limited to 'host/font.c')
-rw-r--r--host/font.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/host/font.c b/host/font.c
index ee9adb3..c1f1d22 100644
--- a/host/font.c
+++ b/host/font.c
@@ -6,7 +6,8 @@
#include <string.h>
#include <errno.h>
-void render_glyph(glyph_t *g, color_t *buf, unsigned int bufwidth, unsigned int offx, unsigned int offy, color_t fg, color_t bg){
+/* Clips at buffer bounds */
+void render_glyph(glyph_t *g, color_t *buf, unsigned int bufwidth, int offx, unsigned int offy, color_t fg, color_t bg){
unsigned int bitmap_row_width = g->width/8;
uint8_t *bitmap = ((uint8_t *)g) + sizeof(glyph_t);
for(unsigned int y=0; y < g->height; y++){
@@ -16,10 +17,13 @@ void render_glyph(glyph_t *g, color_t *buf, unsigned int bufwidth, unsigned int
data |= bitmap[y*bitmap_row_width+i];
}
color_t *p = buf + (offy+y)*bufwidth + offx;
- for(unsigned int x=0; x < g->width; x++){
- color_t c = (data&(1<<(g->width-1))) ? fg : bg;
- *p++ = c;
- data <<= 1;
+ /* Take care to only render what's within the framebuffer's bounds */
+ for(unsigned int x=0; (x < g->width) && (offx+x < bufwidth); x++){
+ if(offx + x >= 0){
+ color_t c = (data&(1<<(g->width-1))) ? fg : bg;
+ *p++ = c;
+ data <<= 1;
+ }
}
}
}