1 /* ======================================================= *
2  * Copyright 1998-2005 Stephen C. Grubb                    *
3  * http://ploticus.sourceforge.net                         *
4  * Covered by GPL; see the file ./Copyright for details.   *
5  * ======================================================= */
6 
7 /* SWF Driver for Ploticus - Copyright 2003 Bill Traill (bill@traill.demon.co.uk).
8  * Portions Copyright 2001, 2002 Stephen C. Grubb
9  * Covered by GPL; see the file ./Copyright for details. */
10 
11 /*
12    Checking for redundant calls is not done here; should be done by caller.
13    special characters not delt with
14 
15 	Jan03 bt	Created swf driver based on existing svg driver svg.c
16 
17 	15 May 03 scg	a couple changes to make font loading more graceful when
18 			font dir not set or default font not available
19 
20 	15 May 03 scg	disabled swf_LS call
21 
22 	12 May 04 scg   This driver wasn't designed to handle multiple "jobs" per process..
23 			swf_movie probably needs to be released at end of each job, and Ming_init()
24 			only called first time (?)
25 
26 */
27 #ifndef NOSWF
28 
29 /* #define MAX_D_ROWS 1000 */
30 
31 #include <stdio.h>
32 #include <math.h>
33 #include <string.h>
34 #include <stdlib.h>
35 #include <ctype.h>
36 #include <ming.h>
37 
38 extern int TDH_err(), GL_member(), PLG_xrgb_to_rgb(), GL_goodnum(), PLG_colorname_to_rgb();
39 extern int unlink(); /* return value not used */
40 int PLGF_linetype(), PLGF_chardir();
41 
42 #define Eerr(a,b,c)  TDH_err(a,b,c)
43 #define stricmp(a,b) strcasecmp(a,b)
44 
45 extern double atof();
46 
47 #define swf_scale_x(x)   ((x * swf_pixs_inch ) + MARG_X - swf_offset_x)
48 #define swf_scale_y(y)   (swf_y_size - (( y * swf_pixs_inch ) + MARG_Y - swf_offset_y))
49 
50 #define MARG_X 0
51 #define MARG_Y 0
52 
53 char *getenv();
54 
55 static int	swf_stdout;		/* 1 if swf_fp is stdout */
56 static FILE	*swf_fp;
57 
58 static double	swf_x_size;		/* width of the drawing area */
59 static double	swf_y_size;		/* height of the drawing area */
60 static int	swf_path_in_prog =0;	/* flag to indicate if an swf path is in progress */
61 
62 static int	swf_cur_color_r = 0, swf_cur_color_g = 0, swf_cur_color_b = 0;
63 
64 static SWFFont	swf_font;
65 /* changed, scg 5/4/04...
66  * static double	path_x[MAX_D_ROWS];
67  * static double	path_y[MAX_D_ROWS];
68  */
69 static double *path_x = NULL, *path_y = NULL;
70 static int max_pts;
71 
72 static int	path_count;
73 
74 static char	swf_dash_style[1024];
75 static double	swf_line_width=1;
76 
77 static char	swf_font_name[100] = "";	/* current font name */
78 static int	swf_chdir;	 		/* char direction in degrees */
79 static int	swf_currpointsz;		/* current char size in points */
80 static char	swf_font_weight[100];
81 static char	swf_font_style[100];
82 
83 static int	swf_pixs_inch; 	   		/* number of pixels per inch - scg */
84 static char	swf_filename[256] = ""; 	/* output file name (was local) - scg */
85 
86 static char	swf_style[1024] = "";	/* line,font styles etc */
87 
88 static double	swf_offset_x;
89 static double	swf_offset_y;
90 
91 static char	swf_tmpfilename[256] = "/unnamed";
92 static int	swf_tmpfile_used = 0;
93 
94 static int	swf_clickmap = 0;
95 static int	swf_debug = 0;
96 
97 static SWFMovie swf_movie;
98 
99 static void swf_MV(char *s);
100 static void swf_LL(char *s);
101 static void swf_LE(char *s);
102 static void swf_CO(char *s);
103 static void swf_PL(char *s);
104 static void swf_PE(char *s);
105 static void swf_TX(char *s);
106 /* static void swf_LS(char *s); */
107 static void swf_PO(char *s);
108 static int swf_FT(char *s); /* was: static void swf_FT(char *s); scg 7/28/03 */
109 static void swf_TR(char *s);
110 
111 /* ============================= */
112 int
PLGF_initstatic()113 PLGF_initstatic()
114 {
115 swf_path_in_prog =0;
116 /* swf_cur_color_r = 256; swf_cur_color_g = 256; swf_cur_color_b = 256; */
117 swf_cur_color_r = 0; swf_cur_color_g = 0; swf_cur_color_b = 0;
118 swf_line_width = 1;
119 strcpy( swf_font_name, "" );
120 strcpy( swf_filename,"" );
121 strcpy( swf_style, "" );
122 strcpy( swf_tmpfilename, "/unnamed" );
123 swf_tmpfile_used = 0;
124 swf_clickmap = 0;
125 swf_debug = 0;
126 
127 return( 0 );
128 }
129 
130 /* ============================================================================ */
131 /* SETPARMS - allow caller to pass required parms that swf driver needs - MUST be called before setup() */
132 /* ============================================================================ */
133 int
PLGF_setparms(debug,tmpname,font)134 PLGF_setparms( debug, tmpname, font )
135 int debug;
136 char *tmpname;
137 char *font;	/* user-selected font, or "" */
138 /* int clickmap; */
139 {
140 swf_debug = debug;
141 sprintf( swf_tmpfilename, "%s_V", tmpname );
142 
143 /* get an early idea of default font.. allows -font to control first load.. scg 5/15/03 */
144 /* this will be /Helvetica by default.. */
145 strcpy( swf_font_name, font );
146 
147 /* swf_clickmap = clickmap; */    /* clickmap not supported */
148 return( 0 );
149 }
150 
151 
152 /* ============================================================================ */
153 /* SETUP */
154 /* ============================================================================ */
155 int
PLGF_setup(name,dev,outfile,pixs_inch,Ux,Uy,Upleftx,Uplefty,maxdrivervect)156 PLGF_setup( name, dev, outfile, pixs_inch, Ux, Uy, Upleftx, Uplefty, maxdrivervect )
157 char *name; /* arbitrary name */
158 char dev;  /* 'p' = monochrome   'c' = color   'e' = eps */
159 char *outfile;  /* file to put code in */
160 int pixs_inch;
161 double Ux;
162 double Uy;
163 int Upleftx;
164 int Uplefty;
165 int maxdrivervect;
166 {
167 
168 /* set globals */
169 if( dev != 'f' ) dev = 'f';
170 strcpy( swf_font_weight, "" );
171 strcpy( swf_font_style, "" );
172 swf_chdir = 0;
173 swf_currpointsz = 10;
174 
175 swf_pixs_inch = pixs_inch; /* scg */
176 swf_path_in_prog =0;
177 swf_line_width=1;
178 strcpy( swf_style, "" );
179 swf_tmpfile_used = 0;
180 
181 max_pts = maxdrivervect;
182 if( path_x != NULL ) free( path_x );
183 if( path_y != NULL ) free( path_y );
184 path_x = (double *) malloc( max_pts * sizeof( double ));
185 path_y = (double *) malloc( max_pts * sizeof( double ));
186 
187 /* determine if we need to write to tmp file, and open appropriate file for write.. */
188 swf_stdout = 0;
189 if( stricmp( outfile, "stdout" )==0 || outfile[0] == '\0' ) swf_stdout = 1;
190 else strcpy( swf_filename, outfile );
191 
192 swf_x_size = Ux * pixs_inch;
193 swf_y_size = Uy * pixs_inch;
194 strcpy(swf_style,"");
195 
196 swf_fp = fopen( swf_tmpfilename, "w" );
197 /* swf_fp = fopen( "temp_dump.txt", "w" );  */
198 fprintf(swf_fp,"FT:%s :%s :%s \n",swf_font_name,swf_font_weight,swf_font_style);
199 fprintf(swf_fp,"PO:%d\n",swf_currpointsz);
200 PLGF_linetype( "0", 1.0, 1.0);
201 PLGF_chardir( swf_chdir );
202 return( 0 );
203 }
204 
205 /* ============================================================================ */
206 /* FMT - return the output file type  */
207 /* ============================================================================ */
208 int
PLGF_fmt(tag)209 PLGF_fmt( tag )
210 char *tag;
211 {
212 strcpy( tag, "swf" );
213 return( 0 );
214 }
215 
216 /* ============================================================================ */
217 /* MOVETO */
218 /* ============================================================================ */
219 int
PLGF_moveto(x,y)220 PLGF_moveto( x, y )
221 double x, y;
222 {
223 if (!swf_path_in_prog) { fprintf(swf_fp,"MV:%lf %lf\n",x,y); }
224 return( 0 );
225 }
226 
227 
228 /* ============================================================================ */
229 /* LINETO */
230 /* ============================================================================ */
231 int
PLGF_lineto(x,y)232 PLGF_lineto( x, y )
233 double x, y;
234 {
235 if (!swf_path_in_prog) { swf_path_in_prog =1; }
236 fprintf(swf_fp,"LL:%lf %lf\n",x,y);
237 return( 0 );
238 }
239 
240 
241 /* ============================================================================ */
242 /* STROKE - render a stroke (line) */
243 /* ============================================================================ */
244 int
PLGF_stroke()245 PLGF_stroke( )
246 {
247 if (swf_path_in_prog) { fprintf(swf_fp,"LE:\n"); }
248 swf_path_in_prog = 0;
249 return( 0 );
250 }
251 
252 
253 /* ============================================================================ */
254 /* PATH - add an element to a path (either new or existing) */
255 /* ============================================================================ */
256 int
PLGF_path(x,y)257 PLGF_path( x, y )
258 double x, y;
259 {
260 if (!swf_path_in_prog) { swf_path_in_prog =1; }
261 fprintf(swf_fp,"PL:%lf %lf\n",x,y);
262 return( 0 );
263 }
264 
265 /* ============================================================================ */
266 /* FILL - fill current path with current color */
267 /* ============================================================================ */
268 int
PLGF_fill()269 PLGF_fill( )
270 {
271 if (swf_path_in_prog) { fprintf(swf_fp,"PE:\n"); }
272 swf_path_in_prog = 0;
273 return( 0 );
274 }
275 
276 /* ============================================================================ */
277 /* COLOR - set current color for text and lines */
278 /* ============================================================================ */
279 int
PLGF_color(color)280 PLGF_color( color )
281 char *color;
282 {
283 int i, n;
284 double r, g, b, PLG_rgb_to_gray();
285 int slen;
286 
287 /* color parameter can be in any of these forms:
288    "rgb(R,G,B)"  where R(ed), G(reen), and B(lue) are 0.0 (none) to 1.0 (full)
289    "xrgb(xxxxxx)" or "xrgb(xxxxxxxxxxxx)"
290    "gray(S)"	 where S is 0.0 (black) to 1.0 (white)
291    "S"		 same as above
292     or, a color name such as "blue" (see color.c)
293 */
294 
295 for( i = 0, slen = strlen( color ); i < slen; i++ ) {
296 	if( GL_member( color[i], "(),/:|-" ) ) color[i] = ' ';
297 	else color[i] = tolower( color[i] );
298 	}
299 
300 if( strncmp( color, "rgb", 3 )==0 ) {
301 	n = sscanf( color, "%*s %lf %lf %lf", &r, &g, &b );
302 	if( n != 3 ) { Eerr( 12031, "Invalid color", color ); return(1); }
303 	}
304 else if( strncmp( color, "gray", 4 )==0 || strncmp( color, "grey", 4 )==0 ) {
305 	n = sscanf( color, "%*s %lf", &r );
306 	if( n != 1 ) { Eerr( 12031, "Invalid color", color ); return(1); }
307 	g = b = r;
308 	}
309 else if( strncmp( color, "xrgb", 4 )==0 ) {
310 	if (PLG_xrgb_to_rgb( color+5, &r, &g, &b)) return(1);
311 	}
312 else if( color[0] == 'x' ) {  /* added scg 5/31/07 */
313         if (PLG_xrgb_to_rgb( &color[1], &r, &g, &b)) return(1);
314         }
315 else if( GL_goodnum( color, &i ) ) {
316 	r = atof( color );
317 	g = b = r;
318 	}
319 else PLG_colorname_to_rgb( color, &r, &g, &b );
320 
321 swf_cur_color_r = r * 255;
322 swf_cur_color_g = g * 255;
323 swf_cur_color_b = b * 255;
324 
325 fprintf(swf_fp,"CO:%d:%d:%d\n",swf_cur_color_r,swf_cur_color_g,swf_cur_color_b);
326 return( 0 );
327 }
328 
329 
330 
331 
332 /* ============================================================================ */
333 /* TEXT - render some text */
334 /* ============================================================================ */
335 int
PLGF_text(com,x,y,s,w)336 PLGF_text( com, x, y, s, w )
337 char com;
338 double x, y;
339 char *s;
340 double w;
341 {
342 fprintf(swf_fp,"TX:%lf %lf %lf %c:%s\n",x,y,w,com, s);
343 return( 0 );
344 }
345 
346 
347 /* ============================================================================ */
348 /* POINTSIZE - set text point size */
349 /* ============================================================================ */
350 int
PLGF_pointsize(p)351 PLGF_pointsize( p )
352 int p;
353 {
354 swf_currpointsz = p;
355 fprintf(swf_fp,"PO:%d\n",swf_currpointsz);
356 return( 0 );
357 }
358 
359 
360 /* ============================================================================ */
361 /* FONT - set font */
362 /* ============================================================================ */
363 int
PLGF_font(f)364 PLGF_font( f )
365 char *f;
366 {
367 if (f[0] == '/') strcpy( swf_font_name, ++f );
368 else strcpy( swf_font_name, f );
369 fprintf(swf_fp,"FT:%s :%s :%s \n",swf_font_name,swf_font_weight,swf_font_style);
370 return( 0 );
371 }
372 
373 /* ============================================================================ */
374 /* CHARDIR - set text direction */
375 /* ============================================================================ */
376 int
PLGF_chardir(t)377 PLGF_chardir( t )
378 int t;
379 {
380 fprintf(swf_fp,"TR:%d\n",t);
381 return( 0 );
382 }
383 
384 
385 /* ============================================================================ */
386 /* LINETYPE - set line style */
387 /* ============================================================================ */
388 int
PLGF_linetype(s,x,y)389 PLGF_linetype( s, x, y )
390 char *s;
391 double x, y;
392 {
393 /* X = line width;  Y = dash pattern magnification (0.1 to 10)
394  *  S indicates dash pattern.  If S is "0", an unbroken (normal) line is produced.
395  *  If S is "1" through "8", a preset dash pattern is used.  Otherwise, S is
396  *  assumed to hold the dash pattern string "[ n1 n2 n3.. ]".
397  */
398 static int dash[10][6]= { {0,0,0,0,0,0}, {1,1}, {3,1}, {5,1}, {2,1,1,1}, {4,1,1,1}, {6,1,1,1},
399 			  {2,1,1,1,1,1}, {4,1,1,1,1,1}, {6,1,1,1,1,1} };
400 int ltype, i;
401 
402 strcpy(swf_dash_style,"");
403 swf_line_width = x ;
404 
405 if(  s[0] == '\0' || strcmp( s, "0" )==0 ) strcpy(swf_dash_style,"");
406 else 	{
407 	char *p = swf_dash_style;
408 
409 	if( strlen( s ) > 1 ) {
410 		ltype = 0;
411 		sscanf( s, "%d %d %d %d %d %d", &dash[0][0], &dash[0][1], &dash[0][2], &dash[0][3], &dash[0][4], &dash[0][5] );
412 	}
413 	else ltype = atoi( s );
414 
415 	for( i = 0; i < 6; i++ ) {
416 		if( dash[ ltype ][ i ] > 0 ) p += sprintf( p,"%3.1f,", dash[ ltype ][ i ] * y );
417 	}
418 	p--;
419 	*p = '\0';
420 }
421 
422 fprintf(swf_fp,"LS:%lf:%s\n",swf_line_width, swf_dash_style);
423 return( 0 );
424 }
425 
426 
427 /* ============================================================================ */
428 /* write a char to stdout */
429 /* ============================================================================ */
putC(byte b,void * data)430 static void putC(byte b, void *data) {
431 	putchar(b);
432 }
433 
434 /* ============================================================================ */
435 /* TRAILER do end of file stuff */
436 /* ============================================================================ */
437 int
PLGF_trailer(x1,y1,x2,y2)438 PLGF_trailer( x1, y1, x2, y2 )
439 double x1, y1, x2, y2;
440 {
441 char *buf;
442 int len;
443 char  ptype[5];
444 char  *ptype_s;
445 
446 /* Close the temp file we have been writing to */
447 fclose(swf_fp);
448 
449 /* clickmap not yet supported */
450 /* if( swf_clickmap ) {
451  *	PL_clickmap_out( 0, 0 );
452  * }
453  */
454 
455 
456 
457 buf = swf_style; /* reuse */
458 swf_fp = fopen( swf_tmpfilename, "r" );
459 if( swf_fp == NULL ) return( Eerr( 75205, "cannot reopen tmpfile", swf_tmpfilename ) );
460 
461 
462 /* swf_fp = fopen( "temp_dump.txt", "r" );  */
463 
464 /* initialise the ming library */
465 Ming_init();
466 swf_movie =  newSWFMovie();
467 
468 
469 /* Calculate the size of the drawing area and
470    set the size of the swf_movie */
471 swf_x_size = (x2-x1) *swf_pixs_inch;
472 swf_y_size = (y2-y1) *swf_pixs_inch;
473 SWFMovie_setDimension(swf_movie, swf_x_size, swf_y_size);
474 
475 
476 /* work out the x and y offset into the drawing area */
477 swf_offset_x = x1 *swf_pixs_inch;
478 swf_offset_y = y1 *swf_pixs_inch;
479 
480 swf_cur_color_r = 0; swf_cur_color_g = 0; swf_cur_color_b = 0; /* bug - axes sometimes same color as plot content..
481 								  but this didn't fix it.. scg 1/19/05 */
482 
483 while (fgets(buf,999,swf_fp)) {
484 /* fprintf( stderr, "---->%s", buf ); */
485 	sscanf(buf,"%2s",ptype);
486 	ptype_s = buf + 3;
487 
488 	/* Strip the newline off the end */
489 	len = strlen(ptype_s);
490 	ptype_s[len-1] = '\0';
491 
492 	if (!strcmp(ptype,"FT")) {
493 		if( swf_FT(ptype_s) != 0 ) return( 1 );  /* allow return of err code for font load error.. scg */
494 
495 	} else if (!strcmp(ptype,"MV")) {
496 		swf_MV(ptype_s);
497 	} else if (!strcmp(ptype,"LL")) {
498 		swf_LL(ptype_s);
499 	} else if (!strcmp(ptype,"LE")) {
500 		swf_LE(ptype_s);
501 	} else if (!strcmp(ptype,"CO")) {
502 		swf_CO(ptype_s);
503 	} else if (!strcmp(ptype,"PL")) {
504 		swf_PL(ptype_s);
505 	} else if (!strcmp(ptype,"PE")) {
506 		swf_PE(ptype_s);
507 	} else if (!strcmp(ptype,"TX")) {
508 		swf_TX(ptype_s);
509 	} else if (!strcmp(ptype,"LS")) {
510 		/* swf_LS(ptype_s); */ /* scg 5/15/03 commented out - causes seg fault on solaris */ ;
511 
512 	} else if (!strcmp(ptype,"PO")) {
513 		swf_PO(ptype_s);
514 	} else if (!strcmp(ptype,"TR")) {
515 		swf_TR(ptype_s);
516 	}
517 }
518 
519 
520 if (swf_stdout) {
521 	SWFByteOutputMethod  put_char;
522 	put_char = putC;
523 	SWFMovie_output(swf_movie,put_char,0);
524 	/* for ming 0.3a+ use SWFMovie_output( swf_movie );  ??? */
525 	}
526 else SWFMovie_save(swf_movie,swf_filename);
527 
528 fclose( swf_fp );
529 
530 unlink( swf_tmpfilename );
531 
532 return( 0 );
533 }
534 
535 
536 /* ================================= */
537 /* FONTNAME - given a base name (such as Helvetica) and a modifier
538    such as I (italic) B (bold) or BI (bold italic), build the
539 	font style and weight strings */
540 
541 int
PLGF_fontname(basename,name)542 PLGF_fontname( basename, name )
543 char *basename;
544 char *name; /* in: B, I, or BI.  out: still the font name but statics now hold the font style and weight */
545 {
546 	int i, slen;
547 
548 	for( i = 0, slen = strlen( name ); i < slen; i++ ) name[i] = tolower( name[i] );
549 
550 	strcpy (swf_font_weight, "");
551 	strcpy (swf_font_style, "");
552 
553 	if( strcmp( name, "b" )==0 ) strcpy (swf_font_weight, "bold");
554 	else if( strcmp( name, "i" )==0 ) strcpy (swf_font_style, "italic");
555 	else if( strcmp( name, "bi" )==0 ) { strcpy (swf_font_weight, "bold"); strcpy (swf_font_style, "italic"); }
556 
557 	if (basename[0] == '/')  strcpy( name, basename++ );
558 	else strcpy( name, basename );
559 
560 	return( 0 );
561 }
562 
563 
564 
565 /* ============================================================================ */
566 /* Line MOVETO */
567 /* ============================================================================ */
swf_MV(s)568 static void swf_MV( s )
569 char *s;
570 {
571 	double x, y;
572 
573 	sscanf(s,"%lf %lf",&x,&y);
574 
575 	path_count = 0;
576 	path_x[path_count] = x;
577 	path_y[path_count] = y;
578 	path_count++ ;
579 
580 	swf_path_in_prog =1;
581 
582 	return;
583 }
584 
585 /* ============================================================================ */
586 /* LINETO */
587 /* ============================================================================ */
swf_LL(s)588 static void swf_LL(s)
589 char *s;
590 {
591 	double x,y;
592 
593 	sscanf(s,"%lf %lf",&x,&y);
594 
595 	if (!swf_path_in_prog) swf_path_in_prog =1;
596 
597 	/* if( (path_count-2) > max_pts ) return; */ /* scg 5/4/04 */
598 	if (path_count >= max_pts ) return; /* scg 5/4/04 and crt 10-Jun-06 */
599 
600 	path_x[path_count] = x;
601 	path_y[path_count] = y;
602 	path_count++;
603 
604 	return;
605 }
606 
607 /* ============================================================================ */
608 /* STROKE - render a stroke (line) */
609 /* ============================================================================ */
swf_LE(s)610 static void swf_LE(s)
611 char *s;
612 {
613 	int i;
614 	SWFShape swf_shape;
615 
616 	swf_shape = newSWFShape();
617 	SWFShape_setLine(swf_shape, swf_line_width,  swf_cur_color_r,swf_cur_color_g,swf_cur_color_b,0xff);
618 	/* SWFShape_setLine(swf_shape,1,  swf_cur_color_r,swf_cur_color_g,swf_cur_color_b,0xff);  */
619 	SWFShape_movePenTo(swf_shape,swf_scale_x(path_x[0]),swf_scale_y(path_y[0]));
620 
621 	for (i=1;i < path_count;i++) {
622 		SWFShape_drawLineTo(swf_shape, swf_scale_x(path_x[i]),swf_scale_y(path_y[i]));
623 	}
624 	SWFMovie_add(swf_movie,swf_shape);
625 
626 	swf_path_in_prog = 0;
627 	return;
628 }
629 
630 /* ============================================================================ */
631 /* swf_PL - path line segment */
632 /* ============================================================================ */
swf_PL(s)633 static void swf_PL(s)
634 char *s;
635 {
636 	double x,y;
637 
638 	sscanf(s,"%lf %lf",&x,&y);
639 
640 	if (!swf_path_in_prog) {
641 		swf_path_in_prog =1;
642 	}
643 
644 	path_x[path_count] = x;
645 	path_y[path_count] = y;
646 	path_count++;
647 
648 	return;
649 }
650 
651 
652 /* ============================================================================ */
653 /* swf_PE -  Path end - fill current path with current color */
654 /* ============================================================================ */
swf_PE(s)655 static void swf_PE(s)
656 char *s;
657 {
658 	int i;
659 	SWFFill swf_fill;
660 	SWFShape swf_shape;
661 
662 	if (swf_path_in_prog) {
663 
664 		swf_shape = newSWFShape();
665 		swf_fill=SWFShape_addSolidFill(swf_shape,swf_cur_color_r,swf_cur_color_g,swf_cur_color_b,0xff);
666 		SWFShape_setRightFill(swf_shape, swf_fill);
667 
668 		SWFShape_movePenTo(swf_shape,swf_scale_x(path_x[0]),swf_scale_y(path_y[0]));
669 		for (i=1;i < path_count;i++) {
670 			SWFShape_drawLineTo(swf_shape,swf_scale_x(path_x[i]),swf_scale_y(path_y[i]));
671 		}
672 		SWFShape_drawLineTo(swf_shape,swf_scale_x(path_x[0]),swf_scale_y(path_y[0]));
673 		SWFMovie_add(swf_movie,swf_shape);
674 	}
675 	swf_path_in_prog = 0;
676 	return;
677 }
678 
679 
680 /* ============================================================================ */
681 /* Colour - set the current colour */
682 /* ============================================================================ */
swf_CO(s)683 static void swf_CO(s)
684 char *s;
685 {
686 	sscanf(s,"%d:%d:%d",&swf_cur_color_r,&swf_cur_color_g,&swf_cur_color_b);
687 	/* printf("Colour %d,%d,%d\n",swf_cur_color_r,swf_cur_color_g,swf_cur_color_b); */
688 	return;
689 }
690 
691 /* ============================================================================ */
692 /* TEXT - render some text */
693 /* ============================================================================ */
swf_TX(s)694 static void swf_TX(s)
695 char *s;
696 {
697 	float width;
698 	char com;
699 	double x, y,w;
700 	int no_chars;
701 	char *str;
702 	SWFText swf_text;
703 	SWFDisplayItem swf_item;
704 
705 fprintf(swf_fp,"TX:%lf %lf %lf %c:%s\n",x,y,w,com, s);
706 
707 	sscanf(s,"%lf %lf %lf %c:%n\n",&x,&y,&w,&com,&no_chars);
708 	str = s + no_chars;
709 
710 /* printf("TX align:%c text:%s\n",com,str);   */
711 
712 	x = swf_scale_x(x);
713 	y = swf_scale_y(y);
714 
715 
716 
717         swf_text =  newSWFText();
718         SWFText_moveTo(swf_text,0,0);
719         SWFText_setFont(swf_text, swf_font);
720         SWFText_setHeight(swf_text, swf_currpointsz);
721         SWFText_setColor(swf_text, swf_cur_color_r,swf_cur_color_g,swf_cur_color_b, 1);
722 
723 
724         SWFText_addString(swf_text,str,0);
725         swf_item = SWFMovie_add(swf_movie,swf_text);
726 
727         /* SWFDisplayItem_rotateTo(swf_item, - swf_chdir); */
728         SWFDisplayItem_rotateTo(swf_item, swf_chdir);
729 
730         /* set the text alignment */
731         width = SWFText_getStringWidth(swf_text, str);
732 
733         if (com == 'T') {}
734         else if (com == 'C') {
735                 x = x - (cos((swf_chdir * 3.141592653)/180.0)*(width/2));
736                 y = y + (sin((swf_chdir * 3.141592653)/180.0)*(width/2));
737         }
738         else if (com == 'J') {
739                 x = x - (cos((swf_chdir * 3.141592653)/180.0)*(width));
740                 y = y + (sin((swf_chdir * 3.141592653)/180.0)*(width));
741         }
742 
743         SWFDisplayItem_moveTo(swf_item, x, y);
744 
745 	return;
746 }
747 
748 /*
749 PI = 3.141592653589793238462643;
750 DegToRad = Degrees * 3.1416 / 180
751 RadToDeg = Radians * 180 / 3.1416
752 */
753 
754 /* ============================================================================ */
755 /* POINTSIZE - set text point size */
756 /* ============================================================================ */
swf_PO(s)757 static void swf_PO(s)
758 char *s;
759 {
760 	sscanf(s,"%d\n",&swf_currpointsz);
761 /* printf ("PO:%d\n",swf_currpointsz); */
762 	return;
763 }
764 
765 /* ============================================================================ */
766 /* Line style */
767 /* ============================================================================ */
768 #ifdef CUT
swf_LS(s)769 static void swf_LS(s)
770 char *s;
771 {
772 /* X = line width;  Y = dash pattern magnification (0.1 to 10)
773  *  S indicates dash pattern.  If S is "0", an unbroken (normal) line is produced.
774  *  If S is "1" through "8", a preset dash pattern is used.  Otherwise, S is
775  *  assumed to hold the dash pattern string "[ n1 n2 n3.. ]".
776  */
777 	int no_chars;
778 
779 	sscanf( s, "%lf:",&swf_line_width, &no_chars);
780 	s = s + no_chars;
781 
782 	strcpy(swf_dash_style,s);
783 /* printf("Width %lf Style:%s\n",swf_line_width,swf_dash_style); */
784 	return;
785 }
786 #endif
787 /* ============================================================================ */
788 /* Font */
789 /* ============================================================================ */
swf_FT(s)790 static int swf_FT(s)
791 /* was static void swf_FT(s) .. changed scg 7/28/03 */
792 char *s;
793 {
794 
795 	FILE *font;
796 	char filename[512];
797 	char *swf_fonts_dir;
798 
799 	sscanf(s,"%s :%s :%s \n",swf_font_name,swf_font_weight,swf_font_style);
800 
801 
802         swf_fonts_dir = getenv( "SWF_FONTS_DIR");
803 
804         if( swf_fonts_dir == NULL ) {
805 		Eerr( 13001, "SWF_FONTS_DIR environment variable not found", "" );
806 		sprintf( filename, "%s.fdb", swf_font_name);
807 	} else {
808 		sprintf( filename, "%s/%s.fdb", swf_fonts_dir, swf_font_name);
809 	}
810 
811 	font = fopen(filename,"r");
812 	if (font == NULL) {
813 		Eerr( 13001, "Unable to open font file ", filename );
814 		if( swf_fonts_dir == NULL ) return(1);	/* don't try to build path.. abort .. scg 5/15/03 */
815 		sprintf( filename, "%s/Arial.fdb", swf_fonts_dir); /* 2nd try */
816 		font = fopen(filename,"r");
817 		if (font == NULL) {
818 			Eerr( 13002, "Unable to load default font", filename );
819 			return( 1 );
820 		} else {
821 			Eerr( 13003, "Using default font test.fdb", "" );
822 		}
823 	}
824 	swf_font = loadSWFFontFromFile(font);
825 	fclose (font);
826 	return( 0 );
827 }
828 
829 /* ============================================================================ */
830 /* Test Rotation */
831 /* ============================================================================ */
swf_TR(s)832 static void swf_TR(s)
833 char *s;
834 {
835 	sscanf(s,"%d\n",&swf_chdir);
836 	return;
837 }
838 
839 
840 
841 #endif /* NOSWF */
842 
843 /* ======================================================= *
844  * Copyright 1998-2005 Stephen C. Grubb                    *
845  * http://ploticus.sourceforge.net                         *
846  * Covered by GPL; see the file ./Copyright for details.   *
847  * ======================================================= */
848