summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/drivers/lcd-h100.c19
-rw-r--r--firmware/export/font.h1
-rw-r--r--firmware/font.c25
3 files changed, 27 insertions, 18 deletions
diff --git a/firmware/drivers/lcd-h100.c b/firmware/drivers/lcd-h100.c
index d27a62da41..157791d991 100644
--- a/firmware/drivers/lcd-h100.c
+++ b/firmware/drivers/lcd-h100.c
@@ -319,24 +319,7 @@ void lcd_setfont(int newfont)
319 319
320int lcd_getstringsize(const unsigned char *str, int *w, int *h) 320int lcd_getstringsize(const unsigned char *str, int *w, int *h)
321{ 321{
322 struct font* pf = font_get(curfont); 322 return font_getstringsize(str, w, h, curfont);
323 int ch;
324 int width = 0;
325
326 while((ch = *str++)) {
327 /* check input range*/
328 if (ch < pf->firstchar || ch >= pf->firstchar+pf->size)
329 ch = pf->defaultchar;
330 ch -= pf->firstchar;
331
332 /* get proportional width and glyph bits*/
333 width += pf->width? pf->width[ch]: pf->maxwidth;
334 }
335 if ( w )
336 *w = width;
337 if ( h )
338 *h = pf->height;
339 return width;
340} 323}
341 324
342/* put a string at a given char position */ 325/* put a string at a given char position */
diff --git a/firmware/export/font.h b/firmware/export/font.h
index 8b3f373245..01751add5c 100644
--- a/firmware/export/font.h
+++ b/firmware/export/font.h
@@ -91,6 +91,7 @@ void font_init(void);
91struct font* font_load(const char *path); 91struct font* font_load(const char *path);
92struct font* font_get(int font); 92struct font* font_get(int font);
93void font_reset(void); 93void font_reset(void);
94int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber);
94 95
95#else /* HAVE_LCD_BITMAP */ 96#else /* HAVE_LCD_BITMAP */
96 97
diff --git a/firmware/font.c b/firmware/font.c
index 37c082f583..303887701d 100644
--- a/firmware/font.c
+++ b/firmware/font.c
@@ -225,6 +225,31 @@ struct font* font_get(int font)
225 panicf("No font!"); 225 panicf("No font!");
226 } 226 }
227} 227}
228/*
229 * Returns the stringsize of a given string.
230 */
231int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber)
232{
233 struct font* pf = font_get(fontnumber);
234 int ch;
235 int width = 0;
236
237 while((ch = *str++)) {
238 /* check input range*/
239 if (ch < pf->firstchar || ch >= pf->firstchar+pf->size)
240 ch = pf->defaultchar;
241 ch -= pf->firstchar;
242
243 /* get proportional width and glyph bits*/
244 width += pf->width? pf->width[ch]: pf->maxwidth;
245 }
246 if ( w )
247 *w = width;
248 if ( h )
249 *h = pf->height;
250 return width;
251}
252
228 253
229#endif /* HAVE_LCD_BITMAP */ 254#endif /* HAVE_LCD_BITMAP */
230 255