engine_control/source/firmware/kernel/bitmap.c

36 lines
730 B
C
Raw Normal View History

2016-07-23 05:59:54 +00:00
/*
* canvas.c
*
* Created on: Jan 15, 2016
* Author: tkl
*/
#include <stddef.h>
#include <string.h>
#include "font.h"
#include "bitmap.h"
int bitmap_print_text(const struct font *font, struct bitmap *bitmap, int x_pos,
int y_pos, char *text)
{
int i = 0, pos = 0;
/* align to page */
if(y_pos % 8 != 0)
y_pos -= y_pos % 8;
pos = y_pos / 8 * bitmap->x_size + x_pos;
while(text[i] != 0) {
while(((pos + font->char_size_x) % bitmap->x_size) < font->char_size_x)
pos++;
memcpy(&bitmap->buffer[pos], &font->font[text[i] * font->char_size_x],
font->char_size_x);
memset(&bitmap->buffer[pos + font->char_size_x], 0x00,
font->char_between);
i++;
pos += font->char_size_x + 1;
}
return 0;
}