1
0
Fork 0
forked from len0rd/rockbox

Redo r30826 (and hopefully not reintroduce font issues) which cleans up the font API. FONT_UI is deprecated, use screens[screen].getuifont() instead (and .setuifont() to set it after a font has been loaded)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30932 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jonathan Gordon 2011-11-08 10:09:33 +00:00
parent 452a3ce274
commit f19f3efb07
13 changed files with 94 additions and 95 deletions

View file

@ -424,13 +424,10 @@ static void ft_load_font(char *file)
set_file(file, (char *)global_settings.font_file, MAX_FILENAME); set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
#endif #endif
splash(0, ID2P(LANG_WAIT)); splash(0, ID2P(LANG_WAIT));
current_font_id = global_status.font_id[screen]; current_font_id = screens[screen].getuifont();
if (current_font_id >= 0) if (current_font_id >= 0)
font_unload(current_font_id); font_unload(current_font_id);
current_font_id = font_load(file); screens[screen].setuifont(font_load(file));
if(screen==SCREEN_MAIN)
font_set_ui(current_font_id);
global_status.font_id[screen] = current_font_id;
viewportmanager_theme_changed(THEME_UI_VIEWPORT); viewportmanager_theme_changed(THEME_UI_VIEWPORT);
} }
#endif #endif

View file

@ -246,10 +246,12 @@ static int parse_statusbar_tags(struct skin_element* element,
viewport_set_fullscreen(&default_vp->vp, curr_screen); viewport_set_fullscreen(&default_vp->vp, curr_screen);
} }
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
/* viewport_set_defaults() sets the font to FONT_UI+curr_screen. /* This parser requires viewports which will use the settings font to
* This parser requires font 1 to always be the UI font, * have font == 1, but the above viewport_set() calls set font to
* so force it back to FONT_UI and handle the screen number at the end */ * the current real font id. So force 1 here it will be set correctly
default_vp->vp.font = FONT_UI; * at the end
*/
default_vp->vp.font = 1;
#endif #endif
} }
return 0; return 0;
@ -1645,7 +1647,7 @@ static bool skin_load_fonts(struct wps_data *data)
font_id = skin_vp->parsed_fontid; font_id = skin_vp->parsed_fontid;
if (font_id == 1) if (font_id == 1)
{ /* the usual case -> built-in fonts */ { /* the usual case -> built-in fonts */
vp->font = global_status.font_id[curr_screen]; vp->font = screens[curr_screen].getuifont();
continue; continue;
} }
else if (font_id <= 0) else if (font_id <= 0)

View file

@ -658,7 +658,7 @@ void skin_render_viewport(struct skin_element* viewport, struct gui_wps *gwps,
/* fix font ID's */ /* fix font ID's */
if (skin_viewport->parsed_fontid == 1) if (skin_viewport->parsed_fontid == 1)
skin_viewport->vp.font = global_status.font_id[display->screen_type]; skin_viewport->vp.font = display->getuifont();
#endif #endif
while (line) while (line)

View file

@ -128,7 +128,7 @@ struct viewport *sb_skin_get_info_vp(enum screen_type screen)
if (!vp) if (!vp)
return NULL; return NULL;
if (vp->parsed_fontid == 1) if (vp->parsed_fontid == 1)
vp->vp.font = global_status.font_id[screen]; vp->vp.font = screens[screen].getuifont();
return &vp->vp; return &vp->vp;
} }

View file

@ -265,8 +265,8 @@ void gui_usb_screen_run(bool early_usb)
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
FOR_NB_SCREENS(i) FOR_NB_SCREENS(i)
{ {
font_unload(global_status.font_id[i]); font_unload(screens[i].getuifont());
global_status.font_id[i] = -1; screens[i].setuifont(FONT_SYSFIXED);
} }
skin_unload_all(); skin_unload_all();
#endif #endif

View file

