#include #include #include #include #include #include "filist.h" #include "bdf.h" #define FONT_PATH "fonts/" #define FONT_PATH_L 6 struct font_loader_t { const char *ext; bool (*func)(const char *, struct font_info *); } font_loaders[] = { { .ext = ".bdf", .func = try_load_bdf }, { .ext = "" } }; struct font_info *get_font(const char *name) { struct font_info *font = find_entry(name); if (font) return font; font = new_entry(name); if (!font) return 0;//out of memory? const uint32_t name_len = strlen(name); for (struct font_loader_t *i = font_loaders; i->ext[0]; ++i) { char *buf = get_block(FONT_PATH_L + name_len + strlen(i->ext) + 1); blockcpy(buf, FONT_PATH, FONT_PATH_L); blockcpy(buf + FONT_PATH_L, name, name_len); strcpy(buf + FONT_PATH_L + name_len, i->ext); struct file *f = open_file(buf); if (!f) { free_block(buf); continue; } syslogf("[libfont] Loading %s%s...", name, i->ext); if (i->func(buf, font)) { close_file(f); free_block(buf); syslogf("[libfont] Loaded %s%s.", name, i->ext); return font; } close_file(f); free_block(buf); syslogf("[libfont] Failed to load %s%s.", name, i->ext); } del_last(); return 0; } void put_char(const struct font_info *font, char ch, uint8_t *pb_ptr, uint32_t pb_pitch, uint8_t bg, uint8_t fg) { //char *const msg = format("put_char(font = 0x%x, ch = '%c', pb_ptr = 0x%x, pb_pitch = %u, bg = 0x%2x, fg = 0x%2x);", font, ch, pb_ptr, pb_pitch, bg, fg); //_system_log(msg); //free_block(msg); const bool *const bitmap = font->bitmaps[(uint8_t)ch] ? font->bitmaps[(uint8_t)ch] : font->bitmaps[0]; for (uint32_t y = 0; y < font->char_height; ++y) for (uint32_t x = 0; x < font->char_width; ++x) pb_ptr[y * pb_pitch + x] = bitmap[y * font->char_width + x] ? fg : bg; }