1 /* output-swf.c - output in SWF format
2
3 Copyright (C) 1999, 2000, 2001 Kevin O' Gorman <spidey@maths.tcd.ie>
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-swf.h"
27 #include <ming/libming.h>
28
29 #define FPS 24.0
30 #define IMGID 1
31 #define IMGLAYER 1
32 #define SWFSCALE 20
33
34 static void
out_splines(SWFMovie m,spline_list_array_type shape,int height)35 out_splines (SWFMovie m, spline_list_array_type shape, int height)
36 {
37 unsigned this_list;
38 color_type last_color = {0,0,0};
39
40 for (this_list = 0; this_list < SPLINE_LIST_ARRAY_LENGTH (shape);
41 this_list++)
42 {
43 SWFShape k;
44
45 unsigned this_spline;
46 spline_list_type list = SPLINE_LIST_ARRAY_ELT (shape, this_list);
47 spline_type first = SPLINE_LIST_ELT (list, 0);
48
49 if (this_list == 0 || !COLOR_EQUAL(list.color, last_color))
50 {
51 k = newSWFShape();
52 SWFShape_setRightFill(k, SWFShape_addSolidFill(k, list.color.r, list.color.g, list.color.b, 0xff));
53 last_color = list.color;
54 }
55 SWFShape_movePenTo(k, SWFSCALE*START_POINT(first).x,
56 SWFSCALE*height - SWFSCALE*START_POINT(first).y);
57
58 for (this_spline = 0; this_spline < SPLINE_LIST_LENGTH (list);
59 this_spline++)
60 {
61 spline_type s = SPLINE_LIST_ELT (list, this_spline);
62
63 if (SPLINE_DEGREE(s) == LINEARTYPE)
64 {
65 SWFShape_drawLineTo(k, SWFSCALE*END_POINT(s).x,
66 SWFSCALE*height - SWFSCALE*END_POINT(s).y);
67 }
68 else
69 {
70 SWFShape_drawCubicTo (k, SWFSCALE*CONTROL1(s).x,
71 SWFSCALE*height - SWFSCALE*CONTROL1(s).y,
72 SWFSCALE*CONTROL2(s).x,
73 SWFSCALE*height - SWFSCALE*CONTROL2(s).y,
74 SWFSCALE*END_POINT(s).x,
75 SWFSCALE*height - SWFSCALE*END_POINT(s).y);
76 }
77 }
78 SWFMovie_add(m,k);
79 }
80 }
81
82
output_swf_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)83 int output_swf_writer(FILE* file, at_string name,
84 int llx, int lly, int urx, int ury,
85 at_output_opts_type * opts,
86 spline_list_array_type shape,
87 at_msg_func msg_func,
88 at_address msg_data)
89 {
90 int width = urx - llx;
91 int height = ury - lly;
92 SWFMovie m;
93
94 #ifdef _WINDOWS
95 if(file == stdout)
96 {
97 fprintf(stderr, "This driver couldn't write to stdout!\n");
98 return -1;
99 }
100 #endif
101
102 Ming_init();
103 Ming_setCubicThreshold(20000);
104
105 m = newSWFMovie();
106
107 out_splines(m, shape, height);
108
109 SWFMovie_setDimension(m, SWFSCALE*(float)width, SWFSCALE*(float)height);
110 SWFMovie_setRate(m, FPS);
111 SWFMovie_nextFrame(m);
112 SWFMovie_output(m, fileOutputMethod, file);
113 return 0;
114 }
115
116