3 $file_input="font.pnm";
4 $file_output="eutopiabold36.rle";
10 open(INPUT,$file_input) || die "Couldn't open font: $!\n";
12 $tag=<INPUT>; chop($tag);
14 { die "Couldn't process image: not a pnm file ($tag)"; }
18 $dimensions=<INPUT>; chop($dimensions);
20 if($dimensions =~ /(\d+) (\d+)/)
21 { $width=$1; $height=$2; }
23 { die "Couldn't process image: couldn't get dimensions"; }
27 print "width $width height $height\n";
29 for($j=0; $j<$height; $j++)
30 { for($i=0; $i<$width; $i++)
32 $red[$i][$j]=ord(getc(INPUT));
33 $green[$i][$j]=ord(getc(INPUT));
34 $blue[$i][$j]=ord(getc(INPUT));
43 open(OUTPUT,">".$file_output) || die "Couldn't open output: $!\n";
46 print OUTPUT pack("C2",0x36,0x05);
49 print OUTPUT pack("C",$height);
57 while($x<$width && !$blank)
59 for($y=0; $y<$height; $y++)
60 { if($blue[$x][$y]!=255)
70 while($x<$width && $blank)
72 for($y=0; $y<$height; $y++)
73 { if($blue[$x][$y]!=255)
81 $spacewidth=$xend-$xstart+$spaceborder;
82 $spacewidth=$spacewidth/2;
86 print "space start=$xstart end=$xend -> width=$spacewidth\n\n";
88 # Put space character code
89 print OUTPUT pack("C",32);
92 print OUTPUT pack("C",$spacewidth);
95 for($y=0;$y<$height;$y++)
96 { print OUTPUT pack("C",1);
97 print OUTPUT pack("C",0);
98 print OUTPUT pack("C",$spacewidth);
103 while($xstart<$width)
105 print "looking for character $char \"".chr($char)."\"\n";
107 $x=$xstart; $blank=1;
108 while($x<$width && $blank)
110 for($y=0; $y<$height; $y++)
111 { if($blue[$x][$y]!=255)
119 $x=$xstart; $blank=0;
120 while($x<$width && !$blank)
122 for($y=0; $y<$height; $y++)
123 { if($blue[$x][$y]!=255)
130 print "start=$xstart end=$xend\n";
132 $dstart=$xstart-$border;
140 print OUTPUT pack("C",$char);
142 # Put character width
143 print OUTPUT pack("C",$dend-$dstart);
145 for($y=0; $y<$height; $y++)
146 { $linecode=""; $bytecode=""; $lastcolour=-1; $count=0;
147 for($x=$dstart; $x<$dend; $x++)
149 # Transparent background
152 # Anti-aliased foreground
153 if($blue[$x][$y]<255 && $red[$x][$y]>0)
154 { $c="+"; $colour=1; }
157 if($blue[$x][$y]==255 && $red[$x][$y]==255 )
158 { $c="#"; $colour=2; }
160 # Anti-aliased shadow (same as shadow)
161 if($blue[$x][$y]<255 && $red[$x][$y]==0)
162 { $c="."; $colour=3; }
165 if($blue[$x][$y]==0 && $red[$x][$y]==0)
166 { $c=" "; $colour=3; }
170 if($colour != $lastcolour)
173 { $linecode.=" $lastcolour,$count";
174 $bytecode.=pack("C2",$lastcolour,$count);
176 $lastcolour=$colour; $count=1;
182 { $linecode.=" $lastcolour,$count";
183 $bytecode.=pack("C2",$lastcolour,$count);
185 print " [$linecode]\n";
187 # Put length of RLE line
188 print OUTPUT pack("C*",length($bytecode)/2);
191 print OUTPUT $bytecode;
201 print OUTPUT pack("C",255);