summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2010-06-07 12:03:30 +0000
committerTeruaki Kawashima <teru@rockbox.org>2010-06-07 12:03:30 +0000
commit642beb0ad40cc1930baa087e195a50a363c3c046 (patch)
tree10b32ca8afea6d6b8e8e5798651ccd6c709c6883
parentfe72cbe6accbffe394d012974d7ccae299d22d8c (diff)
downloadrockbox-642beb0ad40cc1930baa087e195a50a363c3c046.tar.gz
rockbox-642beb0ad40cc1930baa087e195a50a363c3c046.tar.bz2
rockbox-642beb0ad40cc1930baa087e195a50a363c3c046.zip
text viewer: some fixes related to font.
* don't load font if it's not needed. - loading 16-GNU-Unifont seems to take some time. * restore font to settings on exit plugin. * don't allocate buffer on stack for name of fonts in select font menu. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26657 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/text_viewer/tv_menu.c79
-rw-r--r--apps/plugins/text_viewer/tv_window.c17
2 files changed, 31 insertions, 65 deletions
diff --git a/apps/plugins/text_viewer/tv_menu.c b/apps/plugins/text_viewer/tv_menu.c
index 38c4af1f96..d9b5343490 100644
--- a/apps/plugins/text_viewer/tv_menu.c
+++ b/apps/plugins/text_viewer/tv_menu.c
@@ -247,82 +247,41 @@ static bool tv_footer_setting(void)
names, len, NULL);
}
-static int tv_font_comp(const void *a, const void *b)
-{
- struct opt_items *pa;
- struct opt_items *pb;
-
- pa = (struct opt_items *)a;
- pb = (struct opt_items *)b;
-
- return rb->strcmp(pa->string, pb->string);
-}
-
static bool tv_font_setting(void)
{
int count = 0;
- DIR *dir;
- struct dirent *entry;
int i = 0;
- int len;
int new_font = 0;
int old_font;
bool res;
- int size = 0;
- dir = rb->opendir(FONT_DIR);
- if (!dir)
- {
- rb->splash(HZ/2, "font dir does not access");
- return false;
- }
+ struct tree_context *tree;
+ struct tree_context backup;
+ struct entry *dc;
+ int dirfilter = SHOW_FONT;
- while ((entry = rb->readdir(dir)) != NULL)
- {
- len = rb->strlen(entry->d_name);
- if (len < 4 || rb->strcmp(entry->d_name + len - 4, ".fnt"))
- continue;
- size += len - 3;
- count++;
- }
- rb->closedir(dir);
+ tree = rb->tree_get_context();
+ backup = *tree;
+ dc = tree->dircache;
+ rb->strlcat(backup.currdir, "/", MAX_PATH);
+ rb->strlcat(backup.currdir, dc[tree->selected_item].name, MAX_PATH);
+ tree->dirfilter = &dirfilter;
+ rb->set_current_file(FONT_DIR"/");
+ count = tree->filesindir;
struct opt_items names[count];
- unsigned char font_names[size];
- unsigned char *p = font_names;
- dir = rb->opendir(FONT_DIR);
- if (!dir)
- {
- rb->splash(HZ/2, "font dir does not access");
- return false;
- }
-
- while ((entry = rb->readdir(dir)) != NULL)
+ for (i = 0; i < count; i++)
{
- len = rb->strlen(entry->d_name);
- if (len < 4 || rb->strcmp(entry->d_name + len - 4, ".fnt"))
- continue;
+ char *p = rb->strrchr(dc[i].name, '.');
+ if (p) *p = 0;
+ if (!rb->strcmp(dc[i].name, new_prefs.font_name))
+ new_font = i;
- rb->strlcpy(p, entry->d_name, len - 3);
- names[i].string = p;
+ names[i].string = dc[i].name;
names[i].voice_id = -1;
- p += len - 3;
- if (++i >= count)
- break;
}
- rb->closedir(dir);
-
- rb->qsort(names, count, sizeof(struct opt_items), tv_font_comp);
- for (i = 0; i < count; i++)
- {
- if (!rb->strcmp(names[i].string, new_prefs.font_name))
- {
- new_font = i;
- break;
- }
- }
old_font = new_font;
res = rb->set_option("Select Font", &new_font, INT,
@@ -334,6 +293,8 @@ static bool tv_font_setting(void)
rb->strlcpy(new_prefs.font_name, names[new_font].string, MAX_PATH);
}
+ *tree = backup;
+ rb->set_current_file(backup.currdir);
return res;
}
#endif
diff --git a/apps/plugins/text_viewer/tv_window.c b/apps/plugins/text_viewer/tv_window.c
index 72faf23565..67db879ff6 100644
--- a/apps/plugins/text_viewer/tv_window.c
+++ b/apps/plugins/text_viewer/tv_window.c
@@ -279,23 +279,22 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
{
#ifdef HAVE_LCD_BITMAP
static bool is_executing = false;
+ const unsigned char *font_str;
is_executing = true;
+ font_str = oldp? oldp->font_name: rb->global_settings->font_file;
/* change font */
- if (oldp == NULL || rb->strcmp(oldp->font_name, prefs->font_name))
+ if (rb->strcmp(font_str, prefs->font_name))
{
if (!tv_set_font(prefs->font_name))
{
struct tv_preferences new_prefs = *prefs;
- const unsigned char *font_str;
-
- font_str = (oldp == NULL)? rb->global_settings->font_file : oldp->font_name;
if (!tv_set_font(font_str) && oldp != NULL)
{
- font_str = rb->global_settings->font_file;
- tv_set_font(new_prefs.font_name);
+ font_str = rb->global_settings->font_file;
+ tv_set_font(font_str);
}
rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
@@ -363,6 +362,12 @@ bool tv_init_window(unsigned char *buf, size_t bufsize, size_t *used_size)
void tv_finalize_window(void)
{
tv_finalize_text_reader();
+
+ /* restore font */
+ if (rb->strcmp(rb->global_settings->font_file, prefs->font_name))
+ {
+ tv_set_font(rb->global_settings->font_file);
+ }
}
void tv_move_window(int window_delta, int column_delta)