text: font: add pango font backend
[platform/upstream/kmscon.git] / src / text.h
1 /*
2  * kmscon - Text Renderer
3  *
4  * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
5  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
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.
24  */
25
26 /*
27  * Text Renderer
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.
36  */
37
38 #ifndef KMSCON_TEXT_H
39 #define KMSCON_TEXT_H
40
41 #include <stdlib.h>
42 #include "unicode.h"
43 #include "uterm.h"
44
45 /* fonts */
46
47 struct kmscon_font_attr;
48 struct kmscon_glyph;
49 struct kmscon_font;
50 struct kmscon_font_ops;
51
52 #define KMSCON_FONT_MAX_NAME 128
53 #define KMSCON_FONT_DEFAULT_NAME "monospace"
54 #define KMSCON_FONT_DEFAULT_PPI 72
55
56 struct kmscon_font_attr {
57         char name[KMSCON_FONT_MAX_NAME];
58         unsigned int ppi;
59         unsigned int points;
60         bool bold;
61         bool italic;
62         unsigned int height;
63         unsigned int width;
64 };
65
66 void kmscon_font_attr_normalize(struct kmscon_font_attr *attr);
67 bool kmscon_font_attr_match(const struct kmscon_font_attr *a1,
68                             const struct kmscon_font_attr *a2);
69
70 struct kmscon_glyph {
71         unsigned int ascent;
72         unsigned int descent;
73         struct uterm_video_buffer buf;
74 };
75
76 struct kmscon_font {
77         unsigned long ref;
78         const struct kmscon_font_ops *ops;
79         struct kmscon_font_attr attr;
80         unsigned int baseline;
81         void *data;
82 };
83
84 struct kmscon_font_ops {
85         const char *name;
86         int (*init) (struct kmscon_font *out,
87                      const struct kmscon_font_attr *attr);
88         void (*destroy) (struct kmscon_font *font);
89         int (*render) (struct kmscon_font *font, kmscon_symbol_t sym,
90                        const struct kmscon_glyph **out);
91         void (*drop) (struct kmscon_font *font,
92                       const struct kmscon_glyph *glyph);
93 };
94
95 int kmscon_font_register(const struct kmscon_font_ops *ops);
96 void kmscon_font_unregister(const char *name);
97
98 int kmscon_font_find(struct kmscon_font **out,
99                      const struct kmscon_font_attr *attr,
100                      const char *backend);
101 void kmscon_font_ref(struct kmscon_font *font);
102 void kmscon_font_unref(struct kmscon_font *font);
103
104 int kmscon_font_render(struct kmscon_font *font, kmscon_symbol_t sym,
105                        const struct kmscon_glyph **out);
106 void kmscon_font_drop(struct kmscon_font *font,
107                       const struct kmscon_glyph *glyph);
108
109 /* modularized backends */
110
111 int kmscon_font_8x16_load(void);
112 void kmscon_font_8x16_unload(void);
113 int kmscon_font_pango_load(void);
114 void kmscon_font_pango_unload(void);
115
116 #endif /* KMSCON_TEXT_H */