bdf2c.pl 1.33 KB
Newer Older
1 2 3 4 5 6 7 8 9
#!/usr/bin/perl

@encodings=();
for($i=0;$i<256*5;$i++) {
  $encodings[$i]="0";
}

$out="";
$counter=0;
10
$fontname="default";
11 12 13 14 15 16

$i=0;
$searchfor="";
$nullx="0x";

while(<>) {
17 18
  if(/^FONT (.*)$/) {
    $fontname=$1;
dscho's avatar
dscho committed
19
    $fontname=~y/\"//d;
20
  } elsif(/^ENCODING (.*)$/) {
21 22
    $glyphindex=$1;
    $searchfor="BBX";
23 24 25
    $dwidth=0;
  } elsif(/^DWIDTH (.*) (.*)/) {
    $dwidth=$1;
26 27 28
  } elsif(/^BBX (.*) (.*) (.*) (.*)$/) {
    ($width,$height,$x,$y)=($1,$2,$3,$4);
    @encodings[$glyphindex*5..($glyphindex*5+4)]=($counter,$width,$height,$x,$y);
29 30 31 32 33
    if($dwidth != 0) {
      $encodings[$glyphindex*5+1]=$dwidth;
    } else {
      $dwidth=$width;
    }
34 35 36 37 38 39 40 41
    $searchfor="BITMAP";
  } elsif(/^BITMAP/) {
    $i=1;
  } elsif($i>0) {
    if($i>$height) {
      $i=0;
      $out.=" /* $glyphindex */\n";
    } else {
42 43 44 45 46
      if(int(($dwidth+7)/8) > int(($width+7)/8)) {
	$_ .= "00"x(int(($dwidth+7)/8)-int(($width+7)/8));
      }
      $_=substr($_,0,(int(($dwidth+7)/8)*2));
      $counter+=(int(($dwidth+7)/8));
47 48 49 50 51 52 53
      s/(..)/$nullx$1,/g;
      $out.=$_;
      $i++;
    }
  }
}

54 55
print "unsigned char " . $fontname . "FontData[$counter]={\n" . $out;
print "};\nint " . $fontname . "FontMetaData[256*5]={\n";
56 57 58
for($i=0;$i<256*5;$i++) {
  print $encodings[$i] . ",";
}
59 60
print "};\nrfbFontData " . $fontname . "Font={" .
  $fontname . "FontData, " . $fontname . "FontMetaData};\n";