]> git.pld-linux.org Git - packages/eps2ps.git/blame - eps2ps
- remove author name
[packages/eps2ps.git] / eps2ps
CommitLineData
5d87b965
SZ
1#!/home/gaboret/MYBIN/perl
2use Getopt::Std;
3getopts('s:f:rh');
4$scale = 1;
5$format = "a4";
6$rotate = 0;
7if(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}
18if(defined $opt_s){
19# print "-s $opt_s\n";
20 $scale = $opt_s;
21}
22if(defined $opt_f){
23# print "-f $opt_f\n";
24 $format = $opt_f;
25}
26if(defined $opt_r){
27# print "-r \n";
28 $rotate = 1;
29}
30$format =~ s|a|A|;
31
32# Say Hello:
33
34print "This is Christophe Gaboret's EPS to PS Utility, 1st version\n";
35
36# Open Input- and Output-Files
37
38unless ($#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
45unless(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>;
55close(IN);
56print "Input-File: $infile \n";
57if($intext[0] =~ m|^%!PS-Adobe.*EPSF.*|){
58 print "Wow! Input-File is really an EPS File!\n";
59}
60else{
61 print "Error: Input-File is not an EPS File!\n";
62 exit 1;
63}
64
65if($#ARGV > 0){$outfile = $ARGV[1];}
66else{$outfile = $infile.".ps";}
67unless(open(OUT,">".$outfile)){
68 print "Error: Cannot open Output-File!\n";
69 exit 1;
70}
71print "Output-File: $outfile \n";
72
73
74# Initialize Postscript-File
75
76print OUT "%!PS-Adobe-2.0\n";
77print OUT "%%Title: PS-File including EPS-File $infile\n";
78print OUT "%%Creator: Andy's eps2ps Utility, Ver. 0.00\n";
79print OUT "%%For: $ENV{USER}"."@"."$ENV{HOST}\n";
80print OUT "%%Pages: 1\n";
81print OUT "%%Orientation: Portrait\n";
82print OUT "%%BoundingBox: (atend)\n";
83print OUT "%%DocumentFonts: (atend)\n";
84print OUT "%%BeginSetup\n";
85print OUT "%%IncludeFeature: *PageSize $format\n";
86print OUT "%%EndSetup\n";
87print OUT "%%EndComments\n";
88print OUT "% Input-File: $ENV{PWD}/$infile\n";
89print OUT "\n";
90
91
92print OUT "%%EndProlog\n";
93print OUT "\n";
94print OUT "%%Page: 1 1\n";
95print OUT "\n";
96print OUT "gsave\n";
97
98# Start with real paintings
99if ($format eq "A3"){
100 $paperwidth = 841.889763779; #a3 in pts
101 $paperheight = 2 * 595.275590551; # height must be greater equal width!!!
102}
103elsif ($format eq "A2"){
104 $paperwidth = 2 * 595.275590551; #a2 in pts
105 $paperheight = 2 * 841.889763779; # height must be greater equal width!!!
106}
107elsif ($format eq "A1"){
108 $paperwidth = 2 * 841.889763779; #a1 in pts
109 $paperheight = 4 * 595.275590551; # height must be greater equal width!!!
110}
111elsif ($format eq "A0"){
112 $paperwidth = 4 * 595.275590551; #a0 in pts
113 $paperheight = 4 * 841.889763779; # height must be greater equal width!!!
114}
115else{
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;
124foreach(@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
146if($bbh > $bbw){
147 $maxdim = $bbh;
148 $mindim = $bbw;
149}
150else{
151 $maxdim = $bbw;
152 $mindim = $bbh;
153}
154
155if($maxdim * $scale > $paperheight){
156 $scale = $paperheight / $maxdim * 0.95;
157 print "to fit on page $format Scale is reduced to $scale!\n";
158}
159if($mindim *$scale > $paperwidth){
160 $scale = $paperwidth / $mindim * 0.95;
161 print "to fit on page $format Scale is reduced to $scale!\n";
162}
163if($rotate == 0 && $bbw * $scale > $paperwidth){
164 $rotate = 1;
165 print "to fit on page $format figure will be rotated by 90 degrees!\n";
166}
167elsif($rotate == 1 && $bbh * $scale > $paperwidth){
168 $rotate = 0;
169 print "to fit on page $format figure will not be rotated!\n";
170}
171
172
173if($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}
183else{
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}
195print OUT "$scale $scale scale\n";
196print OUT "save\n";
197print OUT "/showpage {} def\n";
198print OUT "\n%\n% Imported EPS-File starts here!\n%\n";
199print OUT "%%BeginDocument: $ENV{PWD}/$infile\n%\n";
200
201foreach(@intext){
202 print OUT "$_";
203}
204
205print OUT "\n%\n% Imported EPS-File ends here!\n%\n";
206print OUT "%%EndDocument\n%\n";
207print OUT "restore\n";
208print OUT "grestore\n";
209
210
211
212
213print OUT "showpage\n";
214
215print OUT "%%Trailer\n";
216$BBoxurX = $BBoxW+$BBoxX;
217$BBoxurY = $BBoxH+$BBoxY;
218print OUT "%%BoundingBox: $BBoxX $BBoxY $BBoxurX $BBoxurY\n";
219print OUT "%%DocumentFonts:$Fonts\n";
220
221close(OUT);
222print "\nConversion succeeded!\n\n";
223
224
225
226
This page took 0.089974 seconds and 4 git commands to generate.