#!/usr/bin/perl
# convert Fig file to HTML imagemap
# Andrew Daviel TRIUMF Dec 2003 advax@triumf.ca
#rect two 94 273 160 347
#circle circle 228 66 245 83
#poly L 275 188 329 190 328 227 399 229 399 265 283 264
#
#
# also
# alt="xx" mandatory ...
# .. now can use shape in A; see http://www.w3.org/TR/html401/struct/objects.html#adef-shape
unless ($ARGV[1]) { &usage ; exit ; }
open (IN,$ARGV[0]) or die ;
open (OUT,">$ARGV[1]") or die ;
if ($ARGV[3]) {
open (OUT2,">>$ARGV[3]") or open (OUT2,">$ARGV[3]") or die ;
$mkarea = 1 ; $out2 = '' ;
print OUT2 "\n" ;
}
unless ($apn) { $apn = 9 ; }
$indepth = 0 ;
if ($ARGV[2]) { $indepth = $ARGV[2] ; }
$_ = () ;
unless (/^#FIG 3.2/) {
die "Not a FIG version 3.2 file\n" ;
}
while () {
chomp ;
tr/ / /s ;
if (/^2 5 /) { # picture
($t,$t2,$style,$width,$fg,$bg,$depth,$u2,$fill,$angle,$u3,$u4,$u5,$u6,$u7,$npts) = split(/ /) ;
$_ = () ; chomp ; tr/ \t/ /s ; s/^ // ;
($flip,$name) = split(/ /) ;
print "Picture $name flip $flip\n" ;
$_ = () ; chomp ; tr/ \t/ /s ; s/^ // ;
@xy = split(/ /) ; $x1 = $x2 = $y1 = $y2 = '' ;
for ($i=0;$i<4;$i++) {
$x = int(shift(@xy)/15+0.5) ;
$y = int(shift(@xy)/15+0.5) ;
if ($x1 eq '' || $x < $x1) { $x1 = $x ; }
if ($x2 eq '' || $x > $x2) { $x2 = $x ; }
if ($y1 eq '' || $y < $y1) { $y1 = $y ; }
if ($y2 eq '' || $y > $y2) { $y2 = $y ; }
}
if ($depth == $indepth || !$indepth) {
$w = ($x2 - $x1) ; $h = $y2 - $y1 ;
if ($w<0) { $w = -$w ; } if ($h<0) { $h = -$h ; }
print "add picture rect $w x $h\n" ;
if ($mkarea) {
print OUT2<
\n" ;
close(OUT2) ;
}
sub usage {
print STDERR<