GNU Unifont 16.0.02 Pan-Unicode font with complete Unicode Plane 0 coverage and partial coverage of higher planes

unihexgen.c
Go to the documentation of this file.
1/**
2 @file unihexgen.c
3
4 @brief unihexgen - Generate a series of glyphs containing
5 hexadecimal code points
6
7 @author Paul Hardy
8
9 @copyright Copyright (C) 2013 Paul Hardy
10
11 This program generates glyphs in Unifont .hex format that contain
12 four- or six-digit hexadecimal numbers in a 16x16 pixel area. These
13 are rendered as white digits on a black background.
14
15 argv[1] is the starting code point (as a hexadecimal
16 string, with no leading "0x".
17
18 argv[2] is the ending code point (as a hexadecimal
19 string, with no leading "0x".
20
21 For example:
22
23 unihexgen e000 f8ff > pua.hex
24
25 This generates the Private Use Area glyph file.
26
27 This utility program works in Roman Czyborra's unifont.hex file
28 format, the basis of the GNU Unifont package.
29*/
30/*
31 This program is released under the terms of the GNU General Public
32 License version 2, or (at your option) a later version.
33
34 LICENSE:
35
36 This program is free software: you can redistribute it and/or modify
37 it under the terms of the GNU General Public License as published by
38 the Free Software Foundation, either version 2 of the License, or
39 (at your option) any later version.
40
41 This program is distributed in the hope that it will be useful,
42 but WITHOUT ANY WARRANTY; without even the implied warranty of
43 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 GNU General Public License for more details.
45
46 You should have received a copy of the GNU General Public License
47 along with this program. If not, see <http://www.gnu.org/licenses/>.
48*/
49
50#include <stdio.h>
51#include <stdlib.h>
52
53
54/**
55 @brief Bitmap pattern for each hexadecimal digit.
56
57 hexdigit[][] definition: the bitmap pattern for
58 each hexadecimal digit.
59
60 Each digit is drawn as a 4 wide by 5 high bitmap,
61 so each digit row is one hexadecimal digit, and
62 each entry has 5 rows.
63
64 For example, the entry for digit 1 is:
65
66 {0x2,0x6,0x2,0x2,0x7},
67
68 which corresponds graphically to:
69
70 --#- ==> 0010 ==> 0x2
71 -##- ==> 0110 ==> 0x6
72 --#- ==> 0010 ==> 0x2
73 --#- ==> 0010 ==> 0x2
74 -### ==> 0111 ==> 0x7
75
76 These row values will then be exclusive-ORed with four one bits
77 (binary 1111, or 0xF) to form white digits on a black background.
78
79
80 Functions hexprint4 and hexprint6 share the hexdigit array;
81 they print four-digit and six-digit hexadecimal code points
82 in a single glyph, respectively.
83*/
84 char hexdigit[16][5] = {
85 {0x6,0x9,0x9,0x9,0x6}, /* 0x0 */
86 {0x2,0x6,0x2,0x2,0x7}, /* 0x1 */
87 {0xF,0x1,0xF,0x8,0xF}, /* 0x2 */
88 {0xE,0x1,0x7,0x1,0xE}, /* 0x3 */
89 {0x9,0x9,0xF,0x1,0x1}, /* 0x4 */
90 {0xF,0x8,0xF,0x1,0xF}, /* 0x5 */
91 {0x6,0x8,0xE,0x9,0x6}, /* 0x6 */ // {0x8,0x8,0xF,0x9,0xF} [alternate square form of 6]
92 {0xF,0x1,0x2,0x4,0x4}, /* 0x7 */
93 {0x6,0x9,0x6,0x9,0x6}, /* 0x8 */
94 {0x6,0x9,0x7,0x1,0x6}, /* 0x9 */ // {0xF,0x9,0xF,0x1,0x1} [alternate square form of 9]
95 {0xF,0x9,0xF,0x9,0x9}, /* 0xA */
96 {0xE,0x9,0xE,0x9,0xE}, /* 0xB */
97 {0x7,0x8,0x8,0x8,0x7}, /* 0xC */
98 {0xE,0x9,0x9,0x9,0xE}, /* 0xD */
99 {0xF,0x8,0xE,0x8,0xF}, /* 0xE */
100 {0xF,0x8,0xE,0x8,0x8} /* 0xF */
101};
102
103
104/**
105 @brief The main function.
106
107 @param[in] argc The count of command line arguments.
108 @param[in] argv Pointer to array of command line arguments (code point range).
109 @return This program exits with status EXIT_SUCCESS.
110*/
111 int
112 main (int argc, char *argv[])
113{
114
115 int startcp, endcp, thiscp;
116 void hexprint4(int); /* function to print one 4-digit unifont.hex code point */
117 void hexprint6(int); /* function to print one 6-digit unifont.hex code point */
118
119 if (argc != 3) {
120 fprintf (stderr,"\n%s - generate unifont.hex code points as\n", argv[0]);
121 fprintf (stderr,"four-digit hexadecimal numbers in a 2 by 2 grid,\n");
122 fprintf (stderr,"or six-digit hexadecimal numbers in a 3 by 2 grid.\n");
123 fprintf (stderr,"Syntax:\n\n");
124 fprintf (stderr," %s first_code_point last_code_point > glyphs.hex\n\n", argv[0]);
125 fprintf (stderr,"Example (to generate glyphs for the Private Use Area):\n\n");
126 fprintf (stderr," %s e000 f8ff > pua.hex\n\n", argv[0]);
127 exit (EXIT_FAILURE);
128 }
129
130 sscanf (argv[1], "%x", &startcp);
131 sscanf (argv[2], "%x", &endcp);
132
133 startcp &= 0xFFFFFF; /* limit to 6 hex digits */
134 endcp &= 0xFFFFFF; /* limit to 6 hex digits */
135
136 /*
137 For each code point in the desired range, generate a glyph.
138 */
139 for (thiscp = startcp; thiscp <= endcp; thiscp++) {
140 if (thiscp <= 0xFFFF) {
141 hexprint4 (thiscp); /* print digits 2/line, 2 lines */
142 }
143 else {
144 hexprint6 (thiscp); /* print digits 3/line, 2 lines */
145 }
146 }
147 exit (EXIT_SUCCESS);
148}
149
150
151/**
152 @brief Generate a bitmap containing a 4-digit Unicode code point.
153
154 Takes a 4-digit Unicode code point as an argument
155 and prints a unifont.hex string for it to stdout.
156
157 @param[in] thiscp The current code point for which to generate a glyph.
158*/
159 void
160 hexprint4 (int thiscp)
161{
162
163 int grid[16]; /* the glyph grid we'll build */
164
165 int row; /* row number in current glyph */
166 int digitrow; /* row number in current hex digit being rendered */
167 int rowbits; /* 1 & 0 bits to draw current glyph row */
168
169 int d1, d2, d3, d4; /* four hexadecimal digits of each code point */
170
171 d1 = (thiscp >> 12) & 0xF;
172 d2 = (thiscp >> 8) & 0xF;
173 d3 = (thiscp >> 4) & 0xF;
174 d4 = (thiscp ) & 0xF;
175
176 /* top and bottom rows are white */
177 grid[0] = grid[15] = 0x0000;
178
179 /* 14 inner rows are 14-pixel wide black lines, centered */
180 for (row = 1; row < 15; row++) grid[row] = 0x7FFE;
181
182 printf ("%04X:", thiscp);
183
184 /*
185 Render the first row of 2 hexadecimal digits
186 */
187 digitrow = 0; /* start at top of first row of digits to render */
188 for (row = 2; row < 7; row++) {
189 rowbits = (hexdigit[d1][digitrow] << 9) |
190 (hexdigit[d2][digitrow] << 3);
191 grid[row] ^= rowbits; /* digits appear as white on black background */
192 digitrow++;
193 }
194
195 /*
196 Render the second row of 2 hexadecimal digits
197 */
198 digitrow = 0; /* start at top of first row of digits to render */
199 for (row = 9; row < 14; row++) {
200 rowbits = (hexdigit[d3][digitrow] << 9) |
201 (hexdigit[d4][digitrow] << 3);
202 grid[row] ^= rowbits; /* digits appear as white on black background */
203 digitrow++;
204 }
205
206 for (row = 0; row < 16; row++) printf ("%04X", grid[row] & 0xFFFF);
207
208 putchar ('\n');
209
210 return;
211}
212
213
214/**
215 @brief Generate a bitmap containing a 6-digit Unicode code point.
216
217 Takes a 6-digit Unicode code point as an argument
218 and prints a unifont.hex string for it to stdout.
219
220 @param[in] thiscp The current code point for which to generate a glyph.
221*/
222 void
223 hexprint6 (int thiscp)
224{
225
226 int grid[16]; /* the glyph grid we'll build */
227
228 int row; /* row number in current glyph */
229 int digitrow; /* row number in current hex digit being rendered */
230 int rowbits; /* 1 & 0 bits to draw current glyph row */
231
232 int d1, d2, d3, d4, d5, d6; /* six hexadecimal digits of each code point */
233
234 d1 = (thiscp >> 20) & 0xF;
235 d2 = (thiscp >> 16) & 0xF;
236 d3 = (thiscp >> 12) & 0xF;
237 d4 = (thiscp >> 8) & 0xF;
238 d5 = (thiscp >> 4) & 0xF;
239 d6 = (thiscp ) & 0xF;
240
241 /* top and bottom rows are white */
242 grid[0] = grid[15] = 0x0000;
243
244 /* 14 inner rows are 16-pixel wide black lines, centered */
245 for (row = 1; row < 15; row++) grid[row] = 0xFFFF;
246
247
248 printf ("%06X:", thiscp);
249
250 /*
251 Render the first row of 3 hexadecimal digits
252 */
253 digitrow = 0; /* start at top of first row of digits to render */
254 for (row = 2; row < 7; row++) {
255 rowbits = (hexdigit[d1][digitrow] << 11) |
256 (hexdigit[d2][digitrow] << 6) |
257 (hexdigit[d3][digitrow] << 1);
258 grid[row] ^= rowbits; /* digits appear as white on black background */
259 digitrow++;
260 }
261
262 /*
263 Render the second row of 3 hexadecimal digits
264 */
265 digitrow = 0; /* start at top of first row of digits to render */
266 for (row = 9; row < 14; row++) {
267 rowbits = (hexdigit[d4][digitrow] << 11) |
268 (hexdigit[d5][digitrow] << 6) |
269 (hexdigit[d6][digitrow] << 1);
270 grid[row] ^= rowbits; /* digits appear as white on black background */
271 digitrow++;
272 }
273
274 for (row = 0; row < 16; row++) printf ("%04X", grid[row] & 0xFFFF);
275
276 putchar ('\n');
277
278 return;
279}
280
main
int main(int argc, char *argv[])
The main function.
Definition: unihexgen.c:112
hexprint4
void hexprint4(int thiscp)
Generate a bitmap containing a 4-digit Unicode code point.
Definition: unihexgen.c:160
hexprint6
void hexprint6(int thiscp)
Generate a bitmap containing a 6-digit Unicode code point.
Definition: unihexgen.c:223
hexdigit
char hexdigit[16][5]
Bitmap pattern for each hexadecimal digit.
Definition: unihexgen.c:84