4 * Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 1999 Bernardo Innocenti <bernie@develer.com>
6 * This file is part of DevLib - See devlib/README for information.
11 * \author Bernardo Innocenti <bernie@develer.com>
12 * \author Stefano Fedrigo <aleph@develer.com>
14 * \brief printf-family routines for text output
19 *#* Revision 1.5 2004/08/25 14:12:09 rasky
20 *#* Aggiornato il comment block dei log RCS
22 *#* Revision 1.4 2004/08/05 18:46:44 bernie
23 *#* Documentation improvements.
25 *#* Revision 1.3 2004/08/03 15:57:18 aleph
26 *#* Add include to fix warning for vsprintf()
28 *#* Revision 1.2 2004/06/03 11:27:09 bernie
29 *#* Add dual-license information.
31 *#* Revision 1.1 2004/05/23 15:43:16 bernie
32 *#* Import mware modules.
34 *#* Revision 1.2 2004/03/26 18:50:50 bernie
35 *#* Move _PROGMEM stuff to compiler.h
37 *#* Revision 1.1 2004/03/19 16:52:28 bernie
38 *#* Move printf() like functions from text.c to text_format.c and add PROGMEM versions.
43 #include "formatwr.h" /* _formatted_write() */
46 #include <stdio.h> /* vsprintf() */
48 #include <string.h> /* strlen() */
51 * Render string \a str in Bitmap \a bm at current cursor position
53 * \note Text formatting functions are also available with an _P suffix
54 * accepting the source string from program memory. This feature
55 * is only available (and useful) on Harvard microprocessors such
60 int PGM_FUNC(text_puts)(const char * PGM_ATTR str, struct Bitmap *bm)
64 while ((c = PGM_READ_CHAR(str++)))
72 * vprintf()-like formatter to render text in a Bitmap.
74 * Perform vprintf()-like formatting on the \a fmt format string using the
75 * variable-argument list \a ap.
76 * Render the resulting string in Bitmap \a bm starting at the current
79 * \see text_puts() text_putchar() text_printf()
81 int PGM_FUNC(text_vprintf)(struct Bitmap *bm, const char * PGM_ATTR fmt, va_list ap)
83 return PGM_FUNC(_formatted_write)(fmt, (void (*)(char, void *))text_putchar, bm, ap);
87 * printf()-like formatter to render text in a Bitmap.
89 * Perform printf()-like formatting on the \a fmt format string.
90 * Render the resulting string in Bitmap \a bm starting at the
91 * current cursor position.
93 * \see text_puts() text_putchar() text_vprintf()
95 int PGM_FUNC(text_printf)(struct Bitmap *bm, const char * PGM_ATTR fmt, ...)
101 len = PGM_FUNC(text_vprintf)(bm, fmt, ap);
109 * Render the result of printf()-like formatting in a specified position
112 * \param bm Bitmap where to render the text
113 * \param row Starting row in character units (zero based)
114 * \param col Starting column in character units (zero based)
115 * \param mode Formatting mode to use. Can be TEXT_NORMAL,
116 * TEXT_FILL, TEXT_INVERT or TEXT_RIGHT or a combination
117 * of these flags ORed together.
118 * \param fmt String possibly containing printf() formatting commands.
120 * \see text_puts() text_putchar() text_printf() text_vprintf()
121 * \see text_moveto() text_style()
123 int PGM_FUNC(text_xprintf)(struct Bitmap *bm,
124 uint8_t row, uint8_t col, uint8_t mode, const char * PGM_ATTR fmt, ...)
127 uint8_t oldstyle = 0;
132 text_moveto(bm, row, col);
134 if (mode & TEXT_INVERT)
135 oldstyle = text_style(STYLEF_INVERT, STYLEF_INVERT);
137 if (mode & (TEXT_CENTER | TEXT_RIGHT))
141 pad = bm->width/FONT_WIDTH - PGM_FUNC(vsprintf)(NULL, fmt, ap);
143 if (mode & TEXT_CENTER)
147 text_putchar(' ', bm);
150 len = PGM_FUNC(text_vprintf)(bm, fmt, ap);
153 if (mode & (TEXT_FILL | TEXT_CENTER))
154 while (bm->penX + FONT_WIDTH < bm->width)
155 text_putchar(' ', bm);
157 if (mode & TEXT_INVERT)
158 text_style(oldstyle, STYLEF_MASK);