@ -319,7 +319,7 @@ void viewport_set_fullscreen(struct viewport *vp,
#ifndef __PCTOOL__ #ifndef __PCTOOL__
set_default_align_flags(vp); set_default_align_flags(vp);
#endif #endif
vp->font = global_status.font_id[screen]; vp->font = screens[screen].getuifont();
vp->line_height = 0; /* calculate from font height */ vp->line_height = 0; /* calculate from font height */
vp->drawmode = DRMODE_SOLID; vp->drawmode = DRMODE_SOLID;
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1

View file

@ -1435,7 +1435,7 @@ static void bubbles_drawboard(struct game_context* bb) {
/* clear screen */ /* clear screen */
rb->lcd_clear_display(); rb->lcd_clear_display();
int font = rb->screens[SCREEN_MAIN]->getfont(); int font = rb->screens[SCREEN_MAIN]->getuifont();
h = rb->font_get(font)->height + 1; h = rb->font_get(font)->height + 1;
/* draw background */ /* draw background */
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR

View file

@ -720,7 +720,7 @@ static void kbd_calc_params(struct keyboard_parameters *pm,
(touchscreen_get_mode() == TOUCHSCREEN_POINT)); (touchscreen_get_mode() == TOUCHSCREEN_POINT));
#endif #endif
pm->curfont = pm->default_lines ? FONT_SYSFIXED : FONT_UI; pm->curfont = pm->default_lines ? FONT_SYSFIXED : sc->getuifont();
font = font_get(pm->curfont); font = font_get(pm->curfont);
pm->font_h = font->height; pm->font_h = font->height;

View file

@ -77,6 +77,24 @@ void screen_helper_setfont(int font)
#endif #endif
} }
int screen_helper_getuifont(void)
{
#ifdef HAVE_LCD_BITMAP
return global_status.font_id[SCREEN_MAIN];
#else
return FONT_SYSFIXED;
#endif
}
void screen_helper_setuifont(int font)
{
#ifdef HAVE_LCD_BITMAP
global_status.font_id[SCREEN_MAIN] = font;
#else
(void)font;
#endif
}
#if NB_SCREENS == 2 #if NB_SCREENS == 2
static int screen_helper_remote_getcharwidth(void) static int screen_helper_remote_getcharwidth(void)
{ {
@ -116,6 +134,23 @@ void screen_helper_remote_setfont(int font)
font = global_status.font_id[SCREEN_REMOTE]; font = global_status.font_id[SCREEN_REMOTE];
lcd_remote_setfont(font); lcd_remote_setfont(font);
} }
int screen_helper_remote_getuifont(void)
{
#ifdef HAVE_LCD_BITMAP
return global_status.font_id[SCREEN_REMOTE];
#else
return FONT_SYSFIXED;
#endif
}
void screen_helper_remote_setuifont(int font)
{
#ifdef HAVE_LCD_BITMAP
global_status.font_id[SCREEN_REMOTE] = font;
#endif
}
#endif #endif
struct screen screens[NB_SCREENS] = struct screen screens[NB_SCREENS] =
@ -147,7 +182,8 @@ struct screen screens[NB_SCREENS] =
.getstringsize=&lcd_getstringsize, .getstringsize=&lcd_getstringsize,
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
.setfont=screen_helper_setfont, .setfont=screen_helper_setfont,
.getfont=&lcd_getfont, .getuifont=screen_helper_getuifont,
.setuifont=screen_helper_setuifont,
.mono_bitmap=&lcd_mono_bitmap, .mono_bitmap=&lcd_mono_bitmap,
.mono_bitmap_part=&lcd_mono_bitmap_part, .mono_bitmap_part=&lcd_mono_bitmap_part,
.set_drawmode=&lcd_set_drawmode, .set_drawmode=&lcd_set_drawmode,
@ -246,8 +282,9 @@ struct screen screens[NB_SCREENS] =
.getheight=&lcd_remote_getheight, .getheight=&lcd_remote_getheight,
.getstringsize=&lcd_remote_getstringsize, .getstringsize=&lcd_remote_getstringsize,
#if 1 /* all remote LCDs are bitmapped so far */ #if 1 /* all remote LCDs are bitmapped so far */
.setfont=screen_helper_setfont, .setfont=screen_helper_remote_setfont,
.getfont=&lcd_remote_getfont, .getuifont=screen_helper_remote_getuifont,
.setuifont=screen_helper_remote_setuifont,
.mono_bitmap=&lcd_remote_mono_bitmap, .mono_bitmap=&lcd_remote_mono_bitmap,
.mono_bitmap_part=&lcd_remote_mono_bitmap_part, .mono_bitmap_part=&lcd_remote_mono_bitmap_part,
.bitmap=(screen_bitmap_func*)&lcd_remote_bitmap, .bitmap=(screen_bitmap_func*)&lcd_remote_bitmap,

