98main (
int argc,
char **argv)
112 int plane_array[0x10000][16];
114 void gethex (
char *instring,
int plane_array[0x10000][16],
int plane);
115 void genlongbmp (
int plane_array[0x10000][16],
int dpi,
int tinynum,
117 void genwidebmp (
int plane_array[0x10000][16],
int dpi,
int tinynum,
121 for (i = 1; i < argc; i++) {
122 if (strncmp (argv[i],
"-l",2) == 0) {
125 else if (strncmp (argv[i],
"-d",2) == 0) {
126 dpi = atoi (&argv[i][2]);
128 else if (strncmp (argv[i],
"-t",2) == 0) {
131 else if (strncmp (argv[i],
"-P",2) == 0) {
133 for (j = 2; argv[i][j] !=
'\0'; j++) {
134 if (argv[i][j] <
'0' || argv[i][j] >
'9') {
136 "ERROR: Specify Unicode plane as decimal number.\n\n");
140 plane = atoi (&argv[i][2]);
141 if (plane < 0 || plane > 17) {
143 "ERROR: Plane out of Unicode range [0,17].\n\n");
154 for (i = 0; i < 128; i++) {
157 for (j = 0; j < 16; j++)
ascii_bits[i][j] = plane_array[i][j];
164 memset ((
void *)plane_array, 0, 0x10000 * 16 *
sizeof (
int));
165 while (fgets (instring,
MAXSTRING, stdin) != NULL) {
166 gethex (instring, plane_array, plane);
174 genwidebmp (plane_array, dpi, tinynum, plane);
177 genlongbmp (plane_array, dpi, tinynum, plane);
193 putchar ( thisword & 0xFF);
194 putchar ((thisword >> 8) & 0xFF);
195 putchar ((thisword >> 16) & 0xFF);
196 putchar ((thisword >> 24) & 0xFF);
211 putchar ( thisword & 0xFF);
212 putchar ((thisword >> 8) & 0xFF);
229gethex (
char *instring,
int plane_array[0x10000][16],
int plane)
244 sscanf (instring,
"%X", &codept);
245 glyph_plane = codept >> 16;
246 if (glyph_plane == plane) {
249 for (i = 0; (i < 9) && (instring[i] !=
':'); i++);
251 bitstring = &instring[i];
252 ndigits = strlen (bitstring);
254 if (bitstring[ndigits - 1] ==
'\n') ndigits--;
255 bytespl = ndigits >> 5;
257 if (bytespl >= 1 && bytespl <= 4) {
258 for (i = 0; i < 16; i++) {
261 case 1: sscanf (bitstring,
"%2X", &temprow);
265 case 2: sscanf (bitstring,
"%4X", &temprow);
269 case 3: sscanf (bitstring,
"%6X", &temprow);
273 case 4: sscanf (bitstring,
"%8X", &temprow);
281 for (bitmask = 0xC0000000; bitmask != 0; bitmask >>= 2) {
283 if ((temprow & bitmask) != 0) newrow |= 1;
287 plane_array[codept][i] = temprow;
308genlongbmp (
int plane_array[0x10000][16],
int dpi,
int tinynum,
int plane)
317 unsigned leftcol[0x1000][16];
321 unsigned toprow[16][16];
327 int DataOffset = 14 + 40 + 8;
347 ImageSize = Height * (Width / 8);
349 FileSize = DataOffset + ImageSize;
352 if (dpi == 0) dpi = 96;
353 ppm = (int)((
double)dpi * 100.0 / 2.54 + 0.5);
393 memset ((
void *)header, 0, 16 * 16 *
sizeof (
int));
394 memset ((
void *)header_string,
' ', 32 *
sizeof (
char));
395 header_string[32] =
'\0';
397 hdrlen = strlen (raw_header);
398 if (hdrlen > 32) hdrlen = 32;
399 startcol = 16 - ((hdrlen + 1) >> 1);
401 memcpy (&header_string[startcol], raw_header, hdrlen);
405 for (j = 0; j < 16; j++) {
406 for (i = 0; i < 16; i++) {
408 (
ascii_bits[header_string[j+j ] & 0x7F][i] & 0xFF00) |
409 (
ascii_bits[header_string[j+j+1] & 0x7F][i] >> 8);
416 memset ((
void *)leftcol, 0, 4096 * 16 *
sizeof (
unsigned));
418 for (codept = 0x0000; codept < 0x10000; codept += 0x10) {
419 d1 = (codept >> 12) & 0xF;
420 d2 = (codept >> 8) & 0xF;
421 d3 = (codept >> 4) & 0xF;
423 thisrow = codept >> 4;
426 for (digitrow = 0; digitrow < 5; digitrow++) {
427 leftcol[thisrow][2 + digitrow] =
433 for (digitrow = 0; digitrow < 5; digitrow++) {
434 leftcol[thisrow][9 + digitrow] =
hexdigit[d3][digitrow] << 10;
436 leftcol[thisrow][9 + 4] |= 0xF << 4;
438 for (i = 0; i < 15; i ++) {
439 leftcol[thisrow][i] |= 0x00000002;
442 leftcol[thisrow][15] = 0x0000FFFE;
445 leftcol[thisrow][15] |= 0x00FF0000;
448 if ((thisrow % 0x40) == 0x3F) {
449 leftcol[thisrow][15] |= 0xFFFF0000;
456 memset ((
void *)toprow, 0, 16 * 16 *
sizeof (
unsigned));
458 for (codept = 0x0; codept <= 0xF; codept++) {
459 d1 = (codept >> 12) & 0xF;
460 d2 = (codept >> 8) & 0xF;
461 d3 = (codept >> 4) & 0xF;
465 for (digitrow = 0; digitrow < 5; digitrow++) {
466 toprow[6 + digitrow][codept] =
hexdigit[d4][digitrow] << 6;
470 for (j = 0; j < 16; j++) {
472 toprow[15][j] = 0x0000;
476 for (j = 0; j < 16; j++) {
477 toprow[14][j] |= 0xFFFF;
481 for (i = 13; i >= 0; i--) {
482 for (j = 0; j < 16; j++) {
483 toprow[i][j] |= 0x0001;
494 for (i = 0xFFF0; i >= 0; i -= 0x10) {
496 for (j = 15; j >= 0; j--) {
498 putchar ((~leftcol[thisrow][j] >> 24) & 0xFF);
499 putchar ((~leftcol[thisrow][j] >> 16) & 0xFF);
500 putchar ((~leftcol[thisrow][j] >> 8) & 0xFF);
501 putchar ( ~leftcol[thisrow][j] & 0xFF);
503 for (k = 0; k < 16; k++) {
504 bytesout = ~plane_array[i+k][j] & 0xFFFF;
505 putchar ((bytesout >> 8) & 0xFF);
506 putchar ( bytesout & 0xFF);
520 for (j = 0; j < 16; j++) {
521 putchar ((~toprow[15][j] >> 8) & 0xFF);
522 putchar ( ~toprow[15][j] & 0xFF);
529 for (j = 0; j < 16; j++) {
530 putchar ((~toprow[14][j] >> 8) & 0xFF);
531 putchar ( ~toprow[14][j] & 0xFF);
534 for (i = 13; i >= 0; i--) {
539 for (j = 0; j < 16; j++) {
540 putchar ((~toprow[i][j] >> 8) & 0xFF);
541 putchar ( ~toprow[i][j] & 0xFF);
550 for (i = 7; i >= 0; i--) {
551 for (j = 0; j < 18; j++) {
557 for (i = 15; i >= 0; i--) {
564 for (j = 0; j < 16; j++) {
565 bytesout = ~header[i][j] & 0xFFFF;
566 putchar ((bytesout >> 8) & 0xFF);
567 putchar ( bytesout & 0xFF);
572 for (i = 7; i >= 0; i--) {
573 for (j = 0; j < 18; j++) {
595genwidebmp (
int plane_array[0x10000][16],
int dpi,
int tinynum,
int plane)
598 char header_string[257];
604 unsigned leftcol[0x100][16];
608 unsigned toprow[32][256];
610 int hexalpha1, hexalpha2;
615 int DataOffset = 14 + 40 + 8;
635 ImageSize = Height * (Width / 8);
637 FileSize = DataOffset + ImageSize;
640 if (dpi == 0) dpi = 96;
641 ppm = (int)((
double)dpi * 100.0 / 2.54 + 0.5);
679 memset ((
void *)header, 0, 256 * 16 *
sizeof (
int));
680 memset ((
void *)header_string,
' ', 256 *
sizeof (
char));
681 header_string[256] =
'\0';
683 hdrlen = strlen (raw_header);
685 if (hdrlen > 32) hdrlen = 32;
686 startcol = 127 - ((hdrlen - 1) >> 1);
688 memcpy (&header_string[startcol], raw_header, hdrlen);
691 for (j = 0; j < 256; j++) {
692 for (i = 0; i < 16; i++) {
693 header[i][j] =
ascii_bits[header_string[j] & 0x7F][i];
700 memset ((
void *)leftcol, 0, 256 * 16 *
sizeof (
unsigned));
702 for (codept = 0x0000; codept < 0x10000; codept += 0x100) {
703 d1 = (codept >> 12) & 0xF;
704 d2 = (codept >> 8) & 0xF;
706 thisrow = codept >> 8;
711 for (digitrow = 0; digitrow < 5; digitrow++) {
712 leftcol[thisrow][6 + digitrow] =
719 hexalpha1 = d1 < 0xA ?
'0' + d1 :
'A' + d1 - 0xA;
720 hexalpha2 = d2 < 0xA ?
'0' + d2 :
'A' + d2 - 0xA;
722 for (i = 0 ; i < 16; i++) {
723 leftcol[thisrow][i] =
729 for (i = 0; i < 15; i ++) {
730 leftcol[thisrow][i] |= 0x00000002;
733 leftcol[thisrow][15] = 0x0000FFFE;
736 leftcol[thisrow][15] |= 0x00FF0000;
739 if ((thisrow % 0x40) == 0x3F) {
740 leftcol[thisrow][15] |= 0xFFFF0000;
747 memset ((
void *)toprow, 0, 32 * 256 *
sizeof (
unsigned));
749 for (codept = 0x00; codept <= 0xFF; codept++) {
750 d3 = (codept >> 4) & 0xF;
754 for (digitrow = 0; digitrow < 5; digitrow++) {
755 toprow[16 + 6 + digitrow][codept] =
762 hexalpha1 = d3 < 0xA ?
'0' + d3 :
'A' + d3 - 0xA;
763 hexalpha2 = d4 < 0xA ?
'0' + d4 :
'A' + d4 - 0xA;
764 for (i = 0 ; i < 16; i++) {
765 toprow[14 + i][codept] =
772 for (j = 0; j < 256; j++) {
774 toprow[16 + 15][j] = 0x0000;
778 for (j = 0; j < 256; j++) {
779 toprow[16 + 14][j] |= 0xFFFF;
783 for (i = 13; i >= 0; i--) {
784 for (j = 0; j < 256; j++) {
785 toprow[16 + i][j] |= 0x0001;
790 for (i = 8; i < 16; i++) {
791 for (j = 0x0F; j < 0x100; j += 0x10) {
792 toprow[i][j] |= 0x0001;
803 for (i = 0xFF00; i >= 0; i -= 0x100) {
805 for (j = 15; j >= 0; j--) {
807 putchar ((~leftcol[thisrow][j] >> 24) & 0xFF);
808 putchar ((~leftcol[thisrow][j] >> 16) & 0xFF);
809 putchar ((~leftcol[thisrow][j] >> 8) & 0xFF);
810 putchar ( ~leftcol[thisrow][j] & 0xFF);
812 for (k = 0x00; k < 0x100; k++) {
813 bytesout = ~plane_array[i+k][j] & 0xFFFF;
814 putchar ((bytesout >> 8) & 0xFF);
815 putchar ( bytesout & 0xFF);
829 for (j = 0; j < 256; j++) {
830 putchar ((~toprow[16 + 15][j] >> 8) & 0xFF);
831 putchar ( ~toprow[16 + 15][j] & 0xFF);
838 for (j = 0; j < 256; j++) {
839 putchar ((~toprow[16 + 14][j] >> 8) & 0xFF);
840 putchar ( ~toprow[16 + 14][j] & 0xFF);
843 for (i = 16 + 13; i >= 0; i--) {
856 for (j = 0; j < 256; j++) {
857 putchar ((~toprow[i][j] >> 8) & 0xFF);
858 putchar ( ~toprow[i][j] & 0xFF);
867 for (i = 7; i >= 0; i--) {
868 for (j = 0; j < 258; j++) {
874 for (i = 15; i >= 0; i--) {
881 for (j = 0; j < 256; j++) {
882 bytesout = ~header[i][j] & 0xFFFF;
883 putchar ((bytesout >> 8) & 0xFF);
884 putchar ( bytesout & 0xFF);
889 for (i = 7; i >= 0; i--) {
890 for (j = 0; j < 258; j++) {
int main(void)
The main function.
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.
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.