chiark / gitweb /
bus-proxyd: explicitly address messages to unique and well-known name
[elogind.git] / src / libsystemd-terminal / unifont-def.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com>
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #pragma once
23
24 #include <stdbool.h>
25 #include <stdint.h>
26 #include <stdlib.h>
27 #include "sparse-endian.h"
28 #include "util.h"
29
30 typedef struct unifont_header unifont_header;
31 typedef struct unifont_glyph_header unifont_glyph_header;
32
33 /*
34  * Unifont: On-disk data
35  * Conventional font-formats have the problem that you have to pre-render each
36  * glyph before you can use it. If you just need one glyph, you have to parse
37  * the font-file until you found that glyph.
38  * GNU-Unifont is a bitmap font with very good Unicode coverage. All glyphs are
39  * (n*8)x16 bitmaps. Our on-disk data stores all those glyphs pre-compiled with
40  * fixed offsets. Therefore, the font-file can be mmap()ed and all glyphs can
41  * be accessed in O(1) (because all glyphs have the same size and thus their
42  * offsets can be easily computed). This guarantees, that the kernel only loads
43  * the pages that are really accessed. Thus, we have a far lower overhead than
44  * traditional font-formats like BDF. Furthermore, the backing file is read-only
45  * and can be shared in memory between multiple users.
46  *
47  * The binary-format starts with a fixed header:
48  *
49  *      | 2bytes | 2bytes | 2bytes | 2bytes |
50  *
51  *      +-----------------------------------+
52  *      |             SIGNATURE             |   8 bytes
53  *      +-----------------+-----------------+
54  *      |  COMPAT FLAGS   | INCOMPAT FLAGS  |   8 bytes
55  *      +-----------------+--------+--------+
56  *      |   HEADER SIZE   |GH-SIZE |G-STRIDE|   8 bytes
57  *      +-----------------+--------+--------+
58  *      |          GLYPH BODY SIZE          |   8 bytes
59  *      +-----------------------------------+
60  *
61  *  * The 8 bytes signature must be set to the ASCII string "DVDHRMUF".
62  *  * The 4 bytes compatible-flags field contains flags for new features that
63  *    might be added in the future and which are compatible to older parsers.
64  *  * The 4 bytes incompatible-flags field contains flags for new features that
65  *    might be added in the future and which are incompatible to old parses.
66  *    Thus, if you encounter an unknown bit set, you must abort!
67  *  * The 4 bytes header-size field contains the size of the header in bytes. It
68  *    must be at least 32 (the size of this fixed header). If new features are
69  *    added, it might be increased. It can also be used to add padding to the
70  *    end of the header.
71  *  * The 2 bytes glyph-header-size field specifies the size of each glyph
72  *    header in bytes (see below).
73  *  * The 2 bytes glyph-stride field specifies the stride of each line of glyph
74  *    data in "bytes per line".
75  *  * The 8 byte glyph-body-size field defines the size of each glyph body in
76  *    bytes.
77  *
78  * After the header, the file can contain padding bytes, depending on the
79  * header-size field. Everything beyond the header+padding is treated as a big
80  * array of glyphs. Each glyph looks like this:
81  *
82  *      |              1 byte               |
83  *
84  *      +-----------------------------------+
85  *      |               WIDTH               |   1 byte
86  *      +-----------------------------------+
87  *      ~              PADDING              ~
88  *      +-----------------------------------+
89  *      ~                                   ~
90  *      ~                                   ~
91  *      ~                DATA               ~
92  *      ~                                   ~
93  *      ~                                   ~
94  *      +-----------------------------------+
95  *
96  *  * The first byte specifies the width of the glyph. If it is 0, the glyph
97  *    must be treated as non-existant.
98  *    All glyphs are "8*n" pixels wide and "16" pixels high. The width-field
99  *    specifies the width multiplier "n".
100  *  * After the width field padding might be added. This depends on the global
101  *    glyph-header-size field. It defines the total size of each glyph-header.
102  *    After the glyph-header+padding, the data-field starts.
103  *  * The data-field contains a byte-array of bitmap data. The array is always
104  *    as big as specified in the global glyph-body-size header field. This might
105  *    include padding.
106  *    The array contains all 16 lines of bitmap information for that glyph. The
107  *    stride is given in the global glyph-stride header field. This can be used
108  *    to add padding after each line.
109  *    Each line is encoded as 1 bit per pixel bitmap. That is, each byte encodes
110  *    data for 8 pixels (left most pixel is encoded in the LSB, right most pixel
111  *    in the MSB). The width field defines the number of bytes valid per line.
112  *    For width==1, you need 1 byte to encode the 8 pixels. The stride defines
113  *    where the encoding of the next line starts.
114  *    Any data beyond the 16th line is padding and must be ignored.
115  */
116
117 /* path to binary file */
118 #define UNIFONT_PATH "/usr/share/systemd/unifont-glyph-array.bin"
119
120 /* header-size of version 1 */
121 #define UNIFONT_HEADER_SIZE_MIN 32
122
123 struct unifont_header {
124         /* fields available in version 1 */
125         uint8_t signature[8];
126         le32_t compatible_flags;
127         le32_t incompatible_flags;
128         le32_t header_size;
129         le16_t glyph_header_size;
130         le16_t glyph_stride;
131         le64_t glyph_body_size;
132 } _packed_;
133
134 struct unifont_glyph_header {
135         /* fields available in version 1 */
136         uint8_t width;
137 } _packed_;