/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * * Copyright (C) 2010 Jonathan Gordon * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ #include "config.h" #include #include #include #include "file.h" #include "settings.h" #include "font.h" #include "skin_buffer.h" #include "skin_fonts.h" static struct skin_font_info { struct font font; int font_id; char name[MAX_PATH]; char *buffer; int ref_count; /* how many times has this font been loaded? */ } font_table[MAXUSERFONTS]; /* need this to know if we should be closing font fd's on the next init */ static bool first_load = true; void skin_font_init(void) { int i; for(i=0;i= 0 && !strcmp(font_table[i].name, filename)) { font_table[i].ref_count++; return font_table[i].font_id; } else if (!font && font_table[i].font_id == -1) { font = &font_table[i]; strcpy(font_table[i].name, filename); } } if (!font) return -1; /* too many fonts loaded */ pf = &font->font; if (!font->buffer) { if (!glyphs) glyphs = GLYPHS_TO_CACHE; #ifndef __PCTOOL__ skin_font_size = font_glyphs_to_bufsize(filename, glyphs); #else skin_font_size = 1; #endif if ( !skin_font_size ) return -1; pf->buffer_start = (char*)skin_buffer_alloc(skin_font_size); if (!pf->buffer_start) return -1; font->buffer = pf->buffer_start; pf->buffer_size = skin_font_size; } else { pf->buffer_start = font->buffer; } pf->fd = -1; font->font_id = font_load(pf, filename); if (font->font_id < 0) return -1; font->ref_count = 1; return font->font_id; } /* unload a skin font. If a font has been loaded more than once it wont actually * be unloaded untill all references have been unloaded */ void skin_font_unload(int font_id) { int i; for(i=0;i