Home | History | Annotate | Line # | Download | only in hpc
      1 /*	$NetBSD: fontconv.c,v 1.3 2001/11/13 12:47:56 lukem Exp $	*/
      2 
      3 #include <sys/cdefs.h>
      4 __KERNEL_RCSID(0, "$NetBSD: fontconv.c,v 1.3 2001/11/13 12:47:56 lukem Exp $");
      5 
      6 #include <stdio.h>
      7 
      8 
      9 int width, height, ascent;
     10 char *fontname;
     11 FILE *ifp;
     12 FILE *ofp;
     13 
     14 
     15 void fc_rcons(int ac, char* av[]);
     16 void fc_rasops(int ac, char* av[]);
     17 
     18 
     19 main(int ac, char* av[])
     20 {
     21 	ifp = stdin;
     22 	ofp = stdout;
     23 	width = 8;
     24 	height = 8;
     25 	ascent = 8;
     26 	fontname = "vt220l";
     27 
     28 	/*
     29 	  fc_rcons(ac, av);
     30 	*/
     31 	fc_rasops(ac, av);
     32 }
     33 
     34 
     35 void
     36 fc_rasops(int ac, char* av[])
     37 {
     38 	int code;
     39 	int width_in_bytes;
     40 	long code_min = 0x10000;
     41 	long code_max = -1;
     42 
     43 	width_in_bytes = (width + 7) / 8;
     44 
     45 	code = 0;
     46 	fprintf(ofp, "static u_char %s%dx%d_data[] = {\n",
     47 	    fontname, width, height, code);
     48 	while (1) {
     49 		int n;
     50 		int i, j, k;
     51 		unsigned char buf[200];
     52 
     53 		n = fread(buf, width_in_bytes, height, ifp);
     54 		if (n != height) {
     55 			if (!feof(ifp)) {
     56 				perror("fread()");
     57 				exit(1);
     58 			} else {
     59 				break;
     60 			}
     61 		}
     62 
     63 		k = 0;
     64 		fprintf(ofp, "    /* code %d */\n", code);
     65 		for (i = 0; i < height; i++) {
     66 			unsigned long d = 0, m;
     67 			fprintf(ofp, "    ");
     68 			for (j = 0; j < width_in_bytes; j++) {
     69 				d |= (((unsigned long)buf[k]) << (24 - 8*j));
     70 				fprintf(ofp, "0x%02x,", (buf[k] & 0xff));
     71 				k++;
     72 			}
     73 			fprintf(ofp, " /* ");
     74 			for (m = 0x80000000, j = 0; j < width; j++, m >>= 1) {
     75 				printf((m & d) ? "##" : "..");
     76 			}
     77 			fprintf(ofp, " */\n");
     78 		}
     79 		fprintf(ofp, "\n");
     80 		if (code < code_min) {
     81 			code_min = code;
     82 		}
     83 		if (code_max < code) {
     84 			code_max = code;
     85 		}
     86 		code++;
     87 	}
     88 	fprintf(ofp, "};\n");
     89 
     90 	fprintf(ofp, "struct wsdisplay_font %s%dx%d = {\n",
     91 	    fontname, width, height);
     92 	fprintf(ofp, "    \"%s\",\t\t\t/* typeface name */\n", fontname);
     93 	fprintf(ofp, "    0x%02x,\t\t\t/* firstchar */\n", code_min);
     94 	fprintf(ofp, "    %d,\t\t\t/* numchars */\n", code_max - code_min + 1);
     95 	fprintf(ofp, "    WSDISPLAY_FONTENC_ISO,\t/* encoding */\n");
     96 	fprintf(ofp, "    %d,\t\t\t\t/* width */\n", width);
     97 	fprintf(ofp, "    %d,\t\t\t\t/* height */\n", height);
     98 	fprintf(ofp, "    %d,\t\t\t\t/* stride */\n", width_in_bytes);
     99 	fprintf(ofp, "    WSDISPLAY_FONTENC_L2R,\t/* bit order */\n");
    100 	fprintf(ofp, "    WSDISPLAY_FONTENC_L2R,\t/* byte order */\n");
    101 	fprintf(ofp, "    %s%dx%d_data\t\t/* data */\n",
    102 	    fontname, width, height);
    103 	fprintf(ofp, "};\n");
    104 }
    105 
    106 
    107 void
    108 fc_rcons(int ac, char* av[])
    109 {
    110 	int code;
    111 	int width_in_bytes;
    112 	long code_min = 0x10000;
    113 	long code_max = -1;
    114 
    115 	width_in_bytes = (width + 7) / 8;
    116 
    117 	code = 0;
    118 	while (1) {
    119 		int n;
    120 		int i, j, k;
    121 		unsigned char buf[200];
    122 
    123 		n = fread(buf, width_in_bytes, height, ifp);
    124 		if (n != height) {
    125 			if (!feof(ifp)) {
    126 				perror("fread()");
    127 				exit(1);
    128 			} else {
    129 				break;
    130 			}
    131 		}
    132 
    133 		fprintf(ofp, "static u_int32_t %s%dx%d_%d_pix[] = {\n",
    134 		    fontname, width, height, code);
    135 
    136 		k = 0;
    137 		for (i = 0; i < height; i++) {
    138 			unsigned long d = 0, m;
    139 			for (j = 0; j < width_in_bytes; j++) {
    140 				d |= (((unsigned long)buf[k++]) << (24 - 8*j));
    141 			}
    142 			fprintf(ofp, "    0x%08x, /* ", d);
    143 			for (m = 0x80000000, j = 0; j < width; j++, m >>= 1) {
    144 				printf((m & d) ? "##" : "..");
    145 			}
    146 			fprintf(ofp, " */\n");
    147 		}
    148 		fprintf(ofp, "};\n");
    149 		fprintf(ofp, "static struct raster %s%dx%d_%d = {",
    150 		    fontname, width, height, code);
    151 		fprintf(ofp, " %d, %d, 1, 1, %s%dx%d_%d_pix, 0 };\n",
    152 		    width, height, fontname, width, height, code);
    153 		if (code < code_min) {
    154 			code_min = code;
    155 		}
    156 		if (code_max < code) {
    157 			code_max = code;
    158 		}
    159 		code++;
    160 	}
    161 
    162 	fprintf(ofp, "struct raster_font %s%dx%d = {\n",
    163 	    fontname, width, height);
    164 	fprintf(ofp, "    %d, %d, %d, ", width, height, ascent);
    165 	fprintf(ofp, "RASFONT_FIXEDWIDTH|RASFONT_NOVERTICALMOVEMENT,\n");
    166 	fprintf(ofp, "    {\n");
    167 	for (code = code_min; code <= code_max; code++) {
    168 		fprintf(ofp, "        { &%s%dx%d_%d, ",
    169 		    fontname, width, height, code);
    170 		fprintf(ofp, "%d, %d, %d, %d },\n", 0, -ascent, width, 0);
    171 	}
    172 	fprintf(ofp, "    },\n");
    173 	fprintf(ofp, "#ifdef COLORFONT_CACHE\n");
    174 	fprintf(ofp, "    (struct raster_fontcache*) -1\n");
    175 	fprintf(ofp, "#endif /*COLORFONT_CACHE*/\n");
    176 	fprintf(ofp, "};\n");
    177 }
    178