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.4 2004/08/05 18:46:44 bernie
20 * Documentation improvements.
22 * Revision 1.3 2004/08/03 15:57:18 aleph
23 * Add include to fix warning for vsprintf()
25 * Revision 1.2 2004/06/03 11:27:09 bernie
26 * Add dual-license information.
28 * Revision 1.1 2004/05/23 15:43:16 bernie
29 * Import mware modules.
31 * Revision 1.2 2004/03/26 18:50:50 bernie
32 * Move _PROGMEM stuff to compiler.h
34 * Revision 1.1 2004/03/19 16:52:28 bernie
35 * Move printf() like functions from text.c to text_format.c and add PROGMEM versions.
40 #include "formatwr.h" /* _formatted_write() */
43 #include <stdio.h> /* vsprintf() */
45 #include <string.h> /* strlen() */
48 * Render string \a str in Bitmap \a bm at current cursor position
50 * \note Text formatting functions are also available with an _P suffix
51 * accepting the source string from program memory. This feature
52 * is only available (and useful) on Harvard microprocessors such
57 int PGM_FUNC(text_puts)(const char * PGM_ATTR str, struct Bitmap *bm)
61 while ((c = PGM_READ_CHAR(str++)))
69 * vprintf()-like formatter to render text in a Bitmap.
71 * Perform vprintf()-like formatting on the \a fmt format string using the
72 * variable-argument list \a ap.
73 * Render the resulting string in Bitmap \a bm starting at the current
76 * \see text_puts() text_putchar() text_printf()
78 int PGM_FUNC(text_vprintf)(struct Bitmap *bm, const char * PGM_ATTR fmt, va_list ap)
80 return PGM_FUNC(_formatted_write)(fmt, (void (*)(char, void *))text_putchar, bm, ap);
84 * printf()-like formatter to render text in a Bitmap.
86 * Perform printf()-like formatting on the \a fmt format string.
87 * Render the resulting string in Bitmap \a bm starting at the
88 * current cursor position.
90 * \see text_puts() text_putchar() text_vprintf()
92 int PGM_FUNC(text_printf)(struct Bitmap *bm, const char * PGM_ATTR fmt, ...)
98 len = PGM_FUNC(text_vprintf)(bm, fmt, ap);
106 * Render the result of printf()-like formatting in a specified position
109 * \param bm Bitmap where to render the text
110 * \param row Starting row in character units (zero based)
111 * \param col Starting column in character units (zero based)
112 * \param mode Formatting mode to use. Can be TEXT_NORMAL,
113 * TEXT_FILL, TEXT_INVERT or TEXT_RIGHT or a combination
114 * of these flags ORed together.
115 * \param fmt String possibly containing printf() formatting commands.
117 * \see text_puts() text_putchar() text_printf() text_vprintf()
118 * \see text_moveto() text_style()
120 int PGM_FUNC(text_xprintf)(struct Bitmap *bm,
121 uint8_t row, uint8_t col, uint8_t mode, const char * PGM_ATTR fmt, ...)
124 uint8_t oldstyle = 0;
129 text_moveto(bm, row, col);
131 if (mode & TEXT_INVERT)
132 oldstyle = text_style(STYLEF_INVERT, STYLEF_INVERT);
134 if (mode & (TEXT_CENTER | TEXT_RIGHT))
138 pad = bm->width/FONT_WIDTH - PGM_FUNC(vsprintf)(NULL, fmt, ap);
140 if (mode & TEXT_CENTER)
144 text_putchar(' ', bm);
147 len = PGM_FUNC(text_vprintf)(bm, fmt, ap);
150 if (mode & (TEXT_FILL | TEXT_CENTER))
151 while (bm->penX + FONT_WIDTH < bm->width)
152 text_putchar(' ', bm);
154 if (mode & TEXT_INVERT)
155 text_style(oldstyle, STYLEF_MASK);