Modify it to adjust Tizen IVI enviroment
[platform/upstream/kmscon.git] / src / font.h
1 /*
2  * kmscon - Font Renderer
3  *
4  * Copyright (c) 2012-2013 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  * Font Renderer
28  */
29
30 #ifndef KMSCON_FONT_H
31 #define KMSCON_FONT_H
32
33 #include <errno.h>
34 #include <stdlib.h>
35 #include "kmscon_module.h"
36 #include "uterm_video.h"
37
38 /* fonts */
39
40 struct kmscon_font_attr;
41 struct kmscon_glyph;
42 struct kmscon_font;
43 struct kmscon_font_ops;
44
45 #define KMSCON_FONT_MAX_NAME 128
46 #define KMSCON_FONT_DEFAULT_NAME "monospace"
47 #define KMSCON_FONT_DEFAULT_PPI 72
48
49 struct kmscon_font_attr {
50         char name[KMSCON_FONT_MAX_NAME];
51         unsigned int ppi;
52         unsigned int points;
53         bool bold;
54         bool italic;
55         unsigned int height;
56         unsigned int width;
57 };
58
59 void kmscon_font_attr_normalize(struct kmscon_font_attr *attr);
60 bool kmscon_font_attr_match(const struct kmscon_font_attr *a1,
61                             const struct kmscon_font_attr *a2);
62
63 struct kmscon_glyph {
64         struct uterm_video_buffer buf;
65         unsigned int width;
66         void *data;
67 };
68
69 struct kmscon_font {
70         unsigned long ref;
71         struct shl_register_record *record;
72         const struct kmscon_font_ops *ops;
73         struct kmscon_font_attr attr;
74         unsigned int baseline;
75         void *data;
76 };
77
78 struct kmscon_font_ops {
79         const char *name;
80         struct kmscon_module *owner;
81         int (*init) (struct kmscon_font *out,
82                      const struct kmscon_font_attr *attr);
83         void (*destroy) (struct kmscon_font *font);
84         int (*render) (struct kmscon_font *font,
85                        uint32_t id, const uint32_t *ch, size_t len,
86                        const struct kmscon_glyph **out);
87         int (*render_empty) (struct kmscon_font *font,
88                              const struct kmscon_glyph **out);
89         int (*render_inval) (struct kmscon_font *font,
90                              const struct kmscon_glyph **out);
91 };
92
93 int kmscon_font_register(const struct kmscon_font_ops *ops);
94 void kmscon_font_unregister(const char *name);
95
96 int kmscon_font_find(struct kmscon_font **out,
97                      const struct kmscon_font_attr *attr,
98                      const char *backend);
99 void kmscon_font_ref(struct kmscon_font *font);
100 void kmscon_font_unref(struct kmscon_font *font);
101
102 int kmscon_font_render(struct kmscon_font *font,
103                        uint32_t id, const uint32_t *ch, size_t len,
104                        const struct kmscon_glyph **out);
105 int kmscon_font_render_empty(struct kmscon_font *font,
106                              const struct kmscon_glyph **out);
107 int kmscon_font_render_inval(struct kmscon_font *font,
108                              const struct kmscon_glyph **out);
109
110 /* modularized backends */
111
112 extern struct kmscon_font_ops kmscon_font_8x16_ops;
113 extern struct kmscon_font_ops kmscon_font_unifont_ops;
114 extern struct kmscon_font_ops kmscon_font_pango_ops;
115
116 #endif /* KMSCON_FONT_H */