summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-09-20 08:07:51 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-09-20 08:07:51 +0000
commitbed3d3f7e06c6582f9677ab6222cd89c84a9c8c7 (patch)
tree59ef1faa129f0813071d5e81b2e55b5d04886202 /firmware/drivers
parenteb5cc653dba373f2d2ce48f8efbc0b19a424971e (diff)
New full ISO-8859-1 system font.
Added font loading from dir browser. Changed default font location to /.rockbox/default.fnt. Code-policed font code. Removed old font tools. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2347 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/lcd.c95
-rw-r--r--firmware/drivers/lcd.h7
2 files changed, 86 insertions, 16 deletions
diff --git a/firmware/drivers/lcd.c b/firmware/drivers/lcd.c
index 8abc638175..2293191139 100644
--- a/firmware/drivers/lcd.c
+++ b/firmware/drivers/lcd.c
@@ -547,7 +547,6 @@ void lcd_set_contrast(int val)
*/
unsigned char lcd_framebuffer[LCD_WIDTH][LCD_HEIGHT/8];
-static int font=0;
static int xmargin=0;
static int ymargin=0;
@@ -661,11 +660,6 @@ void lcd_clear_display (void)
#endif
}
-void lcd_setfont(int newfont)
-{
- font = newfont;
-}
-
void lcd_setmargins(int x, int y)
{
xmargin = x;
@@ -682,10 +676,11 @@ int lcd_getymargin(void)
return ymargin;
}
+static int curfont = FONT_SYSFIXED;
+
/*
* Put a string at specified character position
*/
-//FIXME require font parameter
void lcd_puts(int x, int y, unsigned char *str)
{
int xpos,ypos,w,h;
@@ -707,10 +702,10 @@ void lcd_puts(int x, int y, unsigned char *str)
if(!str || !str[0])
return;
- lcd_getstringsize(str, font, &w, &h);
- xpos = xmargin + x*w / strlen(str); //FIXME why strlen?
+ lcd_getstringsize(str, curfont, &w, &h);
+ xpos = xmargin + x*w / strlen(str);
ypos = ymargin + y*h;
- lcd_putsxy( xpos, ypos, str, font);
+ lcd_putsxy( xpos, ypos, str, curfont);
lcd_clearrect(xpos + w, ypos, LCD_WIDTH - (xpos + w), h);
#if defined(SIMULATOR) && defined(HAVE_LCD_CHARCELLS)
/* this function is being used when simulating a charcell LCD and
@@ -719,6 +714,80 @@ void lcd_puts(int x, int y, unsigned char *str)
#endif
}
+/* set current font*/
+void lcd_setfont(int newfont)
+{
+ curfont = newfont;
+}
+
+/*
+ * Return width and height of a given font.
+ */
+void lcd_getfontsize(int font, int *width, int *height)
+{
+ struct font* pf = font_get(font);
+
+ *width = pf->maxwidth;
+ *height = pf->height;
+}
+
+
+/*
+ * Return width and height of a given font.
+ */
+int lcd_getstringsize(unsigned char *str, int font, int *w, int *h)
+{
+ struct font* pf = font_get(font);
+ 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;
+ }
+ *w = width;
+ *h = pf->height;
+
+ return width;
+}
+
+/*
+ * Put a string at specified bit position
+ */
+void lcd_putsxy(int x, int y, unsigned char *str, int font)
+{
+ int ch;
+ struct font* pf = font_get(font);
+
+ while (((ch = *str++) != '\0')) {
+ bitmap_t *bits;
+ int width;
+
+ /* 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 (x + width > LCD_WIDTH)
+ break;
+
+ /* no partial-height drawing for now...*/
+ if (y + pf->height > LCD_HEIGHT)
+ break;
+ bits = pf->bits + (pf->offset ? pf->offset[ch] : (pf->height * ch));
+
+ lcd_bitmap((unsigned char *)bits, x, y, width, pf->height, true);
+ x += width;
+ }
+}
+
/*
* Display a bitmap at (x, y), size (nx, ny)
* clear is true to clear destination area first
@@ -1038,14 +1107,14 @@ void lcd_puts_scroll(int x, int y, unsigned char* string )
unsigned char ch[2];
int w, h;
int width, height;
- lcd_getfontsize(font, &width, &height);
+ lcd_getfontsize(curfont, &width, &height);
ch[1] = 0; /* zero terminate */
ch[0] = string[0];
width = 0;
s->space = 0;
while ( ch[0] &&
- (width + lcd_getstringsize(ch, 0, &w, &h) <
+ (width + lcd_getstringsize(ch, curfont, &w, &h) <
(LCD_WIDTH - x*8))) {
width += w;
s->space++;
@@ -1058,7 +1127,7 @@ void lcd_puts_scroll(int x, int y, unsigned char* string )
#ifdef HAVE_LCD_BITMAP
s->space += 2;
- lcd_getstringsize(string,0,&w,&h);
+ lcd_getstringsize(string,curfont,&w,&h);
if ( w > LCD_WIDTH - xmargin ) {
#else
if ( s->textlen > s->space ) {
diff --git a/firmware/drivers/lcd.h b/firmware/drivers/lcd.h
index 8c89d4c057..388f31c1cf 100644
--- a/firmware/drivers/lcd.h
+++ b/firmware/drivers/lcd.h
@@ -99,9 +99,6 @@ extern void lcd_double_height (bool on);
*/
extern unsigned char lcd_framebuffer[LCD_WIDTH][LCD_HEIGHT/8];
-extern void lcd_putsxy(int x, int y, unsigned char *string, int font);
-extern void lcd_setfont(int font);
-extern void lcd_getfontsize(int font, int *width, int *height);
extern void lcd_setmargins(int xmargin, int ymargin);
extern int lcd_getxmargin(void);
extern int lcd_getymargin(void);
@@ -118,6 +115,10 @@ extern void lcd_clearpixel(int x, int y);
extern void lcd_invertpixel(int x, int y);
extern void lcd_roll(int pixels);
+extern void lcd_setfont(int font);
+extern void lcd_getfontsize(int font, int *width, int *height);
+extern void lcd_putsxy(int x, int y, unsigned char *string, int font);
+
#endif /* CHARCELLS / BITMAP */
extern int lcd_getstringsize(unsigned char *str, int font, int *w, int *h);