=== modified file 'firmware/font.c' --- firmware/font.c 2010-05-06 16:35:13 +0000 +++ firmware/font.c 2010-05-21 14:45:12 +0000 @@ -36,18 +36,30 @@ #include "panic.h" #include "rbunicode.h" #include "diacritic.h" +#include "buffer.h" #define MAX_FONTSIZE_FOR_16_BIT_OFFSETS 0xFFDB -/* max static loadable font buffer size */ +/* Min/max sizes for main font buffer. */ +/* If the first font loaded is <= MAX, we will allocate */ +/* enough memory to contain the whole font, but no less */ +/* than MIN, to allow for the user to change font later. */ +/* If the first font loaded is > MAX, we will allocate */ +/* MAX, and use the font cache to selectively load glyphs */ #ifndef MAX_FONT_SIZE #if LCD_HEIGHT > 64 -#if MEM > 2 +#if MEM >= 32 +#define MIN_FONT_SIZE 60000 +#define MAX_FONT_SIZE 300000 +#elif MEM > 2 +#define MIN_FONT_SIZE 60000 #define MAX_FONT_SIZE 60000 #else +#define MIN_FONT_SIZE 10000 #define MAX_FONT_SIZE 10000 #endif #else +#define MIN_FONT_SIZE 4000 #define MAX_FONT_SIZE 4000 #endif #endif @@ -75,8 +87,9 @@ /* structure filled in by font_load */ static struct font font_ui; -/* static buffer allocation structures */ -static unsigned char main_buf[MAX_FONT_SIZE]; +/* pointer to boot-time allocated font buffer */ +static unsigned char *main_buf; +static unsigned int main_buf_size; #ifdef HAVE_REMOTE_LCD #define REMOTE_FONT_SIZE 10000 static struct font remote_font_ui; @@ -335,6 +348,20 @@ /* Check file size */ size = filesize(pf->fd); + + /* If buffer size is zero, we need to allocate it */ + if (buf_size == 0) + { + if (size > MAX_FONT_SIZE) + buf_size = MAX_FONT_SIZE; + else if (size < MIN_FONT_SIZE) + buf_size = MIN_FONT_SIZE; + else + buf_size = size; + buf = main_buf = buffer_alloc(buf_size); + main_buf_size = buf_size; + } + pf->buffer_start = buf; pf->buffer_size = buf_size; @@ -430,8 +457,8 @@ if (font_id == FONT_UI) { /* currently, font loading replaces earlier font allocation*/ - buffer = (unsigned char *)(((intptr_t)main_buf + 3) & ~3); - buffer_size = MAX_FONT_SIZE; + buffer = main_buf; + buffer_size = main_buf_size; } else {