Subversion Repositories wimsdev

Rev

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

  1. /*27/7/2013 version 0.01
  2. "Inspired" by FLY program: http://martin.gleeson.com/fly
  3. *********************************************************************************
  4. * J.M. Evers 7/2013                                                             *
  5. * This is all just amateur scriblings... So no copyrights.                      *
  6. * This source code file, and compiled objects derived from it,                  *
  7. * can be used and distributed without restriction, including for commercial use *
  8. * No warrenty whatsoever                                                        *
  9. *********************************************************************************
  10. */
  11. #include "canvasdraw.h"
  12.  
  13. /******************************************************************************
  14. **  Internal Functions
  15. ******************************************************************************/
  16. void    add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */
  17. void    sync_input(FILE *infile);/* proceed with inputfile */
  18. void    add_javascript_function(int js_function[], int canvas_root_id);
  19. void    reset();/* reset some global variables like "use_filled" , "use_dashed" */
  20. int     get_token(FILE *infile); /* read next char until EOL*/
  21. /*
  22. int     x2px(double x);
  23. int     y2px(double y);
  24. */
  25. double  px2x(int x);
  26. double  px2y(int y);
  27. double  get_real(FILE *infile,int last); /* read a value; calculation and symbols allowed */
  28. char    *str_replace ( const char *word, const char *sub_word, const char *rep_word );
  29. char    *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */
  30. char    *get_string(FILE *infile,int last); /* get the string at the end of a command */
  31. char    *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as  separator */
  32. char    *convert_hex2rgb(char *hexcolor);
  33. void    add_read_canvas(int canvas_root_id,int reply_format,int reply_precision);
  34. void    make_js_include(int canvas_root_id);
  35. void    check_string_length(int length);/* checks if the length of string argument of command is correct */
  36. FILE    *js_include_file;
  37. FILE    *get_file(int *line_number, char **filename);
  38. FILE    *infile;    /* will be stdin */
  39. /******************************************************************************
  40. ** global
  41. ******************************************************************************/
  42. int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */
  43. int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */
  44. /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */
  45. int xsize = 320;
  46. int ysize = 320;
  47. double xmin = 0.0;
  48. double xmax = 320.0;
  49. double ymin = 0.0;
  50. double ymax = 320.0;
  51. double tmax = 2;
  52. double tmin = -2;
  53. /* flag to indicate parsing of line status */
  54. int done = FALSE;
  55. int type; /* eg command number */
  56. int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/
  57. int slider = 0;/* slider=1 : x-values ; slider=2 : y-values;slider=3 angle values */
  58. int use_affine = FALSE;
  59. int use_rotate = FALSE;
  60. int use_filled = FALSE;
  61. int use_dashed = FALSE; /* dashing not natively supported in firefox  , for now... */
  62.  
  63. char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */
  64. char *getfile_cmd = "";
  65. /******************************************************************************
  66. ** Main Program
  67. ******************************************************************************/
  68. int main(int argc, char *argv[]){
  69.     /* need unique id for every call to canvasdraw : rand(); is too slow...will result in many identical id's */
  70.     struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);unsigned int canvas_root_id = (unsigned int) tv.tv_usec;
  71.     infile = stdin;/* read flyscript via stdin */
  72.     int i,c;
  73.     double double_data[MAX_INT+1];
  74.     int int_data[MAX_INT+1];
  75.     for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;}
  76.     int use_parametric = FALSE;/* will be reset after parametric plotting */
  77.     int use_axis = FALSE;
  78.     int use_axis_numbering = FALSE;
  79.     int use_pan_and_zoom = FALSE;
  80.     int use_safe_eval = FALSE; /* if true, add just once : js function to evaluate userinput values for plotting etc */
  81.     int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */
  82.     int use_js_plot = FALSE; /* if true , let js-engine plot the curve */
  83.     int jsplot_cnt = 0; /* keepint track on the curve identity */
  84.     int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */
  85.     int line_width = 1;
  86.     int decimals = 2;
  87.     int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */
  88.     int use_userdraw = FALSE; /* flag to indicate user interaction */
  89.     int drag_type = -1;/* 0,1,2 : xy,x,y */
  90.     int use_tooltip = -1; /* 1= tooltip 2= popup window*/
  91.     char *tooltip_text = "Click here";
  92.     char *temp = ""; /* */
  93.     char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
  94.     char *stroke_color = "255,0,0";
  95.     char *fill_color = "0,255,0";
  96.     char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
  97.     char *font_color = "#00000";
  98.     char *draw_type = "points";
  99.     char *fly_font = "normal";
  100.     char *input_style = "font-family:Ariel;text-align:center;color:blue;font-size:12px;background-color:orange;";
  101.     char *flytext = "";
  102.     char *affine_matrix = "[1,0,0,1,0,0]";
  103.     char *function_label = "f(x)=";
  104.     int canvas_type = DRAG_CANVAS; /* to use a specific canvas  for filling etc */
  105.     int pixelsize = 1;
  106.     int reply_format = 0;
  107.     int input_cnt = 0;
  108.     int ext_img_cnt = 0;
  109.     int slider_cnt = 0;
  110.     int font_size = 12;/* this may lead to problems when using something like "fontfamily Italic 24px Ariel" the "font_size" value is not substituted into fontfamily !! */
  111.     int fly_font_size = 12; /*fly_font_size is relative to this... */
  112.     int dashtype[2] = { 4 , 4 }; /* just line_px and space_px : may have more arguments...if needed in future*/
  113.     int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */
  114.     for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
  115.     int arrow_head = 8; /* size in px needed for arrow based  userdraw:  "userdraw arrow,color" */
  116.     int crosshair_size = 5; /* size in px*/
  117.     int plot_steps = 250;/* the js-arrays with x_data_points and y_data_points will have size 250 each: use with care !!! use jscurve when precise plots are required  */
  118.     int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange :just to flag an error message */
  119.     int click_cnt = 0; /*counter to identify the "onclick" ojects ; 0 is first object set onclick: reply[click_cnt]=1 when clicked ; otherwise reply[click_cnt]=0 ; click_cnt is only increased when another object is set  again */
  120.     int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
  121.     int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
  122.     int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/
  123.     int boxplot_cnt = 0;
  124.     int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc  */
  125.     int reply_precision = 100; /* used for precision of student answers / drawings */
  126.     double angle = 0.0;
  127.     char *rotation_center = "null";
  128.     int clickfillmarge = 20; /* in pixels : if the 'remove click' is within this marge, the filling is removed */
  129.     int animation_type = 9; /* REMOVED == object type curve in drag library */
  130.     int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/
  131.     int use_slider_display = 0; /* in case of a slider, should we display its value ?*/
  132.     size_t string_length = 0; /* measure the size of the user input fly-string */
  133.     double stroke_opacity = 0.8; /* use some opacity as default */
  134.     double fill_opacity = 0.8;/* use some opacity as default */
  135.     char *URL = "http://localhost/images";
  136.     char *slider_function_x = "x";
  137.     char *slider_function_y = "y";
  138.     memset(buffer,'\0',MAX_BUFFER);
  139.     void *tmp_buffer = "";
  140.  
  141.     /* default writing a unzipped js-include file into wims getfile directory */
  142.     char *w_wims_session = getenv("w_wims_session");
  143.     if(  w_wims_session == NULL || *w_wims_session == 0 ){
  144.         canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");
  145.     }
  146.     int L0=strlen(w_wims_session) + 21;
  147.     char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
  148.     snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
  149.     mode_t process_mask = umask(0); /* check if file exists */
  150.     int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
  151.     if( result == 0 || errno == EEXIST ){
  152.      umask(process_mask); /* be sure to set correct permission */
  153.      char *w_session = getenv("w_session");
  154.      int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
  155.     getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
  156.      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 */
  157.     /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
  158.     /* now write file into getfile dir*/
  159.     char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */
  160.     int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
  161.     char *location = my_newmem(L2); /* create memory to fit string precisely */
  162.     snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
  163.     js_include_file = fopen(location,"w");/* open the file location for writing */
  164.     /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */
  165.     if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );}
  166.  
  167. /* ----------------------------------------------------- */
  168. /* while more lines to process */
  169.  
  170.     while(!finished){
  171.         if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
  172.         type = get_token(infile);
  173.         done = FALSE;
  174.         /*
  175.         @ canvasdraw
  176.         @ 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...)
  177.         @ general syntax <ul><li>The transparency of all objects can be controlled by command <a href="#opacity">'opacity [0-255],[0,255]'</a></il><li>line width of any object can be controlled by command <a href="#linewidth">'linewidth int'</a></li><li>any may be dashed by using keyword <a href="#dashed">'dashed'</a> before the object command.<br />the dashing type can be controled by command <a href="#dashtype">'dashtype int,int'</a></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 <a href="#filled">'filled'</a> before the object command.<br />The fill colour of 'non_userdraw' objects will be the stroke colour...(flydraw harmonization 19/10/2013)</li><li>all draggable objects may have a <a href="#slider">slider</a> for translation / rotation; several objects may be translated / rotated by a single slider</li> <li> a draggable object can be set draggable by a preceding command <a href="#drag">'drag x/y/xy'</a><br />The translation can be read by javascript:read_dragdrop();The replyformat is : object_number : x-orig : y-orig : x-drag : y-drag<br />The x-orig/y-orig will be returned in maximum precision (javascript float)...<br />the x-drag/y-drag will be returned in defined 'precision' number of decimals<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 <a href="#zoom">zoom</a> and will be translated in case of panning</li><li> a 'onclick object' can be set 'clickable' by the preceding keyword <a href="#onclick">'onclick'</a><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 (instead 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.</li><li>almost every <a href="#userdraw">"userdraw object,color"</a>  or <a href="#multidraw">"multidraw"</a> command 'family' may be combined with keywords <a href="#snaptogrid">"snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command "snaptopoints x1,y1,x2,y2,..."  </li><li>every draggable | onclick object may be combined with keywords <a href="#snaptogrid">snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command "snaptopoints x1,y1,x2,y2,..."  </li><li>almost every command for a single object has a multiple objects counterpart:<br /><ul>general syntaxrule:<li><em>single_object</em> x1,y1,...,color</li><li><em>multi_object</em> color,x1,y1,...</li></ul><li>All inputfields or textareas generated, can be styled individually using command <a href="#inputstyle">'inputstyle some_css'</a><br/>the fontsize used for labeling these elements can be controlled by command <a href="fontsize">'fontsize int'</a> <br />command 'fontfamily' is <b>not</b> active for these elements </li></ul>
  178.         @ If needed multiple interactive scripts may be used in a single webpage.<br />A function 'read_canvas()' and / or 'read_dragdrop()' can read all interactive userdata from these images.<br />The global array 'canvas_scripts' will contain all unique random "canvas_root_id" of the included scripts.<br />The included local javascript "read" functions "read_canvas%d()" and "read_dragdrop%d()" will have this "%d = canvas_root_id"<br />e.g. canvas_scripts[0] will be the random id of the first script in the page and will thus provide a function<br />fun = eval("read_canvas"+canvas_scripts[0]) to read user based drawings / inputfield in this first image.<br />The read_dragdrop is analogue.<br />If the default reply formatting is not suitable, use command <a href='#replyformat'>'replyformat'</a> to format the replies for an individual canvas script,<br />To read all user interactions from all included canvas scripts , use something like:<br /><em>function read_all_canvas_images(){<br />&nbsp;var script_len = canvas_scripts.length;<br />&nbsp;var draw_reply = "";<br />&nbsp;var found_result = false;<br />&nbsp;for(var p = 0 ; p < script_len ; p++){<br />&nbsp;&nbsp;var fun = eval("read_canvas"+canvas_scripts[p]);<br />&nbsp;&nbsp;if( typeof fun === 'function'){<br />&nbsp;&nbsp;&nbsp;var result = fun();<br />&nbsp;&nbsp;&nbsp;if( result&nbsp;&nbsp;&& result.length != 0){<br />&nbsp;&nbsp;&nbsp;&nbsp;if(script_len == 1 ){ return result;};<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;found_result = true;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;draw_reply = draw_reply + result + "\\n";<br />&nbsp;&nbsp;&nbsp;&nbsp;};<br />&nbsp;&nbsp;&nbsp;};<br />&nbsp;&nbsp;};<br />&nbsp;if( found_result ){return draw_reply;}else{return null;};<br />};</em>
  179.         @ you can check the javascript reply format in the wims tool <a href="http://localhost/wims/wims.cgi?lang=en&module=tool/directexec">direct exec</a>
  180.         @ for usage within OEF (without anstype "draw"), something like this (a popup function plotter) will work:<br /><small>\\text{popup_grapher=wims(exec canvasdraw <br />popup<br />size 400,400<br />xrange -10,10<br />yrange -10,10<br />axis<br />axisnumbering<br />opacity 100,100<br />grid 2,2,grey,2,2,6,black<br />snaptogrid<br />linewidth 2<br />jsplot red,5*sin(1/x)<br />strokecolor green<br />functionlabel f(x)=<br />userinput function<br />mouse blue,22<br />)<br />}<br />\\statement{<br />\\popup_grapher<br />}</small>
  181.         @ be aware that older browsers will probably not work correctly<br />no effort has been undertaken to add glue code for older browsers !! <br />in any case it's not wise to use older browsers...not just for canvasdraw
  182.         @ if you find flaws, errors or other incompatibilities -not those mentioned in this document- send <a href='mailto:jm.evers-at-schaersvoorde.nl'>me</a> an email with screenshots and the generated javascript include file.
  183.         @ there is limited support for touch devices : touchstart,touchmove and touchend in commands <a href="#userdraw">userdraw primitives </a>, <a href="#protractor">protractor</a> and <a href="#ruler">ruler</a><br />only single finger gestures are supported (for now)<br />for more accurate user-interaction with canvasdraw on touch devices: use the command family <a href="userinput_xy">userinput</a>
  184.         */
  185.         switch(type){
  186.         case END:
  187.         finished = 1;
  188.         done = TRUE;
  189.         break;
  190.         case 0:
  191.             sync_input(infile);
  192.             break;
  193.         case COMMENT:
  194.             sync_input(infile);
  195.             break;
  196.         case SIZE:
  197.             /*
  198.             @ size width,height
  199.             @ set canvas size in pixels
  200.             @ mandatory first command (can only be preceded by keyword <a href="#popup">'popup'</a>)
  201.             @ 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) !!! this in contrast to flydraw
  202.             */
  203.             found_size_command = 1;
  204.             /* using fabs : however "xsize == int" : so "xsize = abs( (int) get_real(infile,0))" would be the idea... */
  205.             xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
  206.             ysize = (int)(fabs(round(get_real(infile,1))));
  207.             /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
  208.             xmin = 0;xmax = xsize;
  209.             ymin = 0;ymax = ysize;
  210.  
  211. /*
  212.  The sequence in which stuff is finally printed is important !!
  213. */
  214. fprintf(stdout,"\n\
  215. <script type=\"text/javascript\">\n\
  216. /*<![CDATA[*/\n\
  217. if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\
  218. if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\
  219. if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\
  220. canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\
  221. ",canvas_root_id);
  222.  
  223. /* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */
  224. if( use_tooltip != 2){
  225.  fprintf(stdout,"<!-- canvasdraw div  -->\n\
  226. <div tabindex=\"0\" id=\"canvas_div%d\" style=\"position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" oncontextmenu=\"return false;\"></div>\n\
  227. <!-- tooltip and input placeholder  -->\n\
  228. <div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\
  229. <!-- include actual object code via include file -->\n\
  230. <script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd);
  231. }
  232. else
  233. {
  234. /*
  235. set canvas_div invisible and do not include placeholder in main html page :
  236. the js-include will also be in a popup window...to be shown when wims $status = done
  237. */
  238.  fprintf(stdout,"<!-- canvasdraw div invisible  -->\n\
  239. <div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\
  240. <div id=\"tooltip_placeholder_div%d\" style=\"display:none;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\
  241. <!-- include actual object code via include file -->\n\
  242. <script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd);
  243. }
  244.  
  245. /* these must be global...it's all really very poor javascript :( */
  246. fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n\
  247. \"use strict\";\n\
  248. <!-- these variables and functions must be global -->\n\
  249. var read_dragdrop%d;\
  250. var read_canvas%d;\
  251. var set_clock;\
  252. var clear_draw_area%d;\
  253. var update_draw_area%d;\
  254. var draw_boxplot;\
  255. var redraw_all%d;\
  256. var userdraw_primitive;\n\
  257. var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\
  258. var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\
  259. var xsize = %d;\
  260. var ysize = %d;\
  261. var precision = 100;\
  262. var canvas_div = document.getElementById(\"canvas_div%d\");\
  263. var 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;};\
  264. 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;};\
  265. function x2px(x){if(use_xlogscale == 0 ){return parseFloat(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);};};\
  266. function px2x(px){if(use_xlogscale == 0 ){return parseFloat(px*(xmax - xmin)/xsize + xmin);}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);};};\
  267. function px2y(py){if(use_ylogscale == 0 ){return parseFloat(ymax - py*(ymax - ymin)/ysize);}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);};};\
  268. function y2px(y){if(use_ylogscale == 0){return parseFloat(-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);};};\
  269. function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
  270. function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
  271. function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\
  272. 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) ));};\
  273. 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;};\
  274. function slide(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = x2px(obj.xorg[p] + dx);obj.y[p] = y2px(obj.yorg[p] + dy);};return obj;};\
  275. var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));\
  276. var x_use_snap_to_grid = 0;var y_use_snap_to_grid = 0;var snap_x = 1;var snap_y = 1;\
  277. var use_snap_to_points = 0;\
  278. function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
  279. function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\n\
  280. var xlogbase = 10;\
  281. var ylogbase = 10;\
  282. var use_xlogscale = 0;\
  283. var use_ylogscale = 0;\
  284. var x_strings = null;var x_strings_up = null;\
  285. var y_strings = null;\
  286. var use_pan_and_zoom = 0;\
  287. var use_jsmath = 0;\
  288. var xstart = 0;\
  289. var ystart = 0;\
  290. var unit_x=\" \";\
  291. var unit_y=\" \";\
  292. var external_canvas = create_canvas%d(%d,xsize,ysize);\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,EXTERNAL_IMAGE_CANVAS);
  293. /* default add the drag code : nearly always used ...*/
  294.   add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
  295.  
  296.             break;
  297.  
  298.         case XRANGE:
  299.         /*
  300.         @ xrange xmin,xmax
  301.         @ alternative : rangex
  302.         @ if not given: 0,xsize (eg in pixels)
  303.         */
  304.             for(i = 0 ; i<2; i++){
  305.                 switch(i){
  306.                     case 0: xmin = get_real(infile,0);break;
  307.                     case 1: xmax = get_real(infile,1);break;
  308.                     default: break;
  309.                 }
  310.             }
  311.             if(xmin >= xmax){canvas_error(" xrange is not OK : xmin &lt; xmax !\n");}
  312.             fprintf(js_include_file,"var xmin = %f;var xmax = %f;\n",xmin,xmax);
  313.             found_size_command++;
  314.             break;
  315.  
  316.         case YRANGE:
  317.         /*
  318.         @ yrange ymin,ymax
  319.         @ alternative : rangey
  320.         @ if not given 0,ysize (eg in pixels)
  321.         */
  322.             for(i = 0 ; i<2; i++){
  323.                 switch(i){
  324.                     case 0: ymin = get_real(infile,0);break;
  325.                     case 1: ymax = get_real(infile,1);break;
  326.                     default: break;
  327.                 }
  328.             }
  329.             if(ymin >= ymax){canvas_error(" yrange is not OK : ymin &lt; ymax !\n");}
  330.             fprintf(js_include_file,"var ymin = %f;var ymax = %f;\n",ymin,ymax);
  331.             found_size_command++;
  332.             break;
  333.  
  334.         case TRANGE:
  335.         /*
  336.         @ trange tmin,tmax
  337.         @ alternative : ranget
  338.         @ default -2,2
  339.         */
  340.             use_parametric = TRUE;
  341.             for(i = 0 ; i<2; i++){
  342.                 switch(i){
  343.                     case 0: tmin = get_real(infile,0);break;
  344.                     case 1: tmax = get_real(infile,1);break;
  345.                     default: break;
  346.                 }
  347.             }
  348.             if(tmin >= tmax ){canvas_error(" trange is not OK : tmin &lt; tmax!\n");}
  349.             break;
  350.  
  351.         case LINEWIDTH:
  352.         /*
  353.         @ linewidth int
  354.         @ default 1
  355.         */
  356.             line_width = (int) (get_real(infile,1));
  357.             break;
  358.  
  359.         case CROSSHAIRSIZE:
  360.         /*
  361.         @ crosshairsize int
  362.         @ default 8 (px)
  363.         */
  364.             crosshair_size = (int) (get_real(infile,1));
  365.             break;
  366.  
  367.         case CROSSHAIR:
  368.         /*
  369.         @ crosshair x,y,color
  370.         @ draw a single crosshair point at (x;y) in color 'color'
  371.         @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
  372.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  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,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%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,slider,slider_cnt,rotation_center);
  381.                         if(onclick > 0){click_cnt++;}
  382.                         /* click_cnt++ */
  383.                         reset();
  384.                         break;
  385.                     default:break;
  386.                 }
  387.             }
  388.             break;
  389.  
  390.         case CROSSHAIRS:
  391.         /*
  392.         @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
  393.         @ draw multiple crosshair points at given coordinates in color 'color'
  394.         @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
  395.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  396.         */
  397.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  398.             fill_color = stroke_color;
  399.             i=0;
  400.             while( ! done ){     /* get next item until EOL*/
  401.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  402.                 if(i%2 == 0 ){
  403.                     double_data[i] = get_real(infile,0); /* x */
  404.                 }
  405.                 else
  406.                 {
  407.                     double_data[i] = get_real(infile,1); /* y */
  408.                 }
  409.                 i++;
  410.             }
  411.             decimals = find_number_of_digits(precision);
  412.             for(c=0 ; c < i-1 ; c = c+2){
  413.                 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,%d,%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,slider,slider_cnt,rotation_center);
  414.                 if(onclick > 0){click_cnt++;}
  415.                 /* click_cnt++; */
  416.             }
  417.             reset();
  418.             break;
  419.  
  420.         case POINT:
  421.         /*
  422.         @ point x,y,color
  423.         @ draw a single point at (x;y) in color 'color'
  424.         @ use command 'linewidth int'  to adust size
  425.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  426.         @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming)
  427.         @ attention: in case of command <a href="#rotate">'rotate angle'</a> a point has rotation center (0:0) in x/y-range
  428.         */
  429.             for(i=0;i<3;i++){
  430.                 switch(i){
  431.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  432.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  433.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  434.                     decimals = find_number_of_digits(precision);
  435.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],1.5*line_width,line_width,1.5*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,slider,slider_cnt,rotation_center);
  436.                     /* click_cnt++; */
  437.                     if(onclick > 0){click_cnt++;}
  438.                     break;
  439.                     default: break;
  440.                 }
  441.             }
  442.             reset();
  443.             break;
  444.  
  445.         case POINTS:
  446.         /*
  447.         @ points color,x1,y1,x2,y2,...,x_n,y_n
  448.         @ draw multiple points at given coordinates in color 'color'
  449.         @ use command 'linewidth int'  to adust size
  450.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  451.         @ attention: in case of command <a href="#rotate">'rotate angle'</a> the points have rotation center (0:0) in x/y-range
  452.         */
  453.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  454.             fill_color = stroke_color;
  455.             i=0;
  456.             while( ! done ){     /* get next item until EOL*/
  457.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  458.                 if(i%2 == 0 ){
  459.                     double_data[i] = get_real(infile,0); /* x */
  460.                 }
  461.                 else
  462.                 {
  463.                     double_data[i] = get_real(infile,1); /* y */
  464.                 }
  465.                 i++;
  466.             }
  467.             decimals = find_number_of_digits(precision);
  468.             for(c = 0 ; c < i-1 ; c = c+2){
  469.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],1.5*line_width,line_width,1.5*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,slider,slider_cnt,rotation_center);
  470.                 /* click_cnt++; */
  471.                 if(onclick > 0){click_cnt++;}
  472.             }
  473.             reset();
  474.             break;
  475.         case YERRORBARS:
  476.         /*
  477.         @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
  478.         @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color 'color'
  479.         @ the errors E1 and E2 values are in yrange.
  480.         @ use command 'linewidth int' to adust size
  481.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  482.         */
  483.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  484.             fill_color = stroke_color;
  485.             i=0;
  486.             while( ! done ){     /* get next item until EOL*/
  487.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  488.                 if(i%2 == 0 ){
  489.                     double_data[i] = get_real(infile,0); /* x */
  490.                 }
  491.                 else
  492.                 {
  493.                     double_data[i] = get_real(infile,1); /* y */
  494.                 }
  495.                 i++;
  496.             }
  497.             for(c = 2 ; c < i-1 ; c = c+2){
  498.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,19,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",
  499.                 click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],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,slider,slider_cnt,rotation_center);
  500.                 /* click_cnt++; */
  501.                 if(onclick > 0){click_cnt++;}
  502.             }
  503.             decimals = find_number_of_digits(precision);
  504.             reset();
  505.             break;
  506.         case XERRORBARS:
  507.         /*
  508.         @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
  509.         @ draw multiple points with x-errorbars E1 (error value left from point) and E2 (error value right from point) at given coordinates in color 'color'
  510.         @ the errors E1 and E2 values are in xrange.
  511.         @ use command 'linewidth int' to adust size
  512.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  513.         */
  514.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  515.             fill_color = stroke_color;
  516.             i=0;
  517.             while( ! done ){     /* get next item until EOL*/
  518.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  519.                 if(i%2 == 0 ){
  520.                     double_data[i] = get_real(infile,0); /* x */
  521.                 }
  522.                 else
  523.                 {
  524.                     double_data[i] = get_real(infile,1); /* y */
  525.                 }
  526.                 i++;
  527.             }
  528.             decimals = find_number_of_digits(precision);
  529.             for(c = 2 ; c < i-1 ; c = c+2){
  530.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,20,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],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,slider,slider_cnt,rotation_center);
  531.                 /* click_cnt++; */
  532.                 if(onclick > 0){click_cnt++;}
  533.             }
  534.             reset();
  535.             break;
  536.  
  537.         case CIRCLE:
  538.         /*
  539.         @ circle xc,yc,width (2*r in pixels),color
  540.         @ use command 'fcircle xc,yc,d,color'
  541.         @ alternative: disk for a filled circle
  542.         @ use command 'fillcolor color' to set the fillcolor
  543.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  544.         @ will shrink / expand on zoom out / zoom in
  545.         */
  546.             for(i=0;i<4;i++){
  547.                 switch(i){
  548.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  549.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  550.                     case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out : radius in 'dx' xrange*/
  551.                     case 3: stroke_color = get_color(infile,1);/* name or hex color */
  552.                         decimals = find_number_of_digits(precision);
  553.                         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,%d,%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,slider,slider_cnt,rotation_center);
  554.                         if(onclick > 0){click_cnt++;}
  555.                         /* click_cnt++;*/
  556.                         reset();
  557.                         break;
  558.                     default : break;
  559.                 }
  560.             }
  561.             break;
  562.  
  563.         case CIRCLES:
  564.         /*
  565.         @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n
  566.         @ <b>attention</b> r = radius in x-range (!)
  567.         @ use keyword 'filled' or command 'fcircles' to produce solid circles
  568.         @ alternative : disks for filled circles
  569.         @ use command 'fillcolor color' to set the fillcolor
  570.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (individually)
  571.         @ will shrink / expand on zoom out / zoom in
  572.         */
  573.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  574.             fill_color = stroke_color;
  575.             i=1;
  576.             while( ! done ){     /* get next item until EOL*/
  577.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  578.                 switch (i%3){
  579.                  case 1:double_data[i-1] = get_real(infile,0);break; /* x */
  580.                  case 2:double_data[i-1] = get_real(infile,0);break; /* y */
  581.                  case 0:double_data[i-1] = get_real(infile,1);break; /* r */
  582.                 }
  583.                 i++;
  584.             }
  585.             decimals = find_number_of_digits(precision);
  586.             for(c = 0 ; c < i-1 ; c = c+3){
  587.                 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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[c+2],double_data[c+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,slider,slider_cnt,rotation_center);
  588.                 if(onclick > 0){click_cnt++;}
  589.                 /* click_cnt++; */
  590.             }
  591.             reset();
  592.             break;
  593.  
  594.         case SEGMENT:
  595.         /*
  596.         @ segment x1,y1,x2,y2,color
  597.         @ alternative : seg
  598.         @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color'
  599.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  600.         */
  601.             for(i=0;i<5;i++) {
  602.                 switch(i){
  603.                     case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
  604.                     case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
  605.                     case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
  606.                     case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
  607.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  608.                         decimals = find_number_of_digits(precision);
  609.                         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,%d,%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,slider,slider_cnt,rotation_center);
  610.                         if(onclick > 0){click_cnt++;}
  611.                         /* click_cnt++; */
  612.                         reset();
  613.                         break;
  614.                     default: break;
  615.                 }
  616.             }
  617.             break;
  618.  
  619.         case SEGMENTS:
  620.         /*
  621.         @ segments color,x1,y1,x2,y2,...,x_n,y_n
  622.         @ alternative : segs
  623.         @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color 'color'
  624.         @ use command 'linewidth int'  to adust size
  625.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  626.         */
  627.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  628.             fill_color = stroke_color;
  629.             i=0;
  630.             while( ! done ){     /* get next item until EOL*/
  631.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  632.                 if(i%2 == 0 ){
  633.                     double_data[i] = get_real(infile,0); /* x */
  634.                 }
  635.                 else
  636.                 {
  637.                     double_data[i] = get_real(infile,1); /* y */
  638.                 }
  639.                 i++;
  640.             }
  641.             decimals = find_number_of_digits(precision);
  642.             for(c = 0 ; c < i-1 ; c = c+4){
  643.                 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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],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,slider,slider_cnt,rotation_center);
  644.                 if(onclick > 0){click_cnt++;}
  645.                 /* click_cnt++;*/
  646.             }
  647.             reset();
  648.             break;
  649.  
  650.         case LINE:
  651.         /*
  652.         @ line x1,y1,x2,y2,color
  653.         @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
  654.         @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
  655.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  656.         */
  657.             for(i=0;i<5;i++){
  658.                 switch(i){
  659.                     case 0: double_data[10]= get_real(infile,0);break; /* x-values */
  660.                     case 1: double_data[11]= get_real(infile,0);break; /* y-values */
  661.                     case 2: double_data[12]= get_real(infile,0);break; /* x-values */
  662.                     case 3: double_data[13]= get_real(infile,0);break; /* y-values */
  663.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  664.                     if( double_data[10] == double_data[12] ){ /* vertical line*/
  665.                         double_data[1] = xmin;
  666.                         double_data[3] = ymax;
  667.                         double_data[0] = double_data[10];
  668.                         double_data[2] = double_data[10];
  669.                     }
  670.                     else
  671.                     {
  672.                         if( double_data[11] == double_data[13] ){ /* horizontal line */
  673.                             double_data[1] = double_data[11];
  674.                             double_data[3] = double_data[11];
  675.                             double_data[0] = ymin;
  676.                             double_data[2] = xmax;
  677.                         }
  678.                         else
  679.                         {
  680.                         /* m */
  681.                         double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
  682.                         /* q */
  683.                         double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
  684.  
  685.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  686.  
  687.                             double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
  688.                             double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
  689.                             double_data[0] = xmin;
  690.                             double_data[2] = xmax;
  691.                         }
  692.                     }
  693.                     decimals = find_number_of_digits(precision);
  694.                     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,%d,%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,slider,slider_cnt,rotation_center);
  695.                     if(onclick > 0){click_cnt++;}
  696.                     /* click_cnt++;*/
  697.                     reset();
  698.                     break;
  699.                 }
  700.             }
  701.             break;
  702.  
  703.         case LINES:
  704.         /*
  705.         @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n
  706.         @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color'
  707.         @ or use multiple commands 'curve color,formula' or "jscurve color,formule" to draw the line <br />(uses more points to draw the line; is however better draggable)
  708.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  709.         @ <b>attention</b>: the flydraw command "lines" is equivalent to canvasdraw command <a href="#polyline">"polyline"</a>
  710.         */
  711.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  712.             fill_color = stroke_color;
  713.             i=0;
  714.             while( ! done ){     /* get next item until EOL*/
  715.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  716.                 if(i%2 == 0 ){
  717.                     double_data[i] = get_real(infile,0); /* x */
  718.                 }
  719.                 else
  720.                 {
  721.                     double_data[i] = get_real(infile,1); /* y */
  722.                 }
  723.                 i++;
  724.             }
  725.             decimals = find_number_of_digits(precision);
  726.             for(c = 0 ; c < i-1 ; c = c+4){
  727.                 if( double_data[c] == double_data[c+2] ){ /* vertical line*/
  728.                     double_data[c+1] = xmin;
  729.                     double_data[c+3] = ymax;
  730.                     double_data[c+2] = double_data[c];
  731.                 }
  732.                 else
  733.                 {
  734.                     if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  735.                         double_data[c+3] = double_data[c+1];
  736.                         double_data[c] = ymin;
  737.                         double_data[c+2] = xmax;
  738.                     }
  739.                     else
  740.                     {
  741.                         /* m */
  742.                         double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  743.                         /* q */
  744.                         double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  745.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  746.                         double_data[c+1] = (m)*(xmin)+(q);
  747.                         double_data[c+3] = (m)*(xmax)+(q);
  748.                         double_data[c] = xmin;
  749.                         double_data[c+2] = xmax;
  750.                     }
  751.                 }
  752.                 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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],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,slider,slider_cnt,rotation_center);
  753.                 if(onclick > 0){click_cnt++;}
  754.                 /* click_cnt++; */
  755.             }
  756.             reset();
  757.             break;
  758.  
  759.         case HALFLINE:
  760.         /*
  761.         @ demiline x1,y1,x2,y2,color
  762.         @ alternative : halfline
  763.         @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex)
  764.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  765.         */
  766.             for(i=0;i<5;i++){
  767.                 switch(i){
  768.                     case 0: double_data[0]= get_real(infile,0);break; /* x-values */
  769.                     case 1: double_data[1]= get_real(infile,0);break; /* y-values */
  770.                     case 2: double_data[10]= get_real(infile,0);break; /* x-values */
  771.                     case 3: double_data[11]= get_real(infile,0);break; /* y-values */
  772.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  773.                     if(double_data[0] == double_data[10]){ /* vertical halfline */
  774.                         if(double_data[1] < double_data[11]){
  775.                          double_data[3] = ymax + 1000;
  776.                         }
  777.                         else
  778.                         {
  779.                          double_data[3] = ymin - 1000;
  780.                         }
  781.                         double_data[2] = double_data[0];
  782.                     }
  783.                     else
  784.                     { /* horizontal halfline*/
  785.                      if( double_data[1] == double_data[11] ){
  786.                       if( double_data[0] < double_data[10] ){
  787.                         double_data[2] = xmax + 1000; /* halfline to the right */
  788.                       }
  789.                       else
  790.                       {
  791.                         double_data[2] = xmin - 1000; /* halfline to the left */
  792.                       }
  793.                       double_data[3] = double_data[1];
  794.                      }
  795.                      else
  796.                      {
  797.                       /* any other halfline */
  798.                       /* slope */
  799.                       double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
  800.                       /* const */
  801.                       double_data[13] = double_data[1] - double_data[12]*double_data[0];
  802.                       if( double_data[0] < double_data[10] ){
  803.                        double_data[2] = double_data[2] + 1000;
  804.                       }
  805.                       else
  806.                       {
  807.                        double_data[2] = double_data[2] - 1000;
  808.                       }
  809.                       double_data[3] = double_data[12]*double_data[2] + double_data[13];
  810.                      }
  811.                     }
  812.                     decimals = find_number_of_digits(precision);
  813.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%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,slider,slider_cnt,rotation_center);
  814.                     if(onclick > 0){click_cnt++;}
  815.                     /* click_cnt++; */
  816.                     reset();
  817.                     break;
  818.                 }
  819.             }
  820.             break;
  821.  
  822.         case HALFLINES:
  823.         /*
  824.         @ demilines color,x1,y1,x2,y2,....
  825.         @ alternative : halflines
  826.         @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc etc
  827.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually
  828.         */
  829.             stroke_color=get_color(infile,0);
  830.             fill_color = stroke_color;
  831.             i=0;
  832.             while( ! done ){     /* get next item until EOL*/
  833.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  834.                 if(i%2 == 0 ){
  835.                     double_data[i] = get_real(infile,0); /* x */
  836.                 }
  837.                 else
  838.                 {
  839.                     double_data[i] = get_real(infile,1); /* y */
  840.                 }
  841.                 i++;
  842.             }
  843.             decimals = find_number_of_digits(precision);
  844.             for(c = 0 ; c < i-1 ; c = c+4){
  845.                 if( double_data[c] == double_data[c+2] ){ /* vertical line*/
  846.                     if(double_data[c+1] < double_data[c+3]){ /* upright halfline */
  847.                         double_data[c+3] = ymax + 1000;
  848.                     }
  849.                     else
  850.                     {
  851.                      double_data[c+3] = ymin - 1000;/* descending halfline */
  852.                     }
  853.                 }
  854.                 else
  855.                 {
  856.                     if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  857.                         if(double_data[c] < double_data[c+2] ){ /* halfline to the right */
  858.                             double_data[c+2] = xmax+100;
  859.                         }
  860.                         else
  861.                         {
  862.                             double_data[c+2] = xmin-1000; /* halfline to the right */
  863.                         }
  864.                     }
  865.                     else
  866.                     {
  867.                         /* m */
  868.                         double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  869.                         /* q */
  870.                         double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  871.                         if(double_data[c] < double_data[c+2]){ /* to the right */
  872.                             double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it's just segment */
  873.                             double_data[c+3] = (m)*(double_data[c+2])+(q);
  874.                         }
  875.                         else
  876.                         { /* to the left */
  877.                             double_data[c+2] = xmin - 1000;
  878.                             double_data[c+3] = (m)*(double_data[c+2])+(q);
  879.                         }
  880.                     }
  881.                 }
  882.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],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,slider,slider_cnt,rotation_center);
  883.                 if(onclick > 0){click_cnt++;}
  884.                 /* click_cnt++; */
  885.             }
  886.             reset();
  887.             break;
  888.  
  889.         case HLINE:
  890.         /*
  891.         @ hline x,y,color
  892.         @ alternative : horizontalline
  893.         @ draw a horizontal line through point (x:y) in color 'color'
  894.         @ or use command <a href='#curve'>'curve color,formula'</a> to draw the line <br />(uses more points to draw the line; is however better draggable)
  895.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  896.         */
  897.             for(i=0;i<3;i++) {
  898.                 switch(i){
  899.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  900.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  901.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  902.                     double_data[3] = double_data[1];
  903.                     decimals = find_number_of_digits(precision);
  904.                     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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,100*xmin,decimals,100*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,slider,slider_cnt,rotation_center);
  905.                     if(onclick > 0){click_cnt++;}
  906.                     /* click_cnt++; */
  907.                     reset();
  908.                     break;
  909.                 }
  910.             }
  911.             break;
  912.  
  913.         case HLINES:
  914.         /*
  915.         @ hlines color,x1,y1,x2,y2,...
  916.         @ alternative : horizontallines
  917.         @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color'
  918.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  919.         */
  920.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  921.             fill_color = stroke_color;
  922.             i=0;
  923.             while( ! done ){     /* get next item until EOL*/
  924.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  925.                 if(i%2 == 0 ){
  926.                     double_data[i] = get_real(infile,0); /* x */
  927.                 }
  928.                 else
  929.                 {
  930.                     double_data[i] = get_real(infile,1); /* y */
  931.                 }
  932.                 i++;
  933.             }
  934.             decimals = find_number_of_digits(precision);
  935.             for(c = 0 ; c < i-1 ; c = c+2){
  936.                 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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,xmin,decimals,xmax,decimals,double_data[c+1],decimals,double_data[c+1],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,slider,slider_cnt,rotation_center);
  937.                 if(onclick > 0){click_cnt++;}
  938.                 /* click_cnt++; */
  939.             }
  940.             reset();
  941.             break;
  942.  
  943.         case VLINE:
  944.         /*
  945.         @ vline x,y,color
  946.         @ alternative : verticalline
  947.         @ draw a vertical line through point (x:y) in color 'color'
  948.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  949.         */
  950.             for(i=0;i<3;i++) {
  951.                 switch(i){
  952.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  953.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  954.                     case 2: stroke_color=get_color(infile,1);/* name or hex color */
  955.                         double_data[2] = double_data[0];
  956.                         decimals = find_number_of_digits(precision);
  957.                         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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,100*ymin,decimals,100*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,slider,slider_cnt,rotation_center);
  958.                         if(onclick > 0){click_cnt++;}
  959.                         /* click_cnt++; */
  960.                         reset();
  961.                     break;
  962.                 }
  963.             }
  964.             break;
  965.  
  966.         case VLINES:
  967.         /*
  968.         @ vlines color,x1,y1,x2,y2....
  969.         @ alternative : verticallines
  970.         @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color'
  971.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  972.         */
  973.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  974.             fill_color = stroke_color;
  975.             i=0;
  976.             while( ! done ){     /* get next item until EOL*/
  977.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  978.                 if(i%2 == 0 ){
  979.                     double_data[i] = get_real(infile,0); /* x */
  980.                 }
  981.                 else
  982.                 {
  983.                     double_data[i] = get_real(infile,1); /* y */
  984.                 }
  985.                 i++;
  986.             }
  987.             decimals = find_number_of_digits(precision);
  988.             for(c = 0 ; c < i-1 ; c = c+2){
  989.                 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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c],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,slider,slider_cnt,rotation_center);
  990.                 if(onclick > 0){click_cnt++;}
  991.                 /* click_cnt++; */
  992.             }
  993.             reset();
  994.             break;
  995.  
  996.         case SQUARE:
  997.         /*
  998.         @ square x,y,side (px) ,color
  999.         @ draw a square with left top corner (x:y) with side 'side' in color 'color'
  1000.         @ use command 'fsquare x,y,side,color' for a filled square
  1001.         @ use command/keyword  <a href='#filled'>'filled'</a> before command 'square x,y,side,color'
  1002.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1003.         */
  1004.             for(i=0;i<5;i++){
  1005.                 switch(i){
  1006.                     case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
  1007.                     case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
  1008.                     case 2:double_data[2] = (int) (get_real(infile,0));break; /* width in px */
  1009.                     case 3:
  1010.                         stroke_color = get_color(infile,1);/* name or hex color */
  1011.                         decimals = find_number_of_digits(precision);
  1012.                         double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
  1013.                         double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
  1014.                         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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[3],decimals,double_data[3],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[4],decimals,double_data[4],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,slider,slider_cnt,rotation_center);
  1015.                         if(onclick > 0){click_cnt++;}
  1016.                         /* click_cnt++; */
  1017.                         reset();
  1018.                         break;
  1019.                 }
  1020.             }
  1021.             break;
  1022.  
  1023.         case RECT:
  1024.         /*
  1025.         @ rect x1,y1,x2,y2,color
  1026.         @ use command 'frect x1,y1,x2,y2,color' for a filled rectangle
  1027.         @ use command/keyword  <a href='#filled'>'filled'</a> before command 'rect x1,y1,x2,y2,color'
  1028.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1029.         */
  1030.             for(i=0;i<5;i++){
  1031.                 switch(i){
  1032.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  1033.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  1034.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  1035.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  1036.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  1037.                         decimals = find_number_of_digits(precision);
  1038.                         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,%d,%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,slider,slider_cnt,rotation_center);
  1039.                         if(onclick > 0){click_cnt++;}
  1040.                         /* click_cnt++; */
  1041.                         reset();
  1042.                         break;
  1043.                 }
  1044.             }
  1045.             break;
  1046.  
  1047.         case RECTS:
  1048.         /*
  1049.         @ rects color,x1,y1,x2,y2,.....
  1050.         @ use command 'frect color,x1,y1,x2,y2,.....' for a filled rectangle
  1051.         @ use command/keyword  <a href='#filled'>'filled'</a> before command 'rects color,x1,y1,x2,y2,....'
  1052.         @ use command 'fillcolor color' before 'frects' to set the fill colour.
  1053.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  1054.         */
  1055.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1056.             fill_color = stroke_color;
  1057.             i=0;
  1058.             while( ! done ){     /* get next item until EOL*/
  1059.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  1060.                 if(i%2 == 0 ){
  1061.                     double_data[i] = get_real(infile,0); /* x */
  1062.                 }
  1063.                 else
  1064.                 {
  1065.                     double_data[i] = get_real(infile,1); /* y */
  1066.                 }
  1067.                 i++;
  1068.             }
  1069.             decimals = find_number_of_digits(precision);
  1070.             for(c = 0 ; c < i-1 ; c = c+4){
  1071.                 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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+2],decimals,double_data[c],decimals,double_data[c+1],decimals,double_data[c+1],decimals,double_data[c+3],decimals,double_data[c+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,slider,slider_cnt,rotation_center);
  1072.                 if(onclick > 0){click_cnt++;}
  1073.                 /* click_cnt++; */
  1074.             }
  1075.             reset();
  1076.             break;
  1077.  
  1078.         case ROUNDRECT:
  1079.         /*
  1080.         @ roundrect x1,y1,x2,y2,radius in px,color
  1081.         @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle
  1082.         @ use command/keyword  <a href='#filled'>'filled'</a> before command 'roundrect x1,y1,x2,y2,radius,color'
  1083.         @ fillcolor will be identical to 'color'
  1084.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1085.         */
  1086.             for(i=0;i<6;i++){
  1087.                 switch(i){
  1088.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  1089.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  1090.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  1091.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  1092.                     case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
  1093.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  1094.                         /* ensure no inverted roundrect is produced... */
  1095.                         if( double_data[0] > double_data[2] ){double_data[4] = double_data[0];double_data[0] = double_data[2];double_data[2] = double_data[4];}
  1096.                         if( double_data[3] > double_data[1] ){double_data[4] = double_data[1];double_data[1] = double_data[3];double_data[3] = double_data[4];}
  1097.                         decimals = find_number_of_digits(precision);
  1098.                         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,%d,%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,slider,slider_cnt,rotation_center);
  1099.                         if(onclick > 0){click_cnt++;}
  1100.                         /* click_cnt++;*/
  1101.                         reset();
  1102.                     break;
  1103.                 }
  1104.             }
  1105.             break;
  1106.  
  1107.         case ROUNDRECTS:
  1108.         /*
  1109.         @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,....
  1110.         @ for filled roundrects use command/keyword <a href='#filled'>'filled'</a> before command
  1111.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  1112.         */
  1113.  
  1114.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1115.             int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */
  1116.             fill_color = stroke_color;
  1117.             i=0;
  1118.             while( ! done ){     /* get next item until EOL*/
  1119.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  1120.                 if(i%2 == 0 ){
  1121.                     double_data[i] = get_real(infile,0); /* x */
  1122.                 }
  1123.                 else
  1124.                 {
  1125.                     double_data[i] = get_real(infile,1); /* y */
  1126.                 }
  1127.                 i++;
  1128.             }
  1129.             decimals = find_number_of_digits(precision);
  1130.             for(c = 0 ; c < i-1 ; c = c+4){
  1131.                 /* ensure no inverted roundrect is produced... */
  1132.                 if( double_data[c] > double_data[c+2] ){double_data[c+4] = double_data[c];double_data[c] = double_data[c+2];double_data[c+2] = double_data[c+4];}
  1133.                 if( double_data[c+3] > double_data[c+1] ){double_data[c+4] = double_data[c+1];double_data[c+1] = double_data[c+3];double_data[c+3] = double_data[c+4];}
  1134.                 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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+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,slider,slider_cnt,rotation_center);
  1135.                 if(onclick > 0){click_cnt++;}
  1136.                 /* click_cnt++; */
  1137.             }
  1138.             reset();
  1139.             break;
  1140.         case POLYLINE:
  1141.         /*
  1142.         @ polyline color,x1,y1,x2,y2...x_n,y_n
  1143.         @ brokenline color,x1,y1,x2,y2...x_n,y_n
  1144.         @ path color,x1,y1,x2,y2...x_n,y_n
  1145.         @ remark: there is <b>no</b> command polylines | brokenlines | paths ... just use multiple commands "polyline ,x1,y1,x2,y2...x_n,y_n"
  1146.         @ remark: there are commands "userdraw path(s),color" and "userdraw polyline,color"... these are two entirely different things !<br />the path(s) userdraw commands may be used for freehand drawing(s)<br />the polyline userdraw command is analogue to this polyline|brokenline command
  1147.         @ the command interconnects the points in the given order with a line (canvasdraw will not close the drawing: use command <a href="#poly">polygon</a> for this)
  1148.         @ use command <a href='#segments'>'segments'</a> for a series of segments.<br />these may be clicked/dragged individually
  1149.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1150.         */
  1151.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1152.             i=0;
  1153.             c=0;
  1154.             while( ! done ){     /* get next item until EOL*/
  1155.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  1156.                 for( c = 0 ; c < 2; c++){
  1157.                     if(c == 0 ){
  1158.                         double_data[i] = get_real(infile,0);
  1159.                         i++;
  1160.                     }
  1161.                     else
  1162.                     {
  1163.                         double_data[i] = get_real(infile,1);
  1164.                         i++;
  1165.                     }
  1166.                 }
  1167.             }
  1168.             /* draw path : not closed & not filled */
  1169.             decimals = find_number_of_digits(precision);
  1170.             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,%d,%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,slider,slider_cnt,rotation_center);
  1171.             if(onclick > 0){click_cnt++;}
  1172.             /* click_cnt++;*/
  1173.             reset();
  1174.             break;
  1175.         case POLY:
  1176.         /*
  1177.         @ poly color,x1,y1,x2,y2...x_n,y_n
  1178.         @ polygon color,x1,y1,x2,y2...x_n,y_n
  1179.         @ draw closed polygon
  1180.         @ use command 'fpoly' to fill it or use keyword <a href='#filled'>'filled'</a>
  1181.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1182.         */
  1183.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1184.             i=0;
  1185.             c=0;
  1186.             while( ! done ){     /* get next item until EOL*/
  1187.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  1188.                 for( c = 0 ; c < 2; c++){
  1189.                     if(c == 0 ){
  1190.                         double_data[i] = get_real(infile,0);
  1191.                         i++;
  1192.                     }
  1193.                     else
  1194.                     {
  1195.                         double_data[i] = get_real(infile,1);
  1196.                         i++;
  1197.                     }
  1198.                 }
  1199.             }
  1200.             /* draw path :  closed & optional filled */
  1201.                 decimals = find_number_of_digits(precision);
  1202.                 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,%d,%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,slider,slider_cnt,rotation_center);
  1203.                 if(onclick > 0){click_cnt++;}
  1204.                 /* click_cnt++; */
  1205.                 reset();
  1206.             break;
  1207.         case ARC:
  1208.         /*
  1209.          @ arc xc,yc,width,height,start_angle,end_angle,color
  1210.          @ can <b>not</b> be set "onclick" or "drag xy"
  1211.          @ <b>attention</b>: width in height in x/y-range
  1212.          @ will not zoom in or zoom out (because radius is given in pixels an not in x/y-system !). Panning will work
  1213.          @ use command <a href='#angle'>'angle'</a> for scalable angle
  1214.         */
  1215.             for(i=0;i<7;i++){
  1216.                 switch(i){
  1217.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  1218.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  1219.                     case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */
  1220.                     case 3:double_data[3] = get_real(infile,0);break; /* height y-range no pixels ! */
  1221.                     case 4:double_data[4] = get_real(infile,0);break; /* start angle in degrees */
  1222.                     case 5:double_data[5] = get_real(infile,0);break; /* end angle in degrees */
  1223.                     case 6:stroke_color = get_color(infile,1);/* name or hex color */
  1224.                     /* in Shape library:
  1225.                         x[0] = x[1] = xc = double_data[0]
  1226.                         y[0] = y[1] = yc = double_data[1]
  1227.                         w[0] = width = double_data[2]
  1228.                         w[1] = height = double_data[3]
  1229.                         h[0] = start_angle = double_data[4]
  1230.                         h[1] = end_angle = double_data[5]
  1231.                     */
  1232.                         decimals = find_number_of_digits(precision);
  1233.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,12,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],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,slider,slider_cnt,rotation_center);
  1234.                         reset();
  1235.                     break;
  1236.                 }
  1237.             }
  1238.             break;
  1239.         case ANGLE:
  1240.         /*
  1241.          @ angle xc,yc,width,start_angle,end_angle,color
  1242.          @ width is in x-range
  1243.          @ will zoom in/out
  1244.          @ if size is controlled by command <a href='#slider'>'slider'</a> use radians to set limits of slider.
  1245.         */
  1246.             for(i=0;i<7;i++){
  1247.                 switch(i){
  1248.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  1249.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  1250.                     case 2:double_data[2] = get_real(infile,0);break; /* width in pixels ! */
  1251.                     case 3:double_data[3] = get_real(infile,0);break; /* start angle in degrees */
  1252.                     case 4:double_data[4] = get_real(infile,0);break; /* end angle in degrees */
  1253.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  1254.                         decimals = find_number_of_digits(precision);
  1255.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,17,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],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,slider,slider_cnt,rotation_center);
  1256.                         reset();
  1257.                     break;
  1258.                 }
  1259.             }
  1260.             break;
  1261.  
  1262.         case ELLIPSE:
  1263.         /*
  1264.         @ ellipse xc,yc,radius_x,radius_y,color
  1265.         @ a ellipse with center xc/yc in x/y-range
  1266.         @ radius_x and radius_y are in pixels
  1267.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1268.         @ will shrink / expand on zoom out / zoom in
  1269.         */
  1270.             for(i=0;i<5;i++){
  1271.                 switch(i){
  1272.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  1273.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  1274.                     case 2:double_data[2] = get_real(infile,0);break; /* rx -> px  */
  1275.                     case 3:double_data[3] = get_real(infile,0);break; /* ry -> px  */
  1276.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  1277.                         decimals = find_number_of_digits(precision);
  1278.                         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,%d,%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,slider,slider_cnt,rotation_center);
  1279.                         if(onclick > 0){click_cnt++;}
  1280.                         /* click_cnt++; */
  1281.                         reset();
  1282.                     break;
  1283.                 }
  1284.             }
  1285.             break;
  1286.         case DASHTYPE:
  1287.         /*
  1288.         @ dashtype line_width_px,space_width_px
  1289.         @ every indiviual object may have its own dashtype, if needed...
  1290.         @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype
  1291.         @ default value "dashtype 2,2" e.g. 2px line and 2px space
  1292.         @ html5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable
  1293.         */
  1294.             for(i=0;i<2;i++){
  1295.                 switch(i){
  1296.                     case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
  1297.                     case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
  1298.                 }
  1299.             }
  1300.         break;
  1301.  
  1302.         case RAYS:
  1303.         /*
  1304.          @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
  1305.          @ draw rays in color 'color' and center (xc:yc)
  1306.          @ may be set draggable or onclick (every individual ray)
  1307.         */
  1308.             stroke_color=get_color(infile,0);
  1309.             fill_color = stroke_color;
  1310.             double_data[0] = get_real(infile,0);/* xc */
  1311.             double_data[1] = get_real(infile,0);/* yc */
  1312.             i=2;
  1313.             while( ! done ){     /* get next item until EOL*/
  1314.                 if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");}
  1315.                 if(i%2 == 0 ){
  1316.                     double_data[i] = get_real(infile,0); /* x */
  1317.                 }
  1318.                 else
  1319.                 {
  1320.                     double_data[i] = get_real(infile,1); /* y */
  1321.                 }
  1322.             fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
  1323.                 i++;
  1324.             }
  1325.  
  1326.             if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
  1327.             decimals = find_number_of_digits(precision);
  1328.             for(c=2; c<i;c = c+2){
  1329.                 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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[c],decimals,double_data[1],decimals,double_data[c+1],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,slider,slider_cnt,rotation_center);
  1330.                 /* click_cnt++; */
  1331.                 if(onclick > 0){click_cnt++;}
  1332.             }
  1333.             reset();
  1334.             break;
  1335.  
  1336.         case ARROWHEAD:
  1337.         /*
  1338.         @ arrowhead int
  1339.         @ default 8 (pixels)
  1340.         */
  1341.             arrow_head = (int) (get_real(infile,1));
  1342.             break;
  1343.  
  1344.         case ARROW:
  1345.         /*
  1346.         @ arrow x1,y1,x2,y2,h,color
  1347.         @ alternative : vector
  1348.         @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color'
  1349.         @ use command 'linewidth int' to adjust thickness of the arrow
  1350.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1351.         */
  1352.             for(i=0;i<6;i++){
  1353.                 switch(i){
  1354.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  1355.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  1356.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  1357.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  1358.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  1359.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  1360.                         decimals = find_number_of_digits(precision);
  1361.                         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,%d,%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,slider,slider_cnt,rotation_center);
  1362.                         if(onclick > 0){click_cnt++;}
  1363.                         /* click_cnt++;*/
  1364.                         reset();
  1365.                         break;
  1366.                 }
  1367.             }
  1368.             break;
  1369.  
  1370.         case ARROWS:
  1371.         /*
  1372.         @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n
  1373.         @ alternative : vectors
  1374.         @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
  1375.         @ use command 'linewidth int' to adjust thickness of the arrow
  1376.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  1377.         */
  1378.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1379.             fill_color = stroke_color;
  1380.             arrow_head = (int) get_real(infile,0);/* h */
  1381.             i=0;
  1382.             while( ! done ){     /* get next item until EOL*/
  1383.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  1384.                 if(i%2 == 0 ){
  1385.                     double_data[i] = get_real(infile,0); /* x */
  1386.                 }
  1387.                 else
  1388.                 {
  1389.                     double_data[i] = get_real(infile,1); /* y */
  1390.                 }
  1391.                 i++;
  1392.             }
  1393.             decimals = find_number_of_digits(precision);
  1394.             for(c = 0 ; c < i-1 ; c = c+4){
  1395.                 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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+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,slider,slider_cnt,rotation_center);
  1396.                 if(onclick > 0){click_cnt++;}
  1397.                 /* click_cnt++; */
  1398.             }
  1399.             reset();
  1400.             break;
  1401.  
  1402.         case ARROW2:
  1403.         /*
  1404.         @ arrow2 x1,y1,x2,y2,h,color
  1405.         @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and  in color 'color'
  1406.         @ use command 'arrowhead int' to adjust the arrow head size
  1407.         @ use command 'linewidth int' to adjust thickness of the arrow
  1408.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1409.         */
  1410.             for(i=0;i<6;i++){
  1411.                 switch(i){
  1412.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  1413.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  1414.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  1415.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  1416.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  1417.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  1418.                         decimals = find_number_of_digits(precision);
  1419.                         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,%d,%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,slider,slider_cnt,rotation_center);
  1420.                         if(onclick > 0){click_cnt++;}
  1421.                         /* click_cnt++;*/
  1422.                         reset();
  1423.                         break;
  1424.                 }
  1425.             }
  1426.             break;
  1427.  
  1428.         case ARROWS2:
  1429.         /*
  1430.         @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n
  1431.         @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
  1432.         @ use command 'linewidth int' to adjust thickness of the arrows
  1433.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  1434.         */
  1435.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1436.             fill_color = stroke_color;
  1437.             arrow_head = (int) get_real(infile,0);/* h */
  1438.             i=0;
  1439.             while( ! done ){     /* get next item until EOL*/
  1440.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  1441.                 if(i%2 == 0 ){
  1442.                     double_data[i] = get_real(infile,0); /* x */
  1443.                 }
  1444.                 else
  1445.                 {
  1446.                     double_data[i] = get_real(infile,1); /* y */
  1447.                 }
  1448.                 i++;
  1449.             }
  1450.             decimals = find_number_of_digits(precision);
  1451.             for(c = 0 ; c < i-1 ; c = c+4){
  1452.                 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,%d,%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+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,slider,slider_cnt,rotation_center);
  1453.                 if(onclick > 0){click_cnt++;}
  1454.                 /* click_cnt++; */
  1455.  
  1456.             }
  1457.             reset();
  1458.             break;
  1459.  
  1460.         case PARALLEL:
  1461.         /*
  1462.          @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
  1463.          @ can <b>not</b> be set "onclick" or "drag xy"
  1464.         */
  1465.             for( i = 0;i < 8; i++ ){
  1466.                 switch(i){
  1467.                     case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
  1468.                     case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
  1469.                     case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
  1470.                     case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
  1471.                     case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
  1472.                     case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
  1473.                     case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
  1474.                     case 7: stroke_color=get_color(infile,1);/* name or hex color */
  1475.                     decimals = find_number_of_digits(precision);
  1476.                     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,%d,%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,slider,slider_cnt,rotation_center);
  1477.                     if(onclick > 0){click_cnt++;}
  1478.                     /* click_cnt++*/;
  1479.                     reset();
  1480.                     break;
  1481.                     default: break;
  1482.                 }
  1483.             }
  1484.             break;
  1485.  
  1486.         case TRIANGLE:
  1487.         /*
  1488.          @ triangle x1,y1,x2,y2,x3,y3,color
  1489.          @ use ftriangle or keyword <a href='#filled'>'filled'</a> for a solid triangle
  1490.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1491.         */
  1492.             for(i=0;i<7;i++){
  1493.                 switch(i){
  1494.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  1495.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  1496.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  1497.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  1498.                     case 4: double_data[4] = get_real(infile,0);break; /* x */
  1499.                     case 5: double_data[5] = get_real(infile,0);break; /* y */
  1500.                     case 6: stroke_color = get_color(infile,1);/* name or hex color */
  1501.                         decimals = find_number_of_digits(precision);
  1502.                         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,%d,%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,slider,slider_cnt,rotation_center);
  1503.                         if(onclick > 0){click_cnt++;}
  1504.                         /* click_cnt++;*/
  1505.                         reset();
  1506.                         break;
  1507.                     default: break;
  1508.                 }
  1509.             }
  1510.             break;
  1511.         case TRIANGLES:
  1512.         /*
  1513.          @ triangles color,x1,y1,x2,y2,x3,y3,...
  1514.          @ use ftriangles or keyword <a href='#filled'>'filled'</a> for solid triangles
  1515.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  1516.         */
  1517.             stroke_color = get_color(infile,0);/* name or hex color */
  1518.             i = 0;
  1519.             decimals = find_number_of_digits(precision);
  1520.             while( ! done ){
  1521.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  1522.                 double_data[0] = get_real(infile,0); /* x1 */
  1523.                 double_data[1] = get_real(infile,0); /* y1 */
  1524.                 double_data[2] = get_real(infile,0); /* x2 */
  1525.                 double_data[3] = get_real(infile,0); /* y2 */
  1526.                 double_data[4] = get_real(infile,0); /* x3 */
  1527.                 double_data[5] = get_real(infile,1); /* y3 */
  1528.                 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,%d,%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,slider,slider_cnt,rotation_center);
  1529.                 if(onclick > 0){click_cnt++;}
  1530.                 i = i + 6;
  1531.             }
  1532.             reset();
  1533.             break;
  1534.         case LATTICE:
  1535.         /*
  1536.          @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
  1537.          @ can <b>not</b> be set "onclick" or "drag xy"
  1538.         */
  1539.             if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
  1540.             for( i = 0; i<9; i++){
  1541.                 switch(i){
  1542.                     case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
  1543.                     case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
  1544.                     case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
  1545.                     case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
  1546.                     case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
  1547.                     case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
  1548.                     case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
  1549.                     case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
  1550.                     case 8: stroke_color=get_color(infile,1);
  1551.                         decimals = find_number_of_digits(precision);
  1552.                         string_length = snprintf(NULL,0,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s);",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_affine,affine_matrix);
  1553.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1554.                         snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s);",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_affine,affine_matrix);
  1555.                         add_to_buffer(tmp_buffer);break;
  1556.                     default:break;
  1557.                 }
  1558.             }
  1559.             reset();
  1560.             break;
  1561.  
  1562.         case MULTISTROKEOPACITY:
  1563.         /*
  1564.          @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7
  1565.          @ float values 0 - 1 or integer values 0 - 255
  1566.          @ use before command <a href='#multidraw'>'multidraw'</a>
  1567.          @ if not set all stroke opacity_ will be set by previous command <em>'opacity int,int'</em>
  1568.          @ use these up to 7 different stroke opacities for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em>
  1569.          @ wims will not check the amount or validity of your input
  1570.          @ always use the same sequence as is used for 'multidraw'
  1571.         */
  1572.             if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  1573.             temp = get_string(infile,1);
  1574.             temp = str_replace(temp,",","\",\"");
  1575.             fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp);
  1576.             break;
  1577.         case MULTIFILLOPACITY:
  1578.         /*
  1579.          @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8
  1580.          @ float values 0 - 1 or integer values 0 - 255
  1581.          @ use before command <a href='#multidraw'>'multidraw'</a>
  1582.          @ if not set all fill opacity_ will be set by previous command <em>'opacity int,int'</em> and keyword <em>'filled'</em>
  1583.          @ use these up to 7 different stroke opacities for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_y</em>
  1584.          @ wims will not check the amount or validity of your input
  1585.          @ always use the same sequence as is used for 'multidraw'
  1586.         */
  1587.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  1588.             temp = get_string(infile,1);
  1589.             temp = str_replace(temp,",","\",\"");
  1590.             fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp);
  1591.             break;
  1592.         case MULTILABEL:
  1593.         /*
  1594.          @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text'
  1595.          @ use before command <a href='#multidraw'>'multidraw'</a>
  1596.          @ if not set all labels (e.g. the value='' of input type 'button') will be set by the english names for the draw_primitives (like 'point','circle'...)
  1597.          @ the 'stop drawing' button text <b>must</b> be the last item on the 'multilabel' -list <br />for example:<br /><em>multilabel punten,lijnen,Stop met Tekenen<br />multidraw points,lines</em>
  1598.          @ all buttons can be 'styled' by using commant 'inputstyle'<br /><b>note:</b><em>If you want to add some CSS style to the buttons...<br />the id's of the 'draw buttons' are their english command argument<br />(e.g. id="canvasdraw_points" for the draw points button).<br />the id of the 'stop drawing' button is "canvasdraw_stop_drawing".<br />the id of the "OK" button is"canvasdraw_ok_button"</em>
  1599.          @ wims will not check the amount or validity of your input
  1600.          @ always use the same sequence as is used for 'multidraw'
  1601.         */
  1602.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  1603.             temp = get_string(infile,1);
  1604.             temp = str_replace(temp,",","\",\"");
  1605.             fprintf(js_include_file,"var multilabel = [\"%s\"];",temp);
  1606.             break;
  1607.         case MULTILINEWIDTH:
  1608.         /*
  1609.          @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8
  1610.          @ use before command <a href='#multidraw'>'multidraw'</a>
  1611.          @ if not set all line width will be set by a previous command <em>'linewidth int'</em>
  1612.          @ use these up to 7 different line widths for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em>
  1613.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  1614.          @ always use the same sequence as is used for 'multidraw'
  1615.         */
  1616.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  1617.             temp = get_string(infile,1);
  1618.             temp = str_replace(temp,",","\",\"");
  1619.             fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp);
  1620.             break;
  1621.         case MULTIDASH:
  1622.         /*
  1623.          @ multidash 0,1,1
  1624.          @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <em>'multifill points,circle,segments'</em>, are dashed
  1625.          @ use before command <a href='#multidraw'>'multidraw'</a>
  1626.          @ if not set all objects will be set 'not dashed'...<br />unless a generic keyword <em>'dashed'</em> was given before command <em>'multidraw'</em>
  1627.          @ the dash-type is not -yet- adjustable <br />(e.g. command <em>dashtype line_px,space_px</em> will give no control over multidraw objects)
  1628.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  1629.          @ always use the same sequence as is used for 'multidraw'
  1630.         */
  1631.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  1632.             temp = get_string(infile,1);
  1633.             temp = str_replace(temp,",","\",\"");
  1634.             fprintf(js_include_file,"var multidash = [\"%s\"];",temp);
  1635.             reset();/* if command 'dashed' was given...reset to not-dashed */
  1636.             break;
  1637.         case MULTISNAPTOGRID:
  1638.         /*
  1639.          @ multisnaptogrid 0,1,1
  1640.          @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <em>'multifill points,circle,segments'</em>, will snap to the xy-grid (default 1 in x/y-coordinate system: see command <a href='#snaptogrid'>'snaptogrid'</a>)
  1641.          @ only the x-values snap_to_grid: <em>multisnaptogrid 0,2,2</em>
  1642.          @ only the y-values snap_to_grid: <em>multisnaptogrid 0,3,3</em>
  1643.          @ mixing allowed: <em>multisnaptogrid 1,2,3,0</em> e.g. the first object will snap to the xy-grid, the second draw object will snap to the x-values, the third object will snap to the y-valeus of the grid, the last object may be placed anywhere on the canvas
  1644.          @ use before command <a href='#multidraw'>'multidraw'</a>
  1645.          @ if not set all objects will be set 'no snap'...<br />unless a generic command 'snaptogrid' was given before command 'multidraw'
  1646.          @ commands <a href='#xsnaptogrid'>'xsnaptogrid'</a>, <a href='#ysnaptogrid'>'ysnaptogrid'</a>, <a href='#snaptofunction'>'snaptofunction'</a> and <a href='#snaptopoints'>'snaptopoints</a> x1,y1,x2,y2...' are <b>not</b> supported at this time
  1647.          @ always use the same sequence as is used for 'multidraw'
  1648.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  1649.         */
  1650.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  1651.             temp = get_string(infile,1);
  1652.             temp = str_replace(temp,",","\",\"");
  1653.             fprintf(js_include_file,"var multisnaptogrid = [\"%s\"];",temp);
  1654.             reset();/* if command 'dashed' was given...reset to not-dashed */
  1655.             break;
  1656.         case MULTIFILL:
  1657.         /*
  1658.          @ multifill 0,0,1,0,1,0,0
  1659.          @ meaning draw objects no. 3 and 5, in the list of command 'multifill', are filled<br />(if the object is fillable...and not a line,segment,arrow or point...)
  1660.          @ use before command <a href='#multidraw'>'multidraw'</a>
  1661.          @ if not set all objects -except point|points-  will be set 'not filled'...<br />unless a command 'filled' was given before command 'multifill'
  1662.          @ only suitable for draw_primitives like 'circle | circles' , 'triangle | triangles' and 'polygon'
  1663.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  1664.          @ always use the same sequence as is used for 'multidraw'
  1665.         */
  1666.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  1667.             temp = get_string(infile,1);
  1668.             temp = str_replace(temp,",","\",\"");
  1669.             fprintf(js_include_file,"var multifill = [\"%s\"];",temp);
  1670.             break;
  1671.         case MULTISTROKECOLORS:
  1672.         /*
  1673.          @ multistrokecolors color_name_1,color_name_2,...,color_name_8
  1674.          @ use before command <a href='#multidraw'>'multidraw'</a>
  1675.          @ if not set all colors will be 'stroke_color' , 'stroke_opacity'
  1676.          @ use these up to 6 colors for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em>
  1677.          @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
  1678.          @ always use the same sequence as is used for 'multidraw'
  1679.         */
  1680.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  1681.             fprintf(js_include_file,"var multistrokecolors = [");
  1682.             while( ! done ){
  1683.                 temp = get_color(infile,1);
  1684.                 fprintf(js_include_file,"\"%s\",",temp);
  1685.             }
  1686.             fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
  1687.             break;
  1688.         case MULTIFILLCOLORS:
  1689.         /*
  1690.          @ multifillcolors color_name_1,color_name_2,...,color_name_8
  1691.          @ use before command <a href='#multidraw'>'multidraw'</a>
  1692.          @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be 'stroke_color' , 'fill_opacity'
  1693.          @ use these up to 6 colors for the draw primitives used by command 'multidraw obj_type_1,obj_type_2...obj_type_n
  1694.          @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
  1695.          @ always use the same sequence as is used for 'multidraw'
  1696.         */
  1697.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  1698.             fprintf(js_include_file,"var multifillcolors = [");
  1699.             while( ! done ){
  1700.                 temp = get_color(infile,1);
  1701.                 fprintf(js_include_file,"\"%s\",",temp);
  1702.             }
  1703.             fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
  1704.             break;
  1705.         case MULTIUSERINPUT:
  1706.         /*
  1707.         @ multiuserinput 0,1,1,0
  1708.         @ meaning, when the command 'multidraw' is used <br />multidraw circles,points,lines,triangles<br />objects 'points' and 'lines' may additionally be 'drawn' by direct input (inputfields)<br/>all other objects must be drawn with a mouse
  1709.         @ in case of circle | circles a third inputfield for Radius (R) is added.<br />the radius must be in the x/y coordinate system (x-range) and <b>not</b> in pixels...students don't think in pixels.<br />note: R-values will not snap-to-grid
  1710.         @ in case of line(s) | segment(s) | arrow(s) the user should write <b>x1:y1</b> in the first inputfield and <b/>x2:y2</b> in the second.<br />These 'hints' are pre-filled into the input field.<br />other coordinate delimiters are ";" and "," e.g. <b>x1;y1</b> or <b>x1,y1</b>.<br />An error message (alert box) will popup when things are not correctly...
  1711.         @ in case of a triangle | poly3, three inputfields are provided.
  1712.         @ may be styled using command <a href="#inputstyle">"inputstyle"</a>
  1713.         @ an additional button 'stop drawing' may be used to combine userbased drawings with 'drag&amp;drop' or 'onclick' elements
  1714.         @ when exercise if finished (status=done) the buttons will not be shown.<br />To override this default behaviour use command / keyword 'status'
  1715.         @ use before command <a href='#multidraw'>'multidraw'</a>
  1716.         @ always use the same sequence as is used for 'multidraw'
  1717.         */
  1718.             /* simple rawmath and input check */
  1719.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  1720.             temp = get_string(infile,1);
  1721.             temp = str_replace(temp,",","\",\"");
  1722.             fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp);
  1723.             break;
  1724.         case MULTIDRAW:
  1725.         /*
  1726.          @ multidraw obj_type_1,obj_type_2...obj_type_8
  1727.          @ for single object user drawings you may also use command <a href="#userdraw">'userdraw'</a>
  1728.          @ implemented obj_types:<ul><li>point | points </li><li>circle | circles </li><li>line | lines </li><li>segment | segments </li><li>arrow | arrows <br />use command 'arrowhead int' for size (default value 8 pixels)</li><li>rect | rects </li><li>closedpoly<br />only one closedpolygon may be drawn.The number of 'corner points' is not preset (e.g. not limited,freestyle)<br />the polygone is closed when clicking on the first point again..(+/- 10px) </li><li>triangle | triangles<br />poly3, poly4, ... poly9 | polys3, polys4, ... polys9 <br />(<em>only 3 inputfields for poly*</em>)<br />parallelogram | parallelograms <br />(<em>no inputfields: parallelogram can be used for vector "contructions"</em>)</li></ul>
  1729.          @ additionally objects may be user labelled, using obj_type 'text'...<br >in this case allways a text input field and a (x:y) inputfield will be added to the page.<br />use commands 'fontfamily' and 'fontcolor' to adjust. (command 'multistrokeopacity' may be set to adjust text opacity)<br />note: no keyboard listeners are used
  1730.          @ it makes no sense using something like "multidraw point,points" ...
  1731.          @ 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)
  1732.          @ buttons for changing the obj_type (and incase of 'multiuserinput' , some inputfields and buttons) <br />will be present in the reserved div 'tooltip_div' and can be styled using command 'inputstyle some_css'
  1733.          @ the button label will be default the 'object primitive name' (like 'point', 'circles').<br />If you want a different label (e.g. an other language) ,use command 'multilabel'<br />for example in dutch: <br /><em>multilabel cirkel,lijnstuk,punten,STOP<br />multidraw circle,segment,points</em><br />(see command <a href='#multilabel'>'multilabel'</a> for more details)
  1734.          @ multidraw is incompatible with command 'tooltip'
  1735.          @ all 'multidraw' drawings will scale on zooming.<br />this in contrast to the command <a href="#userdraw">'userdraw'</a>.
  1736.          @ wims will <b>not</b> check the amount or validity of your command arguments ! <br />( use javascript console to debug any typo's )
  1737.          @ a local function read_canvas%d will read all userbased drawings.<br />The output is always a 9 lines string with fixed sequence.<br/>line 1 = points_x+";"+points_y+"\\n"<br/>line 2 = circles_x+";"+circlespoint_y+";"+multi_radius+"\\n"<br/>line 3 = segments_x+";"+segments_y+"\\n"<br/>line 4 = arrows_x+";"+arrows_y+"\\n"<br/>line 5 = lines_x+";"+lines_y+"\\n"<br/>line 6 = triangles_x+";"+triangles_y+"\\n"<br/>line 7 = rects_x +";"+rects_y+"\\n"<br />line 8 = closedpoly_x+";"+closedpoly_y+"\\n"<br/>line 9 = text_x+";"+text_y+";"+text"\\n"<br/>The x/y-data are in x/y-coordinate system and display precision may be set by a previous command 'precision 0 | 10 | 100 | 1000...'<br />In case of circles the radius is -for the time being- rounded to pixels<br /><b>use the wims "direct exec" tool to see the format of the reply</b>
  1738.          @ <b>attention</b>: for command argument 'closedpoly' only one polygone can be drawn.<br />The last point (e.g. the point clicked near the first point) of the array is removed.
  1739.          @ <em>technical: all 8 'draw primitives' + 'text' will have their own -transparent- PNG bitmap canvas. <br />So for example there can be a points_canvas entirely separated from a line_canvas.<br />This to avoid the need for a complete redraw when something is drawn to the canvas...(eg only the object_type_canvas is redrawn)<br />This in contrast to many very slow do-it-all HTML5 canvas javascript libraries.<br />The mouselisteners are attached to the canvas-div element.</em>
  1740.         */
  1741.         //    if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  1742.             if( use_userdraw == TRUE ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");}
  1743.             use_userdraw = TRUE;
  1744.             /* LET OP max 6 DRAW PRIMITIVES + TEXT */
  1745.             temp = get_string(infile,1);
  1746.             temp = str_replace(temp,",","\",\"");
  1747.             /* if these are not set, set the default values for the 6 (!!!)  draw_primitives + draw_text */
  1748.             fprintf(js_include_file,"\
  1749.             if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null  ){ var multistrokecolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\
  1750.             if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){ var multifillcolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\
  1751.             if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null ){ var multistrokeopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\
  1752.             if( typeof(multifillopacity) === 'undefined' &&  multifillopacity == null ){ var multifillopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\
  1753.             if( typeof(multilinewidth) === 'undefined' && multilinewidth == null ){ var multilinewidth = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
  1754.             if( typeof(multifill) === 'undefined' && multifill == null ){ var multifill = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
  1755.             if( typeof(multidash) === 'undefined' && multidash == null ){ var multidash = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
  1756.             if( typeof(multilabel) === 'undefined' && multilabel == null ){ var multilabel = [\"%s\",\"stop drawing\"];};\
  1757.             if( typeof(multiuserinput) === 'undefined' && multiuserinput == null ){ var multiuserinput= ['0','0','0','0','0','0','0','1'];};\
  1758.             if( typeof(multisnaptogrid) == 'undefined' && multisnaptogrid == null){var multisnaptogrid;if( x_use_snap_to_grid == 1 && y_use_snap_to_grid == 1){ multisnaptogrid = [1,1,1,1,1,1,1];}else{if( x_use_snap_to_grid == 1 ){ multisnaptogrid = [2,2,2,2,2,2,2];}else{if( y_use_snap_to_grid == 1 ){ multisnaptogrid = [3,3,3,3,3,3,3];}else{ multisnaptogrid = [0,0,0,0,0,0,0];};};};};\
  1759.             var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';",
  1760.             stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,
  1761.             fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,
  1762.             stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,
  1763.             fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,
  1764.             line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,
  1765.             use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,
  1766.             use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,
  1767.             temp,arrow_head,font_color,font_family);
  1768.  
  1769.             if(strstr(temp,"text") != NULL){
  1770.              if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  1771.             }
  1772.  
  1773.             /* the canvasses range from 1000 ... 1008 */
  1774.             add_js_multidraw(js_include_file,canvas_root_id,temp,input_style);
  1775.             reply_precision = precision;
  1776.             if( reply_format == 0){reply_format = 29;}
  1777.             reset();/* if command 'filled' / 'dashed' was given...reset all */
  1778.             break;
  1779.         case RULER:
  1780.         /*
  1781.         @ ruler x,y,x-width ,y-height,mode
  1782.         @ x,y are the initial location
  1783.         @ x-width , y-height are the ruler dimensions width &amp; height in xy-coordinate system
  1784.         @ the ruler scale is by definition the x-scale, set by command 'xrange'<br />for example: a ruler x-width of 6 will have a scale ranging from 0 to 6
  1785.         @ mode : use -1 to set the ruler interactive (eg mouse movement of ruler; drag &amp; rotate)<br />use mode = '0&deg; - 360&deg;' to set the ruler with a static angle of some value
  1786.         @ if combined with a protractor, use replyformat = 32
  1787.         @ only one ruler allowed (for the time being)
  1788.         @ when using command 'zoom' , pay <b>attention</b> to the size and symmetry of your canvas<br />...to avoid a partial image, locate the start position near the center of the visual canvas<br /><em>technical:<br /> the actual 'ruler' is just a static generated image in a new canvas-memory<br />This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas.<br />That is the reason for the 'high-speed dragging and rotating'.<br />I've limited its size to xsize &times; ysize e.g. the same size as the visual canvas... </em>
  1789.         @ usage: first left click on the ruler will activate dragging;<br />a second left click will activate rotating (just move mouse around)<br />a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br />a next click will restart this sequence...
  1790.         */
  1791.             for( i = 0;i < 5; i++ ){
  1792.                 switch(i){
  1793.                     case 0: double_data[0] = get_real(infile,0);break; /* x-center */
  1794.                     case 1: double_data[1] = get_real(infile,0);break; /* y-center */
  1795.                     case 2: double_data[2] = get_real(infile,0);break; /* x-width */
  1796.                     case 3: double_data[3] = get_real(infile,0);break; /* y-width */
  1797.                     case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */
  1798.                     decimals = find_number_of_digits(precision);
  1799.                     if( int_data[0] < 0 ){
  1800.                       if( js_function[JS_FIND_ANGLE] != 1 ){  js_function[JS_FIND_ANGLE] = 1; }
  1801.                     }
  1802.                     add_js_ruler(js_include_file,canvas_root_id,double_data[0],double_data[1],double_data[2],double_data[3],font_family,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width,int_data[0]);
  1803.                     string_length = snprintf(NULL,0,";ruler%d(); ",canvas_root_id);
  1804.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1805.                     snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id);
  1806.                     add_to_buffer(tmp_buffer);
  1807.                     reply_precision = precision;
  1808.                     /* no reply from ruler if non-interactive */
  1809.                     if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;}
  1810.                     break;
  1811.                     default: break;
  1812.                 }
  1813.             }
  1814.             break;
  1815.         case PROTRACTOR:
  1816.         /*
  1817.          @ protractor x,y,x_width,type,mode,use_a_scale
  1818.          @ x,y are the initial location
  1819.          @ x_width : give the width in x-coordinate system (e.g. not in pixels !)
  1820.          @ type = 1 : a triangle range  0 - 180<br />type = 2 : a circle shape 0 - 360
  1821.          @ mode : use -1 to set the protractor interactive (mouse movement of protractor)<br />use mode = '0&deg; - 360&deg;' to set the protractor with a static angle of some value
  1822.          @ if the value of the user_rotation angle is to be shown...use command <a href='#display'>display degree,color,fontsize</a><a href='#display'>display radian,color,fontsize</a>
  1823.          @ use_scale = 1 : the protractor will have some scale values printed; use_scale=0 to disable
  1824.          @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor...
  1825.          @ commands <em>stroke_color | fill_color | linewidth | opacity | font_family</em> will determine the looks of the protractor.
  1826.          @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command 'precision' to set the reply precision.
  1827.          @ if combined with a ruler, use replyformat = 32
  1828.          @ command <em>snap_to_grid</em> may be used to assist the pupil at placing the protractor
  1829.          @ when using command 'zoom' , pay <b>attention</b> to the size and symmetry of your canvas<br />...to avoid a partial image, locate the start position near the center of the visual canvas<br /><em>technical:<br /> the actual 'protractor' is just a static generated image in a new canvas-memory<br />This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas.<br />That is the reason for the 'high-speed dragging and rotating'.<br />I've limited its size to xsize &times; ysize e.g. the same size as the visual canvas... </em>
  1830.          @ only one protractor allowed (for the time being)
  1831.          @ usage: first left click on the protractor will activate dragging;<br />a second left click will activate rotating (just move mouse around)<br />a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br />a next click will restart this sequence...
  1832.         */
  1833.             for( i = 0;i < 6; i++ ){
  1834.                 switch(i){
  1835.                     case 0: double_data[0] = get_real(infile,0);break; /* x-center */
  1836.                     case 1: double_data[1] = get_real(infile,0);break; /* y-center */
  1837.                     case 2: double_data[2] = get_real(infile,0);break; /* x-width */
  1838.                     case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */
  1839.                     case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */
  1840.                     case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */
  1841.                     decimals = find_number_of_digits(precision);
  1842.                     if( int_data[2] < 0 ){
  1843.                      if( js_function[JS_FIND_ANGLE] != 1 ){ /* add je function for calculating angle */
  1844.                         js_function[JS_FIND_ANGLE] = 1;
  1845.                      }
  1846.                     }
  1847.                     add_js_protractor(js_include_file,canvas_root_id,int_data[0],double_data[0],double_data[1],double_data[2],font_family,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width,int_data[2],int_data[1]);
  1848.  
  1849.                     string_length = snprintf(NULL,0,";protractor%d(); ",canvas_root_id);
  1850.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1851.                     snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id);
  1852.                     add_to_buffer(tmp_buffer);
  1853.                     reply_precision = precision;
  1854.                     /* no reply from protractor if non-interactive */
  1855.                     if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;}
  1856.                     break;
  1857.                     default: break;
  1858.                 }
  1859.             }
  1860.             break;
  1861.         case USERDRAW:
  1862.         /*
  1863.         @ userdraw object_type,color
  1864.         @ only a single object_type is allowed.
  1865.         @ for multiple object user drawings use command <a href="#multidraw">'multidraw'</a>
  1866.         @ implemented object_type: <ul><li>point</li><li>points</li><li>crosshair</li><li>crosshairs</li><li>line</li><li>lines</li><li>vline</li><li>vlines</li><li>hline</li><li>hlines</li><li>demiline</li><li>demilines</li><li>segment</li><li>segments</li><li>polyline | brokenline </li><li>circle</li><li>circles</li><li>arrow</li><li>arrow2 (double arrow)</li><li>arrows</li><li>arrows2 (double arrows)</li><li>triangle</li><li>polygon</li><li>poly[3-9] (e.g poly3 ... poly7...poly9 </li><li>rect</li><li>roundrect</li><li>rects</li><li>roundrects</li><li>freehandline | path</li><li>freehandlines | paths</li><li>clickfill : fill the clicked area with a color<br />the click may be set <a href="#snaptogrid">snapped...</a></ br>only one area can be selected <br />use command <a href="#canvastype">'canvastype'</a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)</li><li>text</li><li>arc</li><li>arcs</li><li>input<br/>place a single inputfield on 'canvas'<br />use commands 'inputstyle' for css styling: use command 'linewidth' for adjusting the input field size (default 1)</li><li>inputs<br/>place multiple inputfield : placing inputfields on top of each other is not possible</li></ul>
  1867.         @ 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)
  1868.         @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />"backspace / delete / esc" will remove typed text if the mouse is clicked non the text.<br />You will need to hit "enter" to add the text to the array "userdraw_txt"<br />Placing the cursor somewhere on a typed text and hitting "delete/backspace/esc" ,
  1869.         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
  1870.         @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
  1871.         @ note: all objects will be removed -after a javascript confirm box- when clicked on an object point with middle or right mouse button (e.g. event.which != 1 : all buttons but left)
  1872.         @ use command "filled", "opacity int,int"  and "fillcolor color" to trigger coloured filling of fillable objects
  1873.         @ use command "dashed" and/or "dashtype int,int" to trigger dashing
  1874.         @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas();
  1875.         @ may be combined with onclick or drag xy  of other components of flyscript objects (although not very usefull...)
  1876.         @ may be combined with keyword 'userinput_xy'
  1877.         @ 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.!<br />use command <a href="#multidraw">multidraw</a> is this is a problem for you...
  1878.         */
  1879.             if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
  1880.                 canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");
  1881.             }
  1882.             reply_precision = precision;
  1883.             use_userdraw = TRUE;
  1884.             fprintf(js_include_file,"\n<!-- begin userdraw mouse events -->\nuserdraw_x = new Array();userdraw_y = new Array();\
  1885.             userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\
  1886.             var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;\
  1887.             if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\
  1888.             if(wims_status != \"done\"){\
  1889.             canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\
  1890.             canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\
  1891.             canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
  1892.             canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\
  1893.             canvas_div.addEventListener(\"touchend\"  ,function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
  1894.             }\n<!-- end userdraw mouse & touch events -->",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
  1895.             draw_type = get_string_argument(infile,0);
  1896.             stroke_color = get_color(infile,1);
  1897.             if( strcmp(draw_type,"point") == 0 ){
  1898.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1899.                 if(reply_format == 0 ){reply_format = 8;}
  1900.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1901.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1902.                 if(use_input_xy == 1){
  1903.                     add_input_circle(js_include_file,1,1);
  1904.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  1905.                 }
  1906.                 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);
  1907.             }
  1908.             else
  1909.             if( strcmp(draw_type,"points") == 0 ){
  1910.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1911.                 if(reply_format == 0 ){reply_format = 8;}
  1912.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1913.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1914.                 if(use_input_xy == 1){
  1915.                     add_input_circle(js_include_file,1,2);
  1916.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  1917.                 }
  1918.                 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);
  1919.             }
  1920.             else
  1921.             if( strcmp(draw_type,"segment") == 0 ){
  1922.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1923.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  1924.                 if(reply_format == 0){reply_format = 11;}
  1925.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1926.                 if(use_input_xy == 1){
  1927.                     add_input_segment(js_include_file,1);
  1928.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  1929.                 }
  1930.                 add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1931.             }
  1932.             else
  1933.             if( strcmp(draw_type,"polyline") == 0 ||  strcmp(draw_type,"brokenline") == 0 ){
  1934.                 if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
  1935.                 if(reply_format == 0){reply_format = 23;}
  1936.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1937.                 if( use_input_xy == 1 ){
  1938.                     add_input_polyline(js_include_file);
  1939.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  1940.                 }
  1941.                 add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1942.             }
  1943.             else
  1944.             if( strcmp(draw_type,"segments") == 0 ){
  1945.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1946.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  1947.                 if(reply_format == 0){reply_format = 11;}
  1948.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1949.                 if(use_input_xy == 1){
  1950.                     add_input_segment(js_include_file,2);
  1951.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  1952.                 }
  1953.                 add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1954.             }
  1955.             else
  1956.             if( strcmp(draw_type,"circle") == 0 ){
  1957.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1958.                 if(reply_format == 0){reply_format = 10;}
  1959.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  1960.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1961.                 if(use_input_xy == 1){
  1962.                     add_input_circle(js_include_file,2,1);
  1963.                     add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
  1964.                 }
  1965.                 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]);
  1966.             }
  1967.             else
  1968.             if( strcmp(draw_type,"circles") == 0 ){
  1969.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1970.                 if(reply_format == 0){reply_format = 10;}
  1971.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  1972.                 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]);
  1973.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1974.                 if(use_input_xy == 1){
  1975.                     add_input_circle(js_include_file,2,2);
  1976.                     add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
  1977.                 }
  1978.             }
  1979.             else
  1980.             if(strcmp(draw_type,"crosshair") == 0 ){
  1981.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  1982.                 if(reply_format == 0){reply_format = 8;}
  1983.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1984.                 add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
  1985.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1986.                 if(use_input_xy == 1){
  1987.                     add_input_crosshair(js_include_file,1);
  1988.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  1989.                 }
  1990.             }
  1991.             else
  1992.             if(strcmp(draw_type,"crosshairs") == 0 ){
  1993.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  1994.                 if(reply_format == 0){reply_format = 8;}
  1995.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1996.                 add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
  1997.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1998.                 if(use_input_xy == 1){
  1999.                     add_input_crosshair(js_include_file,2);
  2000.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  2001.                 }
  2002.             }
  2003.             else
  2004.             if(strcmp(draw_type,"freehandline") == 0 ){
  2005.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  2006.                 if(reply_format == 0){reply_format = 6;}
  2007.                 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]);
  2008.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2009.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2010.             }
  2011.             else
  2012.             if(strcmp(draw_type,"freehandlines") == 0 ){
  2013.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  2014.                 if(reply_format == 0){reply_format = 6;}
  2015.                 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]);
  2016.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2017.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2018.             }
  2019.             else
  2020.             if(strcmp(draw_type,"path") == 0 ){
  2021.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  2022.                 if(reply_format == 0){reply_format = 6;}
  2023.                 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]);
  2024.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2025.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2026.             }
  2027.             else
  2028.             if(strcmp(draw_type,"paths") == 0 ){
  2029.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  2030.                 if(reply_format == 0){reply_format = 6;}
  2031.                 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]);
  2032.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2033.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2034.             }
  2035.             else
  2036.             if(strcmp(draw_type,"arrows") == 0 ){
  2037.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  2038.                 if(reply_format == 0){reply_format = 11;}
  2039.                 add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  2040.                 if(use_input_xy == 1){
  2041.                     add_input_arrow(js_include_file,2);
  2042.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  2043.                 }
  2044.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2045.             }
  2046.             else
  2047.             if(strcmp(draw_type,"arrows2") == 0 ){
  2048.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  2049.                 if(reply_format == 0){reply_format = 11;}
  2050.                 add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  2051.                 if(use_input_xy == 1){
  2052.                     add_input_arrow(js_include_file,1);
  2053.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  2054.                 }
  2055.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2056.             }
  2057.             else
  2058.             if(strcmp(draw_type,"arrow2") == 0 ){
  2059.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  2060.                 if(reply_format == 0){reply_format = 11;}
  2061.                 add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  2062.                 if(use_input_xy == 1){
  2063.                     add_input_arrow(js_include_file,1);
  2064.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  2065.                 }
  2066.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2067.             }
  2068.             else
  2069.             if(strcmp(draw_type,"arrow") == 0 ){
  2070.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  2071.                 if(reply_format == 0){reply_format = 11;}
  2072.                 add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  2073.                 if(use_input_xy == 1){
  2074.                     add_input_arrow(js_include_file,1);
  2075.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  2076.                 }
  2077.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2078.             }
  2079.             else
  2080.             if(strcmp(draw_type,"polygon") == 0){
  2081.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  2082.                 if(reply_format == 0){reply_format = 2;}
  2083.                 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]);
  2084.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2085.                 if(use_input_xy == 2){
  2086.                   add_textarea_polygon(js_include_file);
  2087.                   add_textarea_xy(js_include_file,canvas_root_id,input_style);
  2088.                 }
  2089.             }
  2090.             else
  2091.             if(strncmp(draw_type,"poly",4) == 0){
  2092.                 if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
  2093.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  2094.                 if(reply_format == 0){reply_format = 2;}
  2095.                 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]);
  2096.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2097.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2098.             }
  2099.             else
  2100.             if(strcmp(draw_type,"triangle") == 0){
  2101.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  2102.                 if(reply_format == 0){reply_format = 2;}
  2103.                 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]);
  2104.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2105.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2106.             }
  2107.             else
  2108.             if( strcmp(draw_type,"hline") == 0 ){
  2109.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  2110.                 if(reply_format == 0){reply_format = 11;}
  2111.                 add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  2112.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2113.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2114.             }
  2115.             else
  2116.             if( strcmp(draw_type,"hlines") == 0 ){
  2117.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  2118.                 if(reply_format == 0){reply_format = 11;}
  2119.                 add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  2120.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2121.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2122.             }
  2123.             else
  2124.             if( strcmp(draw_type,"vline") == 0 ){
  2125.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  2126.                 if(reply_format == 0){reply_format = 11;}
  2127.                 add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  2128.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2129.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2130.             }
  2131.             else
  2132.             if( strcmp(draw_type,"vlines") == 0 ){
  2133.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  2134.                 if(reply_format == 0){reply_format = 11;}
  2135.                 add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  2136.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2137.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2138.             }
  2139.             else
  2140.             if( strcmp(draw_type,"line") == 0 ){
  2141.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  2142.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  2143.                 if(reply_format == 0){reply_format = 11;}
  2144.                 add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  2145.                 if( use_input_xy == 1 ){
  2146.                     add_input_line(js_include_file,1);
  2147.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  2148.                 }
  2149.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2150.             }
  2151.             else
  2152.             if( strcmp(draw_type,"lines") == 0 ){
  2153.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  2154.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  2155.                 if(reply_format == 0){reply_format = 11;}
  2156.                 add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  2157.                 if( use_input_xy == 1 ){
  2158.                     add_input_line(js_include_file,2);
  2159.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  2160.                 }
  2161.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2162.             }
  2163.             else
  2164.             if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"halflines") == 0 ){
  2165.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  2166.                 if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
  2167.                 if(reply_format == 0){reply_format = 11;}
  2168.                 add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  2169.                 if( use_input_xy == 1 ){
  2170.                     add_input_demiline(js_include_file,2);
  2171.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  2172.                 }
  2173.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2174.             }
  2175.             else
  2176.             if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"halfline") == 0 ){
  2177.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  2178.                 if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
  2179.                 if(reply_format == 0){reply_format = 11;}
  2180.                 add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  2181.                 if( use_input_xy == 1 ){
  2182.                     add_input_demiline(js_include_file,1);
  2183.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  2184.                 }
  2185.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2186.             }
  2187.             else
  2188.             if( strcmp(draw_type,"rects") == 0){
  2189.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  2190.                 if(reply_format == 0){reply_format = 2;}
  2191.                 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]);
  2192.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2193.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2194.             }
  2195.             else
  2196.             if( strcmp(draw_type,"roundrects") == 0){
  2197.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  2198.                 if(reply_format == 0){reply_format = 2;}
  2199.                 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]);
  2200.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2201.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2202.             }
  2203.             else
  2204.             if( strcmp(draw_type,"rect") == 0){
  2205.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  2206.                 if(reply_format == 0){reply_format = 2;}
  2207.                 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]);
  2208.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2209.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2210.             }
  2211.             else
  2212.             if( strcmp(draw_type,"roundrect") == 0){
  2213.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  2214.                 if(reply_format == 0){reply_format = 2;}
  2215.                 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]);
  2216.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2217.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2218.             }
  2219.             else
  2220.             if( strcmp(draw_type,"arcs") == 0){
  2221.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  2222.                 if(reply_format == 0){reply_format = 25;}
  2223.                 add_js_arc(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  2224.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2225.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2226.             }
  2227.             else
  2228.             if( strcmp(draw_type,"arc") == 0){
  2229.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  2230.                 if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
  2231.                 if(reply_format == 0){reply_format = 25;}
  2232.                 add_js_arc(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  2233.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2234.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2235.             }
  2236.             else
  2237.             if( strcmp(draw_type,"text") == 0){
  2238.                 if(reply_format == 0){reply_format = 17;}
  2239.                 add_js_text(js_include_file,canvas_root_id,font_size,font_family,stroke_color,stroke_opacity);
  2240.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2241.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2242.             }
  2243.             else
  2244.             if( strcmp(draw_type,"inputs") == 0){
  2245.                 if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  2246.                 if(reply_format == 0){reply_format = 27;}
  2247.                 add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width);
  2248.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2249.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2250.             }
  2251.             else
  2252.             if( strcmp(draw_type,"input") == 0){
  2253.                 if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  2254.                 if(reply_format == 0){reply_format = 27;}
  2255.                 add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width);
  2256.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  2257.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  2258.             }
  2259.             else
  2260.             if( strcmp(draw_type,"clickfill") == 0){
  2261.                 decimals = find_number_of_digits(precision);
  2262.                 if(reply_format == 0){reply_format = 22;}
  2263.                 add_js_clickfill(js_include_file,canvas_root_id,stroke_color,(int) (fill_opacity/0.0039215));
  2264.                 if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2265.                  js_function[DRAW_FILLTOBORDER] = 1;
  2266.                  add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  2267.                 }
  2268.             }
  2269.             else
  2270.             {
  2271.                 canvas_error("unknown drawtype or typo? ");
  2272.             }
  2273.             reset();
  2274.         break;
  2275.         case SNAPTOFUNCTION:
  2276.         /*
  2277.         @ snaptofunction some_function_in_x,some_funtion_in_y
  2278.         @ alternative : snaptofun some_function_in_x,some_funtion_in_y
  2279.         @ the next object will snap to the calculated values
  2280.         @ if you want only modification of y-values,just use: snaptofunction x,5*sin(1/y)
  2281.         @ if you want only modification of x-values,just use: snaptofunction 5*sin(1/x),y
  2282.         @ for now only one instance of 'snaptofunction' is allowed
  2283.         @ use rawmath on your functions: no validity checking is done by wims !
  2284.         @ example:<br />....<br />snaptofunction 5*(cos(x),4*sin(y)<br />linewidth 3<br />userdraw points,blue<br />....<br />
  2285.         @ example : switching x and y coordinates?<br />snaptofunction y,x
  2286.         */
  2287.         temp = get_string_argument(infile,0);
  2288.         fprintf(js_include_file,"\nuse_snap_to_points = 2;");
  2289.         if( use_js_math == FALSE){/* add this stuff only once...*/
  2290.             add_to_js_math(js_include_file); use_js_math = TRUE;
  2291.         }
  2292.         fprintf(js_include_file,"var snap_fun = {x:to_js_math('%s'),y:to_js_math('%s')};function snap_to_fun(px,py){ var x = px2x(px); var y = px2y(py); return [ x2px(eval(snap_fun.x)) , y2px(eval(snap_fun.y)) ];};",temp,get_string(infile,1));
  2293.         break;
  2294.         case SNAPTOPOINTS:
  2295.         /*
  2296.         @ snaptopoints x1,y1,x2,y2,x3,y3....
  2297.         @ a userdraw object will snap to these points.
  2298.         @ the array size (e.g. the number of points) of command 'snaptopoints' is limited by constant MAX_INT (canvasdraw.h)
  2299.         @ a draggable object (use command "drag  x|y|xy") will snap to the clossed of these points when dragged (mouseup)
  2300.         @ other options: use keyword "snaptogrid", "xsnaptogrid" or "ysnaptogrid"
  2301.         */
  2302.             i = 0;
  2303.             while( ! done ){     /* get next item until EOL*/
  2304.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  2305.                 if(i%2 == 0 ){
  2306.                     double_data[i] = get_real(infile,0); /* x */
  2307.                 }
  2308.                 else
  2309.                 {
  2310.                     double_data[i] = get_real(infile,1); /* y */
  2311.                 }
  2312.                 i++;
  2313.             }
  2314.             decimals = find_number_of_digits(precision);
  2315.             fprintf(js_include_file,"\nuse_snap_to_points = 1;\nfunction find_min_diff(x,y,X,Y){var diff = 100000000;var chk;var idx = 0;for(var p = 0 ; p < %d ; p++){chk = distance(x,y,X[p],Y[p]);if( chk  < diff ){ diff = chk; idx = p;};};return idx;};\nfunction snap_to_points(x,y){x = px2x(x); y = px2y(y);var points = [%s];var xpoints = points[0];var ypoints = points[1];var idx = find_min_diff(x,y,xpoints,ypoints);x = xpoints[idx];y = ypoints[idx];return [x2px(x),y2px(y)];};\n",(int) (0.5*i),double_xy2js_array(double_data,i,decimals));
  2316.         break;
  2317.  
  2318.         case SNAPTOGRID:
  2319.         /*
  2320.          @ snaptogrid
  2321.          @ keyword (no arguments required)
  2322.          @ a draggable object (use command "drag  x|y|xy") will snap to the given grid when dragged (mouseup)
  2323.          @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
  2324.          @ if no grid is defined ,points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1)
  2325.          @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
  2326.          @ if xminor / yminor is defined,(use keyword 'axis' to activate the minor steps) 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 />
  2327.         */
  2328.         fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;");
  2329.         break;
  2330.  
  2331.         case XSNAPTOGRID:
  2332.         /*
  2333.          @ xsnaptogrid
  2334.          @ keyword (no arguments required)
  2335.          @ a draggable object (use command "drag  x|y|xy") will snap to the given x-grid values when dragged (mouseup)
  2336.          @ in case of userdraw the drawn points will snap to xmajor grid
  2337.          @ if no grid is defined ,points will snap to every integer xrange value. (eg snap_x=1)
  2338.          @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
  2339.          @ if xminor is defined (use keyword 'axis' to activate xminor), 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 />
  2340.         */
  2341.         fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 0;");
  2342.         break;
  2343.  
  2344.         case YSNAPTOGRID:
  2345.         /*
  2346.          @ ysnaptogrid
  2347.          @ keyword (no arguments required)
  2348.          @ a draggable object (use command "drag  x|y|xy") will snap to the given y-grid values when dragged (mouseup)
  2349.          @ in case of userdraw the drawn points will snap to ymajor grid
  2350.          @ if no grid is defined ,points will snap to every integer yrange value. (eg snap_y=1)
  2351.          @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
  2352.          @ if yminor is defined (use keyword 'axis' to activate yminor), 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 />
  2353.         */
  2354.         fprintf(js_include_file,"\nx_use_snap_to_grid = 0;y_use_snap_to_grid = 1;");
  2355.         break;
  2356.  
  2357.         case USERINPUT:
  2358.         /*
  2359.          @ userinput function | textarea | inputfield
  2360.          @ alternative : userinput_function
  2361.          @ alternative : userinput_textarea
  2362.          @ alternative : userinput_xy
  2363.          @ textarea and inputfield are only usable in combination with some 'userdraw draw_ type'
  2364.          @ function may be used any time (e.g. without userdraw)
  2365.          @ multiple 'userinput function' commands may be used.
  2366.          @ use command "functionlabel some_string" to define the inputfield text : default value "f(x)="
  2367.          @ use command 'strokecolor some_color' to adjust the plot / functionlabel color
  2368.          @ use command 'inputstyle some_css' to adjust the inputfields
  2369.          @ use command 'fontsize int' to adjust the label fonts. (default 12px)
  2370.          @ the user input for the function will be corrected by a simple 'rawmath' implementation...<br />an error message will be shown if javascript can not interpret the user input
  2371.         */
  2372.             temp = get_string_argument(infile,1);
  2373.             if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
  2374.              if( js_function[DRAW_JSFUNCTION] != 1 ){
  2375.               add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */
  2376.               js_function[DRAW_JSFUNCTION] = 1;
  2377.               if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  2378.               add_input_jsfunction(js_include_file,canvas_root_id,input_style,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size);
  2379.               input_cnt++;
  2380.              }
  2381.              else
  2382.              {
  2383.               /* no need to add DRAW_JSFUNCTION , just call it with the parameters */
  2384.               fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size);
  2385.               input_cnt++;
  2386.              }
  2387.              if( use_js_math == FALSE){/* add this stuff only once...*/
  2388.               add_to_js_math(js_include_file);
  2389.               use_js_math = TRUE;
  2390.              }
  2391.              if( use_js_plot == FALSE){
  2392.               use_js_plot = TRUE;
  2393.               add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  2394.              }
  2395.             }
  2396.             else
  2397.             {
  2398.              if(strstr(temp,"inputfield") != 0 ){
  2399.               if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
  2400.               if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  2401.               use_input_xy = 1;
  2402.              }
  2403.              else
  2404.              {
  2405.               if(strstr(temp,"textarea") != 0 ){
  2406.                if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
  2407.                if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  2408.                use_input_xy = 2;
  2409.               }
  2410.               else
  2411.               {
  2412.                 canvas_error("userinput argument may be \"function,inputfield,textarea\"");
  2413.               }
  2414.              }
  2415.             }
  2416.             break;
  2417.  
  2418.         case USERTEXTAREA_XY:
  2419.         /*
  2420.         @ usertextarea_xy
  2421.         @ keyword (no arguments required)
  2422.         @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being...
  2423.         @ if set two textareas are added to the document<br />(one for x-values , one for y-values)
  2424.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  2425.         @ user drawings will not zoom on zooming (or pan on panning)
  2426.         @ use command 'inputstyle some_css' to adjust the inputarea.
  2427.         @ use command 'fontsize int' to adjust the text labels (if needed)
  2428.         */
  2429.             if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
  2430.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  2431.             use_input_xy = 2;
  2432.             break;
  2433.  
  2434.         case USERINPUT_XY:
  2435.         /*
  2436.         @ userinput_xy
  2437.         @ keyword (no arguments required)
  2438.         @ to be used in combination with command "userdraw object_type,color"
  2439.         @ 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)
  2440.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  2441.         @ 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.
  2442.         @ can <b>not</b> be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields
  2443.         @ user drawings will not zoom on zooming (or pan on panning)
  2444.         @ use command 'inputstyle some_css' to adjust the inputarea.
  2445.         @ use command 'fontsize int' to adjust the text labels (if needed)
  2446.         */
  2447.             /* add simple eval check to avoid code injection with unprotected eval(string) */
  2448.             if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
  2449.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  2450.             use_input_xy = 1;
  2451.             break;
  2452.  
  2453.         case FUNCTION_LABEL:
  2454.         /*
  2455.          @ functionlabel 'some string'
  2456.          @ default value "f(x)="
  2457.          @ no mathml allowed (just ascii string)
  2458.          @ use command 'fontsize int' to adjust the size
  2459.          @ use command 'strokecolor colorname' to adjust the labels (individually, if needed)
  2460.          @ if needed, use before every command 'userinput function | inputfield | textarea'
  2461.         */
  2462.             function_label = get_string_argument(infile,1);
  2463.             break;
  2464.  
  2465.         case USERINPUT_FUNCTION:
  2466.         /*
  2467.         @ userinput_function
  2468.         @ keyword (no arguments required)
  2469.         @ if set , a inputfield will be added to the page
  2470.         @ repeat keyword for more function input fields
  2471.         @ the userinput value will be plotted in the canvas
  2472.         @ this value may be read with 'read_canvas()'. <br />for do it yourself js-scripters : If this is the first inputfield in the script, its id is canvas_input0
  2473.         @ use before this command 'userinput_function',<br />commands like 'inputstyle some_css' , 'xlabel some_description' , 'opacity int,int' , 'linewidth int' , 'dashed' and 'dashtype int,int' to modify
  2474.         @ fontsize can be set using command 'fontsize int'
  2475.         @ incompatible with command 'intooltip link_text_or_image' : it uses the tooltip div for adding the inputfield
  2476.         */
  2477.             if( js_function[DRAW_JSFUNCTION] != 1 ){
  2478.              js_function[DRAW_JSFUNCTION] = 1;
  2479.              add_rawmath(js_include_file);
  2480.              if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  2481.              add_input_jsfunction(js_include_file,canvas_root_id,input_style,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size);
  2482.              input_cnt++;
  2483.             }
  2484.             else
  2485.             {
  2486.               /* no need to add DRAW_JSFUNCTION , just call it with the parameters */
  2487.              fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size);
  2488.              input_cnt++;
  2489.             }
  2490.             if( use_js_math == FALSE){/* add this stuff only once...*/
  2491.              add_to_js_math(js_include_file);
  2492.              use_js_math = TRUE;
  2493.             }
  2494.             if( use_js_plot == FALSE){
  2495.              use_js_plot = TRUE;
  2496.              add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  2497.             }
  2498.             break;
  2499.  
  2500.         case PLOTSTEPS:
  2501.             /*
  2502.              @ plotsteps a_number
  2503.              @ default 150
  2504.              @ only used for commands <a href="#curve">"curve / plot"</a> and  <a href="#levelcurve">"levelcurve"</a>
  2505.              @ use with care !
  2506.             */
  2507.             plot_steps = (int) (get_real(infile,1));
  2508.             break;
  2509.         case FONTSIZE:
  2510.         /*
  2511.          @ fontsize font_size
  2512.          @ default value 12
  2513.          @ note:for some macro's (like grid | legend | xaxistext | xlabel etc) sometimes command <a href="#fontfamily">"fontfamily"</a> can be used for some specific font-setting<br />this is however not always very straight forward...so just try and see what happens
  2514.         */
  2515.             font_size = (int) (get_real(infile,1));
  2516.             break;
  2517.         case FONTCOLOR:
  2518.         /*
  2519.          @ fontcolor color
  2520.          @ color: hexcolor or colorname
  2521.          @ default: black
  2522.          @ example usage: x/y-axis text
  2523.         */
  2524.             font_color = get_color(infile,1);
  2525.             break;
  2526.        
  2527.         case JSCURVE:
  2528.         /*
  2529.          @ jscurve color,formula(x)
  2530.          @ alternative : jsplot color,formula(x)
  2531.          @ your function will be plotted by the javascript engine of the client browser.
  2532.          @ use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e
  2533.          @ use parenthesis and rawmath : use 2*x instead of 2x ; use 2^(sin(x))...etc etc<br />use error console to debug any errors...
  2534.          @ <b>attention</b> : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot !
  2535.          @ no validity check is done by wims.
  2536.          @ zooming & panning are implemented :<br />use command 'zoom color' for mouse driven zooming<br />or use keyword 'setlimits' for inputfields setting xmin/xmax, ymin/ymax
  2537.          @ zooming & panning is better than for curves produced by command <a href="#curve">curve color,formula</a> because for avery change in x/y-range the curve is recalculated in javascript
  2538.          @ use command 'trace_jscurve formula(x)` for tracing
  2539.          @ use command 'jsmath  formula(x)` for calculating and displaying indiviual points on the curve
  2540.          @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet)
  2541.          @ commands plotjump / plotstep are not active for 'jscurve'
  2542.          @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve.
  2543.          @ plotting multiple js-curves on the same canvas <br/>(for example if you want to use 'userdraw clickfill,color' on <a href="#canvastype">canvastype</a> number 111 ,use :<br/> jscurve red,fun1(x),fun2(x)...fun_n(x)<br />  you want to specify individual colors | opacity | linewidth for these multiple js-curves.<br />use commands like: <a href="#multistrokecolors">multistrokecolors</a>,<a href="#multilinewidth">multilinewidth</a>, <a href="#multidash">multidash</a><br />, <a href="multistrokeopacity">multistroke</a><br />the <b>color</b> given for the command "jscurve <b>color</b>,formulas(x)" will not be used in that case...<br />but the color argument must still be given in any case (otherwise syntax error...)
  2544.         */
  2545.             stroke_color = get_color(infile,0);
  2546.             if( use_js_math == FALSE){/* add this stuff only once...*/
  2547.                 add_to_js_math(js_include_file);
  2548.                 use_js_math = TRUE;
  2549.             }
  2550.             if( use_js_plot == FALSE){
  2551.                 use_js_plot = TRUE;
  2552.                 add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  2553.             }
  2554.             temp = get_string(infile,1);
  2555.             temp = str_replace(temp,",","\",\"");
  2556.             string_length = snprintf(NULL,0,  "jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  2557.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2558.             snprintf(tmp_buffer,string_length,"jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  2559.             add_to_buffer(tmp_buffer);
  2560.             jsplot_cnt++;
  2561.              /* we need to create multiple canvasses, so we may zoom and pan ?? */
  2562.         break;
  2563.  
  2564.         case CURVE:
  2565.         /*
  2566.          @ curve color,formula(x)
  2567.          @ alernative : plot color,formula(x)
  2568.          @ use command <a href="#trange">trange</a> in parametric functions before command curve / plot  (trange -pi,pi)<br />curve color,formula1(t),formula2(t)
  2569.          @ use command <a href="#precision">"precision" </a>to ncrease the number of digits of the plotted points
  2570.          @ use command <a href="#plotsteps">"plotsteps"</a> to increase / decrease the amount of plotted points (default 150)
  2571.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2572.          @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">"jsplot"'</a><br />(command "curve" will only calculate points within the xrange)
  2573.         */
  2574.             if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
  2575.                 use_parametric = FALSE;
  2576.                 stroke_color = get_color(infile,0);
  2577.                 char *fun1 = get_string_argument(infile,0);
  2578.                 char *fun2 = get_string_argument(infile,1);
  2579.                 if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
  2580.                 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,%d,%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,slider,slider_cnt,rotation_center);
  2581.             }
  2582.             else
  2583.             {
  2584.                 stroke_color = get_color(infile,0);
  2585.                 char *fun1 = get_string_argument(infile,1);
  2586.                 if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  2587.                 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,%d,%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,slider,slider_cnt,rotation_center);
  2588.             }
  2589.             if(onclick > 0){click_cnt++;}
  2590.             /* click_cnt++; */
  2591.             reset();
  2592.             break;
  2593.  
  2594.         case LEVELCURVE:
  2595.         /*
  2596.         @ levelcurve color,expression in x/y,l1,l2,...
  2597.         @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
  2598.         @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...)
  2599.         @ every individual level curve may be set 'onclick / drag xy' <br />e.g. every single level curve (l1,l2,l3...l_n) has a unique identifier
  2600.         @ note : the arrays for holding the javascript data are limited in size
  2601.         @ note : reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...)
  2602.         */
  2603.             fill_color = get_color(infile,0);
  2604.             char *fun1 = get_string_argument(infile,0);
  2605.             if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  2606.             i = 0;
  2607.             done = FALSE;
  2608.             while( !done ){
  2609.              double_data[i] = get_real(infile,1);
  2610.              i++;
  2611.             }
  2612.             for(c = 0 ; c < i; c++){
  2613.              fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,16,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s));\n",click_cnt,onclick,drag_type,eval_levelcurve(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,double_data[c]),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,slider,slider_cnt,rotation_center);
  2614.              if(onclick > 0){click_cnt++;}
  2615.              /* click_cnt++; */
  2616.             }
  2617.             reset();
  2618.             break;
  2619.  
  2620.         case BEZIER:
  2621.         /*
  2622.         @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end
  2623.         @ draw a bezier curve between points, starting from (x_start:y_start)
  2624.         @ can <b>not</b> be dragged or set onclick
  2625.         */
  2626.             if( js_function[DRAW_BEZIER] != 1 ){ js_function[DRAW_BEZIER] = 1;}
  2627.             decimals = find_number_of_digits(precision);
  2628.             for(i = 0 ; i < 9; i++){
  2629.                 switch(i){
  2630.                     case 0: stroke_color = get_color(infile,0);break;
  2631.                     case 1: double_data[0] = get_real(infile,0);break;/* start x */
  2632.                     case 2: double_data[1] = get_real(infile,0);break;/* start y */
  2633.                     case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */
  2634.                     case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */
  2635.                     case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */
  2636.                     case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */
  2637.                     case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */
  2638.                     case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */
  2639.                         string_length = snprintf(NULL,0,"draw_bezier(%d,%d,[%f,%f,%f,%f,%f,%f,%f,%f],\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],double_data[6],double_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,use_affine,affine_matrix);
  2640.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2641.                         snprintf(tmp_buffer,string_length,"draw_bezier(%d,%d,[%f,%f,%f,%f,%f,%f,%f,%f],\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],double_data[6],double_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,use_affine,affine_matrix);
  2642.                         add_to_buffer(tmp_buffer);
  2643.                         break;
  2644.                     default: break;
  2645.                 }
  2646.             }
  2647.             reset();
  2648.             break;
  2649.  
  2650.         case TRACE_JSCURVE:
  2651.         /*
  2652.          @ trace_jscurve some_math_function
  2653.          @ will use a crosshair to trace the jsmath curve
  2654.          @ two inputfields will display the current x/y-values (numerical evaluation by javascript)
  2655.          @ default labels 'x' and 'y'<br />use commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' to customize the labels for the input fields
  2656.          @ use commands fontsize and inputstyle to format the fonts for labels and inputfields.
  2657.          @ use commands linewidth,strokecolor,crosshairsize to adjust the corsshair.
  2658.          @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x instead of 2x etc etc<br />no check is done on the validity of your function and/or syntax<br />use error console to debug any errors...
  2659.         @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
  2660.         */
  2661.             if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  2662.             if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  2663.             if( use_js_math == FALSE){
  2664.                 add_to_js_math(js_include_file);
  2665.                 use_js_math = TRUE;
  2666.             }
  2667.             add_trace_js_mouse(js_include_file,TRACE_CANVAS,canvas_root_id,stroke_color,get_string(infile,1),font_size,stroke_opacity,line_width,crosshair_size,input_style);
  2668.             break;
  2669.  
  2670.         case JSMATH:
  2671.         /*
  2672.             @ jsmath some_math_function
  2673.             @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
  2674.             @ default labels 'x' and 'y'<br />the commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' will set the label for the input fields
  2675.             @ use command 'inputstyle some_css' for styling the display fields. Use command 'fontsize int' to size the labels 'x' and 'y'
  2676.             @ example: jsmath sin(x^2)
  2677.             @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x instead of 2x etc etc<br />no check is done on the validity of your function and/or syntax<br />use error console to debug any errors...
  2678.             @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
  2679.         */
  2680.             if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  2681.             if( use_js_math == FALSE){
  2682.                 add_to_js_math(js_include_file);
  2683.                 use_js_math = TRUE;
  2684.             }
  2685.             add_calc_y(js_include_file,canvas_root_id,get_string(infile,1),font_size,input_style);
  2686.             break;
  2687.  
  2688.  
  2689.         case FLY_TEXT:
  2690.         /*
  2691.         @ text fontcolor,x,y,font,text_string
  2692.         @ font may be described by keywords : giant,huge,normal,small,tiny
  2693.         @ use command 'fontsize' to increase base fontsize for these keywords
  2694.         @ may be set "onclick" or "drag xy"
  2695.         @ backwards compatible with flydraw
  2696.         @ unicode supported: text red,0,0,huge,\\u2232
  2697.         @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element
  2698.         @ 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 reset 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands.
  2699.         */
  2700.             for(i = 0; i < 5 ;i++){
  2701.                 switch(i){
  2702.                     case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
  2703.                     case 1: double_data[0] = get_real(infile,0);break; /* x */
  2704.                     case 2: double_data[1] = get_real(infile,0);break; /* y */
  2705.                     case 3: fly_font = get_string_argument(infile,0);
  2706.                             if(strcmp(fly_font,"giant") == 0){
  2707.                                 fly_font_size = (int)(font_size + 24);
  2708.                             }
  2709.                             else
  2710.                             {
  2711.                                 if(strcmp(fly_font,"huge") == 0){
  2712.                                     fly_font_size = (int)(font_size + 14);
  2713.                                 }
  2714.                                 else
  2715.                                 {
  2716.                                     if(strcmp(fly_font,"large") == 0){
  2717.                                         fly_font_size = (int)(font_size + 6);
  2718.                                         }
  2719.                                         else
  2720.                                         {
  2721.                                             if(strcmp(fly_font,"small") == 0){
  2722.                                                 fly_font_size = (int)(font_size - 4);
  2723.                                                 if(fly_font_size<0){fly_font_size = 8;}
  2724.                                         }
  2725.                                     }
  2726.                                 }
  2727.                             }
  2728.                             break;
  2729.                     case 4:
  2730.                         temp = get_string_argument(infile,1);
  2731.                         decimals = find_number_of_digits(precision);
  2732.                         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,%f,\"%s\",%d,\"%s\",%d,%s,%d,%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,use_rotate,angle,temp,fly_font_size,"null",use_affine,affine_matrix,slider,slider_cnt,rotation_center);
  2733.                         if(onclick > 0){click_cnt++;}
  2734.                         /* click_cnt++;*/
  2735.                         reset();
  2736.                         break;
  2737.                     default:break;
  2738.                 }
  2739.             }
  2740.             break;
  2741.         case FLY_TEXTUP:
  2742.         /*
  2743.          @ textup fontcolor,x,y,font,text_string
  2744.          @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
  2745.          @ font may be described by keywords : giant,huge,normal,small,tiny
  2746.          @ use command 'fontsize' to increase base fontsize for the keywords
  2747.          @ backwards compatible with flydraw
  2748.          @ unicode supported: textup red,0,0,huge,\\u2232
  2749.          @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element
  2750.          @ 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 reset 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands.
  2751.         */
  2752.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
  2753.             for(i = 0; i<5 ;i++){
  2754.                 switch(i){
  2755.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  2756.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  2757.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  2758.                     case 3: fly_font = get_string_argument(infile,0);
  2759.                             if(strcmp(fly_font,"giant") == 0){
  2760.                                 fly_font_size = (int)(font_size + 24);
  2761.                             }
  2762.                             else
  2763.                             {
  2764.                                 if(strcmp(fly_font,"huge") == 0){
  2765.                                     fly_font_size = (int)(font_size + 14);
  2766.                                 }
  2767.                                 else
  2768.                                 {
  2769.                                     if(strcmp(fly_font,"large") == 0){
  2770.                                         fly_font_size = (int)(font_size + 6);
  2771.                                         }
  2772.                                         else
  2773.                                         {
  2774.                                             if(strcmp(fly_font,"small") == 0){
  2775.                                                 fly_font_size = (int)(font_size - 4);
  2776.                                                 if(fly_font_size<0){fly_font_size = 8;}
  2777.                                         }
  2778.                                     }
  2779.                                 }
  2780.                             }
  2781.                             break;
  2782.                     case 4:
  2783.                     decimals = find_number_of_digits(precision);
  2784.                     temp = get_string_argument(infile,1);
  2785.                     string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix);
  2786.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2787.                     snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix);
  2788.                     add_to_buffer(tmp_buffer);
  2789.                     break;
  2790.                     default:break;
  2791.                 }
  2792.             }
  2793.             reset();
  2794.             break;
  2795.         case FONTFAMILY:
  2796.         /*
  2797.          @ fontfamily font_description
  2798.          @ set the font family; for browsers that support it
  2799.          @ font_description: Ariel ,Courier, Helvetica etc
  2800.          @ 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
  2801.          @ use correct syntax : 'font style' 'font size'px 'fontfamily'
  2802.         */
  2803.             font_family = get_string(infile,1);
  2804.             break;
  2805.         case STRINGUP:
  2806.         /*
  2807.          @ stringup color,x,y,rotation_degrees,the text string
  2808.          @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
  2809.          @ unicode supported: stringup red,0,0,45,\\u2232
  2810.          @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change
  2811.  
  2812.         */
  2813.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library : rotate / mouse issues */
  2814.             for(i=0;i<6;i++){
  2815.                 switch(i){
  2816.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  2817.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  2818.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  2819.                     case 3: double_data[0] = get_real(infile,0);break;/* rotation */
  2820.                     case 4: decimals = find_number_of_digits(precision);
  2821.                             temp = get_string_argument(infile,1);
  2822.                             string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s);\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_affine,affine_matrix);
  2823.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2824.                             snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s);\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_affine,affine_matrix);
  2825.                             add_to_buffer(tmp_buffer);
  2826.                             break;
  2827.                     default:break;
  2828.                 }
  2829.             }
  2830.             reset();
  2831.             break;
  2832.         case STRING:
  2833.         /*
  2834.          @ string color,x,y,the text string
  2835.          @ may be set "onclick" or "drag xy"
  2836.          @ unicode supported: string red,0,0,\\u2232
  2837.          @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
  2838.         */
  2839.             for(i=0;i<5;i++){
  2840.                 switch(i){
  2841.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  2842.                     case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
  2843.                     case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
  2844.                     case 3: decimals = find_number_of_digits(precision);
  2845.                         temp = get_string_argument(infile,1);
  2846.                         decimals = find_number_of_digits(precision);
  2847.                         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,%f,\"%s\",%d,\"%s\",%d,%s,%d,%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,use_rotate,angle,temp,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center);
  2848.                         if(onclick > 0){click_cnt++;}
  2849.                         /* click_cnt++;*/
  2850.                         reset();
  2851.                         break;
  2852.                     default:break;
  2853.                 }
  2854.             }
  2855.             break;
  2856.         case CENTERSTRING:
  2857.         /*
  2858.          @ centerstring color,y-value,the text string
  2859.          @ title color,y-value,the text string
  2860.          @ draw a string centered on the canvas at y = y-value
  2861.          @ can not be set "onclick" or "drag xy" (...)
  2862.          @ unicode supported: centerstring red,5,\\u2232
  2863.          @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
  2864.         */
  2865.             if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;}
  2866.             for(i=0;i<3;i++){
  2867.                 switch(i){
  2868.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  2869.                     case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
  2870.                     case 2: temp = get_string_argument(infile,1);
  2871.                             /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
  2872.                             decimals = find_number_of_digits(precision);
  2873.                             string_length = snprintf(NULL,0,
  2874.                             "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
  2875.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2876.                             snprintf(tmp_buffer,string_length,"draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
  2877.                             add_to_buffer(tmp_buffer);
  2878.                             break;
  2879.                     default:break;
  2880.                 }
  2881.             }
  2882.             break;
  2883.         case MATHML:
  2884.         /*
  2885.         @ mathml x1,y1,x2,y2,mathml_string
  2886.         @ mathml will be displayed in a rectangle left top (x1:y1) , right bottom (x2:y2)
  2887.         @ can be set onclick <br />(however dragging is not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
  2888.         @ 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 /><b>attention</b>: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();"
  2889.         @ 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....
  2890.  
  2891.         */
  2892.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  2893.             for(i=0;i<5;i++){
  2894.                 switch(i){
  2895.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2896.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2897.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  2898.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  2899.                     case 4: decimals = find_number_of_digits(precision);
  2900.                             temp = get_string(infile,1);
  2901.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2902.                             string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d,%d,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick,click_cnt,stroke_color,stroke_opacity);
  2903.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2904.                             snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d,%d,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick,click_cnt,stroke_color,stroke_opacity);
  2905.                             add_to_buffer(tmp_buffer);
  2906.                             if(onclick == 1 ){click_cnt++;}
  2907.                             /*
  2908.                              in case inputs are present , trigger adding the read_mathml()
  2909.                              if no other reply_format is defined
  2910.                              note: all other reply types will include a reading of elements with id='mathml'+p)
  2911.                              */
  2912.                             if(strstr(temp,"mathml0") != NULL){
  2913.                              if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
  2914.                             }
  2915.                             break;
  2916.                     default:break;
  2917.                 }
  2918.             }
  2919.             reset();
  2920.             break;
  2921.         case HTTP:
  2922.         /*
  2923.          @ http x1,y1,x2,y2,http://some_adress.com
  2924.          @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2)
  2925.          @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe
  2926.          @ can <b>not</b> be 'set onclick' or 'drag xy'
  2927.         */
  2928.             if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}
  2929.             for(i=0;i<5;i++){
  2930.                 switch(i){
  2931.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2932.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2933.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  2934.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  2935.                     case 4: decimals = find_number_of_digits(precision);
  2936.                             temp = get_string(infile,1);
  2937.                             if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
  2938.                             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);
  2939.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+2);
  2940.                             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);
  2941.                             add_to_buffer(tmp_buffer);
  2942.                     break;
  2943.                 }
  2944.             }
  2945.             reset();
  2946.             break;
  2947.         case HTML:
  2948.         /*
  2949.          @ html x1,y1,x2,y2,html_string
  2950.          @ all tags are allowed<br /> html-code using inputfields could be read using your own javascript-code. Do not use id's like 'canvas_input0' etc.
  2951.          @ can be set onclick <br />(however dragging not supported)
  2952.         */
  2953.             break;
  2954.         case NOXAXIS:
  2955.         /*
  2956.         @ noaxis
  2957.         @ keyword
  2958.         @ if set, the automatic x-axis numbering will be ignored
  2959.         @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="grid">grid</a>
  2960.         @ to be used before command grid (see <a href="#grid">command grid</a>)
  2961.         */
  2962.             fprintf(js_include_file,"x_strings = [0,\" \"];\n");
  2963.             use_axis_numbering = 1;
  2964.             break;
  2965.         case NOYAXIS:
  2966.         /*
  2967.         @ noayis
  2968.         @ keyword
  2969.         @ if set, the automatic y-axis numbering will be ignored
  2970.         @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="grid">grid</a>
  2971.         @ to be used before command grid (see <a href="#grid">command grid</a>)
  2972.         */
  2973.             fprintf(js_include_file,"y_strings = [0,\" \"];\n");
  2974.             use_axis_numbering = 1;
  2975.             break;
  2976.         case X_AXIS_STRINGS:
  2977.         /*
  2978.          @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  2979.          @ alternative : xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  2980.          @ use these x-axis num1...num_n values instead of default xmin...xmax
  2981.          @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  2982.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a>
  2983.          @ use command "fontcolor", "fontfamily" to adjust font <br />defaults: black,12,Ariel<br />note: command "fontsize" is not active for this command.("fontsize" can be used for the <a href="#legend">"legend"</a> in a <a href="#grid">grid</a>)
  2984.          @ a javascript error message will flag non-matching value:name pairs
  2985.          @ if the 'x-axis words' are too big and will overlap, a simple alternating offset will be applied
  2986.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  2987.          @ 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
  2988.         */
  2989.             temp = get_string(infile,1);
  2990.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  2991.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  2992.             fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp);
  2993.             use_axis_numbering = 1;
  2994.             break;
  2995.         case X_AXIS_STRINGS_UP:
  2996.         /*
  2997.          @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  2998.          @ alternative : xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  2999.          @ the text will be rotated 90&deg; up
  3000.          @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  3001.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a>
  3002.          @ use these x-axis num1...num_n values instead of default xmin...xmax
  3003.          @ use command "fontcolor","fontfamily" to adjust font <br />defaults: black,12,Ariel<br />note: command "fontsize" is not active for this command.("fontsize" can be used for the <a href="#legend">"legend"</a> in a <a href="#grid">grid</a>)
  3004.          @ a javascript error message will flag non-matching value:name pairs
  3005.          @ if the 'x-axis words' are too big, they will overlap the graph<br /> (in this case the text will start from ysize upwards)
  3006.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  3007.          @ example:<br />size 400,400<br />xrange 0,13<br />yrange -100,500<br />axis<br />xaxisup 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
  3008.         */
  3009.             temp = get_string(infile,1);
  3010.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  3011.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  3012.             fprintf(js_include_file,"x_strings_up = 1;x_strings = [\"%s\"];\n ",temp);
  3013.             use_axis_numbering = 1;
  3014.             break;
  3015.         case Y_AXIS_STRINGS:
  3016.         /*
  3017.          @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  3018.          @ alternativ : yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  3019.          @ use command "fontcolor", "fontfamily" to adjust font <br />defaults: black,12,Ariel<br /> note: command "fontsize" is not active for this command.("fontsize" can be used for the <a href="#legend">"legend"</a> in a <a href="#grid">grid</a>)
  3020.          @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  3021.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a>
  3022.          @ use these y-axis num1...num_n  values instead of default ymin...ymax
  3023.          @ a javascript error message will flag non-matching value:name pairs
  3024.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  3025.          @ 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
  3026.         */
  3027.             temp = get_string(infile,1);
  3028.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  3029.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  3030.             fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
  3031.             use_axis_numbering = 1;
  3032.             break;
  3033.  
  3034.         case AXIS_NUMBERING:
  3035.         /*
  3036.             @ axisnumbering
  3037.             @ keyword (no arguments required)
  3038.             @ for special numbering of x-axis or y-axis see grid related commands <a href="#axis">axis</a>  <a href="#xaxis">xaxis</a> , <a href="#xaxisup">xaxisup</a>, <a href="#noxaxis">noxaxis</a> ,<a href="#yaxis">yaxis</a> , <a href="#yaxisup">yaxisup</a>, <a href="#noyaxis">noyaxis</a>
  3039.             @ to be used before command grid (see <a href="#grid">command grid</a>)
  3040.         */
  3041.             use_axis_numbering = 1;
  3042.             break;
  3043.         case AXIS:
  3044.         /*
  3045.             @ axis
  3046.             @ keyword (no arguments required)
  3047.             @ to be used before command grid (see <a href="#grid">command grid</a>)
  3048.  
  3049.         */
  3050.             use_axis = TRUE;
  3051.             break;
  3052.         case KILLSLIDER:
  3053.         /*
  3054.          @ killslider
  3055.          @ keyword (no arguments required)
  3056.          @ ends grouping of object under a previously defined slider
  3057.         */
  3058.             slider = 0;
  3059.             break;
  3060.         case SLIDER_X:
  3061.         /*
  3062.          @ sliderfunction_x some_function_in_x
  3063.          @ default value "x"
  3064.          @ the x-value of the slider object(s) will be calculated with this function.
  3065.          @ default is the x-slider value itself
  3066.          @ only used by command 'slider'
  3067.          @ define before a slider command !
  3068.         */
  3069.          slider_function_x = get_string(infile,1);
  3070.         break;
  3071.         case SLIDER_Y:
  3072.          slider_function_y = get_string(infile,1);
  3073.          /*
  3074.          @ sliderfunction_y some_function_in_y
  3075.          @ default value "y"
  3076.          @ the y-value of the slider object(s) will be calculated with this function.
  3077.          @ only used by command 'slider'
  3078.          @ define before a slider command !
  3079.          */
  3080.         break;
  3081.         case SLIDER:
  3082.         /*
  3083.         @ slider start_value,end_value,width px,height px,<em>type</em>,label
  3084.         @ <em>type</em> may be : xy,x,y,angle
  3085.         @ if a slider value display is desired, use for argument <em>type</em>:<br />xy display<br />x display<br />y display<br />angle radian<br />angle degree
  3086.         @ if a unit (or something like that...) for x/y-value display is needed, use commands 'xunit' and / or 'yunit'
  3087.         @ if the translation should be performed using a function, use for type: xy function,x function,y function<br />use commands sliderfunction_x and/or sliderfunction_y before the slider command to define the functions<br />example:<br />sliderfunction_x x^2<br />sliderfunction_y y^2<br />slider -5,5,100,100,xy function,Some_Text<br />...some stuff to slide<br />killslider<br />sliderfunction_x x^2-2<br />slider -15,15,100,10,x function,Some_Other_Text<br />...more stuff to slide<br />killslider<br />... etc
  3088.         @ use command 'slider' before draggable/clickable objects.
  3089.         @ drag and drop may be combined with rotation slider<br />for example an arrow rotated by a slider may be placed anywhere (drag&drop)<em>size 300,300<br />xrange -5,5<br />yrange -5,5<br />grid 1,1,grey<br />linewidth 3<br />drag xy<br />fillcolor orange<br />strokecolor blue<br />slider 0,2*pi,250,30,angle degrees,Rotate arrow<br />arrow 2,2,5,5,8,red</em>
  3090.         @ no slider for a math function, these can be traced using command 'trace_jscurve some_function_in_x'
  3091.         @ a slider will affect all draggable objects after the 'slider' command...<br />and can be used to group translate / rotate several objects...<br />until a next 'slider' or keyword 'killslider'
  3092.         @ amount of sliders is not limited.
  3093.         @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value'
  3094.         @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page
  3095.         @ every draggable object may have its own slider (no limit in amount of sliders)
  3096.         @ label: some slider text
  3097.         @ use fillcolor for slider ball
  3098.         @ use strokecolor for slider bar
  3099.         @ use fontfamily / fontcolor to set used fonts
  3100.         @ use opacity (only fill opacity will be used) to set transparency
  3101.         @ the slider canvas will be added to the 'tooltip div' : so incompatible with command tooltip ; setlimits etc
  3102.         */
  3103.             slider_cnt++;/* slider starts at 1 */
  3104.             for(i=0; i<6 ; i++){
  3105.                 switch(i){
  3106.                     case 0: double_data[0] = get_real(infile,0);break; /* start value */
  3107.                     case 1: double_data[1] = get_real(infile,0);break; /* end value */
  3108.                     case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
  3109.                     case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
  3110.                     case 4: temp = get_string_argument(infile,0); /* type : xy,x,y,angle */
  3111.                             if(strstr(temp,"xy")!= 0){
  3112.                                 slider = 4;
  3113.                             }
  3114.                             else
  3115.                             {
  3116.                                 if(strstr(temp,"x") != 0){
  3117.                                     slider = 1;
  3118.                                 }
  3119.                                 else
  3120.                                 {
  3121.                                     if(strstr(temp,"y") != 0){
  3122.                                         slider = 2;
  3123.                                     }
  3124.                                     else
  3125.                                     {
  3126.                                         if(strstr(temp,"angle") != 0){ /* angle diplay radian */
  3127.                                             slider = 3;
  3128.                                         }
  3129.                                         else
  3130.                                         {
  3131.                                             canvas_error("slider can be of type: xy,x,y,angle,fun_x:fun_y");
  3132.                                         }
  3133.                                     }
  3134.                                 }
  3135.                             }
  3136.                             if(strstr(temp,"display")!=0){
  3137.                                 if( slider == 4 ){ /* show x:y */
  3138.                                     use_slider_display = 1; /* show x xy values in canvas window */
  3139.                                 }
  3140.                                 else
  3141.                                 {
  3142.                                     if( slider == 1 ){ /* show only x -values */
  3143.                                      use_slider_display = 10;
  3144.                                     }
  3145.                                     else
  3146.                                     {
  3147.                                      use_slider_display = 11; /* show only y -values*/
  3148.                                     }
  3149.                                 }
  3150.                             }
  3151.                             else
  3152.                             {
  3153.                                 if(strstr(temp,"degree")!= 0){
  3154.                                     use_slider_display = 2; /* show angle values in canvas window */
  3155.                                 }
  3156.                                 else
  3157.                                 {
  3158.                                     if(strstr(temp,"radian")!=0){
  3159.                                         use_slider_display = 3; /* show radian values in canvas window */
  3160.                                     }
  3161.                                 }
  3162.                             }
  3163.                             if(use_slider_display != 0 && slider_cnt == 1){ /*add just once the display js-code */
  3164.                                 add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity);
  3165.                             }
  3166.                             if(strstr(temp,"fun")!= 0){
  3167.                                 if( use_js_math == FALSE){/* add this stuff only once...*/
  3168.                                     add_to_js_math(js_include_file); use_js_math = TRUE;
  3169.                                 }
  3170.                                 fprintf(js_include_file,"var slider_function%d = {x:to_js_math('%s'),y:to_js_math('%s')};",slider_cnt,slider_function_x,slider_function_y);
  3171.                                 slider_function_x = "x";slider_function_y = "y";/* reset the functions for next slider...*/
  3172.                             }
  3173.                             else
  3174.                             {
  3175.                                 fprintf(js_include_file,"var slider_function%d = {x:'x',y:'y'};",slider_cnt);
  3176.                                 /* we must define these, otherwise 'use stict' will cause an error */
  3177.                             }
  3178.                     break;
  3179.                     case 5: /* some string used for slider description  */
  3180.                             if(slider == 4){
  3181.                                 add_xyslider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color,use_slider_display);
  3182.                             }
  3183.                             else
  3184.                             {
  3185.                                 add_slider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color,use_slider_display);
  3186.                             }
  3187.                     break;
  3188.                 }
  3189.              }
  3190.             break;
  3191.         case SGRAPH:
  3192.         /*
  3193.          @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
  3194.          @ primitive implementation of a 'broken scale' graph...
  3195.          @ not very versatile: only usable in combination with userdraw <br />eg no other objects will obey this "coordinate system"<br />if you want to place an object into this coordinate system, be aware that 10% or 20% of xsize and/or ysize is 'lost'.<br />Use these "formulas" to recalculate the virtual coordinates:<br />factor=0.8 in case xstart != xmin (or ystart != ymin)<br />factor=0.9 in case xstart = xmin (or ystart = ymin)<br />px_x_point = ((factor*xsize)/(xmax - xstart))*(x_point - xmax)+xsize<br />x_recalculated = px*(xmax - xmin)/xsize + $xmin<br />px_y_point = -1*factor*y_point*ysize/(ymax - ystart) + ymax*factor*ysize/(ymax - ystart)<br />y_recalculated = ymax - py*(ymax - ymin)/ysize<br />
  3196.          @ 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
  3197.         */
  3198.             if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
  3199.             for(i = 0 ; i < 8 ;i++){
  3200.                 switch(i){
  3201.                     case 0:double_data[0] = get_real(infile,0);break;
  3202.                     case 1:double_data[1] = get_real(infile,0);break;
  3203.                     case 2:double_data[2] = get_real(infile,0);break;
  3204.                     case 3:double_data[3] = get_real(infile,0);break;
  3205.                     case 4:int_data[0] = (int)(get_real(infile,0));break;
  3206.                     case 5:int_data[1] = (int)(get_real(infile,0));break;
  3207.                     case 6:stroke_color = get_color(infile,0);break;
  3208.                     case 7:font_color = get_color(infile,1);
  3209.                     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);
  3210.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3211.                     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);
  3212.                     add_to_buffer(tmp_buffer);
  3213.                     break;
  3214.                     default:break;
  3215.                 }
  3216.             }
  3217.             /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
  3218.             break;
  3219.         case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px) ,axis/tickscolor]*/
  3220.         /*
  3221.          @ grid step_x,step_y,gridcolor
  3222.          @ if keywords <a href="#axis">"axis"</a> or <a href="#axisnumbering">"axisnumbering"</a> 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
  3223.          @ in that case, use command <a href="#fontcolor">"fontcolor"</a>, <a href="#fontsize">"fontsize"</a> and / or <a href="#fontfamily">"fontfamily"</a> to adjust font <br />defaults: black,12,Ariel
  3224.          @ 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)
  3225.          @ can <b>not</b> be set <a href="#onclick">"onclick"</a> or <a href="#drag">"drag xy"</a>
  3226.          @ use commands <a href="#xlabel">'xlabel some_string'</a> and/or <a href="#ylabel">'ylabel some_string'</a> to label axis;<br />use command "fontsize" to adjust size:the font family is non-configurable 'italic your_fontsize px Ariel' !
  3227.          @ see commands (see <a href="#xaxis">"xaxis" or xaxistext"</a>, <a href="#yaxis">"yaxis" or "yaxistext"</a> to set tailormade values on axis (the used font is set by <a href="fontfamily">command fontfamily</a>; default '12px Ariel')
  3228.          @ see command <a href="#legend">"legend"</a>to set a legend for the graph ;<br />use command <a href="#fontsize">"fontsize"</a> to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel')
  3229.         */
  3230.             if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
  3231.             if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
  3232.             for(i=0;i<4;i++){
  3233.                 switch(i){
  3234.                     case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
  3235.                     case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
  3236.                     case 2:
  3237.                     if( use_axis == TRUE ){
  3238.                         stroke_color = get_color(infile,0);
  3239.                         done = FALSE;
  3240.                         int_data[0] = (int) (get_real(infile,0));/* xminor */
  3241.                         int_data[1] = (int) (get_real(infile,0));/* yminor */
  3242.                         int_data[2] = (int) (get_real(infile,0));/* tic_length */
  3243.                         fill_color = get_color(infile,1); /* used as axis_color*/
  3244.                     }
  3245.                     else
  3246.                     {
  3247.                         int_data[0] = 1;
  3248.                         int_data[1] = 1;
  3249.                         stroke_color = get_color(infile,1);
  3250.                         fill_color = stroke_color;
  3251.                     }
  3252.                     if( double_data[0] <= 0 ||  double_data[1] <= 0 ||  int_data[0] <= 0 ||  int_data[1] <= 0 ){canvas_error("major or minor ticks must be positive !");}
  3253.                     /* set snap_x snap_y values in pixels */
  3254.                     fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
  3255.                     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,%s,%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_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity);
  3256.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3257.                     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,%s,%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_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity);
  3258.                     add_to_buffer(tmp_buffer);
  3259.                     break;
  3260.                 }
  3261.             }
  3262.             reset();
  3263.             break;
  3264.         case OPACITY:
  3265.         /*
  3266.         @ opacity 0-255,0-255
  3267.         @ opacity 0.0 - 1.0,0.0 - 1.0
  3268.         @ alternative : transparent
  3269.         @ first item is stroke opacity, second is fill opacity
  3270.         */
  3271.             for(i = 0 ; i<2;i++){
  3272.                 switch(i){
  3273.                     case 0: double_data[0]= get_real(infile,0);break;
  3274.                     case 1: double_data[1]= get_real(infile,1);break;
  3275.                     default: break;
  3276.                 }
  3277.             }
  3278.             if( double_data[0] > 255 ||  double_data[1] > 255  ){ canvas_error("opacity [0 - 255] , [0 - 255] ");}/* typo or non-RGB ? */
  3279.             if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = double_data[0];} /* 0.0 - 1.0 */
  3280.             if( double_data[0] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = double_data[0];} /* 0.0 - 1.0 */
  3281.             break;
  3282.         case ROTATION_CENTER:
  3283.         /*
  3284.         @ rotationcenter x_center,y_center
  3285.         @ define an rotation center in your x/y-coordinate system
  3286.         @ wims will not check the validity of your input; use javascript console to debug any erors
  3287.         @ if not defined a rotation will be around the first point of an object
  3288.         @ to be used before command <a href="#rotate">rotate</a>
  3289.         @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given
  3290.         */
  3291.             temp = get_string(infile,1);
  3292.             string_length = snprintf(NULL,0,"[ %s ]",temp);
  3293.             check_string_length(string_length);
  3294.             rotation_center = my_newmem(string_length+1);
  3295.             snprintf(rotation_center,string_length,"[%s]",temp);
  3296.             break;
  3297.         case ROTATE:
  3298.         /*
  3299.          @ rotate rotation_angle
  3300.          @ angle in degrees
  3301.          @ (only) the next object will be rotated is given angle
  3302.          @ positive values rotate counter clockwise
  3303.          @ attention: all objects will be rotated around their first point...<br /><em>rotate 45</em><br /> <em>triangle 1,1,5,1,3,4,red</em><br />will rotate 45 degrees around point (1:1)
  3304.          @ if another rotation center is needed, use command <a href="#rotationcenter">'rotationcenter xc,yc'</a>.<br />to reset this rotationcenter, use keyword <a href="killrotate">'killrotate'</a>
  3305.          @ attention: rotate will mess up the interactivity of the rotated object <br />e.g. if combined with command <a href="#drag">"drag xy"</a> or keyword <a href="onclick">"onclick"</a> : the mouse recognises the original -unrotated- coordinates of the object
  3306.         */
  3307.             use_rotate = TRUE;
  3308.             angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */
  3309.             break;
  3310.         case KILLROTATE:
  3311.         /*
  3312.          @ killrotate will reset the command <a href="#rotationcenter">rotationcenter xc,yc</a>
  3313.          @ a following rotate command will have the first object point as rotation center
  3314.          @ if not set, the rotation center will remain unchanged
  3315.         */
  3316.             rotation_center= my_newmem(6);
  3317.             snprintf(rotation_center,5,"null");
  3318.          break;
  3319.         case KILLAFFINE:
  3320.         /*
  3321.         @ killaffine
  3322.         @ keyword : resets the transformation matrix to 1,0,0,1,0,0
  3323.         */
  3324.             use_affine = FALSE;
  3325.             snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
  3326.             break;
  3327.         case AFFINE:
  3328.         /*
  3329.          @ affine a,b,c,d,tx,ty
  3330.          @ defines a transformation matrix for subsequent objects
  3331.          @ images drawn by setting skew params a &amp; d will be very different from Flydraw's "affine a,b,c,d,e,tx,ty" !!
  3332.          @ use keyword 'killaffine' to end the transformation
  3333.          @ note 1: only 'draggable' / 'noclick' objects can be transformed.
  3334.          @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet)
  3335.          @ note 3: no matrix operations on the transformation matrix implemented (yet)
  3336.          @ a : Scales the drawings horizontally
  3337.          @ b : Skews the drawings horizontally
  3338.          @ c : Skews the drawings vertically
  3339.          @ d : Scales the drawings vertically
  3340.          @ tx: Moves the drawings horizontally in xrange coordinate system
  3341.          @ ty: Moves the drawings vertically in yrange coordinate system
  3342.          @ the data precision may be set by preceding command "precision int"
  3343.         */
  3344.             for(i = 0 ; i<6;i++){
  3345.                 switch(i){
  3346.                     case 0: double_data[0] = get_real(infile,0);break;
  3347.                     case 1: double_data[1] = get_real(infile,0);break;
  3348.                     case 2: double_data[2] = get_real(infile,0);break;
  3349.                     case 3: double_data[3] = get_real(infile,0);break;
  3350.                     case 4: double_data[4] = get_real(infile,0);break;
  3351.                     case 5: double_data[5] = get_real(infile,1);
  3352.                         use_affine = TRUE;
  3353.                         decimals = find_number_of_digits(precision);
  3354.                         string_length = snprintf(NULL,0,     "[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f] ",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4]*xsize/(xmax - xmin),decimals,-1*double_data[5]*ysize/(ymax - ymin));
  3355.                         check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
  3356.                         snprintf(affine_matrix,string_length,"[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f] ",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4]*xsize/(xmax - xmin),decimals,-1*double_data[5]*ysize/(ymax - ymin));
  3357.                         break;
  3358.                     default: break;
  3359.                 }
  3360.             }
  3361.         break;
  3362.         case KILLTRANSLATION:
  3363.         /*
  3364.          @ killtranslation
  3365.          @ alternative : killtranslate
  3366.          @ resets the translation matrix to 1,0,0,1,0,0
  3367.         */
  3368.             use_affine = FALSE;
  3369.             snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
  3370.             break;
  3371.         case TRANSLATION:
  3372.         /*
  3373.          @ translation tx,ty
  3374.          @ alternative : translate
  3375.          @ will translate the next objects tx in xrange and ty in yrange
  3376.          @ use command 'killtranstation' to end the command
  3377.         */
  3378.             for(i = 0 ; i<2;i++){
  3379.                 switch(i){
  3380.                     case 0: double_data[0] = get_real(infile,0);break;
  3381.                     case 1: double_data[1] = get_real(infile,1);
  3382.                         use_affine = TRUE;
  3383.                         decimals = find_number_of_digits(precision);
  3384.                         string_length = snprintf(NULL,0, "[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin));
  3385.                         check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
  3386.                         snprintf(affine_matrix,string_length,"[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin));
  3387.                         break;
  3388.                     default: break;
  3389.                 }
  3390.             }
  3391.         break;
  3392.         case ANIMATE:
  3393.         /*
  3394.          @ animate type
  3395.          @ REMOVED : this should be done with a slider
  3396.          @ type may be "point" (nothing else , yet...)
  3397.          @ the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber'
  3398.          @ will animate a point on the next plot/curve command
  3399.          @ the curve will not be draw
  3400.          @ moves repeatedly from xmin to xmax
  3401.         */
  3402.             if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");}
  3403.             break;
  3404.  
  3405.         case DASHED:
  3406.         /*
  3407.         @ dashed
  3408.         @ keyword (no arguments required)
  3409.         @ next object will be drawn with a dashed line
  3410.         @ change dashing scheme by using command <a href="#dashtype">dashtype</a>
  3411.         */
  3412.             use_dashed = TRUE;
  3413.             break;
  3414.         case FILLED:
  3415.         /*
  3416.         @ filled
  3417.         @ keyword (no arguments required)
  3418.         @ the next 'fillable' object (only) will be filled
  3419.         @ use command "fillcolor color" to set fillcolor
  3420.         @ use command "opacity 0-255,0-255" to set stroke and fill-opacity
  3421.         @ 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 !
  3422.         */
  3423.             use_filled = TRUE;
  3424.             break;
  3425.         case STYLE:
  3426.         /*
  3427.          @ highlight color,opacity,linewidth
  3428.          @ NOT IMPLEMENTED
  3429.          @ use command "onclick" : when the object receives a userclick it will increase its linewidth
  3430.         */
  3431.             break;
  3432.  
  3433.         case FILLCOLOR:
  3434.         /*
  3435.         @ fillcolor colorname or #hex
  3436.         @ set the color for a filled object : mainly used for command 'userdraw obj,stroke_color'
  3437.         @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...)
  3438.         */
  3439.             fill_color = get_color(infile,1);
  3440.             break;
  3441.  
  3442.         case STROKECOLOR:
  3443.         /*
  3444.         @ strokecolor colorname or #hex
  3445.         @ to be used for commands that do not supply a color argument (like command 'linegraph')
  3446.         */
  3447.             stroke_color = get_color(infile,1);
  3448.             break;
  3449.  
  3450.         case BGIMAGE:
  3451.         /*
  3452.          @ bgimage image_location
  3453.          @ use an image as background .<br />technical: we use the background of 'canvas_div'
  3454.          @ the background image will be resized to match "width = xsize" and "height = ysize"
  3455.         */
  3456.         URL = get_string(infile,1);
  3457.         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);
  3458.             break;
  3459.  
  3460.         case BGCOLOR:
  3461.         /*
  3462.          @ bgcolor colorname or #hex
  3463.          @ use this color as background of the "div" containing the canvas(es)
  3464.         */
  3465.         /* [255,255,255]*/
  3466.             bgcolor = get_string(infile,1);
  3467.             if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
  3468.                 int found = 0;
  3469.                 for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  3470.                     if( strcmp( colors[i].name , bgcolor ) == 0 ){
  3471.                         bgcolor = colors[i].hex;
  3472.                         found = 1;
  3473.                         break;
  3474.                     }
  3475.                 }
  3476.                 if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");}
  3477.             }
  3478.             fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
  3479.             break;
  3480.  
  3481.         case COPY:
  3482.         /*
  3483.         @ copy x,y,x1,y1,x2,y2,[filename URL]
  3484.         @ The image may be "bitmap" or "SVG"
  3485.         @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
  3486.         @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
  3487.         @ [filename] is the URL of the image
  3488.         @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
  3489.         @ if command <a href="#drag">'drag x/y/xy'</a> 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 valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords 'snaptogrid','xsnaptogrid','ysnaptogrid' or 'snaptopoints x1,y1,x2,y2...'
  3490.         @ if keyword <a href="#onclick">'onclick'</a> is set before command 'copy' the image(s) is clickable (marked with a green rectangle around the image)<br />use 'read_dragdrop' to get the number of the clicked image(s)<br />use command 'clearbutton some_text' to reset the reply/click array.<br />example: 4 images; student clicked on image 2 and 3 : reply = 0,1,1,0<br />after clicking the clear button: reply = 0,0,0,0<br />May be mixed with commands 'drag x|y|xy' (use javascript read_canvas to get the new coordinates
  3491.         @ 'onclick' for external images may be mixed with canvas generated stuff (like lines,curves etc)
  3492.         @ you may draw / userdraw / drag other stuff on top of an "imported" image
  3493.         */
  3494.             for(i = 0 ; i<7;i++){
  3495.                 switch(i){
  3496.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
  3497.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
  3498.                     case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
  3499.                     case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
  3500.                     case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
  3501.                     case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
  3502.                     case 6: URL = get_string(infile,1);
  3503.                             int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
  3504.                             int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
  3505.                             if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  3506.                             int_data[9] = click_cnt;
  3507.                             if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
  3508.                                  if( reply_format == 0 ){ reply_format = 20; }
  3509.                                  int_data[8] = 2;/* drag & drop */
  3510.                             }
  3511.                             else
  3512.                             {
  3513.                                 if( onclick == 1  ){
  3514.                                     reply_format = 20;
  3515.                                     int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
  3516.                                     click_cnt++; /* will also be used in dragstuff ! */
  3517.                                 }
  3518.                                 else
  3519.                                 {
  3520.                                     int_data[8] = 0; /* just static image */
  3521.                                 }
  3522.                             }
  3523. /*
  3524. function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,ext_img_cnt,resizable,draggable,click_cnt)
  3525. */
  3526.                             string_length = snprintf(NULL,0,  "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%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,int_data[8],int_data[9]);
  3527.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3528.                             snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%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,int_data[8],int_data[9]);
  3529.                             drag_type = -1; /* reset the drag_type indicator */
  3530.                             ext_img_cnt++;
  3531.                             onclick=0;
  3532.                             add_to_buffer(tmp_buffer);
  3533.                             break;
  3534.                     default: break;
  3535.                 }
  3536.             }
  3537.             break;
  3538. /*
  3539. HTML5 specs:
  3540. context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  3541. img     Specifies the image, canvas, or video element to use
  3542. sx      The x coordinate where to start clipping : x1 = int_data[0]
  3543. sy      The y coordinate where to start clipping : x2 = int_data[1]
  3544. swidth  The width of the clipped image : int_data[2] - int_data[0]
  3545. sheight The height of the clipped image : int_data[3] - int_data[1]
  3546. x       The x coordinate where to place the image on the canvas : dx1 = int_data[4]
  3547. y       The y coordinate where to place the image on the canvas : dy1 = int_data[5]
  3548. width   The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6]
  3549. height  The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7]
  3550. */
  3551.         case COPYRESIZED:
  3552.         /*
  3553.         @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
  3554.         @ The image may be any "bitmap" or "SVG"
  3555.         @ 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
  3556.         @ (dx1:dy1) must be left top corner; (dx2 :dy2) must be right bottom corner of inserted image
  3557.         @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
  3558.         @ URL is normal URL of network reachable image file location<br />(as seen from public_html-root or network reachable 'http://some_server/my_images/test.gif'<br />(eg no special wims paths are searched !!)
  3559.         @ if command <a href="#drag">'drag x/y/xy'</a> 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 valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords 'snaptogrid','xsnaptogrid','ysnaptogrid' or 'snaptopoints x1,y1,x2,y2...'
  3560.         @ if keyword <a href="#onclick">'onclick'</a> is set before command 'copy' the image(s) is clickable (marked with a green rectangle around the image)<br />use 'read_dragdrop' to get the number of the clicked image(s)<br />use command 'clearbutton some_text' to reset the reply/click array.<br />example: 4 images; student clicked on image 2 and 3 : reply = 0,1,1,0<br />after clicking the clear button: reply = 0,0,0,0<br />May be mixed with commands 'drag x|y|xy' (use javascript read_canvas to get the new coordinates
  3561.         @ 'onclick' for external images may be mixed with canvas generated stuff (like lines,curves etc)
  3562.         @ you may draw / userdraw / drag stuff on top of an "imported" image
  3563.         */
  3564.             for(i = 0 ; i<9;i++){
  3565.                 switch(i){
  3566.                     case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
  3567.                     case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
  3568.                     case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
  3569.                     case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
  3570.                     case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
  3571.                     case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
  3572.                     case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
  3573.                     case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
  3574.                     case 8: URL = get_string(infile,1);
  3575.                             /* flag error when wrong diagonal:  copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */
  3576.                             if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){
  3577.                                 canvas_error("in copyresized , use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! ");
  3578.                             }
  3579.                             int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */
  3580.                             int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */
  3581.                             int_data[6] = abs(int_data[6] - int_data[4]);/* width */
  3582.                             int_data[7] = abs(int_data[7] - int_data[5]);/* height */
  3583.                             if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  3584.                             int_data[9] = click_cnt;
  3585.                             if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
  3586.                                  if( reply_format == 0 ){ reply_format = 20; }
  3587.                                  int_data[8] = 2;/* drag & drop */
  3588.                             }
  3589.                             else
  3590.                             {
  3591.                                 if( onclick == 1  ){
  3592.                                     reply_format = 20;
  3593.                                     int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
  3594.                                     click_cnt++; /* will also be used in dragstuff ! */
  3595.                                 }
  3596.                                 else
  3597.                                 {
  3598.                                     int_data[8] = 0; /* just static image */
  3599.                                 }
  3600.                             }
  3601. /*
  3602. (URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt)
  3603. URL,[2],[3],[6],    [7], [4],[5],[6],[7],ext_img_cnt,1,    [8],      [9]
  3604. */
  3605.                             string_length = snprintf(NULL,0,  "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%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,int_data[8],int_data[9]);
  3606.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3607.                             snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%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,int_data[8],int_data[9]);
  3608.                             drag_type = -1; /* reset the drag_type indicator */
  3609.                             ext_img_cnt++;
  3610.                             onclick=0;
  3611.                             add_to_buffer(tmp_buffer);
  3612.                             break;
  3613.                     default: break;
  3614.                 }
  3615.             }
  3616.             break;
  3617.         case CLEARBUTTON:
  3618.         /*
  3619.          @ clearbutton value
  3620.          @ alternative : delete
  3621.          @ alternative : erase
  3622.          @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text 'value'
  3623.          @ <b>attention</b> command 'clearbutton' is incompatible with <a href="multidraw">multidraw</a> based drawings<br/>(in 'multidraw' there is always a remove_object_button for every drawprimitive)
  3624.          @ normally <a href="#userdraw">userdraw</a> primitives have the option to use middle/right mouse button on<br /> a point of the object to remove this specific object...this clear button will remove all drawings
  3625.          @ uses the tooltip placeholder div element: may not be used with command 'intooltip'
  3626.          @ use command <a href="#inputstyle">'inputstyle'</a> to style the button...
  3627.          @ the clearbutton will have id="canvas_scripts[%d]" ; starting with %d=0 for the first script<br />to change the style of all "clearbutton" of all included canvasdraw scripts, use something like<br /><em>if(document.getElementById("clearbutton"+canvas_scripts[0])){<br />&nbsp;var p = 0;<br />&nbsp;while(document.getElementById("clearbutton"+canvas_scripts[p])){<br />&nbsp;&nbsp;document.getElementById("clearbutton"+canvas_scripts[p]).className="some_class_name";<br />&nbsp;&nbsp;&lt;!&minus;&minus; or document.getElementById("clearbutton"+canvas_scripts[p]).setAttribute("style","some_style"); &minus;&minus;&gt;<br />&nbsp;&nbsp;p++;<br />&nbsp;};<br />};<br />
  3628.         */
  3629.         if(reply_format == 29){/* eg multidraw is selected */
  3630.          canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw");
  3631.         }
  3632.             add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1));
  3633.         break;
  3634.         case INPUTSTYLE:
  3635.         /*
  3636.         @ inputstyle style_description
  3637.         @ may be used before any 'style-able' html object.(like inputfields or buttons)<br />or any html objects that are generated by some canvasdraw commands
  3638.         @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt
  3639.         */
  3640.             input_style = get_string(infile,1);
  3641.             break;
  3642.         case INPUT:
  3643.         /*
  3644.          @ input x,y,size,editable,value
  3645.          @ to set inputfield "readonly", use editable = 0
  3646.          @ only active inputfields (editable = 1) will be read with read_canvas();
  3647.          @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be cleared and set readonly<br />override this by keyword <a href="#status">'status'</a>
  3648.          @ may be further controlled by <a href="#inputstyle">"inputstyle"</a> (inputcss is not yet implemented...)
  3649.          @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
  3650.         */
  3651.         if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  3652.             for(i = 0 ; i<5;i++){
  3653.                 switch(i){
  3654.                     case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
  3655.                     case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
  3656.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
  3657.                     case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
  3658.                     case 4:
  3659.                             temp = get_string_argument(infile,1);
  3660.                             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);
  3661.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3662.                             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);
  3663.                             add_to_buffer(tmp_buffer);
  3664.                             input_cnt++;break;
  3665.                     default: break;
  3666.                 }
  3667.             }
  3668.             if(reply_format == 0 ){reply_format = 15;}
  3669.             reset();
  3670.             break;
  3671.         case TEXTAREA:
  3672.         /*
  3673.          @ textarea x,y,cols,rows,readonly,value
  3674.          @ may be further controlled by <a href="#inputstyle">"inputstyle"</a>
  3675.          @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be cleared and set readonly<br />override this by keyword <a href="#status">'status'.</a>
  3676.          @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
  3677.         */
  3678.             if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}
  3679.             for(i = 0 ; i<6;i++){
  3680.                 switch(i){
  3681.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
  3682.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
  3683.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
  3684.                     case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
  3685.                     case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
  3686.                     case 5: temp = get_string_argument(infile,1);
  3687.                             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);
  3688.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3689.                             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);
  3690.                             add_to_buffer(tmp_buffer);
  3691.                             input_cnt++;break;
  3692.                     default: break;
  3693.                 }
  3694.             }
  3695.             if(reply_format == 0 ){reply_format = 15;}
  3696.             reset();
  3697.             break;
  3698.         case MOUSE_PRECISION:
  3699.         /*
  3700.             @ precision int
  3701.             @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
  3702.             @ may be used / changed before every object
  3703.             @ In case of user interaction (like 'userdraw' or 'multidraw') this value will be used to determine the amount of decimals in the reply / answer
  3704.         */
  3705.             precision = (int) (get_real(infile,1));
  3706.             if(precision < 1 ){precision = 1;};
  3707.             break;
  3708.         case SETLIMITS:
  3709.         /*
  3710.             @ setlimits
  3711.             @ keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button
  3712.             @ may be used for inputfield based zooming / panning
  3713.             @ may be styled using command <a href="#inputstyle">inputstyle</a>
  3714.             @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to 'xlabel' etc
  3715.             @ note:the input value will not be checked on validity
  3716.         */
  3717.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  3718.             add_setlimits(js_include_file,canvas_root_id,font_size,input_style);
  3719.             /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
  3720.             use_pan_and_zoom = TRUE;
  3721.             done = TRUE;
  3722.             break;
  3723.         case ZOOM:
  3724.         /*
  3725.          @ zoom button_color
  3726.          @ introduce a very small 'controlpanel' at the lower right corner
  3727.          @ giving six 15&times;15px 'active' rectangle areas<br />(for &times;,leftarrow,rightarrow,uparrow,downarrow and a '-' and a '+' sign ) for zooming and/or panning of the image
  3728.          @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings.
  3729.          @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible
  3730.          @ command 'opacity' may be used to set stroke_opacity of 'buttons
  3731.          @ note: use command 'zoom' at the end of your script code (the same is true for command 'mouse')
  3732.          @ note: only objects that may be set draggable / clickable will be zoomed / panned
  3733.          @ 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 !!
  3734.         */
  3735.             fprintf(js_include_file,"use_pan_and_zoom = 1;");
  3736.             use_pan_and_zoom = TRUE;
  3737.             stroke_color = get_color(infile,1);
  3738.             /* we use BG_CANVAS (0) */
  3739.             add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
  3740.             done = TRUE;
  3741.             break;
  3742.         case ONCLICK:
  3743.         /*
  3744.          @ onclick
  3745.          @ keyword (no arguments required)
  3746.          @ if the next object is clicked, its 'object onclick_or_drag sequence number' in fly script is returned <br /> by javascript:read_canvas();
  3747.          @ onclick seqeuence numbering starts at '0'.<br />e.g. if there are 6 objects set onclick, the first onclick object will have id-number '0', the last id-number '5'
  3748.          @ line based objects will show an increase in line width<br />font based objects will show the text in 'bold' when clicked.
  3749.          @ the click zone (accuracy) is determined by 2&times; the line width of the object
  3750.          @ onclick and <a href="#drag">drag x|y|xy</a> may be combined in a single flyscript <br />(although a single object can <b>not</b> be onclick and draggable at the same time...)
  3751.          @ note: not all objects may be set onclick
  3752.         */
  3753.             fprintf(js_include_file,"use_dragdrop_reply = true;");
  3754.             onclick = 1;
  3755.  
  3756.             break;
  3757.         case DRAG:
  3758.         /*
  3759.          @ drag [x][y][xy]
  3760.          @ the next object will be draggable in x / y / xy direction
  3761.          @ the displacement can be read by 'javascript:read_dragdrop();'
  3762.          @ the precision (default 2 decimals) in the student reply may be set with command <a href="#precision">'precision'.</a><br />Use this 'precision' command before this command 'drag x|y|xy' !
  3763.          @ 'onclick' and 'drag x|y|xy' may be combined (for different objects: a single object can either be onclick or drag , not both )
  3764.          @ 'multi_objects' will be numbered in the given x/y-sequence (example: points red,0,0,1,1,2,2,3,3 : point (0:0) is object_number 1)
  3765.          @ <b>attention</b>: static objects and 'onclick/drag' objects of the same type (like point,circle,etc) with the same coordinates (e.g. objects that overlap) will give problems in the 'recognition algorithm')<br />in this example<br /><em>linewidth 4<br />point 0,0,red<br />drag xy<br />point 0,0,blue<br /></em>the blue point will not be recognised as draggable !<br /><em>linewidth 4<br />drag xy<br />point 0,0,red<br />drag xy<br />point 0,0,blue<br /></em>both points will be recognised
  3766.          @ the answer is  : drag_or_onclick_object_number : Xorg : Yorg : Xnew : Ynew<br />wherein object_number is the sequence number of the draggable &amp; onclick objects in your script.<br />Only draggable & onclick objects will have an object_number (e.g things like point,crosshair,line,segment,circle,rect,triangle...etc)
  3767.          @ use keyword 'snaptogrid' , 'xsnaptogrid' , 'ysnaptogrid' or command 'snaptopoints x1,y1,x2,y2,...' to switch from free to discrete movement
  3768.          @ 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.
  3769.          @ 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 !!
  3770.         */
  3771.             temp = get_string(infile,1);
  3772.             if(strstr(temp,"xy") != NULL ){
  3773.                 drag_type = 0;
  3774.             }
  3775.             else
  3776.             {
  3777.                 if(strstr(temp,"x") != NULL ){
  3778.                     drag_type = 1;
  3779.                 }
  3780.                 else
  3781.                 {
  3782.                     drag_type = 2;
  3783.                 }
  3784.             }
  3785.             /* assuming all drag&drop coordinates the same precision: so set only once */
  3786.             if( print_drag_params_only_once == FALSE ){
  3787.              fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;\n",precision);
  3788.              print_drag_params_only_once = TRUE;
  3789.             }
  3790.             onclick = 2;
  3791.             /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
  3792.             break;
  3793.         case BLINK:
  3794.         /*
  3795.          @ blink time(seconds)
  3796.          @ NOT IMPLEMETED -YET
  3797.         */
  3798.             break;
  3799.         case XUNIT:
  3800.         /*
  3801.          @ xunit some_unit_for_x-values
  3802.          @ unicode allowed (no html code)
  3803.          @ use together with command mousex
  3804.          @ will display the cursor x-coordinate in 'unit'
  3805.         */
  3806.             fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
  3807.             break;
  3808.         case YUNIT:
  3809.         /*
  3810.          @ yunit some_unit_for_y-values
  3811.          @ unicode allowed (no html code)
  3812.          @ use together with command mousey
  3813.          @ will display the cursor y-coordinate in 'unit'
  3814.         */
  3815.             fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
  3816.             break;
  3817.         case CURSOR:
  3818.         /*
  3819.         @ cursor 'some CSS cursor_style'
  3820.         @ alternative : pointer
  3821.         @ style can be any valid CSS property value, like crosshair,grabbing,move etc
  3822.         @ wims will not check the validity of your cursor declaration
  3823.         */
  3824.             fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1));
  3825.             break;
  3826.         case MOUSE_DISPLAY:
  3827.         /*
  3828.          @ display TYPE,color,fontsize
  3829.          @ TYPE may be x | y | xy | degree | radian | radius
  3830.          @ will display the mouse cursor coordinates as x-only,y-only,(x:y),<br />the radius of a circle (this only in case 'userdraw circle(s),color')<br />or the angle in degrees or radians for commands "userdraw arc,color" or protractor , ruler (if set dynamic)
  3831.          @ use commands 'xunit' and / or 'yunit' to add the units to the mouse values.<br />The "degree | radian" will always have the appropriate symbol)
  3832.          @ just like commands 'mouse','mousex','mousey','mouse_degree'...only other name)
  3833.         */
  3834.         temp = get_string_argument(infile,0);
  3835.         if( strstr(temp,"xy") != NULL ){
  3836.             int_data[0] = 2;
  3837.         }else{
  3838.             if( strstr(temp,"y") != NULL ){
  3839.                 int_data[0] = 1;
  3840.             }else{
  3841.                 if( strstr(temp,"x") != NULL ){
  3842.                     int_data[0] = 0;
  3843.                 }else{
  3844.                     if(strstr(temp,"degree") != NULL){
  3845.                         int_data[0] = 3;
  3846.                         js_function[JS_FIND_ANGLE] = 1;
  3847.                     }else{
  3848.                         if(strstr(temp,"radian") != NULL){
  3849.                             int_data[0] = 4;
  3850.                             js_function[JS_FIND_ANGLE] = 1;
  3851.                         }else{
  3852.                             if(strstr(temp,"radius") != NULL){
  3853.                                 int_data[0] = 5;
  3854.                             }else{
  3855.                                 int_data[0] = 2;
  3856.                             }
  3857.                         }
  3858.                     }
  3859.                 }
  3860.             }
  3861.         }
  3862.         stroke_color = get_color(infile,0);
  3863.         font_size = (int) (get_real(infile,1));
  3864.         tmp_buffer = my_newmem(26);
  3865.         snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  3866.         add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
  3867.         break;
  3868.         case MOUSE_DEGREE:
  3869.         /*
  3870.          @ mouse_degree color,fontsize
  3871.          @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in 'color' and 'font size'<br /> using a fontfamily Ariel
  3872.          @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
  3873.          @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  3874.  
  3875.         */
  3876.             stroke_color = get_color(infile,0);
  3877.             font_size = (int) (get_real(infile,1));
  3878.             tmp_buffer = my_newmem(26);
  3879.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  3880.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
  3881.             js_function[JS_FIND_ANGLE] = 1;
  3882.             break;
  3883.         case MOUSEX:
  3884.         /*
  3885.          @ mousex color,fontsize
  3886.          @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using the fontfamily Ariel
  3887.          @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  3888.  
  3889.         */
  3890.             stroke_color = get_color(infile,0);
  3891.             font_size = (int) (get_real(infile,1));
  3892.             tmp_buffer = my_newmem(26);
  3893.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  3894.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
  3895.             break;
  3896.         case MOUSEY:
  3897.         /*
  3898.          @ mousey color,fontsize
  3899.          @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
  3900.          @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  3901.  
  3902.         */
  3903.             stroke_color = get_color(infile,0);
  3904.             font_size = (int) (get_real(infile,1));
  3905.             tmp_buffer = my_newmem(26);
  3906.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  3907.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
  3908.             break;
  3909.         case MOUSE:
  3910.         /*
  3911.          @ mouse color,fontsize
  3912.          @ will display the cursor (x:y) coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
  3913.          @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  3914.  
  3915.         */
  3916.             stroke_color = get_color(infile,0);
  3917.             font_size = (int) (get_real(infile,1));
  3918.             tmp_buffer = my_newmem(26);
  3919.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  3920.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
  3921.             break;
  3922.         case INTOOLTIP:
  3923.             /*
  3924.             @ intooltip link_text
  3925.             @ link_text is a single line (span-element)
  3926.             @ link_text may also be an image URL 'http://some_server/images/my_image.png' or '$module_dir/gifs/my_image.jpg'
  3927.             @ link_text may contain HTML markup
  3928.             @ the canvas will be displayed in a tooltip on 'link_text'
  3929.             @ the canvas is default transparent: use command <a href="#bgcolor">'bgcolor color'</a> to adjust background-color<br />the link text will also be shown with this 'bgcolor'.
  3930.             @ many 'userinput stuff' will use the tooltip_placeholder_div element...only one is defined in the wims-page<br />and are therefor these commands are mutually exclusive.<br />keep this in mind...
  3931.             */
  3932.             if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");}
  3933.             if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");}
  3934.             tooltip_text = get_string(infile,1);
  3935.             if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
  3936.             use_tooltip = 1;
  3937.             break;
  3938.         case POPUP:
  3939.             /*
  3940.             @ popup
  3941.             @ keyword (no arguments)
  3942.             @ if fly-script starts with keyword 'popup', the canvas image will be exclusively in a popup window (xsize px &times; ysize px)
  3943.             @ if keyword 'popup' is used after command 'size xsize,ysize' the canvas will also be displayed in a popup window with size 'xsize &times; ysize'
  3944.             @ the popup window will be embedded into the page as a 'normal' image , when 'status=done' ; override with keyword <a href="#status"> 'nostatus'</a>
  3945.             @ to access the read_canvas and read_dragdrop functions in a popup window, use:<br /><em><br /> function read_all(){<br /> if( typeof popup !== 'undefined' ){<br />  var fun1 = popup['read_dragdrop'+canvas_scripts[0]];<br />  var fun2 = popup['read_canvas'+canvas_scripts[0]];<br />   popup.close();<br />  return "dragdrop="+fun1()+"\\ncanvas="+fun2();<br /> };<br /></em>
  3946.             @ to set a canvasdraw produced <a href="#clock">clock</a> or multiple clocks...use something like:<br /><em>popup.set_clock(clock_id,type,diff);</em><br />as js-function for a button (or something else) in your document page.<br />wherein <b>clock_id</b> starts with 0 for the first clock<br /><b>type</b> is 1 for Hours,2 for Minutes and 3 for Seconds<br /><b>diff</b> is the increment (positive or negative) per click
  3947.             */
  3948.             use_tooltip = 2;
  3949.             break;
  3950.         case AUDIO:
  3951.         /*
  3952.         @ audio x,y,w,h,loop,visible,audiofile location
  3953.         @ x,y : left top corner of audio element (in xrange / yrange)
  3954.         @ w,y : width and height in pixels
  3955.         @ loop : 0 or 1 ( 1 = loop audio fragment)
  3956.         @ visible : 0 or 1 (1 = show controls)
  3957.         @ audio format may be in *.mp3 or *.ogg
  3958.         @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format)
  3959.         @ if you are using *.ogg : be aware that Microsoft based systems not support it natively
  3960.         @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
  3961.         @ 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 />
  3962.         */
  3963.             if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
  3964.             for(i=0;i<7;i++){
  3965.                 switch(i){
  3966.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  3967.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  3968.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  3969.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  3970.                     case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
  3971.                     case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
  3972.                     case 6:
  3973.                     temp = get_string(infile,1);
  3974.                     if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
  3975.                     if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
  3976.                     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);
  3977.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3978.                     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);
  3979.                     add_to_buffer(tmp_buffer);
  3980.                     break;
  3981.                     default:break;
  3982.                 }
  3983.             }
  3984.             reset();
  3985.             break;
  3986.         case VIDEO:
  3987.         /*
  3988.         @ video x,y,w,h,videofile location
  3989.         @ x,y : left top corner of audio element (in xrange / yrange)
  3990.         @ w,y : width and height in pixels
  3991.         @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4
  3992.         @ video format may be in *.mp4 (todo:other formats)
  3993.         */
  3994.             if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
  3995.             for(i=0;i<5;i++){
  3996.                 switch(i){
  3997.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  3998.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  3999.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  4000.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  4001.                     case 4: temp = get_string(infile,1);
  4002.                             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);
  4003.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4004.                             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);
  4005.                             add_to_buffer(tmp_buffer);
  4006.                             break;
  4007.                     default:break;
  4008.                 }
  4009.             }
  4010.             reset();
  4011.             break;
  4012.         case HATCHFILL:
  4013.         /*
  4014.         @ hatchfill x0,y0,dx,dy,color
  4015.         @ x0,y0 in xrange / yrange
  4016.         @ distances dx,dy in pixels
  4017.         */
  4018.             if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
  4019.             for(i=0;i<5;i++){
  4020.                 switch(i){
  4021.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  4022.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  4023.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  4024.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  4025.                     case 4: stroke_color = get_color(infile,1);
  4026.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  4027.                     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);
  4028.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4029.                     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);
  4030.                     add_to_buffer(tmp_buffer);
  4031.                     break;
  4032.                     default:break;
  4033.                 }
  4034.             }
  4035.             reset();
  4036.         break;
  4037.         case DIAMONDFILL:
  4038.         /*
  4039.         @ diamondfill x0,y0,dx,dy,color
  4040.         @ x0,y0 in xrange / yrange
  4041.         @ distances dx,dy in pixels
  4042.         */
  4043.             if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
  4044.             for(i=0;i<5;i++){
  4045.                 switch(i){
  4046.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  4047.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  4048.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  4049.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  4050.                     case 4: stroke_color = get_color(infile,1);
  4051.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  4052.                     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);
  4053.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4054.                     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);
  4055.                     add_to_buffer(tmp_buffer);
  4056.                     break;
  4057.                     default:break;
  4058.                 }
  4059.             }
  4060.             reset();
  4061.         break;
  4062.         case GRIDFILL:
  4063.         /*
  4064.         @ gridfill x0,y0,dx,dy,color
  4065.         @ x0,y0 in xrange / yrange
  4066.         @ distances dx,dy in pixels
  4067.         @ a draggable object may <a href="#snaptogrid">snap_to_grid</a> (using keywords snaptogrid,xsnaprogrid, ysnaptogrid or snaptopoints)
  4068.         @ userdraw object may snap_to_grid
  4069.         */
  4070.             if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
  4071.             for(i=0;i<5;i++){
  4072.                 switch(i){
  4073.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  4074.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  4075.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  4076.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  4077.                     case 4: stroke_color = get_color(infile,1);
  4078.                     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);
  4079.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4080.                     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);
  4081.                     add_to_buffer(tmp_buffer);
  4082.                     break;
  4083.                     default:break;
  4084.                 }
  4085.             }
  4086.             reset();
  4087.         break;
  4088.         case DOTFILL:
  4089.         /*
  4090.         @ dotfill x0,y0,dx,dy,color
  4091.         @ x0,y0 in xrange / yrange
  4092.         @ distances dx,dy in pixels
  4093.         @ radius of dots is linewidth
  4094.         */
  4095.             if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
  4096.             for(i=0;i<5;i++){
  4097.                 switch(i){
  4098.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  4099.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  4100.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  4101.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  4102.                     case 4: stroke_color = get_color(infile,1);
  4103.                     /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
  4104.                     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);
  4105.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4106.                     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);
  4107.                     add_to_buffer(tmp_buffer);
  4108.                     break;
  4109.                     default:break;
  4110.                 }
  4111.             }
  4112.             reset();
  4113.         break;
  4114.         case IMAGEFILL:
  4115.         /*
  4116.         @ imagefill dx,dy,image_url
  4117.         @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
  4118.         @ After pattern filling ,the fill-color should be reset !
  4119.         @ wims getins / image from class directory : imagefill 80,80,my_image.gif
  4120.         @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif
  4121.         @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg
  4122.         @ if dx,dy is larger than the image, the whole image will be background to the next object.
  4123.         */
  4124.             if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
  4125.             for(i=0 ;i < 3 ; i++){
  4126.                 switch(i){
  4127.                     case 0:int_data[0] = (int) (get_real(infile,0));break;
  4128.                     case 1:int_data[1] = (int) (get_real(infile,0));break;
  4129.                     case 2: URL = get_string_argument(infile,1);
  4130.                             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);
  4131.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4132.                             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);
  4133.                             add_to_buffer(tmp_buffer);
  4134.                     break;
  4135.                 }
  4136.             }
  4137.             reset();
  4138.         break;
  4139.         case CANVASTYPE:
  4140.          canvas_type = (int) (get_real(infile,1));
  4141.         /*
  4142.         @ canvastype TYPE
  4143.         @ for now only usefull before commands  filltoborder / floodfill / clickfill etc operations<br />Only the images of this TYPE will be scanned and filled
  4144.         @ default value of TYPE is DRAG_CANVAS e.g. 5
  4145.         @ use another TYPE if you know what you are doing...
  4146.         @ other possible canvasses (transparent PNG pictures xsize x ysize on top of eachother)<ul><li>EXTERNAL_IMAGE_CANVAS = 0</li><li>BG_CANVAS = 1</li><li> STATIC_CANVAS = 2</li><li> MOUSE_CANVAS = 3 : used for command "mouse"</li><li> GRID_CANVAS = 4 :used for command "grid"</li><li> DRAG_CANVAS = 5 :default</li><li> DRAW_CANVAS = 6 :used for some static drawings</li><li> TEXT_CANVAS = 7 : used for text-strings</li><li> CLOCK_CANVAS = 8 : used for command "clock"</li><li> ANIMATE_CANVAS = 9 : not used for now</li><li> TRACE_CANVAS = 10 : used for command "trace_jscurve"</li><li> JSPLOT_CANVAS = 111 : will be increased with every new command "jscurve"</li> <li> FILL_CANVAS = 12 : this will be filled...so do not use ! </li><li> USERDRAW_JSPLOT 13 : will be increased with every new command "userinput function"</li></ul>
  4147.         */
  4148.         break;
  4149.         case FILLTOBORDER:
  4150.         /*
  4151.         @ filltoborder x,y,bordercolor,color
  4152.         @ fill the region  of point (x:y)  with color 'color'
  4153.         @ any other color will not act as border to the bucket fill
  4154.         @ use this command  after all boundary objects are declared.
  4155.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  4156.         @ 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..
  4157.         */
  4158.             for(i=0 ;i < 4 ; i++){
  4159.                 switch(i){
  4160.                     case 0:double_data[0] = get_real(infile,0);break;
  4161.                     case 1:double_data[1] = get_real(infile,0);break;
  4162.                     case 2:bgcolor = get_color(infile,0);break;
  4163.                     case 3:fill_color = get_color(infile,1);
  4164.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  4165.                                 js_function[DRAW_FILLTOBORDER] = 1;
  4166.                                 add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  4167.                            }
  4168.                            decimals = find_number_of_digits(precision);
  4169.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  4170.                            string_length = snprintf(NULL,0,  "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215));
  4171.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4172.                            snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215));
  4173.                            add_to_buffer(tmp_buffer);
  4174.                            break;
  4175.                     default:break;
  4176.                 }
  4177.             }
  4178.             reset();
  4179.         break;
  4180.         case FLOODFILL:
  4181.         /*
  4182.         @ floodfill x,y,color
  4183.         @ alternative : fill x,y,color
  4184.         @ fill the region of point (x:y) with color 'color'
  4185.         @ any other color or size of picture (borders of picture) will act as border to the bucket fill
  4186.         @ use this command  after all boundary objects are declared.
  4187.         @ Use command 'userdraw clickfill,color' for user click driven flood fill.
  4188.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  4189.         @ 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..
  4190.         */
  4191.             for(i=0 ;i < 4 ; i++){
  4192.                 switch(i){
  4193.                     case 0:double_data[0] = get_real(infile,0);break;
  4194.                     case 1:double_data[1] = get_real(infile,0);break;
  4195.                     case 2:fill_color = get_color(infile,1);
  4196.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  4197.                                 js_function[DRAW_FILLTOBORDER] = 1;
  4198.                                 add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  4199.                            }
  4200.                            decimals = find_number_of_digits(precision);
  4201.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  4202.                            string_length = snprintf(NULL,0,  "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215));
  4203.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4204.                            snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215));
  4205.                            add_to_buffer(tmp_buffer);
  4206.  
  4207.                            break;
  4208.                     default:break;
  4209.                 }
  4210.             }
  4211.             reset();
  4212.         break;
  4213.         case SETPIXEL:
  4214.         /*
  4215.         @ setpixel x,y,color
  4216.         @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange
  4217.         @ pixels can <b>not</b> be dragged or clicked
  4218.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  4219.         */
  4220.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  4221.             for(i=0;i<3;i++){
  4222.                 switch(i){
  4223.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  4224.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  4225.                     case 2: stroke_color = get_color(infile,1);
  4226.                            string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  4227.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4228.                            snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  4229.                            add_to_buffer(tmp_buffer);
  4230.                            break;
  4231.                     default:break;
  4232.                 }
  4233.             }
  4234.             reset();
  4235.         break;
  4236.         case PIXELSIZE:
  4237.         /*
  4238.         @ pixelsize int
  4239.         @ in case you want to deviate from default pixelsize = 1(...)
  4240.         */
  4241.             pixelsize = (int) get_real(infile,1);
  4242.         break;
  4243.         case PIXELS:
  4244.         /*
  4245.         @ pixels color,x1,y1,x2,y2,x3,y3...
  4246.         @ draw rectangular "points" with diameter 1 pixel
  4247.         @ pixels can <b>not</b> be dragged or clicked
  4248.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  4249.         */
  4250.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  4251.             stroke_color=get_color(infile,0);
  4252.             i=0;
  4253.             c=0;
  4254.             while( ! done ){     /* get next item until EOL*/
  4255.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  4256.                 for( c = 0 ; c < 2; c++){
  4257.                     if(c == 0 ){
  4258.                         double_data[i] = get_real(infile,0);
  4259.                         i++;
  4260.                     }
  4261.                     else
  4262.                     {
  4263.                         double_data[i] = get_real(infile,1);
  4264.                         i++;
  4265.                     }
  4266.                 }
  4267.             }
  4268.             decimals = find_number_of_digits(precision);
  4269.             /*  *double_xy2js_array(double xy[],int len,int decimals) */
  4270.             string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  4271.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4272.             snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  4273.             add_to_buffer(tmp_buffer);
  4274.             reset();
  4275.             break;
  4276.         case REPLYFORMAT:
  4277.         /*
  4278.         @ replyformat number
  4279.         @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop()
  4280.         @ default values should be fine !
  4281.         @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing
  4282.         @ the last value for 'precision int' will be used to calculate  the reply coordinates, if needed (read_canvas();)
  4283.         @ 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 \\n x2,y2,text2...\\n...x_n,y_n,text_n <br /> x/y-values are in xrang/yrange</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>20 = read_canvas() will reply "object_number:x:y" of external images : object_number of the first draggable external image in the fly-script starts with 0 <br />e.g. expect something like 0:-5:4,1:6:2,2:-2:-5 <br /> the first image position is (-5:4) , the second image position is (6:2) and the third image position is (-2:-5)        <li>21 = (x1:y1) (x2:y2) ... (x_n:y_n)<br />verbatim coordinate return</li><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>23 : can only be used for drawtype 'polyline'<br />a typical click sequence in drawtype polyline is x1,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><li>24 = read all inputfield values: even those set 'readonly'</li><li>25 = angle1,angle2...angle_n : will return the radius (one or many) of the user drawn circle segment in degrees </li><li>26 = rad1,rad2...rad_n : will return the radius (one or many) of the user drawn circle segment in radians </li><li>27 = return (only) userdraw inputfields  x1,y1,text1 \\n x2,y2,text2...\\n...x_n,y_n,text_n</li><li>28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n <br />x / y / r in  xrange / yrange coordinate system: may be used to reinput into command 'circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n'<br /> will not return anything else (e.g. no inputfields , text etc)</li></ul>
  4284.  
  4285.         */
  4286.          reply_format = (int) get_real(infile,1);
  4287.          reply_precision = precision;
  4288.         break;
  4289.         case LEGENDCOLORS:
  4290.         /*
  4291.         @ legendcolors color1:color2:color3:...:color_n
  4292.         @ will be used to colour a legend: use this command after the legend command ! e.g.<br />legend test1:test2:test3<br />legendcolors blue:red:orange
  4293.         @ make sure the number of colours match the number of legend items
  4294.         @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
  4295.         */
  4296.             if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
  4297.             temp = get_string(infile,1);
  4298.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  4299.             fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
  4300.             break;
  4301.         case LEGEND:
  4302.         /*
  4303.         @ legend string1:string2:string3....string_n
  4304.         @ will be used to create a legend for a graph
  4305.         @ also see command <a href='#piechart'>'piechart'</a>
  4306.         @ will use the same colors per default as used in the graphs : use command <a href='#legendcolors'>'legendcolors'</a> to override the default
  4307.         @ use command <a href="#fontsize">fontsize</a> to adjust. (command "fontfamily" is not active for command "legend")
  4308.         */
  4309.             temp = get_string(infile,1);
  4310.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  4311.             legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */
  4312.             fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
  4313.             break;
  4314.         case XLABEL:
  4315.         /*
  4316.         @ xlabel some_string
  4317.         @ will be used to create a label for the x-axis (label is in quadrant I)
  4318.         @ can only be used together with command 'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering'
  4319.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command "fontsize" to adjust.<br />(command "fontfamily" is not active for this command)
  4320.         */
  4321.             temp = get_string(infile,1);
  4322.             fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
  4323.             break;
  4324.         case YLABEL:
  4325.         /*
  4326.         @ ylabel some_string
  4327.         @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
  4328.         @ can only be used together with command <a href="#grid">'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering'
  4329.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command "fontsize" to adjust.<br />(command "fontfamily" is not active for this command)
  4330.         */
  4331.             temp = get_string(infile,1);
  4332.             fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
  4333.             break;
  4334.         case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
  4335.         /*
  4336.         @ linegraph x1:y1:x2:y2...x_n:y_n
  4337.         @ will plot your data in a graph
  4338.         @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a>
  4339.         @ can be used together with freestyle x-axis/y-axis texts : see commands <a href='#xaxis'>'xaxis'</a>,<a href='#xaxisup'>'xaxisup'</a> and <a href='#yaxis'>'yaxis'</a>
  4340.         @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner
  4341.         @ also see command <a href='#piechart'>'piechart'</a>
  4342.         @ multiple linegraphs may be used in a single plot
  4343.         @ note: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
  4344.         @ <ul><li>use command <a href='#strokecolor'>'strokecolor'</a> before a command 'linegraph' to set the color of this graph</li><li>use command <a href='#linewidth'>'linewidth'</a> before command 'linegraph' to set linewidth of this graph</li><li>use keyword <a href='#dashed'>'dashed'</a> before command 'linegraph' to set dashing of the graph</li><li>if dashing is set, use command <a href='#dashtype'>'dashtype'</a> before command 'linegraph' to set the type of dashing of the (individual) graph</li></ul>
  4345.         */
  4346.             temp = get_string(infile,1);
  4347.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  4348.             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);
  4349.             linegraph_cnt++;
  4350.             reset();
  4351.             break;
  4352.         case BARCHART:
  4353.         /*
  4354.         @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
  4355.         @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a>
  4356.         @ can be used together with freestyle x-axis/y-axis texts : see commands <a href='#xaxis'>'xaxis'</a>,<a href='#xaxisup'>'xaxisup'</a> and <a href='#yaxis'>'yaxis'</a>
  4357.         @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner
  4358.         @ multiple barchart command may be used in a single script
  4359.         @ also see command <a href='#piechart'>'piechart'</a>
  4360.         @ note: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
  4361.         */
  4362.             temp = get_string(infile,1);
  4363.             if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
  4364.             fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
  4365.             barchart_cnt++;
  4366.             reset();
  4367.             break;
  4368.         case CLOCK:
  4369.         /*
  4370.         @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
  4371.         @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency
  4372.         @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments
  4373.         @ colors are optional: if not defined, default values will be used<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,green,blue,black,yellow
  4374.         @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
  4375.         @ 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><li>3: no prefab buttons...create your own buttons (or other means) to make the clock(s) adjustable by javascript function set_clock(num,type,diff)<br />wherein: num = clock id (starts with 0) ; type = 1 (hours) ; type = 2 (minutes) ; type = 3 (seconds) <br />and diff = the increment of 'type' (positive or negative) </li></ul>
  4376.         @ canvasdraw will not check validity of colornames...the javascript console is your best friend
  4377.         @ no combinations with other reply_types allowed, for now
  4378.         @ if interactive is set to '1', 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
  4379.         @ note: if you need multiple -interactive- clocks on a webpage, use multiple 'clock' commands in a single script !<br />and <i>not multiple canvas scripts</i> in a single page
  4380.         @ note: clocks will not zoom or pan, when using command <a href='#zoom'>'zoom'</a>
  4381.         */
  4382.             if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
  4383.  
  4384.         /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
  4385.             for(i=0;i<9;i++){
  4386.              switch(i){
  4387.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
  4388.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
  4389.               case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
  4390.               case 3: int_data[3] = get_real(infile,0);break;/* hours */
  4391.               case 4: int_data[4] = get_real(infile,0);break;/* minutes */
  4392.               case 5: int_data[5] = get_real(infile,0);break;/* seconds */
  4393.               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 */
  4394.               case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/
  4395.                 switch(int_data[7]){
  4396.                     case 0:break;
  4397.                     case 1:if(clock_cnt == 0){
  4398.                            if( reply_format == 0 ){
  4399.                             reply_format = 18; /* user sets clock */
  4400.                             /* 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");
  4401.                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4402.                                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");
  4403.                                add_to_buffer(tmp_buffer);
  4404.                            */
  4405.                             fprintf(js_include_file,"set_clock = function(num,type,diff){if(wims_status == \"done\"){return;};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 = new 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");
  4406.                            }
  4407.                            else
  4408.                            {
  4409.                             canvas_error("interactive clock may not be used together with other reply_types...");
  4410.                            }
  4411.                           }
  4412.                           fprintf(stdout,"<p style=\"text-align:center\"><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H&minus;\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M&minus;\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S&minus;\" /></p>",input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt);
  4413.                     break;
  4414.                     case 3:if(clock_cnt == 0){
  4415.                             if( reply_format == 0 ){
  4416.                              reply_format = 18; /* user sets clock */
  4417.                              fprintf(js_include_file,"set_clock = function(num,type,diff){if(wims_status == \"done\"){return;};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 = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,1,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n");
  4418.                             }
  4419.                             else
  4420.                             {
  4421.                              canvas_error("interactive clock may not be used together with other reply_types...");
  4422.                             }
  4423.                            }
  4424.                             /*
  4425.                             fprintf(stdout,"<p style=\"text-align:center\"><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H&minus;\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M&minus;\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S&minus;\" /></p>",input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt);
  4426.                            */
  4427.                     break;
  4428.                     case 2:if( reply_format == 0 ){
  4429.                                 reply_format = 19; /* "onclick */
  4430.                                 fprintf(js_include_file,"\n<!-- begin onclick handler for clocks -->\nvar reply = new Array();canvas_div.addEventListener( 'mousedown', user_click,false);\n\nfunction user_click(evt){if(evt.which == 1){var canvas_rect = clock_canvas.getBoundingClientRect();var x = evt.clientX - canvas_rect.left;var y = evt.clientY - canvas_rect.top;var p = 0;var name;var t = true;while(t){try{name = eval('clocks'+p);if( x < name.xc + name.radius && x > name.xc - name.radius ){if( y < name.yc + name.radius && y > name.yc - name.radius ){reply[0] = p;name = new 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);};}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);name = new 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);};p++;}catch(e){t=false;};};};};\n");
  4431.                             }
  4432.                             else
  4433.                             {
  4434.                                 if( reply_format != 19){
  4435.                                    canvas_error("clickable clock(s) may not be used together with other reply_types...");
  4436.                                  }
  4437.                             }
  4438.                      break;
  4439.                      default: canvas_error("interactive must be set 0,1 or 2");break;
  4440.                 }
  4441.                 break;
  4442.                 case 8:
  4443.                         if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock() , for now it's OK */
  4444.                             fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
  4445.                         }
  4446.                         temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/
  4447.                         if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
  4448.                         else{
  4449.                         /* h_color,m_color,s_color,bg_color,fg_color */
  4450.                         temp = ",black\",\"black\",\"red\",\"white\",\"black";}
  4451.                         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);
  4452.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4453.                         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);
  4454.                         add_to_buffer(tmp_buffer);
  4455.                         fprintf(js_include_file,"var clocks%d;",clock_cnt);
  4456.                         clock_cnt++;
  4457.                         break;
  4458.                 default:break;
  4459.              }
  4460.             }
  4461.             break;
  4462.         case PIECHART:
  4463.         /*
  4464.         @ piechart xc,yc,radius,'data+colorlist'
  4465.         @ (xc : yc) center of circle diagram in xrange/yrange
  4466.         @ radius in pixels
  4467.         @ 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
  4468.         @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white
  4469.         @ the number of colors must match the number of data.
  4470.         @ use command "<a href='#opacity'>'opacity'</a> to adjust fill_opacity of colours
  4471.         @ use command <a href='#legend'>'legend'</a> 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...<br />use command 'fontfamily' to set the font of the legend.
  4472.         */
  4473.             if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}
  4474.             for(i=0;i<5;i++){
  4475.                 switch(i){
  4476.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  4477.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  4478.                     case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
  4479.                     case 3: temp = get_string(infile,1);
  4480.                             if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
  4481.                             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,legend_cnt,font_family);
  4482.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4483.                             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,legend_cnt,font_family);
  4484.                             add_to_buffer(tmp_buffer);
  4485.                            break;
  4486.                     default:break;
  4487.                 }
  4488.             }
  4489.             reset();
  4490.         break;
  4491.         case USERBOXPLOTDATA:
  4492.         /*
  4493.          @ userboxplotdata
  4494.          @ keyword, no arguments
  4495.          @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a>
  4496.          @ if set, the student will have to generate some statistical data. These data should be put in a named array "student_boxplot_data"
  4497.          @ "min,Q1,median,Q3,max" are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot.
  4498.          @ see command <a href="#userboxplot">'userboxplot'</a> for calling 'draw_boxplot()'
  4499.         */
  4500.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  4501.             fprintf(js_include_file,"var boxplot_source = 2;\n");
  4502.             js_function[DRAW_JSBOXPLOT] = 1;
  4503.  
  4504.         break;
  4505.         case USERBOXPLOT:
  4506.         /*
  4507.          @ userboxplot
  4508.          @ keyword, no arguments
  4509.          @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a>
  4510.          @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the 'draw_boxplot' function
  4511.          @ for example:<br />put the canvas-script into a html element with id='boxplot'and set style='display:none'<br />define a variable called 'student_boxplot' and fill it with the 5 student-data (from inputfields or something)<br />var student_boxplot = new Array(5)<br />function show_boxplot(){<br />student_boxplot[0] = min;<br />student_boxplot[1] = Q1;<br />student_boxplot[2] = median;<br />student_boxplot[3] = Q3;<br />student_boxplot[4] = max;<br />document.getElementById('boxplot').style.display = "block";<br />draw_boxplot(12345,1,2.00,5.00,[0,0,0,0,0],4,"0,0,255",0.78,"255,165,0",0.60,1,0,1,1);<br />};<br />In the canvas-script the function draw_boxplot has the following arguments:<br />draw_boxplot=function(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1)
  4512.         */
  4513.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  4514.             fprintf(js_include_file,"var boxplot_source = 3;\n");
  4515.             js_function[DRAW_JSBOXPLOT] = 2;
  4516.         break;
  4517.         case BOXPLOTDATA:
  4518.         /*
  4519.         @ boxplotdata some_data
  4520.         @ 'some_data' are a list of numbers separated by a comma "," (items)
  4521.         @ only be used before command 'boxplot': the command <a href="#boxplot">'boxplot'</a> will provide the boxplot drawing of the data.
  4522.         @ xrange 0,100<br />yrange 0,10<br />boxplotdata 11,22,13,15,23,43,12,12,14,2,45,32,44,13,21,24,13,19,35,21,24,23<br />boxplot x,4,5
  4523.         @ note: wims will not check your data input | format. use js-error console to debug any problems.
  4524.         @ a javascript function 'statistics()' will parse the data and calculate the values [min,Q1,median,Q3,max] and hand them to the boxplot draw function.
  4525.         */
  4526.             if( js_function[DRAW_JSBOXPLOT] != 1 ){ js_function[DRAW_JSBOXPLOT] = 1;}
  4527.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  4528.             fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1));
  4529.  
  4530.         break;
  4531.         case BOXPLOT:
  4532.         /*
  4533.         @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max
  4534.         @ example:<br />xrange 0,300<br />yrange 0,10<br />boxplot x,4,8,120,160,170,220,245<br />meaning: create a boxplot in x-direction, with height 4 (in yrange) and centered around line y=8
  4535.         @ example:<br />xrange 0,10<br />yrange 0,300<br />boxplot y,4,8,120,160,170,220,245<br />meaning: create a boxplot in y-direction, with width 4 (in xrange) and centered around line x=8
  4536.         @ use command <a href='filled'>'filled'</a> to fill the box<br /><b>note:</b> the strokecolor is used for filling Q1, the fillcolor is used for filling Q3
  4537.         @ use command <a href='#opacity'>'opacity'</a> to adjust fill_opacity of stroke and fill colours
  4538.         @ use command <a href='#legend'>'legend'</a> to automatically create a legend <br />unicode allowed in legend<br />use command 'fontfamily' to set the font of the legend.
  4539.         @ there is no limit to the number of boxplots used.
  4540.         @ can <b>not</b> be set draggable (<a href='#onclick'>'onclick'</a> is not ready ,yet)
  4541.         @ use keyword <a href="#userboxplot">'userboxplot'</a> before command boxplot, if a pupil must draw a boxplot (using his own min,Q1,median,Q3,max data)
  4542.         @ use keyword <a href="#userboxplotdata">'userboxplotdata'</a> before command boxplot, if a pupil must generate the data by some means.
  4543.         @ use command <a href="#boxplotdata">'boxplotdata'</a> when the boxplot should be drawn from wims-generated raw statistical date
  4544.         */
  4545.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  4546.             for(i=0;i<8;i++){
  4547.                 switch(i){
  4548.                     case 0: temp = get_string_argument(infile,0);
  4549.                             if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */
  4550.                     case 1: double_data[0] = get_real(infile,0);break;/* height | width  */
  4551.                     case 2:
  4552.                     if( js_function[DRAW_JSBOXPLOT] == 0 ){
  4553.                      double_data[1] = get_real(infile,0);
  4554.                      fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */
  4555.                     }
  4556.                     else
  4557.                     {
  4558.                      double_data[1] = get_real(infile,1);
  4559.                      double_data[2] = 1;
  4560.                      double_data[3] = 1;
  4561.                      double_data[4] = 1;
  4562.                      double_data[5] = 1;
  4563.                      double_data[6] = 1;
  4564.                      double_data[7] = 1;
  4565.                      i=8;
  4566.                     }
  4567.                     break;/* center value x or y */
  4568.                     case 3: double_data[2] = get_real(infile,0); break;/* min */
  4569.                     case 4: double_data[3] = get_real(infile,0); break;/* Q1 */
  4570.                     case 5: double_data[4] = get_real(infile,0); break;/* median */
  4571.                     case 6: double_data[5] = get_real(infile,0); break;/* Q3 */
  4572.                     case 7: double_data[6] = get_real(infile,1); break;/* max */
  4573.                     default:break;
  4574.                 }
  4575.             }
  4576.             decimals = find_number_of_digits(precision);
  4577.             /*function draw_boxplot(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1)*/
  4578.             string_length = snprintf(NULL,0,  "draw_boxplot(%d,%d,%.*f,%.*f,[%.*f,%.*f,%.*f,%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d);\n",BOXPLOT+boxplot_cnt,int_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],decimals,double_data[6],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1]);
  4579.             check_string_length(string_length);
  4580.             tmp_buffer = my_newmem(string_length+1);
  4581.             snprintf(tmp_buffer,string_length,  "draw_boxplot(%d,%d,%.*f,%.*f,[%.*f,%.*f,%.*f,%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d);\n",BOXPLOT+boxplot_cnt,int_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],decimals,double_data[6],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1]);
  4582.             add_to_buffer(tmp_buffer);
  4583.             boxplot_cnt++;
  4584.             reset();
  4585.         break;
  4586.         case STATUS:
  4587.         /*
  4588.         @ status
  4589.         @ keyword
  4590.         @ alernative : nostatus
  4591.         @ used to override the effects of "status=done" in wims (answer.phtml)
  4592.         @ affects 'readonly' in inputfields / textarea's in canvasimage and all userdraw based commands
  4593.         @ e.g.: if keyword 'status' is set, the pupil will be able to modify the canvas when the 'wims $status variable' is set to 'done'
  4594.         */
  4595.  
  4596.             fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
  4597.             break;
  4598.         case XLOGBASE:
  4599.         /*
  4600.         @ xlogbase number
  4601.         @ sets the logbase number for the x-axis
  4602.         @ default value 10
  4603.         @ use together with commands xlogscale / xylogscale
  4604.         */
  4605.             fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
  4606.             break;
  4607.         case YLOGBASE:
  4608.         /*
  4609.         @ ylogbase number
  4610.         @ sets the logbase number for the y-axis
  4611.         @ default value 10
  4612.         @ use together with commands ylogscale / xylogscale
  4613.         */
  4614.             fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
  4615.             break;
  4616.         case XLOGSCALE:
  4617.         /*
  4618.          @ xlogscale ymajor,yminor,majorcolor,minorcolor
  4619.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  4620.          @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
  4621.          @ the linewidth is set using command 'linewidth int'
  4622.          @ the opacity of major / minor grid lines is set by command <a href='#opacity'>'opacity</a>'
  4623.          @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number'
  4624.          @ 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>
  4625.          @ note: the complete canvas will be used for the 'log paper'
  4626.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  4627.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  4628.          @ note: when using something like 'xrange 0.0001,0.01'...combined with commands <a href='#mouse'>'mouse'</a> and/or <a href='#userdraw'>'userdraw</a>...<br /> make sure the <a href='#precision'>precision</a> is set accordingly
  4629.          @ note: in case of userdraw , the use of keyword <a href='#userinput_xy'>'userinput_xy'</a> may be handy !
  4630.          @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
  4631.         */
  4632.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  4633.             if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
  4634.             for(i=0;i<4;i++){
  4635.                 switch(i){
  4636.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  4637.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  4638.                     case 2: stroke_color = get_color(infile,0); break;
  4639.                     case 3: fill_color = get_color(infile,1);
  4640.                         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);
  4641.                         tmp_buffer = my_newmem(string_length+1);
  4642.                         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);
  4643.                         fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
  4644.                         add_to_buffer(tmp_buffer);
  4645.                         break;
  4646.                     default:break;
  4647.                 }
  4648.             }
  4649.             break;
  4650.         case YLOGSCALE:
  4651.         /*
  4652.          @ ylogscale xmajor,xminor,majorcolor,minorcolor
  4653.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  4654.          @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
  4655.          @ the linewidth is set using command 'linewidth int'
  4656.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  4657.          @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number'
  4658.          @ 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>
  4659.          @ note: the complete canvas will be used for the 'log paper'
  4660.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  4661.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  4662.          @ 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')
  4663.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  4664.          @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
  4665.         */
  4666.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  4667.             if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
  4668.             for(i=0;i<4;i++){
  4669.                 switch(i){
  4670.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  4671.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  4672.                     case 2: stroke_color = get_color(infile,0); break;
  4673.                     case 3: fill_color = get_color(infile,1);
  4674.                         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);
  4675.                         tmp_buffer = my_newmem(string_length+1);
  4676.                         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);
  4677.                         fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
  4678.                         add_to_buffer(tmp_buffer);
  4679.                         break;
  4680.                     default:break;
  4681.                 }
  4682.             }
  4683.             break;
  4684.         case XYLOGSCALE:
  4685.         /*
  4686.          @ xylogscale majorcolor,minorcolor
  4687.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  4688.          @ the linewidth is set using command 'linewidth int'
  4689.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  4690.          @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number'
  4691.          @ 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>
  4692.          @ note: the complete canvas will be used for the 'log paper'
  4693.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  4694.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  4695.          @ 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')
  4696.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  4697.          @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
  4698.         */
  4699.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  4700.             if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
  4701.             for(i=0;i<2;i++){
  4702.                 switch(i){
  4703.                     case 0: stroke_color = get_color(infile,0); break;
  4704.                     case 1: fill_color = get_color(infile,1);
  4705.                         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);
  4706.                         tmp_buffer = my_newmem(string_length+1);
  4707.                         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);
  4708.                         fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
  4709.                         add_to_buffer(tmp_buffer);
  4710.                         break;
  4711.                     default:break;
  4712.                 }
  4713.             }
  4714.         break;
  4715.         default:sync_input(infile);
  4716.         break;
  4717.     }
  4718.   }
  4719.   /* we are done parsing script file */
  4720.   /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */
  4721.   if( found_size_command == 1 ){
  4722.     fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
  4723.   }
  4724.   else
  4725.   {
  4726.     if( found_size_command != 3 ){
  4727.      canvas_error("Please specify both xrange and yrange ...");
  4728.     }
  4729.   }
  4730.  
  4731.   /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable/clickable shapes / objects  ! */
  4732.   add_javascript_function(js_function,canvas_root_id);
  4733.    /* add read_canvas() etc functions if needed */
  4734.   if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);}
  4735.   if( use_pan_and_zoom == TRUE ){
  4736.   /* in case of zooming ... */
  4737.   fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\
  4738.  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
  4739.  var ymin_start=ymin;var ymax_start=xmax;\
  4740.  var zoom_x_increment=0;var zoom_y_increment=0;\
  4741.  var pan_x_increment=0;var pan_y_increment=0;\
  4742.  if(use_ylogscale == 0 ){\
  4743.   zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (ymax - ymin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\
  4744.  }else{\
  4745.   zoom_x_increment = (xmax - xmin)/20;\
  4746.   pan_x_increment = (xmax - xmin)/20;\
  4747.  };\
  4748.  var zoom_xy=[xmin,xmax,ymin,ymax];\
  4749.  function start_canvas%d(type){\
  4750.   zoom_xy=[xmin,xmax,ymin,ymax];\
  4751.   switch(type){\
  4752.    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
  4753.    case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\
  4754.    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
  4755.    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
  4756.    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
  4757.    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
  4758.    case 6:xmin = xmin_start; xmax = xmax_start;ymin = ymin_start;ymax = ymax_start;break;\
  4759.    default:break;\
  4760.   };\
  4761.   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
  4762.   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
  4763.   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){};\
  4764.   if(typeof(redraw_all%d) === 'function' ){redraw_all%d(zoom_xy);}\
  4765.   %s ;\
  4766.  };\
  4767.  start_canvas%d(333);\
  4768. };\
  4769. \n<!-- end wims_canvas_function -->\n\
  4770. wims_canvas_function%d();\n",precision,canvas_root_id,canvas_root_id,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
  4771.   }
  4772.   else
  4773.   {
  4774.   /* no zoom, just add buffer */
  4775.   fprintf(js_include_file,"\n<!-- add buffer -->\n\
  4776.  %s\
  4777. };\n\
  4778. <!-- end wims_canvas_function -->\n\
  4779. wims_canvas_function%d();\n",buffer,canvas_root_id);
  4780.   }
  4781. /* done writing the javascript include file */
  4782. fclose(js_include_file);
  4783.  
  4784. }
  4785.  
  4786. /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
  4787.  if( use_tooltip > 0 ){
  4788.   if( use_tooltip == 1 ){
  4789.    add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
  4790.   }
  4791.   else
  4792.   {
  4793.    if( use_tooltip == 2 ){
  4794.     add_js_popup(canvas_root_id,xsize,ysize,getfile_cmd);
  4795.    }
  4796.   }
  4797.  }
  4798. exit(EXIT_SUCCESS);
  4799. }
  4800. /* end main() */
  4801.  
  4802. /******************************************************************************
  4803. **
  4804. **  sync_input
  4805. **
  4806. **  synchronises input line - reads to end of line, leaving file pointer
  4807. **  at first character of next line.
  4808. **
  4809. **  Used by:
  4810. **  main program - error handling.
  4811. **
  4812. ******************************************************************************/
  4813. void sync_input(FILE *infile)
  4814. {
  4815.         int c = 0;
  4816.  
  4817.         if( c == '\n' || c == ';' ) return;
  4818.         while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
  4819.         if( c == EOF ) finished = 1;
  4820.         if( c == '\n' || c == '\r' || c == ';') line_number++;
  4821.         return;
  4822. }
  4823.  
  4824. /******************************************************************************/
  4825.  
  4826. char *str_replace(const char *str, const char *old, const char *new){
  4827. /* http://creativeandcritical.net/str-replace-c/ */
  4828.     if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
  4829.     char *ret, *r;
  4830.     const char *p, *q;
  4831.     size_t oldlen = strlen(old);
  4832.     size_t count = 0;
  4833.     size_t retlen = 0;
  4834.     size_t newlen = strlen(new);
  4835.     if (oldlen != newlen){
  4836.         for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
  4837.             count++;
  4838.             retlen = p - str + strlen(p) + count * (newlen - oldlen);
  4839.         }
  4840.     }
  4841.     else
  4842.     {
  4843.         retlen = strlen(str);
  4844.     }
  4845.  
  4846.     if ((ret = malloc(retlen + 1)) == NULL){
  4847.         ret = NULL;
  4848.         canvas_error("string argument is NULL");
  4849.     }
  4850.     else
  4851.     {
  4852.         for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
  4853.             size_t l = q - p;
  4854.             memcpy(r, p, l);
  4855.             r += l;
  4856.             memcpy(r, new, newlen);
  4857.             r += newlen;
  4858.         }
  4859.         strcpy(r, p);
  4860.     }
  4861.     return ret;
  4862. }
  4863.  
  4864. /******************************************************************************/
  4865.  
  4866. char *get_color(FILE *infile , int last){
  4867.     int c,i = 0,is_hex = 0;
  4868.     char temp[MAX_COLOR_STRING], *string;
  4869.     const char *not_allowed = "0123456789";
  4870.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' )  && ( c != '\t' ) ){
  4871.         if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
  4872.         if( c == '#' ){
  4873.             is_hex = 1;
  4874.         }
  4875.         if( c != ' '){
  4876.             if( is_hex == 0 ){if(strchr(not_allowed,c) != 0){canvas_error("found something like a number...but is should have been a colour or #hex color number...<br />Do not use R,G,B !!! ");}}
  4877.             temp[i]=tolower(c);
  4878.             i++;
  4879.         }
  4880.     }
  4881.     if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
  4882.     if( c == '\n' || c == ';'  || c == '\t' ){ done = TRUE; line_number++; }
  4883.     if( c == EOF ){finished = 1;}
  4884.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  4885.     temp[i]='\0';
  4886.     if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
  4887.     if( is_hex == 1 ){
  4888.         char red[3], green[3], blue[3];
  4889.         red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
  4890.         green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
  4891.         blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
  4892.         int r = (int) strtol(red,   NULL, 16);
  4893.         int g = (int) strtol(green, NULL, 16);
  4894.         int b = (int) strtol(blue,  NULL, 16);
  4895.         string = (char *)my_newmem(12);
  4896.         snprintf(string,11,"%d,%d,%d",r,g,b);
  4897.         return string;
  4898.     }
  4899.     else
  4900.     {
  4901.         string = (char *)my_newmem(sizeof(temp));
  4902.         snprintf(string,sizeof(temp),"%s",temp);
  4903.         for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  4904.             if( strcmp( colors[i].name , string ) == 0 ){
  4905.                 return colors[i].rgb;
  4906.             }
  4907.         }
  4908.         canvas_error("I was expecting a color name or hexnumber...but found nothing.");
  4909.     }
  4910.     return "0,0,255";
  4911. }
  4912.  
  4913. char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
  4914.     int c,i=0;
  4915.     char  temp[MAX_BUFFER], *string;
  4916.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){
  4917.         temp[i]=c;
  4918.         i++;
  4919.         if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
  4920.     }
  4921.     if( ( c == '\n' ||  c == '\t'  || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  4922.     if( c == '\n' ||  c == '\t') { done = TRUE; line_number++; }
  4923.     if( c == EOF ) {finished = 1;}
  4924.     temp[i]='\0';
  4925.     if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing !!");}
  4926.     string=(char *)my_newmem(strlen(temp));
  4927.     snprintf(string,sizeof(temp),"%s",temp);
  4928.     return string;
  4929. }
  4930.  
  4931. char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
  4932.     int c,i=0;
  4933.     char temp[MAX_BUFFER], *string;
  4934.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){
  4935.         temp[i]=c;
  4936.         i++;
  4937.         if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
  4938.     }
  4939.     if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
  4940.     if( c == '\n' || c == '\t' ) { line_number++; }
  4941.     if( c == EOF ) {finished = 1;}
  4942.     if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");}
  4943.     temp[i]='\0';
  4944. /*
  4945.     17.10.2014 removed (question Perrin)
  4946.     may cause some unwanted effects...
  4947.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
  4948. */
  4949.     string=(char *)my_newmem(sizeof(temp));
  4950.     snprintf(string,sizeof(temp),"%s",temp);
  4951.     done = TRUE;
  4952.     return string;
  4953. }
  4954.  
  4955. double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
  4956.     int c,i=0,found_calc = 0;
  4957.     double y;
  4958.     char tmp[MAX_INT];
  4959.     /*
  4960.      these things are 'allowed functions' : *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs
  4961.      but there should be a better way to avoid segfaults !
  4962.     */
  4963.     const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/
  4964.     const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */
  4965.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){
  4966.      if( c != ' ' ){
  4967.       if( i == 0 &&  c == '+' ){
  4968.        continue;
  4969.       }
  4970.       else
  4971.       {
  4972.        c = tolower(c);
  4973.        if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");}
  4974.        if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */
  4975.        tmp[i] = c;
  4976.        i++;
  4977.       }
  4978.      }
  4979.      if( i > MAX_INT - 1){canvas_error("number too large");}
  4980.     }
  4981.     if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
  4982.     if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; }
  4983.     if( c == EOF ){done = TRUE ; finished = 1;}
  4984.     tmp[i]='\0';
  4985.     if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
  4986.     if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */
  4987.      void *f = eval_create(tmp);
  4988.      assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  4989.      y = eval_x(f, 1);
  4990.      /* if function is bogus; y = 1 : so no core dumps */
  4991.      eval_destroy(f);
  4992.     }
  4993.     else
  4994.     {
  4995.      y = atof(tmp);
  4996.     }
  4997.     return y;
  4998. }
  4999.  
  5000.  
  5001. void canvas_error(char *msg){
  5002.     fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number,msg);
  5003.     finished = 1;
  5004.     exit(EXIT_SUCCESS);
  5005. }
  5006.  
  5007.  
  5008. /* convert x/y coordinates to pixel */
  5009. int x2px(double x){
  5010.  return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
  5011. }
  5012.  
  5013. int y2px(double y){
  5014.  return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
  5015. }
  5016.  
  5017. double px2x(int x){
  5018.  return (x*(xmax - xmin)/xsize + xmin);
  5019. }
  5020. double px2y(int y){
  5021.  return (y*(ymax - ymin)/ysize + ymin);
  5022. }
  5023.  
  5024. void add_to_buffer(char *tmp){
  5025.  if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
  5026.  /*  do we have enough space left in buffer[MAX_BUFFER] ? */
  5027.  int space_left = (int) (sizeof(buffer) - strlen(buffer));
  5028.  if( space_left > strlen(tmp)){
  5029.   strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
  5030.  }
  5031.  else
  5032.  {
  5033.   canvas_error("buffer is too big\n");
  5034.  }
  5035.  tmp = NULL;free(tmp);
  5036.  return;
  5037. }
  5038.  
  5039. void reset(){
  5040.  if(use_filled == TRUE){use_filled = FALSE;}
  5041.  if(use_dashed == TRUE){use_dashed = FALSE;}
  5042.  if(use_rotate == TRUE){use_rotate = FALSE;}
  5043.  onclick = 0;
  5044. }
  5045.  
  5046.  
  5047.  
  5048. /* What reply format in read_canvas();
  5049.  
  5050. note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
  5051. 1 = x1,x2,x3,x4....x_n
  5052.     y1,y2,y3,y4....y_n
  5053.  
  5054.     x/y in pixels
  5055.  
  5056. 2 = x1,x2,x3,x4....x_n
  5057.     y1,y2,y3,y4....y_n
  5058.     x/y in  xrange / yrange coordinate system
  5059.  
  5060. 3 = x1,x2,x3,x4....x_n
  5061.     y1,y2,y3,y4....y_n
  5062.     r1,r2,r3,r4....r_n
  5063.  
  5064.     x/y in pixels
  5065.     r in pixels
  5066.  
  5067. 4 = x1,x2,x3,x4....x_n
  5068.     y1,y2,y3,y4....y_n
  5069.     r1,r2,r3,r4....r_n
  5070.  
  5071.     x/y in  xrange / yrange coordinate system
  5072.     r in pixels
  5073.  
  5074. 5 = Ax1,Ax2,Ax3,Ax4....Ax_n
  5075.     Ay1,Ay2,Ay3,Ay4....Ay_n
  5076.     Bx1,Bx2,Bx3,Bx4....Bx_n
  5077.     By1,By2,By3,By4....By_n
  5078.     Cx1,Cx2,Cx3,Cx4....Cx_n
  5079.     Cy1,Cy2,Cy3,Cy4....Cy_n
  5080.     ....
  5081.     Zx1,Zx2,Zx3,Zx4....Zx_n
  5082.     Zy1,Zy2,Zy3,Zy4....Zy_n
  5083.  
  5084.     x/y in pixels
  5085.  
  5086. 6 = Ax1,Ax2,Ax3,Ax4....Ax_n
  5087.     Ay1,Ay2,Ay3,Ay4....Ay_n
  5088.     Bx1,Bx2,Bx3,Bx4....Bx_n
  5089.     By1,By2,By3,By4....By_n
  5090.     Cx1,Cx2,Cx3,Cx4....Cx_n
  5091.     Cy1,Cy2,Cy3,Cy4....Cy_n
  5092.     ....
  5093.     Zx1,Zx2,Zx3,Zx4....Zx_n
  5094.     Zy1,Zy2,Zy3,Zy4....Zy_n
  5095.  
  5096.     x/y in  xrange / yrange coordinate system
  5097.  
  5098. 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  5099.  
  5100.     x/y in pixels
  5101.  
  5102. 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  5103.  
  5104.     x/y in  xrange / yrange coordinate system
  5105.  
  5106. 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
  5107.  
  5108.     x/y in pixels
  5109.  
  5110. 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
  5111.  
  5112.     x/y in  xrange / yrange coordinate system
  5113.  
  5114. 11 = Ax1,Ay1,Ax2,Ay2
  5115.      Bx1,By1,Bx2,By2
  5116.      Cx1,Cy1,Cx2,Cy2
  5117.      Dx1,Dy1,Dx2,Dy2
  5118.      ......
  5119.      Zx1,Zy1,Zx2,Zy2
  5120.  
  5121.     x/y in  xrange / yrange coordinate system
  5122.  
  5123. 12 = Ax1,Ay1,Ax2,Ay2
  5124.      Bx1,By1,Bx2,By2
  5125.      Cx1,Cy1,Cx2,Cy2
  5126.      Dx1,Dy1,Dx2,Dy2
  5127.      ......
  5128.      Zx1,Zy1,Zx2,Zy2
  5129.  
  5130.     x/y in pixels
  5131.  
  5132. 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
  5133.  
  5134.     x/y in  xrange / yrange coordinate system
  5135. 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
  5136.     x/y in pixels
  5137. 15 = reply from inputfields,textareas
  5138.     reply1,reply2,reply3,...,reply_n
  5139.     only fields set write (a.g. will not read 'readonly' inputfield values'
  5140.  
  5141. 16 = read mathml inputfields only
  5142.  
  5143. 17 = read userdraw text only (x1,y1,text1\nx2,y2,text2..\n.x_n,y_n,text_n
  5144.  when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
  5145.  
  5146. 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
  5147. 19 = return clicked object number (analogue to shape-library onclick)
  5148. 20 = return x/y-data in x-range/y-range of all 'draggable' images
  5149. 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
  5150. 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
  5151.     x/y in  xrange / yrange coordinate system
  5152. 23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
  5153. 24 = read all inputfield values: even those set 'readonly'
  5154. 25 = return all userdrawn arcs in degrees:
  5155. 26 = return all userdrawn arcs in radians:
  5156. 27 = return (only) userdraw inputfields array: x1,y1,text1 \n x2,y2,text2...
  5157. 28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
  5158.     x/y/r in  xrange / yrange coordinate system: may be used to reinput into command
  5159.     'circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n'
  5160.     will not return anything else (e.g. no inputfields , text etc)
  5161. 29 = mulidraw read :
  5162.  
  5163. */
  5164.  
  5165.  
  5166. void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){
  5167. /* just 1 reply type allowed */
  5168. fprintf(js_include_file,"\
  5169. \n<!-- begin set_reply_precision() -->\n\
  5170. function set_reply_precision(){\
  5171. var len = userdraw_x.length;\
  5172. var prec = %d;\
  5173. for(var p = 0 ; p < len ; p++ ){\
  5174.  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
  5175.  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
  5176. };\
  5177. len = userdraw_radius.length;\
  5178. if( len > 0 ){\
  5179.  for(var p = 0 ; p < len ; p++ ){\
  5180.   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
  5181.  };\
  5182. };\
  5183. };",reply_precision);
  5184.  
  5185. switch(type_reply){
  5186. /*
  5187. answers may have:
  5188. x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
  5189. */
  5190.     case 1: fprintf(js_include_file,"\
  5191. \n<!-- begin function 1 read_canvas%d() -->\n\
  5192. read_canvas%d = function(){\
  5193. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  5194. set_reply_precision();\
  5195. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  5196.  var p = 0;var input_reply = new Array();\
  5197.  if( document.getElementById(\"canvas_input0\")){\
  5198.   var t = 0;\
  5199.   while(document.getElementById(\"canvas_input\"+t)){\
  5200.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5201.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5202.     p++;\
  5203.    };\
  5204.    t++;\
  5205.   };\
  5206.  };\
  5207.  if( typeof(userdraw_text) !== 'undefined' ){\
  5208.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
  5209.  }\
  5210.  else\
  5211.  {\
  5212.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
  5213.  }\
  5214. }\
  5215. else\
  5216. {\
  5217.  if( typeof(userdraw_text) !== 'undefined' ){\
  5218.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
  5219.  }\
  5220.  else\
  5221.  {\
  5222.   return userdraw_x+\"\\n\"+userdraw_y;\
  5223.  }\
  5224. };\
  5225. };\n\
  5226. <!-- end function 1 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5227.     break;
  5228.     case 2: fprintf(js_include_file,"\
  5229. \n<!-- begin function 2 read_canvas%d() -->\n\
  5230. read_canvas%d = function(){\
  5231. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  5232. set_reply_precision();\
  5233. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  5234. var prec = %d;\
  5235. while(userdraw_x[p]){\
  5236.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  5237.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  5238.  p++;\
  5239. };\
  5240. if(p == 0){alert(\"nothing drawn...\");return;};\
  5241. if( document.getElementById(\"canvas_input0\")){\
  5242.  var p = 0;var input_reply = new Array();\
  5243.  if( document.getElementById(\"canvas_input0\")){\
  5244.   var t = 0;\
  5245.   while(document.getElementById(\"canvas_input\"+t)){\
  5246.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5247.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5248.     p++;\
  5249.    };\
  5250.    t++;\
  5251.   };\
  5252.  };\
  5253.  if( typeof(userdraw_text) !== 'undefined' ){\
  5254.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5255.  }\
  5256.  else\
  5257.  {\
  5258.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  5259.  }\
  5260. }\
  5261. else\
  5262. {\
  5263.  if( typeof(userdraw_text) !== 'undefined' ){\
  5264.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  5265.  }\
  5266.  else\
  5267.  {\
  5268.   return reply_x+\"\\n\"+reply_y;\
  5269.  };\
  5270. };\
  5271. };\n\
  5272. <!-- end function 2 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  5273.     break;
  5274.     case 3: fprintf(js_include_file,"\
  5275. \n<!-- begin function 3 read_canvas%d() -->\n\
  5276. read_canvas%d = function(){\
  5277. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  5278. set_reply_precision();\
  5279. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  5280.  var p = 0;var input_reply = new Array();\
  5281.  if( document.getElementById(\"canvas_input0\")){\
  5282.   var t = 0;\
  5283.   while(document.getElementById(\"canvas_input\"+t)){\
  5284.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5285.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5286.     p++;\
  5287.    };\
  5288.    t++;\
  5289.   };\
  5290.  };\
  5291.  if( typeof(userdraw_text) !== 'undefined' ){\
  5292.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5293.  }\
  5294.  else\
  5295.  {\
  5296.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  5297.  }\
  5298. }\
  5299. else\
  5300. {\
  5301.  if( typeof(userdraw_text) !== 'undefined' ){\
  5302.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
  5303.  }\
  5304.  else\
  5305.  {\
  5306.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
  5307.  }\
  5308. }\
  5309. };\n\
  5310. <!-- end function 3 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5311.     break;
  5312.     case 4: fprintf(js_include_file,"\
  5313. \n<!-- begin function 4 read_canvas%d() -->\n\
  5314. read_canvas%d = function(){\
  5315. var prec = %d;\
  5316. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  5317. while(userdraw_x[p]){\
  5318.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  5319.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
  5320.  p++;\
  5321. };\
  5322. if(p == 0){alert(\"nothing drawn...\");return;};\
  5323. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  5324.  var p = 0;var input_reply = new Array();\
  5325.  if( document.getElementById(\"canvas_input0\")){\
  5326.   var t = 0;\
  5327.   while(document.getElementById(\"canvas_input\"+t)){\
  5328.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5329.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5330.     p++;\
  5331.    };\
  5332.    t++;\
  5333.   };\
  5334.  };\
  5335.  if( typeof(userdraw_text) !== 'undefined' ){\
  5336.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5337.  }\
  5338.  else\
  5339.  {\
  5340.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  5341.  }\
  5342. }\
  5343. else\
  5344. {\
  5345.  if( typeof(userdraw_text) !== 'undefined' ){\
  5346.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
  5347.  }\
  5348.  else\
  5349.  {\
  5350.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
  5351.  }\
  5352. };\
  5353. };\n\
  5354. <!-- end function 4 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  5355.     break;
  5356.     /*
  5357.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  5358.         used for userdraw multiple paths
  5359.     */
  5360.     case 5: fprintf(js_include_file,"\
  5361. \n<!-- begin function 5 read_canvas%d() -->\n\
  5362. read_canvas%d = function(){\
  5363. set_reply_precision();\
  5364. var p = 0;\
  5365. var reply = \"\";\
  5366. for(p = 0; p < userdraw_x.length;p++){\
  5367.  if(userdraw_x[p] != null ){\
  5368.   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
  5369.  };\
  5370. };\
  5371. if(p == 0){alert(\"nothing drawn...\");return;};\
  5372. userdraw_x = [];userdraw_y = [];\
  5373. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  5374.  var p = 0;var input_reply = new Array();\
  5375.  if( document.getElementById(\"canvas_input0\")){\
  5376.   var t = 0;\
  5377.   while(document.getElementById(\"canvas_input\"+t)){\
  5378.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5379.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5380.     p++;\
  5381.    };\
  5382.    t++;\
  5383.   };\
  5384.  };\
  5385.  if( typeof(userdraw_text) !== 'undefined' ){\
  5386.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5387.  }\
  5388.  else\
  5389.  {\
  5390.   return reply +\"\\n\"+input_reply;\
  5391.  }\
  5392. }\
  5393. else\
  5394. {\
  5395.  if( typeof(userdraw_text) !== 'undefined' ){\
  5396.   return reply+\"\\n\"+userdraw_text;\
  5397.  }\
  5398.  else\
  5399.  {\
  5400.   return reply;\
  5401.  }\
  5402. };\
  5403. };\n\
  5404. <!-- end function 5 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5405.     break;
  5406.     /*
  5407.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  5408.         used for userdraw multiple paths
  5409.     */
  5410.     case 6: fprintf(js_include_file,"\
  5411. \n<!-- begin function 6 read_canvas%d() -->\n\
  5412. read_canvas%d = function(){\
  5413. var p = 0;\
  5414. var reply = \"\";\
  5415. var tmp_x = new Array();\
  5416. var tmp_y = new Array();\
  5417. var prec = %d;\
  5418. for(p = 0 ; p < userdraw_x.length; p++){\
  5419.  tmp_x = userdraw_x[p];\
  5420.  tmp_y = userdraw_y[p];\
  5421.  if(tmp_x != null){\
  5422.   for(var i = 0 ; i < tmp_x.length ; i++){\
  5423.    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
  5424.    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
  5425.   };\
  5426.   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
  5427.  };\
  5428. };\
  5429. if(p == 0){alert(\"nothing drawn...\");return;};\
  5430. userdraw_x = [];userdraw_y = [];\
  5431. if( document.getElementById(\"canvas_input0\") ){\
  5432.  var p = 0;var input_reply = new Array();\
  5433.  if( document.getElementById(\"canvas_input0\")){\
  5434.   var t = 0;\
  5435.   while(document.getElementById(\"canvas_input\"+t)){\
  5436.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5437.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5438.     p++;\
  5439.    };\
  5440.    t++;\
  5441.   };\
  5442.  };\
  5443.  if( typeof(userdraw_text) !== 'undefined' ){\
  5444.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5445.  }\
  5446.  else\
  5447.  {\
  5448.   return reply +\"\\n\"+input_reply;\
  5449.  }\
  5450. }\
  5451. else\
  5452. {\
  5453.  if( typeof(userdraw_text) !== 'undefined' ){\
  5454.   return reply +\"\\n\"+userdraw_text;\
  5455.  }\
  5456.  else\
  5457.  {\
  5458.   return reply;\
  5459.  }\
  5460. };\
  5461. };\n\
  5462. <!-- end function 6 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  5463.     break;
  5464.     case 7: fprintf(js_include_file,"\
  5465. \n<!-- begin function 7 read_canvas%d() -->\n\
  5466. read_canvas%d = function(){\
  5467. set_reply_precision();\
  5468. var reply = new Array();\
  5469. var p = 0;\
  5470. while(userdraw_x[p]){\
  5471.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
  5472.  p++;\
  5473. };\
  5474. if(p == 0){alert(\"nothing drawn...\");return;};\
  5475. if( document.getElementById(\"canvas_input0\") ){\
  5476.  var p = 0;var input_reply = new Array();\
  5477.  if( document.getElementById(\"canvas_input0\")){\
  5478.   var t = 0;\
  5479.   while(document.getElementById(\"canvas_input\"+t)){\
  5480.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5481.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5482.     p++;\
  5483.    };\
  5484.    t++;\
  5485.   };\
  5486.  };\
  5487.  if( typeof(userdraw_text) !== 'undefined' ){\
  5488.   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5489.  }\
  5490.  else\
  5491.  {\
  5492.   return reply+\"\\n\"+input_reply;\
  5493.  }\
  5494. }\
  5495. else\
  5496. {\
  5497.  if( typeof(userdraw_text) !== 'undefined' ){\
  5498.   return reply+\"\\n\"+userdraw_text;\
  5499.  }\
  5500.  else\
  5501.  {\
  5502.   return reply;\
  5503.  }\
  5504. };\
  5505. };\n\
  5506. <!-- end function 7 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5507.     break;
  5508.     case 8: fprintf(js_include_file,"\
  5509. \n<!-- begin function 8 read_canvas%d() -->\n\
  5510. read_canvas%d = function(){\
  5511. var reply = new Array();\
  5512. var p = 0;\
  5513. var prec = %d;\
  5514. while(userdraw_x[p]){\
  5515.  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  5516.  p++;\
  5517. };\
  5518. if(p == 0){alert(\"nothing drawn...\");return;};\
  5519. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  5520.  var p = 0;var input_reply = new Array();\
  5521.  if( document.getElementById(\"canvas_input0\")){\
  5522.   var t = 0;\
  5523.   while(document.getElementById(\"canvas_input\"+t)){\
  5524.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5525.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5526.     p++;\
  5527.    };\
  5528.    t++;\
  5529.   };\
  5530.  };\
  5531.  if( typeof(userdraw_text) !== 'undefined' ){\
  5532.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5533.  }\
  5534.  else\
  5535.  {\
  5536.   return reply +\"\\n\"+input_reply;\
  5537.  }\
  5538. }\
  5539. else\
  5540. {\
  5541.  if( typeof(userdraw_text) !== 'undefined' ){\
  5542.   return reply +\"\\n\"+userdraw_text;\
  5543.  }\
  5544.  else\
  5545.  {\
  5546.   return reply;\
  5547.  }\
  5548. };\
  5549. };\n\
  5550. <!-- end function 8 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  5551.     break;
  5552.     case 9: fprintf(js_include_file,"\
  5553. \n<!-- begin function 9 read_canvas%d() -->\n\
  5554. read_canvas%d = function(){\
  5555. set_reply_precision();\
  5556. var reply = new Array();\
  5557. var p = 0;\
  5558. while(userdraw_x[p]){\
  5559.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
  5560.  p++;\
  5561. };\
  5562. if(p == 0){alert(\"nothing drawn...\");return;};\
  5563. if( document.getElementById(\"canvas_input0\") ){\
  5564.  var p = 0;var input_reply = new Array();\
  5565.  if( document.getElementById(\"canvas_input0\")){\
  5566.   var t = 0;\
  5567.   while(document.getElementById(\"canvas_input\"+t)){\
  5568.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5569.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5570.     p++;\
  5571.    };\
  5572.    t++;\
  5573.   };\
  5574.  };\
  5575.  if( typeof(userdraw_text) !== 'undefined' ){\
  5576.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5577.  }\
  5578.  else\
  5579.  {\
  5580.   return reply +\"\\n\"+input_reply;\
  5581.  }\
  5582. }\
  5583. else\
  5584. {\
  5585.  if( typeof(userdraw_text) !== 'undefined' ){\
  5586.   return reply +\"\\n\"+userdraw_text;\
  5587.  }\
  5588.  else\
  5589.  {\
  5590.   return reply;\
  5591.  }\
  5592. };\
  5593. };\n\
  5594. <!-- end function 9 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5595.     break;
  5596.     case 10: fprintf(js_include_file,"\
  5597. \n<!-- begin function 10 read_canvas%d() -->\n\
  5598. read_canvas%d = function(){\
  5599. var reply = new Array();\
  5600. var p = 0;\
  5601. var prec = %d;\
  5602. while(userdraw_x[p]){\
  5603.  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\":\" + (Math.round(prec*userdraw_radius[p]))/prec;\
  5604.  p++;\
  5605. };\
  5606. if(p == 0){alert(\"nothing drawn...\");return;};\
  5607. if( document.getElementById(\"canvas_input0\") ){\
  5608.  var p = 0;var input_reply = new Array();\
  5609.  if( document.getElementById(\"canvas_input0\")){\
  5610.   var t = 0;\
  5611.   while(document.getElementById(\"canvas_input\"+t)){\
  5612.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5613.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5614.     p++;\
  5615.    };\
  5616.    t++;\
  5617.   };\
  5618.  };\
  5619.  if( typeof(userdraw_text) !== 'undefined' ){\
  5620.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5621.  }\
  5622.  else\
  5623.  {\
  5624.   return reply +\"\\n\"+input_reply;\
  5625.  }\
  5626. }\
  5627. else\
  5628. {\
  5629.  if( typeof(userdraw_text) !== 'undefined' ){\
  5630.   return reply +\"\\n\"+userdraw_text;\
  5631.  }\
  5632.  else\
  5633.  {\
  5634.   return reply;\
  5635.  }\
  5636. };\
  5637. };\n\
  5638. <!-- end function 10 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  5639.     break;
  5640.     case 11: fprintf(js_include_file,"\
  5641. \n<!-- begin function 11 read_canvas%d() -->\n\
  5642. read_canvas%d = function(){\
  5643. var reply = \"\";\
  5644. var p = 0;\
  5645. var prec = %d;\
  5646. while(userdraw_x[p]){\
  5647.  reply = reply + (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\",\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec +\"\\n\" ;\
  5648.  p = p+2;\
  5649. };\
  5650. if(p == 0){alert(\"nothing drawn...\");return;};\
  5651. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  5652.  var p = 0;var input_reply = new Array();\
  5653.  if( document.getElementById(\"canvas_input0\")){\
  5654.   var t = 0;\
  5655.   while(document.getElementById(\"canvas_input\"+t)){\
  5656.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5657.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5658.     p++;\
  5659.    };\
  5660.    t++;\
  5661.   };\
  5662.  };\
  5663.  if( typeof(userdraw_text) !== 'undefined' ){\
  5664.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5665.  }\
  5666.  else\
  5667.  {\
  5668.   return reply +\"\\n\"+input_reply;\
  5669.  }\
  5670. }\
  5671. else\
  5672. {\
  5673.  if( typeof(userdraw_text) !== 'undefined' ){\
  5674.   return reply +\"\\n\"+userdraw_text;\
  5675.  }\
  5676.  else\
  5677.  {\
  5678.   return reply;\
  5679.  }\
  5680. };\
  5681. };\n\
  5682. <!-- end function 11 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  5683.     break;
  5684.     case 12: fprintf(js_include_file,"\
  5685. \n<!-- begin function 12 read_canvas%d() -->\n\
  5686. read_canvas%d = function(){\
  5687. set_reply_precision();\
  5688. var reply = \"\";\
  5689. var p = 0;\
  5690. for(p = 0; p< userdraw_x.lenght;p = p+2){\
  5691.  if(userdraw_x[p] != null){\
  5692.    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
  5693.  };\
  5694. };\
  5695. if(p == 0){alert(\"nothing drawn...\");return;};\
  5696. if( document.getElementById(\"canvas_input0\") ){\
  5697.  var p = 0;var input_reply = new Array();\
  5698.  if( document.getElementById(\"canvas_input0\")){\
  5699.   var t = 0;\
  5700.   while(document.getElementById(\"canvas_input\"+t)){\
  5701.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5702.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5703.     p++;\
  5704.    };\
  5705.    t++;\
  5706.   };\
  5707.  };\
  5708.  if( typeof(userdraw_text) !== 'undefined' ){\
  5709.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5710.  }\
  5711.  else\
  5712.  {\
  5713.   return reply +\"\\n\"+input_reply;\
  5714.  }\
  5715. }\
  5716. else\
  5717. {\
  5718.  if( typeof(userdraw_text) !== 'undefined' ){\
  5719.   return reply +\"\\n\"+userdraw_text\
  5720.  }\
  5721.  else\
  5722.  {\
  5723.   return reply;\
  5724.  }\
  5725. };\
  5726. };\n\
  5727. <!-- end function 12 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5728.     break;
  5729.     case 13: fprintf(js_include_file,"\
  5730. \n<!-- begin function 13 read_canvas%d() -->\n\
  5731. read_canvas%d = function(){\
  5732. var reply = new Array();\
  5733. var p = 0;var i = 0;\
  5734. var prec = %d;\
  5735. while(userdraw_x[p]){\
  5736.  reply[i] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\":\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec;\
  5737.  p = p+2;i++;\
  5738. };\
  5739. if(p == 0){alert(\"nothing drawn...\");return;};\
  5740. if( document.getElementById(\"canvas_input0\") ){\
  5741.  var p = 0;var input_reply = new Array();\
  5742.  if( document.getElementById(\"canvas_input0\")){\
  5743.   var t = 0;\
  5744.   while(document.getElementById(\"canvas_input\"+t)){\
  5745.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5746.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5747.     p++;\
  5748.    };\
  5749.    t++;\
  5750.   };\
  5751.  };\
  5752.  if( typeof(userdraw_text) !== 'undefined' ){\
  5753.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5754.  }\
  5755.  else\
  5756.  {\
  5757.   return reply +\"\\n\"+input_reply;\
  5758.  }\
  5759. }\
  5760. else\
  5761. {\
  5762.  if( typeof(userdraw_text) !== 'undefined' ){\
  5763.   return reply +\"\\n\"+userdraw_text\
  5764.  }\
  5765.  else\
  5766.  {\
  5767.   return reply;\
  5768.  }\
  5769. };\
  5770. };\n\
  5771. <!-- end function 13 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  5772.     break;
  5773.     case 14: fprintf(js_include_file,"\
  5774. \n<!-- begin function 14 read_canvas%d() -->\n\
  5775. read_canvas%d = function(){\
  5776. set_reply_precision();\
  5777. var reply = new Array();\
  5778. var p = 0;var i = 0;\
  5779. while(userdraw_x[p]){\
  5780.  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
  5781.  p = p+2;i++;\
  5782. };\
  5783. if(p == 0){alert(\"nothing drawn...\");return;};\
  5784. if( document.getElementById(\"canvas_input0\") ){\
  5785.  var p = 0;var input_reply = new Array();\
  5786.  if( document.getElementById(\"canvas_input0\")){\
  5787.   var t = 0;\
  5788.   while(document.getElementById(\"canvas_input\"+t)){\
  5789.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5790.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5791.     p++;\
  5792.    };\
  5793.    t++;\
  5794.   };\
  5795.  };\
  5796.  if( typeof(userdraw_text) !== 'undefined' ){\
  5797.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5798.  }\
  5799.  else\
  5800.  {\
  5801.   return reply +\"\\n\"+input_reply;\
  5802.  }\
  5803. }\
  5804. else\
  5805. {\
  5806.  if( typeof(userdraw_text) !== 'undefined' ){\
  5807.   return reply +\"\\n\"+userdraw_text;\
  5808.  }\
  5809.  else\
  5810.  {\
  5811.   return reply;\
  5812.  }\
  5813. };\
  5814. };\n\
  5815. <!-- end function 14 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5816.     break;
  5817.     case 15: fprintf(js_include_file,"\
  5818. \n<!-- begin function 15  read_canvas%d() -->\n\
  5819. read_canvas%d = function(){\
  5820. var input_reply = new Array();\
  5821. var p = 0;\
  5822. if( document.getElementById(\"canvas_input0\")){\
  5823.  var t = 0;\
  5824.  while(document.getElementById(\"canvas_input\"+t)){\
  5825.   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5826.    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5827.    p++;\
  5828.   };\
  5829.   t++;\
  5830.  };\
  5831. };\
  5832. if( typeof(userdraw_text) !== 'undefined' ){\
  5833.   return input_reply +\"\\n\"+userdraw_text;\
  5834. }\
  5835. else\
  5836. {\
  5837.  return input_reply;\
  5838. };\
  5839. };\n\
  5840. <!-- end function 15 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5841.     break;
  5842.     case 16: fprintf(js_include_file,"\
  5843. \n<!-- begin function 16 read_mathml() -->\n\
  5844. function read_mathml(){\
  5845. var reply = new Array();\
  5846. var p = 0;\
  5847. if( document.getElementById(\"mathml0\")){\
  5848.  while(document.getElementById(\"mathml\"+p)){\
  5849.   reply[p] = document.getElementById(\"mathml\"+p).value;\
  5850.   p++;\
  5851.  };\
  5852. };\
  5853. return reply;\
  5854. };\
  5855. this.read_mathml = read_mathml;\n\
  5856. <!-- end function 16 read_mathml() -->");
  5857.     break;
  5858.     case 17:  fprintf(js_include_file,"\
  5859. \n<!-- begin function 17 read_canvas%d() -->\n\
  5860. read_canvas%d = function(){\
  5861. var len = userdraw_x.length;\
  5862. if( len == 0){alert(\"no text typed...\");return;}\
  5863. var rep = px2x(userdraw_x[0])+\",\"+px2y(userdraw_y[0])+\",\"+userdraw_text[0];\
  5864. for(var p = 1 ; p < len ; p++){\
  5865.  rep = rep + \"\\n\" + px2x(userdraw_x[p]) + \",\" + px2y(userdraw_y[p]) + \",\" + userdraw_text[p];\
  5866. };\
  5867. return rep;\
  5868. };\n\
  5869. <!-- end function 17 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5870.     break;
  5871.     case 18: fprintf(js_include_file,"\
  5872. \n<!-- javascript has no real modulo function -->\n\
  5873. function mod(n, m){\
  5874. var m = parseInt(((n %% m) + m) %% m);\
  5875. return m;\
  5876. };\
  5877. \n<!-- begin function 18 read_canvas%d() -->\n\
  5878. read_canvas%d = function(){\
  5879. var p = 0;\
  5880. var reply = new Array();\
  5881. var name;\
  5882. var t = true;\
  5883. var h;var m;var s;\
  5884. while(t){\
  5885.  try{\
  5886.   name = eval('clocks'+p);\
  5887.   h = name.H;m = name.M;s = name.S;\
  5888.   h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\
  5889.   reply[p] = h+\":\"+m+\":\"+s;\
  5890.   p++;\
  5891.  }catch(e){t=false;};\
  5892. };\
  5893. if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
  5894. return reply;\
  5895. };\n\
  5896. <!-- end function 18 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5897.     break;
  5898.     case 19: fprintf(js_include_file,"\
  5899. \n<!-- begin function 19 read_canvas%d() -->\n\
  5900. read_canvas%d = function(){\
  5901. return reply[0];\
  5902. };\n\
  5903. <!-- end function 19 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5904.     break;
  5905.     case 20: fprintf(js_include_file,"\
  5906. \n<!-- begin function 20 read_canvas%d() -->\n\
  5907. read_canvas%d = function(){\
  5908. var prec = %d;\
  5909. var len  = ext_drag_images.length;\
  5910. var reply = new Array(len);\
  5911. for(var p = 0 ; p < len ; p++){\
  5912.    var img = ext_drag_images[p];\
  5913.    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  5914. };\
  5915. return reply;\
  5916. };\n\
  5917. <!-- end function 20 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  5918.     break;
  5919.     case 21: fprintf(js_include_file,"\
  5920. \n<!-- begin function 21 read_canvas%d() -->\n\
  5921. read_canvas%d = function(){\
  5922. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  5923. var reply_coord = new Array();var p = 0;\
  5924. var prec = %d;\
  5925. while(userdraw_x[p]){\
  5926.  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
  5927.  p++;\
  5928. };\
  5929. if(p == 0){alert(\"nothing drawn...\");return;};\
  5930. if( document.getElementById(\"canvas_input0\") ){\
  5931.  var p = 0;var input_reply = new Array();\
  5932.  if( document.getElementById(\"canvas_input0\")){\
  5933.   var t = 0;\
  5934.   while(document.getElementById(\"canvas_input\"+t)){\
  5935.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5936.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5937.     p++;\
  5938.    };\
  5939.    t++;\
  5940.   };\
  5941.  };\
  5942.  if( typeof(userdraw_text) !== 'undefined' ){\
  5943.   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5944.  }\
  5945.  else\
  5946.  {\
  5947.   return reply_coord+\"\\n\"+input_reply;\
  5948.  }\
  5949. }\
  5950. else\
  5951. {\
  5952.  if( typeof(userdraw_text) !== 'undefined' ){\
  5953.   return reply_coord+\"\\n\"+userdraw_text;\
  5954.  }\
  5955.  else\
  5956.  {\
  5957.   return reply_coord;\
  5958.  };\
  5959. };\
  5960. };\n\
  5961. <!-- end function 21 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  5962.     break;
  5963.     case 22: fprintf(js_include_file,"\
  5964. \n<!-- begin function 22 read_canvas%d() -->\n\
  5965. read_canvas%d = function(){\
  5966. var reply = new Array();\
  5967. var lu = userdraw_x.length;\
  5968. if(lu == 0){alert(\"nothing drawn...\");return;};\
  5969. var idx = 0;\
  5970. var prec = %d;\
  5971. for(var p = 0 ; p < lu ; p++){\
  5972.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
  5973.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
  5974. };\
  5975. if( document.getElementById(\"canvas_input0\") ){\
  5976.  var p = 0;var input_reply = new Array();\
  5977.  if( document.getElementById(\"canvas_input0\")){\
  5978.   var t = 0;\
  5979.   while(document.getElementById(\"canvas_input\"+t)){\
  5980.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5981.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5982.     p++;\
  5983.    };\
  5984.    t++;\
  5985.   };\
  5986.  };\
  5987.  if( typeof(userdraw_text) !== 'undefined' ){\
  5988.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5989.  }\
  5990.  else\
  5991.  {\
  5992.   return reply +\"\\n\"+input_reply;\
  5993.  }\
  5994. }\
  5995. else\
  5996. {\
  5997.  if( typeof(userdraw_text) !== 'undefined' ){\
  5998.   return reply +\"\\n\"+userdraw_text;\
  5999.  }\
  6000.  else\
  6001.  {\
  6002.   return reply;\
  6003.  }\
  6004. };\
  6005. };\n\
  6006. <!-- end function 22 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6007.     break;
  6008.     case 23: fprintf(js_include_file,"\
  6009. \n<!-- begin function 23 read_canvas%d() default 5 px marge -->\n\
  6010. read_canvas%d = function(){\
  6011. if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
  6012. var lu = userdraw_x.length;\
  6013. if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
  6014. var reply_x = new Array();var reply_y = new Array();\
  6015. var marge = 5;var p = 0;\
  6016. var prec = %d;\
  6017. for(var i = 0; i < lu - 1 ; i++ ){\
  6018.  if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\
  6019.   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
  6020.   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
  6021.   p++;\
  6022.  };\
  6023.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\
  6024. };\
  6025. if( document.getElementById(\"canvas_input0\")){\
  6026.  var p = 0;var input_reply = new Array();\
  6027.  if( document.getElementById(\"canvas_input0\")){\
  6028.   var t = 0;\
  6029.   while(document.getElementById(\"canvas_input\"+t)){\
  6030.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6031.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6032.     p++;\
  6033.    };\
  6034.    t++;\
  6035.   };\
  6036.  };\
  6037.  if( typeof(userdraw_text) !== 'undefined' ){\
  6038.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6039.  }\
  6040.  else\
  6041.  {\
  6042.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  6043.  }\
  6044. }\
  6045. else\
  6046. {\
  6047.  if( typeof(userdraw_text) !== 'undefined' ){\
  6048.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  6049.  }\
  6050.  else\
  6051.  {\
  6052.   return reply_x+\"\\n\"+reply_y;\
  6053.  };\
  6054. };\
  6055. };\n\
  6056. <!-- end function 23 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6057.     break;
  6058.     case 24: fprintf(js_include_file,"\n\
  6059. <!-- begin function 24  read_canvas%d() -->\n\
  6060. read_canvas%d = function(){\
  6061. var input_reply = new Array();\
  6062. var p = 0;\
  6063. if( document.getElementById(\"canvas_input0\")){\
  6064.  while(document.getElementById(\"canvas_input\"+p)){\
  6065.    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
  6066.    p++;\
  6067.  };\
  6068.  return input_reply;\
  6069. };\
  6070. };\n\
  6071. <!-- end function 24 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  6072.     break;
  6073.     case 25:
  6074.     fprintf(js_include_file,"\n<!-- begin function 25 read_canvas%d() : angle(s) in degrees-->\n\
  6075. read_canvas%d = function(){\
  6076. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  6077. var lu = userdraw_radius.length;\
  6078. var prec = %d;\
  6079. var angle_reply = new Array(lu);\
  6080. for(var p = 0 ; p < lu ; p++){\
  6081.  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
  6082. };\
  6083. return angle_reply;\
  6084. };\n\
  6085. <!-- end function 25 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6086.     break;
  6087.     case 26:
  6088.     fprintf(js_include_file,"\n<!-- begin function 26 read_canvas%d() : angle(s) in radians-->\n\
  6089. read_canvas%d = function(){\
  6090. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  6091. var lu = userdraw_radius.length;\
  6092. var prec = %d;\
  6093. var angle_reply = new Array(lu);\
  6094. for(var p = 0 ; p < lu ; p++){\
  6095.  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
  6096. };\
  6097. return angle_reply;\
  6098. };\n\
  6099. <!-- end function 26 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6100.     break;
  6101.     case 27:
  6102.     fprintf(js_include_file,"\n<!-- begin function 27 read_canvas%d()  : inputfield(s) location and their values : -->\n\
  6103. read_canvas%d = function(){\
  6104. var lu = userdraw_x.length;\
  6105. if( lu < 1){alert(\"nothing drawn...\");return;}\
  6106. set_reply_precision();\
  6107. var prec = %d;\
  6108. var rep = (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\",\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\",\"+ document.getElementById(\"canvas_input\"+p).value;\
  6109. for(var p = 0 ; p < lu ; p++){\
  6110.   rep = rep = \"\\n\" + (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\":\"+ document.getElementById(\"canvas_input\"+p).value;\
  6111. };\
  6112. return rep;\
  6113. };\n\
  6114. <!-- end function 27 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6115.     break;
  6116.     case 28:
  6117.     fprintf(js_include_file,"\n<!-- begin function 28 read_canvas%d() -->\n\
  6118. read_canvas%d = function(){\
  6119. var prec = %d;\
  6120. var reply = new Array();var p = 0;\
  6121. var idx = 0;\
  6122. while(userdraw_x[p]){\
  6123.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  6124.  idx++;\
  6125.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  6126.  idx++;\
  6127.  reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\
  6128.  idx++;\
  6129.  p++;\
  6130. };\
  6131. if( p == 0){alert(\"nothing drawn...\");return;}\
  6132. return reply;\
  6133. };\n\
  6134. <!-- end function 28 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6135.     break;
  6136.     case 29:
  6137.     fprintf(js_include_file,"\n<!-- begin function 29 read_canvas%d() -->\n\
  6138. function xy_precision(array_x,array_y){\
  6139. var len = array_x.length;\
  6140. var x_array = new Array(len);\
  6141. var y_array = new Array(len);\
  6142. var prec = %d;\
  6143. for(var p = 0 ; p < len ; p++ ){\
  6144.  x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\
  6145.  y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\
  6146. };\
  6147. return x_array+\";\"+y_array;\
  6148. };\n\
  6149. function round_to_pixel(array_r){\
  6150. var len = array_r.length;\
  6151. for(var p = 0 ; p < len ; p++ ){\
  6152.  array_r[p] = Math.round(array_r[p]);\
  6153. };\
  6154. return array_r;\
  6155. };\
  6156. read_canvas%d = function(){\
  6157. var reply=\" \";\
  6158. if( points_x && points_x.length > 0 ){reply = reply + xy_precision(points_x,points_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6159. if( circles_x && circles_x.length > 0 ){ reply = reply + xy_precision(circles_x,circles_y)+\";\"+round_to_pixel(multi_radius)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6160. if( segments_x && segments_x.length > 0 ){ reply = reply +  xy_precision(segments_x,segments_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6161. if( arrows_x && arrows_x.length > 0 ){ reply = reply +  xy_precision(arrows_x,arrows_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6162. if( lines_x && lines_x.length > 0 ){ reply = reply + xy_precision(lines_x,lines_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6163. if( triangles_x && triangles_x.length > 0){ reply = reply + xy_precision(triangles_x,triangles_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6164. if( rects_x && rects_x.length > 0 ){ reply = reply + xy_precision(rects_x,rects_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6165. if( closedpoly_x && closedpoly_x.length > 0){ closedpoly_x.pop();closedpoly_y.pop();reply = reply + xy_precision(closedpoly_x,closedpoly_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6166. if( text_x && text_x.length > 0){ reply = reply + xy_precision(text_x,text_y)+\";\"+text_abc+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6167. return reply;\
  6168. };\n\
  6169. <!-- end function 29 read_canvas%d() -->",canvas_root_id,reply_precision,canvas_root_id,canvas_root_id);
  6170.     break;
  6171.     case 30:
  6172.     fprintf(js_include_file,"\n<!-- begin function 30 read_canvas%d() -->\n\
  6173. read_canvas%d = function(){\
  6174. var reply = new Array(3);\
  6175. var prec = %d;\
  6176. reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
  6177. reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
  6178. reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\
  6179. return reply;\
  6180. };\n\
  6181. <!-- end function 30 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6182.     break;
  6183.     case 31:
  6184.     fprintf(js_include_file,"\n<!-- begin function 31 read_canvas%d() -->\n\
  6185. read_canvas%d = function(){\
  6186. var reply = new Array(3);\
  6187. var prec = %d;\
  6188. reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
  6189. reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
  6190. reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
  6191. return reply;\
  6192. };\n\
  6193. <!-- end function 31 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6194.     break;
  6195.     case 32:
  6196.     fprintf(js_include_file,"\n<!-- begin function 32 read_canvas%d() -->\n\
  6197. read_canvas%d = function(){\
  6198. var reply = new Array(6);\
  6199. var prec = %d;\
  6200. reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
  6201. reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
  6202. reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
  6203. reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
  6204. reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
  6205. reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\
  6206. return reply;\
  6207. };\n\
  6208. <!-- end function 32 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6209.     break;
  6210.     default: canvas_error("hmmm unknown replyformat...");break;
  6211. }
  6212.  return;
  6213. }
  6214.  
  6215.  
  6216. /*
  6217.  add drawfunction :
  6218.  - functions used by userdraw_primitives (circle,rect,path,triangle...)
  6219.  - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
  6220.  - grid / mathml
  6221.  - will not scale or zoom in
  6222.  - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
  6223.  - is printed directly into 'js_include_file'
  6224. */
  6225.  
  6226. void add_javascript_function(int js_function[],int canvas_root_id){
  6227. int i;
  6228. for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
  6229.  if( js_function[i] == 1){
  6230.     switch(i){
  6231.     case JS_FIND_ANGLE:
  6232.     fprintf(js_include_file,"\n\
  6233. <!-- function find_angle() -->\n\
  6234. function find_angle(xc,yc,x1,y1){\
  6235. var dx = x1 - xc;\
  6236. var dy = yc - y1;\
  6237. if( dx > 0 && dy < 0){ return Math.atan(-1*dy/dx);};\
  6238. if( dx < 0 && dy < 0){ return Math.PI + Math.atan(-1*dy/dx);};\
  6239. if( dx < 0 && dy > 0){ return Math.PI + Math.atan(-1*dy/dx);};\
  6240. if( dx > 0 && dy > 0){ return 2*Math.PI + Math.atan(-1*dy/dx);};};");
  6241.     break;
  6242.     case DRAW_EXTERNAL_IMAGE:
  6243. /* the external_canvas is already created: it needs to be FIRST in order to do some drawing onto it
  6244.  draw_external_image(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,int_data[8],int_data[9]);
  6245. */
  6246. fprintf(js_include_file,"\n<!-- drag external images --->\n\
  6247. var external_ctx = external_canvas.getContext(\"2d\");\
  6248. var external_canvas_rect = external_canvas.getBoundingClientRect();\
  6249. canvas_div.addEventListener(\"mousedown\",setxy,false);\
  6250. canvas_div.addEventListener(\"mouseup\",dragstop,false);\
  6251. canvas_div.addEventListener(\"mousemove\",dragxy,false);\
  6252. var selected_image = null;\
  6253. var ext_image_cnt = 0;\
  6254. var ext_drag_images = new Array();\
  6255. function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt){\
  6256. ext_image_cnt = idx;\
  6257. if(draggable == 1 ){\
  6258.  reply[click_cnt] = 0;\
  6259. };\
  6260. var image = new Image();\
  6261. image.src = URL;\
  6262. image.onload = function(){\
  6263.  if( sx < 1 ){ sx = 0; };\
  6264.  if( sy < 1 ){ sy = 0; };\
  6265.  if( swidth < 1 ){swidth = image.width;};\
  6266.  if( sheight < 1 ){sheight = image.height;};\
  6267.  if( width < 1 ){width = image.width;};\
  6268.  if( height < 1 ){height = image.height;};\
  6269.  if( resizable == 0 ){\
  6270.   if( swidth > image.width ){ swidth = image.width; };\
  6271.   if( sheight > image.height){ sheight = image.height;};\
  6272.   if( width > image.width ){ width = image.width; };\
  6273.   if( height > image.height){ height = image.height;};\
  6274.  };\
  6275.  var img = new Array(11);\
  6276.  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
  6277.  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;img[10] = click_cnt;\
  6278.  ext_drag_images[idx] = img;\
  6279.  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  6280. };\
  6281. };\
  6282. function dragstop(evt){\
  6283. selected_image = null;return;\
  6284. };\
  6285. function dragxy(evt){\
  6286. if( selected_image != null ){\
  6287.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  6288.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  6289.  var s_img = ext_drag_images[selected_image];\
  6290.  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\
  6291.  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\
  6292.  if( use_snap_to_points == 1){\
  6293.   var img_xy = snap_to_points(s_img[6],s_img[7]);\
  6294.   s_img[6] = img_xy[0];s_img[7] = img_xy[1];\
  6295.  }\
  6296.  else\
  6297.  {\
  6298.   if( x_use_snap_to_grid == 1 ){\
  6299.    s_img[6] = snap_to_x(s_img[6]);\
  6300.   };\
  6301.   if( y_use_snap_to_grid == 1 ){\
  6302.    s_img[7] = snap_to_x(s_img[7]);\
  6303.   };\
  6304.  };\
  6305.  ext_drag_images[selected_image] = s_img;\
  6306.  external_ctx.clearRect(0,0,xsize,ysize);\
  6307.  for(var i = 0; i <= ext_image_cnt ; i++){\
  6308.   var img = ext_drag_images[i];\
  6309.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  6310.  };\
  6311. };\
  6312. };\
  6313. function setxy(evt){\
  6314. if( ! selected_image && evt.which == 1 ){\
  6315.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  6316.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  6317.  var xm = evt.clientX - external_canvas_rect.left + xoff;\
  6318.  var ym = evt.clientY - external_canvas_rect.top + yoff;\
  6319.  var img;\
  6320.  for(var p = 0 ; p <= ext_image_cnt ; p++){\
  6321.   if( ext_drag_images[p] ){\
  6322.    img = ext_drag_images[p];\
  6323.    if( img[0] != 0 ){\
  6324.     if( xm > img[6] && xm < img[6] + img[8]){\
  6325.      if( ym > img[7] && ym < img[7] + img[9]){\
  6326.       if( img[0] == 1){\
  6327.        if( reply[img[10]] == 1 ){\
  6328.         reply[img[10]] = 0;external_ctx.strokeStyle = '#ffffff';\
  6329.        }\
  6330.        else\
  6331.        {\
  6332.         reply[img[10]] = 1;external_ctx.strokeStyle = '#00ff00';\
  6333.        };\
  6334.        external_ctx.lineWidth = 6;\
  6335.        external_ctx.beginPath();\
  6336.        external_ctx.rect(img[6],img[7],img[8],img[9]);\
  6337.        external_ctx.closePath();\
  6338.        external_ctx.stroke();\
  6339.        return;\
  6340.       }\
  6341.       else\
  6342.       {\
  6343.        img[6] = xm;\
  6344.        img[7] = ym;\
  6345.        ext_drag_images[p] = img;\
  6346.        selected_image = p;\
  6347.        dragxy(evt);\
  6348.       };\
  6349.      };\
  6350.     };\
  6351.    };\
  6352.   };\
  6353.  };\
  6354. }\
  6355. else\
  6356. {\
  6357.  selected_image = null;\
  6358. };\
  6359. };");
  6360.     break;
  6361.     case DRAW_BEZIER:
  6362. fprintf(js_include_file,"\n<!-- draw bezier curve -->\n\
  6363. var draw_bezier = function(canvas_type,linewidth,xy_points,fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
  6364. var obj;\
  6365. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6366.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6367. }\
  6368. else\
  6369. {\
  6370.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6371. };\
  6372. var ctx = obj.getContext(\"2d\");\
  6373. ctx.save();\
  6374. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6375. ctx.lineWidth = linewidth;\
  6376. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6377. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  6378. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  6379. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  6380. ctx.beginPath();\
  6381. ctx.moveTo(x2px(xy_points[0]),y2px(xy_points[1]));\
  6382. ctx.bezierCurveTo(x2px(xy_points[2]),y2px(xy_points[3]),x2px(xy_points[4]),y2px(xy_points[5]),x2px(xy_points[6]),y2px(xy_points[7]));\
  6383. if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  6384. ctx.stroke();\
  6385. ctx.restore();\
  6386. };\n",canvas_root_id,canvas_root_id,canvas_root_id);
  6387.     break;
  6388.     case DRAW_GRIDFILL:/* not used for userdraw */
  6389. fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
  6390. var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\
  6391. var obj;\
  6392. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6393.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6394. }\
  6395. else\
  6396. {\
  6397.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6398. };\
  6399. var ctx = obj.getContext(\"2d\");\
  6400. var x,y;\
  6401. snap_x = dx;snap_y = dy;\
  6402. ctx.save();\
  6403. ctx.lineWidth = line_width;\
  6404. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6405. ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  6406. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  6407.    ctx.moveTo(x,y0);\
  6408.    ctx.lineTo(x,ysize);\
  6409. };\
  6410. for( y = y0 ; y < ysize+dy; y = y + dy ){\
  6411.    ctx.moveTo(x0,y);\
  6412.    ctx.lineTo(xsize,y);\
  6413. };\
  6414. ctx.stroke();\
  6415. ctx.restore();\
  6416. return;};",canvas_root_id,canvas_root_id,canvas_root_id);
  6417.     break;
  6418.  
  6419.     case DRAW_IMAGEFILL:/* not  used for userdraw */
  6420. fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
  6421. var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\
  6422. var obj;\
  6423. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6424.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6425. }\
  6426. else\
  6427. {\
  6428.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6429. };\
  6430. var ctx = obj.getContext(\"2d\");\
  6431. ctx.save();\
  6432. var img = new Image();\
  6433. img.src = URL;\
  6434. img.onload = function(){\
  6435.  if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\
  6436.    ctx.drawImage(img,x0,y0,xsize,ysize);\
  6437.  }\
  6438.  else\
  6439.  {\
  6440.    var repeat = \"repeat\";\
  6441.    if(img.width > xsize - x0){\
  6442.         repeat = \"repeat-y\";\
  6443.    }\
  6444.    else\
  6445.    {\
  6446.     if( img.height > ysize -x0 ){\
  6447.      repeat = \"repeat-x\";\
  6448.     }\
  6449.    }\
  6450.    var pattern = ctx.createPattern(img,repeat);\
  6451.    ctx.rect(x0,y0,xsize,ysize);\
  6452.    ctx.fillStyle = pattern;\
  6453.  }\
  6454.  ctx.fill();\
  6455. };\
  6456. ctx.restore();\
  6457. return;\
  6458. };",canvas_root_id,canvas_root_id,canvas_root_id);
  6459.     break;
  6460.  
  6461.     case DRAW_DOTFILL:/* not  used for userdraw */
  6462. fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
  6463. var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\
  6464. var obj;\
  6465. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6466.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6467. }\
  6468. else\
  6469. {\
  6470.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6471. };\
  6472. var ctx = obj.getContext(\"2d\");\
  6473. var x,y;\
  6474. ctx.closePath();\
  6475. ctx.save();\
  6476. snap_x = dx;snap_y = dy;\
  6477. ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  6478. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  6479.  for( y = y0 ; y < ysize+dy ; y = y + dy ){\
  6480.   ctx.arc(x,y,radius,0,2*Math.PI,false);\
  6481.   ctx.closePath();\
  6482.  }\
  6483. }\
  6484. ctx.fill();\
  6485. ctx.restore();\
  6486. return;};",canvas_root_id,canvas_root_id,canvas_root_id);
  6487.     break;
  6488.  
  6489.     case DRAW_DIAMONDFILL:/* not used for userdraw */
  6490. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  6491. var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  6492.  var obj;\
  6493. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6494.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6495. }\
  6496. else\
  6497. {\
  6498.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6499. };\
  6500. var ctx = obj.getContext(\"2d\");\
  6501. var x;\
  6502. var y;\
  6503. ctx.save();\
  6504. ctx.lineWidth = linewidth;\
  6505. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6506. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6507. y = ysize;\
  6508. for( x = x0 ; x < xsize ; x = x + dx ){\
  6509.  ctx.moveTo(x,y0);\
  6510.  ctx.lineTo(xsize,y);\
  6511.  y = y - dy;\
  6512. };\
  6513. y = y0;\
  6514. for( x = xsize ; x > 0 ; x = x - dx){\
  6515.  ctx.moveTo(x,ysize);\
  6516.  ctx.lineTo(x0,y);\
  6517.  y = y + dy;\
  6518. };\
  6519. x = x0;\
  6520. for( y = y0 ; y < ysize ; y = y + dy ){\
  6521.  ctx.moveTo(xsize,y);\
  6522.  ctx.lineTo(x,ysize);\
  6523.  x = x + dx;\
  6524. };\
  6525. x = xsize;\
  6526. for( y = ysize ; y > y0 ; y = y - dy ){\
  6527.  ctx.moveTo(x,y0);\
  6528.  ctx.lineTo(x0,y);\
  6529.  x = x - dx;\
  6530. };\
  6531. ctx.stroke();\
  6532. ctx.restore();\
  6533. return;\
  6534. }",canvas_root_id,canvas_root_id,canvas_root_id);
  6535.     break;
  6536.  
  6537.     case DRAW_HATCHFILL:/* not used for userdraw */
  6538. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  6539. var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  6540.  var obj;\
  6541. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6542.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6543. }\
  6544. else\
  6545. {\
  6546.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6547. };\
  6548. var ctx = obj.getContext(\"2d\");\
  6549. var x;\
  6550. var y;\
  6551. ctx.save();\
  6552. ctx.lineWidth = linewidth;\
  6553. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6554. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6555. y = ysize;\
  6556. for( x = x0 ; x < xsize ; x = x + dx ){\
  6557.  ctx.moveTo(x,y0);\
  6558.  ctx.lineTo(xsize,y);\
  6559.  y = y - dy;\
  6560. };\
  6561. y = y0;\
  6562. for( x = xsize ; x >= dx ; x = x - dx){\
  6563.  ctx.moveTo(x,ysize);\
  6564.  ctx.lineTo(x0,y);\
  6565.  y = y + dy;\
  6566. };\
  6567. ctx.stroke();\
  6568. ctx.restore();\
  6569. return;\
  6570. };",canvas_root_id,canvas_root_id,canvas_root_id);
  6571.     break;
  6572.     case DRAW_CIRCLES:/*  used for userdraw */
  6573. fprintf(js_include_file,"\n<!-- draw circles -->\n\
  6574. var 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_affine,affine_matrix){\
  6575. ctx.save();\
  6576. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6577. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6578. ctx.lineWidth = line_width;\
  6579. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6580. for(var p = 0 ; p < x_points.length ; p++ ){\
  6581.  ctx.beginPath();\
  6582.  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
  6583.  ctx.closePath();\
  6584.  if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  6585.  if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  6586.  ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6587.  ctx.stroke();\
  6588. }\
  6589. ctx.restore();\
  6590. return;\
  6591. };");
  6592.     break;
  6593.     case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
  6594. fprintf(js_include_file,"\n<!-- draw polyline -->\n\
  6595. var draw_polyline = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
  6596. ctx.save();\
  6597. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6598. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6599. ctx.lineWidth = line_width;\
  6600. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6601. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6602. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  6603. ctx.clearRect(0,0,xsize,ysize);\
  6604. ctx.beginPath();\
  6605. for(var p = 0 ; p < x_points.length-1 ; p++ ){\
  6606.  ctx.moveTo(x_points[p],y_points[p]);\
  6607.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  6608. }\
  6609. ctx.closePath();\
  6610. ctx.stroke();\
  6611. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6612. for(var p = 0 ; p < x_points.length ; p++ ){\
  6613.  ctx.beginPath();\
  6614.  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
  6615.  ctx.closePath();ctx.fill();ctx.stroke();\
  6616. };\
  6617. ctx.restore();\
  6618. return;\
  6619. };");
  6620.     break;
  6621.  
  6622.     case DRAW_SEGMENTS:/*  used for userdraw */
  6623. fprintf(js_include_file,"\n<!-- draw segments -->\n\
  6624. var draw_segments = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
  6625. ctx.save();\
  6626. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6627. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6628. ctx.lineWidth = line_width;\
  6629. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6630. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6631. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  6632. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  6633.  ctx.beginPath();\
  6634.  ctx.moveTo(x_points[p],y_points[p]);\
  6635.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  6636.  ctx.closePath();\
  6637.  ctx.stroke();\
  6638.  }\
  6639.  ctx.restore();\
  6640.  return;\
  6641. };");
  6642.     break;
  6643.  
  6644.     case DRAW_LINES:/*  used for userdraw */
  6645. fprintf(js_include_file,"\n<!-- draw lines -->\n\
  6646. function calc_line(x1,x2,y1,y2){\
  6647. var marge = 2;\
  6648. if(x1 < x2+marge && x1>x2-marge){\
  6649.  return [x1,0,x1,ysize];\
  6650. };\
  6651. if(y1 < y2+marge && y1>y2-marge){\
  6652.  return [0,y1,xsize,y1];\
  6653. };\
  6654. var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
  6655. var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
  6656. return [0,Y1,xsize,Y2];\
  6657. };\
  6658. var draw_lines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
  6659. ctx.save();\
  6660. var line = new Array(4);\
  6661. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6662. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6663. ctx.lineWidth = line_width;\
  6664. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6665. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6666. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  6667. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  6668.  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
  6669.  ctx.beginPath();\
  6670.  ctx.moveTo(line[0],line[1]);\
  6671.  ctx.lineTo(line[2],line[3]);\
  6672.  ctx.closePath();\
  6673.  ctx.stroke();\
  6674.  }\
  6675.  ctx.restore();\
  6676.  return;\
  6677. };");
  6678.     break;
  6679.  
  6680.     case DRAW_DEMILINES:/*  used for userdraw */
  6681. fprintf(js_include_file,"\n<!-- draw demilines -->\n\
  6682. function find_inf_point(x1,y1,x2,y2){\
  6683. if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\
  6684. var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\
  6685. if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\
  6686. };\
  6687. var draw_demilines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
  6688. ctx.save();\
  6689. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6690. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6691. ctx.lineWidth = line_width;\
  6692. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6693. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6694. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  6695. var pair = new Array(4);\
  6696. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  6697.  pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\
  6698.  ctx.beginPath();\
  6699.  ctx.moveTo(pair[0],pair[1]);\
  6700.  ctx.lineTo(pair[2],pair[3]);\
  6701.  ctx.closePath();\
  6702.  ctx.stroke();\
  6703.  }\
  6704.  ctx.restore();\
  6705.  return;\
  6706. };");
  6707.     break;
  6708.  
  6709.     case DRAW_CROSSHAIRS:/*  used for userdraw */
  6710. fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
  6711. var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\
  6712. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6713. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6714. ctx.lineWidth = line_width;\
  6715. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6716. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6717. var x1,x2,y1,y2;\
  6718. for(var p = 0 ; p < x_points.length ; p++ ){\
  6719.  x1 = x_points[p] - crosshair_size;\
  6720.  x2 = x_points[p] + crosshair_size;\
  6721.  y1 = y_points[p] - crosshair_size;\
  6722.  y2 = y_points[p] + crosshair_size;\
  6723.  ctx.beginPath();\
  6724.  ctx.moveTo(x1,y1);\
  6725.  ctx.lineTo(x2,y2);\
  6726.  ctx.closePath();\
  6727.  ctx.stroke();\
  6728.  ctx.beginPath();\
  6729.  ctx.moveTo(x2,y1);\
  6730.  ctx.lineTo(x1,y2);\
  6731.  ctx.closePath();\
  6732.  ctx.stroke();\
  6733. }\
  6734. ctx.restore();\
  6735.  return;\
  6736. };");
  6737.     break;
  6738.  
  6739.     case DRAW_RECTS:/*  used for userdraw */
  6740. fprintf(js_include_file,"\n<!-- draw rects -->\n\
  6741. var 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_affine,affine_matrix){\
  6742. ctx.save();\
  6743. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6744. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6745. ctx.lineWidth = line_width;\
  6746. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6747. ctx.strokeStyle = 'rgba('+stroke_color+','+stroke_opacity+')';\
  6748. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
  6749. for(var p = 0 ; p < x_points.length ; p = p + 2){\
  6750.  ctx.beginPath();\
  6751.  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
  6752.  ctx.closePath();\
  6753.  if(use_filled == 1 ){ctx.fillStyle = 'rgba('+fill_color+','+fill_opacity+')';ctx.fill();}\
  6754.  ctx.stroke();\
  6755. };\
  6756. ctx.restore();\
  6757. return;\
  6758. };");
  6759.     break;
  6760.  
  6761.     case DRAW_ROUNDRECTS:/*  used for userdraw */
  6762. fprintf(js_include_file,"\n<!-- draw round rects -->\n\
  6763. var 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_affine,affine_matrix){\
  6764. ctx.save();\
  6765. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6766. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  6767. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6768. ctx.lineWidth = line_width;\
  6769. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6770. var x,y,w,h,r;\
  6771. for(var p = 0; p < x_points.length; p = p+2){\
  6772.  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);\
  6773.  ctx.beginPath();ctx.moveTo(x + r, y);\
  6774.  ctx.lineTo(x + w - r, y);\
  6775.  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
  6776.  ctx.lineTo(x + w, y + h - r);\
  6777.  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
  6778.  ctx.lineTo(x + r, y + h);\
  6779.  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
  6780.  ctx.lineTo(x, y + r);\
  6781.  ctx.quadraticCurveTo(x, y, x + r, y);\
  6782.  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
  6783.  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6784.  if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\
  6785.  ctx.stroke();\
  6786. }\
  6787. ctx.restore();\
  6788. };");
  6789.     break;
  6790.  
  6791.     case DRAW_ELLIPSES:/* not  used for userdraw */
  6792. fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
  6793. var 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_affine,affine_matrix){\
  6794. var obj;\
  6795. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6796.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6797. }\
  6798. else\
  6799. {\
  6800.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6801. };\
  6802. var ctx = obj.getContext(\"2d\");\
  6803. ctx.save();\
  6804. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6805. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6806. var cx,cy,ry,rx;\
  6807. ctx.lineWidth = line_width;\
  6808. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6809. if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\
  6810. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  6811. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6812. for(var p=0;p< x_points.length;p = p+2){\
  6813.  ctx.beginPath();\
  6814.  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
  6815.  ctx.translate(cx - rx, cy - ry);\
  6816.  ctx.scale(rx, ry);\
  6817.  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
  6818.  if( use_filled == 1 ){ctx.fill();}\
  6819.  ctx.stroke();\
  6820. };\
  6821. ctx.restore();\
  6822. };",canvas_root_id,canvas_root_id,canvas_root_id);
  6823.     break;
  6824.  
  6825.     case DRAW_PATHS: /*  used for userdraw */
  6826. fprintf(js_include_file,"\n<!-- draw paths -->\n\
  6827. var 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_affine,affine_matrix){\
  6828. ctx.save();\
  6829. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6830. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6831. ctx.lineWidth = line_width;\
  6832. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6833. ctx.lineJoin = \"round\";\
  6834. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6835. ctx.beginPath();\
  6836. ctx.moveTo(x_points[0],y_points[0]);\
  6837. for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
  6838. if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
  6839. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  6840. if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  6841. ctx.stroke();\
  6842. ctx.restore();\
  6843. return;\
  6844. };");
  6845.  
  6846.     break;
  6847.     case DRAW_ARROWS:/*  used for userdraw */
  6848. fprintf(js_include_file,"\n<!-- draw arrows -->\n\
  6849. var 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_affine,affine_matrix){\
  6850. ctx.save();\
  6851. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6852. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6853. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6854. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6855. ctx.lineWidth = line_width;\
  6856. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  6857. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  6858. ctx.lineCap = \"round\";\
  6859. var x1,y1,x2,y2,dx,dy,len;\
  6860. for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
  6861.   ctx.save();\
  6862.   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
  6863.   len = Math.sqrt(dx*dx+dy*dy);\
  6864.   ctx.translate(x2,y2);\
  6865.   ctx.rotate(Math.atan2(dy,dx));\
  6866.   ctx.lineCap = \"round\";\
  6867.   ctx.beginPath();\
  6868.   ctx.moveTo(0,0);\
  6869.   ctx.lineTo(-len,0);\
  6870.   ctx.closePath();\
  6871.   ctx.stroke();\
  6872.   ctx.beginPath();\
  6873.   ctx.moveTo(0,0);\
  6874.   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  6875.   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  6876.   ctx.closePath();\
  6877.   ctx.fill();\
  6878.   ctx.restore();\
  6879.   if( type == 2 ){\
  6880.     ctx.save();\
  6881.     ctx.translate(x1,y1);\
  6882.     ctx.rotate(Math.atan2(-dy,-dx));\
  6883.     ctx.beginPath();\
  6884.     ctx.moveTo(0,0);\
  6885.     ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\
  6886.     ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\
  6887.     ctx.closePath();\
  6888.     ctx.stroke();\
  6889.     ctx.fill();\
  6890.     ctx.restore();\
  6891.   };\
  6892.  };\
  6893.  ctx.restore();\
  6894.  return;\
  6895. };");
  6896.     break;
  6897.  
  6898.     case DRAW_VIDEO:/* not  used for userdraw */
  6899. fprintf(js_include_file,"\n<!-- draw video -->\n\
  6900. var draw_video = function(canvas_root_id,x,y,w,h,URL){\
  6901. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  6902. var video_div = document.createElement(\"div\");\
  6903. canvas_div.appendChild(video_div);\
  6904. video_div.style.position = \"absolute\";\
  6905. video_div.style.left = x+\"px\";\
  6906. video_div.style.top = y+\"px\";\
  6907. video_div.style.width = w+\"px\";\
  6908. video_div.style.height = h+\"px\";\
  6909. var video = document.createElement(\"video\");\
  6910. video_div.appendChild(video);\
  6911. video.style.width = w+\"px\";\
  6912. video.style.height = h+\"px\";\
  6913. video.autobuffer = true;\
  6914. video.controls = true;video.autoplay = false;\
  6915. var src = document.createElement(\"source\");\
  6916. src.type = \"video/mp4\";\
  6917. src.src = URL;\
  6918. video.appendChild(src);\
  6919. video.load();\
  6920. return;\
  6921. };");
  6922.     break;
  6923.  
  6924.     case DRAW_AUDIO:/* not used for userdraw */
  6925. fprintf(js_include_file,"\n<!-- draw audio -->\n\
  6926. var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
  6927. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  6928. var audio_div = document.createElement(\"div\");\
  6929. canvas_div.appendChild(audio_div);\
  6930. audio_div.style.position = \"absolute\";\
  6931. audio_div.style.left = x+\"px\";\
  6932. audio_div.style.top = y+\"px\";\
  6933. audio_div.style.width = w+\"px\";\
  6934. audio_div.style.height = h+\"px\";\
  6935. var audio = document.createElement(\"audio\");\
  6936. audio_div.appendChild(audio);\
  6937. audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
  6938. audio.autobuffer = true;\
  6939. if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;};\
  6940. if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;};\
  6941. var src1 = document.createElement(\"source\");\
  6942. src1.type = \"audio/ogg\";\
  6943. src1.src = URL1;\
  6944. audio.appendChild(src1);\
  6945. var src2 = document.createElement(\"source\");\
  6946. src2.type = \"audio/mpeg\";\
  6947. src2.src = URL2;\
  6948. audio.appendChild(src2);\
  6949. audio.load();\
  6950. return;\
  6951. };");
  6952.     break;
  6953.  
  6954.     case DRAW_HTTP:/* not  used for userdraw */
  6955. fprintf(js_include_file,"\n<!-- draw http -->\n\
  6956. var draw_http = function(canvas_root_id,x,y,w,h,URL){\
  6957. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  6958. var http_div = document.createElement(\"div\");\
  6959. var iframe = document.createElement(\"iframe\");\
  6960. canvas_div.appendChild(http_div);\
  6961. http_div.appendChild(iframe);\
  6962. iframe.src = URL;\
  6963. iframe.setAttribute(\"width\",w);\
  6964. iframe.setAttribute(\"height\",h);\
  6965. return;\
  6966. };");
  6967.     break;
  6968.  
  6969.     case DRAW_XML:
  6970. fprintf(js_include_file,"\n<!-- draw xml -->\n\
  6971. var draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick,click_cnt,stroke_color,stroke_opacity){\
  6972. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  6973. var xml_div = document.createElement(\"div\");\
  6974. canvas_div.appendChild(xml_div);\
  6975. xml_div.innerHTML = mathml;\
  6976. xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6977. if(onclick != 0){\
  6978.  xml_div.onclick = function(){\
  6979.  reply[0] = click_cnt;\
  6980.  };\
  6981.  xml_div.onmouseover = function(){\
  6982.  xml_div.style.color = \"red\";\
  6983.  };\
  6984.  xml_div.onmouseout = function(){\
  6985.  xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6986.  };\
  6987. };\
  6988. xml_div.style.position = \"absolute\";\
  6989. xml_div.style.left = x+\"px\";\
  6990. xml_div.style.top = y+\"px\";\
  6991. xml_div.style.width = w+\"px\";\
  6992. xml_div.style.height = h+\"px\";\
  6993. return;\
  6994. };"
  6995. );
  6996.     break;
  6997.     case DRAW_SGRAPH:
  6998. /*
  6999.  xstart = given
  7000.  ystart = given
  7001.  sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
  7002. */
  7003. fprintf(js_include_file,"\n<!-- draw sgraph -->\n\
  7004. var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
  7005. 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);};\
  7006. var ctx = obj.getContext(\"2d\");\
  7007. ctx.font = fontfamily;\
  7008. var minor_opacity = 0.8*opacity;\
  7009. ctx.clearRect(0,0,xsize,ysize);\
  7010. var zero_x = 0.1*xsize;\
  7011. var zero_y = 0.9*ysize;\
  7012. var snor_x;var snor_y;\
  7013. if( xstart != xmin){\
  7014.  snor_x = 0.1*xsize;\
  7015. }\
  7016. else\
  7017. {\
  7018.  snor_x = 0;\
  7019.  xstart = xmin;\
  7020. };\
  7021. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  7022. ctx.lineWidth = 2;\
  7023. ctx.beginPath();\
  7024. ctx.moveTo(xsize,zero_y);\
  7025. ctx.lineTo(zero_x,zero_y);\
  7026. ctx.lineTo(zero_x,0);\
  7027. ctx.stroke();\
  7028. ctx.closePath();\
  7029. ctx.beginPath();\
  7030. ctx.moveTo(zero_x,zero_y);\
  7031. ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
  7032. ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
  7033. ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
  7034. ctx.lineTo(zero_x + snor_x,zero_y);\
  7035. ctx.stroke();\
  7036. ctx.closePath();\
  7037. ctx.beginPath();\
  7038. var num = xstart;\
  7039. var flipflop = 1;\
  7040. var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
  7041. var txtsize;var txt_marge=step_x - 5;\
  7042. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  7043.  txtsize = ctx.measureText(num).width;\
  7044.  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
  7045.  if( flipflop == 1){\
  7046.   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
  7047.  }\
  7048.  else\
  7049.  {\
  7050.   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
  7051.  };\
  7052.  num = num + xmajor;\
  7053. };\
  7054. ctx.stroke();\
  7055. ctx.closePath();\
  7056. ctx.lineWidth = 1;\
  7057. ctx.beginPath();\
  7058. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  7059.   ctx.moveTo(x,zero_y);\
  7060.   ctx.lineTo(x,0);\
  7061. };\
  7062. ctx.stroke();\
  7063. ctx.closePath();\
  7064. if( xminor > 1){\
  7065.  ctx.lineWidth = 0.5;\
  7066.  ctx.beginPath();\
  7067.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  7068.  var minor_step_x = step_x / xminor;\
  7069.  var nx;\
  7070.  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
  7071.    num = 1;\
  7072.    for(var p = 1 ; p < xminor ; p++){\
  7073.     nx = x + num*minor_step_x;\
  7074.     ctx.moveTo(nx,zero_y);\
  7075.     ctx.lineTo(nx,0);\
  7076.     num++;\
  7077.    };\
  7078.  };\
  7079.  ctx.stroke();\
  7080.  ctx.closePath();\
  7081.  ctx.beginPath();\
  7082.  ctx.lineWidth = 2;\
  7083.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  7084.  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  7085.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
  7086.  };\
  7087.  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
  7088.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
  7089.  };\
  7090.  ctx.stroke();\
  7091.  ctx.closePath();\
  7092.  ctx.lineWidth = 0.5;\
  7093. };\
  7094. xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
  7095. if( ystart != ymin){\
  7096.  snor_y = 0.1*ysize;\
  7097. }\
  7098. else\
  7099. {\
  7100.  snor_y = 0;\
  7101.  ystart = ymin;\
  7102. };\
  7103. ctx.lineWidth = 2;\
  7104. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  7105. ctx.beginPath();\
  7106. ctx.moveTo(zero_x,zero_y);\
  7107. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
  7108. ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
  7109. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
  7110. ctx.lineTo(zero_x,zero_y - snor_y);\
  7111. ctx.stroke();\
  7112. ctx.closePath();\
  7113. ctx.beginPath();\
  7114. ctx.lineWidth = 1;\
  7115. num = ystart;\
  7116. var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
  7117. for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
  7118.  ctx.moveTo(zero_x,y);\
  7119.  ctx.lineTo(xsize,y);\
  7120.  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
  7121.  num = num + ymajor;\
  7122. };\
  7123. ctx.stroke();\
  7124. ctx.closePath();\
  7125. if( yminor > 1){\
  7126.  ctx.lineWidth = 0.5;\
  7127.  ctx.beginPath();\
  7128.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  7129.  var minor_step_y = step_y / yminor;\
  7130.  var ny;\
  7131.  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
  7132.   num = 1;\
  7133.   for(var p = 1 ;p < yminor;p++){\
  7134.     ny = y + num*minor_step_y;\
  7135.     ctx.moveTo(zero_x,ny);\
  7136.     ctx.lineTo(xsize,ny);\
  7137.     num++;\
  7138.    };\
  7139.  };\
  7140.  ctx.stroke();\
  7141.  ctx.closePath();\
  7142.  ctx.lineWidth = 2;\
  7143.  ctx.beginPath();\
  7144.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  7145.  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
  7146.   ctx.moveTo(zero_x,y);\
  7147.   ctx.lineTo(zero_x+12,y);\
  7148.  };\
  7149.  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
  7150.   ctx.moveTo(zero_x,y);\
  7151.   ctx.lineTo(zero_x+6,y);\
  7152.  };\
  7153.  ctx.stroke();\
  7154.  ctx.closePath();\
  7155. };\
  7156. ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
  7157. if( typeof(legend%d)  !== 'undefined' ){\
  7158.  ctx.globalAlpha = 1.0;\
  7159.  var y_offset = 2*font_size;\
  7160.  var txt;var txt_size;\
  7161.  var x_offset = xsize - 2*font_size;\
  7162.  var l_length = legend%d.length;var barcolor = new Array();\
  7163.  if( typeof(legendcolors%d) !== 'undefined' ){\
  7164.   for(var p = 0 ; p < l_length ; p++){\
  7165.    barcolor[p] = legendcolors%d[p];\
  7166.   };\
  7167.  }else{\
  7168.   if( barcolor.length == 0 ){\
  7169.    for(var p = 0 ; p < l_length ; p++){\
  7170.     barcolor[p] = stroke_color;\
  7171.    };\
  7172.   };\
  7173.  };\
  7174.  for(var p = 0; p < l_length; p++){\
  7175.   ctx.fillStyle = barcolor[p];\
  7176.   txt = legend%d[p];\
  7177.   txt_size = ctx.measureText(txt).width;\
  7178.   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
  7179.   y_offset = parseInt(y_offset + 1.5*font_size);\
  7180.  };\
  7181. };\
  7182. if( typeof(xaxislabel) !== 'undefined' ){\
  7183.   ctx.fillStyle = \'#000000\';\
  7184.   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
  7185.   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
  7186. };\
  7187. if( typeof(yaxislabel) !== 'undefined'){\
  7188.   ctx.save();\
  7189.   ctx.fillStyle = \'#000000\';\
  7190.   var txt_size = ctx.measureText(yaxislabel).width;\
  7191.   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
  7192.   ctx.rotate(-0.5*Math.PI);\
  7193.   ctx.fillText(yaxislabel,0,0);\
  7194.   ctx.restore();\
  7195. };\
  7196. };\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);
  7197.     break;
  7198.  
  7199.     case DRAW_GRID:/* not used for userdraw */
  7200. fprintf(js_include_file,"\n<!-- draw grid -->\n\
  7201. var 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_affine,affine_matrix,use_dashed,dashtype0,dashtype1,font_color,fill_opacity){\
  7202. 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);};\
  7203. var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
  7204. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7205. ctx.save();\
  7206. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  7207. if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
  7208. var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7209. ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
  7210. var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
  7211. ctx.font = font_family;\
  7212. var barcolor = new Array();\
  7213. var xstep = xsize*xmajor/(xmax - xmin);\
  7214. var ystep = ysize*ymajor/(ymax - ymin);\
  7215. var x2step = xstep / xminor;\
  7216. var y2step = ystep / yminor;\
  7217. var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
  7218. if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
  7219. if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
  7220. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7221. ctx.beginPath();\
  7222. ctx.lineWidth = line_width;\
  7223. ctx.strokeStyle = stroke_color;\
  7224. for(var p = zero_x ; p < xsize; p = p + xstep){\
  7225. ctx.moveTo(p,0);\
  7226. ctx.lineTo(p,ysize);\
  7227. };\
  7228. for(var p = zero_x ; p > 0; p = p - xstep){\
  7229. ctx.moveTo(p,0);\
  7230. ctx.lineTo(p,ysize);\
  7231. };\
  7232. for(var p = zero_y ; p < ysize; p = p + ystep){\
  7233. ctx.moveTo(0,p);\
  7234. ctx.lineTo(xsize,p);\
  7235. };\
  7236. for(var p = zero_y ; p > 0; p = p - ystep){\
  7237. ctx.moveTo(0,p);\
  7238. ctx.lineTo(xsize,p);\
  7239. };\
  7240. if( typeof(xaxislabel) !== 'undefined' ){\
  7241. ctx.save();\
  7242. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  7243. var corr =  ctx.measureText(xaxislabel).width;\
  7244. ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\
  7245. ctx.restore();\
  7246. };\
  7247. if( typeof(yaxislabel) !== 'undefined' ){\
  7248. ctx.save();\
  7249. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  7250. var corr =  ctx.measureText(yaxislabel).width;\
  7251. ctx.translate(zero_x+tics_length + font_size,corr+font_size);\
  7252. ctx.rotate(-0.5*Math.PI);\
  7253. ctx.fillText(yaxislabel,0,0);\
  7254. ctx.restore();\
  7255. };\
  7256. ctx.stroke();\
  7257. ctx.closePath();\
  7258. if( use_axis == 1 ){\
  7259. ctx.save();\
  7260. ctx.beginPath();\
  7261. ctx.strokeStyle = stroke_color;\
  7262. ctx.lineWidth = 0.6*line_width;\
  7263. for(var p = zero_x ; p < xsize; p = p + x2step){\
  7264.  ctx.moveTo(p,0);\
  7265.  ctx.lineTo(p,ysize);\
  7266. };\
  7267. for(var p = zero_x ; p > 0; p = p - x2step){\
  7268.  ctx.moveTo(p,0);\
  7269.  ctx.lineTo(p,ysize);\
  7270. };\
  7271. for(var p = zero_y ; p < ysize; p = p + y2step){\
  7272.  ctx.moveTo(0,p);\
  7273.  ctx.lineTo(xsize,p);\
  7274. };\
  7275. for(var p = zero_y ; p > 0; p = p - y2step){\
  7276.  ctx.moveTo(0,p);\
  7277.  ctx.lineTo(xsize,p);\
  7278. };\
  7279. ctx.stroke();\
  7280. ctx.closePath();\
  7281. ctx.beginPath();\
  7282. ctx.lineWidth = 2*line_width;\
  7283. ctx.strokeStyle = axis_color;\
  7284. ctx.moveTo(0,zero_y);\
  7285. ctx.lineTo(xsize,zero_y);\
  7286. ctx.moveTo(zero_x,0);\
  7287. ctx.lineTo(zero_x,ysize);\
  7288. ctx.stroke();\
  7289. ctx.closePath();\
  7290. ctx.lineWidth = line_width+0.5;\
  7291. ctx.beginPath();\
  7292. for(var p = zero_x ; p < xsize; p = p + xstep){\
  7293.  ctx.moveTo(p,zero_y-tics_length);\
  7294.  ctx.lineTo(p,zero_y+tics_length);\
  7295. };\
  7296. for(var p = zero_x ; p > 0; p = p - xstep){\
  7297.  ctx.moveTo(p,zero_y-tics_length);\
  7298.  ctx.lineTo(p,zero_y+tics_length);\
  7299. };\
  7300. for(var p = zero_y ; p < ysize; p = p + ystep){\
  7301.  ctx.moveTo(zero_x-tics_length,p);\
  7302.  ctx.lineTo(zero_x+tics_length,p);\
  7303. };\
  7304. for(var p = zero_y ; p > 0; p = p - ystep){\
  7305.  ctx.moveTo(zero_x-tics_length,p);\
  7306.  ctx.lineTo(zero_x+tics_length,p);\
  7307. };\
  7308. for(var p = zero_x ; p < xsize; p = p + x2step){\
  7309.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  7310.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  7311. };\
  7312. for(var p = zero_x ; p > 0; p = p - x2step){\
  7313.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  7314.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  7315. };\
  7316. for(var p = zero_y ; p < ysize; p = p + y2step){\
  7317.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  7318.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  7319. };\
  7320. for(var p = zero_y ; p > 0; p = p - y2step){\
  7321.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  7322.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  7323. };\
  7324. ctx.stroke();\
  7325. ctx.closePath();\
  7326. ctx.restore();\
  7327. };\
  7328. if( use_axis_numbering == 1 ){\
  7329. ctx.save();\
  7330. ctx.fillColor = axis_color;\
  7331. ctx.strokeStyle = axis_color;\
  7332. ctx.lineWidth = 2*line_width;\
  7333. ctx.font = font_family;\
  7334. var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
  7335. if( x_strings != null ){\
  7336.  var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  7337.  ctx.beginPath();\
  7338.  if( x_strings_up == null){\
  7339.   for(var p = 0 ; p < len ; p = p+2){\
  7340.    var x_nums = x2px(eval(x_strings[p]));\
  7341.    var x_text = x_strings[p+1];\
  7342.    corr = ctx.measureText(x_text).width;\
  7343.    skip = 1.2*corr/xstep;\
  7344.    if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
  7345.    if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
  7346.    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
  7347.    ctx.moveTo(x_nums,zero_y - tics_length);\
  7348.    ctx.lineTo(x_nums,zero_y + tics_length);\
  7349.   };\
  7350.  }\
  7351.  else\
  7352.  {\
  7353.   for(var p = 0 ; p < len ; p = p+2){\
  7354.    var x_nums = x2px(eval(x_strings[p]));\
  7355.    var x_text = x_strings[p+1];\
  7356.    corr = 2 + tics_length + zero_y + ctx.measureText(x_text).width;\
  7357.    if( corr > ysize ){corr = ysize;};\
  7358.    ctx.save();\
  7359.    ctx.translate(x_nums+0.25*font_size, corr);\
  7360.    ctx.rotate(-1.5708);\
  7361.    ctx.fillText(x_text,0,0);\
  7362.    ctx.restore();\
  7363.    ctx.moveTo(x_nums,zero_y - tics_length);\
  7364.    ctx.lineTo(x_nums,zero_y + tics_length);\
  7365.   };\
  7366.  };\
  7367.  ctx.closePath();\
  7368. }\
  7369. else\
  7370. {\
  7371.  skip = 1;cnt = px2x(zero_x);\
  7372.  prec = Math.log(precision)/(Math.log(10));\
  7373.  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
  7374.  for( var p = zero_x ; p < xsize ; p = p+xstep){\
  7375.   if(skip == 0 ){\
  7376.    disp_cnt = cnt.toFixed(prec);\
  7377.    corr = ctx.measureText(disp_cnt).width;\
  7378.    skip = parseInt(1.2*corr/xstep);\
  7379.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  7380.   }\
  7381.   else\
  7382.   {\
  7383.    skip--;\
  7384.   };\
  7385.   cnt = cnt + xmajor;\
  7386.  };\
  7387.  cnt = px2x(zero_x);skip = 1;\
  7388.  for( var p = zero_x ; p > 0 ; p = p-xstep){\
  7389.   if(skip == 0 ){\
  7390.    disp_cnt = cnt.toFixed(prec);\
  7391.    corr = ctx.measureText(disp_cnt).width;\
  7392.    skip = parseInt(1.2*corr/xstep);\
  7393.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  7394.   }\
  7395.   else\
  7396.   {\
  7397.    skip--;\
  7398.   };\
  7399.   cnt = cnt - xmajor;\
  7400.  };\
  7401. };\
  7402. if( y_strings != null ){\
  7403.  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
  7404.  ctx.beginPath();\
  7405.  for(var p = 0 ; p < len ; p = p+2){\
  7406.   var y_nums = y2px(eval(y_strings[p]));\
  7407.   var y_text = y_strings[p+1];\
  7408.   corr = 2 + tics_length + ctx.measureText(y_text).width;\
  7409.   if( corr > zero_x){corr = parseInt(zero_x+2); }\
  7410.   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
  7411.   ctx.moveTo(zero_x - tics_length,y_nums);\
  7412.   ctx.lineTo(zero_x + tics_length,y_nums);\
  7413.  };\
  7414.  ctx.closePath();\
  7415. }\
  7416. else\
  7417. {\
  7418.  if(f_x == 1){ corr = 1.5*tics_length; }\
  7419.  cnt = px2y(zero_y);skip = 1;\
  7420.  for( var p = zero_y ; p < ysize ; p = p+ystep){\
  7421.   if(skip == 0 ){\
  7422.    skip = parseInt(1.4*font_size/ystep);\
  7423.    disp_cnt = cnt.toFixed(prec);\
  7424.    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  7425.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  7426.   }\
  7427.   else\
  7428.   {\
  7429.    skip--;\
  7430.   };\
  7431.   cnt = cnt - ymajor;\
  7432.  };\
  7433.  corr = 0;cnt = px2y(zero_y);skip = 1;\
  7434.  if(f_x == 1){ corr = 1.5*tics_length; }\
  7435.  for( var p = zero_y ; p > 0 ; p = p-ystep){\
  7436.   if(skip == 0 ){\
  7437.    skip = parseInt(1.4*font_size/ystep);\
  7438.    disp_cnt = cnt.toFixed(prec);\
  7439.    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  7440.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  7441.   }\
  7442.   else\
  7443.   {\
  7444.    skip--;\
  7445.   };\
  7446.   cnt = cnt + ymajor;\
  7447.  };\
  7448. };\
  7449. ctx.stroke();\
  7450. ctx.restore();\
  7451. };\
  7452. if( typeof(legend0)  !== 'undefined' ){\
  7453. ctx.save();\
  7454. ctx.globalAlpha = 1.0;\
  7455. ctx.font = \"bold \"+font_size+\"px Ariel\";\
  7456. var y_offset = 2*font_size;\
  7457. var txt;var txt_size;\
  7458. var x_offset = xsize - 2*font_size;\
  7459. var l_length = legend0.length;\
  7460. if( typeof(legendcolors0) !== 'undefined' ){\
  7461.  for(var p = 0 ; p < l_length ; p++){\
  7462.    barcolor[p] = legendcolors0[p];\
  7463.  };\
  7464. }\
  7465. else\
  7466. {\
  7467.  if( barcolor.length == 0 ){\
  7468.   for(var p = 0 ; p < l_length ; p++){\
  7469.    barcolor[p] = stroke_color;\
  7470.   };\
  7471.  };\
  7472. };\
  7473. for(var p = 0; p < l_length; p++){\
  7474.  ctx.fillStyle = barcolor[p];\
  7475.  txt = legend0[p];\
  7476.  txt_size = ctx.measureText(txt).width;\
  7477.  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
  7478.  y_offset = parseInt(y_offset + 1.5*font_size);\
  7479. };\
  7480. ctx.restore();\
  7481. };\
  7482. if( typeof(barchart_0)  !== 'undefined' ){\
  7483. ctx.save();\
  7484. var num_barcharts = 0;\
  7485. var bar_name = eval('barchart_0');\
  7486. while( typeof(bar_name) !== 'undefined' ){\
  7487.    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
  7488. };\
  7489. var bar_width = parseInt(0.8*x2step/(num_barcharts));\
  7490. for(var i=0 ; i< num_barcharts ; i++){\
  7491.  bar_name = eval('barchart_'+i);\
  7492.  var bar_x = new Array();\
  7493.  var bar_y = new Array();\
  7494.  var lb = bar_name.length;\
  7495.  var idx = 0;\
  7496.  var dx = parseInt(0.5*i*bar_width);\
  7497.  for( var p = 0 ; p < lb ; p = p + 3 ){\
  7498.   bar_x[idx] = x2px(bar_name[p]);\
  7499.   bar_y[idx] = y2px(bar_name[p+1]);\
  7500.   barcolor[idx] = bar_name[p+2];\
  7501.   idx++;\
  7502.  };\
  7503.  ctx.globalAlpha = fill_opacity;\
  7504.  ctx.beginPath();\
  7505.  for( var p = 0; p < idx ; p++ ){\
  7506.   ctx.strokeStyle = barcolor[p];\
  7507.   ctx.fillStyle = barcolor[p];\
  7508.   ctx.rect(bar_x[p]-0.4*x2step+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
  7509.  };\
  7510.  ctx.fill();\
  7511.  ctx.stroke();\
  7512.  ctx.closePath();\
  7513. };\
  7514. ctx.restore();\
  7515. };\
  7516. if( typeof(linegraph_0) !== 'undefined' ){\
  7517. ctx.save();\
  7518. ctx.globalAlpha = 1.0;\
  7519. var i = 0;\
  7520. var line_name = eval('linegraph_'+i);\
  7521. while ( typeof(line_name) !== 'undefined' ){\
  7522.  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
  7523.  ctx.lineWidth = parseInt(line_name[1]);\
  7524.  if(line_name[2] == \"1\"){\
  7525.   var d1 = parseInt(line_name[3]);\
  7526.   var d2 = parseInt(line_name[4]);\
  7527.   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
  7528.  }\
  7529.  else\
  7530.  {\
  7531.  if(ctx.setLineDash){ctx.setLineDash = null;}\
  7532.  if(ctx.mozDash){ctx.mozDash = null;}\
  7533.  };\
  7534.  var data_x = new Array();\
  7535.  var data_y = new Array();\
  7536.  var lb = line_name.length;\
  7537.  var idx = 0;\
  7538.  for( var p = 5 ; p < lb ; p = p + 2 ){\
  7539.   data_x[idx] = x2px(line_name[p]);\
  7540.   data_y[idx] = y2px(line_name[p+1]);\
  7541.   idx++;\
  7542.  };\
  7543.  for( var p = 0; p < idx ; p++){\
  7544.   ctx.beginPath();\
  7545.   ctx.moveTo(data_x[p],data_y[p]);\
  7546.   ctx.lineTo(data_x[p+1],data_y[p+1]);\
  7547.   ctx.stroke();\
  7548.   ctx.closePath();\
  7549.  };\
  7550.  i++;\
  7551.  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
  7552. };\
  7553. ctx.restore();\
  7554. };\
  7555. return;\
  7556. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  7557.     break;
  7558.  
  7559.     case DRAW_PIECHART:
  7560. fprintf(js_include_file,"\n<!-- draw piecharts -->\n\
  7561. function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family){\
  7562. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  7563.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  7564. }\
  7565. else\
  7566. {\
  7567.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  7568. };\
  7569. var ld = data_color_list.length;\
  7570. var sum = 0;\
  7571. var idx = 0;\
  7572. var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
  7573. var colors = new Array();\
  7574. var data = new Array();\
  7575. for(var p = 0;p < ld; p = p + 2){\
  7576.  data[idx] = parseFloat(data_color_list[p]);\
  7577.  sum = sum + data[idx];\
  7578.  colors[idx] = data_color_list[p+1];\
  7579.  idx++;\
  7580. };\
  7581. var ctx = obj.getContext(\"2d\");\
  7582. ctx.save();\
  7583. var angle;\
  7584. var angle_end = 0;\
  7585. var offset = Math.PI / 2;\
  7586. ctx.globalAlpha = fill_opacity;\
  7587. for(var p=0; p < idx; p++){\
  7588.  ctx.beginPath();\
  7589.  ctx.fillStyle = colors[p];\
  7590.  ctx.moveTo(x_center,y_center);\
  7591.  angle = Math.PI * (2 * data[p] / sum);\
  7592.  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
  7593.  ctx.lineTo(x_center, y_center);\
  7594.  ctx.fill();\
  7595.  ctx.closePath();\
  7596.  angle_end  = angle_end + angle;\
  7597. };\
  7598. if(typeof(legend0) !== 'undefined'){\
  7599.  var legenda = eval(\"legend\"+legend_cnt);\
  7600.  ctx.globalAlpha = 1.0;\
  7601.  ctx.font = font_family;\
  7602.  var y_offset = font_size; \
  7603.  var x_offset = 0;\
  7604.  var txt;var txt_size;\
  7605.  for(var p = 0; p < idx; p++){\
  7606.   ctx.fillStyle = colors[p];\
  7607.   txt = legenda[p];\
  7608.   txt_size = ctx.measureText(txt).width;\
  7609.   if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
  7610.   ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
  7611.   y_offset = parseInt(y_offset + 1.5*font_size);\
  7612.  };\
  7613. };\
  7614. ctx.restore();\
  7615. };",canvas_root_id,canvas_root_id,canvas_root_id);
  7616.  
  7617.     break;
  7618.     case DRAW_JSBOXPLOT:
  7619. fprintf(js_include_file,"\n<!-- draw jsboxplots -->\n\
  7620. function statistics(data){\
  7621. var len = data.length;\
  7622. var min = 10000000;\
  7623. var max = -10000000;\
  7624. var sum = 0;var d;\
  7625. for(var i=0;i<len;i++){\
  7626.  d = data[i];\
  7627.  if(d < min){min = d;}else{if(d > max){max = d;};};\
  7628.  sum+= parseFloat(data[i]);\
  7629. };\
  7630. var mean = parseFloat(sum/len);\
  7631. var variance = 0;\
  7632. for(var i=0;i<len;i++){\
  7633.  d = data[i];\
  7634.  variance += (d - mean)*(d - mean);\
  7635. };\
  7636. variance = parseFloat(variance / len);\
  7637. var std = Math.sqrt(variance);\
  7638. data.sort(function(a,b){return a - b;});\
  7639. var median;var Q1;var Q3;\
  7640. var half = Math.floor(0.5*len);\
  7641. var q1 = Math.floor(0.25*len);\
  7642. var q3 = Math.floor(0.75*len);\
  7643. var half = Math.floor(0.5*len);\
  7644. if(len %%2 == 1){\
  7645.  median = data[half];\
  7646.  Q1 = data[q1];\
  7647.  Q3 = data[q3];\
  7648. }\
  7649. else\
  7650. {\
  7651.  median = (data[half - 1] + data[half] )/2;\
  7652.  Q1 = (data[q1 - 1] + data[q1] )/2;\
  7653.  Q3 = (data[q3 - 1] + data[q3] )/2;\
  7654. };\
  7655. return [min,Q1,median,Q3,max];\
  7656. };");
  7657.     break;
  7658.     case DRAW_BOXPLOT:
  7659. fprintf(js_include_file,"\n<!-- draw boxplots -->\n\
  7660. draw_boxplot = function(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1){\
  7661. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  7662.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  7663. }\
  7664. else\
  7665. {\
  7666.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  7667. };\
  7668. var ctx = obj.getContext(\"2d\");\
  7669. ctx.clearRect(0,0,xsize,ysize);\
  7670. ctx.save();\
  7671. ctx.lineWidth = line_width;\
  7672. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7673. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7674. ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7675. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  7676. var hh = 0.25*hw;\
  7677. switch(boxplot_source){\
  7678.  case 1: if( typeof(jsboxplot_data) === 'undefined'){return;};data = statistics(jsboxplot_data);break;\
  7679.  case 2: if( typeof(student_boxplot_data) === 'undefined'){return;};data = statistics(student_boxplot_data);break;\
  7680.  case 3: if( typeof(student_boxplot) === 'undefined'){return;};data = student_boxplot;break;\
  7681.  default: break;\
  7682. };\
  7683. var min,Q1,median,Q3,max;\
  7684. if(xy == 1 ){\
  7685.  min=x2px(data[0]);Q1=x2px(data[1]);median=x2px(data[2]);Q3=x2px(data[3]);max=x2px(data[4]);\
  7686.  hh = Math.abs(y2px(hh) - y2px(ystart));\
  7687.  hw = Math.abs(y2px(hw) - y2px(ystart));\
  7688.  cxy = y2px(cxy);\
  7689.  ctx.beginPath();\
  7690.  ctx.moveTo(min,cxy);\
  7691.  ctx.lineTo(Q1,cxy);\
  7692.  ctx.moveTo(Q3,cxy);\
  7693.  ctx.lineTo(max,cxy);\
  7694.  ctx.moveTo(min,cxy+hh);\
  7695.  ctx.lineTo(min,cxy-hh);\
  7696.  ctx.moveTo(max,cxy+hh);\
  7697.  ctx.lineTo(max,cxy-hh);\
  7698.  ctx.closePath();\
  7699.  ctx.stroke();\
  7700.  ctx.beginPath();\
  7701.  ctx.rect(Q1,cxy-2*hh,median-Q1,hw);\
  7702.  ctx.closePath();\
  7703.  if( use_filled == 1 ){\
  7704.   ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+fill_opacity+\")\";\
  7705.   ctx.fill();\
  7706.  };\
  7707.  ctx.stroke();\
  7708.  ctx.beginPath();\
  7709.  ctx.rect(median,cxy-2*hh,Q3-median,hw);\
  7710.  ctx.closePath();\
  7711.  if( use_filled == 1 ){\
  7712.   ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7713.   ctx.fill();\
  7714.  };\
  7715.  ctx.stroke();\
  7716. }else{\
  7717.  min=y2px(data[0]);Q1=y2px(data[1]);median=y2px(data[2]);Q3=y2px(data[3]);max=y2px(data[4]);\
  7718.  hh = Math.abs(x2px(hh) - x2px(xstart));\
  7719.  hw = Math.abs(x2px(hw) - x2px(xstart));\
  7720.  cxy = x2px(cxy);\
  7721.  ctx.beginPath();\
  7722.  ctx.moveTo(cxy,min);\
  7723.  ctx.lineTo(cxy,Q1);\
  7724.  ctx.moveTo(cxy,Q3);\
  7725.  ctx.lineTo(cxy,max);\
  7726.  ctx.moveTo(cxy + hh,min);\
  7727.  ctx.lineTo(cxy - hh,min);\
  7728.  ctx.moveTo(cxy + hh,max);\
  7729.  ctx.lineTo(cxy - hh,max);\
  7730.  ctx.closePath;\
  7731.  ctx.stroke();\
  7732.  ctx.beginPath();\
  7733.  ctx.rect(cxy - 2*hh,Q1,hw,median - Q1);\
  7734.  ctx.closePath();\
  7735.  if( use_filled == 1 ){\
  7736.   ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+fill_opacity+\")\";\
  7737.   ctx.fill();\
  7738.  };\
  7739.  ctx.stroke();\
  7740.  ctx.beginPath();\
  7741.  ctx.rect(cxy - 2*hh,median,hw,Q3 - median);\
  7742.  ctx.closePath();\
  7743.  if( use_filled == 1 ){\
  7744.   ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7745.   ctx.fill();\
  7746.  };\
  7747.  ctx.stroke();\
  7748. };\
  7749. ctx.restore();};",canvas_root_id,canvas_root_id,canvas_root_id);
  7750.     break;
  7751.     case DRAW_ARCS:
  7752. fprintf(js_include_file,"\n<!-- draw arcs -->\n\
  7753. var draw_arc = function(ctx,xc,yc,r,start,end,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
  7754. ctx.save();\
  7755. if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  7756. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  7757. if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  7758. if(end < start){var tmp = end;end = start;start=tmp;};\
  7759. start = 360 - start;\
  7760. end = 360 - end;\
  7761. ctx.lineWidth = line_width;\
  7762. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7763. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7764. ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7765. ctx.beginPath();\
  7766. ctx.moveTo(xc,yc);\
  7767. ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  7768. ctx.lineTo(xc,yc);\
  7769. ctx.closePath();\
  7770. if( use_filled == 1 ){\
  7771.  ctx.fill();\
  7772. };\
  7773. ctx.stroke();\
  7774. ctx.restore();\
  7775. };");
  7776.  
  7777.     break;
  7778.     case DRAW_CENTERSTRING:
  7779. fprintf(js_include_file,"\n<!-- draw centerstring -->\n\
  7780. var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
  7781. var obj;\
  7782. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  7783.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  7784. }\
  7785. else\
  7786. {\
  7787.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  7788. };\
  7789. var ctx = obj.getContext(\"2d\");\
  7790. ctx.save();\
  7791. ctx.clearRect(0,0,xsize,ysize);\
  7792. ctx.font = font_family;\
  7793. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7794. var stringwidth = ctx.measureText(text).width;\
  7795. var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
  7796. ctx.fillText(text,x,y2px(y));\
  7797. ctx.restore();\
  7798. return;\
  7799. };",canvas_root_id,canvas_root_id,canvas_root_id);
  7800.     break;
  7801.     case DRAW_TEXTS:
  7802. fprintf(js_include_file,"\n<!-- draw text -->\n\
  7803. var draw_text = function(canvas_type,x,y,font_size,font_family,stroke_color,stroke_opacity,angle2,text,use_rotate,angle,use_affine,affine_matrix){\
  7804.  var obj;\
  7805.  if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  7806.   obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  7807.  }\
  7808.  else\
  7809.  {\
  7810.   obj = create_canvas%d(canvas_type,xsize,ysize);\
  7811.  };\
  7812.  var ctx = obj.getContext(\"2d\");\
  7813.  if( font_family != 'null' ){\
  7814.   ctx.font = font_family;\
  7815.  }\
  7816.  else\
  7817.  {\
  7818.   ctx.font = font_size+'px Ariel';\
  7819.  };\
  7820.  if(angle2 == 0 && angle != 0){\
  7821.   ctx.save();\
  7822.   if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7823.   if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7824.  };\
  7825.  ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7826.  if(angle2 != 0){\
  7827.   ctx.save();\
  7828.   ctx.translate(x,y);\
  7829.   ctx.rotate((360-angle2)*(Math.PI / 180));\
  7830.   ctx.fillText(text,0,0);\
  7831.   ctx.restore();\
  7832.  }else{ctx.fillText(text,x,y);};\
  7833. ctx.restore();\
  7834. return;\
  7835. };",canvas_root_id,canvas_root_id,canvas_root_id);
  7836.     break;
  7837.     case DRAW_CURVE:
  7838. fprintf(js_include_file,"\n<!-- draw curve -->\n\
  7839. var draw_curve = function(canvas_type,type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\
  7840. var obj;\
  7841. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  7842.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  7843. }\
  7844. else\
  7845. {\
  7846.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  7847. };\
  7848. var ctx = obj.getContext(\"2d\");\
  7849. ctx.save();\
  7850. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7851. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7852. ctx.beginPath();ctx.lineWidth = line_width;\
  7853. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7854. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7855. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7856. ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
  7857. for(var p = 1 ; p < x_points.length ; p++){\
  7858.  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
  7859.  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
  7860.  }\
  7861.  else\
  7862.  {\
  7863.   ctx.stroke();\
  7864.   ctx.beginPath();\
  7865.   p++;\
  7866.   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
  7867.  };\
  7868. };\
  7869. ctx.stroke();\
  7870. ctx.restore();\
  7871. };",canvas_root_id,canvas_root_id,canvas_root_id);
  7872.     break;
  7873.  
  7874.     case DRAW_INPUTS:
  7875. fprintf(js_include_file,"\n<!-- draw input fields -->\n\
  7876. var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\
  7877. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  7878. var input = document.createElement(\"input\");\
  7879. input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  7880. input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  7881. input.setAttribute(\"size\",size);\
  7882. input.setAttribute(\"value\",value);\
  7883. if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
  7884. canvas_div.appendChild(input);};");
  7885.     break;
  7886.  
  7887.     case DRAW_TEXTAREAS:
  7888. fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
  7889. var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
  7890. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  7891. var textarea = document.createElement(\"textarea\");\
  7892. textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  7893. textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  7894. textarea.setAttribute(\"cols\",cols);\
  7895. textarea.setAttribute(\"rows\",rows);\
  7896. textarea.value = value;\
  7897. if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
  7898. canvas_div.appendChild(textarea);};");
  7899.     break;
  7900.  
  7901. case DRAW_PIXELS:
  7902. fprintf(js_include_file,"\n<!-- draw pixel -->\n\
  7903. var draw_setpixel = function(x,y,color,opacity,pixelsize){\
  7904. var canvas = create_canvas%d(10,xsize,ysize);\
  7905. var d = 0.5*pixelsize;\
  7906. var ctx = canvas.getContext(\"2d\");\
  7907. if(pixelsize%%2 == 1){ ctx.translate(0.5,0.5);};\
  7908. ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
  7909. ctx.clearRect(0,0,xsize,ysize);\
  7910. for(var p=0; p<x.length;p++){\
  7911.  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
  7912. };\
  7913. ctx.fill();ctx.stroke();\
  7914. };",canvas_root_id);
  7915. break;
  7916.  
  7917. case DRAW_CLOCK:
  7918. fprintf(js_include_file,"\n<!-- begin command clock -->\n\
  7919. var clock_canvas = create_canvas%d(%d,xsize,ysize);\
  7920. var clock_ctx = clock_canvas.getContext(\"2d\");\
  7921. var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
  7922. clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\
  7923. clock_ctx.save();\
  7924. clock_ctx.globalAlpha = clock_bg_opacity;\
  7925. this.type = type || 0;\
  7926. this.interaction = interaction || 0;\
  7927. this.H = H;\
  7928. this.M = M;\
  7929. this.S = S;\
  7930. this.xc = xc || xsize/2;\
  7931. this.yc = yc || ysize/2;\
  7932. this.radius = radius || xsize/4;\
  7933. var font_size = parseInt(0.2*this.radius);\
  7934. this.H_color = h_color || \"blue\";\
  7935. this.M_color = m_color || \"blue\";\
  7936. this.S_color = s_color || \"blue\";\
  7937. this.fg_color = fg_color || \"red\";\
  7938. this.bg_color = bg_color || \"white\";\
  7939. clock_ctx.translate(this.xc,this.yc);\
  7940. clock_ctx.beginPath();\
  7941. clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
  7942. clock_ctx.fillStyle = this.bg_color;\
  7943. clock_ctx.fill();\
  7944. clock_ctx.closePath();\
  7945. clock_ctx.beginPath();\
  7946. clock_ctx.font = font_size+\"px Arial\";\
  7947. clock_ctx.fillStyle = this.fg_color;\
  7948. clock_ctx.textAlign = \"center\";\
  7949. clock_ctx.textBaseline = 'middle';\
  7950. var angle;var x1,y1,x2,y2;\
  7951. var angle_cos;var angle_sin;\
  7952. clock_ctx.globalAlpha = clock_fg_opacity;\
  7953. switch(type){\
  7954. case 0:clock_ctx.beginPath();\
  7955. for(var p = 1; p <= 12 ; p++){\
  7956.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  7957.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  7958.  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  7959.  clock_ctx.moveTo(x1,y1);\
  7960.  clock_ctx.lineTo(x2,y2);\
  7961. };\
  7962. for(var p = 1; p <= 60 ; p++){\
  7963.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  7964.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  7965.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  7966.  clock_ctx.moveTo(x1,y1);\
  7967.  clock_ctx.lineTo(x2,y2);\
  7968. };\
  7969. clock_ctx.closePath();\
  7970. clock_ctx.stroke();\
  7971. break;\
  7972. case 1:\
  7973. 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;\
  7974. case 2:\
  7975. for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 0.8*this.radius*Math.cos(angle);y1 = 0.8*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};\
  7976. clock_ctx.beginPath();\
  7977. for(var p = 1; p <= 12 ; p++){\
  7978.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  7979.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  7980.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  7981.  clock_ctx.moveTo(x1,y1);\
  7982.  clock_ctx.lineTo(x2,y2);\
  7983. };\
  7984. for(var p = 1; p <= 60 ; p++){\
  7985.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  7986.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  7987.  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  7988.  clock_ctx.moveTo(x1,y1);\
  7989.  clock_ctx.lineTo(x2,y2);\
  7990. };\
  7991. clock_ctx.closePath();\
  7992. clock_ctx.stroke();\
  7993. break;\
  7994. };\
  7995. angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
  7996. clock_ctx.rotate(angle);\
  7997. clock_ctx.beginPath();\
  7998. clock_ctx.moveTo(-3, -2);\
  7999. clock_ctx.lineTo(-3, 2);\
  8000. clock_ctx.lineTo(this.radius * 0.6, 1);\
  8001. clock_ctx.lineTo(this.radius  * 0.6, -1);\
  8002. clock_ctx.fillStyle = this.H_color;\
  8003. clock_ctx.fill();\
  8004. clock_ctx.rotate(-angle);\
  8005. angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
  8006. clock_ctx.rotate(angle);\
  8007. clock_ctx.beginPath();\
  8008. clock_ctx.moveTo(-3, -2);\
  8009. clock_ctx.lineTo(-3, 2);\
  8010. clock_ctx.lineTo(this.radius  * 0.8, 1);\
  8011. clock_ctx.lineTo(this.radius  * 0.8, -1);\
  8012. clock_ctx.fillStyle = this.M_color;\
  8013. clock_ctx.fill();\
  8014. clock_ctx.rotate(-angle);\
  8015. angle = (this.S - 15) * 2 * Math.PI / 60;\
  8016. clock_ctx.rotate(angle);\
  8017. clock_ctx.beginPath();\
  8018. clock_ctx.moveTo(0,0);\
  8019. clock_ctx.lineTo(this.radius  * 0.9, 1);\
  8020. clock_ctx.lineTo(this.radius  * 0.9, -1);\
  8021. clock_ctx.strokeStyle = this.S_color;\
  8022. clock_ctx.stroke();\
  8023. clock_ctx.restore();\
  8024. };",canvas_root_id,CLOCK_CANVAS);
  8025. break;
  8026.  
  8027. case DRAW_LATTICE:
  8028. fprintf(js_include_file,"\n<!-- draw lattice -->\n\
  8029. var 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_affine,affine_matrix){\
  8030. var obj;\
  8031. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8032.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8033. }\
  8034. else\
  8035. {\
  8036.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8037. };\
  8038. var ctx = obj.getContext(\"2d\");\
  8039. ctx.save();\
  8040. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  8041. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  8042. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8043. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8044. var radius = line_width;\
  8045. var x = 0;\
  8046. var y = 0;\
  8047. var x_step_px = xsize/(xmax-xmin);\
  8048. var y_step_px = ysize/(ymax-ymin);\
  8049. var xv1 = dx1*x_step_px;\
  8050. var yv1 = dy1*y_step_px;\
  8051. var xv2 = dx2*x_step_px;\
  8052. var yv2 = dy2*y_step_px;\
  8053. for(var p = 0; p < n1 ;p++){\
  8054.  x = p*xv1 + x0;\
  8055.  y = p*yv1 + y0;\
  8056.  for(var c = 0; c < n2 ; c++){\
  8057.   ctx.beginPath();\
  8058.   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
  8059.   ctx.fill();\
  8060.   ctx.stroke();\
  8061.   ctx.closePath();\
  8062.  };\
  8063. };\
  8064. ctx.restore();\
  8065. return;\
  8066. };",canvas_root_id,canvas_root_id,canvas_root_id);
  8067.     break;
  8068. case DRAW_XYLOGSCALE:
  8069. fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\
  8070. var 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){\
  8071. var obj;\
  8072. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8073.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8074. }\
  8075. else\
  8076. {\
  8077.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8078. };\
  8079. var ctx = obj.getContext(\"2d\");\
  8080. ctx.clearRect(0,0,xsize,ysize);\
  8081. ctx.save();\
  8082. var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
  8083. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  8084. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  8085. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  8086. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  8087. if(use_axis_numbering == 1){\
  8088.  ctx.font = font_family;\
  8089.  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
  8090.  ymarge = parseInt(1.5*font_size);\
  8091.  ctx.save();\
  8092.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  8093.  ctx.rect(0,0,xmarge,ysize);\
  8094.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  8095.  ctx.fill();\
  8096.  ctx.restore();\
  8097. }else{xmarge = 0;ymarge = 0;};\
  8098. if( typeof(xaxislabel) !== 'undefined' ){\
  8099.  ctx.save();\
  8100.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  8101.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  8102.  corr =  ctx.measureText(xaxislabel).width;\
  8103.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  8104.  ctx.restore();\
  8105. };\
  8106. if( typeof(yaxislabel) !== 'undefined' ){\
  8107.  ctx.save();\
  8108.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  8109.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  8110.  corr = ctx.measureText(yaxislabel).width;\
  8111.  ctx.translate(xmarge+font_size,corr+font_size);\
  8112.  ctx.rotate(-0.5*Math.PI);\
  8113.  ctx.fillText(yaxislabel,0,0);\
  8114.  ctx.restore();\
  8115. };\
  8116. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  8117. ctx.lineWidth = line_width;\
  8118. for(var p = x_min; p <= x_max ; p++){\
  8119.  num = Math.pow(xlogbase,p);\
  8120.  for(var i = 1 ; i < xlogbase ; i++){\
  8121.   x_e = x2px(i*num);\
  8122.   if( i == 1 ){\
  8123.    ctx.lineWidth = line_width;\
  8124.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  8125.    if( use_axis_numbering == 1 && p > x_min){\
  8126.      xtxt = xlogbase+'^'+p.toFixed(0);\
  8127.      corr = 0.5*(ctx.measureText(xtxt).width);\
  8128.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  8129.    };\
  8130.   }else{\
  8131.    ctx.lineWidth = 0.2*line_width;\
  8132.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  8133.   };\
  8134.   if( x_e >= xmarge ){\
  8135.    ctx.beginPath();\
  8136.    ctx.moveTo(x_e,0);\
  8137.    ctx.lineTo(x_e,ysize - ymarge);\
  8138.    ctx.stroke();\
  8139.    ctx.closePath();\
  8140.   };\
  8141.  };\
  8142. };\
  8143. for(var p = y_min; p <= y_max ; p++){\
  8144.  num = Math.pow(ylogbase,p);\
  8145.  for(var i = 1 ; i < ylogbase ; i++){\
  8146.   y_e = y2px(i*num);\
  8147.   if( i == 1 ){\
  8148.    ctx.lineWidth = line_width;\
  8149.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  8150.    if( use_axis_numbering == 1 && p > y_min){\
  8151.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  8152.    };\
  8153.   }else{\
  8154.    ctx.lineWidth = 0.2*line_width;\
  8155.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  8156.   };\
  8157.   ctx.beginPath();\
  8158.   ctx.moveTo(xmarge,y_e);\
  8159.   ctx.lineTo(xsize,y_e);\
  8160.   ctx.stroke();\
  8161.   ctx.closePath();\
  8162.  };\
  8163. };\
  8164. ctx.restore();\
  8165. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  8166.     break;
  8167.  
  8168. case DRAW_XLOGSCALE:
  8169. fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\
  8170. var 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){\
  8171. var obj;\
  8172. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8173.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8174. }\
  8175. else\
  8176. {\
  8177.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8178. };\
  8179. var ctx = obj.getContext(\"2d\");\
  8180. ctx.clearRect(0,0,xsize,ysize);\
  8181. ctx.save();\
  8182. ctx.lineWidth = line_width;\
  8183. var prec = Math.log(precision)/Math.log(10);\
  8184. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  8185. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  8186. var y_min = 0;var y_max = ysize;var x_e;var corr;\
  8187. var xtxt;var ytxt;var num;var xmarge;var ymarge;\
  8188. if(use_axis_numbering == 1){\
  8189.  ctx.font = font_family;\
  8190.  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
  8191.  ymarge = parseInt(1.5*font_size);\
  8192.  ctx.save();\
  8193.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  8194.  ctx.rect(0,0,xmarge,ysize);\
  8195.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  8196.  ctx.fill();\
  8197.  ctx.restore();\
  8198. }else{xmarge = 0;ymarge = 0;};\
  8199. if( typeof(xaxislabel) !== 'undefined' ){\
  8200.  ctx.save();\
  8201.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  8202.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  8203.  corr =  ctx.measureText(xaxislabel).width;\
  8204.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  8205.  ctx.restore();\
  8206. };\
  8207. if( typeof(yaxislabel) !== 'undefined' ){\
  8208.  ctx.save();\
  8209.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  8210.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  8211.  corr = ctx.measureText(yaxislabel).width;\
  8212.  ctx.translate(xmarge+font_size,corr+font_size);\
  8213.  ctx.rotate(-0.5*Math.PI);\
  8214.  ctx.fillText(yaxislabel,0,0);\
  8215.  ctx.restore();\
  8216. };\
  8217. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  8218. ctx.lineWidth = line_width;\
  8219. for(var p = x_min; p <= x_max ; p++){\
  8220.  num = Math.pow(xlogbase,p);\
  8221.  for(var i = 1 ; i < xlogbase ; i++){\
  8222.   x_e = x2px(i*num);\
  8223.   if( i == 1 ){\
  8224.     ctx.lineWidth = line_width;\
  8225.     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  8226.    if( use_axis_numbering == 1 && p > x_min ){\
  8227.      xtxt = xlogbase+'^'+p.toFixed(0);\
  8228.      corr = 0.5*(ctx.measureText(xtxt).width);\
  8229.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  8230.    };\
  8231.   }else{\
  8232.    ctx.lineWidth = 0.2*line_width;\
  8233.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  8234.   };\
  8235.   if( x_e >= xmarge ){\
  8236.    ctx.beginPath();\
  8237.    ctx.moveTo(x_e,0);\
  8238.    ctx.lineTo(x_e,ysize - ymarge);\
  8239.    ctx.stroke();\
  8240.    ctx.closePath();\
  8241.   };\
  8242.  };\
  8243. };\
  8244. var stepy = Math.abs(y2px(ymajor) - y2px(0));\
  8245. var minor_step = stepy / yminor;\
  8246. for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
  8247.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  8248.  ctx.lineWidth = line_width;\
  8249.  ctx.beginPath();\
  8250.  ctx.moveTo(xmarge,y);\
  8251.  ctx.lineTo(xsize,y);\
  8252.  ctx.stroke();\
  8253.  ctx.closePath();\
  8254.  if( use_axis_numbering == 1){\
  8255.   ytxt = (px2y(y)).toFixed(prec);\
  8256.   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
  8257.  };\
  8258.  for(var dy = 1 ; dy < yminor ; dy++){\
  8259.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  8260.   ctx.lineWidth = 0.2*line_width;\
  8261.   ctx.beginPath();\
  8262.   ctx.moveTo(xmarge,y+dy*minor_step);\
  8263.   ctx.lineTo(xsize,y+dy*minor_step);\
  8264.   ctx.stroke();\
  8265.   ctx.closePath();\
  8266.  };\
  8267. };\
  8268. ctx.restore();\
  8269. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  8270.     break;
  8271. case DRAW_YLOGSCALE:
  8272. fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\
  8273. var 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){\
  8274. var obj;\
  8275. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8276.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8277. }\
  8278. else\
  8279. {\
  8280.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8281. };\
  8282. var ctx = obj.getContext(\"2d\");\
  8283. ctx.clearRect(0,0,xsize,ysize);\
  8284. ctx.save();\
  8285. ctx.lineWidth = line_width;\
  8286. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  8287. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  8288. var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
  8289. if(use_axis_numbering == 1){\
  8290.  ctx.font = font_family;\
  8291.  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
  8292.  ymarge = 2*font_size;\
  8293.  ctx.save();\
  8294.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  8295.  ctx.rect(0,0,xmarge,ysize);\
  8296.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  8297.  ctx.fill();\
  8298.  ctx.restore();\
  8299. }else{xmarge = 0;ymarge = 0;};\
  8300. if( typeof(xaxislabel) !== 'undefined' ){\
  8301.  ctx.save();\
  8302.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  8303.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  8304.  corr =  ctx.measureText(xaxislabel).width;\
  8305.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  8306.  ctx.restore();\
  8307. };\
  8308. if( typeof(yaxislabel) !== 'undefined' ){\
  8309.  ctx.save();\
  8310.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  8311.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  8312.  corr = ctx.measureText(yaxislabel).width;\
  8313.  ctx.translate(xmarge+font_size,corr+font_size);\
  8314.  ctx.rotate(-0.5*Math.PI);\
  8315.  ctx.fillText(yaxislabel,0,0);\
  8316.  ctx.restore();\
  8317. };\
  8318. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  8319. ctx.lineWidth = line_width;\
  8320. for(var p = y_min; p <= y_max ; p++){\
  8321.  num = Math.pow(ylogbase,p);\
  8322.  for(var i = 1 ; i < ylogbase ; i++){\
  8323.   y_e = y2px(i*num);\
  8324.   if( i == 1 ){\
  8325.    ctx.lineWidth = line_width;\
  8326.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  8327.    if( use_axis_numbering == 1 && p > y_min){\
  8328.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  8329.    };\
  8330.   }else{\
  8331.    ctx.lineWidth = 0.2*line_width;\
  8332.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  8333.   };\
  8334.   ctx.beginPath();\
  8335.   ctx.moveTo(xmarge,y_e);\
  8336.   ctx.lineTo(xsize,y_e);\
  8337.   ctx.stroke();\
  8338.   ctx.closePath();\
  8339.  };\
  8340. };\
  8341. var stepx = Math.abs(x2px(xmajor) - x2px(0));\
  8342. var minor_step = stepx / xminor;\
  8343. var prec = Math.log(precision)/Math.log(10);\
  8344. var xtxt;var corr;var flip = 0;\
  8345. for(var x = stepx ; x < xsize ; x = x + stepx){\
  8346.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  8347.  ctx.lineWidth = line_width;\
  8348.  ctx.beginPath();\
  8349.  ctx.moveTo(x,ysize-ymarge);\
  8350.  ctx.lineTo(x,0);\
  8351.  ctx.stroke();\
  8352.  ctx.closePath();\
  8353.  if( use_axis_numbering == 1){\
  8354.   xtxt = (px2x(x)).toFixed(prec);\
  8355.   corr = 0.5*(ctx.measureText(xtxt).width);\
  8356.   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
  8357.   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
  8358.  };\
  8359.  for(var dx = 1 ; dx < xminor ; dx++){\
  8360.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  8361.   ctx.lineWidth = 0.2*line_width;\
  8362.   ctx.beginPath();\
  8363.   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
  8364.   ctx.lineTo(x+dx*minor_step,0);\
  8365.   ctx.stroke();\
  8366.   ctx.closePath();\
  8367.  };\
  8368. };\
  8369. ctx.restore();\
  8370. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  8371.     break;
  8372.  
  8373.     default:break;
  8374.    }
  8375.   }
  8376.  }
  8377.   return;
  8378. }
  8379.  
  8380. void check_string_length(int L){
  8381.  if( L > MAX_BUFFER-1){
  8382.   canvas_error("problem with your arguments to command...");
  8383.  }
  8384.  return;
  8385. }
  8386.  
  8387.  
  8388. int get_token(FILE *infile){
  8389.         int     c,i=0;
  8390.         char    temp[MAX_INT], *input_type;
  8391.         char    *line="line",
  8392.         *audio="audio",
  8393.         *blink="blink",
  8394.         *arrowhead="arrowhead",
  8395.         *crosshairsize="crosshairsize",
  8396.         *crosshair="crosshair",
  8397.         *crosshairs="crosshairs",
  8398.         *audioobject="audioobject",
  8399.         *style="style",
  8400.         *mouse="mouse",
  8401.         *mousex="mousex",
  8402.         *mousey="mousey",
  8403.         *mouse_display="display",
  8404.         *mouse_degree="mouse_degree",
  8405.         *userdraw="userdraw",
  8406.         *highlight="highlight",
  8407.         *http="http",
  8408.         *rays="rays",
  8409.         *dashtype="dashtype",
  8410.         *dashed="dashed",
  8411.         *filled="filled",
  8412.         *lattice="lattice",
  8413.         *parallel="parallel",
  8414.         *segment="segment",
  8415.         *segments="segments",
  8416.         *dsegment="dsegment",
  8417.         *dsegments="dsegments",
  8418.         *seg="seg",
  8419.         *segs="segs",
  8420.         *bgimage="bgimage",
  8421.         *bgcolor="bgcolor",
  8422.         *strokecolor="strokecolor",
  8423.         *backgroundimage="backgroundimage",
  8424.         *text="text",
  8425.         *textup="textup",
  8426.         *mouseprecision="mouseprecision",
  8427.         *precision="precision",
  8428.         *plotsteps="plotsteps",
  8429.         *plotstep="plotstep",
  8430.         *tsteps="tsteps",
  8431.         *curve="curve",
  8432.         *dcurve="dcurve",
  8433.         *plot="plot",
  8434.         *dplot="dplot",
  8435.         *levelcurve="levelcurve",
  8436.         *fontsize="fontsize",
  8437.         *fontcolor="fontcolor",
  8438.         *axis="axis",
  8439.         *axisnumbering="axisnumbering",
  8440.         *axisnumbers="axisnumbers",
  8441.         *arrow="arrow",
  8442.         *vector="vector",
  8443.         *vectors="vectors",
  8444.         *darrow="darrow",
  8445.         *arrow2="arrow2",
  8446.         *darrow2="darrow2",
  8447.         *arrows="arrows",
  8448.         *arrows2="arrows2",
  8449.         *zoom="zoom",
  8450.         *grid="grid",
  8451.         *hline="hline",
  8452.         *dhline="dhline",
  8453.         *drag="drag",
  8454.         *horizontalline="horizontalline",
  8455.         *horizontallines="horizontallines",
  8456.         *vline="vline",
  8457.         *dvline="dvline",
  8458.         *verticalline="verticalline",
  8459.         *verticallines="verticallines",
  8460.         *triangle="triangle",
  8461.         *triangles="triangles",
  8462.         *ftriangle="ftriangle",
  8463.         *ftriangles="ftriangles",
  8464.         *mathml="mathml",
  8465.         *html="html",
  8466.         *input="input",
  8467.         *clearbutton="clearbutton",
  8468.         *erase="erase",
  8469.         *delete="delete",
  8470.         *inputstyle="inputstyle",
  8471.         *textarea="textarea",
  8472.         *trange="trange",
  8473.         *ranget="ranget",
  8474.         *xrange="xrange",
  8475.         *yrange="yrange",
  8476.         *rangex="rangex",
  8477.         *rangey="rangey",
  8478.         *path="path",
  8479.         *polyline="polyline",
  8480.         *brokenline="brokenline",
  8481.         *lines="lines",
  8482.         *poly="poly",
  8483.         *polygon="polygon",
  8484.         *fpolygon="fpolygon",
  8485.         *fpoly="fpoly",
  8486.         *filledpoly="filledpoly",
  8487.         *filledpolygon="filledpolygon",
  8488.         *rect="rect",
  8489.         *frect="frect",
  8490.         *rectangle="rectangle",
  8491.         *frectangle="frectangle",
  8492.         *square="square",
  8493.         *fsquare="fsquare",
  8494.         *fsquares="fsquares",
  8495.         *rects="rects",
  8496.         *frects="frects",
  8497.         *dline="dline",
  8498.         *arc="arc",
  8499.         *filledarc="filledarc",
  8500.         *farc="farc",
  8501.         *size="size",
  8502.         *string="string",
  8503.         *stringup="stringup",
  8504.         *copy="copy",
  8505.         *copyresized="copyresized",
  8506.         *opacity="opacity",
  8507.         *transparent="transparent",
  8508.         *fill="fill",
  8509.         *point="point",
  8510.         *points="points",
  8511.         *linewidth="linewidth",
  8512.         *circle="circle",
  8513.         *circles="circles",
  8514.         *fcircle="fcircle",
  8515.         *fcircles="fcircles",
  8516.         *disk="disk",
  8517.         *disks="disks",
  8518.         *comment="#",
  8519.         *end="end",
  8520.         *ellipse="ellipse",
  8521.         *fellipse="fellipse",
  8522.         *rotate="rotate",
  8523.         *affine="affine",
  8524.         *rotationcenter="rotationcenter",
  8525.         *killrotate="killrotate",
  8526.         *killaffine="killaffine",
  8527.         *fontfamily="fontfamily",
  8528.         *fillcolor="fillcolor",
  8529.         *clicktile="clicktile",
  8530.         *clicktile_colors="clicktile_colors",
  8531.         *translation="translation",
  8532.         *translate="translate",
  8533.         *killtranslation="killtranslation",
  8534.         *killtranslate="killtranslate",
  8535.         *onclick="onclick",
  8536.         *roundrects="roundrects",
  8537.         *roundrect="roundrect",
  8538.         *froundrect="froundrect",
  8539.         *froundrects="froundrects",
  8540.         *roundrectangle="roundrectangle",
  8541.         *patternfill="patternfill",
  8542.         *hatchfill="hatchfill",
  8543.         *diafill="diafill",
  8544.         *diamondfill="diamondfill",
  8545.         *dotfill="dotfill",
  8546.         *gridfill="gridfill",
  8547.         *imagefill="imagefill",
  8548.         *xlogbase="xlogbase",
  8549.         *ylogbase="ylogbase",
  8550.         *xlogscale="xlogscale",
  8551.         *ylogscale="ylogscale",
  8552.         *xylogscale="xylogscale",
  8553.         *intooltip="intooltip",
  8554.         *popup="popup",
  8555.         *replyformat="replyformat",
  8556.         *floodfill="floodfill",
  8557.         *filltoborder="filltoborder",
  8558.         *setpixel="setpixel",
  8559.         *pixels="pixels",
  8560.         *pixelsize="pixelsize",
  8561.         *xaxis="xaxis",
  8562.         *xaxisup="xaxisup",
  8563.         *yaxis="yaxis",
  8564.         *xaxistext="xaxistext",
  8565.         *xaxistextup="xaxistextup",
  8566.         *yaxistext="yaxistext",
  8567.         *piechart="piechart",
  8568.         *boxplot="boxplot",
  8569.         *boxplotdata="boxplotdata",
  8570.         *userboxplot="userboxplot",
  8571.         *userboxplotdata="userboxplotdata",
  8572.         *legend="legend",
  8573.         *legendcolors="legendcolors",
  8574.         *xlabel="xlabel",
  8575.         *ylabel="ylabel",
  8576.         *barchart="barchart",
  8577.         *linegraph="linegraph",
  8578.         *clock="clock",
  8579.         *animate="animate",
  8580.         *video="video",
  8581.         *status="status",
  8582.         *nostatus="nostatus",
  8583.         *snaptogrid="snaptogrid",
  8584.         *xsnaptogrid="xsnaptogrid",
  8585.         *ysnaptogrid="ysnaptogrid",
  8586.         *snaptopoints="snaptopoints",
  8587.         *snaptofunction="snaptofunction",
  8588.         *snaptofun="snaptofun",
  8589.         *userinput_xy="userinput_xy",
  8590.         *userinput_function="userinput_function",
  8591.         *usertextarea_xy="usertextarea_xy",
  8592.         *userinput="userinput",
  8593.         *jsmath="jsmath",
  8594.         *trace_jscurve="trace_jscurve",
  8595.         *setlimits="setlimits",
  8596.         *jscurve="jscurve",
  8597.         *jsplot="jsplot",
  8598.         *sgraph="sgraph",
  8599.         *title="title",
  8600.         *centerstring="centerstring",
  8601.         *xunit="xunit",
  8602.         *yunit="yunit",
  8603.         *slider="slider",
  8604.         *killslider="killslider",
  8605.         *angle="angle",
  8606.         *halflines="halflines",
  8607.         *demilines="demilines",
  8608.         *halfline="halfline",
  8609.         *demiline="demiline",
  8610.         *hlines="hlines",
  8611.         *vlines="vlines",
  8612.         *bezier="bezier",
  8613.         *functionlabel="functionlabel",
  8614.         *sliderfunction_x="sliderfunction_x",
  8615.         *sliderfunction_y="sliderfunction_y",
  8616.         *multidraw="multidraw",
  8617.         *multilinewidth="multilinewidth",
  8618.         *multistrokecolors="multistrokecolors",
  8619.         *multifillcolors="multifillcolors",
  8620.         *multistrokeopacity="multistrokeopacity",
  8621.         *multifillopacity="multifillopacity",
  8622.         *multifill="multifill",
  8623.         *multidash="multidash",
  8624.         *multilabel="multilabel",
  8625.         *multiuserinput="multiuserinput",
  8626.         *multisnaptogrid="multisnaptogrid",
  8627.         *protractor="protractor",
  8628.         *ruler="ruler",
  8629.         *cursor="cursor",
  8630.         *pointer="pointer",
  8631.         *yerrorbars="yerrorbars",
  8632.         *xerrorbars="xerrorbars",
  8633.         *noxaxis="noxaxis",
  8634.         *noyaxis="noyaxis",
  8635.         *canvastype="canvastype";
  8636.  
  8637.         while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){
  8638.          if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */
  8639.          }else{
  8640.           if( c == ' ' ){
  8641.             break;
  8642.           }else{
  8643.            temp[i] = c;
  8644.            if(i > MAX_INT - 2){canvas_error("command string too long !");}
  8645.            i++;
  8646.           }
  8647.          }
  8648.          if(temp[0] == '#'){ break; }
  8649.         }
  8650.         if (c == '\n' || c == '\r' || c == '\t' ){  line_number++; }
  8651.         if (c == EOF) {finished=1;return 0;}
  8652.  
  8653.         temp[i]='\0';
  8654.         input_type=(char*)my_newmem(strlen(temp));
  8655.         snprintf(input_type,sizeof(temp),"%s",temp);
  8656. /* fprintf(stdout,"temp = %s <br/>",input_type); */
  8657.         if( strcmp(input_type, size) == 0 ){
  8658.         free(input_type);
  8659.         return SIZE;
  8660.         }
  8661.         if( strcmp(input_type, xrange) == 0 ){
  8662.         free(input_type);
  8663.         return XRANGE;
  8664.         }
  8665.         if( strcmp(input_type, rangex) == 0 ){
  8666.         free(input_type);
  8667.         return XRANGE;
  8668.         }
  8669.         if( strcmp(input_type, trange) == 0 ){
  8670.         free(input_type);
  8671.         return TRANGE;
  8672.         }
  8673.         if( strcmp(input_type, ranget) == 0 ){
  8674.         free(input_type);
  8675.         return TRANGE;
  8676.         }
  8677.         if( strcmp(input_type, yrange) == 0 ){
  8678.         free(input_type);
  8679.         return YRANGE;
  8680.         }
  8681.         if( strcmp(input_type, rangey) == 0 ){
  8682.         free(input_type);
  8683.         return YRANGE;
  8684.         }
  8685.         if( strcmp(input_type, linewidth) == 0 ){
  8686.         free(input_type);
  8687.         return LINEWIDTH;
  8688.         }
  8689.         if( strcmp(input_type, dashed) == 0 ){
  8690.         free(input_type);
  8691.         return DASHED;
  8692.         }
  8693.         if( strcmp(input_type, dashtype) == 0 ){
  8694.         free(input_type);
  8695.         return DASHTYPE;
  8696.         }
  8697.         if( strcmp(input_type, axisnumbering) == 0 ){
  8698.         free(input_type);
  8699.         return AXIS_NUMBERING;
  8700.         }
  8701.         if( strcmp(input_type, axisnumbers) == 0 ){
  8702.         free(input_type);
  8703.         return AXIS_NUMBERING;
  8704.         }
  8705.         if( strcmp(input_type, axis) == 0 ){
  8706.         free(input_type);
  8707.         return AXIS;
  8708.         }
  8709.         if( strcmp(input_type, grid) == 0 ){
  8710.         free(input_type);
  8711.         return GRID;
  8712.         }
  8713.         if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){
  8714.         free(input_type);
  8715.         return HLINES;
  8716.         }
  8717.         if( strcmp(input_type, vlines) == 0 ||  strcmp(input_type, verticallines) == 0 ){
  8718.         free(input_type);
  8719.         return VLINES;
  8720.         }
  8721.         if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){
  8722.         free(input_type);
  8723.         return HLINE;
  8724.         }
  8725.         if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
  8726.         free(input_type);
  8727.         return VLINE;
  8728.         }
  8729.         if( strcmp(input_type, line) == 0 ){
  8730.         free(input_type);
  8731.         return LINE;
  8732.         }
  8733.         if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){
  8734.         free(input_type);
  8735.         return SEGMENTS;
  8736.         }
  8737.         if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
  8738.         free(input_type);
  8739.         return SEGMENT;
  8740.         }
  8741.         if( strcmp(input_type, dsegments) == 0 ){
  8742.         free(input_type);
  8743.         use_dashed = TRUE;
  8744.         return SEGMENTS;
  8745.         }
  8746.         if( strcmp(input_type, dsegment) == 0 ){
  8747.         free(input_type);
  8748.         use_dashed = TRUE;
  8749.         return SEGMENT;
  8750.         }
  8751.         if( strcmp(input_type, crosshairsize) == 0 ){
  8752.         free(input_type);
  8753.         return CROSSHAIRSIZE;
  8754.         }
  8755.         if( strcmp(input_type, arrowhead) == 0 ){
  8756.         free(input_type);
  8757.         return ARROWHEAD;
  8758.         }
  8759.         if( strcmp(input_type, crosshairs) == 0 ){
  8760.         free(input_type);
  8761.         return CROSSHAIRS;
  8762.         }
  8763.         if( strcmp(input_type, crosshair) == 0 ){
  8764.         free(input_type);
  8765.         return CROSSHAIR;
  8766.         }
  8767.         if( strcmp(input_type, onclick) == 0 ){
  8768.         free(input_type);
  8769.         return ONCLICK;
  8770.         }
  8771.         if( strcmp(input_type, drag) == 0 ){
  8772.         free(input_type);
  8773.         return DRAG;
  8774.         }
  8775.         if( strcmp(input_type, userdraw) == 0 ){
  8776.         free(input_type);
  8777.         return USERDRAW;
  8778.         }
  8779.         if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
  8780.         free(input_type);
  8781.         return STYLE;
  8782.         }
  8783.         if( strcmp(input_type, fillcolor) == 0 ){
  8784.         free(input_type);
  8785.         return FILLCOLOR;
  8786.         }
  8787.         if( strcmp(input_type, strokecolor) == 0 ){
  8788.         free(input_type);
  8789.         return STROKECOLOR;
  8790.         }
  8791.         if( strcmp(input_type, filled) == 0  ){
  8792.         free(input_type);
  8793.         return FILLED;
  8794.         }
  8795.         if( strcmp(input_type, http) == 0 ){
  8796.         free(input_type);
  8797.         return HTTP;
  8798.         }
  8799.         if( strcmp(input_type, rays) == 0 ){
  8800.         free(input_type);
  8801.         return RAYS;
  8802.         }
  8803.         if( strcmp(input_type, lattice) == 0 ){
  8804.         free(input_type);
  8805.         return LATTICE;
  8806.         }
  8807.         if( strcmp(input_type, bgimage) == 0 ){
  8808.         free(input_type);
  8809.         return BGIMAGE;
  8810.         }
  8811.         if( strcmp(input_type, bgcolor) == 0 ){
  8812.         free(input_type);
  8813.         return BGCOLOR;
  8814.         }
  8815.         if( strcmp(input_type, backgroundimage) == 0 ){
  8816.         free(input_type);
  8817.         return BGIMAGE;
  8818.         }
  8819.         if( strcmp(input_type, text) == 0 ){
  8820.         free(input_type);
  8821.         return FLY_TEXT;
  8822.         }
  8823.         if( strcmp(input_type, textup) == 0 ){
  8824.         free(input_type);
  8825.         return FLY_TEXTUP;
  8826.         }
  8827.         if( strcmp(input_type, mouse) == 0 ){
  8828.         free(input_type);
  8829.         return MOUSE;
  8830.         }
  8831.         if( strcmp(input_type, mousex) == 0 ){
  8832.         free(input_type);
  8833.         return MOUSEX;
  8834.         }
  8835.         if( strcmp(input_type, mousey) == 0 ){
  8836.         free(input_type);
  8837.         return MOUSEY;
  8838.         }
  8839.         if( strcmp(input_type, mouse_degree) == 0 ){
  8840.         free(input_type);
  8841.         return MOUSE_DEGREE;
  8842.         }
  8843.         if( strcmp(input_type, mouse_display) == 0 ){
  8844.         free(input_type);
  8845.         return MOUSE_DISPLAY;
  8846.         }
  8847.         if( strcmp(input_type, mouseprecision) == 0 ){
  8848.         free(input_type);
  8849.         return MOUSE_PRECISION;
  8850.         }
  8851.         if( strcmp(input_type, precision) == 0 ){
  8852.         free(input_type);
  8853.         return MOUSE_PRECISION;
  8854.         }
  8855.         if( strcmp(input_type, curve) == 0 ){
  8856.         free(input_type);
  8857.         return CURVE;
  8858.         }
  8859.         if( strcmp(input_type, dcurve) == 0 ){
  8860.         use_dashed = TRUE;
  8861.         free(input_type);
  8862.         return CURVE;
  8863.         }
  8864.         if( strcmp(input_type, plot) == 0 ){
  8865.         free(input_type);
  8866.         return CURVE;
  8867.         }
  8868.         if( strcmp(input_type, dplot) == 0 ){
  8869.         use_dashed = TRUE;
  8870.         free(input_type);
  8871.         return CURVE;
  8872.         }
  8873.         if( strcmp(input_type, levelcurve) == 0 ){
  8874.         free(input_type);
  8875.         return LEVELCURVE;
  8876.         }
  8877.         if( strcmp(input_type, plotsteps) == 0 ){
  8878.         free(input_type);
  8879.         return PLOTSTEPS;
  8880.         }
  8881.         if( strcmp(input_type, plotstep) == 0 ){
  8882.         free(input_type);
  8883.         return PLOTSTEPS;
  8884.         }
  8885.         if( strcmp(input_type, tsteps) == 0 ){
  8886.         free(input_type);
  8887.         return PLOTSTEPS;
  8888.         }
  8889.         if( strcmp(input_type, fontsize) == 0 ){
  8890.         free(input_type);
  8891.         return FONTSIZE;
  8892.         }
  8893.         if( strcmp(input_type, fontcolor) == 0 ){
  8894.         free(input_type);
  8895.         return FONTCOLOR;
  8896.         }
  8897.         if( strcmp(input_type, arrow2) == 0 ){
  8898.         free(input_type);
  8899.         return ARROW2;
  8900.         }
  8901.         if( strcmp(input_type, darrow) == 0 ){
  8902.         free(input_type);
  8903.         use_dashed = TRUE;
  8904.         return ARROW;
  8905.         }
  8906.         if( strcmp(input_type, darrow2) == 0 ){
  8907.         free(input_type);
  8908.         use_dashed = TRUE;
  8909.         return ARROW2;
  8910.         }
  8911.         if( strcmp(input_type, arrows2) == 0 ){
  8912.         free(input_type);
  8913.         return ARROWS2;
  8914.         }
  8915.         if( strcmp(input_type, arrows) == 0  || strcmp(input_type, vectors) == 0 ){
  8916.         free(input_type);
  8917.         return ARROWS;
  8918.         }
  8919.         if( strcmp(input_type, arrow) == 0 ||  strcmp(input_type, vector) == 0 ){
  8920.         free(input_type);
  8921.         return ARROW;
  8922.         }
  8923.         if( strcmp(input_type, zoom) == 0 ){
  8924.         free(input_type);
  8925.         return ZOOM;
  8926.         }
  8927.         if( strcmp(input_type, triangle) == 0 ){
  8928.         free(input_type);
  8929.         return TRIANGLE;
  8930.         }
  8931.         if( strcmp(input_type, triangles) == 0 ){
  8932.         free(input_type);
  8933.         return TRIANGLES;
  8934.         }
  8935.         if( strcmp(input_type, ftriangles) == 0 ){
  8936.         free(input_type);
  8937.         use_filled = TRUE;
  8938.         return TRIANGLES;
  8939.         }
  8940.         if( strcmp(input_type, ftriangle) == 0 ){
  8941.         free(input_type);
  8942.         use_filled = TRUE;
  8943.         return TRIANGLE;
  8944.         }
  8945.         if( strcmp(input_type, input) == 0 ){
  8946.         free(input_type);
  8947.         return INPUT;
  8948.         }
  8949.         if( strcmp(input_type, inputstyle) == 0 ){
  8950.         free(input_type);
  8951.         return INPUTSTYLE;
  8952.         }
  8953.         if( strcmp(input_type, textarea) == 0 ){
  8954.         free(input_type);
  8955.         return TEXTAREA;
  8956.         }
  8957.         if( strcmp(input_type, mathml) == 0 ){
  8958.         free(input_type);
  8959.         return MATHML;
  8960.         }
  8961.         if( strcmp(input_type, html) == 0 ){
  8962.         free(input_type);
  8963.         return MATHML;
  8964.         }
  8965.         if( strcmp(input_type, fontfamily) == 0 ){
  8966.         free(input_type);
  8967.         return FONTFAMILY;
  8968.         }
  8969.         if( strcmp(input_type, polyline) == 0 ||  strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){
  8970.         free(input_type);
  8971.         return POLYLINE;
  8972.         }
  8973.         if( strcmp(input_type, lines) == 0 ){
  8974.         free(input_type);
  8975.         return LINES;
  8976.         }
  8977.         if( strcmp(input_type, rects) == 0){
  8978.         free(input_type);
  8979.         return RECTS;
  8980.         }
  8981.         if( strcmp(input_type, frects) == 0 ){
  8982.         free(input_type);
  8983.         use_filled = TRUE;
  8984.         return RECTS;
  8985.         }
  8986.         if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
  8987.         free(input_type);
  8988.         return RECT;
  8989.         }
  8990.         if( strcmp(input_type, square) == 0 ){
  8991.         free(input_type);
  8992.         return RECT;
  8993.         }
  8994.         if( strcmp(input_type, fsquare) == 0 ){
  8995.         free(input_type);
  8996.         use_filled = TRUE;
  8997.         return SQUARE;
  8998.         }
  8999.         if( strcmp(input_type, fsquares) == 0 ){
  9000.         free(input_type);
  9001.         use_filled = TRUE;
  9002.         return RECTS;
  9003.         }
  9004.         if( strcmp(input_type, roundrects) == 0 ){
  9005.         free(input_type);
  9006.         return ROUNDRECTS;
  9007.         }
  9008.         if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
  9009.         free(input_type);
  9010.         return ROUNDRECT;
  9011.         }
  9012.         if( strcmp(input_type, froundrects) == 0 ){
  9013.         free(input_type);
  9014.         use_filled = TRUE;
  9015.         return ROUNDRECTS;
  9016.         }
  9017.         if( strcmp(input_type, froundrect) == 0 ){
  9018.         free(input_type);
  9019.         use_filled = TRUE;
  9020.         return ROUNDRECT;
  9021.         }
  9022.         if( strcmp(input_type, dline) == 0 ){
  9023.         use_dashed = TRUE;
  9024.         free(input_type);
  9025.         return LINE;
  9026.         }
  9027.         if( strcmp(input_type, dvline) == 0 ){
  9028.         use_dashed = TRUE;
  9029.         free(input_type);
  9030.         return VLINE;
  9031.         }
  9032.         if( strcmp(input_type, dhline) == 0 ){
  9033.         use_dashed = TRUE;
  9034.         free(input_type);
  9035.         return HLINE;
  9036.         }
  9037.         if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0  ){
  9038.         free(input_type);
  9039.         return HALFLINES;
  9040.         }
  9041.         if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0  ){
  9042.         free(input_type);
  9043.         return HALFLINE;
  9044.         }
  9045.         if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
  9046.         use_filled = TRUE;
  9047.         free(input_type);
  9048.         return RECT;
  9049.         }
  9050.         if( strcmp(input_type, circles) == 0 ){
  9051.         free(input_type);
  9052.         return CIRCLES;
  9053.         }
  9054.         if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
  9055.         use_filled = TRUE;
  9056.         free(input_type);
  9057.         return CIRCLE;
  9058.         }
  9059.         if( strcmp(input_type, fcircles) == 0  ||  strcmp(input_type, disks) == 0 ){
  9060.         use_filled = TRUE;
  9061.         free(input_type);
  9062.         return CIRCLES;
  9063.         }
  9064.         if( strcmp(input_type, circle) == 0 ){
  9065.         free(input_type);
  9066.         return CIRCLE;
  9067.         }
  9068.         if( strcmp(input_type, point) == 0 ){
  9069.         free(input_type);
  9070.         return POINT;
  9071.         }
  9072.         if( strcmp(input_type, points) == 0 ){
  9073.         free(input_type);
  9074.         return POINTS;
  9075.         }
  9076.         if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){
  9077.         use_filled = TRUE;
  9078.         free(input_type);
  9079.         return ARC;
  9080.         }
  9081.         if( strcmp(input_type, arc) == 0 ){
  9082.         free(input_type);
  9083.         return ARC;
  9084.         }
  9085.         if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
  9086.         free(input_type);
  9087.         return POLY;
  9088.         }
  9089.         if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
  9090.         use_filled = TRUE;
  9091.         free(input_type);
  9092.         return POLY;
  9093.         }
  9094.         if( strcmp(input_type, ellipse) == 0){
  9095.         free(input_type);
  9096.         return ELLIPSE;
  9097.         }
  9098.         if( strcmp(input_type, string) == 0 ){
  9099.         free(input_type);
  9100.         return STRING;
  9101.         }
  9102.         if( strcmp(input_type, stringup) == 0 ){
  9103.         free(input_type);
  9104.         return STRINGUP;
  9105.         }
  9106.         if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){
  9107.         free(input_type);
  9108.         return OPACITY;
  9109.         }
  9110.         if( strcmp(input_type, comment) == 0){
  9111.         free(input_type);
  9112.         return COMMENT;
  9113.         }
  9114.         if( strcmp(input_type, fellipse) == 0){
  9115.         free(input_type);
  9116.         use_filled = TRUE;
  9117.         return ELLIPSE;
  9118.         }
  9119.         if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){
  9120.         free(input_type);
  9121.         return CLEARBUTTON;
  9122.         }
  9123.         if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
  9124.         free(input_type);
  9125.         return TRANSLATION;
  9126.         }
  9127.         if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
  9128.         free(input_type);
  9129.         return KILLTRANSLATION;
  9130.         }
  9131.         if( strcmp(input_type, rotate) == 0){
  9132.         free(input_type);
  9133.         return ROTATE;
  9134.         }
  9135.         if( strcmp(input_type, killrotate) == 0){
  9136.         free(input_type);
  9137.         return KILLROTATE;
  9138.         }
  9139.         if( strcmp(input_type, rotationcenter) == 0){
  9140.         free(input_type);
  9141.         return ROTATION_CENTER;
  9142.         }
  9143.         if( strcmp(input_type, affine) == 0){
  9144.         free(input_type);
  9145.         return AFFINE;
  9146.         }
  9147.         if( strcmp(input_type, killaffine) == 0){
  9148.         free(input_type);
  9149.         return KILLAFFINE;
  9150.         }
  9151.         if( strcmp(input_type, slider) == 0 ){
  9152.         free(input_type);
  9153.         return SLIDER;
  9154.         }
  9155.         if( strcmp(input_type, killslider) == 0 ){
  9156.         free(input_type);
  9157.         return KILLSLIDER;
  9158.         }
  9159.         if( strcmp(input_type, copy) == 0 ){
  9160.         free(input_type);
  9161.         return COPY;
  9162.         }
  9163.         if( strcmp(input_type, copyresized) == 0 ){
  9164.         free(input_type);
  9165.         return COPYRESIZED;
  9166.         }
  9167.         if( strcmp(input_type, xlogscale) == 0 ){
  9168.         free(input_type);
  9169.         return XLOGSCALE;
  9170.         }
  9171.         if( strcmp(input_type, ylogscale) == 0 ){
  9172.         free(input_type);
  9173.         return YLOGSCALE;
  9174.         }
  9175.         if( strcmp(input_type, xylogscale) == 0 ){
  9176.         free(input_type);
  9177.         return XYLOGSCALE;
  9178.         }
  9179.         if( strcmp(input_type, ylogscale) == 0 ){
  9180.         free(input_type);
  9181.         return YLOGSCALE;
  9182.         }
  9183.         if( strcmp(input_type, xlogbase) == 0 ){
  9184.         free(input_type);
  9185.         return XLOGBASE;
  9186.         }
  9187.         if( strcmp(input_type, ylogbase) == 0 ){
  9188.         free(input_type);
  9189.         return YLOGBASE;
  9190.         }
  9191.         if( strcmp(input_type, intooltip) == 0 ){
  9192.         free(input_type);
  9193.         return INTOOLTIP;
  9194.         }
  9195.         if( strcmp(input_type, popup) == 0 ){
  9196.         free(input_type);
  9197.         return POPUP;
  9198.         }
  9199.         if( strcmp(input_type,video) == 0 ){
  9200.         free(input_type);
  9201.         return VIDEO;
  9202.         }
  9203.         if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
  9204.         free(input_type);
  9205.         return FLOODFILL;
  9206.         }
  9207.         if( strcmp(input_type,filltoborder) == 0 ){
  9208.         free(input_type);
  9209.         return FILLTOBORDER;
  9210.         }
  9211.         if( strcmp(input_type, replyformat) == 0 ){
  9212.         free(input_type);
  9213.         return REPLYFORMAT;
  9214.         }
  9215.         if( strcmp(input_type, pixelsize) == 0 ){
  9216.         free(input_type);
  9217.         return PIXELSIZE;
  9218.         }
  9219.         if( strcmp(input_type, setpixel) == 0 ){
  9220.         free(input_type);
  9221.         return SETPIXEL;
  9222.         }
  9223.         if( strcmp(input_type, pixels) == 0 ){
  9224.         free(input_type);
  9225.         return PIXELS;
  9226.         }
  9227.         if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
  9228.         free(input_type);
  9229.         return X_AXIS_STRINGS;
  9230.         }
  9231.         if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){
  9232.         free(input_type);
  9233.         return X_AXIS_STRINGS_UP;
  9234.         }
  9235.         if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
  9236.         free(input_type);
  9237.         return Y_AXIS_STRINGS;
  9238.         }
  9239.         if( strcmp(input_type, legend) == 0  ){
  9240.         free(input_type);
  9241.         return LEGEND;
  9242.         }
  9243.         if( strcmp(input_type, legendcolors) == 0  ){
  9244.         free(input_type);
  9245.         return LEGENDCOLORS;
  9246.         }
  9247.         if( strcmp(input_type, xlabel) == 0  ){
  9248.         free(input_type);
  9249.         return XLABEL;
  9250.         }
  9251.         if( strcmp(input_type, ylabel) == 0  ){
  9252.         free(input_type);
  9253.         return YLABEL;
  9254.         }
  9255.         if( strcmp(input_type, bezier) == 0  ){
  9256.         free(input_type);
  9257.         return BEZIER;
  9258.         }
  9259.         if( strcmp(input_type, animate) == 0  ){
  9260.         free(input_type);
  9261.         return ANIMATE;
  9262.         }
  9263.         /* these are bitmap related flydraw commands...must be removed. eventually */
  9264.         if( strcmp(input_type, transparent) == 0 ){
  9265.         free(input_type);
  9266.         return TRANSPARENT;
  9267.         }
  9268.         if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
  9269.         free(input_type);
  9270.         return STATUS;
  9271.         }
  9272.         if( strcmp(input_type, xsnaptogrid) == 0 ){
  9273.         free(input_type);
  9274.         return XSNAPTOGRID;
  9275.         }
  9276.         if( strcmp(input_type, ysnaptogrid) == 0 ){
  9277.         free(input_type);
  9278.         return YSNAPTOGRID;
  9279.         }
  9280.         if( strcmp(input_type, snaptogrid) == 0 ){
  9281.         free(input_type);
  9282.         return SNAPTOGRID;
  9283.         }
  9284.         if( strcmp(input_type, snaptopoints) == 0 ){
  9285.         free(input_type);
  9286.         return SNAPTOPOINTS;
  9287.         }
  9288.         if( strcmp(input_type, snaptofunction) == 0  || strcmp(input_type, snaptofun) == 0 ){
  9289.         free(input_type);
  9290.         return SNAPTOFUNCTION;
  9291.         }
  9292.         if( strcmp(input_type, userinput_xy) == 0 ){
  9293.         free(input_type);
  9294.         return USERINPUT_XY;
  9295.         }
  9296.         if( strcmp(input_type, userinput_function) == 0 ){
  9297.         free(input_type);
  9298.         return USERINPUT_FUNCTION;
  9299.         }
  9300.         if( strcmp(input_type, usertextarea_xy) == 0 ){
  9301.         free(input_type);
  9302.         return USERTEXTAREA_XY;
  9303.         }
  9304.         if( strcmp(input_type, userinput) == 0 ){
  9305.         free(input_type);
  9306.         return USERINPUT;
  9307.         }
  9308.         if( strcmp(input_type, angle) == 0 ){
  9309.         free(input_type);
  9310.         return ANGLE;
  9311.         }
  9312.         if( strcmp(input_type, functionlabel) == 0 ){
  9313.         free(input_type);
  9314.         return FUNCTION_LABEL;
  9315.         }
  9316.         if( strcmp(input_type, sliderfunction_x) == 0 ){
  9317.         free(input_type);
  9318.         return SLIDER_X;
  9319.         }
  9320.         if( strcmp(input_type, sliderfunction_y) == 0 ){
  9321.         free(input_type);
  9322.         return SLIDER_Y;
  9323.         }
  9324.         if( strcmp(input_type, multidraw) == 0 ){
  9325.         free(input_type);
  9326.         return MULTIDRAW;
  9327.         }
  9328.         if( strcmp(input_type, multistrokeopacity) == 0 ){
  9329.         free(input_type);
  9330.         return MULTISTROKEOPACITY;
  9331.         }
  9332.         if( strcmp(input_type, multifillopacity) == 0 ){
  9333.         free(input_type);
  9334.         return MULTIFILLOPACITY;
  9335.         }
  9336.         if( strcmp(input_type, multilinewidth) == 0 ){
  9337.         free(input_type);
  9338.         return MULTILINEWIDTH;
  9339.         }
  9340.         if( strcmp(input_type, multistrokecolors) == 0 ){
  9341.         free(input_type);
  9342.         return MULTISTROKECOLORS;
  9343.         }
  9344.         if( strcmp(input_type, multifill) == 0 ){
  9345.         free(input_type);
  9346.         return MULTIFILL;
  9347.         }
  9348.         if( strcmp(input_type, multifillcolors) == 0 ){
  9349.         free(input_type);
  9350.         return MULTIFILLCOLORS;
  9351.         }
  9352.         if( strcmp(input_type, multilabel) == 0 ){
  9353.         free(input_type);
  9354.         return MULTILABEL;
  9355.         }
  9356.         if( strcmp(input_type, multidash) == 0 ){
  9357.         free(input_type);
  9358.         return MULTIDASH;
  9359.         }
  9360.         if( strcmp(input_type, multisnaptogrid) == 0 ){
  9361.         free(input_type);
  9362.         return MULTISNAPTOGRID;
  9363.         }
  9364.         if( strcmp(input_type, multiuserinput) == 0 ){
  9365.         free(input_type);
  9366.         return MULTIUSERINPUT;
  9367.         }
  9368.         if( strcmp(input_type, parallel) == 0 ){
  9369.         free(input_type);
  9370.         return PARALLEL;
  9371.         }
  9372.         if( strcmp(input_type, protractor) == 0 ){
  9373.         free(input_type);
  9374.         return PROTRACTOR;
  9375.         }
  9376.         if( strcmp(input_type, ruler) == 0 ){
  9377.         free(input_type);
  9378.         return RULER;
  9379.         }
  9380.         if( strcmp(input_type, cursor) == 0 ||  strcmp(input_type, pointer) == 0 ){
  9381.         free(input_type);
  9382.         return CURSOR;
  9383.         }
  9384.         if( strcmp(input_type, sgraph) == 0 ){
  9385.         free(input_type);
  9386.         return SGRAPH;
  9387.         }
  9388.         if( strcmp(input_type, jsmath) == 0 ){
  9389.         free(input_type);
  9390.         return JSMATH;
  9391.         }
  9392.         if( strcmp(input_type, trace_jscurve) == 0 ){
  9393.         free(input_type);
  9394.         return TRACE_JSCURVE;
  9395.         }
  9396.         if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
  9397.         free(input_type);
  9398.         return JSCURVE;
  9399.         }
  9400.         if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
  9401.         free(input_type);
  9402.         return CENTERSTRING;
  9403.         }
  9404.         if( strcmp(input_type, setlimits) == 0 ){
  9405.         free(input_type);
  9406.         return SETLIMITS;
  9407.         }
  9408.         if( strcmp(input_type, xunit) == 0 ){
  9409.         free(input_type);
  9410.         return XUNIT;
  9411.         }
  9412.         if( strcmp(input_type, yunit) == 0 ){
  9413.         free(input_type);
  9414.         return YUNIT;
  9415.         }
  9416.         if( strcmp(input_type, fill) == 0 ){
  9417.         free(input_type);
  9418.         return FLOODFILL;
  9419.         }
  9420.         if( strcmp(input_type, end) == 0){
  9421.         free(input_type);
  9422.         return END;
  9423.         }
  9424.         if( strcmp(input_type, blink) == 0 ){
  9425.         free(input_type);
  9426.         return BLINK;
  9427.         }
  9428.         if( strcmp(input_type, audio) == 0 ){
  9429.         free(input_type);
  9430.         return AUDIO;
  9431.         }
  9432.         if( strcmp(input_type, audioobject) == 0 ){
  9433.         free(input_type);
  9434.         return AUDIOOBJECT;
  9435.         }
  9436.         if( strcmp(input_type, patternfill) == 0 ){
  9437.         free(input_type);
  9438.         return PATTERNFILL;
  9439.         }
  9440.         if( strcmp(input_type, hatchfill) == 0 ){
  9441.         free(input_type);
  9442.         return HATCHFILL;
  9443.         }
  9444.         if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
  9445.         free(input_type);
  9446.         return DIAMONDFILL;
  9447.         }
  9448.         if( strcmp(input_type, dotfill) == 0 ){
  9449.         free(input_type);
  9450.         return DOTFILL;
  9451.         }
  9452.         if( strcmp(input_type, gridfill) == 0 ){
  9453.         free(input_type);
  9454.         return GRIDFILL;
  9455.         }
  9456.         if( strcmp(input_type, imagefill) == 0 ){
  9457.         free(input_type);
  9458.         return IMAGEFILL;
  9459.         }
  9460.         if( strcmp(input_type, clicktile_colors) == 0 ){
  9461.         free(input_type);
  9462.         return CLICKTILE_COLORS;
  9463.         }
  9464.         if( strcmp(input_type, clicktile) == 0 ){
  9465.         free(input_type);
  9466.         return CLICKTILE;
  9467.         }
  9468.         if( strcmp(input_type, piechart) == 0  ){
  9469.         free(input_type);
  9470.         return PIECHART;
  9471.         }
  9472.         if( strcmp(input_type, boxplot) == 0  ){
  9473.         free(input_type);
  9474.         return BOXPLOT;
  9475.         }
  9476.         if( strcmp(input_type, boxplotdata) == 0  ){
  9477.         free(input_type);
  9478.         return BOXPLOTDATA;
  9479.         }
  9480.         if( strcmp(input_type, userboxplot) == 0  ){
  9481.         free(input_type);
  9482.         return USERBOXPLOT;
  9483.         }
  9484.         if( strcmp(input_type, userboxplotdata) == 0  ){
  9485.         free(input_type);
  9486.         return USERBOXPLOT;
  9487.         }
  9488.         if( strcmp(input_type, barchart) == 0  ){
  9489.         free(input_type);
  9490.         return BARCHART;
  9491.         }
  9492.         if( strcmp(input_type, linegraph) == 0  ){
  9493.         free(input_type);
  9494.         return LINEGRAPH;
  9495.         }
  9496.         if( strcmp(input_type, clock) == 0  ){
  9497.         free(input_type);
  9498.         return CLOCK;
  9499.         }
  9500.         if( strcmp(input_type, yerrorbars) == 0  ){
  9501.         free(input_type);
  9502.         return YERRORBARS;
  9503.         }
  9504.         if( strcmp(input_type, xerrorbars) == 0  ){
  9505.         free(input_type);
  9506.         return XERRORBARS;
  9507.         }
  9508.         if( strcmp(input_type, canvastype) == 0  ){
  9509.         free(input_type);
  9510.         return CANVASTYPE;
  9511.         }
  9512.         if( strcmp(input_type, noyaxis) == 0  ){
  9513.         free(input_type);
  9514.         return NOYAXIS;
  9515.         }
  9516.         if( strcmp(input_type, noxaxis) == 0  ){
  9517.         free(input_type);
  9518.         return NOXAXIS;
  9519.         }
  9520.         free(input_type);
  9521.         ungetc(c,infile);
  9522.         return 0;
  9523. }
  9524.