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

Functions | Variables
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. More...
void | hexprint4 (int thiscp)
| Generate a bitmap containing a 4-digit Unicode code point. More...
void | hexprint6 (int thiscp)
| Generate a bitmap containing a 6-digit Unicode code point. More...

## Variables
char | hexdigit [16][5]
| Bitmap pattern for each hexadecimal digit. More...

## Detailed Description

unihexgen - Generate a series of glyphs containing hexadecimal code points

Author
  Paul Hardy

Copyright
  Copyright (C) 2013 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] | thiscp | The current code point for which to generate a glyph.

Definition at line 160 of file unihexgen.c.

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}
hexdigit
char hexdigit[16][5]
Bitmap pattern for each hexadecimal digit.
Definition: unihexgen.c:84
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] | thiscp | The current code point for which to generate a glyph.

Definition at line 223 of file unihexgen.c.

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}
Here is the caller graph for this function:

## ◆ main()

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

The main function.

Parameters

  [in] | argc | The count of command line arguments.
  [in] | argv | Pointer to array of command line arguments (code point range).

Returns
  This program exits with status EXIT_SUCCESS.

Definition at line 112 of file unihexgen.c.

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}
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
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 84 of file unihexgen.c.