2 * kmscon - Fixed unifont font
4 * Copyright (c) 2012 Ted Kotz <ted@kotz.us>
5 * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files
9 * (the "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * SECTION:font_unifont.c
29 * @short_description: Fixed unifont font
32 * This is a fixed font renderer backend that supports just one font which is
33 * statically compiled into the file. This bitmap font has 8x16 and 16x16
34 * glyphs. This can statically compile in any font defined as a unifont style
35 * hex format. This font is from the GNU unifont project available at:
36 * http://unifoundry.com/unifont.html
38 * This file is heavily based on font_8x16.c
49 #define LOG_SUBSYSTEM "font_unifont"
51 /* array is generated and compiled externally */
52 extern const struct kmscon_glyph kmscon_font_unifont_data_hex_glyphs[];
53 extern size_t kmscon_font_unifont_data_hex_len;
55 static int kmscon_font_unifont_init(struct kmscon_font *out,
56 const struct kmscon_font_attr *attr)
58 static const char name[] = "static-unifont";
60 log_debug("loading static unifont font");
62 memset(&out->attr, 0, sizeof(out->attr));
63 memcpy(out->attr.name, name, sizeof(name));
64 out->attr.bold = false;
65 out->attr.italic = false;
67 out->attr.height = 16;
68 kmscon_font_attr_normalize(&out->attr);
74 static void kmscon_font_unifont_destroy(struct kmscon_font *font)
76 log_debug("unloading static unifont font");
79 static int kmscon_font_unifont_render(struct kmscon_font *font, uint32_t id,
80 const uint32_t *ch, size_t len,
81 const struct kmscon_glyph **out)
83 if (len > 1 || *ch >= kmscon_font_unifont_data_hex_len)
86 *out = &kmscon_font_unifont_data_hex_glyphs[*ch];
90 static int kmscon_font_unifont_render_inval(struct kmscon_font *font,
91 const struct kmscon_glyph **out)
93 if (0xfffd < kmscon_font_unifont_data_hex_len)
94 *out = &kmscon_font_unifont_data_hex_glyphs[0xfffd];
95 else if ('?' < kmscon_font_unifont_data_hex_len)
96 *out = &kmscon_font_unifont_data_hex_glyphs['?'];
98 *out = &kmscon_font_unifont_data_hex_glyphs[0];
103 static int kmscon_font_unifont_render_empty(struct kmscon_font *font,
104 const struct kmscon_glyph **out)
106 if (' ' < kmscon_font_unifont_data_hex_len) {
107 *out = &kmscon_font_unifont_data_hex_glyphs[' '];
110 return kmscon_font_unifont_render_inval(font, out);
114 struct kmscon_font_ops kmscon_font_unifont_ops = {
117 .init = kmscon_font_unifont_init,
118 .destroy = kmscon_font_unifont_destroy,
119 .render = kmscon_font_unifont_render,
120 .render_empty = kmscon_font_unifont_render_empty,
121 .render_inval = kmscon_font_unifont_render_inval,