) {
if (/^%%BoundingBox:\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)/) {
$bbx = 0-$1; $bby = 0-$2;
$bbw = $3+$bbx; $bbh = $4+$bby;
# print "*** Seen BBOX\n";
}
last if /^%%EndComments/;
}
close(PS);
my $scale = 3;
my $density = 72*$scale;
$bbw = $scale * $bbw;
$bbh = $scale * $bbh;
# print "*** gs -q -dNOPAUSE -dNO_PAUSE -sDEVICE=ppmraw -g${bbw}x${bbh} -r$density -sOutputFile=$file.ppm\n";
open(GS, "|gs -q -dNOPAUSE -dNO_PAUSE -sDEVICE=ppmraw -g${bbw}x${bbh} -r$density -sOutputFile=$file.ppm");
print GS "$bbx $bby translate\n";
print GS "($file.ps) run\n";
print GS "showpage\n";
print GS "quit\n";
close(GS);
system("pnmcrop $file.ppm | ppmquant 256 | ppmtogif > $file.gif");
unlink "$file.ppm";
}
}
# 4. Create the HTML file
open(MP,"$main.mp") || die "cannot open $main.mp for reading: $!";
open(HTML,">$main.html") || die "cannot open $main.html for writing: $!";
select HTML;
print "Metapost : exemples\n";
print " Métapost : exemples
\n";
print "
\n";
while(){
if (m/^\s*beginfig\s*\((.*)\)/) {
print "
\n";
print ;
} elsif (m/^\s*endfig/) {
print;
print "
\n";
} else {
print;
}
}
print "
\n";
print "\n";
close HTML;
close MP;
# 5. Remove unnecessary files
opendir(DIR,"./") || die "Cannot open ./ directory for reading : $!";
foreach $file (readdir DIR) {
if ($file =~ m/^$main.[0-9]+$/) {
unlink $file;
unlink "$file.tex";
unlink "$file.dvi";
unlink "$file.aux";
unlink "$file.log";
unlink "$file.eps";
unlink "$file.ps";
my $new = $file;
$new =~ s/\./_/g;
$new .= ".mps";
unlink $new;
} elsif( $file =~ m/\.mpx$/ ) {
unlink $file;
}
}
closedir DIR;
unlink "$main.aux";
unlink "$main.log";