NE_API void load_font_asset(font_asset* font) { if (font->is_system_font) { load_font_from_system(font); } else { load_font_from_file(font); } }
bool _load_fonts(void) { #if ENABLE(FONT_CONFIG) load_font_from_fontconfig(); #elif defined(__ANDROID__) load_font_from_android(); #else FILE *pf = 0; if ((pf = OPENFILE(CONFIG_FILE, F("r")))) { load_font_from_file(pf); fclose(pf); } else { // not found config file. write_default(); } #endif if (!g_font_map.size()) { font_item* ansi_font = get_font_item("arial", "arial.ttf"); font_item* uni_font = get_font_item("sung", "sung.ttf"); g_font_map.add(uni_font); g_font_map.add(ansi_font); } if (FT_Init_FreeType(&g_library) == 0) return true; else return false; }
fs_emu_font *fs_emu_font_new_from_file(const char *name) { fs_emu_log("load font %s\n", name); fs_emu_font *font = g_malloc0(sizeof(fs_emu_font)); font->image = load_font_from_file(name); prepare_font(font); return font; }
fs_emu_font *fs_emu_font_new_from_file(const char *name) { fs_emu_log("load font %s\n", name); fs_emu_font *font = g_malloc0(sizeof(fs_emu_font)); font->image = load_font_from_file(name); if (font->image) { unsigned char *data = font->image->data; uint32_t *idata = (uint32_t *) data; uint32_t *line = idata; int width = font->image->width; int height = font->image->height; int x = 1; int y = 1; int h = 0; //uint32_t blank = line[0] & MASK; uint32_t blank = line[0]; for (int i = 0; i < height; i++) { //if (i > 0 && h == 0 && (idata[i * width] & MASK) == blank) { if (i > 0 && h == 0 && idata[i * width] == blank) { h = i - 1; } idata[i * width] = 0x00000000; } fs_emu_log("font height: %d pixels\n", h); font->h = h; unsigned char c = 31; // first actual character is 32 int in_character = 0; while (1) { if (in_character) { //if ((line[x] & MASK) == blank) { if (line[x] == blank) { //fs_log("blank at %d %d\n", x, y); in_character = 0; font->w[c] = x - font->x[c]; } } else { //if ((line[x] & MASK) != blank) { if ((line[x]) != blank) { c++; //fs_log("char %c at %d %d\n", c, x, y); font->x[c] = x; font->y[c] = y; in_character = 1; } } //fs_log("%d %x\n", x, idata[x]); line[x] = 0x00000000; x++; if (x == width) { x = 1; y = y + (h + 1); if (y >= height) { break; } line = line + width * (h + 1); //exit(1); } } } //#define FONT_DEBUG #ifdef FONT_DEBUG char *out_name; out_name = g_strdup_printf("%s.json", name); FILE *f = fopen(out_name, "wb"); ffs_log(f, "{\"x\":["); for (int i = 0; i < 256; i++) { if (i > 0) { ffs_log(f, ","); } ffs_log(f, "%d", font->x[i]); } ffs_log(f, "],\"y\":["); for (int i = 0; i < 256; i++) { if (i > 0) { ffs_log(f, ","); } ffs_log(f, "%d", font->y[i]); } ffs_log(f, "],\"w\":["); for (int i = 0; i < 256; i++) { if (i > 0) { ffs_log(f, ","); } ffs_log(f, "%d", font->w[i]); } ffs_log(f, "],\"h\":["); for (int i = 0; i < 256; i++) { if (i > 0) { ffs_log(f, ","); } ffs_log(f, "%d", font->h); } ffs_log(f, "]}"); g_free(out_name); fclose(f); out_name = g_strdup_printf("%s.raw", name); f = fopen(out_name, "wb"); fwrite(data, 1, width * height * 4, f); fclose(f); g_free(out_name); #endif return font; }