OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [fonts/] [bdftobogl] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
#! /usr/bin/perl -w
2
 
3
use POSIX;
4
 
5
if ($#ARGV < 0) {
6
    print "Usage: bdftobogl font.bdf > font.c\n";
7
    exit -1;
8
}
9
 
10
$file = $ARGV[0];
11
 
12
$font = $file;
13
$font =~ s/\.bdf//;
14
$font =~ tr/a-zA-Z0-9_/_/cs;
15
 
16
print "/* Generated by bdftobogl on ", substr(`date`, 0, -1), ". */\n";
17
print "#include \"bogl.h\"\n\n";
18
 
19
open BDF, "<$file" || die;
20
while () {
21
    chop;
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+)$/;
27
 
28
    last if /^CHARS /;
29
}
30
 
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";
36
print "*/\n\n";
37
 
38
print "/* Font character content data. */\n";
39
print "static unsigned long ${font}_content[] = {\n";
40
 
41
$pixel_size = $font_ascent + $font_descent;
42
$ofs = 0;
43
$maxwidth = 0;
44
while () {
45
    chop;
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+)/;
50
 
51
    if (/^BITMAP$/) {
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++) {
58
            $bm[$i] = 0;
59
        }
60
        for (my $i = 0; ; $i++) {
61
            $_ = ;
62
            chop;
63
            last if /^ENDCHAR$/;
64
 
65
            $value = hex($_);
66
            $bm[$pixel_size - $font_descent - $bby - $bbh + $i] = $value << (32 - 4 * length($_) - $bbx);
67
        }
68
 
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++) {
73
            print "   |";
74
            for ($j = 31; $j >= 0; $j--) {
75
                print $bm[$i] & (1 << $j) ? "*" : " ";
76
            }
77
            print "|\n";
78
        }
79
        print "   +", ("-" x 32), "+ */\n";
80
 
81
        for (my $i = 0; $i < $pixel_size; $i++) {
82
            $ofs++;
83
            printf "0x%08x,\n", $bm[$i];
84
        }
85
    }
86
}
87
 
88
print "};\n\n";
89
 
90
#print STDERR "Maximum character width=$maxwidth\n";
91
 
92
print "/* Character->glyph data. */\n";
93
print "static short ${font}_ofs[256] = {\n";
94
for (my $i = 0; $i < 256; $i++) {
95
    my $char = $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;
99
}
100
print "};\n\n";
101
 
102
print "/* Character width data. */\n";
103
print "static unsigned char ${font}_width[256] = {\n";
104
for (my $i = 0; $i < 256; $i++) {
105
    my $char = $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;
109
}
110
print "};\n\n";
111
 
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";
119
print "};\n";

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.