Subversion Repositories wimsdev

Rev

Rev 8349 | Rev 8357 | 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_functions(int js_functions[], 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.  
  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 line_width = 1;
  84.     int decimals = 2;
  85.     int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate */
  86.     int use_userdraw = FALSE; /* flag to indicate user interaction: incompatible with "drag & drop" code !! */
  87.     int drag_type = -1;/* 0,1,2 : xy,x,y */
  88.     int use_tooltip = FALSE;
  89.     char *tooltip_text = "Click here";
  90.     char *temp = ""; /* */
  91.     char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
  92.     char *stroke_color = "255,0,0";
  93.     char *fill_color = "0,255,0";
  94.     char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
  95.     char *font_color = "#00000";
  96.     char *draw_type = "points";
  97.     char *fly_font = "normal";
  98.     char *input_style = "";
  99.     char *flytext = "";
  100.     char *affine_matrix = "[1,0,0,1,0,0]";
  101.     char *function_label = "f(x)=";
  102.     int pixelsize = 1;
  103.     int reply_format = 0;
  104.     int input_cnt = 0;
  105.     int ext_img_cnt = 0;
  106.     int slider_cnt = 0;
  107.     int font_size = 12;
  108.     int dashtype[2] = { 4 , 4 };
  109.     int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */
  110.     for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
  111.     int arrow_head = 8; /* size in px*/
  112.     int crosshair_size = 5; /* size in px*/
  113.     int plot_steps = 250;
  114.     int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange*/
  115.     int click_cnt = 1;
  116.     int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
  117.     int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
  118.     int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/
  119.     int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc  */
  120.     int reply_precision = 100; /* used for precision of student answers / drawings */
  121.     double angle = 0.0;
  122.     int clickfillmarge = 20;
  123.     int animation_type = 9; /* == object type curve in drag library */
  124.     int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/
  125.     int use_slider_display = 0; /* in case of a slider, should we display it's value ?*/
  126.     size_t string_length = 0;
  127.     double stroke_opacity = 0.8;
  128.     double fill_opacity = 0.8;
  129.     char *URL = "http://localhost/images";
  130.     memset(buffer,'\0',MAX_BUFFER);
  131.     void *tmp_buffer = "";
  132.  
  133.     /* default writing a unzipped js-include file into wims getfile directory */
  134.     char *w_wims_session = getenv("w_wims_session");
  135.     if(  w_wims_session == NULL || *w_wims_session == 0 ){
  136.         canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");
  137.     }
  138.     int L0=strlen(w_wims_session) + 21;
  139.     char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
  140.     snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
  141.     mode_t process_mask = umask(0); /* check if file exists */
  142.     int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
  143.     if( result == 0 || errno == EEXIST ){
  144.      umask(process_mask); /* be sure to set correct permission */
  145.      char *w_session = getenv("w_session");
  146.      int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
  147.     char *getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
  148.      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 */
  149.     /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
  150.     /* now write file into getfile dir*/
  151.     char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */
  152.     int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
  153.     char *location = my_newmem(L2); /* create memory to fit string precisely */
  154.     snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
  155.     js_include_file = fopen(location,"w");/* open the file location for writing */
  156.     /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */
  157.     if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );}
  158.  
  159. /* ----------------------------------------------------- */
  160. /* while more lines to process */
  161.  
  162.     while(!finished){
  163.         if(line_number>1 && found_size_command == 0){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
  164.         type = get_token(infile);
  165.         done = FALSE;
  166.         /*
  167.         @canvasdraw
  168.         @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...)
  169.         @General syntax <ul><li>The transparency of all objects can be controlled by command 'opacity [0-255],[0,255]'</il><li>a line based object can be controlled by command 'linewidth int'</li><li>a line based object may be dashed by using keyword 'dashed' before the object command.<br />the dashing type can be controled by command 'dashtype int,int'</li><li>a fillable object can be set fillable by starting the object command with an 'f'<br />(like frect,fcircle,ftriangle...)<br />or by using the keyword 'filled' before the object command.<br />The fill colour will be the stroke colour...(19/10/2013)</li><li> all draggable objects may have a slider 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 'drag x/y/xy'<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 zoom and will be translated in case of panning</li><li> a 'onclick object' can be set 'clickable' by the preceding keyword 'onclick'<br />not all flydraw objects can be set clickable</li><li><b>remarks using a ';' as command separator</b><br />commands with only numeric or colour arguments may be using a ';' as command separator (in stead of a new line)<br />commands with a string argument may not use a ';' as command separator !<br />these exceptions are not really straight forward... so keep this in mind.</li></ul>
  170.         @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 />Use command 'replyformat' 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>    
  171.         */
  172.         switch(type){
  173.         case END:
  174.         finished = 1;
  175.         done = TRUE;
  176.         break;
  177.         case 0:
  178.             sync_input(infile);
  179.             break;
  180.         case COMMENT:
  181.             sync_input(infile);
  182.             break;
  183.         case EMPTY:
  184.             sync_input(infile);
  185.             break;
  186.         case SIZE:
  187.             /*
  188.             @size width,height
  189.             @set canvas size in pixels
  190.             @mandatory first command
  191.             @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
  192.             */
  193.             found_size_command = 1;
  194.             xsize = (int)(abs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
  195.             ysize = (int)(abs(round(get_real(infile,1))));
  196.             /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
  197.             xmin = 0;xmax = xsize;
  198.             ymin = 0;ymax = ysize;
  199.  
  200. /*
  201.  The sequence in which stuff is finally printed is important !!
  202.  for example, when writing a 'include.js" the may not be a "script tag <script>" etc etc
  203. */
  204. fprintf(stdout,"\n<script type=\"text/javascript\">\
  205. if( typeof wims_status === 'undefined' ){ var wims_status = \"$status\";};\
  206. if( typeof use_dragdrop_reply === 'undefined' ){ var use_dragdrop_reply = false;};\
  207. if( typeof canvas_scripts === 'undefined' ){ var canvas_scripts = new Array();};\
  208. canvas_scripts.push(\"%d\");</script>\n\
  209. <!-- canvasdraw div and tooltip placeholder, if needed -->\n\
  210. <div tabindex=\"0\" id=\"canvas_div%d\" style=\"position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\
  211. <div id=\"tooltip_placeholder_div%d\" style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\">\
  212. <span id=\"tooltip_placeholder%d\" style=\"display:none;\">\n</span>\
  213. </div>\n",canvas_root_id,canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id);
  214. fprintf(stdout,"<!-- include actual object code via include file -->\n<script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,getfile_cmd);
  215. fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n\
  216. \"use strict\";\n\
  217. <!-- these variables and functions must be global -->\n\
  218. var read_dragdrop%d;\
  219. var read_canvas%d;\
  220. var set_clock;\
  221. var clear_draw_area%d;\
  222. var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\
  223. var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\
  224. var xsize = %d;\
  225. var ysize = %d;\
  226. var precision = 100;\
  227. var canvas_div = document.getElementById(\"canvas_div%d\");\
  228. 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;};\
  229. 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;};\
  230. 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);};};\
  231. 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);};};\
  232. 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);};};\
  233. 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);};};\
  234. function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
  235. function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
  236. function distance(x1,y1,x2,y2){return parseInt(Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ));};\
  237. 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) ));};\
  238. 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;};\
  239. 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;};\
  240. var x_use_snap_to_grid = 0;var y_use_snap_to_grid = 0;var snap_x = 1;var snap_y = 1;\
  241. function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
  242. function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\
  243. var xlogbase = 10;\
  244. var ylogbase = 10;\
  245. var use_xlogscale = 0;\
  246. var use_ylogscale = 0;\
  247. var x_strings = null;\
  248. var y_strings = null;\
  249. var use_pan_and_zoom = 0;\
  250. var use_jsmath = 0;\
  251. var xstart = 0;\
  252. var ystart = 0;\
  253. var unit_x=\" \";\
  254. var unit_y=\" \";",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);
  255. /* default add the drag code : nearly always used ...*/
  256.   add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
  257.  
  258.             break;
  259.         case XRANGE:
  260.         /*
  261.         @ xrange xmin,xmax
  262.         @ if not given: 0,xsize (eg in pixels)
  263.         */
  264.             for(i = 0 ; i<2; i++){
  265.                 switch(i){
  266.                     case 0: xmin = get_real(infile,0);break;
  267.                     case 1: xmax = get_real(infile,1);break;
  268.                     default: break;
  269.                 }
  270.             }
  271.             if(xmin >= xmax){canvas_error(" xrange is not OK : xmin &lt; xmax !\n");}
  272.             fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax);
  273.             found_size_command++;
  274.             break;
  275.         case YRANGE:
  276.         /*
  277.         @ yrange ymin,ymax
  278.         @ if not given 0,ysize (eg in pixels)
  279.         */
  280.             for(i = 0 ; i<2; i++){
  281.                 switch(i){
  282.                     case 0: ymin = get_real(infile,0);break;
  283.                     case 1: ymax = get_real(infile,1);break;
  284.                     default: break;
  285.                 }
  286.             }
  287.             if(ymin >= ymax){canvas_error(" yrange is not OK : ymin &lt; ymax !\n");}
  288.             fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax);
  289.             found_size_command++;
  290.             break;
  291.         case TRANGE:
  292.         /*
  293.         @ trange tmin,tmax
  294.         @ default -2,2
  295.         */
  296.             use_parametric = TRUE;
  297.             for(i = 0 ; i<2; i++){
  298.                 switch(i){
  299.                     case 0: tmin = get_real(infile,0);break;
  300.                     case 1: tmax = get_real(infile,1);break;
  301.                     default: break;
  302.                 }
  303.             }
  304.             if(tmin >= tmax ){canvas_error(" trange is not OK : tmin &lt; tmax!\n");}
  305.             break;
  306.         case LINEWIDTH:
  307.         /*
  308.         @ linewidth int
  309.         @ default 1
  310.         */
  311.             line_width = (int) (get_real(infile,1));
  312.             break;
  313.         case ARROWHEAD:
  314.         /*
  315.         @ arrowhead int
  316.         @ default 8 (pixels)
  317.         */
  318.             arrow_head = (int) (get_real(infile,1));
  319.             break;
  320.         case CROSSHAIRSIZE:
  321.         /*
  322.         @ crosshairsize int
  323.         @ default 8 (px)
  324.         */
  325.             crosshair_size = (int) (get_real(infile,1));
  326.             break;
  327.         case CROSSHAIR:
  328.         /*
  329.         @ crosshair x,y,color
  330.         @ draw a single crosshair point at (x;y) in color 'color'
  331.         @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
  332.         @ may be set draggable / onclick
  333.         */
  334.             for(i=0;i<3;i++){
  335.                 switch(i){
  336.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  337.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  338.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  339.                         decimals = find_number_of_digits(precision);
  340.                         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));\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);
  341.                         click_cnt++;reset();
  342.                         break;
  343.                     default:break;
  344.                 }
  345.             }
  346.             break;
  347.         case CROSSHAIRS:
  348.         /*
  349.         @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
  350.         @ draw multiple crosshair points at given coordinates in color 'color'
  351.         @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
  352.         @ may be set draggable / onclick individually (!)
  353.         */
  354.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  355.             fill_color = stroke_color;
  356.             i=0;
  357.             while( ! done ){     /* get next item until EOL*/
  358.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  359.                 if(i%2 == 0 ){
  360.                     double_data[i] = get_real(infile,0); /* x */
  361.                 }
  362.                 else
  363.                 {
  364.                     double_data[i] = get_real(infile,1); /* y */
  365.                 }
  366.                 i++;
  367.             }
  368.             decimals = find_number_of_digits(precision);
  369.             for(c=0 ; c < i-1 ; c = c+2){
  370.                 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));\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);
  371.                 click_cnt++;
  372.             }
  373.             reset();
  374.             break;
  375.         case POINT:
  376.         /*
  377.         @ point x,y,color
  378.         @ draw a single point at (x;y) in color 'color'
  379.         @ use command 'linewidth int'  to adust size
  380.         @ may be set draggable / onclick
  381.         @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming)
  382.         */
  383.             for(i=0;i<3;i++){
  384.                 switch(i){
  385.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  386.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  387.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  388.                     decimals = find_number_of_digits(precision);
  389.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
  390.                     click_cnt++;break;
  391.                     default: break;
  392.                 }
  393.             }
  394.             reset();
  395.             break;
  396.         case POINTS:
  397.         /*
  398.         @ points color,x1,y1,x2,y2,...,x_n,y_n
  399.         @ draw multiple points at given coordinates in color 'color'
  400.         @ use command 'linewidth int'  to adust size
  401.         @ may be set draggable / onclick individually (!)
  402.         */
  403.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  404.             fill_color = stroke_color;
  405.             i=0;
  406.             while( ! done ){     /* get next item until EOL*/
  407.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  408.                 if(i%2 == 0 ){
  409.                     double_data[i] = get_real(infile,0); /* x */
  410.                 }
  411.                 else
  412.                 {
  413.                     double_data[i] = get_real(infile,1); /* y */
  414.                 }
  415.                 i++;
  416.             }
  417.             decimals = find_number_of_digits(precision);
  418.             for(c = 0 ; c < i-1 ; c = c+2){
  419.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
  420.                 click_cnt++;
  421.             }
  422.             reset();
  423.             break;
  424.         case SEGMENTS:
  425.         /*
  426.         @ segments color,x1,y1,x2,y2,...,x_n,y_n
  427.         @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color 'color'
  428.         @ use command 'linewidth int'  to adust size
  429.         @ may be set draggable / onclick individually (!)
  430.         */
  431.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  432.             fill_color = stroke_color;
  433.             i=0;
  434.             while( ! done ){     /* get next item until EOL*/
  435.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  436.                 if(i%2 == 0 ){
  437.                     double_data[i] = get_real(infile,0); /* x */
  438.                 }
  439.                 else
  440.                 {
  441.                     double_data[i] = get_real(infile,1); /* y */
  442.                 }
  443.                 i++;
  444.             }
  445.             decimals = find_number_of_digits(precision);
  446.             for(c = 0 ; c < i-1 ; c = c+4){
  447.                 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));\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);
  448.                 click_cnt++;
  449.             }
  450.             reset();
  451.             break;
  452.         case SEGMENT:
  453.         /*
  454.         @ segment x1,y1,x2,y2,color
  455.         @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color'
  456.         @ may be set draggable / onclick
  457.         */
  458.             for(i=0;i<5;i++) {
  459.                 switch(i){
  460.                     case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
  461.                     case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
  462.                     case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
  463.                     case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
  464.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  465.                         decimals = find_number_of_digits(precision);
  466.                         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));\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);
  467.                         click_cnt++;reset();
  468.                         break;
  469.                     default: break;
  470.                 }
  471.             }
  472.             break;
  473.         case LINE:
  474.         /*
  475.         @ line x1,y1,x2,y2,color
  476.         @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
  477.         @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
  478.         @ may be set draggable / onclick
  479.         */
  480.             for(i=0;i<5;i++){
  481.                 switch(i){
  482.                     case 0: double_data[10]= get_real(infile,0);break; /* x-values */
  483.                     case 1: double_data[11]= get_real(infile,0);break; /* y-values */
  484.                     case 2: double_data[12]= get_real(infile,0);break; /* x-values */
  485.                     case 3: double_data[13]= get_real(infile,0);break; /* y-values */
  486.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  487.                     if( double_data[10] == double_data[12] ){ /* vertical line*/
  488.                         double_data[1] = xmin;
  489.                         double_data[3] = ymax;
  490.                         double_data[0] = double_data[10];
  491.                         double_data[2] = double_data[10];
  492.                     }
  493.                     else
  494.                     {
  495.                         if( double_data[11] == double_data[13] ){ /* horizontal line */
  496.                             double_data[1] = double_data[11];
  497.                             double_data[3] = double_data[11];
  498.                             double_data[0] = ymin;
  499.                             double_data[2] = xmax;
  500.                         }
  501.                         else
  502.                         {
  503.                         /* m */
  504.                         double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
  505.                         /* q */
  506.                         double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
  507.  
  508.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  509.  
  510.                             double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
  511.                             double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
  512.                             double_data[0] = xmin;
  513.                             double_data[2] = xmax;
  514.                         }
  515.                     }
  516.                     decimals = find_number_of_digits(precision);
  517.                     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));\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);
  518.                     click_cnt++;reset();
  519.                     break;
  520.                 }
  521.             }
  522.             break;
  523.         case LINES:
  524.         /*
  525.         @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n
  526.         @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color'
  527.         @ 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)
  528.         @ may be set draggable / onclick
  529.         @ <b>Attention</b>: the flydraw command "lines" is equivalent to canvasdraw command "polyline"
  530.         */
  531.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  532.             fill_color = stroke_color;
  533.             i=0;
  534.             while( ! done ){     /* get next item until EOL*/
  535.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  536.                 if(i%2 == 0 ){
  537.                     double_data[i] = get_real(infile,0); /* x */
  538.                 }
  539.                 else
  540.                 {
  541.                     double_data[i] = get_real(infile,1); /* y */
  542.                 }
  543.                 i++;
  544.             }
  545.             decimals = find_number_of_digits(precision);
  546.             for(c = 0 ; c < i-1 ; c = c+4){
  547.                 if( double_data[c] == double_data[c+2] ){ /* vertical line*/
  548.                     double_data[c+1] = xmin;
  549.                     double_data[c+3] = ymax;
  550.                     double_data[c+2] = double_data[c];
  551.                 }
  552.                 else
  553.                 {
  554.                     if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  555.                         double_data[c+3] = double_data[c+1];
  556.                         double_data[c] = ymin;
  557.                         double_data[c+2] = xmax;
  558.                     }
  559.                     else
  560.                     {
  561.                         /* m */
  562.                         double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  563.                         /* q */
  564.                         double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  565.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  566.                         double_data[c+1] = (m)*(xmin)+(q);
  567.                         double_data[c+3] = (m)*(xmax)+(q);
  568.                         double_data[c] = xmin;
  569.                         double_data[c+2] = xmax;
  570.                     }
  571.                 }
  572.                 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));\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);
  573.                 click_cnt++;
  574.             }
  575.             reset();
  576.             break;
  577.         case HALFLINE:
  578.         /*
  579.         @ demiline x1,y1,x2,y2,color
  580.         @ alternative : halfline
  581.         @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex)
  582.         @ may be set draggable / onclick
  583.         */
  584.             for(i=0;i<5;i++){
  585.                 switch(i){
  586.                     case 0: double_data[0]= get_real(infile,0);break; /* x-values */
  587.                     case 1: double_data[1]= get_real(infile,0);break; /* y-values */
  588.                     case 2: double_data[10]= get_real(infile,0);break; /* x-values */
  589.                     case 3: double_data[11]= get_real(infile,0);break; /* y-values */
  590.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  591.                     if(double_data[0] == double_data[10]){ /* vertical halfline */
  592.                         if(double_data[1] < double_data[11]){
  593.                          double_data[3] = ymax + 1000;
  594.                         }
  595.                         else
  596.                         {
  597.                          double_data[3] = ymin - 1000;
  598.                         }
  599.                         double_data[2] = double_data[0];
  600.                     }
  601.                     else
  602.                     { /* horizontal halfline*/
  603.                      if( double_data[1] == double_data[11] ){
  604.                       if( double_data[0] < double_data[10] ){
  605.                         double_data[2] = xmax + 1000; /* halfline to the right */
  606.                       }
  607.                       else
  608.                       {
  609.                         double_data[2] = xmin - 1000; /* halfline to the left */
  610.                       }
  611.                       double_data[3] = double_data[1];
  612.                      }
  613.                      else
  614.                      {
  615.                       /* any other halfline */
  616.                       /* slope */
  617.                       double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
  618.                       /* const */
  619.                       double_data[13] = double_data[1] - double_data[12]*double_data[0];
  620.                       if( double_data[0] < double_data[10] ){
  621.                        double_data[2] = double_data[2] + 1000;
  622.                       }
  623.                       else
  624.                       {
  625.                        double_data[2] = double_data[2] - 1000;
  626.                       }
  627.                       double_data[3] = double_data[12]*double_data[2] + double_data[13];
  628.                      }
  629.                     }    
  630.                     decimals = find_number_of_digits(precision);
  631.                     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));\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);
  632.                     click_cnt++;reset();
  633.                     break;
  634.                 }
  635.             }
  636.        
  637.             break;
  638.         case HLINE:
  639.         /*
  640.         @ hline x,y,color
  641.         @ draw a horizontal line through point (x:y) in color 'color'
  642.         @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
  643.         @ may be set draggable / onclick
  644.         */
  645.             for(i=0;i<3;i++) {
  646.                 switch(i){
  647.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  648.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  649.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  650.                     double_data[3] = double_data[1];
  651.                     decimals = find_number_of_digits(precision);
  652.                     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));\n",click_cnt,onclick,drag_type,decimals,xmin,decimals,xmax,decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
  653.                     click_cnt++;reset();
  654.                     break;
  655.                 }
  656.             }
  657.             break;
  658.         case VLINE:
  659.         /*
  660.         @ vline x,y,color
  661.         @ draw a vertical line through point (x:y) in color 'color'
  662.         @ may be set draggable / onclick
  663.         */
  664.             for(i=0;i<3;i++) {
  665.                 switch(i){
  666.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  667.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  668.                     case 2: stroke_color=get_color(infile,1);/* name or hex color */
  669.                         double_data[2] = double_data[0];
  670.                         decimals = find_number_of_digits(precision);
  671.                         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));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,ymin,decimals,ymax,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
  672.                         click_cnt++;reset();
  673.                     break;
  674.                 }
  675.             }
  676.             break;
  677.         case SQUARE:
  678.         /*
  679.         @ square x,y,side (px) ,color
  680.         @ draw a square with left top corner (x:y) with side 'side' in color 'color'
  681.         @ use command 'fsquare x,y,side,color' for a filled square
  682.         @ use command/keyword  'filled' before command 'square x,y,side,color'
  683.         @ use command 'fillcolor color' before 'fsquare' to set the fill colour.
  684.         @ may be set draggable / onclick
  685.         */
  686.             for(i=0;i<5;i++){
  687.                 switch(i){
  688.                     case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
  689.                     case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
  690.                     case 2:double_data[2] = (int) (get_real(infile,0));break; /* width in px */
  691.                     case 3:
  692.                         stroke_color = get_color(infile,1);/* name or hex color */
  693.                         decimals = find_number_of_digits(precision);
  694.                         double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
  695.                         double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
  696.                         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));\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);
  697.                         click_cnt++;reset();
  698.                         break;
  699.                 }
  700.             }
  701.             break;
  702.         case ROUNDRECT:
  703.         /*
  704.         @ roundrect x1,y1,x2,y2,radius,color
  705.         @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle
  706.         @ use command/keyword  'filled' before command 'roundrect x1,y1,x2,y2,radius,color'
  707.         @ use command 'fillcolor color' before 'froundrect' to set the fill colour.
  708.         @ may be set draggable / onclick
  709.         */
  710.             for(i=0;i<6;i++){
  711.                 switch(i){
  712.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  713.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  714.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  715.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  716.                     case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
  717.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  718.                         /* ensure no inverted roundrect is produced... */
  719.                         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];}
  720.                         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];}
  721.                         decimals = find_number_of_digits(precision);
  722.                         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));\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);
  723.                         click_cnt++;reset();
  724.                     break;
  725.                 }
  726.             }
  727.             break;
  728.         case RECT:
  729.         /*
  730.         @ rect x1,y1,x2,y2,color
  731.         @ use command 'rect x1,y1,x2,y2,color' for a filled rectangle
  732.         @ use command/keyword  'filled' before command 'rect x1,y1,x2,y2,color'
  733.         @ use command 'fillcolor color' before 'frect' to set the fill colour.
  734.         @ may be set draggable / onclick
  735.         */
  736.             for(i=0;i<5;i++){
  737.                 switch(i){
  738.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  739.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  740.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  741.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  742.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  743.                         decimals = find_number_of_digits(precision);
  744.                         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));\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);
  745.                         click_cnt++;reset();
  746.                         break;
  747.                 }
  748.             }
  749.             break;
  750.         case POLYLINE:
  751.         /*
  752.         @ polyline color,x1,y1,x2,y2...x_n,y_n
  753.         @ alternatives:<br />polylines color,x1,y1,x2,y2...x_n,y_n<br />brokenline color,x1,y1,x2,y2...x_n,y_n<br />brokenlines color,x1,y1,x2,y2...x_n,y_n
  754.         @ draw a broken line interconnected between all points (not closed)
  755.         @ equivalent to flydraw command "line color,x1,y1,x2,y2...x_n,y_n"
  756.         @ use command "segments color,x1,y1,x2,y2...x_n,y_n" for not interconnected line segments.
  757.         @ may be set draggable / onclick
  758.         */
  759.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  760.             i=0;
  761.             c=0;
  762.             while( ! done ){     /* get next item until EOL*/
  763.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  764.                 for( c = 0 ; c < 2; c++){
  765.                     if(c == 0 ){
  766.                         double_data[i] = get_real(infile,0);
  767.                         i++;
  768.                     }
  769.                     else
  770.                     {
  771.                         double_data[i] = get_real(infile,1);
  772.                         i++;
  773.                     }
  774.                 }
  775.             }
  776.             /* draw path : not closed & not filled */
  777.             decimals = find_number_of_digits(precision);
  778.             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));\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);
  779.             click_cnt++;reset();
  780.             break;
  781.         case POLY:
  782.         /*
  783.         @ poly color,x1,y1,x2,y2...x_n,y_n
  784.         @ draw closed polygon
  785.         @ use command 'fpoly' to fill it, use command 'fillcolor color' to set the fill color
  786.         @ may be set draggable / onclick
  787.         */
  788.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  789.             i=0;
  790.             c=0;
  791.             while( ! done ){     /* get next item until EOL*/
  792.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  793.                 for( c = 0 ; c < 2; c++){
  794.                     if(c == 0 ){
  795.                         double_data[i] = get_real(infile,0);
  796.                         i++;
  797.                     }
  798.                     else
  799.                     {
  800.                         double_data[i] = get_real(infile,1);
  801.                         i++;
  802.                     }
  803.                 }
  804.             }
  805.             /* draw path :  closed & optional filled */
  806.                 decimals = find_number_of_digits(precision);
  807.                 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));\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);
  808.                 click_cnt++;reset();
  809.             break;
  810.         case ARC:
  811.         /*
  812.          @ arc xc,yc,width,height,start_angle,end_angle,color
  813.          @ can not be set "onclick" or "drag xy"
  814.          @ attention: width == height == radius in pixels
  815.          @ will not zoom in or zoom out (because radius is given in pixels an not in x/y-system !). Panning will work
  816.          @ use command 'angle' for scalable angle
  817.         */
  818.             for(i=0;i<7;i++){
  819.                 switch(i){
  820.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  821.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  822.                     case 2:int_data[0] = (int)(get_real(infile,0));break; /* width in pixels ! */
  823.                     case 3:int_data[1] = (int)(get_real(infile,0));break; /* height in pixels ! */
  824.                     case 4:double_data[2] = get_real(infile,0);break; /* start angle in degrees */
  825.                     case 5:double_data[3] = get_real(infile,0);break; /* end angle in degrees */
  826.                     case 6:stroke_color = get_color(infile,1);/* name or hex color */
  827.                     /* in Shape library:
  828.                         x[0] = x[1] = xc
  829.                         y[0] = y[1] = yc
  830.                         w[0] = w[1] = radius = width = height
  831.                         h[0] = start_angle ; h[1] = end_engle
  832.                     */
  833.                         decimals = find_number_of_digits(precision);
  834.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,12,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],int_data[0],int_data[0],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
  835.                         reset();
  836.                     break;
  837.                 }
  838.             }
  839.             break;
  840.         case ANGLE:
  841.         /*
  842.          @ angle xc,yc,width,start_angle,end_angle,color
  843.          @ width is in x-range
  844.          @ will zoom in/out
  845.          @ if size is controlled by command 'slider' use radians to set limits of slider.
  846.         */
  847.             for(i=0;i<7;i++){
  848.                 switch(i){
  849.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  850.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  851.                     case 2:double_data[2] = get_real(infile,0);break; /* width in pixels ! */
  852.                     case 3:double_data[3] = get_real(infile,0);break; /* start angle in degrees */
  853.                     case 4:double_data[4] = get_real(infile,0);break; /* end angle in degrees */
  854.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  855.                         decimals = find_number_of_digits(precision);
  856.                         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));\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);
  857.                         reset();
  858.                     break;
  859.                 }
  860.             }
  861.             break;
  862.  
  863.         case ELLIPSE:
  864.         /*
  865.         @ ellipse xc,yc,radius_x,radius_y,color
  866.         @ a ellipse with center xc/yc in x/y-range
  867.         @ radius_x and radius_y are in pixels
  868.         @ may be set draggable / onclick
  869.         @ will shrink / expand on zoom out / zoom in
  870.         */
  871.             for(i=0;i<5;i++){
  872.                 switch(i){
  873.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  874.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  875.                     case 2:double_data[2] = get_real(infile,0);break; /* rx -> px  */
  876.                     case 3:double_data[3] = get_real(infile,0);break; /* ry -> px  */
  877.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  878.                         decimals = find_number_of_digits(precision);
  879.                         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));\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);
  880.                         click_cnt++;reset();
  881.                     break;
  882.                 }
  883.             }
  884.             break;
  885.         case DASHTYPE:
  886.         /*
  887.         @ dashtype int ,int
  888.         @ When dashed is set, the objects will be drawn with this dashtyp
  889.         @ default value "dashtype 2,2"
  890.         */
  891.             for(i=0;i<2;i++){
  892.                 switch(i){
  893.                     case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
  894.                     case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
  895.                 }
  896.             }
  897.         break;
  898.         case CIRCLE:
  899.         /*
  900.         @ circle xc,yc,width (2*r in pixels),color
  901.         @ use command 'fcircle xc,yc,d,color' or command 'filled' for a filled disk
  902.         @ use command 'fillcolor color' to set the fillcolor
  903.         @ may be set draggable / onclick
  904.         @ will shrink / expand on zoom out / zoom in
  905.         */
  906.             for(i=0;i<4;i++){
  907.                 switch(i){
  908.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  909.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  910.                     case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out : radius in 'dx' xrange*/
  911.                     case 3: stroke_color = get_color(infile,1);/* name or hex color */
  912.                         decimals = find_number_of_digits(precision);
  913.                         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));\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);
  914.                         click_cnt++;reset();
  915.                         break;
  916.                     default : break;
  917.                 }
  918.             }
  919.             break;
  920.  
  921.         case CIRCLES:
  922.         /*
  923.         @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n
  924.         @ Attention r = radius in x-range (!)
  925.         @ use command 'fillcolor color' to set the fillcolor
  926.         @ may be set draggable / onclick (individually)
  927.         @ will shrink / expand on zoom out / zoom in
  928.         */
  929.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  930.             fill_color = stroke_color;
  931.             i=1;
  932.             while( ! done ){     /* get next item until EOL*/
  933.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  934.                 switch (i%3){
  935.                  case 1:double_data[i-1] = get_real(infile,0);break; /* x */
  936.                  case 2:double_data[i-1] = get_real(infile,0);break; /* y */
  937.                  case 0:double_data[i-1] = get_real(infile,1);break; /* r */
  938.                 }
  939.                 i++;
  940.             }
  941.             decimals = find_number_of_digits(precision);
  942.             for(c = 0 ; c < i-1 ; c = c+3){
  943.                 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));\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);
  944.                 click_cnt++;
  945.             }
  946.             reset();
  947.             break;
  948.         case RAYS:
  949.         /*
  950.          @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
  951.          @ draw rays in color 'color' and center (xc:yc)
  952.          @ may be set draggable or onclick (every individual ray)
  953.         */
  954.             stroke_color=get_color(infile,0);
  955.             fill_color = stroke_color;
  956.             double_data[0] = get_real(infile,0);/* xc */
  957.             double_data[1] = get_real(infile,0);/* yc */
  958.             i=2;
  959.             while( ! done ){     /* get next item until EOL*/
  960.                 if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");}
  961.                 if(i%2 == 0 ){
  962.                     double_data[i] = get_real(infile,0); /* x */
  963.                 }
  964.                 else
  965.                 {
  966.                     double_data[i] = get_real(infile,1); /* y */
  967.                 }
  968.             fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
  969.                 i++;
  970.             }
  971.  
  972.             if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
  973.             decimals = find_number_of_digits(precision);
  974.             for(c=2; c<i;c = c+2){
  975.                 click_cnt++;
  976.                 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));\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);
  977.             }
  978.             reset();
  979.             break;
  980.  
  981.         case ARROWS:
  982.         /*
  983.         @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n
  984.         @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
  985.         @ use command 'linewidth int' to adjust thickness of the arrow
  986.         @ may be set draggable / onclick individually
  987.         */
  988.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  989.             fill_color = stroke_color;
  990.             arrow_head = (int) get_real(infile,0);/* h */
  991.             i=0;
  992.             while( ! done ){     /* get next item until EOL*/
  993.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  994.                 if(i%2 == 0 ){
  995.                     double_data[i] = get_real(infile,0); /* x */
  996.                 }
  997.                 else
  998.                 {
  999.                     double_data[i] = get_real(infile,1); /* y */
  1000.                 }
  1001.                 i++;
  1002.             }
  1003.             decimals = find_number_of_digits(precision);
  1004.             for(c = 0 ; c < i-1 ; c = c+4){
  1005.                 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));\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);
  1006.                 click_cnt++;
  1007.             }
  1008.             reset();
  1009.             break;
  1010.         case ARROW:
  1011.         /*
  1012.         @ arrow x1,y1,x2,y2,h,color
  1013.         @ draw a single headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color'
  1014.         @ use command 'linewidth int' to adjust thickness of the arrow
  1015.         @ may be set draggable / onclick
  1016.         */
  1017.             for(i=0;i<6;i++){
  1018.                 switch(i){
  1019.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  1020.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  1021.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  1022.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  1023.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  1024.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  1025.                         decimals = find_number_of_digits(precision);
  1026.                         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));\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);
  1027.                         click_cnt++;
  1028.                         reset();
  1029.                         break;
  1030.                 }
  1031.             }
  1032.             break;
  1033.         case ARROW2:
  1034.         /*
  1035.         @ arrow2 x1,y1,x2,y2,h,color
  1036.         @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and  in color 'color'
  1037.         @ use command 'arrowhead int' to adjust the arrow head size
  1038.         @ use command 'linewidth int' to adjust thickness of the arrow
  1039.         @ may be set draggable / onclick
  1040.         */
  1041.             for(i=0;i<6;i++){
  1042.                 switch(i){
  1043.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  1044.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  1045.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  1046.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  1047.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  1048.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  1049.                         decimals = find_number_of_digits(precision);
  1050.                         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));\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);
  1051.                         click_cnt++;reset();
  1052.                         break;
  1053.                 }
  1054.             }
  1055.             break;
  1056.         case ARROWS2:
  1057.         /*
  1058.         @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n
  1059.         @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
  1060.         @ use command 'linewidth int' to adjust thickness of the arrows
  1061.         @ may be set draggable / onclick individually
  1062.         */
  1063.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1064.             fill_color = stroke_color;
  1065.             arrow_head = (int) get_real(infile,0);/* h */
  1066.             i=0;
  1067.             while( ! done ){     /* get next item until EOL*/
  1068.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  1069.                 if(i%2 == 0 ){
  1070.                     double_data[i] = get_real(infile,0); /* x */
  1071.                 }
  1072.                 else
  1073.                 {
  1074.                     double_data[i] = get_real(infile,1); /* y */
  1075.                 }
  1076.                 i++;
  1077.             }
  1078.             decimals = find_number_of_digits(precision);
  1079.             for(c = 0 ; c < i-1 ; c = c+4){
  1080.                 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));\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);
  1081.                 click_cnt++;
  1082.             }
  1083.             reset();
  1084.             break;
  1085.         case PARALLEL:
  1086.         /*
  1087.          @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
  1088.          @ can not be set "onclick" or "drag xy"
  1089.         */
  1090.             for( i = 0;i < 8; i++ ){
  1091.                 switch(i){
  1092.                     case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
  1093.                     case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
  1094.                     case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
  1095.                     case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
  1096.                     case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
  1097.                     case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
  1098.                     case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
  1099.                     case 7: stroke_color=get_color(infile,1);/* name or hex color */
  1100.                     decimals = find_number_of_digits(precision);
  1101.                     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));\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);
  1102.                     click_cnt++;reset();
  1103.                     break;
  1104.                     default: break;
  1105.                 }
  1106.             }
  1107.             break;
  1108.         case TRIANGLE:
  1109.         /*
  1110.          @triangle x1,y1,x2,y2,x3,y3,color
  1111.          @may be set draggable / onclic
  1112.         */
  1113.             for(i=0;i<7;i++){
  1114.                 switch(i){
  1115.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  1116.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  1117.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  1118.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  1119.                     case 4: double_data[4] = get_real(infile,0);break; /* x */
  1120.                     case 5: double_data[5] = get_real(infile,0);break; /* y */
  1121.                     case 6: stroke_color = get_color(infile,1);/* name or hex color */
  1122.                         decimals = find_number_of_digits(precision);
  1123.                         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));\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);
  1124.                         click_cnt++;reset();
  1125.                         break;
  1126.                     default: break;
  1127.                 }
  1128.             }
  1129.             break;
  1130.         case LATTICE:
  1131.         /*
  1132.          @lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
  1133.          @can not be set "onclick" or "drag xy"
  1134.         */
  1135.             if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
  1136.             for( i = 0; i<9; i++){
  1137.                 switch(i){
  1138.                     case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
  1139.                     case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
  1140.                     case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
  1141.                     case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
  1142.                     case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
  1143.                     case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
  1144.                     case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
  1145.                     case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
  1146.                     case 8: stroke_color=get_color(infile,1);
  1147.                         decimals = find_number_of_digits(precision);
  1148.                         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);
  1149.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1150.                         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);
  1151.                         add_to_buffer(tmp_buffer);
  1152.                     break;
  1153.                     default:break;
  1154.                 }
  1155.             }
  1156.             reset();
  1157.             break;
  1158.         case SNAPTOGRID:
  1159.         /*
  1160.          @ snaptogrid
  1161.          @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
  1162.          @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
  1163.          @ if xminor / yminor is defined, the drawing will snap to xminor and yminor<br />use only even dividers in x/y-minor...for example<br />snaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br />
  1164.         */
  1165.         fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;");
  1166.         break;
  1167.         case XSNAPTOGRID:
  1168.         /*
  1169.          @ xsnaptogrid
  1170.          @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
  1171.          @ in case of userdraw the drawn points will snap to xmajor grid
  1172.          @ if xminor is defined, the drawing will snap to xminor <br />use only even dividers in x-minor...for example<br />xsnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br />
  1173.         */
  1174.         fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 0;");
  1175.         break;
  1176.         case YSNAPTOGRID:
  1177.         /*
  1178.          @ ysnaptogrid
  1179.          @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
  1180.          @ in case of userdraw the drawn points will snap to ymajor grid
  1181.          @ if yminor is defined, the drawing will snap to yminor <br />use only even dividers in y-minor...for example<br />ysnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br />
  1182.         */
  1183.         fprintf(js_include_file,"\nx_use_snap_to_grid = 0;y_use_snap_to_grid = 1;");
  1184.         break;
  1185.         case USERINPUT:
  1186.         /*
  1187.          @ userinput function | textarea | inputfield
  1188.          @ alternative command + argment to keywords "userinput_function","userinput_textarea" and "userinput_xy"
  1189.          @ textarea and inputfield are only usable in combination with some 'userdraw draw_ type'
  1190.          @ function may be used any time (e.g. without userdraw)
  1191.          @ use command "functionlabel some_string" to define the inputfield text : default value "f(x)="
  1192.          @ use command 'strokecolor some_color' to adjust the plot / functionlabel color
  1193.          @ the userinput for the function will be corrected by a simple 'rawmath' implementation...
  1194.         */
  1195.             temp = get_string_argument(infile,1);
  1196.             if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
  1197.              if( js_function[DRAW_JSFUNCTION] != 1 ){
  1198.               add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */
  1199.               js_function[DRAW_JSFUNCTION] = 1;
  1200.               if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  1201.               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]);
  1202.               input_cnt++;
  1203.              }
  1204.              else
  1205.              {
  1206.               /* no need to add DRAW_JSFUNCTION , just call it with the parameters */
  1207.               fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1208.               input_cnt++;
  1209.              }
  1210.              if( use_js_math == FALSE){/* add this stuff only once...*/
  1211.               add_to_js_math(js_include_file);
  1212.               use_js_math = TRUE;
  1213.              }
  1214.              if( use_js_plot == FALSE){
  1215.               use_js_plot = TRUE;
  1216.               add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  1217.              }
  1218.             }
  1219.             else
  1220.             {
  1221.              if(strstr(temp,"inputfield") != 0 ){
  1222.               if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
  1223.               if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  1224.               use_input_xy = 1;
  1225.              }
  1226.              else
  1227.              {
  1228.               if(strstr(temp,"textarea") != 0 ){
  1229.                if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
  1230.                if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  1231.                use_input_xy = 2;
  1232.               }
  1233.               else
  1234.               {
  1235.                 canvas_error("userinput argument may be \"function,inputfield,textarea\"");
  1236.               }
  1237.              }
  1238.             }
  1239.             break;
  1240.         case USERTEXTAREA_XY:
  1241.         /*
  1242.         @ usertextarea_xy
  1243.         @ keyword
  1244.         @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being...
  1245.         @ if set two textareas are added to the document<br />(one for x-values , one for y-values)
  1246.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  1247.         @ user drawings will not zoom on zooming (or pan on panning)
  1248.         */
  1249.             if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
  1250.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  1251.             use_input_xy = 2;
  1252.             break;
  1253.         case USERINPUT_XY:
  1254.         /*
  1255.         @ userinput_xy
  1256.         @ keyword
  1257.         @ to be used in combination with command "userdraw object_type,color"
  1258.         @ 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)
  1259.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  1260.         @ 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.
  1261.         @ can not be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields
  1262.         @ user drawings will not zoom on zooming (or pan on panning)
  1263.         */
  1264.             /* add simple eval check to avoid code injection with unprotected eval(string) */
  1265.             if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
  1266.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  1267.             use_input_xy = 1;
  1268.             break;
  1269.         case FUNCTION_LABEL:
  1270.         /*
  1271.          @ functionlabel 'some string'
  1272.          @ default value "f(x)="
  1273.          @ no mathml allowed (just ascii string)
  1274.          @ if needed, use before every command 'userinput function | inputfield | textarea'
  1275.         */
  1276.             function_label = get_string_argument(infile,1);
  1277.             break;
  1278.         case USERINPUT_FUNCTION:
  1279.         /*
  1280.         @ userinput_function
  1281.         @ keyword
  1282.         @ if set , a inputfield will be added to the page
  1283.         @ repeat keyword for more function input fields
  1284.         @ the userinput value will be plotted in the canvas
  1285.         @ this value may be read with 'read_canvas()'. <br />for do it yourself js-scripters : If this is the first inputfield in the script, it's id is canvas_input0
  1286.         @ 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
  1287.         @ incompatible with command 'intooltip link_text_or_image' : it uses the tooltip div for adding the inputfield
  1288.         */
  1289.             if( js_function[DRAW_JSFUNCTION] != 1 ){
  1290.              js_function[DRAW_JSFUNCTION] = 1;
  1291.              add_rawmath(js_include_file);
  1292.              if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  1293.              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]);
  1294.              input_cnt++;
  1295.             }
  1296.             else
  1297.             {
  1298.               /* no need to add DRAW_JSFUNCTION , just call it with the parameters */
  1299.              fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1300.              input_cnt++;
  1301.             }
  1302.             if( use_js_math == FALSE){/* add this stuff only once...*/
  1303.              add_to_js_math(js_include_file);
  1304.              use_js_math = TRUE;
  1305.             }
  1306.             if( use_js_plot == FALSE){
  1307.              use_js_plot = TRUE;
  1308.              add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  1309.             }
  1310.             break;
  1311.         case USERDRAW:
  1312.         /*
  1313.         @ userdraw object_type,color
  1314.         @ 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</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]</li><li>rect</li><li>roundrect</li><li>rects</li><li>roundrects</li><li>freehandline</li><li>freehandlines</li><li>path</li><li>paths</li><li>text</li><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>
  1315.         @ 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)
  1316.         @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />while typing the background of every typed char will be lightblue..."backspace / delete / esc" will remove typed text.<br />You will need to hit "enter" to add the text to the array "userdraw_txt()" : lightblue background will disappear<br />Placing the cursor somewhere on a typed text and hitting "delete/backspace/esc" , a confirm will popup asking to delete the selected text.This text will be removed from the "userdraw_txt()" answer array.<br />Use commands 'fontsize' and 'fontfamily' to control the text appearance
  1317.         @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
  1318.         @ note: all objects will be removed -after a javascript confirm box- when clicked on an object point with middle or right mouse butten (e.g. event.which != 1 : all buttons but left)
  1319.         @ use command "filled", "opacity int,int"  and "fillcolor color" to trigger coloured filling of fillable objects
  1320.         @ use command "dashed" and/or "dashtype int,int" to trigger dashing
  1321.         @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas();
  1322.         @ may be combined with onclick or drag xy  of other components of flyscript objects (although not very usefull...)
  1323.         @ may be combined with keyword 'userinput_xy' or
  1324.         @ 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.!
  1325.         */
  1326.             if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
  1327.                 canvas_error("Only one userdraw primitive may be used: read documentation !!");
  1328.             }
  1329.             reply_precision = precision;
  1330.             use_userdraw = TRUE;
  1331.             fprintf(js_include_file,"\n<!-- begin userdraw mouse events -->\nuserdraw_x = new Array();userdraw_y = new Array();userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};if(wims_status != \"done\"){canvas_div.addEventListener(\"mousedown\",user_draw,false);canvas_div.addEventListener(\"mousemove\",user_drag,false);canvas_div.addEventListener(\"touchstart\",user_draw,false);canvas_div.addEventListener(\"touchmove\",user_drag,false);}\n<!-- end userdraw mouse events -->",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
  1332.             draw_type = get_string_argument(infile,0);
  1333.             stroke_color = get_color(infile,1);
  1334.             if( strcmp(draw_type,"point") == 0 ){
  1335.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1336.                 if(reply_format == 0 ){reply_format = 8;}
  1337.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1338.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1339.                 if(use_input_xy == 1){
  1340.                     add_input_circle(js_include_file,1,1);
  1341.                     add_input_xy(js_include_file,canvas_root_id);
  1342.                 }
  1343.                 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);
  1344.             }
  1345.             else
  1346.             if( strcmp(draw_type,"points") == 0 ){
  1347.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1348.                 if(reply_format == 0 ){reply_format = 8;}
  1349.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1350.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1351.                 if(use_input_xy == 1){
  1352.                     add_input_circle(js_include_file,1,2);
  1353.                     add_input_xy(js_include_file,canvas_root_id);
  1354.                 }
  1355.                 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);
  1356.             }
  1357.             else
  1358.             if( strcmp(draw_type,"segment") == 0 ){
  1359.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1360.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  1361.                 if(reply_format == 0){reply_format = 11;}
  1362.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1363.                 if(use_input_xy == 1){
  1364.                     add_input_segment(js_include_file,1);
  1365.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1366.                 }
  1367.                 add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1368.             }
  1369.             else
  1370.             if( strcmp(draw_type,"polyline") == 0 ){
  1371.                 if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
  1372.                 if(reply_format == 0){reply_format = 23;}
  1373.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1374.                 if( use_input_xy == 1 ){
  1375.                     add_input_polyline(js_include_file);
  1376.                     add_input_xy(js_include_file,canvas_root_id);
  1377.                 }
  1378.                 add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1379.             }
  1380.             else
  1381.             if( strcmp(draw_type,"segments") == 0 ){
  1382.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1383.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  1384.                 if(reply_format == 0){reply_format = 11;}
  1385.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1386.                 if(use_input_xy == 1){
  1387.                     add_input_segment(js_include_file,2);
  1388.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1389.                 }
  1390.                 add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1391.             }
  1392.             else
  1393.             if( strcmp(draw_type,"circle") == 0 ){
  1394.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1395.                 if(reply_format == 0){reply_format = 10;}
  1396.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  1397.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1398.                 if(use_input_xy == 1){
  1399.                     add_input_circle(js_include_file,2,1);
  1400.                     add_input_xyr(js_include_file,canvas_root_id);
  1401.                 }
  1402.                 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]);
  1403.             }
  1404.             else
  1405.             if( strcmp(draw_type,"circles") == 0 ){
  1406.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1407.                 if(reply_format == 0){reply_format = 10;}
  1408.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  1409.                 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]);
  1410.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1411.                 if(use_input_xy == 1){
  1412.                     add_input_circle(js_include_file,2,2);
  1413.                     add_input_xyr(js_include_file,canvas_root_id);
  1414.                 }
  1415.             }
  1416.             else
  1417.             if(strcmp(draw_type,"crosshair") == 0 ){
  1418.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  1419.                 if(reply_format == 0){reply_format = 8;}
  1420.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1421.                 add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
  1422.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1423.                 if(use_input_xy == 1){
  1424.                     add_input_crosshair(js_include_file,1);
  1425.                     add_input_xy(js_include_file,canvas_root_id);
  1426.                 }
  1427.             }
  1428.             else
  1429.             if(strcmp(draw_type,"crosshairs") == 0 ){
  1430.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  1431.                 if(reply_format == 0){reply_format = 8;}
  1432.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1433.                 add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
  1434.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1435.                 if(use_input_xy == 1){
  1436.                     add_input_crosshair(js_include_file,2);
  1437.                     add_input_xy(js_include_file,canvas_root_id);
  1438.                 }
  1439.             }
  1440.             else
  1441.             if(strcmp(draw_type,"freehandline") == 0 ){
  1442.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1443.                 if(reply_format == 0){reply_format = 6;}
  1444.                 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]);
  1445.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1446.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1447.             }
  1448.             else
  1449.             if(strcmp(draw_type,"freehandlines") == 0 ){
  1450.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1451.                 if(reply_format == 0){reply_format = 6;}
  1452.                 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]);
  1453.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1454.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1455.             }
  1456.             else
  1457.             if(strcmp(draw_type,"path") == 0 ){
  1458.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1459.                 if(reply_format == 0){reply_format = 6;}
  1460.                 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]);
  1461.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1462.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1463.             }
  1464.             else
  1465.             if(strcmp(draw_type,"paths") == 0 ){
  1466.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1467.                 if(reply_format == 0){reply_format = 6;}
  1468.                 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]);
  1469.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1470.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1471.             }
  1472.             else
  1473.             if(strcmp(draw_type,"arrows") == 0 ){
  1474.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  1475.                 if(reply_format == 0){reply_format = 11;}
  1476.                 add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  1477.                 if(use_input_xy == 1){
  1478.                     add_input_arrow(js_include_file,2);
  1479.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1480.                 }
  1481.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1482.             }
  1483.             else
  1484.             if(strcmp(draw_type,"arrows2") == 0 ){
  1485.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  1486.                 if(reply_format == 0){reply_format = 11;}
  1487.                 add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  1488.                 if(use_input_xy == 1){
  1489.                     add_input_arrow(js_include_file,1);
  1490.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1491.                 }
  1492.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1493.             }
  1494.             else
  1495.             if(strcmp(draw_type,"arrow2") == 0 ){
  1496.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  1497.                 if(reply_format == 0){reply_format = 11;}
  1498.                 add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  1499.                 if(use_input_xy == 1){
  1500.                     add_input_arrow(js_include_file,1);
  1501.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1502.                 }
  1503.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1504.             }
  1505.             else
  1506.             if(strcmp(draw_type,"arrow") == 0 ){
  1507.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  1508.                 if(reply_format == 0){reply_format = 11;}
  1509.                 add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  1510.                 if(use_input_xy == 1){
  1511.                     add_input_arrow(js_include_file,1);
  1512.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1513.                 }
  1514.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1515.             }
  1516.             else
  1517.             if(strcmp(draw_type,"polygon") == 0){
  1518.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1519.                 if(reply_format == 0){reply_format = 2;}
  1520.                 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]);
  1521.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1522.                 if(use_input_xy == 2){
  1523.                   add_textarea_polygon(js_include_file);
  1524.                   add_textarea_xy(js_include_file,canvas_root_id);
  1525.                 }
  1526.             }
  1527.             else
  1528.             if(strncmp(draw_type,"poly",4) == 0){
  1529.                 if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
  1530.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1531.                 if(reply_format == 0){reply_format = 2;}
  1532.                 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]);
  1533.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1534.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1535.             }
  1536.             else
  1537.             if(strcmp(draw_type,"triangle") == 0){
  1538.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1539.                 if(reply_format == 0){reply_format = 2;}
  1540.                 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]);
  1541.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1542.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1543.             }
  1544.             else
  1545.             if( strcmp(draw_type,"hline") == 0 ){
  1546.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1547.                 if(reply_format == 0){reply_format = 11;}
  1548.                 add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1549.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1550.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1551.             }
  1552.             else
  1553.             if( strcmp(draw_type,"hlines") == 0 ){
  1554.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1555.                 if(reply_format == 0){reply_format = 11;}
  1556.                 add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1557.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1558.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1559.             }
  1560.             else
  1561.             if( strcmp(draw_type,"vline") == 0 ){
  1562.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1563.                 if(reply_format == 0){reply_format = 11;}
  1564.                 add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1565.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1566.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1567.             }
  1568.             else
  1569.             if( strcmp(draw_type,"vlines") == 0 ){
  1570.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1571.                 if(reply_format == 0){reply_format = 11;}
  1572.                 add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1573.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1574.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1575.             }
  1576.             else
  1577.             if( strcmp(draw_type,"line") == 0 ){
  1578.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1579.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1580.                 if(reply_format == 0){reply_format = 11;}
  1581.                 add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1582.                 if( use_input_xy == 1 ){
  1583.                     add_input_line(js_include_file,1);
  1584.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1585.                 }
  1586.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1587.             }
  1588.             else
  1589.             if( strcmp(draw_type,"lines") == 0 ){
  1590.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1591.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1592.                 if(reply_format == 0){reply_format = 11;}
  1593.                 add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1594.                 if( use_input_xy == 1 ){
  1595.                     add_input_line(js_include_file,2);
  1596.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1597.                 }
  1598.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1599.             }
  1600.             else
  1601.             if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"demilines") == 0 ){
  1602.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1603.                 if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
  1604.                 if(reply_format == 0){reply_format = 11;}
  1605.                 add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1606.                 if( use_input_xy == 1 ){
  1607.                     add_input_demiline(js_include_file,2);
  1608.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1609.                 }
  1610.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1611.             }
  1612.             else
  1613.             if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"demilines") == 0 ){
  1614.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1615.                 if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
  1616.                 if(reply_format == 0){reply_format = 11;}
  1617.                 add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1618.                 if( use_input_xy == 1 ){
  1619.                     add_input_demiline(js_include_file,1);
  1620.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1621.                 }
  1622.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1623.             }
  1624.             else
  1625.             if( strcmp(draw_type,"rects") == 0){
  1626.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  1627.                 if(reply_format == 0){reply_format = 2;}
  1628.                 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]);
  1629.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1630.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1631.             }
  1632.             else
  1633.             if( strcmp(draw_type,"roundrects") == 0){
  1634.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  1635.                 if(reply_format == 0){reply_format = 2;}
  1636.                 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]);
  1637.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1638.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1639.             }
  1640.             else
  1641.             if( strcmp(draw_type,"rect") == 0){
  1642.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  1643.                 if(reply_format == 0){reply_format = 2;}
  1644.                 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]);
  1645.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1646.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1647.             }
  1648.             else
  1649.             if( strcmp(draw_type,"roundrect") == 0){
  1650.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  1651.                 if(reply_format == 0){reply_format = 2;}
  1652.                 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]);
  1653.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1654.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1655.             }
  1656.             else
  1657.             if( strcmp(draw_type,"arcs") == 0){
  1658.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  1659.                 if(reply_format == 0){reply_format = 25;}
  1660.                 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]);
  1661.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1662.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1663.             }
  1664.             else
  1665.             if( strcmp(draw_type,"arc") == 0){
  1666.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  1667.                 if(reply_format == 0){reply_format = 25;}
  1668.                 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]);
  1669.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1670.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1671.             }
  1672.             else
  1673.             if( strcmp(draw_type,"text") == 0){
  1674.                 if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
  1675.                 if(reply_format == 0){reply_format = 17;}
  1676.                 add_js_text(js_include_file,canvas_root_id,font_size,font_family,font_color,stroke_opacity);
  1677.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1678.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1679.             }
  1680.             else
  1681.             if( strcmp(draw_type,"inputs") == 0){
  1682.                 if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  1683.                 if(reply_format == 0){reply_format = 27;}
  1684.                 add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width);
  1685.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1686.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1687.             }
  1688.             else
  1689.             if( strcmp(draw_type,"input") == 0){
  1690.                 if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  1691.                 if(reply_format == 0){reply_format = 27;}
  1692.                 add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width);
  1693.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1694.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1695.             }
  1696.             else
  1697.             {
  1698.                 canvas_error("unknown drawtype or typo? ");
  1699.             }
  1700.             reset();
  1701.         break;
  1702.         case PLOTSTEPS:
  1703.             /*
  1704.              @ plotsteps a_number
  1705.              @ default 150
  1706.              @ use with care !
  1707.             */
  1708.             plot_steps = (int) (get_real(infile,1));
  1709.             break;
  1710.         case FONTSIZE:
  1711.         /*
  1712.          @fontsize font_size
  1713.          @default value 12
  1714.         */
  1715.             font_size = (int) (get_real(infile,1));
  1716.             break;
  1717.         case FONTCOLOR:
  1718.         /*
  1719.          @fontcolor color
  1720.          @color: hexcolor or colorname
  1721.          @default: black
  1722.          @example usage: x/y-axis text
  1723.         */
  1724.             font_color = get_color(infile,1);
  1725.             break;
  1726.         case ANIMATE:
  1727.         /*
  1728.          @animate type
  1729.          @REMOVED : this should be done with a slider
  1730.          @type may be "point" (nothing else , yet...)
  1731.          @the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber'
  1732.          @will animate a point on the next plot/curve command
  1733.          @the curve will not be draw
  1734.          @moves repeatedly from xmin to xmax
  1735.         */
  1736.             if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");}
  1737.             break;
  1738.         case LEVELCURVE:
  1739.         /*
  1740.         @levelcurve color,expression in x/y,l1,l2,...
  1741.         @draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
  1742.         @the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...)
  1743.         @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
  1744.         @note : the arrays for holding the javascript data are limited in size
  1745.         @note : reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...)
  1746.         */
  1747.             fill_color = get_color(infile,0);
  1748.             char *fun1 = get_string_argument(infile,0);
  1749.             if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  1750.             i = 0;
  1751.             done = FALSE;
  1752.             while( !done ){
  1753.              double_data[i] = get_real(infile,1);
  1754.              i++;
  1755.             }
  1756.             for(c = 0 ; c < i; c++){
  1757.              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));\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);
  1758.              click_cnt++;
  1759.             }
  1760.             reset();
  1761.             break;
  1762.         case TRACE_JSCURVE:
  1763.         /*
  1764.          @trace_jscurve some_math_function
  1765.          @will use a crosshair to trace the jsmath curve
  1766.          @two inputfields will display the current x/y-values (numerical evaluation by javascript)
  1767.          @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
  1768.          @use linewidth,strokecolor,crosshairsize to adjust the corsshair.
  1769.          @the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x in stead 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...
  1770.         */
  1771.             if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  1772.             if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1773.             if( use_js_math == FALSE){
  1774.                 add_to_js_math(js_include_file);
  1775.                 use_js_math = TRUE;
  1776.             }
  1777.             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);
  1778.             break;
  1779.         case JSMATH:
  1780.         /*
  1781.             @jsmath some_math_function
  1782.             @will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
  1783.             @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
  1784.             @example: jsmath sin(x^2)
  1785.             @the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x in stead 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...
  1786.         */
  1787.             if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  1788.             if( use_js_math == FALSE){
  1789.                 add_to_js_math(js_include_file);
  1790.                 use_js_math = TRUE;
  1791.             }
  1792.             add_calc_y(js_include_file,canvas_root_id,get_string(infile,1));
  1793.             break;
  1794.         case JSCURVE:
  1795.         /*
  1796.          @jscurve color,formula(x)
  1797.          @your function will be plotted by the javascript engine of the client browser.
  1798.          @use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e
  1799.          @use parenthesis and rawmath : use 2*x in stead of 2x ; use 2^(sin(x))...etc etc<br />use error console to debug any errors...
  1800.          @Attention : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot !
  1801.          @no validity check is done by wims.
  1802.          @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
  1803.          @use command 'trace_jscurve formula(x)` for tracing
  1804.          @use commmand 'jsmath  formula(x)` for calculating and displaying indiviual points on the curve
  1805.          @can not be set draggable / onclick (yet)
  1806.          @commands plotjump / plotstep are not active for 'jscurve'
  1807.         */
  1808.             stroke_color = get_color(infile,0);
  1809.             if( use_js_math == FALSE){/* add this stuff only once...*/
  1810.                 add_to_js_math(js_include_file);
  1811.                 use_js_math = TRUE;
  1812.             }
  1813.             if( use_js_plot == FALSE){
  1814.                 use_js_plot = TRUE;
  1815.                 add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  1816.             }
  1817.             temp = get_string_argument(infile,1);
  1818.             string_length = snprintf(NULL,0,  "jsplot(%d,\"%s\",%d,\"%s\",%.2f,%d,%d,%d); ",JSPLOT_CANVAS+use_js_plot,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1819.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1820.             snprintf(tmp_buffer,string_length,"jsplot(%d,\"%s\",%d,\"%s\",%.2f,%d,%d,%d); ",JSPLOT_CANVAS+use_js_plot,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1821.             add_to_buffer(tmp_buffer);
  1822.             use_js_plot++; /* we need to create multiple canvasses, so we may zoom and pan ?? */
  1823.  
  1824.         break;
  1825.         case CURVE:
  1826.         /*
  1827.          @curve color,formula(x)
  1828.          @plot color,formula(x)
  1829.          @use command trange before command curve / plot  (trange -pi,pi)<br />curve color,formula1(t),formula2(t)
  1830.          @use command "precision" to increase the number of digits of the plotted points
  1831.          @use command "plotsteps" to increase / decrease the amount of plotted points (default 150)
  1832.          @may be set draggable / onclick
  1833.         */
  1834.             if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
  1835.                 use_parametric = FALSE;
  1836.                 stroke_color = get_color(infile,0);
  1837.                 char *fun1 = get_string_argument(infile,0);
  1838.                 char *fun2 = get_string_argument(infile,1);
  1839.                 if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
  1840.                 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));\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);
  1841.                 click_cnt++;
  1842.             }
  1843.             else
  1844.             {
  1845.                 stroke_color = get_color(infile,0);
  1846.                 char *fun1 = get_string_argument(infile,1);
  1847.                 if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  1848.                 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));\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);
  1849.                 click_cnt++;
  1850.             }
  1851.             animation_type = 9;/* reset to curve plotting without animation */
  1852.             reset();
  1853.             break;
  1854.         case FLY_TEXT:
  1855.         /*
  1856.         @ text fontcolor,x,y,font,text_string
  1857.         @ font may be described by keywords : giant,huge,normal,small,tiny
  1858.         @ use command 'fontsize' to increase base fontsize for these keywords
  1859.         @ may be set "onclick" or "drag xy"
  1860.         @ backwards compatible with flydraw
  1861.         @ unicode supported: text red,0,0,huge,\\u2232
  1862.         @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element
  1863.         @ 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.
  1864.         */
  1865.             for(i = 0; i < 5 ;i++){
  1866.                 switch(i){
  1867.                     case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
  1868.                     case 1: double_data[0] = get_real(infile,0);break; /* x */
  1869.                     case 2: double_data[1] = get_real(infile,0);break; /* y */
  1870.                     case 3: fly_font = get_string_argument(infile,0);
  1871.                             if(strcmp(fly_font,"giant") == 0){
  1872.                                 font_size = (int)(font_size + 24);
  1873.                             }
  1874.                             else
  1875.                             {
  1876.                                 if(strcmp(fly_font,"huge") == 0){
  1877.                                     font_size = (int)(font_size + 14);
  1878.                                 }
  1879.                                 else
  1880.                                 {
  1881.                                     if(strcmp(fly_font,"large") == 0){
  1882.                                         font_size = (int)(font_size + 6);
  1883.                                         }
  1884.                                         else
  1885.                                         {
  1886.                                             if(strcmp(fly_font,"small") == 0){
  1887.                                                 font_size = (int)(font_size - 4);
  1888.                                                 if(font_size<0){font_size = 8;}
  1889.                                         }
  1890.                                     }
  1891.                                 }
  1892.                             }
  1893.                             break; /* font_size ! */
  1894.                     case 4:
  1895.                         temp = get_string_argument(infile,1);
  1896.                         decimals = find_number_of_digits(precision);
  1897.                         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));\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);
  1898.                         click_cnt++;reset();break;
  1899.                     default:break;
  1900.                 }
  1901.             }
  1902.             break;
  1903.         case FLY_TEXTUP:
  1904.         /*
  1905.          @ textup fontcolor,x,y,font,text_string
  1906.          @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
  1907.          @ font may be described by keywords : giant,huge,normal,small,tiny
  1908.          @ use command 'fontsize' to increase base fontsize for the keywords
  1909.          @ backwards compatible with flydraw
  1910.          @ unicode supported: textup red,0,0,huge,\\u2232
  1911.          @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element
  1912.          @ 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.
  1913.         */
  1914.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
  1915.             for(i = 0; i<5 ;i++){
  1916.                 switch(i){
  1917.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  1918.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  1919.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  1920.                     case 3: fly_font = get_string_argument(infile,0);
  1921.                             if(strcmp(fly_font,"giant") == 0){
  1922.                                 font_size = (int)(font_size + 24);
  1923.                             }
  1924.                             else
  1925.                             {
  1926.                                 if(strcmp(fly_font,"huge") == 0){
  1927.                                     font_size = (int)(font_size + 14);
  1928.                                 }
  1929.                                 else
  1930.                                 {
  1931.                                     if(strcmp(fly_font,"large") == 0){
  1932.                                         font_size = (int)(font_size + 6);
  1933.                                         }
  1934.                                         else
  1935.                                         {
  1936.                                             if(strcmp(fly_font,"small") == 0){
  1937.                                                 font_size = (int)(font_size - 4);
  1938.                                                 if(font_size<0){font_size = 8;}
  1939.                                         }
  1940.                                     }
  1941.                                 }
  1942.                             }
  1943.                             break; /* font_size ! */
  1944.                     case 4:
  1945.                     decimals = find_number_of_digits(precision);
  1946.                     temp = get_string_argument(infile,1);
  1947.                     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],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix);
  1948.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1949.                     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],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix);
  1950.                     add_to_buffer(tmp_buffer);
  1951.                     break;
  1952.                     default:break;
  1953.                 }
  1954.             }
  1955.             reset();
  1956.             break;
  1957.         case FONTFAMILY:
  1958.         /*
  1959.          @ fontfamily font_description
  1960.          @ set the font family; for browsers that support it
  1961.          @ font_description: Ariel ,Courier, Helvetica etc
  1962.          @ 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
  1963.          @ use correct syntax : 'font style' 'font size'px 'fontfamily'
  1964.         */
  1965.             font_family = get_string(infile,1);
  1966.             break;
  1967.         case STRINGUP:
  1968.         /*
  1969.          @ stringup color,x,y,rotation_degrees,the text string
  1970.          @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
  1971.          @ unicode supported: stringup red,0,0,45,\\u2232
  1972.          @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change
  1973.  
  1974.         */
  1975.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library : rotate / mouse issues */
  1976.             for(i=0;i<6;i++){
  1977.                 switch(i){
  1978.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  1979.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  1980.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  1981.                     case 3: double_data[0] = get_real(infile,0);break;/* rotation */
  1982.                     case 4: decimals = find_number_of_digits(precision);
  1983.                             temp = get_string_argument(infile,1);
  1984.                             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);
  1985.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1986.                             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);
  1987.                             add_to_buffer(tmp_buffer);
  1988.                             break;
  1989.                     default:break;
  1990.                 }
  1991.             }
  1992.             reset();
  1993.             break;
  1994.         case STRING:
  1995.         /*
  1996.          @ string color,x,y,the text string
  1997.          @ may be set "onclick" or "drag xy"
  1998.          @ unicode supported: string red,0,0,\\u2232
  1999.          @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
  2000.         */
  2001.             for(i=0;i<5;i++){
  2002.                 switch(i){
  2003.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  2004.                     case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
  2005.                     case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
  2006.                     case 3: decimals = find_number_of_digits(precision);
  2007.                         temp = get_string_argument(infile,1);
  2008.                         decimals = find_number_of_digits(precision);
  2009.                         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));\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);
  2010.                         click_cnt++;reset();break;
  2011.                     default:break;
  2012.                 }
  2013.             }
  2014.             break;
  2015.         case CENTERSTRING:
  2016.         /*
  2017.          @ centerstring color,y-value,the text string
  2018.          @ title color,y-value,the text string
  2019.          @ draw a string centered on the canvas at y = y-value
  2020.          @ can not set "onclick" or "drag xy" (...)
  2021.          @ unicode supported: centerstring red,5,\\u2232
  2022.          @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
  2023.         */
  2024.             if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;}
  2025.             for(i=0;i<3;i++){
  2026.                 switch(i){
  2027.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  2028.                     case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
  2029.                     case 2: temp = get_string_argument(infile,1);
  2030.                             /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
  2031.                             decimals = find_number_of_digits(precision);
  2032.                             string_length = snprintf(NULL,0,
  2033.                             "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
  2034.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2035.                             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);
  2036.                             add_to_buffer(tmp_buffer);
  2037.                             break;
  2038.                     default:break;
  2039.                 }
  2040.             }
  2041.             break;
  2042.         case MATHML:
  2043.         /*
  2044.         @ mathml x1,y1,x2,y2,mathml_string
  2045.         @ mathml will be displayed in a rectangle left top (x1:y1) , right bottom (x2:y2)
  2046.         @ can be set onclick <br />(however dragging is not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
  2047.         @ if inputfields are incorporated in mathml (with id's : id='mathml0',id='mathml1',...id='mathml_n')<br />the user_input values will be read by javascript:read_mathml();<br />attention: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();"
  2048.         @ 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....
  2049.  
  2050.         */
  2051.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  2052.             for(i=0;i<5;i++){
  2053.                 switch(i){
  2054.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2055.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2056.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  2057.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  2058.                     case 4: decimals = find_number_of_digits(precision);
  2059.                             if(onclick == 1 ){ onclick = click_cnt;click_cnt++;}
  2060.                             temp = get_string(infile,1);
  2061.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2062.                             string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick);
  2063.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2064.                             snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick);
  2065.                             add_to_buffer(tmp_buffer);
  2066.                             /*
  2067.                              in case inputs are present , trigger adding the read_mathml()
  2068.                              if no other reply_format is defined
  2069.                              note: all other reply types will include a reading of elements with id='mathml'+p)
  2070.                              */
  2071.                             if(strstr(temp,"mathml0") != NULL){
  2072.                              if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
  2073.                             }
  2074.                             break;
  2075.                     default:break;
  2076.                 }
  2077.             }
  2078.             reset();
  2079.             break;
  2080.         case HTTP:
  2081.         /*
  2082.          @http x1,y1,x2,y2,http://some_adress.com
  2083.          @an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2)
  2084.          @do not use interactivity (or mouse) if the mouse needs to be active in the iframe
  2085.          @can not be 'set onclick' or 'drag xy'
  2086.         */
  2087.             if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}
  2088.             for(i=0;i<5;i++){
  2089.                 switch(i){
  2090.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2091.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2092.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  2093.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  2094.                     case 4: decimals = find_number_of_digits(precision);
  2095.                             temp = get_string(infile,1);
  2096.                             if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
  2097.                             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);
  2098.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2099.                             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);
  2100.                             add_to_buffer(tmp_buffer);
  2101.                     break;
  2102.                 }
  2103.             }
  2104.             reset();
  2105.             break;
  2106.         case HTML:
  2107.         /*
  2108.          @ html x1,y1,x2,y2,html_string
  2109.          @ all tags are allowed
  2110.          @ can be set onclick <br />(dragging not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
  2111.          @ if inputfields are incorporated  (with id's : id='mathml0',id='mathml1',...id='mathml_n')<br />the user_input values will be read by javascript:read_canvas(); <br />If other inputfields (command input / command textarea) or userdraw is performed, these values will NOT be read as well.
  2112.  
  2113.          note: uses the same code as 'mathml'
  2114.         */
  2115.             break;
  2116.         case X_AXIS_STRINGS:
  2117.         /*
  2118.          @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  2119.          @ xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  2120.          @ use these x-axis values in stead of default xmin...xmax
  2121.          @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
  2122.          @ if the 'x-axis words' are to big amd will overlap, a simple alternating offset will be applied
  2123.          @ 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
  2124.          @ example:<br />size 400,400<br />xrange -5*pi,5*pi<br />yrange -100,500<br />axis<br />xaxis -4*pi:-4\\u03c0:-3*pi:-3\\u03c0:-2*pi:-2\\u03c0:-1*pi:-\\u03c0:0:0:pi:\\u03c0:2*pi:2\\u03c01:3*pi:3\\u03c0:4*pi:4\\u03c0<br />#'xmajor' steps should be synchronised with numbers eg. "1" in this example<br />grid pi,1,grey,1,3,6,grey
  2125.         */
  2126.             temp = get_string(infile,1);
  2127.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  2128.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  2129.             fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp);
  2130.             use_axis_numbering = 1;
  2131.             break;
  2132.         case Y_AXIS_STRINGS:
  2133.         /*
  2134.          @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  2135.          @ yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  2136.          @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
  2137.          @ use these y-axis values in stead of default ymin...ymax
  2138.          @ 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
  2139.         */
  2140.             temp = get_string(infile,1);
  2141.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  2142.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  2143.             fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
  2144.             use_axis_numbering = 1;
  2145.             break;
  2146.  
  2147.         case AXIS_NUMBERING:
  2148.         /*
  2149.             @ axisnumbering
  2150.             @ keyword, no arguments required
  2151.         */
  2152.             use_axis_numbering = 1;
  2153.             break;
  2154.         case AXIS:
  2155.         /*
  2156.             @ axis
  2157.             @ keyword, no arguments required
  2158.  
  2159.         */
  2160.             use_axis = TRUE;
  2161.             break;
  2162.         case KILLSLIDER:
  2163.         /*
  2164.          @ killslider
  2165.          @ keyword, no arguments required
  2166.          @ ends grouping of object under a preciously defined slider
  2167.         */
  2168.             slider = 0;
  2169.             break;
  2170.         case SLIDER:
  2171.         /*
  2172.         @ slider start_value,end_value,width px,height px,type,label
  2173.         @ type: xy,x,y,angle
  2174.         @ if a value display is desired, use<br />type:xy display,x display,y display,angle radian,angle degree
  2175.         @ is a unit for x / y value display is needed, use commands 'xunit' and / or 'yunit'
  2176.         @ use commmand 'slider' before draggable/clickable objects.
  2177.         @ 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'
  2178.         @ amount of sliders is not limited.
  2179.         @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value'
  2180.         @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page
  2181.         @ every draggable object may have it's own slider (no limit in amount of sliders)
  2182.         @ label: some slider text
  2183.         @ use fillcolor for slider ball
  2184.         @ use strokecolor for slider bar
  2185.         @ use fontfamily / fontcolor to set used fonts
  2186.         @ use opacity (only fill opacity will be used) to set transparency
  2187.         @ the slider canvas will be added to the 'tooltip div' : so incompatible with command tooltip ; setlimits etc
  2188.         */
  2189.             for(i=0; i<6 ; i++){
  2190.                 switch(i){
  2191.                     case 0: double_data[0] = get_real(infile,0);break; /* start value */
  2192.                     case 1: double_data[1] = get_real(infile,0);break; /* end value */
  2193.                     case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
  2194.                     case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
  2195.                     case 4: temp = get_string_argument(infile,0); /* type : xy,x,y,angle */
  2196.                     /* xy display*/
  2197.                     if(strstr(temp,"xy")!= 0){
  2198.                      slider = 4;
  2199.                     }
  2200.                     else
  2201.                     {
  2202.                      if(strstr(temp,"x") != 0){
  2203.                       slider = 1;
  2204.                      }
  2205.                      else
  2206.                      {
  2207.                       if(strstr(temp,"y") != 0){
  2208.                        slider = 2;
  2209.                       }
  2210.                       else
  2211.                       {
  2212.                        if(strstr(temp,"angle") != 0){ /* angle diplay radian */
  2213.                         slider = 3;
  2214.                        }
  2215.                        else
  2216.                        {
  2217.                         canvas_error("slider types may be : x , y , xy , angle");
  2218.                        }
  2219.                       }
  2220.                      }
  2221.                     }
  2222.                     if(strstr(temp,"display")!=0){
  2223.                      use_slider_display = 1; /* show x xy values in canvas window */
  2224.                     }
  2225.                     else
  2226.                     {
  2227.                      if(strstr(temp,"degree")!= 0){
  2228.                       use_slider_display = 2; /* show angle values in canvas window */
  2229.                      }
  2230.                      else
  2231.                      {
  2232.                       if(strstr(temp,"radian")!=0){
  2233.                        use_slider_display = 3; /* show radian values in canvas window */
  2234.                       }
  2235.                      }
  2236.                     }
  2237.                     if(use_slider_display != 0 && slider_cnt == 0){ /*add just once the display js-code */
  2238.                      add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity);
  2239.                     }
  2240.                     break;
  2241.                     case 5: /* some string used for slider description  */
  2242.                     slider_cnt++;
  2243.                     if(slider == 4){
  2244.                      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 );
  2245.                     }else{
  2246.                      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);
  2247.                     }
  2248.                     break;
  2249.                 }
  2250.              }
  2251.             break;
  2252.         case SGRAPH:
  2253.         /*
  2254.          @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
  2255.          @ primitive implementation of a 'broken scale' graph...
  2256.          @ 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 />
  2257.          @ 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
  2258.         */
  2259.             if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
  2260.             for(i = 0 ; i < 8 ;i++){
  2261.                 switch(i){
  2262.                     case 0:double_data[0] = get_real(infile,0);break;
  2263.                     case 1:double_data[1] = get_real(infile,0);break;
  2264.                     case 2:double_data[2] = get_real(infile,0);break;
  2265.                     case 3:double_data[3] = get_real(infile,0);break;
  2266.                     case 4:int_data[0] = (int)(get_real(infile,0));break;
  2267.                     case 5:int_data[1] = (int)(get_real(infile,0));break;
  2268.                     case 6:stroke_color = get_color(infile,0);break;
  2269.                     case 7:font_color = get_color(infile,1);
  2270.                     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);
  2271.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2272.                     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);
  2273.                     add_to_buffer(tmp_buffer);
  2274.                     break;
  2275.                     default:break;
  2276.                 }
  2277.             }
  2278.             /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
  2279.             break;
  2280.         case GRID:/* xmajor,ymajor,color [,xminor,yminor,tick length (px) ,color]*/
  2281.         /*
  2282.          @ grid step_x,step_y,gridcolor
  2283.          @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
  2284.          @ if keywords "axis" or "axisnumbering" are set, use :<br />grid step_x,step_y,major_color,minor_x,minor_y,tics height in px,axis_color<br />minor x step = step_x / minor_x
  2285.          @ 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)
  2286.          @ can not be set "onclick" or "drag xy"
  2287.          @ use commands 'xlabel some_string' and/or 'ylabel some_string' to label axis;<br />use command "fontsize" to adjust size (the font family is non-configurable 'italic your_fontsize px Ariel')
  2288.          @ see commands "xaxis" or "xaxistext", "yaxis" or "yaxistext" to set tailormade values on axis (the used font is set by command fontfamily; default '12px Ariel')
  2289.          @ see command "legend" to set a legend for the graph ;<br />use command "fontsize" to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel')
  2290.         */
  2291.             if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
  2292.             if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
  2293.             for(i=0;i<4;i++){
  2294.                 switch(i){
  2295.                     case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
  2296.                     case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
  2297.                     case 2:
  2298.                     if( use_axis == TRUE ){
  2299.                         stroke_color = get_color(infile,0);
  2300.                         done = FALSE;
  2301.                         int_data[0] = (int) (get_real(infile,0));/* xminor */
  2302.                         int_data[1] = (int) (get_real(infile,0));/* yminor */
  2303.                         int_data[2] = (int) (get_real(infile,0));/* tic_length */
  2304.                         fill_color = get_color(infile,1); /* used as axis_color*/
  2305.                     }
  2306.                     else
  2307.                     {
  2308.                         int_data[0] = 1;
  2309.                         int_data[1] = 1;
  2310.                         stroke_color = get_color(infile,1);
  2311.                         fill_color = stroke_color;
  2312.                     }
  2313.                     if( double_data[0] <= 0 ||  double_data[1] <= 0 ||  int_data[0] <= 0 ||  int_data[1] <= 0 ){canvas_error("major or minor tickt must be positive !");}
  2314.                     /* set snap_x snap_y values in pixels */
  2315.                     fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
  2316.                     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);
  2317.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2318.                     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);
  2319.                     add_to_buffer(tmp_buffer);
  2320.                     break;
  2321.                 }
  2322.             }
  2323.             reset();
  2324.             break;
  2325.         case OPACITY:
  2326.         /*
  2327.         @ opacity 0-255,0-255
  2328.         @
  2329.         */
  2330.             for(i = 0 ; i<2;i++){
  2331.                 switch(i){
  2332.                     case 0: double_data[0]=(int)(get_real(infile,0));break;
  2333.                     case 1: double_data[1]=(int)(get_real(infile,1));break;
  2334.                     default: break;
  2335.                 }
  2336.             }
  2337.             if( double_data[0] < 0 || double_data[0] > 255 || double_data[1] < 0 || double_data[1] > 255  ){ canvas_error("opacity [0 - 255] , [0 - 255]");}/* typo or non-RGB ? */
  2338.             stroke_opacity = (double) (0.0039215*double_data[0]);/* 0.0 - 1.0 */
  2339.             fill_opacity = (double) (0.0039215*double_data[1]);/* 0.0 - 1.0 */
  2340.             break;
  2341.         case ROTATE:
  2342.         /*
  2343.          @rotate rotation_angle
  2344.          @angle in degrees
  2345.         */
  2346.             use_rotate = TRUE;
  2347.             angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */
  2348.             break;
  2349.         case KILLAFFINE:
  2350.         /*
  2351.         @ killaffine
  2352.         @ keyword : resets the transformation matrix to 1,0,0,1,0,0
  2353.         */
  2354.             use_affine = FALSE;
  2355.             snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
  2356.             break;
  2357.         case AFFINE:
  2358.         /*
  2359.          @affine a,b,c,d,tx,ty
  2360.          @ defines a transformation matrix for subsequent objects
  2361.          @ use keyword 'killaffine' to end the transformation
  2362.          @ note 1: only 'draggable' / 'noclick' objects can be transformed.
  2363.          @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet)
  2364.          @ note 3: no matrix operations on the transformation matrix implemented (yet)
  2365.          @ a : Scales the drawings horizontally
  2366.          @ b : Skews the drawings horizontally
  2367.          @ c : Skews the drawings vertically
  2368.          @ d : Scales the drawings vertically
  2369.          @ tx: Moves the drawings horizontally in xrange coordinate system
  2370.          @ ty: Moves the drawings vertically in yrange coordinate system
  2371.          @ the data precision is 2 decimals (printf : %2.f)
  2372.         */
  2373.             for(i = 0 ; i<6;i++){
  2374.                 switch(i){
  2375.                     case 0: double_data[0] = get_real(infile,0);break;
  2376.                     case 1: double_data[1] = get_real(infile,0);break;
  2377.                     case 2: double_data[2] = get_real(infile,0);break;
  2378.                     case 3: double_data[3] = get_real(infile,0);break;
  2379.                     case 4: double_data[4] = get_real(infile,0);break;
  2380.                     case 5: double_data[5] = get_real(infile,1);
  2381.                         use_affine = TRUE;
  2382.                         string_length = snprintf(NULL,0,     "[%.2f,%.2f,%.2f,%.2f,%.2f,%.2f] ",double_data[0],double_data[1],double_data[2],double_data[3],double_data[4]*xsize/(xmax - xmin),-1*double_data[5]*ysize/(ymax - ymin));
  2383.                         check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
  2384.                         snprintf(affine_matrix,string_length,"[%.2f,%.2f,%.2f,%.2f,%.2f,%.2f] ",double_data[0],double_data[1],double_data[2],double_data[3],double_data[4]*xsize/(xmax - xmin),-1*double_data[5]*ysize/(ymax - ymin));
  2385.                         break;
  2386.                     default: break;
  2387.                 }
  2388.             }
  2389.         break;
  2390.         case KILLTRANSLATION:
  2391.         /*
  2392.          killtranslation
  2393.         */
  2394.             use_affine = FALSE;
  2395.             snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
  2396.             break;
  2397.         case TRANSLATION:
  2398.         /*
  2399.          @translation tx,ty
  2400.          @will translate the next object tx in xrange and ty in yrange
  2401.          @uase command 'killtranstation' to end the command
  2402.         */
  2403.             for(i = 0 ; i<2;i++){
  2404.                 switch(i){
  2405.                     case 0: double_data[0] = get_real(infile,0);break;
  2406.                     case 1: double_data[1] = get_real(infile,1);
  2407.                         use_affine = TRUE;
  2408.                         string_length = snprintf(NULL,0, "[1,0,0,1,%.2f,%.2f] ",double_data[0]*xsize/(xmax - xmin),-1*double_data[1]*ysize/(ymax - ymin));
  2409.                         check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
  2410.                         snprintf(affine_matrix,string_length,"[1,0,0,1,%.2f,%.2f] ",double_data[0]*xsize/(xmax - xmin),-1*double_data[1]*ysize/(ymax - ymin));
  2411.                         break;
  2412.                     default: break;
  2413.                 }
  2414.             }
  2415.         break;
  2416.  
  2417.         case DASHED:
  2418.         /*
  2419.         @ keyword "dashed"
  2420.         @ next object will be drawn with a dashed line
  2421.         @ change dashing scheme by using command "dashtype int,int)
  2422.         */
  2423.             use_dashed = TRUE;
  2424.             break;
  2425.         case FILLED:
  2426.         /*
  2427.         @ keyword "filled"
  2428.         @ the next 'fillable' object (only) will be filled
  2429.         @ use command "fillcolor color" to set fillcolor
  2430.         @ use command "opacity 0-255,0-255" to set stroke and fill-opacity
  2431.         @ 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 !
  2432.         */
  2433.             use_filled = TRUE;
  2434.             break;
  2435.         case STYLE:
  2436.         /*
  2437.          @highlight color,opacity,linewidth
  2438.          @ NOT IMPLEMENTED
  2439.          @ use command "onclick" : when the object receives a userclick it will increase it's linewidth
  2440.         */
  2441.             break;
  2442.         case FILLCOLOR:
  2443.         /*
  2444.         @ fillcolor colorname or #hex
  2445.         @ Set the color for a filled object : mainly used for command 'userdraw obj,stroke_color'
  2446.         @ All fillable massive object will have a fillcolor == strokecolor (just to be compatible with flydraw...)
  2447.         */
  2448.             fill_color = get_color(infile,1);
  2449.             break;
  2450.         case STROKECOLOR:
  2451.         /*
  2452.         @ strokecolor colorname or #hex
  2453.         @ to be used for commands that do not supply a color argument (like command 'linegraph')
  2454.         */
  2455.             stroke_color = get_color(infile,1);
  2456.             break;
  2457.         case BGIMAGE:
  2458.         /*
  2459.          @bgimage image_location
  2460.          @use an image as background .<br />(we use the background of 'canvas_div' )
  2461.          @the background image will be resized to match "width = xsize" and "height = ysize"
  2462.         */
  2463.         URL = get_string(infile,1);
  2464.         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);
  2465.             break;
  2466.         case BGCOLOR:
  2467.         /*
  2468.          @bgcolor colorname or #hex
  2469.          @use this color as background of the "div" containing the canvas(es)
  2470.         */
  2471.         /* [255,255,255]*/
  2472.             bgcolor = get_string(infile,1);
  2473.             if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
  2474.                 int found = 0;
  2475.                 for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  2476.                     if( strcmp( colors[i].name , bgcolor ) == 0 ){
  2477.                         bgcolor = colors[i].hex;
  2478.                         found = 1;
  2479.                         break;
  2480.                     }
  2481.                 }
  2482.                 if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");}
  2483.             }
  2484.             fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
  2485.             break;
  2486.         case COPY:
  2487.         /*
  2488.         @ copy x,y,x1,y1,x2,y2,[filename URL]
  2489.         @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
  2490.         @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
  2491.         @ [filename] is the URL of the image
  2492.         @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
  2493.         @ if command 'drag x/y/xy' is set before command 'copy', the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valuid for the next image<br />draggable / non-draggable images may be mixed
  2494.         @ if you want to draw / userdraw  on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent
  2495.  
  2496.         context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  2497.         draw_external_image(canvas_type,URL,sx,sy,swidth,sheight,x,y,width,height,drag_drop){
  2498.         */
  2499.             for(i = 0 ; i<7;i++){
  2500.                 switch(i){
  2501.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
  2502.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
  2503.                     case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
  2504.                     case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
  2505.                     case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
  2506.                     case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
  2507.                     case 6: URL = get_string(infile,1);
  2508.                             int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
  2509.                             int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
  2510.                             if( drag_type > -1 ){
  2511.                                 if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
  2512.                                 if(reply_format == 0 ){reply_format = 20;}
  2513.                                 string_length = snprintf(NULL,0,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,1);
  2514.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2515.                                 snprintf(tmp_buffer,string_length,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,1);
  2516.                                 drag_type = -1;
  2517.                                 ext_img_cnt++;
  2518.                             }
  2519.                             else
  2520.                             {
  2521.                                 if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  2522.                                 /*
  2523.                                 draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\n\
  2524.                                 */
  2525.                                 string_length = snprintf(NULL,0,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7]);
  2526.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2527.                                 snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7]);
  2528.                             }
  2529.                             add_to_buffer(tmp_buffer);
  2530.                             break;
  2531.                     default: break;
  2532.                 }
  2533.             }
  2534.             reset();
  2535.             break;
  2536. /*
  2537. context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  2538. img     Specifies the image, canvas, or video element to use
  2539. sx      The x coordinate where to start clipping : x1 = int_data[0]
  2540. sy      The y coordinate where to start clipping : x2 = int_data[1]
  2541. swidth  The width of the clipped image : int_data[2] - int_data[0]
  2542. sheight The height of the clipped image : int_data[3] - int_data[1]
  2543. x       The x coordinate where to place the image on the canvas : dx1 = int_data[4]
  2544. y       The y coordinate where to place the image on the canvas : dy1 = int_data[5]
  2545. width   The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6]
  2546. height  The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7]
  2547. */
  2548.         case COPYRESIZED:
  2549.         /*
  2550.         @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
  2551.         @ 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
  2552.         @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
  2553.         @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
  2554.         @ if command 'drag x/y/xy' is set before command 'copy', the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valuid for the next image<br />draggable / non-draggable images may be mixed
  2555.         @ if you want to draw / userdraw  on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent
  2556.         */
  2557.             for(i = 0 ; i<9;i++){
  2558.                 switch(i){
  2559.                     case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
  2560.                     case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
  2561.                     case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
  2562.                     case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
  2563.                     case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
  2564.                     case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
  2565.                     case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
  2566.                     case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
  2567.                     case 8: URL = get_string(infile,1);
  2568.                             if( drag_type > -1 ){
  2569.                                 if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
  2570.                                 if(reply_format == 0 ){reply_format = 20;}
  2571.                                 string_length = snprintf(NULL,0,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,1);
  2572.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2573.                                 snprintf(tmp_buffer,string_length,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,1);
  2574.                                 drag_type = -1;
  2575.                                 ext_img_cnt++;
  2576.                             }
  2577.                             else
  2578.                             {
  2579.                                 if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  2580.                                 string_length = snprintf(NULL,0,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7]);
  2581.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2582.                                 snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7]);
  2583.                             }
  2584.                             add_to_buffer(tmp_buffer);
  2585.                     default: break;
  2586.                 }
  2587.             }
  2588.             reset();
  2589.             break;
  2590.         case CLEARBUTTON:
  2591.         /*
  2592.          @clearbutton value
  2593.          @adds a button to clear the userdraw canvas with text 'value'
  2594.          @normally userdraw 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
  2595.          @uses the tooltip placeholder div element: may not be used with command 'intooltip'
  2596.          @use command 'inputstyle' to style the button...
  2597.         */
  2598.             add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1));
  2599.         break;
  2600.         case INPUTSTYLE:
  2601.         /*
  2602.         @ inputstyle style_description
  2603.         @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt
  2604.         */
  2605.             input_style = get_string(infile,1);
  2606.             break;
  2607.         case INPUT:
  2608.         /*
  2609.          @ input x,y,size,editable,value
  2610.          @ to set inputfield "readonly", use editable = 0
  2611.          @ only active inputfields (editable = 1) will be read with read_canvas();
  2612.          @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be clearedand set readonly<br />Override this by keyword 'status'
  2613.          @ may be further controlled by "inputstyle" (inputcss is not yet implemented...)
  2614.          @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
  2615.         */
  2616.         if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  2617.             for(i = 0 ; i<5;i++){
  2618.                 switch(i){
  2619.                     case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
  2620.                     case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
  2621.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
  2622.                     case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
  2623.                     case 4:
  2624.                             temp = get_string_argument(infile,1);
  2625.                             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);
  2626.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2627.                             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);
  2628.                             add_to_buffer(tmp_buffer);
  2629.                             input_cnt++;break;
  2630.                     default: break;
  2631.                 }
  2632.             }
  2633.             if(reply_format == 0 ){reply_format = 15;}
  2634.             reset();
  2635.             break;
  2636.         case TEXTAREA:
  2637.         /*
  2638.          @ textarea x,y,cols,rows,readonly,value
  2639.          @ may be further controlled by "inputstyle"
  2640.          @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be clearedand set readonly<br />Override this by keyword 'status'
  2641.          @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
  2642.         */
  2643.             if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}
  2644.             for(i = 0 ; i<6;i++){
  2645.                 switch(i){
  2646.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
  2647.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
  2648.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
  2649.                     case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
  2650.                     case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
  2651.                     case 5: temp = get_string_argument(infile,1);
  2652.                             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);
  2653.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2654.                             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);
  2655.                             add_to_buffer(tmp_buffer);
  2656.                             input_cnt++;break;
  2657.                     default: break;
  2658.                 }
  2659.             }
  2660.             if(reply_format == 0 ){reply_format = 15;}
  2661.             reset();
  2662.             break;
  2663.         case MOUSE_PRECISION:
  2664.         /*
  2665.             @ precision int
  2666.             @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
  2667.             @ may be used / changed before every object
  2668.             @ In case of user interaction (like 'userdraw') this value will be used to determine the amount of decimals in the reply / answer
  2669.         */
  2670.             precision = (int) (get_real(infile,1));
  2671.             if(precision < 1 ){precision = 1;};
  2672.             break;
  2673.         case SETLIMITS:
  2674.         /*
  2675.             @setlimits
  2676.             @keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button
  2677.             @may be used for inputfield based zooming / panning
  2678.             @use command xlabel / ylabel to change text from xmin to 'xlabel'min etc
  2679.             @note:the input value will not be checked on validity
  2680.         */
  2681.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  2682.             add_setlimits(js_include_file,canvas_root_id);
  2683.             /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
  2684.             use_pan_and_zoom = TRUE;
  2685.             done = TRUE;
  2686.             break;
  2687.         case ZOOM:
  2688.         /*
  2689.          @ zoom button_color
  2690.          @ introduce a controlpanel at the lower right corner
  2691.          @ giving six 15x15pixel 'active' rectangle areas<br />(for x,leftarrow,rightarrow,uparrow,downarrow and a '-' and a '+' sign ) for zooming and/or panning of the image
  2692.          @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings.
  2693.          @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible
  2694.          @ command 'opacity' may be used to set stroke_opacity of 'buttons
  2695.          @ NOTE: use command 'zoom' at the end of your script code (the same is true for commanmd 'mouse')
  2696.          @ NOTE: only objects that may be set draggable / clickable will be zoomed / panned
  2697.          @ 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 !!
  2698.         */
  2699.             fprintf(js_include_file,"use_pan_and_zoom = 1;");
  2700.             use_pan_and_zoom = TRUE;
  2701.             stroke_color = get_color(infile,1);
  2702.             /* we use BG_CANVAS (0) */
  2703.             add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
  2704.             done = TRUE;
  2705.             break;
  2706.         case ONCLICK:
  2707.         /*
  2708.          @ onclick
  2709.          @ keyword, no arguments
  2710.          @ if the next object is clicked, it's 'object sequence number' in fly script is returned <br /> by javascript:read_canvas();
  2711.          @ Line based object will show an increase in linewidth<br />Font based objects will show the text in 'bold' when clicked.
  2712.          @ NOTE: not all objects may be set clickable
  2713.         */
  2714.             fprintf(js_include_file,"use_dragdrop_reply = true;");
  2715.             onclick = 1;
  2716.             break;
  2717.         case DRAG:
  2718.         /*
  2719.          @ drag [x][y][xy]
  2720.          @ the next object will be draggable in x / y / xy direction
  2721.          @ the displacement can be read by 'javascript:read_dragdrop();'
  2722.          @ the precision (default 2 decimals) in the student reply may be set with command 'precision'.<br />Use this 'precision' command before this command 'drag x|y|xy' !
  2723.          @ the answer is  : object_number : Xorg : Yorg : Xnew : Ynew<br />wherein object_number is the place of the draggable object in your script.<br />Only draggable object will have an object_number (e.g things like point,crosshair,line,segment,circle,rect,triangle...etc)
  2724.          @ use keywordd 'snaptogrid' , 'xsnaptogrid' or 'ysnaptogrid' to switch from free to discrete movement
  2725.          @ 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.
  2726.          @ 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 !!
  2727.         */
  2728.             temp = get_string(infile,1);
  2729.             if(strstr(temp,"xy") != NULL ){
  2730.                 drag_type = 0;
  2731.             }
  2732.             else
  2733.             {
  2734.                 if(strstr(temp,"x") != NULL ){
  2735.                     drag_type = 1;
  2736.                 }
  2737.                 else
  2738.                 {
  2739.                     drag_type = 2;
  2740.                 }
  2741.             }
  2742.             fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;",precision);
  2743.             onclick = 2;
  2744.        
  2745.             /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
  2746.             break;
  2747.         case BLINK:
  2748.         /*
  2749.          @ blink time(seconds)
  2750.          @ NOT IMPLEMETED -YET
  2751.         */
  2752.             break;
  2753.         case XUNIT:
  2754.         /*
  2755.          @ xunit some_unit_for_x-values
  2756.          @ unicode allowed (no html code)
  2757.          @ use together with command mousex
  2758.          @ will display the cursor x-coordinate 'unit'
  2759.         */
  2760.             fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
  2761.             break;
  2762.         case YUNIT:
  2763.         /*
  2764.          @ yunit some_unit_for_y-values
  2765.          @ unicode allowed (no html code)
  2766.          @ use together with command mousex
  2767.          @ will display the cursor y-coordinate 'unit'
  2768.         */
  2769.             fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
  2770.             break;
  2771.         case MOUSE_DISPLAY:
  2772.         /*
  2773.          @display x|y|xy|degree|radius,color,fontsize
  2774.          @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 ( rhe angle between x-axis;(0:0);(x:y)
  2775.          @use commands 'xunit' and / or 'yunit' to add the units to the mouse values
  2776.          @just like commands 'mouse','mousex','mousey','mouse_degree'...only other name)
  2777.         */
  2778.         temp = get_string_argument(infile,0);
  2779.         if( strstr(temp,"xy") != NULL ){
  2780.             int_data[0] = 2;
  2781.         }else{
  2782.             if( strstr(temp,"y") != NULL ){
  2783.                 int_data[0] = 1;
  2784.             }else{
  2785.                 if( strstr(temp,"x") != NULL ){
  2786.                     int_data[0] = 0;
  2787.                 }else{
  2788.                     if(strstr(temp,"degree") != NULL){
  2789.                         int_data[0] = 3;
  2790.                     }else{
  2791.                         if(strstr(temp,"radius") != NULL){
  2792.                             int_data[0] = 4;
  2793.                         }else{
  2794.                             int_data[0] = 2;
  2795.                         }
  2796.                     }
  2797.                 }
  2798.             }
  2799.         }
  2800.         stroke_color = get_color(infile,0);
  2801.         font_size = (int) (get_real(infile,1));
  2802.         tmp_buffer = my_newmem(26);
  2803.         snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2804.         add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
  2805.         break;
  2806.         case MOUSE_DEGREE:
  2807.         /*
  2808.          @ mouse_degree color,fontsize
  2809.          @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in 'color' and 'font size'<br /> using default fontfamily Ariel
  2810.          @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
  2811.          @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2812.  
  2813.         */
  2814.             stroke_color = get_color(infile,0);
  2815.             font_size = (int) (get_real(infile,1));
  2816.             tmp_buffer = my_newmem(26);
  2817.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2818.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
  2819.             break;
  2820.         case MOUSEX:
  2821.         /*
  2822.          @ mousex color,fontsize
  2823.          @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
  2824.          @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2825.  
  2826.         */
  2827.             stroke_color = get_color(infile,0);
  2828.             font_size = (int) (get_real(infile,1));
  2829.             tmp_buffer = my_newmem(26);
  2830.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2831.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
  2832.             break;
  2833.         case MOUSEY:
  2834.         /*
  2835.          @ mousey color,fontsize
  2836.          @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
  2837.          @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2838.  
  2839.         */
  2840.             stroke_color = get_color(infile,0);
  2841.             font_size = (int) (get_real(infile,1));
  2842.             tmp_buffer = my_newmem(26);
  2843.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2844.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
  2845.             break;
  2846.         case MOUSE:
  2847.         /*
  2848.          @ mouse color,fontsize
  2849.          @ will display the cursor (x:y) coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
  2850.          @ NOTE: use command 'mouse' at the end of your script code (the same is true for commanmd 'zoom')
  2851.  
  2852.         */
  2853.             stroke_color = get_color(infile,0);
  2854.             font_size = (int) (get_real(infile,1));
  2855.             tmp_buffer = my_newmem(26);
  2856.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2857.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
  2858.             break;
  2859.         case INTOOLTIP:
  2860.             /*
  2861.             @ intooltip link_text
  2862.             @ link_text is a single line (span-element)
  2863.             @ link_text may also be an image URL http://some_server/images/my_image.png
  2864.             @ link_text may contain HTML markup
  2865.             @ the canvas will be displayed in a tooltip on 'link_text'
  2866.             @ the canvas is default transparent: use command 'bgcolor color' to adjust background-color<br />the link test will alos be shown with this bgcolor.
  2867.             */
  2868.             if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy command");}
  2869.             use_tooltip = TRUE;
  2870.             tooltip_text = get_string(infile,1);
  2871.             if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
  2872.             break;
  2873.         case AUDIO:
  2874.         /*
  2875.         @ audio x,y,w,h,loop,visible,audiofile location
  2876.         @ x,y : left top corner of audio element (in xrange / yrange)
  2877.         @ w,y : width and height in pixels
  2878.         @ loop : 0 or 1 ( 1 = loop audio fragment)
  2879.         @ visible : 0 or 1 (1 = show controls)
  2880.         @ audio format may be in *.mp3 or *.ogg
  2881.         @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format)
  2882.         @ if you are using *.ogg : be aware that Microsoft based systems not support it natively
  2883.         @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
  2884.         @ 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 />
  2885.         */
  2886.             if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
  2887.             for(i=0;i<7;i++){
  2888.                 switch(i){
  2889.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  2890.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  2891.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  2892.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  2893.                     case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
  2894.                     case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
  2895.                     case 6:
  2896.                     temp = get_string(infile,1);
  2897.                     if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
  2898.                     if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
  2899.                     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);
  2900.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2901.                     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);
  2902.                     add_to_buffer(tmp_buffer);
  2903.                     break;
  2904.                     default:break;
  2905.                 }
  2906.             }
  2907.             reset();
  2908.             break;
  2909.         case VIDEO:
  2910.         /*
  2911.         @ video x,y,w,h,videofile location
  2912.         @ x,y : left top corner of audio element (in xrange / yrange)
  2913.         @ w,y : width and height in pixels
  2914.         @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4
  2915.         @ video format may be in *.mp4 (todo:other formats)
  2916.         */
  2917.             if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
  2918.             for(i=0;i<5;i++){
  2919.                 switch(i){
  2920.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  2921.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  2922.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  2923.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  2924.                     case 4: temp = get_string(infile,1);
  2925.                             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);
  2926.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2927.                             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);
  2928.                             add_to_buffer(tmp_buffer);
  2929.                             break;
  2930.                     default:break;
  2931.                 }
  2932.             }
  2933.             reset();
  2934.             break;
  2935.         case HATCHFILL:
  2936.         /*
  2937.         @ hatchfill x0,y0,dx,dy,color
  2938.         @ x0,y0 in xrange / yrange
  2939.         @ distances dx,dy in pixels
  2940.         */
  2941.             if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
  2942.             for(i=0;i<5;i++){
  2943.                 switch(i){
  2944.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2945.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2946.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2947.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2948.                     case 4: stroke_color = get_color(infile,1);
  2949.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2950.                     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);
  2951.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2952.                     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);
  2953.                     add_to_buffer(tmp_buffer);
  2954.                     break;
  2955.                     default:break;
  2956.                 }
  2957.             }
  2958.             reset();
  2959.         break;
  2960.         case DIAMONDFILL:
  2961.         /*
  2962.         @ diamondfill x0,y0,dx,dy,color
  2963.         @ x0,y0 in xrange / yrange
  2964.         @ distances dx,dy in pixels
  2965.         */
  2966.             if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
  2967.             for(i=0;i<5;i++){
  2968.                 switch(i){
  2969.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2970.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2971.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2972.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2973.                     case 4: stroke_color = get_color(infile,1);
  2974.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2975.                     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);
  2976.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2977.                     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);
  2978.                     add_to_buffer(tmp_buffer);
  2979.                     break;
  2980.                     default:break;
  2981.                 }
  2982.             }
  2983.             reset();
  2984.         break;
  2985.         case GRIDFILL:
  2986.         /*
  2987.         @ gridfill x0,y0,dx,dy,color
  2988.         @ x0,y0 in xrange / yrange
  2989.         @ distances dx,dy in pixels
  2990.         @ a draggable object may snap_to_grid (using keywords xysnaptogrid,xsnaprogrid, ysnaptogrid)
  2991.         @ userdraw object may snap_to_grid
  2992.         */
  2993.             if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
  2994.             for(i=0;i<5;i++){
  2995.                 switch(i){
  2996.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2997.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2998.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2999.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  3000.                     case 4: stroke_color = get_color(infile,1);
  3001.                     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);
  3002.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3003.                     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);
  3004.                     add_to_buffer(tmp_buffer);
  3005.                     break;
  3006.                     default:break;
  3007.                 }
  3008.             }
  3009.             reset();
  3010.         break;
  3011.         case DOTFILL:
  3012.         /*
  3013.         @ dotfill x0,y0,dx,dy,color
  3014.         @ x0,y0 in xrange / yrange
  3015.         @ distances dx,dy in pixels
  3016.         @ radius of dots is linewidth
  3017.         */
  3018.             if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
  3019.             for(i=0;i<5;i++){
  3020.                 switch(i){
  3021.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  3022.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  3023.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  3024.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  3025.                     case 4: stroke_color = get_color(infile,1);
  3026.                     /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
  3027.                     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);
  3028.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3029.                     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);
  3030.                     add_to_buffer(tmp_buffer);
  3031.                     break;
  3032.                     default:break;
  3033.                 }
  3034.             }
  3035.             reset();
  3036.         break;
  3037.         case IMAGEFILL:
  3038.         /*
  3039.         @ imagefill dx,dy,image_url
  3040.         @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
  3041.         @ After pattern filling ,the fill-color should be reset !
  3042.         @ wims getins / image from class directory : imagefill 80,80,my_image.gif
  3043.         @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif
  3044.         @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg
  3045.         @ if dx,dy is larger than the image, the whole image will be background to the next object.
  3046.         */
  3047.             if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
  3048.             for(i=0 ;i < 3 ; i++){
  3049.                 switch(i){
  3050.                     case 0:int_data[0] = (int) (get_real(infile,0));break;
  3051.                     case 1:int_data[1] = (int) (get_real(infile,0));break;
  3052.                     case 2: URL = get_string_argument(infile,1);
  3053.                             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);
  3054.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3055.                             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);
  3056.                             add_to_buffer(tmp_buffer);
  3057.                     break;
  3058.                 }
  3059.             }
  3060.             reset();
  3061.         break;
  3062.         case FILLTOBORDER:
  3063.         /*
  3064.         @ filltoborder x,y,bordercolor,color
  3065.         @ fill the region  of point (x:y) bounded by 'bordercolor' with color 'color'
  3066.         @ any other color will not act as border to the bucket fill
  3067.         @ use this command  after all boundary objects are declared.
  3068.         @ 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..
  3069.         */
  3070.             for(i=0 ;i < 4 ; i++){
  3071.                 switch(i){
  3072.                     case 0:double_data[0] = get_real(infile,0);break;
  3073.                     case 1:double_data[1] = get_real(infile,0);break;
  3074.                     case 2:bgcolor = get_color(infile,0);break;
  3075.                     case 3:fill_color = get_color(infile,1);
  3076.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  3077.                                 js_function[DRAW_FILLTOBORDER] = 1;
  3078.                                 add_js_filltoborder(js_include_file,canvas_root_id);
  3079.                            }
  3080.                            decimals = find_number_of_digits(precision);
  3081.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  3082.                            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));
  3083.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3084.                            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));
  3085.                            add_to_buffer(tmp_buffer);
  3086.                            break;
  3087.                     default:break;
  3088.                 }
  3089.             }
  3090.             reset();
  3091.         break;
  3092.         case FLOODFILL:
  3093.         /*
  3094.         @ floodfill x,y,color
  3095.         @ alternative syntax: fill x,y,color
  3096.         @ fill the region of point (x:y) with color 'color'
  3097.         @ any other color or size of picture (borders of picture) will act as border to the bucket fill
  3098.         @ use this command  after all boundary objects are declared.
  3099.         @ Use command 'clickfill,color' for user click driven flood fill.
  3100.         @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
  3101.         @ 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..
  3102.         */
  3103.             for(i=0 ;i < 4 ; i++){
  3104.                 switch(i){
  3105.                     case 0:double_data[0] = get_real(infile,0);break;
  3106.                     case 1:double_data[1] = get_real(infile,0);break;
  3107.                     case 2:fill_color = get_color(infile,1);
  3108.                            if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
  3109.                                 js_function[DRAW_FLOODFILL] = 1;
  3110.                                 add_js_floodfill(js_include_file,canvas_root_id);
  3111.                            }
  3112.                            decimals = find_number_of_digits(precision);/*floodfill(interaction,x,y,[R,G,B,A]) */
  3113.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  3114.                            string_length = snprintf(NULL,0,  "setTimeout(function(){floodfill(0,%.*f,%.*f,[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215));
  3115.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3116.                            snprintf(tmp_buffer,string_length,"setTimeout(function(){floodfill(0,%.*f,%.*f,[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215));
  3117.                            add_to_buffer(tmp_buffer);
  3118.                            break;
  3119.                     default:break;
  3120.                 }
  3121.             }
  3122.             reset();
  3123.         break;
  3124.         case CLICKFILLMARGE:
  3125.             clickfillmarge = (int) (get_real(infile,1));
  3126.             break;
  3127.         /*
  3128.         @ clickfillmarge int
  3129.         @ default 20 (pixels)
  3130.         @ when using command "clickfill fillcolor" a coloured area my be reverted ("undo") <br />back to background colour with a middle mouse click<br />when the click is in a 40x40 rectangle around a stored m mouseclick (userdraw_x[] and userdraw_y[])
  3131.         */
  3132.         case CLICKFILL:
  3133.         /*
  3134.         @ clickfill fillcolor
  3135.         @ user left mouse click will floodfill the area with fillcolor
  3136.         @ multiple areas may be coloured
  3137.         @ the coloured areas can be removed (changed to "bgcolor") by  middle / right mouse click <br />(if the click is in an 40x40 pixel area of the click coordinate that "painted" the area)
  3138.         @ the answer will be read as the (x:y) click coordinates per coloured area
  3139.         @ background color of main div may be set by using command "bgcolor color"
  3140.         @ may not be combined with command "userdraw"
  3141.         @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
  3142.         */
  3143.          fill_color = get_color(infile,1);
  3144.          if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
  3145.             js_function[DRAW_FLOODFILL] = 1;
  3146.             add_js_floodfill(js_include_file,canvas_root_id);
  3147.          }
  3148.          fprintf(js_include_file,"\n<!-- begin command clickfill -->\nvar marge_xy = %d;userdraw_x = new Array();userdraw_y = new Array();var user_clickfill_cnt = 0;\ncanvas_div.addEventListener(\"mousedown\",clickfill,false);function clickfill(evt){var x = evt.clientX - findPosX(canvas_div) + document.body.scrollLeft + document.documentElement.scrollLeft;var y = evt.clientY - findPosY(canvas_div) + document.body.scrollTop + document.documentElement.scrollTop;if(evt.which != 1){for(var p=0; p < user_clickfill_cnt;p++){if(userdraw_x[p] + marge_xy > x && userdraw_x[p] - marge_xy < x){if(userdraw_y[p] + marge_xy > y && userdraw_y[p] - marge_xy < y){if(confirm(\"Clear ?\")){floodfill(1,userdraw_x[p],userdraw_y[p],canvas_div.style.backgroundColor || [255,255,255,0]);userdraw_x.splice(p,2);userdraw_y.splice(p,2);user_clickfill_cnt--;return;};};};};};userdraw_x[user_clickfill_cnt] = x;userdraw_y[user_clickfill_cnt] = y;user_clickfill_cnt++;floodfill(1,x,y,[%s,%d]);};",clickfillmarge,fill_color,(int) (fill_opacity/0.0039215));
  3149.          add_read_canvas(canvas_root_id,1,reply_precision);
  3150.          reset();
  3151.         break;
  3152.         case SETPIXEL:
  3153.         /*
  3154.         @ setpixel x,y,color
  3155.         @ A "point" with diameter 1 pixel centeres at (x:y) in xrange / yrange
  3156.         @ pixels can not be dragged or clicked
  3157.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  3158.         */
  3159.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  3160.             for(i=0;i<3;i++){
  3161.                 switch(i){
  3162.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  3163.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  3164.                     case 2: stroke_color = get_color(infile,1);
  3165.                            string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  3166.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3167.                            snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  3168.                            add_to_buffer(tmp_buffer);
  3169.                            break;
  3170.                     default:break;
  3171.                 }
  3172.             }
  3173.             reset();
  3174.         break;
  3175.         case PIXELSIZE:
  3176.         /*
  3177.         @ pixelsize int
  3178.         @ in case you want to deviate from default pixelsize = 1...
  3179.         */
  3180.             pixelsize = (int) get_real(infile,1);
  3181.         break;
  3182.         case PIXELS:
  3183.         /*
  3184.         @ pixels color,x1,y1,x2,y2,x3,y3...
  3185.         @ Draw  "points" with diameter 1 pixel
  3186.         @ pixels can not be dragged or clicked
  3187.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  3188.         */
  3189.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  3190.             stroke_color=get_color(infile,0);
  3191.             i=0;
  3192.             c=0;
  3193.             while( ! done ){     /* get next item until EOL*/
  3194.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  3195.                 for( c = 0 ; c < 2; c++){
  3196.                     if(c == 0 ){
  3197.                         double_data[i] = get_real(infile,0);
  3198.                         i++;
  3199.                     }
  3200.                     else
  3201.                     {
  3202.                         double_data[i] = get_real(infile,1);
  3203.                         i++;
  3204.                     }
  3205.                 }
  3206.             }
  3207.             decimals = find_number_of_digits(precision);
  3208.             /*  *double_xy2js_array(double xy[],int len,int decimals) */
  3209.             string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  3210.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3211.             snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  3212.             add_to_buffer(tmp_buffer);
  3213.             reset();
  3214.             break;
  3215.         case REPLYFORMAT:
  3216.         /*
  3217.         @ replyformat number
  3218.         @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop()
  3219.         @ default values should be fine !
  3220.         @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing
  3221.         @ the last value for 'precision int' will be used to calculate  the reply coordinates, if needed (read_canvas();)
  3222.         @ choose<ul><li>1 = x1,x2,x3,x4....x_n<br />y1,y2,y3,y4....y_n<br /><br />x/y in pixels</li><li>2 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br /> x/y in xrange / yrange coordinate system<br /></li><li>3 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br />  r1,r2,r3,r4....r_n<br />  x/y in pixels <br />  r in pixels</li><li>4 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br />  r1,r2,r3,r4....r_n<br />  x/y in xrange / yrange coordinate system<br />  r in pixels</li><li>5 = Ax1,Ax2,Ax3,Ax4....Ax_n<br />  Ay1,Ay2,Ay3,Ay4....Ay_n<br />  Bx1,Bx2,Bx3,Bx4....Bx_n<br />  By1,By2,By3,By4....By_n<br />  Cx1,Cx2,Cx3,Cx4....Cx_n<br />  Cy1,Cy2,Cy3,Cy4....Cy_n<br />  ....<br />  Zx1,Zx2,Zx3,Zx4....Zx_n<br />  Zy1,Zy2,Zy3,Zy4....Zy_n<br />  x/y in pixels<br /></li><li>6 = Ax1,Ax2,Ax3,Ax4....Ax_n<br />  Ay1,Ay2,Ay3,Ay4....Ay_n<br />  Bx1,Bx2,Bx3,Bx4....Bx_n<br />  By1,By2,By3,By4....By_n<br />  Cx1,Cx2,Cx3,Cx4....Cx_n<br />  Cy1,Cy2,Cy3,Cy4....Cy_n<br />  ....<br />  Zx1,Zx2,Zx3,Zx4....Zx_n<br />  Zy1,Zy2,Zy3,Zy4....Zy_n<br />  x/y in xrange / yrange coordinate system<br /></li><li>7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br />  x/y in pixels</li><li>8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br />  x/y in xrange / yrange coordinate system</li><li>9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br />  x/y in pixels</li><li>10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br />  x/y in xrange / yrange coordinate system</li><li>11 = Ax1,Ay1,Ax2,Ay2<br />   Bx1,By1,Bx2,By2<br />   Cx1,Cy1,Cx2,Cy2<br />   Dx1,Dy1,Dx2,Dy2<br />   ......<br />   Zx1,Zy1,Zx2,Zy2<br />  x/y in xrange / yrange coordinate system</li><li>12 = Ax1,Ay1,Ax2,Ay2<br />   Bx1,By1,Bx2,By2<br />Cx1,Cy1,Cx2,Cy2<br />   Dx1,Dy1,Dx2,Dy2<br />   ......<br />   Zx1,Zy1,Zx2,Zy2<br />  x/y in pixels</li><li>13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2<br />  x/y in xrange / yrange coordinate system</li><li>14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2<br />  x/y in pixels</li><li>15 = reply from inputfields,textareas<br />  reply1,reply2,reply3,...,reply_n</li><li>16 = mathml input fields </li><li>17 = read "userdraw text,color" only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n</li><li>18 = read_canvas() will read all interactive clocks in H1:M1:S1,H2:M2:S2...Hn:Mn:Sn</li><li>19 = read_canvas() will return the object number of marked / clicked object (clock)<br />analogue to (shape library) onclick command </li><li>21 = (x1:y1) (x2:y2) ... (x_n:y_n)<br />verbatim coordinate return</li>22 = returns an array .... reply[0]=x1 reply[1]=y1 reply[2]=x2 reply[3]=y2 ... reply[n-1]=x_n reply[n]=y_n<br />  x/y in xrange / yrange coordinate system</li><li>replyformat 23 : can only be used for drawtype 'polyline'<br />a typical click sequence in drawtype polyline isx1,y1,x2,y2,x2,y2,x3,y3,x3,y3.....,x(n-1),y(n-1),x(n-1),y(n-1),xn,yn --replyformat 23--> x1,y1,x2,y2,x3,y3,.....x(n-1),y(n-1),xn,yn multiple occurences will be filtered out.The reply will be in x-y-range (xreply \\n yreply)</li><li>replyformat 24 = read all inputfield values: even those set 'readonly'</li><li>format 25 = angle1,angle2...angle_n : will return the radius (one or many) of the user drawn circle segment in degrees </li><li>format 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 array: x1:y1:text1,x2:y2:text2...</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>
  3223.         @ note to 'userdraw text,color' : the x / y-values are in pixels ! (this to avoid too lengthy calculations in javascript...)
  3224.         */
  3225.          reply_format = (int) get_real(infile,1);
  3226.          reply_precision = precision;
  3227.         break;
  3228.         case LEGENDCOLORS:
  3229.         /*
  3230.         @ legendcolors color1:color2:color3:...:color_n
  3231.         @ 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<br />
  3232.         @ make sure the number of colours match the number of legend items
  3233.         @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
  3234.         */
  3235.             if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
  3236.             temp = get_string(infile,1);
  3237.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  3238.             fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
  3239.             break;
  3240.         case LEGEND:
  3241.         /*
  3242.         @ legend string1:string2:string3....string_n
  3243.         @ will be used to create a legend for a graph
  3244.         @ also see command 'piechart'
  3245.         @ will use the same colors per default as used in the graphs : use command 'legendcolors' to override the default
  3246.         */
  3247.             temp = get_string(infile,1);
  3248.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  3249.             legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */
  3250.             fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
  3251.             break;
  3252.         case XLABEL:
  3253.         /*
  3254.         @ xlabel some_string
  3255.         @ will be used to create a label for the x-axis (label is in quadrant I)
  3256.         @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
  3257.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
  3258.         */
  3259.             temp = get_string(infile,1);
  3260.             fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
  3261.             break;
  3262.         case YLABEL:
  3263.         /*
  3264.         @ ylabel some_string
  3265.         @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
  3266.         @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
  3267.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
  3268.         */
  3269.             temp = get_string(infile,1);
  3270.             fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
  3271.             break;
  3272.         case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
  3273.         /*
  3274.         @ linegraph x1:y1;x2:y2...x_n:y_n
  3275.         @ will plot your data in a graph
  3276.         @ may only to be used together with command 'grid'
  3277.         @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
  3278.         @ use command 'legend' to provide an optional legend in right-top-corner
  3279.         @ also see command 'piechart'
  3280.         @ multiple linegraphs may be used in a single plot
  3281.         @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
  3282.         @ <ul><li>use command 'strokecolor' before command 'linegraph' to set the color of this graph</li><li>use command 'linewidth' before command 'linegraph' to set linewidth of this graph</li><li>use command 'dashed' before command 'linegraph' to set dashing of the graph</li><li>if dashing is set, use command 'dashtype' before command 'linegraph' to set the type of dashing of the graph</li></ul>
  3283.         */
  3284.             temp = get_string(infile,1);
  3285.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  3286.             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);
  3287.             linegraph_cnt++;
  3288.             reset();
  3289.             break;
  3290.         case BARCHART:
  3291.         /*
  3292.         @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
  3293.         @ will be used to create a legend for bar graph
  3294.         @ may only to be used together with command 'grid'
  3295.         @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
  3296.         @ use command 'legend' to provide an optional legend in right-top-corner
  3297.         @ also see command 'piechart'
  3298.         @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
  3299.         */
  3300.             temp = get_string(infile,1);
  3301.             if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
  3302.             fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
  3303.             barchart_cnt++;
  3304.             reset();
  3305.             break;
  3306.         case CLOCK:
  3307.         /*
  3308.         @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
  3309.         @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency
  3310.         @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments
  3311.         @ colors are optional: if not defined, default values will be used<br />default colours: clock 0,0,60,4,35,45,1,2,[space]<br />default colours: clock 0,0,60,4,35,45,1,2,,,,,<br />custom colours: clock 0,0,60,4,35,45,1,2,,,,yellow,red<br />custom colours: clock 0,0,60,4,35,45,1,2,white,white,white,black,yellow
  3312.         @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
  3313.         @ interactive <ul><li>0 : not interactive, just clock(s)</li><li>1 : function read_canvas() will read all active clocks in H:M:S format<br />The active clock(s) can be adjusted by pupils</li><li>2 : function read_canvas() will return the clicked clock <br />(like multiplechoice; first clock in script in nr. 0 )</li></ul>
  3314.         @ canvasdraw will not check validity of colornames...the javascript console is your best friend
  3315.         @ no combinations with other reply_types allowed, for now
  3316.         @ if interactive, 6 buttons per clock will be displayed for adjusting a clock (H+ M+ S+ H- M- S-)<br /> set_clock(clock_id,type,incr) <br />first clock has clock_id=0 ; type : H=1,M=2,S=3 ; incr : increment integer
  3317.         @ NOTE: if you need multiple clocks on a webpage, use multiple 'clock' commands in a single script !<br />and <i>not multiple canvas scripts</i> in a single page
  3318.         */
  3319.             if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
  3320.  
  3321.         /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
  3322.             for(i=0;i<9;i++){
  3323.              switch(i){
  3324.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
  3325.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
  3326.               case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
  3327.               case 3: int_data[3] = get_real(infile,0);break;/* hours */
  3328.               case 4: int_data[4] = get_real(infile,0);break;/* minutes */
  3329.               case 5: int_data[5] = get_real(infile,0);break;/* seconds */
  3330.               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 */
  3331.               case 7: int_data[7] = (int)(get_real(infile,0));/* interactive 0,1,2*/
  3332.                 switch(int_data[7]){
  3333.                     case 0:break;
  3334.                     case 1:if(clock_cnt == 0){
  3335.                                 if( reply_format == 0 ){
  3336.                                      reply_format = 18; /* user sets clock */
  3337.                                     /* 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");
  3338.                                      check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3339.                                      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");
  3340.                                      add_to_buffer(tmp_buffer);
  3341.                                     */
  3342.                                      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");
  3343.                                 }
  3344.                                 else
  3345.                                 {
  3346.                                     canvas_error("interactive clock may not be used together with other reply_types...");
  3347.                                 }
  3348.                              }
  3349.                             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);
  3350.                     break;
  3351.                     case 2:if( reply_format == 0 ){
  3352.                                 reply_format = 19; /* "onclick */
  3353.                                 fprintf(js_include_file,"\n<!-- begin onclick handler for clocks -->\nvar reply = new Array();\n\ncanvas_div.addEventListener( 'mousedown', user_click,false);\n\nfunction user_click(evt){if(evt.which == 1){var canvas_rect = clock_canvas.getBoundingClientRect();\nvar x = evt.clientX - canvas_rect.left;\nvar y = evt.clientY - canvas_rect.top;\nvar p = 0;\nvar name;\nvar t = true;\nwhile(t){try{name = eval('clocks'+p);\nif( x < name.xc + name.radius && x > name.xc - name.radius ){if( y < name.yc + name.radius && y > name.yc - name.radius ){reply[0] = p;\nname = 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);\n};\n}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);\nname = 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};\np++;\n}catch(e){t=false;\n};\n};\n};\n};\n\n<!-- end onclick handler for clocks -->\n ");
  3354.                             }
  3355.                             else
  3356.                             {
  3357.                                 if( reply_format != 19){
  3358.                                    canvas_error("clickable clock(s) may not be used together with other reply_types...");
  3359.                                  }
  3360.                             }
  3361.                      break;
  3362.                      default: canvas_error("interactive must be set 0,1 or 2");break;
  3363.                 }
  3364.                 break;
  3365.                 case 8:
  3366.                         if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock() , for now it's OK */
  3367.                             fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
  3368.                         }
  3369.                         temp = get_string(infile,1);
  3370.                         if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
  3371.                         if( strlen(temp) < 1 ){temp = ",\"\",\"\",\"\",\"\",\"\"";}
  3372.                         string_length = snprintf(NULL,0,"var 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);
  3373.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3374.                         snprintf(tmp_buffer,string_length,"var 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);
  3375.                         add_to_buffer(tmp_buffer);
  3376.                         clock_cnt++;
  3377.                         break;
  3378.                 default:break;
  3379.              }
  3380.             }
  3381.             break;
  3382.         case PIECHART:
  3383.         /*
  3384.         @ piechart xc,yc,radius,'data+colorlist'
  3385.         @ (xc : yc) center of circle diagram in xrange/yrange
  3386.         @ radius in pixels
  3387.         @ 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
  3388.         @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white
  3389.         @ the number of colors must match the number of data.
  3390.         @ use command "opacity 0-255,0-255" to adjust fill_opacity of colours
  3391.         @ use command "legend string1:string2:...:string_n" to automatically create a legend <br />using the same colours as pie segments<br />unicode allowed in legend<br />expect javascript trouble if the amount of 'pie-slices', 'pie-colours' 'pie-legend-titles' do not match<br />a javascript console is your best friend...<br />use command 'fontfamily' to set the font of the legend.
  3392.         */
  3393.             if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}
  3394.             for(i=0;i<5;i++){
  3395.                 switch(i){
  3396.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  3397.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  3398.                     case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
  3399.                     case 3: temp = get_string(infile,1);
  3400.                             if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
  3401.                             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);
  3402.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3403.                             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);
  3404.                             add_to_buffer(tmp_buffer);
  3405.                            break;
  3406.                     default:break;
  3407.                 }
  3408.             }
  3409.             reset();
  3410.         break;
  3411.         case STATUS:
  3412.         /*
  3413.         @status
  3414.         @keyword
  3415.         @alernative keyword: nostatus
  3416.         @used to override the effects of "status=done" in wims (answer.phtml)
  3417.         @affects inputfields / textarea's in canvasimage and all userdraw based commands
  3418.         @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'
  3419.         */
  3420.  
  3421.             fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
  3422.             break;
  3423.         case XLOGBASE:
  3424.         /*
  3425.         @ xlogbase number
  3426.         @ sets the logbase number for the x-axis
  3427.         @ default value 10
  3428.         @ use together with commands xlogscale / xylogscale
  3429.         */
  3430.             fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
  3431.             break;
  3432.         case YLOGBASE:
  3433.         /*
  3434.         @ ylogbase number
  3435.         @ sets the logbase number for the y-axis
  3436.         @ default value 10
  3437.         @ use together with commands ylogscale / xylogscale
  3438.         */
  3439.             fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
  3440.             break;
  3441.         case XLOGSCALE:
  3442.         /*
  3443.          @ xlogscale ymajor,yminor,majorcolor,minorcolor
  3444.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  3445.          @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
  3446.          @ the linewidth is set using command 'linewidth int'
  3447.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  3448.          @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number'
  3449.          @ 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>
  3450.          @ note: the complete canvas will be used for the 'log paper'
  3451.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  3452.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  3453.          @ note: when using something like 'xrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000')
  3454.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  3455.          @ attention: keyword 'snaptogrid' may not lead to the desired result...
  3456.         */
  3457.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  3458.             if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
  3459.             for(i=0;i<4;i++){
  3460.                 switch(i){
  3461.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  3462.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  3463.                     case 2: stroke_color = get_color(infile,0); break;
  3464.                     case 3: fill_color = get_color(infile,1);
  3465.                         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);
  3466.                         tmp_buffer = my_newmem(string_length+1);
  3467.                         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);
  3468.                         fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
  3469.                         add_to_buffer(tmp_buffer);
  3470.                         break;
  3471.                     default:break;
  3472.                 }
  3473.             }
  3474.             break;
  3475.         case YLOGSCALE:
  3476.         /*
  3477.          @ ylogscale xmajor,xminor,majorcolor,minorcolor
  3478.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  3479.          @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
  3480.          @ the linewidth is set using command 'linewidth int'
  3481.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  3482.          @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number'
  3483.          @ 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>
  3484.          @ note: the complete canvas will be used for the 'log paper'
  3485.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  3486.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  3487.          @ 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')
  3488.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  3489.          @ attention: keyword 'snaptogrid' may not lead to the desired result...
  3490.         */
  3491.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  3492.             if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
  3493.             for(i=0;i<4;i++){
  3494.                 switch(i){
  3495.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  3496.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  3497.                     case 2: stroke_color = get_color(infile,0); break;
  3498.                     case 3: fill_color = get_color(infile,1);
  3499.                         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);
  3500.                         tmp_buffer = my_newmem(string_length+1);
  3501.                         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);
  3502.                         fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
  3503.                         add_to_buffer(tmp_buffer);
  3504.                         break;
  3505.                     default:break;
  3506.                 }
  3507.             }
  3508.             break;
  3509.         case XYLOGSCALE:
  3510.         /*
  3511.          @ xylogscale majorcolor,minorcolor
  3512.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  3513.          @ the linewidth is set using command 'linewidth int'
  3514.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  3515.          @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number'
  3516.          @ 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>
  3517.          @ note: the complete canvas will be used for the 'log paper'
  3518.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  3519.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  3520.          @ 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')
  3521.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  3522.          @ attention: keyword 'snaptogrid' may not lead to the desired result...
  3523.         */
  3524.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  3525.             if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
  3526.             for(i=0;i<2;i++){
  3527.                 switch(i){
  3528.                     case 0: stroke_color = get_color(infile,0); break;
  3529.                     case 1: fill_color = get_color(infile,1);
  3530.                         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);
  3531.                         tmp_buffer = my_newmem(string_length+1);
  3532.                         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);
  3533.                         fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
  3534.                         add_to_buffer(tmp_buffer);
  3535.                         break;
  3536.                     default:break;
  3537.                 }
  3538.             }
  3539.         break;
  3540.         default:sync_input(infile);
  3541.         break;
  3542.     }
  3543.   }
  3544.   /* we are done parsing script file */
  3545.   /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */
  3546.   if( found_size_command == 1 ){
  3547.     fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
  3548.   }
  3549.   else
  3550.   {
  3551.     if( found_size_command != 3 ){
  3552.      canvas_error("Please specify both xrange and yrange ...");
  3553.     }
  3554.   }
  3555.  
  3556.   /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable/clickable shapes / objects  ! */
  3557.   add_javascript_functions(js_function,canvas_root_id);
  3558.    /* add read_canvas() etc functions if needed */
  3559.   if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);}
  3560.   if( use_pan_and_zoom == TRUE ){
  3561.   /* in case of zooming ... */
  3562.   fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\
  3563.  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
  3564.  var ymin_start=ymin;var ymax_start=xmax;\
  3565.  var zoom_x_increment=0;var zoom_y_increment=0;\
  3566.  var pan_x_increment=0;var pan_y_increment=0;\
  3567.  if(use_ylogscale == 0 ){\
  3568.   zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (ymax - ymin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\
  3569.  }else{\
  3570.   zoom_x_increment = (xmax - xmin)/20;\
  3571.   pan_x_increment = (xmax - xmin)/20;\
  3572.  };\
  3573.  function start_canvas%d(type){\
  3574.   switch(type){\
  3575.    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
  3576.    case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\
  3577.    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
  3578.    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
  3579.    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
  3580.    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
  3581.    case 6:location.reload();break;\
  3582.    default:break;\
  3583.   };\
  3584.   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
  3585.   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
  3586.   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){}\
  3587.   %s\
  3588.  };\
  3589.  start_canvas%d(333);\
  3590. };\n\
  3591. <!-- end wims_canvas_function -->\n\
  3592. wims_canvas_function%d();\n",precision,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
  3593.   }
  3594.   else
  3595.   {
  3596.   /* no zoom, just add buffer */
  3597.   fprintf(js_include_file,"\n<!-- add buffer -->\n\
  3598.  %s\
  3599. };\n\
  3600. <!-- end wims_canvas_function -->\n\
  3601. wims_canvas_function%d();\n",buffer,canvas_root_id);
  3602.   }
  3603. /* done writing the javascript include file */
  3604. fclose(js_include_file);
  3605.  
  3606. }
  3607.  
  3608. /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
  3609. if(use_tooltip == TRUE){
  3610.   add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
  3611. }
  3612. exit(EXIT_SUCCESS);
  3613. }
  3614. /* end main() */
  3615.  
  3616. /******************************************************************************
  3617. **
  3618. **  sync_input
  3619. **
  3620. **  synchronises input line - reads to end of line, leaving file pointer
  3621. **  at first character of next line.
  3622. **
  3623. **  Used by:
  3624. **  main program - error handling.
  3625. **
  3626. ******************************************************************************/
  3627. void sync_input(FILE *infile)
  3628. {
  3629.         int c = 0;
  3630.  
  3631.         if( c == '\n' || c == ';' ) return;
  3632.         while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
  3633.         if( c == EOF ) finished = 1;
  3634.         if( c == '\n' || c == '\r' || c == ';') line_number++;
  3635.         return;
  3636. }
  3637.  
  3638. /******************************************************************************/
  3639.  
  3640. char *str_replace(const char *str, const char *old, const char *new){
  3641. /* http://creativeandcritical.net/str-replace-c/ */
  3642.     if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
  3643.     char *ret, *r;
  3644.     const char *p, *q;
  3645.     size_t oldlen = strlen(old);
  3646.     size_t count = 0;
  3647.     size_t retlen = 0;
  3648.     size_t newlen = strlen(new);
  3649.     if (oldlen != newlen){
  3650.         for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
  3651.             count++;
  3652.             retlen = p - str + strlen(p) + count * (newlen - oldlen);
  3653.         }
  3654.     }
  3655.     else
  3656.     {
  3657.         retlen = strlen(str);
  3658.     }
  3659.  
  3660.     if ((ret = malloc(retlen + 1)) == NULL){
  3661.         ret = NULL;
  3662.         canvas_error("string argument is NULL");
  3663.     }
  3664.     else
  3665.     {
  3666.         for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
  3667.             size_t l = q - p;
  3668.             memcpy(r, p, l);
  3669.             r += l;
  3670.             memcpy(r, new, newlen);
  3671.             r += newlen;
  3672.         }
  3673.         strcpy(r, p);
  3674.     }
  3675.     return ret;
  3676. }
  3677.  
  3678. /******************************************************************************/
  3679.  
  3680. char *get_color(FILE *infile , int last){
  3681.     int c,i = 0,is_hex = 0;
  3682.     char temp[MAX_COLOR_STRING], *string;
  3683.     const char *not_allowed = "0123456789";
  3684.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){
  3685.         if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
  3686.         if( c == '#' ){
  3687.             is_hex = 1;
  3688.         }
  3689.         if( c != ' '){
  3690.             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 !!! ");}}
  3691.             temp[i]=tolower(c);
  3692.             i++;
  3693.         }
  3694.     }
  3695.     if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
  3696.     if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
  3697.     if( c == EOF ){finished = 1;}
  3698.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  3699.     temp[i]='\0';
  3700.     if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
  3701.     if( is_hex == 1 ){
  3702.         char red[3], green[3], blue[3];
  3703.         red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
  3704.         green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
  3705.         blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
  3706.         int r = (int) strtol(red,   NULL, 16);
  3707.         int g = (int) strtol(green, NULL, 16);
  3708.         int b = (int) strtol(blue,  NULL, 16);
  3709.         string = (char *)my_newmem(12);
  3710.         snprintf(string,11,"%d,%d,%d",r,g,b);
  3711.         return string;
  3712.     }
  3713.     else
  3714.     {
  3715.         string = (char *)my_newmem(sizeof(temp));
  3716.         snprintf(string,sizeof(temp),"%s",temp);
  3717.         for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  3718.             if( strcmp( colors[i].name , string ) == 0 ){
  3719.                 return colors[i].rgb;
  3720.             }
  3721.         }
  3722.         canvas_error("I was expecting a color name or hexnumber...but found nothing.");
  3723.     }
  3724.     return "0,0,255";
  3725. }
  3726.  
  3727. char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
  3728.     int c,i=0;
  3729.     char  temp[MAX_BUFFER], *string;
  3730.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){
  3731.         temp[i]=c;
  3732.         i++;
  3733.         if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
  3734.     }
  3735.     if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  3736.     if( c == '\n') { done = TRUE; line_number++; }
  3737.     if( c == EOF ) {
  3738.         finished = 1;
  3739.         if( last != 1 ){ canvas_error("expected more arguments");}
  3740.     }
  3741.     temp[i]='\0';
  3742.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");}
  3743.     string=(char *)my_newmem(strlen(temp));
  3744.     snprintf(string,sizeof(temp),"%s",temp);
  3745.     return string;
  3746. }
  3747.  
  3748. char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
  3749.     int c,i=0;
  3750.     char temp[MAX_BUFFER], *string;
  3751.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',')){
  3752.         temp[i]=c;
  3753.         i++;
  3754.         if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
  3755.     }
  3756.     if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
  3757.     if( c == '\n') { line_number++; }
  3758.     if( c == EOF ) {finished = 1;}
  3759.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  3760.     temp[i]='\0';
  3761. /*    
  3762.     17.10.2014 removed (question Perrin)
  3763.     may cause some unwanted effects...
  3764.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
  3765. */
  3766.     string=(char *)my_newmem(sizeof(temp));
  3767.     snprintf(string,sizeof(temp),"%s",temp);
  3768.     done = TRUE;
  3769.     return string;
  3770. }
  3771.  
  3772. double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
  3773.     int c,i=0,found_calc = 0;
  3774.     double y;
  3775.     char tmp[MAX_INT];
  3776.     /*
  3777.      these things are 'allowed functions' : *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs
  3778.      but thereshould be a better way to avoid segfaults !
  3779.     */
  3780.     const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/
  3781.     const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */
  3782.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){
  3783.      if( c != ' ' ){
  3784.       if( i == 0 &&  c == '+' ){
  3785.        continue;
  3786.       }
  3787.       else
  3788.       {
  3789.        c = tolower(c);
  3790.        if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");}
  3791.        if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */
  3792.        tmp[i] = c;
  3793.        i++;
  3794.       }
  3795.      }
  3796.      if( i > MAX_INT - 1){canvas_error("number too large");}
  3797.     }
  3798.     if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
  3799.     if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
  3800.     if( c == EOF ){done = TRUE ; finished = 1;}
  3801.     tmp[i]='\0';
  3802.     if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
  3803.     if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */
  3804.      void *f = eval_create(tmp);
  3805.      assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  3806.      y = eval_x(f, 1);
  3807.      /* if function is bogus; y = 1 : so no core dumps */
  3808.      eval_destroy(f);
  3809.     }
  3810.     else
  3811.     {
  3812.      y = atof(tmp);
  3813.     }
  3814.     return y;
  3815. }
  3816.  
  3817.  
  3818. void canvas_error(char *msg){
  3819.     fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg);
  3820.     finished = 1;
  3821.     exit(EXIT_SUCCESS);
  3822. }
  3823.  
  3824.  
  3825. /* convert x/y coordinates to pixel */
  3826. int x2px(double x){
  3827.  return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
  3828. }
  3829.  
  3830. int y2px(double y){
  3831.  return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
  3832. }
  3833.  
  3834. double px2x(int x){
  3835.  return (x*(xmax - xmin)/xsize + xmin);
  3836. }
  3837. double px2y(int y){
  3838.  return (y*(ymax - ymin)/ysize + ymin);
  3839. }
  3840.  
  3841. void add_to_buffer(char *tmp){
  3842.  if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
  3843.  /*  do we have enough space left in buffer[MAX_BUFFER] ? */
  3844.  int space_left = (int) (sizeof(buffer) - strlen(buffer));
  3845.  if( space_left > strlen(tmp)){
  3846.   strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
  3847.  }
  3848.  else
  3849.  {
  3850.   canvas_error("buffer is too big\n");
  3851.  }
  3852.  tmp = NULL;free(tmp);
  3853.  return;
  3854. }
  3855.  
  3856. void reset(){
  3857.  if(use_filled == TRUE){use_filled = FALSE;}
  3858.  if(use_dashed == TRUE){use_dashed = FALSE;}
  3859.  if(use_rotate == TRUE){use_rotate = FALSE;}
  3860.    onclick = 0;
  3861. }
  3862.  
  3863.  
  3864.  
  3865. /* What reply format in read_canvas();
  3866.  
  3867. note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
  3868. 1 = x1,x2,x3,x4....x_n
  3869.     y1,y2,y3,y4....y_n
  3870.  
  3871.     x/y in pixels
  3872.  
  3873. 2 = x1,x2,x3,x4....x_n
  3874.     y1,y2,y3,y4....y_n
  3875.     x/y in  xrange / yrange coordinate system
  3876.  
  3877. 3 = x1,x2,x3,x4....x_n
  3878.     y1,y2,y3,y4....y_n
  3879.     r1,r2,r3,r4....r_n
  3880.  
  3881.     x/y in pixels
  3882.     r in pixels
  3883.  
  3884. 4 = x1,x2,x3,x4....x_n
  3885.     y1,y2,y3,y4....y_n
  3886.     r1,r2,r3,r4....r_n
  3887.  
  3888.     x/y in  xrange / yrange coordinate system
  3889.     r in pixels
  3890.  
  3891. 5 = Ax1,Ax2,Ax3,Ax4....Ax_n
  3892.     Ay1,Ay2,Ay3,Ay4....Ay_n
  3893.     Bx1,Bx2,Bx3,Bx4....Bx_n
  3894.     By1,By2,By3,By4....By_n
  3895.     Cx1,Cx2,Cx3,Cx4....Cx_n
  3896.     Cy1,Cy2,Cy3,Cy4....Cy_n
  3897.     ....
  3898.     Zx1,Zx2,Zx3,Zx4....Zx_n
  3899.     Zy1,Zy2,Zy3,Zy4....Zy_n
  3900.  
  3901.     x/y in pixels
  3902.  
  3903. 6 = Ax1,Ax2,Ax3,Ax4....Ax_n
  3904.     Ay1,Ay2,Ay3,Ay4....Ay_n
  3905.     Bx1,Bx2,Bx3,Bx4....Bx_n
  3906.     By1,By2,By3,By4....By_n
  3907.     Cx1,Cx2,Cx3,Cx4....Cx_n
  3908.     Cy1,Cy2,Cy3,Cy4....Cy_n
  3909.     ....
  3910.     Zx1,Zx2,Zx3,Zx4....Zx_n
  3911.     Zy1,Zy2,Zy3,Zy4....Zy_n
  3912.  
  3913.     x/y in  xrange / yrange coordinate system
  3914.  
  3915. 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  3916.  
  3917.     x/y in pixels
  3918.  
  3919. 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  3920.  
  3921.     x/y in  xrange / yrange coordinate system
  3922.  
  3923. 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
  3924.  
  3925.     x/y in pixels
  3926.  
  3927. 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
  3928.  
  3929.     x/y in  xrange / yrange coordinate system
  3930.  
  3931. 11 = Ax1,Ay1,Ax2,Ay2
  3932.      Bx1,By1,Bx2,By2
  3933.      Cx1,Cy1,Cx2,Cy2
  3934.      Dx1,Dy1,Dx2,Dy2
  3935.      ......
  3936.      Zx1,Zy1,Zx2,Zy2
  3937.  
  3938.     x/y in  xrange / yrange coordinate system
  3939.  
  3940. 12 = Ax1,Ay1,Ax2,Ay2
  3941.      Bx1,By1,Bx2,By2
  3942.      Cx1,Cy1,Cx2,Cy2
  3943.      Dx1,Dy1,Dx2,Dy2
  3944.      ......
  3945.      Zx1,Zy1,Zx2,Zy2
  3946.  
  3947.     x/y in pixels
  3948.  
  3949. 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
  3950.  
  3951.     x/y in  xrange / yrange coordinate system
  3952. 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
  3953.     x/y in pixels
  3954. 15 = reply from inputfields,textareas
  3955.     reply1,reply2,reply3,...,reply_n
  3956.     only fields set write (a.g. will not read 'readonly' inputfield values'
  3957.  
  3958. 16 = read mathml inputfields only
  3959.  
  3960. 17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n
  3961.  when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
  3962.  
  3963. 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
  3964. 19 = return clicked object number (analogue to shape-library onclick)
  3965. 20 = return x/y-data in x-range/y-range of all 'draggable' images
  3966. 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
  3967. 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
  3968.     x/y in  xrange / yrange coordinate system
  3969. 23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
  3970. 24 = read all inputfield values: even those set 'readonly'
  3971. 25 = return all userdrawn arcs in degrees:
  3972. 26 = return all userdrawn arcs in radians:
  3973. 27 = return (only) userdraw inputfields array: x1:y1:text1,x2:y2:text2...
  3974. 28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
  3975.     x/y/r in  xrange / yrange coordinate system: may be used to reinput into command
  3976.     'circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n'
  3977.     will not return anything else (e.g. no inputfields , text etc)
  3978. */
  3979.  
  3980.  
  3981. void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){
  3982. /* just 1 reply type allowed */
  3983. fprintf(js_include_file,"\
  3984. \n<!-- begin set_reply_precision() -->\n\
  3985. function set_reply_precision(){\
  3986. var len = userdraw_x.length;\
  3987. var prec = %d;\
  3988. for(var p = 0 ; p < len ; p++ ){\
  3989.  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
  3990.  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
  3991. };\
  3992. len = userdraw_radius.length;\
  3993. if( len > 0 ){\
  3994.  for(var p = 0 ; p < len ; p++ ){\
  3995.   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
  3996.  };\
  3997. };\
  3998. };",reply_precision);
  3999.  
  4000. switch(type_reply){
  4001. /*
  4002. answers may have:
  4003. x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
  4004. */
  4005.     case 1: fprintf(js_include_file,"\
  4006. \n<!-- begin function 1 read_canvas%d() -->\n\
  4007. read_canvas%d = function(){\
  4008. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  4009. set_reply_precision();\
  4010. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  4011.  var p = 0;var input_reply = new Array();\
  4012.  if( document.getElementById(\"canvas_input0\")){\
  4013.   var t = 0;\
  4014.   while(document.getElementById(\"canvas_input\"+t)){\
  4015.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4016.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4017.     p++;\
  4018.    };\
  4019.    t++;\
  4020.   };\
  4021.  };\
  4022.  if( typeof userdraw_text != 'undefined' ){\
  4023.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
  4024.  }\
  4025.  else\
  4026.  {\
  4027.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
  4028.  }\
  4029. }\
  4030. else\
  4031. {\
  4032.  if( typeof userdraw_text != 'undefined' ){\
  4033.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
  4034.  }\
  4035.  else\
  4036.  {\
  4037.   return userdraw_x+\"\\n\"+userdraw_y;\
  4038.  }\
  4039. };\
  4040. };\n\
  4041. <!-- end function 1 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  4042.     break;
  4043.     case 2: fprintf(js_include_file,"\
  4044. \n<!-- begin function 2 read_canvas%d() -->\n\
  4045. read_canvas%d = function(){\
  4046. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  4047. set_reply_precision();\
  4048. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  4049. var prec = %d;\
  4050. while(userdraw_x[p]){\
  4051.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  4052.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  4053.  p++;\
  4054. };\
  4055. if(p == 0){alert(\"nothing drawn...\");return;};\
  4056. if( document.getElementById(\"canvas_input0\")){\
  4057.  var p = 0;var input_reply = new Array();\
  4058.  if( document.getElementById(\"canvas_input0\")){\
  4059.   var t = 0;\
  4060.   while(document.getElementById(\"canvas_input\"+t)){\
  4061.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4062.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4063.     p++;\
  4064.    };\
  4065.    t++;\
  4066.   };\
  4067.  };\
  4068.  if( typeof userdraw_text != 'undefined' ){\
  4069.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4070.  }\
  4071.  else\
  4072.  {\
  4073.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  4074.  }\
  4075. }\
  4076. else\
  4077. {\
  4078.  if( typeof userdraw_text != 'undefined' ){\
  4079.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  4080.  }\
  4081.  else\
  4082.  {\
  4083.   return reply_x+\"\\n\"+reply_y;\
  4084.  };\
  4085. };\
  4086. };\n\
  4087. <!-- end function 2 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4088.     break;
  4089.     case 3: fprintf(js_include_file,"\
  4090. \n<!-- begin function 3 read_canvas%d() -->\n\
  4091. read_canvas%d = function(){\
  4092. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  4093. set_reply_precision();\
  4094. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  4095.  var p = 0;var input_reply = new Array();\
  4096.  if( document.getElementById(\"canvas_input0\")){\
  4097.   var t = 0;\
  4098.   while(document.getElementById(\"canvas_input\"+t)){\
  4099.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4100.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4101.     p++;\
  4102.    };\
  4103.    t++;\
  4104.   };\
  4105.  };\
  4106.  if( typeof userdraw_text != 'undefined' ){\
  4107.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4108.  }\
  4109.  else\
  4110.  {\
  4111.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  4112.  }\
  4113. }\
  4114. else\
  4115. {\
  4116.  if( typeof userdraw_text != 'undefined' ){\
  4117.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
  4118.  }\
  4119.  else\
  4120.  {\
  4121.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
  4122.  }\
  4123. }\
  4124. };\n\
  4125. <!-- end function 3 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  4126.     break;
  4127.     case 4: fprintf(js_include_file,"\
  4128. \n<!-- begin function 4 read_canvas%d() -->\n\
  4129. read_canvas%d = function(){\
  4130. var prec = %d;\
  4131. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  4132. while(userdraw_x[p]){\
  4133.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  4134.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
  4135.  p++;\
  4136. };\
  4137. if(p == 0){alert(\"nothing drawn...\");return;};\
  4138. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  4139.  var p = 0;var input_reply = new Array();\
  4140.  if( document.getElementById(\"canvas_input0\")){\
  4141.   var t = 0;\
  4142.   while(document.getElementById(\"canvas_input\"+t)){\
  4143.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4144.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4145.     p++;\
  4146.    };\
  4147.    t++;\
  4148.   };\
  4149.  };\
  4150.  if( typeof userdraw_text != 'undefined' ){\
  4151.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4152.  }\
  4153.  else\
  4154.  {\
  4155.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  4156.  }\
  4157. }\
  4158. else\
  4159. {\
  4160.  if( typeof userdraw_text != 'undefined' ){\
  4161.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
  4162.  }\
  4163.  else\
  4164.  {\
  4165.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
  4166.  }\
  4167. };\
  4168. };\n\
  4169. <!-- end function 4 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4170.     break;
  4171.     /*
  4172.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  4173.         used for userdraw multiple paths
  4174.     */
  4175.     case 5: fprintf(js_include_file,"\
  4176. \n<!-- begin function 5 read_canvas%d() -->\n\
  4177. read_canvas%d = function(){\
  4178. set_reply_precision();\
  4179. var p = 0;\
  4180. var reply = \"\";\
  4181. for(p = 0; p < userdraw_x.length;p++){\
  4182.  if(userdraw_x[p] != null ){\
  4183.   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
  4184.  };\
  4185. };\
  4186. if(p == 0){alert(\"nothing drawn...\");return;};\
  4187. userdraw_x = [];userdraw_y = [];\
  4188. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  4189.  var p = 0;var input_reply = new Array();\
  4190.  if( document.getElementById(\"canvas_input0\")){\
  4191.   var t = 0;\
  4192.   while(document.getElementById(\"canvas_input\"+t)){\
  4193.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4194.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4195.     p++;\
  4196.    };\
  4197.    t++;\
  4198.   };\
  4199.  };\
  4200.  if( typeof userdraw_text != 'undefined' ){\
  4201.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4202.  }\
  4203.  else\
  4204.  {\
  4205.   return reply +\"\\n\"+input_reply;\
  4206.  }\
  4207. }\
  4208. else\
  4209. {\
  4210.  if( typeof userdraw_text != 'undefined' ){\
  4211.   return reply+\"\\n\"+userdraw_text;\
  4212.  }\
  4213.  else\
  4214.  {\
  4215.   return reply;\
  4216.  }\
  4217. };\
  4218. };\n\
  4219. <!-- end function 5 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  4220.     break;
  4221.     /*
  4222.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  4223.         used for userdraw multiple paths
  4224.     */
  4225.     case 6: fprintf(js_include_file,"\
  4226. \n<!-- begin function 6 read_canvas%d() -->\n\
  4227. read_canvas%d = function(){\
  4228. var p = 0;\
  4229. var reply = \"\";\
  4230. var tmp_x = new Array();\
  4231. var tmp_y = new Array();\
  4232. var prec = %d;\
  4233. for(p = 0 ; p < userdraw_x.length; p++){\
  4234.  tmp_x = userdraw_x[p];\
  4235.  tmp_y = userdraw_y[p];\
  4236.  if(tmp_x != null){\
  4237.   for(var i = 0 ; i < tmp_x.length ; i++){\
  4238.    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
  4239.    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
  4240.   };\
  4241.   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
  4242.  };\
  4243. };\
  4244. if(p == 0){alert(\"nothing drawn...\");return;};\
  4245. userdraw_x = [];userdraw_y = [];\
  4246. if( document.getElementById(\"canvas_input0\") ){\
  4247.  var p = 0;var input_reply = new Array();\
  4248.  if( document.getElementById(\"canvas_input0\")){\
  4249.   var t = 0;\
  4250.   while(document.getElementById(\"canvas_input\"+t)){\
  4251.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4252.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4253.     p++;\
  4254.    };\
  4255.    t++;\
  4256.   };\
  4257.  };\
  4258.  if( typeof userdraw_text != 'undefined' ){\
  4259.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4260.  }\
  4261.  else\
  4262.  {\
  4263.   return reply +\"\\n\"+input_reply;\
  4264.  }\
  4265. }\
  4266. else\
  4267. {\
  4268.  if( typeof userdraw_text != 'undefined' ){\
  4269.   return reply +\"\\n\"+userdraw_text;\
  4270.  }\
  4271.  else\
  4272.  {\
  4273.   return reply;\
  4274.  }\
  4275. };\
  4276. };\n\
  4277. <!-- end function 6 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4278.     break;
  4279.     case 7: fprintf(js_include_file,"\
  4280. \n<!-- begin function 7 read_canvas%d() -->\n\
  4281. read_canvas%d = function(){\
  4282. set_reply_precision();\
  4283. var reply = new Array();\
  4284. var p = 0;\
  4285. while(userdraw_x[p]){\
  4286.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
  4287.  p++;\
  4288. };\
  4289. if(p == 0){alert(\"nothing drawn...\");return;};\
  4290. if( document.getElementById(\"canvas_input0\") ){\
  4291.  var p = 0;var input_reply = new Array();\
  4292.  if( document.getElementById(\"canvas_input0\")){\
  4293.   var t = 0;\
  4294.   while(document.getElementById(\"canvas_input\"+t)){\
  4295.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4296.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4297.     p++;\
  4298.    };\
  4299.    t++;\
  4300.   };\
  4301.  };\
  4302.  if( typeof userdraw_text != 'undefined' ){\
  4303.   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4304.  }\
  4305.  else\
  4306.  {\
  4307.   return reply+\"\\n\"+input_reply;\
  4308.  }\
  4309. }\
  4310. else\
  4311. {\
  4312.  if( typeof userdraw_text != 'undefined' ){\
  4313.   return reply+\"\\n\"+userdraw_text;\
  4314.  }\
  4315.  else\
  4316.  {\
  4317.   return reply;\
  4318.  }\
  4319. };\
  4320. };\n\
  4321. <!-- end function 7 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  4322.     break;
  4323.     case 8: fprintf(js_include_file,"\
  4324. \n<!-- begin function 8 read_canvas%d() -->\n\
  4325. read_canvas%d = function(){\
  4326. var reply = new Array();\
  4327. var p = 0;\
  4328. var prec = %d;\
  4329. while(userdraw_x[p]){\
  4330.  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  4331.  p++;\
  4332. };\
  4333. if(p == 0){alert(\"nothing drawn...\");return;};\
  4334. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  4335.  var p = 0;var input_reply = new Array();\
  4336.  if( document.getElementById(\"canvas_input0\")){\
  4337.   var t = 0;\
  4338.   while(document.getElementById(\"canvas_input\"+t)){\
  4339.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4340.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4341.     p++;\
  4342.    };\
  4343.    t++;\
  4344.   };\
  4345.  };\
  4346.  if( typeof userdraw_text != 'undefined' ){\
  4347.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4348.  }\
  4349.  else\
  4350.  {\
  4351.   return reply +\"\\n\"+input_reply;\
  4352.  }\
  4353. }\
  4354. else\
  4355. {\
  4356.  if( typeof userdraw_text != 'undefined' ){\
  4357.   return reply +\"\\n\"+userdraw_text;\
  4358.  }\
  4359.  else\
  4360.  {\
  4361.   return reply;\
  4362.  }\
  4363. };\
  4364. };\n\
  4365. <!-- end function 8 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4366.     break;
  4367.     case 9: fprintf(js_include_file,"\
  4368. \n<!-- begin function 9 read_canvas%d() -->\n\
  4369. read_canvas%d = function(){\
  4370. set_reply_precision();\
  4371. var reply = new Array();\
  4372. var p = 0;\
  4373. while(userdraw_x[p]){\
  4374.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
  4375.  p++;\
  4376. };\
  4377. if(p == 0){alert(\"nothing drawn...\");return;};\
  4378. if( document.getElementById(\"canvas_input0\") ){\
  4379.  var p = 0;var input_reply = new Array();\
  4380.  if( document.getElementById(\"canvas_input0\")){\
  4381.   var t = 0;\
  4382.   while(document.getElementById(\"canvas_input\"+t)){\
  4383.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4384.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4385.     p++;\
  4386.    };\
  4387.    t++;\
  4388.   };\
  4389.  };\
  4390.  if( typeof userdraw_text != 'undefined' ){\
  4391.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4392.  }\
  4393.  else\
  4394.  {\
  4395.   return reply +\"\\n\"+input_reply;\
  4396.  }\
  4397. }\
  4398. else\
  4399. {\
  4400.  if( typeof userdraw_text != 'undefined' ){\
  4401.   return reply +\"\\n\"+userdraw_text;\
  4402.  }\
  4403.  else\
  4404.  {\
  4405.   return reply;\
  4406.  }\
  4407. };\
  4408. };\n\
  4409. <!-- end function 9 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  4410.     break;
  4411.     case 10: fprintf(js_include_file,"\
  4412. \n<!-- begin function 10 read_canvas%d() -->\n\
  4413. read_canvas%d = function(){\
  4414. var reply = new Array();\
  4415. var p = 0;\
  4416. var prec = %d;\
  4417. while(userdraw_x[p]){\
  4418.  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;\
  4419.  p++;\
  4420. };\
  4421. if(p == 0){alert(\"nothing drawn...\");return;};\
  4422. if( document.getElementById(\"canvas_input0\") ){\
  4423.  var p = 0;var input_reply = new Array();\
  4424.  if( document.getElementById(\"canvas_input0\")){\
  4425.   var t = 0;\
  4426.   while(document.getElementById(\"canvas_input\"+t)){\
  4427.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4428.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4429.     p++;\
  4430.    };\
  4431.    t++;\
  4432.   };\
  4433.  };\
  4434.  if( typeof userdraw_text != 'undefined' ){\
  4435.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4436.  }\
  4437.  else\
  4438.  {\
  4439.   return reply +\"\\n\"+input_reply;\
  4440.  }\
  4441. }\
  4442. else\
  4443. {\
  4444.  if( typeof userdraw_text != 'undefined' ){\
  4445.   return reply +\"\\n\"+userdraw_text;\
  4446.  }\
  4447.  else\
  4448.  {\
  4449.   return reply;\
  4450.  }\
  4451. };\
  4452. };\n\
  4453. <!-- end function 10 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4454.     break;
  4455.     case 11: fprintf(js_include_file,"\
  4456. \n<!-- begin function 11 read_canvas%d() -->\n\
  4457. read_canvas%d = function(){\
  4458. var reply = \"\";\
  4459. var p = 0;\
  4460. var prec = %d;\
  4461. while(userdraw_x[p]){\
  4462.  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\" ;\
  4463.  p = p+2;\
  4464. };\
  4465. if(p == 0){alert(\"nothing drawn...\");return;};\
  4466. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  4467.  var p = 0;var input_reply = new Array();\
  4468.  if( document.getElementById(\"canvas_input0\")){\
  4469.   var t = 0;\
  4470.   while(document.getElementById(\"canvas_input\"+t)){\
  4471.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4472.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4473.     p++;\
  4474.    };\
  4475.    t++;\
  4476.   };\
  4477.  };\
  4478.  if( typeof userdraw_text != 'undefined' ){\
  4479.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4480.  }\
  4481.  else\
  4482.  {\
  4483.   return reply +\"\\n\"+input_reply;\
  4484.  }\
  4485. }\
  4486. else\
  4487. {\
  4488.  if( typeof userdraw_text != 'undefined' ){\
  4489.   return reply +\"\\n\"+userdraw_text;\
  4490.  }\
  4491.  else\
  4492.  {\
  4493.   return reply;\
  4494.  }\
  4495. };\
  4496. };\n\
  4497. <!-- end function 11 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4498.     break;
  4499.     case 12: fprintf(js_include_file,"\
  4500. \n<!-- begin function 12 read_canvas%d() -->\n\
  4501. read_canvas%d = function(){\
  4502. set_reply_precision();\
  4503. var reply = \"\";\
  4504. var p = 0;\
  4505. for(p = 0; p< userdraw_x.lenght;p = p+2){\
  4506.  if(userdraw_x[p] != null){\
  4507.    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
  4508.  };\
  4509. };\
  4510. if(p == 0){alert(\"nothing drawn...\");return;};\
  4511. if( document.getElementById(\"canvas_input0\") ){\
  4512.  var p = 0;var input_reply = new Array();\
  4513.  if( document.getElementById(\"canvas_input0\")){\
  4514.   var t = 0;\
  4515.   while(document.getElementById(\"canvas_input\"+t)){\
  4516.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4517.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4518.     p++;\
  4519.    };\
  4520.    t++;\
  4521.   };\
  4522.  };\
  4523.  if( typeof userdraw_text != 'undefined' ){\
  4524.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4525.  }\
  4526.  else\
  4527.  {\
  4528.   return reply +\"\\n\"+input_reply;\
  4529.  }\
  4530. }\
  4531. else\
  4532. {\
  4533.  if( typeof userdraw_text != 'undefined' ){\
  4534.   return reply +\"\\n\"+userdraw_text\
  4535.  }\
  4536.  else\
  4537.  {\
  4538.   return reply;\
  4539.  }\
  4540. };\
  4541. };\n\
  4542. <!-- end function 12 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  4543.     break;
  4544.     case 13: fprintf(js_include_file,"\
  4545. \n<!-- begin function 13 read_canvas%d() -->\n\
  4546. read_canvas%d = function(){\
  4547. var reply = new Array();\
  4548. var p = 0;var i = 0;\
  4549. var prec = %d;\
  4550. while(userdraw_x[p]){\
  4551.  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;\
  4552.  p = p+2;i++;\
  4553. };\
  4554. if(p == 0){alert(\"nothing drawn...\");return;};\
  4555. if( document.getElementById(\"canvas_input0\") ){\
  4556.  var p = 0;var input_reply = new Array();\
  4557.  if( document.getElementById(\"canvas_input0\")){\
  4558.   var t = 0;\
  4559.   while(document.getElementById(\"canvas_input\"+t)){\
  4560.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4561.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4562.     p++;\
  4563.    };\
  4564.    t++;\
  4565.   };\
  4566.  };\
  4567.  if( typeof userdraw_text != 'undefined' ){\
  4568.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4569.  }\
  4570.  else\
  4571.  {\
  4572.   return reply +\"\\n\"+input_reply;\
  4573.  }\
  4574. }\
  4575. else\
  4576. {\
  4577.  if( typeof userdraw_text != 'undefined' ){\
  4578.   return reply +\"\\n\"+userdraw_text\
  4579.  }\
  4580.  else\
  4581.  {\
  4582.   return reply;\
  4583.  }\
  4584. };\
  4585. };\n\
  4586. <!-- end function 13 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4587.     break;
  4588.     case 14: fprintf(js_include_file,"\
  4589. \n<!-- begin function 14 read_canvas%d() -->\n\
  4590. read_canvas%d = function(){\
  4591. set_reply_precision();\
  4592. var reply = new Array();\
  4593. var p = 0;var i = 0;\
  4594. while(userdraw_x[p]){\
  4595.  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
  4596.  p = p+2;i++;\
  4597. };\
  4598. if(p == 0){alert(\"nothing drawn...\");return;};\
  4599. if( document.getElementById(\"canvas_input0\") ){\
  4600.  var p = 0;var input_reply = new Array();\
  4601.  if( document.getElementById(\"canvas_input0\")){\
  4602.   var t = 0;\
  4603.   while(document.getElementById(\"canvas_input\"+t)){\
  4604.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4605.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4606.     p++;\
  4607.    };\
  4608.    t++;\
  4609.   };\
  4610.  };\
  4611.  if( typeof userdraw_text != 'undefined' ){\
  4612.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4613.  }\
  4614.  else\
  4615.  {\
  4616.   return reply +\"\\n\"+input_reply;\
  4617.  }\
  4618. }\
  4619. else\
  4620. {\
  4621.  if( typeof userdraw_text != 'undefined' ){\
  4622.   return reply +\"\\n\"+userdraw_text;\
  4623.  }\
  4624.  else\
  4625.  {\
  4626.   return reply;\
  4627.  }\
  4628. };\
  4629. };\n\
  4630. <!-- end function 14 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  4631.     break;
  4632.     case 15: fprintf(js_include_file,"\
  4633. \n<!-- begin function 15  read_canvas%d() -->\n\
  4634. read_canvas%d = function(){\
  4635. var input_reply = new Array();\
  4636. var p = 0;\
  4637. if( document.getElementById(\"canvas_input0\")){\
  4638.  var t = 0;\
  4639.  while(document.getElementById(\"canvas_input\"+t)){\
  4640.   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4641.    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4642.    p++;\
  4643.   };\
  4644.   t++;\
  4645.  };\
  4646. };\
  4647. if( typeof userdraw_text != 'undefined' ){\
  4648.   return input_reply +\"\\n\"+userdraw_text;\
  4649. }\
  4650. else\
  4651. {\
  4652.  return input_reply;\
  4653. };\
  4654. };\n\
  4655. <!-- end function 15 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  4656.     break;
  4657.     case 16: fprintf(js_include_file,"\
  4658. \n<!-- begin function 16 read_mathml() -->\n\
  4659. function read_mathml(){\
  4660. var reply = new Array();\
  4661. var p = 0;\
  4662. if( document.getElementById(\"mathml0\")){\
  4663.  while(document.getElementById(\"mathml\"+p)){\
  4664.   reply[p] = document.getElementById(\"mathml\"+p).value;\
  4665.   p++;\
  4666.  };\
  4667. };\
  4668. return reply;\
  4669. };\
  4670. this.read_mathml = read_mathml;\n\
  4671. <!-- end function 16 read_mathml() -->");
  4672.     break;
  4673.     case 17:  fprintf(js_include_file,"\
  4674. \n<!-- begin function 17 read_canvas%d() -->\n\
  4675. read_canvas%d = function(){\
  4676. if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\
  4677. return userdraw_text;\
  4678. };\n\
  4679. <!-- end function 17 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  4680.     break;
  4681.     case 18: fprintf(js_include_file,"\
  4682. \n<!-- begin function 18 read_canvas%d() -->\n\
  4683. read_canvas%d = function(){\
  4684. var p = 0;\
  4685. var reply = new Array();\
  4686. var name;\
  4687. var t = true;\
  4688. var h;var m;var s;\
  4689. while(t){\
  4690.  try{\
  4691.   name = eval('clocks'+p);\
  4692.   h = name.H;m = name.M;s = name.S;\
  4693.   if(s < 0){s = 60 + s;m = m - 1;};\
  4694.   if(m < 0){m = 60 + m;h = h - 1;};\
  4695.   if(h < 0){h = 12 + h;};\
  4696.   h = parseInt((h+m/60+s/3600)%%12);m = parseInt((m + s/60)%%60);s = parseInt(s%%60);\
  4697.   reply[p] = h+\":\"+m+\":\"+s;\
  4698.   p++;\
  4699.  }catch(e){t=false;};\
  4700. };\
  4701. if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
  4702. return reply;\
  4703. };\n\
  4704. <!-- end function 18 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  4705.     break;
  4706.     case 19: fprintf(js_include_file,"\
  4707. \n<!-- begin function 19 read_canvas%d() -->\n\
  4708. read_canvas%d = function(){\
  4709. return reply[0];\
  4710. };\n\
  4711. <!-- end function 19 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  4712.     break;
  4713.     case 20: fprintf(js_include_file,"\
  4714. \n<!-- begin function 20 read_canvas%d() -->\n\
  4715. read_canvas%d = function(){\
  4716. var prec = %d;\
  4717. var len  = ext_drag_images.length;\
  4718. var reply = new Array(len);\
  4719. for(var p = 0 ; p < len ; p++){\
  4720.    var img = ext_drag_images[p];\
  4721.    reply[p] = (Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  4722. };\
  4723. return reply;\
  4724. };\n\
  4725. <!-- end function 20 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4726.     break;
  4727.     case 21: fprintf(js_include_file,"\
  4728. \n<!-- begin function 21 read_canvas%d() -->\n\
  4729. read_canvas%d = function(){\
  4730. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  4731. var reply_coord = new Array();var p = 0;\
  4732. var prec = %d;\
  4733. while(userdraw_x[p]){\
  4734.  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
  4735.  p++;\
  4736. };\
  4737. if(p == 0){alert(\"nothing drawn...\");return;};\
  4738. if( document.getElementById(\"canvas_input0\") ){\
  4739.  var p = 0;var input_reply = new Array();\
  4740.  if( document.getElementById(\"canvas_input0\")){\
  4741.   var t = 0;\
  4742.   while(document.getElementById(\"canvas_input\"+t)){\
  4743.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4744.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4745.     p++;\
  4746.    };\
  4747.    t++;\
  4748.   };\
  4749.  };\
  4750.  if( typeof userdraw_text != 'undefined' ){\
  4751.   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4752.  }\
  4753.  else\
  4754.  {\
  4755.   return reply_coord+\"\\n\"+input_reply;\
  4756.  }\
  4757. }\
  4758. else\
  4759. {\
  4760.  if( typeof userdraw_text != 'undefined' ){\
  4761.   return reply_coord+\"\\n\"+userdraw_text;\
  4762.  }\
  4763.  else\
  4764.  {\
  4765.   return reply_coord;\
  4766.  };\
  4767. };\
  4768. };\n\
  4769. <!-- end function 21 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4770.     break;
  4771.     case 22: fprintf(js_include_file,"\
  4772. \n<!-- begin function 22 read_canvas%d() -->\n\
  4773. read_canvas%d = function(){\
  4774. var reply = new Array();\
  4775. var lu = userdraw_x.length;\
  4776. if(lu == 0){alert(\"nothing drawn...\");return;};\
  4777. var idx = 0;\
  4778. var prec = %d;\
  4779. for(var p = 0 ; p < lu ; p++){\
  4780.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
  4781.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
  4782. };\
  4783. if( document.getElementById(\"canvas_input0\") ){\
  4784.  var p = 0;var input_reply = new Array();\
  4785.  if( document.getElementById(\"canvas_input0\")){\
  4786.   var t = 0;\
  4787.   while(document.getElementById(\"canvas_input\"+t)){\
  4788.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4789.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4790.     p++;\
  4791.    };\
  4792.    t++;\
  4793.   };\
  4794.  };\
  4795.  if( typeof userdraw_text != 'undefined' ){\
  4796.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4797.  }\
  4798.  else\
  4799.  {\
  4800.   return reply +\"\\n\"+input_reply;\
  4801.  }\
  4802. }\
  4803. else\
  4804. {\
  4805.  if( typeof userdraw_text != 'undefined' ){\
  4806.   return reply +\"\\n\"+userdraw_text;\
  4807.  }\
  4808.  else\
  4809.  {\
  4810.   return reply;\
  4811.  }\
  4812. };\
  4813. };\n\
  4814. <!-- end function 22 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4815.     break;
  4816.     case 23: fprintf(js_include_file,"\
  4817. \n<!-- begin function 23 read_canvas%d() default 5 px marge -->\n\
  4818. read_canvas%d = function(){\
  4819. if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
  4820. var lu = userdraw_x.length;\
  4821. if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
  4822. var reply_x = new Array();var reply_y = new Array();\
  4823. var marge = 5;var p = 0;\
  4824. var prec = %d;\
  4825. for(var i = 0; i < lu - 1 ; i++ ){\
  4826.  if( Math.abs(userdraw_x[i] - userdraw_x[i+1])){\
  4827.   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
  4828.   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
  4829.   p++;\
  4830.  };\
  4831.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\
  4832. };\
  4833. if( document.getElementById(\"canvas_input0\")){\
  4834.  var p = 0;var input_reply = new Array();\
  4835.  if( document.getElementById(\"canvas_input0\")){\
  4836.   var t = 0;\
  4837.   while(document.getElementById(\"canvas_input\"+t)){\
  4838.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4839.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4840.     p++;\
  4841.    };\
  4842.    t++;\
  4843.   };\
  4844.  };\
  4845.  if( typeof userdraw_text != 'undefined' ){\
  4846.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4847.  }\
  4848.  else\
  4849.  {\
  4850.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  4851.  }\
  4852. }\
  4853. else\
  4854. {\
  4855.  if( typeof userdraw_text != 'undefined' ){\
  4856.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  4857.  }\
  4858.  else\
  4859.  {\
  4860.   return reply_x+\"\\n\"+reply_y;\
  4861.  };\
  4862. };\
  4863. };\n\
  4864. <!-- end function 23 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4865.     break;
  4866.     case 24: fprintf(js_include_file,"\n\
  4867. <!-- begin function 24  read_canvas%d() -->\n\
  4868. read_canvas%d = function(){\
  4869. var input_reply = new Array();\
  4870. var p = 0;\
  4871. if( document.getElementById(\"canvas_input0\")){\
  4872.  while(document.getElementById(\"canvas_input\"+p)){\
  4873.    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
  4874.    p++;\
  4875.  };\
  4876.  return input_reply;\
  4877. };\
  4878. };\n\
  4879. <!-- end function 24 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  4880.     break;
  4881.     case 25:
  4882.     fprintf(js_include_file,"\n<!-- begin function 25 read_canvas%d() : angle(s) in degrees-->\n\
  4883. read_canvas%d = function(){\
  4884. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  4885. var lu = userdraw_radius.length;\
  4886. var prec = %d;\
  4887. var angle_reply = new Array(lu);\
  4888. for(var p = 0 ; p < lu ; p++){\
  4889.  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
  4890. };\
  4891. return angle_reply;\
  4892. };\n\
  4893. <!-- end function 25 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4894.     break;
  4895.     case 26:
  4896.     fprintf(js_include_file,"\n<!-- begin function 26 read_canvas%d() : angle(s) in radians-->\n\
  4897. read_canvas%d = function(){\
  4898. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  4899. var lu = userdraw_radius.length;\
  4900. var prec = %d;\
  4901. var angle_reply = new Array(lu);\
  4902. for(var p = 0 ; p < lu ; p++){\
  4903.  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
  4904. };\
  4905. return angle_reply;\
  4906. };\n\
  4907. <!-- end function 26 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4908.     break;
  4909.     case 27:
  4910.     fprintf(js_include_file,"\n<!-- begin function 27 read_canvas%d()  : inputfield(s) location and their values : -->\n\
  4911. read_canvas%d = function(){\
  4912. var lu = userdraw_x.length;\
  4913. if( lu < 1){alert(\"nothing drawn...\");return;}\
  4914. set_reply_precision();\
  4915. var prec = %d;\
  4916. for(var p = 0 ; p < lu ; p++){\
  4917.   reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\":\"+ document.getElementById(\"canvas_input\"+p).value;\
  4918. };\
  4919. return reply;\
  4920. };\n\
  4921. <!-- end function 27 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4922.     break;
  4923.     case 28:
  4924.     fprintf(js_include_file,"\n<!-- begin function 28 read_canvas%d() -->\n\
  4925. read_canvas%d = function(){\
  4926. var prec = %d;\
  4927. var reply = new Array();var p = 0;\
  4928. var idx = 0;\
  4929. while(userdraw_x[p]){\
  4930.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  4931.  idx++;\
  4932.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  4933.  idx++;\
  4934.  reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\
  4935.  idx++;\
  4936.  p++;\
  4937. };\
  4938. if( p == 0){alert(\"nothing drawn...\");return;}\
  4939. return reply;\
  4940. };\n\
  4941. <!-- end function 4 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  4942.     break;
  4943.     default: canvas_error("hmmm unknown replyformat...");break;
  4944. }
  4945.  return;
  4946. }
  4947.  
  4948.  
  4949. /*
  4950.  add drawfunction :
  4951.  - functions used by userdraw_primitives (circle,rect,path,triangle...)
  4952.  - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
  4953.  - grid / mathml
  4954.  - will not scale or zoom in
  4955.  - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
  4956.  - is printed directly into 'js_include_file'
  4957. */
  4958.  
  4959. void add_javascript_functions(int js_functions[],int canvas_root_id){
  4960. int i;
  4961. for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
  4962.  if( js_functions[i] == 1){
  4963.     switch(i){
  4964.     case DRAG_EXTERNAL_IMAGE:
  4965. fprintf(js_include_file,"\n<!-- drag external images --->\n\
  4966. var external_canvas = create_canvas%d(7,xsize,ysize);\
  4967. var external_ctx = external_canvas.getContext(\"2d\");\
  4968. var external_canvas_rect = external_canvas.getBoundingClientRect();\
  4969. canvas_div.addEventListener(\"mousedown\",setxy,false);\
  4970. canvas_div.addEventListener(\"mouseup\",dragstop,false);\
  4971. canvas_div.addEventListener(\"mousemove\",dragxy,false);\
  4972. var selected_image = null;\
  4973. var ext_image_cnt = 0;\
  4974. var ext_drag_images = new Array();\
  4975. function drag_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,draggable){\
  4976. ext_image_cnt = idx;\
  4977. var image = new Image();\
  4978. image.src = URL;\
  4979. image.onload = function(){\
  4980.  if( x0 < 1 ){ x0 = 0; };if( y0 < 1 ){ y0 = 0; };if( sx < 1 ){ sx = 0; };if( sy < 1 ){ sy = 0; };\
  4981.  if( width < 1 ){ width = image.width; };if( height < 1 ){ height = image.height; };\
  4982.  if( swidth < 1 ){ swidth = image.width; };if( sheight < 1 ){ sheight = image.height; };\
  4983.  var img = new Array(10);\
  4984.  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
  4985.  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;\
  4986.  ext_drag_images[idx] = img;\
  4987.  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  4988. };\
  4989. };\
  4990. function dragstop(evt){\
  4991. selected_image = null;return;\
  4992. };\
  4993. function dragxy(evt){\
  4994. if( selected_image != null ){\
  4995.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  4996.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  4997.  var s_img = ext_drag_images[selected_image];\
  4998.  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\
  4999.  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\
  5000.  ext_drag_images[selected_image] = s_img;\
  5001.  external_ctx.clearRect(0,0,xsize,ysize);\
  5002.  for(var i = 0; i <= ext_image_cnt ; i++){\
  5003.   var img = ext_drag_images[i];\
  5004.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  5005.  };\
  5006. };\
  5007. };\
  5008. function setxy(evt){\
  5009. if( ! selected_image && evt.which == 1 ){\
  5010.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  5011.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  5012.  var xm = evt.clientX - external_canvas_rect.left + xoff;\
  5013.  var ym = evt.clientY - external_canvas_rect.top + yoff;\
  5014.  for(var p = 0 ; p <= ext_image_cnt ; p++){\
  5015.   var img = ext_drag_images[p];\
  5016.   if( img[0] == 1 ){\
  5017.    var w = img.width;\
  5018.    var h = img.height;\
  5019.    if( xm > img[6] && xm < img[6] + img[4]){\
  5020.     if( ym > img[7] && ym < img[7] + img[5]){\
  5021.      img[6] = xm;\
  5022.      img[7] = ym;\
  5023.      ext_drag_images[p] = img;\
  5024.      selected_image = p;\
  5025.      dragxy(evt);\
  5026.     };\
  5027.    };\
  5028.   };\
  5029.  };\
  5030. }\
  5031. else\
  5032. {\
  5033.  selected_image = null;\
  5034. };\
  5035. };",canvas_root_id);
  5036.     break;
  5037.  
  5038.     case DRAW_EXTERNAL_IMAGE:
  5039. fprintf(js_include_file,"\n<!-- draw external images -->\n\
  5040. var draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\
  5041. var image = new Image();\
  5042. image.src = URL;\
  5043. var canvas_bg_div = document.getElementById(\"canvas_div%d\");\
  5044. image.onload = function(){\
  5045.  if( x0 < 1 ){ x0 = 0; };\
  5046.  if( y0 < 1 ){ y0 = 0; };\
  5047.  if( sx < 1 ){ sx = 0; };\
  5048.  if( sy < 1 ){ sy = 0; };\
  5049.  if( width < 1 ){ width = image.width;};\
  5050.  if( height < 1 ){ height = image.height;};\
  5051.  if( swidth < 1 ){ swidth = image.width;};\
  5052.  if( sheight < 1 ){ sheight = image.height;};\
  5053.  var ml = x0 - sx;\
  5054.  var mh = y0 - sy;\
  5055.  canvas_bg_div.style.backgroundPosition= \"left \"+ml+\"px top \"+mh+\"px\";\
  5056.  canvas_bg_div.style.backgroundSize = width+\"px \"+height+\"px\";\
  5057.  canvas_bg_div.style.backgroundRepeat = \"no-repeat\";\
  5058.  canvas_bg_div.style.backgroundPosition= sx+\"px \"+sy+\"px\";\
  5059.  canvas_bg_div.style.backgroundImage = \"url(\" + URL + \")\";\
  5060. };\
  5061. };",canvas_root_id);
  5062.     break;
  5063.     case DRAW_GRIDFILL:/* not used for userdraw */
  5064. fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
  5065. var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\
  5066. var obj;\
  5067. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5068.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5069. }\
  5070. else\
  5071. {\
  5072.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5073. };\
  5074. var ctx = obj.getContext(\"2d\");\
  5075. var x,y;\
  5076. snap_x = dx;snap_y = dy;\
  5077. ctx.save();\
  5078. ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  5079. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  5080.    ctx.moveTo(x,y0);\
  5081.    ctx.lineTo(x,ysize);\
  5082. };\
  5083. for( y = y0 ; y < ysize+dy; y = y + dy ){\
  5084.    ctx.moveTo(x0,y);\
  5085.    ctx.lineTo(xsize,y);\
  5086. };\
  5087. ctx.stroke();\
  5088. ctx.restore();\
  5089. return;};",canvas_root_id,canvas_root_id,canvas_root_id);
  5090.     break;
  5091.  
  5092.     case DRAW_IMAGEFILL:/* not  used for userdraw */
  5093. fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
  5094. var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\
  5095. var obj;\
  5096. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5097.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5098. }\
  5099. else\
  5100. {\
  5101.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5102. };\
  5103. var ctx = obj.getContext(\"2d\");\
  5104. ctx.save();\
  5105. var img = new Image();\
  5106. img.src = URL;\
  5107. img.onload = function(){\
  5108.  if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\
  5109.    ctx.drawImage(img,x0,y0,xsize,ysize);\
  5110.  }\
  5111.  else\
  5112.  {\
  5113.    var repeat = \"repeat\";\
  5114.    if(img.width > xsize - x0){\
  5115.         repeat = \"repeat-y\";\
  5116.    }\
  5117.    else\
  5118.    {\
  5119.     if( img.height > ysize -x0 ){\
  5120.      repeat = \"repeat-x\";\
  5121.     }\
  5122.    }\
  5123.    var pattern = ctx.createPattern(img,repeat);\
  5124.    ctx.rect(x0,y0,xsize,ysize);\
  5125.    ctx.fillStyle = pattern;\
  5126.  }\
  5127.  ctx.fill();\
  5128. };\
  5129. ctx.restore();\
  5130. return;\
  5131. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5132.     break;
  5133.  
  5134.     case DRAW_DOTFILL:/* not  used for userdraw */
  5135. fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
  5136. var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\
  5137. var obj;\
  5138. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5139.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5140. }\
  5141. else\
  5142. {\
  5143.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5144. };\
  5145. var ctx = obj.getContext(\"2d\");\
  5146. var x,y;\
  5147. ctx.closePath();\
  5148. ctx.save();\
  5149. snap_x = dx;snap_y = dy;\
  5150. ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  5151. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  5152.  for( y = y0 ; y < ysize+dy ; y = y + dy ){\
  5153.   ctx.arc(x,y,radius,0,2*Math.PI,false);\
  5154.   ctx.closePath();\
  5155.  }\
  5156. }\
  5157. ctx.fill();\
  5158. ctx.restore();\
  5159. return;};",canvas_root_id,canvas_root_id,canvas_root_id);
  5160.     break;
  5161.  
  5162.     case DRAW_DIAMONDFILL:/* not used for userdraw */
  5163. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  5164. var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  5165.  var obj;\
  5166. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5167.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5168. }\
  5169. else\
  5170. {\
  5171.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5172. };\
  5173. var ctx = obj.getContext(\"2d\");\
  5174. var x;\
  5175. var y;\
  5176. ctx.save();\
  5177. ctx.lineWidth = linewidth;\
  5178. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5179. y = ysize;\
  5180. for( x = x0 ; x < xsize ; x = x + dx ){\
  5181.  ctx.moveTo(x,y0);\
  5182.  ctx.lineTo(xsize,y);\
  5183.  y = y - dy;\
  5184. };\
  5185. y = y0;\
  5186. for( x = xsize ; x > 0 ; x = x - dx){\
  5187.  ctx.moveTo(x,ysize);\
  5188.  ctx.lineTo(x0,y);\
  5189.  y = y + dy;\
  5190. };\
  5191. x = x0;\
  5192. for( y = y0 ; y < ysize ; y = y + dy ){\
  5193.  ctx.moveTo(xsize,y);\
  5194.  ctx.lineTo(x,ysize);\
  5195.  x = x + dx;\
  5196. };\
  5197. x = xsize;\
  5198. for( y = ysize ; y > y0 ; y = y - dy ){\
  5199.  ctx.moveTo(x,y0);\
  5200.  ctx.lineTo(x0,y);\
  5201.  x = x - dx;\
  5202. };\
  5203. ctx.stroke();\
  5204. ctx.restore();\
  5205. return;\
  5206. }",canvas_root_id,canvas_root_id,canvas_root_id);
  5207.     break;
  5208.  
  5209.     case DRAW_HATCHFILL:/* not used for userdraw */
  5210. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  5211. var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  5212.  var obj;\
  5213. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5214.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5215. }\
  5216. else\
  5217. {\
  5218.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5219. };\
  5220. var ctx = obj.getContext(\"2d\");\
  5221. var x;\
  5222. var y;\
  5223. ctx.save();\
  5224. ctx.lineWidth = linewidth;\
  5225. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5226. y = ysize;\
  5227. for( x = x0 ; x < xsize ; x = x + dx ){\
  5228.  ctx.moveTo(x,y0);\
  5229.  ctx.lineTo(xsize,y);\
  5230.  y = y - dy;\
  5231. };\
  5232. y = y0;\
  5233. for( x = xsize ; x >= dx ; x = x - dx){\
  5234.  ctx.moveTo(x,ysize);\
  5235.  ctx.lineTo(x0,y);\
  5236.  y = y + dy;\
  5237. };\
  5238. ctx.stroke();\
  5239. ctx.restore();\
  5240. return;\
  5241. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5242.     break;
  5243.     case DRAW_CIRCLES:/*  used for userdraw */
  5244. fprintf(js_include_file,"\n<!-- draw circles -->\n\
  5245. 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){\
  5246. ctx.save();\
  5247. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5248. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5249. ctx.lineWidth = line_width;\
  5250. for(var p = 0 ; p < x_points.length ; p++ ){\
  5251.  ctx.beginPath();\
  5252.  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
  5253.  ctx.closePath();\
  5254.  if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5255.  if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  5256.  ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5257.  ctx.stroke();\
  5258. }\
  5259. ctx.restore();\
  5260. return;\
  5261. };");
  5262.     break;
  5263.     case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
  5264. fprintf(js_include_file,"\n<!-- draw polyline -->\n\
  5265. 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){\
  5266. ctx.save();\
  5267. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5268. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5269. ctx.lineWidth = line_width;\
  5270. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5271. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5272. ctx.clearRect(0,0,xsize,ysize);\
  5273. ctx.beginPath();\
  5274. for(var p = 0 ; p < x_points.length-1 ; p++ ){\
  5275.  ctx.moveTo(x_points[p],y_points[p]);\
  5276.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  5277. }\
  5278. ctx.closePath();\
  5279. ctx.stroke();\
  5280. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5281. for(var p = 0 ; p < x_points.length ; p++ ){\
  5282.  ctx.beginPath();\
  5283.  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
  5284.  ctx.closePath();ctx.fill();ctx.stroke();\
  5285. };\
  5286. ctx.restore();\
  5287. return;\
  5288. };");
  5289.     break;
  5290.  
  5291.     case DRAW_SEGMENTS:/*  used for userdraw */
  5292. fprintf(js_include_file,"\n<!-- draw segments -->\n\
  5293. 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){\
  5294. ctx.save();\
  5295. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5296. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5297. ctx.lineWidth = line_width;\
  5298. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5299. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5300. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  5301.  ctx.beginPath();\
  5302.  ctx.moveTo(x_points[p],y_points[p]);\
  5303.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  5304.  ctx.closePath();\
  5305.  ctx.stroke();\
  5306.  }\
  5307.  ctx.restore();\
  5308.  return;\
  5309. };");
  5310.     break;
  5311.  
  5312.     case DRAW_LINES:/*  used for userdraw */
  5313. fprintf(js_include_file,"\n<!-- draw lines -->\n\
  5314. function calc_line(x1,x2,y1,y2){\
  5315. var marge = 2;\
  5316. if(x1 < x2+marge && x1>x2-marge){\
  5317.  return [x1,0,x1,ysize];\
  5318. };\
  5319. if(y1 < y2+marge && y1>y2-marge){\
  5320.  return [0,y1,xsize,y1];\
  5321. };\
  5322. var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
  5323. var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
  5324. return [0,Y1,xsize,Y2];\
  5325. };\
  5326. 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){\
  5327. ctx.save();\
  5328. var line = new Array(4);\
  5329. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5330. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5331. ctx.lineWidth = line_width;\
  5332. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5333. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5334. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  5335.  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
  5336.  ctx.beginPath();\
  5337.  ctx.moveTo(line[0],line[1]);\
  5338.  ctx.lineTo(line[2],line[3]);\
  5339.  ctx.closePath();\
  5340.  ctx.stroke();\
  5341.  }\
  5342.  ctx.restore();\
  5343.  return;\
  5344. };");
  5345.     break;
  5346.  
  5347.     case DRAW_DEMILINES:/*  used for userdraw */
  5348. fprintf(js_include_file,"\n<!-- draw demilines -->\n\
  5349. function find_inf_point(x1,y1,x2,y2){\
  5350. if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\
  5351. var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\
  5352. if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\
  5353. };\
  5354. 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){\
  5355. ctx.save();\
  5356. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5357. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5358. ctx.lineWidth = line_width;\
  5359. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5360. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5361. var pair = new Array(4);\
  5362. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  5363.  pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\
  5364.  ctx.beginPath();\
  5365.  ctx.moveTo(pair[0],pair[1]);\
  5366.  ctx.lineTo(pair[2],pair[3]);\
  5367.  ctx.closePath();\
  5368.  ctx.stroke();\
  5369.  }\
  5370.  ctx.restore();\
  5371.  return;\
  5372. };");
  5373.     break;
  5374.  
  5375.     case DRAW_CROSSHAIRS:/*  used for userdraw */
  5376. fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
  5377. var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\
  5378. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5379. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5380. ctx.lineWidth = line_width;\
  5381. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5382. var x1,x2,y1,y2;\
  5383. for(var p = 0 ; p < x_points.length ; p++ ){\
  5384.  x1 = x_points[p] - crosshair_size;\
  5385.  x2 = x_points[p] + crosshair_size;\
  5386.  y1 = y_points[p] - crosshair_size;\
  5387.  y2 = y_points[p] + crosshair_size;\
  5388.  ctx.beginPath();\
  5389.  ctx.moveTo(x1,y1);\
  5390.  ctx.lineTo(x2,y2);\
  5391.  ctx.closePath();\
  5392.  ctx.stroke();\
  5393.  ctx.beginPath();\
  5394.  ctx.moveTo(x2,y1);\
  5395.  ctx.lineTo(x1,y2);\
  5396.  ctx.closePath();\
  5397.  ctx.stroke();\
  5398. }\
  5399. ctx.restore();\
  5400.  return;\
  5401. };");
  5402.     break;
  5403.  
  5404.     case DRAW_RECTS:/*  used for userdraw */
  5405. fprintf(js_include_file,"\n<!-- draw rects -->\n\
  5406. 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){\
  5407. ctx.save();\
  5408. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5409. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5410. ctx.lineWidth = line_width;\
  5411. ctx.strokeStyle = \"rgba('+stroke_color+','+stroke_opacity+')\";\
  5412. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
  5413. for(var p = 0 ; p < x_points.length ; p = p + 2){\
  5414.  ctx.beginPath();\
  5415.  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
  5416.  ctx.closePath();\
  5417.  if(use_filled == 1 ){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  5418.  ctx.stroke();\
  5419. };\
  5420. ctx.restore();\
  5421. return;\
  5422. };");
  5423.     break;
  5424.  
  5425.     case DRAW_ROUNDRECTS:/*  used for userdraw */
  5426. fprintf(js_include_file,"\n<!-- draw round rects -->\n\
  5427. 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){\
  5428. ctx.save();\
  5429. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5430. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5431. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5432. var x,y,w,h,r;\
  5433. for(var p = 0; p < x_points.length; p = p+2){\
  5434.  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);\
  5435.  ctx.beginPath();ctx.moveTo(x + r, y);\
  5436.  ctx.lineTo(x + w - r, y);\
  5437.  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
  5438.  ctx.lineTo(x + w, y + h - r);\
  5439.  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
  5440.  ctx.lineTo(x + r, y + h);\
  5441.  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
  5442.  ctx.lineTo(x, y + r);\
  5443.  ctx.quadraticCurveTo(x, y, x + r, y);\
  5444.  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
  5445.  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5446.  if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\
  5447.  ctx.stroke();\
  5448. }\
  5449. ctx.restore();\
  5450. };");
  5451.     break;
  5452.  
  5453.     case DRAW_ELLIPSES:/* not  used for userdraw */
  5454. fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
  5455. 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){\
  5456. var obj;\
  5457. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5458.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5459. }\
  5460. else\
  5461. {\
  5462.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5463. };\
  5464. var ctx = obj.getContext(\"2d\");\
  5465. ctx.save();\
  5466. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5467. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5468. var cx,cy,ry,rx;\
  5469. ctx.lineWidth = line_width;\
  5470. if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\
  5471. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5472. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5473. for(var p=0;p< x_points.length;p = p+2){\
  5474.  ctx.beginPath();\
  5475.  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
  5476.  ctx.translate(cx - rx, cy - ry);\
  5477.  ctx.scale(rx, ry);\
  5478.  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
  5479.  if( use_filled == 1 ){ctx.fill();}\
  5480.  ctx.stroke();\
  5481. };\
  5482. ctx.restore();\
  5483. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5484.     break;
  5485.  
  5486.     case DRAW_PATHS: /*  used for userdraw */
  5487. fprintf(js_include_file,"\n<!-- draw paths -->\n\
  5488. 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){\
  5489. ctx.save();\
  5490. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5491. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5492. ctx.lineWidth = line_width;\
  5493. ctx.lineJoin = \"round\";\
  5494. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5495. ctx.beginPath();\
  5496. ctx.moveTo(x_points[0],y_points[0]);\
  5497. for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
  5498. if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
  5499. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5500. if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  5501. ctx.stroke();\
  5502. ctx.restore();\
  5503. return;\
  5504. };");
  5505.  
  5506.     break;
  5507.     case DRAW_ARROWS:/*  used for userdraw */
  5508. fprintf(js_include_file,"\n<!-- draw arrows -->\n\
  5509. 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){\
  5510. ctx.save();\
  5511. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5512. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5513. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5514. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5515. ctx.lineWidth = line_width;\
  5516. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5517. ctx.lineCap = \"round\";\
  5518. var x1,y1,x2,y2,dx,dy,len;\
  5519. for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
  5520.   ctx.save();\
  5521.   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
  5522.   len = Math.sqrt(dx*dx+dy*dy);\
  5523.   ctx.translate(x2,y2);\
  5524.   ctx.rotate(Math.atan2(dy,dx));\
  5525.   ctx.lineCap = \"round\";\
  5526.   ctx.beginPath();\
  5527.   ctx.moveTo(0,0);\
  5528.   ctx.lineTo(-len,0);\
  5529.   ctx.closePath();\
  5530.   ctx.stroke();\
  5531.   ctx.beginPath();\
  5532.   ctx.moveTo(0,0);\
  5533.   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  5534.   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  5535.   ctx.closePath();\
  5536.   ctx.fill();\
  5537.   ctx.restore();\
  5538.   if( type == 2 ){\
  5539.     ctx.save();\
  5540.     ctx.translate(x1,y1);\
  5541.     ctx.rotate(Math.atan2(-dy,-dx));\
  5542.     ctx.beginPath();\
  5543.     ctx.moveTo(0,0);\
  5544.     ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\
  5545.     ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\
  5546.     ctx.closePath();\
  5547.     ctx.stroke();\
  5548.     ctx.fill();\
  5549.     ctx.restore();\
  5550.   }\
  5551.  }\
  5552.  ctx.restore();\
  5553.  return;\
  5554. };");
  5555.     break;
  5556.  
  5557.     case DRAW_VIDEO:/* not  used for userdraw */
  5558. fprintf(js_include_file,"\n<!-- draw video -->\n\
  5559. var draw_video = function(canvas_root_id,x,y,w,h,URL){\
  5560. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  5561. var video_div = document.createElement(\"div\");\
  5562. canvas_div.appendChild(video_div);\
  5563. video_div.style.position = \"absolute\";\
  5564. video_div.style.left = x+\"px\";\
  5565. video_div.style.top = y+\"px\";\
  5566. video_div.style.width = w+\"px\";\
  5567. video_div.style.height = h+\"px\";\
  5568. var video = document.createElement(\"video\");\
  5569. video_div.appendChild(video);\
  5570. video.style.width = w+\"px\";\
  5571. video.style.height = h+\"px\";\
  5572. video.autobuffer = true;\
  5573. video.controls = true;video.autoplay = false;\
  5574. var src = document.createElement(\"source\");\
  5575. src.type = \"video/mp4\";\
  5576. src.src = URL;\
  5577. video.appendChild(src);\
  5578. video.load();\
  5579. return;\
  5580. };");
  5581.     break;
  5582.  
  5583.     case DRAW_AUDIO:/* not used for userdraw */
  5584. fprintf(js_include_file,"\n<!-- draw audio -->\n\
  5585. var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
  5586. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  5587. var audio_div = document.createElement(\"div\");\
  5588. canvas_div.appendChild(audio_div);\
  5589. audio_div.style.position = \"absolute\";\
  5590. audio_div.style.left = x+\"px\";\
  5591. audio_div.style.top = y+\"px\";\
  5592. audio_div.style.width = w+\"px\";\
  5593. audio_div.style.height = h+\"px\";\
  5594. var audio = document.createElement(\"audio\");\
  5595. audio_div.appendChild(audio);\
  5596. audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
  5597. audio.autobuffer = true;\
  5598. if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;}\
  5599. if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;}\
  5600. var src1 = document.createElement(\"source\");\
  5601. src1.type = \"audio/ogg\";\
  5602. src1.src = URL1;\
  5603. audio.appendChild(src1);\
  5604. var src2 = document.createElement(\"source\");\
  5605. src2.type = \"audio/mpeg\";\
  5606. src2.src = URL2;\
  5607. audio.appendChild(src2);\
  5608. audio.load();\
  5609. return;\
  5610. };");
  5611.     break;
  5612.  
  5613.     case DRAW_HTTP:/* not  used for userdraw */
  5614. fprintf(js_include_file,"\n<!-- draw http -->\n\
  5615. var draw_http = function(canvas_root_id,x,y,w,h,URL){\
  5616. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  5617. var http_div = document.createElement(\"div\");\
  5618. var iframe = document.createElement(\"iframe\");\
  5619. canvas_div.appendChild(http_div);\
  5620. http_div.appendChild(iframe);\
  5621. iframe.src = URL;\
  5622. iframe.setAttribute(\"width\",w);\
  5623. iframe.setAttribute(\"height\",h);\
  5624. return;\
  5625. };");
  5626.     break;
  5627.  
  5628.     case DRAW_XML:
  5629. fprintf(js_include_file,"\n<!-- draw xml -->\n\
  5630. var draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick){\
  5631. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  5632. var xml_div = document.createElement(\"div\");\
  5633. canvas_div.appendChild(xml_div);\
  5634. xml_div.innerHTML = mathml;\
  5635. if(onclick != 0){\
  5636.  xml_div.onclick = function(){\
  5637.   reply[0] = onclick;\
  5638.   alert(\"send \"+onclick+\" ?\");\
  5639.  };\
  5640. };\
  5641. xml_div.style.position = \"absolute\";\
  5642. xml_div.style.left = x+\"px\";\
  5643. xml_div.style.top = y+\"px\";\
  5644. xml_div.style.width = w+\"px\";\
  5645. xml_div.style.height = h+\"px\";\
  5646. return;\
  5647. };"
  5648. );
  5649.     break;
  5650.     case DRAW_SGRAPH:
  5651. /*
  5652.  xstart = given
  5653.  ystart = given
  5654.  sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
  5655. */
  5656. fprintf(js_include_file,"\n<!-- draw sgraph -->\n\
  5657. var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
  5658. 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);};\
  5659. var ctx = obj.getContext(\"2d\");\
  5660. ctx.font = fontfamily;\
  5661. var minor_opacity = 0.8*opacity;\
  5662. ctx.clearRect(0,0,xsize,ysize);\
  5663. var zero_x = 0.1*xsize;\
  5664. var zero_y = 0.9*ysize;\
  5665. var snor_x;var snor_y;\
  5666. if( xstart != xmin){\
  5667.  snor_x = 0.1*xsize;\
  5668. }\
  5669. else\
  5670. {\
  5671.  snor_x = 0;\
  5672.  xstart = xmin;\
  5673. };\
  5674. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  5675. ctx.lineWidth = 2;\
  5676. ctx.beginPath();\
  5677. ctx.moveTo(xsize,zero_y);\
  5678. ctx.lineTo(zero_x,zero_y);\
  5679. ctx.lineTo(zero_x,0);\
  5680. ctx.stroke();\
  5681. ctx.closePath();\
  5682. ctx.beginPath();\
  5683. ctx.moveTo(zero_x,zero_y);\
  5684. ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
  5685. ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
  5686. ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
  5687. ctx.lineTo(zero_x + snor_x,zero_y);\
  5688. ctx.stroke();\
  5689. ctx.closePath();\
  5690. ctx.beginPath();\
  5691. var num = xstart;\
  5692. var flipflop = 1;\
  5693. var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
  5694. var txtsize;var txt_marge=step_x - 5;\
  5695. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  5696.  txtsize = ctx.measureText(num).width;\
  5697.  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
  5698.  if( flipflop == 1){\
  5699.   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
  5700.  }\
  5701.  else\
  5702.  {\
  5703.   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
  5704.  }\
  5705.  num = num + xmajor;\
  5706. };\
  5707. ctx.stroke();\
  5708. ctx.closePath();\
  5709. ctx.lineWidth = 1;\
  5710. ctx.beginPath();\
  5711. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  5712.   ctx.moveTo(x,zero_y);\
  5713.   ctx.lineTo(x,0);\
  5714. };\
  5715. ctx.stroke();\
  5716. ctx.closePath();\
  5717. if( xminor > 1){\
  5718.  ctx.lineWidth = 0.5;\
  5719.  ctx.beginPath();\
  5720.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  5721.  var minor_step_x = step_x / xminor;\
  5722.  var nx;\
  5723.  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
  5724.    num = 1;\
  5725.    for(var p = 1 ; p < xminor ; p++){\
  5726.     nx = x + num*minor_step_x;\
  5727.     ctx.moveTo(nx,zero_y);\
  5728.     ctx.lineTo(nx,0);\
  5729.     num++;\
  5730.    };\
  5731.  };\
  5732.  ctx.stroke();\
  5733.  ctx.closePath();\
  5734.  ctx.beginPath();\
  5735.  ctx.lineWidth = 2;\
  5736.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  5737.  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  5738.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
  5739.  };\
  5740.  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
  5741.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
  5742.  };\
  5743.  ctx.stroke();\
  5744.  ctx.closePath();\
  5745.  ctx.lineWidth = 0.5;\
  5746. };\
  5747. xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
  5748. if( ystart != ymin){\
  5749.  snor_y = 0.1*ysize;\
  5750. }\
  5751. else\
  5752. {\
  5753.  snor_y = 0;\
  5754.  ystart = ymin;\
  5755. };\
  5756. ctx.lineWidth = 2;\
  5757. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  5758. ctx.beginPath();\
  5759. ctx.moveTo(zero_x,zero_y);\
  5760. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
  5761. ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
  5762. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
  5763. ctx.lineTo(zero_x,zero_y - snor_y);\
  5764. ctx.stroke();\
  5765. ctx.closePath();\
  5766. ctx.beginPath();\
  5767. ctx.lineWidth = 1;\
  5768. num = ystart;\
  5769. var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
  5770. for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
  5771.  ctx.moveTo(zero_x,y);\
  5772.  ctx.lineTo(xsize,y);\
  5773.  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
  5774.  num = num + ymajor;\
  5775. };\
  5776. ctx.stroke();\
  5777. ctx.closePath();\
  5778. if( yminor > 1){\
  5779.  ctx.lineWidth = 0.5;\
  5780.  ctx.beginPath();\
  5781.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  5782.  var minor_step_y = step_y / yminor;\
  5783.  var ny;\
  5784.  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
  5785.   num = 1;\
  5786.   for(var p = 1 ;p < yminor;p++){\
  5787.     ny = y + num*minor_step_y;\
  5788.     ctx.moveTo(zero_x,ny);\
  5789.     ctx.lineTo(xsize,ny);\
  5790.     num++;\
  5791.    };\
  5792.  };\
  5793.  ctx.stroke();\
  5794.  ctx.closePath();\
  5795.  ctx.lineWidth = 2;\
  5796.  ctx.beginPath();\
  5797.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  5798.  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
  5799.   ctx.moveTo(zero_x,y);\
  5800.   ctx.lineTo(zero_x+12,y);\
  5801.  };\
  5802.  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
  5803.   ctx.moveTo(zero_x,y);\
  5804.   ctx.lineTo(zero_x+6,y);\
  5805.  };\
  5806.  ctx.stroke();\
  5807.  ctx.closePath();\
  5808. };\
  5809. ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
  5810. if( typeof legend%d  !== 'undefined' ){\
  5811.  ctx.globalAlpha = 1.0;\
  5812.  var y_offset = 2*font_size;\
  5813.  var txt;var txt_size;\
  5814.  var x_offset = xsize - 2*font_size;\
  5815.  var l_length = legend%d.length;var barcolor = new Array();\
  5816.  if( typeof legendcolors%d !== 'undefined' ){\
  5817.   for(var p = 0 ; p < l_length ; p++){\
  5818.    barcolor[p] = legendcolors%d[p];\
  5819.   };\
  5820.  }else{\
  5821.   if( barcolor.length == 0 ){\
  5822.    for(var p = 0 ; p < l_length ; p++){\
  5823.     barcolor[p] = stroke_color;\
  5824.    };\
  5825.   };\
  5826.  };\
  5827.  for(var p = 0; p < l_length; p++){\
  5828.   ctx.fillStyle = barcolor[p];\
  5829.   txt = legend%d[p];\
  5830.   txt_size = ctx.measureText(txt).width;\
  5831.   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
  5832.   y_offset = parseInt(y_offset + 1.5*font_size);\
  5833.  };\
  5834. };\
  5835. if( typeof xaxislabel !== 'undefined' ){\
  5836.   ctx.fillStyle = \'#000000\';\
  5837.   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
  5838.   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
  5839. };\
  5840. if( typeof yaxislabel !== 'undefined'){\
  5841.   ctx.save();\
  5842.   ctx.fillStyle = \'#000000\';\
  5843.   var txt_size = ctx.measureText(yaxislabel).width;\
  5844.   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
  5845.   ctx.rotate(-0.5*Math.PI);\
  5846.   ctx.fillText(yaxislabel,0,0);\
  5847.   ctx.restore();\
  5848. };\
  5849. };\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);
  5850.     break;
  5851.  
  5852.     case DRAW_GRID:/* not used for userdraw */
  5853. fprintf(js_include_file,"\n<!-- draw grid -->\n\
  5854. 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){\
  5855. 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);};\
  5856. var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
  5857. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5858. ctx.save();\
  5859. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  5860. if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
  5861. var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5862. ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
  5863. var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
  5864. ctx.font = font_family;\
  5865. var barcolor = new Array();\
  5866. var xstep = xsize*xmajor/(xmax - xmin);\
  5867. var ystep = ysize*ymajor/(ymax - ymin);\
  5868. var x2step = xstep / xminor;\
  5869. var y2step = ystep / yminor;\
  5870. var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
  5871. if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
  5872. if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
  5873. ctx.beginPath();\
  5874. ctx.lineWidth = line_width;\
  5875. ctx.strokeStyle = stroke_color;\
  5876. for(var p = zero_x ; p < xsize; p = p + xstep){\
  5877. ctx.moveTo(p,0);\
  5878. ctx.lineTo(p,ysize);\
  5879. };\
  5880. for(var p = zero_x ; p > 0; p = p - xstep){\
  5881. ctx.moveTo(p,0);\
  5882. ctx.lineTo(p,ysize);\
  5883. };\
  5884. for(var p = zero_y ; p < ysize; p = p + ystep){\
  5885. ctx.moveTo(0,p);\
  5886. ctx.lineTo(xsize,p);\
  5887. };\
  5888. for(var p = zero_y ; p > 0; p = p - ystep){\
  5889. ctx.moveTo(0,p);\
  5890. ctx.lineTo(xsize,p);\
  5891. };\
  5892. if( typeof xaxislabel !== 'undefined' ){\
  5893. ctx.save();\
  5894. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  5895. var corr =  ctx.measureText(xaxislabel).width;\
  5896. ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\
  5897. ctx.restore();\
  5898. };\
  5899. if( typeof yaxislabel !== 'undefined' ){\
  5900. ctx.save();\
  5901. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  5902. var corr =  ctx.measureText(yaxislabel).width;\
  5903. ctx.translate(zero_x+tics_length + font_size,corr+font_size);\
  5904. ctx.rotate(-0.5*Math.PI);\
  5905. ctx.fillText(yaxislabel,0,0);\
  5906. ctx.restore();\
  5907. };\
  5908. ctx.stroke();\
  5909. ctx.closePath();\
  5910. if( use_axis == 1 ){\
  5911. ctx.save();\
  5912. ctx.beginPath();\
  5913. ctx.strokeStyle = stroke_color;\
  5914. ctx.lineWidth = 0.6*line_width;\
  5915. for(var p = zero_x ; p < xsize; p = p + x2step){\
  5916.  ctx.moveTo(p,0);\
  5917.  ctx.lineTo(p,ysize);\
  5918. };\
  5919. for(var p = zero_x ; p > 0; p = p - x2step){\
  5920.  ctx.moveTo(p,0);\
  5921.  ctx.lineTo(p,ysize);\
  5922. };\
  5923. for(var p = zero_y ; p < ysize; p = p + y2step){\
  5924.  ctx.moveTo(0,p);\
  5925.  ctx.lineTo(xsize,p);\
  5926. };\
  5927. for(var p = zero_y ; p > 0; p = p - y2step){\
  5928.  ctx.moveTo(0,p);\
  5929.  ctx.lineTo(xsize,p);\
  5930. };\
  5931. ctx.stroke();\
  5932. ctx.closePath();\
  5933. ctx.beginPath();\
  5934. ctx.lineWidth = 2*line_width;\
  5935. ctx.strokeStyle = axis_color;\
  5936. ctx.moveTo(0,zero_y);\
  5937. ctx.lineTo(xsize,zero_y);\
  5938. ctx.moveTo(zero_x,0);\
  5939. ctx.lineTo(zero_x,ysize);\
  5940. ctx.stroke();\
  5941. ctx.closePath();\
  5942. ctx.lineWidth = line_width+0.5;\
  5943. ctx.beginPath();\
  5944. for(var p = zero_x ; p < xsize; p = p + xstep){\
  5945.  ctx.moveTo(p,zero_y-tics_length);\
  5946.  ctx.lineTo(p,zero_y+tics_length);\
  5947. };\
  5948. for(var p = zero_x ; p > 0; p = p - xstep){\
  5949.  ctx.moveTo(p,zero_y-tics_length);\
  5950.  ctx.lineTo(p,zero_y+tics_length);\
  5951. };\
  5952. for(var p = zero_y ; p < ysize; p = p + ystep){\
  5953.  ctx.moveTo(zero_x-tics_length,p);\
  5954.  ctx.lineTo(zero_x+tics_length,p);\
  5955. };\
  5956. for(var p = zero_y ; p > 0; p = p - ystep){\
  5957.  ctx.moveTo(zero_x-tics_length,p);\
  5958.  ctx.lineTo(zero_x+tics_length,p);\
  5959. };\
  5960. for(var p = zero_x ; p < xsize; p = p + x2step){\
  5961.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  5962.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  5963. };\
  5964. for(var p = zero_x ; p > 0; p = p - x2step){\
  5965.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  5966.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  5967. };\
  5968. for(var p = zero_y ; p < ysize; p = p + y2step){\
  5969.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  5970.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  5971. };\
  5972. for(var p = zero_y ; p > 0; p = p - y2step){\
  5973.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  5974.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  5975. };\
  5976. ctx.stroke();\
  5977. ctx.closePath();\
  5978. ctx.restore();\
  5979. };\
  5980. if( use_axis_numbering == 1 ){\
  5981. ctx.save();\
  5982. ctx.fillColor = axis_color;\
  5983. ctx.strokeStyle = axis_color;\
  5984. ctx.lineWidth = 2*line_width;\
  5985. ctx.font = font_family;\
  5986. var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
  5987. if( x_strings != null ){\
  5988.  var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  5989.  ctx.beginPath();\
  5990.  for(var p = 0 ; p < len ; p = p+2){\
  5991.   var x_nums = x2px(eval(x_strings[p]));\
  5992.   var x_text = x_strings[p+1];\
  5993.   corr = ctx.measureText(x_text).width;\
  5994.   skip = 1.2*corr/xstep;\
  5995.   if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
  5996.   if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
  5997.   ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
  5998.   ctx.moveTo(x_nums,zero_y - tics_length);\
  5999.   ctx.lineTo(x_nums,zero_y + tics_length);\
  6000.  };\
  6001.  ctx.closePath();\
  6002. }\
  6003. else\
  6004. {\
  6005.  skip = 1;cnt = px2x(zero_x);\
  6006.  prec = Math.log(precision)/(Math.log(10));\
  6007.  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
  6008.  for( var p = zero_x ; p < xsize ; p = p+xstep){\
  6009.   if(skip == 0 ){\
  6010.    disp_cnt = cnt.toFixed(prec);\
  6011.    corr = ctx.measureText(disp_cnt).width;\
  6012.    skip = parseInt(1.2*corr/xstep);\
  6013.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  6014.   }\
  6015.   else\
  6016.   {\
  6017.    skip--;\
  6018.   };\
  6019.   cnt = cnt + xmajor;\
  6020.  };\
  6021.  cnt = px2x(zero_x);skip = 1;\
  6022.  for( var p = zero_x ; p > 0 ; p = p-xstep){\
  6023.   if(skip == 0 ){\
  6024.    disp_cnt = cnt.toFixed(prec);\
  6025.    corr = ctx.measureText(disp_cnt).width;\
  6026.    skip = parseInt(1.2*corr/xstep);\
  6027.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  6028.   }\
  6029.   else\
  6030.   {\
  6031.    skip--;\
  6032.   };\
  6033.   cnt = cnt - xmajor;\
  6034.  };\
  6035. };\
  6036. if( y_strings != null ){\
  6037.  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
  6038.  ctx.beginPath();\
  6039.  for(var p = 0 ; p < len ; p = p+2){\
  6040.   var y_nums = y2px(eval(y_strings[p]));\
  6041.   var y_text = y_strings[p+1];\
  6042.   corr = 2 + tics_length + ctx.measureText(y_text).width;\
  6043.   if( corr > zero_x){corr = parseInt(zero_x+2); }\
  6044.   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
  6045.   ctx.moveTo(zero_x - tics_length,y_nums);\
  6046.   ctx.lineTo(zero_x + tics_length,y_nums);\
  6047.  };\
  6048.  ctx.closePath();\
  6049. }\
  6050. else\
  6051. {\
  6052.  if(f_x == 1){ corr = 1.5*tics_length; }\
  6053.  cnt = px2y(zero_y);skip = 1;\
  6054.  for( var p = zero_y ; p < ysize ; p = p+ystep){\
  6055.   if(skip == 0 ){\
  6056.    skip = parseInt(1.4*font_size/ystep);\
  6057.    disp_cnt = cnt.toFixed(prec);\
  6058.    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  6059.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  6060.   }\
  6061.   else\
  6062.   {\
  6063.    skip--;\
  6064.   };\
  6065.   cnt = cnt - ymajor;\
  6066.  };\
  6067.  corr = 0;cnt = px2y(zero_y);skip = 1;\
  6068.  if(f_x == 1){ corr = 1.5*tics_length; }\
  6069.  for( var p = zero_y ; p > 0 ; p = p-ystep){\
  6070.   if(skip == 0 ){\
  6071.    skip = parseInt(1.4*font_size/ystep);\
  6072.    disp_cnt = cnt.toFixed(prec);\
  6073.    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  6074.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  6075.   }\
  6076.   else\
  6077.   {\
  6078.    skip--;\
  6079.   };\
  6080.   cnt = cnt + ymajor;\
  6081.  };\
  6082. };\
  6083. ctx.stroke();\
  6084. ctx.restore();\
  6085. };\
  6086. if( typeof legend0  !== 'undefined' ){\
  6087. ctx.save();\
  6088. ctx.globalAlpha = 1.0;\
  6089. ctx.font = \"bold \"+font_size+\"px Ariel\";\
  6090. var y_offset = 2*font_size;\
  6091. var txt;var txt_size;\
  6092. var x_offset = xsize - 2*font_size;\
  6093. var l_length = legend0.length;\
  6094. if( typeof legendcolors0 !== 'undefined' ){\
  6095.  for(var p = 0 ; p < l_length ; p++){\
  6096.    barcolor[p] = legendcolors0[p];\
  6097.  };\
  6098. }\
  6099. else\
  6100. {\
  6101.  if( barcolor.length == 0 ){\
  6102.   for(var p = 0 ; p < l_length ; p++){\
  6103.    barcolor[p] = stroke_color;\
  6104.   };\
  6105.  };\
  6106. };\
  6107. for(var p = 0; p < l_length; p++){\
  6108.  ctx.fillStyle = barcolor[p];\
  6109.  txt = legend0[p];\
  6110.  txt_size = ctx.measureText(txt).width;\
  6111.  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
  6112.  y_offset = parseInt(y_offset + 1.5*font_size);\
  6113. };\
  6114. ctx.restore();\
  6115. };\
  6116. if( typeof barchart_0  !== 'undefined' ){\
  6117. ctx.save();\
  6118. var num_barcharts = 0;\
  6119. var bar_name = eval('barchart_0');\
  6120. while( typeof bar_name !== 'undefined' ){\
  6121.    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
  6122. };\
  6123. var bar_width = parseInt(0.8*xstep/(num_barcharts));\
  6124. for(var i=0 ; i< num_barcharts ; i++){\
  6125.  bar_name = eval('barchart_'+i);\
  6126.  var bar_x = new Array();\
  6127.  var bar_y = new Array();\
  6128.  var lb = bar_name.length;\
  6129.  var idx = 0;\
  6130.  var dx = parseInt(0.5*i*bar_width);\
  6131.  for( var p = 0 ; p < lb ; p = p + 3 ){\
  6132.   bar_x[idx] = x2px(bar_name[p]);\
  6133.   bar_y[idx] = y2px(bar_name[p+1]);\
  6134.   barcolor[idx] = bar_name[p+2];\
  6135.   idx++;\
  6136.  };\
  6137.  ctx.globalAlpha = fill_opacity;\
  6138.  ctx.beginPath();\
  6139.  for( var p = 0; p < idx ; p++ ){\
  6140.   ctx.strokeStyle = barcolor[p];\
  6141.   ctx.fillStyle = barcolor[p];\
  6142.   ctx.rect(bar_x[p]-0.4*xstep+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
  6143.  };\
  6144.  ctx.fill();\
  6145.  ctx.stroke();\
  6146.  ctx.closePath();\
  6147. };\
  6148. ctx.restore();\
  6149. };\
  6150. if( typeof linegraph_0 !== 'undefined' ){\
  6151. ctx.save();\
  6152. ctx.globalAlpha = 1.0;\
  6153. var i = 0;\
  6154. var line_name = eval('linegraph_'+i);\
  6155. while ( typeof line_name !== 'undefined' ){\
  6156.  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
  6157.  ctx.lineWidth = parseInt(line_name[1]);\
  6158.  if(line_name[2] == \"1\"){\
  6159.   var d1 = parseInt(line_name[3]);\
  6160.   var d2 = parseInt(line_name[4]);\
  6161.   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
  6162.  }\
  6163.  else\
  6164.  {\
  6165.  if(ctx.setLineDash){ctx.setLineDash = null;}\
  6166.  if(ctx.mozDash){ctx.mozDash = null;}\
  6167.  };\
  6168.  var data_x = new Array();\
  6169.  var data_y = new Array();\
  6170.  var lb = line_name.length;\
  6171.  var idx = 0;\
  6172.  for( var p = 5 ; p < lb ; p = p + 2 ){\
  6173.   data_x[idx] = x2px(line_name[p]);\
  6174.   data_y[idx] = y2px(line_name[p+1]);\
  6175.   idx++;\
  6176.  };\
  6177.  for( var p = 0; p < idx ; p++){\
  6178.   ctx.beginPath();\
  6179.   ctx.moveTo(data_x[p],data_y[p]);\
  6180.   ctx.lineTo(data_x[p+1],data_y[p+1]);\
  6181.   ctx.stroke();\
  6182.   ctx.closePath();\
  6183.  };\
  6184.  i++;\
  6185.  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
  6186. };\
  6187. ctx.restore();\
  6188. };\
  6189. return;\
  6190. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  6191.     break;
  6192.  
  6193.     case DRAW_PIECHART:
  6194. fprintf(js_include_file,"\n<!-- draw piecharts -->\n\
  6195. function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family){\
  6196. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6197.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6198. }\
  6199. else\
  6200. {\
  6201.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6202. };\
  6203. var ld = data_color_list.length;\
  6204. var sum = 0;\
  6205. var idx = 0;\
  6206. var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
  6207. var colors = new Array();\
  6208. var data = new Array();\
  6209. for(var p = 0;p < ld; p = p + 2){\
  6210.  data[idx] = parseFloat(data_color_list[p]);\
  6211.  sum = sum + data[idx];\
  6212.  colors[idx] = data_color_list[p+1];\
  6213.  idx++;\
  6214. };\
  6215. var ctx = obj.getContext(\"2d\");\
  6216. ctx.save();\
  6217. var angle;\
  6218. var angle_end = 0;\
  6219. var offset = Math.PI / 2;\
  6220. ctx.globalAlpha = fill_opacity;\
  6221. for(var p=0; p < idx; p++){\
  6222.  ctx.beginPath();\
  6223.  ctx.fillStyle = colors[p];\
  6224.  ctx.moveTo(x_center,y_center);\
  6225.  angle = Math.PI * (2 * data[p] / sum);\
  6226.  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
  6227.  ctx.lineTo(x_center, y_center);\
  6228.  ctx.fill();\
  6229.  ctx.closePath();\
  6230.  angle_end  = angle_end + angle;\
  6231. };\
  6232. if(typeof legend0 !== 'undefined'){\
  6233.  var legenda = eval(\"legend\"+legend_cnt);\
  6234.  ctx.globalAlpha = 1.0;\
  6235.  ctx.font = font_family;\
  6236.  var y_offset = font_size; \
  6237.  var x_offset = 0;\
  6238.  var txt;var txt_size;\
  6239.  for(var p = 0; p < idx; p++){\
  6240.   ctx.fillStyle = colors[p];\
  6241.   txt = legenda[p];\
  6242.   txt_size = ctx.measureText(txt).width;\
  6243.   if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
  6244.   ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
  6245.   y_offset = parseInt(y_offset + 1.5*font_size);\
  6246.  };\
  6247. };\
  6248. ctx.restore();\
  6249. };",canvas_root_id,canvas_root_id,canvas_root_id);
  6250.  
  6251.     break;
  6252.     case DRAW_ARCS:
  6253. fprintf(js_include_file,"\n<!-- draw arcs -->\n\
  6254. 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){\
  6255. ctx.save();\
  6256. if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  6257. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  6258. if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  6259. if(end < start){var tmp = end;end = start;start=tmp;};\
  6260. start = 360 - start;\
  6261. end = 360 - end;\
  6262. ctx.lineWidth = line_width;\
  6263. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6264. ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  6265. ctx.beginPath();\
  6266. ctx.moveTo(xc,yc);\
  6267. ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  6268. ctx.lineTo(xc,yc);\
  6269. ctx.closePath();\
  6270. if( use_filled == 1 ){\
  6271.  ctx.fill();\
  6272. };\
  6273. ctx.stroke();\
  6274. ctx.restore();\
  6275. };");
  6276.  
  6277.     break;
  6278.     case DRAW_CENTERSTRING:
  6279. fprintf(js_include_file,"\n<!-- draw centerstring -->\n\
  6280. var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
  6281. var obj;\
  6282. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6283.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6284. }\
  6285. else\
  6286. {\
  6287.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6288. };\
  6289. var ctx = obj.getContext(\"2d\");\
  6290. ctx.save();\
  6291. ctx.font = font_family;\
  6292. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6293. var stringwidth = ctx.measureText(text).width;\
  6294. var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
  6295. ctx.fillText(text,x,y2px(y));\
  6296. return;\
  6297. };",canvas_root_id,canvas_root_id,canvas_root_id);
  6298.     break;
  6299.     case DRAW_TEXTS:
  6300. fprintf(js_include_file,"\n<!-- draw text -->\n\
  6301. 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){\
  6302.  var obj;\
  6303.  if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6304.   obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6305.  }\
  6306.  else\
  6307.  {\
  6308.   obj = create_canvas%d(canvas_type,xsize,ysize);\
  6309.  };\
  6310.  var ctx = obj.getContext(\"2d\");\
  6311.  if(angle2 == 0 && angle != 0){\
  6312.   ctx.save();\
  6313.   if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6314.   if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6315.  };\
  6316.  if( font_family.indexOf('px') != null ){\
  6317.   ctx.font = font_family;\
  6318.  }\
  6319.  else\
  6320.  {\
  6321.   ctx.font = font_family;\
  6322.  };\
  6323.  ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6324.  if(angle2 != 0){\
  6325.   ctx.save();\
  6326.   ctx.translate(x,y);\
  6327.   ctx.rotate((360-angle2)*(Math.PI / 180));\
  6328.   ctx.fillText(text,0,0);\
  6329.   ctx.restore();\
  6330.  }else{ctx.fillText(text,x,y);};\
  6331. ctx.restore();\
  6332. return;\
  6333. };",canvas_root_id,canvas_root_id,canvas_root_id);
  6334.     break;
  6335.     case DRAW_CURVE:
  6336. fprintf(js_include_file,"\n<!-- draw curve -->\n\
  6337. 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){\
  6338. var obj;\
  6339. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6340.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6341. }\
  6342. else\
  6343. {\
  6344.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6345. };\
  6346. var ctx = obj.getContext(\"2d\");\
  6347. ctx.save();\
  6348. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6349. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6350. ctx.beginPath();ctx.lineWidth = line_width;\
  6351. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  6352. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6353. ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
  6354. for(var p = 1 ; p < x_points.length ; p++){\
  6355.  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
  6356.  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
  6357.  }\
  6358.  else\
  6359.  {\
  6360.   ctx.stroke();\
  6361.   ctx.beginPath();\
  6362.   p++;\
  6363.   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
  6364.  };\
  6365. };\
  6366. ctx.stroke();\
  6367. ctx.restore();\
  6368. };",canvas_root_id,canvas_root_id,canvas_root_id);
  6369.     break;
  6370.  
  6371.     case DRAW_INPUTS:
  6372. fprintf(js_include_file,"\n<!-- draw input fields -->\n\
  6373. var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\
  6374. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  6375. var input = document.createElement(\"input\");\
  6376. input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  6377. input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  6378. input.setAttribute(\"size\",size);\
  6379. input.setAttribute(\"value\",value);\
  6380. if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
  6381. canvas_div.appendChild(input);};");
  6382.     break;
  6383.  
  6384.     case DRAW_TEXTAREAS:
  6385. fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
  6386. var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
  6387. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  6388. var textarea = document.createElement(\"textarea\");\
  6389. textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  6390. textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  6391. textarea.setAttribute(\"cols\",cols);\
  6392. textarea.setAttribute(\"rows\",rows);\
  6393. textarea.value = value;\
  6394. if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
  6395. canvas_div.appendChild(textarea);};");
  6396.     break;
  6397.  
  6398. case DRAW_PIXELS:
  6399. fprintf(js_include_file,"\n<!-- draw pixel -->\n\
  6400. var draw_setpixel = function(x,y,color,opacity,pixelsize){\
  6401. var canvas = create_canvas%d(10,xsize,ysize);\
  6402. var d = 0.5*pixelsize;\
  6403. var ctx = canvas.getContext(\"2d\");\
  6404. ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
  6405. ctx.clearRect(0,0,xsize,ysize);\
  6406. for(var p=0; p<x.length;p++){\
  6407.  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
  6408. };\
  6409. ctx.fill();ctx.stroke();\
  6410. };",canvas_root_id);
  6411. break;
  6412.  
  6413. case DRAW_CLOCK:
  6414. fprintf(js_include_file,"\n<!-- begin command clock -->\n\
  6415. var clock_canvas = create_canvas%d(%d,xsize,ysize);\
  6416. var clock_ctx = clock_canvas.getContext(\"2d\");\
  6417. var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
  6418. clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\
  6419. clock_ctx.save();\
  6420. clock_ctx.globalAlpha = clock_bg_opacity;\
  6421. this.type = type || 0;\
  6422. this.interaction = interaction || 0;\
  6423. this.H = H;\
  6424. this.M = M;\
  6425. this.S = S;\
  6426. if(this.S == -1){this.S = 59;this.M = this.M - 1;};\
  6427. if(this.M == -1){this.M = 59;this.H = this.H - 1;};\
  6428. if(this.H == -1){this.H = 11;};\
  6429. this.xc = xc || xsize/2;\
  6430. this.yc = yc || ysize/2;\
  6431. this.radius = radius || xsize/4;\
  6432. var font_size = parseInt(0.2*this.radius);\
  6433. this.H_color = h_color || \"blue\";\
  6434. this.M_color = m_color || \"blue\";\
  6435. this.S_color = s_color || \"blue\";\
  6436. this.fg_color = fg_color || \"red\";\
  6437. this.bg_color = bg_color || \"white\";\
  6438. clock_ctx.translate(this.xc,this.yc);\
  6439. clock_ctx.beginPath();\
  6440. clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
  6441. clock_ctx.fillStyle = this.bg_color;\
  6442. clock_ctx.fill();\
  6443. clock_ctx.closePath();\
  6444. clock_ctx.beginPath();\
  6445. clock_ctx.font = font_size+\"px Arial\";\
  6446. clock_ctx.fillStyle = this.fg_color;\
  6447. clock_ctx.textAlign = \"center\";\
  6448. clock_ctx.textBaseline = 'middle';\
  6449. var angle;var x1,y1,x2,y2;\
  6450. var angle_cos;var angle_sin;\
  6451. clock_ctx.globalAlpha = clock_fg_opacity;\
  6452. switch(type){\
  6453. case 0:clock_ctx.beginPath();\
  6454. for(var p = 1; p <= 12 ; p++){\
  6455.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  6456.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  6457.  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  6458.  clock_ctx.moveTo(x1,y1);\
  6459.  clock_ctx.lineTo(x2,y2);\
  6460. };\
  6461. for(var p = 1; p <= 60 ; p++){\
  6462.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  6463.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  6464.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  6465.  clock_ctx.moveTo(x1,y1);\
  6466.  clock_ctx.lineTo(x2,y2);\
  6467. };\
  6468. clock_ctx.closePath();\
  6469. clock_ctx.stroke();\
  6470. break;\
  6471. case 1:\
  6472. 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;\
  6473. case 2:\
  6474. 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);};\
  6475. clock_ctx.beginPath();\
  6476. for(var p = 1; p <= 12 ; p++){\
  6477.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  6478.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  6479.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  6480.  clock_ctx.moveTo(x1,y1);\
  6481.  clock_ctx.lineTo(x2,y2);\
  6482. };\
  6483. for(var p = 1; p <= 60 ; p++){\
  6484.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  6485.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  6486.  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  6487.  clock_ctx.moveTo(x1,y1);\
  6488.  clock_ctx.lineTo(x2,y2);\
  6489. };\
  6490. clock_ctx.closePath();\
  6491. clock_ctx.stroke();\
  6492. break;\
  6493. };\
  6494. angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
  6495. clock_ctx.rotate(angle);\
  6496. clock_ctx.beginPath();\
  6497. clock_ctx.moveTo(-3, -2);\
  6498. clock_ctx.lineTo(-3, 2);\
  6499. clock_ctx.lineTo(this.radius * 0.7, 1);\
  6500. clock_ctx.lineTo(this.radius  * 0.7, -1);\
  6501. clock_ctx.fillStyle = this.H_color;\
  6502. clock_ctx.fill();\
  6503. clock_ctx.rotate(-angle);\
  6504. angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
  6505. clock_ctx.rotate(angle);\
  6506. clock_ctx.beginPath();\
  6507. clock_ctx.moveTo(-3, -2);\
  6508. clock_ctx.lineTo(-3, 2);\
  6509. clock_ctx.lineTo(this.radius  * 0.8, 1);\
  6510. clock_ctx.lineTo(this.radius  * 0.8, -1);\
  6511. clock_ctx.fillStyle = this.M_color;\
  6512. clock_ctx.fill();\
  6513. clock_ctx.rotate(-angle);\
  6514. angle = (this.S - 15) * 2 * Math.PI / 60;\
  6515. clock_ctx.rotate(angle);\
  6516. clock_ctx.beginPath();\
  6517. clock_ctx.moveTo(0,0);\
  6518. clock_ctx.lineTo(this.radius  * 0.95, 0);\
  6519. clock_ctx.lineTo(this.radius  * 0.9, -1);\
  6520. clock_ctx.strokeStyle = this.S_color;\
  6521. clock_ctx.stroke();\
  6522. clock_ctx.restore();\
  6523. };",canvas_root_id,CLOCK_CANVAS);
  6524. break;
  6525.  
  6526. case DRAW_LATTICE:
  6527. fprintf(js_include_file,"\n<!-- draw lattice -->\n\
  6528. 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){\
  6529. var obj;\
  6530. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6531.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6532. }\
  6533. else\
  6534. {\
  6535.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6536. };\
  6537. var ctx = obj.getContext(\"2d\");\
  6538. ctx.save();\
  6539. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6540. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6541. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6542. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6543. var radius = line_width;\
  6544. var x = 0;\
  6545. var y = 0;\
  6546. var x_step_px = xsize/(xmax-xmin);\
  6547. var y_step_px = ysize/(ymax-ymin);\
  6548. var xv1 = dx1*x_step_px;\
  6549. var yv1 = dy1*y_step_px;\
  6550. var xv2 = dx2*x_step_px;\
  6551. var yv2 = dy2*y_step_px;\
  6552. for(var p = 0; p < n1 ;p++){\
  6553.  x = p*xv1 + x0;\
  6554.  y = p*yv1 + y0;\
  6555.  for(var c = 0; c < n2 ; c++){\
  6556.   ctx.beginPath();\
  6557.   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
  6558.   ctx.fill();\
  6559.   ctx.stroke();\
  6560.   ctx.closePath();\
  6561.  };\
  6562. };\
  6563. ctx.restore();\
  6564. return;\
  6565. };",canvas_root_id,canvas_root_id,canvas_root_id);
  6566.     break;
  6567. case DRAW_XYLOGSCALE:
  6568. fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\
  6569. 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){\
  6570. var obj;\
  6571. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6572.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6573. }\
  6574. else\
  6575. {\
  6576.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6577. };\
  6578. var ctx = obj.getContext(\"2d\");\
  6579. ctx.clearRect(0,0,xsize,ysize);\
  6580. ctx.save();\
  6581. var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
  6582. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  6583. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  6584. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  6585. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  6586. if(use_axis_numbering == 1){\
  6587.  ctx.font = font_family;\
  6588.  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
  6589.  ymarge = parseInt(1.5*font_size);\
  6590.  ctx.save();\
  6591.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  6592.  ctx.rect(0,0,xmarge,ysize);\
  6593.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  6594.  ctx.fill();\
  6595.  ctx.restore();\
  6596. }else{xmarge = 0;ymarge = 0;};\
  6597. if( typeof xaxislabel !== 'undefined' ){\
  6598.  ctx.save();\
  6599.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6600.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6601.  corr =  ctx.measureText(xaxislabel).width;\
  6602.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  6603.  ctx.restore();\
  6604. };\
  6605. if( typeof yaxislabel !== 'undefined' ){\
  6606.  ctx.save();\
  6607.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6608.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6609.  corr = ctx.measureText(yaxislabel).width;\
  6610.  ctx.translate(xmarge+font_size,corr+font_size);\
  6611.  ctx.rotate(-0.5*Math.PI);\
  6612.  ctx.fillText(yaxislabel,0,0);\
  6613.  ctx.restore();\
  6614. };\
  6615. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6616. ctx.lineWidth = line_width;\
  6617. for(var p = x_min; p <= x_max ; p++){\
  6618.  num = Math.pow(xlogbase,p);\
  6619.  for(var i = 1 ; i < xlogbase ; i++){\
  6620.   x_e = x2px(i*num);\
  6621.   if( i == 1 ){\
  6622.    ctx.lineWidth = line_width;\
  6623.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6624.    if( use_axis_numbering == 1 && p > x_min){\
  6625.      xtxt = xlogbase+'^'+p.toFixed(0);\
  6626.      corr = 0.5*(ctx.measureText(xtxt).width);\
  6627.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  6628.    };\
  6629.   }else{\
  6630.    ctx.lineWidth = 0.2*line_width;\
  6631.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6632.   };\
  6633.   if( x_e >= xmarge ){\
  6634.    ctx.beginPath();\
  6635.    ctx.moveTo(x_e,0);\
  6636.    ctx.lineTo(x_e,ysize - ymarge);\
  6637.    ctx.stroke();\
  6638.    ctx.closePath();\
  6639.   };\
  6640.  };\
  6641. };\
  6642. for(var p = y_min; p <= y_max ; p++){\
  6643.  num = Math.pow(ylogbase,p);\
  6644.  for(var i = 1 ; i < ylogbase ; i++){\
  6645.   y_e = y2px(i*num);\
  6646.   if( i == 1 ){\
  6647.    ctx.lineWidth = line_width;\
  6648.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6649.    if( use_axis_numbering == 1 && p > y_min){\
  6650.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  6651.    };\
  6652.   }else{\
  6653.    ctx.lineWidth = 0.2*line_width;\
  6654.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6655.   };\
  6656.   ctx.beginPath();\
  6657.   ctx.moveTo(xmarge,y_e);\
  6658.   ctx.lineTo(xsize,y_e);\
  6659.   ctx.stroke();\
  6660.   ctx.closePath();\
  6661.  };\
  6662. };\
  6663. ctx.restore();\
  6664. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  6665.     break;
  6666.  
  6667. case DRAW_XLOGSCALE:
  6668. fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\
  6669. 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){\
  6670. var obj;\
  6671. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6672.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6673. }\
  6674. else\
  6675. {\
  6676.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6677. };\
  6678. var ctx = obj.getContext(\"2d\");\
  6679. ctx.clearRect(0,0,xsize,ysize);\
  6680. ctx.save();\
  6681. ctx.lineWidth = line_width;\
  6682. var prec = Math.log(precision)/Math.log(10);\
  6683. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  6684. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  6685. var y_min = 0;var y_max = ysize;var x_e;var corr;\
  6686. var xtxt;var ytxt;var num;var xmarge;var ymarge;\
  6687. if(use_axis_numbering == 1){\
  6688.  ctx.font = font_family;\
  6689.  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
  6690.  ymarge = parseInt(1.5*font_size);\
  6691.  ctx.save();\
  6692.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  6693.  ctx.rect(0,0,xmarge,ysize);\
  6694.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  6695.  ctx.fill();\
  6696.  ctx.restore();\
  6697. }else{xmarge = 0;ymarge = 0;};\
  6698. if( typeof xaxislabel !== 'undefined' ){\
  6699.  ctx.save();\
  6700.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6701.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6702.  corr =  ctx.measureText(xaxislabel).width;\
  6703.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  6704.  ctx.restore();\
  6705. };\
  6706. if( typeof yaxislabel !== 'undefined' ){\
  6707.  ctx.save();\
  6708.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6709.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6710.  corr = ctx.measureText(yaxislabel).width;\
  6711.  ctx.translate(xmarge+font_size,corr+font_size);\
  6712.  ctx.rotate(-0.5*Math.PI);\
  6713.  ctx.fillText(yaxislabel,0,0);\
  6714.  ctx.restore();\
  6715. };\
  6716. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6717. ctx.lineWidth = line_width;\
  6718. for(var p = x_min; p <= x_max ; p++){\
  6719.  num = Math.pow(xlogbase,p);\
  6720.  for(var i = 1 ; i < xlogbase ; i++){\
  6721.   x_e = x2px(i*num);\
  6722.   if( i == 1 ){\
  6723.     ctx.lineWidth = line_width;\
  6724.     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6725.    if( use_axis_numbering == 1 && p > x_min ){\
  6726.      xtxt = xlogbase+'^'+p.toFixed(0);\
  6727.      corr = 0.5*(ctx.measureText(xtxt).width);\
  6728.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  6729.    };\
  6730.   }else{\
  6731.    ctx.lineWidth = 0.2*line_width;\
  6732.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6733.   };\
  6734.   if( x_e >= xmarge ){\
  6735.    ctx.beginPath();\
  6736.    ctx.moveTo(x_e,0);\
  6737.    ctx.lineTo(x_e,ysize - ymarge);\
  6738.    ctx.stroke();\
  6739.    ctx.closePath();\
  6740.   };\
  6741.  };\
  6742. };\
  6743. var stepy = Math.abs(y2px(ymajor) - y2px(0));\
  6744. var minor_step = stepy / yminor;\
  6745. for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
  6746.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6747.  ctx.lineWidth = line_width;\
  6748.  ctx.beginPath();\
  6749.  ctx.moveTo(xmarge,y);\
  6750.  ctx.lineTo(xsize,y);\
  6751.  ctx.stroke();\
  6752.  ctx.closePath();\
  6753.  if( use_axis_numbering == 1){\
  6754.   ytxt = (px2y(y)).toFixed(prec);\
  6755.   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
  6756.  };\
  6757.  for(var dy = 1 ; dy < yminor ; dy++){\
  6758.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6759.   ctx.lineWidth = 0.2*line_width;\
  6760.   ctx.beginPath();\
  6761.   ctx.moveTo(xmarge,y+dy*minor_step);\
  6762.   ctx.lineTo(xsize,y+dy*minor_step);\
  6763.   ctx.stroke();\
  6764.   ctx.closePath();\
  6765.  };\
  6766. };\
  6767. ctx.restore();\
  6768. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  6769.     break;
  6770. case DRAW_YLOGSCALE:
  6771. fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\
  6772. 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){\
  6773. var obj;\
  6774. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6775.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6776. }\
  6777. else\
  6778. {\
  6779.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6780. };\
  6781. var ctx = obj.getContext(\"2d\");\
  6782. ctx.clearRect(0,0,xsize,ysize);\
  6783. ctx.save();\
  6784. ctx.lineWidth = line_width;\
  6785. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  6786. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  6787. var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
  6788. if(use_axis_numbering == 1){\
  6789.  ctx.font = font_family;\
  6790.  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
  6791.  ymarge = 2*font_size;\
  6792.  ctx.save();\
  6793.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  6794.  ctx.rect(0,0,xmarge,ysize);\
  6795.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  6796.  ctx.fill();\
  6797.  ctx.restore();\
  6798. }else{xmarge = 0;ymarge = 0;};\
  6799. if( typeof xaxislabel !== 'undefined' ){\
  6800.  ctx.save();\
  6801.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6802.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6803.  corr =  ctx.measureText(xaxislabel).width;\
  6804.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  6805.  ctx.restore();\
  6806. };\
  6807. if( typeof yaxislabel !== 'undefined' ){\
  6808.  ctx.save();\
  6809.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6810.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6811.  corr = ctx.measureText(yaxislabel).width;\
  6812.  ctx.translate(xmarge+font_size,corr+font_size);\
  6813.  ctx.rotate(-0.5*Math.PI);\
  6814.  ctx.fillText(yaxislabel,0,0);\
  6815.  ctx.restore();\
  6816. };\
  6817. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6818. ctx.lineWidth = line_width;\
  6819. for(var p = y_min; p <= y_max ; p++){\
  6820.  num = Math.pow(ylogbase,p);\
  6821.  for(var i = 1 ; i < ylogbase ; i++){\
  6822.   y_e = y2px(i*num);\
  6823.   if( i == 1 ){\
  6824.    ctx.lineWidth = line_width;\
  6825.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6826.    if( use_axis_numbering == 1 && p > y_min){\
  6827.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  6828.    };\
  6829.   }else{\
  6830.    ctx.lineWidth = 0.2*line_width;\
  6831.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6832.   };\
  6833.   ctx.beginPath();\
  6834.   ctx.moveTo(xmarge,y_e);\
  6835.   ctx.lineTo(xsize,y_e);\
  6836.   ctx.stroke();\
  6837.   ctx.closePath();\
  6838.  };\
  6839. };\
  6840. var stepx = Math.abs(x2px(xmajor) - x2px(0));\
  6841. var minor_step = stepx / xminor;\
  6842. var prec = Math.log(precision)/Math.log(10);\
  6843. var xtxt;var corr;var flip = 0;\
  6844. for(var x = stepx ; x < xsize ; x = x + stepx){\
  6845.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6846.  ctx.lineWidth = line_width;\
  6847.  ctx.beginPath();\
  6848.  ctx.moveTo(x,ysize-ymarge);\
  6849.  ctx.lineTo(x,0);\
  6850.  ctx.stroke();\
  6851.  ctx.closePath();\
  6852.  if( use_axis_numbering == 1){\
  6853.   xtxt = (px2x(x)).toFixed(prec);\
  6854.   corr = 0.5*(ctx.measureText(xtxt).width);\
  6855.   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
  6856.   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
  6857.  };\
  6858.  for(var dx = 1 ; dx < xminor ; dx++){\
  6859.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6860.   ctx.lineWidth = 0.2*line_width;\
  6861.   ctx.beginPath();\
  6862.   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
  6863.   ctx.lineTo(x+dx*minor_step,0);\
  6864.   ctx.stroke();\
  6865.   ctx.closePath();\
  6866.  };\
  6867. };\
  6868. ctx.restore();\
  6869. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  6870.     break;
  6871.     default:break;
  6872.    }
  6873.   }
  6874.  }
  6875.   return;
  6876. }
  6877.  
  6878. void check_string_length(int L){
  6879.  if(L<1 || L > MAX_BUFFER-1){
  6880.   canvas_error("problem with your arguments to command...");
  6881.  }
  6882.  return;
  6883. }
  6884.  
  6885.  
  6886. int get_token(FILE *infile){
  6887.         int     c,i=0;
  6888.         char    temp[MAX_INT], *input_type;
  6889.         char    *line="line",
  6890.         *audio="audio",
  6891.         *blink="blink",
  6892.         *arrowhead="arrowhead",
  6893.         *crosshairsize="crosshairsize",
  6894.         *crosshair="crosshair",
  6895.         *crosshairs="crosshairs",
  6896.         *audioobject="audioobject",
  6897.         *style="style",
  6898.         *mouse="mouse",
  6899.         *mousex="mousex",
  6900.         *mousey="mousey",
  6901.         *mouse_display="display",
  6902.         *mouse_degree="mouse_degree",
  6903.         *userdraw="userdraw",
  6904.         *highlight="highlight",
  6905.         *http="http",
  6906.         *rays="rays",
  6907.         *dashtype="dashtype",
  6908.         *dashed="dashed",
  6909.         *filled="filled",
  6910.         *lattice="lattice",
  6911.         *parallel="parallel",
  6912.         *segment="segment",
  6913.         *segments="segments",
  6914.         *dsegment="dsegment",
  6915.         *seg="seg",
  6916.         *bgimage="bgimage",
  6917.         *bgcolor="bgcolor",
  6918.         *strokecolor="strokecolor",
  6919.         *backgroundimage="backgroundimage",
  6920.         *text="text",
  6921.         *textup="textup",
  6922.         *mouseprecision="mouseprecision",
  6923.         *precision="precision",
  6924.         *plotsteps="plotsteps",
  6925.         *plotstep="plotstep",
  6926.         *tsteps="tsteps",
  6927.         *curve="curve",
  6928.         *dcurve="dcurve",
  6929.         *plot="plot",
  6930.         *dplot="dplot",
  6931.         *levelcurve="levelcurve",
  6932.         *fontsize="fontsize",
  6933.         *fontcolor="fontcolor",
  6934.         *axis="axis",
  6935.         *axisnumbering="axisnumbering",
  6936.         *axisnumbers="axisnumbers",
  6937.         *arrow="arrow",
  6938.         *darrow="darrow",
  6939.         *arrow2="arrow2",
  6940.         *darrow2="darrow2",
  6941.         *arrows="arrows",
  6942.         *arrows2="arrows2",
  6943.         *zoom="zoom",
  6944.         *grid="grid",
  6945.         *hline="hline",
  6946.         *dhline="dhline",
  6947.         *drag="drag",
  6948.         *horizontalline="horizontalline",
  6949.         *vline="vline",
  6950.         *dvline="dvline",
  6951.         *verticalline="verticalline",
  6952.         *triangle="triangle",
  6953.         *ftriangle="ftriangle",
  6954.         *mathml="mathml",
  6955.         *html="html",
  6956.         *input="input",
  6957.         *clearbutton="clearbutton",
  6958.         *inputstyle="inputstyle",
  6959.         *textarea="textarea",
  6960.         *trange="trange",
  6961.         *ranget="ranget",
  6962.         *xrange="xrange",
  6963.         *yrange="yrange",
  6964.         *rangex="rangex",
  6965.         *rangey="rangey",
  6966.         *polyline="polyline",
  6967.         *polylines="polylines",
  6968.         *brokenline="brokenline",
  6969.         *brokenlines="brokenlines",
  6970.         *lines="lines",
  6971.         *poly="poly",
  6972.         *polygon="polygon",
  6973.         *fpolygon="fpolygon",
  6974.         *fpoly="fpoly",
  6975.         *filledpoly="filledpoly",
  6976.         *filledpolygon="filledpolygon",
  6977.         *rect="rect",
  6978.         *frect="frect",
  6979.         *rectangle="rectangle",
  6980.         *frectangle="frectangle",
  6981.         *square="square",
  6982.         *fsquare="fsquare",
  6983.         *dline="dline",
  6984.         *arc="arc",
  6985.         *filledarc="filledarc",
  6986.         *size="size",
  6987.         *string="string",
  6988.         *stringup="stringup",
  6989.         *copy="copy",
  6990.         *copyresized="copyresized",
  6991.         *opacity="opacity",
  6992.         *transparent="transparent",
  6993.         *fill="fill",
  6994.         *point="point",
  6995.         *points="points",
  6996.         *linewidth="linewidth",
  6997.         *circle="circle",
  6998.         *circles="circles",
  6999.         *fcircle="fcircle",
  7000.         *disk="disk",
  7001.         *comment="#",
  7002.         *end="end",
  7003.         *ellipse="ellipse",
  7004.         *fellipse="fellipse",
  7005.         *rotate="rotate",
  7006.         *affine="affine",
  7007.         *killaffine="killaffine",
  7008.         *fontfamily="fontfamily",
  7009.         *fillcolor="fillcolor",
  7010.         *clicktile="clicktile",
  7011.         *clicktile_colors="clicktile_colors",
  7012.         *translation="translation",
  7013.         *translate="translate",
  7014.         *killtranslation="killtranslation",
  7015.         *killtranslate="killtranslate",
  7016.         *onclick="onclick",
  7017.         *roundrect="roundrect",
  7018.         *froundrect="froundrect",
  7019.         *roundrectangle="roundrectangle",
  7020.         *patternfill="patternfill",
  7021.         *hatchfill="hatchfill",
  7022.         *diafill="diafill",
  7023.         *diamondfill="diamondfill",
  7024.         *dotfill="dotfill",
  7025.         *gridfill="gridfill",
  7026.         *imagefill="imagefill",
  7027.         *xlogbase="xlogbase",
  7028.         *ylogbase="ylogbase",
  7029.         *xlogscale="xlogscale",
  7030.         *ylogscale="ylogscale",
  7031.         *xylogscale="xylogscale",
  7032.         *intooltip="intooltip",
  7033.         *replyformat="replyformat",
  7034.         *floodfill="floodfill",
  7035.         *filltoborder="filltoborder",
  7036.         *clickfill="clickfill",
  7037.         *setpixel="setpixel",
  7038.         *pixels="pixels",
  7039.         *pixelsize="pixelsize",
  7040.         *clickfillmarge="clickfillmarge",
  7041.         *xaxis="xaxis",
  7042.         *yaxis="yaxis",
  7043.         *xaxistext="xaxistext",
  7044.         *yaxistext="yaxistext",
  7045.         *piechart="piechart",
  7046.         *legend="legend",
  7047.         *legendcolors="legendcolors",
  7048.         *xlabel="xlabel",
  7049.         *ylabel="ylabel",
  7050.         *barchart="barchart",
  7051.         *linegraph="linegraph",
  7052.         *clock="clock",
  7053.         *animate="animate",
  7054.         *video="video",
  7055.         *status="status",
  7056.         *nostatus="nostatus",
  7057.         *snaptogrid="snaptogrid",
  7058.         *xsnaptogrid="xsnaptogrid",
  7059.         *ysnaptogrid="ysnaptogrid",
  7060.         *userinput_xy="userinput_xy",
  7061.         *userinput_function="userinput_function",
  7062.         *usertextarea_xy="usertextarea_xy",
  7063.         *userinput="userinput",
  7064.         *jsmath="jsmath",
  7065.         *trace_jscurve="trace_jscurve",
  7066.         *setlimits="setlimits",
  7067.         *jscurve="jscurve",
  7068.         *jsplot="jsplot",
  7069.         *sgraph="sgraph",
  7070.         *title="title",
  7071.         *centerstring="centerstring",
  7072.         *xunit="xunit",
  7073.         *yunit="yunit",
  7074.         *slider="slider",
  7075.         *killslider="killslider",
  7076.         *angle="angle",
  7077.         *halfline="halfline",
  7078.         *demiline="demiline",
  7079.         *functionlabel="functionlabel";
  7080.  
  7081.         while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')){
  7082.             if( i == 0 && (c == ' ' || c == '\t') ){
  7083.         continue; /* white spaces or tabs allowed before first command identifier */
  7084.             }
  7085.             else
  7086.             {
  7087.         if( c == ' ' || c == '\t' ){
  7088.             break;
  7089.         }
  7090.         else
  7091.         {
  7092.             temp[i] = c;
  7093.             if(i > MAX_INT - 2){canvas_error("command string too long !");}
  7094.             i++;
  7095.         }
  7096.             }
  7097.             if(temp[0] == '#') break;
  7098.         }
  7099.         if (c == EOF) finished = 1;
  7100.  
  7101.         if (c == '\n' || c == '\r') {
  7102.         line_number++;
  7103.         if (i == 0) { return EMPTY; }
  7104.         } else if (c == EOF) {
  7105.         return 0;
  7106.         }
  7107.  
  7108.         temp[i]='\0';
  7109.         input_type=(char*)my_newmem(strlen(temp));
  7110.         snprintf(input_type,sizeof(temp),"%s",temp);
  7111.  
  7112.         if( strcmp(input_type, size) == 0 ){
  7113.         free(input_type);
  7114.         return SIZE;
  7115.         }
  7116.         if( strcmp(input_type, xrange) == 0 ){
  7117.         free(input_type);
  7118.         return XRANGE;
  7119.         }
  7120.         if( strcmp(input_type, rangex) == 0 ){
  7121.         free(input_type);
  7122.         return XRANGE;
  7123.         }
  7124.         if( strcmp(input_type, trange) == 0 ){
  7125.         free(input_type);
  7126.         return TRANGE;
  7127.         }
  7128.         if( strcmp(input_type, ranget) == 0 ){
  7129.         free(input_type);
  7130.         return TRANGE;
  7131.         }
  7132.         if( strcmp(input_type, yrange) == 0 ){
  7133.         free(input_type);
  7134.         return YRANGE;
  7135.         }
  7136.         if( strcmp(input_type, rangey) == 0 ){
  7137.         free(input_type);
  7138.         return YRANGE;
  7139.         }
  7140.         if( strcmp(input_type, linewidth) == 0 ){
  7141.         free(input_type);
  7142.         return LINEWIDTH;
  7143.         }
  7144.         if( strcmp(input_type, dashed) == 0 ){
  7145.         free(input_type);
  7146.         return DASHED;
  7147.         }
  7148.         if( strcmp(input_type, dashtype) == 0 ){
  7149.         free(input_type);
  7150.         return DASHTYPE;
  7151.         }
  7152.         if( strcmp(input_type, axisnumbering) == 0 ){
  7153.         free(input_type);
  7154.         return AXIS_NUMBERING;
  7155.         }
  7156.         if( strcmp(input_type, axisnumbers) == 0 ){
  7157.         free(input_type);
  7158.         return AXIS_NUMBERING;
  7159.         }
  7160.         if( strcmp(input_type, axis) == 0 ){
  7161.         free(input_type);
  7162.         return AXIS;
  7163.         }
  7164.         if( strcmp(input_type, grid) == 0 ){
  7165.         free(input_type);
  7166.         return GRID;
  7167.         }
  7168.         if( strcmp(input_type, parallel) == 0 ){
  7169.         free(input_type);
  7170.         return PARALLEL;
  7171.         }
  7172.         if( strcmp(input_type, hline) == 0 ||  strcmp(input_type, horizontalline) == 0 ){
  7173.         free(input_type);
  7174.         return HLINE;
  7175.         }
  7176.         if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
  7177.         free(input_type);
  7178.         return VLINE;
  7179.         }
  7180.         if( strcmp(input_type, line) == 0 ){
  7181.         free(input_type);
  7182.         return LINE;
  7183.         }
  7184.         if( strcmp(input_type, segments) == 0 ){
  7185.         free(input_type);
  7186.         return SEGMENTS;
  7187.         }
  7188.         if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
  7189.         free(input_type);
  7190.         return SEGMENT;
  7191.         }
  7192.         if( strcmp(input_type, dsegment) == 0 ){
  7193.         free(input_type);
  7194.         use_dashed = TRUE;
  7195.         return SEGMENT;
  7196.         }
  7197.         if( strcmp(input_type, crosshairsize) == 0 ){
  7198.         free(input_type);
  7199.         return CROSSHAIRSIZE;
  7200.         }
  7201.         if( strcmp(input_type, arrowhead) == 0 ){
  7202.         free(input_type);
  7203.         return ARROWHEAD;
  7204.         }
  7205.         if( strcmp(input_type, crosshairs) == 0 ){
  7206.         free(input_type);
  7207.         return CROSSHAIRS;
  7208.         }
  7209.         if( strcmp(input_type, crosshair) == 0 ){
  7210.         free(input_type);
  7211.         return CROSSHAIR;
  7212.         }
  7213.         if( strcmp(input_type, onclick) == 0 ){
  7214.         free(input_type);
  7215.         return ONCLICK;
  7216.         }
  7217.         if( strcmp(input_type, drag) == 0 ){
  7218.         free(input_type);
  7219.         return DRAG;
  7220.         }
  7221.         if( strcmp(input_type, userdraw) == 0 ){
  7222.         free(input_type);
  7223.         return USERDRAW;
  7224.         }
  7225.         if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
  7226.         free(input_type);
  7227.         return STYLE;
  7228.         }
  7229.         if( strcmp(input_type, fillcolor) == 0 ){
  7230.         free(input_type);
  7231.         return FILLCOLOR;
  7232.         }
  7233.         if( strcmp(input_type, strokecolor) == 0 ){
  7234.         free(input_type);
  7235.         return STROKECOLOR;
  7236.         }
  7237.         if( strcmp(input_type, filled) == 0  ){
  7238.         free(input_type);
  7239.         return FILLED;
  7240.         }
  7241.         if( strcmp(input_type, http) == 0 ){
  7242.         free(input_type);
  7243.         return HTTP;
  7244.         }
  7245.         if( strcmp(input_type, rays) == 0 ){
  7246.         free(input_type);
  7247.         return RAYS;
  7248.         }
  7249.         if( strcmp(input_type, lattice) == 0 ){
  7250.         free(input_type);
  7251.         return LATTICE;
  7252.         }
  7253.         if( strcmp(input_type, bgimage) == 0 ){
  7254.         free(input_type);
  7255.         return BGIMAGE;
  7256.         }
  7257.         if( strcmp(input_type, bgcolor) == 0 ){
  7258.         free(input_type);
  7259.         return BGCOLOR;
  7260.         }
  7261.         if( strcmp(input_type, backgroundimage) == 0 ){
  7262.         free(input_type);
  7263.         return BGIMAGE;
  7264.         }
  7265.         if( strcmp(input_type, text) == 0 ){
  7266.         free(input_type);
  7267.         return FLY_TEXT;
  7268.         }
  7269.         if( strcmp(input_type, textup) == 0 ){
  7270.         free(input_type);
  7271.         return FLY_TEXTUP;
  7272.         }
  7273.         if( strcmp(input_type, mouse) == 0 ){
  7274.         free(input_type);
  7275.         return MOUSE;
  7276.         }
  7277.         if( strcmp(input_type, mousex) == 0 ){
  7278.         free(input_type);
  7279.         return MOUSEX;
  7280.         }
  7281.         if( strcmp(input_type, mousey) == 0 ){
  7282.         free(input_type);
  7283.         return MOUSEY;
  7284.         }
  7285.         if( strcmp(input_type, mouse_degree) == 0 ){
  7286.         free(input_type);
  7287.         return MOUSE_DEGREE;
  7288.         }
  7289.         if( strcmp(input_type, mouse_display) == 0 ){
  7290.         free(input_type);
  7291.         return MOUSE_DISPLAY;
  7292.         }
  7293.         if( strcmp(input_type, mouseprecision) == 0 ){
  7294.         free(input_type);
  7295.         return MOUSE_PRECISION;
  7296.         }
  7297.         if( strcmp(input_type, precision) == 0 ){
  7298.         free(input_type);
  7299.         return MOUSE_PRECISION;
  7300.         }
  7301.         if( strcmp(input_type, curve) == 0 ){
  7302.         free(input_type);
  7303.         return CURVE;
  7304.         }
  7305.         if( strcmp(input_type, dcurve) == 0 ){
  7306.         use_dashed = TRUE;
  7307.         free(input_type);
  7308.         return CURVE;
  7309.         }
  7310.         if( strcmp(input_type, plot) == 0 ){
  7311.         free(input_type);
  7312.         return CURVE;
  7313.         }
  7314.         if( strcmp(input_type, dplot) == 0 ){
  7315.         use_dashed = TRUE;
  7316.         free(input_type);
  7317.         return CURVE;
  7318.         }
  7319.         if( strcmp(input_type, levelcurve) == 0 ){
  7320.         free(input_type);
  7321.         return LEVELCURVE;
  7322.         }
  7323.         if( strcmp(input_type, plotsteps) == 0 ){
  7324.         free(input_type);
  7325.         return PLOTSTEPS;
  7326.         }
  7327.         if( strcmp(input_type, plotstep) == 0 ){
  7328.         free(input_type);
  7329.         return PLOTSTEPS;
  7330.         }
  7331.         if( strcmp(input_type, tsteps) == 0 ){
  7332.         free(input_type);
  7333.         return PLOTSTEPS;
  7334.         }
  7335.         if( strcmp(input_type, fontsize) == 0 ){
  7336.         free(input_type);
  7337.         return FONTSIZE;
  7338.         }
  7339.         if( strcmp(input_type, fontcolor) == 0 ){
  7340.         free(input_type);
  7341.         return FONTCOLOR;
  7342.         }
  7343.         if( strcmp(input_type, arrow2) == 0 ){
  7344.         free(input_type);
  7345.         return ARROW2;
  7346.         }
  7347.         if( strcmp(input_type, darrow) == 0 ){
  7348.         free(input_type);
  7349.         use_dashed = TRUE;
  7350.         return ARROW;
  7351.         }
  7352.         if( strcmp(input_type, darrow2) == 0 ){
  7353.         free(input_type);
  7354.         use_dashed = TRUE;
  7355.         return ARROW2;
  7356.         }
  7357.         if( strcmp(input_type, arrows2) == 0 ){
  7358.         free(input_type);
  7359.         return ARROWS2;
  7360.         }
  7361.         if( strcmp(input_type, arrows) == 0 ){
  7362.         free(input_type);
  7363.         return ARROWS;
  7364.         }
  7365.         if( strcmp(input_type, arrow) == 0 ){
  7366.         free(input_type);
  7367.         return ARROW;
  7368.         }
  7369.         if( strcmp(input_type, zoom) == 0 ){
  7370.         free(input_type);
  7371.         return ZOOM;
  7372.         }
  7373.         if( strcmp(input_type, triangle) == 0 ){
  7374.         free(input_type);
  7375.         return TRIANGLE;
  7376.         }
  7377.         if( strcmp(input_type, ftriangle) == 0 ){
  7378.         free(input_type);
  7379.         use_filled = TRUE;
  7380.         return TRIANGLE;
  7381.         }
  7382.         if( strcmp(input_type, input) == 0 ){
  7383.         free(input_type);
  7384.         return INPUT;
  7385.         }
  7386.         if( strcmp(input_type, inputstyle) == 0 ){
  7387.         free(input_type);
  7388.         return INPUTSTYLE;
  7389.         }
  7390.         if( strcmp(input_type, textarea) == 0 ){
  7391.         free(input_type);
  7392.         return TEXTAREA;
  7393.         }
  7394.         if( strcmp(input_type, mathml) == 0 ){
  7395.         free(input_type);
  7396.         return MATHML;
  7397.         }
  7398.         if( strcmp(input_type, html) == 0 ){
  7399.         free(input_type);
  7400.         return MATHML;
  7401.         }
  7402.         if( strcmp(input_type, fontfamily) == 0 ){
  7403.         free(input_type);
  7404.         return FONTFAMILY;
  7405.         }
  7406.         if( strcmp(input_type, polyline) == 0 || strcmp(input_type, polylines) == 0 || strcmp(input_type, brokenline) == 0  || strcmp(input_type, brokenlines) == 0  ){
  7407.         free(input_type);
  7408.         return POLYLINE;
  7409.         }
  7410.         if( strcmp(input_type, lines) == 0 ){
  7411.         free(input_type);
  7412.         return LINES;
  7413.         }
  7414.         if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
  7415.         free(input_type);
  7416.         return RECT;
  7417.         }
  7418.         if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
  7419.         free(input_type);
  7420.         return ROUNDRECT;
  7421.         }
  7422.         if( strcmp(input_type, froundrect) == 0 ){
  7423.         free(input_type);
  7424.         use_filled = TRUE;
  7425.         return ROUNDRECT;
  7426.         }
  7427.         if( strcmp(input_type, square) == 0 ){
  7428.         free(input_type);
  7429.         return SQUARE;
  7430.         }
  7431.         if( strcmp(input_type, fsquare) == 0 ){
  7432.         free(input_type);
  7433.         use_filled = TRUE;
  7434.         return SQUARE;
  7435.         }
  7436.         if( strcmp(input_type, dline) == 0 ){
  7437.         use_dashed = TRUE;
  7438.         free(input_type);
  7439.         return LINE;
  7440.         }
  7441.         if( strcmp(input_type, dvline) == 0 ){
  7442.         use_dashed = TRUE;
  7443.         free(input_type);
  7444.         return VLINE;
  7445.         }
  7446.         if( strcmp(input_type, dhline) == 0 ){
  7447.         use_dashed = TRUE;
  7448.         free(input_type);
  7449.         return HLINE;
  7450.         }
  7451.         if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
  7452.         use_filled = TRUE;
  7453.         free(input_type);
  7454.         return RECT;
  7455.         }
  7456.         if( strcmp(input_type, circles) == 0 ){
  7457.         free(input_type);
  7458.         return CIRCLES;
  7459.         }
  7460.         if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
  7461.         use_filled = TRUE;
  7462.         free(input_type);
  7463.         return CIRCLE;
  7464.         }
  7465.         if( strcmp(input_type, circle) == 0 ){
  7466.         free(input_type);
  7467.         return CIRCLE;
  7468.         }
  7469.         if( strcmp(input_type, point) == 0 ){
  7470.         free(input_type);
  7471.         return POINT;
  7472.         }
  7473.         if( strcmp(input_type, points) == 0 ){
  7474.         free(input_type);
  7475.         return POINTS;
  7476.         }
  7477.         if( strcmp(input_type, filledarc) == 0 ){
  7478.         use_filled = TRUE;
  7479.         free(input_type);
  7480.         return ARC;
  7481.         }
  7482.         if( strcmp(input_type, arc) == 0 ){
  7483.         free(input_type);
  7484.         return ARC;
  7485.         }
  7486.         if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
  7487.         free(input_type);
  7488.         return POLY;
  7489.         }
  7490.         if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
  7491.         use_filled = TRUE;
  7492.         free(input_type);
  7493.         return POLY;
  7494.         }
  7495.         if( strcmp(input_type, ellipse) == 0){
  7496.         free(input_type);
  7497.         return ELLIPSE;
  7498.         }
  7499.         if( strcmp(input_type, fill) == 0 ){
  7500.         free(input_type);
  7501.         return FLOODFILL;
  7502.         }
  7503.         if( strcmp(input_type, string) == 0 ){
  7504.         free(input_type);
  7505.         return STRING;
  7506.         }
  7507.         if( strcmp(input_type, stringup) == 0 ){
  7508.         free(input_type);
  7509.         return STRINGUP;
  7510.         }
  7511.         if( strcmp(input_type, opacity) == 0 ){
  7512.         free(input_type);
  7513.         return OPACITY;
  7514.         }
  7515.         if( strcmp(input_type, comment) == 0){
  7516.         free(input_type);
  7517.         return COMMENT;
  7518.         }
  7519.         if( strcmp(input_type, end) == 0){
  7520.         free(input_type);
  7521.         return END;
  7522.         }
  7523.         if( strcmp(input_type, fellipse) == 0){
  7524.         free(input_type);
  7525.         use_filled = TRUE;
  7526.         return ELLIPSE;
  7527.         }
  7528.         if( strcmp(input_type, blink) == 0 ){
  7529.         free(input_type);
  7530.         return BLINK;
  7531.         }
  7532.         if( strcmp(input_type, clearbutton) == 0){
  7533.         free(input_type);
  7534.         return CLEARBUTTON;
  7535.         }
  7536.         if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
  7537.         free(input_type);
  7538.         return TRANSLATION;
  7539.         }
  7540.         if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
  7541.         free(input_type);
  7542.         return KILLTRANSLATION;
  7543.         }
  7544.         if( strcmp(input_type, rotate) == 0){
  7545.         free(input_type);
  7546.         return ROTATE;
  7547.         }
  7548.         if( strcmp(input_type, affine) == 0){
  7549.         free(input_type);
  7550.         return AFFINE;
  7551.         }
  7552.         if( strcmp(input_type, killaffine) == 0){
  7553.         free(input_type);
  7554.         return KILLAFFINE;
  7555.         }
  7556.         if( strcmp(input_type, audio) == 0 ){
  7557.         free(input_type);
  7558.         return AUDIO;
  7559.         }
  7560.         if( strcmp(input_type, audioobject) == 0 ){
  7561.         free(input_type);
  7562.         return AUDIOOBJECT;
  7563.         }
  7564.         if( strcmp(input_type, slider) == 0 ){
  7565.         free(input_type);
  7566.         return SLIDER;
  7567.         }
  7568.         if( strcmp(input_type, killslider) == 0 ){
  7569.         free(input_type);
  7570.         return KILLSLIDER;
  7571.         }
  7572.         if( strcmp(input_type, copy) == 0 ){
  7573.         free(input_type);
  7574.         return COPY;
  7575.         }
  7576.         if( strcmp(input_type, copyresized) == 0 ){
  7577.         free(input_type);
  7578.         return COPYRESIZED;
  7579.         }
  7580.         if( strcmp(input_type, patternfill) == 0 ){
  7581.         free(input_type);
  7582.         return PATTERNFILL;
  7583.         }
  7584.         if( strcmp(input_type, hatchfill) == 0 ){
  7585.         free(input_type);
  7586.         return HATCHFILL;
  7587.         }
  7588.         if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
  7589.         free(input_type);
  7590.         return DIAMONDFILL;
  7591.         }
  7592.         if( strcmp(input_type, dotfill) == 0 ){
  7593.         free(input_type);
  7594.         return DOTFILL;
  7595.         }
  7596.         if( strcmp(input_type, gridfill) == 0 ){
  7597.         free(input_type);
  7598.         return GRIDFILL;
  7599.         }
  7600.         if( strcmp(input_type, imagefill) == 0 ){
  7601.         free(input_type);
  7602.         return IMAGEFILL;
  7603.         }
  7604.         if( strcmp(input_type, clicktile_colors) == 0 ){
  7605.         free(input_type);
  7606.         return CLICKTILE_COLORS;
  7607.         }
  7608.         if( strcmp(input_type, clicktile) == 0 ){
  7609.         free(input_type);
  7610.         return CLICKTILE;
  7611.         }
  7612.         if( strcmp(input_type, xlogscale) == 0 ){
  7613.         free(input_type);
  7614.         return XLOGSCALE;
  7615.         }
  7616.         if( strcmp(input_type, ylogscale) == 0 ){
  7617.         free(input_type);
  7618.         return YLOGSCALE;
  7619.         }
  7620.         if( strcmp(input_type, xylogscale) == 0 ){
  7621.         free(input_type);
  7622.         return XYLOGSCALE;
  7623.         }
  7624.         if( strcmp(input_type, ylogscale) == 0 ){
  7625.         free(input_type);
  7626.         return YLOGSCALE;
  7627.         }
  7628.         if( strcmp(input_type, xlogbase) == 0 ){
  7629.         free(input_type);
  7630.         return XLOGBASE;
  7631.         }
  7632.         if( strcmp(input_type, ylogbase) == 0 ){
  7633.         free(input_type);
  7634.         return YLOGBASE;
  7635.         }
  7636.         if( strcmp(input_type, intooltip) == 0 ){
  7637.         free(input_type);
  7638.         return INTOOLTIP;
  7639.         }
  7640.         if( strcmp(input_type,video) == 0 ){
  7641.         free(input_type);
  7642.         return VIDEO;
  7643.         }
  7644.         if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
  7645.         free(input_type);
  7646.         return FLOODFILL;
  7647.         }
  7648.         if( strcmp(input_type,filltoborder) == 0 ){
  7649.         free(input_type);
  7650.         return FILLTOBORDER;
  7651.         }
  7652.         if( strcmp(input_type,clickfill) == 0 ){
  7653.         free(input_type);
  7654.         return CLICKFILL;
  7655.         }
  7656.         if( strcmp(input_type, replyformat) == 0 ){
  7657.         free(input_type);
  7658.         return REPLYFORMAT;
  7659.         }
  7660.         if( strcmp(input_type, pixelsize) == 0 ){
  7661.         free(input_type);
  7662.         return PIXELSIZE;
  7663.         }
  7664.         if( strcmp(input_type, setpixel) == 0 ){
  7665.         free(input_type);
  7666.         return SETPIXEL;
  7667.         }
  7668.         if( strcmp(input_type, pixels) == 0 ){
  7669.         free(input_type);
  7670.         return PIXELS;
  7671.         }
  7672.         if( strcmp(input_type, clickfillmarge) == 0 ){
  7673.         free(input_type);
  7674.         return CLICKFILLMARGE;
  7675.         }
  7676.         if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
  7677.         free(input_type);
  7678.         return X_AXIS_STRINGS;
  7679.         }
  7680.         if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
  7681.         free(input_type);
  7682.         return Y_AXIS_STRINGS;
  7683.         }
  7684.         if( strcmp(input_type, piechart) == 0  ){
  7685.         free(input_type);
  7686.         return PIECHART;
  7687.         }
  7688.         if( strcmp(input_type, barchart) == 0  ){
  7689.         free(input_type);
  7690.         return BARCHART;
  7691.         }
  7692.         if( strcmp(input_type, linegraph) == 0  ){
  7693.         free(input_type);
  7694.         return LINEGRAPH;
  7695.         }
  7696.         if( strcmp(input_type, clock) == 0  ){
  7697.         free(input_type);
  7698.         return CLOCK;
  7699.         }
  7700.         if( strcmp(input_type, legend) == 0  ){
  7701.         free(input_type);
  7702.         return LEGEND;
  7703.         }
  7704.         if( strcmp(input_type, legendcolors) == 0  ){
  7705.         free(input_type);
  7706.         return LEGENDCOLORS;
  7707.         }
  7708.         if( strcmp(input_type, xlabel) == 0  ){
  7709.         free(input_type);
  7710.         return XLABEL;
  7711.         }
  7712.         if( strcmp(input_type, ylabel) == 0  ){
  7713.         free(input_type);
  7714.         return YLABEL;
  7715.         }
  7716.         if( strcmp(input_type, animate) == 0  ){
  7717.         free(input_type);
  7718.         return ANIMATE;
  7719.         }
  7720.         /* these are bitmap related flydraw commmands...must be removed. eventually */
  7721.         if( strcmp(input_type, transparent) == 0 ){
  7722.         free(input_type);
  7723.         return TRANSPARENT;
  7724.         }
  7725.         if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
  7726.         free(input_type);
  7727.         return STATUS;
  7728.         }
  7729.         if( strcmp(input_type, snaptogrid) == 0 ){
  7730.         free(input_type);
  7731.         return SNAPTOGRID;
  7732.         }
  7733.         if( strcmp(input_type, xsnaptogrid) == 0 ){
  7734.         free(input_type);
  7735.         return XSNAPTOGRID;
  7736.         }
  7737.         if( strcmp(input_type, ysnaptogrid) == 0 ){
  7738.         free(input_type);
  7739.         return YSNAPTOGRID;
  7740.         }
  7741.         if( strcmp(input_type, userinput_xy) == 0 ){
  7742.         free(input_type);
  7743.         return USERINPUT_XY;
  7744.         }
  7745.         if( strcmp(input_type, userinput_function) == 0 ){
  7746.         free(input_type);
  7747.         return USERINPUT_FUNCTION;
  7748.         }
  7749.         if( strcmp(input_type, usertextarea_xy) == 0 ){
  7750.         free(input_type);
  7751.         return USERTEXTAREA_XY;
  7752.         }
  7753.         if( strcmp(input_type, userinput) == 0 ){
  7754.         free(input_type);
  7755.         return USERINPUT;
  7756.         }
  7757.         if( strcmp(input_type, sgraph) == 0 ){
  7758.         free(input_type);
  7759.         return SGRAPH;
  7760.         }
  7761.         if( strcmp(input_type, jsmath) == 0 ){
  7762.         free(input_type);
  7763.         return JSMATH;
  7764.         }
  7765.         if( strcmp(input_type, trace_jscurve) == 0 ){
  7766.         free(input_type);
  7767.         return TRACE_JSCURVE;
  7768.         }
  7769.         if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
  7770.         free(input_type);
  7771.         return JSCURVE;
  7772.         }
  7773.         if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
  7774.         free(input_type);
  7775.         return CENTERSTRING;
  7776.         }
  7777.         if( strcmp(input_type, setlimits) == 0 ){
  7778.         free(input_type);
  7779.         return SETLIMITS;
  7780.         }
  7781.         if( strcmp(input_type, xunit) == 0 ){
  7782.         free(input_type);
  7783.         return XUNIT;
  7784.         }
  7785.         if( strcmp(input_type, yunit) == 0 ){
  7786.         free(input_type);
  7787.         return YUNIT;
  7788.         }
  7789.         if( strcmp(input_type, angle) == 0 ){
  7790.         free(input_type);
  7791.         return ANGLE;
  7792.         }
  7793.         if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0  ){
  7794.         free(input_type);
  7795.         return HALFLINE;
  7796.         }
  7797.         if( strcmp(input_type, functionlabel) == 0 ){
  7798.         free(input_type);
  7799.         return FUNCTION_LABEL;
  7800.         }
  7801.         free(input_type);
  7802.         ungetc(c,infile);
  7803.         return 0;
  7804. }
  7805.  
  7806.