]> git.pld-linux.org Git - packages/eps2ps.git/blob - eps2ps
- cosmetics.
[packages/eps2ps.git] / eps2ps
1 #!/home/gaboret/MYBIN/perl
2 use Getopt::Std;
3 getopts('s:f:rh');
4 $scale = 1;
5 $format = "a4";
6 $rotate = 0;
7 if(defined $opt_h){
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";
16     exit 1;
17 }
18 if(defined $opt_s){
19 #    print "-s $opt_s\n";
20     $scale = $opt_s;
21 }
22 if(defined $opt_f){
23 #    print "-f $opt_f\n";
24     $format = $opt_f;
25 }
26 if(defined $opt_r){
27 #    print "-r \n";
28     $rotate = 1;
29 }
30 $format =~ s|a|A|;
31
32 # Say Hello:
33
34 print "This is Christophe Gaboret's EPS to PS Utility, 1st version\n";
35
36 # Open Input- and Output-Files
37  
38 unless ($#ARGV > -1)               # Identify arguments
39 {
40     print "Error: No Input File specified!\n";
41     exit 1;
42 }
43
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";
50         exit 1;
51     }
52 }         
53
54 @intext = <IN>;
55 close(IN);
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";
59 }
60 else{
61     print "Error: Input-File is not an EPS File!\n";
62     exit 1;
63 }
64
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";
69     exit 1;
70 }
71 print "Output-File: $outfile \n";
72
73
74 # Initialize Postscript-File
75
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";
89 print OUT "\n";
90
91
92 print OUT "%%EndProlog\n";
93 print OUT "\n";
94 print OUT "%%Page: 1 1\n";
95 print OUT "\n";
96 print OUT "gsave\n";
97
98 # Start with real paintings
99 if ($format eq "A3"){
100     $paperwidth = 841.889763779;        #a3 in pts
101     $paperheight = 2 * 595.275590551;   # height must be greater equal width!!!
102 }
103 elsif ($format eq "A2"){
104     $paperwidth = 2 * 595.275590551;    #a2 in pts
105     $paperheight = 2 * 841.889763779;   # height must be greater equal width!!!
106 }
107 elsif ($format eq "A1"){
108     $paperwidth = 2 * 841.889763779;    #a1 in pts
109     $paperheight = 4 * 595.275590551;   # height must be greater equal width!!!
110 }
111 elsif ($format eq "A0"){
112     $paperwidth = 4 * 595.275590551;    #a0 in pts
113     $paperheight = 4 * 841.889763779;   # height must be greater equal width!!!
114 }
115 else{
116     $paperwidth = 595.275590551;        #a4 in pts
117     $paperheight = 841.889763779;       # height must be greater equal width!!!
118 }
119
120 # Where's the BoundingBox?? What Fonts are needed?
121
122 $Fonts = "";
123 $bbundefined=1;
124 foreach(@intext){
125     if($_ =~ m|^%%BoundingBox:\s(-?\d+(\.\d*)?)\s(-?\d+(\.\d*)?)\s(-?\d+(\.\d*)?)\s(-?\d+(\.\d*)?)|&&$bbundefined){
126        $bbx = $1;
127        $bby = $3;
128        $bburx = $5;
129        $bbury = $7;
130        $bbw = $bburx - $bbx;
131        $bbh = $bbury - $bby;
132        $bbundefined=0;
133        print "I found this BoundingBox: $bbx $bby $bburx $bbury\n";
134 #       print "BBw= $bbw, BBh = $bbh\n";
135    }
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";
141
142    } 
143 }
144
145 #find out, if we have to rotate this stuff
146 if($bbh > $bbw){
147     $maxdim = $bbh;
148     $mindim = $bbw;
149 }
150 else{
151     $maxdim = $bbw;
152     $mindim = $bbh;
153 }
154
155 if($maxdim * $scale > $paperheight){
156     $scale = $paperheight / $maxdim * 0.95;
157     print "to fit on page $format Scale is reduced to $scale!\n";
158 }
159 if($mindim *$scale > $paperwidth){
160     $scale = $paperwidth / $mindim * 0.95;
161     print "to fit on page $format Scale is reduced to $scale!\n";
162 }
163 if($rotate == 0 && $bbw * $scale > $paperwidth){
164     $rotate = 1;
165     print "to fit on page $format figure will be rotated by 90 degrees!\n";
166 }    
167 elsif($rotate == 1 && $bbh * $scale > $paperwidth){
168     $rotate = 0;
169     print "to fit on page $format figure will not be rotated!\n";
170 }    
171     
172
173 if($rotate == 0){
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";
182 }
183 else{
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";
194 }    
195 print OUT "$scale $scale scale\n";
196 print OUT "save\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"; 
200
201 foreach(@intext){
202     print OUT "$_";
203 }
204
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";
209
210
211
212
213 print OUT "showpage\n";
214
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";
220
221 close(OUT);
222 print "\nConversion succeeded!\n\n";
223
224
225
226
This page took 0.138117 seconds and 3 git commands to generate.