1 /* output-sk.c - output in sketch format
2 
3    Copyright (C) 1999, 2000, 2001 Bernhard Herzog
4 
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public License
7    as published by the Free Software Foundation; either version 2.1 of
8    the License, or (at your option) any later version.
9 
10    This library is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18    USA. */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif /* Def: HAVE_CONFIG_H */
23 
24 #include "spline.h"
25 #include "color.h"
26 #include "output-sk.h"
27 
28 static void
out_splines(FILE * file,spline_list_array_type shape)29 out_splines (FILE * file, spline_list_array_type shape)
30 {
31   unsigned this_list;
32   spline_list_type list;
33 
34   color_type last_color = {0,0,0};
35 
36   for (this_list = 0; this_list < SPLINE_LIST_ARRAY_LENGTH (shape);
37     this_list++)
38     {
39       unsigned this_spline;
40       spline_type first;
41 
42       list = SPLINE_LIST_ARRAY_ELT (shape, this_list);
43       first = SPLINE_LIST_ELT (list, 0);
44 
45       if (this_list == 0 || !COLOR_EQUAL(list.color, last_color))
46         {
47           if (this_list > 0 && !shape.centerline)
48             fputs("bC()\n", file);
49           fprintf(file, (shape.centerline || list.open) ? "lp((%g,%g,%g))\n"
50             : "fp((%g,%g,%g))\n", list.color.r / 255.0,
51             list.color.g / 255.0, list.color.b / 255.0);
52           fputs((shape.centerline || list.open) ? "fe()\n" : "le()\n", file); /* no outline */
53             last_color = list.color;
54           fputs("b()\n", file); /* the beginning of a bezier object */
55 	    }
56 
57       fprintf(file, "bs(%g,%g,0)\n",
58         START_POINT(first).x, START_POINT(first).y);
59 
60       for (this_spline = 0; this_spline < SPLINE_LIST_LENGTH (list);
61 	     this_spline++)
62         {
63           spline_type s = SPLINE_LIST_ELT (list, this_spline);
64 
65           if (SPLINE_DEGREE(s) == LINEARTYPE)
66             fprintf(file, "bs(%g,%g,0)\n", END_POINT(s).x, END_POINT(s).y);
67           else
68             fprintf(file, "bc(%g,%g,%g,%g,%g,%g,0)\n",
69               CONTROL1(s).x, CONTROL1(s).y,
70               CONTROL2(s).x, CONTROL2(s).y,
71               END_POINT(s).x, END_POINT(s).y);
72         }
73     }
74   if (SPLINE_LIST_ARRAY_LENGTH(shape) > 0 && !shape.centerline)
75 	  fputs("bC()\n", file);
76 }
77 
78 
output_sk_writer(FILE * file,at_string name,int llx,int lly,int urx,int ury,at_output_opts_type * opts,spline_list_array_type shape,at_msg_func msg_func,at_address msg_data)79 int output_sk_writer(FILE* file, at_string name,
80 		     int llx, int lly, int urx, int ury,
81 		     at_output_opts_type * opts,
82 		     spline_list_array_type shape,
83 		     at_msg_func msg_func, at_address msg_data)
84 {
85   fputs("##Sketch 1 0\n", file);
86   fputs("document()\n", file);
87   fputs("layer('Layer 1',1,1,0,0)\n", file);
88   fputs("guess_cont()\n", file);
89 
90   out_splines(file, shape);
91   return 0;
92 }
93