Correctly compute text width for prop fonts; Make styles a per-bitmap attribute.
[bertos.git] / gfx / text.h
1 /*!
2  * \file
3  * <!--
4  * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
5  * Copyright 1999 Bernardo Innocenti <bernie@develer.com>
6  * This file is part of DevLib - See README.devlib for information.
7  * -->
8  *
9  * \brief Text graphic routines (interface)
10  *
11  * \author Bernardo Innocenti <bernie@develer.com>
12  * \author Stefano Fedrigo <aleph@develer.com>
13  * \version $Id$
14  */
15
16 /*#*
17  *#* $Log$
18  *#* Revision 1.4  2006/03/07 22:18:04  bernie
19  *#* Correctly compute text width for prop fonts; Make styles a per-bitmap attribute.
20  *#*
21  *#* Revision 1.3  2006/02/10 12:26:19  bernie
22  *#* Add STYLEF_TALL (unimplemented).
23  *#*
24  *#* Revision 1.2  2005/11/04 18:17:45  bernie
25  *#* Fix header guards and includes for new location of gfx module.
26  *#*
27  *#* Revision 1.1  2005/11/04 18:11:35  bernie
28  *#* Move graphics stuff from mware/ to gfx/.
29  *#*
30  *#* Revision 1.11  2005/04/11 19:10:28  bernie
31  *#* Include top-level headers from cfg/ subdir.
32  *#*
33  *#* Revision 1.10  2005/03/01 23:26:46  bernie
34  *#* Use new CPU-neutral program-memory API.
35  *#*
36  *#* Revision 1.9  2004/12/31 16:44:29  bernie
37  *#* Sanitize for non-Harvard processors.
38  *#*
39  *#* Revision 1.8  2004/10/03 20:43:37  bernie
40  *#* Import changes from project_ks.
41  *#*
42  *#* Revision 1.7  2004/09/20 03:28:49  bernie
43  *#* Fix header; Conditionalize AVR-specific code.
44  *#*
45  *#* Revision 1.6  2004/09/14 20:57:30  bernie
46  *#* Reformat.
47  *#*
48  *#* Revision 1.5  2004/09/06 21:51:26  bernie
49  *#* Extend interface to allow any algorithmic style.
50  *#*
51  *#* Revision 1.4  2004/08/25 14:12:09  rasky
52  *#* Aggiornato il comment block dei log RCS
53  *#*
54  *#* Revision 1.3  2004/08/05 18:46:44  bernie
55  *#* Documentation improvements.
56  *#*
57  *#* Revision 1.2  2004/06/03 11:27:09  bernie
58  *#* Add dual-license information.
59  *#*
60  *#*/
61
62 #ifndef GFX_TEXT_H
63 #define GFX_TEXT_H
64
65 #include <cfg/compiler.h>
66 #include <cfg/macros.h> /* BV() */
67 #include <cfg/cpu.h> /* CPU_HARVARD */
68
69 #include <stdarg.h>
70
71 /*!
72  * \name Style flags
73  * \see text_style()
74  * \{
75  */
76 #define STYLEF_BOLD        BV(0)
77 #define STYLEF_ITALIC      BV(1)
78 #define STYLEF_UNDERLINE   BV(2)
79 #define STYLEF_INVERT      BV(3)
80 #define STYLEF_EXPANDED    BV(4)
81 #define STYLEF_CONDENSED   BV(5)
82 #define STYLEF_STRIKEOUT   BV(6)  /*<! Not implemented */
83 #define STYLEF_TALL        BV(7)  /*<! Not implemented */
84
85 #define STYLEF_MASK \
86         (STYLEF_BOLD | STYLEF_ITALIC | STYLEF_UNDERLINE \
87         | STYLEF_INVERT | STYLEF_EXPANDED | STYLEF_CONDENSED \
88         | STYLEF_STRIKEOUT | STYLEF_TALL)
89 /*\}*/
90
91 /*!
92  * \name Formatting flags for text rendering
93  * \see text_xprintf()
94  * \{
95  */
96 #define TEXT_NORMAL   0       /*!< Normal mode */
97 #define TEXT_FILL     BV(13)  /*!< Fill rest of line with spaces */
98 #define TEXT_CENTER   BV(14)  /*!< Center string in line */
99 #define TEXT_RIGHT    BV(15)  /*!< Right aligned */
100 /*\}*/
101
102 /*! Escape sequences codes */
103 #define ANSI_ESC_CLEARSCREEN 'c'
104
105
106 /* Fwd decl */
107 struct Bitmap;
108
109 /* Low-level text functions (mware/text.c) */
110 void text_moveto(struct Bitmap *bm, int row, int col);
111 void text_setcoord(struct Bitmap *bm, int x, int y);
112 int text_putchar(char c, struct Bitmap *bm);
113 uint8_t text_style(struct Bitmap *bm, uint8_t flags, uint8_t mask);
114 void text_clear(struct Bitmap *bm);
115 void text_clearLine(struct Bitmap *bm, int line);
116
117 /* Text formatting functions (mware/text_format.c) */
118 int text_puts(const char *str, struct Bitmap *bm);
119 int text_vprintf(struct Bitmap *bm, const char *fmt, va_list ap);
120 int text_printf(struct Bitmap *bm, const char *fmt, ...) FORMAT(__printf__, 2, 3);
121 int text_xprintf(struct Bitmap *bm, uint8_t row, uint8_t col, uint16_t mode, const char *fmt, ...) FORMAT(__printf__, 5, 6);
122 int text_vwidthf(struct Bitmap *bm, const char * fmt, va_list ap);
123 int text_widthf(struct Bitmap *bm, const char * fmt, ...) FORMAT(__printf__, 2, 3);
124
125 /* Text formatting functions for program-memory strings (mware/text_format.c) */
126 #if CPU_HARVARD
127 #include <mware/pgm.h>
128 int text_puts_P(const char * PROGMEM str, struct Bitmap *bm);
129 int text_vprintf_P(struct Bitmap *bm, const char * PROGMEM fmt, va_list ap);
130 int text_printf_P(struct Bitmap *bm, const char * PROGMEM fmt, ...) FORMAT(__printf__, 2, 3);
131 int text_xprintf_P(struct Bitmap *bm, uint8_t row, uint8_t col, uint16_t mode, const char * PROGMEM fmt, ...) FORMAT(__printf__, 5, 6);
132 int text_vwidthf_P(struct Bitmap *bm, const char * PROGMEM fmt, va_list ap);
133 int text_widthf_P(struct Bitmap *bm, const char * PROGMEM fmt, ...);
134 #endif /* CPU_HARVARD */
135
136 #endif /* GFX_TEXT_H */