From: bernie Date: Fri, 10 Feb 2006 12:31:55 +0000 (+0000) Subject: Add multiple font support in bitmaps. X-Git-Tag: 1.0.0~742 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;ds=sidebyside;h=22ea75fdc24002bc8b2a6fea2be1080cc3b39b1c;p=bertos.git Add multiple font support in bitmaps. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@499 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/gfx/font.c b/gfx/font.c index 934f851a..767c269e 100755 --- a/gfx/font.c +++ b/gfx/font.c @@ -15,6 +15,9 @@ /*#* *#* $Log$ + *#* Revision 1.3 2006/02/10 12:29:05 bernie + *#* Add multiple font support in bitmaps. + *#* *#* Revision 1.2 2005/11/04 18:17:45 bernie *#* Fix header guards and includes for new location of gfx module. *#* @@ -42,7 +45,7 @@ #include "font.h" -const PROGMEM uint8_t font[256 * 6] = +static const PROGMEM uint8_t default_font_glyphs[256 * 6] = { /* 0x00 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* */ @@ -333,3 +336,11 @@ const PROGMEM uint8_t font[256 * 6] = 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x00, /* þ */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* ÿ */ }; + +struct Font default_font = +{ + /* .glyph = */ default_font_glyphs, + /* .width = */ 6, + /* .height = */ 8 +}; + diff --git a/gfx/font.h b/gfx/font.h index 1f5d2780..1701b1fc 100755 --- a/gfx/font.h +++ b/gfx/font.h @@ -14,6 +14,9 @@ /*#* *#* $Log$ + *#* Revision 1.3 2006/02/10 12:29:05 bernie + *#* Add multiple font support in bitmaps. + *#* *#* Revision 1.2 2005/11/04 18:17:45 bernie *#* Fix header guards and includes for new location of gfx module. *#* @@ -51,15 +54,22 @@ #include /* uint8_t */ #include /* PROGMEM */ -/*! - * \name Font size (in pixel) - * \{ - */ -#define FONT_WIDTH 6 -#define FONT_HEIGHT 8 -/* \} */ +typedef struct Font +{ + /** + * Pointer to glyph data. + * + * Data is an array of at most 256 glyphs packed together. + * Raster format must be the same of the bitmap. + */ + const PROGMEM uint8_t * const glyph; + + uint8_t width; /**< Pixel width of character cell. */ + uint8_t height; /**< Pixel height of character cell. */ + +} Font; -/*! Font table. */ -extern const PROGMEM uint8_t font[256 * FONT_WIDTH]; +/**< The default font. */ +extern struct Font default_font; #endif /* GFX_FONT_H */ diff --git a/gfx/text.c b/gfx/text.c index 3e980601..75d5dc3f 100755 --- a/gfx/text.c +++ b/gfx/text.c @@ -15,6 +15,9 @@ /*#* *#* $Log$ + *#* Revision 1.3 2006/02/10 12:31:55 bernie + *#* Add multiple font support in bitmaps. + *#* *#* Revision 1.2 2005/11/04 18:17:45 bernie *#* Fix header guards and includes for new location of gfx module. *#* @@ -79,6 +82,7 @@ #include #include #include +#include #include @@ -104,12 +108,12 @@ static bool ansi_mode = false; void text_moveto(struct Bitmap *bm, int row, int col) { ASSERT(col >= 0); - ASSERT(col < bm->width / FONT_WIDTH); + ASSERT(col < bm->width / bm->font->width); ASSERT(row >= 0); - ASSERT(row < bm->height / FONT_HEIGHT); +// ASSERT(row < bm->height / bm->font->height); - bm->penX = col * FONT_WIDTH; - bm->penY = row * FONT_HEIGHT; + bm->penX = col * bm->font->width; + bm->penY = row * bm->font->height; } @@ -134,11 +138,11 @@ static int text_putglyph(char c, struct Bitmap *bm) uint8_t *buf; /* - * Il carattere da stampare viene usato come indice per prelevare - * la prima colonna di dots del glyph all'interno del font. + * Compute the first column of pixels of the selected glyph, + * using the character code to index the glyph array. */ - glyph = font + (((unsigned char)c) * FONT_WIDTH); - glyph_width = FONT_WIDTH; + glyph_width = bm->font->width; + glyph = &bm->font->glyph[(unsigned char)c * (((glyph_width + 7) / 8) * bm->font->height) ]; if (text_styles & STYLEF_CONDENSED) --glyph_width; @@ -147,12 +151,13 @@ static int text_putglyph(char c, struct Bitmap *bm) glyph_width *= 2; /* The y coord is rounded at multiples of 8 for simplicity */ - bm->penY &= ~((coord_t)7); +// bm->penY &= ~((coord_t)7); /* Check if glyph to write fits in the bitmap */ - if ((bm->penX < 0) || (bm->penX + glyph_width > bm->width) || - (bm->penY < 0) || (bm->penY + FONT_HEIGHT > bm->height)) + if ((bm->penX < 0) || (bm->penX + glyph_width > bm->width) + || (bm->penY < 0) || (bm->penY + bm->font->height > bm->height)) { + kprintf("w=%d, h=%d\n", glyph_width, bm->font->height); DB(kprintf("bad coords x=%d y=%d\n", bm->penX, bm->penY);) return 0; } @@ -160,7 +165,7 @@ static int text_putglyph(char c, struct Bitmap *bm) /* Locate position where to write in the raster */ buf = bm->raster + bm->penY / 8 * bm->width + bm->penX; - bm->penX += glyph_width; +// bm->penX += glyph_width; /* If some styles are set */ if (text_styles) @@ -207,9 +212,14 @@ static int text_putglyph(char c, struct Bitmap *bm) *buf++ = dots; } } - else /* No style: fast vanilla copy of glyph to line buffer */ - while (glyph_width--) - *buf++ = PGM_READ_CHAR(glyph++); + else + { + /* No style: fast vanilla copy of glyph to line buffer */ + gfx_blitRaster(bm, bm->penX, bm->penY, glyph, glyph_width, bm->font->height); +// while (glyph_width--) +// *buf++ = PGM_READ_CHAR(glyph++); + } + bm->penX += glyph_width; return c; } @@ -243,9 +253,9 @@ int text_putchar(char c, struct Bitmap *bm) } else if (c == '\n') /* Go one line down on a line-feed */ { - if (bm->penY + FONT_HEIGHT < bm->height) + if (bm->penY + bm->font->height < bm->height) { - bm->penY += FONT_HEIGHT; + bm->penY += bm->font->height; bm->penX = 0; } } @@ -267,9 +277,9 @@ void text_clear(struct Bitmap *bmp) } -void text_clearLine(struct Bitmap *bmp, int line) +void text_clearLine(struct Bitmap *bm, int line) { - gfx_rectClear(bmp, 0, line * FONT_HEIGHT, bmp->width, (line + 1) * FONT_HEIGHT); + gfx_rectClear(bm, 0, line * bm->font->height, bm->width, (line + 1) * bm->font->height); } diff --git a/gfx/text_format.c b/gfx/text_format.c index 9dfaa6a5..c59a3af9 100755 --- a/gfx/text_format.c +++ b/gfx/text_format.c @@ -15,6 +15,9 @@ /*#* *#* $Log$ + *#* Revision 1.4 2006/02/10 12:31:33 bernie + *#* Add multiple font support in bitmaps. + *#* *#* Revision 1.3 2005/11/27 23:31:58 bernie *#* Reorder includes. *#* @@ -167,17 +170,17 @@ int PGM_FUNC(text_xprintf)(struct Bitmap *bm, pad /= 2; if (style & TEXT_FILL) - gfx_rectFillC(bm, 0, row * FONT_HEIGHT, pad, (row + 1) * FONT_HEIGHT, + gfx_rectFillC(bm, 0, row * bm->font->height, pad, (row + 1) * bm->font->height, (style & STYLEF_INVERT) ? 0xFF : 0x00); - text_setcoord(bm, pad, row * FONT_HEIGHT); + text_setcoord(bm, pad, row * bm->font->height); } len = PGM_FUNC(text_vprintf)(bm, fmt, ap); va_end(ap); if (style & TEXT_FILL) - gfx_rectFillC(bm, bm->penX, row * FONT_HEIGHT, bm->width, (row + 1) * FONT_HEIGHT, + gfx_rectFillC(bm, bm->penX, row * bm->font->height, bm->width, (row + 1) * bm->font->height, (style & STYLEF_INVERT) ? 0xFF : 0x00); /* Restore old style */ @@ -196,7 +199,7 @@ int PGM_FUNC(text_vwidthf)( const char * PGM_ATTR fmt, va_list ap) { - return PGM_FUNC(vsprintf)(NULL, fmt, ap) * FONT_WIDTH; + return PGM_FUNC(vsprintf)(NULL, fmt, ap) * bm->font->width; }