Subversion Repositories wimsdev

Rev

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

  1. /*
  2. 27/7/2013 version 0.01
  3. "Inspired" by FLY program: http://martin.gleeson.com/fly
  4. *********************************************************************************
  5. * J.M. Evers 7/2013                                                             *
  6. * This is all just amateur scriblings... So no copyrights.                      *
  7. * This source code file, and compiled objects derived from it,                  *
  8. * can be used and distributed without restriction, including for commercial use *
  9. * No warrenty whatsoever                                                        *
  10. *********************************************************************************
  11. */
  12.  
  13. #include "../../Lib/libwims.h"
  14. #include "canvasdraw.h"
  15. #include <assert.h>
  16. #include "canvasmacro.c"
  17.  
  18. /******************************************************************************
  19. **  Internal Functions
  20. ******************************************************************************/
  21. void    add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */
  22. void    sync_input(FILE *infile);/* proceed with inputfile */
  23. void    canvas_error(char *msg);
  24. void    add_javascript_functions(int js_functions[], int canvas_root_id);
  25. void    reset();/* reset some global variables like "use_filled" , "use_dashed" */
  26. int     get_token(FILE *infile); /* read next char until EOL*/
  27. int     x2px(double x);
  28. int     y2px(double y);
  29. double  px2x(int x);
  30. double  px2y(int y);
  31. double  get_real(FILE *infile,int last); /* read a value; calculation and symbols allowed */
  32. char    *str_replace ( const char *word, const char *sub_word, const char *rep_word );
  33. char    *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */
  34. char    *get_string(FILE *infile,int last); /* get the string at the end of a command */
  35. char    *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as  separator */
  36. char    *convert_hex2rgb(char *hexcolor);
  37. void    add_read_canvas(int reply_format,int reply_precision);
  38. void    make_js_include(int canvas_root_id);
  39. void    check_string_length(int length);/* checks if the length of string argument of command is correct */
  40. FILE    *js_include_file;
  41. FILE    *get_file(int *line_number, char **filename);
  42. FILE    *infile;    /* will be stdin */
  43. /******************************************************************************
  44. ** global
  45. ******************************************************************************/
  46. int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */
  47. int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */
  48. /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */
  49. int xsize = 320;
  50. int ysize = 320;
  51. double xmin = 0.0;
  52. double xmax = 320.0;
  53. double ymin = 0.0;
  54. double ymax = 320.0;
  55. double tmax = 2;
  56. double tmin = -2;
  57. /* flag to indicate parsing of line status */
  58. int done = FALSE;
  59. int type; /* eg command number */
  60. int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/
  61. int slider = 0;/* slider=1 : x-values ; slider=2 : y-values;slider=3 angle values */
  62. int use_affine = FALSE;
  63. int use_rotate = FALSE;
  64. int use_filled = FALSE;
  65. int use_dashed = FALSE; /* dashing not natively supported in firefox  , for now... */
  66.  
  67. char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */
  68.  
  69. /******************************************************************************
  70. ** Main Program
  71. ******************************************************************************/
  72. int main(int argc, char *argv[]){
  73.     /* need unique id for every call to canvasdraw : rand(); is too slow...will result in many identical id's */
  74.     struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);unsigned int canvas_root_id = (unsigned int) tv.tv_usec;
  75.     infile = stdin;/* read flyscript via stdin */
  76.     int i,c;
  77.     double double_data[MAX_INT+1];
  78.     int int_data[MAX_INT+1];
  79.     for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;}
  80.     int use_parametric = FALSE;/* will be reset after parametric plotting */
  81.     int use_axis = FALSE;
  82.     int use_axis_numbering = FALSE;
  83.     int use_pan_and_zoom = FALSE;
  84.     int use_safe_eval = FALSE; /* if true, add just once : js function to evaluate userinput values for plotting etc */
  85.     int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */
  86.     int use_js_plot = FALSE; /* if true , let js-engine plot the curve */
  87.     int line_width = 1;
  88.     int decimals = 2;
  89.     int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate */
  90.     int use_userdraw = FALSE; /* flag to indicate user interaction: incompatible with "drag & drop" code !! */
  91.     int drag_type = -1;/* 0,1,2 : xy,x,y */
  92.     int use_tooltip = FALSE;
  93.     char *tooltip_text = "Click here";
  94.     char *temp = ""; /* */
  95.     char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
  96.     char *stroke_color = "255,0,0";
  97.     char *fill_color = "0,255,0";
  98.     char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
  99.     char *font_color = "#00000";
  100.     char *draw_type = "points";
  101.     char *fly_font = "normal";
  102.     char *input_style = "";
  103.     char *flytext = "";
  104.     char *affine_matrix = "[1,0,0,1,0,0]";
  105.     int pixelsize = 1;
  106.     int reply_format = 0;
  107.     int input_cnt = 0;
  108.     int ext_img_cnt = 0;
  109.     int slider_cnt = 0;
  110.     int font_size = 12;
  111.     int dashtype[2] = { 4 , 4 };
  112.     int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */
  113.     for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
  114.     int arrow_head = 8; /* size in px*/
  115.     int crosshair_size = 5; /* size in px*/
  116.     int plot_steps = 250;
  117.     int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange*/
  118.     int click_cnt = 1;
  119.     int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
  120.     int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
  121.     int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/
  122.     int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc  */
  123.     int reply_precision = 100; /* used for precision of student answers / drawings */
  124.     double angle = 0.0;
  125.     int clickfillmarge = 20;
  126.     int animation_type = 9; /* == object type curve in drag library */
  127.     int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/
  128.     int use_slider_display = 0; /* in case of a slider, should we display it's value ?*/
  129.     size_t string_length = 0;
  130.     double stroke_opacity = 0.8;
  131.     double fill_opacity = 0.8;
  132.     char *URL = "http://localhost/images";
  133.     memset(buffer,'\0',MAX_BUFFER);
  134.     void *tmp_buffer = "";
  135.    
  136.     /* default writing a unzipped js-include file into wims getfile directory */
  137.     char *w_wims_session = getenv("w_wims_session");
  138.     if(  w_wims_session == NULL || *w_wims_session == 0 ){
  139.         canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");
  140.     }
  141.     int L0=strlen(w_wims_session) + 21;
  142.     char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
  143.     snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
  144.     mode_t process_mask = umask(0); /* check if file exists */
  145.     int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
  146.     if( result == 0 || errno == EEXIST ){
  147.      umask(process_mask); /* be sure to set correct permission */
  148.      char *w_session = getenv("w_session");
  149.      int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
  150.     char *getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
  151.      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 */   
  152.     /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
  153.     /* now write file into getfile dir*/
  154.     char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */
  155.     int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
  156.     char *location = my_newmem(L2); /* create memory to fit string precisely */
  157.     snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
  158.     js_include_file = fopen(location,"w");/* open the file location for writing */
  159.     /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */
  160.     if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );}
  161.  
  162. /* ----------------------------------------------------- */
  163. /* while more lines to process */
  164.  
  165.     while(!finished){
  166.         if(line_number>1 && found_size_command == 0){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
  167.         type = get_token(infile);
  168.         done = FALSE;
  169.         /*
  170.         @canvasdraw
  171.         @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...)
  172.         @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>
  173.         */
  174.         switch(type){
  175.         case END:
  176.         finished = 1;
  177.         done = TRUE;
  178.         break;
  179.         case 0:
  180.             sync_input(infile);
  181.             break;
  182.         case COMMENT:
  183.             sync_input(infile);
  184.             break;
  185.         case EMPTY:
  186.             sync_input(infile);
  187.             break;
  188.         case SIZE:
  189.             /*
  190.             @size width,height
  191.             @set canvas size in pixels
  192.             @mandatory first command
  193.             @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
  194.             */
  195.             found_size_command = 1;
  196.             xsize = (int)(abs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
  197.             ysize = (int)(abs(round(get_real(infile,1))));
  198.             /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
  199.             xmin = 0;xmax = xsize;
  200.             ymin = 0;ymax = ysize;
  201.  
  202. /*
  203.  The sequence in which stuff is finally printed is important !!
  204.  for example, when writing a 'include.js" the may not be a "script tag <script>" etc etc
  205. */
  206. fprintf(stdout,"\n<script type=\"text/javascript\">var wims_status = \"$status\";</script>\n<!-- canvasdraw div and tooltip placeholder, if needed -->\n<div tabindex=\"0\" id=\"canvas_div%d\" style=\"position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div><div id=\"tooltip_placeholder_div%d\" style=\"display:block;margin-bottom:4px;\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id);
  207. fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n");
  208. fprintf(stdout,"<!-- include actual object code via include file -->\n<script type=\"text/javascript\" src=\"%s\"></script>\n",getfile_cmd);
  209. fprintf(js_include_file,"\
  210. \"use strict\";\n\
  211. var read_dragdrop;\
  212. var read_canvas;\
  213. var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\
  214. var xsize = %d;\
  215. var ysize = %d;\
  216. var precision = 100;\
  217. var canvas_div = document.getElementById(\"canvas_div%d\");\
  218. 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;};\
  219. 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;};\
  220. 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);};};\
  221. 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);};};\
  222. 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);};};\
  223. 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);};};\
  224. function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
  225. function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
  226. function distance(x1,y1,x2,y2){return parseInt(Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ));};\
  227. 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) ));};\
  228. 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;};\
  229. 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;};\
  230. var x_use_snap_to_grid = 0;var y_use_snap_to_grid = 0;var snap_x = 1;var snap_y = 1;\
  231. function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
  232. function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\
  233. var xlogbase = 10;\
  234. var ylogbase = 10;\
  235. var use_xlogscale = 0;\
  236. var use_ylogscale = 0;\
  237. var x_strings = null;\
  238. var y_strings = null;\
  239. var use_pan_and_zoom = 0;\
  240. var use_jsmath = 0;\
  241. var xstart = 0;\
  242. var ystart = 0;\
  243. var unit_x=\" \";\
  244. var unit_y=\" \";",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  245. /* default add the drag code : nearly always used ...*/
  246. add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
  247.             break;
  248.         case XRANGE:
  249.         /*
  250.         @ xrange xmin,xmax
  251.         @ if not given: 0,xsize (eg in pixels)
  252.         */
  253.             for(i = 0 ; i<2; i++){
  254.                 switch(i){
  255.                     case 0: xmin = get_real(infile,0);break;
  256.                     case 1: xmax = get_real(infile,1);break;
  257.                     default: break;
  258.                 }
  259.             }
  260.             if(xmin >= xmax){canvas_error(" xrange is not OK : xmin &lt; xmax !\n");}
  261.             fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax);
  262.             found_size_command++;
  263.             break;
  264.         case YRANGE:
  265.         /*
  266.         @ yrange ymin,ymax
  267.         @ if not given 0,ysize (eg in pixels)
  268.         */
  269.             for(i = 0 ; i<2; i++){
  270.                 switch(i){
  271.                     case 0: ymin = get_real(infile,0);break;
  272.                     case 1: ymax = get_real(infile,1);break;
  273.                     default: break;
  274.                 }
  275.             }
  276.             if(ymin >= ymax){canvas_error(" yrange is not OK : ymin &lt; ymax !\n");}
  277.             fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax);
  278.             found_size_command++;
  279.             break;
  280.         case TRANGE:
  281.         /*
  282.         @ trange tmin,tmax
  283.         @ default -2,2
  284.         */
  285.             use_parametric = TRUE;
  286.             for(i = 0 ; i<2; i++){
  287.                 switch(i){
  288.                     case 0: tmin = get_real(infile,0);break;
  289.                     case 1: tmax = get_real(infile,1);break;
  290.                     default: break;
  291.                 }
  292.             }
  293.             if(tmin >= tmax ){canvas_error(" trange is not OK : tmin &lt; tmax!\n");}
  294.             break;
  295.         case LINEWIDTH:
  296.         /*
  297.         @ linewidth int
  298.         @ default 1
  299.         */
  300.             line_width = (int) (get_real(infile,1));
  301.             break;
  302.         case ARROWHEAD:
  303.         /*
  304.         @ arrowhead int
  305.         @ default 8 (pixels)
  306.         */
  307.             arrow_head = (int) (get_real(infile,1));
  308.             break;
  309.         case CROSSHAIRSIZE:
  310.         /*
  311.         @ crosshairsize int
  312.         @ default 10 (px)
  313.         */
  314.             crosshair_size = (int) (get_real(infile,1));
  315.             break;
  316.         case CROSSHAIR:
  317.         /*
  318.         @ crosshair x,y,color
  319.         @ draw a single crosshair point at (x;y) in color 'color'
  320.         @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
  321.         @ may be set draggable / onclick
  322.         */
  323.             for(i=0;i<3;i++){
  324.                 switch(i){
  325.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  326.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  327.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  328.                         decimals = find_number_of_digits(precision);
  329.                         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);
  330.                         click_cnt++;reset();
  331.                         break;
  332.                     default:break;
  333.                 }
  334.             }
  335.             break;
  336.         case CROSSHAIRS:
  337.         /*
  338.         @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
  339.         @ draw multiple crosshair points at given coordinates in color 'color'
  340.         @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
  341.         @ may be set draggable / onclick individually (!)
  342.         */
  343.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  344.             fill_color = stroke_color;
  345.             i=0;
  346.             while( ! done ){     /* get next item until EOL*/
  347.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  348.                 if(i%2 == 0 ){
  349.                     double_data[i] = get_real(infile,0); /* x */
  350.                 }
  351.                 else
  352.                 {
  353.                     double_data[i] = get_real(infile,1); /* y */
  354.                 }
  355.                 i++;
  356.             }
  357.             decimals = find_number_of_digits(precision);
  358.             for(c=0 ; c < i-1 ; c = c+2){
  359.                 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);
  360.                 click_cnt++;
  361.             }
  362.             reset();
  363.             break;
  364.         case POINT:
  365.         /*
  366.         @ point x,y,color
  367.         @ draw a single point at (x;y) in color 'color'
  368.         @ use command 'linewidth int'  to adust size
  369.         @ may be set draggable / onclick
  370.         @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming)
  371.         */
  372.             for(i=0;i<3;i++){
  373.                 switch(i){
  374.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  375.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  376.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  377.                     decimals = find_number_of_digits(precision);
  378.                     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);
  379.                     click_cnt++;break;
  380.                     default: break;
  381.                 }
  382.             }
  383.             reset();
  384.             break;
  385.         case POINTS:
  386.         /*
  387.         @ points color,x1,y1,x2,y2,...,x_n,y_n
  388.         @ draw multiple points at given coordinates in color 'color'
  389.         @ use command 'linewidth int'  to adust size
  390.         @ may be set draggable / onclick individually (!)
  391.         */
  392.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  393.             fill_color = stroke_color;
  394.             i=0;
  395.             while( ! done ){     /* get next item until EOL*/
  396.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  397.                 if(i%2 == 0 ){
  398.                     double_data[i] = get_real(infile,0); /* x */
  399.                 }
  400.                 else
  401.                 {
  402.                     double_data[i] = get_real(infile,1); /* y */
  403.                 }
  404.                 i++;
  405.             }
  406.             decimals = find_number_of_digits(precision);           
  407.             for(c = 0 ; c < i-1 ; c = c+2){
  408.                 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);
  409.                 click_cnt++;
  410.             }
  411.             reset();
  412.             break;
  413.         case SEGMENT:
  414.         /*
  415.         @ segment x1,y1,x2,y2,color
  416.         @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color'
  417.         @ may be set draggable / onclick
  418.         */
  419.             for(i=0;i<5;i++) {
  420.                 switch(i){
  421.                     case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
  422.                     case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
  423.                     case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
  424.                     case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
  425.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  426.                         decimals = find_number_of_digits(precision);
  427.                         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);
  428.                         click_cnt++;reset();
  429.                         break;
  430.                     default: break;
  431.                 }
  432.             }
  433.             break;
  434.         case LINE:
  435.         /*
  436.         @ line x1,y1,x2,y2,color
  437.         @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
  438.         @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
  439.         @ may be set draggable / onclick
  440.         */
  441.             for(i=0;i<5;i++){
  442.                 switch(i){
  443.                     case 0: double_data[10]= get_real(infile,0);break; /* x-values */
  444.                     case 1: double_data[11]= get_real(infile,0);break; /* y-values */
  445.                     case 2: double_data[12]= get_real(infile,0);break; /* x-values */
  446.                     case 3: double_data[13]= get_real(infile,0);break; /* y-values */
  447.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  448.                     if( double_data[10] == double_data[12] ){ /* vertical line*/
  449.                         double_data[1] = xmin;
  450.                         double_data[3] = ymax;
  451.                         double_data[0] = double_data[10];
  452.                         double_data[2] = double_data[10];
  453.                     }
  454.                     else
  455.                     {
  456.                         if( double_data[11] == double_data[13] ){ /* horizontal line */
  457.                             double_data[1] = double_data[11];
  458.                             double_data[3] = double_data[11];
  459.                             double_data[0] = ymin;
  460.                             double_data[2] = xmax;
  461.                         }
  462.                         else
  463.                         {
  464.                         /* m */
  465.                         double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
  466.                         /* q */
  467.                         double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
  468.                        
  469.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  470.                        
  471.                             double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
  472.                             double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
  473.                             double_data[0] = xmin;
  474.                             double_data[2] = xmax;
  475.                         }
  476.                     }
  477.                     decimals = find_number_of_digits(precision);
  478.                     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);
  479.                     click_cnt++;reset();
  480.                     break;
  481.                 }
  482.             }
  483.             break;
  484.         case HLINE:
  485.         /*
  486.         @ hline x,y,color
  487.         @ draw a horizontal line through point (x:y) in color 'color'
  488.         @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
  489.         @ may be set draggable / onclick
  490.         */
  491.             for(i=0;i<3;i++) {
  492.                 switch(i){
  493.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  494.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  495.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  496.                     double_data[3] = double_data[1];
  497.                     decimals = find_number_of_digits(precision);
  498.                     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);
  499.                     click_cnt++;reset();
  500.                     break;
  501.                 }
  502.             }
  503.             break;
  504.         case VLINE:
  505.         /*
  506.         @ vline x,y,color
  507.         @ draw a vertical line through point (x:y) in color 'color'
  508.         @ may be set draggable / onclick
  509.         */
  510.             for(i=0;i<3;i++) {
  511.                 switch(i){
  512.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  513.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  514.                     case 2: stroke_color=get_color(infile,1);/* name or hex color */
  515.                         double_data[2] = double_data[0];
  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],%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);
  518.                         click_cnt++;reset();
  519.                     break;
  520.                 }
  521.             }
  522.             break;
  523.         case SQUARE:
  524.         /*
  525.         @ square x,y,side (px) ,color
  526.         @ draw a square with left top corner (x:y) with side 'side' in color 'color'
  527.         @ use command 'fsquare x,y,side,color' for a filled square
  528.         @ use command/keyword  'filled' before command 'square x,y,side,color'
  529.         @ use command 'fillcolor color' before 'fsquare' to set the fill colour.
  530.         @ may be set draggable / onclick
  531.         */
  532.             for(i=0;i<5;i++){
  533.                 switch(i){
  534.                     case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
  535.                     case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
  536.                     case 2:double_data[2] = (int) (get_real(infile,0));break; /* width in px */
  537.                     case 3:
  538.                         stroke_color = get_color(infile,1);/* name or hex color */
  539.                         decimals = find_number_of_digits(precision);
  540.                         double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
  541.                         double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
  542.                         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);
  543.                         click_cnt++;reset();
  544.                         break;
  545.                 }
  546.             }
  547.             break;
  548.         case ROUNDRECT:
  549.         /*
  550.         @ roundrect x1,y1,x2,y2,radius,color
  551.         @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle
  552.         @ use command/keyword  'filled' before command 'roundrect x1,y1,x2,y2,radius,color'
  553.         @ use command 'fillcolor color' before 'froundrect' to set the fill colour.
  554.         @ may be set draggable / onclick
  555.         */
  556.             for(i=0;i<6;i++){
  557.                 switch(i){
  558.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  559.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  560.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  561.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  562.                     case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
  563.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  564.                         /* ensure no inverted roundrect is produced... */
  565.                         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];}
  566.                         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];}
  567.                         decimals = find_number_of_digits(precision);
  568.                         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);
  569.                         click_cnt++;reset();
  570.                     break;
  571.                 }
  572.             }
  573.             break;
  574.         case RECT:
  575.         /*
  576.         @ rect x1,y1,x2,y2,color
  577.         @ use command 'rect x1,y1,x2,y2,color' for a filled rectangle
  578.         @ use command/keyword  'filled' before command 'rect x1,y1,x2,y2,color'
  579.         @ use command 'fillcolor color' before 'frect' to set the fill colour.
  580.         @ may be set draggable / onclick
  581.         */
  582.             for(i=0;i<5;i++){
  583.                 switch(i){
  584.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  585.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  586.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  587.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  588.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  589.                         decimals = find_number_of_digits(precision);
  590.                         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);
  591.                         click_cnt++;reset();
  592.                         break;
  593.                 }
  594.             }
  595.             break;
  596.         case POLYLINE:
  597.         /*
  598.         @ polyline color,x1,y1,x2,y2...x_n,y_n
  599.         @ may be set draggable / onclick
  600.         */
  601.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  602.             i=0;
  603.             c=0;
  604.             while( ! done ){     /* get next item until EOL*/
  605.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  606.                 for( c = 0 ; c < 2; c++){
  607.                     if(c == 0 ){
  608.                         double_data[i] = get_real(infile,0);
  609.                         i++;
  610.                     }
  611.                     else
  612.                     {
  613.                         double_data[i] = get_real(infile,1);
  614.                         i++;
  615.                     }
  616.                 }
  617.             }
  618.             /* draw path : not closed & not filled */
  619.             decimals = find_number_of_digits(precision);
  620.             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);
  621.             click_cnt++;reset();
  622.             break;
  623.         case POLY:
  624.         /*
  625.         @ poly color,x1,y1,x2,y2...x_n,y_n
  626.         @ draw closed polygon
  627.         @ use command 'fpoly' to fill it, use command 'fillcolor color' to set the fill color
  628.         @ may be set draggable / onclick
  629.         */
  630.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  631.             i=0;
  632.             c=0;
  633.             while( ! done ){     /* get next item until EOL*/
  634.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  635.                 for( c = 0 ; c < 2; c++){
  636.                     if(c == 0 ){
  637.                         double_data[i] = get_real(infile,0);
  638.                         i++;
  639.                     }
  640.                     else
  641.                     {
  642.                         double_data[i] = get_real(infile,1);
  643.                         i++;
  644.                     }
  645.                 }
  646.             }
  647.             /* draw path :  closed & optional filled */
  648.                 decimals = find_number_of_digits(precision);
  649.                 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);
  650.                 click_cnt++;reset();
  651.             break;
  652.         case ARC:
  653.         /*
  654.          @ arc xc,yc,width,height,start_angle,end_angle,color
  655.          @ can not be set "onclick" or "drag xy"
  656.          @ attention: width == height == radius in pixels
  657.          @ will not zoom in or zoom out (because radius is given in pixels an not in x/y-system !). Panning will work
  658.          @ use command 'angle' for scalable angle
  659.         */
  660.             for(i=0;i<7;i++){
  661.                 switch(i){
  662.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  663.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  664.                     case 2:int_data[0] = (int)(get_real(infile,0));break; /* width in pixels ! */
  665.                     case 3:int_data[1] = (int)(get_real(infile,0));break; /* height in pixels ! */
  666.                     case 4:double_data[2] = get_real(infile,0);break; /* start angle in degrees */
  667.                     case 5:double_data[3] = get_real(infile,0);break; /* end angle in degrees */
  668.                     case 6:stroke_color = get_color(infile,1);/* name or hex color */
  669.                     /* in Shape library:
  670.                         x[0] = x[1] = xc
  671.                         y[0] = y[1] = yc
  672.                         w[0] = w[1] = radius = width = height  
  673.                         h[0] = start_angle ; h[1] = end_engle
  674.                     */
  675.                         decimals = find_number_of_digits(precision);
  676.                         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);
  677.                         reset();
  678.                     break;
  679.                 }
  680.             }
  681.             break;
  682.         case ANGLE:
  683.         /*
  684.          @ angle xc,yc,width,start_angle,end_angle,color
  685.          @ width is in x-range
  686.          @ will zoom in/out
  687.          @ if size is controlled by command 'slider' use radians to set limits of slider.
  688.         */
  689.             for(i=0;i<7;i++){
  690.                 switch(i){
  691.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  692.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  693.                     case 2:double_data[2] = get_real(infile,0);break; /* width in pixels ! */
  694.                     case 3:double_data[3] = get_real(infile,0);break; /* start angle in degrees */
  695.                     case 4:double_data[4] = get_real(infile,0);break; /* end angle in degrees */
  696.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  697.                         decimals = find_number_of_digits(precision);
  698.                         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);
  699.                         reset();
  700.                     break;
  701.                 }
  702.             }
  703.             break;
  704.  
  705.         case ELLIPSE:
  706.         /*
  707.         @ ellipse xc,yc,radius_x,radius_y,color
  708.         @ a ellipse with center xc/yc in x/y-range
  709.         @ radius_x and radius_y are in pixels
  710.         @ may be set draggable / onclick
  711.         @ will shrink / expand on zoom out / zoom in
  712.         */
  713.             for(i=0;i<5;i++){
  714.                 switch(i){
  715.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  716.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  717.                     case 2:double_data[2] = get_real(infile,0);break; /* rx -> px  */
  718.                     case 3:double_data[3] = get_real(infile,0);break; /* ry -> px  */
  719.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  720.                         decimals = find_number_of_digits(precision);
  721.                         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);
  722.                         click_cnt++;reset();
  723.                     break;
  724.                 }
  725.             }
  726.             break;
  727.         case DASHTYPE:
  728.         /*
  729.         @ dashtype int ,int
  730.         @ When dashed is set, the objects will be drawn with this dashtyp
  731.         @ default value "dashtype 2,2"
  732.         */
  733.             for(i=0;i<2;i++){
  734.                 switch(i){
  735.                     case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
  736.                     case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
  737.                 }
  738.             }
  739.         break;
  740.         case CIRCLE:
  741.         /*
  742.         @ circle xc,yc,width (2*r in pixels),color
  743.         @ use command 'fcircle xc,yc,d,color' or command 'filled' for a filled disk
  744.         @ use command 'fillcolor color' to set the fillcolor
  745.         @ may be set draggable / onclick
  746.         @ will shrink / expand on zoom out / zoom in
  747.         */
  748.             for(i=0;i<4;i++){
  749.                 switch(i){
  750.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  751.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  752.                     case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out : radius in 'dx' xrange*/
  753.                     case 3: stroke_color = get_color(infile,1);/* name or hex color */
  754.                         decimals = find_number_of_digits(precision);
  755.                         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);
  756.                         click_cnt++;reset();
  757.                     break;
  758.                 }
  759.             }
  760.             break;
  761.         case RAYS:
  762.         /*
  763.          @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
  764.          @ draw rays in color 'color' and center (xc:yc)
  765.          @ may be set draggable or onclick (every individual ray)
  766.         */
  767.             stroke_color=get_color(infile,0);
  768.             fill_color = stroke_color;
  769.             double_data[0] = get_real(infile,0);/* xc */
  770.             double_data[1] = get_real(infile,0);/* yc */
  771.             i=2;
  772.             while( ! done ){     /* get next item until EOL*/
  773.                 if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");}
  774.                 if(i%2 == 0 ){
  775.                     double_data[i] = get_real(infile,0); /* x */
  776.                 }
  777.                 else
  778.                 {
  779.                     double_data[i] = get_real(infile,1); /* y */
  780.                 }
  781.             fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
  782.                 i++;
  783.             }
  784.            
  785.             if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
  786.             decimals = find_number_of_digits(precision);           
  787.             for(c=2; c<i;c = c+2){
  788.                 click_cnt++;
  789.                 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);
  790.             }
  791.             reset();
  792.             break;
  793.         case ARROW:
  794.         /*
  795.         @ arrow x1,y1,x2,y2,h,color
  796.         @ draw a single headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color'
  797.         @ use command 'linewidth int' to adjust thickness of the arrow
  798.         @ may be set draggable / onclick
  799.         */
  800.             for(i=0;i<6;i++){
  801.                 switch(i){
  802.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  803.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  804.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  805.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  806.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  807.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  808.                         decimals = find_number_of_digits(precision);
  809.                         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);
  810.                         click_cnt++;
  811.                         reset();
  812.                         break;
  813.                 }
  814.             }
  815.             break;
  816.         case ARROW2:
  817.         /*
  818.         @ arrow2 x1,y1,x2,y2,h,color
  819.         @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and  in color 'color'
  820.         @ use command 'arrowhead int' to adjust the arrow head size
  821.         @ use command 'linewidth int' to adjust thickness of the arrow
  822.         @ may be set draggable / onclick
  823.         */
  824.             for(i=0;i<6;i++){
  825.                 switch(i){
  826.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  827.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  828.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  829.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  830.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  831.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  832.                         decimals = find_number_of_digits(precision);
  833.                         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);
  834.                         click_cnt++;reset();
  835.                         break;
  836.                 }
  837.             }
  838.             break;
  839.         case PARALLEL:
  840.         /*
  841.          @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
  842.          @ can not be set "onclick" or "drag xy"
  843.         */
  844.             for( i = 0;i < 8; i++ ){
  845.                 switch(i){
  846.                     case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
  847.                     case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
  848.                     case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
  849.                     case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
  850.                     case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
  851.                     case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
  852.                     case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
  853.                     case 7: stroke_color=get_color(infile,1);/* name or hex color */
  854.                     decimals = find_number_of_digits(precision);
  855.                     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);
  856.                     click_cnt++;reset();
  857.                     break;
  858.                     default: break;
  859.                 }
  860.             }
  861.             break;
  862.         case TRIANGLE:
  863.         /*
  864.          @triangle x1,y1,x2,y2,x3,y3,color
  865.          @may be set draggable / onclic
  866.         */
  867.             for(i=0;i<7;i++){
  868.                 switch(i){
  869.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  870.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  871.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  872.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  873.                     case 4: double_data[4] = get_real(infile,0);break; /* x */
  874.                     case 5: double_data[5] = get_real(infile,0);break; /* y */
  875.                     case 6: stroke_color = get_color(infile,1);/* name or hex color */
  876.                         decimals = find_number_of_digits(precision);
  877.                         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);
  878.                         click_cnt++;reset();
  879.                         break;
  880.                     default: break;
  881.                 }
  882.             }
  883.             break;
  884.         case LATTICE:
  885.         /*
  886.          @lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
  887.          @can not be set "onclick" or "drag xy"
  888.         */
  889.             if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
  890.             for( i = 0; i<9; i++){
  891.                 switch(i){
  892.                     case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
  893.                     case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
  894.                     case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
  895.                     case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
  896.                     case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
  897.                     case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
  898.                     case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
  899.                     case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
  900.                     case 8: stroke_color=get_color(infile,1);
  901.                         decimals = find_number_of_digits(precision);
  902.                         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);
  903.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  904.                         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);
  905.                         add_to_buffer(tmp_buffer);
  906.                     break;
  907.                     default:break;
  908.                 }
  909.             }
  910.             reset();
  911.             break;
  912.         case SNAPTOGRID:
  913.         /*
  914.          @ snaptogrid
  915.          @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
  916.          @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
  917.          @ 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 />
  918.         */
  919.         fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;");
  920.         break;
  921.         case XSNAPTOGRID:
  922.         /*
  923.          @ xsnaptogrid
  924.          @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
  925.          @ in case of userdraw the drawn points will snap to xmajor grid
  926.          @ 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 />
  927.         */
  928.         fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 0;");
  929.         break;
  930.         case YSNAPTOGRID:
  931.         /*
  932.          @ ysnaptogrid
  933.          @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
  934.          @ in case of userdraw the drawn points will snap to ymajor grid
  935.          @ 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 />
  936.         */
  937.         fprintf(js_include_file,"\nx_use_snap_to_grid = 0;y_use_snap_to_grid = 1;");
  938.         break;
  939.         case USERTEXTAREA_XY:
  940.         /*
  941.         @ usertextarea_xy
  942.         @ keyword
  943.         @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being...
  944.         @ if set two textareas are added to the document<br />(one for x-values , one for y-values)
  945.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  946.         @ user drawings will not zoom on zooming (or pan on panning)
  947.         */
  948.             if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
  949.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  950.             use_input_xy = 2;
  951.             break;
  952.         case USERINPUT_XY:
  953.         /*
  954.         @ userinput_xy
  955.         @ keyword
  956.         @ to be used in combination with command "userdraw object_type,color"
  957.         @ 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)
  958.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  959.         @ 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.
  960.         @ can not be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields
  961.         @ user drawings will not zoom on zooming (or pan on panning)
  962.         */
  963.             /* add simple eval check to avoid code injection with unprotected eval(string) */
  964.             if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
  965.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  966.             use_input_xy = 1;
  967.             break;
  968.         case USERDRAW:
  969.         /*
  970.         @ userdraw object_type,color
  971.         @ 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>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>
  972.         @ 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)
  973.         @ 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
  974.         @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
  975.         @ 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)
  976.         @ use command "filled", "opacity int,int"  and "fillcolor color" to trigger coloured filling of fillable objects
  977.         @ use command "dashed" and/or "dashtype int,int" to trigger dashing
  978.         @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas();
  979.         @ may be combined with onclick or drag xy  of other components of flyscript objects (although not very usefull...)
  980.         @ may be combined with keyword 'userinput_xy' or
  981.         @ 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.!
  982.         */
  983.             if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
  984.                 canvas_error("Only one userdraw primitive may be used: read documentation !!");
  985.             }
  986.             reply_precision = precision;
  987.             use_userdraw = TRUE;
  988.             fprintf(js_include_file,"\n<!-- begin userdraw mouse events -->\nvar userdraw_x = new Array();var userdraw_y = new Array();var userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};if(wims_status != \"done\"){canvas_div.addEventListener(\"mousedown\",user_draw,false);canvas_div.addEventListener(\"mousemove\",user_drag,false);canvas_div.addEventListener(\"touchstart\",user_draw,false);canvas_div.addEventListener(\"touchmove\",user_drag,false);}\n<!-- end userdraw mouse events -->",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
  989.             draw_type = get_string_argument(infile,0);
  990.             stroke_color = get_color(infile,1);
  991.             if( strcmp(draw_type,"point") == 0 ){
  992.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  993.                 if(reply_format == 0 ){reply_format = 8;}
  994.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  995.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  996.                 if(use_input_xy == 1){
  997.                     add_input_circle(js_include_file,1,1);
  998.                     add_input_xy(js_include_file,canvas_root_id);
  999.                 }
  1000.                 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);
  1001.             }
  1002.             else
  1003.             if( strcmp(draw_type,"points") == 0 ){
  1004.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1005.                 if(reply_format == 0 ){reply_format = 8;}
  1006.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1007.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1008.                 if(use_input_xy == 1){
  1009.                     add_input_circle(js_include_file,1,2);
  1010.                     add_input_xy(js_include_file,canvas_root_id);
  1011.                 }
  1012.                 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);
  1013.             }
  1014.             else
  1015.             if( strcmp(draw_type,"segment") == 0 ){
  1016.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1017.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  1018.                 if(reply_format == 0){reply_format = 11;}
  1019.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1020.                 if(use_input_xy == 1){
  1021.                     add_input_segment(js_include_file,1);
  1022.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1023.                 }
  1024.                 add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1025.             }
  1026.             else
  1027.             if( strcmp(draw_type,"polyline") == 0 ){
  1028.                 if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
  1029.                 if(reply_format == 0){reply_format = 23;}
  1030.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1031.                 if( use_input_xy == 1 ){
  1032.                     add_input_polyline(js_include_file);
  1033.                     add_input_xy(js_include_file,canvas_root_id);
  1034.                 }
  1035.                 add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1036.             }
  1037.             else
  1038.             if( strcmp(draw_type,"segments") == 0 ){
  1039.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1040.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  1041.                 if(reply_format == 0){reply_format = 11;}
  1042.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1043.                 if(use_input_xy == 1){
  1044.                     add_input_segment(js_include_file,2);
  1045.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1046.                 }
  1047.                 add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1048.             }
  1049.             else
  1050.             if( strcmp(draw_type,"circle") == 0 ){
  1051.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1052.                 if(reply_format == 0){reply_format = 10;}
  1053.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  1054.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1055.                 if(use_input_xy == 1){
  1056.                     add_input_circle(js_include_file,2,1);
  1057.                     add_input_xyr(js_include_file,canvas_root_id);
  1058.                 }
  1059.                 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]);
  1060.             }
  1061.             else
  1062.             if( strcmp(draw_type,"circles") == 0 ){
  1063.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1064.                 if(reply_format == 0){reply_format = 10;}
  1065.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  1066.                 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]);
  1067.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1068.                 if(use_input_xy == 1){
  1069.                     add_input_circle(js_include_file,2,2);
  1070.                     add_input_xyr(js_include_file,canvas_root_id);
  1071.                 }
  1072.             }
  1073.             else
  1074.             if(strcmp(draw_type,"crosshair") == 0 ){
  1075.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  1076.                 if(reply_format == 0){reply_format = 8;}
  1077.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1078.                 add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
  1079.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1080.                 if(use_input_xy == 1){
  1081.                     add_input_crosshair(js_include_file,1);
  1082.                     add_input_xy(js_include_file,canvas_root_id);
  1083.                 }
  1084.             }
  1085.             else
  1086.             if(strcmp(draw_type,"crosshairs") == 0 ){
  1087.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  1088.                 if(reply_format == 0){reply_format = 8;}
  1089.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  1090.                 add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
  1091.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1092.                 if(use_input_xy == 1){
  1093.                     add_input_crosshair(js_include_file,2);
  1094.                     add_input_xy(js_include_file,canvas_root_id);
  1095.                 }
  1096.             }
  1097.             else
  1098.             if(strcmp(draw_type,"freehandline") == 0 ){
  1099.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1100.                 if(reply_format == 0){reply_format = 6;}
  1101.                 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]);  
  1102.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1103.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1104.             }
  1105.             else
  1106.             if(strcmp(draw_type,"freehandlines") == 0 ){
  1107.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1108.                 if(reply_format == 0){reply_format = 6;}
  1109.                 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]);  
  1110.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1111.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1112.             }
  1113.             else
  1114.             if(strcmp(draw_type,"path") == 0 ){
  1115.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1116.                 if(reply_format == 0){reply_format = 6;}
  1117.                 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]);  
  1118.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1119.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1120.             }
  1121.             else
  1122.             if(strcmp(draw_type,"paths") == 0 ){
  1123.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1124.                 if(reply_format == 0){reply_format = 6;}
  1125.                 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]);  
  1126.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1127.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1128.             }
  1129.             else
  1130.             if(strcmp(draw_type,"arrows") == 0 ){
  1131.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  1132.                 if(reply_format == 0){reply_format = 11;}
  1133.                 add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  1134.                 if(use_input_xy == 1){
  1135.                     add_input_arrow(js_include_file,2);
  1136.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1137.                 }
  1138.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1139.             }
  1140.             else
  1141.             if(strcmp(draw_type,"arrows2") == 0 ){
  1142.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  1143.                 if(reply_format == 0){reply_format = 11;}
  1144.                 add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  1145.                 if(use_input_xy == 1){
  1146.                     add_input_arrow(js_include_file,1);
  1147.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1148.                 }
  1149.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1150.             }
  1151.             else
  1152.             if(strcmp(draw_type,"arrow2") == 0 ){
  1153.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  1154.                 if(reply_format == 0){reply_format = 11;}
  1155.                 add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  1156.                 if(use_input_xy == 1){
  1157.                     add_input_arrow(js_include_file,1);
  1158.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1159.                 }
  1160.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1161.             }
  1162.             else
  1163.             if(strcmp(draw_type,"arrow") == 0 ){
  1164.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  1165.                 if(reply_format == 0){reply_format = 11;}
  1166.                 add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  1167.                 if(use_input_xy == 1){
  1168.                     add_input_arrow(js_include_file,1);
  1169.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1170.                 }
  1171.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1172.             }
  1173.             else
  1174.             if(strcmp(draw_type,"polygon") == 0){
  1175.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1176.                 if(reply_format == 0){reply_format = 2;}
  1177.                 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]);
  1178.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1179.                 if(use_input_xy == 2){
  1180.                   add_textarea_polygon(js_include_file);
  1181.                   add_textarea_xy(js_include_file,canvas_root_id);
  1182.                 }
  1183.             }
  1184.             else
  1185.             if(strncmp(draw_type,"poly",4) == 0){
  1186.                 if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
  1187.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1188.                 if(reply_format == 0){reply_format = 2;}
  1189.                 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]);
  1190.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1191.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1192.             }
  1193.             else
  1194.             if(strcmp(draw_type,"triangle") == 0){
  1195.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  1196.                 if(reply_format == 0){reply_format = 2;}
  1197.                 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]);
  1198.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1199.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1200.             }
  1201.             else
  1202.             if( strcmp(draw_type,"hline") == 0 ){
  1203.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1204.                 if(reply_format == 0){reply_format = 11;}
  1205.                 add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1206.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1207.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1208.             }
  1209.             else
  1210.             if( strcmp(draw_type,"hlines") == 0 ){
  1211.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1212.                 if(reply_format == 0){reply_format = 11;}
  1213.                 add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1214.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1215.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1216.             }
  1217.             else
  1218.             if( strcmp(draw_type,"vline") == 0 ){
  1219.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1220.                 if(reply_format == 0){reply_format = 11;}
  1221.                 add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1222.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1223.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1224.             }
  1225.             else
  1226.             if( strcmp(draw_type,"vlines") == 0 ){
  1227.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1228.                 if(reply_format == 0){reply_format = 11;}
  1229.                 add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1230.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1231.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1232.             }
  1233.             else
  1234.             if( strcmp(draw_type,"line") == 0 ){
  1235.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1236.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1237.                 if(reply_format == 0){reply_format = 11;}
  1238.                 add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1239.                 if( use_input_xy == 1 ){
  1240.                     add_input_line(js_include_file,1);
  1241.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1242.                 }
  1243.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1244.             }
  1245.             else
  1246.             if( strcmp(draw_type,"lines") == 0 ){
  1247.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1248.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1249.                 if(reply_format == 0){reply_format = 11;}
  1250.                 add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1251.                 if( use_input_xy == 1 ){
  1252.                     add_input_line(js_include_file,2);
  1253.                     add_input_x1y1x2y2(js_include_file,canvas_root_id);
  1254.                 }
  1255.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1256.             }
  1257.             else
  1258.             if( strcmp(draw_type,"rects") == 0){
  1259.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  1260.                 if(reply_format == 0){reply_format = 2;}
  1261.                 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]);
  1262.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1263.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1264.             }
  1265.             else
  1266.             if( strcmp(draw_type,"roundrects") == 0){
  1267.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  1268.                 if(reply_format == 0){reply_format = 2;}
  1269.                 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]);
  1270.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1271.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1272.             }
  1273.             else
  1274.             if( strcmp(draw_type,"rect") == 0){
  1275.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  1276.                 if(reply_format == 0){reply_format = 2;}
  1277.                 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]);
  1278.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1279.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1280.             }
  1281.             else
  1282.             if( strcmp(draw_type,"roundrect") == 0){
  1283.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  1284.                 if(reply_format == 0){reply_format = 2;}
  1285.                 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]);
  1286.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1287.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1288.             }
  1289.             else
  1290.             if( strcmp(draw_type,"arcs") == 0){
  1291.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  1292.                 if(reply_format == 0){reply_format = 25;}
  1293.                 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]);
  1294.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1295.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1296.             }
  1297.             else
  1298.             if( strcmp(draw_type,"arc") == 0){
  1299.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  1300.                 if(reply_format == 0){reply_format = 25;}
  1301.                 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]);
  1302.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1303.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1304.             }
  1305.             else
  1306.             if( strcmp(draw_type,"text") == 0){
  1307.                 if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}      
  1308.                 if(reply_format == 0){reply_format = 17;}
  1309.                 add_js_text(js_include_file,canvas_root_id,font_size,font_family,font_color,stroke_opacity);
  1310.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1311.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1312.             }
  1313.             else
  1314.             if( strcmp(draw_type,"inputs") == 0){
  1315.                 if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}    
  1316.                 if(reply_format == 0){reply_format = 15;}
  1317.                 add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width);
  1318.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1319.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1320.             }
  1321.             else
  1322.             if( strcmp(draw_type,"input") == 0){
  1323.                 if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}    
  1324.                 if(reply_format == 0){reply_format = 15;}
  1325.                 add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width);
  1326.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  1327.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  1328.             }
  1329.             else
  1330.             {
  1331.                 canvas_error("unknown drawtype or typo? ");
  1332.             }
  1333.             reset();
  1334.         break;
  1335.         case PLOTSTEPS:
  1336.             /*
  1337.              @ plotsteps a_number
  1338.              @ default 150
  1339.              @ use with care !
  1340.             */
  1341.             plot_steps = (int) (get_real(infile,1));
  1342.             break;
  1343.         case FONTSIZE:
  1344.         /*
  1345.          @fontsize font_size
  1346.          @default value 12
  1347.         */
  1348.             font_size = (int) (get_real(infile,1));
  1349.             break;
  1350.         case FONTCOLOR:
  1351.         /*
  1352.          @fontcolor color
  1353.          @color: hexcolor or colorname
  1354.          @default: black
  1355.          @example usage: x/y-axis text
  1356.         */
  1357.             font_color = get_color(infile,1);
  1358.             break;
  1359.         case ANIMATE:
  1360.         /*
  1361.          @animate type
  1362.          @REMOVED : this should be done with a slider
  1363.          @type may be "point" (nothing else , yet...)
  1364.          @the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber'
  1365.          @will animate a point on the next plot/curve command
  1366.          @the curve will not be draw
  1367.          @moves repeatedly from xmin to xmax
  1368.         */
  1369.             if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");}
  1370.             break;
  1371.         case LEVELCURVE:
  1372.         /*
  1373.         @levelcurve color,expression in x/y,l1,l2,...
  1374.         @draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
  1375.         @the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...)
  1376.         @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
  1377.         @note : the arrays for holding the javascript data are limited in size
  1378.         @note : reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...)
  1379.         */
  1380.             fill_color = get_color(infile,0);
  1381.             char *fun1 = get_string_argument(infile,0);
  1382.             if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  1383.             i = 0;
  1384.             done = FALSE;
  1385.             while( !done ){
  1386.              double_data[i] = get_real(infile,1);
  1387.              i++;
  1388.             }
  1389.             for(c = 0 ; c < i; c++){
  1390.              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);
  1391.              click_cnt++;
  1392.             }
  1393.             reset();
  1394.             break;
  1395.         case TRACE_JSCURVE:
  1396.         /*
  1397.          @trace_jscurve some_math_function
  1398.          @will use a crosshair to trace the jsmath curve
  1399.          @two inputfields will display the current x/y-values (numerical evaluation by javascript)
  1400.          @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  
  1401.          @use linewidth,strokecolor,crosshairsize to adjust the corsshair.
  1402.          @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...
  1403.         */
  1404.             if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  1405.             if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1406.             if( use_js_math == FALSE){
  1407.                 add_to_js_math(js_include_file);
  1408.                 use_js_math = TRUE;
  1409.             }
  1410.             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);
  1411.             break;
  1412.         case JSMATH:
  1413.         /*
  1414.             @jsmath some_math_function
  1415.             @will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
  1416.             @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  
  1417.             @example: jsmath sin(x^2)
  1418.             @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...
  1419.         */
  1420.             if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  1421.             if( use_js_math == FALSE){
  1422.                 add_to_js_math(js_include_file);
  1423.                 use_js_math = TRUE;
  1424.             }
  1425.             add_calc_y(js_include_file,canvas_root_id,get_string(infile,1));
  1426.             break;
  1427.         case JSCURVE:
  1428.         /*
  1429.          @jscurve color,formula(x)
  1430.          @your function will be plotted by the javascript engine of the client browser.
  1431.          @use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e
  1432.          @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...
  1433.          @Attention : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot !
  1434.          @no validity check is done by wims.
  1435.          @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
  1436.          @use command 'trace_jscurve formula(x)` for tracing
  1437.          @use commmand 'jsmath  formula(x)` for calculating and displaying indiviual points on the curve
  1438.          @can not be set draggable / onclick (yet)
  1439.          @commands plotjump / plotstep are not active for 'jscurve'
  1440.         */
  1441.             stroke_color = get_color(infile,0);
  1442.             if( use_js_math == FALSE){/* add this stuff only once...*/
  1443.                 add_to_js_math(js_include_file);
  1444.                 use_js_math = TRUE;
  1445.             }
  1446.             if( use_js_plot == FALSE){
  1447.                 use_js_plot = TRUE;
  1448.                 add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  1449.             }
  1450.             temp = get_string_argument(infile,1);
  1451.             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]);
  1452.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1453.             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]);
  1454.             add_to_buffer(tmp_buffer);
  1455.             use_js_plot++; /* we need to create multiple canvasses, so we may zoom and pan ?? */
  1456.  
  1457.         break;
  1458.         case CURVE:
  1459.         /*
  1460.          @curve color,formula(x)
  1461.          @plot color,formula(x)
  1462.          @use command trange before command curve / plot  (trange -pi,pi)<br />curve color,formula1(t),formula2(t)
  1463.          @use command "precision" to increase the number of digits of the plotted points
  1464.          @use command "plotsteps" to increase / decrease the amount of plotted points (default 150)
  1465.          @may be set draggable / onclick
  1466.         */
  1467.             if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
  1468.                 use_parametric = FALSE;
  1469.                 stroke_color = get_color(infile,0);
  1470.                 char *fun1 = get_string_argument(infile,0);
  1471.                 char *fun2 = get_string_argument(infile,1);
  1472.                 if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
  1473.                 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);
  1474.                 click_cnt++;
  1475.             }
  1476.             else
  1477.             {
  1478.                 stroke_color = get_color(infile,0);
  1479.                 char *fun1 = get_string_argument(infile,1);
  1480.                 if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} 
  1481.                 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);
  1482.                 click_cnt++;
  1483.             }
  1484.             animation_type = 9;/* reset to curve plotting without animation */
  1485.             reset();
  1486.             break;
  1487.         case FLY_TEXT:
  1488.         /*
  1489.         @ text fontcolor,x,y,font,text_string
  1490.         @ font may be described by keywords : giant,huge,normal,small,tiny
  1491.         @ use command 'fontsize' to increase base fontsize for these keywords
  1492.         @ may be set "onclick" or "drag xy"
  1493.         @ backwards compatible with flydraw
  1494.         @ unicode supported: text red,0,0,huge,\\u2232
  1495.         @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element
  1496.         @ 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.
  1497.         */
  1498.             for(i = 0; i < 5 ;i++){
  1499.                 switch(i){
  1500.                     case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
  1501.                     case 1: double_data[0] = get_real(infile,0);break; /* x */
  1502.                     case 2: double_data[1] = get_real(infile,0);break; /* y */
  1503.                     case 3: fly_font = get_string_argument(infile,0);
  1504.                             if(strcmp(fly_font,"giant") == 0){
  1505.                                 font_size = (int)(font_size + 24);
  1506.                             }
  1507.                             else
  1508.                             {
  1509.                                 if(strcmp(fly_font,"huge") == 0){
  1510.                                     font_size = (int)(font_size + 14);
  1511.                                 }
  1512.                                 else
  1513.                                 {
  1514.                                     if(strcmp(fly_font,"large") == 0){
  1515.                                         font_size = (int)(font_size + 6);
  1516.                                         }
  1517.                                         else
  1518.                                         {
  1519.                                             if(strcmp(fly_font,"small") == 0){
  1520.                                                 font_size = (int)(font_size - 4);
  1521.                                                 if(font_size<0){font_size = 8;}
  1522.                                         }
  1523.                                     }
  1524.                                 }
  1525.                             }
  1526.                             break; /* font_size ! */
  1527.                     case 4:
  1528.                         temp = get_string_argument(infile,1);
  1529.                         decimals = find_number_of_digits(precision);
  1530.                         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);
  1531.                         click_cnt++;reset();break;
  1532.                     default:break;
  1533.                 }
  1534.             }
  1535.             break;
  1536.         case FLY_TEXTUP:
  1537.         /*
  1538.          @ textup fontcolor,x,y,font,text_string
  1539.          @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
  1540.          @ font may be described by keywords : giant,huge,normal,small,tiny
  1541.          @ use command 'fontsize' to increase base fontsize for the keywords
  1542.          @ backwards compatible with flydraw
  1543.          @ unicode supported: textup red,0,0,huge,\\u2232
  1544.          @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element
  1545.          @ 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.
  1546.         */
  1547.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}  
  1548.             for(i = 0; i<5 ;i++){
  1549.                 switch(i){
  1550.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  1551.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  1552.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  1553.                     case 3: fly_font = get_string_argument(infile,0);
  1554.                             if(strcmp(fly_font,"giant") == 0){
  1555.                                 font_size = (int)(font_size + 24);
  1556.                             }
  1557.                             else
  1558.                             {
  1559.                                 if(strcmp(fly_font,"huge") == 0){
  1560.                                     font_size = (int)(font_size + 14);
  1561.                                 }
  1562.                                 else
  1563.                                 {
  1564.                                     if(strcmp(fly_font,"large") == 0){
  1565.                                         font_size = (int)(font_size + 6);
  1566.                                         }
  1567.                                         else
  1568.                                         {
  1569.                                             if(strcmp(fly_font,"small") == 0){
  1570.                                                 font_size = (int)(font_size - 4);
  1571.                                                 if(font_size<0){font_size = 8;}
  1572.                                         }
  1573.                                     }
  1574.                                 }
  1575.                             }
  1576.                             break; /* font_size ! */
  1577.                     case 4:
  1578.                     decimals = find_number_of_digits(precision);
  1579.                     temp = get_string_argument(infile,1);
  1580.                     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);
  1581.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1582.                     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);
  1583.                     add_to_buffer(tmp_buffer);
  1584.                     break;
  1585.                     default:break;
  1586.                 }
  1587.             }
  1588.             reset();
  1589.             break;
  1590.         case FONTFAMILY:
  1591.         /*
  1592.          @ fontfamily font_description
  1593.          @ set the font family; for browsers that support it
  1594.          @ font_description: Ariel ,Courier, Helvetica etc
  1595.          @ 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
  1596.          @ use correct syntax : 'font style' 'font size'px 'fontfamily'
  1597.         */
  1598.             font_family = get_string(infile,1);
  1599.             break;
  1600.         case STRINGUP:
  1601.         /*
  1602.          @ stringup color,x,y,rotation_degrees,the text string
  1603.          @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
  1604.          @ unicode supported: stringup red,0,0,45,\\u2232
  1605.          @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change
  1606.  
  1607.         */
  1608.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library : rotate / mouse issues */
  1609.             for(i=0;i<6;i++){
  1610.                 switch(i){
  1611.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  1612.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  1613.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  1614.                     case 3: double_data[0] = get_real(infile,0);break;/* rotation */
  1615.                     case 4: decimals = find_number_of_digits(precision);
  1616.                             temp = get_string_argument(infile,1);
  1617.                             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);
  1618.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1619.                             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);
  1620.                             add_to_buffer(tmp_buffer);
  1621.                             break;
  1622.                     default:break;
  1623.                 }
  1624.             }
  1625.             reset();
  1626.             break;
  1627.         case STRING:
  1628.         /*
  1629.          @ string color,x,y,the text string
  1630.          @ may be set "onclick" or "drag xy"
  1631.          @ unicode supported: string red,0,0,\\u2232
  1632.          @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
  1633.         */
  1634.             for(i=0;i<5;i++){
  1635.                 switch(i){
  1636.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  1637.                     case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
  1638.                     case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
  1639.                     case 3: decimals = find_number_of_digits(precision);
  1640.                         temp = get_string_argument(infile,1);
  1641.                         decimals = find_number_of_digits(precision);
  1642.                         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);
  1643.                         click_cnt++;reset();break;
  1644.                     default:break;
  1645.                 }
  1646.             }
  1647.             break;
  1648.         case CENTERSTRING:
  1649.         /*
  1650.          @ centerstring color,y-value,the text string
  1651.          @ title color,y-value,the text string
  1652.          @ draw a string centered on the canvas at y = y-value
  1653.          @ can not set "onclick" or "drag xy" (...)
  1654.          @ unicode supported: centerstring red,5,\\u2232
  1655.          @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
  1656.         */
  1657.             if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;}
  1658.             for(i=0;i<3;i++){
  1659.                 switch(i){
  1660.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  1661.                     case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
  1662.                     case 2: temp = get_string_argument(infile,1);
  1663.                             /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
  1664.                             decimals = find_number_of_digits(precision);
  1665.                             string_length = snprintf(NULL,0,
  1666.                             "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
  1667.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1668.                             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);
  1669.                             add_to_buffer(tmp_buffer);
  1670.                             break;
  1671.                     default:break;
  1672.                 }
  1673.             }
  1674.             break;
  1675.         case MATHML:
  1676.         /*
  1677.         @ mathml x1,y1,x2,y2,mathml_string
  1678.         @ mathml will be displayed in a rectangle left top (x1:y1) , right bottom (x2:y2)
  1679.         @ can be set onclick <br />(however dragging is not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
  1680.         @ 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();"
  1681.         @ 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....
  1682.        
  1683.         */
  1684.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  1685.             for(i=0;i<5;i++){
  1686.                 switch(i){
  1687.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  1688.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  1689.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  1690.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  1691.                     case 4: decimals = find_number_of_digits(precision);
  1692.                             if(onclick == 1 ){ onclick = click_cnt;click_cnt++;}
  1693.                             temp = get_string(infile,1);
  1694.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  1695.                             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);
  1696.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1697.                             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);
  1698.                             add_to_buffer(tmp_buffer);
  1699.                             /*
  1700.                              in case inputs are present , trigger adding the read_mathml()
  1701.                              if no other reply_format is defined
  1702.                              note: all other reply types will include a reading of elements with id='mathml'+p)
  1703.                              */
  1704.                             if(strstr(temp,"mathml0") != NULL){
  1705.                              if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
  1706.                             }
  1707.                             break;
  1708.                     default:break;
  1709.                 }
  1710.             }
  1711.             reset();
  1712.             break;
  1713.         case HTTP:
  1714.         /*
  1715.          @http x1,y1,x2,y2,http://some_adress.com
  1716.          @an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2)
  1717.          @do not use interactivity (or mouse) if the mouse needs to be active in the iframe
  1718.          @can not be 'set onclick' or 'drag xy'
  1719.         */
  1720.             if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}    
  1721.             for(i=0;i<5;i++){
  1722.                 switch(i){
  1723.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  1724.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  1725.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  1726.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  1727.                     case 4: decimals = find_number_of_digits(precision);
  1728.                             temp = get_string(infile,1);
  1729.                             if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
  1730.                             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);
  1731.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1732.                             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);
  1733.                             add_to_buffer(tmp_buffer);
  1734.                     break;
  1735.                 }
  1736.             }
  1737.             reset();
  1738.             break;
  1739.         case HTML:
  1740.         /*
  1741.          @ html x1,y1,x2,y2,html_string
  1742.          @ all tags are allowed
  1743.          @ can be set onclick <br />(dragging not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
  1744.          @ 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.
  1745.          
  1746.          note: uses the same code as 'mathml'
  1747.         */
  1748.             break;
  1749.         case X_AXIS_STRINGS:
  1750.         /*
  1751.          @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  1752.          @ xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  1753.          @ use these x-axis values in stead of default xmin...xmax
  1754.          @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
  1755.          @ if the 'x-axis words' are to big amd will overlap, a simple alternating offset will be applied
  1756.          @ 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
  1757.          @ 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
  1758.         */
  1759.             temp = get_string(infile,1);
  1760.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  1761.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  1762.             fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp);
  1763.             use_axis_numbering = 1;
  1764.             break;
  1765.         case Y_AXIS_STRINGS:
  1766.         /*
  1767.          @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  1768.          @ yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  1769.          @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
  1770.          @ use these y-axis values in stead of default ymin...ymax
  1771.          @ 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
  1772.         */
  1773.             temp = get_string(infile,1);
  1774.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  1775.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  1776.             fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
  1777.             use_axis_numbering = 1;
  1778.             break;
  1779.          
  1780.         case AXIS_NUMBERING:
  1781.         /*
  1782.             @ axisnumbering
  1783.             @ keyword, no arguments required
  1784.         */
  1785.             use_axis_numbering = 1;
  1786.             break;
  1787.         case AXIS:
  1788.         /*
  1789.             @ axis
  1790.             @ keyword, no arguments required
  1791.  
  1792.         */
  1793.             use_axis = TRUE;
  1794.             break;
  1795.         case KILLSLIDER:
  1796.         /*
  1797.          @ killslider
  1798.          @ keyword, no arguments required
  1799.          @ ends grouping of object under a preciously defined slider
  1800.         */
  1801.             slider = 0;
  1802.             break;
  1803.         case SLIDER:
  1804.         /*
  1805.         @ slider start_value,end_value,width px,height px,type,label
  1806.         @ type: xy,x,y,angle
  1807.         @ if a value display is desired, use<br />type:xy display,x display,y display,angle radian,angle degree
  1808.         @ is a unit for x / y value display is needed, use commands 'xunit' and / or 'yunit'
  1809.         @ use commmand 'slider' before draggable/clickable objects.
  1810.         @ 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'
  1811.         @ amount of sliders is not limited.
  1812.         @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value'
  1813.         @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page
  1814.         @ every draggable object may have it's own slider (no limit in amount of sliders)
  1815.         @ label: some slider text
  1816.         @ use fillcolor for slider ball
  1817.         @ use strokecolor for slider bar
  1818.         @ use fontfamily / fontcolor to set used fonts
  1819.         @ use opacity (only fill opacity will be used) to set transparency
  1820.         @ the slider canvas will be added to the 'tooltip div' : so incompatible with command tooltip ; setlimits etc
  1821.         */
  1822.             for(i=0; i<6 ; i++){
  1823.                 switch(i){
  1824.                     case 0: double_data[0] = get_real(infile,0);break; /* start value */
  1825.                     case 1: double_data[1] = get_real(infile,0);break; /* end value */
  1826.                     case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
  1827.                     case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
  1828.                     case 4: temp = get_string_argument(infile,0); /* type : xy,x,y,angle */
  1829.                     /* xy display*/
  1830.                     if(strstr(temp,"xy")!= 0){
  1831.                      slider = 4;
  1832.                     }
  1833.                     else
  1834.                     {
  1835.                      if(strstr(temp,"x") != 0){
  1836.                       slider = 1;
  1837.                      }
  1838.                      else
  1839.                      {
  1840.                       if(strstr(temp,"y") != 0){
  1841.                        slider = 2;
  1842.                       }
  1843.                       else
  1844.                       {
  1845.                        if(strstr(temp,"angle") != 0){ /* angle diplay radian */
  1846.                         slider = 3;
  1847.                        }
  1848.                        else
  1849.                        {
  1850.                         canvas_error("slider types may be : x , y , xy , angle");
  1851.                        }
  1852.                       }
  1853.                      }
  1854.                     }
  1855.                     if(strstr(temp,"display")!=0){
  1856.                      use_slider_display = 1; /* show x xy values in canvas window */
  1857.                     }
  1858.                     else
  1859.                     {
  1860.                      if(strstr(temp,"degree")!= 0){
  1861.                       use_slider_display = 2; /* show angle values in canvas window */
  1862.                      }
  1863.                      else
  1864.                      {
  1865.                       if(strstr(temp,"radian")!=0){
  1866.                        use_slider_display = 3; /* show radian values in canvas window */
  1867.                       }
  1868.                      }
  1869.                     }
  1870.                     if(use_slider_display != 0 && slider_cnt == 0){ /*add just once the display js-code */
  1871.                      add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity);
  1872.                     }
  1873.                     break;
  1874.                     case 5: /* some string used for slider description  */
  1875.                     slider_cnt++;
  1876.                     if(slider == 4){
  1877.                      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 );
  1878.                     }else{
  1879.                      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);
  1880.                     }
  1881.                     break;
  1882.                 }
  1883.              }
  1884.             break;
  1885.         case SGRAPH:
  1886.         /*
  1887.          @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
  1888.          @ primitive implementation of a 'broken scale' graph...
  1889.          @ 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 />
  1890.          @ 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
  1891.         */
  1892.             if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
  1893.             for(i = 0 ; i < 8 ;i++){
  1894.                 switch(i){
  1895.                     case 0:double_data[0] = get_real(infile,0);break;
  1896.                     case 1:double_data[1] = get_real(infile,0);break;
  1897.                     case 2:double_data[2] = get_real(infile,0);break;
  1898.                     case 3:double_data[3] = get_real(infile,0);break;
  1899.                     case 4:int_data[0] = (int)(get_real(infile,0));break;
  1900.                     case 5:int_data[1] = (int)(get_real(infile,0));break;
  1901.                     case 6:stroke_color = get_color(infile,0);break;
  1902.                     case 7:font_color = get_color(infile,1);
  1903.                     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);
  1904.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1905.                     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);
  1906.                     add_to_buffer(tmp_buffer);
  1907.                     break;
  1908.                     default:break;
  1909.                 }
  1910.             }
  1911.             /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
  1912.             break;
  1913.         case GRID:/* xmajor,ymajor,color [,xminor,yminor,tick length (px) ,color]*/
  1914.         /*
  1915.          @ grid step_x,step_y,gridcolor
  1916.          @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
  1917.          @ 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
  1918.          @ 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)
  1919.          @ can not be set "onclick" or "drag xy"
  1920.          @ 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')
  1921.          @ 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')
  1922.          @ 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')
  1923.         */
  1924.             if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
  1925.             if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
  1926.             for(i=0;i<4;i++){
  1927.                 switch(i){
  1928.                     case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
  1929.                     case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
  1930.                     case 2:
  1931.                     if( use_axis == TRUE ){
  1932.                         stroke_color = get_color(infile,0);
  1933.                         done = FALSE;
  1934.                         int_data[0] = (int) (get_real(infile,0));/* xminor */
  1935.                         int_data[1] = (int) (get_real(infile,0));/* yminor */
  1936.                         int_data[2] = (int) (get_real(infile,0));/* tic_length */
  1937.                         fill_color = get_color(infile,1); /* used as axis_color*/
  1938.                     }
  1939.                     else
  1940.                     {
  1941.                         int_data[0] = 1;
  1942.                         int_data[1] = 1;
  1943.                         stroke_color = get_color(infile,1);
  1944.                         fill_color = stroke_color;
  1945.                     }
  1946.                     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 !");}
  1947.                     /* set snap_x snap_y values in pixels */
  1948.                     fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
  1949.                     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);
  1950.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1951.                     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);
  1952.                     add_to_buffer(tmp_buffer);
  1953.                     break;
  1954.                 }
  1955.             }
  1956.             reset();
  1957.             break;
  1958.         case OPACITY:
  1959.         /*
  1960.         @ opacity 0-255,0-255
  1961.         @
  1962.         */
  1963.             for(i = 0 ; i<2;i++){
  1964.                 switch(i){
  1965.                     case 0: double_data[0]=(int)(get_real(infile,0));break;
  1966.                     case 1: double_data[1]=(int)(get_real(infile,1));break;
  1967.                     default: break;
  1968.                 }
  1969.             }
  1970.             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 ? */
  1971.             stroke_opacity = (double) (0.0039215*double_data[0]);/* 0.0 - 1.0 */
  1972.             fill_opacity = (double) (0.0039215*double_data[1]);/* 0.0 - 1.0 */
  1973.             break;
  1974.         case ROTATE:
  1975.         /*
  1976.          @rotate rotation_angle
  1977.          @angle in degrees
  1978.         */
  1979.             use_rotate = TRUE;
  1980.             angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */
  1981.             break;
  1982.         case KILLAFFINE:
  1983.         /*
  1984.         @ killaffine
  1985.         @ keyword : resets the transformation matrix to 1,0,0,1,0,0
  1986.         */
  1987.             use_affine = FALSE;
  1988.             snprintf(affine_matrix,14,"[1,0,0,1,0,0]");    
  1989.             break;
  1990.         case AFFINE:
  1991.         /*
  1992.          @affine a,b,c,d,tx,ty
  1993.          @ defines a transformation matrix for subsequent objects
  1994.          @ use keyword 'killaffine' to end the transformation
  1995.          @ note 1: only 'draggable' / 'noclick' objects can be transformed.
  1996.          @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet)
  1997.          @ note 3: no matrix operations on the transformation matrix implemented (yet)
  1998.          @ a : Scales the drawings horizontally
  1999.          @ b : Skews the drawings horizontally
  2000.          @ c : Skews the drawings vertically
  2001.          @ d : Scales the drawings vertically
  2002.          @ tx: Moves the drawings horizontally in xrange coordinate system
  2003.          @ ty: Moves the drawings vertically in yrange coordinate system
  2004.          @ the data precision is 2 decimals (printf : %2.f)
  2005.         */
  2006.             for(i = 0 ; i<6;i++){
  2007.                 switch(i){
  2008.                     case 0: double_data[0] = get_real(infile,0);break;
  2009.                     case 1: double_data[1] = get_real(infile,0);break;
  2010.                     case 2: double_data[2] = get_real(infile,0);break;
  2011.                     case 3: double_data[3] = get_real(infile,0);break;
  2012.                     case 4: double_data[4] = get_real(infile,0);break;
  2013.                     case 5: double_data[5] = get_real(infile,1);
  2014.                         use_affine = TRUE;
  2015.                         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));
  2016.                         check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
  2017.                         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));    
  2018.                         break;
  2019.                     default: break;
  2020.                 }
  2021.             }
  2022.         break;
  2023.         case KILLTRANSLATION:
  2024.         /*
  2025.          killtranslation
  2026.         */
  2027.             use_affine = FALSE;
  2028.             snprintf(affine_matrix,14,"[1,0,0,1,0,0]");    
  2029.             break;
  2030.         case TRANSLATION:
  2031.         /*
  2032.          @translation tx,ty
  2033.          @will translate the next object tx in xrange and ty in yrange
  2034.          @uase command 'killtranstation' to end the command
  2035.         */
  2036.             for(i = 0 ; i<2;i++){
  2037.                 switch(i){
  2038.                     case 0: double_data[0] = get_real(infile,0);break;
  2039.                     case 1: double_data[1] = get_real(infile,1);
  2040.                         use_affine = TRUE;
  2041.                         string_length = snprintf(NULL,0, "[1,0,0,1,%.2f,%.2f] ",double_data[0]*xsize/(xmax - xmin),-1*double_data[1]*ysize/(ymax - ymin));
  2042.                         check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
  2043.                         snprintf(affine_matrix,string_length,"[1,0,0,1,%.2f,%.2f] ",double_data[0]*xsize/(xmax - xmin),-1*double_data[1]*ysize/(ymax - ymin));
  2044.                         break;
  2045.                     default: break;
  2046.                 }
  2047.             }
  2048.         break;
  2049.  
  2050.         case DASHED:
  2051.         /*
  2052.         @ keyword "dashed"
  2053.         @ next object will be drawn with a dashed line
  2054.         @ change dashing scheme by using command "dashtype int,int)
  2055.         */
  2056.             use_dashed = TRUE;
  2057.             break;
  2058.         case FILLED:
  2059.         /*
  2060.         @ keyword "filled"
  2061.         @ the next 'fillable' object (only) will be filled
  2062.         @ use command "fillcolor color" to set fillcolor
  2063.         @ use command "opacity 0-255,0-255" to set stroke and fill-opacity
  2064.         @ 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 !
  2065.         */
  2066.             use_filled = TRUE;
  2067.             break;
  2068.         case STYLE:
  2069.         /*
  2070.          @highlight color,opacity,linewidth
  2071.          @ NOT IMPLEMENTED
  2072.          @ use command "onclick" : when the object receives a userclick it will increase it's linewidth
  2073.         */
  2074.             break;
  2075.         case FILLCOLOR:
  2076.         /*
  2077.         @ fillcolor colorname or #hex
  2078.         @ Set the color for a filled object : mainly used for command 'userdraw obj,stroke_color'
  2079.         @ All fillable massive object will have a fillcolor == strokecolor (just to be compatible with flydraw...)
  2080.         */
  2081.             fill_color = get_color(infile,1);
  2082.             break;
  2083.         case STROKECOLOR:
  2084.         /*
  2085.         @ strokecolor colorname or #hex
  2086.         @ to be used for commands that do not supply a color argument (like command 'linegraph')
  2087.         */
  2088.             stroke_color = get_color(infile,1);
  2089.             break;
  2090.         case BGIMAGE:
  2091.         /*
  2092.          @bgimage image_location
  2093.          @use an image as background .<br />(we use the background of 'canvas_div' )
  2094.          @the background image will be resized to match "width = xsize" and "height = ysize"
  2095.         */
  2096.         URL = get_string(infile,1);
  2097.         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);
  2098.             break;
  2099.         case BGCOLOR:
  2100.         /*
  2101.          @bgcolor colorname or #hex
  2102.          @use this color as background of the "div" containing the canvas(es)
  2103.         */
  2104.         /* [255,255,255]*/
  2105.             bgcolor = get_string(infile,1);
  2106.             if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
  2107.                 int found = 0;
  2108.                 for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  2109.                     if( strcmp( colors[i].name , bgcolor ) == 0 ){
  2110.                         bgcolor = colors[i].hex;
  2111.                         found = 1;
  2112.                         break;
  2113.                     }
  2114.                 }
  2115.                 if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");}
  2116.             }
  2117.             fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
  2118.             break;
  2119.         case COPY:
  2120.         /*
  2121.         @ copy x,y,x1,y1,x2,y2,[filename URL]
  2122.         @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
  2123.         @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
  2124.         @ [filename] is the URL of the image   
  2125.         @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
  2126.         @ 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
  2127.         @ if you want to draw / userdraw  on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent
  2128.  
  2129.         context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  2130.         draw_external_image(canvas_type,URL,sx,sy,swidth,sheight,x,y,width,height,drag_drop){
  2131.         */
  2132.             for(i = 0 ; i<7;i++){
  2133.                 switch(i){
  2134.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
  2135.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
  2136.                     case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
  2137.                     case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
  2138.                     case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
  2139.                     case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
  2140.                     case 6: URL = get_string(infile,1);
  2141.                             int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
  2142.                             int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
  2143.                             if( drag_type > -1 ){
  2144.                                 if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
  2145.                                 if(reply_format == 0 ){reply_format = 20;}
  2146.                                 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);
  2147.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2148.                                 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);                       
  2149.                                 drag_type = -1;
  2150.                                 ext_img_cnt++;
  2151.                             }
  2152.                             else
  2153.                             {
  2154.                                 if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  2155.                                 /*
  2156.                                 draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\n\
  2157.                                 */
  2158.                                 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]);
  2159.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2160.                                 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]);
  2161.                             }
  2162.                             add_to_buffer(tmp_buffer);
  2163.                             break;
  2164.                     default: break;
  2165.                 }
  2166.             }
  2167.             reset();
  2168.             break;
  2169. /*
  2170. context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  2171. img     Specifies the image, canvas, or video element to use
  2172. sx      The x coordinate where to start clipping : x1 = int_data[0]
  2173. sy      The y coordinate where to start clipping : x2 = int_data[1]
  2174. swidth  The width of the clipped image : int_data[2] - int_data[0]
  2175. sheight The height of the clipped image : int_data[3] - int_data[1]
  2176. x       The x coordinate where to place the image on the canvas : dx1 = int_data[4]
  2177. y       The y coordinate where to place the image on the canvas : dy1 = int_data[5]
  2178. width   The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6]
  2179. height  The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7]
  2180. */
  2181.         case COPYRESIZED:
  2182.         /*
  2183.         @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
  2184.         @ 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
  2185.         @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
  2186.         @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
  2187.         @ 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
  2188.         @ if you want to draw / userdraw  on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent
  2189.         */
  2190.             for(i = 0 ; i<9;i++){
  2191.                 switch(i){
  2192.                     case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
  2193.                     case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
  2194.                     case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
  2195.                     case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
  2196.                     case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
  2197.                     case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
  2198.                     case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
  2199.                     case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
  2200.                     case 8: URL = get_string(infile,1);
  2201.                             if( drag_type > -1 ){
  2202.                                 if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
  2203.                                 if(reply_format == 0 ){reply_format = 20;}
  2204.                                 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);
  2205.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2206.                                 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);
  2207.                                 drag_type = -1;
  2208.                                 ext_img_cnt++;
  2209.                             }
  2210.                             else
  2211.                             {
  2212.                                 if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  2213.                                 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]);
  2214.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2215.                                 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]);
  2216.                             }
  2217.                             add_to_buffer(tmp_buffer);
  2218.                     default: break;
  2219.                 }
  2220.             }
  2221.             reset();
  2222.             break;
  2223.         case BUTTON:
  2224.         /*
  2225.          button x,y,value
  2226.          does nothing : from svgdraw
  2227.         */
  2228.         break;
  2229.         case INPUTSTYLE:
  2230.         /*
  2231.         @ inputstyle style_description
  2232.         @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt
  2233.         */
  2234.             input_style = get_string(infile,1);
  2235.             break;
  2236.         case INPUT:
  2237.         /*
  2238.          @ input x,y,size,editable,value
  2239.          @ to set inputfield "readonly", use editable = 0
  2240.          @ only active inputfields (editable = 1) will be read with read_canvas();
  2241.          @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be clearedand set readonly<br />Override this by keyword 'status'
  2242.          @ may be further controlled by "inputstyle" (inputcss is not yet implemented...)
  2243.          @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
  2244.         */
  2245.         if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}    
  2246.             for(i = 0 ; i<5;i++){
  2247.                 switch(i){
  2248.                     case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
  2249.                     case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
  2250.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
  2251.                     case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
  2252.                     case 4:
  2253.                             temp = get_string_argument(infile,1);
  2254.                             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);
  2255.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2256.                             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);
  2257.                             add_to_buffer(tmp_buffer);
  2258.                             input_cnt++;break;
  2259.                     default: break;
  2260.                 }
  2261.             }
  2262.             if(reply_format == 0 ){reply_format = 15;}
  2263.             reset();
  2264.             break;
  2265.         case TEXTAREA:
  2266.         /*
  2267.          @ textarea x,y,cols,rows,readonly,value
  2268.          @ may be further controlled by "inputstyle"
  2269.          @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be clearedand set readonly<br />Override this by keyword 'status'
  2270.          @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
  2271.         */
  2272.             if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}  
  2273.             for(i = 0 ; i<6;i++){
  2274.                 switch(i){
  2275.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
  2276.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
  2277.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
  2278.                     case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
  2279.                     case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
  2280.                     case 5: temp = get_string_argument(infile,1);
  2281.                             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);
  2282.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2283.                             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);
  2284.                             add_to_buffer(tmp_buffer);
  2285.                             input_cnt++;break;
  2286.                     default: break;
  2287.                 }
  2288.             }
  2289.             if(reply_format == 0 ){reply_format = 15;}
  2290.             reset();
  2291.             break;
  2292.         case MOUSE_PRECISION:
  2293.         /*
  2294.             @ precision int
  2295.             @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
  2296.             @ may be used / changed before every object
  2297.             @ In case of user interaction (like 'userdraw') this value will be used to determine the amount of decimals in the reply / answer
  2298.         */
  2299.             precision = (int) (get_real(infile,1));
  2300.             if(precision < 1 ){precision = 1;};
  2301.             break;
  2302.         case SETLIMITS:
  2303.         /*
  2304.             @setlimits
  2305.             @keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button
  2306.             @may be used for inputfield based zooming / panning
  2307.             @use command xlabel / ylabel to change text from xmin to 'xlabel'min etc
  2308.             @note:the input value will not be checked on validity
  2309.         */
  2310.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  2311.             add_setlimits(js_include_file,canvas_root_id);
  2312.             /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
  2313.             use_pan_and_zoom = TRUE;
  2314.             done = TRUE;
  2315.             break;
  2316.         case ZOOM:
  2317.         /*
  2318.          @ zoom button_color
  2319.          @ introduce a controlpanel at the lower right corner
  2320.          @ 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
  2321.          @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings.
  2322.          @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible
  2323.          @ command 'opacity' may be used to set stroke_opacity of 'buttons
  2324.          @ NOTE: use command 'zoom' at the end of your script code (the same is true for commanmd 'mouse')
  2325.          @ NOTE: only objects that may be set draggable / clickable will be zoomed / panned
  2326.          @ 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 !!
  2327.         */
  2328.             fprintf(js_include_file,"use_pan_and_zoom = 1;");
  2329.             use_pan_and_zoom = TRUE;
  2330.             stroke_color = get_color(infile,1);
  2331.             /* we use BG_CANVAS (0) */
  2332.             add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
  2333.             done = TRUE;
  2334.             break;
  2335.         case ONCLICK:
  2336.         /*
  2337.          @ onclick
  2338.          @ keyword, no arguments
  2339.          @ if the next object is clicked, it's 'object sequence number' in fly script is returned <br /> by javascript:read_canvas();
  2340.          @ Line based object will show an increase in linewidth<br />Font based objects will show the text in 'bold' when clicked.
  2341.          @ NOTE: not all objects may be set clickable
  2342.         */
  2343.            
  2344.             onclick = 1;
  2345.             break;
  2346.         case DRAG:
  2347.         /*
  2348.          @ drag [x][y][xy]
  2349.          @ the next object will be draggable in x / y / xy direction
  2350.          @ the displacement can be read by 'javascript:read_dragdrop();'
  2351.          @ 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' !
  2352.          @ 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)
  2353.          @ use keywordd 'snaptogrid' , 'xsnaptogrid' or 'ysnaptogrid' to switch from free to discrete movement
  2354.          @ 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.
  2355.          @ 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 !!
  2356.         */
  2357.             temp = get_string(infile,1);
  2358.             if(strstr(temp,"xy") != NULL ){
  2359.                 drag_type = 0;
  2360.             }
  2361.             else
  2362.             {
  2363.                 if(strstr(temp,"x") != NULL ){
  2364.                     drag_type = 1;
  2365.                 }
  2366.                 else
  2367.                 {
  2368.                     drag_type = 2;
  2369.                 }
  2370.             }
  2371.             fprintf(js_include_file,"var dragdrop_precision = %d;",precision);
  2372.             onclick = 2;
  2373.             /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
  2374.             break;
  2375.         case BLINK:
  2376.         /*
  2377.          @ blink time(seconds)
  2378.          @ NOT IMPLEMETED -YET
  2379.         */
  2380.             break;
  2381.         case XUNIT:
  2382.         /*
  2383.          @ xunit some_unit_for_x-values
  2384.          @ unicode allowed (no html code)
  2385.          @ use together with command mousex
  2386.          @ will display the cursor x-coordinate 'unit'
  2387.         */
  2388.             fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
  2389.             break;
  2390.         case YUNIT:
  2391.         /*
  2392.          @ yunit some_unit_for_y-values
  2393.          @ unicode allowed (no html code)
  2394.          @ use together with command mousex
  2395.          @ will display the cursor y-coordinate 'unit'
  2396.         */
  2397.             fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
  2398.             break;
  2399.         case MOUSE_DISPLAY:
  2400.         /*
  2401.          @display x|y|xy|degree|,color,fontsize
  2402.          @will display the mouse cursor coordinates as x-only,y-only,(x:y) or the angle in degrees<br />(angle between x-axis;(0:0);(x:y)
  2403.          @just like commands 'mouse','mousex','mousey','mouse_degree'...only other name)
  2404.         */
  2405.         temp = get_string_argument(infile,0);
  2406.         if( strstr(temp,"xy") != NULL ){
  2407.             int_data[0] = 2;
  2408.         }else{
  2409.             if( strstr(temp,"y") != NULL ){
  2410.                 int_data[0] = 1;
  2411.             }else{
  2412.                 if( strstr(temp,"x") != NULL ){
  2413.                     int_data[0] = 0;
  2414.                     if(strstr(temp,"degree") != NULL){
  2415.                         int_data[0] = 3;
  2416.                     }else{
  2417.                         int_data[0] = 2;
  2418.                     }
  2419.                 }      
  2420.             }
  2421.         }      
  2422.         stroke_color = get_color(infile,0);
  2423.         font_size = (int) (get_real(infile,1));
  2424.         tmp_buffer = my_newmem(26);
  2425.         snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2426.         add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
  2427.         break;
  2428.         case MOUSE_DEGREE:
  2429.         /*
  2430.          @ mouse_degree color,fontsize
  2431.          @ 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
  2432.          @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
  2433.          @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2434.  
  2435.         */
  2436.             stroke_color = get_color(infile,0);
  2437.             font_size = (int) (get_real(infile,1));
  2438.             tmp_buffer = my_newmem(26);
  2439.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2440.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
  2441.             break;
  2442.         case MOUSEX:
  2443.         /*
  2444.          @ mousex color,fontsize
  2445.          @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
  2446.          @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2447.  
  2448.         */
  2449.             stroke_color = get_color(infile,0);
  2450.             font_size = (int) (get_real(infile,1));
  2451.             tmp_buffer = my_newmem(26);
  2452.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2453.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
  2454.             break;
  2455.         case MOUSEY:
  2456.         /*
  2457.          @ mousey color,fontsize
  2458.          @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
  2459.          @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2460.  
  2461.         */
  2462.             stroke_color = get_color(infile,0);
  2463.             font_size = (int) (get_real(infile,1));
  2464.             tmp_buffer = my_newmem(26);
  2465.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2466.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
  2467.             break;
  2468.         case MOUSE:
  2469.         /*
  2470.          @ mouse color,fontsize
  2471.          @ will display the cursor (x:y) coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
  2472.          @ NOTE: use command 'mouse' at the end of your script code (the same is true for commanmd 'zoom')
  2473.  
  2474.         */
  2475.             stroke_color = get_color(infile,0);
  2476.             font_size = (int) (get_real(infile,1));
  2477.             tmp_buffer = my_newmem(26);
  2478.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2479.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
  2480.             break;
  2481.         case INTOOLTIP:
  2482.             /*
  2483.             @ intooltip link_text
  2484.             @ link_text is a single line (span-element)
  2485.             @ link_text may also be an image URL http://some_server/images/my_image.png
  2486.             @ link_text may contain HTML markup
  2487.             @ the canvas will be displayed in a tooltip on 'link_text'
  2488.             @ the canvas is default transparent: use command 'bgcolor color' to adjust background-color<br />the link test will alos be shown with this bgcolor.
  2489.             */
  2490.             if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy command");}
  2491.             use_tooltip = TRUE;
  2492.             tooltip_text = get_string(infile,1);
  2493.             if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
  2494.             break;
  2495.         case AUDIO:
  2496.         /*
  2497.         @ audio x,y,w,h,loop,visible,audiofile location
  2498.         @ x,y : left top corner of audio element (in xrange / yrange)
  2499.         @ w,y : width and height in pixels
  2500.         @ loop : 0 or 1 ( 1 = loop audio fragment)
  2501.         @ visible : 0 or 1 (1 = show controls)
  2502.         @ audio format may be in *.mp3 or *.ogg
  2503.         @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format)
  2504.         @ if you are using *.ogg : be aware that Microsoft based systems not support it natively
  2505.         @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
  2506.         @ 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 />
  2507.         */
  2508.             if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
  2509.             for(i=0;i<7;i++){
  2510.                 switch(i){
  2511.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  2512.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  2513.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  2514.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  2515.                     case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
  2516.                     case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
  2517.                     case 6:
  2518.                     temp = get_string(infile,1);
  2519.                     if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
  2520.                     if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
  2521.                     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);
  2522.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2523.                     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);
  2524.                     add_to_buffer(tmp_buffer);
  2525.                     break;
  2526.                     default:break;
  2527.                 }
  2528.             }
  2529.             reset();
  2530.             break;
  2531.         case VIDEO:
  2532.         /*
  2533.         @ video x,y,w,h,videofile location
  2534.         @ x,y : left top corner of audio element (in xrange / yrange)
  2535.         @ w,y : width and height in pixels
  2536.         @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4
  2537.         @ video format may be in *.mp4 (todo:other formats)
  2538.         */
  2539.             if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
  2540.             for(i=0;i<5;i++){
  2541.                 switch(i){
  2542.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  2543.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  2544.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  2545.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  2546.                     case 4: temp = get_string(infile,1);
  2547.                             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);
  2548.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2549.                             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);
  2550.                             add_to_buffer(tmp_buffer);
  2551.                             break;
  2552.                     default:break;
  2553.                 }
  2554.             }
  2555.             reset();
  2556.             break;
  2557.         case HATCHFILL:
  2558.         /*
  2559.         @ hatchfill x0,y0,dx,dy,color
  2560.         @ x0,y0 in xrange / yrange
  2561.         @ distances dx,dy in pixels
  2562.         */
  2563.             if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
  2564.             for(i=0;i<5;i++){
  2565.                 switch(i){
  2566.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2567.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2568.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2569.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2570.                     case 4: stroke_color = get_color(infile,1);
  2571.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2572.                     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);
  2573.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2574.                     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);
  2575.                     add_to_buffer(tmp_buffer);
  2576.                     break;
  2577.                     default:break;
  2578.                 }
  2579.             }
  2580.             reset();
  2581.         break;
  2582.         case DIAMONDFILL:
  2583.         /*
  2584.         @ diamondfill x0,y0,dx,dy,color
  2585.         @ x0,y0 in xrange / yrange
  2586.         @ distances dx,dy in pixels
  2587.         */
  2588.             if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
  2589.             for(i=0;i<5;i++){
  2590.                 switch(i){
  2591.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2592.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2593.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2594.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2595.                     case 4: stroke_color = get_color(infile,1);
  2596.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2597.                     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);
  2598.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2599.                     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);
  2600.                     add_to_buffer(tmp_buffer);
  2601.                     break;
  2602.                     default:break;
  2603.                 }
  2604.             }
  2605.             reset();
  2606.         break;
  2607.         case GRIDFILL:
  2608.         /*
  2609.         @ gridfill x0,y0,dx,dy,color
  2610.         @ x0,y0 in xrange / yrange
  2611.         @ distances dx,dy in pixels
  2612.         @ a draggable object may snap_to_grid (using keywords xysnaptogrid,xsnaprogrid, ysnaptogrid)
  2613.         @ userdraw object may snap_to_grid
  2614.         */
  2615.             if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
  2616.             for(i=0;i<5;i++){
  2617.                 switch(i){
  2618.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2619.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2620.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2621.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2622.                     case 4: stroke_color = get_color(infile,1);
  2623.                     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);
  2624.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2625.                     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);
  2626.                     add_to_buffer(tmp_buffer);
  2627.                     break;
  2628.                     default:break;
  2629.                 }
  2630.             }
  2631.             reset();
  2632.         break;
  2633.         case DOTFILL:
  2634.         /*
  2635.         @ dotfill x0,y0,dx,dy,color
  2636.         @ x0,y0 in xrange / yrange
  2637.         @ distances dx,dy in pixels
  2638.         @ radius of dots is linewidth
  2639.         */
  2640.             if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
  2641.             for(i=0;i<5;i++){
  2642.                 switch(i){
  2643.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2644.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2645.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2646.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2647.                     case 4: stroke_color = get_color(infile,1);
  2648.                     /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
  2649.                     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);
  2650.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2651.                     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);
  2652.                     add_to_buffer(tmp_buffer);
  2653.                     break;
  2654.                     default:break;
  2655.                 }
  2656.             }
  2657.             reset();
  2658.         break;
  2659.         case IMAGEFILL:
  2660.         /*
  2661.         @ imagefill dx,dy,image_url
  2662.         @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
  2663.         @ After pattern filling ,the fill-color should be reset !
  2664.         @ wims getins / image from class directory : imagefill 80,80,my_image.gif
  2665.         @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif
  2666.         @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg
  2667.         @ if dx,dy is larger than the image, the whole image will be background to the next object.
  2668.         */
  2669.             if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
  2670.             for(i=0 ;i < 3 ; i++){
  2671.                 switch(i){
  2672.                     case 0:int_data[0] = (int) (get_real(infile,0));break;
  2673.                     case 1:int_data[1] = (int) (get_real(infile,0));break;
  2674.                     case 2: URL = get_string_argument(infile,1);
  2675.                             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);
  2676.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2677.                             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);
  2678.                             add_to_buffer(tmp_buffer);
  2679.                     break;
  2680.                 }
  2681.             }
  2682.             reset();
  2683.         break;
  2684.         case FILLTOBORDER:
  2685.         /*
  2686.         @ filltoborder x,y,bordercolor,color
  2687.         @ fill the region  of point (x:y) bounded by 'bordercolor' with color 'color'
  2688.         @ any other color will not act as border to the bucket fill
  2689.         @ use this command  after all boundary objects are declared.
  2690.         @ 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..
  2691.         */
  2692.             for(i=0 ;i < 4 ; i++){
  2693.                 switch(i){
  2694.                     case 0:double_data[0] = get_real(infile,0);break;
  2695.                     case 1:double_data[1] = get_real(infile,0);break;
  2696.                     case 2:bgcolor = get_color(infile,0);break;
  2697.                     case 3:fill_color = get_color(infile,1);
  2698.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2699.                                 js_function[DRAW_FILLTOBORDER] = 1;
  2700.                                 add_js_filltoborder(js_include_file,canvas_root_id);
  2701.                            }
  2702.                            decimals = find_number_of_digits(precision);
  2703.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  2704.                            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));
  2705.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2706.                            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));
  2707.                            add_to_buffer(tmp_buffer);
  2708.                            break;
  2709.                     default:break;
  2710.                 }
  2711.             }
  2712.             reset();
  2713.         break;
  2714.         case FLOODFILL:
  2715.         /*
  2716.         @ floodfill x,y,color
  2717.         @ alternative syntax: fill x,y,color
  2718.         @ fill the region of point (x:y) with color 'color'
  2719.         @ any other color or size of picture (borders of picture) will act as border to the bucket fill
  2720.         @ use this command  after all boundary objects are declared.
  2721.         @ Use command 'clickfill,color' for user click driven flood fill.
  2722.         @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
  2723.         @ 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..
  2724.         */
  2725.             for(i=0 ;i < 4 ; i++){
  2726.                 switch(i){
  2727.                     case 0:double_data[0] = get_real(infile,0);break;
  2728.                     case 1:double_data[1] = get_real(infile,0);break;
  2729.                     case 2:fill_color = get_color(infile,1);
  2730.                            if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
  2731.                                 js_function[DRAW_FLOODFILL] = 1;
  2732.                                 add_js_floodfill(js_include_file,canvas_root_id);
  2733.                            }
  2734.                            decimals = find_number_of_digits(precision);/*floodfill(interaction,x,y,[R,G,B,A]) */
  2735.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  2736.                            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));
  2737.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2738.                            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));
  2739.                            add_to_buffer(tmp_buffer);
  2740.                            break;
  2741.                     default:break;
  2742.                 }
  2743.             }
  2744.             reset();
  2745.         break;
  2746.         case CLICKFILLMARGE:
  2747.             clickfillmarge = (int) (get_real(infile,1));
  2748.             break;
  2749.         /*
  2750.         @ clickfillmarge int
  2751.         @ default 20 (pixels)
  2752.         @ 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[])
  2753.         */
  2754.         case CLICKFILL:
  2755.         /*
  2756.         @ clickfill fillcolor
  2757.         @ user left mouse click will floodfill the area with fillcolor
  2758.         @ multiple areas may be coloured
  2759.         @ 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)
  2760.         @ the answer will be read as the (x:y) click coordinates per coloured area
  2761.         @ background color of main div may be set by using command "bgcolor color"
  2762.         @ may not be combined with command "userdraw"
  2763.         @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
  2764.         */
  2765.          fill_color = get_color(infile,1);
  2766.          if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
  2767.             js_function[DRAW_FLOODFILL] = 1;
  2768.             add_js_floodfill(js_include_file,canvas_root_id);
  2769.          }
  2770.          fprintf(js_include_file,"\n<!-- begin command clickfill -->\nvar marge_xy = %d;var userdraw_x = new Array();var userdraw_y = new Array();var user_clickfill_cnt = 0;\ncanvas_div.addEventListener(\"mousedown\",clickfill,false);function clickfill(evt){var x = evt.clientX - findPosX(canvas_div) + document.body.scrollLeft + document.documentElement.scrollLeft;var y = evt.clientY - findPosY(canvas_div) + document.body.scrollTop + document.documentElement.scrollTop;if(evt.which != 1){for(var p=0; p < user_clickfill_cnt;p++){if(userdraw_x[p] + marge_xy > x && userdraw_x[p] - marge_xy < x){if(userdraw_y[p] + marge_xy > y && userdraw_y[p] - marge_xy < y){if(confirm(\"Clear ?\")){floodfill(1,userdraw_x[p],userdraw_y[p],canvas_div.style.backgroundColor || [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));
  2771.          add_read_canvas(1,reply_precision);
  2772.          reset();
  2773.         break;
  2774.         case SETPIXEL:
  2775.         /*
  2776.         @ setpixel x,y,color
  2777.         @ A "point" with diameter 1 pixel centeres at (x:y) in xrange / yrange
  2778.         @ pixels can not be dragged or clicked
  2779.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  2780.         */
  2781.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  2782.             for(i=0;i<3;i++){
  2783.                 switch(i){
  2784.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  2785.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  2786.                     case 2: stroke_color = get_color(infile,1);
  2787.                            string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  2788.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2789.                            snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  2790.                            add_to_buffer(tmp_buffer);
  2791.                            break;
  2792.                     default:break;
  2793.                 }
  2794.             }
  2795.             reset();
  2796.         break;
  2797.         case PIXELSIZE:
  2798.         /*
  2799.         @ pixelsize int
  2800.         @ in case you want to deviate from default pixelsize = 1...
  2801.         */
  2802.             pixelsize = (int) get_real(infile,1);
  2803.         break;
  2804.         case PIXELS:
  2805.         /*
  2806.         @ pixels color,x1,y1,x2,y2,x3,y3...
  2807.         @ Draw  "points" with diameter 1 pixel
  2808.         @ pixels can not be dragged or clicked
  2809.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  2810.         */
  2811.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  2812.             stroke_color=get_color(infile,0);
  2813.             i=0;
  2814.             c=0;
  2815.             while( ! done ){     /* get next item until EOL*/
  2816.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  2817.                 for( c = 0 ; c < 2; c++){
  2818.                     if(c == 0 ){
  2819.                         double_data[i] = get_real(infile,0);
  2820.                         i++;
  2821.                     }
  2822.                     else
  2823.                     {
  2824.                         double_data[i] = get_real(infile,1);
  2825.                         i++;
  2826.                     }
  2827.                 }
  2828.             }
  2829.             decimals = find_number_of_digits(precision);
  2830.             /*  *double_xy2js_array(double xy[],int len,int decimals) */
  2831.             string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  2832.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2833.             snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  2834.             add_to_buffer(tmp_buffer);
  2835.             reset();
  2836.             break;
  2837.         case REPLYFORMAT:
  2838.         /*
  2839.         @ replyformat number
  2840.         @ use number=-1 to deactivate the js-function read_canvas()
  2841.         @ default values should be fine !
  2842.         @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing
  2843.         @ the last value for 'precision int' will be used to calculate  the reply coordinates, if needed (read_canvas();)
  2844.         @ 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></ul>
  2845.         @ note to 'userdraw text,color' : the x / y-values are in pixels ! (this to avoid too lengthy calculations in javascript...)
  2846.         */
  2847.          reply_format = (int) get_real(infile,1);
  2848.          reply_precision = precision;
  2849.         break;
  2850.         case LEGENDCOLORS:
  2851.         /*
  2852.         @ legendcolors color1:color2:color3:...:color_n
  2853.         @ 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 />
  2854.         @ make sure the number of colours match the number of legend items
  2855.         @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
  2856.         */
  2857.             if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
  2858.             temp = get_string(infile,1);
  2859.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2860.             fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
  2861.             break;
  2862.         case LEGEND:
  2863.         /*
  2864.         @ legend string1:string2:string3....string_n
  2865.         @ will be used to create a legend for a graph
  2866.         @ also see command 'piechart'  
  2867.         @ will use the same colors per default as used in the graphs : use command 'legendcolors' to override the default
  2868.         */
  2869.             temp = get_string(infile,1);
  2870.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2871.             legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */
  2872.             fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
  2873.             break;
  2874.         case XLABEL:
  2875.         /*
  2876.         @ xlabel some_string
  2877.         @ will be used to create a label for the x-axis (label is in quadrant I)
  2878.         @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
  2879.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
  2880.         */
  2881.             temp = get_string(infile,1);
  2882.             fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
  2883.             break;
  2884.         case YLABEL:
  2885.         /*
  2886.         @ ylabel some_string
  2887.         @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
  2888.         @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
  2889.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
  2890.         */
  2891.             temp = get_string(infile,1);
  2892.             fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
  2893.             break;
  2894.         case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
  2895.         /*
  2896.         @ linegraph x1:y1;x2:y2...x_n:y_n
  2897.         @ will plot your data in a graph
  2898.         @ may only to be used together with command 'grid'
  2899.         @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
  2900.         @ use command 'legend' to provide an optional legend in right-top-corner
  2901.         @ also see command 'piechart'
  2902.         @ multiple linegraphs may be used in a single plot
  2903.         @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
  2904.         @ <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>
  2905.         */    
  2906.             temp = get_string(infile,1);
  2907.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2908.             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);
  2909.             linegraph_cnt++;
  2910.             reset();
  2911.             break;
  2912.         case BARCHART:
  2913.         /*
  2914.         @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
  2915.         @ will be used to create a legend for bar graph
  2916.         @ may only to be used together with command 'grid'
  2917.         @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
  2918.         @ use command 'legend' to provide an optional legend in right-top-corner
  2919.         @ also see command 'piechart'
  2920.         @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
  2921.         */
  2922.             temp = get_string(infile,1);
  2923.             if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
  2924.             fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
  2925.             barchart_cnt++;
  2926.             reset();
  2927.             break;
  2928.         case CLOCK:
  2929.         /*
  2930.         @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
  2931.         @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency
  2932.         @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments
  2933.         @ 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
  2934.         @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
  2935.         @ 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>
  2936.         @ canvasdraw will not check validity of colornames...the javascript console is your best friend
  2937.         @ no combinations with other reply_types allowed, for now
  2938.         @ 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
  2939.         */
  2940.             if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
  2941.  
  2942.         /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
  2943.             for(i=0;i<9;i++){
  2944.              switch(i){
  2945.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
  2946.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
  2947.               case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
  2948.               case 3: int_data[3] = get_real(infile,0);break;/* hours */
  2949.               case 4: int_data[4] = get_real(infile,0);break;/* minutes */
  2950.               case 5: int_data[5] = get_real(infile,0);break;/* seconds */
  2951.               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 */
  2952.               case 7: int_data[7] = (int)(get_real(infile,0));/* interactive 0,1,2*/
  2953.                 switch(int_data[7]){
  2954.                     case 0:break;
  2955.                     case 1:if(clock_cnt == 0){
  2956.                                 if( reply_format == 0 ){
  2957.                                      reply_format = 18; /* user sets clock */
  2958.                                     /* 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");
  2959.                                      check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2960.                                      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");
  2961.                                      add_to_buffer(tmp_buffer);
  2962.                                     */
  2963.                                      fprintf(js_include_file,"var 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 = 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");
  2964.                                 }
  2965.                                 else
  2966.                                 {
  2967.                                     canvas_error("interactive clock may not be used together with other reply_types...");
  2968.                                 }
  2969.                                 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);
  2970.                              }
  2971.                     break;
  2972.                     case 2:if( reply_format == 0 ){
  2973.                                 reply_format = 19; /* "onclick */
  2974.                                 fprintf(js_include_file,"\n<!-- begin onclick handler for clocks -->\nvar reply = new Array();\n\ncanvas_div.addEventListener( 'mousedown', user_click,false);\n\nfunction user_click(evt){if(evt.which == 1){var canvas_rect = clock_canvas.getBoundingClientRect();\nvar x = evt.clientX - canvas_rect.left;\nvar y = evt.clientY - canvas_rect.top;\nvar p = 0;\nvar name;\nvar t = true;\nwhile(t){try{name = eval('clocks'+p);\nif( x < name.xc + name.radius && x > name.xc - name.radius ){if( y < name.yc + name.radius && y > name.yc - name.radius ){reply[0] = p;\nname = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,\"lightblue\",name.fg_color);\n};\n}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);\nname = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);\n};\np++;\n}catch(e){t=false;\n};\n};\n};\n};\n\n<!-- end onclick handler for clocks -->\n ");
  2975.                             }
  2976.                             else
  2977.                             {
  2978.                                 if( reply_format != 19){
  2979.                                    canvas_error("clickable clock(s) may not be used together with other reply_types...");
  2980.                                  }
  2981.                             }
  2982.                      break;
  2983.                      default: canvas_error("interactive must be set 0,1 or 2");break;
  2984.                 }
  2985.                 break;
  2986.                 case 8:
  2987.                         fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
  2988.                         temp = get_string(infile,1);
  2989.                         if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
  2990.                         if( strlen(temp) < 1 ){temp = ",\"\",\"\",\"\",\"\",\"\"";}
  2991.                         string_length = snprintf(NULL,0,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp);
  2992.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2993.                         snprintf(tmp_buffer,string_length,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp);
  2994.                         add_to_buffer(tmp_buffer);
  2995.                         clock_cnt++;
  2996.                         break;
  2997.                 default:break;
  2998.              }
  2999.             }
  3000.             break;
  3001.         case PIECHART:
  3002.         /*
  3003.         @ piechart xc,yc,radius,'data+colorlist'
  3004.         @ (xc : yc) center of circle diagram in xrange/yrange
  3005.         @ radius in pixels
  3006.         @ 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
  3007.         @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white
  3008.         @ the number of colors must match the number of data.
  3009.         @ use command "opacity 0-255,0-255" to adjust fill_opacity of colours
  3010.         @ 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.
  3011.         */
  3012.             if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}    
  3013.             for(i=0;i<5;i++){
  3014.                 switch(i){
  3015.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  3016.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  3017.                     case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
  3018.                     case 3: temp = get_string(infile,1);
  3019.                             if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
  3020.                             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);
  3021.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3022.                             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);
  3023.                             add_to_buffer(tmp_buffer);
  3024.                            break;
  3025.                     default:break;
  3026.                 }
  3027.             }
  3028.             reset();
  3029.         break;
  3030.         case STATUS:
  3031.         /*
  3032.         @status
  3033.         @keyword
  3034.         @alernative keyword: nostatus
  3035.         @used to override the effects of "status=done" in wims (answer.phtml)
  3036.         @affects inputfields / textarea's in canvasimage and all userdraw based commands
  3037.         @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'
  3038.         */
  3039.        
  3040.             fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
  3041.             break;
  3042.         case XLOGBASE:
  3043.         /*
  3044.         @ xlogbase number
  3045.         @ sets the logbase number for the x-axis
  3046.         @ default value 10
  3047.         @ use together with commands xlogscale / xylogscale
  3048.         */
  3049.             fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
  3050.             break;
  3051.         case YLOGBASE:
  3052.         /*
  3053.         @ ylogbase number
  3054.         @ sets the logbase number for the y-axis
  3055.         @ default value 10
  3056.         @ use together with commands ylogscale / xylogscale
  3057.         */
  3058.             fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
  3059.             break;
  3060.         case XLOGSCALE:
  3061.         /*
  3062.          @ xlogscale ymajor,yminor,majorcolor,minorcolor
  3063.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  3064.          @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
  3065.          @ the linewidth is set using command 'linewidth int'
  3066.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  3067.          @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number'
  3068.          @ 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>
  3069.          @ note: the complete canvas will be used for the 'log paper'
  3070.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  3071.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  3072.          @ 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')  
  3073.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  3074.          @ attention: keyword 'snaptogrid' may not lead to the desired result...
  3075.         */
  3076.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  3077.             if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
  3078.             for(i=0;i<4;i++){
  3079.                 switch(i){
  3080.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  3081.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  3082.                     case 2: stroke_color = get_color(infile,0); break;
  3083.                     case 3: fill_color = get_color(infile,1);
  3084.                         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);
  3085.                         tmp_buffer = my_newmem(string_length+1);
  3086.                         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);
  3087.                         fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
  3088.                         add_to_buffer(tmp_buffer);
  3089.                         break;
  3090.                     default:break;
  3091.                 }
  3092.             }
  3093.             break;
  3094.         case YLOGSCALE:
  3095.         /*
  3096.          @ ylogscale xmajor,xminor,majorcolor,minorcolor
  3097.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  3098.          @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
  3099.          @ the linewidth is set using command 'linewidth int'
  3100.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  3101.          @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number'
  3102.          @ 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>
  3103.          @ note: the complete canvas will be used for the 'log paper'
  3104.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  3105.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  3106.          @ 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')  
  3107.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  3108.          @ attention: keyword 'snaptogrid' may not lead to the desired result...
  3109.         */
  3110.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  3111.             if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
  3112.             for(i=0;i<4;i++){
  3113.                 switch(i){
  3114.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  3115.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  3116.                     case 2: stroke_color = get_color(infile,0); break;
  3117.                     case 3: fill_color = get_color(infile,1);
  3118.                         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);
  3119.                         tmp_buffer = my_newmem(string_length+1);
  3120.                         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);
  3121.                         fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
  3122.                         add_to_buffer(tmp_buffer);
  3123.                         break;
  3124.                     default:break;
  3125.                 }
  3126.             }
  3127.             break;
  3128.         case XYLOGSCALE:
  3129.         /*
  3130.          @ xylogscale majorcolor,minorcolor
  3131.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  3132.          @ the linewidth is set using command 'linewidth int'
  3133.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  3134.          @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number'
  3135.          @ 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>
  3136.          @ note: the complete canvas will be used for the 'log paper'
  3137.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  3138.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  3139.          @ 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')  
  3140.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  3141.          @ attention: keyword 'snaptogrid' may not lead to the desired result...
  3142.         */
  3143.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  3144.             if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
  3145.             for(i=0;i<2;i++){
  3146.                 switch(i){
  3147.                     case 0: stroke_color = get_color(infile,0); break;
  3148.                     case 1: fill_color = get_color(infile,1);
  3149.                         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);
  3150.                         tmp_buffer = my_newmem(string_length+1);
  3151.                         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);
  3152.                         fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
  3153.                         add_to_buffer(tmp_buffer);
  3154.                         break;
  3155.                     default:break;
  3156.                 }
  3157.             }
  3158.         break;
  3159.         default:sync_input(infile);
  3160.         break;
  3161.     }
  3162.   }
  3163.   /* we are done parsing script file */
  3164.   /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */
  3165.   if( found_size_command == 1 ){
  3166.     fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
  3167.   }
  3168.   else
  3169.   {
  3170.     if( found_size_command != 3 ){
  3171.      canvas_error("Please specify bothe xrange and yrange ...");
  3172.     }
  3173.   }
  3174.   /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable shapes / objects  ! */
  3175.   add_javascript_functions(js_function,canvas_root_id);
  3176.    /* add read_canvas() etc functions if needed */
  3177.   if( reply_format > 0 ){ add_read_canvas(reply_format,reply_precision);}
  3178.   if( use_pan_and_zoom == TRUE ){
  3179.   /* in case of zooming ... */
  3180.   fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\
  3181.  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
  3182.  var ymin_start=ymin;var ymax_start=xmax;\
  3183.  var zoom_x_increment=0;var zoom_y_increment=0;\
  3184.  var pan_x_increment=0;var pan_y_increment=0;\
  3185.  if(use_ylogscale == 0 ){\
  3186.   zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (ymax - ymin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\
  3187.  }else{\
  3188.   zoom_x_increment = (xmax - xmin)/20;\
  3189.   pan_x_increment = (xmax - xmin)/20;\
  3190.  };\
  3191.  function start_canvas%d(type){\
  3192.   switch(type){\
  3193.    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
  3194.    case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\
  3195.    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
  3196.    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
  3197.    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
  3198.    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
  3199.    case 6:location.reload();break;\
  3200.    default:break;\
  3201.   };\
  3202.   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
  3203.   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
  3204.   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){}\
  3205.   %s\
  3206.  };\
  3207.  start_canvas%d(333);\
  3208. };\n\
  3209. <!-- end wims_canvas_function -->\n\
  3210. wims_canvas_function%d();\n",precision,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
  3211.   }
  3212.   else
  3213.   {
  3214.   /* no zoom, just add buffer */
  3215.   fprintf(js_include_file,"\n<!-- add buffer -->\n\
  3216.  %s\
  3217. };\n\
  3218. <!-- end wims_canvas_function -->\n\
  3219. wims_canvas_function%d();\n",buffer,canvas_root_id);
  3220.   }
  3221. /* done writing the javascript include file */
  3222. fclose(js_include_file);
  3223.  
  3224. }
  3225.  
  3226. /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
  3227. if(use_tooltip == TRUE){
  3228.   add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
  3229. }
  3230. exit(EXIT_SUCCESS);
  3231. }
  3232. /* end main() */
  3233.  
  3234. /******************************************************************************
  3235. **
  3236. **  sync_input
  3237. **
  3238. **  synchronises input line - reads to end of line, leaving file pointer
  3239. **  at first character of next line.
  3240. **
  3241. **  Used by:
  3242. **  main program - error handling.
  3243. **
  3244. ******************************************************************************/
  3245. void sync_input(FILE *infile)
  3246. {
  3247.         int c = 0;
  3248.  
  3249.         if( c == '\n' || c == ';' ) return;
  3250.         while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
  3251.         if( c == EOF ) finished = 1;
  3252.         if( c == '\n' || c == '\r' || c == ';') line_number++;
  3253.         return;
  3254. }
  3255.  
  3256. /******************************************************************************/
  3257.  
  3258. char *str_replace(const char *str, const char *old, const char *new){
  3259. /* http://creativeandcritical.net/str-replace-c/ */
  3260.     if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
  3261.     char *ret, *r;
  3262.     const char *p, *q;
  3263.     size_t oldlen = strlen(old);
  3264.     size_t count = 0;
  3265.     size_t retlen = 0;
  3266.     size_t newlen = strlen(new);
  3267.     if (oldlen != newlen){
  3268.         for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
  3269.             count++;
  3270.             retlen = p - str + strlen(p) + count * (newlen - oldlen);
  3271.         }
  3272.     }
  3273.     else
  3274.     {
  3275.         retlen = strlen(str);
  3276.     }
  3277.    
  3278.     if ((ret = malloc(retlen + 1)) == NULL){
  3279.         ret = NULL;
  3280.         canvas_error("string argument is NULL");
  3281.     }
  3282.     else
  3283.     {
  3284.         for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
  3285.             size_t l = q - p;
  3286.             memcpy(r, p, l);
  3287.             r += l;
  3288.             memcpy(r, new, newlen);
  3289.             r += newlen;
  3290.         }
  3291.         strcpy(r, p);
  3292.     }
  3293.     return ret;
  3294. }
  3295.  
  3296. /******************************************************************************/
  3297.  
  3298. char *get_color(FILE *infile , int last){
  3299.     int c,i = 0,is_hex = 0;
  3300.     char temp[MAX_COLOR_STRING], *string;
  3301.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){
  3302.         if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
  3303.         if( c == '#' ){
  3304.             is_hex = 1;
  3305.         }
  3306.         if( c != ' '){
  3307.             temp[i]=tolower(c);
  3308.             i++;
  3309.         }
  3310.     }
  3311.     if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
  3312.     if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
  3313.     if( c == EOF ){finished = 1;}
  3314.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  3315.     temp[i]='\0';
  3316.     if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
  3317.     if( is_hex == 1 ){
  3318.         char red[3], green[3], blue[3];
  3319.         red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
  3320.         green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
  3321.         blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
  3322.         int r = (int) strtol(red,   NULL, 16);
  3323.         int g = (int) strtol(green, NULL, 16);
  3324.         int b = (int) strtol(blue,  NULL, 16);
  3325.         string = (char *)my_newmem(12);
  3326.         snprintf(string,11,"%d,%d,%d",r,g,b);
  3327.         return string;
  3328.     }
  3329.     else
  3330.     {
  3331.         string = (char *)my_newmem(sizeof(temp));
  3332.         snprintf(string,sizeof(temp),"%s",temp);
  3333.         for( i = 0; i <= NUMBER_OF_COLORNAMES ; i++ ){
  3334.             if( strcmp( colors[i].name , string ) == 0 ){
  3335.                 return colors[i].rgb;
  3336.             }
  3337.         }
  3338.     }
  3339.     /* not found...return error */
  3340.     free(string);string = NULL;
  3341.     canvas_error("I was expecting a color name or hexnumber...but found nothing.");
  3342.     return NULL;
  3343. }
  3344.  
  3345. char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
  3346.     int c,i=0;
  3347.     char  temp[MAX_BUFFER], *string;
  3348.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){
  3349.         temp[i]=c;
  3350.         i++;
  3351.         if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
  3352.     }
  3353.     if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  3354.     if( c == '\n') { done = TRUE; line_number++; }
  3355.     if( c == EOF ) {
  3356.         finished = 1;
  3357.         if( last != 1 ){ canvas_error("expected more arguments");}
  3358.     }
  3359.     temp[i]='\0';
  3360.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");}
  3361.     string=(char *)my_newmem(strlen(temp));
  3362.     snprintf(string,sizeof(temp),"%s",temp);
  3363.     return string;
  3364. }
  3365.  
  3366. char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
  3367.     int c,i=0;
  3368.     char temp[MAX_BUFFER], *string;
  3369.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',')){
  3370.         temp[i]=c;
  3371.         i++;
  3372.         if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
  3373.     }
  3374.     if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
  3375.     if( c == '\n') { line_number++; }
  3376.     if( c == EOF ) {finished = 1;}
  3377.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  3378.     temp[i]='\0';
  3379.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
  3380.     string=(char *)my_newmem(sizeof(temp));
  3381.     snprintf(string,sizeof(temp),"%s",temp);
  3382.     done = TRUE;
  3383.     return string;
  3384. }
  3385.  
  3386. double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
  3387.     int c,i=0,found_calc = 0;
  3388.     double y;
  3389.     char tmp[MAX_INT];
  3390.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){
  3391.      if( c != ' ' ){
  3392.      /*
  3393.      libmatheval will segfault when for example: "xrange -10,+10" or "xrange -10,10+" is used
  3394.      We will check after assert() if it's a NULL pointer...and exit program via :
  3395.      canvas_error("I'm having trouble parsing your \"expression\" ");
  3396.      */
  3397.       if( i == 0 &&  c == '+' ){
  3398.        continue;
  3399.       }
  3400.       else
  3401.       {
  3402.        if(canvas_iscalculation(c) != 0){
  3403.         found_calc = 1;
  3404.         c = tolower(c);
  3405.        }
  3406.        tmp[i] = c;
  3407.        i++;
  3408.       }
  3409.      }
  3410.      if( i > MAX_INT - 1){canvas_error("number too large");}
  3411.     }
  3412.     if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
  3413.     if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
  3414.     if( c == EOF ){done = TRUE ; finished = 1;}
  3415.     tmp[i]='\0';
  3416.     if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
  3417.     if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */
  3418.      void *f = eval_create(tmp);
  3419.      assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  3420.      y = eval_x(f, 1);
  3421.      /* if function is bogus; y = 1 : so no core dumps */
  3422.      eval_destroy(f);
  3423.     }
  3424.     else
  3425.     {
  3426.      y = atof(tmp);
  3427.     }
  3428.     return y;
  3429. }
  3430. void canvas_error(char *msg){
  3431.     fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg);
  3432.     finished = 1;
  3433.     exit(EXIT_SUCCESS);
  3434. }
  3435.  
  3436.  
  3437. /* convert x/y coordinates to pixel */
  3438. int x2px(double x){
  3439.  return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
  3440. }
  3441.  
  3442. int y2px(double y){
  3443.  return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
  3444. }
  3445.  
  3446. double px2x(int x){
  3447.  return (x*(xmax - xmin)/xsize + xmin);
  3448. }
  3449. double px2y(int y){
  3450.  return (y*(ymax - ymin)/ysize + ymin);
  3451. }
  3452.  
  3453. void add_to_buffer(char *tmp){
  3454.  if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
  3455.  /*  do we have enough space left in buffer[MAX_BUFFER] ? */
  3456.  int space_left = (int) (sizeof(buffer) - strlen(buffer));
  3457.  if( space_left > strlen(tmp)){
  3458.   strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
  3459.  }
  3460.  else
  3461.  {
  3462.   canvas_error("buffer is too big\n");
  3463.  }
  3464.  tmp = NULL;free(tmp);
  3465.  return;
  3466. }
  3467.  
  3468. void reset(){
  3469.  if(use_filled == TRUE){use_filled = FALSE;}
  3470.  if(use_dashed == TRUE){use_dashed = FALSE;}
  3471.  if(use_rotate == TRUE){use_rotate = FALSE;}
  3472.    onclick = 0;
  3473. }
  3474.  
  3475.  
  3476.  
  3477. /* What reply format in read_canvas();
  3478.  
  3479. note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
  3480. 1 = x1,x2,x3,x4....x_n
  3481.     y1,y2,y3,y4....y_n
  3482.  
  3483.     x/y in pixels
  3484.  
  3485. 2 = x1,x2,x3,x4....x_n
  3486.     y1,y2,y3,y4....y_n
  3487.     x/y in  xrange / yrange coordinate system
  3488.  
  3489. 3 = x1,x2,x3,x4....x_n
  3490.     y1,y2,y3,y4....y_n
  3491.     r1,r2,r3,r4....r_n
  3492.  
  3493.     x/y in pixels
  3494.     r in pixels
  3495.  
  3496. 4 = x1,x2,x3,x4....x_n
  3497.     y1,y2,y3,y4....y_n
  3498.     r1,r2,r3,r4....r_n
  3499.  
  3500.     x/y in  xrange / yrange coordinate system
  3501.     r in pixels
  3502.  
  3503. 5 = Ax1,Ax2,Ax3,Ax4....Ax_n
  3504.     Ay1,Ay2,Ay3,Ay4....Ay_n
  3505.     Bx1,Bx2,Bx3,Bx4....Bx_n
  3506.     By1,By2,By3,By4....By_n
  3507.     Cx1,Cx2,Cx3,Cx4....Cx_n
  3508.     Cy1,Cy2,Cy3,Cy4....Cy_n
  3509.     ....
  3510.     Zx1,Zx2,Zx3,Zx4....Zx_n
  3511.     Zy1,Zy2,Zy3,Zy4....Zy_n
  3512.    
  3513.     x/y in pixels
  3514.  
  3515. 6 = Ax1,Ax2,Ax3,Ax4....Ax_n
  3516.     Ay1,Ay2,Ay3,Ay4....Ay_n
  3517.     Bx1,Bx2,Bx3,Bx4....Bx_n
  3518.     By1,By2,By3,By4....By_n
  3519.     Cx1,Cx2,Cx3,Cx4....Cx_n
  3520.     Cy1,Cy2,Cy3,Cy4....Cy_n
  3521.     ....
  3522.     Zx1,Zx2,Zx3,Zx4....Zx_n
  3523.     Zy1,Zy2,Zy3,Zy4....Zy_n
  3524.  
  3525.     x/y in  xrange / yrange coordinate system
  3526.    
  3527. 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  3528.    
  3529.     x/y in pixels
  3530.  
  3531. 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  3532.    
  3533.     x/y in  xrange / yrange coordinate system
  3534.  
  3535. 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n    
  3536.  
  3537.     x/y in pixels
  3538.  
  3539. 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n    
  3540.  
  3541.     x/y in  xrange / yrange coordinate system
  3542.  
  3543. 11 = Ax1,Ay1,Ax2,Ay2
  3544.      Bx1,By1,Bx2,By2
  3545.      Cx1,Cy1,Cx2,Cy2
  3546.      Dx1,Dy1,Dx2,Dy2
  3547.      ......
  3548.      Zx1,Zy1,Zx2,Zy2
  3549.      
  3550.     x/y in  xrange / yrange coordinate system
  3551.  
  3552. 12 = Ax1,Ay1,Ax2,Ay2
  3553.      Bx1,By1,Bx2,By2
  3554.      Cx1,Cy1,Cx2,Cy2
  3555.      Dx1,Dy1,Dx2,Dy2
  3556.      ......
  3557.      Zx1,Zy1,Zx2,Zy2
  3558.      
  3559.     x/y in pixels
  3560.  
  3561. 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
  3562.  
  3563.     x/y in  xrange / yrange coordinate system
  3564. 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
  3565.     x/y in pixels
  3566. 15 = reply from inputfields,textareas
  3567.     reply1,reply2,reply3,...,reply_n
  3568.     only fields set write (a.g. will not read 'readonly' inputfield values'
  3569.  
  3570. 16 = read mathml inputfields only
  3571.  
  3572. 17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n
  3573.  when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
  3574.  
  3575. 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
  3576. 19 = return clicked object number (analogue to shape-library onclick)
  3577. 20 = return x/y-data in x-range/y-range of all 'draggable' images
  3578. 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
  3579. 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
  3580.     x/y in  xrange / yrange coordinate system
  3581. 23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
  3582. 24 = read all inputfield values: even those set 'readonly'
  3583. 25 = return all userdrawn arcs in degrees:
  3584. 26 = return all userdrawn arcs in radians:
  3585. */
  3586.  
  3587.  
  3588. void add_read_canvas(int type_reply,int reply_precision){
  3589. /* just 1 reply type allowed */
  3590. fprintf(js_include_file,"\
  3591. \n<!-- begin set_reply_precision() -->\n\
  3592. function set_reply_precision(){\
  3593. var len = userdraw_x.length;\
  3594. var prec = %d;\
  3595. for(var p = 0 ; p < len ; p++ ){\
  3596.  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
  3597.  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
  3598. };\
  3599. len = userdraw_radius.length;\
  3600. if( len > 0 ){\
  3601.  for(var p = 0 ; p < len ; p++ ){\
  3602.   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
  3603.  };\
  3604. };\
  3605. };",reply_precision);
  3606.  
  3607. switch(type_reply){
  3608. /*  
  3609. answers may have:
  3610. x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
  3611. */
  3612.     case 1: fprintf(js_include_file,"\
  3613. \n<!-- begin function 1 read_canvas() -->\n\
  3614. read_canvas = function(){\
  3615. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3616. set_reply_precision();\
  3617. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3618.  var p = 0;var input_reply = new Array();\
  3619.  if( document.getElementById(\"canvas_input0\")){\
  3620.   var t = 0;\
  3621.   while(document.getElementById(\"canvas_input\"+t)){\
  3622.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3623.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3624.     p++;\
  3625.    };\
  3626.    t++;\
  3627.   };\
  3628.  };\
  3629.  if( typeof userdraw_text != 'undefined' ){\
  3630.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
  3631.  }\
  3632.  else\
  3633.  {\
  3634.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
  3635.  }\
  3636. }\
  3637. else\
  3638. {\
  3639.  if( typeof userdraw_text != 'undefined' ){\
  3640.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
  3641.  }\
  3642.  else\
  3643.  {\
  3644.   return userdraw_x+\"\\n\"+userdraw_y;\
  3645.  }\
  3646. };\
  3647. };\n\
  3648. <!-- end function 1 read_canvas() -->");
  3649.     break;
  3650.     case 2: fprintf(js_include_file,"\
  3651. \n<!-- begin function 2 read_canvas() -->\n\
  3652. read_canvas = function(){\
  3653. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3654. set_reply_precision();\
  3655. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  3656. var prec = %d;\
  3657. while(userdraw_x[p]){\
  3658.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  3659.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  3660.  p++;\
  3661. };\
  3662. if(p == 0){alert(\"nothing drawn...\");return;};\
  3663. if( document.getElementById(\"canvas_input0\")){\
  3664.  var p = 0;var input_reply = new Array();\
  3665.  if( document.getElementById(\"canvas_input0\")){\
  3666.   var t = 0;\
  3667.   while(document.getElementById(\"canvas_input\"+t)){\
  3668.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3669.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3670.     p++;\
  3671.    };\
  3672.    t++;\
  3673.   };\
  3674.  };\
  3675.  if( typeof userdraw_text != 'undefined' ){\
  3676.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3677.  }\
  3678.  else\
  3679.  {\
  3680.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  3681.  }\
  3682. }\
  3683. else\
  3684. {\
  3685.  if( typeof userdraw_text != 'undefined' ){\
  3686.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  3687.  }\
  3688.  else\
  3689.  {\
  3690.   return reply_x+\"\\n\"+reply_y;\
  3691.  };\
  3692. };\
  3693. };\n\
  3694. <!-- end function 2 read_canvas() -->",reply_precision);
  3695.     break;
  3696.     case 3: fprintf(js_include_file,"\
  3697. \n<!-- begin function 3 read_canvas() -->\n\
  3698. read_canvas = function(){\
  3699. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3700. set_reply_precision();\
  3701. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3702.  var p = 0;var input_reply = new Array();\
  3703.  if( document.getElementById(\"canvas_input0\")){\
  3704.   var t = 0;\
  3705.   while(document.getElementById(\"canvas_input\"+t)){\
  3706.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3707.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3708.     p++;\
  3709.    };\
  3710.    t++;\
  3711.   };\
  3712.  };\
  3713.  if( typeof userdraw_text != 'undefined' ){\
  3714.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3715.  }\
  3716.  else\
  3717.  {\
  3718.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  3719.  }\
  3720. }\
  3721. else\
  3722. {\
  3723.  if( typeof userdraw_text != 'undefined' ){\
  3724.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
  3725.  }\
  3726.  else\
  3727.  {\
  3728.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
  3729.  }\
  3730. }\
  3731. };\n\
  3732. <!-- end function 3 read_canvas() -->");
  3733.     break;
  3734.     case 4: fprintf(js_include_file,"\
  3735. \n<!-- begin function 4 read_canvas() -->\n\
  3736. read_canvas = function(){\
  3737. var prec = %d;\
  3738. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  3739. while(userdraw_x[p]){\
  3740.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  3741.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
  3742.  p++;\
  3743. };\
  3744. if(p == 0){alert(\"nothing drawn...\");return;};\
  3745. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3746.  var p = 0;var input_reply = new Array();\
  3747.  if( document.getElementById(\"canvas_input0\")){\
  3748.   var t = 0;\
  3749.   while(document.getElementById(\"canvas_input\"+t)){\
  3750.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3751.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3752.     p++;\
  3753.    };\
  3754.    t++;\
  3755.   };\
  3756.  };\
  3757.  if( typeof userdraw_text != 'undefined' ){\
  3758.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3759.  }\
  3760.  else\
  3761.  {\
  3762.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  3763.  }\
  3764. }\
  3765. else\
  3766. {\
  3767.  if( typeof userdraw_text != 'undefined' ){\
  3768.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
  3769.  }\
  3770.  else\
  3771.  {\
  3772.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
  3773.  }\
  3774. };\
  3775. };\n\
  3776. <!-- end function 4 read_canvas() -->",reply_precision);
  3777.     break;
  3778.     /*
  3779.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  3780.         used for userdraw multiple paths
  3781.     */
  3782.     case 5: fprintf(js_include_file,"\
  3783. \n<!-- begin function 5 read_canvas() -->\n\
  3784. read_canvas = function(){\
  3785. set_reply_precision();\
  3786. var p = 0;\
  3787. var reply = \"\";\
  3788. for(p = 0; p < userdraw_x.length;p++){\
  3789.  if(userdraw_x[p] != null ){\
  3790.   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
  3791.  };\
  3792. };\
  3793. if(p == 0){alert(\"nothing drawn...\");return;};\
  3794. userdraw_x = [];userdraw_y = [];\
  3795. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3796.  var p = 0;var input_reply = new Array();\
  3797.  if( document.getElementById(\"canvas_input0\")){\
  3798.   var t = 0;\
  3799.   while(document.getElementById(\"canvas_input\"+t)){\
  3800.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3801.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3802.     p++;\
  3803.    };\
  3804.    t++;\
  3805.   };\
  3806.  };\
  3807.  if( typeof userdraw_text != 'undefined' ){\
  3808.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3809.  }\
  3810.  else\
  3811.  {\
  3812.   return reply +\"\\n\"+input_reply;\
  3813.  }\
  3814. }\
  3815. else\
  3816. {\
  3817.  if( typeof userdraw_text != 'undefined' ){\
  3818.   return reply+\"\\n\"+userdraw_text;\
  3819.  }\
  3820.  else\
  3821.  {\
  3822.   return reply;\
  3823.  }\
  3824. };\
  3825. };\n\
  3826. <!-- end function 5 read_canvas() -->");
  3827.     break;
  3828.     /*
  3829.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  3830.         used for userdraw multiple paths
  3831.     */
  3832.     case 6: fprintf(js_include_file,"\
  3833. \n<!-- begin function 6 read_canvas() -->\n\
  3834. read_canvas = function(){\
  3835. var p = 0;\
  3836. var reply = \"\";\
  3837. var tmp_x = new Array();\
  3838. var tmp_y = new Array();\
  3839. var prec = %d;\
  3840. for(p = 0 ; p < userdraw_x.length; p++){\
  3841.  tmp_x = userdraw_x[p];\
  3842.  tmp_y = userdraw_y[p];\
  3843.  if(tmp_x != null){\
  3844.   for(var i = 0 ; i < tmp_x.length ; i++){\
  3845.    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
  3846.    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
  3847.   };\
  3848.   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
  3849.  };\
  3850. };\
  3851. if(p == 0){alert(\"nothing drawn...\");return;};\
  3852. userdraw_x = [];userdraw_y = [];\
  3853. if( document.getElementById(\"canvas_input0\") ){\
  3854.  var p = 0;var input_reply = new Array();\
  3855.  if( document.getElementById(\"canvas_input0\")){\
  3856.   var t = 0;\
  3857.   while(document.getElementById(\"canvas_input\"+t)){\
  3858.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3859.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3860.     p++;\
  3861.    };\
  3862.    t++;\
  3863.   };\
  3864.  };\
  3865.  if( typeof userdraw_text != 'undefined' ){\
  3866.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3867.  }\
  3868.  else\
  3869.  {\
  3870.   return reply +\"\\n\"+input_reply;\
  3871.  }\
  3872. }\
  3873. else\
  3874. {\
  3875.  if( typeof userdraw_text != 'undefined' ){\
  3876.   return reply +\"\\n\"+userdraw_text;\
  3877.  }\
  3878.  else\
  3879.  {\
  3880.   return reply;\
  3881.  }\
  3882. };\
  3883. };\n\
  3884. <!-- end function 6 read_canvas() -->",reply_precision);
  3885.     break;
  3886.     case 7: fprintf(js_include_file,"\
  3887. \n<!-- begin function 7 read_canvas() -->\n\
  3888. read_canvas = function(){\
  3889. set_reply_precision();\
  3890. var reply = new Array();\
  3891. var p = 0;\
  3892. while(userdraw_x[p]){\
  3893.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
  3894.  p++;\
  3895. };\
  3896. if(p == 0){alert(\"nothing drawn...\");return;};\
  3897. if( document.getElementById(\"canvas_input0\") ){\
  3898.  var p = 0;var input_reply = new Array();\
  3899.  if( document.getElementById(\"canvas_input0\")){\
  3900.   var t = 0;\
  3901.   while(document.getElementById(\"canvas_input\"+t)){\
  3902.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3903.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3904.     p++;\
  3905.    };\
  3906.    t++;\
  3907.   };\
  3908.  };\
  3909.  if( typeof userdraw_text != 'undefined' ){\
  3910.   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3911.  }\
  3912.  else\
  3913.  {\
  3914.   return reply+\"\\n\"+input_reply;\
  3915.  }\
  3916. }\
  3917. else\
  3918. {\
  3919.  if( typeof userdraw_text != 'undefined' ){\
  3920.   return reply+\"\\n\"+userdraw_text;\
  3921.  }\
  3922.  else\
  3923.  {\
  3924.   return reply;\
  3925.  }\
  3926. };\
  3927. };\n\
  3928. <!-- end function 7 read_canvas() -->");
  3929.     break;
  3930.     case 8: fprintf(js_include_file,"\
  3931. \n<!-- begin function 8 read_canvas() -->\n\
  3932. read_canvas = function(){\
  3933. var reply = new Array();\
  3934. var p = 0;\
  3935. var prec = %d;\
  3936. while(userdraw_x[p]){\
  3937.  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  3938.  p++;\
  3939. };\
  3940. if(p == 0){alert(\"nothing drawn...\");return;};\
  3941. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3942.  var p = 0;var input_reply = new Array();\
  3943.  if( document.getElementById(\"canvas_input0\")){\
  3944.   var t = 0;\
  3945.   while(document.getElementById(\"canvas_input\"+t)){\
  3946.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3947.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3948.     p++;\
  3949.    };\
  3950.    t++;\
  3951.   };\
  3952.  };\
  3953.  if( typeof userdraw_text != 'undefined' ){\
  3954.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3955.  }\
  3956.  else\
  3957.  {\
  3958.   return reply +\"\\n\"+input_reply;\
  3959.  }\
  3960. }\
  3961. else\
  3962. {\
  3963.  if( typeof userdraw_text != 'undefined' ){\
  3964.   return reply +\"\\n\"+userdraw_text;\
  3965.  }\
  3966.  else\
  3967.  {\
  3968.   return reply;\
  3969.  }\
  3970. };\
  3971. };\n\
  3972. <!-- end function 8 read_canvas() -->",reply_precision);
  3973.     break;
  3974.     case 9: fprintf(js_include_file,"\
  3975. \n<!-- begin function 9 read_canvas() -->\n\
  3976. read_canvas = function(){\
  3977. set_reply_precision();\
  3978. var reply = new Array();\
  3979. var p = 0;\
  3980. while(userdraw_x[p]){\
  3981.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
  3982.  p++;\
  3983. };\
  3984. if(p == 0){alert(\"nothing drawn...\");return;};\
  3985. if( document.getElementById(\"canvas_input0\") ){\
  3986.  var p = 0;var input_reply = new Array();\
  3987.  if( document.getElementById(\"canvas_input0\")){\
  3988.   var t = 0;\
  3989.   while(document.getElementById(\"canvas_input\"+t)){\
  3990.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3991.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3992.     p++;\
  3993.    };\
  3994.    t++;\
  3995.   };\
  3996.  };\
  3997.  if( typeof userdraw_text != 'undefined' ){\
  3998.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3999.  }\
  4000.  else\
  4001.  {\
  4002.   return reply +\"\\n\"+input_reply;\
  4003.  }\
  4004. }\
  4005. else\
  4006. {\
  4007.  if( typeof userdraw_text != 'undefined' ){\
  4008.   return reply +\"\\n\"+userdraw_text;\
  4009.  }\
  4010.  else\
  4011.  {\
  4012.   return reply;\
  4013.  }\
  4014. };\
  4015. };\n\
  4016. <!-- end function 9 read_canvas() -->");
  4017.     break;
  4018.     case 10: fprintf(js_include_file,"\
  4019. \n<!-- begin function 10 read_canvas() -->\n\
  4020. read_canvas = function(){\
  4021. var reply = new Array();\
  4022. var p = 0;\
  4023. var prec = %d;\
  4024. while(userdraw_x[p]){\
  4025.  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;\
  4026.  p++;\
  4027. };\
  4028. if(p == 0){alert(\"nothing drawn...\");return;};\
  4029. if( document.getElementById(\"canvas_input0\") ){\
  4030.  var p = 0;var input_reply = new Array();\
  4031.  if( document.getElementById(\"canvas_input0\")){\
  4032.   var t = 0;\
  4033.   while(document.getElementById(\"canvas_input\"+t)){\
  4034.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4035.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4036.     p++;\
  4037.    };\
  4038.    t++;\
  4039.   };\
  4040.  };\
  4041.  if( typeof userdraw_text != 'undefined' ){\
  4042.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4043.  }\
  4044.  else\
  4045.  {\
  4046.   return reply +\"\\n\"+input_reply;\
  4047.  }\
  4048. }\
  4049. else\
  4050. {\
  4051.  if( typeof userdraw_text != 'undefined' ){\
  4052.   return reply +\"\\n\"+userdraw_text;\
  4053.  }\
  4054.  else\
  4055.  {\
  4056.   return reply;\
  4057.  }\
  4058. };\
  4059. };\n\
  4060. <!-- end function 10 read_canvas() -->",reply_precision);
  4061.     break;
  4062.     case 11: fprintf(js_include_file,"\
  4063. \n<!-- begin function 11 read_canvas() -->\n\
  4064. read_canvas = function(){\
  4065. var reply = \"\";\
  4066. var p = 0;\
  4067. var prec = %d;\
  4068. while(userdraw_x[p]){\
  4069.  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\" ;\
  4070.  p = p+2;\
  4071. };\
  4072. if(p == 0){alert(\"nothing drawn...\");return;};\
  4073. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  4074.  var p = 0;var input_reply = new Array();\
  4075.  if( document.getElementById(\"canvas_input0\")){\
  4076.   var t = 0;\
  4077.   while(document.getElementById(\"canvas_input\"+t)){\
  4078.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4079.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4080.     p++;\
  4081.    };\
  4082.    t++;\
  4083.   };\
  4084.  };\
  4085.  if( typeof userdraw_text != 'undefined' ){\
  4086.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4087.  }\
  4088.  else\
  4089.  {\
  4090.   return reply +\"\\n\"+input_reply;\
  4091.  }\
  4092. }\
  4093. else\
  4094. {\
  4095.  if( typeof userdraw_text != 'undefined' ){\
  4096.   return reply +\"\\n\"+userdraw_text;\
  4097.  }\
  4098.  else\
  4099.  {\
  4100.   return reply;\
  4101.  }\
  4102. };\
  4103. };\n\
  4104. <!-- end function 11 read_canvas() -->",reply_precision);
  4105.     break;
  4106.     case 12: fprintf(js_include_file,"\
  4107. \n<!-- begin function 12 read_canvas() -->\n\
  4108. read_canvas = function(){\
  4109. set_reply_precision();\
  4110. var reply = \"\";\
  4111. var p = 0;\
  4112. for(p = 0; p< userdraw_x.lenght;p = p+2){\
  4113.  if(userdraw_x[p] != null){\
  4114.    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
  4115.  };\
  4116. };\
  4117. if(p == 0){alert(\"nothing drawn...\");return;};\
  4118. if( document.getElementById(\"canvas_input0\") ){\
  4119.  var p = 0;var input_reply = new Array();\
  4120.  if( document.getElementById(\"canvas_input0\")){\
  4121.   var t = 0;\
  4122.   while(document.getElementById(\"canvas_input\"+t)){\
  4123.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4124.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4125.     p++;\
  4126.    };\
  4127.    t++;\
  4128.   };\
  4129.  };\
  4130.  if( typeof userdraw_text != 'undefined' ){\
  4131.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4132.  }\
  4133.  else\
  4134.  {\
  4135.   return reply +\"\\n\"+input_reply;\
  4136.  }\
  4137. }\
  4138. else\
  4139. {\
  4140.  if( typeof userdraw_text != 'undefined' ){\
  4141.   return reply +\"\\n\"+userdraw_text\
  4142.  }\
  4143.  else\
  4144.  {\
  4145.   return reply;\
  4146.  }\
  4147. };\
  4148. };\n\
  4149. <!-- end function 12 read_canvas() -->");
  4150.     break;
  4151.     case 13: fprintf(js_include_file,"\
  4152. \n<!-- begin function 13 read_canvas() -->\n\
  4153. read_canvas = function(){\
  4154. var reply = new Array();\
  4155. var p = 0;var i = 0;\
  4156. var prec = %d;\
  4157. while(userdraw_x[p]){\
  4158.  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;\
  4159.  p = p+2;i++;\
  4160. };\
  4161. if(p == 0){alert(\"nothing drawn...\");return;};\
  4162. if( document.getElementById(\"canvas_input0\") ){\
  4163.  var p = 0;var input_reply = new Array();\
  4164.  if( document.getElementById(\"canvas_input0\")){\
  4165.   var t = 0;\
  4166.   while(document.getElementById(\"canvas_input\"+t)){\
  4167.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4168.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4169.     p++;\
  4170.    };\
  4171.    t++;\
  4172.   };\
  4173.  };\
  4174.  if( typeof userdraw_text != 'undefined' ){\
  4175.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4176.  }\
  4177.  else\
  4178.  {\
  4179.   return reply +\"\\n\"+input_reply;\
  4180.  }\
  4181. }\
  4182. else\
  4183. {\
  4184.  if( typeof userdraw_text != 'undefined' ){\
  4185.   return reply +\"\\n\"+userdraw_text\
  4186.  }\
  4187.  else\
  4188.  {\
  4189.   return reply;\
  4190.  }\
  4191. };\
  4192. };\n\
  4193. <!-- end function 13 read_canvas() -->",reply_precision);
  4194.     break;
  4195.     case 14: fprintf(js_include_file,"\
  4196. \n<!-- begin function 14 read_canvas() -->\n\
  4197. read_canvas = function(){\
  4198. set_reply_precision();\
  4199. var reply = new Array();\
  4200. var p = 0;var i = 0;\
  4201. while(userdraw_x[p]){\
  4202.  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
  4203.  p = p+2;i++;\
  4204. };\
  4205. if(p == 0){alert(\"nothing drawn...\");return;};\
  4206. if( document.getElementById(\"canvas_input0\") ){\
  4207.  var p = 0;var input_reply = new Array();\
  4208.  if( document.getElementById(\"canvas_input0\")){\
  4209.   var t = 0;\
  4210.   while(document.getElementById(\"canvas_input\"+t)){\
  4211.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4212.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4213.     p++;\
  4214.    };\
  4215.    t++;\
  4216.   };\
  4217.  };\
  4218.  if( typeof userdraw_text != 'undefined' ){\
  4219.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4220.  }\
  4221.  else\
  4222.  {\
  4223.   return reply +\"\\n\"+input_reply;\
  4224.  }\
  4225. }\
  4226. else\
  4227. {\
  4228.  if( typeof userdraw_text != 'undefined' ){\
  4229.   return reply +\"\\n\"+userdraw_text;\
  4230.  }\
  4231.  else\
  4232.  {\
  4233.   return reply;\
  4234.  }\
  4235. };\
  4236. };\n\
  4237. <!-- end function 14 read_canvas() -->");
  4238.     break;
  4239.     case 15: fprintf(js_include_file,"\
  4240. \n<!-- begin function 15  read_canvas() -->\n\
  4241. read_canvas = function(){\
  4242. var input_reply = new Array();\
  4243. var p = 0;\
  4244. if( document.getElementById(\"canvas_input0\")){\
  4245.  var t = 0;\
  4246.  while(document.getElementById(\"canvas_input\"+t)){\
  4247.   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4248.    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4249.    p++;\
  4250.   };\
  4251.   t++;\
  4252.  };\
  4253. };\
  4254. if( typeof userdraw_text != 'undefined' ){\
  4255.   return input_reply +\"\\n\"+userdraw_text;\
  4256. }\
  4257. else\
  4258. {\
  4259.  return input_reply;\
  4260. };\
  4261. };\n\
  4262. <!-- end function 15 read_canvas() -->");
  4263.     break;
  4264.     case 16: fprintf(js_include_file,"\
  4265. \n<!-- begin function 16 read_mathml() -->\n\
  4266. function read_mathml(){\
  4267. var reply = new Array();\
  4268. var p = 0;\
  4269. if( document.getElementById(\"mathml0\")){\
  4270.  while(document.getElementById(\"mathml\"+p)){\
  4271.   reply[p] = document.getElementById(\"mathml\"+p).value;\
  4272.   p++;\
  4273.  };\
  4274. };\
  4275. return reply;\
  4276. };\
  4277. this.read_mathml = read_mathml;\n\
  4278. <!-- end function 16 read_mathml() -->");
  4279.     break;
  4280.     case 17:  fprintf(js_include_file,"\
  4281. \n<!-- begin function 17 read_canvas() -->\n\
  4282. read_canvas = function(){\
  4283. if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\
  4284. return userdraw_text;\
  4285. };\n\
  4286. <!-- end function 17 read_canvas() -->");
  4287.     break;
  4288.     case 18: fprintf(js_include_file,"\
  4289. \n<!-- begin function 18 read_canvas() -->\n\
  4290. read_canvas = function(){\
  4291. var p = 0;\
  4292. var reply = new Array();\
  4293. var name;\
  4294. var t = true;\
  4295. var h;var m;var s;\
  4296. while(t){\
  4297.  try{\
  4298.   name = eval('clocks'+p);\
  4299.   h = name.H;m = name.M;s = name.S;\
  4300.   if(s < 0){s = 60 + s;m = m - 1;};\
  4301.   if(m < 0){m = 60 + m;h = h - 1;};\
  4302.   if(h < 0){h = 12 + h;};\
  4303.   h = parseInt((h+m/60+s/3600)%%12);m = parseInt((m + s/60)%%60);s = parseInt(s%%60);\
  4304.   reply[p] = h+\":\"+m+\":\"+s;\
  4305.   p++;\
  4306.  }catch(e){t=false;};\
  4307. };\
  4308. if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
  4309. return reply;\
  4310. };\n\
  4311. <!-- end function 18 read_canvas() -->");
  4312.     break;
  4313.     case 19: fprintf(js_include_file,"\
  4314. \n<!-- begin function 19 read_canvas() -->\n\
  4315. read_canvas = function(){\
  4316. return reply[0];\
  4317. };\n\
  4318. <!-- end function 19 read_canvas() -->");
  4319.     case 20: fprintf(js_include_file,"\
  4320. \n<!-- begin function 20 read_canvas() -->\n\
  4321. read_canvas = function(){\
  4322. var prec = %d;\
  4323. var len  = ext_drag_images.length;\
  4324. var reply = new Array(len);\
  4325. for(var p = 0 ; p < len ; p++){\
  4326.    var img = ext_drag_images[p];\
  4327.    reply[p] = (Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  4328. };\
  4329. return reply;\
  4330. };\n\
  4331. <!-- end function 20 read_canvas() -->",reply_precision);
  4332.     break;
  4333.     case 21: fprintf(js_include_file,"\
  4334. \n<!-- begin function 21 read_canvas() -->\n\
  4335. read_canvas = function(){\
  4336. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  4337. var reply_coord = new Array();var p = 0;\
  4338. var prec = %d;\
  4339. while(userdraw_x[p]){\
  4340.  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
  4341.  p++;\
  4342. };\
  4343. if(p == 0){alert(\"nothing drawn...\");return;};\
  4344. if( document.getElementById(\"canvas_input0\") ){\
  4345.  var p = 0;var input_reply = new Array();\
  4346.  if( document.getElementById(\"canvas_input0\")){\
  4347.   var t = 0;\
  4348.   while(document.getElementById(\"canvas_input\"+t)){\
  4349.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4350.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4351.     p++;\
  4352.    };\
  4353.    t++;\
  4354.   };\
  4355.  };\
  4356.  if( typeof userdraw_text != 'undefined' ){\
  4357.   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4358.  }\
  4359.  else\
  4360.  {\
  4361.   return reply_coord+\"\\n\"+input_reply;\
  4362.  }\
  4363. }\
  4364. else\
  4365. {\
  4366.  if( typeof userdraw_text != 'undefined' ){\
  4367.   return reply_coord+\"\\n\"+userdraw_text;\
  4368.  }\
  4369.  else\
  4370.  {\
  4371.   return reply_coord;\
  4372.  };\
  4373. };\
  4374. };\n\
  4375. <!-- end function 21 read_canvas() -->",reply_precision);
  4376.     break;
  4377.     case 22: fprintf(js_include_file,"\
  4378. \n<!-- begin function 22 read_canvas() -->\n\
  4379. read_canvas = function(){\
  4380. var reply = new Array();\
  4381. var lu = userdraw_x.length;\
  4382. if(lu == 0){alert(\"nothing drawn...\");return;};\
  4383. var idx = 0;\
  4384. var prec = %d;\
  4385. for(var p = 0 ; p < lu ; p++){\
  4386.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
  4387.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
  4388. };\
  4389. if( document.getElementById(\"canvas_input0\") ){\
  4390.  var p = 0;var input_reply = new Array();\
  4391.  if( document.getElementById(\"canvas_input0\")){\
  4392.   var t = 0;\
  4393.   while(document.getElementById(\"canvas_input\"+t)){\
  4394.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4395.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4396.     p++;\
  4397.    };\
  4398.    t++;\
  4399.   };\
  4400.  };\
  4401.  if( typeof userdraw_text != 'undefined' ){\
  4402.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4403.  }\
  4404.  else\
  4405.  {\
  4406.   return reply +\"\\n\"+input_reply;\
  4407.  }\
  4408. }\
  4409. else\
  4410. {\
  4411.  if( typeof userdraw_text != 'undefined' ){\
  4412.   return reply +\"\\n\"+userdraw_text;\
  4413.  }\
  4414.  else\
  4415.  {\
  4416.   return reply;\
  4417.  }\
  4418. };\
  4419. };\n\
  4420. <!-- end function 22 read_canvas() -->",reply_precision);
  4421.     break;
  4422.     case 23: fprintf(js_include_file,"\
  4423. \n<!-- begin function 23 read_canvas() default 5 px marge -->\n\
  4424. read_canvas = function(){\
  4425. if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
  4426. var lu = userdraw_x.length;\
  4427. if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
  4428. var reply_x = new Array();var reply_y = new Array();\
  4429. var marge = 5;var p = 0;\
  4430. var prec = %d;\
  4431. for(var i = 0; i < lu - 1 ; i++ ){\
  4432.  if( Math.abs(userdraw_x[i] - userdraw_x[i+1])){\
  4433.   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
  4434.   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
  4435.   p++;\
  4436.  };\
  4437.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\
  4438. };\
  4439. if( document.getElementById(\"canvas_input0\")){\
  4440.  var p = 0;var input_reply = new Array();\
  4441.  if( document.getElementById(\"canvas_input0\")){\
  4442.   var t = 0;\
  4443.   while(document.getElementById(\"canvas_input\"+t)){\
  4444.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4445.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4446.     p++;\
  4447.    };\
  4448.    t++;\
  4449.   };\
  4450.  };\
  4451.  if( typeof userdraw_text != 'undefined' ){\
  4452.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4453.  }\
  4454.  else\
  4455.  {\
  4456.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  4457.  }\
  4458. }\
  4459. else\
  4460. {\
  4461.  if( typeof userdraw_text != 'undefined' ){\
  4462.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  4463.  }\
  4464.  else\
  4465.  {\
  4466.   return reply_x+\"\\n\"+reply_y;\
  4467.  };\
  4468. };\
  4469. };\n\
  4470. <!-- end function 23 read_canvas() -->",reply_precision);
  4471.     break;
  4472.     case 24: fprintf(js_include_file,"\n\
  4473. <!-- begin function 24  read_canvas() -->\n\
  4474. read_canvas = function(){\
  4475. var input_reply = new Array();\
  4476. var p = 0;\
  4477. if( document.getElementById(\"canvas_input0\")){\
  4478.  while(document.getElementById(\"canvas_input\"+p)){\
  4479.    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
  4480.    p++;\
  4481.  };\
  4482.  return input_reply;\
  4483. };\
  4484. };\n\
  4485. <!-- end function 24 read_canvas() -->");
  4486.     break;
  4487.     case 25:
  4488.     fprintf(js_include_file,"\n<!-- begin function 25 read_canvas() : angle(s) in degrees-->\n\
  4489. read_canvas = function(){\
  4490. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  4491. var lu = userdraw_radius.length;\
  4492. var prec = %d;\
  4493. var angle_reply = new Array(lu);\
  4494. for(var p = 0 ; p < lu ; p++){\
  4495.  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
  4496. };\
  4497. return angle_reply;\
  4498. };\n\
  4499. <!-- end function 25 read_canvas() -->",reply_precision);
  4500.     break;
  4501.     case 26:
  4502.     fprintf(js_include_file,"\n<!-- begin function 25 read_canvas() : angle(s) in radians-->\n\
  4503. read_canvas = function(){\
  4504. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  4505. var lu = userdraw_radius.length;\
  4506. var prec = %d;\
  4507. var angle_reply = new Array(lu);\
  4508. for(var p = 0 ; p < lu ; p++){\
  4509.  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
  4510. };\
  4511. return angle_reply;\
  4512. };\n\
  4513. <!-- end function 25 read_canvas() -->",reply_precision);
  4514.     break;
  4515.     default: canvas_error("hmmm unknown replyformat...");break;
  4516. }
  4517.  return;
  4518. }
  4519.  
  4520.  
  4521. /*
  4522.  add drawfunction :
  4523.  - functions used by userdraw_primitives (circle,rect,path,triangle...)
  4524.  - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
  4525.  - grid / mathml
  4526.  - will not scale or zoom in
  4527.  - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
  4528.  - is printed directly into 'js_include_file'
  4529. */
  4530.  
  4531. void add_javascript_functions(int js_functions[],int canvas_root_id){
  4532. int i;
  4533. for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
  4534.  if( js_functions[i] == 1){
  4535.     switch(i){
  4536.     case DRAG_EXTERNAL_IMAGE:
  4537. fprintf(js_include_file,"\n<!-- drag external images --->\n\
  4538. var external_canvas = create_canvas%d(7,xsize,ysize);\
  4539. var external_ctx = external_canvas.getContext(\"2d\");\
  4540. var external_canvas_rect = external_canvas.getBoundingClientRect();\
  4541. canvas_div.addEventListener(\"mousedown\",setxy,false);\
  4542. canvas_div.addEventListener(\"mouseup\",dragstop,false);\
  4543. canvas_div.addEventListener(\"mousemove\",dragxy,false);\
  4544. var selected_image = null;\
  4545. var ext_image_cnt = 0;\
  4546. var ext_drag_images = new Array();\
  4547. function drag_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,draggable){\
  4548. ext_image_cnt = idx;\
  4549. var image = new Image();\
  4550. image.src = URL;\
  4551. image.onload = function(){\
  4552.  if( x0 < 1 ){ x0 = 0; };if( y0 < 1 ){ y0 = 0; };if( sx < 1 ){ sx = 0; };if( sy < 1 ){ sy = 0; };\
  4553.  if( width < 1 ){ width = image.width; };if( height < 1 ){ height = image.height; };\
  4554.  if( swidth < 1 ){ swidth = image.width; };if( sheight < 1 ){ sheight = image.height; };\
  4555.  var img = new Array(10);\
  4556.  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
  4557.  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;\
  4558.  ext_drag_images[idx] = img;\
  4559.  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  4560. };\
  4561. };\
  4562. function dragstop(evt){\
  4563. selected_image = null;return;\
  4564. };\
  4565. function dragxy(evt){\
  4566. if( selected_image != null ){\
  4567.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  4568.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  4569.  var s_img = ext_drag_images[selected_image];\
  4570.  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\
  4571.  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\
  4572.  ext_drag_images[selected_image] = s_img;\
  4573.  external_ctx.clearRect(0,0,xsize,ysize);\
  4574.  for(var i = 0; i <= ext_image_cnt ; i++){\
  4575.   var img = ext_drag_images[i];\
  4576.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  4577.  };\
  4578. };\
  4579. };\
  4580. function setxy(evt){\
  4581. if( ! selected_image && evt.which == 1 ){\
  4582.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  4583.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  4584.  var xm = evt.clientX - external_canvas_rect.left + xoff;\
  4585.  var ym = evt.clientY - external_canvas_rect.top + yoff;\
  4586.  for(var p = 0 ; p <= ext_image_cnt ; p++){\
  4587.   var img = ext_drag_images[p];\
  4588.   if( img[0] == 1 ){\
  4589.    var w = img.width;\
  4590.    var h = img.height;\
  4591.    if( xm > img[6] && xm < img[6] + img[4]){\
  4592.     if( ym > img[7] && ym < img[7] + img[5]){\
  4593.      img[6] = xm;\
  4594.      img[7] = ym;\
  4595.      ext_drag_images[p] = img;\
  4596.      selected_image = p;\
  4597.      dragxy(evt);\
  4598.     };\
  4599.    };\
  4600.   };\
  4601.  };\
  4602. }\
  4603. else\
  4604. {\
  4605.  selected_image = null;\
  4606. };\
  4607. };",canvas_root_id);
  4608.     break;
  4609.  
  4610.     case DRAW_EXTERNAL_IMAGE:
  4611. fprintf(js_include_file,"\n<!-- draw external images -->\n\
  4612. var draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\
  4613. var image = new Image();\
  4614. image.src = URL;\
  4615. var canvas_bg_div = document.getElementById(\"canvas_div%d\");\
  4616. image.onload = function(){\
  4617.  if( x0 < 1 ){ x0 = 0; };\
  4618.  if( y0 < 1 ){ y0 = 0; };\
  4619.  if( sx < 1 ){ sx = 0; };\
  4620.  if( sy < 1 ){ sy = 0; };\
  4621.  if( width < 1 ){ width = image.width;};\
  4622.  if( height < 1 ){ height = image.height;};\
  4623.  if( swidth < 1 ){ swidth = image.width;};\
  4624.  if( sheight < 1 ){ sheight = image.height;};\
  4625.  var ml = x0 - sx;\
  4626.  var mh = y0 - sy;\
  4627.  canvas_bg_div.style.backgroundPosition= \"left \"+ml+\"px top \"+mh+\"px\";\
  4628.  canvas_bg_div.style.backgroundSize = width+\"px \"+height+\"px\";\
  4629.  canvas_bg_div.style.backgroundRepeat = \"no-repeat\";\
  4630.  canvas_bg_div.style.backgroundPosition= sx+\"px \"+sy+\"px\";\
  4631.  canvas_bg_div.style.backgroundImage = \"url(\" + URL + \")\";\
  4632. };\
  4633. };",canvas_root_id);    
  4634.     break;
  4635.     case DRAW_GRIDFILL:/* not used for userdraw */
  4636. fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
  4637. var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\
  4638. var obj;\
  4639. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4640.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4641. }\
  4642. else\
  4643. {\
  4644.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4645. };\
  4646. var ctx = obj.getContext(\"2d\");\
  4647. var x,y;\
  4648. snap_x = dx;snap_y = dy;\
  4649. ctx.save();\
  4650. ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  4651. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  4652.    ctx.moveTo(x,y0);\
  4653.    ctx.lineTo(x,ysize);\
  4654. };\
  4655. for( y = y0 ; y < ysize+dy; y = y + dy ){\
  4656.    ctx.moveTo(x0,y);\
  4657.    ctx.lineTo(xsize,y);\
  4658. };\
  4659. ctx.stroke();\
  4660. ctx.restore();\
  4661. return;};",canvas_root_id,canvas_root_id,canvas_root_id);
  4662.     break;
  4663.    
  4664.     case DRAW_IMAGEFILL:/* not  used for userdraw */
  4665. fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
  4666. var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\
  4667. var obj;\
  4668. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4669.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4670. }\
  4671. else\
  4672. {\
  4673.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4674. };\
  4675. var ctx = obj.getContext(\"2d\");\
  4676. ctx.save();\
  4677. var img = new Image();\
  4678. img.src = URL;\
  4679. img.onload = function(){\
  4680.  if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\
  4681.    ctx.drawImage(img,x0,y0,xsize,ysize);\
  4682.  }\
  4683.  else\
  4684.  {\
  4685.    var repeat = \"repeat\";\
  4686.    if(img.width > xsize - x0){\
  4687.         repeat = \"repeat-y\";\
  4688.    }\
  4689.    else\
  4690.    {\
  4691.     if( img.height > ysize -x0 ){\
  4692.      repeat = \"repeat-x\";\
  4693.     }\
  4694.    }\
  4695.    var pattern = ctx.createPattern(img,repeat);\
  4696.    ctx.rect(x0,y0,xsize,ysize);\
  4697.    ctx.fillStyle = pattern;\
  4698.  }\
  4699.  ctx.fill();\
  4700. };\
  4701. ctx.restore();\
  4702. return;\
  4703. };",canvas_root_id,canvas_root_id,canvas_root_id);
  4704.     break;
  4705.    
  4706.     case DRAW_DOTFILL:/* not  used for userdraw */
  4707. fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
  4708. var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\
  4709. var obj;\
  4710. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4711.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4712. }\
  4713. else\
  4714. {\
  4715.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4716. };\
  4717. var ctx = obj.getContext(\"2d\");\
  4718. var x,y;\
  4719. ctx.closePath();\
  4720. ctx.save();\
  4721. snap_x = dx;snap_y = dy;\
  4722. ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  4723. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  4724.  for( y = y0 ; y < ysize+dy ; y = y + dy ){\
  4725.   ctx.arc(x,y,radius,0,2*Math.PI,false);\
  4726.   ctx.closePath();\
  4727.  }\
  4728. }\
  4729. ctx.fill();\
  4730. ctx.restore();\
  4731. return;};",canvas_root_id,canvas_root_id,canvas_root_id);
  4732.     break;
  4733.  
  4734.     case DRAW_DIAMONDFILL:/* not used for userdraw */
  4735. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  4736. var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  4737.  var obj;\
  4738. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4739.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4740. }\
  4741. else\
  4742. {\
  4743.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4744. };\
  4745. var ctx = obj.getContext(\"2d\");\
  4746. var x;\
  4747. var y;\
  4748. ctx.save();\
  4749. ctx.lineWidth = linewidth;\
  4750. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4751. y = ysize;\
  4752. for( x = x0 ; x < xsize ; x = x + dx ){\
  4753.  ctx.moveTo(x,y0);\
  4754.  ctx.lineTo(xsize,y);\
  4755.  y = y - dy;\
  4756. };\
  4757. y = y0;\
  4758. for( x = xsize ; x > 0 ; x = x - dx){\
  4759.  ctx.moveTo(x,ysize);\
  4760.  ctx.lineTo(x0,y);\
  4761.  y = y + dy;\
  4762. };\
  4763. x = x0;\
  4764. for( y = y0 ; y < ysize ; y = y + dy ){\
  4765.  ctx.moveTo(xsize,y);\
  4766.  ctx.lineTo(x,ysize);\
  4767.  x = x + dx;\
  4768. };\
  4769. x = xsize;\
  4770. for( y = ysize ; y > y0 ; y = y - dy ){\
  4771.  ctx.moveTo(x,y0);\
  4772.  ctx.lineTo(x0,y);\
  4773.  x = x - dx;\
  4774. };\
  4775. ctx.stroke();\
  4776. ctx.restore();\
  4777. return;\
  4778. }",canvas_root_id,canvas_root_id,canvas_root_id);
  4779.     break;
  4780.    
  4781.     case DRAW_HATCHFILL:/* not used for userdraw */
  4782. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  4783. var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  4784.  var obj;\
  4785. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4786.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4787. }\
  4788. else\
  4789. {\
  4790.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4791. };\
  4792. var ctx = obj.getContext(\"2d\");\
  4793. var x;\
  4794. var y;\
  4795. ctx.save();\
  4796. ctx.lineWidth = linewidth;\
  4797. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4798. y = ysize;\
  4799. for( x = x0 ; x < xsize ; x = x + dx ){\
  4800.  ctx.moveTo(x,y0);\
  4801.  ctx.lineTo(xsize,y);\
  4802.  y = y - dy;\
  4803. };\
  4804. y = y0;\
  4805. for( x = xsize ; x >= dx ; x = x - dx){\
  4806.  ctx.moveTo(x,ysize);\
  4807.  ctx.lineTo(x0,y);\
  4808.  y = y + dy;\
  4809. };\
  4810. ctx.stroke();\
  4811. ctx.restore();\
  4812. return;\
  4813. };",canvas_root_id,canvas_root_id,canvas_root_id);
  4814.     break;
  4815.     case DRAW_CIRCLES:/*  used for userdraw */
  4816. fprintf(js_include_file,"\n<!-- draw circles -->\n\
  4817. 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){\
  4818. ctx.save();\
  4819. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4820. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4821. ctx.lineWidth = line_width;\
  4822. for(var p = 0 ; p < x_points.length ; p++ ){\
  4823.  ctx.beginPath();\
  4824.  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
  4825.  ctx.closePath();\
  4826.  if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4827.  if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  4828.  ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4829.  ctx.stroke();\
  4830. }\
  4831. ctx.restore();\
  4832. return;\
  4833. };");
  4834.     break;
  4835.     case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
  4836. fprintf(js_include_file,"\n<!-- draw polyline -->\n\
  4837. 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){\
  4838. ctx.save();\
  4839. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4840. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4841. ctx.lineWidth = line_width;\
  4842. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4843. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4844. ctx.clearRect(0,0,xsize,ysize);\
  4845. ctx.beginPath();\
  4846. for(var p = 0 ; p < x_points.length-1 ; p++ ){\
  4847.  ctx.moveTo(x_points[p],y_points[p]);\
  4848.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  4849. }\
  4850. ctx.closePath();\
  4851. ctx.stroke();\
  4852. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4853. for(var p = 0 ; p < x_points.length ; p++ ){\
  4854.  ctx.beginPath();\
  4855.  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
  4856.  ctx.closePath();ctx.fill();ctx.stroke();\
  4857. };\
  4858. ctx.restore();\
  4859. return;\
  4860. };");
  4861.     break;
  4862.    
  4863.     case DRAW_SEGMENTS:/*  used for userdraw */
  4864. fprintf(js_include_file,"\n<!-- draw segments -->\n\
  4865. 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){\
  4866. ctx.save();\
  4867. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4868. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4869. ctx.lineWidth = line_width;\
  4870. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4871. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4872. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  4873.  ctx.beginPath();\
  4874.  ctx.moveTo(x_points[p],y_points[p]);\
  4875.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  4876.  ctx.closePath();\
  4877.  ctx.stroke();\
  4878.  }\
  4879.  ctx.restore();\
  4880.  return;\
  4881. };");
  4882.     break;
  4883.    
  4884.     case DRAW_LINES:/*  used for userdraw */
  4885. fprintf(js_include_file,"\n<!-- draw lines -->\n\
  4886. function calc_line(x1,x2,y1,y2){\
  4887. var marge = 2;\
  4888. if(x1 < x2+marge && x1>x2-marge){\
  4889.  return [x1,0,x1,ysize];\
  4890. };\
  4891. if(y1 < y2+marge && y1>y2-marge){\
  4892.  return [0,y1,xsize,y1];\
  4893. };\
  4894. var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
  4895. var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
  4896. return [0,Y1,xsize,Y2];\
  4897. };\
  4898. 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){\
  4899. ctx.save();\
  4900. var line = new Array(4);\
  4901. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4902. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4903. ctx.lineWidth = line_width;\
  4904. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4905. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4906. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  4907.  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
  4908.  ctx.beginPath();\
  4909.  ctx.moveTo(line[0],line[1]);\
  4910.  ctx.lineTo(line[2],line[3]);\
  4911.  ctx.closePath();\
  4912.  ctx.stroke();\
  4913.  }\
  4914.  ctx.restore();\
  4915.  return;\
  4916. };");
  4917.     break;
  4918.  
  4919.     case DRAW_CROSSHAIRS:/*  used for userdraw */
  4920. fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
  4921. var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\
  4922. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4923. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4924. ctx.lineWidth = line_width;\
  4925. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4926. var x1,x2,y1,y2;\
  4927. for(var p = 0 ; p < x_points.length ; p++ ){\
  4928.  x1 = x_points[p] - crosshair_size;\
  4929.  x2 = x_points[p] + crosshair_size;\
  4930.  y1 = y_points[p] - crosshair_size;\
  4931.  y2 = y_points[p] + crosshair_size;\
  4932.  ctx.beginPath();\
  4933.  ctx.moveTo(x1,y1);\
  4934.  ctx.lineTo(x2,y2);\
  4935.  ctx.closePath();\
  4936.  ctx.stroke();\
  4937.  ctx.beginPath();\
  4938.  ctx.moveTo(x2,y1);\
  4939.  ctx.lineTo(x1,y2);\
  4940.  ctx.closePath();\
  4941.  ctx.stroke();\
  4942. }\
  4943. ctx.restore();\
  4944.  return;\
  4945. };");
  4946.     break;
  4947.  
  4948.     case DRAW_RECTS:/*  used for userdraw */
  4949. fprintf(js_include_file,"\n<!-- draw rects -->\n\
  4950. 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){\
  4951. ctx.save();\
  4952. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4953. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4954. ctx.lineWidth = line_width;\
  4955. ctx.strokeStyle = \"rgba('+stroke_color+','+stroke_opacity+')\";\
  4956. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
  4957. for(var p = 0 ; p < x_points.length ; p = p + 2){\
  4958.  ctx.beginPath();\
  4959.  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
  4960.  ctx.closePath();\
  4961.  if(use_filled == 1 ){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  4962.  ctx.stroke();\
  4963. };\
  4964. ctx.restore();\
  4965. return;\
  4966. };");
  4967.     break;
  4968.  
  4969.     case DRAW_ROUNDRECTS:/*  used for userdraw */
  4970. fprintf(js_include_file,"\n<!-- draw round rects -->\n\
  4971. 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){\
  4972. ctx.save();\
  4973. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4974. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4975. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4976. var x,y,w,h,r;\
  4977. for(var p = 0; p < x_points.length; p = p+2){\
  4978.  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);\
  4979.  ctx.beginPath();ctx.moveTo(x + r, y);\
  4980.  ctx.lineTo(x + w - r, y);\
  4981.  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
  4982.  ctx.lineTo(x + w, y + h - r);\
  4983.  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
  4984.  ctx.lineTo(x + r, y + h);\
  4985.  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
  4986.  ctx.lineTo(x, y + r);\
  4987.  ctx.quadraticCurveTo(x, y, x + r, y);\
  4988.  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
  4989.  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4990.  if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\
  4991.  ctx.stroke();\
  4992. }\
  4993. ctx.restore();\
  4994. };");
  4995.     break;
  4996.  
  4997.     case DRAW_ELLIPSES:/* not  used for userdraw */
  4998. fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
  4999. 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){\
  5000. var obj;\
  5001. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5002.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5003. }\
  5004. else\
  5005. {\
  5006.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5007. };\
  5008. var ctx = obj.getContext(\"2d\");\
  5009. ctx.save();\
  5010. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5011. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5012. var cx,cy,ry,rx;\
  5013. ctx.lineWidth = line_width;\
  5014. if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\
  5015. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5016. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5017. for(var p=0;p< x_points.length;p = p+2){\
  5018.  ctx.beginPath();\
  5019.  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
  5020.  ctx.translate(cx - rx, cy - ry);\
  5021.  ctx.scale(rx, ry);\
  5022.  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
  5023.  if( use_filled == 1 ){ctx.fill();}\
  5024.  ctx.stroke();\
  5025. };\
  5026. ctx.restore();\
  5027. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5028.     break;
  5029.  
  5030.     case DRAW_PATHS: /*  used for userdraw */
  5031. fprintf(js_include_file,"\n<!-- draw paths -->\n\
  5032. 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){\
  5033. ctx.save();\
  5034. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5035. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5036. ctx.lineWidth = line_width;\
  5037. ctx.lineJoin = \"round\";\
  5038. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5039. ctx.beginPath();\
  5040. ctx.moveTo(x_points[0],y_points[0]);\
  5041. for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
  5042. if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
  5043. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5044. if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  5045. ctx.stroke();\
  5046. ctx.restore();\
  5047. return;\
  5048. };");
  5049.    
  5050.     break;
  5051.     case DRAW_ARROWS:/*  used for userdraw */
  5052. fprintf(js_include_file,"\n<!-- draw arrows -->\n\
  5053. 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){\
  5054. ctx.save();\
  5055. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5056. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5057. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5058. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5059. ctx.lineWidth = line_width;\
  5060. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5061. ctx.lineCap = \"round\";\
  5062. var x1,y1,x2,y2,dx,dy,len;\
  5063. for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
  5064.   ctx.save();\
  5065.   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
  5066.   len = Math.sqrt(dx*dx+dy*dy);\
  5067.   ctx.translate(x2,y2);\
  5068.   ctx.rotate(Math.atan2(dy,dx));\
  5069.   ctx.lineCap = \"round\";\
  5070.   ctx.beginPath();\
  5071.   ctx.moveTo(0,0);\
  5072.   ctx.lineTo(-len,0);\
  5073.   ctx.closePath();\
  5074.   ctx.stroke();\
  5075.   ctx.beginPath();\
  5076.   ctx.moveTo(0,0);\
  5077.   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  5078.   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  5079.   ctx.closePath();\
  5080.   ctx.fill();\
  5081.   ctx.restore();\
  5082.   if( type == 2 ){\
  5083.     ctx.save();\
  5084.     ctx.translate(x1,y1);\
  5085.     ctx.rotate(Math.atan2(-dy,-dx));\
  5086.     ctx.beginPath();\
  5087.     ctx.moveTo(0,0);\
  5088.     ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  5089.     ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  5090.     ctx.closePath();\
  5091.     ctx.stroke();\
  5092.     ctx.fill();\
  5093.     ctx.restore();\
  5094.   }\
  5095.  }\
  5096.  ctx.restore();\
  5097.  return;\
  5098. };");
  5099.     break;
  5100.  
  5101.     case DRAW_VIDEO:/* not  used for userdraw */
  5102. fprintf(js_include_file,"\n<!-- draw video -->\n\
  5103. var draw_video = function(canvas_root_id,x,y,w,h,URL){\
  5104. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  5105. var video_div = document.createElement(\"div\");\
  5106. canvas_div.appendChild(video_div);\
  5107. video_div.style.position = \"absolute\";\
  5108. video_div.style.left = x+\"px\";\
  5109. video_div.style.top = y+\"px\";\
  5110. video_div.style.width = w+\"px\";\
  5111. video_div.style.height = h+\"px\";\
  5112. var video = document.createElement(\"video\");\
  5113. video_div.appendChild(video);\
  5114. video.style.width = w+\"px\";\
  5115. video.style.height = h+\"px\";\
  5116. video.autobuffer = true;\
  5117. video.controls = true;video.autoplay = false;\
  5118. var src = document.createElement(\"source\");\
  5119. src.type = \"video/mp4\";\
  5120. src.src = URL;\
  5121. video.appendChild(src);\
  5122. video.load();\
  5123. return;\
  5124. };");    
  5125.     break;
  5126.    
  5127.     case DRAW_AUDIO:/* not used for userdraw */
  5128. fprintf(js_include_file,"\n<!-- draw audio -->\n\
  5129. var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
  5130. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  5131. var audio_div = document.createElement(\"div\");\
  5132. canvas_div.appendChild(audio_div);\
  5133. audio_div.style.position = \"absolute\";\
  5134. audio_div.style.left = x+\"px\";\
  5135. audio_div.style.top = y+\"px\";\
  5136. audio_div.style.width = w+\"px\";\
  5137. audio_div.style.height = h+\"px\";\
  5138. var audio = document.createElement(\"audio\");\
  5139. audio_div.appendChild(audio);\
  5140. audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
  5141. audio.autobuffer = true;\
  5142. if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;}\
  5143. if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;}\
  5144. var src1 = document.createElement(\"source\");\
  5145. src1.type = \"audio/ogg\";\
  5146. src1.src = URL1;\
  5147. audio.appendChild(src1);\
  5148. var src2 = document.createElement(\"source\");\
  5149. src2.type = \"audio/mpeg\";\
  5150. src2.src = URL2;\
  5151. audio.appendChild(src2);\
  5152. audio.load();\
  5153. return;\
  5154. };");
  5155.     break;
  5156.    
  5157.     case DRAW_HTTP:/* not  used for userdraw */
  5158. fprintf(js_include_file,"\n<!-- draw http -->\n\
  5159. var draw_http = function(canvas_root_id,x,y,w,h,URL){\
  5160. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  5161. var http_div = document.createElement(\"div\");\
  5162. var iframe = document.createElement(\"iframe\");\
  5163. canvas_div.appendChild(http_div);\
  5164. http_div.appendChild(iframe);\
  5165. iframe.src = URL;\
  5166. iframe.setAttribute(\"width\",w);\
  5167. iframe.setAttribute(\"height\",h);\
  5168. return;\
  5169. };");
  5170.     break;
  5171.    
  5172.     case DRAW_XML:
  5173. fprintf(js_include_file,"\n<!-- draw xml -->\n\
  5174. var draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick){\
  5175. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  5176. var xml_div = document.createElement(\"div\");\
  5177. canvas_div.appendChild(xml_div);\
  5178. xml_div.innerHTML = mathml;\
  5179. if(onclick != 0){\
  5180.  xml_div.onclick = function(){\
  5181.   reply[0] = onclick;\
  5182.   alert(\"send \"+onclick+\" ?\");\
  5183.  };\
  5184. };\
  5185. xml_div.style.position = \"absolute\";\
  5186. xml_div.style.left = x+\"px\";\
  5187. xml_div.style.top = y+\"px\";\
  5188. xml_div.style.width = w+\"px\";\
  5189. xml_div.style.height = h+\"px\";\
  5190. return;\
  5191. };"
  5192. );
  5193.     break;
  5194.     case DRAW_SGRAPH:
  5195. /*
  5196.  xstart = given
  5197.  ystart = given
  5198.  sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
  5199. */
  5200. fprintf(js_include_file,"\n<!-- draw sgraph -->\n\
  5201. var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
  5202. 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);};\
  5203. var ctx = obj.getContext(\"2d\");\
  5204. ctx.font = fontfamily;\
  5205. var minor_opacity = 0.8*opacity;\
  5206. ctx.clearRect(0,0,xsize,ysize);\
  5207. var zero_x = 0.1*xsize;\
  5208. var zero_y = 0.9*ysize;\
  5209. var snor_x;\
  5210. if( xstart != xmin){\
  5211.  snor_x = 0.1*xsize;\
  5212. }\
  5213. else\
  5214. {\
  5215.  snor_x = 0;\
  5216.  xstart = xmin;\
  5217. };\
  5218. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  5219. ctx.lineWidth = 2;\
  5220. ctx.beginPath();\
  5221. ctx.moveTo(xsize,zero_y);\
  5222. ctx.lineTo(zero_x,zero_y);\
  5223. ctx.lineTo(zero_x,0);\
  5224. ctx.stroke();\
  5225. ctx.closePath();\
  5226. ctx.beginPath();\
  5227. ctx.moveTo(zero_x,zero_y);\
  5228. ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
  5229. ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
  5230. ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
  5231. ctx.lineTo(zero_x + snor_x,zero_y);\
  5232. ctx.stroke();\
  5233. ctx.closePath();\
  5234. ctx.beginPath();\
  5235. var num = xstart;\
  5236. var flipflop = 1;\
  5237. var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
  5238. var txtsize;var txt_marge=step_x - 5;\
  5239. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  5240.  txtsize = ctx.measureText(num).width;\
  5241.  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
  5242.  if( flipflop == 1){\
  5243.   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
  5244.  }\
  5245.  else\
  5246.  {\
  5247.   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
  5248.  }\
  5249.  num = num + xmajor;\
  5250. };\
  5251. ctx.stroke();\
  5252. ctx.closePath();\
  5253. ctx.lineWidth = 1;\
  5254. ctx.beginPath();\
  5255. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  5256.   ctx.moveTo(x,zero_y);\
  5257.   ctx.lineTo(x,0);\
  5258. };\
  5259. ctx.stroke();\
  5260. ctx.closePath();\
  5261. if( xminor > 1){\
  5262.  ctx.lineWidth = 0.5;\
  5263.  ctx.beginPath();\
  5264.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  5265.  var minor_step_x = step_x / xminor;\
  5266.  var nx;\
  5267.  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
  5268.    num = 1;\
  5269.    for(var p = 1 ; p < xminor ; p++){\
  5270.     nx = x + num*minor_step_x;\
  5271.     ctx.moveTo(nx,zero_y);\
  5272.     ctx.lineTo(nx,0);\
  5273.     num++;\
  5274.    };\
  5275.  };\
  5276.  ctx.stroke();\
  5277.  ctx.closePath();\
  5278.  ctx.beginPath();\
  5279.  ctx.lineWidth = 2;\
  5280.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  5281.  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  5282.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
  5283.  };\
  5284.  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
  5285.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
  5286.  };\
  5287.  ctx.stroke();\
  5288.  ctx.closePath();\
  5289.  ctx.lineWidth = 0.5;\
  5290. };\
  5291. xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
  5292. if( ystart != ymin){\
  5293.  snor_y = 0.1*ysize;\
  5294. }\
  5295. else\
  5296. {\
  5297.  snor_y = 0;\
  5298.  ystart = ymin;\
  5299. };\
  5300. ctx.lineWidth = 2;\
  5301. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  5302. ctx.beginPath();\
  5303. ctx.moveTo(zero_x,zero_y);\
  5304. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
  5305. ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
  5306. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
  5307. ctx.lineTo(zero_x,zero_y - snor_y);\
  5308. ctx.stroke();\
  5309. ctx.closePath();\
  5310. ctx.beginPath();\
  5311. ctx.lineWidth = 1;\
  5312. num = ystart;\
  5313. var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
  5314. for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
  5315.  ctx.moveTo(zero_x,y);\
  5316.  ctx.lineTo(xsize,y);\
  5317.  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
  5318.  num = num + ymajor;\
  5319. };\
  5320. ctx.stroke();\
  5321. ctx.closePath();\
  5322. if( yminor > 1){\
  5323.  ctx.lineWidth = 0.5;\
  5324.  ctx.beginPath();\
  5325.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  5326.  var minor_step_y = step_y / yminor;\
  5327.  var ny;\
  5328.  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
  5329.   num = 1;\
  5330.   for(var p = 1 ;p < yminor;p++){\
  5331.     ny = y + num*minor_step_y;\
  5332.     ctx.moveTo(zero_x,ny);\
  5333.     ctx.lineTo(xsize,ny);\
  5334.     num++;\
  5335.    };\
  5336.  };\
  5337.  ctx.stroke();\
  5338.  ctx.closePath();\
  5339.  ctx.lineWidth = 2;\
  5340.  ctx.beginPath();\
  5341.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  5342.  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
  5343.   ctx.moveTo(zero_x,y);\
  5344.   ctx.lineTo(zero_x+12,y);\
  5345.  };\
  5346.  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
  5347.   ctx.moveTo(zero_x,y);\
  5348.   ctx.lineTo(zero_x+6,y);\
  5349.  };\
  5350.  ctx.stroke();\
  5351.  ctx.closePath();\
  5352. };\
  5353. ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
  5354. if( typeof legend%d  !== 'undefined' ){\
  5355.  ctx.globalAlpha = 1.0;\
  5356.  var y_offset = 2*font_size;\
  5357.  var txt;var txt_size;\
  5358.  var x_offset = xsize - 2*font_size;\
  5359.  var l_length = legend%d.length;var barcolor = new Array();\
  5360.  if( typeof legendcolors%d !== 'undefined' ){\
  5361.   for(var p = 0 ; p < l_length ; p++){\
  5362.    barcolor[p] = legendcolors%d[p];\
  5363.   };\
  5364.  }else{\
  5365.   if( barcolor.length == 0 ){\
  5366.    for(var p = 0 ; p < l_length ; p++){\
  5367.     barcolor[p] = stroke_color;\
  5368.    };\
  5369.   };\
  5370.  };\
  5371.  for(var p = 0; p < l_length; p++){\
  5372.   ctx.fillStyle = barcolor[p];\
  5373.   txt = legend%d[p];\
  5374.   txt_size = ctx.measureText(txt).width;\
  5375.   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
  5376.   y_offset = parseInt(y_offset + 1.5*font_size);\
  5377.  };\
  5378. };\
  5379. if( typeof xaxislabel !== 'undefined' ){\
  5380.   ctx.fillStyle = \'#000000\';\
  5381.   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
  5382.   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
  5383. };\
  5384. if( typeof yaxislabel !== 'undefined'){\
  5385.   ctx.save();\
  5386.   ctx.fillStyle = \'#000000\';\
  5387.   var txt_size = ctx.measureText(yaxislabel).width;\
  5388.   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
  5389.   ctx.rotate(-0.5*Math.PI);\
  5390.   ctx.fillText(yaxislabel,0,0);\
  5391.   ctx.restore();\
  5392. };\
  5393. };\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);
  5394.     break;
  5395.  
  5396.     case DRAW_GRID:/* not used for userdraw */
  5397. fprintf(js_include_file,"\n<!-- draw grid -->\n\
  5398. 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){\
  5399. 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);};\
  5400. var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
  5401. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5402. ctx.save();\
  5403. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  5404. if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
  5405. var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5406. ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
  5407. var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
  5408. ctx.font = font_family;\
  5409. var barcolor = new Array();\
  5410. var xstep = xsize*xmajor/(xmax - xmin);\
  5411. var ystep = ysize*ymajor/(ymax - ymin);\
  5412. var x2step = xstep / xminor;\
  5413. var y2step = ystep / yminor;\
  5414. var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
  5415. if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
  5416. if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
  5417. ctx.beginPath();\
  5418. ctx.lineWidth = line_width;\
  5419. ctx.strokeStyle = stroke_color;\
  5420. for(var p = zero_x ; p < xsize; p = p + xstep){\
  5421. ctx.moveTo(p,0);\
  5422. ctx.lineTo(p,ysize);\
  5423. };\
  5424. for(var p = zero_x ; p > 0; p = p - xstep){\
  5425. ctx.moveTo(p,0);\
  5426. ctx.lineTo(p,ysize);\
  5427. };\
  5428. for(var p = zero_y ; p < ysize; p = p + ystep){\
  5429. ctx.moveTo(0,p);\
  5430. ctx.lineTo(xsize,p);\
  5431. };\
  5432. for(var p = zero_y ; p > 0; p = p - ystep){\
  5433. ctx.moveTo(0,p);\
  5434. ctx.lineTo(xsize,p);\
  5435. };\
  5436. if( typeof xaxislabel !== 'undefined' ){\
  5437. ctx.save();\
  5438. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  5439. var corr =  ctx.measureText(xaxislabel).width;\
  5440. ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\
  5441. ctx.restore();\
  5442. };\
  5443. if( typeof yaxislabel !== 'undefined' ){\
  5444. ctx.save();\
  5445. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  5446. var corr =  ctx.measureText(yaxislabel).width;\
  5447. ctx.translate(zero_x+tics_length + font_size,corr+font_size);\
  5448. ctx.rotate(-0.5*Math.PI);\
  5449. ctx.fillText(yaxislabel,0,0);\
  5450. ctx.restore();\
  5451. };\
  5452. ctx.stroke();\
  5453. ctx.closePath();\
  5454. if( use_axis == 1 ){\
  5455. ctx.save();\
  5456. ctx.beginPath();\
  5457. ctx.strokeStyle = stroke_color;\
  5458. ctx.lineWidth = 0.6*line_width;\
  5459. for(var p = zero_x ; p < xsize; p = p + x2step){\
  5460.  ctx.moveTo(p,0);\
  5461.  ctx.lineTo(p,ysize);\
  5462. };\
  5463. for(var p = zero_x ; p > 0; p = p - x2step){\
  5464.  ctx.moveTo(p,0);\
  5465.  ctx.lineTo(p,ysize);\
  5466. };\
  5467. for(var p = zero_y ; p < ysize; p = p + y2step){\
  5468.  ctx.moveTo(0,p);\
  5469.  ctx.lineTo(xsize,p);\
  5470. };\
  5471. for(var p = zero_y ; p > 0; p = p - y2step){\
  5472.  ctx.moveTo(0,p);\
  5473.  ctx.lineTo(xsize,p);\
  5474. };\
  5475. ctx.stroke();\
  5476. ctx.closePath();\
  5477. ctx.beginPath();\
  5478. ctx.lineWidth = 2*line_width;\
  5479. ctx.strokeStyle = axis_color;\
  5480. ctx.moveTo(0,zero_y);\
  5481. ctx.lineTo(xsize,zero_y);\
  5482. ctx.moveTo(zero_x,0);\
  5483. ctx.lineTo(zero_x,ysize);\
  5484. ctx.stroke();\
  5485. ctx.closePath();\
  5486. ctx.lineWidth = line_width+0.5;\
  5487. ctx.beginPath();\
  5488. for(var p = zero_x ; p < xsize; p = p + xstep){\
  5489.  ctx.moveTo(p,zero_y-tics_length);\
  5490.  ctx.lineTo(p,zero_y+tics_length);\
  5491. };\
  5492. for(var p = zero_x ; p > 0; p = p - xstep){\
  5493.  ctx.moveTo(p,zero_y-tics_length);\
  5494.  ctx.lineTo(p,zero_y+tics_length);\
  5495. };\
  5496. for(var p = zero_y ; p < ysize; p = p + ystep){\
  5497.  ctx.moveTo(zero_x-tics_length,p);\
  5498.  ctx.lineTo(zero_x+tics_length,p);\
  5499. };\
  5500. for(var p = zero_y ; p > 0; p = p - ystep){\
  5501.  ctx.moveTo(zero_x-tics_length,p);\
  5502.  ctx.lineTo(zero_x+tics_length,p);\
  5503. };\
  5504. for(var p = zero_x ; p < xsize; p = p + x2step){\
  5505.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  5506.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  5507. };\
  5508. for(var p = zero_x ; p > 0; p = p - x2step){\
  5509.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  5510.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  5511. };\
  5512. for(var p = zero_y ; p < ysize; p = p + y2step){\
  5513.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  5514.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  5515. };\
  5516. for(var p = zero_y ; p > 0; p = p - y2step){\
  5517.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  5518.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  5519. };\
  5520. ctx.stroke();\
  5521. ctx.closePath();\
  5522. ctx.restore();\
  5523. };\
  5524. if( use_axis_numbering == 1 ){\
  5525. ctx.save();\
  5526. ctx.fillColor = axis_color;\
  5527. ctx.strokeStyle = axis_color;\
  5528. ctx.lineWidth = 2*line_width;\
  5529. ctx.font = font_family;\
  5530. var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
  5531. if( x_strings != null ){\
  5532.  var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  5533.  ctx.beginPath();\
  5534.  for(var p = 0 ; p < len ; p = p+2){\
  5535.   var x_nums = x2px(eval(x_strings[p]));\
  5536.   var x_text = x_strings[p+1];\
  5537.   corr = ctx.measureText(x_text).width;\
  5538.   skip = 1.2*corr/xstep;\
  5539.   if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
  5540.   if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
  5541.   ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
  5542.   ctx.moveTo(x_nums,zero_y - tics_length);\
  5543.   ctx.lineTo(x_nums,zero_y + tics_length);\
  5544.  };\
  5545.  ctx.closePath();\
  5546. }\
  5547. else\
  5548. {\
  5549.  skip = 1;cnt = px2x(zero_x);\
  5550.  prec = Math.log(precision)/(Math.log(10));\
  5551.  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
  5552.  for( var p = zero_x ; p < xsize ; p = p+xstep){\
  5553.   if(skip == 0 ){\
  5554.    disp_cnt = cnt.toFixed(prec);\
  5555.    corr = ctx.measureText(disp_cnt).width;\
  5556.    skip = parseInt(1.2*corr/xstep);\
  5557.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  5558.   }\
  5559.   else\
  5560.   {\
  5561.    skip--;\
  5562.   };\
  5563.   cnt = cnt + xmajor;\
  5564.  };\
  5565.  cnt = px2x(zero_x);skip = 1;\
  5566.  for( var p = zero_x ; p > 0 ; p = p-xstep){\
  5567.   if(skip == 0 ){\
  5568.    disp_cnt = cnt.toFixed(prec);\
  5569.    corr = ctx.measureText(disp_cnt).width;\
  5570.    skip = parseInt(1.2*corr/xstep);\
  5571.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  5572.   }\
  5573.   else\
  5574.   {\
  5575.    skip--;\
  5576.   };\
  5577.   cnt = cnt - xmajor;\
  5578.  };\
  5579. };\
  5580. if( y_strings != null ){\
  5581.  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
  5582.  ctx.beginPath();\
  5583.  for(var p = 0 ; p < len ; p = p+2){\
  5584.   var y_nums = y2px(eval(y_strings[p]));\
  5585.   var y_text = y_strings[p+1];\
  5586.   corr = 2 + tics_length + ctx.measureText(y_text).width;\
  5587.   if( corr > zero_x){corr = parseInt(zero_x+2); }\
  5588.   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
  5589.   ctx.moveTo(zero_x - tics_length,y_nums);\
  5590.   ctx.lineTo(zero_x + tics_length,y_nums);\
  5591.  };\
  5592.  ctx.closePath();\
  5593. }\
  5594. else\
  5595. {\
  5596.  if(f_x == 1){ corr = 1.5*tics_length; }\
  5597.  cnt = px2y(zero_y);skip = 1;\
  5598.  for( var p = zero_y ; p < ysize ; p = p+ystep){\
  5599.   if(skip == 0 ){\
  5600.    skip = parseInt(1.4*font_size/ystep);\
  5601.    disp_cnt = cnt.toFixed(prec);\
  5602.    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  5603.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  5604.   }\
  5605.   else\
  5606.   {\
  5607.    skip--;\
  5608.   };\
  5609.   cnt = cnt - ymajor;\
  5610.  };\
  5611.  corr = 0;cnt = px2y(zero_y);skip = 1;\
  5612.  if(f_x == 1){ corr = 1.5*tics_length; }\
  5613.  for( var p = zero_y ; p > 0 ; p = p-ystep){\
  5614.   if(skip == 0 ){\
  5615.    skip = parseInt(1.4*font_size/ystep);\
  5616.    disp_cnt = cnt.toFixed(prec);\
  5617.    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  5618.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  5619.   }\
  5620.   else\
  5621.   {\
  5622.    skip--;\
  5623.   };\
  5624.   cnt = cnt + ymajor;\
  5625.  };\
  5626. };\
  5627. ctx.stroke();\
  5628. ctx.restore();\
  5629. };\
  5630. if( typeof legend0  !== 'undefined' ){\
  5631. ctx.save();\
  5632. ctx.globalAlpha = 1.0;\
  5633. ctx.font = \"bold \"+font_size+\"px Ariel\";\
  5634. var y_offset = 2*font_size;\
  5635. var txt;var txt_size;\
  5636. var x_offset = xsize - 2*font_size;\
  5637. var l_length = legend0.length;\
  5638. if( typeof legendcolors0 !== 'undefined' ){\
  5639.  for(var p = 0 ; p < l_length ; p++){\
  5640.    barcolor[p] = legendcolors0[p];\
  5641.  };\
  5642. }\
  5643. else\
  5644. {\
  5645.  if( barcolor.length == 0 ){\
  5646.   for(var p = 0 ; p < l_length ; p++){\
  5647.    barcolor[p] = stroke_color;\
  5648.   };\
  5649.  };\
  5650. };\
  5651. for(var p = 0; p < l_length; p++){\
  5652.  ctx.fillStyle = barcolor[p];\
  5653.  txt = legend0[p];\
  5654.  txt_size = ctx.measureText(txt).width;\
  5655.  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
  5656.  y_offset = parseInt(y_offset + 1.5*font_size);\
  5657. };\
  5658. ctx.restore();\
  5659. };\
  5660. if( typeof barchart_0  !== 'undefined' ){\
  5661. ctx.save();\
  5662. var num_barcharts = 0;\
  5663. var bar_name = eval('barchart_0');\
  5664. while( typeof bar_name !== 'undefined' ){\
  5665.    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
  5666. };\
  5667. var bar_width = parseInt(0.8*xstep/(num_barcharts));\
  5668. for(var i=0 ; i< num_barcharts ; i++){\
  5669.  bar_name = eval('barchart_'+i);\
  5670.  var bar_x = new Array();\
  5671.  var bar_y = new Array();\
  5672.  var lb = bar_name.length;\
  5673.  var idx = 0;\
  5674.  var dx = parseInt(0.5*i*bar_width);\
  5675.  for( var p = 0 ; p < lb ; p = p + 3 ){\
  5676.   bar_x[idx] = x2px(bar_name[p]);\
  5677.   bar_y[idx] = y2px(bar_name[p+1]);\
  5678.   barcolor[idx] = bar_name[p+2];\
  5679.   idx++;\
  5680.  };\
  5681.  ctx.globalAlpha = fill_opacity;\
  5682.  ctx.beginPath();\
  5683.  for( var p = 0; p < idx ; p++ ){\
  5684.   ctx.strokeStyle = barcolor[p];\
  5685.   ctx.fillStyle = barcolor[p];\
  5686.   ctx.rect(bar_x[p]-0.4*xstep+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
  5687.  };\
  5688.  ctx.fill();\
  5689.  ctx.stroke();\
  5690.  ctx.closePath();\
  5691. };\
  5692. ctx.restore();\
  5693. };\
  5694. if( typeof linegraph_0 !== 'undefined' ){\
  5695. ctx.save();\
  5696. ctx.globalAlpha = 1.0;\
  5697. var i = 0;\
  5698. var line_name = eval('linegraph_'+i);\
  5699. while ( typeof line_name !== 'undefined' ){\
  5700.  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
  5701.  ctx.lineWidth = parseInt(line_name[1]);\
  5702.  if(line_name[2] == \"1\"){\
  5703.   var d1 = parseInt(line_name[3]);\
  5704.   var d2 = parseInt(line_name[4]);\
  5705.   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
  5706.  }\
  5707.  else\
  5708.  {\
  5709.  if(ctx.setLineDash){ctx.setLineDash = null;}\
  5710.  if(ctx.mozDash){ctx.mozDash = null;}\
  5711.  };\
  5712.  var data_x = new Array();\
  5713.  var data_y = new Array();\
  5714.  var lb = line_name.length;\
  5715.  var idx = 0;\
  5716.  for( var p = 5 ; p < lb ; p = p + 2 ){\
  5717.   data_x[idx] = x2px(line_name[p]);\
  5718.   data_y[idx] = y2px(line_name[p+1]);\
  5719.   idx++;\
  5720.  };\
  5721.  for( var p = 0; p < idx ; p++){\
  5722.   ctx.beginPath();\
  5723.   ctx.moveTo(data_x[p],data_y[p]);\
  5724.   ctx.lineTo(data_x[p+1],data_y[p+1]);\
  5725.   ctx.stroke();\
  5726.   ctx.closePath();\
  5727.  };\
  5728.  i++;\
  5729.  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
  5730. };\
  5731. ctx.restore();\
  5732. };\
  5733. return;\
  5734. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  5735.     break;
  5736.    
  5737.     case DRAW_PIECHART:
  5738. fprintf(js_include_file,"\n<!-- draw piecharts -->\n\
  5739. function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family){\
  5740. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5741.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5742. }\
  5743. else\
  5744. {\
  5745.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5746. };\
  5747. var ld = data_color_list.length;\
  5748. var sum = 0;\
  5749. var idx = 0;\
  5750. var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
  5751. var colors = new Array();\
  5752. var data = new Array();\
  5753. for(var p = 0;p < ld; p = p + 2){\
  5754.  data[idx] = parseFloat(data_color_list[p]);\
  5755.  sum = sum + data[idx];\
  5756.  colors[idx] = data_color_list[p+1];\
  5757.  idx++;\
  5758. };\
  5759. var ctx = obj.getContext(\"2d\");\
  5760. ctx.save();\
  5761. var angle;\
  5762. var angle_end = 0;\
  5763. var offset = Math.PI / 2;\
  5764. ctx.globalAlpha = fill_opacity;\
  5765. for(var p=0; p < idx; p++){\
  5766.  ctx.beginPath();\
  5767.  ctx.fillStyle = colors[p];\
  5768.  ctx.moveTo(x_center,y_center);\
  5769.  angle = Math.PI * (2 * data[p] / sum);\
  5770.  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
  5771.  ctx.lineTo(x_center, y_center);\
  5772.  ctx.fill();\
  5773.  ctx.closePath();\
  5774.  angle_end  = angle_end + angle;\
  5775. };\
  5776. if(typeof legend0 !== 'undefined'){\
  5777.  var legenda = eval(\"legend\"+legend_cnt);\
  5778.  ctx.globalAlpha = 1.0;\
  5779.  ctx.font = font_family;\
  5780.  var y_offset = font_size; \
  5781.  var x_offset = 0;\
  5782.  var txt;var txt_size;\
  5783.  for(var p = 0; p < idx; p++){\
  5784.   ctx.fillStyle = colors[p];\
  5785.   txt = legenda[p];\
  5786.   txt_size = ctx.measureText(txt).width;\
  5787.   if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
  5788.   ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
  5789.   y_offset = parseInt(y_offset + 1.5*font_size);\
  5790.  };\
  5791. };\
  5792. ctx.restore();\
  5793. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5794.    
  5795.     break;
  5796.     case DRAW_ARCS:
  5797. fprintf(js_include_file,"\n<!-- draw arcs -->\n\
  5798. 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){\
  5799. ctx.save();\
  5800. if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  5801. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  5802. if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  5803. if(end < start){var tmp = end;end = start;start=tmp;};\
  5804. start = 360 - start;\
  5805. end = 360 - end;\
  5806. ctx.lineWidth = line_width;\
  5807. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5808. ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  5809. ctx.beginPath();\
  5810. ctx.moveTo(xc,yc);\
  5811. ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  5812. ctx.lineTo(xc,yc);\
  5813. ctx.closePath();\
  5814. if( use_filled == 1 ){\
  5815.  ctx.fill();\
  5816. };\
  5817. ctx.stroke();\
  5818. ctx.restore();\
  5819. };");
  5820.    
  5821.     break;
  5822.     case DRAW_CENTERSTRING:
  5823. fprintf(js_include_file,"\n<!-- draw centerstring -->\n\
  5824. var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
  5825. var obj;\
  5826. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5827.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5828. }\
  5829. else\
  5830. {\
  5831.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5832. };\
  5833. var ctx = obj.getContext(\"2d\");\
  5834. ctx.save();\
  5835. ctx.font = font_family;\
  5836. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5837. var stringwidth = ctx.measureText(text).width;\
  5838. var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
  5839. ctx.fillText(text,x,y2px(y));\
  5840. return;\
  5841. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5842.     break;
  5843.     case DRAW_TEXTS:
  5844. fprintf(js_include_file,"\n<!-- draw text -->\n\
  5845. 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){\
  5846.  var obj;\
  5847.  if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5848.   obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5849.  }\
  5850.  else\
  5851.  {\
  5852.   obj = create_canvas%d(canvas_type,xsize,ysize);\
  5853.  };\
  5854.  var ctx = obj.getContext(\"2d\");\
  5855.  if(angle2 == 0 && angle != 0){\
  5856.   ctx.save();\
  5857.   if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5858.   if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5859.  };\
  5860.  if( font_family.indexOf('px') != null ){\
  5861.   ctx.font = font_family;\
  5862.  }\
  5863.  else\
  5864.  {\
  5865.   ctx.font = font_family;\
  5866.  };\
  5867.  ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5868.  if(angle2 != 0){\
  5869.   ctx.save();\
  5870.   ctx.translate(x,y);\
  5871.   ctx.rotate((360-angle2)*(Math.PI / 180));\
  5872.   ctx.fillText(text,0,0);\
  5873.   ctx.restore();\
  5874.  }else{ctx.fillText(text,x,y);};\
  5875. ctx.restore();\
  5876. return;\
  5877. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5878.     break;
  5879.     case DRAW_CURVE:
  5880. fprintf(js_include_file,"\n<!-- draw curve -->\n\
  5881. 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){\
  5882. var obj;\
  5883. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5884.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5885. }\
  5886. else\
  5887. {\
  5888.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5889. };\
  5890. var ctx = obj.getContext(\"2d\");\
  5891. ctx.save();\
  5892. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5893. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5894. ctx.beginPath();ctx.lineWidth = line_width;\
  5895. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5896. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5897. ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
  5898. for(var p = 1 ; p < x_points.length ; p++){\
  5899.  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
  5900.  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
  5901.  }\
  5902.  else\
  5903.  {\
  5904.   ctx.stroke();\
  5905.   ctx.beginPath();\
  5906.   p++;\
  5907.   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
  5908.  };\
  5909. };\
  5910. ctx.stroke();\
  5911. ctx.restore();\
  5912. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5913.     break;
  5914.    
  5915.     case DRAW_INPUTS:
  5916. fprintf(js_include_file,"\n<!-- draw input fields -->\n\
  5917. var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\
  5918. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  5919. var input = document.createElement(\"input\");\
  5920. input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  5921. input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  5922. input.setAttribute(\"size\",size);\
  5923. input.setAttribute(\"value\",value);\
  5924. if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
  5925. canvas_div.appendChild(input);};");
  5926.     break;
  5927.    
  5928.     case DRAW_TEXTAREAS:
  5929. fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
  5930. var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
  5931. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  5932. var textarea = document.createElement(\"textarea\");\
  5933. textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  5934. textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  5935. textarea.setAttribute(\"cols\",cols);\
  5936. textarea.setAttribute(\"rows\",rows);\
  5937. textarea.value = value;\
  5938. if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
  5939. canvas_div.appendChild(textarea);};");
  5940.     break;
  5941.    
  5942. case DRAW_PIXELS:
  5943. fprintf(js_include_file,"\n<!-- draw pixel -->\n\
  5944. var draw_setpixel = function(x,y,color,opacity,pixelsize){\
  5945. var canvas = create_canvas%d(10,xsize,ysize);\
  5946. var d = 0.5*pixelsize;\
  5947. var ctx = canvas.getContext(\"2d\");\
  5948. ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
  5949. ctx.clearRect(0,0,xsize,ysize);\
  5950. for(var p=0; p<x.length;p++){\
  5951.  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
  5952. };\
  5953. ctx.fill();ctx.stroke();\
  5954. };",canvas_root_id);
  5955. break;
  5956.  
  5957. case DRAW_CLOCK:
  5958. fprintf(js_include_file,"\n<!-- begin command clock -->\n\
  5959. var clock_canvas = create_canvas%d(%d,xsize,ysize);\
  5960. var clock_ctx = clock_canvas.getContext(\"2d\");\
  5961. var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
  5962. clock_ctx.save();\
  5963. clock_ctx.clearRect(xc-radius,yc-radius,xc+radius,yc+radius);\
  5964. clock_ctx.globalAlpha = clock_bg_opacity;\
  5965. this.type = type || 0;\
  5966. this.interaction = interaction || 0;\
  5967. this.H = H;\
  5968. this.M = M;\
  5969. this.S = S;\
  5970. if(this.S == -1){this.S = 59;this.M = this.M - 1;};\
  5971. if(this.M == -1){this.M = 59;this.H = this.H - 1;};\
  5972. if(this.H == -1){this.H = 11;};\
  5973. this.xc = xc || xsize/2;\
  5974. this.yc = yc || ysize/2;\
  5975. this.radius = radius || xsize/4;\
  5976. var font_size = parseInt(0.2*this.radius);\
  5977. this.H_color = h_color || \"blue\";\
  5978. this.M_color = m_color || \"blue\";\
  5979. this.S_color = s_color || \"blue\";\
  5980. this.fg_color = fg_color || \"red\";\
  5981. this.bg_color = bg_color || \"white\";\
  5982. clock_ctx.translate(this.xc,this.yc);\
  5983. clock_ctx.beginPath();\
  5984. clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
  5985. clock_ctx.fillStyle = this.bg_color;\
  5986. clock_ctx.fill();\
  5987. clock_ctx.closePath();\
  5988. clock_ctx.beginPath();\
  5989. clock_ctx.font = font_size+\"px Arial\";\
  5990. clock_ctx.fillStyle = this.fg_color;\
  5991. clock_ctx.textAlign = \"center\";\
  5992. clock_ctx.textBaseline = 'middle';\
  5993. var angle;var x1,y1,x2,y2;\
  5994. var angle_cos;var angle_sin;\
  5995. clock_ctx.globalAlpha = clock_fg_opacity;\
  5996. switch(type){\
  5997. case 0:clock_ctx.beginPath();\
  5998. for(var p = 1; p <= 12 ; p++){\
  5999.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  6000.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  6001.  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  6002.  clock_ctx.moveTo(x1,y1);\
  6003.  clock_ctx.lineTo(x2,y2);\
  6004. };\
  6005. for(var p = 1; p <= 60 ; p++){\
  6006.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  6007.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  6008.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  6009.  clock_ctx.moveTo(x1,y1);\
  6010.  clock_ctx.lineTo(x2,y2);\
  6011. };\
  6012. clock_ctx.closePath();\
  6013. clock_ctx.stroke();\
  6014. break;\
  6015. case 1:\
  6016. 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;\
  6017. case 2:\
  6018. 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);};\
  6019. clock_ctx.beginPath();\
  6020. for(var p = 1; p <= 12 ; p++){\
  6021.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  6022.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  6023.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  6024.  clock_ctx.moveTo(x1,y1);\
  6025.  clock_ctx.lineTo(x2,y2);\
  6026. };\
  6027. for(var p = 1; p <= 60 ; p++){\
  6028.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  6029.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  6030.  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  6031.  clock_ctx.moveTo(x1,y1);\
  6032.  clock_ctx.lineTo(x2,y2);\
  6033. };\
  6034. clock_ctx.closePath();\
  6035. clock_ctx.stroke();\
  6036. break;\
  6037. };\
  6038. angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
  6039. clock_ctx.rotate(angle);\
  6040. clock_ctx.beginPath();\
  6041. clock_ctx.moveTo(-3, -2);\
  6042. clock_ctx.lineTo(-3, 2);\
  6043. clock_ctx.lineTo(this.radius * 0.7, 1);\
  6044. clock_ctx.lineTo(this.radius  * 0.7, -1);\
  6045. clock_ctx.fillStyle = this.H_color;\
  6046. clock_ctx.fill();\
  6047. clock_ctx.rotate(-angle);\
  6048. angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
  6049. clock_ctx.rotate(angle);\
  6050. clock_ctx.beginPath();\
  6051. clock_ctx.moveTo(-3, -2);\
  6052. clock_ctx.lineTo(-3, 2);\
  6053. clock_ctx.lineTo(this.radius  * 0.8, 1);\
  6054. clock_ctx.lineTo(this.radius  * 0.8, -1);\
  6055. clock_ctx.fillStyle = this.M_color;\
  6056. clock_ctx.fill();\
  6057. clock_ctx.rotate(-angle);\
  6058. angle = (this.S - 15) * 2 * Math.PI / 60;\
  6059. clock_ctx.rotate(angle);\
  6060. clock_ctx.beginPath();\
  6061. clock_ctx.moveTo(0,0);\
  6062. clock_ctx.lineTo(this.radius  * 0.95, 0);\
  6063. clock_ctx.lineTo(this.radius  * 0.9, -1);\
  6064. clock_ctx.strokeStyle = this.S_color;\
  6065. clock_ctx.stroke();\
  6066. clock_ctx.restore();\
  6067. };",canvas_root_id,CLOCK_CANVAS);
  6068. break;
  6069.  
  6070. case DRAW_LATTICE:
  6071. fprintf(js_include_file,"\n<!-- draw lattice -->\n\
  6072. 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){\
  6073. var obj;\
  6074. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6075.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6076. }\
  6077. else\
  6078. {\
  6079.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6080. };\
  6081. var ctx = obj.getContext(\"2d\");\
  6082. ctx.save();\
  6083. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6084. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6085. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6086. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6087. var radius = line_width;\
  6088. var x = 0;\
  6089. var y = 0;\
  6090. var x_step_px = xsize/(xmax-xmin);\
  6091. var y_step_px = ysize/(ymax-ymin);\
  6092. var xv1 = dx1*x_step_px;\
  6093. var yv1 = dy1*y_step_px;\
  6094. var xv2 = dx2*x_step_px;\
  6095. var yv2 = dy2*y_step_px;\
  6096. for(var p = 0; p < n1 ;p++){\
  6097.  x = p*xv1 + x0;\
  6098.  y = p*yv1 + y0;\
  6099.  for(var c = 0; c < n2 ; c++){\
  6100.   ctx.beginPath();\
  6101.   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
  6102.   ctx.fill();\
  6103.   ctx.stroke();\
  6104.   ctx.closePath();\
  6105.  };\
  6106. };\
  6107. ctx.restore();\
  6108. return;\
  6109. };",canvas_root_id,canvas_root_id,canvas_root_id);
  6110.     break;
  6111. case DRAW_XYLOGSCALE:
  6112. fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\
  6113. 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){\
  6114. var obj;\
  6115. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6116.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6117. }\
  6118. else\
  6119. {\
  6120.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6121. };\
  6122. var ctx = obj.getContext(\"2d\");\
  6123. ctx.clearRect(0,0,xsize,ysize);\
  6124. ctx.save();\
  6125. var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
  6126. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  6127. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  6128. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  6129. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  6130. if(use_axis_numbering == 1){\
  6131.  ctx.font = font_family;\
  6132.  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
  6133.  ymarge = parseInt(1.5*font_size);\
  6134.  ctx.save();\
  6135.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  6136.  ctx.rect(0,0,xmarge,ysize);\
  6137.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  6138.  ctx.fill();\
  6139.  ctx.restore();\
  6140. }else{xmarge = 0;ymarge = 0;};\
  6141. if( typeof xaxislabel !== 'undefined' ){\
  6142.  ctx.save();\
  6143.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6144.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6145.  corr =  ctx.measureText(xaxislabel).width;\
  6146.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  6147.  ctx.restore();\
  6148. };\
  6149. if( typeof yaxislabel !== 'undefined' ){\
  6150.  ctx.save();\
  6151.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6152.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6153.  corr = ctx.measureText(yaxislabel).width;\
  6154.  ctx.translate(xmarge+font_size,corr+font_size);\
  6155.  ctx.rotate(-0.5*Math.PI);\
  6156.  ctx.fillText(yaxislabel,0,0);\
  6157.  ctx.restore();\
  6158. };\
  6159. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6160. ctx.lineWidth = line_width;\
  6161. for(var p = x_min; p <= x_max ; p++){\
  6162.  num = Math.pow(xlogbase,p);\
  6163.  for(var i = 1 ; i < xlogbase ; i++){\
  6164.   x_e = x2px(i*num);\
  6165.   if( i == 1 ){\
  6166.    ctx.lineWidth = line_width;\
  6167.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6168.    if( use_axis_numbering == 1 && p > x_min){\
  6169.      xtxt = xlogbase+'^'+p.toFixed(0);\
  6170.      corr = 0.5*(ctx.measureText(xtxt).width);\
  6171.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  6172.    };\
  6173.   }else{\
  6174.    ctx.lineWidth = 0.2*line_width;\
  6175.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6176.   };\
  6177.   if( x_e >= xmarge ){\
  6178.    ctx.beginPath();\
  6179.    ctx.moveTo(x_e,0);\
  6180.    ctx.lineTo(x_e,ysize - ymarge);\
  6181.    ctx.stroke();\
  6182.    ctx.closePath();\
  6183.   };\
  6184.  };\
  6185. };\
  6186. for(var p = y_min; p <= y_max ; p++){\
  6187.  num = Math.pow(ylogbase,p);\
  6188.  for(var i = 1 ; i < ylogbase ; i++){\
  6189.   y_e = y2px(i*num);\
  6190.   if( i == 1 ){\
  6191.    ctx.lineWidth = line_width;\
  6192.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6193.    if( use_axis_numbering == 1 && p > y_min){\
  6194.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  6195.    };\
  6196.   }else{\
  6197.    ctx.lineWidth = 0.2*line_width;\
  6198.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6199.   };\
  6200.   ctx.beginPath();\
  6201.   ctx.moveTo(xmarge,y_e);\
  6202.   ctx.lineTo(xsize,y_e);\
  6203.   ctx.stroke();\
  6204.   ctx.closePath();\
  6205.  };\
  6206. };\
  6207. ctx.restore();\
  6208. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  6209.     break;
  6210.  
  6211. case DRAW_XLOGSCALE:
  6212. fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\
  6213. 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){\
  6214. var obj;\
  6215. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6216.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6217. }\
  6218. else\
  6219. {\
  6220.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6221. };\
  6222. var ctx = obj.getContext(\"2d\");\
  6223. ctx.clearRect(0,0,xsize,ysize);\
  6224. ctx.save();\
  6225. ctx.lineWidth = line_width;\
  6226. var prec = Math.log(precision)/Math.log(10);\
  6227. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  6228. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  6229. var y_min = 0;var y_max = ysize;var x_e;var corr;\
  6230. var xtxt;var ytxt;var num;var xmarge;var ymarge;\
  6231. if(use_axis_numbering == 1){\
  6232.  ctx.font = font_family;\
  6233.  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
  6234.  ymarge = parseInt(1.5*font_size);\
  6235.  ctx.save();\
  6236.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  6237.  ctx.rect(0,0,xmarge,ysize);\
  6238.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  6239.  ctx.fill();\
  6240.  ctx.restore();\
  6241. }else{xmarge = 0;ymarge = 0;};\
  6242. if( typeof xaxislabel !== 'undefined' ){\
  6243.  ctx.save();\
  6244.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6245.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6246.  corr =  ctx.measureText(xaxislabel).width;\
  6247.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  6248.  ctx.restore();\
  6249. };\
  6250. if( typeof yaxislabel !== 'undefined' ){\
  6251.  ctx.save();\
  6252.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6253.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6254.  corr = ctx.measureText(yaxislabel).width;\
  6255.  ctx.translate(xmarge+font_size,corr+font_size);\
  6256.  ctx.rotate(-0.5*Math.PI);\
  6257.  ctx.fillText(yaxislabel,0,0);\
  6258.  ctx.restore();\
  6259. };\
  6260. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6261. ctx.lineWidth = line_width;\
  6262. for(var p = x_min; p <= x_max ; p++){\
  6263.  num = Math.pow(xlogbase,p);\
  6264.  for(var i = 1 ; i < xlogbase ; i++){\
  6265.   x_e = x2px(i*num);\
  6266.   if( i == 1 ){\
  6267.     ctx.lineWidth = line_width;\
  6268.     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6269.    if( use_axis_numbering == 1 && p > x_min ){\
  6270.      xtxt = xlogbase+'^'+p.toFixed(0);\
  6271.      corr = 0.5*(ctx.measureText(xtxt).width);\
  6272.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  6273.    };\
  6274.   }else{\
  6275.    ctx.lineWidth = 0.2*line_width;\
  6276.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6277.   };\
  6278.   if( x_e >= xmarge ){\
  6279.    ctx.beginPath();\
  6280.    ctx.moveTo(x_e,0);\
  6281.    ctx.lineTo(x_e,ysize - ymarge);\
  6282.    ctx.stroke();\
  6283.    ctx.closePath();\
  6284.   };\
  6285.  };\
  6286. };\
  6287. var stepy = Math.abs(y2px(ymajor) - y2px(0));\
  6288. var minor_step = stepy / yminor;\
  6289. for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
  6290.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6291.  ctx.lineWidth = line_width;\
  6292.  ctx.beginPath();\
  6293.  ctx.moveTo(xmarge,y);\
  6294.  ctx.lineTo(xsize,y);\
  6295.  ctx.stroke();\
  6296.  ctx.closePath();\
  6297.  if( use_axis_numbering == 1){\
  6298.   ytxt = (px2y(y)).toFixed(prec);\
  6299.   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
  6300.  };\
  6301.  for(var dy = 1 ; dy < yminor ; dy++){\
  6302.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6303.   ctx.lineWidth = 0.2*line_width;\
  6304.   ctx.beginPath();\
  6305.   ctx.moveTo(xmarge,y+dy*minor_step);\
  6306.   ctx.lineTo(xsize,y+dy*minor_step);\
  6307.   ctx.stroke();\
  6308.   ctx.closePath();\
  6309.  };\
  6310. };\
  6311. ctx.restore();\
  6312. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  6313.     break;
  6314. case DRAW_YLOGSCALE:
  6315. fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\
  6316. 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){\
  6317. var obj;\
  6318. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6319.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6320. }\
  6321. else\
  6322. {\
  6323.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6324. };\
  6325. var ctx = obj.getContext(\"2d\");\
  6326. ctx.clearRect(0,0,xsize,ysize);\
  6327. ctx.save();\
  6328. ctx.lineWidth = line_width;\
  6329. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  6330. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  6331. var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
  6332. if(use_axis_numbering == 1){\
  6333.  ctx.font = font_family;\
  6334.  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
  6335.  ymarge = 2*font_size;\
  6336.  ctx.save();\
  6337.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  6338.  ctx.rect(0,0,xmarge,ysize);\
  6339.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  6340.  ctx.fill();\
  6341.  ctx.restore();\
  6342. }else{xmarge = 0;ymarge = 0;};\
  6343. if( typeof xaxislabel !== 'undefined' ){\
  6344.  ctx.save();\
  6345.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6346.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6347.  corr =  ctx.measureText(xaxislabel).width;\
  6348.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  6349.  ctx.restore();\
  6350. };\
  6351. if( typeof yaxislabel !== 'undefined' ){\
  6352.  ctx.save();\
  6353.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6354.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6355.  corr = ctx.measureText(yaxislabel).width;\
  6356.  ctx.translate(xmarge+font_size,corr+font_size);\
  6357.  ctx.rotate(-0.5*Math.PI);\
  6358.  ctx.fillText(yaxislabel,0,0);\
  6359.  ctx.restore();\
  6360. };\
  6361. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6362. ctx.lineWidth = line_width;\
  6363. for(var p = y_min; p <= y_max ; p++){\
  6364.  num = Math.pow(ylogbase,p);\
  6365.  for(var i = 1 ; i < ylogbase ; i++){\
  6366.   y_e = y2px(i*num);\
  6367.   if( i == 1 ){\
  6368.    ctx.lineWidth = line_width;\
  6369.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6370.    if( use_axis_numbering == 1 && p > y_min){\
  6371.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  6372.    };\
  6373.   }else{\
  6374.    ctx.lineWidth = 0.2*line_width;\
  6375.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6376.   };\
  6377.   ctx.beginPath();\
  6378.   ctx.moveTo(xmarge,y_e);\
  6379.   ctx.lineTo(xsize,y_e);\
  6380.   ctx.stroke();\
  6381.   ctx.closePath();\
  6382.  };\
  6383. };\
  6384. var stepx = Math.abs(x2px(xmajor) - x2px(0));\
  6385. var minor_step = stepx / xminor;\
  6386. var prec = Math.log(precision)/Math.log(10);\
  6387. var xtxt;var corr;var flip = 0;\
  6388. for(var x = stepx ; x < xsize ; x = x + stepx){\
  6389.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6390.  ctx.lineWidth = line_width;\
  6391.  ctx.beginPath();\
  6392.  ctx.moveTo(x,ysize-ymarge);\
  6393.  ctx.lineTo(x,0);\
  6394.  ctx.stroke();\
  6395.  ctx.closePath();\
  6396.  if( use_axis_numbering == 1){\
  6397.   xtxt = (px2x(x)).toFixed(prec);\
  6398.   corr = 0.5*(ctx.measureText(xtxt).width);\
  6399.   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
  6400.   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
  6401.  };\
  6402.  for(var dx = 1 ; dx < xminor ; dx++){\
  6403.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6404.   ctx.lineWidth = 0.2*line_width;\
  6405.   ctx.beginPath();\
  6406.   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
  6407.   ctx.lineTo(x+dx*minor_step,0);\
  6408.   ctx.stroke();\
  6409.   ctx.closePath();\
  6410.  };\
  6411. };\
  6412. ctx.restore();\
  6413. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  6414.     break;
  6415.     default:break;
  6416.    }
  6417.   }
  6418.  }
  6419.   return;
  6420. }
  6421.  
  6422. void check_string_length(int L){
  6423.  if(L<1 || L > MAX_BUFFER-1){
  6424.   canvas_error("problem with your arguments to command...");
  6425.  }
  6426.  return;
  6427. }
  6428.  
  6429.  
  6430. int get_token(FILE *infile){
  6431.         int     c,i=0;
  6432.         char    temp[MAX_INT], *input_type;
  6433.         char    *line="line",
  6434.         *audio="audio",
  6435.         *blink="blink",
  6436.         *arrowhead="arrowhead",
  6437.         *crosshairsize="crosshairsize",
  6438.         *crosshair="crosshair",
  6439.         *crosshairs="crosshairs",
  6440.         *audioobject="audioobject",
  6441.         *style="style",
  6442.         *mouse="mouse",
  6443.         *mousex="mousex",
  6444.         *mousey="mousey",
  6445.         *mouse_display="display",
  6446.         *mouse_degree="mouse_degree",
  6447.         *userdraw="userdraw",
  6448.         *highlight="highlight",
  6449.         *http="http",
  6450.         *rays="rays",
  6451.         *dashtype="dashtype",
  6452.         *dashed="dashed",
  6453.         *filled="filled",
  6454.         *lattice="lattice",
  6455.         *parallel="parallel",
  6456.         *segment="segment",
  6457.         *dsegment="dsegment",
  6458.         *seg="seg",
  6459.         *bgimage="bgimage",
  6460.         *bgcolor="bgcolor",
  6461.         *strokecolor="strokecolor",
  6462.         *backgroundimage="backgroundimage",
  6463.         *text="text",
  6464.         *textup="textup",
  6465.         *mouseprecision="mouseprecision",
  6466.         *precision="precision",
  6467.         *plotsteps="plotsteps",
  6468.         *plotstep="plotstep",
  6469.         *tsteps="tsteps",
  6470.         *curve="curve",
  6471.         *dcurve="dcurve",
  6472.         *plot="plot",
  6473.         *dplot="dplot",
  6474.         *levelcurve="levelcurve",
  6475.         *fontsize="fontsize",
  6476.         *fontcolor="fontcolor",
  6477.         *axis="axis",
  6478.         *axisnumbering="axisnumbering",
  6479.         *axisnumbers="axisnumbers",
  6480.         *arrow="arrow",
  6481.         *darrow="darrow",
  6482.         *arrow2="arrow2",
  6483.         *darrow2="darrow2",
  6484.         *zoom="zoom",
  6485.         *grid="grid",
  6486.         *hline="hline",
  6487.         *dhline="dhline",
  6488.         *drag="drag",
  6489.         *horizontalline="horizontalline",
  6490.         *vline="vline",
  6491.         *dvline="dvline",
  6492.         *verticalline="verticalline",
  6493.         *triangle="triangle",
  6494.         *ftriangle="ftriangle",
  6495.         *mathml="mathml",
  6496.         *html="html",
  6497.         *input="input",
  6498.         *button="button",
  6499.         *inputstyle="inputstyle",
  6500.         *textarea="textarea",
  6501.         *trange="trange",
  6502.         *ranget="ranget",
  6503.         *xrange="xrange",
  6504.         *yrange="yrange",
  6505.         *rangex="rangex",
  6506.         *rangey="rangey",
  6507.         *polyline="polyline",
  6508.         *lines="lines",
  6509.         *poly="poly",
  6510.         *polygon="polygon",
  6511.         *fpolygon="fpolygon",
  6512.         *fpoly="fpoly",
  6513.         *filledpoly="filledpoly",
  6514.         *filledpolygon="filledpolygon",
  6515.         *rect="rect",
  6516.         *frect="frect",
  6517.         *rectangle="rectangle",
  6518.         *frectangle="frectangle",
  6519.         *square="square",
  6520.         *fsquare="fsquare",
  6521.         *dline="dline",
  6522.         *arc="arc",
  6523.         *filledarc="filledarc",
  6524.         *size="size",
  6525.         *string="string",
  6526.         *stringup="stringup",
  6527.         *copy="copy",
  6528.         *copyresized="copyresized",
  6529.         *opacity="opacity",
  6530.         *transparent="transparent",
  6531.         *fill="fill",
  6532.         *point="point",
  6533.         *points="points",
  6534.         *linewidth="linewidth",
  6535.         *circle="circle",
  6536.         *fcircle="fcircle",
  6537.         *disk="disk",
  6538.         *comment="#",
  6539.         *end="end",
  6540.         *ellipse="ellipse",
  6541.         *fellipse="fellipse",
  6542.         *rotate="rotate",
  6543.         *affine="affine",
  6544.         *killaffine="killaffine",
  6545.         *fontfamily="fontfamily",
  6546.         *fillcolor="fillcolor",
  6547.         *clicktile="clicktile",
  6548.         *clicktile_colors="clicktile_colors",
  6549.         *translation="translation",
  6550.         *translate="translate",
  6551.         *killtranslation="killtranslation",
  6552.         *killtranslate="killtranslate",
  6553.         *onclick="onclick",
  6554.         *roundrect="roundrect",
  6555.         *froundrect="froundrect",
  6556.         *roundrectangle="roundrectangle",
  6557.         *patternfill="patternfill",
  6558.         *hatchfill="hatchfill",
  6559.         *diafill="diafill",
  6560.         *diamondfill="diamondfill",
  6561.         *dotfill="dotfill",
  6562.         *gridfill="gridfill",
  6563.         *imagefill="imagefill",
  6564.         *xlogbase="xlogbase",
  6565.         *ylogbase="ylogbase",
  6566.         *xlogscale="xlogscale",
  6567.         *ylogscale="ylogscale",
  6568.         *xylogscale="xylogscale",
  6569.         *intooltip="intooltip",
  6570.         *replyformat="replyformat",
  6571.         *floodfill="floodfill",
  6572.         *filltoborder="filltoborder",
  6573.         *clickfill="clickfill",
  6574.         *setpixel="setpixel",
  6575.         *pixels="pixels",
  6576.         *pixelsize="pixelsize",
  6577.         *clickfillmarge="clickfillmarge",
  6578.         *xaxis="xaxis",
  6579.         *yaxis="yaxis",
  6580.         *xaxistext="xaxistext",
  6581.         *yaxistext="yaxistext",
  6582.         *piechart="piechart",
  6583.         *legend="legend",
  6584.         *legendcolors="legendcolors",
  6585.         *xlabel="xlabel",
  6586.         *ylabel="ylabel",
  6587.         *barchart="barchart",
  6588.         *linegraph="linegraph",
  6589.         *clock="clock",
  6590.         *animate="animate",
  6591.         *video="video",
  6592.         *status="status",
  6593.         *nostatus="nostatus",
  6594.         *snaptogrid="snaptogrid",
  6595.         *xsnaptogrid="xsnaptogrid",
  6596.         *ysnaptogrid="ysnaptogrid",
  6597.         *userinput_xy="userinput_xy",
  6598.         *usertextarea_xy="usertextarea_xy",
  6599.         *jsmath="jsmath",
  6600.         *trace_jscurve="trace_jscurve",
  6601.         *setlimits="setlimits",
  6602.         *jscurve="jscurve",
  6603.         *jsplot="jsplot",
  6604.         *sgraph="sgraph",
  6605.         *title="title",
  6606.         *centerstring="centerstring",
  6607.         *xunit="xunit",
  6608.         *yunit="yunit",
  6609.         *slider="slider",
  6610.         *killslider="killslider",
  6611.         *angle="angle";
  6612.  
  6613.         while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')){
  6614.             if( i == 0 && (c == ' ' || c == '\t') ){
  6615.         continue; /* white spaces or tabs allowed before first command identifier */
  6616.             }
  6617.             else
  6618.             {
  6619.         if( c == ' ' || c == '\t' ){
  6620.             break;
  6621.         }
  6622.         else
  6623.         {
  6624.             temp[i] = c;
  6625.             if(i > MAX_INT - 2){canvas_error("command string too long !");}
  6626.             i++;
  6627.         }
  6628.             }
  6629.             if(temp[0] == '#') break;
  6630.         }
  6631.         if (c == EOF) finished = 1;
  6632.  
  6633.         if (c == '\n' || c == '\r') {
  6634.         line_number++;
  6635.         if (i == 0) { return EMPTY; }
  6636.         } else if (c == EOF) {
  6637.         return 0;
  6638.         }
  6639.  
  6640.         temp[i]='\0';
  6641.         input_type=(char*)my_newmem(strlen(temp));
  6642.         snprintf(input_type,sizeof(temp),"%s",temp);
  6643.  
  6644.         if( strcmp(input_type, size) == 0 ){
  6645.         free(input_type);
  6646.         return SIZE;
  6647.         }
  6648.         if( strcmp(input_type, xrange) == 0 ){
  6649.         free(input_type);
  6650.         return XRANGE;
  6651.         }
  6652.         if( strcmp(input_type, rangex) == 0 ){
  6653.         free(input_type);
  6654.         return XRANGE;
  6655.         }
  6656.         if( strcmp(input_type, trange) == 0 ){
  6657.         free(input_type);
  6658.         return TRANGE;
  6659.         }
  6660.         if( strcmp(input_type, ranget) == 0 ){
  6661.         free(input_type);
  6662.         return TRANGE;
  6663.         }
  6664.         if( strcmp(input_type, yrange) == 0 ){
  6665.         free(input_type);
  6666.         return YRANGE;
  6667.         }
  6668.         if( strcmp(input_type, rangey) == 0 ){
  6669.         free(input_type);
  6670.         return YRANGE;
  6671.         }
  6672.         if( strcmp(input_type, linewidth) == 0 ){
  6673.         free(input_type);
  6674.         return LINEWIDTH;
  6675.         }
  6676.         if( strcmp(input_type, dashed) == 0 ){
  6677.         free(input_type);
  6678.         return DASHED;
  6679.         }
  6680.         if( strcmp(input_type, dashtype) == 0 ){
  6681.         free(input_type);
  6682.         return DASHTYPE;
  6683.         }
  6684.         if( strcmp(input_type, axisnumbering) == 0 ){
  6685.         free(input_type);
  6686.         return AXIS_NUMBERING;
  6687.         }
  6688.         if( strcmp(input_type, axisnumbers) == 0 ){
  6689.         free(input_type);
  6690.         return AXIS_NUMBERING;
  6691.         }
  6692.         if( strcmp(input_type, axis) == 0 ){
  6693.         free(input_type);
  6694.         return AXIS;
  6695.         }
  6696.         if( strcmp(input_type, grid) == 0 ){
  6697.         free(input_type);
  6698.         return GRID;
  6699.         }
  6700.         if( strcmp(input_type, parallel) == 0 ){
  6701.         free(input_type);
  6702.         return PARALLEL;
  6703.         }
  6704.         if( strcmp(input_type, hline) == 0 ||  strcmp(input_type, horizontalline) == 0 ){
  6705.         free(input_type);
  6706.         return HLINE;
  6707.         }
  6708.         if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
  6709.         free(input_type);
  6710.         return VLINE;
  6711.         }
  6712.         if( strcmp(input_type, line) == 0 ){
  6713.         free(input_type);
  6714.         return LINE;
  6715.         }
  6716.         if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
  6717.         free(input_type);
  6718.         return SEGMENT;
  6719.         }
  6720.         if( strcmp(input_type, dsegment) == 0 ){
  6721.         free(input_type);
  6722.         use_dashed = TRUE;
  6723.         return SEGMENT;
  6724.         }
  6725.         if( strcmp(input_type, crosshairsize) == 0 ){
  6726.         free(input_type);
  6727.         return CROSSHAIRSIZE;
  6728.         }
  6729.         if( strcmp(input_type, arrowhead) == 0 ){
  6730.         free(input_type);
  6731.         return ARROWHEAD;
  6732.         }
  6733.         if( strcmp(input_type, crosshairs) == 0 ){
  6734.         free(input_type);
  6735.         return CROSSHAIRS;
  6736.         }
  6737.         if( strcmp(input_type, crosshair) == 0 ){
  6738.         free(input_type);
  6739.         return CROSSHAIR;
  6740.         }
  6741.         if( strcmp(input_type, onclick) == 0 ){
  6742.         free(input_type);
  6743.         return ONCLICK;
  6744.         }
  6745.         if( strcmp(input_type, drag) == 0 ){
  6746.         free(input_type);
  6747.         return DRAG;
  6748.         }
  6749.         if( strcmp(input_type, userdraw) == 0 ){
  6750.         free(input_type);
  6751.         return USERDRAW;
  6752.         }
  6753.         if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
  6754.         free(input_type);
  6755.         return STYLE;
  6756.         }
  6757.         if( strcmp(input_type, fillcolor) == 0 ){
  6758.         free(input_type);
  6759.         return FILLCOLOR;
  6760.         }
  6761.         if( strcmp(input_type, strokecolor) == 0 ){
  6762.         free(input_type);
  6763.         return STROKECOLOR;
  6764.         }
  6765.         if( strcmp(input_type, filled) == 0  ){
  6766.         free(input_type);
  6767.         return FILLED;
  6768.         }
  6769.         if( strcmp(input_type, http) == 0 ){
  6770.         free(input_type);
  6771.         return HTTP;
  6772.         }
  6773.         if( strcmp(input_type, rays) == 0 ){
  6774.         free(input_type);
  6775.         return RAYS;
  6776.         }
  6777.         if( strcmp(input_type, lattice) == 0 ){
  6778.         free(input_type);
  6779.         return LATTICE;
  6780.         }
  6781.         if( strcmp(input_type, bgimage) == 0 ){
  6782.         free(input_type);
  6783.         return BGIMAGE;
  6784.         }
  6785.         if( strcmp(input_type, bgcolor) == 0 ){
  6786.         free(input_type);
  6787.         return BGCOLOR;
  6788.         }
  6789.         if( strcmp(input_type, backgroundimage) == 0 ){
  6790.         free(input_type);
  6791.         return BGIMAGE;
  6792.         }
  6793.         if( strcmp(input_type, text) == 0 ){
  6794.         free(input_type);
  6795.         return FLY_TEXT;
  6796.         }
  6797.         if( strcmp(input_type, textup) == 0 ){
  6798.         free(input_type);
  6799.         return FLY_TEXTUP;
  6800.         }
  6801.         if( strcmp(input_type, mouse) == 0 ){
  6802.         free(input_type);
  6803.         return MOUSE;
  6804.         }
  6805.         if( strcmp(input_type, mousex) == 0 ){
  6806.         free(input_type);
  6807.         return MOUSEX;
  6808.         }
  6809.         if( strcmp(input_type, mousey) == 0 ){
  6810.         free(input_type);
  6811.         return MOUSEY;
  6812.         }
  6813.         if( strcmp(input_type, mouse_degree) == 0 ){
  6814.         free(input_type);
  6815.         return MOUSE_DEGREE;
  6816.         }
  6817.         if( strcmp(input_type, mouse_display) == 0 ){
  6818.         free(input_type);
  6819.         return MOUSE_DISPLAY;
  6820.         }
  6821.         if( strcmp(input_type, mouseprecision) == 0 ){
  6822.         free(input_type);
  6823.         return MOUSE_PRECISION;
  6824.         }
  6825.         if( strcmp(input_type, precision) == 0 ){
  6826.         free(input_type);
  6827.         return MOUSE_PRECISION;
  6828.         }
  6829.         if( strcmp(input_type, curve) == 0 ){
  6830.         free(input_type);
  6831.         return CURVE;
  6832.         }
  6833.         if( strcmp(input_type, dcurve) == 0 ){
  6834.         use_dashed = TRUE;
  6835.         free(input_type);
  6836.         return CURVE;
  6837.         }
  6838.         if( strcmp(input_type, plot) == 0 ){
  6839.         free(input_type);
  6840.         return CURVE;
  6841.         }
  6842.         if( strcmp(input_type, dplot) == 0 ){
  6843.         use_dashed = TRUE;
  6844.         free(input_type);
  6845.         return CURVE;
  6846.         }
  6847.         if( strcmp(input_type, levelcurve) == 0 ){
  6848.         free(input_type);
  6849.         return LEVELCURVE;
  6850.         }
  6851.         if( strcmp(input_type, plotsteps) == 0 ){
  6852.         free(input_type);
  6853.         return PLOTSTEPS;
  6854.         }
  6855.         if( strcmp(input_type, plotstep) == 0 ){
  6856.         free(input_type);
  6857.         return PLOTSTEPS;
  6858.         }
  6859.         if( strcmp(input_type, tsteps) == 0 ){
  6860.         free(input_type);
  6861.         return PLOTSTEPS;
  6862.         }
  6863.         if( strcmp(input_type, fontsize) == 0 ){
  6864.         free(input_type);
  6865.         return FONTSIZE;
  6866.         }
  6867.         if( strcmp(input_type, fontcolor) == 0 ){
  6868.         free(input_type);
  6869.         return FONTCOLOR;
  6870.         }
  6871.         if( strcmp(input_type, arrow) == 0 ){
  6872.         free(input_type);
  6873.         return ARROW;
  6874.         }
  6875.         if( strcmp(input_type, arrow2) == 0 ){
  6876.         free(input_type);
  6877.         return ARROW2;
  6878.         }
  6879.         if( strcmp(input_type, darrow) == 0 ){
  6880.         free(input_type);
  6881.         use_dashed = TRUE;
  6882.         return ARROW;
  6883.         }
  6884.         if( strcmp(input_type, darrow2) == 0 ){
  6885.         free(input_type);
  6886.         use_dashed = TRUE;
  6887.         return ARROW2;
  6888.         }
  6889.         if( strcmp(input_type, zoom) == 0 ){
  6890.         free(input_type);
  6891.         return ZOOM;
  6892.         }
  6893.         if( strcmp(input_type, triangle) == 0 ){
  6894.         free(input_type);
  6895.         return TRIANGLE;
  6896.         }
  6897.         if( strcmp(input_type, ftriangle) == 0 ){
  6898.         free(input_type);
  6899.         use_filled = TRUE;
  6900.         return TRIANGLE;
  6901.         }
  6902.         if( strcmp(input_type, input) == 0 ){
  6903.         free(input_type);
  6904.         return INPUT;
  6905.         }
  6906.         if( strcmp(input_type, inputstyle) == 0 ){
  6907.         free(input_type);
  6908.         return INPUTSTYLE;
  6909.         }
  6910.         if( strcmp(input_type, textarea) == 0 ){
  6911.         free(input_type);
  6912.         return TEXTAREA;
  6913.         }
  6914.         if( strcmp(input_type, mathml) == 0 ){
  6915.         free(input_type);
  6916.         return MATHML;
  6917.         }
  6918.         if( strcmp(input_type, html) == 0 ){
  6919.         free(input_type);
  6920.         return MATHML;
  6921.         }
  6922.         if( strcmp(input_type, fontfamily) == 0 ){
  6923.         free(input_type);
  6924.         return FONTFAMILY;
  6925.         }
  6926.         if( strcmp(input_type, lines) == 0  ||  strcmp(input_type, polyline) == 0 ){
  6927.         free(input_type);
  6928.         return POLYLINE;
  6929.         }
  6930.         if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
  6931.         free(input_type);
  6932.         return RECT;
  6933.         }
  6934.         if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
  6935.         free(input_type);
  6936.         return ROUNDRECT;
  6937.         }
  6938.         if( strcmp(input_type, froundrect) == 0 ){
  6939.         free(input_type);
  6940.         use_filled = TRUE;
  6941.         return ROUNDRECT;
  6942.         }
  6943.         if( strcmp(input_type, square) == 0 ){
  6944.         free(input_type);
  6945.         return SQUARE;
  6946.         }
  6947.         if( strcmp(input_type, fsquare) == 0 ){
  6948.         free(input_type);
  6949.         use_filled = TRUE;
  6950.         return SQUARE;
  6951.         }
  6952.         if( strcmp(input_type, dline) == 0 ){
  6953.         use_dashed = TRUE;
  6954.         free(input_type);
  6955.         return LINE;
  6956.         }
  6957.         if( strcmp(input_type, dvline) == 0 ){
  6958.         use_dashed = TRUE;
  6959.         free(input_type);
  6960.         return VLINE;
  6961.         }
  6962.         if( strcmp(input_type, dhline) == 0 ){
  6963.         use_dashed = TRUE;
  6964.         free(input_type);
  6965.         return HLINE;
  6966.         }
  6967.         if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
  6968.         use_filled = TRUE;
  6969.         free(input_type);
  6970.         return RECT;
  6971.         }
  6972.         if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
  6973.         use_filled = TRUE;
  6974.         free(input_type);
  6975.         return CIRCLE;
  6976.         }
  6977.         if( strcmp(input_type, circle) == 0 ){
  6978.         free(input_type);
  6979.         return CIRCLE;
  6980.         }
  6981.         if( strcmp(input_type, point) == 0 ){
  6982.         free(input_type);
  6983.         return POINT;
  6984.         }
  6985.         if( strcmp(input_type, points) == 0 ){
  6986.         free(input_type);
  6987.         return POINTS;
  6988.         }
  6989.         if( strcmp(input_type, filledarc) == 0 ){
  6990.         use_filled = TRUE;
  6991.         free(input_type);
  6992.         return ARC;
  6993.         }
  6994.         if( strcmp(input_type, arc) == 0 ){
  6995.         free(input_type);
  6996.         return ARC;
  6997.         }
  6998.         if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
  6999.         free(input_type);
  7000.         return POLY;
  7001.         }
  7002.         if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
  7003.         use_filled = TRUE;
  7004.         free(input_type);
  7005.         return POLY;
  7006.         }
  7007.         if( strcmp(input_type, ellipse) == 0){
  7008.         free(input_type);
  7009.         return ELLIPSE;
  7010.         }
  7011.         if( strcmp(input_type, fill) == 0 ){
  7012.         free(input_type);
  7013.         return FLOODFILL;
  7014.         }
  7015.         if( strcmp(input_type, string) == 0 ){
  7016.         free(input_type);
  7017.         return STRING;
  7018.         }
  7019.         if( strcmp(input_type, stringup) == 0 ){
  7020.         free(input_type);
  7021.         return STRINGUP;
  7022.         }
  7023.         if( strcmp(input_type, opacity) == 0 ){
  7024.         free(input_type);
  7025.         return OPACITY;
  7026.         }
  7027.         if( strcmp(input_type, comment) == 0){
  7028.         free(input_type);
  7029.         return COMMENT;
  7030.         }
  7031.         if( strcmp(input_type, end) == 0){
  7032.         free(input_type);
  7033.         return END;
  7034.         }
  7035.         if( strcmp(input_type, fellipse) == 0){
  7036.         free(input_type);
  7037.         use_filled = TRUE;
  7038.         return ELLIPSE;
  7039.         }      
  7040.         if( strcmp(input_type, blink) == 0 ){
  7041.         free(input_type);
  7042.         return BLINK;
  7043.         }
  7044.         if( strcmp(input_type, button) == 0){
  7045.         free(input_type);
  7046.         return BUTTON;
  7047.         }
  7048.         if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
  7049.         free(input_type);
  7050.         return TRANSLATION;
  7051.         }
  7052.         if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
  7053.         free(input_type);
  7054.         return KILLTRANSLATION;
  7055.         }
  7056.         if( strcmp(input_type, rotate) == 0){
  7057.         free(input_type);
  7058.         return ROTATE;
  7059.         }
  7060.         if( strcmp(input_type, affine) == 0){
  7061.         free(input_type);
  7062.         return AFFINE;
  7063.         }
  7064.         if( strcmp(input_type, killaffine) == 0){
  7065.         free(input_type);
  7066.         return KILLAFFINE;
  7067.         }
  7068.         if( strcmp(input_type, audio) == 0 ){
  7069.         free(input_type);
  7070.         return AUDIO;
  7071.         }
  7072.         if( strcmp(input_type, audioobject) == 0 ){
  7073.         free(input_type);
  7074.         return AUDIOOBJECT;
  7075.         }
  7076.         if( strcmp(input_type, slider) == 0 ){
  7077.         free(input_type);
  7078.         return SLIDER;
  7079.         }
  7080.         if( strcmp(input_type, killslider) == 0 ){
  7081.         free(input_type);
  7082.         return KILLSLIDER;
  7083.         }
  7084.         if( strcmp(input_type, copy) == 0 ){
  7085.         free(input_type);
  7086.         return COPY;
  7087.         }
  7088.         if( strcmp(input_type, copyresized) == 0 ){
  7089.         free(input_type);
  7090.         return COPYRESIZED;
  7091.         }
  7092.         if( strcmp(input_type, patternfill) == 0 ){
  7093.         free(input_type);
  7094.         return PATTERNFILL;
  7095.         }
  7096.         if( strcmp(input_type, hatchfill) == 0 ){
  7097.         free(input_type);
  7098.         return HATCHFILL;
  7099.         }
  7100.         if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
  7101.         free(input_type);
  7102.         return DIAMONDFILL;
  7103.         }
  7104.         if( strcmp(input_type, dotfill) == 0 ){
  7105.         free(input_type);
  7106.         return DOTFILL;
  7107.         }
  7108.         if( strcmp(input_type, gridfill) == 0 ){
  7109.         free(input_type);
  7110.         return GRIDFILL;
  7111.         }
  7112.         if( strcmp(input_type, imagefill) == 0 ){
  7113.         free(input_type);
  7114.         return IMAGEFILL;
  7115.         }
  7116.         if( strcmp(input_type, clicktile_colors) == 0 ){
  7117.         free(input_type);
  7118.         return CLICKTILE_COLORS;
  7119.         }
  7120.         if( strcmp(input_type, clicktile) == 0 ){
  7121.         free(input_type);
  7122.         return CLICKTILE;
  7123.         }
  7124.         if( strcmp(input_type, xlogscale) == 0 ){
  7125.         free(input_type);
  7126.         return XLOGSCALE;
  7127.         }
  7128.         if( strcmp(input_type, ylogscale) == 0 ){
  7129.         free(input_type);
  7130.         return YLOGSCALE;
  7131.         }
  7132.         if( strcmp(input_type, xylogscale) == 0 ){
  7133.         free(input_type);
  7134.         return XYLOGSCALE;
  7135.         }
  7136.         if( strcmp(input_type, ylogscale) == 0 ){
  7137.         free(input_type);
  7138.         return YLOGSCALE;
  7139.         }
  7140.         if( strcmp(input_type, xlogbase) == 0 ){
  7141.         free(input_type);
  7142.         return XLOGBASE;
  7143.         }
  7144.         if( strcmp(input_type, ylogbase) == 0 ){
  7145.         free(input_type);
  7146.         return YLOGBASE;
  7147.         }
  7148.         if( strcmp(input_type, intooltip) == 0 ){
  7149.         free(input_type);
  7150.         return INTOOLTIP;
  7151.         }
  7152.         if( strcmp(input_type,video) == 0 ){
  7153.         free(input_type);
  7154.         return VIDEO;
  7155.         }
  7156.         if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
  7157.         free(input_type);
  7158.         return FLOODFILL;
  7159.         }      
  7160.         if( strcmp(input_type,filltoborder) == 0 ){
  7161.         free(input_type);
  7162.         return FILLTOBORDER;
  7163.         }      
  7164.         if( strcmp(input_type,clickfill) == 0 ){
  7165.         free(input_type);
  7166.         return CLICKFILL;
  7167.         }      
  7168.         if( strcmp(input_type, replyformat) == 0 ){
  7169.         free(input_type);
  7170.         return REPLYFORMAT;
  7171.         }
  7172.         if( strcmp(input_type, pixelsize) == 0 ){
  7173.         free(input_type);
  7174.         return PIXELSIZE;
  7175.         }
  7176.         if( strcmp(input_type, setpixel) == 0 ){
  7177.         free(input_type);
  7178.         return SETPIXEL;
  7179.         }
  7180.         if( strcmp(input_type, pixels) == 0 ){
  7181.         free(input_type);
  7182.         return PIXELS;
  7183.         }
  7184.         if( strcmp(input_type, clickfillmarge) == 0 ){
  7185.         free(input_type);
  7186.         return CLICKFILLMARGE;
  7187.         }
  7188.         if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
  7189.         free(input_type);
  7190.         return X_AXIS_STRINGS;
  7191.         }
  7192.         if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
  7193.         free(input_type);
  7194.         return Y_AXIS_STRINGS;
  7195.         }
  7196.         if( strcmp(input_type, piechart) == 0  ){
  7197.         free(input_type);
  7198.         return PIECHART;
  7199.         }
  7200.         if( strcmp(input_type, barchart) == 0  ){
  7201.         free(input_type);
  7202.         return BARCHART;
  7203.         }
  7204.         if( strcmp(input_type, linegraph) == 0  ){
  7205.         free(input_type);
  7206.         return LINEGRAPH;
  7207.         }
  7208.         if( strcmp(input_type, clock) == 0  ){
  7209.         free(input_type);
  7210.         return CLOCK;
  7211.         }
  7212.         if( strcmp(input_type, legend) == 0  ){
  7213.         free(input_type);
  7214.         return LEGEND;
  7215.         }
  7216.         if( strcmp(input_type, legendcolors) == 0  ){
  7217.         free(input_type);
  7218.         return LEGENDCOLORS;
  7219.         }
  7220.         if( strcmp(input_type, xlabel) == 0  ){
  7221.         free(input_type);
  7222.         return XLABEL;
  7223.         }
  7224.         if( strcmp(input_type, ylabel) == 0  ){
  7225.         free(input_type);
  7226.         return YLABEL;
  7227.         }
  7228.         if( strcmp(input_type, animate) == 0  ){
  7229.         free(input_type);
  7230.         return ANIMATE;
  7231.         }
  7232.         /* these are bitmap related flydraw commmands...must be removed. eventually */
  7233.         if( strcmp(input_type, transparent) == 0 ){
  7234.         free(input_type);
  7235.         return TRANSPARENT;
  7236.         }
  7237.         if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
  7238.         free(input_type);
  7239.         return STATUS;
  7240.         }
  7241.         if( strcmp(input_type, snaptogrid) == 0 ){
  7242.         free(input_type);
  7243.         return SNAPTOGRID;
  7244.         }
  7245.         if( strcmp(input_type, xsnaptogrid) == 0 ){
  7246.         free(input_type);
  7247.         return XSNAPTOGRID;
  7248.         }
  7249.         if( strcmp(input_type, ysnaptogrid) == 0 ){
  7250.         free(input_type);
  7251.         return YSNAPTOGRID;
  7252.         }
  7253.         if( strcmp(input_type, userinput_xy) == 0 ){
  7254.         free(input_type);
  7255.         return USERINPUT_XY;
  7256.         }
  7257.         if( strcmp(input_type, usertextarea_xy) == 0 ){
  7258.         free(input_type);
  7259.         return USERTEXTAREA_XY;
  7260.         }
  7261.         if( strcmp(input_type, sgraph) == 0 ){
  7262.         free(input_type);
  7263.         return SGRAPH;
  7264.         }
  7265.         if( strcmp(input_type, jsmath) == 0 ){
  7266.         free(input_type);
  7267.         return JSMATH;
  7268.         }
  7269.         if( strcmp(input_type, trace_jscurve) == 0 ){
  7270.         free(input_type);
  7271.         return TRACE_JSCURVE;
  7272.         }
  7273.         if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
  7274.         free(input_type);
  7275.         return JSCURVE;
  7276.         }
  7277.         if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
  7278.         free(input_type);
  7279.         return CENTERSTRING;
  7280.         }
  7281.         if( strcmp(input_type, setlimits) == 0 ){
  7282.         free(input_type);
  7283.         return SETLIMITS;
  7284.         }
  7285.         if( strcmp(input_type, xunit) == 0 ){
  7286.         free(input_type);
  7287.         return XUNIT;
  7288.         }
  7289.         if( strcmp(input_type, yunit) == 0 ){
  7290.         free(input_type);
  7291.         return YUNIT;
  7292.         }
  7293.         if( strcmp(input_type, angle) == 0 ){
  7294.         free(input_type);
  7295.         return ANGLE;
  7296.         }
  7297.         free(input_type);
  7298.         ungetc(c,infile);
  7299.         return 0;
  7300. }
  7301.  
  7302.