summaryrefslogtreecommitdiff
path: root/firmware/font.c
diff options
context:
space:
mode:
authorMarcoen Hirschberg <marcoen@gmail.com>2006-03-22 09:53:27 +0000
committerMarcoen Hirschberg <marcoen@gmail.com>2006-03-22 09:53:27 +0000
commitd257683f3edbb0a2b819b27d34c2708809d3d57d (patch)
tree94ad35018c304fa345f1b1963cc49493086b39a5 /firmware/font.c
parentd0e8c57b779bbf96d84c5251465dc92303df5424 (diff)
downloadrockbox-d257683f3edbb0a2b819b27d34c2708809d3d57d.tar.gz
rockbox-d257683f3edbb0a2b819b27d34c2708809d3d57d.zip
font caching fixes by Frank Dischner
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9178 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/font.c')
-rw-r--r--firmware/font.c29
1 files changed, 20 insertions, 9 deletions
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)
389 389
390 for (str = utf8decode(str, &ch); ch != 0 ; str = utf8decode(str, &ch)) 390 for (str = utf8decode(str, &ch); ch != 0 ; str = utf8decode(str, &ch))
391 { 391 {
392 /* check input range*/
393 if (ch < pf->firstchar || ch >= pf->firstchar+pf->size)
394 ch = pf->defaultchar;
395 ch -= pf->firstchar;
396 392
397 /* get proportional width and glyph bits*/ 393 /* get proportional width and glyph bits*/
398 width += font_get_width(pf,ch); 394 width += font_get_width(pf,ch);
@@ -467,6 +463,11 @@ static void cache_create(int maxwidth, int height)
467 */ 463 */
468int font_get_width(struct font* pf, unsigned short char_code) 464int font_get_width(struct font* pf, unsigned short char_code)
469{ 465{
466 /* check input range*/
467 if (char_code < pf->firstchar || char_code >= pf->firstchar+pf->size)
468 char_code = pf->defaultchar;
469 char_code -= pf->firstchar;
470
470 return (fnt_file >= 0 && pf != &sysfont)? 471 return (fnt_file >= 0 && pf != &sysfont)?
471 font_cache_get(&font_cache_ui,char_code,load_cache_entry,pf)->width: 472 font_cache_get(&font_cache_ui,char_code,load_cache_entry,pf)->width:
472 pf->width? pf->width[char_code]: pf->maxwidth; 473 pf->width? pf->width[char_code]: pf->maxwidth;
@@ -475,6 +476,12 @@ int font_get_width(struct font* pf, unsigned short char_code)
475const unsigned char* font_get_bits(struct font* pf, unsigned short char_code) 476const unsigned char* font_get_bits(struct font* pf, unsigned short char_code)
476{ 477{
477 const unsigned char* bits; 478 const unsigned char* bits;
479
480 /* check input range*/
481 if (char_code < pf->firstchar || char_code >= pf->firstchar+pf->size)
482 char_code = pf->defaultchar;
483 char_code -= pf->firstchar;
484
478 if (fnt_file >= 0 && pf != &sysfont) 485 if (fnt_file >= 0 && pf != &sysfont)
479 { 486 {
480 bits = 487 bits =
@@ -493,11 +500,15 @@ const unsigned char* font_get_bits(struct font* pf, unsigned short char_code)
493void glyph_file_write(void* data) 500void glyph_file_write(void* data)
494{ 501{
495 struct font_cache_entry* p = data; 502 struct font_cache_entry* p = data;
503 struct font* pf = &font_ui;
504 unsigned short ch;
496 unsigned char tmp[2]; 505 unsigned char tmp[2];
497 506
498 if (p->_char_code != 0xffff && glyph_file >= 0) { 507 ch = p->_char_code + pf->firstchar;
499 tmp[0] = p->_char_code >> 8; 508
500 tmp[1] = p->_char_code & 0xff; 509 if (ch != 0xffff && glyph_file >= 0) {
510 tmp[0] = ch >> 8;
511 tmp[1] = ch & 0xff;
501 if (write(glyph_file, tmp, 2) != 2) { 512 if (write(glyph_file, tmp, 2) != 2) {
502 close(glyph_file); 513 close(glyph_file);
503 glyph_file = -1; 514 glyph_file = -1;
@@ -545,8 +556,8 @@ void glyph_cache_load(void)
545 close(fd); 556 close(fd);
546 } else { 557 } else {
547 /* load latin1 chars into cache */ 558 /* load latin1 chars into cache */
548 ch = 255 - pf->firstchar; 559 ch = 256;
549 while (ch--) 560 while (ch-- > 32)
550 font_get_bits(pf, ch); 561 font_get_bits(pf, ch);
551 } 562 }
552 } 563 }