2010-02-14 06:26:16 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2010-02-27 18:07:38 +00:00
|
|
|
* $Id$
|
2010-02-14 06:26:16 +00:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2010-02-27 16:51:51 +00:00
|
|
|
static struct skin_font_info {
|
2010-02-14 06:26:16 +00:00
|
|
|
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;
|
|
|
|
}
|
2010-02-21 02:53:50 +00:00
|
|
|
first_load = false;
|
2010-02-14 06:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* load a font into the skin buffer. return the font id. */
|
2010-08-25 14:11:38 +00:00
|
|
|
int skin_font_load(char* font_name, int glyphs)
|
2010-02-14 06:26:16 +00:00
|
|
|
{
|
|
|
|
int i;
|
2010-08-25 14:23:31 +00:00
|
|
|
int skin_font_size = 0;
|
2010-02-14 06:26:16 +00:00
|
|
|
struct font *pf;
|
2010-02-27 16:51:51 +00:00
|
|
|
struct skin_font_info *font = NULL;
|
2010-02-14 06:26:16 +00:00
|
|
|
char filename[MAX_PATH];
|
2010-08-10 13:36:14 +00:00
|
|
|
char tmp[MAX_PATH];
|
2010-02-14 06:26:16 +00:00
|
|
|
|
|
|
|
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
|
2010-08-10 13:36:14 +00:00
|
|
|
snprintf(tmp, MAX_PATH, FONT_DIR "/%s.fnt", font_name);
|
|
|
|
get_user_file_path(tmp, FORCE_BUFFER_COPY, filename, sizeof(filename));
|
|
|
|
|
2010-02-14 06:26:16 +00:00
|
|
|
for(i=0;i<MAXUSERFONTS;i++)
|
|
|
|
{
|
2010-08-10 13:36:14 +00:00
|
|
|
if (font_table[i].font_id >= 0 && !strcmp(font_table[i].name, filename))
|
2010-02-14 06:26:16 +00:00
|
|
|
{
|
|
|
|
font_table[i].ref_count++;
|
|
|
|
return font_table[i].font_id;
|
|
|
|
}
|
|
|
|
else if (!font && font_table[i].font_id == -1)
|
|
|
|
{
|
|
|
|
font = &font_table[i];
|
2010-09-01 05:21:39 +00:00
|
|
|
strcpy(font_table[i].name, filename);
|
2010-02-14 06:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!font)
|
|
|
|
return -1; /* too many fonts loaded */
|
|
|
|
|
|
|
|
pf = &font->font;
|
|
|
|
if (!font->buffer)
|
|
|
|
{
|
2010-08-25 14:11:38 +00:00
|
|
|
if (!glyphs)
|
|
|
|
glyphs = GLYPHS_TO_CACHE;
|
2010-08-25 14:23:31 +00:00
|
|
|
#ifndef __PCTOOL__
|
2010-08-27 18:25:23 +00:00
|
|
|
skin_font_size = font_glyphs_to_bufsize(filename, glyphs);
|
2010-08-25 14:23:31 +00:00
|
|
|
#endif
|
2010-08-25 14:11:38 +00:00
|
|
|
if ( !skin_font_size )
|
|
|
|
{
|
|
|
|
skin_font_size = SKIN_FONT_SIZE;
|
|
|
|
}
|
|
|
|
pf->buffer_start = (char*)skin_buffer_alloc(skin_font_size);
|
2010-02-14 06:26:16 +00:00
|
|
|
if (!pf->buffer_start)
|
|
|
|
return -1;
|
|
|
|
font->buffer = pf->buffer_start;
|
2010-08-25 14:23:31 +00:00
|
|
|
pf->buffer_size = skin_font_size;
|
2010-02-14 06:26:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pf->buffer_start = font->buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
pf->fd = -1;
|
|
|
|
font->font_id = font_load(pf, filename);
|
|
|
|
|
|
|
|
if (font->font_id < 0)
|
|
|
|
return -1;
|
2010-03-06 14:14:44 +00:00
|
|
|
font->ref_count = 1;
|
2010-02-14 06:26:16 +00:00
|
|
|
|
|
|
|
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';
|
2010-03-06 14:14:44 +00:00
|
|
|
}
|
2010-02-14 06:26:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|