From c6ec0f48a5999c4456439eb4e0b54467b464ed02 Mon Sep 17 00:00:00 2001 From: Christian Gmeiner Date: Tue, 19 Apr 2005 12:47:16 +0000 Subject: moved lcd_getstringsize into font.c git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6321 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/lcd-h100.c | 19 +------------------ firmware/export/font.h | 1 + firmware/font.c | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/firmware/drivers/lcd-h100.c b/firmware/drivers/lcd-h100.c index d27a62d..157791d 100644 --- a/firmware/drivers/lcd-h100.c +++ b/firmware/drivers/lcd-h100.c @@ -319,24 +319,7 @@ void lcd_setfont(int newfont) int lcd_getstringsize(const unsigned char *str, int *w, int *h) { - struct font* pf = font_get(curfont); - int ch; - int width = 0; - - while((ch = *str++)) { - /* 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 += pf->width? pf->width[ch]: pf->maxwidth; - } - if ( w ) - *w = width; - if ( h ) - *h = pf->height; - return width; + return font_getstringsize(str, w, h, curfont); } /* put a string at a given char position */ diff --git a/firmware/export/font.h b/firmware/export/font.h index 8b3f373..01751ad 100644 --- a/firmware/export/font.h +++ b/firmware/export/font.h @@ -91,6 +91,7 @@ void font_init(void); struct font* font_load(const char *path); struct font* font_get(int font); void font_reset(void); +int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber); #else /* HAVE_LCD_BITMAP */ diff --git a/firmware/font.c b/firmware/font.c index 37c082f..3038877 100644 --- a/firmware/font.c +++ b/firmware/font.c @@ -225,6 +225,31 @@ struct font* font_get(int font) panicf("No font!"); } } +/* + * Returns the stringsize of a given string. + */ +int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber) +{ + struct font* pf = font_get(fontnumber); + int ch; + int width = 0; + + while((ch = *str++)) { + /* 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 += pf->width? pf->width[ch]: pf->maxwidth; + } + if ( w ) + *w = width; + if ( h ) + *h = pf->height; + return width; +} + #endif /* HAVE_LCD_BITMAP */ -- cgit v1.1