rllib  1
rlsvgvdi.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  rlsvgsdi.cpp - description
3  -------------------
4  begin : Tu Mar 17 2016
5  copyright : (C) 2016 by R. Lehrig
6  email : lehrig@t-online.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #include "rlsvgvdi.h"
18 #include "rlcutil.h"
19 #include <math.h>
20 #include <stdarg.h>
21 #ifdef RLWIN32
22 #include <winsock2.h>
23 #include <windows.h>
24 #include <io.h>
25 #include <direct.h>
26 #define MSG_NOSIGNAL 0
27 #else
28 #include <sys/time.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <arpa/inet.h>
32 #include <netdb.h>
33 #include "unistd.h"
34 #endif
35 
36 #ifdef PVMAC
37 #define MSG_NOSIGNAL 0
38 #endif
39 
41 {
42  sout = NULL;
43  fout = NULL;
44  pipe = NULL;
45  idForPvbrowser = 0;
46  outputState = 0;
47  fontsize = 10;
48  fontstring.printf("font-family=\"%s\" font-weight=\"%s\" font-size=\"%d\"", "Times", "normal", fontsize);
49  strcpy(stroke,"#000000"); // black
50  lineoptions.printf("stroke=\"%s\"", stroke);
51  textoptions.printf("stroke=\"%s\" %s", stroke, fontstring.text());
52  strcpy(floatFormat,"%.2f");
53  dx = dy = 1.0f;
54  sr = 3;
55  boxx = boxy = boxw = boxh = 0;
56  xmin = 0.0f;
57  xmax = 100.0f;
58  ymin = 0.0f;
59  ymax = 100.0f;
60  width = 1;
61  xold = yold = 0;
62 }
63 
65 {
66  endOutput();
67 }
68 
69 int rlSvgVdi::setOutput(int *_socket_out, int _idForPvbrowser)
70 {
71  pipe = NULL;
72  sout = _socket_out;
73  if(*sout < 0)
74  {
75  outputState = -1;
76  return -1;
77  }
78  if(strlen(outputfilename.text()) == 0)
79  {
80  }
81  else
82  {
83  if(fout != NULL) fclose(fout);
84  }
85  fout = NULL;
86  outputfilename = "";
87  idForPvbrowser = _idForPvbrowser;
88  outputState = 1;
89  if(idForPvbrowser > 0)
90  {
91  char buf[80];
92  sprintf(buf,"gsvgRead(%d)\n", idForPvbrowser);
93  perhapsSend(buf);
94  }
95  return 0;
96 }
97 
98 int rlSvgVdi::setOutput(FILE *_fout)
99 {
100  pipe = NULL;
101  sout = NULL;
102  if(strlen(outputfilename.text()) == 0)
103  {
104  }
105  else
106  {
107  if(fout != NULL) fclose(fout);
108  }
109  fout = _fout;
110  if(fout == NULL)
111  {
112  outputState = -1;
113  return -1;
114  }
115  outputfilename = "";
116  outputState = 1;
117  return 0;
118 }
119 
120 int rlSvgVdi::setOutput(const char *_outputfilename)
121 {
122  pipe = NULL;
123  sout = NULL;
124  if(strlen(outputfilename.text()) == 0)
125  {
126  }
127  else
128  {
129  if(fout != NULL) fclose(fout);
130  }
131  outputfilename = _outputfilename;
132  fout = fopen(_outputfilename,"w");
133  if(fout == NULL)
134  {
135  outputState = -1;
136  return -1;
137  }
138  outputState = 1;
139  return 0;
140 }
141 
143 {
144  pipe = _pipe;
145  sout = NULL;
146  if(strlen(outputfilename.text()) == 0)
147  {
148  }
149  else
150  {
151  if(fout != NULL) fclose(fout);
152  }
153  outputfilename = "";
154  if(pipe == NULL)
155  {
156  outputState = -1;
157  return -1;
158  }
159  outputState = 1;
160  return 0;
161 }
162 
164 {
165  if(sout != NULL && idForPvbrowser > 0)
166  {
167  char buf[80];
168  sprintf(buf,"\n<svgend></svgend>\n");
169  perhapsSend(buf);
170  sprintf(buf,"gbeginDraw(%d)\n", idForPvbrowser);
171  perhapsSend(buf);
172  sprintf(buf,"gupdateSVG(%d)\n", idForPvbrowser);
173  perhapsSend(buf);
174  sprintf(buf,"gendDraw\n");
175  perhapsSend(buf);
176  }
177  if(strlen(outputfilename.text()) == 0)
178  {
179  }
180  else
181  {
182  if(fout != NULL) fclose(fout);
183  fout = NULL;
184  }
185  if(pipe != NULL)
186  {
187  char buf[4];
188  buf[0] = EOF;
189  buf[1] = '\0';
190  pipe->writeString(buf);
191  pipe = NULL;
192  }
193  svg = "";
194  svg2 = "";
195  svg3 = "";
196  if(outputState < 0) return -1;
197  outputState = 0;
198  return 0;
199 }
200 
201 int rlSvgVdi::perhapsSend(const char *text)
202 {
203  if(outputState <= 0) return -1;
204  if(sout != NULL)
205  {
206  int ret,bytes_left,first_byte;
207  const char *cbuf;
208  if(sout == NULL) return -1;
209  if(*sout == -1) return -1;
210  cbuf = text;
211  bytes_left = strlen(text);
212  first_byte = 0;
213 
214  while(bytes_left > 0)
215  {
216  ret = send(*sout,&cbuf[first_byte],bytes_left,MSG_NOSIGNAL);
217  if(ret <= 0)
218  {
219  //disconnect();
220  if(*sout != -1)
221  {
222 #ifdef RLWIN32
223  closesocket(*sout);
224 #else
225  close(*sout);
226 #endif
227  }
228  *sout = -1;
229  outputState = -1;
230  return -1;
231  }
232  bytes_left -= ret;
233  first_byte += ret;
234  }
235  }
236  else if(fout != NULL)
237  {
238  if(fputs(text, fout) < 0)
239  {
240  outputState = -1;
241  }
242  }
243  else if(pipe != NULL)
244  {
245  if(pipe->writeString(text) < 0)
246  {
247  outputState = -1;
248  }
249  }
250  else
251  {
252  outputState = 0;
253  }
254  return 0;
255 }
256 
257 const char *rlSvgVdi::svgHeader(int width, int height, int rbackground, int gbackground, int bbackground)
258 {
259  svg.printf("<svg width=\"%dpx\" height=\"%dpx\" viewBox=\"0 0 %d %d\" style=\"background: rgb(%d,%d,%d)\"\n", width, height, width, height, rbackground, gbackground, bbackground);
260  svg += " xmlns=\"http://www.w3.org/2000/svg\" version=\"1.2\" baseProfile=\"tiny\">\n";
261  svg += " <desc>svgvdi for smf files</desc>\n";
262  perhapsSend(svg.text());
263  return svg.text();
264 }
265 
266 const char *rlSvgVdi::svgTrailer()
267 {
268  svg = "</svg>\n";
269  perhapsSend(svg.text());
270  return svg.text();
271 }
272 
273 const char *rlSvgVdi::drawEllipse(int x, int y, int rx, int ry)
274 {
275  svg.printf("<ellipse cx=\"%d\" cy=\"%d\" rx=\"%d\" ry=\"%d\" %s />\n", x, y, rx, ry, lineoptions.text());
276  perhapsSend(svg.text());
277  return svg.text();
278 }
279 
280 const char* rlSvgVdi::moveTo(int x, int y)
281 {
282  xold = x;
283  yold = y;
284  return "";
285 }
286 
287 const char *rlSvgVdi::lineTo(int x, int y)
288 {
289  int xnew, ynew;
290  xnew = x;
291  ynew = y;
292  svg.printf("<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" %s />\n", xold, yold, xnew, ynew, lineoptions.text());
293  xold = xnew;
294  yold = ynew;
295  perhapsSend(svg.text());
296  return svg.text();
297 }
298 
299 const char *rlSvgVdi::line(int x1, int y1, int x2, int y2)
300 {
301  int xnew, ynew;
302  xold = x2;
303  yold = y2;
304  xnew = x1;
305  ynew = y1;
306  svg.printf("<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" %s />\n", xold, yold, xnew, ynew, lineoptions.text());
307  perhapsSend(svg.text());
308  return svg.text();
309 }
310 
311 const char *rlSvgVdi::textInAxis(float x, float y, const char *txt, int alignment)
312 {
313  float dy;
314 /*
315  ymax-ymin dy
316  ----------- = ----------
317  boxh fontsize/2
318 */
319  if(alignment == ALIGN_CENTER)
320  {
321  dy = ((ymax-ymin) * (fontsize/2) ) / (boxh);
322  return text(tx(x), ty(y+dy), txt, alignment);
323  }
324  else
325  {
326  return text(tx(x), ty(y), txt, alignment);
327  }
328 }
329 
330 const char *rlSvgVdi::text(int x, int y, const char *txt, int alignment)
331 {
332  switch(alignment)
333  {
334  case ALIGN_LEFT: // |example
335  svg.printf("<text x=\"%d\" y=\"%d\" %s>%s</text>\n", x, y, textoptions.text(), txt);
336  break;
337  case ALIGN_CENTER: // exa|mple
338  svg.printf("<text x=\"%d\" y=\"%d\" text-anchor=\"middle\" %s>%s</text>\n", x, y, textoptions.text(), txt);
339  break;
340  case ALIGN_RIGHT: // example|
341  svg.printf("<text x=\"%d\" y=\"%d\" text-anchor=\"end\" %s>%s</text>\n", x, y, textoptions.text(), txt);
342  break;
343  case ALIGN_VERT_CENTER:
344  svg.printf("<g transform=\"translate(%d,%d)\" >\n <g transform=\"rotate(-90)\" >\n <text x=\"0\" y=\"0\" text-anchor=\"middle\" %s>%s</text>\n </g>\n</g>\n", x, y, textoptions.text(), txt);
345  break;
346  default:
347  svg.printf("<text x=\"%d\" y=\"%d\" %s>%s/text>\n", x, y, textoptions.text(), txt);
348  break;
349  }
350  perhapsSend(svg.text());
351  return svg.text();
352 }
353 
354 const char *rlSvgVdi::box(int x, int y, int w, int h)
355 {
356  boxx = x;
357  boxy = y;
358  boxw = w;
359  boxh = h;
360  svg2 = moveTo(x ,y );
361  svg2 += lineTo(x+w,y );
362  svg2 += lineTo(x+w,y+h);
363  svg2 += lineTo(x ,y+h);
364  svg2 += lineTo(x ,y );
365  return svg2.text();
366 }
367 
368 const char *rlSvgVdi::boxWithText(int x, int y, int w, int h, int fontsize, const char *xlabel, const char *ylabel, const char * rylabel)
369 {
370  svg3 = box(x,y,w,h);
371  if(xlabel != NULL) svg3 += text(x+w/2,y+h+fontsize*3,xlabel,ALIGN_CENTER);
372  if(ylabel != NULL) svg3 += text(x-fontsize*5,y+h/2,ylabel,ALIGN_VERT_CENTER);
373  if(rylabel != NULL) svg3 += text(x+w+fontsize*5,y+h/2,rylabel,ALIGN_VERT_CENTER);
374  return svg3.text();
375 }
376 
377 const char *rlSvgVdi::rect(int x, int y, int w, int h)
378 {
379  svg2 = moveTo(x ,y );
380  svg2 += lineTo(x+w ,y );
381  svg2 += lineTo(x+w ,y+h);
382  svg2 += lineTo(x ,y+h);
383  svg2 += lineTo(x ,y );
384  return svg2.text();
385 }
386 
387 static int beautyval(char *text)
388 {
389  char *cptr = strchr(text,'.');
390  if(cptr != NULL)
391  {
392  char *end = cptr + strlen(cptr) - 1;
393  while(end != cptr) // eliminate trailing 0
394  {
395  if (*end == '0') { *end = '\0'; }
396  else if(*end == '.') { *end = '\0'; break; }
397  else { break; }
398  end--;
399  }
400  if(cptr == end) *cptr = '\0';
401  }
402  return 0;
403 }
404 
405 const char *rlSvgVdi::xGrid()
406 {
407  svg2 = "";
408  for(float x=(xmin+dx); x<xmax; x+=dx)
409  {
410  svg2 += moveTo(tx(x),boxy);
411  svg2 += lineTo(tx(x),boxy+boxh);
412  }
413  return svg2.text();
414 }
415 
416 const char *rlSvgVdi::yGrid()
417 {
418  svg2 = "";
419  for(float y=(ymin+dy); y<=(ymax-dy); y+=dy)
420  {
421  svg2 += moveTo(boxx,ty(y));
422  svg2 += lineTo(boxx+boxw, ty(y));
423  }
424  return svg2.text();
425 }
426 
427 const char *rlSvgVdi::xAxis(float start, float delta, float end, int draw)
428 {
429  float x;
430  int y;
431  char txt[80];
432 
433  svg2 = "";
434  xmin = start;
435  dx = delta;
436  xmax = end;
437  if(draw==0) return "";
438 
439  x = start;
440  y = boxy + boxh;
441 
442  while(x <= end)
443  {
444  svg2 += moveTo(tx(x),y);
445  svg2 += lineTo(tx(x),y+8);
446  sprintf(txt,floatFormat,x);
447  beautyval(txt);
448  svg2 += text(tx(x),y+((3*fontsize)/2),txt,ALIGN_CENTER);
449  x += delta;
450  }
451 
452  if(start < 0.0f && end > 0.0f)
453  {
454  svg2 += moveTo(tx(0.0f),boxy);
455  svg2 += lineTo(tx(0.0f),boxy+boxh);
456  }
457  return svg2.text();
458 }
459 
460 const char *rlSvgVdi::yAxis(float start, float delta, float end, int draw)
461 {
462 float y;
463 int x;
464 char txt[80];
465 
466  svg2 = "";
467  ymin = start;
468  dy = delta;
469  ymax = end;
470  if(draw==0) return "";
471  x = boxx;
472  y = start;
473 
474  while(y <= end)
475  {
476  svg2 += moveTo(x,ty(y));
477  svg2 += lineTo(x-8,ty(y));
478  sprintf(txt,floatFormat,y);
479  beautyval(txt);
480  svg2 += text(x-10,ty(y),txt,ALIGN_RIGHT);
481  y += delta;
482  }
483 
484 
485  if(start < 0.0f && end > 0.0f)
486  {
487  svg2 += moveTo(boxx,ty(0.0f));
488  svg2 += lineTo(boxx+boxw,ty(0.0f));
489  }
490  return svg2.text();
491 }
492 
493 const char *rlSvgVdi::rightYAxis(float start, float delta, float end, int draw)
494 {
495 float y;
496 int x;
497 char txt[80];
498 
499  ymin = start;
500  dy = delta;
501  ymax = end;
502  if(draw==0) return "";
503  x = boxx+boxw;
504  y = start;
505 
506  svg2 = "";
507  while(y <= end)
508  {
509  xold = x;
510  yold = ty(y);
511  svg2 += moveTo(xold, yold);
512  svg2 += lineTo(xold+8,yold);
513  //p.drawLine(x,ty(y),xold,yold);
514  sprintf(txt,floatFormat,y);
515  beautyval(txt);
516  svg2 += text(xold+10,yold,txt,ALIGN_LEFT);
517  y += delta;
518  }
519 
520  if(start < 0.0f && end > 0.0f)
521  {
522  int xnew, ynew;
523  xold = boxx+boxw;
524  yold = ty(0.0f);
525  xnew = boxx+boxw;
526  ynew = ty(0.0f);
527  svg2 += moveTo(xold,yold);
528  svg2 += lineTo(xnew,ynew);
529  //p.drawLine(xold,yold,xnew,ynew);
530  xold = xnew;
531  yold = ynew;
532  }
533  return svg2.text();
534 }
535 
536 const char *rlSvgVdi::drawSymbol(int x, int y, int type)
537 {
538  //const char *cptr;
539  int xnew, ynew;
540  svg2 = "";
541  switch(type)
542  {
543  case LINESTYLE_CIRCLE:
545  svg2 += drawEllipse(x-sr,y-sr,sr,sr);
546  break;
547  case LINESTYLE_CROSS:
549  xold = x+sr;
550  yold = y-sr;
551  svg2 += line(x-sr,y+sr,xold,yold);
552  xold = x+sr;
553  yold = y+sr;
554  svg2 += line(x-sr,y-sr,xold,yold);
555  break;
556  case LINESTYLE_RECT:
558  xold = x+sr;
559  yold = y-sr;
560  svg2 += line(x-sr,y-sr,xold,yold);
561  xnew = x+sr;
562  ynew = y+sr;
563  svg2 += line(xold,yold,xnew,ynew);
564  xold = xnew;
565  yold = ynew;
566  xnew = x-sr;
567  ynew = y+sr;
568  svg2 += line(xold,yold,xnew,ynew);
569  xold = xnew;
570  yold = ynew;
571  xnew = x-sr;
572  ynew = y-sr;
573  svg2 += line(xold,yold,xnew,ynew);
574  xold = xnew;
575  yold = ynew;
576  break;
577  default:
578  break;
579  }
580  return svg2.text();
581 }
582 
583 const char *rlSvgVdi::line(float *x, float *y, int n, int linestyle)
584 {
585  char buf[80];
586  svg3 = "";
587  if(linestyle != LINESTYLE_CROSS_NO_LINE && linestyle != LINESTYLE_CIRCLE_NO_LINE &&linestyle != LINESTYLE_RECT_NO_LINE )
588  {
589  //svg3 = moveTo(tx(x[0]),ty(y[0]));
590  //for(int i=1; i<n; i++) svg3 += lineTo(tx(x[i]),ty(y[i]));
591  svg3 = "<polyline points=\"";
592  for(int i=0; i<n; i++)
593  {
594  sprintf(buf," %d,%d", tx(x[i]), ty(y[i]));
595  svg3 += buf;
596  }
597  svg3 += "\"\n";
598  svg3 += lineoptions.text();
599  svg3 += " fill=\"none\"/>\n";
600  perhapsSend(svg3.text());
601  }
602  if(linestyle != LINESTYLE_NONE)
603  {
604  for(int i=1; i<n; i++) svg3 += drawSymbol(tx(x[i]),ty(y[i]),linestyle);
605  }
606  return svg3.text();
607 }
608 
609 const char *rlSvgVdi::setColor(int r, int g, int b)
610 {
611  sprintf(stroke,"#%02x%02x%02x", r, g, b);
612  lineoptions.printf("stroke=\"%s\"", stroke);
613  if(strlen(dasharray.text()) > 0)
614  {
615  lineoptions += " stroke-dasharray=\"";
617  lineoptions += "\"";
618  }
619  if(width != 1)
620  {
621  rlString buf;
622  buf.printf(" stroke-width=\"%d\"", width);
623  lineoptions += buf.text();
624  }
625  textoptions.printf("stroke=\"%s\" %s", stroke, fontstring.text());
626  return "";
627 }
628 
629 const char *rlSvgVdi::setFont(const char *family, int size, int weight, int italic)
630 {
631  fontsize = size;
632  if(weight == 1) fontstring.printf("font-family=\"%s\" font-weight=\"%s\" font-size=\"%d\"", family, "normal", size);
633  else fontstring.printf("font-family=\"%s\" font-weight=\"%s\" font-size=\"%d\"", family, "bold", size);
634  if(italic == 1) fontstring += " font-style=\"italic\"";
635  textoptions.printf("stroke=\"%s\" %s", stroke, fontstring.text());
636  return "";
637 }
638 
639 const char *rlSvgVdi::setWidth(int w)
640 {
641  width = w;
642  lineoptions.printf("stroke=\"%s\"", stroke);
643  if(strlen(dasharray.text()) > 0)
644  {
645  lineoptions += " stroke-dasharray=\"";
647  lineoptions += "\"";
648  }
649  if(width != 1)
650  {
651  rlString buf;
652  buf.printf(" stroke-width=\"%d\"", width);
653  lineoptions += buf.text();
654  }
655  return "";
656 }
657 
658 const char *rlSvgVdi::setLinestyle(const char *_dasharray)
659 {
660  dasharray = _dasharray;
661  lineoptions.printf("stroke=\"%s\"", stroke);
662  if(strlen(dasharray.text()) > 0)
663  {
664  lineoptions += " stroke-dasharray=\"";
666  lineoptions += "\"";
667  }
668  if(width != 1)
669  {
670  rlString buf;
671  buf.printf(" stroke-width=\"%d\"", width);
672  lineoptions += buf.text();
673  }
674  return "";
675 }
676 
677 const char *rlSvgVdi::comment(const char *text)
678 {
679  svg.printf("<!-- %s -->\n", text);
680  perhapsSend(svg.text());
681  return svg.text();
682 }
683 
684 const char *rlSvgVdi::svg_put(const char *text)
685 {
686  perhapsSend(text);
687  return text;
688 }
689 
690 const char *rlSvgVdi::svg_printf(const char *format, ...)
691 {
692  int ret;
693  char message[rl_PRINTF_LENGTH]; // should be big enough
694  va_list ap;
695  va_start(ap,format);
696  ret = rlvsnprintf(message, rl_PRINTF_LENGTH - 1, format, ap);
697  va_end(ap);
698  if(ret < 0) return "";
699  return svg_put(message);
700 }
701 
702 const char *rlSvgVdi::svg_d(int *x, int *y, int count)
703 {
704  char buf[80];
705  svg = "d=\"";
706  sprintf(buf,"M %d %d", x[0], y[0]);
707  svg += buf;
708  for(int i=1; i<count; i++)
709  {
710  sprintf(buf," L %d %d", x[i], y[i]);
711  svg += buf;
712  }
713  svg += "\"\n";
714  perhapsSend(svg.text());
715  return svg.text();
716 }
717 
718 const char *rlSvgVdi::svg_points(int *x, int *y, int count)
719 {
720  char buf[80];
721  svg = "points=\"";
722  for(int i=0; i<count; i++)
723  {
724  sprintf(buf," %d,%d", x[i], y[i]);
725  svg += buf;
726  }
727  svg += "\"\n";
728  perhapsSend(svg.text());
729  return svg.text();
730 }
731 
732 int rlSvgVdi::tx(float x)
733 {
734  return (int)(boxx + (((x-xmin)*boxw)/(xmax-xmin))); // x i
735 } // xmax-xmin boxw
736 
737 int rlSvgVdi::ty(float y)
738 {
739  int i0;
740  i0 = (int)((ymin * boxh)/(ymax-ymin));
741  return i0 + (int)(boxy+boxh-((y*boxh)/(ymax-ymin))); // y i ymin i0
742 } // ymax-ymin boxh ymax-ymin boxh
743 
745 {
746  return fontsize;
747 }
748 
750 {
751  return boxx;
752 }
753 
755 {
756  return boxy;
757 }
758 
760 {
761  return boxw;
762 }
763 
765 {
766  return boxh;
767 }
768 
769 /*
770 int interpret(const char *linebuf)
771 {
772 int x,y,w,h,r,g,b,n,i;
773 
774  if(opt.arg_debug > 1) printf("rlSvgVdi=%s",linebuf);
775  switch(linebuf[1])
776  {
777  case 'b':
778  if(strncmp(linebuf,"gbeginDraw",10) == 0)
779  {
780  strcpy(floatFormat,"%.2f");
781  beginDraw(1);
782  }
783  else if(strncmp(linebuf,"gbox",4) == 0)
784  {
785  sscanf(linebuf,"gbox(%d,%d,%d,%d)",&x,&y,&w,&h);
786  box(x,y,w,h);
787  }
788  break;
789  case 'd':
790  if(strncmp(linebuf,"gdrawArc",8) == 0)
791  {
792  int astart,alen;
793  sscanf(linebuf,"gdrawArc(%d,%d,%d,%d,%d,%d)",&x,&y,&w,&h,&astart,&alen);
794  p.drawArc(zx(x),zy(y),zx(w),zy(h),astart*16,alen*16);
795  }
796  else if(strncmp(linebuf,"gdrawPie",8) == 0)
797  {
798  int astart,alen;
799  sscanf(linebuf,"gdrawPie(%d,%d,%d,%d,%d,%d)",&x,&y,&w,&h,&astart,&alen);
800  p.drawPie(zx(x),zy(y),zx(w),zy(h),astart*16,alen*16);
801  }
802  else if(strncmp(linebuf,"gdrawPolygon",12) == 0)
803  {
804  char buf[80];
805  int cnt;
806  sscanf(linebuf,"gdrawPolygon(%d)",&cnt);
807  QPolygon points(cnt);
808  i=0;
809  while(1)
810  {
811  gets(buf,sizeof(buf)-1);
812  if(buf[0] == '}') break;
813  sscanf(buf,"%d,%d",&x,&y);
814  points.setPoint(i++,zx(x),zy(y));
815  }
816  p.drawPolygon(points);
817  }
818  break;
819  case 'e':
820  if(strncmp(linebuf,"gendDraw",8) == 0)
821  {
822  strcpy(floatFormat,"%.2f");
823  endDraw();
824  return -1;
825  }
826  break;
827  case 'l':
828  if(strncmp(linebuf,"glineTo",7) == 0)
829  {
830  sscanf(linebuf,"glineTo(%d,%d)",&x,&y);
831  lineTo(x,y);
832  }
833  else if(strncmp(linebuf,"gline(",6) == 0)
834  {
835  int maxarray = MAXARRAY;
836  const char *cptr;
837  cptr = strstr(linebuf,"-n=");
838  if(cptr != NULL) sscanf(cptr,"-n=%d", &maxarray);
839  if(maxarray < 1) maxarray = MAXARRAY;
840  float xa[maxarray],ya[maxarray];
841  char buf[80];
842  for(n=0; 1; n++)
843  {
844  if(gets(buf,sizeof(buf)-1) == -1) break;
845  if(buf[0] == '}') break;
846  if(n >= maxarray) break;
847  sscanf(buf,"%f,%f",&xa[n],&ya[n]);
848  }
849  if(n>0) line(xa,ya,n);
850  }
851  break;
852  case 'm':
853  if(strncmp(linebuf,"gmoveTo",7) == 0)
854  {
855  sscanf(linebuf,"gmoveTo(%d,%d)",&x,&y);
856  moveTo(x,y);
857  }
858  break;
859  case 'p':
860  if(strncmp(linebuf,"gplaySVGsocket",14) == 0)
861  {
862  socketPlaySVG();
863  }
864  else if(strncmp(linebuf,"gplaySVG",8) == 0)
865  {
866  char filename[1024];
867  getText(linebuf,filename);
868  playSVG(filename);
869  }
870  break;
871  case 'r':
872  if(strncmp(linebuf,"grect",5) == 0)
873  {
874  sscanf(linebuf,"grect(%d,%d,%d,%d)",&x,&y,&w,&h);
875  rect(x,y,w,h);
876  }
877  else if(strncmp(linebuf,"grightYAxis",11) == 0)
878  {
879  float start,delta,end;
880  int draw;
881  sscanf(linebuf,"grightYAxis(%f,%f,%f,%d)",&start,&delta,&end,&draw);
882  rightYAxis(start,delta,end,draw);
883  }
884  else if(strncmp(linebuf,"grotate",7) == 0)
885  {
886  float rx;
887  sscanf(linebuf,"grotate(%f)",&rx);
888  p.rotate(rx);
889  }
890  break;
891  case 's':
892  if(strncmp(linebuf,"gsetBackgroundColor",19) == 0)
893  {
894  sscanf(linebuf,"gsetBackgroundColor(%d,%d,%d)",&r,&g,&b);
895  setBackgroundColor(r,g,b);
896  }
897  else if(strncmp(linebuf,"gsetColor",9) == 0)
898  {
899  sscanf(linebuf,"gsetColor(%d,%d,%d)",&r,&g,&b);
900  setColor(r,g,b);
901  }
902  else if(strncmp(linebuf,"gsetWidth",9) == 0)
903  {
904  QPen pen;
905  sscanf(linebuf,"gsetWidth(%d)",&w);
906  pen = p.pen();
907  pen.setWidth(w);
908  p.setPen(pen);
909  }
910  else if(strncmp(linebuf,"gsetStyle",9) == 0)
911  {
912  QPen pen;
913  sscanf(linebuf,"gsetStyle(%d)",&i);
914  pen = p.pen();
915  if((Qt::PenStyle) i == Qt::NoPen) i = 1;
916  pen.setStyle((Qt::PenStyle) i);
917  //if(i==0) pen.setStyle(Qt::SolidLine);
918  //if(i==1) pen.setStyle(Qt::DotLine);
919  p.setPen(pen);
920  }
921  else if(strncmp(linebuf,"gsetFont",8) == 0)
922  {
923  char family[80];
924  const char *cptr;
925  int size,weight,italic;
926  getText(linebuf,family);
927  cptr = strstr(linebuf,"\",");
928  if(cptr != NULL)
929  {
930  cptr += 2;
931  sscanf(cptr,"%d,%d,%d",&size,&weight,&italic);
932  setFont(family,size,weight,italic);
933  }
934  }
935  else if(strncmp(linebuf,"gsetLinestyle",13) == 0)
936  {
937  sscanf(linebuf,"gsetLinestyle(%d)",&i);
938  setLinestyle(i);
939  }
940  else if(strncmp(linebuf,"gsetFloatFormat",15) == 0)
941  {
942  char txt[1024];
943  getText(linebuf,txt);
944  strcpy(floatFormat,txt);
945  }
946  else if(strncmp(linebuf,"gscale",6) == 0)
947  {
948  float rx,ry;
949  sscanf(linebuf,"gscale(%f,%f)",&rx,&ry);
950  p.scale(rx,ry);
951  }
952  break;
953  case 't':
954  if(strncmp(linebuf,"gtext(",6) == 0)
955  {
956  char txt[1024];
957  int alignment;
958  sscanf(linebuf,"gtext(%d,%d,%d,",&x,&y,&alignment);
959  getText(linebuf,txt);
960  text(x,y,alignment,txt);
961  }
962  else if(strncmp(linebuf,"gtextInAxis(",12) == 0)
963  {
964  char txt[1024];
965  int alignment;
966  float fx,fy;
967  sscanf(linebuf,"gtextInAxis(%f,%f,%d,",&fx,&fy,&alignment);
968  getText(linebuf,txt);
969  textInAxis(fx,fy,alignment,txt);
970  }
971  else if(strncmp(linebuf,"gtranslate",10) == 0)
972  {
973  float rx,ry;
974  sscanf(linebuf,"gtranslate(%f,%f)",&rx,&ry);
975  p.translate(rx,ry);
976  }
977  break;
978  case 'u':
979  if(strncmp(linebuf,"gupdateSVG(",11) == 0)
980  {
981  if(svgAnimator != NULL) svgAnimator->update(0);
982  }
983  break;
984  case 'x':
985  if(strncmp(linebuf,"gxAxis",6) == 0)
986  {
987  float start,delta,end;
988  int draw;
989  sscanf(linebuf,"gxAxis(%f,%f,%f,%d)",&start,&delta,&end,&draw);
990  xAxis(start,delta,end,draw);
991  }
992  else if(strncmp(linebuf,"gxGrid",6) == 0)
993  {
994  xGrid();
995  }
996  break;
997  case 'y':
998  if(strncmp(linebuf,"gyAxis",6) == 0)
999  {
1000  float start,delta,end;
1001  int draw;
1002  sscanf(linebuf,"gyAxis(%f,%f,%f,%d)",&start,&delta,&end,&draw);
1003  yAxis(start,delta,end,draw);
1004  }
1005  else if(strncmp(linebuf,"gyGrid",6) == 0)
1006  {
1007  yGrid();
1008  }
1009  break;
1010  }
1011  return 0;
1012 }
1013 */
1014 
const char * setWidth(int w)
Definition: rlsvgvdi.cpp:639
int xold
Definition: rlsvgvdi.h:135
int outputState
Definition: rlsvgvdi.h:116
const char * rect(int x, int y, int w, int h)
Definition: rlsvgvdi.cpp:377
const char * svgHeader(int width=1280, int height=1024, int rbackground=255, int gbackground=255, int bbackground=255)
Definition: rlsvgvdi.cpp:257
float ymin
Definition: rlsvgvdi.h:137
rlString fontstring
Definition: rlsvgvdi.h:129
rlSvgVdi()
Definition: rlsvgvdi.cpp:40
int getBoxX()
Definition: rlsvgvdi.cpp:749
const char * comment(const char *text)
Definition: rlsvgvdi.cpp:677
const char * moveTo(int x, int y)
Definition: rlsvgvdi.cpp:280
const char * xGrid()
Definition: rlsvgvdi.cpp:405
const char * lineTo(int x, int y)
Definition: rlsvgvdi.cpp:287
#define MSG_NOSIGNAL
Definition: rlsvgvdi.cpp:26
int getFontsize()
Definition: rlsvgvdi.cpp:744
const char * svg_points(int *x, int *y, int count)
Definition: rlsvgvdi.cpp:718
rlString lineoptions
Definition: rlsvgvdi.h:133
const char * yGrid()
Definition: rlsvgvdi.cpp:416
float dy
Definition: rlsvgvdi.h:137
int idForPvbrowser
Definition: rlsvgvdi.h:128
int writeString(const char *buf)
Definition: rlspawn.cpp:415
const char * textInAxis(float x, float y, const char *text, int alignment)
Definition: rlsvgvdi.cpp:311
const char * svg_d(int *x, int *y, int count)
Definition: rlsvgvdi.cpp:702
const char * box(int x, int y, int w, int h)
Definition: rlsvgvdi.cpp:354
const char * setColor(int r, int g, int b)
Definition: rlsvgvdi.cpp:609
rlSpawn * pipe
Definition: rlsvgvdi.h:126
const char * line(int x1, int y1, int x2, int y2)
Definition: rlsvgvdi.cpp:299
static int beautyval(char *text)
Definition: rlsvgvdi.cpp:387
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
float ymax
Definition: rlsvgvdi.h:137
int yold
Definition: rlsvgvdi.h:135
int getBoxW()
Definition: rlsvgvdi.cpp:759
const char * drawEllipse(int x, int y, int rx, int ry)
Definition: rlsvgvdi.cpp:273
int perhapsSend(const char *text)
Definition: rlsvgvdi.cpp:201
char * text()
Definition: rlstring.cpp:126
rlString svg2
Definition: rlsvgvdi.h:129
int * sout
Definition: rlsvgvdi.h:124
rlString svg
Definition: rlsvgvdi.h:129
int ty(float y)
Definition: rlsvgvdi.cpp:737
float xmin
Definition: rlsvgvdi.h:136
const char * yAxis(float start, float delta, float end, int draw=1)
Definition: rlsvgvdi.cpp:460
int boxy
Definition: rlsvgvdi.h:140
int rlvsnprintf(char *text, int len, const char *format, va_list ap)
Definition: rlcutil.cpp:197
const char * text(int x, int y, const char *text, int alignment=ALIGN_LEFT)
Definition: rlsvgvdi.cpp:330
int sr
Definition: rlsvgvdi.h:142
int width
Definition: rlsvgvdi.h:131
const char * svgTrailer()
Definition: rlsvgvdi.cpp:266
const char * drawSymbol(int x, int y, int type)
Definition: rlsvgvdi.cpp:536
const char * rightYAxis(float start, float delta, float end, int draw=1)
Definition: rlsvgvdi.cpp:493
int getBoxY()
Definition: rlsvgvdi.cpp:754
~rlSvgVdi()
Definition: rlsvgvdi.cpp:64
const char * setLinestyle(const char *dasharray)
Definition: rlsvgvdi.cpp:658
FILE * fout
Definition: rlsvgvdi.h:125
rlString dasharray
Definition: rlsvgvdi.h:132
int boxw
Definition: rlsvgvdi.h:140
const char * boxWithText(int x, int y, int w, int h, int fontsize, const char *xlabel, const char *ylabel, const char *rylabel)
Definition: rlsvgvdi.cpp:368
int printf(const char *format,...)
Definition: rlstring.cpp:145
char floatFormat[80]
Definition: rlsvgvdi.h:143
rlString outputfilename
Definition: rlsvgvdi.h:127
int fontsize
Definition: rlsvgvdi.h:141
int tx(float x)
Definition: rlsvgvdi.cpp:732
int setOutput(int *socket_out, int idForPvbrowser=0)
Definition: rlsvgvdi.cpp:69
rlString svg3
Definition: rlsvgvdi.h:129
int boxh
Definition: rlsvgvdi.h:140
int endOutput()
Definition: rlsvgvdi.cpp:163
const char * setFont(const char *family, int size, int weight, int italic)
Definition: rlsvgvdi.cpp:629
char stroke[16]
Definition: rlsvgvdi.h:130
float xmax
Definition: rlsvgvdi.h:136
const char * xAxis(float start, float delta, float end, int draw=1)
Definition: rlsvgvdi.cpp:427
rlString textoptions
Definition: rlsvgvdi.h:133
const char * svg_put(const char *text)
Definition: rlsvgvdi.cpp:684
float dx
Definition: rlsvgvdi.h:136
int boxx
Definition: rlsvgvdi.h:140
int getBoxH()
Definition: rlsvgvdi.cpp:764
const char * svg_printf(const char *format,...)
Definition: rlsvgvdi.cpp:690