-
Notifications
You must be signed in to change notification settings - Fork 6
/
hershey-fonts.cpp
185 lines (179 loc) · 13 KB
/
hershey-fonts.cpp
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
175
176
177
178
179
180
181
182
183
#include "ccow.h"
#include <stdlib.h>
#include <string.h>
#include <linux/input.h>
// The font data here was modified from
// http://paulbourke.net/dataformats/hershey/
// Compiled by Paul Bourke in 1997.
static const int8_t hershey_font_simplex_compact[95][112] = {
/* num_stroke_pts, width, stroke_data 21=top, 0=bottom */
/* Ascii 32 */ { 0, 16, },
/* ! Ascii 33 */ { 8, 10, 5,21,5,7,-1,-1,5,2,4,1,5,0,6,1,5,2,},
/* " Ascii 34 */ { 5, 16, 4,21,4,14,-1,-1,12,21,12,14,},
/* # Ascii 35 */ {11, 21, 11,25,4,-7,-1,-1,17,25,10,-7,-1,-1,4,12,18,12,-1,-1,3,6,17,6,},
/* $ Ascii 36 */ {26, 20, 8,25,8,-4,-1,-1,12,25,12,-4,-1,-1,17,18,15,20,12,21,8,21,5,20,3,18,3,16,4,14,5,13,7,12,13,10,15,9,16,8,17,6,17,3,15,1,12,0,8,0,5,1,3,3,},
/* % Ascii 37 */ {31, 24, 21,21,3,0,-1,-1,8,21,10,19,10,17,9,15,7,14,5,14,3,16,3,18,4,20,6,21,8,21,10,20,13,19,16,19,19,20,21,21,-1,-1,17,7,15,6,14,4,14,2,16,0,18,0,20,1,21,3,21,5,19,7,17,7,},
/* & Ascii 38 */ {34, 26, 23,12,23,13,22,14,21,14,20,13,19,11,17,6,15,3,13,1,11,0,7,0,5,1,4,2,3,4,3,6,4,8,5,9,12,13,13,14,14,16,14,18,13,20,11,21,9,20,8,18,8,16,9,13,11,10,16,3,18,1,20,0,22,0,23,1,23,2,},
/* ' Ascii 39 */ { 7, 10, 5,19,4,20,5,21,6,20,6,18,5,16,4,15,},
/* ( Ascii 40 */ {10, 14, 11,25,9,23,7,20,5,16,4,11,4,7,5,2,7,-2,9,-5,11,-7,},
/* ) Ascii 41 */ {10, 14, 3,25,5,23,7,20,9,16,10,11,10,7,9,2,7,-2,5,-5,3,-7,},
/* * Ascii 42 */ { 8, 16, 8,21,8,9,-1,-1,3,18,13,12,-1,-1,13,18,3,12,},
/* + Ascii 43 */ { 5, 26, 13,18,13,0,-1,-1,4,9,22,9,},
/* , Ascii 44 */ { 8, 10, 6,1,5,0,4,1,5,2,6,1,6,-1,5,-3,4,-4,},
/* - Ascii 45 */ { 2, 26, 4,9,22,9,},
/* . Ascii 46 */ { 5, 10, 5,2,4,1,5,0,6,1,5,2,},
/* / Ascii 47 */ { 2, 22, 20,25,2,-7,},
/* 0 Ascii 48 */ {17, 20, 9,21,6,20,4,17,3,12,3,9,4,4,6,1,9,0,11,0,14,1,16,4,17,9,17,12,16,17,14,20,11,21,9,21,},
/* 1 Ascii 49 */ { 4, 20, 8,19,10,20,11,21,11,0,},
/* 2 Ascii 50 */ {14, 20, 4,16,4,17,5,19,6,20,8,21,12,21,14,20,15,19,16,17,16,15,15,13,13,10,3,0,17,0,},
/* 3 Ascii 51 */ {15, 20, 5,21,16,21,10,13,13,13,15,12,16,11,17,8,17,6,16,3,14,1,11,0,8,0,5,1,4,2,3,4,},
/* 4 Ascii 52 */ { 6, 20, 13,21,3,7,18,7,-1,-1,13,21,13,0,},
/* 5 Ascii 53 */ {17, 20, 15,21,5,21,4,12,5,13,8,14,11,14,14,13,16,11,17,8,17,6,16,3,14,1,11,0,8,0,5,1,4,2,3,4,},
/* 6 Ascii 54 */ {23, 20, 16,18,15,20,12,21,10,21,7,20,5,17,4,12,4,7,5,3,7,1,10,0,11,0,14,1,16,3,17,6,17,7,16,10,14,12,11,13,10,13,7,12,5,10,4,7,},
/* 7 Ascii 55 */ { 5, 20, 17,21,7,0,-1,-1,3,21,17,21,},
/* 8 Ascii 56 */ {29, 20, 8,21,5,20,4,18,4,16,5,14,7,13,11,12,14,11,16,9,17,7,17,4,16,2,15,1,12,0,8,0,5,1,4,2,3,4,3,7,4,9,6,11,9,12,13,13,15,14,16,16,16,18,15,20,12,21,8,21,},
/* 9 Ascii 57 */ {23, 20, 16,14,15,11,13,9,10,8,9,8,6,9,4,11,3,14,3,15,4,18,6,20,9,21,10,21,13,20,15,18,16,14,16,9,15,4,13,1,10,0,8,0,5,1,4,3,},
/* : Ascii 58 */ {11, 10, 5,14,4,13,5,12,6,13,5,14,-1,-1,5,2,4,1,5,0,6,1,5,2,},
/* ; Ascii 59 */ {14, 10, 5,14,4,13,5,12,6,13,5,14,-1,-1,6,1,5,0,4,1,5,2,6,1,6,-1,5,-3,4,-4,},
/* < Ascii 60 */ { 3, 24, 20,18,4,9,20,0,},
/* = Ascii 61 */ { 5, 26, 4,12,22,12,-1,-1,4,6,22,6,},
/* > Ascii 62 */ { 3, 24, 4,18,20,9,4,0,},
/* ? Ascii 63 */ {20, 18, 3,16,3,17,4,19,5,20,7,21,11,21,13,20,14,19,15,17,15,15,14,13,13,12,9,10,9,7,-1,-1,9,2,8,1,9,0,10,1,9,2,},
/* @ Ascii 64 */ {55, 27, 18,13,17,15,15,16,12,16,10,15,9,14,8,11,8,8,9,6,11,5,14,5,16,6,17,8,-1,-1,12,16,10,14,9,11,9,8,10,6,11,5,-1,-1,18,16,17,8,17,6,19,5,21,5,23,7,24,10,24,12,23,15,22,17,20,19,18,20,15,21,12,21,9,20,7,19,5,17,4,15,3,12,3,9,4,6,5,4,7,2,9,1,12,0,15,0,18,1,20,2,21,3,-1,-1,19,16,18,8,18,6,19,5,},
/* A Ascii 65 */ { 8, 18, 9,21,1,0,-1,-1,9,21,17,0,-1,-1,4,7,14,7,},
/* B Ascii 66 */ {23, 21, 4,21,4,0,-1,-1,4,21,13,21,16,20,17,19,18,17,18,15,17,13,16,12,13,11,-1,-1,4,11,13,11,16,10,17,9,18,7,18,4,17,2,16,1,13,0,4,0,},
/* C Ascii 67 */ {18, 21, 18,16,17,18,15,20,13,21,9,21,7,20,5,18,4,16,3,13,3,8,4,5,5,3,7,1,9,0,13,0,15,1,17,3,18,5,},
/* D Ascii 68 */ {15, 21, 4,21,4,0,-1,-1,4,21,11,21,14,20,16,18,17,16,18,13,18,8,17,5,16,3,14,1,11,0,4,0,},
/* E Ascii 69 */ {11, 19, 4,21,4,0,-1,-1,4,21,17,21,-1,-1,4,11,12,11,-1,-1,4,0,17,0,},
/* F Ascii 70 */ { 8, 18, 4,21,4,0,-1,-1,4,21,17,21,-1,-1,4,11,12,11,},
/* G Ascii 71 */ {22, 21, 18,16,17,18,15,20,13,21,9,21,7,20,5,18,4,16,3,13,3,8,4,5,5,3,7,1,9,0,13,0,15,1,17,3,18,5,18,8,-1,-1,13,8,18,8,},
/* H Ascii 72 */ { 8, 22, 4,21,4,0, -1,-1 ,4,11,18,11, -1,-1, 18,21,18,0, },
/* I Ascii 73 */ { 2, 8, 4,21,4,0,},
/* J Ascii 74 */ {10, 16, 12,21,12,5,11,2,10,1,8,0,6,0,4,1,3,2,2,5,2,7,},
/* K Ascii 75 */ { 8, 21, 4,21,4,0,-1,-1,18,21,4,7,-1,-1,9,12,18,0,},
/* L Ascii 76 */ { 5, 17, 4,21,4,0,-1,-1,4,0,16,0,},
/* M Ascii 77 */ { 8, 24, 4,0,4,21, 4,21,12,0, 12,0,20,21, 20,21,20,0,},
/* N Ascii 78 */ { 6, 22, 4,0,4,21, 4,21,18,0, 18,0,18,21,},
/* O Ascii 79 */ {21, 22, 9,21,7,20,5,18,4,16,3,13,3,8,4,5,5,3,7,1,9,0,13,0,15,1,17,3,18,5,19,8,19,13,18,16,17,18,15,20,13,21,9,21,},
/* P Ascii 80 */ {13, 21, 4,21,4,0,-1,-1,4,21,13,21,16,20,17,19,18,17,18,14,17,12,16,11,13,10,4,10,},
/* Q Ascii 81 */ {24, 22, 9,21,7,20,5,18,4,16,3,13,3,8,4,5,5,3,7,1,9,0,13,0,15,1,17,3,18,5,19,8,19,13,18,16,17,18,15,20,13,21,9,21,-1,-1,12,4,18,-2,},
/* R Ascii 82 */ {16, 21, 4,21,4,0,-1,-1,4,21,13,21,16,20,17,19,18,17,18,15,17,13,16,12,13,11,4,11,-1,-1,11,11,18,0,},
/* S Ascii 83 */ {20, 20, 17,18,15,20,12,21,8,21,5,20,3,18,3,16,4,14,5,13,7,12,13,10,15,9,16,8,17,6,17,3,15,1,12,0,8,0,5,1,3,3,},
/* T Ascii 84 */ { 5, 16, 8,21,8,0,-1,-1,1,21,15,21,},
/* U Ascii 85 */ {10, 22, 4,21,4,6,5,3,7,1,10,0,12,0,15,1,17,3,18,6,18,21,},
/* V Ascii 86 */ { 5, 18, 1,21,9,0,-1,-1,17,21,9,0,},
/* W Ascii 87 */ {11, 24, 2,21,7,0,-1,-1,12,21,7,0,-1,-1,12,21,17,0,-1,-1,22,21,17,0,},
/* X Ascii 88 */ { 5, 20, 3,21,17,0,-1,-1,17,21,3,0,},
/* Y Ascii 89 */ { 6, 18, 1,21,9,11,17,21, -1,-1, 9,11,9,0},
/* Z Ascii 90 */ { 6, 20, 3,21,17,21, 17,21,3,0, 3,0,17,0,},
/* [ Ascii 91 */ { 4, 14, 11,25,4,25,4,-7,11,-7,},
/* \ Ascii 92 */ { 2, 14, 0,21,14,-3,},
/* ] Ascii 93 */ { 4, 14, 3,25,10,25,10,-7,3,-7},
/* ^ Ascii 94 */ {10, 16, 6,15,8,18,10,15,-1,-1,3,12,8,17,13,12,-1,-1,8,17,8,0,},
/* _ Ascii 95 */ { 2, 16, 0,-2,16,-2,},
/* ` Ascii 96 */ { 7, 10, 6,21,5,20,4,18,4,16,5,15,6,16,5,17,},
/* a Ascii 97 */ {17, 19, 15,11,13,13,11,14,8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3, -1,-1,15,14,15,0,},
/* b Ascii 98 */ {17, 19, 4,21,4,0,-1,-1,4,11,6,13,8,14,11,14,13,13,15,11,16,8,16,6,15,3,13,1,11,0,8,0,6,1,4,3,},
/* c Ascii 99 */ {14, 18, 15,11,13,13,11,14,8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3,},
/* d Ascii 100 */ {17, 19, 15,21,15,0,-1,-1,15,11,13,13,11,14,8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3,},
/* e Ascii 101 */ {17, 18, 3,8,15,8,15,10,14,12,13,13,11,14,8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3,},
/* f Ascii 102 */ { 8, 12, 10,21,8,21,6,20,5,17,5,0,-1,-1,2,14,9,14,},
/* g Ascii 103 */ {22, 19, 15,11,13,13,11,14,8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3, -1,-1,15,14,15,-2,14,-5,13,-6,11,-7,8,-7,6,-6,},
/* h Ascii 104 */ {10, 19, 4,21,4,0,-1,-1,4,10,7,13,9,14,12,14,14,13,15,10,15,0,},
/* i Ascii 105 */ { 8, 8, 3,21,4,20,5,21,4,22,3,21,-1,-1,4,14,4,0,},
/* j Ascii 106 */ {11, 10, 5,21,6,20,7,21,6,22,5,21,-1,-1,6,14,6,-3,5,-6,3,-7,1,-7,},
/* k Ascii 107 */ { 8, 17, 4,21,4,0,-1,-1,14,14,4,4,-1,-1,8,8,15,0,},
/* l Ascii 108 */ { 2, 8, 4,21,4,0,},
/* m Ascii 109 */ {18, 30, 4,14,4,0,-1,-1,4,10,7,13,9,14,12,14,14,13,15,10,15,0,-1,-1,15,10,18,13,20,14,23,14,25,13,26,10,26,0,},
/* n Ascii 110 */ {10, 19, 4,14,4,0,-1,-1,4,10,7,13,9,14,12,14,14,13,15,10,15,0,},
/* o Ascii 111 */ {17, 19, 8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3,16,6,16,8,15,11,13,13,11,14,8,14,},
/* p Ascii 112 */ {17, 19, 4,14,4,-7,-1,-1,4,11,6,13,8,14,11,14,13,13,15,11,16,8,16,6,15,3,13,1,11,0,8,0,6,1,4,3,},
/* q Ascii 113 */ {17, 19, 15,11,13,13,11,14,8,14,6,13,4,11,3,8,3,6,4,3,6,1,8,0,11,0,13,1,15,3, -1,-1,15,14,15,-7,},
/* r Ascii 114 */ { 8, 13, 4,14,4,0,-1,-1,4,8,5,11,7,13,9,14,12,14,},
/* s Ascii 115 */ {17, 17, 14,11,13,13,10,14,7,14,4,13,3,11,4,9,6,8,11,7,13,6,14,4,14,3,13,1,10,0,7,0,4,1,3,3,},
/* t Ascii 116 */ { 8, 12, 5,21,5,4,6,1,8,0,10,0,-1,-1,2,14,9,14,},
/* u Ascii 117 */ {10, 19, 4,14,4,4,5,1,7,0,10,0,12,1,15,4,-1,-1,15,14,15,0,},
/* v Ascii 118 */ { 5, 16, 2,14,8,0,-1,-1,14,14,8,0,},
/* w Ascii 119 */ { 5, 22, 3,14,7,0,11,14,15,0,19,14,},
/* x Ascii 120 */ { 5, 17, 3,14,14,0,-1,-1,14,14,3,0,},
/* y Ascii 121 */ { 9, 16, 2,14,8,0,-1,-1,14,14,8,0,6,-4,4,-6,2,-7,1,-7,},
/* z Ascii 122 */ { 6, 17, 3,14,14,14, 14,14,3,0, 3,0,14,0,},
/* { Ascii 123 */ {39, 14, 9,25,7,24,6,23,5,21,5,19,6,17,7,16,8,14,8,12,6,10,-1,-1,7,24,6,22,6,20,7,18,8,17,9,15,9,13,8,11,4,9,8,7,9,5,9,3,8,1,7,0,6,-2,6,-4,7,-6,-1,-1,6,8,8,6,8,4,7,2,6,1,5,-1,5,-3,6,-5,7,-6,9,-7,},
/* | Ascii 124 */ { 2, 8, 4,25,4,-7,},
/* } Ascii 125 */ {39, 14, 5,25,7,24,8,23,9,21,9,19,8,17,7,16,6,14,6,12,8,10,-1,-1,7,24,8,22,8,20,7,18,6,17,5,15,5,13,6,11,10,9,6,7,5,5,5,3,6,1,7,0,8,-2,8,-4,7,-6,-1,-1,8,8,6,6,6,4,7,2,8,1,9,-1,9,-3,8,-5,7,-6,5,-7,},
/* ~ Ascii 126 */ {23, 24, 3,6,3,8,4,11,6,12,8,12,10,11,14,8,16,7,18,7,20,8,21,10,-1,-1,3,8,4,10,6,11,8,11,10,10,14,7,16,6,18,6,20,7,21,10,21,12,},
};
const int8_t* get_font_char(const char* font_name, char ascii_value, int& out_num_verts, int& out_horiz_dist)
{
if (1 || !strcmp(font_name, "hershey"))
{
if (ascii_value >= 32 || ascii_value <= 126)
{
const int8_t* char_data = hershey_font_simplex_compact[ascii_value - 32];
out_num_verts = char_data[0];
out_horiz_dist = char_data[1];
return char_data + 2;
}
}
return NULL;
}
char keycode_to_ascii(int keycode, int mods)
{
if (mods & (MOD_CTRL|MOD_ALT))
{
// Do whatever we want here. Maybe launch VNC?
return 0;
}
switch (keycode)
{
case KEY_SEMICOLON: return (mods & MOD_SHIFT) ? ':' : ';'; break;
case KEY_LEFTBRACE: return (mods & MOD_SHIFT) ? '{' : '['; break;
case KEY_RIGHTBRACE: return (mods & MOD_SHIFT) ? '}' : ']'; break;
case KEY_MINUS: return (mods & MOD_SHIFT) ? '_' : '-'; break;
case KEY_EQUAL: return (mods & MOD_SHIFT) ? '+' : '='; break;
case KEY_APOSTROPHE: return (mods & MOD_SHIFT) ? '\"' : '\''; break;
case KEY_GRAVE: return (mods & MOD_SHIFT) ? '~' : '`'; break;
case KEY_BACKSLASH: return (mods & MOD_SHIFT) ? '|' : '\\'; break;
case KEY_COMMA: return (mods & MOD_SHIFT) ? '<' : ','; break;
case KEY_DOT: return (mods & MOD_SHIFT) ? '>' : '.'; break;
case KEY_SLASH: return (mods & MOD_SHIFT) ? '?' : '/'; break;
case KEY_SPACE: return ' '; break;
case KEY_0: return (mods & MOD_SHIFT) ? ')' : '0'; break;
case KEY_1: return (mods & MOD_SHIFT) ? '!' : '1'; break;
case KEY_2: return (mods & MOD_SHIFT) ? '@' : '2'; break;
case KEY_3: return (mods & MOD_SHIFT) ? '#' : '3'; break;
case KEY_4: return (mods & MOD_SHIFT) ? '$' : '4'; break;
case KEY_5: return (mods & MOD_SHIFT) ? '%' : '5'; break;
case KEY_6: return (mods & MOD_SHIFT) ? '^' : '6'; break;
case KEY_7: return (mods & MOD_SHIFT) ? '&' : '7'; break;
case KEY_8: return (mods & MOD_SHIFT) ? '*' : '8'; break;
case KEY_9: return (mods & MOD_SHIFT) ? '(' : '9'; break;
case KEY_A: return (mods & MOD_CAPS) ? 'A' : 'a'; break;
case KEY_B: return (mods & MOD_CAPS) ? 'B' : 'b'; break;
case KEY_C: return (mods & MOD_CAPS) ? 'C' : 'c'; break;
case KEY_D: return (mods & MOD_CAPS) ? 'D' : 'd'; break;
case KEY_E: return (mods & MOD_CAPS) ? 'E' : 'e'; break;
case KEY_F: return (mods & MOD_CAPS) ? 'F' : 'f'; break;
case KEY_G: return (mods & MOD_CAPS) ? 'G' : 'g'; break;
case KEY_H: return (mods & MOD_CAPS) ? 'H' : 'h'; break;
case KEY_I: return (mods & MOD_CAPS) ? 'I' : 'i'; break;
case KEY_J: return (mods & MOD_CAPS) ? 'J' : 'j'; break;
case KEY_K: return (mods & MOD_CAPS) ? 'K' : 'k'; break;
case KEY_L: return (mods & MOD_CAPS) ? 'L' : 'l'; break;
case KEY_M: return (mods & MOD_CAPS) ? 'M' : 'm'; break;
case KEY_N: return (mods & MOD_CAPS) ? 'N' : 'n'; break;
case KEY_O: return (mods & MOD_CAPS) ? 'O' : 'o'; break;
case KEY_P: return (mods & MOD_CAPS) ? 'P' : 'p'; break;
case KEY_Q: return (mods & MOD_CAPS) ? 'Q' : 'q'; break;
case KEY_R: return (mods & MOD_CAPS) ? 'R' : 'r'; break;
case KEY_S: return (mods & MOD_CAPS) ? 'S' : 's'; break;
case KEY_T: return (mods & MOD_CAPS) ? 'T' : 't'; break;
case KEY_U: return (mods & MOD_CAPS) ? 'U' : 'u'; break;
case KEY_V: return (mods & MOD_CAPS) ? 'V' : 'v'; break;
case KEY_W: return (mods & MOD_CAPS) ? 'W' : 'w'; break;
case KEY_X: return (mods & MOD_CAPS) ? 'X' : 'x'; break;
case KEY_Y: return (mods & MOD_CAPS) ? 'Y' : 'y'; break;
case KEY_Z: return (mods & MOD_CAPS) ? 'Z' : 'z'; break;
default: return 0; break;
}
}