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.

{
int grid[16]; /* the glyph grid we'll build */
int row; /* row number in current glyph */
int digitrow; /* row number in current hex digit being rendered */
int rowbits; /* 1 & 0 bits to draw current glyph row */
int d1, d2, d3, d4; /* four hexadecimal digits of each code point */
d1 = (thiscp >> 12) & 0xF;
d2 = (thiscp >> 8) & 0xF;
d3 = (thiscp >> 4) & 0xF;
d4 = (thiscp ) & 0xF;
/* top and bottom rows are white */
grid[0] = grid[15] = 0x0000;
/* 14 inner rows are 14-pixel wide black lines, centered */
for (row = 1; row < 15; row++) grid[row] = 0x7FFE;
printf ("%04X:", thiscp);
/*
Render the first row of 2 hexadecimal digits
*/
digitrow = 0; /* start at top of first row of digits to render */
for (row = 2; row < 7; row++) {
rowbits = (hexdigit[d1][digitrow] << 9) |
(hexdigit[d2][digitrow] << 3);
grid[row] ^= rowbits; /* digits appear as white on black background */
digitrow++;
}
/*
Render the second row of 2 hexadecimal digits
*/
digitrow = 0; /* start at top of first row of digits to render */
for (row = 9; row < 14; row++) {
rowbits = (hexdigit[d3][digitrow] << 9) |
(hexdigit[d4][digitrow] << 3);
grid[row] ^= rowbits; /* digits appear as white on black background */
digitrow++;
}
for (row = 0; row < 16; row++) printf ("%04X", grid[row] & 0xFFFF);
putchar ('\n');
return;
}
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.

{
int grid[16]; /* the glyph grid we'll build */
int row; /* row number in current glyph */
int digitrow; /* row number in current hex digit being rendered */
int rowbits; /* 1 & 0 bits to draw current glyph row */
int d1, d2, d3, d4, d5, d6; /* six hexadecimal digits of each code point */
d1 = (thiscp >> 20) & 0xF;
d2 = (thiscp >> 16) & 0xF;
d3 = (thiscp >> 12) & 0xF;
d4 = (thiscp >> 8) & 0xF;
d5 = (thiscp >> 4) & 0xF;
d6 = (thiscp ) & 0xF;
/* top and bottom rows are white */
grid[0] = grid[15] = 0x0000;
/* 14 inner rows are 16-pixel wide black lines, centered */
for (row = 1; row < 15; row++) grid[row] = 0xFFFF;
printf ("%06X:", thiscp);
/*
Render the first row of 3 hexadecimal digits
*/
digitrow = 0; /* start at top of first row of digits to render */
for (row = 2; row < 7; row++) {
rowbits = (hexdigit[d1][digitrow] << 11) |
(hexdigit[d2][digitrow] << 6) |
(hexdigit[d3][digitrow] << 1);
grid[row] ^= rowbits; /* digits appear as white on black background */
digitrow++;
}
/*
Render the second row of 3 hexadecimal digits
*/
digitrow = 0; /* start at top of first row of digits to render */
for (row = 9; row < 14; row++) {
rowbits = (hexdigit[d4][digitrow] << 11) |
(hexdigit[d5][digitrow] << 6) |
(hexdigit[d6][digitrow] << 1);
grid[row] ^= rowbits; /* digits appear as white on black background */
digitrow++;
}
for (row = 0; row < 16; row++) printf ("%04X", grid[row] & 0xFFFF);
putchar ('\n');
return;
}
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.

{
int startcp, endcp, thiscp;
void hexprint4(int); /* function to print one 4-digit unifont.hex code point */
void hexprint6(int); /* function to print one 6-digit unifont.hex code point */
if (argc != 3) {
fprintf (stderr,"\n%s - generate unifont.hex code points as\n", argv[0]);
fprintf (stderr,"four-digit hexadecimal numbers in a 2 by 2 grid,\n");
fprintf (stderr,"or six-digit hexadecimal numbers in a 3 by 2 grid.\n");
fprintf (stderr,"Syntax:\n\n");
fprintf (stderr," %s first_code_point last_code_point > glyphs.hex\n\n", argv[0]);
fprintf (stderr,"Example (to generate glyphs for the Private Use Area):\n\n");
fprintf (stderr," %s e000 f8ff > pua.hex\n\n", argv[0]);
exit (EXIT_FAILURE);
}
sscanf (argv[1], "%x", &startcp);
sscanf (argv[2], "%x", &endcp);
startcp &= 0xFFFFFF; /* limit to 6 hex digits */
endcp &= 0xFFFFFF; /* limit to 6 hex digits */
/*
For each code point in the desired range, generate a glyph.
*/
for (thiscp = startcp; thiscp <= endcp; thiscp++) {
if (thiscp <= 0xFFFF) {
hexprint4 (thiscp); /* print digits 2/line, 2 lines */
}
else {
hexprint6 (thiscp); /* print digits 3/line, 2 lines */
}
}
exit (EXIT_SUCCESS);
}
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.

hexprint6
void hexprint6(int thiscp)
Generate a bitmap containing a 6-digit Unicode code point.
Definition: unihexgen.c:223
hexprint4
void hexprint4(int thiscp)
Generate a bitmap containing a 4-digit Unicode code point.
Definition: unihexgen.c:160
hexdigit
char hexdigit[16][5]
Bitmap pattern for each hexadecimal digit.
Definition: unihexgen.c:84