Index: apps/lang/english.lang
===================================================================
--- apps/lang/english.lang (revision 30602)
+++ apps/lang/english.lang (working copy)
@@ -12830,3 +12830,17 @@
multidrive_usb: "USB Hide Internal Drive"
+
+ id: LANG_GLYPHS
+ desc: in settings_menu
+ user: core
+
+ *: "Glyphs to cache"
+
+
+ *: "Glyphs to cache"
+
+
+ *: "Glyphs to cache"
+
+
Index: apps/settings.c
===================================================================
--- apps/settings.c (revision 30602)
+++ apps/settings.c (working copy)
@@ -885,7 +885,7 @@
CHART2(">font_load ", global_settings.font_file);
if (global_status.font_id[SCREEN_MAIN] >= 0)
font_unload(global_status.font_id[SCREEN_MAIN]);
- rc = font_load(buf);
+ rc = font_load_glyphs(buf, global_settings.glyphs);
CHART2(" 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)
{
return param->type == DEFAULT;
@@ -1678,12 +1671,13 @@
#ifndef __PCTOOL__
if (skinfonts[font_id-2].glyphs > 0)
{
- font->id = font_load_ex(path,
- font_glyphs_to_bufsize(path, skinfonts[font_id-2].glyphs));
+ font->id = font_load_glyphs(path,
+ skinfonts[font_id-2].glyphs);
}
else
#endif
- font->id = font_load(path);
+ font->id = font_load_glyphs(path,
+ global_settings.glyphs);
//printf("[%d] %s -> %d\n",font_id, font->name, font->id);
id_array[font_count++] = font->id;
}
Index: apps/settings.h
===================================================================
--- apps/settings.h (revision 30602)
+++ apps/settings.h (working copy)
@@ -671,6 +671,7 @@
#ifdef HAVE_REMOTE_LCD
unsigned char remote_font_file[MAX_FILENAME+1]; /* last font */
#endif
+ int glyphs; /* default glyphs to load */
unsigned char kbd_file[MAX_FILENAME+1]; /* last keyboard */
#endif /* HAVE_LCD_BITMAP */
int backlight_timeout; /* backlight off timeout: 0-18 0=never,
Index: apps/menus/theme_menu.c
===================================================================
--- apps/menus/theme_menu.c (revision 30602)
+++ apps/menus/theme_menu.c (working copy)
@@ -332,7 +332,7 @@
MENUITEM_FUNCTION(browse_fonts, MENU_FUNC_USEPARAM,
ID2P(LANG_CUSTOM_FONT),
browse_folder, (void*)&fonts, NULL, Icon_Font);
-
+MENUITEM_SETTING(glyphs, &global_settings.glyphs, NULL);
MENUITEM_FUNCTION(browse_sbs, MENU_FUNC_USEPARAM,
ID2P(LANG_BASE_SKIN),
browse_folder, (void*)&sbs, NULL, Icon_Wps);
@@ -372,6 +372,7 @@
&browse_themes,
#ifdef HAVE_LCD_BITMAP
&browse_fonts,
+ &glyphs,
#endif
&browse_wps,
#ifdef HAVE_REMOTE_LCD
Index: apps/settings_list.c
===================================================================
--- apps/settings_list.c (revision 30602)
+++ apps/settings_list.c (working copy)
@@ -222,7 +222,9 @@
#else
#define DEFAULT_FONTNAME "35-Adobe-Helvetica"
#endif
-
+#define DEFAULT_GLYPHS 250
+#define MIN_GLYPHS 50
+#define MAX_GLYPHS 65535
#else
#define DEFAULT_FONTNAME ""
#endif
@@ -1587,6 +1589,9 @@
#ifdef HAVE_LCD_BITMAP
TEXT_SETTING(F_THEMESETTING, font_file, "font",
DEFAULT_FONTNAME, FONT_DIR "/", ".fnt"),
+ INT_SETTING(F_THEMESETTING, glyphs, LANG_GLYPHS, DEFAULT_GLYPHS,
+ "glyphs",UNIT_INT, MIN_GLYPHS, MAX_GLYPHS, 5,
+ NULL, NULL, NULL),
#endif
#ifdef HAVE_REMOTE_LCD
TEXT_SETTING(F_THEMESETTING, remote_font_file, "remote font",
Index: firmware/export/font.h
===================================================================
--- firmware/export/font.h (revision 30602)
+++ firmware/export/font.h (working copy)
@@ -118,6 +118,8 @@
const char* font_filename(int font_id);
int font_load(const char *path);
int font_load_ex(const char *path, size_t buffer_size);
+int font_load_glyphs(const char *path, int glyphs);
+#define font_load_whole(x) font_load_glyphs(x, 65535);
int font_glyphs_to_bufsize(const char *path, int glyphs);
void font_unload(int font_id);
Index: firmware/font.c
===================================================================
--- firmware/font.c (revision 30602)
+++ firmware/font.c (working copy)
@@ -43,18 +43,9 @@
#define MAX_FONTSIZE_FOR_16_BIT_OFFSETS 0xFFDB
-/* max static loadable font buffer size */
-#ifndef MAX_FONT_SIZE
-#if LCD_HEIGHT > 64
-#if MEMORYSIZE > 2
-#define MAX_FONT_SIZE 60000
-#else
-#define MAX_FONT_SIZE 10000
-#endif
-#else
-#define MAX_FONT_SIZE 4000
-#endif
-#endif
+/* number of glyphs to allocate in font cache */
+/* (gui uses global_settings.glyphs, not this) */
+#define DEFAULT_GLYPH_CAPACITY 250
#ifndef FONT_HEADER_SIZE
#define FONT_HEADER_SIZE 36
@@ -542,9 +533,14 @@
}
int font_load(const char *path)
{
- return font_load_ex(path, MAX_FONT_SIZE);
+ return font_load_glyphs(path, DEFAULT_GLYPH_CAPACITY);
}
+int font_load_glyphs(const char *path, int glyphs)
+{
+ return font_load_ex(path, font_glyphs_to_bufsize( path, glyphs));
+}
+
void font_unload(int font_id)
{
int *handle = &buflib_allocations[font_id];
@@ -758,10 +754,14 @@
return;
}
+/* returns the total font and cache buffer size needed for
+ * the number of requested glyphs or the entire file size
+ * if smaller than the font_cache structure would be */
int font_glyphs_to_bufsize(const char *path, int glyphs)
{
struct font f;
int bufsize;
+ int fsize;
char buf[FONT_HEADER_SIZE];
f.buffer_start = buf;
@@ -771,7 +771,7 @@
f.fd = open(path, O_RDONLY|O_BINARY);
if(f.fd < 0)
return 0;
-
+ fsize = filesize(f.fd);
read(f.fd, f.buffer_position, FONT_HEADER_SIZE);
f.buffer_end = f.buffer_position + FONT_HEADER_SIZE;
@@ -785,10 +785,17 @@
bufsize = LRU_SLOT_OVERHEAD + sizeof(struct font_cache_entry) +
sizeof( unsigned short);
bufsize += glyph_bytes(&f, f.maxwidth);
+ if(glyphs > f.size)
+ glyphs = f.size;
bufsize *= glyphs;
if ( bufsize < FONT_HEADER_SIZE )
bufsize = FONT_HEADER_SIZE;
- return bufsize;
+ /* pad for alignment */
+ bufsize += 3;
+ if ( fsize < bufsize )
+ return fsize;
+ else
+ return bufsize;
}
static int ushortcmp(const void *a, const void *b)
Index: manual/configure_rockbox/theme_settings.tex
===================================================================
--- manual/configure_rockbox/theme_settings.tex (revision 30602)
+++ manual/configure_rockbox/theme_settings.tex (working copy)
@@ -52,6 +52,8 @@
\item[Font.]
Browse the installed fonts on your \dap{}. Selecting one will activate it.
See \reference{ref:Loadingfonts} for further details about fonts.
+ \item[Glyphs.]
+ Set the amount of font memory to reserve for loaded fonts in glyphs.
} % \nopt{player}
\item[While Playing Screen.]