6 print "Usage: bdftobogl font.bdf > font.c\n";
14 $font =~ tr/a-zA-Z0-9_/_/cs;
16 print "/* Generated by bdftobogl on ", substr(`date`, 0, -1), ". */\n";
17 print "#include \"bogl.h\"\n\n";
19 open BDF, "<$file" || die;
22 $pixel_size = $1 if /^PIXEL_SIZE (\d+)$/;
23 $font_ascent = $1 if /^FONT_ASCENT (\d+)$/;
24 $font_descent = $1 if /^FONT_DESCENT (\d+)$/;
25 $font_name = $1 if /^FONT (.*)$/;
26 $default_char = $1 if /^DEFAULT_CHAR (\d+)$/;
31 print "/* Font information:\n\n";
32 print " name: $font_name\n";
33 print " pixel size: $pixel_size\n";
34 print " ascent: $font_ascent\n";
35 print " descent: $font_descent\n";
38 print "/* Font character content data. */\n";
39 print "static unsigned long ${font}_content[] = {\n";
41 $pixel_size = $font_ascent + $font_descent;
46 undef $encoding, undef $width, undef $bbx, undef $bby, undef $bbw, undef $bbh if /^STARTCHAR /;
47 $encoding = $1 if /^ENCODING (\d+)/;
48 $width = $1 if /^DWIDTH (-?\d+)/;
49 ($bbw, $bbh, $bbx, $bby) = ($1, $2, $3, $4) if /^BBX (-?\d+) (-?\d+) (-?\d+) (-?\d+)/;
52 next if !defined $encoding;
53 $encoding_tab[$encoding] = $ofs;
54 $width -= $bbx, $bbx = 0 if $bbx < 0;
55 $width[$encoding] = $width;
56 $maxwidth = $width if $width > $maxwidth;
57 for (my $i = 0; $i < $pixel_size; $i++) {
60 for (my $i = 0; ; $i++) {
66 $bm[$pixel_size - $font_descent - $bby - $bbh + $i] = $value << (32 - 4 * length($_) - $bbx);
69 printf "\n/* Character %c (0x%02x):\n", $encoding, $encoding;
70 print " bbw=$bbw, bbh=$bbh, bbx=$bbx, bby=$bby, width=$width\n";
71 print " +", ("-" x 32), "+\n";
72 for (my $i = 0; $i < $pixel_size; $i++) {
74 for ($j = 31; $j >= 0; $j--) {
75 print $bm[$i] & (1 << $j) ? "*" : " ";
79 print " +", ("-" x 32), "+ */\n";
81 for (my $i = 0; $i < $pixel_size; $i++) {
83 printf "0x%08x,\n", $bm[$i];
90 #print STDERR "Maximum character width=$maxwidth\n";
92 print "/* Character->glyph data. */\n";
93 print "static short ${font}_ofs[256] = {\n";
94 for (my $i = 0; $i < 256; $i++) {
96 my $ofs = $encoding_tab[$i];
97 $ofs = $encoding_tab[$default_char], $char = $default_char if !defined $ofs;
98 printf " $ofs,\t/* %c (0x%02x) */\n", $char, $i;
102 print "/* Character width data. */\n";
103 print "static unsigned char ${font}_width[256] = {\n";
104 for (my $i = 0; $i < 256; $i++) {
106 my $width = $width[$i];
107 $width = $width[$default_char], $char = $default_char if !defined $encoding_tab[$i];
108 printf " $width,\t/* %c (0x%02x) */\n", $char, $i;
112 print "/* Exported structure definition. */\n";
113 print "const struct bogl_font font_${font} = {\n";
114 print " \"$font\",\n";
115 print " $pixel_size,\n";
116 print " ${font}_content,\n";
117 print " ${font}_ofs,\n";
118 print " ${font}_width,\n";