annotate ascii2bdf.pl @ 0:a6ddaa18e3c1

k14 unicode font kit
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 15 Jun 2013 12:23:00 +0900
parents
children 7f5d4dad9d6b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #!/usr/bin/perl
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 use strict;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 my ($name,$encoding,@bitmap);
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #while(<>) {
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 # last if (/^ENDPROP/);
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #}
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #my $dum = <>; # skip CHARS
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 my ($lineno,$line);
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 my $width;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 my $height;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 while(<>) {
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 if(/^STARTCHAR\s+(.*)/) { &init(); $name=$1; print;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 } elsif (/^ENCODING\s+(\d+)/) { $encoding=$1; print;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 } elsif (/^SWIDTH (\d+) (\d+)/) { print;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 } elsif (/^DWIDTH (\d+) (\d+)/) { $width = $1; print;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 } elsif (/^BBX ([-+\d]+) ([-+\d]+) ([-+\d]+) ([-+\d]+)/) { print; $height = $2;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 } elsif (/^BITMAP/) { print; $line = $lineno+2; # error line must start 1
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 } elsif (/^ENDCHAR/) { &display(); print "ENDCHAR\n";
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 } elsif (/^[ *]+$/) { chop; push(@bitmap,$_);
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 }
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 $lineno++;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 }
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 sub display {
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 my $hwidth = int((($width+7)&(~7))/4);
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 # print "hwdith $hwidth\n";
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 my $i = 0;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 for my $hex (@bitmap) {
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 my $bin;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 my $orig = $hex;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 my $j = 0;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 while($hex =~ s/..//) {
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 if ($& eq " ") {
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 $bin .= "0";
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 } elsif ($& eq "**") {
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 $bin .= "1";
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 } else {
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 print $line+$i,": Error Bad Alignment ","| "x$width,"\n";
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 print $line+$i,": Error Bad Alignment ","$orig\n";
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 last;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 }
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 if ($j++ > $width) {
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 print $line+$i,": Error Too long",substr($orig,$j),
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 "|$hex too long \n" if ($hex =~ /[^ ]/);
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 last;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 }
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 }
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 # print "bitmap $bin -- $i\n";
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 my $h = pack("B*",$bin . "0"x$width);
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 my $b = unpack("H*",$h);
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 $b = substr($b,0,$hwidth);
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 print "$b\n";
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 last if ($i++ > $height-2);
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 }
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 # print "hhhh $height-$i = ",$height-$i,"\n";
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 print (("0"x$hwidth."\n")x($height-$i)) if ($height-$i > 0);
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 }
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 sub init {
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 $name = '';
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 $encoding = 0;
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 @bitmap= ();
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 }
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
a6ddaa18e3c1 k14 unicode font kit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 # end