GNU Unifont 17.0.01
Pan-Unicode font with complete Unicode Plane 0 coverage and partial coverage of higher planes
unihexgen.c File Reference

unihexgen - Generate a series of glyphs containing hexadecimal code points More...

#include <stdio.h>
#include <stdlib.h>
Include dependency graph for unihexgen.c:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 The main function.
 
void hexprint4 (int thiscp)
 Generate a bitmap containing a 4-digit Unicode code point.
 
void hexprint6 (int thiscp)
 Generate a bitmap containing a 6-digit Unicode code point.
 

Variables

char hexdigit [16][5]
 Bitmap pattern for each hexadecimal digit.
 

Detailed Description

unihexgen - Generate a series of glyphs containing hexadecimal code points

Author
Paul Hardy

This program generates glyphs in Unifont .hex format that contain four- or six-digit hexadecimal numbers in a 16x16 pixel area. These are rendered as white digits on a black background.

argv[1] is the starting code point (as a hexadecimal string, with no leading "0x".

argv[2] is the ending code point (as a hexadecimal string, with no leading "0x".

For example:

   unihexgen e000 f8ff > pua.hex

This generates the Private Use Area glyph file.

This utility program works in Roman Czyborra's unifont.hex file format, the basis of the GNU Unifont package.

Definition in file unihexgen.c.

Function Documentation

◆ hexprint4()

void hexprint4 ( int  thiscp)

Generate a bitmap containing a 4-digit Unicode code point.

Takes a 4-digit Unicode code point as an argument and prints a unifont.hex string for it to stdout.

Parameters
[in]thiscpThe current code point for which to generate a glyph.

Definition at line 164 of file unihexgen.c.

165{
166
167 int grid[16]; /* the glyph grid we'll build */
168
169 int row; /* row number in current glyph */
170 int digitrow; /* row number in current hex digit being rendered */
171 int rowbits; /* 1 & 0 bits to draw current glyph row */
172
173 int d1, d2, d3, d4; /* four hexadecimal digits of each code point */
174
175 d1 = (thiscp >> 12) & 0xF;
176 d2 = (thiscp >> 8) & 0xF;
177 d3 = (thiscp >> 4) & 0xF;
178 d4 = (thiscp ) & 0xF;
179
180 /* top and bottom rows are white */
181 grid[0] = grid[15] = 0x0000;
182
183 /* 14 inner rows are 14-pixel wide black lines, centered */
184 for (row = 1; row < 15; row++) grid[row] = 0x7FFE;
185
186 printf ("%04X:", thiscp);
187
188 /*
189 Render the first row of 2 hexadecimal digits
190 */
191 digitrow = 0; /* start at top of first row of digits to render */
192 for (row = 2; row < 7; row++) {
193 rowbits = (hexdigit[d1][digitrow] << 9) |
194 (hexdigit[d2][digitrow] << 3);
195 grid[row] ^= rowbits; /* digits appear as white on black background */
196 digitrow++;
197 }
198
199 /*
200 Render the second row of 2 hexadecimal digits
201 */
202 digitrow = 0; /* start at top of first row of digits to render */
203 for (row = 9; row < 14; row++) {
204 rowbits = (hexdigit[d3][digitrow] << 9) |
205 (hexdigit[d4][digitrow] << 3);
206 grid[row] ^= rowbits; /* digits appear as white on black background */
207 digitrow++;
208 }
209
210 for (row = 0; row < 16; row++) printf ("%04X", grid[row] & 0xFFFF);
211
212 putchar ('\n');
213
214 return;
215}
char hexdigit[16][5]
Bitmap pattern for each hexadecimal digit.
Definition: unihexgen.c:88
Here is the caller graph for this function:

◆ hexprint6()

void hexprint6 ( int  thiscp)

Generate a bitmap containing a 6-digit Unicode code point.

Takes a 6-digit Unicode code point as an argument and prints a unifont.hex string for it to stdout.

Parameters
[in]thiscpThe current code point for which to generate a glyph.

Definition at line 227 of file unihexgen.c.

228{
229
230 int grid[16]; /* the glyph grid we'll build */
231
232 int row; /* row number in current glyph */
233 int digitrow; /* row number in current hex digit being rendered */
234 int rowbits; /* 1 & 0 bits to draw current glyph row */
235
236 int d1, d2, d3, d4, d5, d6; /* six hexadecimal digits of each code point */
237
238 d1 = (thiscp >> 20) & 0xF;
239 d2 = (thiscp >> 16) & 0xF;
240 d3 = (thiscp >> 12) & 0xF;
241 d4 = (thiscp >> 8) & 0xF;
242 d5 = (thiscp >> 4) & 0xF;
243 d6 = (thiscp ) & 0xF;
244
245 /* top and bottom rows are white */
246 grid[0] = grid[15] = 0x0000;
247
248 /* 14 inner rows are 16-pixel wide black lines, centered */
249 for (row = 1; row < 15; row++) grid[row] = 0xFFFF;
250
251
252 printf ("%06X:", thiscp);
253
254 /*
255 Render the first row of 3 hexadecimal digits
256 */
257 digitrow = 0; /* start at top of first row of digits to render */
258 for (row = 2; row < 7; row++) {
259 rowbits = (hexdigit[d1][digitrow] << 11) |
260 (hexdigit[d2][digitrow] << 6) |
261 (hexdigit[d3][digitrow] << 1);
262 grid[row] ^= rowbits; /* digits appear as white on black background */
263 digitrow++;
264 }
265
266 /*
267 Render the second row of 3 hexadecimal digits
268 */
269 digitrow = 0; /* start at top of first row of digits to render */
270 for (row = 9; row < 14; row++) {
271 rowbits = (hexdigit[d4][digitrow] << 11) |
272 (hexdigit[d5][digitrow] << 6) |
273 (hexdigit[d6][digitrow] << 1);
274 grid[row] ^= rowbits; /* digits appear as white on black background */
275 digitrow++;
276 }
277
278 for (row = 0; row < 16; row++) printf ("%04X", grid[row] & 0xFFFF);
279
280 putchar ('\n');
281
282 return;
283}
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

The main function.

Parameters
[in]argcThe count of command line arguments.
[in]argvPointer to array of command line arguments (code point range).
Returns
This program exits with status EXIT_SUCCESS.

Definition at line 116 of file unihexgen.c.

117{
118
119 unsigned startcp, endcp, thiscp;
120 void hexprint4(int); /* function to print one 4-digit unifont.hex code point */
121 void hexprint6(int); /* function to print one 6-digit unifont.hex code point */
122
123 if (argc != 3) {
124 fprintf (stderr,"\n%s - generate unifont.hex code points as\n", argv[0]);
125 fprintf (stderr,"four-digit hexadecimal numbers in a 2 by 2 grid,\n");
126 fprintf (stderr,"or six-digit hexadecimal numbers in a 3 by 2 grid.\n");
127 fprintf (stderr,"Syntax:\n\n");
128 fprintf (stderr," %s first_code_point last_code_point > glyphs.hex\n\n", argv[0]);
129 fprintf (stderr,"Example (to generate glyphs for the Private Use Area):\n\n");
130 fprintf (stderr," %s e000 f8ff > pua.hex\n\n", argv[0]);
131 exit (EXIT_FAILURE);
132 }
133
134 sscanf (argv[1], "%x", &startcp);
135 sscanf (argv[2], "%x", &endcp);
136
137 startcp &= 0xFFFFFF; /* limit to 6 hex digits */
138 endcp &= 0xFFFFFF; /* limit to 6 hex digits */
139
140 /*
141 For each code point in the desired range, generate a glyph.
142 */
143 for (thiscp = startcp; thiscp <= endcp; thiscp++) {
144 if (thiscp <= 0xFFFF) {
145 hexprint4 (thiscp); /* print digits 2/line, 2 lines */
146 }
147 else {
148 hexprint6 (thiscp); /* print digits 3/line, 2 lines */
149 }
150 }
151 exit (EXIT_SUCCESS);
152}
void hexprint4(int thiscp)
Generate a bitmap containing a 4-digit Unicode code point.
Definition: unihexgen.c:164
void hexprint6(int thiscp)
Generate a bitmap containing a 6-digit Unicode code point.
Definition: unihexgen.c:227
Here is the call graph for this function:

Variable Documentation

◆ hexdigit

char hexdigit[16][5]
Initial value:
= {
{0x6,0x9,0x9,0x9,0x6},
{0x2,0x6,0x2,0x2,0x7},
{0xF,0x1,0xF,0x8,0xF},
{0xE,0x1,0x7,0x1,0xE},
{0x9,0x9,0xF,0x1,0x1},
{0xF,0x8,0xF,0x1,0xF},
{0x6,0x8,0xE,0x9,0x6},
{0xF,0x1,0x2,0x4,0x4},
{0x6,0x9,0x6,0x9,0x6},
{0x6,0x9,0x7,0x1,0x6},
{0xF,0x9,0xF,0x9,0x9},
{0xE,0x9,0xE,0x9,0xE},
{0x7,0x8,0x8,0x8,0x7},
{0xE,0x9,0x9,0x9,0xE},
{0xF,0x8,0xE,0x8,0xF},
{0xF,0x8,0xE,0x8,0x8}
}

Bitmap pattern for each hexadecimal digit.

hexdigit[][] definition: the bitmap pattern for each hexadecimal digit.

Each digit is drawn as a 4 wide by 5 high bitmap, so each digit row is one hexadecimal digit, and each entry has 5 rows.

For example, the entry for digit 1 is:

{0x2,0x6,0x2,0x2,0x7},

which corresponds graphically to:

–#- ==> 0010 ==> 0x2 -##- ==> 0110 ==> 0x6 –#- ==> 0010 ==> 0x2 –#- ==> 0010 ==> 0x2 -### ==> 0111 ==> 0x7

These row values will then be exclusive-ORed with four one bits (binary 1111, or 0xF) to form white digits on a black background.

Functions hexprint4 and hexprint6 share the hexdigit array; they print four-digit and six-digit hexadecimal code points in a single glyph, respectively.

Definition at line 88 of file unihexgen.c.