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.
48 /* TODO: rename to kmscon_char_attr */
49 struct font_char_attr {
50 uint8_t fr; /* foreground red */
51 uint8_t fg; /* foreground green */
52 uint8_t fb; /* foreground blue */
53 uint8_t br; /* background red */
54 uint8_t bg; /* background green */
55 uint8_t bb; /* background blue */
56 unsigned int bold : 1; /* bold character */
57 unsigned int underline : 1; /* underlined character */
58 unsigned int inverse : 1; /* inverse colors */
59 unsigned int protect : 1; /* cannot be erased */
64 struct kmscon_font_attr;
67 struct kmscon_font_ops;
69 #define KMSCON_FONT_MAX_NAME 128
70 #define KMSCON_FONT_DEFAULT_NAME "monospace"
71 #define KMSCON_FONT_DEFAULT_PPI 72
73 struct kmscon_font_attr {
74 char name[KMSCON_FONT_MAX_NAME];
83 void kmscon_font_attr_normalize(struct kmscon_font_attr *attr);
84 bool kmscon_font_attr_match(const struct kmscon_font_attr *a1,
85 const struct kmscon_font_attr *a2);
88 struct uterm_video_buffer buf;
94 const struct kmscon_font_ops *ops;
95 struct kmscon_font_attr attr;
96 unsigned int baseline;
100 struct kmscon_font_ops {
102 int (*init) (struct kmscon_font *out,
103 const struct kmscon_font_attr *attr);
104 void (*destroy) (struct kmscon_font *font);
105 int (*render) (struct kmscon_font *font, kmscon_symbol_t sym,
106 const struct kmscon_glyph **out);
107 int (*render_empty) (struct kmscon_font *font,
108 const struct kmscon_glyph **out);
109 int (*render_inval) (struct kmscon_font *font,
110 const struct kmscon_glyph **out);
113 int kmscon_font_register(const struct kmscon_font_ops *ops);
114 void kmscon_font_unregister(const char *name);
116 int kmscon_font_find(struct kmscon_font **out,
117 const struct kmscon_font_attr *attr,
118 const char *backend);
119 void kmscon_font_ref(struct kmscon_font *font);
120 void kmscon_font_unref(struct kmscon_font *font);
122 int kmscon_font_render(struct kmscon_font *font, kmscon_symbol_t sym,
123 const struct kmscon_glyph **out);
124 int kmscon_font_render_empty(struct kmscon_font *font,
125 const struct kmscon_glyph **out);
126 int kmscon_font_render_inval(struct kmscon_font *font,
127 const struct kmscon_glyph **out);
132 struct kmscon_text_ops;
136 const struct kmscon_text_ops *ops;
139 struct kmscon_font *font;
140 struct uterm_screen *screen;
146 struct kmscon_text_ops {
148 int (*init) (struct kmscon_text *txt);
149 void (*destroy) (struct kmscon_text *txt);
150 int (*set) (struct kmscon_text *txt);
151 void (*unset) (struct kmscon_text *txt);
152 int (*prepare) (struct kmscon_text *txt);
153 int (*draw) (struct kmscon_text *txt, kmscon_symbol_t ch,
154 unsigned int posx, unsigned int posy,
155 const struct font_char_attr *attr);
156 int (*render) (struct kmscon_text *txt);
157 void (*abort) (struct kmscon_text *txt);
160 int kmscon_text_register(const struct kmscon_text_ops *ops);
161 void kmscon_text_unregister(const char *name);
163 int kmscon_text_new(struct kmscon_text **out, const char *backend);
164 void kmscon_text_ref(struct kmscon_text *txt);
165 void kmscon_text_unref(struct kmscon_text *txt);
167 int kmscon_text_set(struct kmscon_text *txt,
168 struct kmscon_font *font,
169 struct uterm_screen *screen);
170 void kmscon_text_unset(struct kmscon_text *txt);
171 unsigned int kmscon_text_get_cols(struct kmscon_text *txt);
172 unsigned int kmscon_text_get_rows(struct kmscon_text *txt);
174 int kmscon_text_prepare(struct kmscon_text *txt);
175 int kmscon_text_draw(struct kmscon_text *txt, kmscon_symbol_t ch,
176 unsigned int posx, unsigned int posy,
177 const struct font_char_attr *attr);
178 int kmscon_text_render(struct kmscon_text *txt);
179 void kmscon_text_abort(struct kmscon_text *txt);
181 /* modularized backends */
183 #ifdef KMSCON_HAVE_8X16
185 int kmscon_font_8x16_load(void);
186 void kmscon_font_8x16_unload(void);
190 static inline int kmscon_font_8x16_load(void)
195 static inline void kmscon_font_8x16_unload(void)
201 #ifdef KMSCON_HAVE_FREETYPE2
203 int kmscon_font_freetype2_load(void);
204 void kmscon_font_freetype2_unload(void);
208 static inline int kmscon_font_freetype2_load(void)
213 static inline void kmscon_font_freetype2_unload(void)
219 #ifdef KMSCON_HAVE_PANGO
221 int kmscon_font_pango_load(void);
222 void kmscon_font_pango_unload(void);
226 static inline int kmscon_font_pango_load(void)
231 static inline void kmscon_font_pango_unload(void)
237 #ifdef KMSCON_HAVE_BBLIT
239 int kmscon_text_bblit_load(void);
240 void kmscon_text_bblit_unload(void);
244 static inline int kmscon_text_bblit_load(void)
249 static inline void kmscon_text_bblit_unload(void)
255 #ifdef KMSCON_HAVE_GLES2
257 int kmscon_text_gltex_load(void);
258 void kmscon_text_gltex_unload(void);
262 static inline int kmscon_text_gltex_load(void)
267 static inline void kmscon_text_gltex_unload(void)
273 #endif /* KMSCON_TEXT_H */