diff options
Diffstat (limited to 'apps/gui/skin_engine/skin_fonts.c')
-rw-r--r-- | apps/gui/skin_engine/skin_fonts.c | 142 |
1 files changed, 0 insertions, 142 deletions
diff --git a/apps/gui/skin_engine/skin_fonts.c b/apps/gui/skin_engine/skin_fonts.c deleted file mode 100644 index a89b76281b..0000000000 --- a/apps/gui/skin_engine/skin_fonts.c +++ /dev/null | |||
@@ -1,142 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
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 | |||
33 | static struct skin_font_info { | ||
34 | struct font font; | ||
35 | int font_id; | ||
36 | char name[MAX_PATH]; | ||
37 | char *buffer; | ||
38 | int ref_count; /* how many times has this font been loaded? */ | ||
39 | } font_table[MAXUSERFONTS]; | ||
40 | |||
41 | /* need this to know if we should be closing font fd's on the next init */ | ||
42 | static bool first_load = true; | ||
43 | |||
44 | void skin_font_init(void) | ||
45 | { | ||
46 | int i; | ||
47 | for(i=0;i<MAXUSERFONTS;i++) | ||
48 | { | ||
49 | if (!first_load) | ||
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; | ||
55 | } | ||
56 | first_load = false; | ||
57 | } | ||
58 | |||
59 | /* load a font into the skin buffer. return the font id. */ | ||
60 | int skin_font_load(char* font_name, int glyphs) | ||
61 | { | ||
62 | int i; | ||
63 | int skin_font_size = 0; | ||
64 | struct font *pf; | ||
65 | struct skin_font_info *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 | snprintf(filename, MAX_PATH, FONT_DIR "/%s.fnt", font_name); | ||
75 | |||
76 | for(i=0;i<MAXUSERFONTS;i++) | ||
77 | { | ||
78 | if (font_table[i].font_id >= 0 && !strcmp(font_table[i].name, filename)) | ||
79 | { | ||
80 | font_table[i].ref_count++; | ||
81 | return font_table[i].font_id; | ||
82 | } | ||
83 | else if (!font && font_table[i].font_id == -1) | ||
84 | { | ||
85 | font = &font_table[i]; | ||
86 | strcpy(font_table[i].name, filename); | ||
87 | } | ||
88 | } | ||
89 | if (!font) | ||
90 | return -1; /* too many fonts loaded */ | ||
91 | |||
92 | pf = &font->font; | ||
93 | if (!font->buffer) | ||
94 | { | ||
95 | if (!glyphs) | ||
96 | glyphs = GLYPHS_TO_CACHE; | ||
97 | #ifndef __PCTOOL__ | ||
98 | skin_font_size = font_glyphs_to_bufsize(filename, glyphs); | ||
99 | #else | ||
100 | skin_font_size = 1; | ||
101 | #endif | ||
102 | if ( !skin_font_size ) | ||
103 | return -1; | ||
104 | pf->buffer_start = (char*)skin_buffer_alloc(skin_font_size); | ||
105 | if (!pf->buffer_start) | ||
106 | return -1; | ||
107 | font->buffer = pf->buffer_start; | ||
108 | pf->buffer_size = skin_font_size; | ||
109 | } | ||
110 | else | ||
111 | { | ||
112 | pf->buffer_start = font->buffer; | ||
113 | } | ||
114 | |||
115 | pf->fd = -1; | ||
116 | font->font_id = font_load(pf, filename); | ||
117 | |||
118 | if (font->font_id < 0) | ||
119 | return -1; | ||
120 | font->ref_count = 1; | ||
121 | |||
122 | return font->font_id; | ||
123 | } | ||
124 | /* unload a skin font. If a font has been loaded more than once it wont actually | ||
125 | * be unloaded untill all references have been unloaded */ | ||
126 | void skin_font_unload(int font_id) | ||
127 | { | ||
128 | int i; | ||
129 | for(i=0;i<MAXUSERFONTS;i++) | ||
130 | { | ||
131 | if (font_table[i].font_id == font_id) | ||
132 | { | ||
133 | if (--font_table[i].ref_count == 0) | ||
134 | { | ||
135 | font_unload(font_id); | ||
136 | font_table[i].font_id = -1; | ||
137 | font_table[i].name[0] = '\0'; | ||
138 | } | ||
139 | return; | ||
140 | } | ||
141 | } | ||
142 | } | ||