summaryrefslogtreecommitdiffstats
path: root/apps/gui
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2011-09-24 13:19:34 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2011-09-24 13:19:34 +0000
commitaa0f4a4bbe370032d8166628f456709be1330118 (patch)
tree597c91fb16493881d7a281ef3c28e274a899022b /apps/gui
parentf323300b82aa945dd4cadb20d8d7e23a6602ef49 (diff)
downloadrockbox-aa0f4a4bbe370032d8166628f456709be1330118.tar.gz
rockbox-aa0f4a4bbe370032d8166628f456709be1330118.zip
FS#12273 - use buflib for font storage. thanks to the testers :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30589 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui')
-rw-r--r--apps/gui/skin_engine/skin_engine.c5
-rw-r--r--apps/gui/skin_engine/skin_engine.h4
-rw-r--r--apps/gui/skin_engine/skin_fonts.c142
-rw-r--r--apps/gui/skin_engine/skin_fonts.h50
-rw-r--r--apps/gui/skin_engine/skin_parser.c78
-rw-r--r--apps/gui/skin_engine/skin_render.c5
-rw-r--r--apps/gui/skin_engine/wps_internals.h3
-rw-r--r--apps/gui/statusbar-skinned.c4
-rw-r--r--apps/gui/usb_screen.c9
-rw-r--r--apps/gui/viewport.c7
10 files changed, 71 insertions, 236 deletions
diff --git a/apps/gui/skin_engine/skin_engine.c b/apps/gui/skin_engine/skin_engine.c
index 7a9a10ec57..069c3467a9 100644
--- a/apps/gui/skin_engine/skin_engine.c
+++ b/apps/gui/skin_engine/skin_engine.c
@@ -107,9 +107,9 @@ void settings_apply_skins(void)
{
int i, j;
- for (i=0; i<SKINNABLE_SCREENS_COUNT; i++)
+ for(j=0; j<SKINNABLE_SCREENS_COUNT; j++)
{
- FOR_NB_SCREENS(j)
+ FOR_NB_SCREENS(i)
skin_data_free_buflib_allocs(&skins[j][i].data);
}
@@ -117,7 +117,6 @@ void settings_apply_skins(void)
#ifdef HAVE_LCD_BITMAP
skin_backdrop_init();
- skin_font_init();
#endif
gui_sync_skin_init();
diff --git a/apps/gui/skin_engine/skin_engine.h b/apps/gui/skin_engine/skin_engine.h
index c8104f9304..310411bb1d 100644
--- a/apps/gui/skin_engine/skin_engine.h
+++ b/apps/gui/skin_engine/skin_engine.h
@@ -25,7 +25,6 @@
#ifndef PLUGIN
-#include "skin_fonts.h"
#include "tag_table.h"
#include "wps_internals.h" /* TODO: remove this line.. shoudlnt be needed */
@@ -44,8 +43,7 @@ enum skinnable_screens {
#ifdef HAVE_LCD_BITMAP
-#define SKIN_BUFFER_SIZE (2048 + SKIN_FONT_SIZE) + \
- (WPS_MAX_TOKENS * \
+#define SKIN_BUFFER_SIZE (WPS_MAX_TOKENS * \
(sizeof(struct wps_token) + (sizeof(struct skin_element))))
#endif
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 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * 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"
-
-static struct skin_font_info {
- 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;
- }
- first_load = false;
-}
-
-/* load a font into the skin buffer. return the font id. */
-int skin_font_load(char* font_name, int glyphs)
-{
- int i;
- int skin_font_size = 0;
- struct font *pf;
- struct skin_font_info *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
- snprintf(filename, MAX_PATH, FONT_DIR "/%s.fnt", font_name);
-
- for(i=0;i<MAXUSERFONTS;i++)
- {
- if (font_table[i].font_id >= 0 && !strcmp(font_table[i].name, filename))
- {
- font_table[i].ref_count++;
- return font_table[i].font_id;
- }
- else if (!font && font_table[i].font_id == -1)
- {
- font = &font_table[i];
- strcpy(font_table[i].name, filename);
- }
- }
- if (!font)
- return -1; /* too many fonts loaded */
-
- pf = &font->font;
- if (!font->buffer)
- {
- if (!glyphs)
- glyphs = GLYPHS_TO_CACHE;
-#ifndef __PCTOOL__
- skin_font_size = font_glyphs_to_bufsize(filename, glyphs);
-#else
- skin_font_size = 1;
-#endif
- if ( !skin_font_size )
- return -1;
- pf->buffer_start = (char*)skin_buffer_alloc(skin_font_size);
- if (!pf->buffer_start)
- return -1;
- font->buffer = pf->buffer_start;
- pf->buffer_size = skin_font_size;
- }
- else
- {
- pf->buffer_start = font->buffer;
- }
-
- 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;
- }
- }
-}
diff --git a/apps/gui/skin_engine/skin_fonts.h b/apps/gui/skin_engine/skin_fonts.h
deleted file mode 100644
index 698ed4fe7c..0000000000
--- a/apps/gui/skin_engine/skin_fonts.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * 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"
-
-#ifndef _SKINFONTS_H_
-#define _SKINFONTS_H_
-
-#if LCD_HEIGHT > 160
-#define SKIN_FONT_SIZE (1024*10)
-#else
-#define SKIN_FONT_SIZE (1024*3)
-#endif
-#define GLYPHS_TO_CACHE 256
-
-void skin_font_init(void);
-
-/* load a font into the skin buffer. return the font id.
- * reserve room for glyphs glyphs */
-int skin_font_load(char* font_name, int glyphs);
-
-/* 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);
-#endif
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index 9c73c3e682..8c87553be3 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -62,7 +62,6 @@
#include "radio.h"
#include "tuner.h"
#endif
-#include "skin_fonts.h"
#ifdef HAVE_LCD_BITMAP
#include "bmp.h"
@@ -77,6 +76,12 @@
#define WPS_ERROR_INVALID_PARAM -1
+#if LCD_HEIGHT > 160
+#define SKIN_FONT_SIZE (1024*10)
+#else
+#define SKIN_FONT_SIZE (1024*3)
+#endif
+#define GLYPHS_TO_CACHE 256
static bool isdefault(struct skin_tag_parameter *param)
{
@@ -415,8 +420,13 @@ static int parse_font_load(struct skin_element *element,
glyphs = element->params[2].data.number;
else
glyphs = GLYPHS_TO_CACHE;
+ if (id < 2)
+ {
+ DEBUGF("font id must be >= 2\n");
+ return 1;
+ }
#if defined(DEBUG) || defined(SIMULATOR)
- if (skinfonts[id-FONT_FIRSTUSERFONT].name != NULL)
+ if (skinfonts[id-2].name != NULL)
{
DEBUGF("font id %d already being used\n", id);
}
@@ -426,9 +436,9 @@ static int parse_font_load(struct skin_element *element,
ptr = strchr(filename, '.');
if (!ptr || strncmp(ptr, ".fnt", 4))
return WPS_ERROR_INVALID_PARAM;
- skinfonts[id-FONT_FIRSTUSERFONT].id = -1;
- skinfonts[id-FONT_FIRSTUSERFONT].name = filename;
- skinfonts[id-FONT_FIRSTUSERFONT].glyphs = glyphs;
+ skinfonts[id-2].id = -1;
+ skinfonts[id-2].name = filename;
+ skinfonts[id-2].glyphs = glyphs;
return 0;
}
@@ -1442,6 +1452,11 @@ void skin_data_free_buflib_allocs(struct wps_data *wps_data)
core_free(img->buflib_handle);
list = list->next;
}
+ if (wps_data->font_ids != NULL)
+ {
+ while (wps_data->font_count > 0)
+ font_unload(wps_data->font_ids[--wps_data->font_count]);
+ }
#endif
#endif
}
@@ -1617,6 +1632,8 @@ static bool load_skin_bitmaps(struct wps_data *wps_data, char *bmpdir)
static bool skin_load_fonts(struct wps_data *data)
{
/* don't spit out after the first failue to aid debugging */
+ int id_array[MAXUSERFONTS];
+ int font_count = 0;
bool success = true;
struct skin_element *vp_list;
int font_id;
@@ -1628,19 +1645,20 @@ static bool skin_load_fonts(struct wps_data *data)
(struct skin_viewport*)vp_list->data;
struct viewport *vp = &skin_vp->vp;
-
- if (vp->font <= FONT_UI)
+ font_id = skin_vp->parsed_fontid;
+ if (font_id == 1)
{ /* the usual case -> built-in fonts */
-#ifdef HAVE_REMOTE_LCD
- if (vp->font == FONT_UI)
- vp->font += curr_screen;
-#endif
+ vp->font = global_status.font_id[curr_screen];
+ continue;
+ }
+ else if (font_id <= 0)
+ {
+ vp->font = FONT_SYSFIXED;
continue;
}
- font_id = vp->font;
/* now find the corresponding skin_font */
- struct skin_font *font = &skinfonts[font_id-FONT_FIRSTUSERFONT];
+ struct skin_font *font = &skinfonts[font_id-2];
if (!font->name)
{
if (success)
@@ -1655,10 +1673,12 @@ static bool skin_load_fonts(struct wps_data *data)
* multiple viewports use the same */
if (font->id < 0)
{
- char *dot = strchr(font->name, '.');
- *dot = '\0';
- font->id = skin_font_load(font->name,
- skinfonts[font_id-FONT_FIRSTUSERFONT].glyphs);
+ char path[MAX_PATH];
+ snprintf(path, sizeof path, FONT_DIR "/%s", font->name);
+ font->id = font_load(path/*,
+ skinfonts[font_id-FONT_FIRSTUSERFONT].glyphs*/);
+ //printf("[%d] %s -> %d\n",font_id, font->name, font->id);
+ id_array[font_count++] = font->id;
}
if (font->id < 0)
@@ -1667,13 +1687,24 @@ static bool skin_load_fonts(struct wps_data *data)
font_id, font->name);
font->name = NULL; /* to stop trying to load it again if we fail */
success = false;
- font->name = NULL;
continue;
}
/* finally, assign the font_id to the viewport */
vp->font = font->id;
}
+ if (success)
+ {
+ data->font_ids = skin_buffer_alloc(font_count * sizeof(int));
+ if (data->font_ids == NULL)
+ {
+ while (font_count > 0)
+ font_unload(id_array[--font_count]);
+ return false;
+ }
+ memcpy(data->font_ids, id_array, sizeof(int)*font_count);
+ data->font_count = font_count;
+ }
return success;
}
@@ -1690,17 +1721,12 @@ static int convert_viewport(struct wps_data *data, struct skin_element* element)
skin_vp->hidden_flags = 0;
skin_vp->label = NULL;
skin_vp->is_infovp = false;
+ skin_vp->parsed_fontid = 1;
element->data = skin_vp;
curr_vp = skin_vp;
curr_viewport_element = element;
viewport_set_defaults(&skin_vp->vp, curr_screen);
-#ifdef HAVE_REMOTE_LCD
- /* viewport_set_defaults() sets the font to FONT_UI+curr_screen.
- * This parser requires font 1 to always be the UI font,
- * so force it back to FONT_UI and handle the screen number at the end */
- skin_vp->vp.font = FONT_UI;
-#endif
#if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
skin_vp->start_fgcolour = skin_vp->vp.fg_pattern;
@@ -1788,9 +1814,7 @@ static int convert_viewport(struct wps_data *data, struct skin_element* element)
#ifdef HAVE_LCD_BITMAP
/* font */
if (!isdefault(param))
- {
- skin_vp->vp.font = param->data.number;
- }
+ skin_vp->parsed_fontid = param->data.number;
#endif
if ((unsigned) skin_vp->vp.x >= (unsigned) display->lcdwidth ||
skin_vp->vp.width + skin_vp->vp.x > display->lcdwidth ||
diff --git a/apps/gui/skin_engine/skin_render.c b/apps/gui/skin_engine/skin_render.c
index 994ca23553..5a64be17dc 100644
--- a/apps/gui/skin_engine/skin_render.c
+++ b/apps/gui/skin_engine/skin_render.c
@@ -31,6 +31,7 @@
#ifdef HAVE_ALBUMART
#include "albumart.h"
#endif
+#include "settings.h"
#include "skin_display.h"
#include "skin_engine.h"
#include "skin_parser.h"
@@ -650,6 +651,10 @@ void skin_render_viewport(struct skin_element* viewport, struct gui_wps *gwps,
img->display = -1;
imglist = imglist->next;
}
+
+ /* fix font ID's */
+ if (skin_viewport->parsed_fontid == 1)
+ skin_viewport->vp.font = global_status.font_id[display->screen_type];
#endif
while (line)
diff --git a/apps/gui/skin_engine/wps_internals.h b/apps/gui/skin_engine/wps_internals.h
index 244d08595e..c16191c41d 100644
--- a/apps/gui/skin_engine/wps_internals.h
+++ b/apps/gui/skin_engine/wps_internals.h
@@ -182,6 +182,7 @@ struct skin_viewport {
char hidden_flags;
bool is_infovp;
char* label;
+ int parsed_fontid;
#if LCD_DEPTH > 1
unsigned start_fgcolour;
unsigned start_bgcolour;
@@ -325,6 +326,8 @@ struct wps_data
struct skin_element *tree;
#ifdef HAVE_LCD_BITMAP
struct skin_token_list *images;
+ int *font_ids;
+ int font_count;
#endif
#if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
struct {
diff --git a/apps/gui/statusbar-skinned.c b/apps/gui/statusbar-skinned.c
index 3f914bd922..ad9a391e4c 100644
--- a/apps/gui/statusbar-skinned.c
+++ b/apps/gui/statusbar-skinned.c
@@ -125,6 +125,10 @@ struct viewport *sb_skin_get_info_vp(enum screen_type screen)
viewportmanager_theme_undo(screen, true);
}
vp = skin_find_item(infovp_label[screen], SKIN_FIND_UIVP, data);
+ if (!vp)
+ return NULL;
+ if (vp->parsed_fontid == 1)
+ vp->vp.font = global_status.font_id[screen];
return &vp->vp;
}
diff --git a/apps/gui/usb_screen.c b/apps/gui/usb_screen.c
index 66b7094760..2b3355021d 100644
--- a/apps/gui/usb_screen.c
+++ b/apps/gui/usb_screen.c
@@ -41,7 +41,6 @@
#ifdef HAVE_LCD_BITMAP
#include "bitmaps/usblogo.h"
-#include "skin_engine/skin_fonts.h"
#endif
#ifdef HAVE_REMOTE_LCD
@@ -265,11 +264,9 @@ void gui_usb_screen_run(bool early_usb)
{
/* The font system leaves the .fnt fd's open, so we need for force close them all */
#ifdef HAVE_LCD_BITMAP
- font_reset(NULL);
-#ifdef HAVE_REMOTE_LCD
- font_load_remoteui(NULL);
-#endif
- skin_font_init(); /* unload all the skin fonts */
+ FOR_NB_SCREENS(i)
+ font_unload(global_status.font_id[i]);
+ // FIXME skin_font_init(); /* unload all the skin fonts */
#endif
}
diff --git a/apps/gui/viewport.c b/apps/gui/viewport.c
index 34ebbf9043..df8093d581 100644
--- a/apps/gui/viewport.c
+++ b/apps/gui/viewport.c
@@ -272,13 +272,10 @@ void viewportmanager_theme_changed(const int which)
screens[SCREEN_MAIN].has_buttonbar = global_settings.buttonbar;
}
#endif
- if (which & THEME_UI_VIEWPORT)
- {
- }
if (which & THEME_LANGUAGE)
{
}
- if (which & THEME_STATUSBAR)
+ if (which & (THEME_STATUSBAR|THEME_UI_VIEWPORT))
{
FOR_NB_SCREENS(i)
{
@@ -324,7 +321,7 @@ void viewport_set_fullscreen(struct viewport *vp,
#ifndef __PCTOOL__
set_default_align_flags(vp);
#endif
- vp->font = FONT_UI + screen; /* default to UI to discourage SYSFONT use */
+ vp->font = global_status.font_id[screen];
vp->drawmode = DRMODE_SOLID;
#if LCD_DEPTH > 1
#ifdef HAVE_REMOTE_LCD