Subversion Repositories HelenOS

Rev

Rev 4176 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4176 Rev 4187
1
#!/usr/bin/perl -w
1
#!/usr/bin/perl -w
2
 
2
 
3
#
3
#
4
# Copyright (c) 2000 Dmitry Bolkhovityanov
4
# Copyright (c) 2000 Dmitry Bolkhovityanov
5
# Copyright (c) 2009 Martin Decky
5
# Copyright (c) 2009 Martin Decky
6
# All rights reserved.
6
# All rights reserved.
7
#
7
#
8
# Redistribution and use in source and binary forms, with or without
8
# Redistribution and use in source and binary forms, with or without
9
# modification, are permitted provided that the following conditions
9
# modification, are permitted provided that the following conditions
10
# are met:
10
# are met:
11
#
11
#
12
# - Redistributions of source code must retain the above copyright
12
# - Redistributions of source code must retain the above copyright
13
#   notice, this list of conditions and the following disclaimer.
13
#   notice, this list of conditions and the following disclaimer.
14
# - Redistributions in binary form must reproduce the above copyright
14
# - Redistributions in binary form must reproduce the above copyright
15
#   notice, this list of conditions and the following disclaimer in the
15
#   notice, this list of conditions and the following disclaimer in the
16
#   documentation and/or other materials provided with the distribution.
16
#   documentation and/or other materials provided with the distribution.
17
# - The name of the author may not be used to endorse or promote products
17
# - The name of the author may not be used to endorse or promote products
18
#   derived from this software without specific prior written permission.
18
#   derived from this software without specific prior written permission.
19
#
19
#
20
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
#
30
#
31
 
31
 
32
use strict;
32
use strict;
33
 
33
 
34
my $skip;
34
my $skip;
35
 
35
 
36
my $width;
36
my $width;
37
my $height;
37
my $height;
38
my $offset_x;
38
my $offset_x;
39
my $offset_y;
39
my $offset_y;
40
 
40
 
41
my $gwidth;
41
my $gwidth;
42
my $gheight;
42
my $gheight;
43
my $goffset_x;
43
my $goffset_x;
44
my $goffset_y;
44
my $goffset_y;
45
 
45
 
46
my $index;
46
my $index;
47
my @glyphs;
47
my @glyphs;
48
my @chars;
48
my @chars;
49
 
49
 
50
open(BDF, "u_vga16.bdf") or die("Unable to open source font\n");
50
open(BDF, "u_vga16.bdf") or die("Unable to open source font\n");
51
 
51
 
52
READHEADER: while (<BDF>) {
52
READHEADER: while (<BDF>) {
53
    /^FONTBOUNDINGBOX\s/ and do {
53
    /^FONTBOUNDINGBOX\s/ and do {
54
        ($skip, $width, $height, $offset_x, $offset_y) = (split);
54
        ($skip, $width, $height, $offset_x, $offset_y) = (split);
55
       
55
       
56
        die("Font width is not 8px\n") if ($width != 8);
56
        die("Font width is not 8px\n") if ($width != 8);
57
        die("Font height is not 16px\n") if ($height != 16);
57
        die("Font height is not 16px\n") if ($height != 16);
58
    };
58
    };
59
    /^CHARS\s/ && last READHEADER;
59
    /^CHARS\s/ && last READHEADER;
60
}
60
}
61
 
61
 
62
READCHARS: while (<BDF>) {
62
READCHARS: while (<BDF>) {
63
    /^ENCODING\s+([0-9]+)\s*$/ && do {
63
    /^ENCODING\s+([0-9]+)\s*$/ && do {
64
        $index = $1;
64
        $index = $1;
65
    };
65
    };
66
    /^BBX\s/ && do {
66
    /^BBX\s/ && do {
67
        ($skip, $gwidth, $gheight, $goffset_x, $goffset_y) = (split);
67
        ($skip, $gwidth, $gheight, $goffset_x, $goffset_y) = (split);
68
    };
68
    };
69
    /^BITMAP/ && do {
69
    /^BITMAP/ && do {
70
        my @glyph = ();
70
        my @glyph = ();
71
        my $y;
71
        my $y;
72
       
72
       
73
        # Add empty lines at top
73
        # Add empty lines at top
74
        my $empties = $height + $offset_y - $goffset_y - $gheight;
74
        my $empties = $height + $offset_y - $goffset_y - $gheight;
75
       
75
       
76
        for ($y = 0; $y < $empties; $y++) {
76
        for ($y = 0; $y < $empties; $y++) {
77
            $glyph[$y] = 0;
77
            $glyph[$y] = 0;
78
        }
78
        }
79
       
79
       
80
        # Scan the hex bitmap
80
        # Scan the hex bitmap
81
        for ($y = $empties; $y < $empties + $gheight; $y++) {
81
        for ($y = $empties; $y < $empties + $gheight; $y++) {
82
            $_ = <BDF>;
82
            $_ = <BDF>;
83
            $glyph[$y] = hex(substr($_, 0, 2)) >> $goffset_x;
83
            $glyph[$y] = hex(substr($_, 0, 2)) >> $goffset_x;
84
        }
84
        }
85
       
85
       
86
        # Add empty lines at bottom
86
        # Add empty lines at bottom
87
        my $fill = $height - $gheight - $empties;
87
        my $fill = $height - $gheight - $empties;
88
        for ($y = $empties + $gheight; $y < $empties + $gheight + $fill; $y++) {
88
        for ($y = $empties + $gheight; $y < $empties + $gheight + $fill; $y++) {
89
            $glyph[$y] = 0;
89
            $glyph[$y] = 0;
90
        }
90
        }
91
       
91
       
92
        if ($index != 0) {
92
        if ($index != 0) {
93
            $glyphs[$index] = (\@glyph);
93
            $glyphs[$index] = (\@glyph);
94
            push(@chars, $index);
94
            push(@chars, $index);
95
        }
95
        }
96
    };
96
    };
97
    /^ENDFONT/ && last READCHARS;
97
    /^ENDFONT/ && last READCHARS;
98
}
98
}
99
 
