2 * kmscon - Text Renderer
4 * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * The Text-Renderer subsystem provides a simple way to draw text into a
29 * framebuffer. The system is modular and several different backends are
30 * available that can be used.
31 * The system is split into:
32 * - Font renderer: The font renderer allows selecting fonts and rendering
33 * single glyphs into memory-buffers
34 * - Text renderer: The text renderer uses the font renderer to draw a whole
35 * console into a framebuffer.
47 /* TODO: rename to kmscon_char_attr */
48 struct font_char_attr {
49 uint8_t fr; /* foreground red */
50 uint8_t fg; /* foreground green */
51 uint8_t fb; /* foreground blue */
52 uint8_t br; /* background red */
53 uint8_t bg; /* background green */
54 uint8_t bb; /* background blue */
55 unsigned int bold : 1; /* bold character */
56 unsigned int underline : 1; /* underlined character */
57 unsigned int inverse : 1; /* inverse colors */
58 unsigned int protect : 1; /* cannot be erased */
63 struct kmscon_font_attr;
66 struct kmscon_font_ops;
68 #define KMSCON_FONT_MAX_NAME 128
69 #define KMSCON_FONT_DEFAULT_NAME "monospace"
70 #define KMSCON_FONT_DEFAULT_PPI 72
72 struct kmscon_font_attr {
73 char name[KMSCON_FONT_MAX_NAME];
82 void kmscon_font_attr_normalize(struct kmscon_font_attr *attr);
83 bool kmscon_font_attr_match(const struct kmscon_font_attr *a1,
84 const struct kmscon_font_attr *a2);
87 struct uterm_video_buffer buf;
93 const struct kmscon_font_ops *ops;
94 struct kmscon_font_attr attr;
95 unsigned int baseline;
99 struct kmscon_font_ops {
101 int (*init) (struct kmscon_font *out,
102 const struct kmscon_font_attr *attr);
103 void (*destroy) (struct kmscon_font *font);
104 int (*render) (struct kmscon_font *font, kmscon_symbol_t sym,
105 const struct kmscon_glyph **out);
106 int (*render_empty) (struct kmscon_font *font,
107 const struct kmscon_glyph **out);
108 int (*render_inval) (struct kmscon_font *font,
109 const struct kmscon_glyph **out);
112 int kmscon_font_register(const struct kmscon_font_ops *ops);
113 void kmscon_font_unregister(const char *name);
115 int kmscon_font_find(struct kmscon_font **out,
116 const struct kmscon_font_attr *attr,
117 const char *backend);
118 void kmscon_font_ref(struct kmscon_font *font);
119 void kmscon_font_unref(struct kmscon_font *font);
121 int kmscon_font_render(struct kmscon_font *font, kmscon_symbol_t sym,
122 const struct kmscon_glyph **out);
123 int kmscon_font_render_empty(struct kmscon_font *font,
124 const struct kmscon_glyph **out);
125 int kmscon_font_render_inval(struct kmscon_font *font,
126 const struct kmscon_glyph **out);
131 struct kmscon_text_ops;
135 const struct kmscon_text_ops *ops;
136 struct kmscon_font *font;
137 struct uterm_screen *screen;
147 struct kmscon_text_ops {
149 int (*init) (struct kmscon_text *txt);
150 void (*destroy) (struct kmscon_text *txt);
151 void (*new_font) (struct kmscon_text *txt);
152 void (*new_bgcolor) (struct kmscon_text *txt);
153 void (*new_screen) (struct kmscon_text *txt);
154 void (*prepare) (struct kmscon_text *txt);
155 void (*draw) (struct kmscon_text *txt, kmscon_symbol_t ch,
156 unsigned int posx, unsigned int posy,
157 const struct font_char_attr *attr);
158 void (*render) (struct kmscon_text *txt);
161 int kmscon_text_register(const struct kmscon_text_ops *ops);
162 void kmscon_text_unregister(const char *name);
164 int kmscon_text_new(struct kmscon_text **out, const char *backend);
165 void kmscon_text_ref(struct kmscon_text *txt);
166 void kmscon_text_unref(struct kmscon_text *txt);
168 void kmscon_text_set_font(struct kmscon_text *txt,
169 struct kmscon_font *font);
170 void kmscon_text_set_bgcolor(struct kmscon_text *txt,
171 uint8_t r, uint8_t g, uint8_t b);
172 void kmscon_text_set_screen(struct kmscon_text *txt,
173 struct uterm_screen *screen);
174 unsigned int kmscon_text_get_cols(struct kmscon_text *txt);
175 unsigned int kmscon_text_get_rows(struct kmscon_text *txt);
177 void kmscon_text_prepare(struct kmscon_text *txt);
178 void kmscon_text_draw(struct kmscon_text *txt, kmscon_symbol_t ch,
179 unsigned int posx, unsigned int posy,
180 const struct font_char_attr *attr);
181 void kmscon_text_render(struct kmscon_text *txt);
183 /* modularized backends */
185 #ifdef KMSCON_HAVE_8X16
187 int kmscon_font_8x16_load(void);
188 void kmscon_font_8x16_unload(void);
192 static inline int kmscon_font_8x16_load(void)
197 static inline void kmscon_font_8x16_unload(void)
203 #ifdef KMSCON_HAVE_FREETYPE2
205 int kmscon_font_freetype2_load(void);
206 void kmscon_font_freetype2_unload(void);
210 static inline int kmscon_font_freetype2_load(void)
215 static inline void kmscon_font_freetype2_unload(void)
221 #ifdef KMSCON_HAVE_PANGO
223 int kmscon_font_pango_load(void);
224 void kmscon_font_pango_unload(void);
228 static inline int kmscon_font_pango_load(void)
233 static inline void kmscon_font_pango_unload(void)
239 #ifdef KMSCON_HAVE_BBLIT
241 int kmscon_text_bblit_load(void);
242 void kmscon_text_bblit_unload(void);
246 static inline int kmscon_text_bblit_load(void)
251 static inline void kmscon_text_bblit_unload(void)
257 #endif /* KMSCON_TEXT_H */