1 /********************************************************************
2 This file is part of the abs 0.907 distribution. abs is a spreadsheet
3 with graphical user interface.
4
5 Copyright (C) 1998-2001 Andr� Bertin (Andre.Bertin@ping.be)
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version if in the same spirit as version 2.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 Concact: abs@pi.be
22 http://home.pi.be/bertin/abs.shtml
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 #include "print.h"
59 #include "worksheet.h"
60 #include "application.h"
61 #include "main.h"
62 #include "callback.h"
63 #include "fig.h"
64 #include "gr_interf.h"
65
66 #include <stdio.h>
67
68 PrintParam printparam;
69
70
71 int
printfile(PrintParam pp)72 printfile (PrintParam pp)
73 {
74 FILE *fp;
75 int i, j;
76 double H, W;
77 int PH = 29.7 * 450;
78 int PW = 21.0 * 450;
79 int x0, y0, xn, yn;
80 Graph *gr;
81 Drawing *dr;
82 int tofile = 0;
83 char paper[10];
84 char *spc;
85 int i1, i2, j1, j2;
86 char command[256];
87 int p;
88
89 strncpy (paper, pp.papertype, 8);
90 spc = strchr (paper, ' ');
91 *spc = '\0';
92
93 if (ActiveWorksheet == NULL)
94 return -1;
95 if (ActiveWorksheet->maxrow < 1)
96 return -1;
97
98 getselection (&i1, &j1, &i2, &j2);
99
100 if (pp.what == PWKS || pp.what == PWKB || (i1 == i2 && j1 == j2) || i1 < 1 || j1 < 1
101 || i2 > ActiveWorksheet->nblin || j2 > ActiveWorksheet->nbcol)
102 {
103 i1 = 1;
104 j1 = 1;
105 i2 = ActiveWorksheet->maxrow;
106 j2 = ActiveWorksheet->_maxcol;
107
108 absijtoxy (i1, j1, &x0, &y0);
109 absijtoxy (i2 + 1, j2 + 1, &xn, &yn);
110
111
112 for (i = 0; i < getnumgra (); i++)
113 {
114 gr = (Graph *) getgra (i);
115 if (gr->x + gr->w > xn)
116 xn = gr->x + gr->w;
117 if (gr->y + gr->h > yn)
118 yn = gr->y + gr->h;
119 }
120
121 for (i = 0; i < getnumdra (); i++)
122 {
123 dr = (Drawing *) getdra (i);
124 if (dr->x2 > xn)
125 xn = dr->x2;
126 if (dr->y2 > yn)
127 yn = dr->y2;
128 if (dr->x1 > xn)
129 xn = dr->x1;
130 if (dr->y1 > yn)
131 yn = dr->y1;
132 }
133 }
134
135 else
136 {
137 absijtoxy (i1, j1, &x0, &y0);
138 absijtoxy (i2 + 1, j2 + 1, &xn, &yn);
139 }
140
141 if (pp.filename == NULL)
142 {
143 if (strstr (pp.destination, "fig"))
144 pp.filename = "output.fig";
145 else
146 pp.filename = "output.ps";
147 }
148 else
149 tofile = 1;
150
151 fp = fopen ("output.fig", "w");
152 if (fp == NULL)
153 return -1;
154 FIG_init (fp);
155
156 W = abs (xn - x0);
157 H = abs (yn - y0);
158
159
160
161 if (!strncmp (paper, "A0", 2))
162 {
163 PH = 118.9 * 450;
164 PW = 84.1 * 450;
165 }
166 if (!strncmp (paper, "A1", 2))
167 {
168 PH = 84.1 * 450;
169 PW = 59.4 * 450;
170 }
171 if (!strncmp (paper, "A2", 2))
172 {
173 PH = 59.4 * 450;
174 PW = 42.0 * 450;
175 }
176 if (!strncmp (paper, "A3", 2))
177 {
178 PH = 42.0 * 450;
179 PW = 29.7 * 450;
180 }
181 if (!strncmp (paper, "A4", 2))
182 {
183 PH = 29.7 * 450;
184 PW = 21.0 * 450;
185 }
186 if (!strncmp (paper, "B5", 2))
187 {
188 PH = 25.7 * 450;
189 PW = 18.2 * 450;
190 }
191 if (!strncmp (paper, "Ledger", 6))
192 {
193 PH = 17 * 2.54 * 450;
194 PW = 11 * 2.54 * 450;
195 }
196 if (!strncmp (paper, "Legal", 5))
197 {
198 PH = 14 * 2.54 * 450;
199 PW = 11 * 2.54 * 450;
200 }
201 if (!strncmp (paper, "Letter", 6))
202 {
203 PH = 11 * 2.54 * 450;
204 PW = 8.5 * 2.54 * 450;
205 }
206
207
208
209
210
211 if (pp.magnification == 0)
212 {
213 double Wmax, Hmax, mh = 1, mw = 1;
214 if (pp.orientation == PORTRAIT)
215 {
216 Wmax = (PW - (pp.lm + pp.rm) * 450) * pp.nbhpages;
217 Hmax = (PH - (pp.tm + pp.bm) * 450) * pp.nbvpages;
218 }
219 else
220 {
221 Hmax = (PW - (pp.lm + pp.rm) * 450) * pp.nbhpages;
222 Wmax = (PH - (pp.tm + pp.bm) * 450) * pp.nbvpages;
223 }
224 if (H * 15 > Hmax)
225 mh = Hmax / (H * 15);
226 if (W * 15 > Wmax)
227 mw = Wmax / (W * 15);
228 if (mw < mh)
229 mh = mw;
230 pp.magnification = mh * 100.0;
231 }
232
233
234 FIG_options (1200, pp.center, pp.orientation, paper);
235
236
237
238 i = x0 - pp.lm * 30;
239 j = y0 - pp.tm * 30;
240 setout (2, 15, 15, i, j);
241
242 for (i = i1; i <= i2; i++)
243 {
244 for (j = j1; j <= j2; j++)
245 {
246 xdrawcell (i, j, 5, 1);
247 }
248 }
249
250 for (i = 0; i < getnumgra (); i++)
251 {
252 gr = (Graph *) getgra (i);
253 if (gr->x >= x0 && gr->y >= y0 && gr->x + gr->w <= x0 + W
254 && gr->y + gr->h <= y0 + H)
255 doplot (gr);
256 }
257
258 for (i = 0; i < getnumdra (); i++)
259 {
260 dr = (Drawing *) getdra (i);
261 if (
262 (dr->x1 >= x0 && dr->y1 >= y0 && dr->x1 <= x0 + W
263 && dr->y1 <= y0 + H) || (dr->x2 >= x0 && dr->y2 >= y0
264 && dr->x2 <= x0 + W && dr->y2 <= y0 + H))
265 redrawdr (dr);
266 }
267
268 setout (0, 1, 1, x0, y0);
269
270 fclose (fp);
271
272 if (!strcmp (pp.destination, "fig format file"))
273 return 0;
274 if (!strcmp (pp.destination, "xfig preview"))
275 {
276 sprintf (command, "xfig %s", pp.filename);
277 system (command);
278 return 0;
279 }
280
281 if (!strcmp (pp.destination, "ghostview preview") ||
282 !strcmp (pp.destination, "postscript format file"))
283 {
284 pp.language = "ps";
285 sprintf (command, "fig2dev -L%s", pp.language);
286 if (pp.center == CENTER)
287 sprintf (command, "%s -c", command);
288
289
290
291 sprintf (command, "%s -P", command);
292 sprintf (command, "%s -z %s", command, paper);
293
294
295 sprintf (command, "%s -M", command);
296
297 sprintf (command, "%s -m %f", command, pp.magnification / 100.0);
298 if (pp.orientation == PORTRAIT)
299 {
300 sprintf (command, "%s -p xxx", command);
301 }
302 else
303 {
304 sprintf (command, "%s -l xxx", command);
305 }
306 sprintf (command, "%s -n output.ps", command);
307 p = pp.xshift;
308 sprintf (command, "%s -x %d", command, p);
309 p = pp.yshift;
310 sprintf (command, "%s -y %d", command, p);
311 sprintf (command, "%s output.fig %s", command, pp.filename);
312 fprintf (stderr, command);
313 system (command);
314 }
315 if (!strcmp (pp.destination, "ghostview preview"))
316 {
317 sprintf (command, "ghostview %s", pp.filename);
318 system (command);
319 return 0;
320 }
321
322 return 0;
323 }
324