Really make it work on both architectures.
[bertos.git] / mware / text_format.c
index ecfbc49469670e19a2cd2bb5e108eab35bbf2fac..d8080a90c53d3c46727bd0f37f0f0902c2aa0d4f 100755 (executable)
@@ -6,16 +6,24 @@
  * This file is part of DevLib - See devlib/README for information.
  * -->
  *
- * \version $Id$
+ * \brief printf-family routines for text output
  *
+ * \version $Id$
  * \author Bernardo Innocenti <bernie@develer.com>
  * \author Stefano Fedrigo <aleph@develer.com>
- *
- * \brief printf-family routines for text output
  */
 
 /*#*
  *#* $Log$
+ *#* Revision 1.9  2004/12/31 17:47:45  bernie
+ *#* Rename UNUSED() to UNUSED_ARG().
+ *#*
+ *#* Revision 1.8  2004/11/16 21:16:56  bernie
+ *#* Update to new naming scheme in mware/gfx.c.
+ *#*
+ *#* Revision 1.7  2004/10/03 19:05:04  bernie
+ *#* text_widthf(), text_vwidthf(): New functions.
+ *#*
  *#* Revision 1.6  2004/09/14 20:59:04  bernie
  *#* text_xprintf(): Support all styles; Pixel-wise text centering.
  *#*
@@ -139,13 +147,13 @@ int PGM_FUNC(text_xprintf)(struct Bitmap *bm,
 
        if (style & (TEXT_CENTER | TEXT_RIGHT))
        {
-               uint8_t pad = bm->width - PGM_FUNC(vsprintf)(NULL, fmt, ap) * FONT_WIDTH;
+               uint8_t pad = bm->width - PGM_FUNC(text_vwidthf)(bm, fmt, ap);
 
                if (style & TEXT_CENTER)
                        pad /= 2;
 
                if (style & TEXT_FILL)
-                       gfx_RectFillC(bm, 0, row * FONT_HEIGHT, pad, (row + 1) * FONT_HEIGHT,
+                       gfx_rectFillC(bm, 0, row * FONT_HEIGHT, pad, (row + 1) * FONT_HEIGHT,
                                (style & STYLEF_INVERT) ? 0xFF : 0x00);
 
                text_setcoord(bm, pad, row * FONT_HEIGHT);
@@ -155,7 +163,7 @@ int PGM_FUNC(text_xprintf)(struct Bitmap *bm,
        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 * FONT_HEIGHT, bm->width, (row + 1) * FONT_HEIGHT,
                        (style & STYLEF_INVERT) ? 0xFF : 0x00);
 
        /* Restore old style */
@@ -165,3 +173,30 @@ int PGM_FUNC(text_xprintf)(struct Bitmap *bm,
        return len;
 }
 
+
+/*!
+ * Return the width in pixels of a vprintf()-formatted string.
+ */
+int PGM_FUNC(text_vwidthf)(
+       UNUSED_ARG(struct Bitmap *, bm),
+       const char * PGM_ATTR fmt,
+       va_list ap)
+{
+       return PGM_FUNC(vsprintf)(NULL, fmt, ap) * FONT_WIDTH;
+}
+
+
+/*!
+ * Return the width in pixels of a printf()-formatted string.
+ */
+int PGM_FUNC(text_widthf)(struct Bitmap *bm, const char * PGM_ATTR fmt, ...)
+{
+       int width;
+
+       va_list ap;
+       va_start(ap, fmt);
+       width = PGM_FUNC(text_vwidthf)(bm, fmt, ap);
+       va_end(ap);
+
+       return width;
+}