summaryrefslogtreecommitdiff
path: root/apps/gui/skin_engine/skin_fonts.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/skin_engine/skin_fonts.c')
-rw-r--r--apps/gui/skin_engine/skin_fonts.c139
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: skin_tokens.c 24526 2010-02-05 23:58:53Z jdgordon $
9 *
10 * Copyright (C) 2010 Jonathan Gordon
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23#include <stdio.h>
24#include <string.h>
25#include <stdlib.h>
26
27#include "file.h"
28#include "settings.h"
29#include "font.h"
30#include "skin_buffer.h"
31#include "skin_fonts.h"
32#define FONT_SIZE 10000
33
34
35static struct skin_font {
36 struct font font;
37 int font_id;
38 char name[MAX_PATH];
39 char *buffer;
40 int ref_count; /* how many times has this font been loaded? */
41} font_table[MAXUSERFONTS];
42
43/* need this to know if we should be closing font fd's on the next init */
44static bool first_load = true;
45
46void skin_font_init(void)
47{
48 int i;
49 for(i=0;i<MAXUSERFONTS;i++)
50 {
51 if (!first_load)
52 font_unload(font_table[i].font_id);
53 font_table[i].font_id = -1;
54 font_table[i].name[0] = '\0';
55 font_table[i].buffer = NULL;
56 font_table[i].ref_count = 0;
57 }
58}
59
60/* load a font into the skin buffer. return the font id. */
61int skin_font_load(char* font_name)
62{
63 int i;
64 struct font *pf;
65 struct skin_font *font = NULL;
66 char filename[MAX_PATH];
67
68 if (!strcmp(font_name, global_settings.font_file))
69 return FONT_UI;
70#ifdef HAVE_REMOTE_LCD
71 if (!strcmp(font_name, global_settings.remote_font_file))
72 return FONT_UI_REMOTE;
73#endif
74 for(i=0;i<MAXUSERFONTS;i++)
75 {
76 if (font_table[i].font_id >= 0 && !strcmp(font_table[i].name, font_name))
77 {
78 font_table[i].ref_count++;
79 return font_table[i].font_id;
80 }
81 else if (!font && font_table[i].font_id == -1)
82 {
83 font = &font_table[i];
84 }
85 }
86 if (!font)
87 return -1; /* too many fonts loaded */
88
89 pf = &font->font;
90 if (!font->buffer)
91 {
92 pf->buffer_start = skin_buffer_alloc(FONT_SIZE);
93 if (!pf->buffer_start)
94 return -1;
95 font->buffer = pf->buffer_start;
96 }
97 else
98 {
99 pf->buffer_start = font->buffer;
100 }
101 pf->buffer_size = FONT_SIZE;
102
103 snprintf(filename, MAX_PATH, FONT_DIR "/%s.fnt", font_name);
104 strcpy(font->name, font_name);
105
106 pf->fd = -1;
107 font->font_id = font_load(pf, filename);
108
109 if (font->font_id < 0)
110 return -1;
111 font->ref_count = 1;
112
113 return font->font_id;
114}
115
116/* unload a skin font. If a font has been loaded more than once it wont actually
117 * be unloaded untill all references have been unloaded */
118void skin_font_unload(int font_id)
119{
120 int i;
121 for(i=0;i<MAXUSERFONTS;i++)
122 {
123 if (font_table[i].font_id == font_id)
124 {
125 if (--font_table[i].ref_count == 0)
126 {
127 font_unload(font_id);
128 font_table[i].font_id = -1;
129 font_table[i].name[0] = '\0';
130 }
131 return;
132 }
133 }
134}
135
136
137
138
139