diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2010-02-14 06:26:16 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2010-02-14 06:26:16 +0000 |
commit | 1c2aa35371aed8d895b3448dad865b913da57cfb (patch) | |
tree | 8a790ad8efe5d0abd73eaf77adc854d336ce0ef4 /apps/gui/skin_engine/skin_fonts.c | |
parent | ed21ab1c8c9b16ec62933313c3d36a93d9255f62 (diff) |
FS#10984 - multifont! 2 major additions:
1) seperate UI font for the remote and main displays
2) allow individual skins to load additional fonts for use in the skin (Uo to 7 extra in this first version) see CustomWPS for info on how to load a font in the skins.
Code should always use FONT_UI+screen_number to get the correct user font
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24644 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui/skin_engine/skin_fonts.c')
-rw-r--r-- | apps/gui/skin_engine/skin_fonts.c | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/apps/gui/skin_engine/skin_fonts.c b/apps/gui/skin_engine/skin_fonts.c new file mode 100644 index 0000000000..1d3ef84271 --- /dev/null +++ b/apps/gui/skin_engine/skin_fonts.c @@ -0,0 +1,139 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: skin_tokens.c 24526 2010-02-05 23:58:53Z jdgordon $ + * + * 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 <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include "file.h" +#include "settings.h" +#include "font.h" +#include "skin_buffer.h" +#include "skin_fonts.h" +#define FONT_SIZE 10000 + + +static struct skin_font { + 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<MAXUSERFONTS;i++) + { + if (!first_load) + font_unload(font_table[i].font_id); + font_table[i].font_id = -1; + font_table[i].name[0] = '\0'; + font_table[i].buffer = NULL; + font_table[i].ref_count = 0; + } +} + +/* load a font into the skin buffer. return the font id. */ +int skin_font_load(char* font_name) +{ + int i; + struct font *pf; + struct skin_font *font = NULL; + char filename[MAX_PATH]; + + if (!strcmp(font_name, global_settings.font_file)) + return FONT_UI; +#ifdef HAVE_REMOTE_LCD + if (!strcmp(font_name, global_settings.remote_font_file)) + return FONT_UI_REMOTE; +#endif + for(i=0;i<MAXUSERFONTS;i++) + { + if (font_table[i].font_id >= 0 && !strcmp(font_table[i].name, font_name)) + { + font_table[i].ref_count++; + return font_table[i].font_id; + } + else if (!font && font_table[i].font_id == -1) + { + font = &font_table[i]; + } + } + if (!font) + return -1; /* too many fonts loaded */ + + pf = &font->font; + if (!font->buffer) + { + pf->buffer_start = skin_buffer_alloc(FONT_SIZE); + if (!pf->buffer_start) + return -1; + font->buffer = pf->buffer_start; + } + else + { + pf->buffer_start = font->buffer; + } + pf->buffer_size = FONT_SIZE; + + snprintf(filename, MAX_PATH, FONT_DIR "/%s.fnt", font_name); + strcpy(font->name, font_name); + + 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<MAXUSERFONTS;i++) + { + if (font_table[i].font_id == font_id) + { + if (--font_table[i].ref_count == 0) + { + font_unload(font_id); + font_table[i].font_id = -1; + font_table[i].name[0] = '\0'; + } + return; + } + } +} + + + + + |