Line 0
Link Here
|
|
|
1 |
|
2 |
|
3 |
/* |
4 |
* TransFig: Facility for Translating Fig code |
5 |
* Copyright (c) 1991 by Micah Beck |
6 |
* Parts Copyright (c) 1985-1988 by Supoj Sutanthavibul |
7 |
* Parts Copyright (c) 1989-1999 by Brian V. Smith |
8 |
* |
9 |
* Any party obtaining a copy of these files is granted, free of charge, a |
10 |
* full and unrestricted irrevocable, world-wide, paid up, royalty-free, |
11 |
* nonexclusive right and license to deal in this software and |
12 |
* documentation files (the "Software"), including without limitation the |
13 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, |
14 |
* and/or sell copies of the Software, and to permit persons who receive |
15 |
* copies from any such party to do so, with the only requirement being |
16 |
* that this copyright notice remain intact. |
17 |
* |
18 |
*/ |
19 |
|
20 |
/* |
21 |
* gensml.c : Kivio Stencil driver for fig2dev |
22 |
* |
23 |
* Author: Peter Korf |
24 |
* Code stolen from genlatex.c |
25 |
* |
26 |
*/ |
27 |
#if defined(hpux) || defined(SYSV) || defined(SVR4) |
28 |
#include <sys/types.h> |
29 |
#endif |
30 |
#include <sys/file.h> |
31 |
#include "fig2dev.h" |
32 |
#include "object.h" |
33 |
#include "texfonts.h" |
34 |
|
35 |
extern double rad2deg; |
36 |
extern void unpsfont(); |
37 |
|
38 |
//static put_box(); |
39 |
//static put_arc_box(); |
40 |
//static single_line(); |
41 |
//static start_line(); |
42 |
void end_line(); |
43 |
void setcolor(int,int); |
44 |
|
45 |
|
46 |
//static put_solidline(); |
47 |
//static put_dashline(); |
48 |
//static put_dotline(); |
49 |
//static put_quarter(); |
50 |
|
51 |
#define rint(a) floor((a)+0.5) /* close enough? */ |
52 |
|
53 |
#define DESC_NAME "unknown" |
54 |
extern char *from; |
55 |
|
56 |
#define SWAP(x,y) {tmp=x; x=y; y=tmp;} |
57 |
//#define TRANS(x,y) (*translate_coordinates)(&x,&y) |
58 |
//#define TRANS2(x1,y1,x2,y2) (*translate_coordinates)(&x1,&y1); \ |
59 |
// (*translate_coordinates)(&x2,&y2) |
60 |
//#define TRANSD(x,y) (*translate_coordinates_d)(&x,&y) |
61 |
#define TRANS(x,y) translate1(&x,&y) |
62 |
#define TRANS2(x1,y1,x2,y2) translate1(&x1,&y1);translate1(&x2,&y2); |
63 |
|
64 |
#ifndef MIN |
65 |
#define MIN(x,y) (((x) <= (y))? (x): (y)) |
66 |
#endif |
67 |
#ifndef MAX |
68 |
#define MAX(x,y) (((x) >= (y))? (x): (y)) |
69 |
#endif |
70 |
#define ABS(x) (((x) >= 0)? (x): -(x)) |
71 |
#define round4(x) ((round(10000.0*(x))/10000.0)) |
72 |
#define round6(x) ((round(1000000.0*(x))/1000000.0)) |
73 |
#define MAXCIRCLEDIA 80 |
74 |
#define MAXCIRCLERAD ((MAXCIRCLEDIA-0.5)/(2*72.27)) |
75 |
|
76 |
|
77 |
#define SCALEFAKTOR 300 |
78 |
|
79 |
static char desc_name[] = DESC_NAME; |
80 |
static float offsetx,offsety,scale=1; |
81 |
static int counter=0; |
82 |
|
83 |
static unsigned int rgbColorVal(int colorIndex); |
84 |
// static unsigned int setStyle(F_compound *objects;); |
85 |
|
86 |
|
87 |
static int verbose;// = 0; |
88 |
extern double dash_mag;// = 1.0; |
89 |
extern int thick_width;// = 2; |
90 |
extern double tolerance;// = 2.0; |
91 |
extern double arc_tolerance;// = 1.0; |
92 |
extern int (*translate_coordinates)();// = NULL; |
93 |
extern int (*translate_coordinates_d)();// = NULL; |
94 |
extern double unitlength; |
95 |
static int cur_thickness;// 1; |
96 |
extern double ldot_diameter;// .0/72.0; |
97 |
extern char *dot_cmd;// =tindot; |
98 |
extern char *ldot_cmd;// =hin_ldot; |
99 |
extern double dot_xoffset; |
100 |
extern double dot_yoffset; |
101 |
extern double ldot_xoffset; |
102 |
extern double ldot_yoffset; |
103 |
|
104 |
|
105 |
static |
106 |
translate1(xp, yp) |
107 |
float *xp, *yp; |
108 |
{ |
109 |
if (verbose) fprintf(tfp, "<!-- translate1 %.3f %.3f %.3f-->\n",*xp,offsetx,scale); |
110 |
*xp = (float)(*xp-offsetx)/scale; |
111 |
*yp = (float)(*yp-offsety)/scale; |
112 |
|
113 |
//*xp = *xp + 1; |
114 |
//*yp = *yp + 1; |
115 |
} |
116 |
|
117 |
static |
118 |
translate2(xp, yp) |
119 |
float *xp, *yp; |
120 |
{ |
121 |
if (verbose) fprintf(tfp, "<!-- translate2 -->\n"); |
122 |
|
123 |
// *xp /= (double)120; |
124 |
// *yp /= (double)120; |
125 |
*xp = (*xp-offsetx)/scale; |
126 |
*yp = (*yp-offsety)/scale; |
127 |
// *xp = *xp + 1; |
128 |
// *yp = (double)(TOP - *yp -1); |
129 |
} |
130 |
|
131 |
static translate1_d(xp, yp) |
132 |
float *xp, *yp; |
133 |
{ |
134 |
if (verbose) fprintf(tfp, "<!-- translate1_d -->\n"); |
135 |
// *xp /= (double)120; |
136 |
// *yp /= (double)120; |
137 |
*xp = (*xp-offsetx)/scale; |
138 |
*yp = (*yp-offsety)/scale; |
139 |
// *xp = *xp + 1.0; |
140 |
// *yp = *yp + 1.0; |
141 |
} |
142 |
static |
143 |
translate2_d(xp, yp) |
144 |
float *xp, *yp; |
145 |
{ |
146 |
if (verbose) fprintf(tfp, "<!-- translate2_d -->\n"); |
147 |
// *xp /= (double)120; |
148 |
// *yp /= (double)120; |
149 |
*xp = (*xp-offsetx)/scale; |
150 |
*yp = (*yp-offsety)/scale; |
151 |
// *xp = *xp + 1.0; |
152 |
// *yp = (double)TOP - *yp -1.0; |
153 |
} |
154 |
|
155 |
void |
156 |
gensml_option(opt, optarg) |
157 |
char opt, *optarg; |
158 |
{ |
159 |
int i; |
160 |
|
161 |
switch (opt) { |
162 |
case 'a': |
163 |
fprintf(stderr, "warning: latex option -a obsolete"); |
164 |
break; |
165 |
|
166 |
case 'd': |
167 |
dash_mag = atof(optarg); /* set dash magnification */ |
168 |
break; |
169 |
|
170 |
dash_mag = atof(optarg); /* set dash magnification */ |
171 |
break; |
172 |
|
173 |
|
174 |
case 'f': /* set default text font */ |
175 |
for ( i = 1; i <= MAX_FONT; i++ ) |
176 |
if ( !strcmp(optarg, texfontnames[i]) ) break; |
177 |
|
178 |
if ( i > MAX_FONT) |
179 |
{ |
180 |
fprintf(stderr, |
181 |
"warning: non-standard font name %s ignored\n", optarg); |
182 |
} |
183 |
else |
184 |
{ |
185 |
texfontnames[0] = texfontnames[i]; |
186 |
#ifdef NFSS |
187 |
texfontfamily[0] = texfontfamily[i]; |
188 |
texfontseries[0] = texfontseries[i]; |
189 |
texfontshape[0] = texfontshape[i]; |
190 |
#endif |
191 |
} |
192 |
break; |
193 |
|
194 |
case 'l': /* set thin/thick line threshold */ |
195 |
thick_width = atoi(optarg); |
196 |
break; |
197 |
|
198 |
case 'v': |
199 |
verbose = 1; /* verbose mode */ |
200 |
break; |
201 |
|
202 |
case 'n': |
203 |
sprintf(desc_name,"%s",optarg); /* description name (library) */ |
204 |
break; |
205 |
|
206 |
case 's': |
207 |
case 'm': |
208 |
case 'L': |
209 |
break; |
210 |
|
211 |
break; |
212 |
|
213 |
default: |
214 |
put_msg(Err_badarg, opt, "latex"); |
215 |
exit(1); |
216 |
} |
217 |
} |
218 |
|
219 |
void |
220 |
gensml_start(objects) |
221 |
F_compound *objects; |
222 |
{ |
223 |
int tmp; |
224 |
char name1[40]=" "; |
225 |
float x1,y1,x2,y2; |
226 |
strncpy((char *)name1,from,strlen(from)-4); |
227 |
|
228 |
// strncpy((char *)name1,(char *)name1,strlen(name1)-4); |
229 |
// memcpy(rindex((const char*)from,'.'),'\0',1); |
230 |
// name[strlen((const char*)from)]='\0'; |
231 |
/* print any whole-figure comments prefixed with "%" */ |
232 |
fprintf(tfp, "<?xml version=\"1.0\"?>\n"); |
233 |
|
234 |
// if (objects->comments) { |
235 |
// print_comments("<!-- ",objects->comments, "-->"); |
236 |
// } |
237 |
|
238 |
// fprintf(tfp, "<!-- do not edit ! generated with: fig2dev -L sml %s --->\n",from); |
239 |
fprintf(tfp, "<KivioShapeStencil creator=\"fig2dev\">\n" ); |
240 |
fprintf(tfp, "<KivioSMLStencilSpawnerInfo>\n" ); |
241 |
fprintf(tfp, "<Author data=\"see README files\"/>\n" ); |
242 |
|
243 |
// print_comments("<Title data=\" ",objects->comments, "\"/>"); |
244 |
fprintf(tfp, "<Id data=\"%s\"/>\n",name1); |
245 |
if (objects->comments) { |
246 |
print_comments("<Description data=\" ",objects->comments, "\"/>"); |
247 |
print_comments("<Title data=\" ",objects->comments, "\"/>"); |
248 |
} else |
249 |
{ |
250 |
fprintf(tfp, "<Description data=\"%s\"/>\n",name1); |
251 |
fprintf(tfp, "<Title data=\"%s\"/>\n",name1); |
252 |
} |
253 |
fprintf(tfp, "<Version data=\"0.1\"/>\n" ); |
254 |
fprintf(tfp, "<Web data=\"www.xfig.org\"/>\n" ); |
255 |
fprintf(tfp, "<Email data=\"peter@niendo.de\"/>\n" ); |
256 |
fprintf(tfp, "<Copyright data=\"see README files \"/>\n" ); |
257 |
fprintf(tfp, "<AutoUpdate data=\"off\"/>\n" ); |
258 |
fprintf(tfp, "</KivioSMLStencilSpawnerInfo>\n" ); |
259 |
|
260 |
texfontsizes[0] = texfontsizes[1] = |
261 |
TEXFONTSIZE(font_size?font_size:DEFAULT_FONT_SIZE); |
262 |
mag=1; |
263 |
ppi=1; |
264 |
unitlength = mag/ppi; |
265 |
dash_mag /= unitlength; |
266 |
|
267 |
// fprintf(tfp, "mag: %f,ppi: %f,dashmag; %f\n",mag,ppi,dash_mag); |
268 |
|
269 |
// fprintf(tfp, "x1: %d,y1: %d,x2; %d,y2 %d\n", |
270 |
// objects->nwcorner.x, |
271 |
// objects->nwcorner.y,objects->secorner.x,objects->secorner.y); |
272 |
//translate_coordinates = translate2; |
273 |
//translate_coordinates_d = translate2_d; |
274 |
offsetx=(float)llx; |
275 |
offsety=(float)lly; |
276 |
|
277 |
x1=(float)llx; |
278 |
y1=(float)lly; |
279 |
x2=(float)urx; |
280 |
y2=(float)ury; |
281 |
TRANS2(x1, y1, x2, y2); |
282 |
//if (llx > urx) SWAP(llx, urx) |
283 |
//if (lly > ury) SWAP(lly, ury) |
284 |
|
285 |
// if((urx>300) || (ury>300)) { |
286 |
|
287 |
scale=urx/SCALEFAKTOR; |
288 |
|
289 |
// if (scale<1) scale=1; |
290 |
|
291 |
// urx=(double)urx/6; |
292 |
// ury=(double)ury/6; |
293 |
fprintf(tfp, "<Dimensions w=\"%.3f\" h=\"%.3f\" defaultAspect=\"0.75\"/>\n",x2/scale,y2/scale); |
294 |
fprintf(tfp, "<KivioShape type=\"TextBox\" name=\"TextBox%d\" x=\"0.0\" y=\"0.0\" w=\"%.3f\" h=\"%.3f\" />\n",counter++,x2/scale,y2/scale); |
295 |
|
296 |
// TRANS2(llx, lly, urx, ury); |
297 |
// } else |
298 |
// fprintf(tfp, "<Dimensions w=\"%d\" h=\"%d\" defaultAspect=\"0.75\"/>\n",urx,ury); |
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
/* LaTeX start */ |
305 |
|
306 |
/* print any whole-figure comments prefixed with "%" */ |
307 |
// if (objects->comments) { |
308 |
// fprintf(tfp,"%%\n"); |
309 |
// print_comments("% ",objects->comments, ""); |
310 |
// fprintf(tfp,"%%\n"); |
311 |
// } |
312 |
|
313 |
// fprintf(tfp, "\\setlength{\\unitlength}{%lisp}%%\n", |
314 |
// (long) (round(4736286.72*unitlength))); |
315 |
/* define the SetFigFont macro */ |
316 |
// define_setfigfont(tfp); |
317 |
// fprintf(tfp, "\\begin{picture}(%d,%d)(%d,%d)\n", |
318 |
// urx-llx, ury-lly, llx, lly); |
319 |
|
320 |
} |
321 |
|
322 |
int |
323 |
gensml_end() |
324 |
{ |
325 |
fprintf(tfp, "</KivioShapeStencil>\n"); |
326 |
/* all ok */ |
327 |
return 0; |
328 |
} |
329 |
|
330 |
|
331 |
void |
332 |
gensml_line(l) |
333 |
F_line *l; |
334 |
{ |
335 |
F_point *p, *q; |
336 |
float x, y,x1,y1, llx, lly, urx, ury, arrow; |
337 |
float r1,r2; |
338 |
int type=0; |
339 |
if (verbose) |
340 |
fprintf(tfp, "<!--depth: %d, Type: %d, Style: %d, Farbe_fill: %d, Farbe_pen: %d -->\n",l->depth,l->type,l->fill_style,l->fill_color,l->pen_color); |
341 |
|
342 |
/* print any comments prefixed with "%" */ |
343 |
//print_comments("% ",l->comments, ""); |
344 |
|
345 |
// set_linewidth(l->thickness); |
346 |
// setcolor(l->pen_color); |
347 |
p = l->points; |
348 |
q = p->next; |
349 |
|
350 |
|
351 |
|
352 |
if (q == NULL) { /* A single point line */ |
353 |
|
354 |
x = p->x; y = p->y; |
355 |
TRANS(x, y); |
356 |
|
357 |
// fprintf(tfp, "\\put(%3d,%3d){\\makebox(%.4f,%.4f){%s}}\n", |
358 |
// x, y, dot_xoffset, dot_yoffset, dot_cmd); |
359 |
fprintf(tfp, "<KivioShape type=\"LineArray\" name=\"Point%d\">\n",counter++); |
360 |
|
361 |
fprintf(tfp, "\t<Line x1=\"%.3f\" y1=\"%.3f\" x2=\"%.3f\" y2=\"%.3f\"/>\n", |
362 |
x, y, x+0.001, y+0.001); |
363 |
} |
364 |
|
365 |
/* a box, perhaps with rounded corners */ |
366 |
else |
367 |
switch (l->type) { |
368 |
case T_BOX: |
369 |
case T_ARC_BOX: { |
370 |
x = p->x; y = p->y; |
371 |
TRANS(x, y); |
372 |
llx = urx = x; |
373 |
lly = ury = y; |
374 |
while (q != NULL) { |
375 |
x = q->x; y = q->y; |
376 |
TRANS(x, y); |
377 |
if (x < llx) llx = x; |
378 |
if (y < lly) lly = y; |
379 |
if (x > urx) urx = x; |
380 |
if (y > ury) ury = y; |
381 |
q = q->next; |
382 |
} |
383 |
|
384 |
//if ((l->fill_style != -1) && (l->fill_color !=-1 )) { |
385 |
if (l->type == T_ARC_BOX) { |
386 |
// put_arc_box (llx, lly, urx, ury, l->radius, l->style, l->style_val); |
387 |
r1=l->radius/scale/ppi; |
388 |
r2=l->radius/scale/ppi; |
389 |
// //TRANS(r1,r2); |
390 |
fprintf(tfp, "<KivioShape type=\"RoundRectangle\" name=\"RoundRectangle%d\" x=\"%.3f\" y=\"%.3f\" w=\"%.3f\" h=\"%.3f\" r1=\"%0.2f\" r2=\"%0.2f\">\n", |
391 |
counter++, llx, lly, urx-llx, ury-lly,r1,r2); |
392 |
} |
393 |
else { |
394 |
fprintf(tfp, "<KivioShape type=\"Rectangle\" name=\"Rectangle%d\" x=\"%.3f\" y=\"%.3f\" w=\"%.3f\" h=\"%.3f\">\n", |
395 |
counter++, llx, lly, urx-llx, ury-lly); |
396 |
|
397 |
|
398 |
} |
399 |
/*} else |
400 |
{ |
401 |
fprintf(tfp, "<KivioShape type=\"LineArray\" name=\"Rectangle%d\">\n",counter++); |
402 |
fprintf(tfp, "\t<Line x1=\"%.3f\" y1=\"%.3f\" x2=\"%.3f\" y2=\"%.3f\"/>\n", |
403 |
llx, lly, urx,lly); |
404 |
fprintf(tfp, "\t<Line x1=\"%.3f\" y1=\"%.3f\" x2=\"%.3f\" y2=\"%.3f\"/>\n", |
405 |
urx,lly, urx,ury); |
406 |
fprintf(tfp, "\t<Line x1=\"%.3f\" y1=\"%.3f\" x2=\"%.3f\" y2=\"%.3f\"/>\n", |
407 |
urx,ury,llx,ury); |
408 |
fprintf(tfp, "\t<Line x1=\"%.3f\" y1=\"%.3f\" x2=\"%.3f\" y2=\"%.3f\"/>\n", |
409 |
llx,ury, llx,lly); |
410 |
} |
411 |
*/ |
412 |
break; |
413 |
} |
414 |
case T_POLYLINE: |
415 |
case T_POLYGON: { |
416 |
|
417 |
if ( (l->fill_style == -1) && (l->fill_color ==-1 )) |
418 |
{ |
419 |
fprintf(tfp, "<KivioShape type=\"Polyline\" name=\"Polyline%d\">\n",counter++); |
420 |
type=0; |
421 |
} |
422 |
else |
423 |
{ |
424 |
fprintf(tfp, "<KivioShape type=\"Polygon\" name=\"Polygon%d\">\n",counter++); |
425 |
|
426 |
|
427 |
type=0; |
428 |
|
429 |
// fprintf(tfp, "<KivioShape type=\"LineArray\" name=\"LineArray%d\">\n",counter++); |
430 |
//type=1; |
431 |
} |
432 |
|
433 |
|
434 |
// if (l->type == T_BOUNDINGBOX) |
435 |
// fprintf(tfp, "<KivioShape type=\"Polygon\" name=\"Lines\">\n"); |
436 |
|
437 |
|
438 |
|
439 |
while (q != NULL) { |
440 |
//arrow = 0; |
441 |
//if (l->for_arrow && q->next == NULL) |
442 |
//arrow = 1; |
443 |
//if (l->back_arrow && p == l->points) |
444 |
//arrow = (arrow)? 2: -1; |
445 |
if (type==0) { |
446 |
// if ((l->type == T_POLYGON) && (l->fill_style != UNFILLED)) { |
447 |
x = p->x; y = p->y; |
448 |
TRANS(x, y); |
449 |
fprintf(tfp, "\t<KivioPoint x=\"%.3f\" y=\"%.3f\"/>\n",x,y); |
450 |
} |
451 |
else { |
452 |
x=p->x; |
453 |
y=p->y; |
454 |
x1=q->x; |
455 |
y1=q->y; |
456 |
TRANS2(x, y, x1, y1); |
457 |
fprintf(tfp, "\t<Line x1=\"%.3f\" y1=\"%.3f\" x2=\"%.3f\" y2=\"%.3f\"/>\n", |
458 |
x, y, x1,y1); |
459 |
|
460 |
// single_line(p->x, p->y, q->x, q->y, arrow, l->style, l->style_val); |
461 |
} |
462 |
|
463 |
p = q; |
464 |
q = q->next; |
465 |
} |
466 |
|
467 |
if (type==0) { |
468 |
|
469 |
x = p->x; y = p->y; |
470 |
TRANS(x, y); |
471 |
fprintf(tfp, "\t<KivioPoint x=\"%.3f\" y=\"%.3f\"/>\n",x,y); |
472 |
} |
473 |
break; |
474 |
} |
475 |
default: { fprintf(stderr, "Objekt nicht unterstützt\n"); |
476 |
} |
477 |
|
478 |
} |
479 |
set_linewidth(l->thickness,l->pen_color); |
480 |
//if (type==0) |
481 |
set_arrow(&(l->for_arrow),&(l->back_arrow)); |
482 |
|
483 |
setcolor(l->fill_style,l->fill_color); |
484 |
end_line(); |
485 |
} |
486 |
|
487 |
void |
488 |
gensml_spline(s) |
489 |
F_spline *s; |
490 |
{ |
491 |
fprintf(stderr, "Can't generate spline; omitting object\n"); |
492 |
} |
493 |
|
494 |
void |
495 |
gensml_ellipse(e) |
496 |
F_ellipse *e; |
497 |
{ |
498 |
float x, y, d, dx, dy; |
499 |
|
500 |
if (verbose) |
501 |
if (verbose) |
502 |
fprintf(tfp, "<!--depth: %d, Type: %d, Style: %d, Farbe_fill: %d, Farbe_pen: %d -->\n",e->depth,e->type,e->fill_style,e->fill_color,e->pen_color); |
503 |
|
504 |
/* print any comments prefixed with "%" */ |
505 |
print_comments("<!-- ",e->comments, "-->"); |
506 |
|
507 |
switch (e->style) { |
508 |
case SOLID_LINE: |
509 |
break; |
510 |
case DASH_LINE: |
511 |
fprintf(stderr, "Dashed circles and elipses not supported\n"); |
512 |
break; |
513 |
case DOTTED_LINE: |
514 |
fprintf(stderr, "Dotted circles and elipses not supported\n"); |
515 |
break; |
516 |
} |
517 |
|
518 |
x = e->center.x; |
519 |
y = e->center.y; |
520 |
TRANS(x, y); |
521 |
|
522 |
TRANS(x, y); |
523 |
if ((e->type == T_CIRCLE_BY_RAD || e->type == T_CIRCLE_BY_DIA) |
524 |
&& e->radiuses.x*unitlength <= MAXCIRCLERAD) { |
525 |
d = 2 * e->radiuses.x; |
526 |
|
527 |
|
528 |
|
529 |
if (e->fill_style == BLACK_FILL) |
530 |
// fprintf(tfp, "\\put(%3d,%3d){\\circle*{%d}}\n", x, y, d) |
531 |
; |
532 |
else { |
533 |
// fprintf(tfp, "\\put(%3d,%3d){\\circle{%d}}\n", x, y, d); |
534 |
if (e->fill_style != UNFILLED) |
535 |
fprintf(stderr, "Circle area fill not implemented\n"); |
536 |
} |
537 |
fprintf(tfp, "<!-- -->\n"); |
538 |
|
539 |
|
540 |
fprintf(tfp, "<KivioShape type=\"Ellipse\" name=\"Circle%d\" x=\"%.3f\" y=\"%.3f\" w=\"%.3f\" h=\"%.3f\">\n", |
541 |
counter++,x, y, d, d); |
542 |
|
543 |
} else { |
544 |
dx = 2*e->radiuses.x/scale; |
545 |
dy = 2*e->radiuses.y /scale; |
546 |
x = e->center.x-e->radiuses.x; |
547 |
y = e->center.y-e->radiuses.y; |
548 |
|
549 |
TRANS(x,y); |
550 |
fprintf(tfp, "<KivioShape type=\"Ellipse\" name=\"Ellipse%d\" x=\"%.3f\" y=\"%.3f\" w=\"%.3f\" h=\"%.3f\">\n", |
551 |
counter++,x, y, dx, dy); |
552 |
} |
553 |
setcolor(e->fill_style,e->fill_color); |
554 |
set_linewidth(e->thickness,e->pen_color); |
555 |
end_line(); |
556 |
} |
557 |
|
558 |
void |
559 |
gensml_text(t) |
560 |
F_text *t; |
561 |
{ |
562 |
float x, y; |
563 |
char *tpos; |
564 |
unsigned char *cp; |
565 |
|
566 |
if (verbose) |
567 |
fprintf(tfp, "<!-- Fig TEXT object-->\n"); |
568 |
|
569 |
/* print any comments prefixed with "%" */ |
570 |
print_comments("<!-- ",t->comments, "-->"); |
571 |
|
572 |
x = t->base_x; |
573 |
y = t->base_y; |
574 |
TRANS(x, y); |
575 |
|
576 |
switch (t->type) { |
577 |
|
578 |
case T_LEFT_JUSTIFIED: |
579 |
case DEFAULT: |
580 |
tpos = "0"; |
581 |
break; |
582 |
|
583 |
case T_CENTER_JUSTIFIED: |
584 |
tpos = "1"; |
585 |
break; |
586 |
|
587 |
case T_RIGHT_JUSTIFIED: |
588 |
tpos = "[rb]"; |
589 |
break; |
590 |
|
591 |
default: |
592 |
fprintf(stderr, "Text incorrectly positioned\n"); |
593 |
tpos = "[lb]"; /* make left in this case */ |
594 |
} |
595 |
|
596 |
/* smash is used to position text at baseline */ |
597 |
// unpsfont(t); |
598 |
|
599 |
fprintf(tfp, "<KivioShape type=\"TextBox\" name=\"TextBox%d\" x=\"%.3f\" y=\"%.3f\" w=\"100\" h=\"100\">\n",counter++,x,y); |
600 |
fprintf(tfp, " <Position x=\"0\" y=\"0\" />\n"); |
601 |
fprintf(tfp, " <Dimension w=\"100\" h=\"100\" />\n"); |
602 |
setcolor(1,t->color); |
603 |
fprintf(tfp, " <KivioTextStyle vTextAlign=\"32\" isHtml=\"0\" hTextAlign=\"%d\" text=\"%s\" />\n",t->type,t->cstring); |
604 |
fprintf(tfp, " <Font fixedPitch=\"0\" size=\"%d\" strikeOut=\"0\" family=\"\" bold=\"0\" underline=\"0\" color=\"#0\"/>\n",t->size); |
605 |
fprintf(tfp, "</KivioShape>\n"); |
606 |
|
607 |
{ int texsize; |
608 |
double baselineskip; |
609 |
|
610 |
texsize = TEXFONTMAG(t); |
611 |
baselineskip = (texsize * 1.2); |
612 |
|
613 |
} |
614 |
|
615 |
|
616 |
} |
617 |
|
618 |
void |
619 |
gensml_arc(a) |
620 |
F_arc *a; |
621 |
{ |
622 |
F_pos p1, p2, pq[4]; |
623 |
double cx, cy; |
624 |
double v1x, v1y, v2x, v2y; |
625 |
double r, angle1, angle2; |
626 |
float q1, q2 ; |
627 |
float y,x; |
628 |
int p1_arrow, p2_arrow,i; |
629 |
static char *ad1[4] = { " 0,-1", " 1, 0", " 0, 1", "-1, 0" }; |
630 |
static char *ad2[4] = { "-1, 0", " 0,-1", " 1, 0", " 0, 1" }; |
631 |
|
632 |
if (verbose) |
633 |
fprintf(tfp, "<!-- Fig ARC object -->\n"); |
634 |
|
635 |
/* print any comments prefixed with "%" */ |
636 |
// print_comments("% ",a->comments, ""); |
637 |
|
638 |
// set_linewidth(a->thickness); |
639 |
// if (a->fill_style != UNFILLED) setcolor(a->pen_color); |
640 |
// switch (a->style) { |
641 |
// case SOLID_LINE: |
642 |
// break; |
643 |
// case DASH_LINE: |
644 |
// fprintf(stderr, "Dashed arcs not supported\n"); |
645 |
// break; |
646 |
// case DOTTED_LINE: |
647 |
// fprintf(stderr, "Dotted arcs not supported\n"); |
648 |
// break; |
649 |
// } |
650 |
// if (a->direction == 1) { |
651 |
// p1 = a->point[0]; |
652 |
// p2 = a->point[2]; |
653 |
// p1_arrow = (a->back_arrow != NULL); |
654 |
// p2_arrow = (a->for_arrow != NULL); |
655 |
// } else { |
656 |
// p1 = a->point[2]; |
657 |
// p2 = a->point[0]; |
658 |
// p1_arrow = (a->for_arrow != NULL); |
659 |
// p2_arrow = (a->back_arrow != NULL); |
660 |
// } |
661 |
|
662 |
|
663 |
fprintf(tfp, "<KivioShape type=\"Bezier\" name=\"Bezier%d\">\n",counter++); |
664 |
|
665 |
|
666 |
/* cx = a->center.x; |
667 |
cy = a->center.y; |
668 |
TRANS2(p1.x, p1.y, p2.x, p2.y); |
669 |
TRANSD(cx, cy); |
670 |
/*** compute vectors and angles from arc center to p1, p2 ***/ |
671 |
/* v1x = (double)p1.x - cx; |
672 |
v1y = (double)p1.y - cy; |
673 |
v2x = (double)p2.x - cx; |
674 |
v2y = (double)p2.y - cy; |
675 |
angle1 = atan2(v1y, v1x) * rad2deg; |
676 |
angle2 = atan2(v2y, v2x) * rad2deg; |
677 |
if (angle1 < 0.0) |
678 |
angle1 += 360.0; |
679 |
if (angle2 < 0.0) |
680 |
angle2 += 360.0; |
681 |
/* compute arc radius */ |
682 |
// r = sqrt(v1x*v1x+v1y*v1y); |
683 |
/*** compute intersection of arc with x and y axis (origin at cx, cy) */ |
684 |
// pq[0].x = round(cx); |
685 |
// pq[0].y = round(cy + r); |
686 |
// pq[1].x = round(cx - r); |
687 |
// pq[1].y = round(cy); |
688 |
// pq[2].x = round(cx); |
689 |
// pq[2].y = round(cy - r); |
690 |
// pq[3].x = round(cx + r); |
691 |
// pq[3].y = round(cy); |
692 |
|
693 |
|
694 |
for(i=0;i<=2;i++) { |
695 |
x=a->point[i].x; |
696 |
y=a->point[i].y; |
697 |
TRANS(x,y); |
698 |
fprintf(tfp, "\t<KivioPoint x=\"%.3f\" y=\"%.3f\" type=\"bezier\" />\n",x,y); |
699 |
if (i==1) fprintf(tfp, "\t<KivioPoint x=\"%.3f\" y=\"%.3f\" type=\"bezier\" />\n",x,y); |
700 |
} |
701 |
|
702 |
/*** compute in which quadrants p1 and p2 are located ***/ |
703 |
/*q1 = (int)(angle1/90.0); |
704 |
q2 = (int)(angle2/90.0); |
705 |
if (fabs(angle1 - 90.0*q1) > arc_tolerance |
706 |
|| fabs(angle2 - 90.0*q2) > arc_tolerance) |
707 |
// fprintf(stderr, "Approximating arc by ovals\n"); |
708 |
|
709 |
/*** Draw arc ** |
710 |
if (a->type == T_OPEN_ARC && a->thickness != 0 && p1_arrow) |
711 |
// fprintf(tfp, "\\put(%3d,%3d){\\vector(%s){0}}\n", p1.x, p1.y, ad1[q1]); |
712 |
|
713 |
|
714 |
while (q1 != q2) { |
715 |
put_quarter(p1, pq[q1], q1); |
716 |
p1 = pq[q1]; |
717 |
q1 = (q1 + 1) % 4; |
718 |
} |
719 |
put_quarter(p1, p2, q1); |
720 |
if (a->type == T_OPEN_ARC && a->thickness != 0 && p2_arrow) |
721 |
// fprintf(tfp, "\\put(%3d,%3d){\\vector(%s){0}}\n", p2.x, p2.y, ad2[q2]); |
722 |
|
723 |
if (a->fill_style != UNFILLED) |
724 |
fprintf(stderr, "Arc area fill not implemented\n"); |
725 |
// resetcolor(a->pen_color); |
726 |
*/ |
727 |
setcolor(a->fill_style,a->fill_color); |
728 |
set_linewidth(a->thickness,a->pen_color); |
729 |
end_line(); |
730 |
|
731 |
} |
732 |
|
733 |
|
734 |
#define MAXCOLORS 32 |
735 |
|
736 |
/* need this for communication between color routines. Sorry */ |
737 |
static int lastcolor=-1; |
738 |
|
739 |
void setcolor(sty,col) |
740 |
int sty,col; |
741 |
{ |
742 |
int color,style; |
743 |
|
744 |
color=rgbColorVal(col); |
745 |
|
746 |
if(col==7) { |
747 |
if(sty==20) |
748 |
color=255; |
749 |
else |
750 |
color=(255/20)*sty; |
751 |
color=256*256*color+256*color+color; |
752 |
} |
753 |
|
754 |
if((col==0) || (col==-1)) { |
755 |
if(sty==20) |
756 |
color=0; |
757 |
else |
758 |
color=255-(255/20)*sty; |
759 |
color=256*256*color+256*color+color; |
760 |
} |
761 |
|
762 |
if(sty==-1) |
763 |
style=0; |
764 |
else |
765 |
style=1; |
766 |
|
767 |
fprintf(tfp, "\t<KivioFillStyle colorStyle=\"%d\" color=\"#%6.6x\" />\n", style ,color); |
768 |
return; |
769 |
} |
770 |
|
771 |
int |
772 |
set_linewidth(w,col) |
773 |
int w,col; |
774 |
{ |
775 |
float i,x; |
776 |
x=1; |
777 |
i=w/20; |
778 |
fprintf(tfp, "\t<KivioLineStyle width=\"%.3f\" capStyle=\"32\" pattern=\"1\" joinStyle=\"128\" color=\"#%6.6x\" />\n", |
779 |
i,rgbColorVal(col) ); |
780 |
} |
781 |
|
782 |
|
783 |
void end_line() |
784 |
{ |
785 |
fprintf(tfp, "</KivioShape>\n"); |
786 |
} |
787 |
|
788 |
int |
789 |
set_arrow(F_arrow *for_arrow,F_arrow *back_arrow) |
790 |
{ |
791 |
int f, f_t, f_ht, f_wid, b, b_t, b_ht, b_wid; |
792 |
|
793 |
if (verbose) fprintf(tfp, "<!--%d %d -->\n",(for_arrow==NULL),(back_arrow==NULL)); |
794 |
|
795 |
if(((for_arrow==NULL)==0) && ((back_arrow==NULL)==0)) { |
796 |
return; |
797 |
} |
798 |
|
799 |
if((for_arrow!=NULL)==0) { |
800 |
f_t=for_arrow->type==0 ? 1 : 2; |
801 |
f_wid=for_arrow->wid; |
802 |
f_ht=for_arrow->ht; |
803 |
} |
804 |
else |
805 |
{ |
806 |
f_t==0; |
807 |
f_wid=0; |
808 |
f_ht=0; |
809 |
} |
810 |
if((back_arrow!=NULL)==0) { |
811 |
b_t=back_arrow->type==0 ? 1 : 2; |
812 |
b_wid=back_arrow->wid; |
813 |
b_ht=back_arrow->ht; |
814 |
} |
815 |
else |
816 |
{ |
817 |
b_t=0; |
818 |
b_wid=0; |
819 |
b_ht=0; |
820 |
} |
821 |
fprintf(tfp, "<KivioArrowHeads>\n"); |
822 |
fprintf(tfp, "\t<KivioArrowHead w=\"%d\" l=\"%d\" type=\"%d\" cut=\"0\" />\n",f_wid,f_ht,f_t); |
823 |
fprintf(tfp, "\t<KivioArrowHead w=\"%d\" l=\"%d\" type=\"%d\" cut=\"0\" />\n",b_wid,b_ht,b_t); |
824 |
fprintf(tfp, "</KivioArrowHeads>\n"); |
825 |
return; |
826 |
} |
827 |
|
828 |
static unsigned int |
829 |
rgbColorVal(int colorIndex) |
830 |
{ |
831 |
extern User_color user_colors[]; |
832 |
unsigned int rgb; |
833 |
static unsigned int rgbColors[NUM_STD_COLS] = { |
834 |
0x000000, 0x0000ff, 0x00ff00, 0x00ffff, 0xff0000, 0xff00ff, |
835 |
0xffff00, 0xffffff, 0x00008f, 0x0000b0, 0x0000d1, 0x87cfff, |
836 |
0x008f00, 0x00b000, 0x00d100, 0x008f8f, 0x00b0b0, 0x00d1d1, |
837 |
0x8f0000, 0xb00000, 0xd10000, 0x8f008f, 0xb000b0, 0xd100d1, |
838 |
0x803000, 0xa14000, 0xb46100, 0xff8080, 0xffa1a1, 0xffbfbf, |
839 |
0xffe0e0, 0xffd600 |
840 |
}; |
841 |
|
842 |
if (colorIndex == DEFAULT) |
843 |
rgb = rgbColors[0]; |
844 |
else if (colorIndex < NUM_STD_COLS) |
845 |
rgb = rgbColors[colorIndex]; |
846 |
else |
847 |
rgb = ((user_colors[colorIndex-NUM_STD_COLS].r & 0xff) << 16) |
848 |
| ((user_colors[colorIndex-NUM_STD_COLS].g & 0xff) << 8) |
849 |
| (user_colors[colorIndex-NUM_STD_COLS].b & 0xff); |
850 |
return rgb; |
851 |
} |
852 |
|
853 |
|
854 |
struct driver dev_sml = { |
855 |
gensml_option, |
856 |
gensml_start, |
857 |
gensml_arc, |
858 |
gensml_ellipse, |
859 |
gensml_line, |
860 |
gensml_spline, |
861 |
gensml_text, |
862 |
gensml_end, |
863 |
EXCLUDE_TEXT |
864 |
}; |