99
 
100
close(BDF);
100
close(BDF);
101
 
101
 
102
@chars = sort { $a <=> $b } (@chars);
102
@chars = sort { $a <=> $b } (@chars);
103
 
103
 
104
print "#define FONT_GLYPHS     " . @chars . "\n";
104
print "#define FONT_GLYPHS     " . (@chars + 1). "\n";
105
print "#define FONT_SCANLINES  " . $height . "\n";
105
print "#define FONT_SCANLINES  " . $height . "\n";
106
 
106
 
107
print "\n";
107
print "\n";
108
print "index_t fb_font_glyph(const wchar_t ch)\n";
108
print "index_t fb_font_glyph(const wchar_t ch)\n";
109
print "{";
109
print "{\n";
-
 
110
print "\tif (ch == 0x0000)\n";
-
 
111
print "\t\treturn 0;\n\n";
110
 
112
 
111
my $pos = 0;
113
my $pos = 0;
112
my $start = -1;
114
my $start = -1;
113
my $start_pos = 0;
115
my $start_pos = 0;
114
my $prev = 0;
116
my $prev = 0;
115
for $index (@chars) {
117
for $index (@chars) {
116
    if ($prev + 1 < $index) {
118
    if ($prev + 1 < $index) {
117
        if ($start != -1) {
119
        if ($start != -1) {
118
            if ($start == $prev) {
120
            if ($start == $prev) {
119
                printf "\tif (ch == 0x%.4x)\n", $start;
121
                printf "\tif (ch == 0x%.4x)\n", $start;
-
 
122
                print "\t\treturn " . $start_pos . ";\n";
120
            } else {
123
            } else {
121
                printf "\tif ((ch >= 0x%.4x) && (ch <= 0x%.4x))\n", $start, $prev;
124
                printf "\tif ((ch >= 0x%.4x) && (ch <= 0x%.4x))\n", $start, $prev;
-
 
125
                print "\t\treturn (ch - " . ($start - $start_pos) . ");\n";
122
            }
126
            }
123
           
127
           
124
            print "\t\treturn (ch - " . ($start - $start_pos) . ");\n";
-
 
125
            print "\t\n";
128
            print "\t\n";
126
        }
129
        }
127
       
130
       
128
        $start = $index;
131
        $start = $index;
129
        $start_pos = $pos;
132
        $start_pos = $pos;
130
    }
133
    }
-
 
134
   
131
    $pos++;
135
    $pos++;
132
    $prev = $index;
136
    $prev = $index;
133
}
137
}
134
 
138
 
135
print "\treturn 31;\n";
139
print "\treturn " . @chars . ";\n";
136
print "}\n";
140
print "}\n";
137
 
141
 
138
print "\n";
142
print "\n";
139
print "uint8_t fb_font[FONT_GLYPHS][FONT_SCANLINES] = {";
143
print "uint8_t fb_font[FONT_GLYPHS][FONT_SCANLINES] = {";
140
 
144
 
141
my $f1 = 0;
-
 
142
for $index (@chars) {
145
for $index (@chars) {
143
    print "," if ($f1 > 0);
-
 
144
    print "\n\t{";
146
    print "\n\t{";
145
   
147
   
146
    my $y;
148
    my $y;
147
    for ($y = 0; $y < $height; $y++) {
149
    for ($y = 0; $y < $height; $y++) {
148
        print ", " if ($y > 0);
150
        print ", " if ($y > 0);
149
        printf "0x%.2x", $glyphs[$index]->[$y];
151
        printf "0x%.2x", $glyphs[$index]->[$y];
150
    }
152
    }
151
   
153
   
152
    print "}";
154
    print "},";
-
 
155
}
-
 
156
 
-
 
157
print "\n\t\n\t/* Special glyph for unknown character */\n\t{";
153
    $f1++;
158
my $y;
-
 
159
for ($y = 0; $y < $height; $y++) {
-
 
160
    print ", " if ($y > 0);
-
 
161
    printf "0x%.2x", $glyphs[63]->[$y];
154
}
162
}
155
 
163
 
156
print "\n};\n";
164
print "}\n};\n";
157
 
165