1 #!/home/gaboret/MYBIN/perl
8 print "\nUsage: eps2ps [ -s Scale ] [ -f Format ] [ -r ] infile [ outfile ]\n\n";
9 print "DESCRIPTION:\n";
10 print "eps2ps converts Encapsulated Postscript (*.eps) files to\n";
11 print "Postscript (.ps) format.\n";
12 print "eps2ps is not guaranteed to work with all *.eps files on earth!!!\n\n";
13 print "-s defines the scale factor. It's limited to the paper's extents.\n";
14 print "-f defines the paper format (A0-A4). Default is A4.\n";
15 print "-r rotates the plot by 90 deg.\n\n";
19 # print "-s $opt_s\n";
23 # print "-f $opt_f\n";
34 print "This is Christophe Gaboret's EPS to PS Utility, 1st version\n";
36 # Open Input- and Output-Files
38 unless ($#ARGV > -1) # Identify arguments
40 print "Error: No Input File specified!\n";
44 $infile = $ARGV[0]; # Try to open Input
45 unless(open(IN,"<".$infile)){
46 print "Input-File $infile is empty, I will try $infile".".eps!\n";
47 $infile = $infile.".eps"; # forgotten .eps ending ?
48 unless(open(IN,"<".$infile)){
49 print "Error: Input-File $infile is empty, too!\n";
56 print "Input-File: $infile \n";
57 if($intext[0] =~ m|^%!PS-Adobe.*EPSF.*|){
58 print "Wow! Input-File is really an EPS File!\n";
61 print "Error: Input-File is not an EPS File!\n";
65 if($#ARGV > 0){$outfile = $ARGV[1];}
66 else{$outfile = $infile.".ps";}
67 unless(open(OUT,">".$outfile)){
68 print "Error: Cannot open Output-File!\n";
71 print "Output-File: $outfile \n";
74 # Initialize Postscript-File
76 print OUT "%!PS-Adobe-2.0\n";
77 print OUT "%%Title: PS-File including EPS-File $infile\n";
78 print OUT "%%Creator: Andy's eps2ps Utility, Ver. 0.00\n";
79 print OUT "%%For: $ENV{USER}"."@"."$ENV{HOST}\n";
80 print OUT "%%Pages: 1\n";
81 print OUT "%%Orientation: Portrait\n";
82 print OUT "%%BoundingBox: (atend)\n";
83 print OUT "%%DocumentFonts: (atend)\n";
84 print OUT "%%BeginSetup\n";
85 print OUT "%%IncludeFeature: *PageSize $format\n";
86 print OUT "%%EndSetup\n";
87 print OUT "%%EndComments\n";
88 print OUT "% Input-File: $ENV{PWD}/$infile\n";
92 print OUT "%%EndProlog\n";
94 print OUT "%%Page: 1 1\n";
98 # Start with real paintings
100 $paperwidth = 841.889763779; #a3 in pts
101 $paperheight = 2 * 595.275590551; # height must be greater equal width!!!
103 elsif ($format eq "A2"){
104 $paperwidth = 2 * 595.275590551; #a2 in pts
105 $paperheight = 2 * 841.889763779; # height must be greater equal width!!!
107 elsif ($format eq "A1"){
108 $paperwidth = 2 * 841.889763779; #a1 in pts
109 $paperheight = 4 * 595.275590551; # height must be greater equal width!!!
111 elsif ($format eq "A0"){
112 $paperwidth = 4 * 595.275590551; #a0 in pts
113 $paperheight = 4 * 841.889763779; # height must be greater equal width!!!
116 $paperwidth = 595.275590551; #a4 in pts
117 $paperheight = 841.889763779; # height must be greater equal width!!!
120 # Where's the BoundingBox?? What Fonts are needed?
125 if($_ =~ m|^%%BoundingBox:\s(-?\d+(\.\d*)?)\s(-?\d+(\.\d*)?)\s(-?\d+(\.\d*)?)\s(-?\d+(\.\d*)?)|&&$bbundefined){
130 $bbw = $bburx - $bbx;
131 $bbh = $bbury - $bby;
133 print "I found this BoundingBox: $bbx $bby $bburx $bbury\n";
134 # print "BBw= $bbw, BBh = $bbh\n";
136 elsif($_ =~ m|^%%DocumentFonts:([\w\s]+)$|){
137 $Fonts = join(' ',$Fonts,$1);
138 $Fonts =~ s/\(atend\)//g;
139 $Fonts =~ s/\s\s+/ /g;
140 print "I found these DocumentFonts:$Fonts\n";
145 #find out, if we have to rotate this stuff
155 if($maxdim * $scale > $paperheight){
156 $scale = $paperheight / $maxdim * 0.95;
157 print "to fit on page $format Scale is reduced to $scale!\n";
159 if($mindim *$scale > $paperwidth){
160 $scale = $paperwidth / $mindim * 0.95;
161 print "to fit on page $format Scale is reduced to $scale!\n";
163 if($rotate == 0 && $bbw * $scale > $paperwidth){
165 print "to fit on page $format figure will be rotated by 90 degrees!\n";
167 elsif($rotate == 1 && $bbh * $scale > $paperwidth){
169 print "to fit on page $format figure will not be rotated!\n";
174 $xorig = $paperwidth/2-$bbw*$scale/2-$bbx*$scale;
175 $yorig = $paperheight/2-$bbh*$scale/2-$bby*$scale;
176 print OUT "$xorig $yorig translate\n";
177 $BBoxX = $xorig + $bbx * $scale;
178 $BBoxY = $yorig + $bby * $scale;
179 $BBoxW = $bbw * $scale;
180 $BBoxH = $bbh * $scale;
181 print "Scale is $scale, picture is not rotated\n";
184 $xorig = $paperheight/2-$bbw*$scale/2-$bbx*$scale;
185 $yorig = $paperwidth/2-$bbh*$scale/2-$bby*$scale;
186 print OUT "$paperwidth 0 translate\n";
187 print OUT "90 rotate\n";
188 print OUT "$xorig $yorig translate\n";
189 $BBoxX = $paperwidth/2-$bbh*$scale/2;
190 $BBoxY = $paperheight/2-$bbw*$scale/2;
191 $BBoxW = $bbh*$scale;
192 $BBoxH = $bbw*$scale;
193 print "Scale is $scale, picture is rotated by 90 degrees\n";
195 print OUT "$scale $scale scale\n";
197 print OUT "/showpage {} def\n";
198 print OUT "\n%\n% Imported EPS-File starts here!\n%\n";
199 print OUT "%%BeginDocument: $ENV{PWD}/$infile\n%\n";
205 print OUT "\n%\n% Imported EPS-File ends here!\n%\n";
206 print OUT "%%EndDocument\n%\n";
207 print OUT "restore\n";
208 print OUT "grestore\n";
213 print OUT "showpage\n";
215 print OUT "%%Trailer\n";
216 $BBoxurX = $BBoxW+$BBoxX;
217 $BBoxurY = $BBoxH+$BBoxY;
218 print OUT "%%BoundingBox: $BBoxX $BBoxY $BBoxurX $BBoxurY\n";
219 print OUT "%%DocumentFonts:$Fonts\n";
222 print "\nConversion succeeded!\n\n";