forked from len0rd/rockbox
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
This commit is contained in:
parent
fe72cbe6ac
commit
642beb0ad4
2 changed files with 32 additions and 66 deletions
|
|
@ -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)
|
||||
{
|
||||
len = rb->strlen(entry->d_name);
|
||||
if (len < 4 || rb->strcmp(entry->d_name + len - 4, ".fnt"))
|
||||
continue;
|
||||
|
||||
rb->strlcpy(p, entry->d_name, len - 3);
|
||||
names[i].string = p;
|
||||
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))
|
||||
{
|
||||
char *p = rb->strrchr(dc[i].name, '.');
|
||||
if (p) *p = 0;
|
||||
if (!rb->strcmp(dc[i].name, new_prefs.font_name))
|
||||
new_font = i;
|
||||
break;
|
||||
}
|
||||
|
||||
names[i].string = dc[i].name;
|
||||
names[i].voice_id = -1;
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue