From d257683f3edbb0a2b819b27d34c2708809d3d57d Mon Sep 17 00:00:00 2001 From: Marcoen Hirschberg Date: Wed, 22 Mar 2006 09:53:27 +0000 Subject: font caching fixes by Frank Dischner git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9178 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/lcd-16bit.c | 5 ----- firmware/drivers/lcd-2bit-horz.c | 5 ----- firmware/drivers/lcd-h100-remote.c | 5 ----- firmware/drivers/lcd-h100.c | 5 ----- firmware/drivers/lcd-recorder.c | 5 ----- firmware/font.c | 29 ++++++++++++++++++++--------- 6 files changed, 20 insertions(+), 34 deletions(-) diff --git a/firmware/drivers/lcd-16bit.c b/firmware/drivers/lcd-16bit.c index 08e62b828f..e98403aa1b 100644 --- a/firmware/drivers/lcd-16bit.c +++ b/firmware/drivers/lcd-16bit.c @@ -735,11 +735,6 @@ static void lcd_putsxyofs(int x, int y, int ofs, const unsigned char *str) int width; const unsigned char *bits; - /* check input range */ - if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) - ch = pf->defaultchar; - ch -= pf->firstchar; - /* get proportional width and glyph bits */ width = font_get_width(pf,ch); diff --git a/firmware/drivers/lcd-2bit-horz.c b/firmware/drivers/lcd-2bit-horz.c index a76ebe1f0d..bfb69da33b 100644 --- a/firmware/drivers/lcd-2bit-horz.c +++ b/firmware/drivers/lcd-2bit-horz.c @@ -703,11 +703,6 @@ static void lcd_putsxyofs(int x, int y, int ofs, const unsigned char *str) int width; const unsigned char *bits; - /* check input range */ - if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) - ch = pf->defaultchar; - ch -= pf->firstchar; - /* get proportional width and glyph bits */ width = font_get_width(pf,ch); diff --git a/firmware/drivers/lcd-h100-remote.c b/firmware/drivers/lcd-h100-remote.c index 58953f61b5..ffe6f1492c 100644 --- a/firmware/drivers/lcd-h100-remote.c +++ b/firmware/drivers/lcd-h100-remote.c @@ -1117,11 +1117,6 @@ static void lcd_remote_putsxyofs(int x, int y, int ofs, const unsigned char *str int width; const unsigned char *bits; - /* check input range */ - if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) - ch = pf->defaultchar; - ch -= pf->firstchar; - /* get proportional width and glyph bits */ width = font_get_width(pf, ch); diff --git a/firmware/drivers/lcd-h100.c b/firmware/drivers/lcd-h100.c index 1d80458679..8a06367112 100644 --- a/firmware/drivers/lcd-h100.c +++ b/firmware/drivers/lcd-h100.c @@ -1033,11 +1033,6 @@ static void lcd_putsxyofs(int x, int y, int ofs, const unsigned char *str) int width; const unsigned char *bits; - /* check input range */ - if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) - ch = pf->defaultchar; - ch -= pf->firstchar; - /* get proportional width and glyph bits */ width = font_get_width(pf,ch); diff --git a/firmware/drivers/lcd-recorder.c b/firmware/drivers/lcd-recorder.c index 7a44acf590..89b041dc3d 100644 --- a/firmware/drivers/lcd-recorder.c +++ b/firmware/drivers/lcd-recorder.c @@ -886,11 +886,6 @@ static void lcd_putsxyofs(int x, int y, int ofs, const unsigned char *str) int width; const unsigned char *bits; - /* check input range */ - if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) - ch = pf->defaultchar; - ch -= pf->firstchar; - /* get proportional width and glyph bits */ width = font_get_width(pf,ch); diff --git a/firmware/font.c b/firmware/font.c index d45c0e803f..5f244bcb37 100644 --- a/firmware/font.c +++ b/firmware/font.c @@ -389,10 +389,6 @@ int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber) for (str = utf8decode(str, &ch); ch != 0 ; str = utf8decode(str, &ch)) { - /* check input range*/ - if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) - ch = pf->defaultchar; - ch -= pf->firstchar; /* get proportional width and glyph bits*/ width += font_get_width(pf,ch); @@ -467,6 +463,11 @@ static void cache_create(int maxwidth, int height) */ int font_get_width(struct font* pf, unsigned short char_code) { + /* check input range*/ + if (char_code < pf->firstchar || char_code >= pf->firstchar+pf->size) + char_code = pf->defaultchar; + char_code -= pf->firstchar; + return (fnt_file >= 0 && pf != &sysfont)? font_cache_get(&font_cache_ui,char_code,load_cache_entry,pf)->width: pf->width? pf->width[char_code]: pf->maxwidth; @@ -475,6 +476,12 @@ int font_get_width(struct font* pf, unsigned short char_code) const unsigned char* font_get_bits(struct font* pf, unsigned short char_code) { const unsigned char* bits; + + /* check input range*/ + if (char_code < pf->firstchar || char_code >= pf->firstchar+pf->size) + char_code = pf->defaultchar; + char_code -= pf->firstchar; + if (fnt_file >= 0 && pf != &sysfont) { bits = @@ -493,11 +500,15 @@ const unsigned char* font_get_bits(struct font* pf, unsigned short char_code) void glyph_file_write(void* data) { struct font_cache_entry* p = data; + struct font* pf = &font_ui; + unsigned short ch; unsigned char tmp[2]; - if (p->_char_code != 0xffff && glyph_file >= 0) { - tmp[0] = p->_char_code >> 8; - tmp[1] = p->_char_code & 0xff; + ch = p->_char_code + pf->firstchar; + + if (ch != 0xffff && glyph_file >= 0) { + tmp[0] = ch >> 8; + tmp[1] = ch & 0xff; if (write(glyph_file, tmp, 2) != 2) { close(glyph_file); glyph_file = -1; @@ -545,8 +556,8 @@ void glyph_cache_load(void) close(fd); } else { /* load latin1 chars into cache */ - ch = 255 - pf->firstchar; - while (ch--) + ch = 256; + while (ch-- > 32) font_get_bits(pf, ch); } } -- cgit v1.2.3