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 #include <stdlib.h>
53 #include <stdio.h>
54 #include "math.h"
55 #include "print.h"
56
57
58
59 typedef struct f_pos
60 {
61 int x, y;
62 }
63 F_pos;
64
65
66 int
compute_arccenter(p1,p2,p3,x,y)67 compute_arccenter (p1, p2, p3, x, y)
68 F_pos p1, p2, p3;
69 float *x, *y;
70 {
71 double s12, s13, len1, len2, len3, dx12, dy12, dx13, dy13;
72 double resx, resy;
73
74 if ((p1.x == p3.x && p1.y == p3.y) ||
75 (p1.x == p2.x && p1.y == p2.y) ||
76 (p2.x == p3.x && p2.y == p3.y))
77 {
78 return 0;
79 }
80
81 dx12 = p1.x - p2.x;
82 dy12 = p1.y - p2.y;
83 dx13 = p1.x - p3.x;
84 dy13 = p1.y - p3.y;
85
86 s12 = asin (dy12 / sqrt (dx12 * dx12 + dy12 * dy12));
87 s13 = asin (dy13 / sqrt (dx13 * dx13 + dy13 * dy13));
88
89
90
91 len1 = (double) p1.x * (double) p1.x + (double) p1.y * (double) p1.y;
92 len2 = (double) p2.x * (double) p2.x + (double) p2.y * (double) p2.y;
93 len3 = (double) p3.x * (double) p3.x + (double) p3.y * (double) p3.y;
94 resy = (dx12 * (len3 - len1) - dx13 * (len2 - len1)) /
95 (2 * (dx13 * dy12 - dx12 * dy13));
96 if (p1.x != p3.x)
97 resx = (len3 + 2 * (resy) * dy13 - len1) / (2 * (-dx13));
98 else
99 resx = (len2 + 2 * (resy) * dy12 - len1) / (2 * (-dx12));
100 *x = (float) resx;
101 *y = (float) resy;
102 return 1;
103 }
104
105
106 FILE *outfile;
107 static int selfont = -1;
108 static int selsize = 10;
109 static int selcolor = -1;
110
111 int
FIG_write(buf)112 FIG_write (buf)
113 char *buf;
114 {
115 fprintf (outfile, "%s\n", buf);
116 return 0;
117 }
118
119 int
FIG_set_size(x,y)120 FIG_set_size (x, y)
121 int x, y;
122 {
123 return 0;
124
125 }
126
127 #define abs_Ncolors 46
128
129 static char abs_color_values[abs_Ncolors][14] =
130 {
131 "white", "black", "#C000C000C000", "#800080008000", "#990033000000", "#330033000000",
132 "#000000", "#9a3000", "#303000", "#003000", "#003065", "#000082", "#30309a", "#303030",
133 "#820000", "#ff6500", "#828200", "#008200", "#008282", "#0000ff", "#65659a", "#828282",
134 "#ff0000", "#ff9a00", "#9acf00", "#309a65", "#30cfcf", "#3065ff", "#820082", "#969696",
135 "#ff00ff", "#ffcf00", "#ffff00", "#00ff00", "#00ffff", "#00cfff", "#9a3065", "#c3c3c3",
136 "#ff9acf", "#ffcf9a", "#ffff9a", "#cfffcf", "#cfffff", "#9acfff", "#cf9aff", "#ffffff"
137 };
138
139 int
FIG_options(int resolution,int center,int orientation,char * paper)140 FIG_options (int resolution, int center, int orientation, char *paper)
141 {
142 int i;
143 if (orientation == PORTRAIT)
144 FIG_write ("Portrait");
145 else
146 FIG_write ("Landscape");
147
148 if (center == CENTER)
149 FIG_write ("Center");
150 else
151 FIG_write ("Flush left");
152
153 FIG_write ("Inches");
154 FIG_write (paper);
155 FIG_write ("100.00");
156 FIG_write ("Single");
157 FIG_write ("-2");
158 FIG_write ("1200 2");
159 for (i = 6; i < abs_Ncolors; i++)
160 {
161 fprintf (outfile, "0 %d %s\n", 32 - 6 + i, abs_color_values[i]);
162 }
163 return 0;
164 }
165
166 int
FIG_init(name)167 FIG_init (name)
168 FILE *name;
169 {
170 outfile = name;
171 FIG_write ("#FIG 3.2");
172 return 0;
173 }
174
175 int
FIG_setcol(col)176 FIG_setcol (col)
177 int col;
178 {
179
180 switch (col)
181 {
182 case 0:
183 selcolor = 7;
184 break;
185 case 1:
186 selcolor = 0;
187 break;
188 case 2:
189 selcolor = 0;
190 break;
191 case 3:
192 selcolor = 0;
193 break;
194 case 4:
195 selcolor = 0;
196 break;
197 case 5:
198 selcolor = 0;
199 break;
200 case 45:
201 selcolor = 7;
202 break;
203 default:
204 selcolor = col - 6 + 32;
205 break;
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242 }
243 return 0;
244 }
245
246
247 int
FIG_graphics()248 FIG_graphics ()
249 {
250 return 0;
251 }
252
253 int
FIG_fillarc(x1,y1,w,h,a1,a2)254 FIG_fillarc (x1, y1, w, h, a1, a2)
255 long x1, y1, w, h, a1, a2;
256 {
257 long centerx, centery, x2, y2, x3, y3;
258 F_pos p1, p2, p3;
259 int pi = 90 * 64;
260 float cx, cy;
261
262 w = w / 2;
263 h = h / 2;
264 centerx = x1 + w;
265 centery = y1 + h;
266
267 if (a1 == 0 && a2 == pi)
268 {
269 x1 = centerx;
270 y1 = centery - h;
271 x2 = centerx + 1.44 * w / 2;
272 y2 = centery - 1.44 * h / 2;
273 x3 = centerx + w;
274 y3 = centery;
275
276 }
277 else if (a1 == -pi && a2 == pi)
278 {
279 x1 = centerx + w;
280 y1 = centery;
281 x2 = centerx + 1.44 * w / 2;
282 y2 = centery + 1.44 * h / 2;
283 x3 = centerx;
284 y3 = centery + h;
285
286 }
287 else if (a1 == 2 * pi && a2 == pi)
288 {
289 x1 = centerx;
290 y1 = centery + h;
291 x2 = centerx - 1.44 * w / 2;
292 y2 = centery + 1.44 * h / 2;
293 x3 = centerx - w;
294 y3 = centery;
295
296 }
297 else if (a1 == pi && a2 == pi)
298 {
299 x1 = centerx - w;
300 y1 = centery;
301 x2 = centerx - 1.44 * w / 2;
302 y2 = centery - 1.44 * h / 2;
303 x3 = centerx;
304 y3 = centery - h;
305
306 }
307 else
308 {
309
310 x1 = centerx - w;
311 y1 = centery - h;
312 x2 = centerx;
313 y2 = centery;
314 x3 = centerx + w;
315 y3 = centery + h;
316
317 fprintf (outfile, "%d %d %d %d %d %d %d %d %d %.3f %d %.4f %ld %ld %ld %ld %ld %ld %ld %ld\n",
318 1, 0, 0, 1,
319 selcolor, selcolor, 0, 20, -1,
320 0.00, 1, 0.00,
321 x2, y2,
322 w, h,
323 x1, y1,
324 x3, y3);
325
326
327 return 0;
328 }
329
330 p1.x = x1;
331 p1.y = y1;
332 p2.x = x2;
333 p2.y = y2;
334 p3.x = x3;
335 p3.y = y3;
336
337 compute_arccenter (p1, p2, p3, &cx, &cy);
338
339
340 fprintf (outfile, "%d %d %d %d %d %d %d %d %d %.3f %d %d %d %d %.3f %.3f %ld %ld %ld %ld %ld %ld\n",
341 5, 0, 0, 1,
342 selcolor, 0, 0, 0, -1,
343 0.00, 0, 0,
344 0, 0,
345 cx, cy,
346 x1, y1,
347 x2, y2,
348 x3, y3);
349
350 return 0;
351
352 }
353
354 int
FIG_arc(x1,y1,w,h,a1,a2)355 FIG_arc (x1, y1, w, h, a1, a2)
356 long x1, y1, w, h, a1, a2;
357 {
358 long centerx, centery, x2, y2, x3, y3;
359 F_pos p1, p2, p3;
360 int pi = 90 * 64;
361 float cx, cy;
362
363 w = w / 2;
364 h = h / 2;
365 centerx = x1 + w;
366 centery = y1 + h;
367
368 if (a1 == 0 && a2 == pi)
369 {
370 x1 = centerx;
371 y1 = centery - h;
372 x2 = centerx + 1.44 * w / 2;
373 y2 = centery - 1.44 * h / 2;
374 x3 = centerx + w;
375 y3 = centery;
376
377 }
378 else if (a1 == -pi && a2 == pi)
379 {
380 x1 = centerx + w;
381 y1 = centery;
382 x2 = centerx + 1.44 * w / 2;
383 y2 = centery + 1.44 * h / 2;
384 x3 = centerx;
385 y3 = centery + h;
386
387 }
388 else if (a1 == 2 * pi && a2 == pi)
389 {
390 x1 = centerx;
391 y1 = centery + h;
392 x2 = centerx - 1.44 * w / 2;
393 y2 = centery + 1.44 * h / 2;
394 x3 = centerx - w;
395 y3 = centery;
396
397 }
398 else if (a1 == pi && a2 == pi)
399 {
400 x1 = centerx - w;
401 y1 = centery;
402 x2 = centerx - 1.44 * w / 2;
403 y2 = centery - 1.44 * h / 2;
404 x3 = centerx;
405 y3 = centery - h;
406
407 }
408 else
409 {
410
411 x1 = centerx - w;
412 y1 = centery - h;
413 x2 = centerx;
414 y2 = centery;
415 x3 = centerx + w;
416 y3 = centery + h;
417
418
419 fprintf (outfile, "%d %d %d %d %d %d %d %d %d %.3f %d %.4f %ld %ld %ld %ld %ld %ld %ld %ld\n",
420 1, 0, 0, 1,
421 selcolor, 0, 0, 0, -1,
422 0.00, 1, 0.00,
423 x2, y2,
424 w, h,
425 x1, y1,
426 x3, y3);
427
428
429 return 0;
430
431 }
432 p1.x = x1;
433 p1.y = y1;
434 p2.x = x2;
435 p2.y = y2;
436 p3.x = x3;
437 p3.y = y3;
438
439 compute_arccenter (p1, p2, p3, &cx, &cy);
440
441
442 fprintf (outfile, "%d %d %d %d %d %d %d %d %d %.3f %d %d %d %d %.3f %.3f %ld %ld %ld %ld %ld %ld\n",
443 5, 0, 0, 1,
444 selcolor, 0, 0, 0, -1,
445 0.00, 0, 0,
446 0, 0,
447 cx, cy,
448 x1, y1,
449 x2, y2,
450 x3, y3);
451
452
453
454
455
456
457
458
459
460
461 return 0;
462 }
463
464 int
FIG_rectangle(x1,y1,w,h)465 FIG_rectangle (x1, y1, w, h)
466 int x1, y1, w, h;
467 {
468
469 int x2 = x1 + w;
470 int y2 = y1 + h;
471
472 fprintf (outfile, "2 2 0 1 %d 7 0 0 -1 0.000 0 0 -1 0 0 5\n", selcolor);
473 fprintf (outfile, " %d %d %d %d %d %d %d %d %d %d\n", x1, y1, x2, y1, x2, y2, x1, y2, x1, y1);
474
475
476 return 0;
477 }
478
479 int
FIG_fillrectangle(x1,y1,w,h,d)480 FIG_fillrectangle (x1, y1, w, h, d)
481 int x1, y1, w, h, d;
482 {
483
484 int x2 = x1 + w;
485 int y2 = y1 + h;
486
487 fprintf (outfile, "2 2 0 1 %d %d %d 0 20 0.000 0 0 -1 0 0 5\n", selcolor, selcolor, d);
488 fprintf (outfile, " %d %d %d %d %d %d %d %d %d %d\n", x1, y1, x2, y1, x2, y2, x1, y2, x1, y1);
489
490 return 0;
491 }
492
493
494 int
FIG_linetype(linetype)495 FIG_linetype (linetype)
496 int linetype;
497 {
498 return 0;
499 }
500
501 int
FIG_line(x1,y1,x2,y2)502 FIG_line (x1, y1, x2, y2)
503 long x1, y1, x2, y2;
504 {
505 fprintf (outfile, "2 1 0 1 %d 7 0 0 -1 0.000 0 0 -1 0 0 2\n", selcolor);
506 fprintf (outfile, " %ld %ld %ld %ld\n", x1, y1, x2, y2);
507 return 0;
508 }
509
510 int
FIG_setfont(font,fontw,fonts)511 FIG_setfont (font, fontw, fonts)
512 int font, fontw, fonts;
513 {
514
515 switch (font)
516 {
517 case 0:
518 {
519 selfont = -1;
520 break;
521 }
522 case 1:
523 {
524 switch (fontw)
525 {
526 case 0:
527 selfont = 12;
528 break;
529 case 1:
530 selfont = 14;
531 break;
532 case 2:
533 selfont = 13;
534 break;
535 case 3:
536 selfont = 15;
537 break;
538 }
539 break;
540 }
541 case 2:
542 {
543 switch (fontw)
544 {
545 case 0:
546 selfont = 16;
547 break;
548 case 1:
549 selfont = 18;
550 break;
551 case 2:
552 selfont = 17;
553 break;
554 case 3:
555 selfont = 19;
556 break;
557 }
558 break;
559 }
560 case 3:
561 {
562 switch (fontw)
563 {
564 case 0:
565 selfont = 0;
566 break;
567 case 1:
568 selfont = 2;
569 break;
570 case 2:
571 selfont = 1;
572 break;
573 case 3:
574 selfont = 3;
575 break;
576 }
577 break;
578 }
579 case 4:
580 {
581 selfont = 32;
582 break;
583
584 }
585 }
586
587 switch (fonts)
588 {
589 case 0:
590 {
591 selsize = 6;
592 break;
593 }
594 case 1:
595 {
596 selsize = 8;
597 break;
598 }
599 case 2:
600 {
601 selsize = 10;
602 break;
603 }
604 case 3:
605 {
606 selsize = 12;
607 break;
608 }
609 case 4:
610 {
611 selsize = 14;
612 break;
613 }
614 case 5:
615 {
616 selsize = 18;
617 break;
618 }
619 case 6:
620 {
621 selsize = 24;
622 break;
623 }
624
625 }
626
627
628 return 0;
629 }
630
631 int
FIG_put_text(x,y,str)632 FIG_put_text (x, y, str)
633 long x, y;
634 char *str;
635 {
636 if (str == NULL)
637 return 0;
638 if (strlen (str) < 1)
639 return 0;
640 fprintf (outfile, "4 0 %d 0 0 %d %d 0.0 4 130 1000 %ld %ld %s\\001\n", selcolor, selfont, selsize, x, y, str);
641 return 0;
642 }
643
644 int
FIG_text_angle(ang)645 FIG_text_angle (ang)
646 int ang;
647 {
648 return 0;
649 }
650
651 int
FIG_justify_text(mode)652 FIG_justify_text (mode)
653 int mode;
654 {
655
656 return 0;
657 }
658
659
660 int
FIG_point(x,y,number)661 FIG_point (x, y, number)
662 int x, y;
663 int number;
664 {
665 return 0;
666 }
667