View file

@ -71,7 +71,8 @@ struct screen
int (*getstringsize)(const unsigned char *str, int *w, int *h); int (*getstringsize)(const unsigned char *str, int *w, int *h);
#if defined(HAVE_LCD_BITMAP) || defined(HAVE_REMOTE_LCD) /* always bitmap */ #if defined(HAVE_LCD_BITMAP) || defined(HAVE_REMOTE_LCD) /* always bitmap */
void (*setfont)(int newfont); void (*setfont)(int newfont);
int (*getfont)(void); int (*getuifont)(void);
void (*setuifont)(int newfont);
void (*scroll_step)(int pixels); void (*scroll_step)(int pixels);
void (*puts_style_offset)(int x, int y, const unsigned char *str, void (*puts_style_offset)(int x, int y, const unsigned char *str,

View file

@ -876,37 +876,38 @@ void settings_apply(bool read_disk)
/* fonts need to be loaded before the WPS */ /* fonts need to be loaded before the WPS */
if (global_settings.font_file[0] if (global_settings.font_file[0]
&& global_settings.font_file[0] != '-') { && global_settings.font_file[0] != '-') {
const char* loaded_font = font_filename(global_status.font_id[SCREEN_MAIN]); int font_ui = screens[SCREEN_MAIN].getuifont();
const char* loaded_font = font_filename(font_ui);
snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
global_settings.font_file); global_settings.font_file);
if (!loaded_font || strcmp(loaded_font, buf)) if (!loaded_font || strcmp(loaded_font, buf))
{ {
CHART2(">font_load ", global_settings.font_file); CHART2(">font_load ", global_settings.font_file);
if (global_status.font_id[SCREEN_MAIN] >= 0) if (font_ui >= 0)
font_unload(global_status.font_id[SCREEN_MAIN]); font_unload(font_ui);
rc = font_load(buf); rc = font_load(buf);
font_set_ui(rc);
CHART2("<font_load ", global_settings.font_file); CHART2("<font_load ", global_settings.font_file);
global_status.font_id[SCREEN_MAIN] = rc; screens[SCREEN_MAIN].setuifont(rc);
lcd_setfont(rc); screens[SCREEN_MAIN].setfont(rc);
} }
} }
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
if ( global_settings.remote_font_file[0] if ( global_settings.remote_font_file[0]
&& global_settings.remote_font_file[0] != '-') { && global_settings.remote_font_file[0] != '-') {
const char* loaded_font = font_filename(global_status.font_id[SCREEN_REMOTE]); int font_ui = screens[SCREEN_REMOTE].getuifont();
const char* loaded_font = font_filename(font_ui);
snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt", snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
global_settings.remote_font_file); global_settings.remote_font_file);
if (!loaded_font || strcmp(loaded_font, buf)) if (!loaded_font || strcmp(loaded_font, buf))
{ {
CHART2(">font_load_remoteui ", global_settings.remote_font_file); CHART2(">font_load_remoteui ", global_settings.remote_font_file);
if (global_status.font_id[SCREEN_REMOTE] >= 0) if (font_ui >= 0)
font_unload(global_status.font_id[SCREEN_REMOTE]); font_unload(font_ui);
rc = font_load(buf); rc = font_load(buf);
CHART2("<font_load_remoteui ", global_settings.remote_font_file); CHART2("<font_load_remoteui ", global_settings.remote_font_file);
global_status.font_id[SCREEN_REMOTE] = rc; screens[SCREEN_REMOTE].setuifont(rc);
lcd_remote_setfont(rc); screens[SCREEN_REMOTE].setfont(rc);
} }
} }
#endif #endif
@ -1076,10 +1077,11 @@ void settings_reset(void)
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
FOR_NB_SCREENS(i) FOR_NB_SCREENS(i)
{ {
if (global_status.font_id[i] > FONT_SYSFIXED) if (screens[i].getuifont() > FONT_SYSFIXED)
{ {
font_unload(global_status.font_id[i]); font_unload(screens[i].getuifont());
global_status.font_id[i] = FONT_SYSFIXED; screens[i].setuifont(FONT_SYSFIXED);
screens[i].setfont(FONT_SYSFIXED);
} }
} }
#endif #endif

