2 unibdf2hex - program to convert a BDF file into a unifont.hex file.
4 Author: Paul Hardy, January 2008
6 Note: currently this has hard-coded code points for glyphs extracted
7 from Wen Quan Yi to create the Unifont source file "wqy.hex".
9 Copyright (C) 2008, 2013 Paul Hardy
13 This program is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
38 int rownum; /* number of lines we output in bitmap */
41 int bbxx, bbxy, bbxxoff, bbxyoff;
43 int descent=2; /* font descent wrt baseline */
44 int startrow; /* row to start glyph */
45 int rowlen=4; /* number of digits per row */
48 while (fgets (inbuf, MAXBUF - 1, stdin)) {
49 if (strncmp (inbuf, "ENCODING ", 9)) continue;
50 sscanf (&inbuf[9], "%d", &thispoint); /* get code point */
52 /* Read bounding box values from BBX line */
53 while (fgets (inbuf, MAXBUF - 1, stdin)) {
54 if (!strncmp (inbuf, "BBX ", 4)) break;
56 sscanf (&inbuf[4], "%d %d %d %d", &bbxx, &bbxy, &bbxxoff, &bbxyoff);
58 /* Find BITMAP start */
59 while (fgets (inbuf, MAXBUF - 1, stdin)) {
60 if (!strncmp (inbuf, "BITMAP", 6)) break;
63 fprintf (stdout, "%04X:", thispoint);
65 /* Print initial blank rows */
66 startrow = descent + bbxyoff + bbxy;
68 /* Force everything to 16 pixels wide */
69 for (i = 16; i > startrow; i--) {
70 fprintf (stdout, "%0*d", rowlen, 0);
73 /* Copy bitmap until END */
74 while (fgets (inbuf, MAXBUF - 1, stdin)) {
75 if (!strncmp (inbuf, "END", 3)) break;
76 sscanf (inbuf, "%X", &rowout);
77 /* Now force glyph to a 16x16 grid even if they'd fit in 8x16 */
78 if (bbxx <= 8) rowout <<= 8; /* shift left for 16x16 glyph */
80 fprintf (stdout, "%0*X", rowlen, rowout);
84 /* Pad empty lines until glyph has sufficient height */
86 fprintf (stdout, "%0*d", rowlen, 0);
89 fprintf (stdout,"\n");