Subversion Repositories wimsdev

Rev

Rev 7784 | Rev 7786 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2. 27/7/2013 version 0.01
  3. "Inspired" by FLY program: http://martin.gleeson.com/fly
  4. *********************************************************************************
  5. * J.M. Evers 7/2013                                                             *
  6. * This is all just amateur scriblings... So no copyrights.                      *
  7. * This source code file, and compiled objects derived from it,                  *
  8. * can be used and distributed without restriction, including for commercial use *
  9. * No warrenty whatsoever                                                        *
  10. *********************************************************************************
  11. */
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <errno.h>
  15. #include <string.h>
  16. #include <unistd.h>
  17. #include <time.h> /* use for random id's */
  18. #include <math.h>
  19. /*
  20. #include <ctype.h>
  21. 11/2013
  22. removed: FreeBSD 9.0 / 9.1 C-lib bug...in chroot it will result in: Undefined symbol "_ThreadRuneLocale" implemented own versions of tolower() / toupper()
  23. Clang is fine (FreeBSD 10.0)
  24. */
  25.  
  26. /*
  27. in case svgdraw is in ~/src/Misc/svgdraw
  28. #include "../svgdraw/include/matheval.h"
  29. */
  30. #include "include/matheval.h"
  31. #include <assert.h>
  32. #include "canvasdraw.h"
  33. #include<sys/stat.h>
  34.  
  35. /* needed for gettimeofday */
  36. #include <sys/time.h>
  37. #include "canvasmacro.c"
  38. /******************************************************************************
  39. **  Internal Functions
  40. ******************************************************************************/
  41. void    add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */
  42. void    sync_input(FILE *infile);/* proceed with inputfile */
  43. void    canvas_error(char *msg);
  44. void    add_javascript_functions(int js_functions[], int canvas_root_id);
  45. void    reset();/* reset some global variables like "use_filled" , "use_dashed" */
  46. int     get_token(FILE *infile); /* read next char until EOL*/
  47. int     x2px(double x);
  48. int     y2px(double y);
  49. double  px2x(int x);
  50. double  px2y(int y);
  51. double  get_real(FILE *infile,int last); /* read a values; calculation and symbols allowed */
  52. double  get_double(FILE *infile , int orientation , int last); /*the same as get_real(): but for an unknown amount of data args*/
  53. char    *str_replace ( const char *word, const char *sub_word, const char *rep_word );
  54. char    *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */
  55. char    *get_string(FILE *infile,int last); /* get the string at theend of a command */
  56. char    *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as  separator */
  57. char    *convert_hex2rgb(char *hexcolor);
  58. void    add_read_canvas(int reply_format);
  59. void    make_js_include(int canvas_root_id);
  60. void    check_string_length(int length);/* checks if the length of string argument of command is correct */
  61. FILE    *js_include_file;
  62. FILE    *get_file(int *line_number, char **filename);
  63. FILE    *infile;    /* will be stdin */
  64. /******************************************************************************
  65. ** global
  66. ******************************************************************************/
  67. int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */
  68. int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */
  69. /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */
  70. int xsize = 320;
  71. int ysize = 320;
  72. double xmin = 0.0;
  73. double xmax = 320.0;
  74. double ymin = 0.0;
  75. double ymax = 320.0;
  76. double tmax = 2;
  77. double tmin = -2;
  78. /* flag to indicate parsing of line status */
  79. int done = FALSE;
  80. int type; /* eg command number */
  81. int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/
  82. int use_affine = FALSE;
  83. int use_rotate = FALSE;
  84. int use_translate = FALSE;
  85. int use_filled = FALSE;
  86. int use_dashed = FALSE; /* dashing not natively supported in firefox  , for now... */
  87. char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */
  88.  
  89. /******************************************************************************
  90. ** Main Program
  91. ******************************************************************************/
  92. int main(int argc, char *argv[]){
  93.     /* need unique id for every call to canvasdraw : rand(); is too slow...will result in many identical id's */
  94.     struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);unsigned int canvas_root_id = (unsigned int) tv.tv_usec;
  95.     infile = stdin;/* read flyscript via stdin */
  96.     int i,c;
  97.     double double_data[MAX_INT+1];
  98.     int int_data[MAX_INT+1];
  99.     for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;}
  100.     int use_parametric = FALSE;/* will be reset after parametric plotting */
  101.     int use_axis = FALSE;
  102.     int use_axis_numbering = FALSE;
  103.     int line_width = 1;
  104.     int decimals = 2;
  105.     int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate */
  106.     int use_userdraw = FALSE; /* flag to indicate user interaction: incompatible with "drag & drop" code !! */
  107.     int drag_type = -1;/* 0,1,2 : xy,x,y */
  108.     int use_tooltip = FALSE;
  109.     char *tooltip_text = "Click here";
  110.     char *temp = ""; /* */
  111.     char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
  112.     char *stroke_color = "255,0,0";
  113.     char *fill_color = "0,255,0";
  114.     char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
  115.     char *font_color = "#00000";
  116.     char *draw_type = "points";
  117.     char *fly_font = "normal";
  118.     char *input_style = "";
  119.     char *flytext = "";
  120.     char *affine_matrix = "[1,0,0,1,0,0]";
  121.     int pixelsize = 1;
  122.     int reply_format = 0;
  123.     int input_cnt = 0;
  124.     int ext_img_cnt = 0;
  125.     int font_size = 12;
  126.     int dashtype[2] = { 2 , 2 };
  127.     int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */
  128.     for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
  129.     int arrow_head = 8; /* size in px*/
  130.     int crosshair_size = 10; /* size in px*/
  131.     int plot_steps = 150;
  132.     int found_size_command = 0;
  133.     int click_cnt = 1;
  134.     int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
  135.     int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
  136.     int use_mouse_coordinates = FALSE;
  137.     double angle = 0.0;
  138.     int translate_x = 0;
  139.     int translate_y = 0;
  140.     int clickfillmarge = 20;
  141.     int animation_type = 9; /* == object type curve in drag library */
  142.     int use_input_xy = 0;
  143.     size_t string_length = 0;
  144.     double stroke_opacity = 0.8;
  145.     double fill_opacity = 0.8;
  146.     char *URL = "http://localhost/images";
  147.     memset(buffer,'\0',MAX_BUFFER);
  148.     void *tmp_buffer = "";
  149.    
  150.     /* default writing a unzipped js-include file into wims getfile directory */
  151.     char *w_wims_session = getenv("w_wims_session");
  152.     if(  w_wims_session == NULL || *w_wims_session == 0 ){
  153.         canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");
  154.     }
  155.     int L0=strlen(w_wims_session) + 21;
  156.     char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
  157.     snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
  158.     mode_t process_mask = umask(0); /* check if file exists */
  159.     int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
  160.     if( result == 0 || errno == EEXIST ){
  161.      umask(process_mask); /* be sure to set correct permission */
  162.      char *w_session = getenv("w_session");
  163.      int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
  164.     char *getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
  165.      snprintf(getfile_cmd,L1,"wims.cgi?session=%s&cmd=getfile&special_parm=%d.js",w_session,canvas_root_id);/* extension ".gz" is MANDATORY for webserver */   
  166.     /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
  167.     /* now write file into getfile dir*/
  168.     char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */
  169.     int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
  170.     char *location = my_newmem(L2); /* create memory to fit string precisely */
  171.     snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
  172.     js_include_file = fopen(location,"w");/* open the file location for writing */
  173.     /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */
  174.     if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );}
  175.  
  176. /* ----------------------------------------------------- */
  177. /* while more lines to process */
  178.  
  179.     while(!finished){
  180.         if(line_number>1 && found_size_command == FALSE){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
  181.         type = get_token(infile);
  182.         done = FALSE;
  183.         /*
  184.         @canvasdraw
  185.         @will try use the same syntax as flydraw or svgdraw to paint a html5 bitmap image<br />by generating a tailor-made javascript include file: providing only the js-functionality needed to perform the job.<br />thus ensuring a minimal strain on the client browser <br />(unlike some popular 'canvas-do-it-all' libraries, who have proven to be not suitable for low-end computers found in schools...)
  186.         @General syntax <ul><li>The transparency of all objects can be controlled by command 'opacity [0-255],[0,255]'</il><li>a line based object can be controlled by command 'linewidth int'</li><li>a line based object may be dashed by using keyword 'dashed' before the object command.<br />the dashing type can be controled by command 'dashtype int,int'</li><li>a fillable object can be set fillable by starting the object command with an 'f'<br />(like frect,fcircle,ftriangle...)<br />or by using the keyword 'filled' before the object command.<br />The fill colour will be the stroke colour...(19/10/2013)<li> a draggable object can be set draggable by a preceding command 'drag x/y/xy'<br />The translation can be read by javascript:read_dragdrop();<br />Multiple objects may be set draggable / clickable (no limit)<br /> not all flydraw objects may be dragged / clicked<br />Only draggable / clickable objects will be scaled on zoom and will be translated in case of panning</li><li> a 'onclick object' can be set 'clickable' by the preceding keyword 'onclick'<br />not all flydraw objects can be set clickable</li><li><b>remarks using a ';' as command separator</b><br />commands with only numeric or colour arguments may be using a ';' as command separator (in stead of a new line)<br />commands with a string argument may not use a ';' as command separator !<br />these exceptions are not really straight forward... so keep this in mind.<br />example:<br />size 200,200;xrange -5,5;yrange -5,5;hline 0,0,black;vline 0,0,black<br />plot red,sin(x)<br />drag xy<br />html 0,0,5,-5, &amp;euro; <br />lines green,2,0,2,-2,-2,2,-2,0;rectangle 1,1,4,4,purple;frectangle -1,-1,-4,-4,yellow</li></ul>
  187.         */
  188.         switch(type){
  189.         case END:
  190.         finished = 1;
  191.         done = TRUE;
  192.         break;
  193.         case 0:
  194.             sync_input(infile);
  195.             break;
  196.         case COMMENT:
  197.             sync_input(infile);
  198.             break;
  199.         case EMPTY:
  200.             sync_input(infile);
  201.             break;
  202.         case SIZE:
  203.             /*
  204.             @size width,height
  205.             @set canvas size in pixels
  206.             @mandatory first command
  207.             @if xrange and/or yrange is not given the range will be set to pixels :<br />xrange 0,xsize yrange 0,ysize<br />note: lower left  corner is Origin (0:0)
  208.             */
  209.             found_size_command = TRUE;
  210.             xsize = (int)(abs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
  211.             ysize = (int)(abs(round(get_real(infile,1))));
  212.             /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
  213.             xmin = 0;xmax = xsize;
  214.             ymin = 0;ymax = ysize;
  215.  
  216. /*
  217.  The sequence in which stuff is finally printed is important !!
  218.  for example, when writing a 'include.js" the may not be a "script tag <script>" etc etc
  219. */
  220. fprintf(stdout,"\n<script type=\"text/javascript\">var wims_status = \"$status\";</script>\n<!-- canvasdraw div and tooltip placeholder, if needed -->\n<div tabindex=\"0\" id=\"canvas_div%d\" style=\"position:relative;width:%dpx;height:%dpx;\" ></div><div id=\"tooltip_placeholder_div%d\" style=\"display:block\"><span id=\"tooltip_placeholder%d\" style=\"display:none\"></span></div>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id);
  221. fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n");
  222. fprintf(stdout,"<!-- include actual object code via include file -->\n<script type=\"text/javascript\" src=\"%s\"></script>\n",getfile_cmd);
  223. fprintf(js_include_file,"var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\
  224. var xsize = %d;\
  225. var ysize = %d;\
  226. var canvas_div = document.getElementById(\"canvas_div%d\");\
  227. create_canvas%d = function(canvas_type,size_x,size_y){var cnv;if(document.getElementById(\"wims_canvas%d\"+canvas_type)){ cnv = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{try{ cnv = document.createElement(\"canvas\"); }catch(e){alert(\"Your browser does not support HTML5 CANVAS:GET FIREFOX !\");return;};canvas_div.appendChild(cnv);};cnv.width = size_x;cnv.height = size_y;cnv.style.top = 0;cnv.style.left = 0;cnv.style.position = \"absolute\";cnv.id = \"wims_canvas%d\"+canvas_type;return cnv;};\
  228. function findPosX(i){ var obj = i;var curleft = 0;if(obj.offsetParent){while(1){curleft += obj.offsetLeft;if(!obj.offsetParent){break;};obj = obj.offsetParent;};}else{if(obj.x){curleft += obj.x;};};return curleft;};function findPosY(i){var obj = i;var curtop = 0;if(obj.offsetParent){while(1){curtop += obj.offsetTop;if(!obj.offsetParent){break;};obj = obj.offsetParent;};}else{if(obj.y){curtop += obj.y;};};return curtop;};\
  229. function x2px(x){if(use_xlogscale == 0 ){return x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin);}else{var x_max = Math.log(xmax)/Math.log(xlogbase);var x_min = Math.log(xmin)/Math.log(xlogbase);var x_in = Math.log(x)/Math.log(xlogbase);return x_in*xsize/(x_max - x_min) - xsize*x_min/(x_max - x_min);};};\
  230. function px2x(px){if(use_xlogscale == 0 ){return (Math.round((px*(xmax - xmin)/xsize + xmin)*precision))/precision;}else{var x_max = Math.log(xmax)/Math.log(xlogbase);var x_min = Math.log(xmin)/Math.log(xlogbase);var x_out = x_min +px*(x_max - x_min)/(xsize);return Math.pow(xlogbase,x_out);};};\
  231. function px2y(py){if(use_ylogscale == 0 ){return (Math.round((ymax -py*(ymax - ymin)/ysize)*precision))/precision;}else{var y_max = Math.log(ymax)/Math.log(ylogbase);var y_min = Math.log(ymin)/Math.log(ylogbase);var y_out = y_max +py*(y_min - y_max)/(ysize);return Math.pow(ylogbase,y_out);};};\
  232. function y2px(y){if(use_ylogscale == 0){return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);}else{var y_max = Math.log(ymax)/Math.log(ylogbase);var y_min = Math.log(ymin)/Math.log(ylogbase);var y_in = Math.log(y)/Math.log(ylogbase);return (y_max - y_in)*ysize/(y_max - y_min);};};\
  233. function scale_x_radius(rx){return parseInt(x2px(rx) - x2px(0));};\
  234. function scale_y_radius(ry){return parseInt(y2px(ry) - y2px(0));};\
  235. function distance(x1,y1,x2,y2){return parseInt(Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ));};\
  236. function distance_to_line (r,q,x,y){var c = (y) - (-1/r)*(x);var xs = r*(c - q)/(r*r+1);var ys = (r)*(xs)+(q);return parseInt(Math.sqrt( (xs-x)*(xs-x) + (ys-y)*(ys-y) ));};\
  237. function move(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = obj.x[p] + dx;obj.y[p] = obj.y[p] + dy;}return obj;};\
  238. var xlogbase = 10;\
  239. var ylogbase = 10;\
  240. var use_xlogscale = 0;\
  241. var use_ylogscale = 0;\
  242. var x_strings = null;\
  243. var y_strings = null;\
  244. var use_pan_and_zoom = 0;\
  245. var x_use_snap_to_grid = 0;\
  246. var y_use_snap_to_grid = 0;\
  247. var xstart = 0;\
  248. var ystart = 0",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  249. /* default add the drag code : nearly always used ...*/
  250. add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
  251.             break;
  252.         case XRANGE:
  253.         /*
  254.         @ xrange xmin,xmax
  255.         @ if not given: 0,xsize (eg in pixels)
  256.         */
  257.             for(i = 0 ; i<2; i++){
  258.                 switch(i){
  259.                     case 0: xmin = get_real(infile,0);break;
  260.                     case 1: xmax = get_real(infile,1);break;
  261.                     default: break;
  262.                 }
  263.             }
  264.             if(xmin >= xmax){canvas_error(" xrange is not OK : xmin &lt; xmax !\n");}
  265.             fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax);
  266.             break;
  267.         case YRANGE:
  268.         /*
  269.         @ yrange ymin,ymax
  270.         @ if not given 0,ysize (eg in pixels)
  271.         */
  272.             for(i = 0 ; i<2; i++){
  273.                 switch(i){
  274.                     case 0: ymin = get_real(infile,0);break;
  275.                     case 1: ymax = get_real(infile,1);break;
  276.                     default: break;
  277.                 }
  278.             }
  279.             if(ymin >= ymax){canvas_error(" yrange is not OK : ymin &lt; ymax !\n");}
  280.             fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax);
  281.             break;
  282.         case TRANGE:
  283.         /*
  284.         @ trange tmin,tmax
  285.         @ default -2,2
  286.         */
  287.             use_parametric = TRUE;
  288.             for(i = 0 ; i<2; i++){
  289.                 switch(i){
  290.                     case 0: tmin = get_real(infile,0);break;
  291.                     case 1: tmax = get_real(infile,1);break;
  292.                     default: break;
  293.                 }
  294.             }
  295.             if(tmin >= tmax ){canvas_error(" trange is not OK : tmin &lt; tmax!\n");}
  296.             break;
  297.         case LINEWIDTH:
  298.         /*
  299.         @ linewidth int
  300.         @ default 1
  301.         */
  302.             line_width = (int) (get_real(infile,1));
  303.             break;
  304.         case ARROWHEAD:
  305.         /*
  306.         @ arrowhead int
  307.         @ default 8 (pixels)
  308.         */
  309.             arrow_head = (int) (get_real(infile,1));
  310.             break;
  311.         case CROSSHAIRSIZE:
  312.         /*
  313.         @ crosshairsize int
  314.         @ default 10 (px)
  315.         */
  316.             crosshair_size = (int) (get_real(infile,1));
  317.             break;
  318.         case CROSSHAIR:
  319.         /*
  320.         @ crosshair x,y,color
  321.         @ draw a single crosshair point at (x;y) in color 'color'
  322.         @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
  323.         @ may be set draggable / onclick
  324.         */
  325.             for(i=0;i<3;i++){
  326.                 switch(i){
  327.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  328.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  329.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  330.                         decimals = find_number_of_digits(precision);
  331.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  332.                         click_cnt++;reset();
  333.                         break;
  334.                     default:break;
  335.                 }
  336.             }
  337.             break;
  338.         case CROSSHAIRS:
  339.         /*
  340.         @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
  341.         @ draw multiple crosshair points at given coordinates in color 'color'
  342.         @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
  343.         @ may be set draggable / onclick individually (!)
  344.         */
  345.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  346.             fill_color = stroke_color;
  347.             i=0;
  348.             while( ! done ){     /* get next item until EOL*/
  349.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  350.                 if(i%2 == 0 ){
  351.                     double_data[i] = get_real(infile,0); /* x */
  352.                 }
  353.                 else
  354.                 {
  355.                     double_data[i] = get_real(infile,1); /* y */
  356.                 }
  357.                 i++;
  358.             }
  359.             decimals = find_number_of_digits(precision);
  360.             for(c=0 ; c < i-1 ; c = c+2){
  361.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  362.                 click_cnt++;
  363.             }
  364.             reset();
  365.             break;
  366.         case POINT:
  367.         /*
  368.         @ point x,y,color
  369.         @ draw a single point at (x;y) in color 'color'
  370.         @ use command 'linewidth int'  to adust size
  371.         @ may be set draggable / onclick
  372.         @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming)
  373.         */
  374.             for(i=0;i<3;i++){
  375.                 switch(i){
  376.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  377.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  378.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  379.                     decimals = find_number_of_digits(precision);
  380.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  381.                     click_cnt++;break;
  382.                     default: break;
  383.                 }
  384.             }
  385.             reset();
  386.             break;
  387.         case POINTS:
  388.         /*
  389.         @ points color,x1,y1,x2,y2,...,x_n,y_n
  390.         @ draw multiple points at given coordinates in color 'color'
  391.         @ use command 'linewidth int'  to adust size
  392.         @ may be set draggable / onclick individually (!)
  393.         */
  394.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  395.             fill_color = stroke_color;
  396.             i=0;
  397.             while( ! done ){     /* get next item until EOL*/
  398.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  399.                 if(i%2 == 0 ){
  400.                     double_data[i] = get_real(infile,0); /* x */
  401.                 }
  402.                 else
  403.                 {
  404.                     double_data[i] = get_real(infile,1); /* y */
  405.                 }
  406.                 i++;
  407.             }
  408.             decimals = find_number_of_digits(precision);           
  409.             for(c = 0 ; c < i-1 ; c = c+2){
  410.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  411.                 click_cnt++;
  412.             }
  413.             reset();
  414.             break;
  415.         case SEGMENT:
  416.         /*
  417.         @ segment x1,y1,x2,y2,color
  418.         @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color'
  419.         @ may be set draggable / onclick
  420.         */
  421.             for(i=0;i<5;i++) {
  422.                 switch(i){
  423.                     case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
  424.                     case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
  425.                     case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
  426.                     case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
  427.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  428.                         decimals = find_number_of_digits(precision);
  429.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  430.                         click_cnt++;reset();
  431.                         break;
  432.                     default: break;
  433.                 }
  434.             }
  435.             break;
  436.         case LINE:
  437.         /*
  438.         @ line x1,y1,x2,y2,color
  439.         @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
  440.         @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
  441.         @ may be set draggable / onclick
  442.         */
  443.             for(i=0;i<5;i++){
  444.                 switch(i){
  445.                     case 0: double_data[10]= get_real(infile,0);break; /* x-values */
  446.                     case 1: double_data[11]= get_real(infile,0);break; /* y-values */
  447.                     case 2: double_data[12]= get_real(infile,0);break; /* x-values */
  448.                     case 3: double_data[13]= get_real(infile,0);break; /* y-values */
  449.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  450.                     if( double_data[10] == double_data[12] ){ /* vertical line*/
  451.                         double_data[1] = xmin;
  452.                         double_data[3] = ymax;
  453.                         double_data[0] = double_data[10];
  454.                         double_data[2] = double_data[10];
  455.                     }
  456.                     else
  457.                     {
  458.                         if( double_data[11] == double_data[13] ){ /* horizontal line */
  459.                             double_data[1] = double_data[11];
  460.                             double_data[3] = double_data[11];
  461.                             double_data[0] = ymin;
  462.                             double_data[2] = xmax;
  463.                         }
  464.                         else
  465.                         {
  466.                         /* m */
  467.                         double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
  468.                         /* q */
  469.                         double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
  470.                        
  471.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  472.                        
  473.                             double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
  474.                             double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
  475.                             double_data[0] = xmin;
  476.                             double_data[2] = xmax;
  477.                         }
  478.                     }
  479.                     decimals = find_number_of_digits(precision);
  480.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  481.                     click_cnt++;reset();
  482.                     break;
  483.                 }
  484.             }
  485.             break;
  486.         case HLINE:
  487.         /*
  488.         @ hline x,y,color
  489.         @ draw a horizontal line through point (x:y) in color 'color'
  490.         @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
  491.         @ may be set draggable / onclick
  492.         */
  493.             for(i=0;i<3;i++) {
  494.                 switch(i){
  495.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  496.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  497.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  498.                     double_data[3] = double_data[1];
  499.                     decimals = find_number_of_digits(precision);
  500.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,xmin,decimals,xmax,decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  501.                     click_cnt++;reset();
  502.                     break;
  503.                 }
  504.             }
  505.             break;
  506.         case VLINE:
  507.         /*
  508.         @ vline x,y,color
  509.         @ draw a vertical line through point (x:y) in color 'color'
  510.         @ may be set draggable / onclick
  511.         */
  512.             for(i=0;i<3;i++) {
  513.                 switch(i){
  514.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  515.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  516.                     case 2: stroke_color=get_color(infile,1);/* name or hex color */
  517.                         double_data[2] = double_data[0];
  518.                         decimals = find_number_of_digits(precision);
  519.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,ymin,decimals,ymax,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  520.                         click_cnt++;reset();
  521.                     break;
  522.                 }
  523.             }
  524.             break;
  525.         case SQUARE:
  526.         /*
  527.         @ square x,y,side,color
  528.         @ draw a square with left top corner (x:y) with side 'side' in color 'color'
  529.         @ use command 'fsquare x,y,side,color' for a filled square
  530.         @ use command/keyword  'filled' before command 'square x,y,side,color'
  531.         @ use command 'fillcolor color' before 'fsquare' to set the fill colour.
  532.         @ may be set draggable / onclick
  533.         */
  534.             for(i=0;i<5;i++){
  535.                 switch(i){
  536.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  537.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  538.                     case 2:double_data[2] = get_real(infile,0);
  539.                            double_data[3] = double_data[2];
  540.                            break; /* x-values */
  541.                     case 3:stroke_color = get_color(infile,1);/* name or hex color */
  542.                         decimals = find_number_of_digits(precision);
  543.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  544.                         click_cnt++;reset();
  545.                         break;
  546.                 }
  547.             }
  548.             break;
  549.         case ROUNDRECT:
  550.         /*
  551.         @ roundrect x1,y1,x2,y2,radius,color
  552.         @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle
  553.         @ use command/keyword  'filled' before command 'roundrect x1,y1,x2,y2,radius,color'
  554.         @ use command 'fillcolor color' before 'froundrect' to set the fill colour.
  555.         @ may be set draggable / onclick
  556.         */
  557.             for(i=0;i<6;i++){
  558.                 switch(i){
  559.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  560.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  561.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  562.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  563.                     case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
  564.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  565.                         decimals = find_number_of_digits(precision);
  566.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,6,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  567.                         click_cnt++;reset();
  568.                     break;
  569.                 }
  570.             }
  571.             break;
  572.         case RECT:
  573.         /*
  574.         @ rect x1,y1,x2,y2,color
  575.         @ use command 'rect x1,y1,x2,y2,color' for a filled rectangle
  576.         @ use command/keyword  'filled' before command 'rect x1,y1,x2,y2,color'
  577.         @ use command 'fillcolor color' before 'frect' to set the fill colour.
  578.         @ may be set draggable / onclick
  579.         */
  580.             for(i=0;i<5;i++){
  581.                 switch(i){
  582.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  583.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  584.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  585.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  586.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  587.                         decimals = find_number_of_digits(precision);
  588.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[2],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[3],decimals,double_data[3],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  589.                         click_cnt++;reset();
  590.                         break;
  591.                 }
  592.             }
  593.             break;
  594.         case POLYLINE:
  595.         /*
  596.         @ polyline color,x1,y1,x2,y2...x_n,y_n
  597.         @ may be set draggable / onclick
  598.         */
  599.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  600.             i=0;
  601.             c=0;
  602.             while( ! done ){     /* get next item until EOL*/
  603.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  604.                 for( c = 0 ; c < 2; c++){
  605.                     if(c == 0 ){
  606.                         double_data[i] = get_real(infile,0);
  607.                         i++;
  608.                     }
  609.                     else
  610.                     {
  611.                         double_data[i] = get_real(infile,1);
  612.                         i++;
  613.                     }
  614.                 }
  615.             }
  616.             /* draw path : not closed & not filled */
  617.             decimals = find_number_of_digits(precision);
  618.             fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  619.             click_cnt++;reset();
  620.             break;
  621.         case POLY:
  622.         /*
  623.         @ poly color,x1,y1,x2,y2...x_n,y_n
  624.         @ draw closed polygon
  625.         @ use command 'fpoly' to fill it, use command 'fillcolor color' to set the fill color
  626.         @ may be set draggable / onclick
  627.         */
  628.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  629.             i=0;
  630.             c=0;
  631.             while( ! done ){     /* get next item until EOL*/
  632.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  633.                 for( c = 0 ; c < 2; c++){
  634.                     if(c == 0 ){
  635.                         double_data[i] = get_real(infile,0);
  636.                         i++;
  637.                     }
  638.                     else
  639.                     {
  640.                         double_data[i] = get_real(infile,1);
  641.                         i++;
  642.                     }
  643.                 }
  644.             }
  645.             /* draw path :  closed & optional filled */
  646.                 decimals = find_number_of_digits(precision);
  647.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  648.                 click_cnt++;reset();
  649.             break;
  650.         case ARC:
  651.         /*
  652.          @ arc xc,yc,width,height,start_angle,end_angle,color
  653.          @ can not be set "onclick" or "drag xy"
  654.          @ attention: width == height == radius in pixels)
  655.         */
  656.             for(i=0;i<7;i++){
  657.                 switch(i){
  658.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  659.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  660.                     case 2:int_data[0] = (int)(get_real(infile,0));break; /* width in pixels ! */
  661.                     case 3:int_data[1] = (int)(get_real(infile,0));break; /* height in pixels ! */
  662.                     case 4:double_data[2] = get_real(infile,0);break; /* start angle in degrees */
  663.                     case 5:double_data[3] = get_real(infile,0);break; /* end angle in degrees */
  664.                     case 6:stroke_color = get_color(infile,1);/* name or hex color */
  665.                     /* in Shape library:
  666.                         x[0] = x[1] = xc
  667.                         y[0] = y[1] = yc
  668.                         w[0] = w[1] = radius = width = height  
  669.                         h[0] = start_angle ; h[1] = end_engle
  670.                     */
  671.                         decimals = find_number_of_digits(precision);
  672.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,12,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],int_data[0],int_data[0],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  673.                         reset();
  674.                     break;
  675.                 }
  676.             }
  677.             break;
  678.         case ELLIPSE:
  679.         /*
  680.         @ ellipse xc,yc,radius_x,radius_y,color
  681.         @ a ellipse with center xc/yc in x/y-range
  682.         @ radius_x and radius_y are in pixels
  683.         @ may be set draggable / onclick
  684.         @ will shrink / expand on zoom out / zoom in
  685.         */
  686.             for(i=0;i<5;i++){
  687.                 switch(i){
  688.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  689.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  690.                     case 2:double_data[2] = get_real(infile,0);break; /* rx -> px  */
  691.                     case 3:double_data[3] = get_real(infile,0);break; /* ry -> px  */
  692.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  693.                         decimals = find_number_of_digits(precision);
  694.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  695.                         click_cnt++;reset();
  696.                     break;
  697.                 }
  698.             }
  699.             break;
  700.         case DASHTYPE:
  701.         /*
  702.         @ dashtype int ,int
  703.         @ When dashed is set, the objects will be drawn with this dashtyp
  704.         @ default value "dashtype 2,2"
  705.         */
  706.             for(i=0;i<2;i++){
  707.                 switch(i){
  708.                     case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
  709.                     case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
  710.                 }
  711.             }
  712.         break;
  713.         case CIRCLE:
  714.         /*
  715.         @ circle xc,yc,width (2*r in pixels),color
  716.         @ use command 'fcircle xc,yc,d,color' or command 'filled' for a filled disk
  717.         @ use command 'fillcolor color' to set the fillcolor
  718.         @ may be set draggable / onclick
  719.         @ will shrink / expand on zoom out / zoom in
  720.         */
  721.             for(i=0;i<4;i++){
  722.                 switch(i){
  723.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  724.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  725.                     case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* radius in 'dx' xrange*/
  726.                     case 3: stroke_color = get_color(infile,1);/* name or hex color */
  727.                         decimals = find_number_of_digits(precision);
  728.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],double_data[2],double_data[2],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  729.                         click_cnt++;reset();
  730.                     break;
  731.                 }
  732.             }
  733.             break;
  734.         case RAYS:
  735.         /*
  736.          @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
  737.          @ draw rays in color 'color' and center (xc:yc)
  738.          @ may be set draggable or onclick (the complete object, not an indiviual ray !)
  739.         */
  740.             stroke_color=get_color(infile,0);
  741.             i=0;
  742.             while( ! done ){     /* get next until EOL*/
  743.                 if(i > MAX_INT - 1){canvas_error("to much rays in argument: repeat command multiple times to fit");}
  744.                 if( i > 3){
  745.                     double_data[i++] = double_data[0];
  746.                     double_data[i++] = double_data[1];
  747.                 }
  748.                 for(c=0; c<=1 ;c++){ /* switch x2px / y2px */
  749.                     double_data[i++]= get_double(infile,c,1);
  750.                 }
  751.             }
  752.             decimals = find_number_of_digits(precision);
  753.             for(c=0; c<i;c = c+4){
  754.                 click_cnt++;
  755.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[c+2],decimals,double_data[0],decimals,double_data[c+3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  756.             }
  757.             reset();
  758.             break;
  759.         case ARROW:
  760.         /*
  761.         @ arrow x1,y1,x2,y2,h,color
  762.         @ draw a single headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color'
  763.         @ use command 'linewidth int' to adjust thickness of the arrow
  764.         @ may be set draggable / onclick
  765.         */
  766.             for(i=0;i<6;i++){
  767.                 switch(i){
  768.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  769.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  770.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  771.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  772.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  773.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  774.                         decimals = find_number_of_digits(precision);
  775.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,8,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  776.                         click_cnt++;
  777.                         reset();
  778.                         break;
  779.                 }
  780.             }
  781.             break;
  782.         case ARROW2:
  783.         /*
  784.         @ arrow2 x1,y1,x2,y2,h,color
  785.         @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and  in color 'color'
  786.         @ use command 'arrowhead int' to adjust the arrow head size
  787.         @ use command 'linewidth int' to adjust thickness of the arrow
  788.         @ may be set draggable / onclick
  789.         */
  790.             for(i=0;i<6;i++){
  791.                 switch(i){
  792.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  793.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  794.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  795.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  796.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  797.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  798.                         decimals = find_number_of_digits(precision);
  799.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,10,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  800.                         click_cnt++;reset();
  801.                         break;
  802.                 }
  803.             }
  804.             break;
  805.         case PARALLEL:
  806.         /*
  807.          @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
  808.          @ can not be set "onclick" or "drag xy"
  809.         */
  810.             for( i = 0;i < 8; i++ ){
  811.                 switch(i){
  812.                     case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
  813.                     case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
  814.                     case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
  815.                     case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
  816.                     case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
  817.                     case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
  818.                     case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
  819.                     case 7: stroke_color=get_color(infile,1);/* name or hex color */
  820.                     decimals = find_number_of_digits(precision);
  821.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,11,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d,%d],[%d,%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  822.                     click_cnt++;reset();
  823.                     break;
  824.                     default: break;
  825.                 }
  826.             }
  827.             break;
  828.         case TRIANGLE:
  829.         /*
  830.          @triangle x1,y1,x2,y2,x3,y3,color
  831.          @may be set draggable / onclic
  832.         */
  833.             for(i=0;i<7;i++){
  834.                 switch(i){
  835.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  836.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  837.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  838.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  839.                     case 4: double_data[4] = get_real(infile,0);break; /* x */
  840.                     case 5: double_data[5] = get_real(infile,0);break; /* y */
  841.                     case 6: stroke_color = get_color(infile,1);/* name or hex color */
  842.                         decimals = find_number_of_digits(precision);
  843.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,6,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  844.                         click_cnt++;reset();
  845.                         break;
  846.                     default: break;
  847.                 }
  848.             }
  849.             break;
  850.         case LATTICE:
  851.         /*
  852.          @lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
  853.          @can not be set "onclick" or "drag xy"
  854.         */
  855.             if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
  856.             for( i = 0; i<9; i++){
  857.                 switch(i){
  858.                     case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
  859.                     case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
  860.                     case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
  861.                     case 3: int_data[3] = (int) (get_real(infile,0));break; /* y1-values  -> y-pixels*/
  862.                     case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
  863.                     case 5: int_data[5] = (int) (get_real(infile,0));break; /* y2-values  -> y-pixels*/
  864.                     case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
  865.                     case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
  866.                     case 8: stroke_color=get_color(infile,1);
  867.                         decimals = find_number_of_digits(precision);
  868.                         string_length = snprintf(NULL,0,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,[%d,%d]);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_translate,translate_x,translate_y);
  869.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  870.                         snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,[%d,%d]);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_translate,translate_x,translate_y);
  871.                         add_to_buffer(tmp_buffer);
  872.                     break;
  873.                     default:break;
  874.                 }
  875.             }
  876.             reset();
  877.             break;
  878.         case SNAPTOGRID:
  879.         /*
  880.          @ snaptogrid
  881.          @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
  882.          @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
  883.          @ if xminor / yminor is defined, the drawing will snap to xminor and yminor<br />use only even dividers in x/y-minor...for example<br />snaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br />
  884.         */
  885.         fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;var snap_x = 1;var snap_y = 1;function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\n");
  886.         break;
  887.         case XSNAPTOGRID:
  888.         /*
  889.          @ xsnaptogrid
  890.          @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
  891.          @ in case of userdraw the drawn points will snap to xmajor grid
  892.          @ if xminor / yminor is defined, the drawing will snap to xminor <br />use only even dividers in x-minor...for example<br />xsnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br />
  893.         */
  894.         fprintf(js_include_file,"\nx_use_snap_to_grid = 1;var snap_x = 1;if (typeof snap_y === 'undefined') { var snap_y = 1;};var snap_y = 1;function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\n");
  895.         break;
  896.         case YSNAPTOGRID:
  897.         /*
  898.          @ ysnaptogrid
  899.          @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
  900.          @ in case of userdraw the drawn points will snap to ymajor grid
  901.          @ if xminor / yminor is defined, the drawing will snap to yminor <br />use only even dividers in y-minor...for example<br />ysnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br />
  902.         */
  903.         fprintf(js_include_file,"\ny_use_snap_to_grid = 1;if (typeof snap_x === 'undefined') { var snap_x = 1;};var snap_y = 1;\nfunction snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\n");
  904.         break;
  905.         case USERTEXTAREA_XY:
  906.         /*
  907.         @ usertextarea_xy
  908.         @ keyword
  909.         @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being...
  910.         @ if set two textareas are added to the document<br />(one for x-values , one for y-values)
  911.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  912.         @ can not be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields
  913.         @ user drawings will not zoom on zooming (or pan on panning)
  914.         */
  915.             if(use_tooltip == TRUE){canvas_error("usertextarea_xy can not be combined with intooltip command");}
  916.             if( use_input_xy == 1 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
  917.             fprintf(js_include_file,"function safe_eval(exp){if(exp.indexOf('^') != -1){exp = exp.replace(/\\s*(.*)\\^\\s*(.*)/ig, \"pow($1, $2)\");};var reg = /(?:[a-z$_][a-z0-9$_]*)|(?:[;={}\\[\\]\"'!&<>^\\\\?:])/ig;var valid = true;exp = exp.replace(reg,function($0){if (Math.hasOwnProperty($0)){return \"Math.\"+$0;}else{valid = false;};});if (!valid){alert(\"hmmm \"+exp+\" ?\"); exp = null;}else{try { exp = eval(exp); } catch (e) {alert(\"Invalid arithmetic expression\"); exp = null;};};return exp;};");
  918.             use_input_xy = 2;
  919.             break;
  920.         case USERINPUT_XY:
  921.         /*
  922.         @ userinput_xy
  923.         @ keyword
  924.         @ to be used in combination with command "userdraw object_type,color"
  925.         @ if set two (or three) input fields are added to the document<br />(one for x-values , one for y-values and in case of drawing circle one for radius-values)
  926.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  927.         @ math input is allowed (e.g something like: 1+3,2*6,1/3,sqrt(3), sin(pi/4),10^-2,log(2)...)<br />eval function is 'protected' against code injection.
  928.         @ can not be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields
  929.         @ user drawings will not zoom on zooming (or pan on panning)
  930.         */
  931.             if(use_tooltip == TRUE){canvas_error("userinput_xy can not be combined with intooltip command");}
  932.             /* add simple eval check to avoid code injection with unprotected eval(string) */
  933.             fprintf(js_include_file,"function safe_eval(exp){if(exp.indexOf('^') != -1){exp = exp.replace(/\\s*(.*)\\^\\s*(.*)/ig, \"pow($1, $2)\");};var reg = /(?:[a-z$_][a-z0-9$_]*)|(?:[;={}\\[\\]\"'!&<>^\\\\?:])/ig;var valid = true;exp = exp.replace(reg,function($0){if (Math.hasOwnProperty($0)){return \"Math.\"+$0;}else{valid = false;};});if (!valid){alert(\"hmmm \"+exp+\" ?\"); exp = null;}else{try { exp = eval(exp); } catch (e) {alert(\"Invalid arithmetic expression\"); exp = null;};};return exp;};");
  934.             use_input_xy = 1;
  935.             break;
  936.         case USERDRAW:
  937.         /*
  938.         @ userdraw object_type,color
  939.         @ implemented object_type: <ul><li>point</li><li>points</li><li>crosshair</li><li>crosshairs</li><li>line</li><li>lines</li><li>segment</li><li>segments</li><li>polyline</li><li>circle</li><li>circles</li><li>arrow</li><li>arrows</li><li>triangle</li><li>polygon</li><li>poly[3-9]</li><li>rect</li><li>roundrect</li><li>rects</li><li>roundrects</li><li>freehandline</li><li>freehandlines</li><li>path</li><li>paths</li><li>text</li></ul>
  940.         @ note: mouselisteners are only active if "$status != done " (eg only drawing in an active/non-finished exercise) <br /> to overrule use command/keyword "status" (no arguments required)
  941.         @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />while typing the background of every typed char will be lightblue..."backspace / delete / esc" will remove typed text.<br />You will need to hit "enter" to add the text to the array "userdraw_txt()" : lightblue background will disappear<br />Placing the cursor somewhere on a typed text and hitting "delete/backspace/esc" , a confirm will popup asking to delete the selected text.This text will be removed from the "userdraw_txt()" answer array.<br />Use commands 'fontsize' and 'fontfamily' to control the text appearance
  942.         @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
  943.         @ note: all objects will be removed -after a javascript confirm box- when clicked on an object point with middle or right mouse butten (e.g. event.which != 1 : all buttons but left)
  944.         @ use command "filled", "opacity int,int"  and "fillcolor color" to trigger coloured filling of fillable objects
  945.         @ use command "dashed" and/or "dashtype int,int" to trigger dashing
  946.         @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas();
  947.         @ may be combined with onclick or drag xy  of other components of flyscript objects (although not very usefull...)
  948.         @ may be combined with keyword 'userinput_xy' or
  949.         @ note: when zooming / panning after a drawing, the drawing will NOT be zoomed / panned...this is a "design" flaw and not a feature <br />To avoid trouble do not use zooming / panning together width userdraw.!
  950.         */
  951.             if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
  952.                 canvas_error("Only one userdraw primitive may be used: read documentation !!");
  953.             }
  954.             use_userdraw = TRUE;
  955.             fprintf(js_include_file,"<!-- begin userdraw mouse events -->\nvar userdraw_x = new Array();var userdraw_y = new Array();var userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};if(wims_status != \"done\"){canvas_div.addEventListener(\"mousedown\",user_draw,false);canvas_div.addEventListener(\"mousemove\",user_drag,false);canvas_div.addEventListener(\"touchstart\",user_draw,false);canvas_div.addEventListener(\"touchmove\",user_drag,false);}\n<!-- end userdraw mouse events -->",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
  956.             draw_type = get_string_argument(infile,0);
  957.             stroke_color = get_color(infile,1);
  958.             if( strcmp(draw_type,"point") == 0 ){
  959.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  960.                 if(reply_format < 1 ){reply_format = 8;}
  961.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  962.                 if(use_input_xy == 1){
  963.                     add_input_circle(js_include_file,1,1);
  964.                     add_input_xy(js_include_file,canvas_root_id);
  965.                 }
  966.                 add_js_points(js_include_file,1,draw_type,line_width,line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);
  967.             }
  968.             else
  969.             if( strcmp(draw_type,"points") == 0 ){
  970.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  971.                 if(reply_format < 1 ){reply_format = 8;}
  972.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  973.                 if(use_input_xy == 1){
  974.                     add_input_circle(js_include_file,1,2);
  975.                     add_input_xy(js_include_file,canvas_root_id);
  976.                 }
  977.                 add_js_points(js_include_file,2,draw_type,line_width,line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);
  978.             }
  979.             else
  980.             if( strcmp(draw_type,"segment") == 0 ){
  981.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  982.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  983.                 if(reply_format < 1){reply_format = 11;}
  984.                 if(use_input_xy == 1){
  985.                     add_input_segment(js_include_file,1);
  986.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  987.                 }
  988.                 add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  989.             }
  990.             else
  991.             if( strcmp(draw_type,"polyline") == 0 ){
  992.                 if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
  993.                 if(reply_format < 1){reply_format = 23;}
  994.                 if( use_input_xy == 1 ){
  995.                     add_input_polyline(js_include_file);
  996.                     add_input_xy(js_include_file,canvas_root_id);
  997.                 }
  998.                 add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  999.             }
  1000.             else
  1001.             if( strcmp(draw_type,"segments") == 0 ){
  1002.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1003.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  1004.                 if(reply_format < 1){reply_format = 11;}
  1005.                 if(use_input_xy == 1){
  1006.                     add_input_segment(js_include_file,2);
  1007.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1008.                 }
  1009.                 add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1010.             }
  1011.             else
  1012.             if( strcmp(draw_type,"circle") == 0 ){
  1013.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1014.                 if(reply_format < 1){reply_format = 10;}
  1015.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  1016.                 if(use_input_xy == 1){
  1017.                     add_input_circle(js_include_file,2,1);
  1018.                     add_input_xyr(js_include_file,canvas_root_id);
  1019.                 }
  1020.                 add_js_circles(js_include_file,1,draw_type,line_width,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1021.             }
  1022.             else
  1023.             if( strcmp(draw_type,"circles") == 0 ){
  1024.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1025.                 if(reply_format < 1){reply_format = 10;}
  1026.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  1027.                 add_js_circles(js_include_file,2,draw_type,line_width,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1028.                 if(use_input_xy == 1){
  1029.                     add_input_circle(js_include_file,2,2);
  1030.                     add_input_xyr(js_include_file,canvas_root_id);
  1031.                 }
  1032.             }
  1033.             else
  1034.             if(strcmp(draw_type,"crosshair") == 0 ){
  1035.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  1036.                 if(reply_format < 1){reply_format = 8;}
  1037.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1038.                 add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
  1039.                 if(use_input_xy == 1){
  1040.                     add_input_crosshair(js_include_file,1);
  1041.                     add_input_xy(js_include_file,canvas_root_id);
  1042.                 }
  1043.             }
  1044.             else
  1045.             if(strcmp(draw_type,"crosshairs") == 0 ){
  1046.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  1047.                 if(reply_format < 1){reply_format = 8;}
  1048.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1049.                 add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
  1050.                 if(use_input_xy == 1){
  1051.                     add_input_crosshair(js_include_file,2);
  1052.                     add_input_xy(js_include_file,canvas_root_id);
  1053.                 }
  1054.             }
  1055.             else
  1056.             if(strcmp(draw_type,"freehandline") == 0 ){
  1057.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1058.                 if(reply_format < 1){reply_format = 6;}
  1059.                 add_js_paths(js_include_file,1,draw_type,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);  
  1060.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1061.             }
  1062.             else
  1063.             if(strcmp(draw_type,"freehandlines") == 0 ){
  1064.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1065.                 if(reply_format < 1){reply_format = 6;}
  1066.                 add_js_paths(js_include_file,2,draw_type,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);  
  1067.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1068.             }
  1069.             else
  1070.             if(strcmp(draw_type,"path") == 0 ){
  1071.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1072.                 if(reply_format < 1){reply_format = 6;}
  1073.                 add_js_paths(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);  
  1074.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1075.             }
  1076.             else
  1077.             if(strcmp(draw_type,"paths") == 0 ){
  1078.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1079.                 if(reply_format < 1){reply_format = 6;}
  1080.                 add_js_paths(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);  
  1081.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1082.             }
  1083.             else
  1084.             if(strcmp(draw_type,"arrows") == 0 ){
  1085.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  1086.                 if(reply_format < 1){reply_format = 11;}
  1087.                 add_js_arrows(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  1088.                 if(use_input_xy == 1){
  1089.                     add_input_arrow(js_include_file,2);
  1090.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1091.                 }
  1092.             }
  1093.             else
  1094.             if(strcmp(draw_type,"arrow") == 0 ){
  1095.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  1096.                 if(reply_format < 1){reply_format = 11;}
  1097.                 add_js_arrows(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  1098.                 if(use_input_xy == 1){
  1099.                     add_input_arrow(js_include_file,1);
  1100.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1101.                 }
  1102.             }
  1103.             else
  1104.             if(strcmp(draw_type,"polygon") == 0){
  1105.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1106.                 if(reply_format < 1){reply_format = 2;}
  1107.                 add_js_poly(js_include_file,-1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1108.                 if( use_input_xy == 2 ){
  1109.                   add_textarea_polygon(js_include_file);
  1110.                   add_textarea_xy(js_include_file,canvas_root_id);
  1111.                 }
  1112.             }
  1113.             else
  1114.             if(strncmp(draw_type,"poly",4) == 0){
  1115.                 if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
  1116.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1117.                 if(reply_format < 1){reply_format = 2;}
  1118.                 add_js_poly(js_include_file,(int) (draw_type[4]-'0'),draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1119.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1120.             }
  1121.             else
  1122.             if(strcmp(draw_type,"triangle") == 0){
  1123.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1124.                 if(reply_format < 1){reply_format = 2;}
  1125.                 add_js_poly(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1126.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1127.             }
  1128.             else
  1129.             if( strcmp(draw_type,"line") == 0 ){
  1130.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1131.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1132.                 if(reply_format < 1){reply_format = 11;}
  1133.                 add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1134.                 if( use_input_xy == 1 ){
  1135.                     add_input_line(js_include_file,1);
  1136.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1137.                 }
  1138.             }
  1139.             else
  1140.             if( strcmp(draw_type,"lines") == 0 ){
  1141.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1142.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1143.                 if(reply_format < 1){reply_format = 11;}
  1144.                 add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1145.                 if( use_input_xy == 1 ){
  1146.                     add_input_line(js_include_file,2);
  1147.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1148.                 }
  1149.             }
  1150.             else
  1151.             if( strcmp(draw_type,"rects") == 0){
  1152.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  1153.                 if(reply_format < 1){reply_format = 2;}
  1154.                 add_js_rect(js_include_file,2,0,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1155.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1156.             }
  1157.             else
  1158.             if( strcmp(draw_type,"roundrects") == 0){
  1159.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  1160.                 if(reply_format < 1){reply_format = 2;}
  1161.                 add_js_rect(js_include_file,2,1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1162.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1163.             }
  1164.             else
  1165.             if( strcmp(draw_type,"rect") == 0){
  1166.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  1167.                 if(reply_format < 1){reply_format = 2;}
  1168.                 add_js_rect(js_include_file,1,0,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1169.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1170.             }
  1171.             else
  1172.             if( strcmp(draw_type,"roundrect") == 0){
  1173.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  1174.                 if(reply_format < 1){reply_format = 2;}
  1175.                 add_js_rect(js_include_file,1,1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1176.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1177.             }
  1178.             else
  1179.             if( strcmp(draw_type,"text") == 0){
  1180.                 if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}      
  1181.                 if(reply_format < 1){reply_format = 17;}
  1182.                 add_js_text(js_include_file,canvas_root_id,font_size,font_family,font_color,stroke_opacity,use_rotate,angle,use_translate,translate_x,translate_y);
  1183.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1184.             }
  1185.             else
  1186.             {
  1187.                 canvas_error("unknown drawtype or typo? ");
  1188.             }
  1189.             reset();
  1190.         break;
  1191.         case PLOTSTEPS:
  1192.             /*
  1193.              @ plotsteps a_number
  1194.              @ default 150
  1195.              @ use with care !
  1196.             */
  1197.             plot_steps = (int) (get_real(infile,1));
  1198.             break;
  1199.         case FONTSIZE:
  1200.         /*
  1201.          @fontsize font_size
  1202.          @default value 12
  1203.         */
  1204.             font_size = (int) (get_real(infile,1));
  1205.             break;
  1206.         case FONTCOLOR:
  1207.         /*
  1208.          @fontcolor color
  1209.          @color: hexcolor or colorname
  1210.          @default: black
  1211.          @example usage: x/y-axis text
  1212.         */
  1213.             font_color = get_color(infile,1);
  1214.             break;
  1215.         case ANIMATE:
  1216.         /*
  1217.          @animate type
  1218.          @type may be "point" (nothing else , yet...)
  1219.          @the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber'
  1220.          @will animate a point on the next plot/curve command
  1221.          @the curve will not be draw
  1222.          @moves repeatedly from xmin to xmax
  1223.         */
  1224.             if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");}
  1225.             break;
  1226.         case CURVE:
  1227.         /*
  1228.          @curve color,formula(x)
  1229.          @plot color,formula(x)
  1230.          @use command trange before command curve / plot  (trange -pi,pi)<br />curve color,formula1(t),formula2(t)
  1231.          @use command "precision" to increase the number of digits of the plotted points
  1232.          @use command "plotsteps" to increase / decrease the amount of plotted points (default 150)
  1233.          @may be set draggable / onclick
  1234.         */
  1235.             if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
  1236.                 use_parametric = FALSE;
  1237.                 stroke_color = get_color(infile,0);
  1238.                 char *fun1 = get_string_argument(infile,0);
  1239.                 char *fun2 = get_string_argument(infile,1);
  1240.                 if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
  1241.                 use_parametric = FALSE;
  1242.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,animation_type,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision),2*line_width,2*line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  1243.                 click_cnt++;
  1244.             }
  1245.             else
  1246.             {
  1247.                 stroke_color = get_color(infile,0);
  1248.                 char *fun1 = get_string_argument(infile,1);
  1249.                 if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} 
  1250.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,animation_type,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix);
  1251.                 click_cnt++;
  1252.             }
  1253.             animation_type = 9;/* rest to curve plotting without animation */
  1254.             reset();
  1255.             break;
  1256.         case FLY_TEXT:
  1257.         /*
  1258.         @ text fontcolor,x,y,font,text_string
  1259.         @ font may be described by keywords : giant,huge,normal,small,tiny
  1260.         @ use command 'fontsize' to increase base fontsize for the keywords
  1261.         @ may be set "onclick" or "drag xy"
  1262.         @ backwards compatible with flydraw
  1263.         @ unicode supported: text red,0,0,huge,\\u2232
  1264.         @ use command 'string' and 'fontfamily' for a more fine grained control over html5 canvas text element
  1265.         @ Avoid  mixing old flydraw commands 'text' 'textup' with new canvasdraw commands 'string' stringup'<br />If the fontfamily was set completely like "fontfamily italic 24px Ariel".<br />In that case rested 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands.
  1266.         */
  1267.             for(i = 0; i < 5 ;i++){
  1268.                 switch(i){
  1269.                     case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
  1270.                     case 1: double_data[0] = get_real(infile,0);break; /* x */
  1271.                     case 2: double_data[1] = get_real(infile,0);break; /* y */
  1272.                     case 3: fly_font = get_string_argument(infile,0);
  1273.                             if(strcmp(fly_font,"giant") == 0){
  1274.                                 font_size = (int)(font_size + 24);
  1275.                             }
  1276.                             else
  1277.                             {
  1278.                                 if(strcmp(fly_font,"huge") == 0){
  1279.                                     font_size = (int)(font_size + 14);
  1280.                                 }
  1281.                                 else
  1282.                                 {
  1283.                                     if(strcmp(fly_font,"large") == 0){
  1284.                                         font_size = (int)(font_size + 6);
  1285.                                         }
  1286.                                         else
  1287.                                         {
  1288.                                             if(strcmp(fly_font,"small") == 0){
  1289.                                                 font_size = (int)(font_size - 4);
  1290.                                                 if(font_size<0){font_size = 8;}
  1291.                                         }
  1292.                                     }
  1293.                                 }
  1294.                             }
  1295.                             break; /* font_size ! */
  1296.                     case 4:
  1297.                         temp = get_string_argument(infile,1);
  1298.                         decimals = find_number_of_digits(precision);
  1299.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%d,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,0,0,temp,font_size,font_family,use_affine,affine_matrix);
  1300.                         click_cnt++;reset();break;
  1301.                     default:break;
  1302.                 }
  1303.             }
  1304.             break;
  1305.         case FLY_TEXTUP:
  1306.         /*
  1307.          @ textup fontcolor,x,y,font,text_string
  1308.          @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
  1309.          @ font may be described by keywords : giant,huge,normal,small,tiny
  1310.          @ use command 'fontsize' to increase base fontsize for the keywords
  1311.          @ backwards compatible with flydraw
  1312.          @ unicode supported: textup red,0,0,huge,\\u2232
  1313.          @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element
  1314.          @ Avoid  mixing old flydraw commands 'text' 'textup' with new canvasdraw commands 'string' stringup'<br />If the fontfamily was set completely like "fontfamily italic 24px Ariel".<br />In that case rested 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands.
  1315.         */
  1316.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}  
  1317.             for(i = 0; i<5 ;i++){
  1318.                 switch(i){
  1319.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  1320.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  1321.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  1322.                     case 3: fly_font = get_string_argument(infile,0);
  1323.                             if(strcmp(fly_font,"giant") == 0){
  1324.                                 font_size = (int)(font_size + 24);
  1325.                             }
  1326.                             else
  1327.                             {
  1328.                                 if(strcmp(fly_font,"huge") == 0){
  1329.                                     font_size = (int)(font_size + 14);
  1330.                                 }
  1331.                                 else
  1332.                                 {
  1333.                                     if(strcmp(fly_font,"large") == 0){
  1334.                                         font_size = (int)(font_size + 6);
  1335.                                         }
  1336.                                         else
  1337.                                         {
  1338.                                             if(strcmp(fly_font,"small") == 0){
  1339.                                                 font_size = (int)(font_size - 4);
  1340.                                                 if(font_size<0){font_size = 8;}
  1341.                                         }
  1342.                                     }
  1343.                                 }
  1344.                             }
  1345.                             break; /* font_size ! */
  1346.                     case 4:
  1347.                     decimals = find_number_of_digits(precision);
  1348.                     temp = get_string_argument(infile,1);
  1349.                     string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,[%d,%d]);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_translate,translate_x,translate_y);
  1350.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1351.                     snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,[%d,%d]);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_translate,translate_x,translate_y);
  1352.                     add_to_buffer(tmp_buffer);
  1353.                     break;
  1354.                     default:break;
  1355.                 }
  1356.             }
  1357.             reset();
  1358.             break;
  1359.         case FONTFAMILY:
  1360.         /*
  1361.          @ fontfamily font_description
  1362.          @ set the font family; for browsers that support it
  1363.          @ font_description: Ariel ,Courier, Helvetica etc
  1364.          @ in case commands<br /> 'string color,x,y,the string'<br /> 'stringup color,x,y,rotation,the string'<br />fontfamily can be something like:<br />italic 34px Ariel
  1365.          @ use correct syntax : 'font style' 'font size'px 'fontfamily'
  1366.         */
  1367.             font_family = get_string(infile,1);
  1368.             break;
  1369.         case STRINGUP:
  1370.         /*
  1371.          @ stringup color,x,y,rotation_degrees,the text string
  1372.          @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
  1373.          @ unicode supported: stringup red,0,0,45,\\u2232
  1374.          @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change
  1375.  
  1376.         */
  1377.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library : rotate / mouse issues */
  1378.             for(i=0;i<6;i++){
  1379.                 switch(i){
  1380.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  1381.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  1382.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  1383.                     case 3: double_data[0] = get_real(infile,0);break;/* rotation */
  1384.                     case 4: decimals = find_number_of_digits(precision);
  1385.                             temp = get_string_argument(infile,1);
  1386.                             string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,[%d,%d]);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_translate,translate_x,translate_y);
  1387.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1388.                             snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,[%d,%d]);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_translate,translate_x,translate_y);
  1389.                             add_to_buffer(tmp_buffer);
  1390.                             break;
  1391.                     default:break;
  1392.                 }
  1393.             }
  1394.             reset();
  1395.             break;
  1396.         case STRING:
  1397.         /*
  1398.          @ string color,x,y,the text string
  1399.          @ may be set "onclick" or "drag xy"
  1400.          @ unicode supported: string red,0,0,\\u2232
  1401.          @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
  1402.         */
  1403.             for(i=0;i<5;i++){
  1404.                 switch(i){
  1405.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  1406.                     case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
  1407.                     case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
  1408.                     case 3: decimals = find_number_of_digits(precision);
  1409.                         temp = get_string_argument(infile,1);
  1410.                         decimals = find_number_of_digits(precision);
  1411.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%d,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,0,0,temp,font_size,font_family,use_affine,affine_matrix);
  1412.                         click_cnt++;reset();break;
  1413.                             break;
  1414.                     default:break;
  1415.                 }
  1416.             }
  1417.             break;
  1418.         case MATHML:
  1419.         /*
  1420.         @ mathml x1,y1,x2,y2,mathml_string
  1421.         @ mathml will be displayed in a rectangle left top (x1:y1) , right bottom (x2:y2)
  1422.         @ can be set onclick <br />(however dragging is not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
  1423.         @ if inputfields are incorporated in mathml (with id's : id='mathml0',id='mathml1',...id='mathml_n')<br />the user_input values will be read by javascript:read_mathml();<br />attention: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();"
  1424.         @ If other inputfields (command input / command textarea) or userdraw is performed, the function read_canvas() will not read mathml. Use some generic function to read it....
  1425.        
  1426.         */
  1427.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  1428.             for(i=0;i<5;i++){
  1429.                 switch(i){
  1430.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  1431.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  1432.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  1433.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  1434.                     case 4: decimals = find_number_of_digits(precision);
  1435.                             if(onclick == 1 ){ onclick = click_cnt;click_cnt++;}
  1436.                             temp = get_string(infile,1);
  1437.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  1438.                             string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick);
  1439.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1440.                             snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick);
  1441.                             add_to_buffer(tmp_buffer);
  1442.                             /*
  1443.                              in case inputs are present , trigger adding the read_mathml()
  1444.                              if no other reply_format is defined
  1445.                              note: all other reply types will include a reading of elements with id='mathml'+p)
  1446.                              */
  1447.                             if(strstr(temp,"mathml0") != NULL){
  1448.                              if(reply_format < 1 ){reply_format = 16;} /* no other reply type is defined */
  1449.                             }
  1450.                             break;
  1451.                     default:break;
  1452.                 }
  1453.             }
  1454.             reset();
  1455.             break;
  1456.         case HTTP:
  1457.         /*
  1458.          @http x1,y1,x2,y2,http://some_adress.com
  1459.          @an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2)
  1460.          @do not use interactivity (or mouse) if the mouse needs to be active in the iframe
  1461.          @can not be 'set onclick' or 'drag xy'
  1462.         */
  1463.             if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}    
  1464.             for(i=0;i<5;i++){
  1465.                 switch(i){
  1466.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  1467.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  1468.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  1469.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  1470.                     case 4: decimals = find_number_of_digits(precision);
  1471.                             temp = get_string(infile,1);
  1472.                             if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
  1473.                             string_length = snprintf(NULL,0,"draw_http(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp);
  1474.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1475.                             snprintf(tmp_buffer,string_length,"draw_http(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp);
  1476.                             add_to_buffer(tmp_buffer);
  1477.                     break;
  1478.                 }
  1479.             }
  1480.             reset();
  1481.             break;
  1482.         case HTML:
  1483.         /*
  1484.          @ html x1,y1,x2,y2,html_string
  1485.          @ all tags are allowed
  1486.          @ can be set onclick <br />(dragging not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
  1487.          @ if inputfields are incorporated  (with id's : id='mathml0',id='mathml1',...id='mathml_n')<br />the user_input values will be read by javascript:read_canvas(); <br />If other inputfields (command input / command textarea) or userdraw is performed, these values will NOT be read as well.
  1488.          
  1489.          note: uses the same code as 'mathml'
  1490.         */
  1491.             break;
  1492.         case X_AXIS_STRINGS:
  1493.         /*
  1494.          @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  1495.          @ xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  1496.          @ use these x-axis values in stead of default xmin...xmax
  1497.          @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
  1498.          @ if the 'x-axis words' are to big amd will overlap, a simple alternating offset will be applied
  1499.          @ example:<br />size 400,400<br />xrange 0,13<br />yrange -100,500<br />axis<br />xaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december<br />#'xmajor' steps should be synchronised with numbers eg. "1" in this example<br />grid 1,100,grey,1,4,6,grey
  1500.          @ example:<br />size 400,400<br />xrange -5*pi,5*pi<br />yrange -100,500<br />axis<br />xaxis -4*pi:-4\\u03c0:-3*pi:-3\\u03c0:-2*pi:-2\\u03c0:-1*pi:-\\u03c0:0:0:pi:\\u03c0:2*pi:2\\u03c01:3*pi:3\\u03c0:4*pi:4\\u03c0<br />#'xmajor' steps should be synchronised with numbers eg. "1" in this example<br />grid pi,1,grey,1,3,6,grey
  1501.         */
  1502.             temp = get_string(infile,1);
  1503.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  1504.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  1505.             fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp);
  1506.             use_axis_numbering = 1;
  1507.             break;
  1508.         case Y_AXIS_STRINGS:
  1509.         /*
  1510.          @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  1511.          @ yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  1512.          @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
  1513.          @ use these y-axis values in stead of default ymin...ymax
  1514.          @ example:<br />size 400,400<br />yrange 0,13<br />xrange -100,500<br />axis<br />yaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december<br />#'ymajor' steps should be synchronised with numbers eg. "1" in this example<br />grid 100,1,grey,4,1,6,grey
  1515.         */
  1516.             temp = get_string(infile,1);
  1517.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  1518.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  1519.             fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
  1520.             use_axis_numbering = 1;
  1521.             break;
  1522.          
  1523.         case AXIS_NUMBERING:
  1524.         /*
  1525.             @ axisnumbering
  1526.             @ keyword, no aguments required
  1527.         */
  1528.             use_axis_numbering = 1;
  1529.             break;
  1530.         case AXIS:
  1531.         /*
  1532.             @ axis
  1533.             @ keyword, no aguments required
  1534.  
  1535.         */
  1536.             use_axis = TRUE;
  1537.             break;
  1538.         case SGRAPH:
  1539.         /*
  1540.          @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
  1541.          @ primitive implementation of a 'broken scale' graph...
  1542.          @ not very versatile.
  1543.          @ example:<br />size 400,400<br />xrange 0,10000<br />yrange 0,100<br />sgraph 9000,50,100,10,4,4,grey,blue<br />userinput_xy<br />linewidth 2<br />userdraw segments,red
  1544.         */
  1545.             if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
  1546.             for(i = 0 ; i < 8 ;i++){
  1547.                 switch(i){
  1548.                     case 0:double_data[0] = get_real(infile,0);break;
  1549.                     case 1:double_data[1] = get_real(infile,0);break;
  1550.                     case 2:double_data[2] = get_real(infile,0);break;
  1551.                     case 3:double_data[3] = get_real(infile,0);break;
  1552.                     case 4:int_data[0] = (int)(get_real(infile,0));break;
  1553.                     case 5:int_data[1] = (int)(get_real(infile,0));break;
  1554.                     case 6:stroke_color = get_color(infile,0);break;
  1555.                     case 7:font_color = get_color(infile,1);
  1556.                     string_length = snprintf(NULL,0,"xstart = %f;\nystart = %f;\ndraw_sgraph(%d,%d,%f,%f,%d,%d,\"%s\",\"%s\",\"%s\",%f,%d);\n",double_data[0],double_data[1],GRID_CANVAS,precision,double_data[2],double_data[3],int_data[0],int_data[1],stroke_color,font_color,font_family,stroke_opacity,font_size);
  1557.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1558.                     snprintf(tmp_buffer,string_length,"xstart = %f;\nystart = %f;\ndraw_sgraph(%d,%d,%f,%f,%d,%d,\"%s\",\"%s\",\"%s\",%f,%d);\n",double_data[0],double_data[1],GRID_CANVAS,precision,double_data[2],double_data[3],int_data[0],int_data[1],stroke_color,font_color,font_family,stroke_opacity,font_size);
  1559.                     add_to_buffer(tmp_buffer);
  1560.                     break;
  1561.                     default:break;
  1562.                 }
  1563.             }
  1564.             /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
  1565.             break;
  1566.         case GRID:/* xmajor,ymajor,color [,xminor,yminor,tick length (px) ,color]*/
  1567.         /*
  1568.          @ grid step_x,step_y,gridcolor
  1569.          @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
  1570.          @ if keywords "axis" or "axisnumbering" are set, use :<br />grid step_x,step_y,major_color,minor_x,minor_y,tics height in px,axis_color<br />minor x step = step_x / minor_x
  1571.          @ if xmin > 0 and/or ymin > 0 and zooming / panning is not activ: <br /> be aware that the x/y-axis numbering and x/y major/minor tic marks will not be visual <br /> as they are placed under the x-axis and left to the y-axis (in Quadrant II and IV)
  1572.          @ can not be set "onclick" or "drag xy"
  1573.          @ use commands 'xlabel some_string' and/or 'ylabel some_string' to label axis;<br />use command "fontsize" to adjust size (the font family is non-configurable 'italic your_fontsize px Ariel')
  1574.          @ see commands "xaxis" or "xaxistext", "yaxis" or "yaxistext" to set tailormade values on axis (the used font is set by command fontfamily; default '12px Ariel')
  1575.          @ see command "legend" to set a legend for the graph ;<br />use command "fontsize" to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel')
  1576.         */
  1577.             if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
  1578.             if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
  1579.             for(i=0;i<4;i++){
  1580.                 switch(i){
  1581.                     case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
  1582.                     case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
  1583.                     case 2:
  1584.                     if( use_axis == TRUE ){
  1585.                         stroke_color = get_color(infile,0);
  1586.                         done = FALSE;
  1587.                         int_data[0] = (int) (get_real(infile,0));/* xminor */
  1588.                         int_data[1] = (int) (get_real(infile,0));/* yminor */
  1589.                         int_data[2] = (int) (get_real(infile,0));/* tic_length */
  1590.                         fill_color = get_color(infile,1); /* used as axis_color*/
  1591.                     }
  1592.                     else
  1593.                     {
  1594.                         int_data[0] = 1;
  1595.                         int_data[1] = 1;
  1596.                         stroke_color = get_color(infile,1);
  1597.                         fill_color = stroke_color;
  1598.                     }
  1599.                     if( double_data[0] <= 0 ||  double_data[1] <= 0 ||  int_data[0] <= 0 ||  int_data[1] <= 0 ){canvas_error("major or minor tickt must be positive !");}
  1600.                     /* set snap_x snap_y values in pixels */
  1601.                     fprintf(js_include_file,"snap_x = %f;snap_y = %f\n;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
  1602. /* draw_grid%d = function(canvas_type,precision,stroke_opacity,xmajor,ymajor,xminor,yminor,tics_length,line_width,stroke_color,axis_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_translate,vector,use_dashed,dashtype0,dashtype1,font_color,fill_opacity){ */
  1603.  
  1604.                     string_length = snprintf(NULL,0,  "draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,[%d,%d],%d,%d,%d,\"%s\",%.2f);\n",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_translate,translate_x,translate_y,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity);
  1605.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1606.                     snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,[%d,%d],%d,%d,%d,\"%s\",%.2f);\n",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_translate,translate_x,translate_y,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity);
  1607.                     add_to_buffer(tmp_buffer);
  1608.                     break;
  1609.                 }
  1610.             }
  1611.             reset();
  1612.             break;
  1613.         case OPACITY:
  1614.         /*
  1615.         @ opacity 0-255,0-255
  1616.         @
  1617.         */
  1618.             for(i = 0 ; i<2;i++){
  1619.                 switch(i){
  1620.                     case 0: double_data[0]=(int)(get_real(infile,0));break;
  1621.                     case 1: double_data[1]=(int)(get_real(infile,1));break;
  1622.                     default: break;
  1623.                 }
  1624.             }
  1625.             if( double_data[0] < 0 || double_data[0] > 255 || double_data[1] < 0 || double_data[1] > 255  ){ canvas_error("opacity [0 - 255] , [0 - 255]");}/* typo or non-RGB ? */
  1626.             stroke_opacity = (double) (0.0039215*double_data[0]);/* 0.0 - 1.0 */
  1627.             fill_opacity = (double) (0.0039215*double_data[1]);/* 0.0 - 1.0 */
  1628.             break;
  1629.         case ROTATE:
  1630.         /*
  1631.          @rotate rotation_angle
  1632.          @
  1633.         */
  1634.             use_rotate = TRUE;
  1635.             use_translate = TRUE;
  1636.             translate_x = x2px(0);
  1637.             translate_y = y2px(0);
  1638.             angle = get_real(infile,1);
  1639.             break;
  1640.         case KILLAFFINE:
  1641.         /*
  1642.         @ killaffine
  1643.         @ keyword : resets the transformation matrix to 1,0,0,1,0,0
  1644.         */
  1645.             use_affine = FALSE;
  1646.             snprintf(affine_matrix,14,"[1,0,0,1,0,0]");    
  1647.             break;
  1648.         case AFFINE:
  1649.         /*
  1650.          @affine a,b,c,d,tx,ty
  1651.          @ defines a transformation matrix for subsequent objects
  1652.          @ use keyword 'killaffine' to end the transformation
  1653.          @ note 1: only 'draggable' / 'noclick' objects can be transformed.
  1654.          @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet)
  1655.          @ note 3: no matrix operations on the transformation matrix implemented (yet)
  1656.          @ a : Scales the drawings horizontally
  1657.          @ b : Skews the drawings horizontally
  1658.          @ c : Skews the drawings vertically
  1659.          @ d : Scales the drawings vertically
  1660.          @ tx: Moves the the drawings horizontally in pixels !
  1661.          @ ty: Moves the the drawings vertically in pixels !
  1662.         */
  1663.             for(i = 0 ; i<6;i++){
  1664.                 switch(i){
  1665.                     case 0: double_data[0] = get_real(infile,0);break;
  1666.                     case 1: double_data[1] = get_real(infile,0);break;
  1667.                     case 2: double_data[2] = get_real(infile,0);break;
  1668.                     case 3: double_data[3] = get_real(infile,0);break;
  1669.                     case 4: int_data[0] = (int)(get_real(infile,0));break;
  1670.                     case 5: int_data[1] = (int)(get_real(infile,1));
  1671.                         use_affine = TRUE;
  1672.                         string_length = snprintf(NULL,0,"[%.2f,%.2f,%.2f,%.2f,%d,%d] ",double_data[0],double_data[1],double_data[2],double_data[3],int_data[0],int_data[1]);
  1673.                         check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
  1674.                         snprintf(affine_matrix,string_length,"[%.2f,%.2f,%.2f,%.2f,%d,%d] ",double_data[0],double_data[1],double_data[2],double_data[3],int_data[0],int_data[1]);    
  1675.                     break;
  1676.                     default: break;
  1677.                 }
  1678.             }
  1679.         break;
  1680.         case KILLTRANSLATION:
  1681.         /*
  1682.          killtranslation
  1683.         */
  1684.             break;
  1685.         case TRANSLATION:
  1686.         /*
  1687.          @translation tx,ty
  1688.          @
  1689.         */
  1690.             use_translate = TRUE;
  1691.             translate_x = get_real(infile,0);
  1692.             translate_y = get_real(infile,1);
  1693.             break;
  1694.         case DASHED:
  1695.         /*
  1696.         @ keyword "dashed"
  1697.         @ next object will be drawn with a dashed line
  1698.         @ change dashing scheme by using command "dashtype int,int)
  1699.         */
  1700.             use_dashed = TRUE;
  1701.             break;
  1702.         case FILLED:
  1703.         /*
  1704.         @ keyword "filled"
  1705.         @ the next 'fillable' object (only) will be filled
  1706.         @ use command "fillcolor color" to set fillcolor
  1707.         @ use command "opacity 0-255,0-255" to set stroke and fill-opacity
  1708.         @ use command "fill x,y,color" or "floodfill x,y,color" to fill the space around (x;y) with color <br />pixel operation implemented in javascript: use with care !
  1709.         */
  1710.             use_filled = TRUE;
  1711.             break;
  1712.         case STYLE:
  1713.         /*
  1714.          @highlight color,opacity,linewidth
  1715.          @ NOT IMPLEMENTED
  1716.          @ use command "onclick" : when the object receives a userclick it will increase it's linewidth
  1717.         */
  1718.             break;
  1719.         case FILLCOLOR:
  1720.         /*
  1721.         @ fillcolor colorname or #hex
  1722.         @ Set the color for a filled object : mainly used for command 'userdraw obj,stroke_color'
  1723.         @ All fillable massive object will have a fillcolor == strokecolor (just to be compatible with flydraw...)
  1724.         */
  1725.             fill_color = get_color(infile,1);
  1726.             break;
  1727.         case STROKECOLOR:
  1728.         /*
  1729.         @ strokecolor colorname or #hex
  1730.         @ to be used for commands that do not supply a color argument (like command 'linegraph')
  1731.         */
  1732.             stroke_color = get_color(infile,1);
  1733.             break;
  1734.         case BGIMAGE:
  1735.         /*
  1736.          @bgimage image_location
  1737.          @use an image as background .<br />(we use the background of 'canvas_div' )
  1738.          @the background image will be resized to match "width = xsize" and "height = ysize"
  1739.         */
  1740.         URL = get_string(infile,1);
  1741.         fprintf(js_include_file,"<!-- set background image to canvas div -->\ncanvas_div.style.backgroundImage = \"url(%s)\";canvas_div.style.backgroundSize = \"%dpx %dpx\";\n",URL,xsize,ysize);
  1742.             break;
  1743.         case BGCOLOR:
  1744.         /*
  1745.          @bgcolor colorname or #hex
  1746.          @use this color as background of the "div" containing the canvas(es)
  1747.         */
  1748.         /* [255,255,255]*/
  1749.             bgcolor = get_string(infile,1);
  1750.             if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
  1751.                 int found = 0;
  1752.                 for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  1753.                     if( strcmp( colors[i].name , bgcolor ) == 0 ){
  1754.                         bgcolor = colors[i].hex;
  1755.                         found = 1;
  1756.                         break;
  1757.                     }
  1758.                 }
  1759.                 if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");}
  1760.             }
  1761.             fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
  1762.             break;
  1763.         case COPY:
  1764.         /*
  1765.         @ copy x,y,x1,y1,x2,y2,[filename URL]
  1766.         @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
  1767.         @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
  1768.         @ [filename] is the URL of the image   
  1769.         @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
  1770.         @ if command 'drag x/y/xy' is set before command 'copy', the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valuid for the next image<br />draggable / non-draggable images may be mixed
  1771.         @ if you want to draw / userdraw  on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent
  1772.  
  1773.         context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  1774.         draw_external_image(canvas_type,URL,sx,sy,swidth,sheight,x,y,width,height,drag_drop){
  1775.         */
  1776.             for(i = 0 ; i<7;i++){
  1777.                 switch(i){
  1778.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
  1779.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
  1780.                     case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
  1781.                     case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
  1782.                     case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
  1783.                     case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
  1784.                     case 6: URL = get_string(infile,1);
  1785.                             int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
  1786.                             int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
  1787.                             if( drag_type > -1 ){
  1788.                                 if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
  1789.                                 if(reply_format < 1 ){reply_format = 20;}
  1790.                                 string_length = snprintf(NULL,0,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,1);
  1791.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1792.                                 snprintf(tmp_buffer,string_length,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,1);                       
  1793.                                 drag_type = -1;
  1794.                                 ext_img_cnt++;
  1795.                             }
  1796.                             else
  1797.                             {
  1798.                                 if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  1799.                                 /*
  1800.                                 draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\n\
  1801.                                 */
  1802.                                 string_length = snprintf(NULL,0,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7]);
  1803.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1804.                                 snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7]);
  1805.                             }
  1806.                             add_to_buffer(tmp_buffer);
  1807.                             break;
  1808.                     default: break;
  1809.                 }
  1810.             }
  1811.             reset();
  1812.             break;
  1813. /*
  1814. context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  1815. img     Specifies the image, canvas, or video element to use
  1816. sx      The x coordinate where to start clipping : x1 = int_data[0]
  1817. sy      The y coordinate where to start clipping : x2 = int_data[1]
  1818. swidth  The width of the clipped image : int_data[2] - int_data[0]
  1819. sheight The height of the clipped image : int_data[3] - int_data[1]
  1820. x       The x coordinate where to place the image on the canvas : dx1 = int_data[4]
  1821. y       The y coordinate where to place the image on the canvas : dy1 = int_data[5]
  1822. width   The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6]
  1823. height  The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7]
  1824. */
  1825.         case COPYRESIZED:
  1826.         /*
  1827.         @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
  1828.         @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [ filename], <br />possibly resized,<br />to the region of (dx1,dy1) to (dx2,dy2) in x/y-range
  1829.         @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
  1830.         @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
  1831.         @ if command 'drag x/y/xy' is set before command 'copy', the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valuid for the next image<br />draggable / non-draggable images may be mixed
  1832.         @ if you want to draw / userdraw  on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent
  1833.         */
  1834.             for(i = 0 ; i<9;i++){
  1835.                 switch(i){
  1836.                     case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
  1837.                     case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
  1838.                     case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
  1839.                     case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
  1840.                     case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
  1841.                     case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
  1842.                     case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
  1843.                     case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
  1844.                     case 8: URL = get_string(infile,1);
  1845.                             if( drag_type > -1 ){
  1846.                                 if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
  1847.                                 if(reply_format < 1 ){reply_format = 20;}
  1848.                                 string_length = snprintf(NULL,0,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,1);
  1849.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1850.                                 snprintf(tmp_buffer,string_length,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,1);
  1851.                                 drag_type = -1;
  1852.                                 ext_img_cnt++;
  1853.                             }
  1854.                             else
  1855.                             {
  1856.                                 if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  1857.                                 string_length = snprintf(NULL,0,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7]);
  1858.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1859.                                 snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7]);
  1860.                             }
  1861.                             add_to_buffer(tmp_buffer);
  1862.                     default: break;
  1863.                 }
  1864.             }
  1865.             reset();
  1866.             break;
  1867.         case BUTTON:
  1868.         /*
  1869.          button x,y,value
  1870.         */
  1871.         break;
  1872.         case INPUTSTYLE:
  1873.         /*
  1874.         @ inputstyle style_description
  1875.         @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt
  1876.         */
  1877.             input_style = get_string(infile,1);
  1878.             break;
  1879.         case INPUT:
  1880.         /*
  1881.          @ input x,y,size,editable,value
  1882.          @ to set inputfield "readonly", use editable = 0
  1883.          @ only active inputfields (editable = 1) will be read with read_canvas();
  1884.          @ may be further controlled by "inputstyle" (inputcss is not yet implemented...)
  1885.          @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
  1886.         */
  1887.         if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}    
  1888.             for(i = 0 ; i<5;i++){
  1889.                 switch(i){
  1890.                     case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
  1891.                     case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
  1892.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
  1893.                     case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
  1894.                     case 4:
  1895.                             temp = get_string_argument(infile,1);
  1896.                             string_length = snprintf(NULL,0,  "draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp);
  1897.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1898.                             snprintf(tmp_buffer,string_length,"draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp);
  1899.                             add_to_buffer(tmp_buffer);
  1900.                             input_cnt++;break;
  1901.                     default: break;
  1902.                 }
  1903.             }
  1904.             if(reply_format < 1 ){reply_format = 15;}
  1905.             reset();
  1906.             break;
  1907.         case TEXTAREA:
  1908.         /*
  1909.          @ textarea x,y,cols,rows,readonly,value
  1910.          @ may be further controlled by "inputstyle"
  1911.          @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
  1912.         */
  1913.             if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}  
  1914.             for(i = 0 ; i<6;i++){
  1915.                 switch(i){
  1916.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
  1917.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
  1918.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
  1919.                     case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
  1920.                     case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
  1921.                     case 5: temp = get_string_argument(infile,1);
  1922.                             string_length = snprintf(NULL,0,  "draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],input_style,temp);
  1923.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1924.                             snprintf(tmp_buffer,string_length,"draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],input_style,temp);
  1925.                             add_to_buffer(tmp_buffer);
  1926.                             input_cnt++;break;
  1927.                     default: break;
  1928.                 }
  1929.             }
  1930.             if(reply_format < 1 ){reply_format = 15;}
  1931.             reset();
  1932.             break;
  1933.         case MOUSE_PRECISION:
  1934.         /*
  1935.             @ precision int
  1936.             @ 10 = 1 decimal ; 100 = 2 decimals etc
  1937.             @ may be used / changed before every object
  1938.         */
  1939.             precision = (int) (get_real(infile,1));
  1940.             break;
  1941.         case ZOOM:
  1942.         /*
  1943.          @ zoom button_color
  1944.          @ introduce a controlpanel at the lower right corner
  1945.          @ giving six 15x15pixel 'active' rectangle areas<br />(for x,leftarrow,rightarrow,uparrow,downarrow and a '-' and a '+' sign ) for zooming and/or panning of the image
  1946.          @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings.
  1947.          @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible
  1948.          @ command 'opacity' may be used to set stroke_opacity of 'buttons
  1949.          @ NOTE: only objects that may be set draggable / clickable will be zoomed / panned
  1950.          @ NOTE: when an object is dragged, zooming / panning will cause the coordinates to be reset to the original position :( <br />e.g. dragging / panning will get lost. (array with 'drag data' is erased)<br />This is a design flaw and not a feature !!
  1951.         */
  1952.             fprintf(js_include_file,"use_pan_and_zoom = 1;");
  1953.             if( js_function[DRAW_ZOOM_BUTTONS] != 1 ){ js_function[DRAW_ZOOM_BUTTONS] = 1;}
  1954.             /* we use BG_CANVAS (0) */
  1955.             stroke_color = get_color(infile,1);
  1956.             string_length = snprintf(NULL,0," draw_zoom_buttons(%d,\"%s\",%f);",BG_CANVAS,stroke_color,stroke_opacity);
  1957.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1958.             snprintf(tmp_buffer,MAX_BUFFER-1,"draw_zoom_buttons(%d,\"%s\",%f);",BG_CANVAS,stroke_color,stroke_opacity);
  1959.             add_to_buffer(tmp_buffer);
  1960.             done = TRUE;
  1961.             break;
  1962.         case ONCLICK:
  1963.         /*
  1964.          @ onclick
  1965.          @ keyword, no arguments
  1966.          @ if the next object is clicked, it's 'object sequence number' in fly script is returned <br /> by javascript:read_canvas();
  1967.          @ Line based object will show an increase in linewidth<br />Font based objects will show the text in 'bold' when clicked.
  1968.          @ NOTE: not all objects  may be set clickable
  1969.         */
  1970.            
  1971.             onclick = 1;
  1972.             break;
  1973.         case DRAG:
  1974.         /*
  1975.          @ drag [x][y][xy]
  1976.          @ the next object will be draggable in x / y / xy direction
  1977.          @ the displacement can be read by 'javascript:read_dragdrop();'
  1978.          @ in case of external images (commands copy / copyresized) the external image can be set draggable ; always xy. <br />The function javascript;read_canvas() will return the xy-coordinates of all images.
  1979.          @ NOTE: in case an object is dragged , zooming or panning will cause the coordinates to be reset to the original position :( <br />e.g. dragging / panning will get lost. (array with 'drag data' is erased)<br />This is a design flaw and not a feature !!
  1980.         */
  1981.             temp = get_string(infile,1);
  1982.             if(strstr(temp,"xy") != NULL ){
  1983.                 drag_type = 0;
  1984.             }
  1985.             else
  1986.             {
  1987.                 if(strstr(temp,"x") != NULL ){
  1988.                     drag_type = 1;
  1989.                 }
  1990.                 else
  1991.                 {
  1992.                     drag_type = 2;
  1993.                 }
  1994.             }
  1995.             onclick = 2;
  1996.             /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
  1997.             break;
  1998.         case BLINK:
  1999.         /*
  2000.          @ blink time(seconds)
  2001.          @ NOT IMPLEMETED -YET
  2002.         */
  2003.             break;
  2004.         case MOUSE:
  2005.         /*
  2006.          @ mouse color,fontsize
  2007.          @ will display the cursor coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
  2008.         */
  2009.             use_mouse_coordinates = TRUE; /* will add & call function "use_mouse_coordinates(){}" in current_canvas /current_context */
  2010.             stroke_color = get_color(infile,0);
  2011.             font_size = (int) (get_real(infile,1));
  2012.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity);
  2013.             break;
  2014.         case INTOOLTIP:
  2015.             /*
  2016.             @ intooltip link_text
  2017.             @ link_text is a single line (span-element)
  2018.             @ link_text may also be an image URL http://some_server/images/my_image.png
  2019.             @ link_text may contain HTML markup
  2020.             @ the canvas will be displayed in a tooltip on 'link_text'
  2021.             @ the canvas is default transparent: use command 'bgcolor color' to adjust background-color<br />the link test will alos be shown with this bgcolor.
  2022.             */
  2023.             if(use_input_xy == TRUE){canvas_error("intooltip can not be combined with userinput_xy command");}
  2024.             use_tooltip = TRUE;
  2025.             tooltip_text = get_string(infile,1);
  2026.             if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
  2027.             break;
  2028.         case AUDIO:
  2029.         /*
  2030.         @ audio x,y,w,h,loop,visible,audiofile location
  2031.         @ x,y : left top corner of audio element (in xrange / yrange)
  2032.         @ w,y : width and height in pixels
  2033.         @ loop : 0 or 1 ( 1 = loop audio fragment)
  2034.         @ visible : 0 or 1 (1 = show controls)
  2035.         @ audio format may be in *.mp3 or *.ogg
  2036.         @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format)
  2037.         @ if you are using *.ogg : be aware that Microsoft based systems not support it natively
  2038.         @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
  2039.         @ example: upload both audio1.ogg and audio1.mp3 to http://server/files/<br />audio 0,0,http://server/files/audio1.mp3<br />svdraw will copy html-tag audio1.mp3 to audio1.ogg<br /> and the browser will play the compatible file (audio1.ogg or audio1.mp3)<br />
  2040.         */
  2041.             if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
  2042.             for(i=0;i<7;i++){
  2043.                 switch(i){
  2044.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  2045.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  2046.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  2047.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  2048.                     case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
  2049.                     case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
  2050.                     case 6:
  2051.                     temp = get_string(infile,1);
  2052.                     if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
  2053.                     if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
  2054.                     string_length = snprintf(NULL,0,  "draw_audio(%d,%d,%d,%d,%d,%d,%d,\"%s.ogg\",\"%s.mp3\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],temp,temp);
  2055.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2056.                     snprintf(tmp_buffer,string_length,"draw_audio(%d,%d,%d,%d,%d,%d,%d,\"%s.ogg\",\"%s.mp3\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],temp,temp);
  2057.                     add_to_buffer(tmp_buffer);
  2058.                     break;
  2059.                     default:break;
  2060.                 }
  2061.             }
  2062.             reset();
  2063.             break;
  2064.         case VIDEO:
  2065.         /*
  2066.         @ video x,y,w,h,videofile location
  2067.         @ x,y : left top corner of audio element (in xrange / yrange)
  2068.         @ w,y : width and height in pixels
  2069.         @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4
  2070.         @ video format may be in *.mp4 (todo:other formats)
  2071.         */
  2072.             if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
  2073.             for(i=0;i<5;i++){
  2074.                 switch(i){
  2075.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  2076.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  2077.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  2078.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  2079.                     case 4: temp = get_string(infile,1);
  2080.                             string_length = snprintf(NULL,0,  "draw_video(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp);
  2081.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2082.                             snprintf(tmp_buffer,string_length,"draw_video(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp);
  2083.                             add_to_buffer(tmp_buffer);
  2084.                             break;
  2085.                     default:break;
  2086.                 }
  2087.             }
  2088.             reset();
  2089.             break;
  2090.         case HATCHFILL:
  2091.         /*
  2092.         @ hatchfill x0,y0,dx,dy,color
  2093.         @ x0,y0 in xrange / yrange
  2094.         @ distances dx,dy in pixels
  2095.         */
  2096.             if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
  2097.             for(i=0;i<5;i++){
  2098.                 switch(i){
  2099.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2100.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2101.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2102.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2103.                     case 4: stroke_color = get_color(infile,1);
  2104.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2105.                     string_length = snprintf(NULL,0,  "draw_hatchfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  2106.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2107.                     snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  2108.                     add_to_buffer(tmp_buffer);
  2109.                     break;
  2110.                     default:break;
  2111.                 }
  2112.             }
  2113.             reset();
  2114.         break;
  2115.         case DIAMONDFILL:
  2116.         /*
  2117.         @ diamondfill x0,y0,dx,dy,color
  2118.         @ x0,y0 in xrange / yrange
  2119.         @ distances dx,dy in pixels
  2120.         */
  2121.             if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
  2122.             for(i=0;i<5;i++){
  2123.                 switch(i){
  2124.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2125.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2126.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2127.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2128.                     case 4: stroke_color = get_color(infile,1);
  2129.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2130.                     string_length = snprintf(NULL,0,  "draw_diamondfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  2131.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2132.                     snprintf(tmp_buffer,string_length,"draw_diamondfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  2133.                     add_to_buffer(tmp_buffer);
  2134.                     break;
  2135.                     default:break;
  2136.                 }
  2137.             }
  2138.             reset();
  2139.         break;
  2140.         case GRIDFILL:
  2141.         /*
  2142.         @ gridfill x0,y0,dx,dy,color
  2143.         @ x0,y0 in xrange / yrange
  2144.         @ distances dx,dy in pixels
  2145.         */
  2146.             if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
  2147.             for(i=0;i<5;i++){
  2148.                 switch(i){
  2149.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2150.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2151.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2152.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2153.                     case 4: stroke_color = get_color(infile,1);
  2154.                     /* draw_gridfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2155.                     string_length = snprintf(NULL,0,  "draw_gridfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  2156.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2157.                     snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  2158.                     add_to_buffer(tmp_buffer);
  2159.                     break;
  2160.                     default:break;
  2161.                 }
  2162.             }
  2163.             reset();
  2164.         break;
  2165.         case DOTFILL:
  2166.         /*
  2167.         @ dotfill x0,y0,dx,dy,color
  2168.         @ x0,y0 in xrange / yrange
  2169.         @ distances dx,dy in pixels
  2170.         @ radius of dots is linewidth
  2171.         */
  2172.             if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
  2173.             for(i=0;i<5;i++){
  2174.                 switch(i){
  2175.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2176.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2177.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2178.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2179.                     case 4: stroke_color = get_color(infile,1);
  2180.                     /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
  2181.                     string_length = snprintf(NULL,0,  "draw_dotfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  2182.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2183.                     snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  2184.                     add_to_buffer(tmp_buffer);
  2185.                     break;
  2186.                     default:break;
  2187.                 }
  2188.             }
  2189.             reset();
  2190.         break;
  2191.         case IMAGEFILL:
  2192.         /*
  2193.         @ imagefill dx,dy,image_url
  2194.         @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
  2195.         @ After pattern filling ,the fill-color should be reset !
  2196.         @ wims getins / image from class directory : imagefill 80,80,my_image.gif
  2197.         @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif
  2198.         @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg
  2199.         @ if dx,dy is larger than the image, the whole image will be background to the next object.
  2200.         */
  2201.             if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
  2202.             for(i=0 ;i < 3 ; i++){
  2203.                 switch(i){
  2204.                     case 0:int_data[0] = (int) (get_real(infile,0));break;
  2205.                     case 1:int_data[1] = (int) (get_real(infile,0));break;
  2206.                     case 2: URL = get_string_argument(infile,1);
  2207.                             string_length = snprintf(NULL,0,  "draw_imagefill(%d,%d,%d,\"%s\",%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],URL,xsize,ysize);
  2208.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2209.                             snprintf(tmp_buffer,string_length,"draw_imagefill(%d,%d,%d,\"%s\",%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],URL,xsize,ysize);
  2210.                             add_to_buffer(tmp_buffer);
  2211.                     break;
  2212.                 }
  2213.             }
  2214.         break;
  2215.         case FILLTOBORDER:
  2216.         /*
  2217.         @ filltoborder x,y,bordercolor,color
  2218.         @ fill the region  of point (x:y) bounded by 'bordercolor' with color 'color'
  2219.         @ any other color will not act as border to the bucket fill
  2220.         @ use this command  after all boundary objects are declared.
  2221.         @ NOTE: filltoborder is a very (client) cpu intensive operation!<br />filling is done pixel by pixel<br/>e.g. image size of 400x400 uses 160000 pixels : each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU..
  2222.         */
  2223.             for(i=0 ;i < 4 ; i++){
  2224.                 switch(i){
  2225.                     case 0:double_data[0] = get_real(infile,0);break;
  2226.                     case 1:double_data[1] = get_real(infile,0);break;
  2227.                     case 2:bgcolor = get_color(infile,0);break;
  2228.                     case 3:fill_color = get_color(infile,1);
  2229.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2230.                                 js_function[DRAW_FILLTOBORDER] = 1;
  2231.                                 add_js_filltoborder(js_include_file,canvas_root_id);
  2232.                            }
  2233.                            decimals = find_number_of_digits(precision);
  2234.                            string_length = snprintf(NULL,0,  "filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215));
  2235.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2236.                            snprintf(tmp_buffer,string_length,"filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215));
  2237.                            add_to_buffer(tmp_buffer);
  2238.                            break;
  2239.                     default:break;
  2240.                     }
  2241.                 }
  2242.         break;
  2243.         case FLOODFILL:
  2244.         /*
  2245.         @ floodfill x,y,color
  2246.         @ alternative syntax: fill x,y,color
  2247.         @ fill the region of point (x:y) with color 'color'
  2248.         @ any other color or size of picture (borders of picture) will act as border to the bucket fill
  2249.         @ use this command  after all boundary objects are declared.
  2250.         @ Use command 'clickfill,color' for user click driven flood fill.
  2251.         @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
  2252.         @ NOTE: floodfill is a very (client) cpu intensive operation!<br />filling is done pixel by pixel<br/>e.g. image size of 400x400 uses 160000 pixels : each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU..
  2253.         */
  2254.             for(i=0 ;i < 4 ; i++){
  2255.                 switch(i){
  2256.                     case 0:double_data[0] = get_real(infile,0);break;
  2257.                     case 1:double_data[1] = get_real(infile,0);break;
  2258.                     case 2:fill_color = get_color(infile,1);
  2259.                            if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
  2260.                                 js_function[DRAW_FLOODFILL] = 1;
  2261.                                 add_js_floodfill(js_include_file,canvas_root_id);
  2262.                            }
  2263.                            decimals = find_number_of_digits(precision);/*floodfill(interaction,x,y,[R,G,B,A]) */
  2264.                            string_length = snprintf(NULL,0,  "floodfill(0,%.*f,%.*f,[%s,%d]);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215));
  2265.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2266.                            snprintf(tmp_buffer,string_length,"floodfill(0,%.*f,%.*f,[%s,%d]);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215));
  2267.                            add_to_buffer(tmp_buffer);
  2268.                            break;
  2269.                     default:break;
  2270.                     }
  2271.                 }
  2272.         break;
  2273.         case CLICKFILLMARGE:
  2274.             clickfillmarge = (int) (get_real(infile,1));
  2275.             break;
  2276.         /*
  2277.         @ clickfillmarge int
  2278.         @ default 20 (pixels)
  2279.         @ when using command "clickfill fillcolor" a coloured area my be reverted ("undo") <br />back to background colour with a middle mouse click<br />when the click is in a 40x40 rectangle around a stored m mouseclick (userdraw_x[] and userdraw_y[])
  2280.         */
  2281.         case CLICKFILL:
  2282.         /*
  2283.         @ clickfill fillcolor
  2284.         @ user left mouse click will floodfill the area with fillcolor
  2285.         @ multiple areas may be coloured
  2286.         @ the coloured areas can be removed (changed to "bgcolor") by  middle / right mouse click <br />(if the click is in an 40x40 pixel area of the click coordinate that "painted" the area)
  2287.         @ the answer will be read as the (x:y) click coordinates per coloured area
  2288.         @ background color of main div may be set by using command "bgcolor color"
  2289.         @ may not be combined with command "userdraw"
  2290.         @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
  2291.         */
  2292.          fill_color = get_color(infile,1);
  2293.          if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
  2294.             js_function[DRAW_FLOODFILL] = 1;
  2295.             add_js_floodfill(js_include_file,canvas_root_id);
  2296.          }
  2297.          fprintf(js_include_file,"\n<!-- begin command clickfill -->\nvar marge_xy = %d;var userdraw_x = new Array();var userdraw_y = new Array();var user_clickfill_cnt = 0;\ncanvas_div.addEventListener(\"mousedown\",clickfill,false);function clickfill(evt){var x = evt.clientX - findPosX(canvas_div) + document.body.scrollLeft + document.documentElement.scrollLeft;var y = evt.clientY - findPosY(canvas_div) + document.body.scrollTop + document.documentElement.scrollTop;if(evt.which != 1){for(var p=0; p < user_clickfill_cnt;p++){if(userdraw_x[p] + marge_xy > x && userdraw_x[p] - marge_xy < x){if(userdraw_y[p] + marge_xy > y && userdraw_y[p] - marge_xy < y){if(confirm(\"Clear ?\")){floodfill(1,userdraw_x[p],userdraw_y[p],canvas_div.style.backgroundColor);userdraw_x.splice(p,2);userdraw_y.splice(p,2);user_clickfill_cnt--;return;};};};};};userdraw_x[user_clickfill_cnt] = x;userdraw_y[user_clickfill_cnt] = y;user_clickfill_cnt++;floodfill(1,x,y,[%s,%d]);};",clickfillmarge,fill_color,(int) (fill_opacity/0.0039215));
  2298.          add_read_canvas(1);
  2299.         break;
  2300.         case SETPIXEL:
  2301.         /*
  2302.         @ setpixel x,y,color
  2303.         @ A "point" with diameter 1 pixel centeres at (x:y) in xrange / yrange
  2304.         @ pixels can not be dragged or clicked
  2305.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  2306.         */
  2307.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  2308.             for(i=0;i<3;i++){
  2309.                 switch(i){
  2310.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  2311.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  2312.                     case 2: stroke_color = get_color(infile,1);
  2313.                            string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  2314.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2315.                            snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  2316.                            add_to_buffer(tmp_buffer);
  2317.                            break;
  2318.                     default:break;
  2319.                 }
  2320.             }
  2321.             reset();
  2322.         break;
  2323.         case PIXELSIZE:
  2324.         /*
  2325.         @ pixelsize int
  2326.         @ in case you want to deviate from default pixelsize = 1...
  2327.         */
  2328.             pixelsize = (int) get_real(infile,1);
  2329.         break;
  2330.         case PIXELS:
  2331.         /*
  2332.         @ pixels color,x1,y1,x2,y2,x3,y3...
  2333.         @ Draw  "points" with diameter 1 pixel
  2334.         @ pixels can not be dragged or clicked
  2335.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  2336.         */
  2337.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  2338.             stroke_color=get_color(infile,0);
  2339.             i=0;
  2340.             c=0;
  2341.             while( ! done ){     /* get next item until EOL*/
  2342.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  2343.                 for( c = 0 ; c < 2; c++){
  2344.                     if(c == 0 ){
  2345.                         double_data[i] = get_real(infile,0);
  2346.                         i++;
  2347.                     }
  2348.                     else
  2349.                     {
  2350.                         double_data[i] = get_real(infile,1);
  2351.                         i++;
  2352.                     }
  2353.                 }
  2354.             }
  2355.             decimals = find_number_of_digits(precision);
  2356.             /*  *double_xy2js_array(double xy[],int len,int decimals) */
  2357.             string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  2358.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2359.             snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  2360.             add_to_buffer(tmp_buffer);
  2361.             break;
  2362.         case REPLYFORMAT:
  2363.         /*
  2364.         @ replyformat number
  2365.         @ default values should be fine !
  2366.         @ choose<ul><li>1 = x1,x2,x3,x4....x_n<br />y1,y2,y3,y4....y_n<br /><br />x/y in pixels</li><li>2 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br /> x/y in xrange / yrange coordinate system<br /></li><li>3 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br />  r1,r2,r3,r4....r_n<br />  x/y in pixels <br />  r in pixels</li><li>4 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br />  r1,r2,r3,r4....r_n<br />  x/y in xrange / yrange coordinate system<br />  r in pixels</li><li>5 = Ax1,Ax2,Ax3,Ax4....Ax_n<br />  Ay1,Ay2,Ay3,Ay4....Ay_n<br />  Bx1,Bx2,Bx3,Bx4....Bx_n<br />  By1,By2,By3,By4....By_n<br />  Cx1,Cx2,Cx3,Cx4....Cx_n<br />  Cy1,Cy2,Cy3,Cy4....Cy_n<br />  ....<br />  Zx1,Zx2,Zx3,Zx4....Zx_n<br />  Zy1,Zy2,Zy3,Zy4....Zy_n<br />  x/y in pixels<br /></li><li>6 = Ax1,Ax2,Ax3,Ax4....Ax_n<br />  Ay1,Ay2,Ay3,Ay4....Ay_n<br />  Bx1,Bx2,Bx3,Bx4....Bx_n<br />  By1,By2,By3,By4....By_n<br />  Cx1,Cx2,Cx3,Cx4....Cx_n<br />  Cy1,Cy2,Cy3,Cy4....Cy_n<br />  ....<br />  Zx1,Zx2,Zx3,Zx4....Zx_n<br />  Zy1,Zy2,Zy3,Zy4....Zy_n<br />  x/y in xrange / yrange coordinate system<br /></li><li>7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br />  x/y in pixels</li><li>8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br />  x/y in xrange / yrange coordinate system</li><li>9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br />  x/y in pixels</li><li>10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br />  x/y in xrange / yrange coordinate system</li><li>11 = Ax1,Ay1,Ax2,Ay2<br />   Bx1,By1,Bx2,By2<br />   Cx1,Cy1,Cx2,Cy2<br />   Dx1,Dy1,Dx2,Dy2<br />   ......<br />   Zx1,Zy1,Zx2,Zy2<br />  x/y in xrange / yrange coordinate system</li><li>12 = Ax1,Ay1,Ax2,Ay2<br />   Bx1,By1,Bx2,By2<br />Cx1,Cy1,Cx2,Cy2<br />   Dx1,Dy1,Dx2,Dy2<br />   ......<br />   Zx1,Zy1,Zx2,Zy2<br />  x/y in pixels</li><li>13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2<br />  x/y in xrange / yrange coordinate system</li><li>14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2<br />  x/y in pixels</li><li>15 = reply from inputfields,textareas<br />  reply1,reply2,reply3,...,reply_n</li><li>16 = mathml input fields </li><li>17 = read "userdraw text,color" only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n</li><li>18 = read_canvas() will read all interactive clocks in H1:M1:S1,H2:M2:S2...Hn:Mn:Sn</li><li>19 = read_canvas() will return the object number of marked / clicked object (clock)<br />analogue to (shape library) onclick command </li><li>21 = (x1:y1) (x2:y2) ... (x_n:y_n)<br />verbatim coordinate return</li>22 = returns an array .... reply[0]=x1 reply[1]=y1 reply[2]=x2 reply[3]=y2 ... reply[n-1]=x_n reply[n]=y_n<br />  x/y in xrange / yrange coordinate system</li><li>replyformat 23 : can only be used for drawtype 'polyline'<br />a typical click sequence in drawtype polyline isx1,y1,x2,y2,x2,y2,x3,y3,x3,y3.....,x(n-1),y(n-1),x(n-1),y(n-1),xn,yn --replyformat 23--> x1,y1,x2,y2,x3,y3,.....x(n-1),y(n-1),xn,yn multiple occurences will be filtered out.The reply will be in x-y-range (xreply \\n yreply)</li></ul>
  2367.         @ note to 'userdraw text,color' : the x / y-values are in pixels ! (this to avoid too lengthy calculations in javascript...)
  2368.         */
  2369.          reply_format = (int) get_real(infile,1);
  2370.         break;
  2371.         case LEGENDCOLORS:
  2372.         /*
  2373.         @ legendcolors color1:color2:color3:...:color_n
  2374.         @ will be used to colour a legend
  2375.         @ make sure the number of colours match the number of legend items
  2376.         @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
  2377.         */
  2378.             temp = get_string(infile,1);
  2379.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2380.             fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",canvas_root_id,temp);
  2381.             break;
  2382.         case LEGEND:
  2383.         /*
  2384.         @ legend string1:string2:string3....string_n
  2385.         @ will be used to create a legend for a graph
  2386.         @ also see command 'piechart'  
  2387.         */
  2388.             temp = get_string(infile,1);
  2389.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2390.             fprintf(js_include_file,"var legend%d = [\"%s\"];",canvas_root_id,temp);
  2391.             break;
  2392.         case XLABEL:
  2393.         /*
  2394.         @ xlabel some_string
  2395.         @ will be used to create a label for the x-axis (label is in quadrant I)
  2396.         @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
  2397.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
  2398.         */
  2399.             temp = get_string(infile,1);
  2400.             fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
  2401.             break;
  2402.         case YLABEL:
  2403.         /*
  2404.         @ ylabel some_string
  2405.         @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
  2406.         @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
  2407.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
  2408.         */
  2409.             temp = get_string(infile,1);
  2410.             fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
  2411.             break;
  2412.         case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
  2413.         /*
  2414.         @ linegraph x1:y1;x2:y2...x_n:y;2
  2415.         @ will plot your data in a graph
  2416.         @ may only to be used together with command 'grid'
  2417.         @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
  2418.         @ use command 'legend' to provide an optional legend in right-top-corner
  2419.         @ also see command 'piechart'
  2420.         @ multiple linegraphs may be used in a single plot
  2421.         @ <ul><li>use command 'strokecolor' before command 'linegraph' to set the color of this graph</li><li>use command 'linewidth' before command 'linegraph' to set linewidth of this graph</li><li>use command 'dashed' before command 'linegraph' to set dashing of the graph</li><li>if dashing is set, use command 'dashtype' before command 'linegraph' to set the type of dashing of the graph</li></ul>
  2422.         */    
  2423.             temp = get_string(infile,1);
  2424.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2425.             fprintf(js_include_file,"var linegraph_%d = [\"%s\",\"%d\",\"%d\",\"%d\",\"%d\",\"%s\"];",linegraph_cnt,stroke_color,line_width,use_dashed,dashtype[0],dashtype[1],temp);
  2426.             linegraph_cnt++;
  2427.             reset();
  2428.             break;
  2429.         case CLOCK:
  2430.         /*
  2431.         @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
  2432.         @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments
  2433.         @ colors are optional: if not defined, default values will be used<br />default colours: clock 0,0,60,4,35,45,1,2,[space]<br />default colours: clock 0,0,60,4,35,45,1,2,,,,,<br />custom colours: clock 0,0,60,4,35,45,1,2,,,,yellow,red<br />custom colours: clock 0,0,60,4,35,45,1,2,white,white,white,black,yellow
  2434.         @ interactive <ul><li>0 : not interactive, just clock(s)</li><li>1 : function read_canvas() will read all active clocks in H:M:S format<br />The active clock(s) can be adjusted by pupils</li><li>2 : function read_canvas() will return the clicked clock <br />(like multiplechoice; first clock in script in nr. 0 )</li></ul>
  2435.         @ canvasdraw will not check validity of colornames...the javascript console is your best friend
  2436.         @ no combinations with other reply_types allowed, for now
  2437.         @ if interactive, 6 buttons per clock will be displayed for adjusting a clock (H+ M+ S+ H- M- S-)<br /> set_clock(clock_id,type,incr) <br />first clock has clock_id=0 ; type : H=1,M=2,S=3 ; incr : increment integer
  2438.         */
  2439.             if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
  2440.  
  2441.         /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
  2442.             for(i=0;i<9;i++){
  2443.              switch(i){
  2444.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
  2445.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
  2446.               case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
  2447.               case 3: int_data[3] = get_real(infile,0);break;/* hours */
  2448.               case 4: int_data[4] = get_real(infile,0);break;/* minutes */
  2449.               case 5: int_data[5] = get_real(infile,0);break;/* seconds */
  2450.               case 6: int_data[6] = get_real(infile,0);if(int_data[6] < 0 || int_data[6] > 2){canvas_error("hourglass can be 0,1 or 2");}break;/* type hourglass */
  2451.               case 7: int_data[7] = (int)(get_real(infile,0));/* interactive 0,1,2*/
  2452.                 switch(int_data[7]){
  2453.                     case 0:break;
  2454.                     case 1:if(clock_cnt == 0){
  2455.                                 if( reply_format == 0 ){
  2456.                                      reply_format = 18; /* user sets clock */
  2457.                                     /* string_length = snprintf(NULL,0,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n");
  2458.                                      check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2459.                                      snprintf(tmp_buffer,string_length,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n");
  2460.                                      add_to_buffer(tmp_buffer);
  2461.                                     */
  2462.                                      fprintf(js_include_file,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n");
  2463.                                 }
  2464.                                 else
  2465.                                 {
  2466.                                     canvas_error("interactive clock may not be used together with other reply_types...");
  2467.                                 }
  2468.                                 fprintf(stdout,"<br /><input type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H-\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M-\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S-\" /><br />",clock_cnt,clock_cnt,clock_cnt,clock_cnt,clock_cnt,clock_cnt);
  2469.                              }
  2470.                     break;
  2471.                     case 2:if( reply_format == 0 ){
  2472.                                 reply_format = 19; /* "onclick */
  2473.                                 fprintf(js_include_file,"\n<!-- begin onclick handler for clocks -->\nvar reply = new Array();\n\ncanvas_div.addEventListener( 'mousedown', user_click,false);\n\nfunction user_click(evt){if(evt.which == 1){var canvas_rect = clock_canvas.getBoundingClientRect();\nvar x = evt.clientX - canvas_rect.left;\nvar y = evt.clientY - canvas_rect.top;\nvar p = 0;\nvar name;\nvar t = true;\nwhile(t){try{name = eval('clocks'+p);\nif( x < name.xc + name.radius && x > name.xc - name.radius ){if( y < name.yc + name.radius && y > name.yc - name.radius ){reply[0] = p;\nname = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,\"lightblue\",name.fg_color);\n};\n}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);\nname = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);\n};\np++;\n}catch(e){t=false;\n};\n};\n};\n};\n\n<!-- end onclick handler for clocks -->\n ");
  2474.                             }
  2475.                             else
  2476.                             {
  2477.                                 if( reply_format != 19){
  2478.                                    canvas_error("clickable clock(s) may not be used together with other reply_types...");
  2479.                                  }
  2480.                             }
  2481.                      break;
  2482.                      default: canvas_error("interactive must be set 0,1 or 2");break;
  2483.                 }
  2484.                 break;
  2485.                 case 8:
  2486.                         temp = get_string(infile,1);
  2487.                         if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
  2488.                         if( strlen(temp) < 1 ){temp = ",\"\",\"\",\"\",\"\",\"\"";}
  2489.                         string_length = snprintf(NULL,0,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp);
  2490.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2491.                         snprintf(tmp_buffer,string_length,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp);
  2492.                         add_to_buffer(tmp_buffer);
  2493.                         clock_cnt++;
  2494.                         break;
  2495.                 default:break;
  2496.              }
  2497.             }
  2498.             break;
  2499.         case BARCHART:
  2500.         /*
  2501.         @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
  2502.         @ will be used to create a legend for bar graph
  2503.         @ may only to be used together with command 'grid'
  2504.         @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
  2505.         @ use command 'legend' to provide an optional legend in right-top-corner
  2506.         @ also see command 'piechart'  
  2507.         */
  2508.             temp = get_string(infile,1);
  2509.             if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
  2510.             fprintf(js_include_file,"var barchart%d = [\"%s\"];",canvas_root_id,temp);
  2511.             reset();
  2512.             break;
  2513.         case PIECHART:
  2514.         /*
  2515.         @ piechart xc,yc,radius,'data+colorlist'
  2516.         @ (xc : yc) center of circle diagram in xrange/yrange
  2517.         @ radius in pixels
  2518.         @ data+color list: a colon separated list of raw data and corresponding colours<br />canvasdraw will not check validity of colornames...<br />in case of trouble look into javascript debugging of your browser
  2519.         @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white
  2520.         @ the number of colors must match the number of data.
  2521.         @ use command "opacity 0-255,0-255" to adjust fill_opacity of colours
  2522.         @ use command "legend string1:string2:...:string_n" to automatically create a legend <br />using the same colours as pie segments<br />unicode allowed in legend<br />expect javascript trouble if the amount of 'pie-slices', 'pie-colours' 'pie-legend-titles' do not match<br />a javascript console is your best friend...
  2523.         */
  2524.             if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}    
  2525.             for(i=0;i<5;i++){
  2526.                 switch(i){
  2527.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2528.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2529.                     case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
  2530.                     case 3: temp = get_string(infile,1);
  2531.                             if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
  2532.                             string_length = snprintf(NULL,0,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\");\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,font_size,font_family);
  2533.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2534.                             snprintf(tmp_buffer,string_length,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\");\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,font_size,font_family);
  2535.                             add_to_buffer(tmp_buffer);
  2536.                            break;
  2537.                     default:break;
  2538.                 }
  2539.             }
  2540.             reset();
  2541.         break;
  2542.         case STATUS:
  2543.             fprintf(js_include_file,"\nstatus=\"waiting\";\n");
  2544.             break;
  2545.         case XLOGBASE:
  2546.         /*
  2547.         @ xlogbase number
  2548.         @ sets the logbase number for the x-axis
  2549.         @ default value 10
  2550.         @ use together with commands xlogscale / xylogscale
  2551.         */
  2552.             fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
  2553.             break;
  2554.         case YLOGBASE:
  2555.         /*
  2556.         @ ylogbase number
  2557.         @ sets the logbase number for the y-axis
  2558.         @ default value 10
  2559.         @ use together with commands ylogscale / xylogscale
  2560.         */
  2561.             fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
  2562.             break;
  2563.         case XLOGSCALE:
  2564.         /*
  2565.          @ xlogscale ymajor,yminor,majorcolor,minorcolor
  2566.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  2567.          @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
  2568.          @ the linewidth is set using command 'linewidth int'
  2569.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  2570.          @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number'
  2571.          @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use command 'precision' before 'xlogscale' command to set the precision (decimals) of the axis numbering</li><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul>
  2572.          @ note: the complete canvas will be used for the 'log paper'
  2573.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  2574.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  2575.          @ note: when using something like 'xrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000')  
  2576.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  2577.          @ attention: keyword 'snaptogrid' may not lead to the desired result...
  2578.         */
  2579.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  2580.             if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
  2581.             for(i=0;i<4;i++){
  2582.                 switch(i){
  2583.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  2584.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  2585.                     case 2: stroke_color = get_color(infile,0); break;
  2586.                     case 3: fill_color = get_color(infile,1);
  2587.                         string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision);
  2588.                         tmp_buffer = my_newmem(string_length+1);
  2589.                         snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision);
  2590.                         fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
  2591.                         add_to_buffer(tmp_buffer);
  2592.                         break;
  2593.                     default:break;
  2594.                 }
  2595.             }
  2596.             break;
  2597.         case YLOGSCALE:
  2598.         /*
  2599.          @ ylogscale xmajor,xminor,majorcolor,minorcolor
  2600.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  2601.          @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
  2602.          @ the linewidth is set using command 'linewidth int'
  2603.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  2604.          @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number'
  2605.          @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use command 'precision' before 'ylogscale' command to set the precision (decimals) of the axis numbering</li><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul>
  2606.          @ note: the complete canvas will be used for the 'log paper'
  2607.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  2608.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  2609.          @ note: when using something like 'yrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000')  
  2610.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  2611.          @ attention: keyword 'snaptogrid' may not lead to the desired result...
  2612.         */
  2613.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  2614.             if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
  2615.             for(i=0;i<4;i++){
  2616.                 switch(i){
  2617.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  2618.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  2619.                     case 2: stroke_color = get_color(infile,0); break;
  2620.                     case 3: fill_color = get_color(infile,1);
  2621.                         string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision);
  2622.                         tmp_buffer = my_newmem(string_length+1);
  2623.                         snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision);
  2624.                         fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
  2625.                         add_to_buffer(tmp_buffer);
  2626.                         break;
  2627.                     default:break;
  2628.                 }
  2629.             }
  2630.             break;
  2631.         case XYLOGSCALE:
  2632.         /*
  2633.          @ xylogscale majorcolor,minorcolor
  2634.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  2635.          @ the linewidth is set using command 'linewidth int'
  2636.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  2637.          @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number'
  2638.          @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul>
  2639.          @ note: the complete canvas will be used for the 'log paper'
  2640.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  2641.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  2642.          @ note: when using something like 'yrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000')  
  2643.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  2644.          @ attention: keyword 'snaptogrid' may not lead to the desired result...
  2645.         */
  2646.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  2647.             if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
  2648.             for(i=0;i<2;i++){
  2649.                 switch(i){
  2650.                     case 0: stroke_color = get_color(infile,0); break;
  2651.                     case 1: fill_color = get_color(infile,1);
  2652.                         string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,precision);
  2653.                         tmp_buffer = my_newmem(string_length+1);
  2654.                         snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,precision);
  2655.                         fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
  2656.                         add_to_buffer(tmp_buffer);
  2657.                         break;
  2658.                     default:break;
  2659.                 }
  2660.             }
  2661.         break;
  2662.         default:sync_input(infile);
  2663.         break;
  2664.     }
  2665.   }
  2666.   /* we are done parsing script file */
  2667.  
  2668.   /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable shapes / objects  ! */
  2669.   add_javascript_functions(js_function,canvas_root_id);
  2670.    /* add read_canvas() etc functions if needed */
  2671.   if( reply_format > 0 ){ add_read_canvas(reply_format);}
  2672.   /* using mouse coordinate display ? */
  2673.   if( use_mouse_coordinates == TRUE ){
  2674.     tmp_buffer = my_newmem(26);
  2675.     snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2676.   }
  2677.   /* add global variables / contants */
  2678.   fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\
  2679.  var precision = %d;var xmin=%f;var xmax=%f;var ymin=%f;\
  2680.  var ymax=%f;var xmin_start=xmin;var xmax_start=xmax;\
  2681.  var ymin_start=ymin;var ymax_start=xmax;\
  2682.  var zoom_x_increment=0;var zoom_y_increment=0;\
  2683.  var pan_x_increment=0;var pan_y_increment=0;\
  2684.  if(use_ylogscale == 0 ){\
  2685.   zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (xmax - xmin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\
  2686.  }else{\
  2687.   zoom_x_increment = (xmax - xmin)/20;\
  2688.   pan_x_increment = (xmax - xmin)/20;\
  2689.  };\
  2690.  function start_canvas%d(type){\
  2691.   switch(type){\
  2692.    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
  2693.    case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\
  2694.    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
  2695.    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
  2696.    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
  2697.    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
  2698.    case 6:location.reload();break;\
  2699.    default:break;\
  2700.   };\
  2701.   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
  2702.   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
  2703.   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){}\
  2704.   %s\
  2705.  };\
  2706.  start_canvas%d(22);\
  2707. };\n\
  2708. <!-- end wims_canvas_function -->\n\
  2709. wims_canvas_function%d();\n",precision,xmin,xmax,ymin,ymax,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
  2710. /* done writing the javascript include file */
  2711. fclose(js_include_file);
  2712.  
  2713. }
  2714.  
  2715. /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
  2716. if(use_tooltip == TRUE){
  2717.   add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
  2718. }
  2719. exit(EXIT_SUCCESS);
  2720. }
  2721. /* end main() */
  2722.  
  2723. /******************************************************************************
  2724. **
  2725. **  sync_input
  2726. **
  2727. **  synchronises input line - reads to end of line, leaving file pointer
  2728. **  at first character of next line.
  2729. **
  2730. **  Used by:
  2731. **  main program - error handling.
  2732. **
  2733. ******************************************************************************/
  2734. void sync_input(FILE *infile)
  2735. {
  2736.         int c = 0;
  2737.  
  2738.         if( c == '\n' || c == ';' ) return;
  2739.         while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
  2740.         if( c == EOF ) finished = 1;
  2741.         if( c == '\n' || c == '\r' || c == ';') line_number++;
  2742.         return;
  2743. }
  2744.  
  2745. /******************************************************************************/
  2746.  
  2747. char *str_replace(const char *str, const char *old, const char *new){
  2748. /* http://creativeandcritical.net/str-replace-c/ */
  2749.     if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
  2750.     char *ret, *r;
  2751.     const char *p, *q;
  2752.     size_t oldlen = strlen(old);
  2753.     size_t count = 0;
  2754.     size_t retlen = 0;
  2755.     size_t newlen = strlen(new);
  2756.     if (oldlen != newlen){
  2757.         for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
  2758.             count++;
  2759.             retlen = p - str + strlen(p) + count * (newlen - oldlen);
  2760.         }
  2761.     }
  2762.     else
  2763.     {
  2764.         retlen = strlen(str);
  2765.     }
  2766.    
  2767.     if ((ret = malloc(retlen + 1)) == NULL){
  2768.         ret = NULL;
  2769.         canvas_error("string argument is NULL");
  2770.     }
  2771.     else
  2772.     {
  2773.         for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
  2774.             size_t l = q - p;
  2775.             memcpy(r, p, l);
  2776.             r += l;
  2777.             memcpy(r, new, newlen);
  2778.             r += newlen;
  2779.         }
  2780.         strcpy(r, p);
  2781.     }
  2782.     return ret;
  2783. }
  2784.  
  2785. /******************************************************************************/
  2786. /*
  2787. avoid the use of ctypes.h for tolower() toupper();
  2788. it gives trouble in FreeBSD 9.0 / 9.1 when used in a chroot environment (C library bug) : Undefined symbol "_ThreadRuneLocale"
  2789. Upper case -> Lower case : c = c - 'A'+ 'a';
  2790. Lower case ->  Upper case  c = c + 'A'  - 'a';
  2791. */
  2792. int tolower(int c){
  2793.  if(c <= 'Z'){
  2794.   if (c >= 'A'){
  2795.    return c - 'A' + 'a';
  2796.   }
  2797.  }
  2798.  return c;
  2799. }
  2800.  
  2801. int toupper(int c){
  2802.  if(c >= 'a' && c <= 'z'){
  2803.    return c + 'A' - 'a';
  2804.  }
  2805.  return c;
  2806. }
  2807.  
  2808. char *get_color(FILE *infile , int last){
  2809.     int c,i = 0,is_hex = 0;
  2810.     char temp[MAX_COLOR_STRING], *string;
  2811.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){
  2812.         if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
  2813.         if( c == '#' ){
  2814.             is_hex = 1;
  2815.         }
  2816.         if( c != ' '){
  2817.             temp[i]=tolower(c);
  2818.             i++;
  2819.         }
  2820.     }
  2821.     if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
  2822.     if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
  2823.     if( c == EOF ){finished = 1;}
  2824.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  2825.     temp[i]='\0';
  2826.     if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
  2827.     if( is_hex == 1 ){
  2828.         char red[3], green[3], blue[3];
  2829.         red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
  2830.         green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
  2831.         blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
  2832.         int r = (int) strtol(red,   NULL, 16);
  2833.         int g = (int) strtol(green, NULL, 16);
  2834.         int b = (int) strtol(blue,  NULL, 16);
  2835.         string = (char *)my_newmem(12);
  2836.         snprintf(string,11,"%d,%d,%d",r,g,b);
  2837.         return string;
  2838.     }
  2839.     else
  2840.     {
  2841.         string = (char *)my_newmem(sizeof(temp));
  2842.         snprintf(string,sizeof(temp),"%s",temp);
  2843.         for( i = 0; i <= NUMBER_OF_COLORNAMES ; i++ ){
  2844.             if( strcmp( colors[i].name , string ) == 0 ){
  2845.                 return colors[i].rgb;
  2846.             }
  2847.         }
  2848.     }
  2849.     /* not found...return error */
  2850.     free(string);string = NULL;
  2851.     canvas_error("I was expecting a color name or hexnumber...but found nothing.");
  2852.     return NULL;
  2853. }
  2854.  
  2855. char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
  2856.     int c,i=0;
  2857.     char  temp[MAX_BUFFER], *string;
  2858.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){
  2859.         temp[i]=c;
  2860.         i++;
  2861.         if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
  2862.     }
  2863.     if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  2864.     if( c == '\n') { done = TRUE; line_number++; }
  2865.     if( c == EOF ) {
  2866.         finished = 1;
  2867.         if( last != 1 ){ canvas_error("expected more arguments");}
  2868.     }
  2869.     temp[i]='\0';
  2870.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");}
  2871.     string=(char *)my_newmem(strlen(temp));
  2872.     snprintf(string,sizeof(temp),"%s",temp);
  2873.     return string;
  2874. }
  2875.  
  2876. char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
  2877.     int c,i=0;
  2878.     char temp[MAX_BUFFER], *string;
  2879.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',')){
  2880.         temp[i]=c;
  2881.         i++;
  2882.         if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
  2883.     }
  2884.     if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
  2885.     if( c == '\n') { line_number++; }
  2886.     if( c == EOF ) {finished = 1;}
  2887.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  2888.     temp[i]='\0';
  2889.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
  2890.     string=(char *)my_newmem(sizeof(temp));
  2891.     snprintf(string,sizeof(temp),"%s",temp);
  2892.     done = TRUE;
  2893.     return string;
  2894. }
  2895.  
  2896. double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
  2897.     int c,i=0,found_calc = 0;
  2898.     double y;
  2899.     char tmp[MAX_INT];
  2900.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){
  2901.      if( c != ' ' ){
  2902.      /*
  2903.      libmatheval will segfault when for example: "xrange -10,+10" or "xrange -10,10+" is used
  2904.      We will check after assert() if it's a NULL pointer...and exit program via :
  2905.      canvas_error("I'm having trouble parsing your \"expression\" ");
  2906.      */
  2907.       if( i == 0 &&  c == '+' ){
  2908.        continue;
  2909.       }
  2910.       else
  2911.       {
  2912.        if(canvas_iscalculation(c) != 0){
  2913.         found_calc = 1;
  2914.         c = tolower(c);
  2915.        }
  2916.        tmp[i] = c;
  2917.        i++;
  2918.       }
  2919.      }
  2920.      if( i > MAX_INT - 1){canvas_error("number too large");}
  2921.     }
  2922.     if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
  2923.     if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
  2924.     if( c == EOF ){done = TRUE ; finished = 1;}
  2925.     tmp[i]='\0';
  2926.     if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
  2927.     if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */
  2928.      void *f = evaluator_create(tmp);
  2929.      assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  2930.      y = evaluator_evaluate_x(f, 1);
  2931.      /* if function is bogus; y = 1 : so no core dumps */
  2932.      evaluator_destroy(f);
  2933.     }
  2934.     else
  2935.     {
  2936.      y = atof(tmp);
  2937.     }
  2938.     return y;
  2939. }
  2940.  
  2941. double get_double(FILE *infile , int orientation , int last){  /* last = 0 : more arguments ; last=1 final argument */
  2942. /* orientation=0 : x-values ...  orientation=1 :y-values */
  2943.     int c;
  2944.     int i = 0;
  2945.     int found_calc = 0; /* signal user input like : 2*pi/3 */
  2946.     char tmp[MAX_INT];
  2947.     double dx;
  2948.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){
  2949.         if( c != ' '){/* no spaces in numbers */
  2950.             if(canvas_iscalculation(c) != 0 ){
  2951.                 found_calc = 1;
  2952.                 c = tolower(c);
  2953.             }
  2954.             tmp[i]=c;
  2955.             i++;
  2956.             if( i > MAX_INT-1){canvas_error("number too large");}
  2957.         }
  2958.     }
  2959.     if( c == '\n' || c == EOF || c == ';' ){
  2960.         if( last == 0 ){canvas_error("expecting more arguments");}
  2961.         if( c == EOF ){finished = TRUE;}
  2962.         done = TRUE;
  2963.         /*return 0; */
  2964.     }
  2965.     tmp[i]='\0';
  2966.    
  2967.     if( strlen(tmp) == 0 || i == 0){
  2968.         if( orientation == 0 ){
  2969.             canvas_error("expected a x-value \n e.g. a number in x-range / y-range coordinate system\nbut found nothing !!");
  2970.         }
  2971.         else
  2972.         {
  2973.             canvas_error("expected a y-value \n e.g. a number in x-range / y-range coordinate system\nbut found nothing !!");
  2974.         }
  2975.     }
  2976.     if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */
  2977.         void *f = evaluator_create(tmp);
  2978.         assert(f);
  2979.         if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ");}
  2980.         dx = evaluator_evaluate_x(f, 1);
  2981.         evaluator_destroy(f);
  2982.     }
  2983.     else
  2984.     {
  2985.         dx = atof(tmp); /* no pi/e/sin(2*pi/3) found : will use atof to convert inputstring  to float */
  2986.     }
  2987.     if( c == '\n' || c == ';') { line_number++; }
  2988.     if( c != EOF ) {
  2989.         if( c == '\n' || c ==';') {
  2990.             done = TRUE;
  2991.         }
  2992.     }
  2993.     else
  2994.     {
  2995.         finished = TRUE;
  2996.     }
  2997.     if( (done == TRUE || finished == TRUE) && last != 1 ){ canvas_error("expected more arguments");}
  2998.     if(orientation == 0){
  2999.         return x2px( dx ); /* convert to pixels according xrange */
  3000.     }
  3001.     else
  3002.     {
  3003.         return y2px( dx );/* convert to pixels according yrange */
  3004.     }
  3005. }
  3006. void canvas_error(char *msg){
  3007.     fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg);
  3008.     finished = 1;
  3009.     exit(EXIT_SUCCESS);
  3010. }
  3011.  
  3012.  
  3013. /* convert x/y coordinates to pixel */
  3014. int x2px(double x){
  3015.  return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
  3016. }
  3017.  
  3018. int y2px(double y){
  3019.  return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
  3020. }
  3021.  
  3022. double px2x(int x){
  3023.  return (x*(xmax - xmin)/xsize + xmin);
  3024. }
  3025. double px2y(int y){
  3026.  return (y*(ymax - ymin)/ysize + ymin);
  3027. }
  3028.  
  3029. void add_to_buffer(char *tmp){
  3030.  if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
  3031.  /*  do we have enough space left in buffer[MAX_BUFFER] ? */
  3032.  int space_left = (int) (sizeof(buffer) - strlen(buffer));
  3033.  if( space_left > strlen(tmp)){
  3034.   strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
  3035.  }
  3036.  else
  3037.  {
  3038.   canvas_error("buffer is too big\n");
  3039.  }
  3040.  tmp = NULL;free(tmp);
  3041.  return;
  3042. }
  3043.  
  3044. void reset(){
  3045.  if(use_filled == TRUE){use_filled = FALSE;}
  3046.  if(use_dashed == TRUE){use_dashed = FALSE;}
  3047.  if(use_translate == TRUE){use_translate = FALSE;}
  3048.  if(use_rotate == TRUE){use_rotate = FALSE;}
  3049.  onclick = 0;
  3050. }
  3051.  
  3052.  
  3053.  
  3054. /* What reply format in read_canvas();
  3055.  
  3056. note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
  3057. 1 = x1,x2,x3,x4....x_n
  3058.     y1,y2,y3,y4....y_n
  3059.  
  3060.     x/y in pixels
  3061.  
  3062. 2 = x1,x2,x3,x4....x_n
  3063.     y1,y2,y3,y4....y_n
  3064.     x/y in  xrange / yrange coordinate system
  3065.  
  3066. 3 = x1,x2,x3,x4....x_n
  3067.     y1,y2,y3,y4....y_n
  3068.     r1,r2,r3,r4....r_n
  3069.  
  3070.     x/y in pixels
  3071.     r in pixels
  3072.  
  3073. 4 = x1,x2,x3,x4....x_n
  3074.     y1,y2,y3,y4....y_n
  3075.     r1,r2,r3,r4....r_n
  3076.  
  3077.     x/y in  xrange / yrange coordinate system
  3078.     r in pixels
  3079.  
  3080. 5 = Ax1,Ax2,Ax3,Ax4....Ax_n
  3081.     Ay1,Ay2,Ay3,Ay4....Ay_n
  3082.     Bx1,Bx2,Bx3,Bx4....Bx_n
  3083.     By1,By2,By3,By4....By_n
  3084.     Cx1,Cx2,Cx3,Cx4....Cx_n
  3085.     Cy1,Cy2,Cy3,Cy4....Cy_n
  3086.     ....
  3087.     Zx1,Zx2,Zx3,Zx4....Zx_n
  3088.     Zy1,Zy2,Zy3,Zy4....Zy_n
  3089.    
  3090.     x/y in pixels
  3091.  
  3092. 6 = Ax1,Ax2,Ax3,Ax4....Ax_n
  3093.     Ay1,Ay2,Ay3,Ay4....Ay_n
  3094.     Bx1,Bx2,Bx3,Bx4....Bx_n
  3095.     By1,By2,By3,By4....By_n
  3096.     Cx1,Cx2,Cx3,Cx4....Cx_n
  3097.     Cy1,Cy2,Cy3,Cy4....Cy_n
  3098.     ....
  3099.     Zx1,Zx2,Zx3,Zx4....Zx_n
  3100.     Zy1,Zy2,Zy3,Zy4....Zy_n
  3101.  
  3102.     x/y in  xrange / yrange coordinate system
  3103.    
  3104. 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  3105.    
  3106.     x/y in pixels
  3107.  
  3108. 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  3109.    
  3110.     x/y in  xrange / yrange coordinate system
  3111.  
  3112. 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n    
  3113.  
  3114.     x/y in pixels
  3115.  
  3116. 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n    
  3117.  
  3118.     x/y in  xrange / yrange coordinate system
  3119.  
  3120. 11 = Ax1,Ay1,Ax2,Ay2
  3121.      Bx1,By1,Bx2,By2
  3122.      Cx1,Cy1,Cx2,Cy2
  3123.      Dx1,Dy1,Dx2,Dy2
  3124.      ......
  3125.      Zx1,Zy1,Zx2,Zy2
  3126.      
  3127.     x/y in  xrange / yrange coordinate system
  3128.  
  3129. 12 = Ax1,Ay1,Ax2,Ay2
  3130.      Bx1,By1,Bx2,By2
  3131.      Cx1,Cy1,Cx2,Cy2
  3132.      Dx1,Dy1,Dx2,Dy2
  3133.      ......
  3134.      Zx1,Zy1,Zx2,Zy2
  3135.      
  3136.     x/y in pixels
  3137.  
  3138. 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
  3139.  
  3140.     x/y in  xrange / yrange coordinate system
  3141. 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
  3142.     x/y in pixels
  3143. 15 = reply from inputfields,textareas
  3144.     reply1,reply2,reply3,...,reply_n
  3145.  
  3146. 16 = read mathml inputfields only
  3147.  
  3148. 17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n
  3149.  when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
  3150.  
  3151. 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
  3152. 19 = return clicked object number (analogue to shape-library onclick)
  3153. 20 = return x/y-data in x-range/y-range of all 'draggable' images
  3154. 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
  3155. 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
  3156.     x/y in  xrange / yrange coordinate system
  3157. 23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
  3158. */
  3159.  
  3160.  
  3161. void add_read_canvas(int type_reply){
  3162. /* just 1 reply type allowed */
  3163. switch(type_reply){
  3164. /*  TO DO
  3165. !!!!  NEED TO SIMPLIFY !!!!  
  3166. answers may have:
  3167. x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
  3168. */
  3169.     case 1: fprintf(js_include_file,"\
  3170. \n<!-- begin function 1 read_canvas() -->\n\
  3171. function read_canvas(){\
  3172. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3173. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3174.  var p = 0;var input_reply = new Array();\
  3175.  if( document.getElementById(\"canvas_input0\")){\
  3176.   var t = 0;\
  3177.   while(document.getElementById(\"canvas_input\"+t)){\
  3178.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3179.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3180.     p++;\
  3181.    };\
  3182.    t++;\
  3183.   };\
  3184.  };\
  3185.  if( typeof userdraw_text != 'undefined' ){\
  3186.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
  3187.  }\
  3188.  else\
  3189.  {\
  3190.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
  3191.  }\
  3192. }\
  3193. else\
  3194. {\
  3195.  if( typeof userdraw_text != 'undefined' ){\
  3196.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
  3197.  }\
  3198.  else\
  3199.  {\
  3200.   return userdraw_x+\"\\n\"+userdraw_y;\
  3201.  }\
  3202. };\
  3203. };\
  3204. this.read_canvas = read_canvas;\n\
  3205. <!-- end function 1 read_canvas() -->");
  3206.     break;
  3207.     case 2: fprintf(js_include_file,"\
  3208. \n<!-- begin function 2 read_canvas() -->\n\
  3209. function read_canvas(){\
  3210. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3211. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  3212. while(userdraw_x[p]){\
  3213.  reply_x[p] = px2x(userdraw_x[p]);\
  3214.  reply_y[p] = px2y(userdraw_y[p]);\
  3215.  p++;\
  3216. };\
  3217. if(p == 0){alert(\"nothing drawn...\");return;};\
  3218. if( document.getElementById(\"canvas_input0\")){\
  3219.  var p = 0;var input_reply = new Array();\
  3220.  if( document.getElementById(\"canvas_input0\")){\
  3221.   var t = 0;\
  3222.   while(document.getElementById(\"canvas_input\"+t)){\
  3223.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3224.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3225.     p++;\
  3226.    };\
  3227.    t++;\
  3228.   };\
  3229.  };\
  3230.  if( typeof userdraw_text != 'undefined' ){\
  3231.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3232.  }\
  3233.  else\
  3234.  {\
  3235.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  3236.  }\
  3237. }\
  3238. else\
  3239. {\
  3240.  if( typeof userdraw_text != 'undefined' ){\
  3241.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  3242.  }\
  3243.  else\
  3244.  {\
  3245.   return reply_x+\"\\n\"+reply_y;\
  3246.  };\
  3247. };\
  3248. };\
  3249. this.read_canvas = read_canvas;\n\
  3250. <!-- end function 2 read_canvas() -->");
  3251.     break;
  3252.     case 3: fprintf(js_include_file,"\
  3253. \n<!-- begin function 3 read_canvas() -->\n\
  3254. function read_canvas(){\
  3255. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3256. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3257.  var p = 0;var input_reply = new Array();\
  3258.  if( document.getElementById(\"canvas_input0\")){\
  3259.   var t = 0;\
  3260.   while(document.getElementById(\"canvas_input\"+t)){\
  3261.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3262.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3263.     p++;\
  3264.    };\
  3265.    t++;\
  3266.   };\
  3267.  };\
  3268.  if( typeof userdraw_text != 'undefined' ){\
  3269.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3270.  }\
  3271.  else\
  3272.  {\
  3273.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  3274.  }\
  3275. }\
  3276. else\
  3277. {\
  3278.  if( typeof userdraw_text != 'undefined' ){\
  3279.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
  3280.  }\
  3281.  else\
  3282.  {\
  3283.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
  3284.  }\
  3285. }\
  3286. };\
  3287. this.read_canvas = read_canvas;\n\
  3288. <!-- end function 3 read_canvas() -->");
  3289.     break;
  3290.     case 4: fprintf(js_include_file,"\
  3291. \n<!-- begin function 4 read_canvas() -->\n\
  3292. function read_canvas(){\
  3293. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  3294. while(userdraw_x[p]){\
  3295.  reply_x[p] = px2x(userdraw_x[p]);\
  3296.  reply_y[p] = px2y(userdraw_y[p]);\
  3297.  p++;\
  3298. };\
  3299. if(p == 0){alert(\"nothing drawn...\");return;};\
  3300. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3301.  var p = 0;var input_reply = new Array();\
  3302.  if( document.getElementById(\"canvas_input0\")){\
  3303.   var t = 0;\
  3304.   while(document.getElementById(\"canvas_input\"+t)){\
  3305.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3306.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3307.     p++;\
  3308.    };\
  3309.    t++;\
  3310.   };\
  3311.  };\
  3312.  if( typeof userdraw_text != 'undefined' ){\
  3313.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3314.  }\
  3315.  else\
  3316.  {\
  3317.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  3318.  }\
  3319. }\
  3320. else\
  3321. {\
  3322.  if( typeof userdraw_text != 'undefined' ){\
  3323.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
  3324.  }\
  3325.  else\
  3326.  {\
  3327.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
  3328.  }\
  3329. };\
  3330. };\
  3331. this.read_canvas = read_canvas;\n\
  3332. <!-- end function 4 read_canvas() -->");
  3333.     break;
  3334.     /*
  3335.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  3336.         used for userdraw multiple paths
  3337.     */
  3338.     case 5: fprintf(js_include_file,"\
  3339. \n<!-- begin function 5 read_canvas() -->\n\
  3340. function read_canvas(){\
  3341. var p = 0;\
  3342. var reply = \"\";\
  3343. for(p = 0; p < userdraw_x.length;p++){\
  3344.  if(userdraw_x[p] != null ){\
  3345.   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
  3346.  };\
  3347. };\
  3348. if(p == 0){alert(\"nothing drawn...\");return;};\
  3349. userdraw_x = [];userdraw_y = [];\
  3350. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3351.  var p = 0;var input_reply = new Array();\
  3352.  if( document.getElementById(\"canvas_input0\")){\
  3353.   var t = 0;\
  3354.   while(document.getElementById(\"canvas_input\"+t)){\
  3355.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3356.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3357.     p++;\
  3358.    };\
  3359.    t++;\
  3360.   };\
  3361.  };\
  3362.  if( typeof userdraw_text != 'undefined' ){\
  3363.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3364.  }\
  3365.  else\
  3366.  {\
  3367.   return reply +\"\\n\"+input_reply;\
  3368.  }\
  3369. }\
  3370. else\
  3371. {\
  3372.  if( typeof userdraw_text != 'undefined' ){\
  3373.   return reply+\"\\n\"+userdraw_text;\
  3374.  }\
  3375.  else\
  3376.  {\
  3377.   return reply;\
  3378.  }\
  3379. };\
  3380. };\
  3381. this.read_canvas = rdad_canvas;\n\
  3382. <!-- end function 5 read_canvas() -->");
  3383.     break;
  3384.     /*
  3385.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  3386.         used for userdraw multiple paths
  3387.     */
  3388.     case 6: fprintf(js_include_file,"\
  3389. \n<!-- begin function 6 read_canvas() -->\n\
  3390. function read_canvas(){\
  3391. var p = 0;\
  3392. var reply = \"\";\
  3393. var tmp_x = new Array();\
  3394. var tmp_y = new Array();\
  3395. for(p = 0 ; p < userdraw_x.length; p++){\
  3396.  tmp_x = userdraw_x[p];\
  3397.  tmp_y = userdraw_y[p];\
  3398.  if(tmp_x != null){\
  3399.   for(var i = 0 ; i < tmp_x.length ; i++){\
  3400.    tmp_x[i] = px2x(tmp_x[i]);\
  3401.    tmp_y[i] = px2y(tmp_y[i]);\
  3402.   };\
  3403.   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
  3404.  };\
  3405. };\
  3406. if(p == 0){alert(\"nothing drawn...\");return;};\
  3407. userdraw_x = [];userdraw_y = [];\
  3408. if( document.getElementById(\"canvas_input0\") ){\
  3409.  var p = 0;var input_reply = new Array();\
  3410.  if( document.getElementById(\"canvas_input0\")){\
  3411.   var t = 0;\
  3412.   while(document.getElementById(\"canvas_input\"+t)){\
  3413.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3414.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3415.     p++;\
  3416.    };\
  3417.    t++;\
  3418.   };\
  3419.  };\
  3420.  if( typeof userdraw_text != 'undefined' ){\
  3421.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3422.  }\
  3423.  else\
  3424.  {\
  3425.   return reply +\"\\n\"+input_reply;\
  3426.  }\
  3427. }\
  3428. else\
  3429. {\
  3430.  if( typeof userdraw_text != 'undefined' ){\
  3431.   return reply +\"\\n\"+userdraw_text;\
  3432.  }\
  3433.  else\
  3434.  {\
  3435.   return reply;\
  3436.  }\
  3437. };\
  3438. };\
  3439. this.read_canvas = read_canvas;\n\
  3440. <!-- end function 6 read_canvas() -->");
  3441.     break;
  3442.     case 7: fprintf(js_include_file,"\
  3443. \n<!-- begin function 7 read_canvas() -->\n\
  3444. function read_canvas(){\
  3445. var reply = new Array();\
  3446. var p = 0;\
  3447. while(userdraw_x[p]){\
  3448.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
  3449.  p++;\
  3450. };\
  3451. if(p == 0){alert(\"nothing drawn...\");return;};\
  3452. if( document.getElementById(\"canvas_input0\") ){\
  3453.  var p = 0;var input_reply = new Array();\
  3454.  if( document.getElementById(\"canvas_input0\")){\
  3455.   var t = 0;\
  3456.   while(document.getElementById(\"canvas_input\"+t)){\
  3457.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3458.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3459.     p++;\
  3460.    };\
  3461.    t++;\
  3462.   };\
  3463.  };\
  3464.  if( typeof userdraw_text != 'undefined' ){\
  3465.   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3466.  }\
  3467.  else\
  3468.  {\
  3469.   return reply+\"\\n\"+input_reply;\
  3470.  }\
  3471. };\
  3472. else\
  3473. {\
  3474.  if( typeof userdraw_text != 'undefined' ){\
  3475.   return reply+\"\\n\"+userdraw_text;\
  3476.  }\
  3477.  else\
  3478.  {\
  3479.   return reply;\
  3480.  }\
  3481. };\
  3482. };\
  3483. this.read_canvas = read_canvas;\n\
  3484. <!-- end function 7 read_canvas() -->");
  3485.     break;
  3486.     case 8: fprintf(js_include_file,"\
  3487. \n<!-- begin function 8 read_canvas() -->\n\
  3488. function read_canvas(){\
  3489. var reply = new Array();\
  3490. var p = 0;\
  3491. while(userdraw_x[p]){\
  3492.  reply[p] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]);\
  3493.  p++;\
  3494. };\
  3495. if(p == 0){alert(\"nothing drawn...\");return;};\
  3496. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3497.  var p = 0;var input_reply = new Array();\
  3498.  if( document.getElementById(\"canvas_input0\")){\
  3499.   var t = 0;\
  3500.   while(document.getElementById(\"canvas_input\"+t)){\
  3501.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3502.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3503.     p++;\
  3504.    };\
  3505.    t++;\
  3506.   };\
  3507.  };\
  3508.  if( typeof userdraw_text != 'undefined' ){\
  3509.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3510.  }\
  3511.  else\
  3512.  {\
  3513.   return reply +\"\\n\"+input_reply;\
  3514.  }\
  3515. }\
  3516. else\
  3517. {\
  3518.  if( typeof userdraw_text != 'undefined' ){\
  3519.   return reply +\"\\n\"+userdraw_text;\
  3520.  }\
  3521.  else\
  3522.  {\
  3523.   return reply;\
  3524.  }\
  3525. };\
  3526. };\
  3527. this.read_canvas = read_canvas;\n\
  3528. <!-- end function 8 read_canvas() -->");
  3529.     break;
  3530.     case 9: fprintf(js_include_file,"\
  3531. \n<!-- begin function 9 read_canvas() -->\n\
  3532. function read_canvas(){\
  3533. var reply = new Array();\
  3534. var p = 0;\
  3535. while(userdraw_x[p]){\
  3536.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
  3537.  p++;\
  3538. };\
  3539. if(p == 0){alert(\"nothing drawn...\");return;};\
  3540. if( document.getElementById(\"canvas_input0\") ){\
  3541.  var p = 0;var input_reply = new Array();\
  3542.  if( document.getElementById(\"canvas_input0\")){\
  3543.   var t = 0;\
  3544.   while(document.getElementById(\"canvas_input\"+t)){\
  3545.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3546.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3547.     p++;\
  3548.    };\
  3549.    t++;\
  3550.   };\
  3551.  };\
  3552.  if( typeof userdraw_text != 'undefined' ){\
  3553.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3554.  }\
  3555.  else\
  3556.  {\
  3557.   return reply +\"\\n\"+input_reply;\
  3558.  }\
  3559. }\
  3560. else\
  3561. {\
  3562.  if( typeof userdraw_text != 'undefined' ){\
  3563.   return reply +\"\\n\"+userdraw_text;\
  3564.  }\
  3565.  else\
  3566.  {\
  3567.   return reply;\
  3568.  }\
  3569. };\
  3570. };\
  3571. this.read_canvas = read_canvas;\n\
  3572. <!-- end function 9 read_canvas() -->");
  3573.     break;
  3574.     case 10: fprintf(js_include_file,"\
  3575. \n<!-- begin function 10 read_canvas() -->\n\
  3576. function read_canvas(){\
  3577. var reply = new Array();\
  3578. var p = 0;\
  3579. while(userdraw_x[p]){\
  3580.  reply[p] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]) +\":\" + userdraw_radius[p];\
  3581.  p++;\
  3582. };\
  3583. if(p == 0){alert(\"nothing drawn...\");return;};\
  3584. if( document.getElementById(\"canvas_input0\") ){\
  3585.  var p = 0;var input_reply = new Array();\
  3586.  if( document.getElementById(\"canvas_input0\")){\
  3587.   var t = 0;\
  3588.   while(document.getElementById(\"canvas_input\"+t)){\
  3589.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3590.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3591.     p++;\
  3592.    };\
  3593.    t++;\
  3594.   };\
  3595.  };\
  3596.  if( typeof userdraw_text != 'undefined' ){\
  3597.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3598.  }\
  3599.  else\
  3600.  {\
  3601.   return reply +\"\\n\"+input_reply;\
  3602.  }\
  3603. }\
  3604. else\
  3605. {\
  3606.  if( typeof userdraw_text != 'undefined' ){\
  3607.   return reply +\"\\n\"+userdraw_text;\
  3608.  }\
  3609.  else\
  3610.  {\
  3611.   return reply;\
  3612.  }\
  3613. };\
  3614. };\
  3615. this.read_canvas = read_canvas;\n\
  3616. <!-- end function 10 read_canvas() -->");
  3617.     break;
  3618.     case 11: fprintf(js_include_file,"\
  3619. \n<!-- begin function 11 read_canvas() -->\n\
  3620. function read_canvas(){\
  3621. var reply = \"\";\
  3622. var p = 0;\
  3623. while(userdraw_x[p]){\
  3624.  reply = reply + px2x(userdraw_x[p]) +\",\" + px2y(userdraw_y[p]) +\",\" + px2x(userdraw_x[p+1]) +\",\" + px2y(userdraw_y[p+1]) +\"\\n\" ;\
  3625.  p = p+2;\
  3626. };\
  3627. if(p == 0){alert(\"nothing drawn...\");return;};\
  3628. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3629.  var p = 0;var input_reply = new Array();\
  3630.  if( document.getElementById(\"canvas_input0\")){\
  3631.   var t = 0;\
  3632.   while(document.getElementById(\"canvas_input\"+t)){\
  3633.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3634.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3635.     p++;\
  3636.    };\
  3637.    t++;\
  3638.   };\
  3639.  };\
  3640.  if( typeof userdraw_text != 'undefined' ){\
  3641.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3642.  }\
  3643.  else\
  3644.  {\
  3645.   return reply +\"\\n\"+input_reply;\
  3646.  }\
  3647. }\
  3648. else\
  3649. {\
  3650.  if( typeof userdraw_text != 'undefined' ){\
  3651.   return reply +\"\\n\"+userdraw_text;\
  3652.  }\
  3653.  else\
  3654.  {\
  3655.   return reply;\
  3656.  }\
  3657. };\
  3658. };\
  3659. this.read_canvas = read_canvas;\n\
  3660. <!-- end function 11 read_canvas() -->");
  3661.     break;
  3662.     case 12: fprintf(js_include_file,"\
  3663. \n<!-- begin function 12 read_canvas() -->\n\
  3664. function read_canvas(){\
  3665. var reply = \"\";\
  3666. var p = 0;\
  3667. for(p = 0; p< userdraw_x.lenght;p = p+2){\
  3668.  if(userdraw_x[p] != null){\
  3669.    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
  3670.  };\
  3671. };\
  3672. if(p == 0){alert(\"nothing drawn...\");return;};\
  3673. if( document.getElementById(\"canvas_input0\") ){\
  3674.  var p = 0;var input_reply = new Array();\
  3675.  if( document.getElementById(\"canvas_input0\")){\
  3676.   var t = 0;\
  3677.   while(document.getElementById(\"canvas_input\"+t)){\
  3678.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3679.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3680.     p++;\
  3681.    };\
  3682.    t++;\
  3683.   };\
  3684.  };\
  3685.  if( typeof userdraw_text != 'undefined' ){\
  3686.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3687.  }\
  3688.  else\
  3689.  {\
  3690.   return reply +\"\\n\"+input_reply;\
  3691.  }\
  3692. }\
  3693. else\
  3694. {\
  3695.  if( typeof userdraw_text != 'undefined' ){\
  3696.   return reply +\"\\n\"+userdraw_text\
  3697.  }\
  3698.  else\
  3699.  {\
  3700.   return reply;\
  3701.  }\
  3702. };\
  3703. };\
  3704. this.read_canvas = read_canvas;\n\
  3705. <!-- end function 12 read_canvas() -->");
  3706.     break;
  3707.     case 13: fprintf(js_include_file,"\
  3708. \n<!-- begin function 13 read_canvas() -->\n\
  3709. function read_canvas(){\
  3710. var reply = new Array();\
  3711. var p = 0;var i = 0;\
  3712. while(userdraw_x[p]){\
  3713.  reply[i] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]) +\":\" + px2x(userdraw_x[p+1]) +\":\" + px2y(userdraw_y[p+1]);\
  3714.  p = p+2;i++;\
  3715. };\
  3716. if(p == 0){alert(\"nothing drawn...\");return;};\
  3717. if( document.getElementById(\"canvas_input0\") ){\
  3718.  var p = 0;var input_reply = new Array();\
  3719.  if( document.getElementById(\"canvas_input0\")){\
  3720.   var t = 0;\
  3721.   while(document.getElementById(\"canvas_input\"+t)){\
  3722.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3723.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3724.     p++;\
  3725.    };\
  3726.    t++;\
  3727.   };\
  3728.  };\
  3729.  if( typeof userdraw_text != 'undefined' ){\
  3730.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3731.  }\
  3732.  else\
  3733.  {\
  3734.   return reply +\"\\n\"+input_reply;\
  3735.  }\
  3736. }\
  3737. else\
  3738. {\
  3739.  if( typeof userdraw_text != 'undefined' ){\
  3740.   return reply +\"\\n\"+userdraw_text\
  3741.  }\
  3742.  else\
  3743.  {\
  3744.   return reply;\
  3745.  }\
  3746. };\
  3747. };\
  3748. this.read_canvas = read_canvas;\n\
  3749. <!-- end function 13 read_canvas() -->");
  3750.     break;
  3751.     case 14: fprintf(js_include_file,"\
  3752. \n<!-- begin function 14 read_canvas() -->\n\
  3753. function read_canvas(){\
  3754. var reply = new Array();\
  3755. var p = 0;var i = 0;\
  3756. while(userdraw_x[p]){\
  3757.  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
  3758.  p = p+2;i++;\
  3759. };\
  3760. if(p == 0){alert(\"nothing drawn...\");return;};\
  3761. if( document.getElementById(\"canvas_input0\") ){\
  3762.  var p = 0;var input_reply = new Array();\
  3763.  if( document.getElementById(\"canvas_input0\")){\
  3764.   var t = 0;\
  3765.   while(document.getElementById(\"canvas_input\"+t)){\
  3766.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3767.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3768.     p++;\
  3769.    };\
  3770.    t++;\
  3771.   };\
  3772.  };\
  3773.  if( typeof userdraw_text != 'undefined' ){\
  3774.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3775.  }\
  3776.  else\
  3777.  {\
  3778.   return reply +\"\\n\"+input_reply;\
  3779.  }\
  3780. }\
  3781. else\
  3782. {\
  3783.  if( typeof userdraw_text != 'undefined' ){\
  3784.   return reply +\"\\n\"+userdraw_text;\
  3785.  }\
  3786.  else\
  3787.  {\
  3788.   return reply;\
  3789.  }\
  3790. };\
  3791. };\
  3792. this.read_canvas = read_canvas;\n\
  3793. <!-- end function 14 read_canvas() -->");
  3794.     break;
  3795.     case 15: fprintf(js_include_file,"\
  3796. \n<!-- begin function 15  read_canvas() -->\n\
  3797. function read_canvas(){\
  3798. var input_reply = new Array();\
  3799. var p = 0;\
  3800. if( document.getElementById(\"canvas_input0\")){\
  3801.  var t = 0;\
  3802.  while(document.getElementById(\"canvas_input\"+t)){\
  3803.   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3804.    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3805.    p++;\
  3806.   };\
  3807.   t++;\
  3808.  };\
  3809. };\
  3810. if( typeof userdraw_text != 'undefined' ){\
  3811.   return input_reply +\"\\n\"+userdraw_text;\
  3812. }\
  3813. else\
  3814. {\
  3815.  return input_reply;\
  3816. };\
  3817. };\
  3818. this.read_canvas = read_canvas;\n\
  3819. <!-- end function 15 read_canvas() -->");
  3820.     break;
  3821.     case 16: fprintf(js_include_file,"\
  3822. \n<!-- begin function 16 read_mathml() -->\n\
  3823. function read_mathml(){\
  3824. var reply = new Array();\
  3825. var p = 0;\
  3826. if( document.getElementById(\"mathml0\")){\
  3827.  while(document.getElementById(\"mathml\"+p)){\
  3828.   reply[p] = document.getElementById(\"mathml\"+p).value;\
  3829.   p++;\
  3830.  };\
  3831. };\
  3832. return reply;\
  3833. };\
  3834. this.read_mathml = read_mathml;\n\
  3835. <!-- end function 16 read_mathml() -->");
  3836.     break;
  3837.     case 17:  fprintf(js_include_file,"\
  3838. \n<!-- begin function 17 read_canvas() -->\n\
  3839. function read_canvas(){\
  3840. if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\
  3841. return userdraw_text;\
  3842. };\
  3843. this.read_canvas = read_canvas;\n\
  3844. <!-- end function 17 read_canvas() -->");
  3845.     break;
  3846.     case 18: fprintf(js_include_file,"\
  3847. \n<!-- begin function 18 read_canvas() -->\n\
  3848. function read_canvas(){\
  3849. var p = 0;\
  3850. var reply = new Array();\
  3851. var name;\
  3852. var t = true;\
  3853. while(t){\
  3854.  try{ name = eval('clocks'+p);\
  3855.  reply[p] = parseInt((name.H+name.M/60+name.S/3600)%%12)+\":\"+parseInt((name.M + name.S/60)%%60)+\":\"+(name.S)%%60;p++}catch(e){t=false;};\
  3856. };\
  3857. if( p == 0){alert(\"clock(s) not modified...\");return;}\
  3858. return reply;\
  3859. };\
  3860. this.read_canvas = read_canvas;\n\
  3861. <!-- end function 18 read_canvas() -->");
  3862.     break;
  3863.     case 19: fprintf(js_include_file,"\
  3864. \n<!-- begin function 19 read_canvas() -->\n\
  3865. function read_canvas(){\
  3866. return reply[0];\
  3867. };\
  3868. this.read_canvas = read_canvas;\n\
  3869. <!-- end function 19 read_canvas() -->");
  3870.     case 20: fprintf(js_include_file,"\
  3871. \n<!-- begin function 20 read_canvas() -->\n\
  3872. function read_canvas(){\
  3873. var len  = ext_drag_images.length;\
  3874. var reply = new Array(len);\
  3875. for(var p = 0 ; p < len ; p++){\
  3876.    var img = ext_drag_images[p];\
  3877.    reply[p] = px2x(img[6])+\":\"+px2y(img[7]);\
  3878. };\
  3879. return reply;\
  3880. };\
  3881. this.read_canvas = read_canvas;\n\
  3882. <!-- end function 20 read_canvas() -->");
  3883.     break;
  3884.     case 21: fprintf(js_include_file,"\
  3885. \n<!-- begin function 21 read_canvas() -->\n\
  3886. function read_canvas(){\
  3887. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3888. var reply_coord = new Array();var p = 0;\
  3889. while(userdraw_x[p]){\
  3890.  reply_coord[p] = \"(\"+px2x(userdraw_x[p])+\":\"+px2y(userdraw_y[p])+\")\";\
  3891.  p++;\
  3892. };\
  3893. if(p == 0){alert(\"nothing drawn...\");return;};\
  3894. if( document.getElementById(\"canvas_input0\") ){\
  3895.  var p = 0;var input_reply = new Array();\
  3896.  if( document.getElementById(\"canvas_input0\")){\
  3897.   var t = 0;\
  3898.   while(document.getElementById(\"canvas_input\"+t)){\
  3899.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3900.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3901.     p++;\
  3902.    };\
  3903.    t++;\
  3904.   };\
  3905.  };\
  3906.  if( typeof userdraw_text != 'undefined' ){\
  3907.   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3908.  }\
  3909.  else\
  3910.  {\
  3911.   return reply_coord+\"\\n\"+input_reply;\
  3912.  }\
  3913. }\
  3914. else\
  3915. {\
  3916.  if( typeof userdraw_text != 'undefined' ){\
  3917.   return reply_coord+\"\\n\"+userdraw_text;\
  3918.  }\
  3919.  else\
  3920.  {\
  3921.   return reply_coord;\
  3922.  };\
  3923. };\
  3924. };\
  3925. this.read_canvas = read_canvas;\n\
  3926. <!-- end function 21 read_canvas() -->");
  3927.     break;
  3928.     case 22: fprintf(js_include_file,"\
  3929. \n<!-- begin function 22 read_canvas() -->\n\
  3930. function read_canvas(){\
  3931. var reply = new Array();\
  3932. var p = 0;\
  3933. var idx = 0;\
  3934. while(userdraw_x[p]){\
  3935.  reply[idx] = px2x(userdraw_x[p]);\
  3936.  idx++;\
  3937.  reply[idx] = px2y(userdraw_y[p]);\
  3938.  idx++;p++;\
  3939. };\
  3940. if(p == 0){alert(\"nothing drawn...\");return;};\
  3941. if( document.getElementById(\"canvas_input0\") ){\
  3942.  var p = 0;var input_reply = new Array();\
  3943.  if( document.getElementById(\"canvas_input0\")){\
  3944.   var t = 0;\
  3945.   while(document.getElementById(\"canvas_input\"+t)){\
  3946.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3947.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3948.     p++;\
  3949.    };\
  3950.    t++;\
  3951.   };\
  3952.  };\
  3953.  if( typeof userdraw_text != 'undefined' ){\
  3954.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3955.  }\
  3956.  else\
  3957.  {\
  3958.   return reply +\"\\n\"+input_reply;\
  3959.  }\
  3960. }\
  3961. else\
  3962. {\
  3963.  if( typeof userdraw_text != 'undefined' ){\
  3964.   return reply +\"\\n\"+userdraw_text;\
  3965.  }\
  3966.  else\
  3967.  {\
  3968.   return reply;\
  3969.  }\
  3970. };\
  3971. };\
  3972. this.read_canvas = read_canvas;\n\
  3973. <!-- end function 22 read_canvas() -->");
  3974.     break;
  3975.     case 23: fprintf(js_include_file,"\
  3976. \n<!-- begin function 23 read_canvas() default 5 px marge -->\n\
  3977. function read_canvas(){\
  3978. if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
  3979. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  3980. var lu = userdraw_x.length;\
  3981. if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
  3982. var marge = 5;\
  3983. reply_x[p] = px2x(userdraw_x[0]);reply_y[p] = px2y(userdraw_y[0]);p++;\
  3984. for(var i = 0; i < lu - 1 ; i++ ){\
  3985.  if( (userdraw_x[i] < (userdraw_x[i+1] + marge)) && (userdraw_x[i] > (userdraw_x[i+1] - marge)) ){\
  3986.   if( (userdraw_y[i] < (userdraw_y[i+1] + marge)) && (userdraw_y[i] > (userdraw_y[i+1] - marge)) ){\
  3987.    reply_x[p] = px2x(userdraw_x[i]);reply_y[p] = px2y(userdraw_y[i]);\
  3988.    if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
  3989.    p++;\
  3990.   };\
  3991.  };\
  3992. };\
  3993. if( document.getElementById(\"canvas_input0\")){\
  3994.  var p = 0;var input_reply = new Array();\
  3995.  if( document.getElementById(\"canvas_input0\")){\
  3996.   var t = 0;\
  3997.   while(document.getElementById(\"canvas_input\"+t)){\
  3998.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3999.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4000.     p++;\
  4001.    };\
  4002.    t++;\
  4003.   };\
  4004.  };\
  4005.  if( typeof userdraw_text != 'undefined' ){\
  4006.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4007.  }\
  4008.  else\
  4009.  {\
  4010.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  4011.  }\
  4012. }\
  4013. else\
  4014. {\
  4015.  if( typeof userdraw_text != 'undefined' ){\
  4016.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  4017.  }\
  4018.  else\
  4019.  {\
  4020.   return reply_x+\"\\n\"+reply_y;\
  4021.  };\
  4022. };\
  4023. };\
  4024. this.read_canvas = read_canvas;\n\
  4025. <!-- end function 23 read_canvas() -->");
  4026.     break;
  4027.  
  4028.     default: canvas_error("hmmm unknown replyformat...");break;
  4029. }
  4030.  return;
  4031. }
  4032.  
  4033.  
  4034. /*
  4035.  add drawfunction :
  4036.  - functions used by userdraw_primitives (circle,rect,path,triangle...)
  4037.  - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
  4038.  - grid / mathml
  4039.  - will not scale or zoom in
  4040.  - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
  4041.  - is printed directly into 'js_include_file'
  4042. */
  4043.  
  4044. void add_javascript_functions(int js_functions[],int canvas_root_id){
  4045. int i;
  4046. for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
  4047.  if( js_functions[i] == 1){
  4048.     switch(i){
  4049.     case DRAG_EXTERNAL_IMAGE:
  4050. fprintf(js_include_file,"\n<!-- drag external images --->\n\
  4051. var external_canvas = create_canvas%d(7,xsize,ysize);\
  4052. var external_ctx = external_canvas.getContext(\"2d\");\
  4053. var external_canvas_rect = external_canvas.getBoundingClientRect();\
  4054. canvas_div.addEventListener(\"mousedown\",setxy,false);\
  4055. canvas_div.addEventListener(\"mouseup\",dragstop,false);\
  4056. canvas_div.addEventListener(\"mousemove\",dragxy,false);\
  4057. var selected_image = null;\
  4058. var ext_image_cnt = 0;\
  4059. var ext_drag_images = new Array();\
  4060. function drag_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,draggable){\
  4061. ext_image_cnt = idx;\
  4062. var image = new Image();\
  4063. image.src = URL;\
  4064. image.onload = function(){\
  4065.  if( x0 < 1 ){ x0 = 0; };if( y0 < 1 ){ y0 = 0; };if( sx < 1 ){ sx = 0; };if( sy < 1 ){ sy = 0; };\
  4066.  if( width < 1 ){ width = image.width; };if( height < 1 ){ height = image.height; };\
  4067.  if( swidth < 1 ){ swidth = image.width; };if( sheight < 1 ){ sheight = image.height; };\
  4068.  img = new Array(10);\
  4069.  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
  4070.  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;\
  4071.  ext_drag_images[idx] = img;\
  4072.  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  4073. };\
  4074. };\
  4075. function dragstop(evt){\
  4076. selected_image = null;return;\
  4077. };\
  4078. function dragxy(evt){\
  4079. if( selected_image != null ){\
  4080.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  4081.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  4082.  var s_img = ext_drag_images[selected_image];\
  4083.  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\
  4084.  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\
  4085.  ext_drag_images[selected_image] = s_img;\
  4086.  external_ctx.clearRect(0,0,xsize,ysize);\
  4087.  for(var i = 0; i <= ext_image_cnt ; i++){\
  4088.   var img = ext_drag_images[i];\
  4089.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  4090.  };\
  4091. };\
  4092. };\
  4093. function setxy(evt){\
  4094. if( ! selected_image && evt.which == 1 ){\
  4095.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  4096.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  4097.  var xm = evt.clientX - external_canvas_rect.left + xoff;\
  4098.  var ym = evt.clientY - external_canvas_rect.top + yoff;\
  4099.  for(var p = 0 ; p <= ext_image_cnt ; p++){\
  4100.   var img = ext_drag_images[p];\
  4101.   if( img[0] == 1 ){\
  4102.    var w = img.width;\
  4103.    var h = img.height;\
  4104.    if( xm > img[6] && xm < img[6] + img[4]){\
  4105.     if( ym > img[7] && ym < img[7] + img[5]){\
  4106.      img[6] = xm;\
  4107.      img[7] = ym;\
  4108.      ext_drag_images[p] = img;\
  4109.      selected_image = p;\
  4110.      dragxy(evt);\
  4111.     };\
  4112.    };\
  4113.   };\
  4114.  };\
  4115. }\
  4116. else\
  4117. {\
  4118.  selected_image = null;\
  4119. };\
  4120. };",canvas_root_id);
  4121.     break;
  4122.  
  4123.     case DRAW_EXTERNAL_IMAGE:
  4124. fprintf(js_include_file,"\n<!-- draw external images -->\n\
  4125. draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\
  4126. var image = new Image();\
  4127. image.src = URL;\
  4128. var canvas_bg_div = document.getElementById(\"canvas_div%d\");\
  4129. image.onload = function(){\
  4130.  if( x0 < 1 ){ x0 = 0; };\
  4131.  if( y0 < 1 ){ y0 = 0; };\
  4132.  if( sx < 1 ){ sx = 0; };\
  4133.  if( sy < 1 ){ sy = 0; };\
  4134.  if( width < 1 ){ width = image.width;};\
  4135.  if( height < 1 ){ height = image.height;};\
  4136.  if( swidth < 1 ){ swidth = image.width;};\
  4137.  if( sheight < 1 ){ sheight = image.height;};\
  4138.  var ml = x0 - sx;\
  4139.  var mh = y0 - sy;\
  4140.  canvas_bg_div.style.backgroundPosition= \"left \"+ml+\"px top \"+mh+\"px\";\
  4141.  canvas_bg_div.style.backgroundSize = width+\"px \"+height+\"px\";\
  4142.  canvas_bg_div.style.backgroundRepeat = \"no-repeat\";\
  4143.  canvas_bg_div.style.backgroundPosition= sx+\"px \"+sy+\"px\";\
  4144.  canvas_bg_div.style.backgroundImage = \"url(\" + URL + \")\";\
  4145. };\
  4146. };",canvas_root_id);    
  4147.     break;
  4148.    
  4149.     case DRAW_ZOOM_BUTTONS: /* 6 rectangles 15x15 px  forbidden zone for drawing : y < ysize - 15*/
  4150. fprintf(js_include_file,"\n<!-- draw zoom buttons -->\n\
  4151. draw_zoom_buttons = function(canvas_type,color,opacity){\
  4152. var obj;\
  4153. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4154.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4155. }\
  4156. else\
  4157. {\
  4158.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4159. };\
  4160. var ctx = obj.getContext(\"2d\");\
  4161. ctx.font =\"18px Ariel\";\
  4162. ctx.textAlign = \"right\";\
  4163. ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  4164. ctx.fillText(\"+\",xsize,ysize);\
  4165. ctx.fillText(\"\\u2212\",xsize - 15,ysize);\
  4166. ctx.fillText(\"\\u2192\",xsize - 30,ysize-2);\
  4167. ctx.fillText(\"\\u2190\",xsize - 45,ysize-2);\
  4168. ctx.fillText(\"\\u2191\",xsize - 60,ysize-2);\
  4169. ctx.fillText(\"\\u2193\",xsize - 75,ysize-2);\
  4170. ctx.fillText(\"\\u00D7\",xsize - 90,ysize-2);\
  4171. ctx.stroke();\
  4172. };",canvas_root_id,canvas_root_id,canvas_root_id);
  4173.    
  4174.     break;
  4175.     case DRAW_GRIDFILL:/* not used for userdraw */
  4176. fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
  4177. draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\
  4178. var obj;\
  4179. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4180.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4181. }\
  4182. else\
  4183. {\
  4184.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4185. };\
  4186. var ctx = obj.getContext(\"2d\");\
  4187. var x,y;\
  4188. ctx.save();\
  4189. ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  4190. snap_x = dx;snap_y = dy;\
  4191. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  4192.    ctx.moveTo(x,y0);\
  4193.    ctx.lineTo(x,ysize);\
  4194. };\
  4195. for( y = y0 ; y < ysize+dy; y = y + dy ){\
  4196.    ctx.moveTo(x0,y);\
  4197.    ctx.lineTo(xsize,y);\
  4198. };\
  4199. ctx.stroke();\
  4200. ctx.restore();\
  4201. return;};",canvas_root_id,canvas_root_id,canvas_root_id);
  4202.     break;
  4203.    
  4204.     case DRAW_IMAGEFILL:/* not  used for userdraw */
  4205. fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
  4206. draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\
  4207. var obj;\
  4208. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4209.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4210. }\
  4211. else\
  4212. {\
  4213.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4214. };\
  4215. var ctx = obj.getContext(\"2d\");\
  4216. ctx.save();\
  4217. var img = new Image();\
  4218. img.src = URL;\
  4219. img.onload = function(){\
  4220.  if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\
  4221.    ctx.drawImage(img,x0,y0,xsize,ysize);\
  4222.  }\
  4223.  else\
  4224.  {\
  4225.    var repeat = \"repeat\";\
  4226.    if(img.width > xsize - x0){\
  4227.         repeat = \"repeat-y\";\
  4228.    }\
  4229.    else\
  4230.    {\
  4231.     if( img.height > ysize -x0 ){\
  4232.      repeat = \"repeat-x\";\
  4233.     }\
  4234.    }\
  4235.    var pattern = ctx.createPattern(img,repeat);\
  4236.    ctx.rect(x0,y0,xsize,ysize);\
  4237.    ctx.fillStyle = pattern;\
  4238.  }\
  4239.  ctx.fill();\
  4240. };\
  4241. ctx.restore();\
  4242. return;\
  4243. };",canvas_root_id,canvas_root_id,canvas_root_id);
  4244.     break;
  4245.    
  4246.     case DRAW_DOTFILL:/* not  used for userdraw */
  4247. fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
  4248. draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\
  4249. var obj;\
  4250. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4251.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4252. }\
  4253. else\
  4254. {\
  4255.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4256. };\
  4257. var ctx = obj.getContext(\"2d\");\
  4258. var x,y;\
  4259. ctx.closePath();\
  4260. ctx.save();\
  4261. snap_x = dx;snap_y = dy;\
  4262. ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  4263. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  4264.  for( y = y0 ; y < ysize+dy ; y = y + dy ){\
  4265.   ctx.arc(x,y,radius,0,2*Math.PI,false);\
  4266.   ctx.closePath();\
  4267.  }\
  4268. }\
  4269. ctx.fill();\
  4270. ctx.restore();\
  4271. return;};",canvas_root_id,canvas_root_id,canvas_root_id);
  4272.     break;
  4273.  
  4274.     case DRAW_DIAMONDFILL:/* not used for userdraw */
  4275. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  4276. draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  4277.  var obj;\
  4278. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4279.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4280. }\
  4281. else\
  4282. {\
  4283.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4284. };\
  4285. var ctx = obj.getContext(\"2d\");\
  4286. var x;\
  4287. var y;\
  4288. ctx.save();\
  4289. ctx.lineWidth = linewidth;\
  4290. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4291. y = ysize;\
  4292. for( x = x0 ; x < xsize ; x = x + dx ){\
  4293.  ctx.moveTo(x,y0);\
  4294.  ctx.lineTo(xsize,y);\
  4295.  y = y - dy;\
  4296. };\
  4297. y = y0;\
  4298. for( x = xsize ; x > 0 ; x = x - dx){\
  4299.  ctx.moveTo(x,ysize);\
  4300.  ctx.lineTo(x0,y);\
  4301.  y = y + dy;\
  4302. };\
  4303. x = x0;\
  4304. for( y = y0 ; y < ysize ; y = y + dy ){\
  4305.  ctx.moveTo(xsize,y);\
  4306.  ctx.lineTo(x,ysize);\
  4307.  x = x + dx;\
  4308. };\
  4309. x = xsize;\
  4310. for( y = ysize ; y > y0 ; y = y - dy ){\
  4311.  ctx.moveTo(x,y0);\
  4312.  ctx.lineTo(x0,y);\
  4313.  x = x - dx;\
  4314. };\
  4315. ctx.stroke();\
  4316. ctx.restore();\
  4317. return;\
  4318. }",canvas_root_id,canvas_root_id,canvas_root_id);
  4319.     break;
  4320.    
  4321.     case DRAW_HATCHFILL:/* not used for userdraw */
  4322. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  4323. draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  4324.  var obj;\
  4325. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4326.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4327. }\
  4328. else\
  4329. {\
  4330.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4331. };\
  4332. var ctx = obj.getContext(\"2d\");\
  4333. var x;\
  4334. var y;\
  4335. ctx.save();\
  4336. ctx.lineWidth = linewidth;\
  4337. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4338. y = ysize;\
  4339. for( x = x0 ; x < xsize ; x = x + dx ){\
  4340.  ctx.moveTo(x,y0);\
  4341.  ctx.lineTo(xsize,y);\
  4342.  y = y - dy;\
  4343. };\
  4344. y = y0;\
  4345. for( x = xsize ; x >= dx ; x = x - dx){\
  4346.  ctx.moveTo(x,ysize);\
  4347.  ctx.lineTo(x0,y);\
  4348.  y = y + dy;\
  4349. };\
  4350. ctx.stroke();\
  4351. ctx.restore();\
  4352. return;\
  4353. };",canvas_root_id,canvas_root_id,canvas_root_id);
  4354.     break;
  4355.     case DRAW_CIRCLES:/*  used for userdraw */
  4356. fprintf(js_include_file,"\n<!-- draw circles -->\n\
  4357. draw_circles = function(ctx,x_points,y_points,radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\
  4358. ctx.save();\
  4359. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4360. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4361. ctx.lineWidth = line_width;\
  4362. for(var p = 0 ; p < x_points.length ; p++ ){\
  4363.  ctx.beginPath();\
  4364.  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
  4365.  ctx.closePath();\
  4366.  if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4367.  if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  4368.  ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4369.  ctx.stroke();\
  4370. }\
  4371. ctx.restore();\
  4372. return;\
  4373. };");
  4374.     break;
  4375.     case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
  4376. fprintf(js_include_file,"\n<!-- draw polyline -->\n\
  4377. draw_polyline = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\
  4378. ctx.save();\
  4379. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4380. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4381. ctx.lineWidth = line_width;\
  4382. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4383. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4384. ctx.clearRect(0,0,xsize,ysize);\
  4385. ctx.beginPath();\
  4386. for(var p = 0 ; p < x_points.length-1 ; p++ ){\
  4387.  ctx.moveTo(x_points[p],y_points[p]);\
  4388.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  4389. }\
  4390. ctx.closePath();\
  4391. ctx.stroke();\
  4392. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4393. for(var p = 0 ; p < x_points.length ; p++ ){\
  4394.  ctx.beginPath();\
  4395.  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
  4396.  ctx.closePath();ctx.fill();ctx.stroke();\
  4397. };\
  4398. ctx.restore();\
  4399. return;\
  4400. };");
  4401.     break;
  4402.    
  4403.     case DRAW_SEGMENTS:/*  used for userdraw */
  4404. fprintf(js_include_file,"\n<!-- draw segments -->\n\
  4405. draw_segments = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\
  4406. ctx.save();\
  4407. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4408. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4409. ctx.lineWidth = line_width;\
  4410. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4411. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4412. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  4413.  ctx.beginPath();\
  4414.  ctx.moveTo(x_points[p],y_points[p]);\
  4415.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  4416.  ctx.closePath();\
  4417.  ctx.stroke();\
  4418.  }\
  4419.  ctx.restore();\
  4420.  return;\
  4421. };");
  4422.     break;
  4423.    
  4424.     case DRAW_LINES:/*  used for userdraw */
  4425. fprintf(js_include_file,"\n<!-- draw lines -->\n\
  4426. function calc_line(x1,x2,y1,y2){\
  4427. var marge = 2;\
  4428. if(x1 < x2+marge && x1>x2-marge){\
  4429.  return [x1,0,x1,ysize];\
  4430. };\
  4431. if(y1 < y2+marge && y1>y2-marge){\
  4432.  return [0,y1,xsize,y1];\
  4433. };\
  4434. var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
  4435. var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
  4436. return [0,Y1,xsize,Y2];\
  4437. };\
  4438. draw_lines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\
  4439. ctx.save();\
  4440. var line = new Array(4);\
  4441. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4442. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4443. ctx.lineWidth = line_width;\
  4444. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4445. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4446. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  4447.  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
  4448.  ctx.beginPath();\
  4449.  ctx.moveTo(line[0],line[1]);\
  4450.  ctx.lineTo(line[2],line[3]);\
  4451.  ctx.closePath();\
  4452.  ctx.stroke();\
  4453.  }\
  4454.  ctx.restore();\
  4455.  return;\
  4456. };");
  4457.     break;
  4458.  
  4459.     case DRAW_CROSSHAIRS:/*  used for userdraw */
  4460. fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
  4461. draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_translate,vector){\
  4462. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4463. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4464. ctx.lineWidth = line_width;\
  4465. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4466. var x1,x2,y1,y2;\
  4467. for(var p = 0 ; p < x_points.length ; p++ ){\
  4468.  x1 = x_points[p] - crosshair_size;\
  4469.  x2 = x_points[p] + crosshair_size;\
  4470.  y1 = y_points[p] - crosshair_size;\
  4471.  y2 = y_points[p] + crosshair_size;\
  4472.  ctx.beginPath();\
  4473.  ctx.moveTo(x1,y1);\
  4474.  ctx.lineTo(x2,y2);\
  4475.  ctx.closePath();\
  4476.  ctx.stroke();\
  4477.  ctx.beginPath();\
  4478.  ctx.moveTo(x2,y1);\
  4479.  ctx.lineTo(x1,y2);\
  4480.  ctx.closePath();\
  4481.  ctx.stroke();\
  4482. }\
  4483. ctx.restore();\
  4484.  return;\
  4485. };");
  4486.     break;
  4487.  
  4488.     case DRAW_RECTS:/*  used for userdraw */
  4489. fprintf(js_include_file,"\n<!-- draw rects -->\n\
  4490. draw_rects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\
  4491. ctx.save();\
  4492. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4493. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4494. ctx.lineWidth = line_width;\
  4495. ctx.strokeStyle = \"rgba('+stroke_color+','+stroke_opacity+')\";\
  4496. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
  4497. for(var p = 0 ; p < x_points.length ; p = p + 2){\
  4498.  ctx.beginPath();\
  4499.  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
  4500.  ctx.closePath();\
  4501.  if(use_filled == 1 ){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  4502.  ctx.stroke();\
  4503. };\
  4504. ctx.restore();\
  4505. return;\
  4506. };");
  4507.     break;
  4508.  
  4509.     case DRAW_ROUNDRECTS:/*  used for userdraw */
  4510. fprintf(js_include_file,"\n<!-- draw round rects -->\n\
  4511. draw_roundrects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_translate,vector){\
  4512. ctx.save();\
  4513. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4514. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4515. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4516. var x,y,w,h,r;\
  4517. for(var p = 0; p < x_points.length; p = p+2){\
  4518.  x = x_points[p];y = y_points[p];w = x_points[p+1] - x;h = y_points[p+1] - y;r = parseInt(0.1*w);\
  4519.  ctx.beginPath();ctx.moveTo(x + r, y);\
  4520.  ctx.lineTo(x + w - r, y);\
  4521.  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
  4522.  ctx.lineTo(x + w, y + h - r);\
  4523.  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
  4524.  ctx.lineTo(x + r, y + h);\
  4525.  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
  4526.  ctx.lineTo(x, y + r);\
  4527.  ctx.quadraticCurveTo(x, y, x + r, y);\
  4528.  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
  4529.  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4530.  if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\
  4531.  ctx.stroke();\
  4532. }\
  4533. ctx.restore();\
  4534. };");
  4535.     break;
  4536.  
  4537.     case DRAW_ELLIPSES:/* not  used for userdraw */
  4538. fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
  4539. draw_ellipses = function(canvas_type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_translate,vector){\
  4540. var obj;\
  4541. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4542.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4543. }\
  4544. else\
  4545. {\
  4546.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4547. };\
  4548. var ctx = obj.getContext(\"2d\");\
  4549. ctx.save();\
  4550. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4551. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4552. var cx,cy,ry,rx;\
  4553. ctx.lineWidth = line_width;\
  4554. if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\
  4555. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4556. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4557. for(var p=0;p< x_points.length;p = p+2){\
  4558.  ctx.beginPath();\
  4559.  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
  4560.  ctx.translate(cx - rx, cy - ry);\
  4561.  ctx.scale(rx, ry);\
  4562.  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
  4563.  if( use_filled == 1 ){ctx.fill();}\
  4564.  ctx.stroke();\
  4565. };\
  4566. ctx.restore();\
  4567. };",canvas_root_id,canvas_root_id,canvas_root_id);
  4568.     break;
  4569.  
  4570.     case DRAW_PATHS: /*  used for userdraw */
  4571. fprintf(js_include_file,"\n<!-- draw paths -->\n\
  4572. draw_paths = function(ctx,x_points,y_points,line_width,closed_path,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_translate,vector){\
  4573. ctx.save();\
  4574. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4575. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4576. ctx.lineWidth = line_width;\
  4577. ctx.lineJoin = \"round\";\
  4578. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4579. ctx.beginPath();\
  4580. ctx.moveTo(x_points[0],y_points[0]);\
  4581. for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
  4582. if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
  4583. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4584. if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  4585. ctx.stroke();\
  4586. ctx.restore();\
  4587. return;\
  4588. };");
  4589.    
  4590.     break;
  4591.     case DRAW_ARROWS:/*  used for userdraw */
  4592. fprintf(js_include_file,"\n<!-- draw arrows -->\n\
  4593. draw_arrows = function(ctx,x_points,y_points,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,use_translate,vector){\
  4594. ctx.save();\
  4595. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4596. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4597. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4598. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4599. ctx.lineWidth = line_width;\
  4600. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4601. ctx.lineCap = \"round\";\
  4602. ctx.save();\
  4603. var x1,y1,x2,y2,dx,dy,len;\
  4604. for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
  4605.   ctx.restore();ctx.save();\
  4606.   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
  4607.   len = Math.sqrt(dx*dx+dy*dy);\
  4608.   ctx.translate(x2,y2);\
  4609.   ctx.rotate(Math.atan2(dy,dx));\
  4610.   ctx.lineCap = \"round\";\
  4611.   ctx.beginPath();\
  4612.   ctx.moveTo(0,0);\
  4613.   ctx.lineTo(-len,0);\
  4614.   ctx.closePath();\
  4615.   ctx.stroke();\
  4616.   ctx.beginPath();\
  4617.   ctx.moveTo(0,0);\
  4618.   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  4619.   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  4620.   ctx.closePath();\
  4621.   ctx.fill();\
  4622.   if( type == 2 ){\
  4623.     ctx.restore();\
  4624.     ctx.save();\
  4625.     ctx.translate(x1,y1);\
  4626.     ctx.rotate(Math.atan2(-dy,-dx));\
  4627.     ctx.beginPath();\
  4628.     ctx.moveTo(0,0);\
  4629.     ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  4630.     ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  4631.     ctx.closePath();\
  4632.     ctx.stroke();\
  4633.     ctx.fill();\
  4634.   }\
  4635.  }\
  4636.  ctx.restore();\
  4637.  return;\
  4638. };");
  4639.     break;
  4640.  
  4641.     case DRAW_VIDEO:/* not  used for userdraw */
  4642. fprintf(js_include_file,"\n<!-- draw video -->\n\
  4643. draw_video = function(canvas_root_id,x,y,w,h,URL){\
  4644. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  4645. var video_div = document.createElement(\"div\");\
  4646. canvas_div.appendChild(video_div);\
  4647. video_div.style.position = \"absolute\";\
  4648. video_div.style.left = x+\"px\";\
  4649. video_div.style.top = y+\"px\";\
  4650. video_div.style.width = w+\"px\";\
  4651. video_div.style.height = h+\"px\";\
  4652. var video = document.createElement(\"video\");\
  4653. video_div.appendChild(video);\
  4654. video.style.width = w+\"px\";\
  4655. video.style.height = h+\"px\";\
  4656. video.autobuffer = true;\
  4657. video.controls = true;video.autoplay = false;\
  4658. var src = document.createElement(\"source\");\
  4659. src.type = \"video/mp4\";\
  4660. src.src = URL;\
  4661. video.appendChild(src);\
  4662. video.load();\
  4663. return;\
  4664. };");    
  4665.     break;
  4666.    
  4667.     case DRAW_AUDIO:/* not used for userdraw */
  4668. fprintf(js_include_file,"\n<!-- draw audio -->\n\
  4669. draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
  4670. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  4671. var audio_div = document.createElement(\"div\");\
  4672. canvas_div.appendChild(audio_div);\
  4673. audio_div.style.position = \"absolute\";\
  4674. audio_div.style.left = x+\"px\";\
  4675. audio_div.style.top = y+\"px\";\
  4676. audio_div.style.width = w+\"px\";\
  4677. audio_div.style.height = h+\"px\";\
  4678. var audio = document.createElement(\"audio\");\
  4679. audio_div.appendChild(audio);\
  4680. audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
  4681. audio.autobuffer = true;\
  4682. if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;}\
  4683. if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;}\
  4684. var src1 = document.createElement(\"source\");\
  4685. src1.type = \"audio/ogg\";\
  4686. src1.src = URL1;\
  4687. audio.appendChild(src1);\
  4688. var src2 = document.createElement(\"source\");\
  4689. src2.type = \"audio/mpeg\";\
  4690. src2.src = URL2;\
  4691. audio.appendChild(src2);\
  4692. audio.load();\
  4693. return;\
  4694. };");
  4695.     break;
  4696.    
  4697.     case DRAW_HTTP:/* not  used for userdraw */
  4698. fprintf(js_include_file,"\n<!-- draw http -->\n\
  4699. draw_http = function(canvas_root_id,x,y,w,h,URL){\
  4700. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  4701. var http_div = document.createElement(\"div\");\
  4702. var iframe = document.createElement(\"iframe\");\
  4703. canvas_div.appendChild(http_div);\
  4704. http_div.appendChild(iframe);\
  4705. iframe.src = URL;\
  4706. iframe.setAttribute(\"width\",w);\
  4707. iframe.setAttribute(\"height\",h);\
  4708. return;\
  4709. };");
  4710.     break;
  4711.    
  4712.     case DRAW_XML:
  4713. fprintf(js_include_file,"\n<!-- draw xml -->\n\
  4714. draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick){\
  4715. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  4716. var xml_div = document.createElement(\"div\");\
  4717. canvas_div.appendChild(xml_div);\
  4718. xml_div.innerHTML = mathml;\
  4719. if(onclick != 0){\
  4720.  xml_div.onclick = function(){\
  4721.   reply[0] = onclick;\
  4722.   alert(\"send \"+onclick+\" ?\");\
  4723.  };\
  4724. };\
  4725. xml_div.style.position = \"absolute\";\
  4726. xml_div.style.left = x+\"px\";\
  4727. xml_div.style.top = y+\"px\";\
  4728. xml_div.style.width = w+\"px\";\
  4729. xml_div.style.height = h+\"px\";\
  4730. return;\
  4731. };"
  4732. );
  4733.     break;
  4734.     case DRAW_SGRAPH:
  4735. /*
  4736.  xstart = given
  4737.  ystart = given
  4738.  sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
  4739. */
  4740. fprintf(js_include_file,"\n<!-- draw sgraph -->\n\
  4741. draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
  4742. var obj;if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){obj = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{ obj = create_canvas%d(canvas_type,xsize,ysize);};\
  4743. var ctx = obj.getContext(\"2d\");\
  4744. ctx.font = fontfamily;\
  4745. var minor_opacity = 0.8*opacity;\
  4746. ctx.clearRect(0,0,xsize,ysize);\
  4747. var d_x =  1.8*font_size;\
  4748. var d_y =  ctx.measureText(\"+ymax+\").width;\
  4749. var dx = xsize / (xmax - xmin);\
  4750. var dy = ysize / (ymax - ymin);\
  4751. var zero_x = d_y + dx;\
  4752. var zero_y = ysize - dy - d_x;\
  4753. var snor_x;\
  4754. if( xstart != xmin){\
  4755.  snor_x = 0.1*xsize;\
  4756. }\
  4757. else\
  4758. {\
  4759.  snor_x = 0;\
  4760.  xstart = xmin;\
  4761. };\
  4762. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  4763. ctx.lineWidth = 2;\
  4764. ctx.beginPath();\
  4765. ctx.moveTo(xsize,zero_y);\
  4766. ctx.lineTo(zero_x,zero_y);\
  4767. ctx.lineTo(zero_x,0);\
  4768. ctx.stroke();\
  4769. ctx.closePath();\
  4770. ctx.beginPath();\
  4771. ctx.moveTo(zero_x,zero_y);\
  4772. ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
  4773. ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
  4774. ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
  4775. ctx.lineTo(zero_x + snor_x,zero_y);\
  4776. ctx.stroke();\
  4777. ctx.closePath();\
  4778. ctx.beginPath();\
  4779. var num = xstart;\
  4780. var flipflop = 1;\
  4781. var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
  4782. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  4783.   if( 0.5*ctx.measureText(num).width > step_x ){\
  4784.    if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};\
  4785.   };\
  4786.   if( flipflop == 1){\
  4787.    ctx.fillText(num,x - 0.5*ctx.measureText(num).width,zero_y+font_size);\
  4788.   }\
  4789.   else\
  4790.   {\
  4791.    ctx.fillText(num,x - 0.5*ctx.measureText(num).width,zero_y+2*font_size);\
  4792.   }\
  4793.   num = num + xmajor;\
  4794. };\
  4795. ctx.stroke();\
  4796. ctx.closePath();\
  4797. ctx.lineWidth = 1;\
  4798. ctx.beginPath();\
  4799. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  4800.   ctx.moveTo(x,zero_y);\
  4801.   ctx.lineTo(x,0);\
  4802. };\
  4803. ctx.stroke();\
  4804. ctx.closePath();\
  4805. if( xminor > 1){\
  4806.  ctx.lineWidth = 0.5;\
  4807.  ctx.beginPath();\
  4808.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  4809.  var minor_step_x = step_x / xminor;\
  4810.  var nx;\
  4811.  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
  4812.    num = 1;\
  4813.    for(var p = 1 ; p < xminor ; p++){\
  4814.     nx = x + num*minor_step_x;\
  4815.     ctx.moveTo(nx,zero_y);\
  4816.     ctx.lineTo(nx,0);\
  4817.     num++;\
  4818.    };\
  4819.  };\
  4820.  ctx.stroke();\
  4821.  ctx.closePath();\
  4822.  ctx.beginPath();\
  4823.  ctx.lineWidth = 2;\
  4824.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  4825.  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  4826.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
  4827.  };\
  4828.  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
  4829.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
  4830.  };\
  4831.  ctx.stroke();\
  4832.  ctx.closePath();\
  4833.  ctx.lineWidth = 0.5;\
  4834. };\
  4835. xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
  4836. if( ystart != ymin){\
  4837.  snor_y = 0.1*ysize;\
  4838. }\
  4839. else\
  4840. {\
  4841.  snor_y = 0;\
  4842.  ystart = ymin;\
  4843. };\
  4844. ctx.lineWidth = 2;\
  4845. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  4846. ctx.beginPath();\
  4847. ctx.moveTo(zero_x,zero_y);\
  4848. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
  4849. ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
  4850. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
  4851. ctx.lineTo(zero_x,zero_y - snor_y);\
  4852. ctx.stroke();\
  4853. ctx.closePath();\
  4854. ctx.beginPath();\
  4855. ctx.lineWidth = 1;\
  4856. num = ystart;\
  4857. var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
  4858. for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
  4859.  ctx.moveTo(zero_x,y);\
  4860.  ctx.lineTo(xsize,y);\
  4861.  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
  4862.  num = num + ymajor;\
  4863. };\
  4864. ctx.stroke();\
  4865. ctx.closePath();\
  4866. if( yminor > 1){\
  4867.  ctx.lineWidth = 0.5;\
  4868.  ctx.beginPath();\
  4869.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  4870.  var minor_step_y = step_y / yminor;\
  4871.  var ny;\
  4872.  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
  4873.   num = 1;\
  4874.   for(var p = 1 ;p < yminor;p++){\
  4875.     ny = y + num*minor_step_y;\
  4876.     ctx.moveTo(zero_x,ny);\
  4877.     ctx.lineTo(xsize,ny);\
  4878.     num++;\
  4879.    };\
  4880.  };\
  4881.  ctx.stroke();\
  4882.  ctx.closePath();\
  4883.  ctx.lineWidth = 2;\
  4884.  ctx.beginPath();\
  4885.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  4886.  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
  4887.   ctx.moveTo(zero_x,y);\
  4888.   ctx.lineTo(zero_x+12,y);\
  4889.  };\
  4890.  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
  4891.   ctx.moveTo(zero_x,y);\
  4892.   ctx.lineTo(zero_x+6,y);\
  4893.  };\
  4894.  ctx.stroke();\
  4895.  ctx.closePath();\
  4896. };\
  4897. ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
  4898. if( typeof legend%d  !== 'undefined' ){\
  4899.  ctx.globalAlpha = 1.0;\
  4900.  var y_offset = 2*font_size;\
  4901.  var txt;var txt_size;\
  4902.  var x_offset = xsize - 2*font_size;\
  4903.  var l_length = legend%d.length;var barcolor = new Array();\
  4904.  if( typeof legendcolors%d !== 'undefined' ){\
  4905.   for(var p = 0 ; p < l_length ; p++){\
  4906.    barcolor[p] = legendcolors%d[p];\
  4907.   };\
  4908.  }else{\
  4909.   if( barcolor.length == 0 ){\
  4910.    for(var p = 0 ; p < l_length ; p++){\
  4911.     barcolor[p] = stroke_color;\
  4912.    };\
  4913.   };\
  4914.  };\
  4915.  for(var p = 0; p < l_length; p++){\
  4916.   ctx.fillStyle = barcolor[p];\
  4917.   txt = legend%d[p];\
  4918.   txt_size = ctx.measureText(txt).width;\
  4919.   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
  4920.   y_offset = parseInt(y_offset + 1.5*font_size);\
  4921.  };\
  4922. };\
  4923. if( typeof xaxislabel !== 'undefined' ){\
  4924.   ctx.fillStyle = \'#000000\';\
  4925.   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
  4926.   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
  4927. };\
  4928. if( typeof yaxislabel !== 'undefined'){\
  4929.   ctx.save();\
  4930.   ctx.fillStyle = \'#000000\';\
  4931.   var txt_size = ctx.measureText(yaxislabel).width;\
  4932.   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
  4933.   ctx.rotate(-0.5*Math.PI);\
  4934.   ctx.fillText(yaxislabel,0,0);\
  4935.   ctx.save();\
  4936. };\
  4937. };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  4938.     break;
  4939.  
  4940.     case DRAW_GRID:/* not used for userdraw */
  4941. fprintf(js_include_file,"\n<!-- draw grid -->\n\
  4942. draw_grid%d = function(canvas_type,precision,stroke_opacity,xmajor,ymajor,xminor,yminor,tics_length,line_width,stroke_color,axis_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_translate,vector,use_dashed,dashtype0,dashtype1,font_color,fill_opacity){\
  4943. var obj;\
  4944. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4945. obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4946. }\
  4947. else\
  4948. {\
  4949. obj = create_canvas%d(canvas_type,xsize,ysize);\
  4950. };\
  4951. var ctx = obj.getContext(\"2d\");\
  4952. ctx.clearRect(0,0,xsize,ysize);\
  4953. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4954. ctx.save();\
  4955. if( use_translate == 1 ){ctx.translate(vector[0],vector[1]);};\
  4956. if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
  4957. var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4958. ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
  4959. var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
  4960. ctx.font = font_family;\
  4961. var xstep = xsize*xmajor/(xmax - xmin);\
  4962. var ystep = ysize*ymajor/(ymax - ymin);\
  4963. var x2step = xstep / xminor;\
  4964. var y2step = ystep / yminor;\
  4965. var zero_x;var zero_y;var f_x;var f_y;\
  4966. if(xmin < 0 ){zero_x = x2px(0);f_x = 1;}else{zero_x = x2px(xmin);f_x = -1;}\
  4967. if(ymin < 0 ){zero_y = y2px(0);f_y = 1;}else{zero_y = y2px(ymin);f_y = -1;}\
  4968. ctx.beginPath();\
  4969. ctx.lineWidth = line_width;\
  4970. ctx.strokeStyle = stroke_color;\
  4971. for(var p = zero_x ; p < xsize; p = p + xstep){\
  4972. ctx.moveTo(p,0);\
  4973. ctx.lineTo(p,ysize);\
  4974. };\
  4975. for(var p = zero_x ; p > 0; p = p - xstep){\
  4976. ctx.moveTo(p,0);\
  4977. ctx.lineTo(p,ysize);\
  4978. };\
  4979. for(var p = zero_y ; p < ysize; p = p + ystep){\
  4980. ctx.moveTo(0,p);\
  4981. ctx.lineTo(xsize,p);\
  4982. };\
  4983. for(var p = zero_y ; p > 0; p = p - ystep){\
  4984. ctx.moveTo(0,p);\
  4985. ctx.lineTo(xsize,p);\
  4986. };\
  4987. if( typeof xaxislabel !== 'undefined' ){\
  4988. ctx.save();\
  4989. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  4990. var corr =  ctx.measureText(xaxislabel).width;\
  4991. ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\
  4992. ctx.restore();\
  4993. };\
  4994. if( typeof yaxislabel !== 'undefined' ){\
  4995. ctx.save();\
  4996. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  4997. corr =  ctx.measureText(yaxislabel).width;\
  4998. ctx.translate(zero_x+tics_length + font_size,corr+font_size);\
  4999. ctx.rotate(-0.5*Math.PI);\
  5000. ctx.fillText(yaxislabel,0,0);\
  5001. ctx.restore();\
  5002. };\
  5003. ctx.stroke();\
  5004. ctx.closePath();\
  5005. if( use_axis == 1 ){\
  5006. ctx.beginPath();\
  5007. ctx.strokeStyle = stroke_color;\
  5008. ctx.lineWidth = 0.6*line_width;\
  5009. for(var p = zero_x ; p < xsize; p = p + x2step){\
  5010.  ctx.moveTo(p,0);\
  5011.  ctx.lineTo(p,ysize);\
  5012. };\
  5013. for(var p = zero_x ; p > 0; p = p - x2step){\
  5014.  ctx.moveTo(p,0);\
  5015.  ctx.lineTo(p,ysize);\
  5016. };\
  5017. for(var p = zero_y ; p < ysize; p = p + y2step){\
  5018.  ctx.moveTo(0,p);\
  5019.  ctx.lineTo(xsize,p);\
  5020. };\
  5021. for(var p = zero_y ; p > 0; p = p - y2step){\
  5022.  ctx.moveTo(0,p);\
  5023.  ctx.lineTo(xsize,p);\
  5024. };\
  5025. ctx.stroke();\
  5026. ctx.closePath();\
  5027. ctx.beginPath();\
  5028. ctx.lineWidth = 2*line_width;\
  5029. ctx.strokeStyle = axis_color;\
  5030. ctx.moveTo(0,zero_y);\
  5031. ctx.lineTo(xsize,zero_y);\
  5032. ctx.moveTo(zero_x,0);\
  5033. ctx.lineTo(zero_x,ysize);\
  5034. ctx.stroke();\
  5035. ctx.closePath();\
  5036. ctx.lineWidth = line_width+0.5;\
  5037. ctx.beginPath();\
  5038. for(var p = zero_x ; p < xsize; p = p + xstep){\
  5039.  ctx.moveTo(p,zero_y-tics_length);\
  5040.  ctx.lineTo(p,zero_y+tics_length);\
  5041. };\
  5042. for(var p = zero_x ; p > 0; p = p - xstep){\
  5043.  ctx.moveTo(p,zero_y-tics_length);\
  5044.  ctx.lineTo(p,zero_y+tics_length);\
  5045. };\
  5046. for(var p = zero_y ; p < ysize; p = p + ystep){\
  5047.  ctx.moveTo(zero_x-tics_length,p);\
  5048.  ctx.lineTo(zero_x+tics_length,p);\
  5049. };\
  5050. for(var p = zero_y ; p > 0; p = p - ystep){\
  5051.  ctx.moveTo(zero_x-tics_length,p);\
  5052.  ctx.lineTo(zero_x+tics_length,p);\
  5053. };\
  5054. for(var p = zero_x ; p < xsize; p = p + x2step){\
  5055.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  5056.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  5057. };\
  5058. for(var p = zero_x ; p > 0; p = p - x2step){\
  5059.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  5060.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  5061. };\
  5062. for(var p = zero_y ; p < ysize; p = p + y2step){\
  5063.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  5064.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  5065. };\
  5066. for(var p = zero_y ; p > 0; p = p - y2step){\
  5067.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  5068.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  5069. };\
  5070. ctx.stroke();\
  5071. ctx.closePath();\
  5072. if( use_axis_numbering == 1 ){\
  5073.  var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
  5074.  if( x_strings != null ){\
  5075.   var f = 1.4;\
  5076.   var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  5077.   for(var p = 0 ; p < len ; p = p+2){\
  5078.     var x_nums = x2px(eval(x_strings[p]));\
  5079.     var x_text = x_strings[p+1];\
  5080.     corr = ctx.measureText(x_text).width;\
  5081.     skip = 1.2*corr/xstep;\
  5082.     if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
  5083.     if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
  5084.     ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
  5085.   }\
  5086.  }\
  5087.  else\
  5088.  {\
  5089.   corr=0;skip = 1;cnt = px2x(zero_x);\
  5090.   prec = Math.log(precision)/(Math.log(10));\
  5091.   for( var p = zero_x ; p < xsize ; p = p+xstep){\
  5092.    if(skip == 0 ){\
  5093.      disp_cnt = cnt.toFixed(prec);\
  5094.      corr = ctx.measureText(disp_cnt).width;\
  5095.      skip = parseInt(1.2*corr/xstep);\
  5096.      ctx.fillText(disp_cnt,p-0.5*corr,parseInt(zero_y+(1.4*f_x*font_size)));\
  5097.    }\
  5098.    else\
  5099.    {\
  5100.     skip--;\
  5101.    };\
  5102.    cnt = cnt + xmajor;\
  5103.   };\
  5104.   cnt = px2x(zero_x);skip = 1;\
  5105.   for( var p = zero_x ; p > 0 ; p = p-xstep){\
  5106.    if(skip == 0 ){\
  5107.     disp_cnt = cnt.toFixed(prec);\
  5108.     corr = ctx.measureText(disp_cnt).width;\
  5109.     skip = parseInt(1.2*corr/xstep);\
  5110.     ctx.fillText(disp_cnt,p-0.5*corr,parseInt(zero_y+(1.4*f_x*font_size)));\
  5111.    }\
  5112.    else\
  5113.    {\
  5114.     skip--;\
  5115.    };\
  5116.    cnt = cnt - xmajor;\
  5117.   };\
  5118.  };\
  5119.  if( y_strings != null ){\
  5120.   var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
  5121.   for(var p = 0 ; p < len ; p = p+2){\
  5122.    var y_nums = y2px(eval(y_strings[p]));\
  5123.    var y_text = y_strings[p+1];\
  5124.    var f = 1.4;\
  5125.    corr = 2 + tics_length + ctx.measureText(y_text).width;\
  5126.    if( corr > zero_x){corr = parseInt(zero_x+2); }\
  5127.    ctx.fillText(y_text,zero_x - corr,y_nums);\
  5128.   };\
  5129.  }\
  5130.  else\
  5131.  {\
  5132.   corr = 0;cnt = px2y(zero_y);skip = 1;\
  5133.   for( var p = zero_y ; p < ysize ; p = p+ystep){\
  5134.    if(skip == 0 ){\
  5135.     skip = parseInt(1.4*font_size/ystep);\
  5136.     disp_cnt = cnt.toFixed(prec);\
  5137.     if(f_y == 1){corr = 2 + tics_length + ctx.measureText(disp_cnt).width;}\
  5138.     ctx.fillText(disp_cnt,parseInt(zero_x - corr),parseInt(p+(0.4*font_size)));\
  5139.    }\
  5140.    else\
  5141.    {\
  5142.     skip--;\
  5143.    };\
  5144.    cnt = cnt - ymajor;\
  5145.   }\
  5146.   corr = 0;cnt = px2y(zero_y);skip = 1;\
  5147.   for( var p = zero_y ; p > 0 ; p = p-ystep){\
  5148.    if(skip == 0 ){\
  5149.     skip = parseInt(1.4*font_size/ystep);\
  5150.     disp_cnt = cnt.toFixed(prec);\
  5151.     if(f_y == 1){corr = 2 + tics_length + ctx.measureText(disp_cnt).width;}\
  5152.     ctx.fillText(disp_cnt,parseInt(zero_x - corr),parseInt(p+(0.4*font_size)));\
  5153.    }\
  5154.    else\
  5155.    {\
  5156.     skip--;\
  5157.    };\
  5158.    cnt = cnt + ymajor;\
  5159.   }\
  5160.  };\
  5161. };\
  5162. ctx.strokeStyle = stroke_color;\
  5163. ctx.lineWidth = 2;\
  5164. ctx.beginPath();\
  5165. ctx.rect(0,0,xsize,ysize);\
  5166. ctx.closePath();\
  5167. ctx.stroke();\
  5168. };\
  5169. if( typeof linegraph_0 !== 'undefined' ){\
  5170. ctx.restore();\
  5171. ctx.save();\
  5172. ctx.globalAlpha = 1.0;\
  5173. var i = 0;\
  5174. var line_name = eval('linegraph_'+i);\
  5175. while ( typeof line_name !== 'undefined' ){\
  5176.  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
  5177.  ctx.lineWidth = parseInt(line_name[1]);\
  5178.  if(line_name[2] == \"1\"){\
  5179.   var d1 = parseInt(line_name[3]);\
  5180.   var d2 = parseInt(line_name[4]);\
  5181.   if(ctx.setLineDash){ ctx.setLineDash(d1,d2); } else { ctx.mozDash = [d1,d2];};\
  5182.  }\
  5183.  else\
  5184.  {\
  5185.  if(ctx.setLineDash){ctx.setLineDash = null;}\
  5186.  if(ctx.mozDash){ctx.mozDash = null;}\
  5187.  };\
  5188.  var data_x = new Array();\
  5189.  var data_y = new Array();\
  5190.  var lb = line_name.length;\
  5191.  var idx = 0;\
  5192.  for( var p = 5 ; p < lb ; p = p + 2 ){\
  5193.   data_x[idx] = x2px(line_name[p]);\
  5194.   data_y[idx] = y2px(line_name[p+1]);\
  5195.   idx++;\
  5196.  };\
  5197.  for( var p = 0; p < idx ; p++){\
  5198.   ctx.beginPath();\
  5199.   ctx.moveTo(data_x[p],data_y[p]);\
  5200.   ctx.lineTo(data_x[p+1],data_y[p+1]);\
  5201.   ctx.stroke();\
  5202.   ctx.closePath();\
  5203.  };\
  5204.  i++;\
  5205.  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
  5206. };\
  5207. };\
  5208. var barcolor = new Array();\
  5209. if( typeof barchart%d  !== 'undefined' ){\
  5210. ctx.restore();\
  5211. ctx.save();\
  5212. ctx.globalAlpha = 1.0;\
  5213. var bar_x = new Array();\
  5214. var bar_y = new Array();\
  5215. var lb = barchart%d.length;\
  5216. var idx = 0;\
  5217. for( var p = 0 ; p < lb ; p = p + 3 ){\
  5218.  bar_x[idx] = x2px(barchart%d[p]);\
  5219.  bar_y[idx] = y2px(barchart%d[p+1]);\
  5220.  barcolor[idx] = barchart%d[p+2];\
  5221.  idx++;\
  5222. };\
  5223. var dx = parseInt(0.6*xstep);\
  5224. ctx.globalAlpha = fill_opacity;\
  5225. for( var p = 0; p < idx ; p++ ){\
  5226.  ctx.beginPath();\
  5227.  ctx.strokeStyle = barcolor[p];\
  5228.  ctx.fillStyle = barcolor[p];\
  5229.  ctx.rect(bar_x[p]-0.5*dx,bar_y[p],dx,zero_y - bar_y[p]);\
  5230.  ctx.fill();\
  5231.  ctx.stroke();\
  5232.  ctx.closePath();\
  5233. };\
  5234. };\
  5235. if( typeof legend%d  !== 'undefined' ){\
  5236. ctx.globalAlpha = 1.0;\
  5237. ctx.font = \"bold \"+font_size+\"px Ariel\";\
  5238. var y_offset = 2*font_size;\
  5239. var txt;var txt_size;\
  5240. var x_offset = xsize - 2*font_size;\
  5241. var l_length = legend%d.length;\
  5242. if( typeof legendcolors%d !== 'undefined' ){\
  5243.  for(var p = 0 ; p < l_length ; p++){\
  5244.    barcolor[p] = legendcolors%d[p];\
  5245.  };\
  5246. }else{\
  5247.  if( barcolor.length == 0 ){\
  5248.   for(var p = 0 ; p < l_length ; p++){\
  5249.    barcolor[p] = stroke_color;\
  5250.   };\
  5251.  };\
  5252. };\
  5253. for(var p = 0; p < l_length; p++){\
  5254.  ctx.fillStyle = barcolor[p];\
  5255.  txt = legend%d[p];\
  5256.  txt_size = ctx.measureText(txt).width;\
  5257.  ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
  5258.  y_offset = parseInt(y_offset + 1.5*font_size);\
  5259. };\
  5260. };\
  5261. ctx.restore();\
  5262. return;\
  5263. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  5264.     break;
  5265.    
  5266.     case DRAW_PIECHART:
  5267. fprintf(js_include_file,"\n<!-- draw piechars -->\n\
  5268. function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,font_size,font_family){\
  5269. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5270.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5271. }\
  5272. else\
  5273. {\
  5274.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5275. };\
  5276. var ld = data_color_list.length;\
  5277. var sum = 0;\
  5278. var idx = 0;\
  5279. var colors = new Array();\
  5280. var data = new Array();\
  5281. for(var p = 0;p < ld; p = p + 2){\
  5282.  data[idx] = parseFloat(data_color_list[p]);\
  5283.  sum = sum + data[idx];\
  5284.  colors[idx] = data_color_list[p+1];\
  5285.  idx++;\
  5286. };\
  5287. var ctx = obj.getContext(\"2d\");\
  5288. ctx.save();\
  5289. var angle;\
  5290. var angle_end = 0;\
  5291. var offset = Math.PI / 2;\
  5292. ctx.globalAlpha = fill_opacity;\
  5293. for(var p=0; p < idx; p++){\
  5294.  ctx.beginPath();\
  5295.  ctx.fillStyle = colors[p];\
  5296.  ctx.moveTo(x_center,y_center);\
  5297.  angle = Math.PI * (2 * data[p] / sum);\
  5298.  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
  5299.  ctx.lineTo(x_center, y_center);\
  5300.  ctx.fill();\
  5301.  ctx.closePath();\
  5302.  angle_end  = angle_end + angle;\
  5303. };\
  5304. if( typeof legend%d  !== 'undefined' ){\
  5305.  ctx.globalAlpha = 1.0;\
  5306.  ctx.font = font_size+\"px \"+font_family;\
  5307.  var y_offset = font_size; \
  5308.  var x_offset = 0;\
  5309.  var txt;var txt_size;\
  5310.  for(var p = 0; p < idx; p++){\
  5311.   ctx.fillStyle = colors[p];\
  5312.   txt = legend%d[p];\
  5313.   txt_size = ctx.measureText(txt).width;\
  5314.   if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
  5315.   ctx.fillText(legend%d[p],x_center + radius - x_offset, y_center - radius + y_offset);\
  5316.   y_offset = parseInt(y_offset + 1.5*font_size);\
  5317.  };\
  5318. };\
  5319. ctx.restore();\
  5320. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  5321.    
  5322.     break;
  5323.     case DRAW_ARCS:
  5324. fprintf(js_include_file,"\n<!-- draw arcs -->\n\
  5325. draw_arc = function(canvas_type,xc,yc,r,start,end,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_translate,vector){\
  5326. var obj;\
  5327. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5328.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5329. }\
  5330. else\
  5331. {\
  5332.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5333. };\
  5334. var ctx = obj.getContext(\"2d\");\
  5335. ctx.save();\
  5336. if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  5337. if( use_translate == 1 ){ctx.translate(vector[0],vector[1]);};\
  5338. if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  5339. if(end < start){var tmp = end;end = start;start=tmp;};\
  5340. start=360-start;\
  5341. end=360-end;\
  5342. ctx.lineWidth = line_width;\
  5343. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5344. if( use_filled == 1 ){\
  5345.  ctx.beginPath();\
  5346.  ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  5347.  var x1 = xc + r*Math.cos(Math.PI*start/180);\
  5348.  var y1 = yc + r*Math.sin(Math.PI*start/180);\
  5349.  var x2 = xc + r*Math.cos(Math.PI*end/180);\
  5350.  var y2 = yc + r*Math.sin(Math.PI*end/180);\
  5351.  ctx.beginPath();\
  5352.  ctx.moveTo(x1,y1);\
  5353.  ctx.lineTo(xc,yc);\
  5354.  ctx.moveTo(xc,yc);\
  5355.  ctx.lineTo(x2,y2);\
  5356.  ctx.closePath();\
  5357.  ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  5358.  ctx.fill();\
  5359.  ctx.stroke();\
  5360. }\
  5361. else\
  5362. {\
  5363.    ctx.beginPath();\
  5364.    ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  5365.    ctx.stroke();\
  5366.    ctx.closePath();\
  5367. }\
  5368. ctx.restore();\
  5369. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5370.    
  5371.     break;
  5372.     case DRAW_TEXTS:
  5373. fprintf(js_include_file,"\n<!-- draw text -->\n\
  5374. draw_text = function(canvas_type,x,y,font_size,font_family,stroke_color,stroke_opacity,angle2,text,use_rotate,angle,use_translate,vector){\
  5375.  var obj;\
  5376.  if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5377.   obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5378.  }\
  5379.  else\
  5380.  {\
  5381.   obj = create_canvas%d(canvas_type,xsize,ysize);\
  5382.  };\
  5383.  var ctx = obj.getContext(\"2d\");\
  5384.  if(angle2 == 0 && angle != 0){\
  5385.   ctx.save();\
  5386.   if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  5387.   if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5388.  };\
  5389.  if( font_family.indexOf('px') != null ){\
  5390.   ctx.font = font_family;\
  5391.  }\
  5392.  else\
  5393.  {\
  5394.   ctx.font = \"+font_size+'px '+font_family \";\
  5395.  };\
  5396.  ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5397.  if(angle2 != 0){\
  5398.   ctx.save();\
  5399.   ctx.translate(x,y);\
  5400.   ctx.rotate((360-angle2)*(Math.PI / 180));\
  5401.   ctx.fillText(text,0,0);\
  5402.   ctx.restore();\
  5403.  }else{ctx.fillText(text,x,y);};\
  5404. ctx.restore();\
  5405. return;\
  5406. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5407.    
  5408.     break;
  5409.     case DRAW_CURVE:
  5410. fprintf(js_include_file,"\n<!-- draw curve -->\n\
  5411. draw_curve = function(canvas_type,type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,use_rotate,angle,use_translate,vector){\
  5412. var obj;\
  5413. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5414.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5415. }\
  5416. else\
  5417. {\
  5418.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5419. };\
  5420. var ctx = obj.getContext(\"2d\");\
  5421. ctx.save();\
  5422. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  5423. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5424. ctx.beginPath();ctx.lineWidth = line_width;\
  5425. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5426. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5427. ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
  5428. for(var p = 1 ; p < x_points.length ; p++){\
  5429.  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
  5430.  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
  5431.  }\
  5432.  else\
  5433.  {\
  5434.   ctx.stroke();\
  5435.   ctx.beginPath();\
  5436.   p++;\
  5437.   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
  5438.  };\
  5439. };\
  5440. ctx.stroke();\
  5441. ctx.restore();\
  5442. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5443.     break;
  5444.    
  5445.     case DRAW_INPUTS:
  5446. fprintf(js_include_file,"\n<!-- draw input fields -->\n\
  5447. draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\
  5448. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  5449. var input = document.createElement(\"input\");\
  5450. input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  5451. input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  5452. input.setAttribute(\"size\",size);\
  5453. input.setAttribute(\"value\",value);\
  5454. if( readonly == 0 ){ input.setAttribute(\"readonly\",\"readonly\");};\
  5455. canvas_div.appendChild(input);};");
  5456.     break;
  5457.    
  5458.     case DRAW_TEXTAREAS:
  5459. fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
  5460. draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
  5461. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  5462. var textarea = document.createElement(\"textarea\");\
  5463. textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  5464. textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  5465. textarea.setAttribute(\"cols\",cols);\
  5466. textarea.setAttribute(\"rows\",rows);\
  5467. textarea.innerHTML = value;\
  5468. canvas_div.appendChild(textarea);};");
  5469.     break;
  5470.    
  5471. case DRAW_PIXELS:
  5472. fprintf(js_include_file,"\n<!-- draw pixel -->\n\
  5473. draw_setpixel = function(x,y,color,opacity,pixelsize){\
  5474. var canvas = create_canvas%d(10,xsize,ysize);\
  5475. var d = 0.5*pixelsize;\
  5476. var ctx = canvas.getContext(\"2d\");\
  5477. ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
  5478. ctx.clearRect(0,0,xsize,ysize);\
  5479. for(var p=0; p<x.length;p++){\
  5480.  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
  5481. };\
  5482. ctx.fill();ctx.stroke();\
  5483. };",canvas_root_id);
  5484. break;
  5485.  
  5486. case DRAW_CLOCK:
  5487. fprintf(js_include_file,"\n<!-- begin command clock -->\n\
  5488. var clock_canvas = create_canvas%d(%d,xsize,ysize);\
  5489. var clock_ctx = clock_canvas.getContext(\"2d\");\
  5490. var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
  5491. clock_ctx.save();\
  5492. this.type = type || 0;\
  5493. this.interaction = interaction || 0;\
  5494. this.H = H || parseInt(110*(Math.random()));\
  5495. this.M = M || parseInt(590*(Math.random()));\
  5496. this.S = S || parseInt(590*(Math.random()));\
  5497. this.xc = xc || xsize/2;\
  5498. this.yc = yc || ysize/2;\
  5499. this.radius = radius || xsize/4;\
  5500. var font_size = parseInt(0.2*this.radius);\
  5501. this.H_color = h_color || \"blue\";\
  5502. this.M_color = m_color || \"blue\";\
  5503. this.S_color = s_color || \"blue\";\
  5504. this.fg_color = fg_color || \"red\";\
  5505. this.bg_color = bg_color || \"white\";\
  5506. clock_ctx.translate(this.xc,this.yc);\
  5507. clock_ctx.beginPath();\
  5508. clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
  5509. clock_ctx.fillStyle = this.bg_color;\
  5510. clock_ctx.fill();\
  5511. clock_ctx.closePath();\
  5512. clock_ctx.beginPath();\
  5513. clock_ctx.font = font_size+\"px Arial\";\
  5514. clock_ctx.fillStyle = this.fg_color;\
  5515. clock_ctx.textAlign = \"center\";\
  5516. clock_ctx.textBaseline = 'middle';\
  5517. var angle;var x1,y1,x2,y2;\
  5518. var angle_cos;var angle_sin;\
  5519. switch(type){\
  5520. case 0:clock_ctx.beginPath();\
  5521. for(var p = 1; p <= 12 ; p++){\
  5522.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  5523.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  5524.  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  5525.  clock_ctx.moveTo(x1,y1);\
  5526.  clock_ctx.lineTo(x2,y2);\
  5527. };\
  5528. for(var p = 1; p <= 60 ; p++){\
  5529.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  5530.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  5531.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  5532.  clock_ctx.moveTo(x1,y1);\
  5533.  clock_ctx.lineTo(x2,y2);\
  5534. };\
  5535. clock_ctx.closePath();\
  5536. clock_ctx.stroke();\
  5537. break;\
  5538. case 1:\
  5539. for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 0.9*this.radius*Math.cos(angle);y1 = 0.9*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};break;\
  5540. case 2:for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 1.1*this.radius*Math.cos(angle);y1 = 1.1*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};\
  5541. clock_ctx.beginPath();\
  5542. for(var p = 1; p <= 12 ; p++){\
  5543.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  5544.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  5545.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  5546.  clock_ctx.moveTo(x1,y1);\
  5547.  clock_ctx.lineTo(x2,y2);\
  5548. };\
  5549. for(var p = 1; p <= 60 ; p++){\
  5550.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  5551.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  5552.  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  5553.  clock_ctx.moveTo(x1,y1);\
  5554.  clock_ctx.lineTo(x2,y2);\
  5555. };\
  5556. clock_ctx.closePath();\
  5557. clock_ctx.stroke();\
  5558. break;\
  5559. };\
  5560. angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
  5561. clock_ctx.rotate(angle);\
  5562. clock_ctx.beginPath();\
  5563. clock_ctx.moveTo(-3, -2);\
  5564. clock_ctx.lineTo(-3, 2);\
  5565. clock_ctx.lineTo(this.radius * 0.7, 1);\
  5566. clock_ctx.lineTo(this.radius  * 0.7, -1);\
  5567. clock_ctx.fillStyle = this.H_color;\
  5568. clock_ctx.fill();\
  5569. clock_ctx.rotate(-angle);\
  5570. angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
  5571. clock_ctx.rotate(angle);\
  5572. clock_ctx.beginPath();\
  5573. clock_ctx.moveTo(-3, -2);\
  5574. clock_ctx.lineTo(-3, 2);\
  5575. clock_ctx.lineTo(this.radius  * 0.8, 1);\
  5576. clock_ctx.lineTo(this.radius  * 0.8, -1);\
  5577. clock_ctx.fillStyle = this.M_color;\
  5578. clock_ctx.fill();\
  5579. clock_ctx.rotate(-angle);\
  5580. angle = (this.S - 15) * 2 * Math.PI / 60;\
  5581. clock_ctx.rotate(angle);\
  5582. clock_ctx.beginPath();\
  5583. clock_ctx.moveTo(0,0);\
  5584. clock_ctx.lineTo(this.radius  * 0.95, 0);\
  5585. clock_ctx.lineTo(this.radius  * 0.9, -1);\
  5586. clock_ctx.strokeStyle = this.S_color;\
  5587. clock_ctx.stroke();\
  5588. clock_ctx.restore();\
  5589. };",canvas_root_id,CLOCK_CANVAS);
  5590. break;
  5591.  
  5592. case DRAW_LATTICE:
  5593. fprintf(js_include_file,"\n<!-- draw lattice -->\n\
  5594. draw_lattice = function(canvas_type,line_width,x0,y0,dx1,dy1,dx2,dy2,n1,n2,fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_translate,vector){\
  5595. var obj;\
  5596. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5597.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5598. }\
  5599. else\
  5600. {\
  5601.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5602. };\
  5603. var ctx = obj.getContext(\"2d\");\
  5604. ctx.save();\
  5605. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  5606. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5607. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5608. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5609. var radius = line_width;\
  5610. var x = 0;\
  5611. var y = 0;\
  5612. var x_step_px = xsize/(xmax-xmin);\
  5613. var y_step_px = ysize/(ymax-ymin);\
  5614. var xv1 = dx1*x_step_px;\
  5615. var yv1 = dy1*y_step_px;\
  5616. var xv2 = dx2*x_step_px;\
  5617. var yv2 = dy2*y_step_px;\
  5618. for(var p = 0; p < n1 ;p++){\
  5619.  x = p*xv1 + x0;\
  5620.  y = p*yv1 + y0;\
  5621.  for(var c = 0; c < n2 ; c++){\
  5622.   ctx.beginPath();\
  5623.   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
  5624.   ctx.fill();\
  5625.   ctx.stroke();\
  5626.   ctx.closePath();\
  5627.  };\
  5628. };\
  5629. ctx.restore();\
  5630. return;\
  5631. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5632.     break;
  5633. case DRAW_XYLOGSCALE:
  5634. fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\
  5635. draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,precision){\n\
  5636. var obj;\n\
  5637. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\
  5638.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\
  5639. }\n\
  5640. else\n\
  5641. {\n\
  5642.  obj = create_canvas%d(canvas_type,xsize,ysize);\n\
  5643. };\n\
  5644. var ctx = obj.getContext(\"2d\");\n\
  5645. ctx.clearRect(0,0,xsize,ysize);\
  5646. ctx.save();\n\
  5647. var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
  5648. var x_min = Math.log(xmin)/Math.log(xlogbase);\n\
  5649. var x_max = Math.log(xmax)/Math.log(xlogbase);\n\
  5650. var y_min = Math.log(ymin)/Math.log(ylogbase);\n\
  5651. var y_max = Math.log(ymax)/Math.log(ylogbase);\n\
  5652. if(use_axis_numbering == 1){\
  5653.  ctx.font = font_family;\n\
  5654.  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\n\
  5655.  ymarge = parseInt(1.5*font_size);\n\
  5656.  ctx.save();\n\
  5657.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\n\
  5658.  ctx.rect(0,0,xmarge,ysize);\n\
  5659.  ctx.rect(0,ysize-ymarge,xsize,ysize);\n\
  5660.  ctx.fill();\n\
  5661.  ctx.restore();\n\
  5662. }else{xmarge = 0;ymarge = 0;};\n\
  5663. if( typeof xaxislabel !== 'undefined' ){\
  5664.  ctx.save();\n\
  5665.  ctx.font = \"italic \"+font_size+\"px Ariel\";\n\
  5666.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5667.  corr =  ctx.measureText(xaxislabel).width;\n\
  5668.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\n\
  5669.  ctx.restore();\n\
  5670. };\n\
  5671. if( typeof yaxislabel !== 'undefined' ){\
  5672.  ctx.save();\n\
  5673.  ctx.font = \"italic \"+font_size+\"px Ariel\";\n\
  5674.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5675.  corr = ctx.measureText(yaxislabel).width;\n\
  5676.  ctx.translate(xmarge+font_size,corr+font_size);\n\
  5677.  ctx.rotate(-0.5*Math.PI);\n\
  5678.  ctx.fillText(yaxislabel,0,0);\n\
  5679.  ctx.restore();\n\
  5680. };\n\
  5681. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5682. ctx.lineWidth = line_width;\n\n\
  5683. for(var p = x_min; p <= x_max ; p++){\n\
  5684.  num = Math.pow(xlogbase,p);\n\n\
  5685.  for(var i = 1 ; i < xlogbase ; i++){\n\
  5686.   x_e = x2px(i*num);\n\n\
  5687.   if( i == 1 ){\
  5688.    ctx.lineWidth = line_width;\n\n\
  5689.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\n\
  5690.    if( use_axis_numbering == 1 && p > x_min){\
  5691.      xtxt = xlogbase+'^'+p.toFixed(0);\n\
  5692.      corr = 0.5*(ctx.measureText(xtxt).width);\n\
  5693.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\n\
  5694.    };\n\
  5695.   }else{\
  5696.    ctx.lineWidth = 0.2*line_width;\n\n\
  5697.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\n\
  5698.   };\n\
  5699.   if( x_e >= xmarge ){\
  5700.    ctx.beginPath();\n\
  5701.    ctx.moveTo(x_e,0);\n\
  5702.    ctx.lineTo(x_e,ysize - ymarge);\n\n\
  5703.    ctx.stroke();\n\
  5704.    ctx.closePath();\n\
  5705.   };\
  5706.  };\n\
  5707. };\n\
  5708. for(var p = y_min; p <= y_max ; p++){\n\
  5709.  num = Math.pow(ylogbase,p);\n\
  5710.  for(var i = 1 ; i < ylogbase ; i++){\n\
  5711.   y_e = y2px(i*num);\n\
  5712.   if( i == 1 ){\n\
  5713.    ctx.lineWidth = line_width;\n\
  5714.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  5715.    if( use_axis_numbering == 1 && p > y_min){\n\
  5716.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\n\
  5717.    };\n\
  5718.   }else{\n\
  5719.    ctx.lineWidth = 0.2*line_width;\n\
  5720.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\n\
  5721.   };\n\
  5722.   ctx.beginPath();\n\
  5723.   ctx.moveTo(xmarge,y_e);\n\
  5724.   ctx.lineTo(xsize,y_e);\n\
  5725.   ctx.stroke();\n\
  5726.   ctx.closePath();\n\
  5727.  };\n\
  5728. };\n\
  5729. ctx.restore();\
  5730. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  5731.     break;
  5732.  
  5733. case DRAW_XLOGSCALE:
  5734. fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\
  5735. draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,ymajor,yminor,precision){\n\
  5736. var obj;\n\
  5737. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\
  5738.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\
  5739. }\n\
  5740. else\n\
  5741. {\n\
  5742.  obj = create_canvas%d(canvas_type,xsize,ysize);\n\
  5743. };\n\
  5744. var ctx = obj.getContext(\"2d\");\n\
  5745. ctx.clearRect(0,0,xsize,ysize);\
  5746. ctx.save();\n\
  5747. ctx.lineWidth = line_width;\n\
  5748. var prec = Math.log(precision)/Math.log(10);\
  5749. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  5750. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  5751. var y_min = 0;var y_max = ysize;var x_e;var corr;\
  5752. var xtxt;var ytxt;var num;var xmarge;var ymarge;\
  5753. if(use_axis_numbering == 1){\
  5754.  ctx.font = font_family;\n\
  5755.  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\n\
  5756.  ymarge = parseInt(1.5*font_size);\n\
  5757.  ctx.save();\n\
  5758.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\n\
  5759.  ctx.rect(0,0,xmarge,ysize);\n\
  5760.  ctx.rect(0,ysize-ymarge,xsize,ysize);\n\
  5761.  ctx.fill();\n\
  5762.  ctx.restore();\n\
  5763. }else{xmarge = 0;ymarge = 0;};\n\
  5764. if( typeof xaxislabel !== 'undefined' ){\
  5765.  ctx.save();\n\
  5766.  ctx.font = \"italic \"+font_size+\"px Ariel\";\n\
  5767.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5768.  corr =  ctx.measureText(xaxislabel).width;\n\
  5769.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\n\
  5770.  ctx.restore();\n\
  5771. };\n\
  5772. if( typeof yaxislabel !== 'undefined' ){\
  5773.  ctx.save();\n\
  5774.  ctx.font = \"italic \"+font_size+\"px Ariel\";\n\
  5775.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5776.  corr = ctx.measureText(yaxislabel).width;\n\
  5777.  ctx.translate(xmarge+font_size,corr+font_size);\n\
  5778.  ctx.rotate(-0.5*Math.PI);\n\
  5779.  ctx.fillText(yaxislabel,0,0);\n\
  5780.  ctx.restore();\n\
  5781. };\n\
  5782. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5783. ctx.lineWidth = line_width;\n\n\
  5784. for(var p = x_min; p <= x_max ; p++){\n\
  5785.  num = Math.pow(xlogbase,p);\n\
  5786.  for(var i = 1 ; i < xlogbase ; i++){\n\
  5787.   x_e = x2px(i*num);\n\
  5788.   if( i == 1 ){\
  5789.     ctx.lineWidth = line_width;\n\
  5790.     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  5791.    if( use_axis_numbering == 1 && p > x_min ){\
  5792.      xtxt = xlogbase+'^'+p.toFixed(0);\
  5793.      corr = 0.5*(ctx.measureText(xtxt).width);\
  5794.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  5795.    };\
  5796.   }else{\
  5797.    ctx.lineWidth = 0.2*line_width;\n\
  5798.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  5799.   };\
  5800.   if( x_e >= xmarge ){\
  5801.    ctx.beginPath();\n\
  5802.    ctx.moveTo(x_e,0);\n\
  5803.    ctx.lineTo(x_e,ysize - ymarge);\n\n\
  5804.    ctx.stroke();\n\
  5805.    ctx.closePath();\n\
  5806.   };\
  5807.  };\
  5808. };\n\
  5809. var stepy = Math.abs(y2px(ymajor) - y2px(0));\
  5810. var minor_step = stepy / yminor;\
  5811. for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
  5812.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  5813.  ctx.lineWidth = line_width;\n\
  5814.  ctx.beginPath();\n\
  5815.  ctx.moveTo(xmarge,y);\n\
  5816.  ctx.lineTo(xsize,y);\n\
  5817.  ctx.stroke();\n\
  5818.  ctx.closePath();\n\
  5819.  if( use_axis_numbering == 1){\
  5820.   ytxt = (px2y(y)).toFixed(prec);\
  5821.   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
  5822.  };\
  5823.  for(var dy = 1 ; dy < yminor ; dy++){\
  5824.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  5825.   ctx.lineWidth = 0.2*line_width;\n\
  5826.   ctx.beginPath();\n\
  5827.   ctx.moveTo(xmarge,y+dy*minor_step);\
  5828.   ctx.lineTo(xsize,y+dy*minor_step);\n\
  5829.   ctx.stroke();\n\
  5830.   ctx.closePath();\n\
  5831.  };\
  5832. };\
  5833. ctx.restore();\n\
  5834. };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  5835.     break;
  5836. case DRAW_YLOGSCALE:
  5837. fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\
  5838. draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,xmajor,xminor,precision){\n\
  5839. var obj;\n\
  5840. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\
  5841.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\
  5842. }\n\
  5843. else\n\
  5844. {\n\
  5845.  obj = create_canvas%d(canvas_type,xsize,ysize);\n\
  5846. };\n\
  5847. var ctx = obj.getContext(\"2d\");\n\
  5848. ctx.clearRect(0,0,xsize,ysize);\
  5849. ctx.save();\n\
  5850. ctx.lineWidth = line_width;\n\
  5851. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  5852. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  5853. var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;\
  5854. if(use_axis_numbering == 1){\
  5855.  ctx.font = font_family;\n\
  5856.  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\n\
  5857.  ymarge = 2*font_size;\n\
  5858.  ctx.save();\n\
  5859.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\n\
  5860.  ctx.rect(0,0,xmarge,ysize);\n\
  5861.  ctx.rect(0,ysize-ymarge,xsize,ysize);\n\
  5862.  ctx.fill();\n\
  5863.  ctx.restore();\n\
  5864. }else{xmarge = 0;ymarge = 0;};\n\
  5865. if( typeof xaxislabel !== 'undefined' ){\
  5866.  ctx.save();\n\
  5867.  ctx.font = \"italic \"+font_size+\"px Ariel\";\n\
  5868.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5869.  corr =  ctx.measureText(xaxislabel).width;\n\
  5870.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\n\
  5871.  ctx.restore();\n\
  5872. };\n\
  5873. if( typeof yaxislabel !== 'undefined' ){\
  5874.  ctx.save();\n\
  5875.  ctx.font = \"italic \"+font_size+\"px Ariel\";\n\
  5876.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5877.  corr = ctx.measureText(yaxislabel).width;\n\
  5878.  ctx.translate(xmarge+font_size,corr+font_size);\n\
  5879.  ctx.rotate(-0.5*Math.PI);\n\
  5880.  ctx.fillText(yaxislabel,0,0);\n\
  5881.  ctx.restore();\n\
  5882. };\n\
  5883. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5884. ctx.lineWidth = line_width;\n\n\
  5885. for(var p = y_min; p <= y_max ; p++){\n\
  5886.  num = Math.pow(ylogbase,p);\n\
  5887.  for(var i = 1 ; i < ylogbase ; i++){\n\
  5888.   y_e = y2px(i*num);\n\
  5889.   if( i == 1 ){\
  5890.    ctx.lineWidth = line_width;\n\
  5891.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  5892.    if( use_axis_numbering == 1 && p > y_min){\
  5893.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  5894.    };\
  5895.   }else{\
  5896.    ctx.lineWidth = 0.2*line_width;\n\
  5897.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  5898.   };\
  5899.   ctx.beginPath();\n\
  5900.   ctx.moveTo(xmarge,y_e);\n\
  5901.   ctx.lineTo(xsize,y_e);\n\
  5902.   ctx.stroke();\n\
  5903.   ctx.closePath();\n\
  5904.  };\n\
  5905. };\n\
  5906. var stepx = Math.abs(x2px(xmajor) - x2px(0));\
  5907. var minor_step = stepx / xminor;\
  5908. var prec = Math.log(precision)/Math.log(10);\
  5909. var xtxt;var corr;var flip = 0;\
  5910. for(var x = stepx ; x < xsize ; x = x + stepx){\
  5911.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  5912.  ctx.lineWidth = line_width;\n\
  5913.  ctx.beginPath();\n\
  5914.  ctx.moveTo(x,ysize-ymarge);\n\
  5915.  ctx.lineTo(x,0);\n\
  5916.  ctx.stroke();\n\
  5917.  ctx.closePath();\n\
  5918.  if( use_axis_numbering == 1){\
  5919.   xtxt = (px2x(x)).toFixed(prec);\
  5920.   corr = 0.5*(ctx.measureText(xtxt).width);\
  5921.   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
  5922.   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
  5923.  };\
  5924.  for(var dx = 1 ; dx < xminor ; dx++){\
  5925.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  5926.   ctx.lineWidth = 0.2*line_width;\n\
  5927.   ctx.beginPath();\n\
  5928.   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
  5929.   ctx.lineTo(x+dx*minor_step,0);\n\
  5930.   ctx.stroke();\n\
  5931.   ctx.closePath();\n\
  5932.  };\
  5933. };\
  5934. ctx.restore();\n\
  5935. };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  5936.  
  5937.     break;
  5938.  
  5939.  
  5940.     default:break;
  5941.    }
  5942.   }
  5943.  }
  5944.   return;
  5945. }
  5946.  
  5947. void check_string_length(int L){
  5948.  if(L<1 || L > MAX_BUFFER-1){
  5949.   canvas_error("problem with your arguments to command...");
  5950.  }
  5951.  return;
  5952. }
  5953.  
  5954.  
  5955. int get_token(FILE *infile){
  5956.         int     c,i=0;
  5957.         char    temp[MAX_INT], *input_type;
  5958.         char    *line="line",
  5959.         *audio="audio",
  5960.         *blink="blink",
  5961.         *arrowhead="arrowhead",
  5962.         *crosshairsize="crosshairsize",
  5963.         *crosshair="crosshair",
  5964.         *crosshairs="crosshairs",
  5965.         *audioobject="audioobject",
  5966.         *style="style",
  5967.         *mouse="mouse",
  5968.         *userdraw="userdraw",
  5969.         *highlight="highlight",
  5970.         *http="http",
  5971.         *rays="rays",
  5972.         *dashtype="dashtype",
  5973.         *dashed="dashed",
  5974.         *filled="filled",
  5975.         *lattice="lattice",
  5976.         *parallel="parallel",
  5977.         *segment="segment",
  5978.         *dsegment="dsegment",
  5979.         *seg="seg",
  5980.         *bgimage="bgimage",
  5981.         *bgcolor="bgcolor",
  5982.         *strokecolor="strokecolor",
  5983.         *backgroundimage="backgroundimage",
  5984.         *text="text",
  5985.         *textup="textup",
  5986.         *mouseprecision="mouseprecision",
  5987.         *precision="precision",
  5988.         *plotsteps="plotsteps",
  5989.         *plotstep="plotstep",
  5990.         *tsteps="tsteps",
  5991.         *curve="curve",
  5992.         *dcurve="dcurve",
  5993.         *plot="plot",
  5994.         *dplot="dplot",
  5995.         *fontsize="fontsize",
  5996.         *fontcolor="fontcolor",
  5997.         *axis="axis",
  5998.         *axisnumbering="axisnumbering",
  5999.         *axisnumbers="axisnumbers",
  6000.         *arrow="arrow",
  6001.         *darrow="darrow",
  6002.         *arrow2="arrow2",
  6003.         *darrow2="darrow2",
  6004.         *zoom="zoom",
  6005.         *grid="grid",
  6006.         *hline="hline",
  6007.         *drag="drag",
  6008.         *horizontalline="horizontalline",
  6009.         *vline="vline",
  6010.         *verticalline="verticalline",
  6011.         *triangle="triangle",
  6012.         *ftriangle="ftriangle",
  6013.         *mathml="mathml",
  6014.         *html="html",
  6015.         *input="input",
  6016.         *button="button",
  6017.         *inputstyle="inputstyle",
  6018.         *textarea="textarea",
  6019.         *trange="trange",
  6020.         *ranget="ranget",
  6021.         *xrange="xrange",
  6022.         *yrange="yrange",
  6023.         *rangex="rangex",
  6024.         *rangey="rangey",
  6025.         *polyline="polyline",
  6026.         *lines="lines",
  6027.         *poly="poly",
  6028.         *polygon="polygon",
  6029.         *fpolygon="fpolygon",
  6030.         *fpoly="fpoly",
  6031.         *filledpoly="filledpoly",
  6032.         *filledpolygon="filledpolygon",
  6033.         *rect="rect",
  6034.         *frect="frect",
  6035.         *rectangle="rectangle",
  6036.         *frectangle="frectangle",
  6037.         *square="square",
  6038.         *fsquare="fsquare",
  6039.         *dline="dline",
  6040.         *arc="arc",
  6041.         *filledarc="filledarc",
  6042.         *size="size",
  6043.         *string="string",
  6044.         *stringup="stringup",
  6045.         *copy="copy",
  6046.         *copyresized="copyresized",
  6047.         *opacity="opacity",
  6048.         *transparent="transparent",
  6049.         *fill="fill",
  6050.         *slider="slider",
  6051.         *point="point",
  6052.         *points="points",
  6053.         *linewidth="linewidth",
  6054.         *circle="circle",
  6055.         *fcircle="fcircle",
  6056.         *disk="disk",
  6057.         *comment="#",
  6058.         *end="end",
  6059.         *ellipse="ellipse",
  6060.         *fellipse="fellipse",
  6061.         *rotate="rotate",
  6062.         *affine="affine",
  6063.         *killaffine="killaffine",
  6064.         *fontfamily="fontfamily",
  6065.         *fillcolor="fillcolor",
  6066.         *clicktile="clicktile",
  6067.         *clicktile_colors="clicktile_colors",
  6068.         *translation="translation",
  6069.         *translate="translate",
  6070.         *killtranslation="killtranslation",
  6071.         *killtranslate="killtranslate",
  6072.         *onclick="onclick",
  6073.         *roundrect="roundrect",
  6074.         *froundrect="froundrect",
  6075.         *roundrectangle="roundrectangle",
  6076.         *patternfill="patternfill",
  6077.         *hatchfill="hatchfill",
  6078.         *diafill="diafill",
  6079.         *diamondfill="diamondfill",
  6080.         *dotfill="dotfill",
  6081.         *gridfill="gridfill",
  6082.         *imagefill="imagefill",
  6083.         *xlogbase="xlogbase",
  6084.         *ylogbase="ylogbase",
  6085.         *xlogscale="xlogscale",
  6086.         *ylogscale="ylogscale",
  6087.         *xylogscale="xylogscale",
  6088.         *intooltip="intooltip",
  6089.         *replyformat="replyformat",
  6090.         *floodfill="floodfill",
  6091.         *filltoborder="filltoborder",
  6092.         *clickfill="clickfill",
  6093.         *setpixel="setpixel",
  6094.         *pixels="pixels",
  6095.         *pixelsize="pixelsize",
  6096.         *clickfillmarge="clickfillmarge",
  6097.         *xaxis="xaxis",
  6098.         *yaxis="yaxis",
  6099.         *xaxistext="xaxistext",
  6100.         *yaxistext="yaxistext",
  6101.         *piechart="piechart",
  6102.         *legend="legend",
  6103.         *legendcolors="legendcolors",
  6104.         *xlabel="xlabel",
  6105.         *ylabel="ylabel",
  6106.         *barchart="barchart",
  6107.         *linegraph="linegraph",
  6108.         *clock="clock",
  6109.         *animate="animate",
  6110.         *video="video",
  6111.         *status="status",
  6112.         *snaptogrid="snaptogrid",
  6113.         *xsnaptogrid="xsnaptogrid",
  6114.         *ysnaptogrid="ysnaptogrid",
  6115.         *userinput_xy="userinput_xy",
  6116.         *usertextarea_xy="usertextarea_xy",
  6117.         *sgraph="sgraph";
  6118.  
  6119.         while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')){
  6120.             if( i == 0 && (c == ' ' || c == '\t') ){
  6121.         continue; /* white spaces or tabs allowed before first command identifier */
  6122.             }
  6123.             else
  6124.             {
  6125.         if( c == ' ' || c == '\t' ){
  6126.             break;
  6127.         }
  6128.         else
  6129.         {
  6130.             temp[i] = c;
  6131.             if(i > MAX_INT - 2){canvas_error("command string too long !");}
  6132.             i++;
  6133.         }
  6134.             }
  6135.             if(temp[0] == '#') break;
  6136.         }
  6137.         if (c == EOF) finished = 1;
  6138.  
  6139.         if (c == '\n' || c == '\r') {
  6140.         line_number++;
  6141.         if (i == 0) { return EMPTY; }
  6142.         } else if (c == EOF) {
  6143.         return 0;
  6144.         }
  6145.  
  6146.         temp[i]='\0';
  6147.         input_type=(char*)my_newmem(strlen(temp));
  6148.         snprintf(input_type,sizeof(temp),"%s",temp);
  6149.  
  6150.         if( strcmp(input_type, size) == 0 ){
  6151.         free(input_type);
  6152.         return SIZE;
  6153.         }
  6154.         if( strcmp(input_type, xrange) == 0 ){
  6155.         free(input_type);
  6156.         return XRANGE;
  6157.         }
  6158.         if( strcmp(input_type, rangex) == 0 ){
  6159.         free(input_type);
  6160.         return XRANGE;
  6161.         }
  6162.         if( strcmp(input_type, trange) == 0 ){
  6163.         free(input_type);
  6164.         return TRANGE;
  6165.         }
  6166.         if( strcmp(input_type, ranget) == 0 ){
  6167.         free(input_type);
  6168.         return TRANGE;
  6169.         }
  6170.         if( strcmp(input_type, yrange) == 0 ){
  6171.         free(input_type);
  6172.         return YRANGE;
  6173.         }
  6174.         if( strcmp(input_type, rangey) == 0 ){
  6175.         free(input_type);
  6176.         return YRANGE;
  6177.         }
  6178.         if( strcmp(input_type, linewidth) == 0 ){
  6179.         free(input_type);
  6180.         return LINEWIDTH;
  6181.         }
  6182.         if( strcmp(input_type, dashed) == 0 ){
  6183.         free(input_type);
  6184.         return DASHED;
  6185.         }
  6186.         if( strcmp(input_type, dashtype) == 0 ){
  6187.         free(input_type);
  6188.         return DASHTYPE;
  6189.         }
  6190.         if( strcmp(input_type, axisnumbering) == 0 ){
  6191.         free(input_type);
  6192.         return AXIS_NUMBERING;
  6193.         }
  6194.         if( strcmp(input_type, axisnumbers) == 0 ){
  6195.         free(input_type);
  6196.         return AXIS_NUMBERING;
  6197.         }
  6198.         if( strcmp(input_type, axis) == 0 ){
  6199.         free(input_type);
  6200.         return AXIS;
  6201.         }
  6202.         if( strcmp(input_type, grid) == 0 ){
  6203.         free(input_type);
  6204.         return GRID;
  6205.         }
  6206.         if( strcmp(input_type, parallel) == 0 ){
  6207.         free(input_type);
  6208.         return PARALLEL;
  6209.         }
  6210.         if( strcmp(input_type, hline) == 0 ||  strcmp(input_type, horizontalline) == 0 ){
  6211.         free(input_type);
  6212.         return HLINE;
  6213.         }
  6214.         if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
  6215.         free(input_type);
  6216.         return VLINE;
  6217.         }
  6218.         if( strcmp(input_type, line) == 0 ){
  6219.         free(input_type);
  6220.         return LINE;
  6221.         }
  6222.         if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
  6223.         free(input_type);
  6224.         return SEGMENT;
  6225.         }
  6226.         if( strcmp(input_type, dsegment) == 0 ){
  6227.         free(input_type);
  6228.         use_dashed = TRUE;
  6229.         return SEGMENT;
  6230.         }
  6231.         if( strcmp(input_type, crosshairsize) == 0 ){
  6232.         free(input_type);
  6233.         return CROSSHAIRSIZE;
  6234.         }
  6235.         if( strcmp(input_type, arrowhead) == 0 ){
  6236.         free(input_type);
  6237.         return ARROWHEAD;
  6238.         }
  6239.         if( strcmp(input_type, crosshairs) == 0 ){
  6240.         free(input_type);
  6241.         return CROSSHAIRS;
  6242.         }
  6243.         if( strcmp(input_type, crosshair) == 0 ){
  6244.         free(input_type);
  6245.         return CROSSHAIR;
  6246.         }
  6247.         if( strcmp(input_type, onclick) == 0 ){
  6248.         free(input_type);
  6249.         return ONCLICK;
  6250.         }
  6251.         if( strcmp(input_type, drag) == 0 ){
  6252.         free(input_type);
  6253.         return DRAG;
  6254.         }
  6255.         if( strcmp(input_type, userdraw) == 0 ){
  6256.         free(input_type);
  6257.         return USERDRAW;
  6258.         }
  6259.         if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
  6260.         free(input_type);
  6261.         return STYLE;
  6262.         }
  6263.         if( strcmp(input_type, fillcolor) == 0 ){
  6264.         free(input_type);
  6265.         return FILLCOLOR;
  6266.         }
  6267.         if( strcmp(input_type, strokecolor) == 0 ){
  6268.         free(input_type);
  6269.         return STROKECOLOR;
  6270.         }
  6271.         if( strcmp(input_type, filled) == 0  ){
  6272.         free(input_type);
  6273.         return FILLED;
  6274.         }
  6275.         if( strcmp(input_type, http) == 0 ){
  6276.         free(input_type);
  6277.         return HTTP;
  6278.         }
  6279.         if( strcmp(input_type, rays) == 0 ){
  6280.         free(input_type);
  6281.         return RAYS;
  6282.         }
  6283.         if( strcmp(input_type, lattice) == 0 ){
  6284.         free(input_type);
  6285.         return LATTICE;
  6286.         }
  6287.         if( strcmp(input_type, bgimage) == 0 ){
  6288.         free(input_type);
  6289.         return BGIMAGE;
  6290.         }
  6291.         if( strcmp(input_type, bgcolor) == 0 ){
  6292.         free(input_type);
  6293.         return BGCOLOR;
  6294.         }
  6295.         if( strcmp(input_type, backgroundimage) == 0 ){
  6296.         free(input_type);
  6297.         return BGIMAGE;
  6298.         }
  6299.         if( strcmp(input_type, text) == 0 ){
  6300.         free(input_type);
  6301.         return FLY_TEXT;
  6302.         }
  6303.         if( strcmp(input_type, textup) == 0 ){
  6304.         free(input_type);
  6305.         return FLY_TEXTUP;
  6306.         }
  6307.         if( strcmp(input_type, mouse) == 0 ){
  6308.         free(input_type);
  6309.         return MOUSE;
  6310.         }
  6311.         if( strcmp(input_type, mouseprecision) == 0 ){
  6312.         free(input_type);
  6313.         return MOUSE_PRECISION;
  6314.         }
  6315.         if( strcmp(input_type, precision) == 0 ){
  6316.         free(input_type);
  6317.         return MOUSE_PRECISION;
  6318.         }
  6319.         if( strcmp(input_type, curve) == 0 ){
  6320.         free(input_type);
  6321.         return CURVE;
  6322.         }
  6323.         if( strcmp(input_type, dcurve) == 0 ){
  6324.         free(input_type);
  6325.         return CURVE;
  6326.         }
  6327.         if( strcmp(input_type, plot) == 0 ){
  6328.         free(input_type);
  6329.         return CURVE;
  6330.         }
  6331.         if( strcmp(input_type, dplot) == 0 ){
  6332.         free(input_type);
  6333.         return CURVE;
  6334.         }
  6335.         if( strcmp(input_type, plotsteps) == 0 ){
  6336.         free(input_type);
  6337.         return PLOTSTEPS;
  6338.         }
  6339.         if( strcmp(input_type, plotstep) == 0 ){
  6340.         free(input_type);
  6341.         return PLOTSTEPS;
  6342.         }
  6343.         if( strcmp(input_type, tsteps) == 0 ){
  6344.         free(input_type);
  6345.         return PLOTSTEPS;
  6346.         }
  6347.         if( strcmp(input_type, fontsize) == 0 ){
  6348.         free(input_type);
  6349.         return FONTSIZE;
  6350.         }
  6351.         if( strcmp(input_type, fontcolor) == 0 ){
  6352.         free(input_type);
  6353.         return FONTCOLOR;
  6354.         }
  6355.         if( strcmp(input_type, arrow) == 0 ){
  6356.         free(input_type);
  6357.         return ARROW;
  6358.         }
  6359.         if( strcmp(input_type, arrow2) == 0 ){
  6360.         free(input_type);
  6361.         return ARROW2;
  6362.         }
  6363.         if( strcmp(input_type, darrow) == 0 ){
  6364.         free(input_type);
  6365.         return ARROW;
  6366.         }
  6367.         if( strcmp(input_type, darrow2) == 0 ){
  6368.         free(input_type);
  6369.         use_dashed = TRUE;
  6370.         return ARROW2;
  6371.         }
  6372.         if( strcmp(input_type, zoom) == 0 ){
  6373.         free(input_type);
  6374.         return ZOOM;
  6375.         }
  6376.         if( strcmp(input_type, triangle) == 0 ){
  6377.         free(input_type);
  6378.         return TRIANGLE;
  6379.         }
  6380.         if( strcmp(input_type, ftriangle) == 0 ){
  6381.         free(input_type);
  6382.         use_filled = TRUE;
  6383.         return TRIANGLE;
  6384.         }
  6385.         if( strcmp(input_type, input) == 0 ){
  6386.         free(input_type);
  6387.         return INPUT;
  6388.         }
  6389.         if( strcmp(input_type, inputstyle) == 0 ){
  6390.         free(input_type);
  6391.         return INPUTSTYLE;
  6392.         }
  6393.         if( strcmp(input_type, textarea) == 0 ){
  6394.         free(input_type);
  6395.         return TEXTAREA;
  6396.         }
  6397.         if( strcmp(input_type, mathml) == 0 ){
  6398.         free(input_type);
  6399.         return MATHML;
  6400.         }
  6401.         if( strcmp(input_type, html) == 0 ){
  6402.         free(input_type);
  6403.         return MATHML;
  6404.         }
  6405.         if( strcmp(input_type, fontfamily) == 0 ){
  6406.         free(input_type);
  6407.         return FONTFAMILY;
  6408.         }
  6409.         if( strcmp(input_type, lines) == 0  ||  strcmp(input_type, polyline) == 0 ){
  6410.         free(input_type);
  6411.         return POLYLINE;
  6412.         }
  6413.         if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
  6414.         free(input_type);
  6415.         return RECT;
  6416.         }
  6417.         if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
  6418.         free(input_type);
  6419.         return ROUNDRECT;
  6420.         }
  6421.         if( strcmp(input_type, froundrect) == 0 ){
  6422.         free(input_type);
  6423.         use_filled = TRUE;
  6424.         return ROUNDRECT;
  6425.         }
  6426.         if( strcmp(input_type, square) == 0 ){
  6427.         free(input_type);
  6428.         return SQUARE;
  6429.         }
  6430.         if( strcmp(input_type, fsquare) == 0 ){
  6431.         free(input_type);
  6432.         use_filled = TRUE;
  6433.         return SQUARE;
  6434.         }
  6435.         if( strcmp(input_type, dline) == 0 ){
  6436.         use_dashed = TRUE;
  6437.         free(input_type);
  6438.         return LINE;
  6439.         }
  6440.         if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
  6441.         use_filled = TRUE;
  6442.         free(input_type);
  6443.         return RECT;
  6444.         }
  6445.         if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
  6446.         use_filled = TRUE;
  6447.         free(input_type);
  6448.         return CIRCLE;
  6449.         }
  6450.         if( strcmp(input_type, circle) == 0 ){
  6451.         free(input_type);
  6452.         return CIRCLE;
  6453.         }
  6454.         if( strcmp(input_type, point) == 0 ){
  6455.         free(input_type);
  6456.         return POINT;
  6457.         }
  6458.         if( strcmp(input_type, points) == 0 ){
  6459.         free(input_type);
  6460.         return POINTS;
  6461.         }
  6462.         if( strcmp(input_type, filledarc) == 0 ){
  6463.         use_filled = TRUE;
  6464.         free(input_type);
  6465.         return ARC;
  6466.         }
  6467.         if( strcmp(input_type, arc) == 0 ){
  6468.         free(input_type);
  6469.         return ARC;
  6470.         }
  6471.         if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
  6472.         free(input_type);
  6473.         return POLY;
  6474.         }
  6475.         if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
  6476.         use_filled = TRUE;
  6477.         free(input_type);
  6478.         return POLY;
  6479.         }
  6480.         if( strcmp(input_type, ellipse) == 0){
  6481.         free(input_type);
  6482.         return ELLIPSE;
  6483.         }
  6484.         if( strcmp(input_type, fill) == 0 ){
  6485.         free(input_type);
  6486.         return FLOODFILL;
  6487.         }
  6488.         if( strcmp(input_type, string) == 0 ){
  6489.         free(input_type);
  6490.         return STRING;
  6491.         }
  6492.         if( strcmp(input_type, stringup) == 0 ){
  6493.         free(input_type);
  6494.         return STRINGUP;
  6495.         }
  6496.         if( strcmp(input_type, opacity) == 0 ){
  6497.         free(input_type);
  6498.         return OPACITY;
  6499.         }
  6500.         if( strcmp(input_type, comment) == 0){
  6501.         free(input_type);
  6502.         return COMMENT;
  6503.         }
  6504.         if( strcmp(input_type, end) == 0){
  6505.         free(input_type);
  6506.         return END;
  6507.         }
  6508.         if( strcmp(input_type, fellipse) == 0){
  6509.         free(input_type);
  6510.         use_filled = TRUE;
  6511.         return ELLIPSE;
  6512.         }      
  6513.         if( strcmp(input_type, blink) == 0 ){
  6514.         free(input_type);
  6515.         return BLINK;
  6516.         }
  6517.         if( strcmp(input_type, button) == 0){
  6518.         free(input_type);
  6519.         return BUTTON;
  6520.         }
  6521.         if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
  6522.         free(input_type);
  6523.         return TRANSLATION;
  6524.         }
  6525.         if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
  6526.         free(input_type);
  6527.         return KILLTRANSLATION;
  6528.         }
  6529.         if( strcmp(input_type, rotate) == 0){
  6530.         free(input_type);
  6531.         return ROTATE;
  6532.         }
  6533.         if( strcmp(input_type, affine) == 0){
  6534.         free(input_type);
  6535.         return AFFINE;
  6536.         }
  6537.         if( strcmp(input_type, killaffine) == 0){
  6538.         free(input_type);
  6539.         return KILLAFFINE;
  6540.         }
  6541.         if( strcmp(input_type, audio) == 0 ){
  6542.         free(input_type);
  6543.         return AUDIO;
  6544.         }
  6545.         if( strcmp(input_type, audioobject) == 0 ){
  6546.         free(input_type);
  6547.         return AUDIOOBJECT;
  6548.         }
  6549.         if( strcmp(input_type, slider) == 0 ){
  6550.         free(input_type);
  6551.         return SLIDER;
  6552.         }
  6553.         if( strcmp(input_type, copy) == 0 ){
  6554.         free(input_type);
  6555.         return COPY;
  6556.         }
  6557.         if( strcmp(input_type, copyresized) == 0 ){
  6558.         free(input_type);
  6559.         return COPYRESIZED;
  6560.         }
  6561.         if( strcmp(input_type, patternfill) == 0 ){
  6562.         free(input_type);
  6563.         return PATTERNFILL;
  6564.         }
  6565.         if( strcmp(input_type, hatchfill) == 0 ){
  6566.         free(input_type);
  6567.         return HATCHFILL;
  6568.         }
  6569.         if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
  6570.         free(input_type);
  6571.         return DIAMONDFILL;
  6572.         }
  6573.         if( strcmp(input_type, dotfill) == 0 ){
  6574.         free(input_type);
  6575.         return DOTFILL;
  6576.         }
  6577.         if( strcmp(input_type, gridfill) == 0 ){
  6578.         free(input_type);
  6579.         return GRIDFILL;
  6580.         }
  6581.         if( strcmp(input_type, imagefill) == 0 ){
  6582.         free(input_type);
  6583.         return IMAGEFILL;
  6584.         }
  6585.         if( strcmp(input_type, clicktile_colors) == 0 ){
  6586.         free(input_type);
  6587.         return CLICKTILE_COLORS;
  6588.         }
  6589.         if( strcmp(input_type, clicktile) == 0 ){
  6590.         free(input_type);
  6591.         return CLICKTILE;
  6592.         }
  6593.         if( strcmp(input_type, xlogscale) == 0 ){
  6594.         free(input_type);
  6595.         return XLOGSCALE;
  6596.         }
  6597.         if( strcmp(input_type, ylogscale) == 0 ){
  6598.         free(input_type);
  6599.         return YLOGSCALE;
  6600.         }
  6601.         if( strcmp(input_type, xylogscale) == 0 ){
  6602.         free(input_type);
  6603.         return XYLOGSCALE;
  6604.         }
  6605.         if( strcmp(input_type, ylogscale) == 0 ){
  6606.         free(input_type);
  6607.         return YLOGSCALE;
  6608.         }
  6609.         if( strcmp(input_type, xlogbase) == 0 ){
  6610.         free(input_type);
  6611.         return XLOGBASE;
  6612.         }
  6613.         if( strcmp(input_type, ylogbase) == 0 ){
  6614.         free(input_type);
  6615.         return YLOGBASE;
  6616.         }
  6617.         if( strcmp(input_type, intooltip) == 0 ){
  6618.         free(input_type);
  6619.         return INTOOLTIP;
  6620.         }
  6621.         if( strcmp(input_type,video) == 0 ){
  6622.         free(input_type);
  6623.         return VIDEO;
  6624.         }
  6625.         if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
  6626.         free(input_type);
  6627.         return FLOODFILL;
  6628.         }      
  6629.         if( strcmp(input_type,filltoborder) == 0 ){
  6630.         free(input_type);
  6631.         return FILLTOBORDER;
  6632.         }      
  6633.         if( strcmp(input_type,clickfill) == 0 ){
  6634.         free(input_type);
  6635.         return CLICKFILL;
  6636.         }      
  6637.         if( strcmp(input_type, replyformat) == 0 ){
  6638.         free(input_type);
  6639.         return REPLYFORMAT;
  6640.         }
  6641.         if( strcmp(input_type, pixelsize) == 0 ){
  6642.         free(input_type);
  6643.         return PIXELSIZE;
  6644.         }
  6645.         if( strcmp(input_type, setpixel) == 0 ){
  6646.         free(input_type);
  6647.         return SETPIXEL;
  6648.         }
  6649.         if( strcmp(input_type, pixels) == 0 ){
  6650.         free(input_type);
  6651.         return PIXELS;
  6652.         }
  6653.         if( strcmp(input_type, clickfillmarge) == 0 ){
  6654.         free(input_type);
  6655.         return CLICKFILLMARGE;
  6656.         }
  6657.         if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
  6658.         free(input_type);
  6659.         return X_AXIS_STRINGS;
  6660.         }
  6661.         if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
  6662.         free(input_type);
  6663.         return Y_AXIS_STRINGS;
  6664.         }
  6665.         if( strcmp(input_type, piechart) == 0  ){
  6666.         free(input_type);
  6667.         return PIECHART;
  6668.         }
  6669.         if( strcmp(input_type, barchart) == 0  ){
  6670.         free(input_type);
  6671.         return BARCHART;
  6672.         }
  6673.         if( strcmp(input_type, linegraph) == 0  ){
  6674.         free(input_type);
  6675.         return LINEGRAPH;
  6676.         }
  6677.         if( strcmp(input_type, clock) == 0  ){
  6678.         free(input_type);
  6679.         return CLOCK;
  6680.         }
  6681.         if( strcmp(input_type, legend) == 0  ){
  6682.         free(input_type);
  6683.         return LEGEND;
  6684.         }
  6685.         if( strcmp(input_type, legendcolors) == 0  ){
  6686.         free(input_type);
  6687.         return LEGENDCOLORS;
  6688.         }
  6689.         if( strcmp(input_type, xlabel) == 0  ){
  6690.         free(input_type);
  6691.         return XLABEL;
  6692.         }
  6693.         if( strcmp(input_type, ylabel) == 0  ){
  6694.         free(input_type);
  6695.         return YLABEL;
  6696.         }
  6697.         if( strcmp(input_type, animate) == 0  ){
  6698.         free(input_type);
  6699.         return ANIMATE;
  6700.         }
  6701.         /* these are bitmap related flydraw commmands...must be removed. eventually */
  6702.         if( strcmp(input_type, transparent) == 0 ){
  6703.         free(input_type);
  6704.         return TRANSPARENT;
  6705.         }
  6706.         if( strcmp(input_type, status) == 0 ){
  6707.         free(input_type);
  6708.         return STATUS;
  6709.         }
  6710.         if( strcmp(input_type, snaptogrid) == 0 ){
  6711.         free(input_type);
  6712.         return SNAPTOGRID;
  6713.         }
  6714.         if( strcmp(input_type, xsnaptogrid) == 0 ){
  6715.         free(input_type);
  6716.         return XSNAPTOGRID;
  6717.         }
  6718.         if( strcmp(input_type, ysnaptogrid) == 0 ){
  6719.         free(input_type);
  6720.         return YSNAPTOGRID;
  6721.         }
  6722.         if( strcmp(input_type, userinput_xy) == 0 ){
  6723.         free(input_type);
  6724.         return USERINPUT_XY;
  6725.         }
  6726.         if( strcmp(input_type, usertextarea_xy) == 0 ){
  6727.         free(input_type);
  6728.         return USERTEXTAREA_XY;
  6729.         }
  6730.         if( strcmp(input_type, sgraph) == 0 ){
  6731.         free(input_type);
  6732.         return SGRAPH;
  6733.         }
  6734.         free(input_type);
  6735.         ungetc(c,infile);
  6736.         return 0;
  6737. }
  6738.  
  6739.  
  6740.