X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=gfx%2Ftext_format.c;h=7c20472569aa9c410189a7a046424af0f4ed0c39;hb=1fc31f45bcec8bc23a5924ae5b288439abca8ded;hp=e1452d8a0015f0f354d1f40c4b9c1b0e7b236ca9;hpb=c66da8dee53d20f2bc02267d798530f5fb1bf37f;p=bertos.git diff --git a/gfx/text_format.c b/gfx/text_format.c old mode 100755 new mode 100644 index e1452d8a..7c204725 --- a/gfx/text_format.c +++ b/gfx/text_format.c @@ -1,9 +1,34 @@ -/*! +/** * \file * * * \brief printf-family routines for text output @@ -15,6 +40,21 @@ /*#* *#* $Log$ + *#* Revision 1.10 2006/07/19 12:56:26 bernie + *#* Convert to new Doxygen style. + *#* + *#* Revision 1.9 2006/04/27 05:39:24 bernie + *#* Enhance text rendering to arbitrary x,y coords. + *#* + *#* Revision 1.8 2006/03/22 09:50:11 bernie + *#* Don't use C99 stuff. + *#* + *#* Revision 1.7 2006/03/20 17:51:55 bernie + *#* Cleanups. + *#* + *#* Revision 1.6 2006/03/13 02:05:54 bernie + *#* Mark slow paths as UNLIKELY. + *#* *#* Revision 1.5 2006/03/07 22:18:04 bernie *#* Correctly compute text width for prop fonts; Make styles a per-bitmap attribute. *#* @@ -78,7 +118,7 @@ #include #include /* strlen() */ -/*! +/** * Render string \a str in Bitmap \a bm at current cursor position * * \note Text formatting functions are also available with an _P suffix @@ -99,7 +139,7 @@ int PGM_FUNC(text_puts)(const char * PGM_ATTR str, struct Bitmap *bm) } -/*! +/** * vprintf()-like formatter to render text in a Bitmap. * * Perform vprintf()-like formatting on the \a fmt format string using the @@ -114,7 +154,7 @@ int PGM_FUNC(text_vprintf)(struct Bitmap *bm, const char * PGM_ATTR fmt, va_list return PGM_FUNC(_formatted_write)(fmt, (void (*)(char, void *))text_putchar, bm, ap); } -/*! +/** * printf()-like formatter to render text in a Bitmap. * * Perform printf()-like formatting on the \a fmt format string. @@ -135,32 +175,18 @@ int PGM_FUNC(text_printf)(struct Bitmap *bm, const char * PGM_ATTR fmt, ...) return len; } - -/*! - * Render the result of printf()-like formatting in a specified position - * of a Bitmap. - * - * \param bm Bitmap where to render the text - * \param row Starting row in character units (zero based) - * \param col Starting column in character units (zero based) - * \param style Formatting style to use. In addition to any STYLEF_ - * flag, it can be TEXT_NORMAL, TEXT_FILL, TEXT_INVERT or - * TEXT_RIGHT, or a combination of these flags ORed together. - * \param fmt String possibly containing printf() formatting commands. +/** + * Render text with vprintf()-like formatting at a specified pixel position. * - * \see text_puts() text_putchar() text_printf() text_vprintf() - * \see text_moveto() text_style() + * \see text_xyprintf() */ -int PGM_FUNC(text_xprintf)(struct Bitmap *bm, - uint8_t row, uint8_t col, uint16_t style, const char * PGM_ATTR fmt, ...) +int PGM_FUNC(text_xyvprintf)(struct Bitmap *bm, + coord_t x, coord_t y, uint16_t style, const char * PGM_ATTR fmt, va_list ap) { int len; uint8_t oldstyle = 0; - va_list ap; - va_start(ap, fmt); - - text_moveto(bm, row, col); + text_setCoord(bm, x, y); if (style & STYLEF_MASK) oldstyle = text_style(bm, style, STYLEF_MASK); @@ -173,17 +199,16 @@ int PGM_FUNC(text_xprintf)(struct Bitmap *bm, pad /= 2; if (style & TEXT_FILL) - gfx_rectFillC(bm, 0, row * bm->font->height, pad, (row + 1) * bm->font->height, + gfx_rectFillC(bm, 0, y, pad, y + bm->font->height, (style & STYLEF_INVERT) ? 0xFF : 0x00); - text_setcoord(bm, pad, row * bm->font->height); + text_setCoord(bm, pad, y); } len = PGM_FUNC(text_vprintf)(bm, fmt, ap); - va_end(ap); if (style & TEXT_FILL) - gfx_rectFillC(bm, bm->penX, row * bm->font->height, bm->width, (row + 1) * bm->font->height, + gfx_rectFillC(bm, bm->penX, y, bm->width, y + bm->font->height, (style & STYLEF_INVERT) ? 0xFF : 0x00); /* Restore old style */ @@ -194,10 +219,59 @@ int PGM_FUNC(text_xprintf)(struct Bitmap *bm, } +/** + * Render text with printf()-like formatting at a specified pixel position. + * + * \param bm Bitmap where to render the text + * \param x [pixels] Initial X coordinate of text. + * \param y [pixels] Coordinate of top border of text. + * \param style Formatting style to use. In addition to any STYLEF_ + * flag, it can be TEXT_NORMAL, TEXT_FILL, TEXT_INVERT or + * TEXT_RIGHT, or a combination of these flags ORed together. + * \param fmt String possibly containing printf() formatting commands. + * + * \see text_puts() text_putchar() text_printf() text_vprintf() + * \see text_moveTo() text_style() + */ +int PGM_FUNC(text_xyprintf)(struct Bitmap *bm, + coord_t x, coord_t y, uint16_t style, const char * PGM_ATTR fmt, ...) +{ + int len; + va_list ap; + + va_start(ap, fmt); + len = PGM_FUNC(text_xyvprintf)(bm, x, y, style, fmt, ap); + va_end(ap); + + return len; +} + + +/** + * Render text with printf()-like formatting at a specified row/column position. + * + * \see text_xyprintf() + */ +int PGM_FUNC(text_xprintf)(struct Bitmap *bm, + uint8_t row, uint8_t col, uint16_t style, const char * PGM_ATTR fmt, ...) +{ + int len; + va_list ap; + + va_start(ap, fmt); + len = PGM_FUNC(text_xyvprintf)( + bm, col * bm->font->width, row * bm->font->height, + style, fmt, ap); + va_end(ap); + + return len; +} + + struct TextWidthData { - Bitmap *bitmap; - coord_t width; + Bitmap *bitmap; + coord_t width; }; /** @@ -219,9 +293,9 @@ static int text_charWidth(int c, struct TextWidthData *twd) coord_t glyph_width; - if (index < bm->font->first || index > bm->font->last) + if (UNLIKELY(!FONT_HAS_GLYPH(bm->font, index))) { - if ('?' >= bm->font->first && '?' <= bm->font->last) + if (!FONT_HAS_GLYPH(bm->font, '?')) index = '?'; else index = bm->font->first; @@ -248,7 +322,7 @@ static int text_charWidth(int c, struct TextWidthData *twd) return c; } -/*! +/** * Return the width in pixels of a vprintf()-formatted string. */ int PGM_FUNC(text_vwidthf)( @@ -261,14 +335,16 @@ int PGM_FUNC(text_vwidthf)( return PGM_FUNC(vsprintf)(NULL, fmt, ap) * bm->font->width; else { - struct TextWidthData twd = { bm, 0 }; + struct TextWidthData twd; + twd.bitmap = bm; + twd.width = 0; _formatted_write(fmt, (void (*)(char, void *))text_charWidth, &twd, ap); return twd.width; } } -/*! +/** * Return the width in pixels of a printf()-formatted string. */ int PGM_FUNC(text_widthf)(struct Bitmap *bm, const char * PGM_ATTR fmt, ...)