View file

@ -55,7 +55,7 @@ enum {
/* SYSFONT, FONT_UI, FONT_UI_REMOTE + MAXUSERFONTS fonts in skins */ /* SYSFONT, FONT_UI, FONT_UI_REMOTE + MAXUSERFONTS fonts in skins */
#define MAXFONTS (FONT_FIRSTUSERFONT + MAXUSERFONTS) #define MAXFONTS (FONT_FIRSTUSERFONT + MAXUSERFONTS)
#define FONT_UI MAXUSERFONTS #define FONT_UI MAXFONTS
/* /*
* .fnt loadable font file format definition * .fnt loadable font file format definition
@ -124,9 +124,6 @@ int font_glyphs_to_bufsize(const char *path, int glyphs);
void font_unload(int font_id); void font_unload(int font_id);
void font_unload_all(void); void font_unload_all(void);
void font_lock(int font_id, bool lock); void font_lock(int font_id, bool lock);
/* set the default UI font */
void font_set_ui(int font_id);
int font_get_ui(void);
struct font* font_get(int font); struct font* font_get(int font);

View file

@ -88,7 +88,6 @@ struct buflib_alloc_data {
}; };
static int buflib_allocations[MAXFONTS]; static int buflib_allocations[MAXFONTS];
static int font_ui = -1;
static int cache_fd; static int cache_fd;
static struct font* cache_pf; static struct font* cache_pf;
@ -560,7 +559,7 @@ int font_load_ex(const char *path, size_t buffer_size)
lock_font_handle(handle, false); lock_font_handle(handle, false);
buflib_allocations[font_id] = handle; buflib_allocations[font_id] = handle;
//printf("%s -> [%d] -> %d\n", path, font_id, handle); //printf("%s -> [%d] -> %d\n", path, font_id, *handle);
return font_id; /* success!*/ return font_id; /* success!*/
} }
int font_load(const char *path) int font_load(const char *path)
@ -617,52 +616,28 @@ void font_unload_all(void)
/* /*
* Return a pointer to an incore font structure. * Return a pointer to an incore font structure.
* Return the requested font, font_ui, or sysfont * If the requested font isn't loaded/compiled-in,
* decrement the font number and try again.
*/ */
struct font* font_get(int font_id) struct font* font_get(int font)
{ {
struct buflib_alloc_data *alloc; struct font* pf;
struct font *pf; if (font == FONT_UI)
int handle, id=-1; font = MAXFONTS-1;
if (font <= FONT_SYSFIXED)
if( font_id == FONT_UI )
id = font_ui;
if( font_id == FONT_SYSFIXED )
return &sysfont; return &sysfont;
if( id == -1 ) while (1) {
id = font_id; if (buflib_allocations[font] > 0)
{
handle = buflib_allocations[id]; struct buflib_alloc_data *alloc = core_get_data(buflib_allocations[font]);
if( handle > 0 ) pf = &alloc->font;
{ if (pf && pf->height)
alloc = core_get_data(buflib_allocations[id]); return pf;
pf=&alloc->font; }
if( pf && pf->height ) if (--font < 0)
return pf; return &sysfont;
} }
handle = buflib_allocations[font_ui];
if( handle > 0 )
{
alloc = core_get_data(buflib_allocations[font_ui]);
pf=&alloc->font;
if( pf && pf->height )
return pf;
}
return &sysfont;
}
void font_set_ui( int font_id )
{
font_ui = font_id;
return;
}
int font_get_ui()
{
return font_ui;
} }
static int pf_to_handle(struct font* pf) static int pf_to_handle(struct font* pf)
@ -1004,18 +979,6 @@ struct font* font_get(int font)
return &sysfont; return &sysfont;
} }
void font_set_ui(int font_id)
{
(void)font_id;
return;
}
int font_get_ui()
{
return FONT_SYSFIXED;
}
/* /*
* Returns width of character * Returns width of character
*/ */