1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
#!/usr/local/bin/perl
#
# This is mathlabels, Copyright 1992 Silvio Levy
# $Header: /u/levy/RCS/mathlabels.orig,v 1.3 1994/09/19 02:08:15 levy Exp $
#
#
# first argument: file name for labels
# second to fifth arguments: xlo, xhi, ylo, yhi (to fix the aspect ratio)
# use OK for these arguments if no changes need to be made
#
die "$0 file.lab xlo xhi ylo yho < file_orig.ps > file.ps\n (use OK"
. " for the last four args)\n"
if ($#ARGV != 4);
$filename=$ARGV[0]; shift;
$xlo=$ARGV[0]; shift;
$xhi=$ARGV[0]; shift;
$ylo=$ARGV[0]; shift;
$yhi=$ARGV[0]; shift;
die "Can't open $filename" unless open(labels,">$filename");
#
# get various parameters output by psfix
#
while (<>) {
print;
last if (/^MathPictureStart/);
($trash,$lmarg)=split(' ') if (/\/Mlmarg/);
($trash,$rmarg)=split(' ') if (/\/Mrmarg/);
($trash,$bmarg)=split(' ') if (/\/Mbmarg/);
($trash,$tmarg)=split(' ') if (/\/Mtmarg/);
($trash,$width)=split(' '), $width*=72 if (/\/Mwidth/);
($trash,$height)=split(' '), $height*=72 if (/\/Mheight/);
($trash,$nodistort)=split(' ') if (/\/Mnodistort/);
}
&doit(0,0,$width,$height);
sub doit {
local($XLO,$YLO,$XHI,$YHI)=@_; # target bounding box
local($Ax,$Bx,$Ay,$By);
line:
while (<>) {
return if (/^MathSubEnd/);
if (/ MathSubStart/) {
($Xlo,$Ylo,$Xhi,$Yhi) = split(' ');
print;
&doit($Xlo*$Ax+$Bx,$Ylo*$Ay+$By,$Xhi*$Ax+$Bx,$Yhi*$Ay+$By);
}
#
# look between the lines
#
# % Scaling calculations
# ... [
# ] MathScale
#
# to mimic the action of MathScale
#
if (/% Scaling calculations/) {
$collecting=1;
$npts=-2;
}
if ($collecting) { #[
if (/] MathScale/) {
#
# do the calculations
#
$collecting=0;
$i=0;
while ($i<$npts-2) {
print($point[$npts]);
}
($trash,$gxlow,$gylow) = split(' ',$point[$npts-2]);
$gxlow=$xlo unless ($xlo=~/OK/);
$gylow=$ylo unless ($ylo=~/OK/);
print("[ $gxlow $gylow 0 0 ]\n");
($trash,$gxhigh,$gyhigh) = split(' ',$point[$npts-1]);
$gxhigh=$xhi unless ($xhi=~/OK/);
$gyhigh=$yhi unless ($yhi=~/OK/);
print("[ $gxhigh $gyhigh 0 0 ]\n");
($Ax,$Ay,$Bx,$By) =
&findpars($XLO,$YLO,$XHI,$YHI,$gxlow,$gylow,$gxhigh,$gyhigh);
print;
} else {
#
# put scaling lines into an array
#
if ($npts>=0) {
if (!/Msboxa/ && !/Mrotsboxa/) {
$point[$npts] = $_;
$npts++;
}
} else {
print;
$npts++;
}
}
next line;
}
#
# issue labeling command
#
if (/\[\((.*)\)\] *([^ ]*) *([^ ]*) *([^ ]*) *([^ ]*) *(.*Mrotshowa|Mshowa)/) {
$_=$1;
$xpos=$2*$Ax+$Bx;
$ypos=$3*$Ay+$By;
$xrelpos=$4;
$yrelpos=$5;
s/\\([\\()])/$1/g;
printf labels ("\\setlabel{%s}{%f}{%f}{%f}{%f}\n",
$_,$xpos,$ypos,$xrelpos,$yrelpos);
next line;
}
print;
}
}
sub findpars {
local($xlow,$ylow,$xhigh,$yhigh,$gxlow,$gylow,$gxhigh,$gyhigh)=@_;
local ($Ax,$Ay,$Bx,$By);
$Ax=($xhigh-$xlow)/($gxhigh-$gxlow);
$Ay=($yhigh-$ylow)/($gyhigh-$gylow);
if ($nodistort=~/true/) {
$Ax=$Ay if ($Ax>$Ay);
$Ay=$Ax if ($Ay>$Ax);
}
$Bx=(($xlow+$xhigh)-($gxlow+$gxhigh)*$Ax)/2;
$By=(($ylow+$yhigh)-($gylow+$gyhigh)*$Ay)/2;
return($Ax,$Ay,$Bx,$By);
}
|