87main (
int argc, 
char **argv)
 
  101   int plane_array[0x10000][16];
 
  108      for (i = 1; i < argc; i++) {
 
  109         if (strncmp (argv[i],
"-l",2) == 0) { 
 
  112         else if (strncmp (argv[i],
"-d",2) == 0) {
 
  113            dpi = atoi (&argv[i][2]); 
 
  115         else if (strncmp (argv[i],
"-t",2) == 0) {
 
  118         else if (strncmp (argv[i],
"-P",2) == 0) {
 
  120            for (j = 2; argv[i][j] != 
'\0'; j++) {
 
  121               if (argv[i][j] < 
'0' || argv[i][j] > 
'9') {
 
  123                           "ERROR: Specify Unicode plane as decimal number.\n\n");
 
  127            plane = atoi (&argv[i][2]); 
 
  128            if (plane < 0 || plane > 17) {
 
  130                        "ERROR: Plane out of Unicode range [0,17].\n\n");
 
  141   for (i = 0; i < 128; i++) {
 
  143      for (j = 0; j < 16; j++) 
ascii_bits[i][j] = plane_array[i][j];
 
  150   memset ((
void *)plane_array, 0, 0x10000 * 16 * 
sizeof (
int));
 
  151   while (fgets (instring, 
MAXSTRING, stdin) != NULL) {
 
  152      gethex (instring, plane_array, plane); 
 
  160      genwidebmp (plane_array, dpi, tinynum, plane);
 
  163      genlongbmp (plane_array, dpi, tinynum, plane);
 
  179   putchar ( thisword        & 0xFF);
 
  180   putchar ((thisword >>  8) & 0xFF);
 
  181   putchar ((thisword >> 16) & 0xFF);
 
  182   putchar ((thisword >> 24) & 0xFF);
 
  197   putchar ( thisword       & 0xFF);
 
  198   putchar ((thisword >> 8) & 0xFF);
 
  215gethex (
char *instring, 
int plane_array[0x10000][16], 
int plane)
 
  230   sscanf (instring, 
"%X", &codept);
 
  231   glyph_plane = codept >> 16;
 
  232   if (glyph_plane == plane) {
 
  235      for (i = 0; (i < 9) && (instring[i] != 
':'); i++);
 
  237      bitstring = &instring[i];
 
  238      ndigits = strlen (bitstring);
 
  240      if (bitstring[ndigits - 1] == 
'\n') ndigits--;
 
  241      bytespl = ndigits >> 5;  
 
  243      if (bytespl >= 1 && bytespl <= 4) {
 
  244         for (i = 0; i < 16; i++) { 
 
  247               case 1: sscanf (bitstring, 
"%2X", &temprow);
 
  251               case 2: sscanf (bitstring, 
"%4X", &temprow);
 
  255               case 3: sscanf (bitstring, 
"%6X", &temprow);
 
  259               case 4: sscanf (bitstring, 
"%8X", &temprow);
 
  267               for (bitmask = 0xC0000000; bitmask != 0; bitmask >>= 2) {
 
  269                  if ((temprow & bitmask) != 0) newrow |= 1;
 
  273            plane_array[codept][i] = temprow;  
 
  294genlongbmp (
int plane_array[0x10000][16], 
int dpi, 
int tinynum, 
int plane)
 
  303   unsigned leftcol[0x1000][16]; 
 
  307   unsigned toprow[16][16];      
 
  313   int DataOffset = 14 + 40 + 8; 
 
  333   ImageSize = Height * (Width / 8); 
 
  335   FileSize = DataOffset + ImageSize;
 
  338   if (dpi == 0) dpi = 96;
 
  339   ppm = (int)((
double)dpi * 100.0 / 2.54 + 0.5);
 
  379   memset ((
void *)header, 0, 16 * 16 * 
sizeof (
int)); 
 
  380   memset ((
void *)header_string, 
' ', 32 * 
sizeof (
char)); 
 
  381   header_string[32] = 
'\0';  
 
  383   hdrlen = strlen (raw_header);
 
  384   if (hdrlen > 32) hdrlen = 32;        
 
  385   startcol = 16 - ((hdrlen + 1) >> 1); 
 
  387   memcpy (&header_string[startcol], raw_header, hdrlen);
 
  391   for (j = 0; j < 16; j++) {
 
  392      for (i = 0; i < 16; i++) {
 
  394            (
ascii_bits[header_string[j+j  ] & 0x7F][i] & 0xFF00) |
 
  395            (
ascii_bits[header_string[j+j+1] & 0x7F][i] >> 8);
 
  402   memset ((
void *)leftcol, 0, 4096 * 16 * 
sizeof (
unsigned));
 
  404   for (codept = 0x0000; codept < 0x10000; codept += 0x10) {
 
  405      d1 = (codept >> 12) & 0xF; 
 
  406      d2 = (codept >>  8) & 0xF;
 
  407      d3 = (codept >>  4) & 0xF;
 
  409      thisrow = codept >> 4; 
 
  412      for (digitrow = 0; digitrow < 5; digitrow++) {
 
  413         leftcol[thisrow][2 + digitrow] =
 
  419      for (digitrow = 0; digitrow < 5; digitrow++) {
 
  420         leftcol[thisrow][9 + digitrow] = 
hexdigit[d3][digitrow] << 10;
 
  422      leftcol[thisrow][9 + 4] |= 0xF << 4; 
 
  424      for (i = 0; i < 15; i ++) {
 
  425         leftcol[thisrow][i] |= 0x00000002;      
 
  428      leftcol[thisrow][15] = 0x0000FFFE;        
 
  431         leftcol[thisrow][15] |= 0x00FF0000;  
 
  434      if ((thisrow % 0x40) == 0x3F) {    
 
  435         leftcol[thisrow][15] |= 0xFFFF0000; 
 
  442   memset ((
void *)toprow, 0, 16 * 16 * 
sizeof (
unsigned));
 
  444   for (codept = 0x0; codept <= 0xF; codept++) {
 
  445      d1 = (codept >> 12) & 0xF; 
 
  446      d2 = (codept >>  8) & 0xF;
 
  447      d3 = (codept >>  4) & 0xF;
 
  451      for (digitrow = 0; digitrow < 5; digitrow++) {
 
  452         toprow[6 + digitrow][codept] = 
hexdigit[d4][digitrow] << 6;
 
  456   for (j = 0; j < 16; j++) {
 
  458      toprow[15][j] = 0x0000;
 
  462   for (j = 0; j < 16; j++) {
 
  463      toprow[14][j] |= 0xFFFF;
 
  467   for (i = 13; i >= 0; i--) {
 
  468      for (j = 0; j < 16; j++) {
 
  469         toprow[i][j] |= 0x0001;
 
  480   for (i = 0xFFF0; i >= 0; i -= 0x10) {
 
  482      for (j = 15; j >= 0; j--) {
 
  484         putchar ((~leftcol[thisrow][j] >> 24) & 0xFF);
 
  485         putchar ((~leftcol[thisrow][j] >> 16) & 0xFF);
 
  486         putchar ((~leftcol[thisrow][j] >>  8) & 0xFF);
 
  487         putchar ( ~leftcol[thisrow][j]        & 0xFF);
 
  489         for (k = 0; k < 16; k++) {
 
  490            bytesout = ~plane_array[i+k][j] & 0xFFFF;
 
  491            putchar ((bytesout >> 8) & 0xFF);
 
  492            putchar ( bytesout       & 0xFF);
 
  506   for (j = 0; j < 16; j++) {
 
  507      putchar ((~toprow[15][j] >> 8) & 0xFF);
 
  508      putchar ( ~toprow[15][j]       & 0xFF);
 
  515   for (j = 0; j < 16; j++) {
 
  516      putchar ((~toprow[14][j] >> 8) & 0xFF);
 
  517      putchar ( ~toprow[14][j]       & 0xFF);
 
  520   for (i = 13; i >= 0; i--) {
 
  525      for (j = 0; j < 16; j++) {
 
  526         putchar ((~toprow[i][j] >> 8) & 0xFF);
 
  527         putchar ( ~toprow[i][j]       & 0xFF);
 
  536   for (i = 7; i >= 0; i--) {
 
  537      for (j = 0; j < 18; j++) {
 
  543   for (i = 15; i >= 0; i--) {
 
  550      for (j = 0; j < 16; j++) {
 
  551         bytesout = ~header[i][j] & 0xFFFF;
 
  552         putchar ((bytesout >> 8) & 0xFF);
 
  553         putchar ( bytesout       & 0xFF);
 
  558   for (i = 7; i >= 0; i--) {
 
  559      for (j = 0; j < 18; j++) {
 
  581genwidebmp (
int plane_array[0x10000][16], 
int dpi, 
int tinynum, 
int plane)
 
  584   char header_string[257];
 
  590   unsigned leftcol[0x100][16]; 
 
  594   unsigned toprow[32][256];    
 
  596   int hexalpha1, hexalpha2;    
 
  601   int DataOffset = 14 + 40 + 8; 
 
  621   ImageSize = Height * (Width / 8); 
 
  623   FileSize = DataOffset + ImageSize;
 
  626   if (dpi == 0) dpi = 96;
 
  627   ppm = (int)((
double)dpi * 100.0 / 2.54 + 0.5);
 
  665   memset ((
void *)header, 0, 256 * 16 * 
sizeof (
int)); 
 
  666   memset ((
void *)header_string, 
' ', 256 * 
sizeof (
char)); 
 
  667   header_string[256] = 
'\0';  
 
  669   hdrlen = strlen (raw_header);
 
  671   if (hdrlen > 32) hdrlen = 32;
 
  672   startcol = 127 - ((hdrlen - 1) >> 1);  
 
  674   memcpy (&header_string[startcol], raw_header, hdrlen);
 
  677   for (j = 0; j < 256; j++) {
 
  678      for (i = 0; i < 16; i++) {
 
  679         header[i][j] = 
ascii_bits[header_string[j] & 0x7F][i];
 
  686   memset ((
void *)leftcol, 0, 256 * 16 * 
sizeof (
unsigned));
 
  688   for (codept = 0x0000; codept < 0x10000; codept += 0x100) {
 
  689      d1 = (codept >> 12) & 0xF; 
 
  690      d2 = (codept >>  8) & 0xF;
 
  692      thisrow = codept >> 8; 
 
  697         for (digitrow = 0; digitrow < 5; digitrow++) {
 
  698            leftcol[thisrow][6 + digitrow] =
 
  705         hexalpha1 = d1 < 0xA ? 
'0' + d1 : 
'A' + d1 - 0xA;
 
  706         hexalpha2 = d2 < 0xA ? 
'0' + d2 : 
'A' + d2 - 0xA;
 
  708         for (i = 0 ; i < 16; i++) {
 
  709            leftcol[thisrow][i] =
 
  715      for (i = 0; i < 15; i ++) {
 
  716         leftcol[thisrow][i] |= 0x00000002;      
 
  719      leftcol[thisrow][15] = 0x0000FFFE;        
 
  722         leftcol[thisrow][15] |= 0x00FF0000;  
 
  725      if ((thisrow % 0x40) == 0x3F) {    
 
  726         leftcol[thisrow][15] |= 0xFFFF0000; 
 
  733   memset ((
void *)toprow, 0, 32 * 256 * 
sizeof (
unsigned));
 
  735   for (codept = 0x00; codept <= 0xFF; codept++) {
 
  736      d3 = (codept >>  4) & 0xF;
 
  740         for (digitrow = 0; digitrow < 5; digitrow++) {
 
  741            toprow[16 + 6 + digitrow][codept] =
 
  748         hexalpha1 = d3 < 0xA ? 
'0' + d3 : 
'A' + d3 - 0xA;
 
  749         hexalpha2 = d4 < 0xA ? 
'0' + d4 : 
'A' + d4 - 0xA;
 
  750         for (i = 0 ; i < 16; i++) {
 
  751            toprow[14 + i][codept] =
 
  758   for (j = 0; j < 256; j++) {
 
  760      toprow[16 + 15][j] = 0x0000;
 
  764   for (j = 0; j < 256; j++) {
 
  765      toprow[16 + 14][j] |= 0xFFFF;
 
  769   for (i = 13; i >= 0; i--) {
 
  770      for (j = 0; j < 256; j++) {
 
  771         toprow[16 + i][j] |= 0x0001;
 
  776   for (i = 8; i < 16; i++) {
 
  777      for (j = 0x0F; j < 0x100; j += 0x10) {
 
  778         toprow[i][j] |= 0x0001;
 
  789   for (i = 0xFF00; i >= 0; i -= 0x100) {
 
  791      for (j = 15; j >= 0; j--) {
 
  793         putchar ((~leftcol[thisrow][j] >> 24) & 0xFF);
 
  794         putchar ((~leftcol[thisrow][j] >> 16) & 0xFF);
 
  795         putchar ((~leftcol[thisrow][j] >>  8) & 0xFF);
 
  796         putchar ( ~leftcol[thisrow][j]        & 0xFF);
 
  798         for (k = 0x00; k < 0x100; k++) {
 
  799            bytesout = ~plane_array[i+k][j] & 0xFFFF;
 
  800            putchar ((bytesout >> 8) & 0xFF);
 
  801            putchar ( bytesout       & 0xFF);
 
  815   for (j = 0; j < 256; j++) {
 
  816      putchar ((~toprow[16 + 15][j] >> 8) & 0xFF);
 
  817      putchar ( ~toprow[16 + 15][j]       & 0xFF);
 
  824   for (j = 0; j < 256; j++) {
 
  825      putchar ((~toprow[16 + 14][j] >> 8) & 0xFF);
 
  826      putchar ( ~toprow[16 + 14][j]       & 0xFF);
 
  829   for (i = 16 + 13; i >= 0; i--) {
 
  842      for (j = 0; j < 256; j++) {
 
  843         putchar ((~toprow[i][j] >> 8) & 0xFF);
 
  844         putchar ( ~toprow[i][j]       & 0xFF);
 
  853   for (i = 7; i >= 0; i--) {
 
  854      for (j = 0; j < 258; j++) {
 
  860   for (i = 15; i >= 0; i--) {
 
  867      for (j = 0; j < 256; j++) {
 
  868         bytesout = ~header[i][j] & 0xFFFF;
 
  869         putchar ((bytesout >> 8) & 0xFF);
 
  870         putchar ( bytesout       & 0xFF);
 
  875   for (i = 7; i >= 0; i--) {
 
  876      for (j = 0; j < 258; j++) {
 
unsigned hexdigit[16][4]
32 bit representation of 16x8 0..F bitmap
void gethex(char *instring, int plane_array[0x10000][16], int plane)
Read a Unifont .hex-format input file from stdin.
void genwidebmp(int plane_array[0x10000][16], int dpi, int tinynum, int plane)
Generate the BMP output file in wide format.
int main(int argc, char **argv)
The main function.
void output4(int thisword)
Output a 4-byte integer in little-endian order.
void output2(int thisword)
Output a 2-byte integer in little-endian order.
void genlongbmp(int plane_array[0x10000][16], int dpi, int tinynum, int plane)
Generate the BMP output file in long format.
unifontpic.h - Header file for unifontpic.c
#define HEADER_STRING
To be printed as chart title.
int ascii_bits[128][16]
Array to hold ASCII bitmaps for chart title.
const char * ascii_hex[128]
Array of Unifont ASCII glyphs for chart row & column headings.