1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
30 #include "skin_buffer.h"
31 #include "skin_fonts.h"
33 static struct skin_font_info
{
38 int ref_count
; /* how many times has this font been loaded? */
39 } font_table
[MAXUSERFONTS
];
41 /* need this to know if we should be closing font fd's on the next init */
42 static bool first_load
= true;
44 void skin_font_init(void)
47 for(i
=0;i
<MAXUSERFONTS
;i
++)
50 font_unload(font_table
[i
].font_id
);
51 font_table
[i
].font_id
= -1;
52 font_table
[i
].name
[0] = '\0';
53 font_table
[i
].buffer
= NULL
;
54 font_table
[i
].ref_count
= 0;
59 /* load a font into the skin buffer. return the font id. */
60 int skin_font_load(char* font_name
)
64 struct skin_font_info
*font
= NULL
;
65 char filename
[MAX_PATH
];
67 if (!strcmp(font_name
, global_settings
.font_file
))
69 #ifdef HAVE_REMOTE_LCD
70 if (!strcmp(font_name
, global_settings
.remote_font_file
))
71 return FONT_UI_REMOTE
;
73 for(i
=0;i
<MAXUSERFONTS
;i
++)
75 if (font_table
[i
].font_id
>= 0 && !strcmp(font_table
[i
].name
, font_name
))
77 font_table
[i
].ref_count
++;
78 return font_table
[i
].font_id
;
80 else if (!font
&& font_table
[i
].font_id
== -1)
82 font
= &font_table
[i
];
86 return -1; /* too many fonts loaded */
91 pf
->buffer_start
= skin_buffer_alloc(SKIN_FONT_SIZE
);
92 if (!pf
->buffer_start
)
94 font
->buffer
= pf
->buffer_start
;
98 pf
->buffer_start
= font
->buffer
;
100 pf
->buffer_size
= SKIN_FONT_SIZE
;
102 snprintf(filename
, MAX_PATH
, FONT_DIR
"/%s.fnt", font_name
);
103 strcpy(font
->name
, font_name
);
106 font
->font_id
= font_load(pf
, filename
);
108 if (font
->font_id
< 0)
112 return font
->font_id
;
115 /* unload a skin font. If a font has been loaded more than once it wont actually
116 * be unloaded untill all references have been unloaded */
117 void skin_font_unload(int font_id
)
120 for(i
=0;i
<MAXUSERFONTS
;i
++)
122 if (font_table
[i
].font_id
== font_id
)
124 if (--font_table
[i
].ref_count
== 0)
126 font_unload(font_id
);
127 font_table
[i
].font_id
= -1;
128 font_table
[i
].name
[0] = '\0';