diff ascii2bdf.pl @ 2:7f5d4dad9d6b

merge operation
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 15 Jun 2013 18:19:15 +0900
parents a6ddaa18e3c1
children 0285a01caf93
line wrap: on
line diff
--- a/ascii2bdf.pl	Sat Jun 15 14:16:00 2013 +0900
+++ b/ascii2bdf.pl	Sat Jun 15 18:19:15 2013 +0900
@@ -3,27 +3,59 @@
 
 my ($name,$encoding,@bitmap);
 
-#while(<>) {
-#    last if (/^ENDPROP/);
-#}
-
-#my $dum = <>; # skip CHARS
-
 my ($lineno,$line);
 my $width;
 my $height;
+my @header;
+my $char;
+my @bytes;
+my %chars;
 
 while(<>) {
-    if(/^STARTCHAR\s+(.*)/) { &init(); $name=$1; print;
-    } elsif (/^ENCODING\s+(\d+)/) {    $encoding=$1; print;
-    } elsif (/^SWIDTH (\d+) (\d+)/) { print;
-    } elsif (/^DWIDTH (\d+) (\d+)/) { $width = $1; print;
-    } elsif (/^BBX ([-+\d]+) ([-+\d]+) ([-+\d]+) ([-+\d]+)/) { print; $height = $2;
-    } elsif (/^BITMAP/) { print; $line = $lineno+2; # error line must start 1
-    } elsif (/^ENDCHAR/) {  &display(); print "ENDCHAR\n";
+    if(/^STARTFONT\s+(.*)/) {   
+        push(@header,$_);
+        while(<>) {
+            push(@header,$_);
+            last if(/^ENDPROPERTIES/);
+        }
+    } elsif(/^CHARS/) { 
+    } elsif(/^STARTCHAR\s+(.*)/) { &init(); $name=$1; 
+    } elsif (/^ENCODING\s+(\d+)/) {    $encoding=$1; $char={name=>$name,encoding=>$_}; $chars{$encoding} = $char;
+    } elsif (/^SWIDTH (\d+) (\d+)/) { $char->{swidth} = $_;
+    } elsif (/^DWIDTH (\d+) (\d+)/) { $width = $1; $char->{dwidth} = $_;
+    } elsif (/^BBX ([-+\d]+) ([-+\d]+) ([-+\d]+) ([-+\d]+)/) { $height = $2; $char->{bbx} = $_;
+    } elsif (/^BITMAP/) { $line = $lineno+2; # error line must start 1
+    } elsif (/^ENDCHAR/) {  
+        &display() if (@bitmap) ; 
+    } elsif (/^[0-9A-Fa-f]+$/) {  push(@{$char->{byte}},$_);
     } elsif (/^[ *]+$/) {  chop; push(@bitmap,$_);
     }
     $lineno++;
+    $lineno = 0 if (eof);
+}
+
+print @header if (@header);
+print "CHARS ",scalar(keys %chars)+1,"\n\n";
+for my $k ( sort {$a <=> $b} keys %chars) {
+    my $ch = $chars{$k};
+    print "STARTCHAR $ch->{name}\n";
+    print $ch->{encoding};
+    print $ch->{swidth};
+    print $ch->{dwidth};
+    print $ch->{bbx};
+    print "BITMAP\n";
+    for my $byte (@{$ch->{byte}}) {
+        print $byte;
+    }
+    print "ENDCHAR\n\n";
+}
+print "ENDFONT\n";
+
+sub showchar {
+    my ($ch) = @_;
+    for my $k ( keys %{$ch} ) {
+        print "$k => $ch->{$k}\n";
+    }
 }
 
 sub display {
@@ -54,17 +86,65 @@
         my $h =  pack("B*",$bin . "0"x$width);
         my $b = unpack("H*",$h);
         $b = substr($b,0,$hwidth);
-        print "$b\n";
+        push(@{$char->{byte}},$b."\n");
         last if ($i++ > $height-2);
     }
     # print "hhhh $height-$i = ",$height-$i,"\n";
-    print (("0"x$hwidth."\n")x($height-$i)) if ($height-$i > 0);
+    # print (("0"x$hwidth."\n")x($height-$i)) if ($height-$i > 0);
+    while ($height-$i > 0) {
+        push(@{$char->{byte}},("0"x$hwidth."\n"));
+        $i++;
+    }
 }
 
 sub init {
     $name = '';
     $encoding = 0;
     @bitmap= ();
+    @bytes= ();
 }
 
+=head1 NAME
+
+ascii2bdf -- convert readable bdf to bdf and merge
+
+=head1 AUTHORS
+
+Shinji KONO <kono@ie.u-ryukyu.ac.jp>
+
+=head1 SYNOPSIS
+
+    perl ascii2bdf.pl orignal.bdf fix.bdf fix1.bdf
+
+=head1 DESCRIPTION
+
+this script converts
+
+    STARTCHAR uni2163
+    ENCODING 8547
+    SWIDTH 960 0
+    DWIDTH 14 0
+    BBX 14 14 0 -2
+    BITMAP
+
+        **  **          **            
+        **  **          **            
+        **  **          **            
+        **    **      **              
+        **    **      **              
+        **    **      **              
+        **      **  **                
+        **      **  **                
+        **      **  **                
+        **        **          
+        **        **          
+                                  
+                                    
+    ENDCHAR
+
+to bdf and merge it to the orignal one.
+
+=cut
+
+
 # end