gen_glyph.pl
874 Bytes
#!/usr/bin/perl -w
die "Usage: gen_glyph.pl <Chinese GB 16x16 font map> <output glyph file> <GB byte1> <GB byte2>\n" unless $#ARGV==3;
$GBCODE_BYTE_OFFSET = 0xa1;
$GBCODE_UNIT_LEN = 94;
$GBCODE_CHAR_SIZE = 32; #16x16 bitmap -> 32 bytes
open(IN_DB, "<$ARGV[0]") or die "Can't open $ARGV[0]: $!";
open(OUT_GLYPH, ">$ARGV[1]") or die "Can't open $ARGV[1]: $!";
$c = hex($ARGV[2]);
$c2 = hex($ARGV[3]);
$idx = ($c-$GBCODE_BYTE_OFFSET)*$GBCODE_UNIT_LEN + ($c2-$GBCODE_BYTE_OFFSET);
$skip = $idx * $GBCODE_CHAR_SIZE;
printf OUT_GLYPH "unsigned char texFont[] = {\n";
seek(IN_DB, $skip, 0);
for ($i=0; $i<$GBCODE_CHAR_SIZE; $i++) {
if ($i%2==0) { printf OUT_GLYPH "\n"; }
$byte = getc(IN_DB);
for ($j=0; $j<8; $j++) {
printf OUT_GLYPH "0x%02x, ", (vec($byte, 0, 8) & (0x80>>$j))==0 ? 0:0xff;
}
}
printf OUT_GLYPH "\n};";
close IN_DB;
close OUT_GLYPH;