-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfont.cc
More file actions
174 lines (167 loc) · 9.49 KB
/
font.cc
File metadata and controls
174 lines (167 loc) · 9.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* font.cc - simple ascii font bitmap */
/* Copyright (C) 2013 Goswin von Brederlow <goswin-v-b@web.de> (crop & C++ code)
Copyright (C) 2012 yamamushi (generation from Unifont + fixes) [1]
Copyright (C) 2008 Paul Hardy (Unifont release) [2]
Copyright (C) 2008 Roman Czyborra (glyphs)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
[1] http://opengameart.org/content/complete-unicode-plane-0-bitmap-font-png
[2] http://unifoundry.com/index.html
*/
#include "font.h"
namespace Font {
uint8_t data[98][16] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // <pad>
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // ' '
{ 0, 0, 0, 0, 16, 16, 16, 16, 16, 16, 16, 0, 16, 16, 0, 0}, // '!'
{ 0, 0, 68, 68, 68, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // '"'
{ 0, 0, 0, 0, 18, 18, 18,126, 36, 36,126, 72, 72, 72, 0, 0}, // '#'
{ 0, 0, 0, 0, 16,124,146,144,112, 28, 18,146,124, 16, 0, 0}, // '$'
{ 0, 0, 0, 0, 98,148,148,104, 16, 16, 44, 82, 82,140, 0, 0}, // '%'
{ 0, 0, 0, 0, 56, 68, 68, 68, 56,114,138,132,140,114, 0, 0}, // '&'
{ 0, 0, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // '''
{ 0, 0, 0, 8, 16, 16, 32, 32, 32, 32, 32, 32, 16, 16, 8, 0}, // '('
{ 0, 0, 0, 32, 16, 16, 8, 8, 8, 8, 8, 8, 16, 16, 32, 0}, // ')'
{ 0, 0, 0, 0, 0, 0, 16,146, 84, 56, 84,146, 16, 0, 0, 0}, // '*'
{ 0, 0, 0, 0, 0, 0, 16, 16, 16,254, 16, 16, 16, 0, 0, 0}, // '+'
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 8, 8, 16}, // ','
{ 0, 0, 0, 0, 0, 0, 0, 0, 0,126, 0, 0, 0, 0, 0, 0}, // '-'
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 24, 0, 0}, // '.'
{ 0, 0, 0, 0, 2, 2, 4, 8, 8, 16, 16, 32, 64, 64, 0, 0}, // '/'
{ 0, 0, 0, 0, 24, 36, 66, 66, 66, 66, 66, 66, 36, 24, 0, 0}, // '0'
{ 0, 0, 0, 0, 16, 48, 80, 16, 16, 16, 16, 16, 16,124, 0, 0}, // '1'
{ 0, 0, 0, 0, 60, 66, 66, 2, 12, 16, 32, 64, 64,126, 0, 0}, // '2'
{ 0, 0, 0, 0, 60, 66, 66, 2, 28, 2, 2, 66, 66, 60, 0, 0}, // '3'
{ 0, 0, 0, 0, 4, 12, 20, 36, 68, 68,126, 4, 4, 4, 0, 0}, // '4'
{ 0, 0, 0, 0,126, 64, 64, 64,124, 2, 2, 2, 66, 60, 0, 0}, // '5'
{ 0, 0, 0, 0, 28, 32, 64, 64,124, 66, 66, 66, 66, 60, 0, 0}, // '6'
{ 0, 0, 0, 0,126, 2, 2, 4, 4, 4, 8, 8, 8, 8, 0, 0}, // '7'
{ 0, 0, 0, 0, 60, 66, 66, 66, 60, 66, 66, 66, 66, 60, 0, 0}, // '8'
{ 0, 0, 0, 0, 60, 66, 66, 66, 62, 2, 2, 2, 4, 56, 0, 0}, // '9'
{ 0, 0, 0, 0, 0, 0, 24, 24, 0, 0, 0, 24, 24, 0, 0, 0}, // ':'
{ 0, 0, 0, 0, 0, 0, 24, 24, 0, 0, 0, 24, 8, 8, 16, 0}, // ';'
{ 0, 0, 0, 0, 0, 4, 8, 16, 32, 64, 32, 16, 8, 4, 0, 0}, // '<'
{ 0, 0, 0, 0, 0, 0, 0,126, 0, 0, 0,126, 0, 0, 0, 0}, // '='
{ 0, 0, 0, 0, 0, 64, 32, 16, 8, 4, 8, 16, 32, 64, 0, 0}, // '>'
{ 0, 0, 0, 0, 60, 66, 66, 2, 4, 8, 8, 0, 8, 8, 0, 0}, // '?'
{ 0, 0, 0, 0, 28, 34, 74, 86, 82, 82, 82, 78, 32, 30, 0, 0}, // '@'
{ 0, 0, 0, 0, 24, 36, 36, 66, 66,126, 66, 66, 66, 66, 0, 0}, // 'A'
{ 0, 0, 0, 0,124, 66, 66, 66,124, 66, 66, 66, 66,124, 0, 0}, // 'B'
{ 0, 0, 0, 0, 60, 66, 66, 64, 64, 64, 64, 66, 66, 60, 0, 0}, // 'C'
{ 0, 0, 0, 0,120, 68, 66, 66, 66, 66, 66, 66, 68,120, 0, 0}, // 'D'
{ 0, 0, 0, 0,126, 64, 64, 64,124, 64, 64, 64, 64,126, 0, 0}, // 'E'
{ 0, 0, 0, 0,126, 64, 64, 64,124, 64, 64, 64, 64, 64, 0, 0}, // 'F'
{ 0, 0, 0, 0, 60, 66, 66, 64, 64, 78, 66, 66, 70, 58, 0, 0}, // 'G'
{ 0, 0, 0, 0, 66, 66, 66, 66,126, 66, 66, 66, 66, 66, 0, 0}, // 'H'
{ 0, 0, 0, 0,124, 16, 16, 16, 16, 16, 16, 16, 16,124, 0, 0}, // 'I'
{ 0, 0, 0, 0, 62, 8, 8, 8, 8, 8, 8,136,136,112, 0, 0}, // 'J'
{ 0, 0, 0, 0, 66, 68, 72, 80, 96, 96, 80, 72, 68, 66, 0, 0}, // 'K'
{ 0, 0, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64,126, 0, 0}, // 'L'
{ 0, 0, 0, 0, 66, 66,102,102, 90, 90, 66, 66, 66, 66, 0, 0}, // 'M'
{ 0, 0, 0, 0, 66, 98, 98, 82, 82, 74, 74, 70, 70, 66, 0, 0}, // 'N'
{ 0, 0, 0, 0, 60, 66, 66, 66, 66, 66, 66, 66, 66, 60, 0, 0}, // 'O'
{ 0, 0, 0, 0,124, 66, 66, 66,124, 64, 64, 64, 64, 64, 0, 0}, // 'P'
{ 0, 0, 0, 0,120,132,132,132,132,132,132,180,204,120, 6, 0}, // 'Q'
{ 0, 0, 0, 0,124, 66, 66, 66,124, 72, 68, 68, 66, 66, 0, 0}, // 'R'
{ 0, 0, 0, 0, 60, 66, 66, 64, 48, 12, 2, 66, 66, 60, 0, 0}, // 'S'
{ 0, 0, 0, 0,254, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0}, // 'T'
{ 0, 0, 0, 0, 66, 66, 66, 66, 66, 66, 66, 66, 66, 60, 0, 0}, // 'U'
{ 0, 0, 0, 0,130,130,130, 68, 68, 68, 40, 40, 16, 16, 0, 0}, // 'V'
{ 0, 0, 0, 0, 66, 66, 66, 66, 90, 90,102,102, 66, 66, 0, 0}, // 'W'
{ 0, 0, 0, 0, 66, 66, 36, 36, 24, 24, 36, 36, 66, 66, 0, 0}, // 'X'
{ 0, 0, 0, 0,130,130, 68, 68, 40, 16, 16, 16, 16, 16, 0, 0}, // 'Y'
{ 0, 0, 0, 0,126, 2, 2, 4, 8, 16, 32, 64, 64,126, 0, 0}, // 'Z'
{ 0, 0, 0, 56, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 56, 0}, // '['
{ 0, 0, 0, 0, 64, 64, 32, 16, 16, 8, 8, 4, 2, 2, 0, 0}, // '\'
{ 0, 0, 0, 56, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 56, 0}, // ']'
{ 0, 0, 24, 36, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // '^'
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,254, 0}, // '_'
{ 0, 32, 16, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // '`'
{ 0, 0, 0, 0, 0, 0, 60, 66, 2, 62, 66, 66, 70, 58, 0, 0}, // 'a'
{ 0, 0, 0, 64, 64, 64, 92, 98, 66, 66, 66, 66, 98, 92, 0, 0}, // 'b'
{ 0, 0, 0, 0, 0, 0, 60, 66, 64, 64, 64, 64, 66, 60, 0, 0}, // 'c'
{ 0, 0, 0, 2, 2, 2, 58, 70, 66, 66, 66, 66, 70, 58, 0, 0}, // 'd'
{ 0, 0, 0, 0, 0, 0, 60, 66, 66,126, 64, 64, 66, 60, 0, 0}, // 'e'
{ 0, 0, 0, 12, 16, 16, 16,124, 16, 16, 16, 16, 16, 16, 0, 0}, // 'f'
{ 0, 0, 0, 0, 0, 2, 58, 68, 68, 68, 56, 32, 60, 66, 66, 60}, // 'g'
{ 0, 0, 0, 64, 64, 64, 92, 98, 66, 66, 66, 66, 66, 66, 0, 0}, // 'h'
{ 0, 0, 0, 16, 16, 0, 48, 16, 16, 16, 16, 16, 16,124, 0, 0}, // 'i'
{ 0, 0, 0, 4, 4, 0, 12, 4, 4, 4, 4, 4, 4, 4, 72, 48}, // 'j'
{ 0, 0, 0, 0, 64, 64, 68, 72, 80, 96, 80, 72, 68, 66, 0, 0}, // 'k'
{ 0, 0, 0, 0, 48, 16, 16, 16, 16, 16, 16, 16, 16,124, 0, 0}, // 'l'
{ 0, 0, 0, 0, 0, 0,236,146,146,146,146,146,146,146, 0, 0}, // 'm'
{ 0, 0, 0, 0, 0, 0, 92, 98, 66, 66, 66, 66, 66, 66, 0, 0}, // 'n'
{ 0, 0, 0, 0, 0, 0, 60, 66, 66, 66, 66, 66, 66, 60, 0, 0}, // 'o'
{ 0, 0, 0, 0, 0, 0, 92, 98, 66, 66, 66, 66, 98, 92, 64, 64}, // 'p'
{ 0, 0, 0, 0, 0, 0, 58, 70, 66, 66, 66, 66, 70, 58, 2, 2}, // 'q'
{ 0, 0, 0, 0, 0, 0, 92, 98, 66, 64, 64, 64, 64, 64, 0, 0}, // 'r'
{ 0, 0, 0, 0, 0, 0, 60, 66, 64, 48, 12, 2, 66, 60, 0, 0}, // 's'
{ 0, 0, 0, 0, 16, 16,124, 16, 16, 16, 16, 16, 16, 12, 0, 0}, // 't'
{ 0, 0, 0, 0, 0, 0, 66, 66, 66, 66, 66, 66, 70, 58, 0, 0}, // 'u'
{ 0, 0, 0, 0, 0, 0, 66, 66, 66, 36, 36, 36, 24, 24, 0, 0}, // 'v'
{ 0, 0, 0, 0, 0, 0,130,146,146,146,146,146,146,108, 0, 0}, // 'w'
{ 0, 0, 0, 0, 0, 0, 66, 66, 36, 24, 24, 36, 66, 66, 0, 0}, // 'x'
{ 0, 0, 0, 0, 0, 0, 66, 66, 66, 66, 66, 38, 26, 2, 2, 60}, // 'y'
{ 0, 0, 0, 0, 0, 0,126, 2, 4, 8, 16, 32, 64,126, 0, 0}, // 'z'
{ 0, 0, 0, 24, 32, 32, 16, 16, 32, 32, 16, 16, 32, 32, 24, 0}, // '{'
{ 0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}, // '|'
{ 0, 0, 0, 48, 8, 8, 16, 16, 8, 8, 16, 16, 8, 8, 48, 0}, // '}'
{ 0, 0, 0, 98,146,140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // '~'
{170, 0, 0, 0, 0, 61,161,189,161, 61, 0, 0, 0, 0, 0, 85}, // <checkers>
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // <pad>
};
void putc(const Framebuffer::FB &fb, uint32_t x, uint32_t y, char c,
uint32_t color, uint32_t border, bool fill) {
uint32_t *base = (uint32_t*)fb.base;
uint32_t pitch = fb.pitch / 4;
if ((c < 32) || (c > 127)) {
// non printable chars get checkers
c = 127;
};
// font data begins at ascii 32 but has 1 char padding
c -= 31;
// lookup glyph
uint8_t *glyph = data[(int)c];
// row pointer for framebuffer
uint32_t *row = &base[y * pitch];
for (uint32_t v = 0; v < 16; ++v) {
if (y + v >= fb.height) break;
uint16_t mask = 0x80;
// pixel position in the row
uint32_t *pixel = &row[x];
for (uint32_t u = 0; u < 8; ++u) {
if (x + u >= fb.width) break;
// Draw color if bit is set
// Draw border if bit right, left, below or above is set
// Otherwise draw border if fill or skip pixel
if (*glyph & mask) {
*pixel++ = color;
} else if (glyph[0] & (mask << 1)) {
*pixel++ = border;
} else if (glyph[0] & (mask >> 1)) {
*pixel++ = border;
} else if (glyph[-1] & mask) {
*pixel++ = border;
} else if (glyph[1] & mask) {
*pixel++ = border;
} else if (fill) {
*pixel++ = border;
} else {
pixel++;
}
mask >>= 1;
}
++glyph;
row += pitch;
}
}
}