/*#*
*#* $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.
*#*
#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, /* */
0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x00, /* þ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* ÿ */
};
+
+struct Font default_font =
+{
+ /* .glyph = */ default_font_glyphs,
+ /* .width = */ 6,
+ /* .height = */ 8
+};
+
/*#*
*#* $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.
*#*
#include <cfg/compiler.h> /* uint8_t */
#include <mware/pgm.h> /* 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 */
/*#*
*#* $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.
*#*
#include <gfx/gfx.h>
#include <gfx/font.h>
#include <gfx/text.h>
+#include <gfx/text.h>
#include <cfg/debug.h>
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;
}
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;
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;
}
/* 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)
*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;
}
}
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;
}
}
}
-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);
}
/*#*
*#* $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.
*#*
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 */
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;
}