Subversion Repositories wimsdev

Rev

Rev 8127 | Rev 8130 | 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 = 27;}
  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 = 27;}
  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|radius,color,fontsize
  2402.          @will display the mouse cursor coordinates as x-only,y-only,(x:y),<br />the radius of a circle (this only in case 'userdraw circle(s),color' !!<br />or the angle in degrees ( rhe angle between x-axis;(0:0);(x:y)
  2403.          @use commands 'xunit' and / or 'yunit' to add the units to the mouse values
  2404.          @just like commands 'mouse','mousex','mousey','mouse_degree'...only other name)
  2405.         */
  2406.         temp = get_string_argument(infile,0);
  2407.         if( strstr(temp,"xy") != NULL ){
  2408.             int_data[0] = 2;
  2409.         }else{
  2410.             if( strstr(temp,"y") != NULL ){
  2411.                 int_data[0] = 1;
  2412.             }else{
  2413.                 if( strstr(temp,"x") != NULL ){
  2414.                     int_data[0] = 0;
  2415.                 }else{
  2416.                     if(strstr(temp,"degree") != NULL){
  2417.                         int_data[0] = 3;
  2418.                     }else{
  2419.                         if(strstr(temp,"radius") != NULL){
  2420.                             int_data[0] = 4;
  2421.                         }else{
  2422.                             int_data[0] = 2;
  2423.                         }
  2424.                     }
  2425.                 }
  2426.             }
  2427.         }
  2428.         stroke_color = get_color(infile,0);
  2429.         font_size = (int) (get_real(infile,1));
  2430.         tmp_buffer = my_newmem(26);
  2431.         snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2432.         add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
  2433.         break;
  2434.         case MOUSE_DEGREE:
  2435.         /*
  2436.          @ mouse_degree color,fontsize
  2437.          @ 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
  2438.          @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
  2439.          @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2440.  
  2441.         */
  2442.             stroke_color = get_color(infile,0);
  2443.             font_size = (int) (get_real(infile,1));
  2444.             tmp_buffer = my_newmem(26);
  2445.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2446.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
  2447.             break;
  2448.         case MOUSEX:
  2449.         /*
  2450.          @ mousex color,fontsize
  2451.          @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
  2452.          @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2453.  
  2454.         */
  2455.             stroke_color = get_color(infile,0);
  2456.             font_size = (int) (get_real(infile,1));
  2457.             tmp_buffer = my_newmem(26);
  2458.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2459.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
  2460.             break;
  2461.         case MOUSEY:
  2462.         /*
  2463.          @ mousey color,fontsize
  2464.          @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
  2465.          @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2466.  
  2467.         */
  2468.             stroke_color = get_color(infile,0);
  2469.             font_size = (int) (get_real(infile,1));
  2470.             tmp_buffer = my_newmem(26);
  2471.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2472.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
  2473.             break;
  2474.         case MOUSE:
  2475.         /*
  2476.          @ mouse color,fontsize
  2477.          @ will display the cursor (x:y) coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
  2478.          @ NOTE: use command 'mouse' at the end of your script code (the same is true for commanmd 'zoom')
  2479.  
  2480.         */
  2481.             stroke_color = get_color(infile,0);
  2482.             font_size = (int) (get_real(infile,1));
  2483.             tmp_buffer = my_newmem(26);
  2484.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2485.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
  2486.             break;
  2487.         case INTOOLTIP:
  2488.             /*
  2489.             @ intooltip link_text
  2490.             @ link_text is a single line (span-element)
  2491.             @ link_text may also be an image URL http://some_server/images/my_image.png
  2492.             @ link_text may contain HTML markup
  2493.             @ the canvas will be displayed in a tooltip on 'link_text'
  2494.             @ the canvas is default transparent: use command 'bgcolor color' to adjust background-color<br />the link test will alos be shown with this bgcolor.
  2495.             */
  2496.             if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy command");}
  2497.             use_tooltip = TRUE;
  2498.             tooltip_text = get_string(infile,1);
  2499.             if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
  2500.             break;
  2501.         case AUDIO:
  2502.         /*
  2503.         @ audio x,y,w,h,loop,visible,audiofile location
  2504.         @ x,y : left top corner of audio element (in xrange / yrange)
  2505.         @ w,y : width and height in pixels
  2506.         @ loop : 0 or 1 ( 1 = loop audio fragment)
  2507.         @ visible : 0 or 1 (1 = show controls)
  2508.         @ audio format may be in *.mp3 or *.ogg
  2509.         @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format)
  2510.         @ if you are using *.ogg : be aware that Microsoft based systems not support it natively
  2511.         @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
  2512.         @ 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 />
  2513.         */
  2514.             if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
  2515.             for(i=0;i<7;i++){
  2516.                 switch(i){
  2517.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  2518.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  2519.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  2520.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  2521.                     case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
  2522.                     case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
  2523.                     case 6:
  2524.                     temp = get_string(infile,1);
  2525.                     if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
  2526.                     if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
  2527.                     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);
  2528.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2529.                     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);
  2530.                     add_to_buffer(tmp_buffer);
  2531.                     break;
  2532.                     default:break;
  2533.                 }
  2534.             }
  2535.             reset();
  2536.             break;
  2537.         case VIDEO:
  2538.         /*
  2539.         @ video x,y,w,h,videofile location
  2540.         @ x,y : left top corner of audio element (in xrange / yrange)
  2541.         @ w,y : width and height in pixels
  2542.         @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4
  2543.         @ video format may be in *.mp4 (todo:other formats)
  2544.         */
  2545.             if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
  2546.             for(i=0;i<5;i++){
  2547.                 switch(i){
  2548.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  2549.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  2550.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  2551.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  2552.                     case 4: temp = get_string(infile,1);
  2553.                             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);
  2554.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2555.                             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);
  2556.                             add_to_buffer(tmp_buffer);
  2557.                             break;
  2558.                     default:break;
  2559.                 }
  2560.             }
  2561.             reset();
  2562.             break;
  2563.         case HATCHFILL:
  2564.         /*
  2565.         @ hatchfill x0,y0,dx,dy,color
  2566.         @ x0,y0 in xrange / yrange
  2567.         @ distances dx,dy in pixels
  2568.         */
  2569.             if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
  2570.             for(i=0;i<5;i++){
  2571.                 switch(i){
  2572.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2573.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2574.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2575.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2576.                     case 4: stroke_color = get_color(infile,1);
  2577.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2578.                     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);
  2579.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2580.                     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);
  2581.                     add_to_buffer(tmp_buffer);
  2582.                     break;
  2583.                     default:break;
  2584.                 }
  2585.             }
  2586.             reset();
  2587.         break;
  2588.         case DIAMONDFILL:
  2589.         /*
  2590.         @ diamondfill x0,y0,dx,dy,color
  2591.         @ x0,y0 in xrange / yrange
  2592.         @ distances dx,dy in pixels
  2593.         */
  2594.             if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
  2595.             for(i=0;i<5;i++){
  2596.                 switch(i){
  2597.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2598.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2599.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2600.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2601.                     case 4: stroke_color = get_color(infile,1);
  2602.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2603.                     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);
  2604.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2605.                     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);
  2606.                     add_to_buffer(tmp_buffer);
  2607.                     break;
  2608.                     default:break;
  2609.                 }
  2610.             }
  2611.             reset();
  2612.         break;
  2613.         case GRIDFILL:
  2614.         /*
  2615.         @ gridfill x0,y0,dx,dy,color
  2616.         @ x0,y0 in xrange / yrange
  2617.         @ distances dx,dy in pixels
  2618.         @ a draggable object may snap_to_grid (using keywords xysnaptogrid,xsnaprogrid, ysnaptogrid)
  2619.         @ userdraw object may snap_to_grid
  2620.         */
  2621.             if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
  2622.             for(i=0;i<5;i++){
  2623.                 switch(i){
  2624.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2625.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2626.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2627.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2628.                     case 4: stroke_color = get_color(infile,1);
  2629.                     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);
  2630.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2631.                     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);
  2632.                     add_to_buffer(tmp_buffer);
  2633.                     break;
  2634.                     default:break;
  2635.                 }
  2636.             }
  2637.             reset();
  2638.         break;
  2639.         case DOTFILL:
  2640.         /*
  2641.         @ dotfill x0,y0,dx,dy,color
  2642.         @ x0,y0 in xrange / yrange
  2643.         @ distances dx,dy in pixels
  2644.         @ radius of dots is linewidth
  2645.         */
  2646.             if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
  2647.             for(i=0;i<5;i++){
  2648.                 switch(i){
  2649.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2650.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2651.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  2652.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2653.                     case 4: stroke_color = get_color(infile,1);
  2654.                     /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
  2655.                     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);
  2656.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2657.                     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);
  2658.                     add_to_buffer(tmp_buffer);
  2659.                     break;
  2660.                     default:break;
  2661.                 }
  2662.             }
  2663.             reset();
  2664.         break;
  2665.         case IMAGEFILL:
  2666.         /*
  2667.         @ imagefill dx,dy,image_url
  2668.         @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
  2669.         @ After pattern filling ,the fill-color should be reset !
  2670.         @ wims getins / image from class directory : imagefill 80,80,my_image.gif
  2671.         @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif
  2672.         @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg
  2673.         @ if dx,dy is larger than the image, the whole image will be background to the next object.
  2674.         */
  2675.             if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
  2676.             for(i=0 ;i < 3 ; i++){
  2677.                 switch(i){
  2678.                     case 0:int_data[0] = (int) (get_real(infile,0));break;
  2679.                     case 1:int_data[1] = (int) (get_real(infile,0));break;
  2680.                     case 2: URL = get_string_argument(infile,1);
  2681.                             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);
  2682.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2683.                             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);
  2684.                             add_to_buffer(tmp_buffer);
  2685.                     break;
  2686.                 }
  2687.             }
  2688.             reset();
  2689.         break;
  2690.         case FILLTOBORDER:
  2691.         /*
  2692.         @ filltoborder x,y,bordercolor,color
  2693.         @ fill the region  of point (x:y) bounded by 'bordercolor' with color 'color'
  2694.         @ any other color will not act as border to the bucket fill
  2695.         @ use this command  after all boundary objects are declared.
  2696.         @ 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..
  2697.         */
  2698.             for(i=0 ;i < 4 ; i++){
  2699.                 switch(i){
  2700.                     case 0:double_data[0] = get_real(infile,0);break;
  2701.                     case 1:double_data[1] = get_real(infile,0);break;
  2702.                     case 2:bgcolor = get_color(infile,0);break;
  2703.                     case 3:fill_color = get_color(infile,1);
  2704.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2705.                                 js_function[DRAW_FILLTOBORDER] = 1;
  2706.                                 add_js_filltoborder(js_include_file,canvas_root_id);
  2707.                            }
  2708.                            decimals = find_number_of_digits(precision);
  2709.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  2710.                            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));
  2711.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2712.                            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));
  2713.                            add_to_buffer(tmp_buffer);
  2714.                            break;
  2715.                     default:break;
  2716.                 }
  2717.             }
  2718.             reset();
  2719.         break;
  2720.         case FLOODFILL:
  2721.         /*
  2722.         @ floodfill x,y,color
  2723.         @ alternative syntax: fill x,y,color
  2724.         @ fill the region of point (x:y) with color 'color'
  2725.         @ any other color or size of picture (borders of picture) will act as border to the bucket fill
  2726.         @ use this command  after all boundary objects are declared.
  2727.         @ Use command 'clickfill,color' for user click driven flood fill.
  2728.         @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
  2729.         @ 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..
  2730.         */
  2731.             for(i=0 ;i < 4 ; i++){
  2732.                 switch(i){
  2733.                     case 0:double_data[0] = get_real(infile,0);break;
  2734.                     case 1:double_data[1] = get_real(infile,0);break;
  2735.                     case 2:fill_color = get_color(infile,1);
  2736.                            if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
  2737.                                 js_function[DRAW_FLOODFILL] = 1;
  2738.                                 add_js_floodfill(js_include_file,canvas_root_id);
  2739.                            }
  2740.                            decimals = find_number_of_digits(precision);/*floodfill(interaction,x,y,[R,G,B,A]) */
  2741.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  2742.                            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));
  2743.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2744.                            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));
  2745.                            add_to_buffer(tmp_buffer);
  2746.                            break;
  2747.                     default:break;
  2748.                 }
  2749.             }
  2750.             reset();
  2751.         break;
  2752.         case CLICKFILLMARGE:
  2753.             clickfillmarge = (int) (get_real(infile,1));
  2754.             break;
  2755.         /*
  2756.         @ clickfillmarge int
  2757.         @ default 20 (pixels)
  2758.         @ 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[])
  2759.         */
  2760.         case CLICKFILL:
  2761.         /*
  2762.         @ clickfill fillcolor
  2763.         @ user left mouse click will floodfill the area with fillcolor
  2764.         @ multiple areas may be coloured
  2765.         @ 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)
  2766.         @ the answer will be read as the (x:y) click coordinates per coloured area
  2767.         @ background color of main div may be set by using command "bgcolor color"
  2768.         @ may not be combined with command "userdraw"
  2769.         @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
  2770.         */
  2771.          fill_color = get_color(infile,1);
  2772.          if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
  2773.             js_function[DRAW_FLOODFILL] = 1;
  2774.             add_js_floodfill(js_include_file,canvas_root_id);
  2775.          }
  2776.          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));
  2777.          add_read_canvas(1,reply_precision);
  2778.          reset();
  2779.         break;
  2780.         case SETPIXEL:
  2781.         /*
  2782.         @ setpixel x,y,color
  2783.         @ A "point" with diameter 1 pixel centeres at (x:y) in xrange / yrange
  2784.         @ pixels can not be dragged or clicked
  2785.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  2786.         */
  2787.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  2788.             for(i=0;i<3;i++){
  2789.                 switch(i){
  2790.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  2791.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  2792.                     case 2: stroke_color = get_color(infile,1);
  2793.                            string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  2794.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2795.                            snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  2796.                            add_to_buffer(tmp_buffer);
  2797.                            break;
  2798.                     default:break;
  2799.                 }
  2800.             }
  2801.             reset();
  2802.         break;
  2803.         case PIXELSIZE:
  2804.         /*
  2805.         @ pixelsize int
  2806.         @ in case you want to deviate from default pixelsize = 1...
  2807.         */
  2808.             pixelsize = (int) get_real(infile,1);
  2809.         break;
  2810.         case PIXELS:
  2811.         /*
  2812.         @ pixels color,x1,y1,x2,y2,x3,y3...
  2813.         @ Draw  "points" with diameter 1 pixel
  2814.         @ pixels can not be dragged or clicked
  2815.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  2816.         */
  2817.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  2818.             stroke_color=get_color(infile,0);
  2819.             i=0;
  2820.             c=0;
  2821.             while( ! done ){     /* get next item until EOL*/
  2822.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  2823.                 for( c = 0 ; c < 2; c++){
  2824.                     if(c == 0 ){
  2825.                         double_data[i] = get_real(infile,0);
  2826.                         i++;
  2827.                     }
  2828.                     else
  2829.                     {
  2830.                         double_data[i] = get_real(infile,1);
  2831.                         i++;
  2832.                     }
  2833.                 }
  2834.             }
  2835.             decimals = find_number_of_digits(precision);
  2836.             /*  *double_xy2js_array(double xy[],int len,int decimals) */
  2837.             string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  2838.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2839.             snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  2840.             add_to_buffer(tmp_buffer);
  2841.             reset();
  2842.             break;
  2843.         case REPLYFORMAT:
  2844.         /*
  2845.         @ replyformat number
  2846.         @ use number=-1 to deactivate the js-function read_canvas()
  2847.         @ default values should be fine !
  2848.         @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing
  2849.         @ the last value for 'precision int' will be used to calculate  the reply coordinates, if needed (read_canvas();)
  2850.         @ choose<ul><li>1 = x1,x2,x3,x4....x_n<br />y1,y2,y3,y4....y_n<br /><br />x/y in pixels</li><li>2 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br /> x/y in xrange / yrange coordinate system<br /></li><li>3 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br />  r1,r2,r3,r4....r_n<br />  x/y in pixels <br />  r in pixels</li><li>4 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br />  r1,r2,r3,r4....r_n<br />  x/y in xrange / yrange coordinate system<br />  r in pixels</li><li>5 = Ax1,Ax2,Ax3,Ax4....Ax_n<br />  Ay1,Ay2,Ay3,Ay4....Ay_n<br />  Bx1,Bx2,Bx3,Bx4....Bx_n<br />  By1,By2,By3,By4....By_n<br />  Cx1,Cx2,Cx3,Cx4....Cx_n<br />  Cy1,Cy2,Cy3,Cy4....Cy_n<br />  ....<br />  Zx1,Zx2,Zx3,Zx4....Zx_n<br />  Zy1,Zy2,Zy3,Zy4....Zy_n<br />  x/y in pixels<br /></li><li>6 = Ax1,Ax2,Ax3,Ax4....Ax_n<br />  Ay1,Ay2,Ay3,Ay4....Ay_n<br />  Bx1,Bx2,Bx3,Bx4....Bx_n<br />  By1,By2,By3,By4....By_n<br />  Cx1,Cx2,Cx3,Cx4....Cx_n<br />  Cy1,Cy2,Cy3,Cy4....Cy_n<br />  ....<br />  Zx1,Zx2,Zx3,Zx4....Zx_n<br />  Zy1,Zy2,Zy3,Zy4....Zy_n<br />  x/y in xrange / yrange coordinate system<br /></li><li>7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br />  x/y in pixels</li><li>8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br />  x/y in xrange / yrange coordinate system</li><li>9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br />  x/y in pixels</li><li>10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br />  x/y in xrange / yrange coordinate system</li><li>11 = Ax1,Ay1,Ax2,Ay2<br />   Bx1,By1,Bx2,By2<br />   Cx1,Cy1,Cx2,Cy2<br />   Dx1,Dy1,Dx2,Dy2<br />   ......<br />   Zx1,Zy1,Zx2,Zy2<br />  x/y in xrange / yrange coordinate system</li><li>12 = Ax1,Ay1,Ax2,Ay2<br />   Bx1,By1,Bx2,By2<br />Cx1,Cy1,Cx2,Cy2<br />   Dx1,Dy1,Dx2,Dy2<br />   ......<br />   Zx1,Zy1,Zx2,Zy2<br />  x/y in pixels</li><li>13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2<br />  x/y in xrange / yrange coordinate system</li><li>14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2<br />  x/y in pixels</li><li>15 = reply from inputfields,textareas<br />  reply1,reply2,reply3,...,reply_n</li><li>16 = mathml input fields </li><li>17 = read "userdraw text,color" only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n</li><li>18 = read_canvas() will read all interactive clocks in H1:M1:S1,H2:M2:S2...Hn:Mn:Sn</li><li>19 = read_canvas() will return the object number of marked / clicked object (clock)<br />analogue to (shape library) onclick command </li><li>21 = (x1:y1) (x2:y2) ... (x_n:y_n)<br />verbatim coordinate return</li>22 = returns an array .... reply[0]=x1 reply[1]=y1 reply[2]=x2 reply[3]=y2 ... reply[n-1]=x_n reply[n]=y_n<br />  x/y in xrange / yrange coordinate system</li><li>replyformat 23 : can only be used for drawtype 'polyline'<br />a typical click sequence in drawtype polyline isx1,y1,x2,y2,x2,y2,x3,y3,x3,y3.....,x(n-1),y(n-1),x(n-1),y(n-1),xn,yn --replyformat 23--> x1,y1,x2,y2,x3,y3,.....x(n-1),y(n-1),xn,yn multiple occurences will be filtered out.The reply will be in x-y-range (xreply \\n yreply)</li><li>replyformat 24 = read all inputfield values: even those set 'readonly'</li><li>format 25 = angle1,angle2...angle_n : will return the radius (one or many) of the user drawn circle segment in degrees </li><li>format 26 = rad1,rad2...rad_n : will return the radius (one or many) of the user drawn circle segment in radians </li><li>27 = return (only) userdraw inputfields array: x1:y1:text1,x2:y2:text2...</li></ul>
  2851.         @ note to 'userdraw text,color' : the x / y-values are in pixels ! (this to avoid too lengthy calculations in javascript...)
  2852.         */
  2853.          reply_format = (int) get_real(infile,1);
  2854.          reply_precision = precision;
  2855.         break;
  2856.         case LEGENDCOLORS:
  2857.         /*
  2858.         @ legendcolors color1:color2:color3:...:color_n
  2859.         @ 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 />
  2860.         @ make sure the number of colours match the number of legend items
  2861.         @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
  2862.         */
  2863.             if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
  2864.             temp = get_string(infile,1);
  2865.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2866.             fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
  2867.             break;
  2868.         case LEGEND:
  2869.         /*
  2870.         @ legend string1:string2:string3....string_n
  2871.         @ will be used to create a legend for a graph
  2872.         @ also see command 'piechart'  
  2873.         @ will use the same colors per default as used in the graphs : use command 'legendcolors' to override the default
  2874.         */
  2875.             temp = get_string(infile,1);
  2876.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2877.             legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */
  2878.             fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
  2879.             break;
  2880.         case XLABEL:
  2881.         /*
  2882.         @ xlabel some_string
  2883.         @ will be used to create a label for the x-axis (label is in quadrant I)
  2884.         @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
  2885.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
  2886.         */
  2887.             temp = get_string(infile,1);
  2888.             fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
  2889.             break;
  2890.         case YLABEL:
  2891.         /*
  2892.         @ ylabel some_string
  2893.         @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
  2894.         @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
  2895.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
  2896.         */
  2897.             temp = get_string(infile,1);
  2898.             fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
  2899.             break;
  2900.         case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
  2901.         /*
  2902.         @ linegraph x1:y1;x2:y2...x_n:y_n
  2903.         @ will plot your data in a graph
  2904.         @ may only to be used together with command 'grid'
  2905.         @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
  2906.         @ use command 'legend' to provide an optional legend in right-top-corner
  2907.         @ also see command 'piechart'
  2908.         @ multiple linegraphs may be used in a single plot
  2909.         @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
  2910.         @ <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>
  2911.         */    
  2912.             temp = get_string(infile,1);
  2913.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2914.             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);
  2915.             linegraph_cnt++;
  2916.             reset();
  2917.             break;
  2918.         case BARCHART:
  2919.         /*
  2920.         @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
  2921.         @ will be used to create a legend for bar graph
  2922.         @ may only to be used together with command 'grid'
  2923.         @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
  2924.         @ use command 'legend' to provide an optional legend in right-top-corner
  2925.         @ also see command 'piechart'
  2926.         @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
  2927.         */
  2928.             temp = get_string(infile,1);
  2929.             if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
  2930.             fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
  2931.             barchart_cnt++;
  2932.             reset();
  2933.             break;
  2934.         case CLOCK:
  2935.         /*
  2936.         @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
  2937.         @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency
  2938.         @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments
  2939.         @ 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
  2940.         @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
  2941.         @ 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>
  2942.         @ canvasdraw will not check validity of colornames...the javascript console is your best friend
  2943.         @ no combinations with other reply_types allowed, for now
  2944.         @ 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
  2945.         */
  2946.             if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
  2947.  
  2948.         /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
  2949.             for(i=0;i<9;i++){
  2950.              switch(i){
  2951.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
  2952.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
  2953.               case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
  2954.               case 3: int_data[3] = get_real(infile,0);break;/* hours */
  2955.               case 4: int_data[4] = get_real(infile,0);break;/* minutes */
  2956.               case 5: int_data[5] = get_real(infile,0);break;/* seconds */
  2957.               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 */
  2958.               case 7: int_data[7] = (int)(get_real(infile,0));/* interactive 0,1,2*/
  2959.                 switch(int_data[7]){
  2960.                     case 0:break;
  2961.                     case 1:if(clock_cnt == 0){
  2962.                                 if( reply_format == 0 ){
  2963.                                      reply_format = 18; /* user sets clock */
  2964.                                     /* 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");
  2965.                                      check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2966.                                      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");
  2967.                                      add_to_buffer(tmp_buffer);
  2968.                                     */
  2969.                                      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");
  2970.                                 }
  2971.                                 else
  2972.                                 {
  2973.                                     canvas_error("interactive clock may not be used together with other reply_types...");
  2974.                                 }
  2975.                                 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);
  2976.                              }
  2977.                     break;
  2978.                     case 2:if( reply_format == 0 ){
  2979.                                 reply_format = 19; /* "onclick */
  2980.                                 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 ");
  2981.                             }
  2982.                             else
  2983.                             {
  2984.                                 if( reply_format != 19){
  2985.                                    canvas_error("clickable clock(s) may not be used together with other reply_types...");
  2986.                                  }
  2987.                             }
  2988.                      break;
  2989.                      default: canvas_error("interactive must be set 0,1 or 2");break;
  2990.                 }
  2991.                 break;
  2992.                 case 8:
  2993.                         fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
  2994.                         temp = get_string(infile,1);
  2995.                         if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
  2996.                         if( strlen(temp) < 1 ){temp = ",\"\",\"\",\"\",\"\",\"\"";}
  2997.                         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);
  2998.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2999.                         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);
  3000.                         add_to_buffer(tmp_buffer);
  3001.                         clock_cnt++;
  3002.                         break;
  3003.                 default:break;
  3004.              }
  3005.             }
  3006.             break;
  3007.         case PIECHART:
  3008.         /*
  3009.         @ piechart xc,yc,radius,'data+colorlist'
  3010.         @ (xc : yc) center of circle diagram in xrange/yrange
  3011.         @ radius in pixels
  3012.         @ 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
  3013.         @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white
  3014.         @ the number of colors must match the number of data.
  3015.         @ use command "opacity 0-255,0-255" to adjust fill_opacity of colours
  3016.         @ 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.
  3017.         */
  3018.             if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}    
  3019.             for(i=0;i<5;i++){
  3020.                 switch(i){
  3021.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  3022.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  3023.                     case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
  3024.                     case 3: temp = get_string(infile,1);
  3025.                             if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
  3026.                             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);
  3027.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3028.                             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);
  3029.                             add_to_buffer(tmp_buffer);
  3030.                            break;
  3031.                     default:break;
  3032.                 }
  3033.             }
  3034.             reset();
  3035.         break;
  3036.         case STATUS:
  3037.         /*
  3038.         @status
  3039.         @keyword
  3040.         @alernative keyword: nostatus
  3041.         @used to override the effects of "status=done" in wims (answer.phtml)
  3042.         @affects inputfields / textarea's in canvasimage and all userdraw based commands
  3043.         @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'
  3044.         */
  3045.        
  3046.             fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
  3047.             break;
  3048.         case XLOGBASE:
  3049.         /*
  3050.         @ xlogbase number
  3051.         @ sets the logbase number for the x-axis
  3052.         @ default value 10
  3053.         @ use together with commands xlogscale / xylogscale
  3054.         */
  3055.             fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
  3056.             break;
  3057.         case YLOGBASE:
  3058.         /*
  3059.         @ ylogbase number
  3060.         @ sets the logbase number for the y-axis
  3061.         @ default value 10
  3062.         @ use together with commands ylogscale / xylogscale
  3063.         */
  3064.             fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
  3065.             break;
  3066.         case XLOGSCALE:
  3067.         /*
  3068.          @ xlogscale ymajor,yminor,majorcolor,minorcolor
  3069.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  3070.          @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
  3071.          @ the linewidth is set using command 'linewidth int'
  3072.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  3073.          @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number'
  3074.          @ 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>
  3075.          @ note: the complete canvas will be used for the 'log paper'
  3076.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  3077.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  3078.          @ 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')  
  3079.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  3080.          @ attention: keyword 'snaptogrid' may not lead to the desired result...
  3081.         */
  3082.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  3083.             if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
  3084.             for(i=0;i<4;i++){
  3085.                 switch(i){
  3086.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  3087.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  3088.                     case 2: stroke_color = get_color(infile,0); break;
  3089.                     case 3: fill_color = get_color(infile,1);
  3090.                         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);
  3091.                         tmp_buffer = my_newmem(string_length+1);
  3092.                         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);
  3093.                         fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
  3094.                         add_to_buffer(tmp_buffer);
  3095.                         break;
  3096.                     default:break;
  3097.                 }
  3098.             }
  3099.             break;
  3100.         case YLOGSCALE:
  3101.         /*
  3102.          @ ylogscale xmajor,xminor,majorcolor,minorcolor
  3103.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  3104.          @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
  3105.          @ the linewidth is set using command 'linewidth int'
  3106.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  3107.          @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number'
  3108.          @ 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>
  3109.          @ note: the complete canvas will be used for the 'log paper'
  3110.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  3111.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  3112.          @ 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')  
  3113.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  3114.          @ attention: keyword 'snaptogrid' may not lead to the desired result...
  3115.         */
  3116.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  3117.             if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
  3118.             for(i=0;i<4;i++){
  3119.                 switch(i){
  3120.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  3121.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  3122.                     case 2: stroke_color = get_color(infile,0); break;
  3123.                     case 3: fill_color = get_color(infile,1);
  3124.                         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);
  3125.                         tmp_buffer = my_newmem(string_length+1);
  3126.                         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);
  3127.                         fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
  3128.                         add_to_buffer(tmp_buffer);
  3129.                         break;
  3130.                     default:break;
  3131.                 }
  3132.             }
  3133.             break;
  3134.         case XYLOGSCALE:
  3135.         /*
  3136.          @ xylogscale majorcolor,minorcolor
  3137.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  3138.          @ the linewidth is set using command 'linewidth int'
  3139.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  3140.          @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number'
  3141.          @ 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>
  3142.          @ note: the complete canvas will be used for the 'log paper'
  3143.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  3144.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  3145.          @ 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')  
  3146.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  3147.          @ attention: keyword 'snaptogrid' may not lead to the desired result...
  3148.         */
  3149.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  3150.             if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
  3151.             for(i=0;i<2;i++){
  3152.                 switch(i){
  3153.                     case 0: stroke_color = get_color(infile,0); break;
  3154.                     case 1: fill_color = get_color(infile,1);
  3155.                         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);
  3156.                         tmp_buffer = my_newmem(string_length+1);
  3157.                         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);
  3158.                         fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
  3159.                         add_to_buffer(tmp_buffer);
  3160.                         break;
  3161.                     default:break;
  3162.                 }
  3163.             }
  3164.         break;
  3165.         default:sync_input(infile);
  3166.         break;
  3167.     }
  3168.   }
  3169.   /* we are done parsing script file */
  3170.   /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */
  3171.   if( found_size_command == 1 ){
  3172.     fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
  3173.   }
  3174.   else
  3175.   {
  3176.     if( found_size_command != 3 ){
  3177.      canvas_error("Please specify bothe xrange and yrange ...");
  3178.     }
  3179.   }
  3180.   /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable shapes / objects  ! */
  3181.   add_javascript_functions(js_function,canvas_root_id);
  3182.    /* add read_canvas() etc functions if needed */
  3183.   if( reply_format > 0 ){ add_read_canvas(reply_format,reply_precision);}
  3184.   if( use_pan_and_zoom == TRUE ){
  3185.   /* in case of zooming ... */
  3186.   fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\
  3187.  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
  3188.  var ymin_start=ymin;var ymax_start=xmax;\
  3189.  var zoom_x_increment=0;var zoom_y_increment=0;\
  3190.  var pan_x_increment=0;var pan_y_increment=0;\
  3191.  if(use_ylogscale == 0 ){\
  3192.   zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (ymax - ymin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\
  3193.  }else{\
  3194.   zoom_x_increment = (xmax - xmin)/20;\
  3195.   pan_x_increment = (xmax - xmin)/20;\
  3196.  };\
  3197.  function start_canvas%d(type){\
  3198.   switch(type){\
  3199.    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
  3200.    case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\
  3201.    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
  3202.    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
  3203.    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
  3204.    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
  3205.    case 6:location.reload();break;\
  3206.    default:break;\
  3207.   };\
  3208.   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
  3209.   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
  3210.   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){}\
  3211.   %s\
  3212.  };\
  3213.  start_canvas%d(333);\
  3214. };\n\
  3215. <!-- end wims_canvas_function -->\n\
  3216. wims_canvas_function%d();\n",precision,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
  3217.   }
  3218.   else
  3219.   {
  3220.   /* no zoom, just add buffer */
  3221.   fprintf(js_include_file,"\n<!-- add buffer -->\n\
  3222.  %s\
  3223. };\n\
  3224. <!-- end wims_canvas_function -->\n\
  3225. wims_canvas_function%d();\n",buffer,canvas_root_id);
  3226.   }
  3227. /* done writing the javascript include file */
  3228. fclose(js_include_file);
  3229.  
  3230. }
  3231.  
  3232. /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
  3233. if(use_tooltip == TRUE){
  3234.   add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
  3235. }
  3236. exit(EXIT_SUCCESS);
  3237. }
  3238. /* end main() */
  3239.  
  3240. /******************************************************************************
  3241. **
  3242. **  sync_input
  3243. **
  3244. **  synchronises input line - reads to end of line, leaving file pointer
  3245. **  at first character of next line.
  3246. **
  3247. **  Used by:
  3248. **  main program - error handling.
  3249. **
  3250. ******************************************************************************/
  3251. void sync_input(FILE *infile)
  3252. {
  3253.         int c = 0;
  3254.  
  3255.         if( c == '\n' || c == ';' ) return;
  3256.         while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
  3257.         if( c == EOF ) finished = 1;
  3258.         if( c == '\n' || c == '\r' || c == ';') line_number++;
  3259.         return;
  3260. }
  3261.  
  3262. /******************************************************************************/
  3263.  
  3264. char *str_replace(const char *str, const char *old, const char *new){
  3265. /* http://creativeandcritical.net/str-replace-c/ */
  3266.     if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
  3267.     char *ret, *r;
  3268.     const char *p, *q;
  3269.     size_t oldlen = strlen(old);
  3270.     size_t count = 0;
  3271.     size_t retlen = 0;
  3272.     size_t newlen = strlen(new);
  3273.     if (oldlen != newlen){
  3274.         for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
  3275.             count++;
  3276.             retlen = p - str + strlen(p) + count * (newlen - oldlen);
  3277.         }
  3278.     }
  3279.     else
  3280.     {
  3281.         retlen = strlen(str);
  3282.     }
  3283.    
  3284.     if ((ret = malloc(retlen + 1)) == NULL){
  3285.         ret = NULL;
  3286.         canvas_error("string argument is NULL");
  3287.     }
  3288.     else
  3289.     {
  3290.         for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
  3291.             size_t l = q - p;
  3292.             memcpy(r, p, l);
  3293.             r += l;
  3294.             memcpy(r, new, newlen);
  3295.             r += newlen;
  3296.         }
  3297.         strcpy(r, p);
  3298.     }
  3299.     return ret;
  3300. }
  3301.  
  3302. /******************************************************************************/
  3303.  
  3304. char *get_color(FILE *infile , int last){
  3305.     int c,i = 0,is_hex = 0;
  3306.     char temp[MAX_COLOR_STRING], *string;
  3307.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){
  3308.         if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
  3309.         if( c == '#' ){
  3310.             is_hex = 1;
  3311.         }
  3312.         if( c != ' '){
  3313.             temp[i]=tolower(c);
  3314.             i++;
  3315.         }
  3316.     }
  3317.     if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
  3318.     if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
  3319.     if( c == EOF ){finished = 1;}
  3320.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  3321.     temp[i]='\0';
  3322.     if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
  3323.     if( is_hex == 1 ){
  3324.         char red[3], green[3], blue[3];
  3325.         red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
  3326.         green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
  3327.         blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
  3328.         int r = (int) strtol(red,   NULL, 16);
  3329.         int g = (int) strtol(green, NULL, 16);
  3330.         int b = (int) strtol(blue,  NULL, 16);
  3331.         string = (char *)my_newmem(12);
  3332.         snprintf(string,11,"%d,%d,%d",r,g,b);
  3333.         return string;
  3334.     }
  3335.     else
  3336.     {
  3337.         string = (char *)my_newmem(sizeof(temp));
  3338.         snprintf(string,sizeof(temp),"%s",temp);
  3339.         for( i = 0; i <= NUMBER_OF_COLORNAMES ; i++ ){
  3340.             if( strcmp( colors[i].name , string ) == 0 ){
  3341.                 return colors[i].rgb;
  3342.             }
  3343.         }
  3344.     }
  3345.     /* not found...return error */
  3346.     free(string);string = NULL;
  3347.     canvas_error("I was expecting a color name or hexnumber...but found nothing.");
  3348.     return NULL;
  3349. }
  3350.  
  3351. char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
  3352.     int c,i=0;
  3353.     char  temp[MAX_BUFFER], *string;
  3354.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){
  3355.         temp[i]=c;
  3356.         i++;
  3357.         if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
  3358.     }
  3359.     if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  3360.     if( c == '\n') { done = TRUE; line_number++; }
  3361.     if( c == EOF ) {
  3362.         finished = 1;
  3363.         if( last != 1 ){ canvas_error("expected more arguments");}
  3364.     }
  3365.     temp[i]='\0';
  3366.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");}
  3367.     string=(char *)my_newmem(strlen(temp));
  3368.     snprintf(string,sizeof(temp),"%s",temp);
  3369.     return string;
  3370. }
  3371.  
  3372. char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
  3373.     int c,i=0;
  3374.     char temp[MAX_BUFFER], *string;
  3375.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',')){
  3376.         temp[i]=c;
  3377.         i++;
  3378.         if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
  3379.     }
  3380.     if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
  3381.     if( c == '\n') { line_number++; }
  3382.     if( c == EOF ) {finished = 1;}
  3383.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  3384.     temp[i]='\0';
  3385.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
  3386.     string=(char *)my_newmem(sizeof(temp));
  3387.     snprintf(string,sizeof(temp),"%s",temp);
  3388.     done = TRUE;
  3389.     return string;
  3390. }
  3391.  
  3392. double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
  3393.     int c,i=0,found_calc = 0;
  3394.     double y;
  3395.     char tmp[MAX_INT];
  3396.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){
  3397.      if( c != ' ' ){
  3398.      /*
  3399.      libmatheval will segfault when for example: "xrange -10,+10" or "xrange -10,10+" is used
  3400.      We will check after assert() if it's a NULL pointer...and exit program via :
  3401.      canvas_error("I'm having trouble parsing your \"expression\" ");
  3402.      */
  3403.       if( i == 0 &&  c == '+' ){
  3404.        continue;
  3405.       }
  3406.       else
  3407.       {
  3408.        if(canvas_iscalculation(c) != 0){
  3409.         found_calc = 1;
  3410.         c = tolower(c);
  3411.        }
  3412.        tmp[i] = c;
  3413.        i++;
  3414.       }
  3415.      }
  3416.      if( i > MAX_INT - 1){canvas_error("number too large");}
  3417.     }
  3418.     if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
  3419.     if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
  3420.     if( c == EOF ){done = TRUE ; finished = 1;}
  3421.     tmp[i]='\0';
  3422.     if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
  3423.     if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */
  3424.      void *f = eval_create(tmp);
  3425.      assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  3426.      y = eval_x(f, 1);
  3427.      /* if function is bogus; y = 1 : so no core dumps */
  3428.      eval_destroy(f);
  3429.     }
  3430.     else
  3431.     {
  3432.      y = atof(tmp);
  3433.     }
  3434.     return y;
  3435. }
  3436. void canvas_error(char *msg){
  3437.     fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg);
  3438.     finished = 1;
  3439.     exit(EXIT_SUCCESS);
  3440. }
  3441.  
  3442.  
  3443. /* convert x/y coordinates to pixel */
  3444. int x2px(double x){
  3445.  return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
  3446. }
  3447.  
  3448. int y2px(double y){
  3449.  return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
  3450. }
  3451.  
  3452. double px2x(int x){
  3453.  return (x*(xmax - xmin)/xsize + xmin);
  3454. }
  3455. double px2y(int y){
  3456.  return (y*(ymax - ymin)/ysize + ymin);
  3457. }
  3458.  
  3459. void add_to_buffer(char *tmp){
  3460.  if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
  3461.  /*  do we have enough space left in buffer[MAX_BUFFER] ? */
  3462.  int space_left = (int) (sizeof(buffer) - strlen(buffer));
  3463.  if( space_left > strlen(tmp)){
  3464.   strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
  3465.  }
  3466.  else
  3467.  {
  3468.   canvas_error("buffer is too big\n");
  3469.  }
  3470.  tmp = NULL;free(tmp);
  3471.  return;
  3472. }
  3473.  
  3474. void reset(){
  3475.  if(use_filled == TRUE){use_filled = FALSE;}
  3476.  if(use_dashed == TRUE){use_dashed = FALSE;}
  3477.  if(use_rotate == TRUE){use_rotate = FALSE;}
  3478.    onclick = 0;
  3479. }
  3480.  
  3481.  
  3482.  
  3483. /* What reply format in read_canvas();
  3484.  
  3485. note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
  3486. 1 = x1,x2,x3,x4....x_n
  3487.     y1,y2,y3,y4....y_n
  3488.  
  3489.     x/y in pixels
  3490.  
  3491. 2 = x1,x2,x3,x4....x_n
  3492.     y1,y2,y3,y4....y_n
  3493.     x/y in  xrange / yrange coordinate system
  3494.  
  3495. 3 = x1,x2,x3,x4....x_n
  3496.     y1,y2,y3,y4....y_n
  3497.     r1,r2,r3,r4....r_n
  3498.  
  3499.     x/y in pixels
  3500.     r in pixels
  3501.  
  3502. 4 = x1,x2,x3,x4....x_n
  3503.     y1,y2,y3,y4....y_n
  3504.     r1,r2,r3,r4....r_n
  3505.  
  3506.     x/y in  xrange / yrange coordinate system
  3507.     r in pixels
  3508.  
  3509. 5 = Ax1,Ax2,Ax3,Ax4....Ax_n
  3510.     Ay1,Ay2,Ay3,Ay4....Ay_n
  3511.     Bx1,Bx2,Bx3,Bx4....Bx_n
  3512.     By1,By2,By3,By4....By_n
  3513.     Cx1,Cx2,Cx3,Cx4....Cx_n
  3514.     Cy1,Cy2,Cy3,Cy4....Cy_n
  3515.     ....
  3516.     Zx1,Zx2,Zx3,Zx4....Zx_n
  3517.     Zy1,Zy2,Zy3,Zy4....Zy_n
  3518.    
  3519.     x/y in pixels
  3520.  
  3521. 6 = Ax1,Ax2,Ax3,Ax4....Ax_n
  3522.     Ay1,Ay2,Ay3,Ay4....Ay_n
  3523.     Bx1,Bx2,Bx3,Bx4....Bx_n
  3524.     By1,By2,By3,By4....By_n
  3525.     Cx1,Cx2,Cx3,Cx4....Cx_n
  3526.     Cy1,Cy2,Cy3,Cy4....Cy_n
  3527.     ....
  3528.     Zx1,Zx2,Zx3,Zx4....Zx_n
  3529.     Zy1,Zy2,Zy3,Zy4....Zy_n
  3530.  
  3531.     x/y in  xrange / yrange coordinate system
  3532.    
  3533. 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  3534.    
  3535.     x/y in pixels
  3536.  
  3537. 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  3538.    
  3539.     x/y in  xrange / yrange coordinate system
  3540.  
  3541. 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n    
  3542.  
  3543.     x/y in pixels
  3544.  
  3545. 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n    
  3546.  
  3547.     x/y in  xrange / yrange coordinate system
  3548.  
  3549. 11 = Ax1,Ay1,Ax2,Ay2
  3550.      Bx1,By1,Bx2,By2
  3551.      Cx1,Cy1,Cx2,Cy2
  3552.      Dx1,Dy1,Dx2,Dy2
  3553.      ......
  3554.      Zx1,Zy1,Zx2,Zy2
  3555.      
  3556.     x/y in  xrange / yrange coordinate system
  3557.  
  3558. 12 = Ax1,Ay1,Ax2,Ay2
  3559.      Bx1,By1,Bx2,By2
  3560.      Cx1,Cy1,Cx2,Cy2
  3561.      Dx1,Dy1,Dx2,Dy2
  3562.      ......
  3563.      Zx1,Zy1,Zx2,Zy2
  3564.      
  3565.     x/y in pixels
  3566.  
  3567. 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
  3568.  
  3569.     x/y in  xrange / yrange coordinate system
  3570. 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
  3571.     x/y in pixels
  3572. 15 = reply from inputfields,textareas
  3573.     reply1,reply2,reply3,...,reply_n
  3574.     only fields set write (a.g. will not read 'readonly' inputfield values'
  3575.  
  3576. 16 = read mathml inputfields only
  3577.  
  3578. 17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n
  3579.  when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
  3580.  
  3581. 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
  3582. 19 = return clicked object number (analogue to shape-library onclick)
  3583. 20 = return x/y-data in x-range/y-range of all 'draggable' images
  3584. 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
  3585. 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
  3586.     x/y in  xrange / yrange coordinate system
  3587. 23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
  3588. 24 = read all inputfield values: even those set 'readonly'
  3589. 25 = return all userdrawn arcs in degrees:
  3590. 26 = return all userdrawn arcs in radians:
  3591. 27 = return (only) userdraw inputfields array: x1:y1:text1,x2:y2:text2...
  3592. */
  3593.  
  3594.  
  3595. void add_read_canvas(int type_reply,int reply_precision){
  3596. /* just 1 reply type allowed */
  3597. fprintf(js_include_file,"\
  3598. \n<!-- begin set_reply_precision() -->\n\
  3599. function set_reply_precision(){\
  3600. var len = userdraw_x.length;\
  3601. var prec = %d;\
  3602. for(var p = 0 ; p < len ; p++ ){\
  3603.  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
  3604.  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
  3605. };\
  3606. len = userdraw_radius.length;\
  3607. if( len > 0 ){\
  3608.  for(var p = 0 ; p < len ; p++ ){\
  3609.   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
  3610.  };\
  3611. };\
  3612. };",reply_precision);
  3613.  
  3614. switch(type_reply){
  3615. /*  
  3616. answers may have:
  3617. x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
  3618. */
  3619.     case 1: fprintf(js_include_file,"\
  3620. \n<!-- begin function 1 read_canvas() -->\n\
  3621. read_canvas = function(){\
  3622. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3623. set_reply_precision();\
  3624. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3625.  var p = 0;var input_reply = new Array();\
  3626.  if( document.getElementById(\"canvas_input0\")){\
  3627.   var t = 0;\
  3628.   while(document.getElementById(\"canvas_input\"+t)){\
  3629.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3630.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3631.     p++;\
  3632.    };\
  3633.    t++;\
  3634.   };\
  3635.  };\
  3636.  if( typeof userdraw_text != 'undefined' ){\
  3637.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
  3638.  }\
  3639.  else\
  3640.  {\
  3641.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
  3642.  }\
  3643. }\
  3644. else\
  3645. {\
  3646.  if( typeof userdraw_text != 'undefined' ){\
  3647.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
  3648.  }\
  3649.  else\
  3650.  {\
  3651.   return userdraw_x+\"\\n\"+userdraw_y;\
  3652.  }\
  3653. };\
  3654. };\n\
  3655. <!-- end function 1 read_canvas() -->");
  3656.     break;
  3657.     case 2: fprintf(js_include_file,"\
  3658. \n<!-- begin function 2 read_canvas() -->\n\
  3659. read_canvas = function(){\
  3660. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3661. set_reply_precision();\
  3662. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  3663. var prec = %d;\
  3664. while(userdraw_x[p]){\
  3665.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  3666.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  3667.  p++;\
  3668. };\
  3669. if(p == 0){alert(\"nothing drawn...\");return;};\
  3670. if( document.getElementById(\"canvas_input0\")){\
  3671.  var p = 0;var input_reply = new Array();\
  3672.  if( document.getElementById(\"canvas_input0\")){\
  3673.   var t = 0;\
  3674.   while(document.getElementById(\"canvas_input\"+t)){\
  3675.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3676.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3677.     p++;\
  3678.    };\
  3679.    t++;\
  3680.   };\
  3681.  };\
  3682.  if( typeof userdraw_text != 'undefined' ){\
  3683.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3684.  }\
  3685.  else\
  3686.  {\
  3687.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  3688.  }\
  3689. }\
  3690. else\
  3691. {\
  3692.  if( typeof userdraw_text != 'undefined' ){\
  3693.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  3694.  }\
  3695.  else\
  3696.  {\
  3697.   return reply_x+\"\\n\"+reply_y;\
  3698.  };\
  3699. };\
  3700. };\n\
  3701. <!-- end function 2 read_canvas() -->",reply_precision);
  3702.     break;
  3703.     case 3: fprintf(js_include_file,"\
  3704. \n<!-- begin function 3 read_canvas() -->\n\
  3705. read_canvas = function(){\
  3706. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3707. set_reply_precision();\
  3708. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3709.  var p = 0;var input_reply = new Array();\
  3710.  if( document.getElementById(\"canvas_input0\")){\
  3711.   var t = 0;\
  3712.   while(document.getElementById(\"canvas_input\"+t)){\
  3713.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3714.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3715.     p++;\
  3716.    };\
  3717.    t++;\
  3718.   };\
  3719.  };\
  3720.  if( typeof userdraw_text != 'undefined' ){\
  3721.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3722.  }\
  3723.  else\
  3724.  {\
  3725.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  3726.  }\
  3727. }\
  3728. else\
  3729. {\
  3730.  if( typeof userdraw_text != 'undefined' ){\
  3731.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
  3732.  }\
  3733.  else\
  3734.  {\
  3735.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
  3736.  }\
  3737. }\
  3738. };\n\
  3739. <!-- end function 3 read_canvas() -->");
  3740.     break;
  3741.     case 4: fprintf(js_include_file,"\
  3742. \n<!-- begin function 4 read_canvas() -->\n\
  3743. read_canvas = function(){\
  3744. var prec = %d;\
  3745. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  3746. while(userdraw_x[p]){\
  3747.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  3748.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
  3749.  p++;\
  3750. };\
  3751. if(p == 0){alert(\"nothing drawn...\");return;};\
  3752. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3753.  var p = 0;var input_reply = new Array();\
  3754.  if( document.getElementById(\"canvas_input0\")){\
  3755.   var t = 0;\
  3756.   while(document.getElementById(\"canvas_input\"+t)){\
  3757.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3758.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3759.     p++;\
  3760.    };\
  3761.    t++;\
  3762.   };\
  3763.  };\
  3764.  if( typeof userdraw_text != 'undefined' ){\
  3765.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3766.  }\
  3767.  else\
  3768.  {\
  3769.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  3770.  }\
  3771. }\
  3772. else\
  3773. {\
  3774.  if( typeof userdraw_text != 'undefined' ){\
  3775.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
  3776.  }\
  3777.  else\
  3778.  {\
  3779.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
  3780.  }\
  3781. };\
  3782. };\n\
  3783. <!-- end function 4 read_canvas() -->",reply_precision);
  3784.     break;
  3785.     /*
  3786.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  3787.         used for userdraw multiple paths
  3788.     */
  3789.     case 5: fprintf(js_include_file,"\
  3790. \n<!-- begin function 5 read_canvas() -->\n\
  3791. read_canvas = function(){\
  3792. set_reply_precision();\
  3793. var p = 0;\
  3794. var reply = \"\";\
  3795. for(p = 0; p < userdraw_x.length;p++){\
  3796.  if(userdraw_x[p] != null ){\
  3797.   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
  3798.  };\
  3799. };\
  3800. if(p == 0){alert(\"nothing drawn...\");return;};\
  3801. userdraw_x = [];userdraw_y = [];\
  3802. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3803.  var p = 0;var input_reply = new Array();\
  3804.  if( document.getElementById(\"canvas_input0\")){\
  3805.   var t = 0;\
  3806.   while(document.getElementById(\"canvas_input\"+t)){\
  3807.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3808.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3809.     p++;\
  3810.    };\
  3811.    t++;\
  3812.   };\
  3813.  };\
  3814.  if( typeof userdraw_text != 'undefined' ){\
  3815.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3816.  }\
  3817.  else\
  3818.  {\
  3819.   return reply +\"\\n\"+input_reply;\
  3820.  }\
  3821. }\
  3822. else\
  3823. {\
  3824.  if( typeof userdraw_text != 'undefined' ){\
  3825.   return reply+\"\\n\"+userdraw_text;\
  3826.  }\
  3827.  else\
  3828.  {\
  3829.   return reply;\
  3830.  }\
  3831. };\
  3832. };\n\
  3833. <!-- end function 5 read_canvas() -->");
  3834.     break;
  3835.     /*
  3836.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  3837.         used for userdraw multiple paths
  3838.     */
  3839.     case 6: fprintf(js_include_file,"\
  3840. \n<!-- begin function 6 read_canvas() -->\n\
  3841. read_canvas = function(){\
  3842. var p = 0;\
  3843. var reply = \"\";\
  3844. var tmp_x = new Array();\
  3845. var tmp_y = new Array();\
  3846. var prec = %d;\
  3847. for(p = 0 ; p < userdraw_x.length; p++){\
  3848.  tmp_x = userdraw_x[p];\
  3849.  tmp_y = userdraw_y[p];\
  3850.  if(tmp_x != null){\
  3851.   for(var i = 0 ; i < tmp_x.length ; i++){\
  3852.    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
  3853.    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
  3854.   };\
  3855.   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
  3856.  };\
  3857. };\
  3858. if(p == 0){alert(\"nothing drawn...\");return;};\
  3859. userdraw_x = [];userdraw_y = [];\
  3860. if( document.getElementById(\"canvas_input0\") ){\
  3861.  var p = 0;var input_reply = new Array();\
  3862.  if( document.getElementById(\"canvas_input0\")){\
  3863.   var t = 0;\
  3864.   while(document.getElementById(\"canvas_input\"+t)){\
  3865.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3866.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3867.     p++;\
  3868.    };\
  3869.    t++;\
  3870.   };\
  3871.  };\
  3872.  if( typeof userdraw_text != 'undefined' ){\
  3873.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3874.  }\
  3875.  else\
  3876.  {\
  3877.   return reply +\"\\n\"+input_reply;\
  3878.  }\
  3879. }\
  3880. else\
  3881. {\
  3882.  if( typeof userdraw_text != 'undefined' ){\
  3883.   return reply +\"\\n\"+userdraw_text;\
  3884.  }\
  3885.  else\
  3886.  {\
  3887.   return reply;\
  3888.  }\
  3889. };\
  3890. };\n\
  3891. <!-- end function 6 read_canvas() -->",reply_precision);
  3892.     break;
  3893.     case 7: fprintf(js_include_file,"\
  3894. \n<!-- begin function 7 read_canvas() -->\n\
  3895. read_canvas = function(){\
  3896. set_reply_precision();\
  3897. var reply = new Array();\
  3898. var p = 0;\
  3899. while(userdraw_x[p]){\
  3900.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
  3901.  p++;\
  3902. };\
  3903. if(p == 0){alert(\"nothing drawn...\");return;};\
  3904. if( document.getElementById(\"canvas_input0\") ){\
  3905.  var p = 0;var input_reply = new Array();\
  3906.  if( document.getElementById(\"canvas_input0\")){\
  3907.   var t = 0;\
  3908.   while(document.getElementById(\"canvas_input\"+t)){\
  3909.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3910.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3911.     p++;\
  3912.    };\
  3913.    t++;\
  3914.   };\
  3915.  };\
  3916.  if( typeof userdraw_text != 'undefined' ){\
  3917.   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3918.  }\
  3919.  else\
  3920.  {\
  3921.   return reply+\"\\n\"+input_reply;\
  3922.  }\
  3923. }\
  3924. else\
  3925. {\
  3926.  if( typeof userdraw_text != 'undefined' ){\
  3927.   return reply+\"\\n\"+userdraw_text;\
  3928.  }\
  3929.  else\
  3930.  {\
  3931.   return reply;\
  3932.  }\
  3933. };\
  3934. };\n\
  3935. <!-- end function 7 read_canvas() -->");
  3936.     break;
  3937.     case 8: fprintf(js_include_file,"\
  3938. \n<!-- begin function 8 read_canvas() -->\n\
  3939. read_canvas = function(){\
  3940. var reply = new Array();\
  3941. var p = 0;\
  3942. var prec = %d;\
  3943. while(userdraw_x[p]){\
  3944.  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  3945.  p++;\
  3946. };\
  3947. if(p == 0){alert(\"nothing drawn...\");return;};\
  3948. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3949.  var p = 0;var input_reply = new Array();\
  3950.  if( document.getElementById(\"canvas_input0\")){\
  3951.   var t = 0;\
  3952.   while(document.getElementById(\"canvas_input\"+t)){\
  3953.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3954.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3955.     p++;\
  3956.    };\
  3957.    t++;\
  3958.   };\
  3959.  };\
  3960.  if( typeof userdraw_text != 'undefined' ){\
  3961.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3962.  }\
  3963.  else\
  3964.  {\
  3965.   return reply +\"\\n\"+input_reply;\
  3966.  }\
  3967. }\
  3968. else\
  3969. {\
  3970.  if( typeof userdraw_text != 'undefined' ){\
  3971.   return reply +\"\\n\"+userdraw_text;\
  3972.  }\
  3973.  else\
  3974.  {\
  3975.   return reply;\
  3976.  }\
  3977. };\
  3978. };\n\
  3979. <!-- end function 8 read_canvas() -->",reply_precision);
  3980.     break;
  3981.     case 9: fprintf(js_include_file,"\
  3982. \n<!-- begin function 9 read_canvas() -->\n\
  3983. read_canvas = function(){\
  3984. set_reply_precision();\
  3985. var reply = new Array();\
  3986. var p = 0;\
  3987. while(userdraw_x[p]){\
  3988.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
  3989.  p++;\
  3990. };\
  3991. if(p == 0){alert(\"nothing drawn...\");return;};\
  3992. if( document.getElementById(\"canvas_input0\") ){\
  3993.  var p = 0;var input_reply = new Array();\
  3994.  if( document.getElementById(\"canvas_input0\")){\
  3995.   var t = 0;\
  3996.   while(document.getElementById(\"canvas_input\"+t)){\
  3997.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3998.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3999.     p++;\
  4000.    };\
  4001.    t++;\
  4002.   };\
  4003.  };\
  4004.  if( typeof userdraw_text != 'undefined' ){\
  4005.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4006.  }\
  4007.  else\
  4008.  {\
  4009.   return reply +\"\\n\"+input_reply;\
  4010.  }\
  4011. }\
  4012. else\
  4013. {\
  4014.  if( typeof userdraw_text != 'undefined' ){\
  4015.   return reply +\"\\n\"+userdraw_text;\
  4016.  }\
  4017.  else\
  4018.  {\
  4019.   return reply;\
  4020.  }\
  4021. };\
  4022. };\n\
  4023. <!-- end function 9 read_canvas() -->");
  4024.     break;
  4025.     case 10: fprintf(js_include_file,"\
  4026. \n<!-- begin function 10 read_canvas() -->\n\
  4027. read_canvas = function(){\
  4028. var reply = new Array();\
  4029. var p = 0;\
  4030. var prec = %d;\
  4031. while(userdraw_x[p]){\
  4032.  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;\
  4033.  p++;\
  4034. };\
  4035. if(p == 0){alert(\"nothing drawn...\");return;};\
  4036. if( document.getElementById(\"canvas_input0\") ){\
  4037.  var p = 0;var input_reply = new Array();\
  4038.  if( document.getElementById(\"canvas_input0\")){\
  4039.   var t = 0;\
  4040.   while(document.getElementById(\"canvas_input\"+t)){\
  4041.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4042.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4043.     p++;\
  4044.    };\
  4045.    t++;\
  4046.   };\
  4047.  };\
  4048.  if( typeof userdraw_text != 'undefined' ){\
  4049.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4050.  }\
  4051.  else\
  4052.  {\
  4053.   return reply +\"\\n\"+input_reply;\
  4054.  }\
  4055. }\
  4056. else\
  4057. {\
  4058.  if( typeof userdraw_text != 'undefined' ){\
  4059.   return reply +\"\\n\"+userdraw_text;\
  4060.  }\
  4061.  else\
  4062.  {\
  4063.   return reply;\
  4064.  }\
  4065. };\
  4066. };\n\
  4067. <!-- end function 10 read_canvas() -->",reply_precision);
  4068.     break;
  4069.     case 11: fprintf(js_include_file,"\
  4070. \n<!-- begin function 11 read_canvas() -->\n\
  4071. read_canvas = function(){\
  4072. var reply = \"\";\
  4073. var p = 0;\
  4074. var prec = %d;\
  4075. while(userdraw_x[p]){\
  4076.  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\" ;\
  4077.  p = p+2;\
  4078. };\
  4079. if(p == 0){alert(\"nothing drawn...\");return;};\
  4080. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  4081.  var p = 0;var input_reply = new Array();\
  4082.  if( document.getElementById(\"canvas_input0\")){\
  4083.   var t = 0;\
  4084.   while(document.getElementById(\"canvas_input\"+t)){\
  4085.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4086.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4087.     p++;\
  4088.    };\
  4089.    t++;\
  4090.   };\
  4091.  };\
  4092.  if( typeof userdraw_text != 'undefined' ){\
  4093.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4094.  }\
  4095.  else\
  4096.  {\
  4097.   return reply +\"\\n\"+input_reply;\
  4098.  }\
  4099. }\
  4100. else\
  4101. {\
  4102.  if( typeof userdraw_text != 'undefined' ){\
  4103.   return reply +\"\\n\"+userdraw_text;\
  4104.  }\
  4105.  else\
  4106.  {\
  4107.   return reply;\
  4108.  }\
  4109. };\
  4110. };\n\
  4111. <!-- end function 11 read_canvas() -->",reply_precision);
  4112.     break;
  4113.     case 12: fprintf(js_include_file,"\
  4114. \n<!-- begin function 12 read_canvas() -->\n\
  4115. read_canvas = function(){\
  4116. set_reply_precision();\
  4117. var reply = \"\";\
  4118. var p = 0;\
  4119. for(p = 0; p< userdraw_x.lenght;p = p+2){\
  4120.  if(userdraw_x[p] != null){\
  4121.    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
  4122.  };\
  4123. };\
  4124. if(p == 0){alert(\"nothing drawn...\");return;};\
  4125. if( document.getElementById(\"canvas_input0\") ){\
  4126.  var p = 0;var input_reply = new Array();\
  4127.  if( document.getElementById(\"canvas_input0\")){\
  4128.   var t = 0;\
  4129.   while(document.getElementById(\"canvas_input\"+t)){\
  4130.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4131.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4132.     p++;\
  4133.    };\
  4134.    t++;\
  4135.   };\
  4136.  };\
  4137.  if( typeof userdraw_text != 'undefined' ){\
  4138.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4139.  }\
  4140.  else\
  4141.  {\
  4142.   return reply +\"\\n\"+input_reply;\
  4143.  }\
  4144. }\
  4145. else\
  4146. {\
  4147.  if( typeof userdraw_text != 'undefined' ){\
  4148.   return reply +\"\\n\"+userdraw_text\
  4149.  }\
  4150.  else\
  4151.  {\
  4152.   return reply;\
  4153.  }\
  4154. };\
  4155. };\n\
  4156. <!-- end function 12 read_canvas() -->");
  4157.     break;
  4158.     case 13: fprintf(js_include_file,"\
  4159. \n<!-- begin function 13 read_canvas() -->\n\
  4160. read_canvas = function(){\
  4161. var reply = new Array();\
  4162. var p = 0;var i = 0;\
  4163. var prec = %d;\
  4164. while(userdraw_x[p]){\
  4165.  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;\
  4166.  p = p+2;i++;\
  4167. };\
  4168. if(p == 0){alert(\"nothing drawn...\");return;};\
  4169. if( document.getElementById(\"canvas_input0\") ){\
  4170.  var p = 0;var input_reply = new Array();\
  4171.  if( document.getElementById(\"canvas_input0\")){\
  4172.   var t = 0;\
  4173.   while(document.getElementById(\"canvas_input\"+t)){\
  4174.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4175.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4176.     p++;\
  4177.    };\
  4178.    t++;\
  4179.   };\
  4180.  };\
  4181.  if( typeof userdraw_text != 'undefined' ){\
  4182.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4183.  }\
  4184.  else\
  4185.  {\
  4186.   return reply +\"\\n\"+input_reply;\
  4187.  }\
  4188. }\
  4189. else\
  4190. {\
  4191.  if( typeof userdraw_text != 'undefined' ){\
  4192.   return reply +\"\\n\"+userdraw_text\
  4193.  }\
  4194.  else\
  4195.  {\
  4196.   return reply;\
  4197.  }\
  4198. };\
  4199. };\n\
  4200. <!-- end function 13 read_canvas() -->",reply_precision);
  4201.     break;
  4202.     case 14: fprintf(js_include_file,"\
  4203. \n<!-- begin function 14 read_canvas() -->\n\
  4204. read_canvas = function(){\
  4205. set_reply_precision();\
  4206. var reply = new Array();\
  4207. var p = 0;var i = 0;\
  4208. while(userdraw_x[p]){\
  4209.  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
  4210.  p = p+2;i++;\
  4211. };\
  4212. if(p == 0){alert(\"nothing drawn...\");return;};\
  4213. if( document.getElementById(\"canvas_input0\") ){\
  4214.  var p = 0;var input_reply = new Array();\
  4215.  if( document.getElementById(\"canvas_input0\")){\
  4216.   var t = 0;\
  4217.   while(document.getElementById(\"canvas_input\"+t)){\
  4218.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4219.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4220.     p++;\
  4221.    };\
  4222.    t++;\
  4223.   };\
  4224.  };\
  4225.  if( typeof userdraw_text != 'undefined' ){\
  4226.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4227.  }\
  4228.  else\
  4229.  {\
  4230.   return reply +\"\\n\"+input_reply;\
  4231.  }\
  4232. }\
  4233. else\
  4234. {\
  4235.  if( typeof userdraw_text != 'undefined' ){\
  4236.   return reply +\"\\n\"+userdraw_text;\
  4237.  }\
  4238.  else\
  4239.  {\
  4240.   return reply;\
  4241.  }\
  4242. };\
  4243. };\n\
  4244. <!-- end function 14 read_canvas() -->");
  4245.     break;
  4246.     case 15: fprintf(js_include_file,"\
  4247. \n<!-- begin function 15  read_canvas() -->\n\
  4248. read_canvas = function(){\
  4249. var input_reply = new Array();\
  4250. var p = 0;\
  4251. if( document.getElementById(\"canvas_input0\")){\
  4252.  var t = 0;\
  4253.  while(document.getElementById(\"canvas_input\"+t)){\
  4254.   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4255.    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4256.    p++;\
  4257.   };\
  4258.   t++;\
  4259.  };\
  4260. };\
  4261. if( typeof userdraw_text != 'undefined' ){\
  4262.   return input_reply +\"\\n\"+userdraw_text;\
  4263. }\
  4264. else\
  4265. {\
  4266.  return input_reply;\
  4267. };\
  4268. };\n\
  4269. <!-- end function 15 read_canvas() -->");
  4270.     break;
  4271.     case 16: fprintf(js_include_file,"\
  4272. \n<!-- begin function 16 read_mathml() -->\n\
  4273. function read_mathml(){\
  4274. var reply = new Array();\
  4275. var p = 0;\
  4276. if( document.getElementById(\"mathml0\")){\
  4277.  while(document.getElementById(\"mathml\"+p)){\
  4278.   reply[p] = document.getElementById(\"mathml\"+p).value;\
  4279.   p++;\
  4280.  };\
  4281. };\
  4282. return reply;\
  4283. };\
  4284. this.read_mathml = read_mathml;\n\
  4285. <!-- end function 16 read_mathml() -->");
  4286.     break;
  4287.     case 17:  fprintf(js_include_file,"\
  4288. \n<!-- begin function 17 read_canvas() -->\n\
  4289. read_canvas = function(){\
  4290. if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\
  4291. return userdraw_text;\
  4292. };\n\
  4293. <!-- end function 17 read_canvas() -->");
  4294.     break;
  4295.     case 18: fprintf(js_include_file,"\
  4296. \n<!-- begin function 18 read_canvas() -->\n\
  4297. read_canvas = function(){\
  4298. var p = 0;\
  4299. var reply = new Array();\
  4300. var name;\
  4301. var t = true;\
  4302. var h;var m;var s;\
  4303. while(t){\
  4304.  try{\
  4305.   name = eval('clocks'+p);\
  4306.   h = name.H;m = name.M;s = name.S;\
  4307.   if(s < 0){s = 60 + s;m = m - 1;};\
  4308.   if(m < 0){m = 60 + m;h = h - 1;};\
  4309.   if(h < 0){h = 12 + h;};\
  4310.   h = parseInt((h+m/60+s/3600)%%12);m = parseInt((m + s/60)%%60);s = parseInt(s%%60);\
  4311.   reply[p] = h+\":\"+m+\":\"+s;\
  4312.   p++;\
  4313.  }catch(e){t=false;};\
  4314. };\
  4315. if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
  4316. return reply;\
  4317. };\n\
  4318. <!-- end function 18 read_canvas() -->");
  4319.     break;
  4320.     case 19: fprintf(js_include_file,"\
  4321. \n<!-- begin function 19 read_canvas() -->\n\
  4322. read_canvas = function(){\
  4323. return reply[0];\
  4324. };\n\
  4325. <!-- end function 19 read_canvas() -->");
  4326.     case 20: fprintf(js_include_file,"\
  4327. \n<!-- begin function 20 read_canvas() -->\n\
  4328. read_canvas = function(){\
  4329. var prec = %d;\
  4330. var len  = ext_drag_images.length;\
  4331. var reply = new Array(len);\
  4332. for(var p = 0 ; p < len ; p++){\
  4333.    var img = ext_drag_images[p];\
  4334.    reply[p] = (Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  4335. };\
  4336. return reply;\
  4337. };\n\
  4338. <!-- end function 20 read_canvas() -->",reply_precision);
  4339.     break;
  4340.     case 21: fprintf(js_include_file,"\
  4341. \n<!-- begin function 21 read_canvas() -->\n\
  4342. read_canvas = function(){\
  4343. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  4344. var reply_coord = new Array();var p = 0;\
  4345. var prec = %d;\
  4346. while(userdraw_x[p]){\
  4347.  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
  4348.  p++;\
  4349. };\
  4350. if(p == 0){alert(\"nothing drawn...\");return;};\
  4351. if( document.getElementById(\"canvas_input0\") ){\
  4352.  var p = 0;var input_reply = new Array();\
  4353.  if( document.getElementById(\"canvas_input0\")){\
  4354.   var t = 0;\
  4355.   while(document.getElementById(\"canvas_input\"+t)){\
  4356.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4357.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4358.     p++;\
  4359.    };\
  4360.    t++;\
  4361.   };\
  4362.  };\
  4363.  if( typeof userdraw_text != 'undefined' ){\
  4364.   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4365.  }\
  4366.  else\
  4367.  {\
  4368.   return reply_coord+\"\\n\"+input_reply;\
  4369.  }\
  4370. }\
  4371. else\
  4372. {\
  4373.  if( typeof userdraw_text != 'undefined' ){\
  4374.   return reply_coord+\"\\n\"+userdraw_text;\
  4375.  }\
  4376.  else\
  4377.  {\
  4378.   return reply_coord;\
  4379.  };\
  4380. };\
  4381. };\n\
  4382. <!-- end function 21 read_canvas() -->",reply_precision);
  4383.     break;
  4384.     case 22: fprintf(js_include_file,"\
  4385. \n<!-- begin function 22 read_canvas() -->\n\
  4386. read_canvas = function(){\
  4387. var reply = new Array();\
  4388. var lu = userdraw_x.length;\
  4389. if(lu == 0){alert(\"nothing drawn...\");return;};\
  4390. var idx = 0;\
  4391. var prec = %d;\
  4392. for(var p = 0 ; p < lu ; p++){\
  4393.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
  4394.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
  4395. };\
  4396. if( document.getElementById(\"canvas_input0\") ){\
  4397.  var p = 0;var input_reply = new Array();\
  4398.  if( document.getElementById(\"canvas_input0\")){\
  4399.   var t = 0;\
  4400.   while(document.getElementById(\"canvas_input\"+t)){\
  4401.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4402.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4403.     p++;\
  4404.    };\
  4405.    t++;\
  4406.   };\
  4407.  };\
  4408.  if( typeof userdraw_text != 'undefined' ){\
  4409.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4410.  }\
  4411.  else\
  4412.  {\
  4413.   return reply +\"\\n\"+input_reply;\
  4414.  }\
  4415. }\
  4416. else\
  4417. {\
  4418.  if( typeof userdraw_text != 'undefined' ){\
  4419.   return reply +\"\\n\"+userdraw_text;\
  4420.  }\
  4421.  else\
  4422.  {\
  4423.   return reply;\
  4424.  }\
  4425. };\
  4426. };\n\
  4427. <!-- end function 22 read_canvas() -->",reply_precision);
  4428.     break;
  4429.     case 23: fprintf(js_include_file,"\
  4430. \n<!-- begin function 23 read_canvas() default 5 px marge -->\n\
  4431. read_canvas = function(){\
  4432. if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
  4433. var lu = userdraw_x.length;\
  4434. if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
  4435. var reply_x = new Array();var reply_y = new Array();\
  4436. var marge = 5;var p = 0;\
  4437. var prec = %d;\
  4438. for(var i = 0; i < lu - 1 ; i++ ){\
  4439.  if( Math.abs(userdraw_x[i] - userdraw_x[i+1])){\
  4440.   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
  4441.   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
  4442.   p++;\
  4443.  };\
  4444.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\
  4445. };\
  4446. if( document.getElementById(\"canvas_input0\")){\
  4447.  var p = 0;var input_reply = new Array();\
  4448.  if( document.getElementById(\"canvas_input0\")){\
  4449.   var t = 0;\
  4450.   while(document.getElementById(\"canvas_input\"+t)){\
  4451.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  4452.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  4453.     p++;\
  4454.    };\
  4455.    t++;\
  4456.   };\
  4457.  };\
  4458.  if( typeof userdraw_text != 'undefined' ){\
  4459.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  4460.  }\
  4461.  else\
  4462.  {\
  4463.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  4464.  }\
  4465. }\
  4466. else\
  4467. {\
  4468.  if( typeof userdraw_text != 'undefined' ){\
  4469.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  4470.  }\
  4471.  else\
  4472.  {\
  4473.   return reply_x+\"\\n\"+reply_y;\
  4474.  };\
  4475. };\
  4476. };\n\
  4477. <!-- end function 23 read_canvas() -->",reply_precision);
  4478.     break;
  4479.     case 24: fprintf(js_include_file,"\n\
  4480. <!-- begin function 24  read_canvas() -->\n\
  4481. read_canvas = function(){\
  4482. var input_reply = new Array();\
  4483. var p = 0;\
  4484. if( document.getElementById(\"canvas_input0\")){\
  4485.  while(document.getElementById(\"canvas_input\"+p)){\
  4486.    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
  4487.    p++;\
  4488.  };\
  4489.  return input_reply;\
  4490. };\
  4491. };\n\
  4492. <!-- end function 24 read_canvas() -->");
  4493.     break;
  4494.     case 25:
  4495.     fprintf(js_include_file,"\n<!-- begin function 25 read_canvas() : angle(s) in degrees-->\n\
  4496. read_canvas = function(){\
  4497. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  4498. var lu = userdraw_radius.length;\
  4499. var prec = %d;\
  4500. var angle_reply = new Array(lu);\
  4501. for(var p = 0 ; p < lu ; p++){\
  4502.  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
  4503. };\
  4504. return angle_reply;\
  4505. };\n\
  4506. <!-- end function 25 read_canvas() -->",reply_precision);
  4507.     break;
  4508.     case 26:
  4509.     fprintf(js_include_file,"\n<!-- begin function 26 read_canvas() : angle(s) in radians-->\n\
  4510. read_canvas = function(){\
  4511. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  4512. var lu = userdraw_radius.length;\
  4513. var prec = %d;\
  4514. var angle_reply = new Array(lu);\
  4515. for(var p = 0 ; p < lu ; p++){\
  4516.  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
  4517. };\
  4518. return angle_reply;\
  4519. };\n\
  4520. <!-- end function 26 read_canvas() -->",reply_precision);
  4521.     break;
  4522.     case 27:
  4523.     fprintf(js_include_file,"\n<!-- begin function 27 read_canvas()  : inputfield(s) location and their values : -->\n\
  4524. read_canvas = function(){\
  4525. var lu = userdraw_x.length;\
  4526. if( lu < 1){alert(\"nothing drawn...\");return;}\
  4527. set_reply_precision();\
  4528. var prec = %d;\
  4529. for(var p = 0 ; p < lu ; p++){\
  4530.   reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\":\"+ document.getElementById(\"canvas_input\"+p).value;\
  4531. };\
  4532. return reply;\
  4533. };\n\
  4534. <!-- end function 27 read_canvas() -->",reply_precision);    
  4535.     break;
  4536.     default: canvas_error("hmmm unknown replyformat...");break;
  4537. }
  4538.  return;
  4539. }
  4540.  
  4541.  
  4542. /*
  4543.  add drawfunction :
  4544.  - functions used by userdraw_primitives (circle,rect,path,triangle...)
  4545.  - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
  4546.  - grid / mathml
  4547.  - will not scale or zoom in
  4548.  - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
  4549.  - is printed directly into 'js_include_file'
  4550. */
  4551.  
  4552. void add_javascript_functions(int js_functions[],int canvas_root_id){
  4553. int i;
  4554. for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
  4555.  if( js_functions[i] == 1){
  4556.     switch(i){
  4557.     case DRAG_EXTERNAL_IMAGE:
  4558. fprintf(js_include_file,"\n<!-- drag external images --->\n\
  4559. var external_canvas = create_canvas%d(7,xsize,ysize);\
  4560. var external_ctx = external_canvas.getContext(\"2d\");\
  4561. var external_canvas_rect = external_canvas.getBoundingClientRect();\
  4562. canvas_div.addEventListener(\"mousedown\",setxy,false);\
  4563. canvas_div.addEventListener(\"mouseup\",dragstop,false);\
  4564. canvas_div.addEventListener(\"mousemove\",dragxy,false);\
  4565. var selected_image = null;\
  4566. var ext_image_cnt = 0;\
  4567. var ext_drag_images = new Array();\
  4568. function drag_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,draggable){\
  4569. ext_image_cnt = idx;\
  4570. var image = new Image();\
  4571. image.src = URL;\
  4572. image.onload = function(){\
  4573.  if( x0 < 1 ){ x0 = 0; };if( y0 < 1 ){ y0 = 0; };if( sx < 1 ){ sx = 0; };if( sy < 1 ){ sy = 0; };\
  4574.  if( width < 1 ){ width = image.width; };if( height < 1 ){ height = image.height; };\
  4575.  if( swidth < 1 ){ swidth = image.width; };if( sheight < 1 ){ sheight = image.height; };\
  4576.  var img = new Array(10);\
  4577.  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
  4578.  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;\
  4579.  ext_drag_images[idx] = img;\
  4580.  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  4581. };\
  4582. };\
  4583. function dragstop(evt){\
  4584. selected_image = null;return;\
  4585. };\
  4586. function dragxy(evt){\
  4587. if( selected_image != null ){\
  4588.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  4589.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  4590.  var s_img = ext_drag_images[selected_image];\
  4591.  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\
  4592.  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\
  4593.  ext_drag_images[selected_image] = s_img;\
  4594.  external_ctx.clearRect(0,0,xsize,ysize);\
  4595.  for(var i = 0; i <= ext_image_cnt ; i++){\
  4596.   var img = ext_drag_images[i];\
  4597.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  4598.  };\
  4599. };\
  4600. };\
  4601. function setxy(evt){\
  4602. if( ! selected_image && evt.which == 1 ){\
  4603.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  4604.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  4605.  var xm = evt.clientX - external_canvas_rect.left + xoff;\
  4606.  var ym = evt.clientY - external_canvas_rect.top + yoff;\
  4607.  for(var p = 0 ; p <= ext_image_cnt ; p++){\
  4608.   var img = ext_drag_images[p];\
  4609.   if( img[0] == 1 ){\
  4610.    var w = img.width;\
  4611.    var h = img.height;\
  4612.    if( xm > img[6] && xm < img[6] + img[4]){\
  4613.     if( ym > img[7] && ym < img[7] + img[5]){\
  4614.      img[6] = xm;\
  4615.      img[7] = ym;\
  4616.      ext_drag_images[p] = img;\
  4617.      selected_image = p;\
  4618.      dragxy(evt);\
  4619.     };\
  4620.    };\
  4621.   };\
  4622.  };\
  4623. }\
  4624. else\
  4625. {\
  4626.  selected_image = null;\
  4627. };\
  4628. };",canvas_root_id);
  4629.     break;
  4630.  
  4631.     case DRAW_EXTERNAL_IMAGE:
  4632. fprintf(js_include_file,"\n<!-- draw external images -->\n\
  4633. var draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\
  4634. var image = new Image();\
  4635. image.src = URL;\
  4636. var canvas_bg_div = document.getElementById(\"canvas_div%d\");\
  4637. image.onload = function(){\
  4638.  if( x0 < 1 ){ x0 = 0; };\
  4639.  if( y0 < 1 ){ y0 = 0; };\
  4640.  if( sx < 1 ){ sx = 0; };\
  4641.  if( sy < 1 ){ sy = 0; };\
  4642.  if( width < 1 ){ width = image.width;};\
  4643.  if( height < 1 ){ height = image.height;};\
  4644.  if( swidth < 1 ){ swidth = image.width;};\
  4645.  if( sheight < 1 ){ sheight = image.height;};\
  4646.  var ml = x0 - sx;\
  4647.  var mh = y0 - sy;\
  4648.  canvas_bg_div.style.backgroundPosition= \"left \"+ml+\"px top \"+mh+\"px\";\
  4649.  canvas_bg_div.style.backgroundSize = width+\"px \"+height+\"px\";\
  4650.  canvas_bg_div.style.backgroundRepeat = \"no-repeat\";\
  4651.  canvas_bg_div.style.backgroundPosition= sx+\"px \"+sy+\"px\";\
  4652.  canvas_bg_div.style.backgroundImage = \"url(\" + URL + \")\";\
  4653. };\
  4654. };",canvas_root_id);    
  4655.     break;
  4656.     case DRAW_GRIDFILL:/* not used for userdraw */
  4657. fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
  4658. var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\
  4659. var obj;\
  4660. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4661.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4662. }\
  4663. else\
  4664. {\
  4665.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4666. };\
  4667. var ctx = obj.getContext(\"2d\");\
  4668. var x,y;\
  4669. snap_x = dx;snap_y = dy;\
  4670. ctx.save();\
  4671. ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  4672. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  4673.    ctx.moveTo(x,y0);\
  4674.    ctx.lineTo(x,ysize);\
  4675. };\
  4676. for( y = y0 ; y < ysize+dy; y = y + dy ){\
  4677.    ctx.moveTo(x0,y);\
  4678.    ctx.lineTo(xsize,y);\
  4679. };\
  4680. ctx.stroke();\
  4681. ctx.restore();\
  4682. return;};",canvas_root_id,canvas_root_id,canvas_root_id);
  4683.     break;
  4684.    
  4685.     case DRAW_IMAGEFILL:/* not  used for userdraw */
  4686. fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
  4687. var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\
  4688. var obj;\
  4689. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4690.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4691. }\
  4692. else\
  4693. {\
  4694.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4695. };\
  4696. var ctx = obj.getContext(\"2d\");\
  4697. ctx.save();\
  4698. var img = new Image();\
  4699. img.src = URL;\
  4700. img.onload = function(){\
  4701.  if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\
  4702.    ctx.drawImage(img,x0,y0,xsize,ysize);\
  4703.  }\
  4704.  else\
  4705.  {\
  4706.    var repeat = \"repeat\";\
  4707.    if(img.width > xsize - x0){\
  4708.         repeat = \"repeat-y\";\
  4709.    }\
  4710.    else\
  4711.    {\
  4712.     if( img.height > ysize -x0 ){\
  4713.      repeat = \"repeat-x\";\
  4714.     }\
  4715.    }\
  4716.    var pattern = ctx.createPattern(img,repeat);\
  4717.    ctx.rect(x0,y0,xsize,ysize);\
  4718.    ctx.fillStyle = pattern;\
  4719.  }\
  4720.  ctx.fill();\
  4721. };\
  4722. ctx.restore();\
  4723. return;\
  4724. };",canvas_root_id,canvas_root_id,canvas_root_id);
  4725.     break;
  4726.    
  4727.     case DRAW_DOTFILL:/* not  used for userdraw */
  4728. fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
  4729. var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\
  4730. var obj;\
  4731. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4732.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4733. }\
  4734. else\
  4735. {\
  4736.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4737. };\
  4738. var ctx = obj.getContext(\"2d\");\
  4739. var x,y;\
  4740. ctx.closePath();\
  4741. ctx.save();\
  4742. snap_x = dx;snap_y = dy;\
  4743. ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  4744. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  4745.  for( y = y0 ; y < ysize+dy ; y = y + dy ){\
  4746.   ctx.arc(x,y,radius,0,2*Math.PI,false);\
  4747.   ctx.closePath();\
  4748.  }\
  4749. }\
  4750. ctx.fill();\
  4751. ctx.restore();\
  4752. return;};",canvas_root_id,canvas_root_id,canvas_root_id);
  4753.     break;
  4754.  
  4755.     case DRAW_DIAMONDFILL:/* not used for userdraw */
  4756. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  4757. var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  4758.  var obj;\
  4759. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4760.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4761. }\
  4762. else\
  4763. {\
  4764.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4765. };\
  4766. var ctx = obj.getContext(\"2d\");\
  4767. var x;\
  4768. var y;\
  4769. ctx.save();\
  4770. ctx.lineWidth = linewidth;\
  4771. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4772. y = ysize;\
  4773. for( x = x0 ; x < xsize ; x = x + dx ){\
  4774.  ctx.moveTo(x,y0);\
  4775.  ctx.lineTo(xsize,y);\
  4776.  y = y - dy;\
  4777. };\
  4778. y = y0;\
  4779. for( x = xsize ; x > 0 ; x = x - dx){\
  4780.  ctx.moveTo(x,ysize);\
  4781.  ctx.lineTo(x0,y);\
  4782.  y = y + dy;\
  4783. };\
  4784. x = x0;\
  4785. for( y = y0 ; y < ysize ; y = y + dy ){\
  4786.  ctx.moveTo(xsize,y);\
  4787.  ctx.lineTo(x,ysize);\
  4788.  x = x + dx;\
  4789. };\
  4790. x = xsize;\
  4791. for( y = ysize ; y > y0 ; y = y - dy ){\
  4792.  ctx.moveTo(x,y0);\
  4793.  ctx.lineTo(x0,y);\
  4794.  x = x - dx;\
  4795. };\
  4796. ctx.stroke();\
  4797. ctx.restore();\
  4798. return;\
  4799. }",canvas_root_id,canvas_root_id,canvas_root_id);
  4800.     break;
  4801.    
  4802.     case DRAW_HATCHFILL:/* not used for userdraw */
  4803. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  4804. var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  4805.  var obj;\
  4806. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4807.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4808. }\
  4809. else\
  4810. {\
  4811.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4812. };\
  4813. var ctx = obj.getContext(\"2d\");\
  4814. var x;\
  4815. var y;\
  4816. ctx.save();\
  4817. ctx.lineWidth = linewidth;\
  4818. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4819. y = ysize;\
  4820. for( x = x0 ; x < xsize ; x = x + dx ){\
  4821.  ctx.moveTo(x,y0);\
  4822.  ctx.lineTo(xsize,y);\
  4823.  y = y - dy;\
  4824. };\
  4825. y = y0;\
  4826. for( x = xsize ; x >= dx ; x = x - dx){\
  4827.  ctx.moveTo(x,ysize);\
  4828.  ctx.lineTo(x0,y);\
  4829.  y = y + dy;\
  4830. };\
  4831. ctx.stroke();\
  4832. ctx.restore();\
  4833. return;\
  4834. };",canvas_root_id,canvas_root_id,canvas_root_id);
  4835.     break;
  4836.     case DRAW_CIRCLES:/*  used for userdraw */
  4837. fprintf(js_include_file,"\n<!-- draw circles -->\n\
  4838. 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){\
  4839. ctx.save();\
  4840. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4841. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4842. ctx.lineWidth = line_width;\
  4843. for(var p = 0 ; p < x_points.length ; p++ ){\
  4844.  ctx.beginPath();\
  4845.  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
  4846.  ctx.closePath();\
  4847.  if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4848.  if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  4849.  ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4850.  ctx.stroke();\
  4851. }\
  4852. ctx.restore();\
  4853. return;\
  4854. };");
  4855.     break;
  4856.     case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
  4857. fprintf(js_include_file,"\n<!-- draw polyline -->\n\
  4858. 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){\
  4859. ctx.save();\
  4860. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4861. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4862. ctx.lineWidth = line_width;\
  4863. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4864. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4865. ctx.clearRect(0,0,xsize,ysize);\
  4866. ctx.beginPath();\
  4867. for(var p = 0 ; p < x_points.length-1 ; p++ ){\
  4868.  ctx.moveTo(x_points[p],y_points[p]);\
  4869.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  4870. }\
  4871. ctx.closePath();\
  4872. ctx.stroke();\
  4873. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4874. for(var p = 0 ; p < x_points.length ; p++ ){\
  4875.  ctx.beginPath();\
  4876.  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
  4877.  ctx.closePath();ctx.fill();ctx.stroke();\
  4878. };\
  4879. ctx.restore();\
  4880. return;\
  4881. };");
  4882.     break;
  4883.    
  4884.     case DRAW_SEGMENTS:/*  used for userdraw */
  4885. fprintf(js_include_file,"\n<!-- draw segments -->\n\
  4886. 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){\
  4887. ctx.save();\
  4888. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4889. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4890. ctx.lineWidth = line_width;\
  4891. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4892. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4893. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  4894.  ctx.beginPath();\
  4895.  ctx.moveTo(x_points[p],y_points[p]);\
  4896.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  4897.  ctx.closePath();\
  4898.  ctx.stroke();\
  4899.  }\
  4900.  ctx.restore();\
  4901.  return;\
  4902. };");
  4903.     break;
  4904.    
  4905.     case DRAW_LINES:/*  used for userdraw */
  4906. fprintf(js_include_file,"\n<!-- draw lines -->\n\
  4907. function calc_line(x1,x2,y1,y2){\
  4908. var marge = 2;\
  4909. if(x1 < x2+marge && x1>x2-marge){\
  4910.  return [x1,0,x1,ysize];\
  4911. };\
  4912. if(y1 < y2+marge && y1>y2-marge){\
  4913.  return [0,y1,xsize,y1];\
  4914. };\
  4915. var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
  4916. var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
  4917. return [0,Y1,xsize,Y2];\
  4918. };\
  4919. 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){\
  4920. ctx.save();\
  4921. var line = new Array(4);\
  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. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4927. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  4928.  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
  4929.  ctx.beginPath();\
  4930.  ctx.moveTo(line[0],line[1]);\
  4931.  ctx.lineTo(line[2],line[3]);\
  4932.  ctx.closePath();\
  4933.  ctx.stroke();\
  4934.  }\
  4935.  ctx.restore();\
  4936.  return;\
  4937. };");
  4938.     break;
  4939.  
  4940.     case DRAW_CROSSHAIRS:/*  used for userdraw */
  4941. fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
  4942. var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\
  4943. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4944. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4945. ctx.lineWidth = line_width;\
  4946. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4947. var x1,x2,y1,y2;\
  4948. for(var p = 0 ; p < x_points.length ; p++ ){\
  4949.  x1 = x_points[p] - crosshair_size;\
  4950.  x2 = x_points[p] + crosshair_size;\
  4951.  y1 = y_points[p] - crosshair_size;\
  4952.  y2 = y_points[p] + crosshair_size;\
  4953.  ctx.beginPath();\
  4954.  ctx.moveTo(x1,y1);\
  4955.  ctx.lineTo(x2,y2);\
  4956.  ctx.closePath();\
  4957.  ctx.stroke();\
  4958.  ctx.beginPath();\
  4959.  ctx.moveTo(x2,y1);\
  4960.  ctx.lineTo(x1,y2);\
  4961.  ctx.closePath();\
  4962.  ctx.stroke();\
  4963. }\
  4964. ctx.restore();\
  4965.  return;\
  4966. };");
  4967.     break;
  4968.  
  4969.     case DRAW_RECTS:/*  used for userdraw */
  4970. fprintf(js_include_file,"\n<!-- draw rects -->\n\
  4971. 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){\
  4972. ctx.save();\
  4973. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4974. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4975. ctx.lineWidth = line_width;\
  4976. ctx.strokeStyle = \"rgba('+stroke_color+','+stroke_opacity+')\";\
  4977. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
  4978. for(var p = 0 ; p < x_points.length ; p = p + 2){\
  4979.  ctx.beginPath();\
  4980.  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
  4981.  ctx.closePath();\
  4982.  if(use_filled == 1 ){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  4983.  ctx.stroke();\
  4984. };\
  4985. ctx.restore();\
  4986. return;\
  4987. };");
  4988.     break;
  4989.  
  4990.     case DRAW_ROUNDRECTS:/*  used for userdraw */
  4991. fprintf(js_include_file,"\n<!-- draw round rects -->\n\
  4992. 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){\
  4993. ctx.save();\
  4994. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  4995. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4996. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4997. var x,y,w,h,r;\
  4998. for(var p = 0; p < x_points.length; p = p+2){\
  4999.  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);\
  5000.  ctx.beginPath();ctx.moveTo(x + r, y);\
  5001.  ctx.lineTo(x + w - r, y);\
  5002.  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
  5003.  ctx.lineTo(x + w, y + h - r);\
  5004.  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
  5005.  ctx.lineTo(x + r, y + h);\
  5006.  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
  5007.  ctx.lineTo(x, y + r);\
  5008.  ctx.quadraticCurveTo(x, y, x + r, y);\
  5009.  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
  5010.  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5011.  if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\
  5012.  ctx.stroke();\
  5013. }\
  5014. ctx.restore();\
  5015. };");
  5016.     break;
  5017.  
  5018.     case DRAW_ELLIPSES:/* not  used for userdraw */
  5019. fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
  5020. 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){\
  5021. var obj;\
  5022. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5023.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5024. }\
  5025. else\
  5026. {\
  5027.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5028. };\
  5029. var ctx = obj.getContext(\"2d\");\
  5030. ctx.save();\
  5031. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5032. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5033. var cx,cy,ry,rx;\
  5034. ctx.lineWidth = line_width;\
  5035. if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\
  5036. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5037. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5038. for(var p=0;p< x_points.length;p = p+2){\
  5039.  ctx.beginPath();\
  5040.  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
  5041.  ctx.translate(cx - rx, cy - ry);\
  5042.  ctx.scale(rx, ry);\
  5043.  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
  5044.  if( use_filled == 1 ){ctx.fill();}\
  5045.  ctx.stroke();\
  5046. };\
  5047. ctx.restore();\
  5048. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5049.     break;
  5050.  
  5051.     case DRAW_PATHS: /*  used for userdraw */
  5052. fprintf(js_include_file,"\n<!-- draw paths -->\n\
  5053. 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){\
  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.lineWidth = line_width;\
  5058. ctx.lineJoin = \"round\";\
  5059. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5060. ctx.beginPath();\
  5061. ctx.moveTo(x_points[0],y_points[0]);\
  5062. for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
  5063. if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
  5064. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5065. if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  5066. ctx.stroke();\
  5067. ctx.restore();\
  5068. return;\
  5069. };");
  5070.    
  5071.     break;
  5072.     case DRAW_ARROWS:/*  used for userdraw */
  5073. fprintf(js_include_file,"\n<!-- draw arrows -->\n\
  5074. 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){\
  5075. ctx.save();\
  5076. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5077. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5078. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5079. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5080. ctx.lineWidth = line_width;\
  5081. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5082. ctx.lineCap = \"round\";\
  5083. var x1,y1,x2,y2,dx,dy,len;\
  5084. for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
  5085.   ctx.save();\
  5086.   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
  5087.   len = Math.sqrt(dx*dx+dy*dy);\
  5088.   ctx.translate(x2,y2);\
  5089.   ctx.rotate(Math.atan2(dy,dx));\
  5090.   ctx.lineCap = \"round\";\
  5091.   ctx.beginPath();\
  5092.   ctx.moveTo(0,0);\
  5093.   ctx.lineTo(-len,0);\
  5094.   ctx.closePath();\
  5095.   ctx.stroke();\
  5096.   ctx.beginPath();\
  5097.   ctx.moveTo(0,0);\
  5098.   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  5099.   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  5100.   ctx.closePath();\
  5101.   ctx.fill();\
  5102.   ctx.restore();\
  5103.   if( type == 2 ){\
  5104.     ctx.save();\
  5105.     ctx.translate(x1,y1);\
  5106.     ctx.rotate(Math.atan2(-dy,-dx));\
  5107.     ctx.beginPath();\
  5108.     ctx.moveTo(0,0);\
  5109.     ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  5110.     ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  5111.     ctx.closePath();\
  5112.     ctx.stroke();\
  5113.     ctx.fill();\
  5114.     ctx.restore();\
  5115.   }\
  5116.  }\
  5117.  ctx.restore();\
  5118.  return;\
  5119. };");
  5120.     break;
  5121.  
  5122.     case DRAW_VIDEO:/* not  used for userdraw */
  5123. fprintf(js_include_file,"\n<!-- draw video -->\n\
  5124. var draw_video = function(canvas_root_id,x,y,w,h,URL){\
  5125. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  5126. var video_div = document.createElement(\"div\");\
  5127. canvas_div.appendChild(video_div);\
  5128. video_div.style.position = \"absolute\";\
  5129. video_div.style.left = x+\"px\";\
  5130. video_div.style.top = y+\"px\";\
  5131. video_div.style.width = w+\"px\";\
  5132. video_div.style.height = h+\"px\";\
  5133. var video = document.createElement(\"video\");\
  5134. video_div.appendChild(video);\
  5135. video.style.width = w+\"px\";\
  5136. video.style.height = h+\"px\";\
  5137. video.autobuffer = true;\
  5138. video.controls = true;video.autoplay = false;\
  5139. var src = document.createElement(\"source\");\
  5140. src.type = \"video/mp4\";\
  5141. src.src = URL;\
  5142. video.appendChild(src);\
  5143. video.load();\
  5144. return;\
  5145. };");    
  5146.     break;
  5147.    
  5148.     case DRAW_AUDIO:/* not used for userdraw */
  5149. fprintf(js_include_file,"\n<!-- draw audio -->\n\
  5150. var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
  5151. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  5152. var audio_div = document.createElement(\"div\");\
  5153. canvas_div.appendChild(audio_div);\
  5154. audio_div.style.position = \"absolute\";\
  5155. audio_div.style.left = x+\"px\";\
  5156. audio_div.style.top = y+\"px\";\
  5157. audio_div.style.width = w+\"px\";\
  5158. audio_div.style.height = h+\"px\";\
  5159. var audio = document.createElement(\"audio\");\
  5160. audio_div.appendChild(audio);\
  5161. audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
  5162. audio.autobuffer = true;\
  5163. if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;}\
  5164. if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;}\
  5165. var src1 = document.createElement(\"source\");\
  5166. src1.type = \"audio/ogg\";\
  5167. src1.src = URL1;\
  5168. audio.appendChild(src1);\
  5169. var src2 = document.createElement(\"source\");\
  5170. src2.type = \"audio/mpeg\";\
  5171. src2.src = URL2;\
  5172. audio.appendChild(src2);\
  5173. audio.load();\
  5174. return;\
  5175. };");
  5176.     break;
  5177.    
  5178.     case DRAW_HTTP:/* not  used for userdraw */
  5179. fprintf(js_include_file,"\n<!-- draw http -->\n\
  5180. var draw_http = function(canvas_root_id,x,y,w,h,URL){\
  5181. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  5182. var http_div = document.createElement(\"div\");\
  5183. var iframe = document.createElement(\"iframe\");\
  5184. canvas_div.appendChild(http_div);\
  5185. http_div.appendChild(iframe);\
  5186. iframe.src = URL;\
  5187. iframe.setAttribute(\"width\",w);\
  5188. iframe.setAttribute(\"height\",h);\
  5189. return;\
  5190. };");
  5191.     break;
  5192.    
  5193.     case DRAW_XML:
  5194. fprintf(js_include_file,"\n<!-- draw xml -->\n\
  5195. var draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick){\
  5196. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  5197. var xml_div = document.createElement(\"div\");\
  5198. canvas_div.appendChild(xml_div);\
  5199. xml_div.innerHTML = mathml;\
  5200. if(onclick != 0){\
  5201.  xml_div.onclick = function(){\
  5202.   reply[0] = onclick;\
  5203.   alert(\"send \"+onclick+\" ?\");\
  5204.  };\
  5205. };\
  5206. xml_div.style.position = \"absolute\";\
  5207. xml_div.style.left = x+\"px\";\
  5208. xml_div.style.top = y+\"px\";\
  5209. xml_div.style.width = w+\"px\";\
  5210. xml_div.style.height = h+\"px\";\
  5211. return;\
  5212. };"
  5213. );
  5214.     break;
  5215.     case DRAW_SGRAPH:
  5216. /*
  5217.  xstart = given
  5218.  ystart = given
  5219.  sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
  5220. */
  5221. fprintf(js_include_file,"\n<!-- draw sgraph -->\n\
  5222. var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
  5223. 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);};\
  5224. var ctx = obj.getContext(\"2d\");\
  5225. ctx.font = fontfamily;\
  5226. var minor_opacity = 0.8*opacity;\
  5227. ctx.clearRect(0,0,xsize,ysize);\
  5228. var zero_x = 0.1*xsize;\
  5229. var zero_y = 0.9*ysize;\
  5230. var snor_x;var snor_y;\
  5231. if( xstart != xmin){\
  5232.  snor_x = 0.1*xsize;\
  5233. }\
  5234. else\
  5235. {\
  5236.  snor_x = 0;\
  5237.  xstart = xmin;\
  5238. };\
  5239. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  5240. ctx.lineWidth = 2;\
  5241. ctx.beginPath();\
  5242. ctx.moveTo(xsize,zero_y);\
  5243. ctx.lineTo(zero_x,zero_y);\
  5244. ctx.lineTo(zero_x,0);\
  5245. ctx.stroke();\
  5246. ctx.closePath();\
  5247. ctx.beginPath();\
  5248. ctx.moveTo(zero_x,zero_y);\
  5249. ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
  5250. ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
  5251. ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
  5252. ctx.lineTo(zero_x + snor_x,zero_y);\
  5253. ctx.stroke();\
  5254. ctx.closePath();\
  5255. ctx.beginPath();\
  5256. var num = xstart;\
  5257. var flipflop = 1;\
  5258. var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
  5259. var txtsize;var txt_marge=step_x - 5;\
  5260. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  5261.  txtsize = ctx.measureText(num).width;\
  5262.  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
  5263.  if( flipflop == 1){\
  5264.   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
  5265.  }\
  5266.  else\
  5267.  {\
  5268.   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
  5269.  }\
  5270.  num = num + xmajor;\
  5271. };\
  5272. ctx.stroke();\
  5273. ctx.closePath();\
  5274. ctx.lineWidth = 1;\
  5275. ctx.beginPath();\
  5276. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  5277.   ctx.moveTo(x,zero_y);\
  5278.   ctx.lineTo(x,0);\
  5279. };\
  5280. ctx.stroke();\
  5281. ctx.closePath();\
  5282. if( xminor > 1){\
  5283.  ctx.lineWidth = 0.5;\
  5284.  ctx.beginPath();\
  5285.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  5286.  var minor_step_x = step_x / xminor;\
  5287.  var nx;\
  5288.  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
  5289.    num = 1;\
  5290.    for(var p = 1 ; p < xminor ; p++){\
  5291.     nx = x + num*minor_step_x;\
  5292.     ctx.moveTo(nx,zero_y);\
  5293.     ctx.lineTo(nx,0);\
  5294.     num++;\
  5295.    };\
  5296.  };\
  5297.  ctx.stroke();\
  5298.  ctx.closePath();\
  5299.  ctx.beginPath();\
  5300.  ctx.lineWidth = 2;\
  5301.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  5302.  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  5303.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
  5304.  };\
  5305.  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
  5306.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
  5307.  };\
  5308.  ctx.stroke();\
  5309.  ctx.closePath();\
  5310.  ctx.lineWidth = 0.5;\
  5311. };\
  5312. xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
  5313. if( ystart != ymin){\
  5314.  snor_y = 0.1*ysize;\
  5315. }\
  5316. else\
  5317. {\
  5318.  snor_y = 0;\
  5319.  ystart = ymin;\
  5320. };\
  5321. ctx.lineWidth = 2;\
  5322. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  5323. ctx.beginPath();\
  5324. ctx.moveTo(zero_x,zero_y);\
  5325. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
  5326. ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
  5327. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
  5328. ctx.lineTo(zero_x,zero_y - snor_y);\
  5329. ctx.stroke();\
  5330. ctx.closePath();\
  5331. ctx.beginPath();\
  5332. ctx.lineWidth = 1;\
  5333. num = ystart;\
  5334. var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
  5335. for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
  5336.  ctx.moveTo(zero_x,y);\
  5337.  ctx.lineTo(xsize,y);\
  5338.  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
  5339.  num = num + ymajor;\
  5340. };\
  5341. ctx.stroke();\
  5342. ctx.closePath();\
  5343. if( yminor > 1){\
  5344.  ctx.lineWidth = 0.5;\
  5345.  ctx.beginPath();\
  5346.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  5347.  var minor_step_y = step_y / yminor;\
  5348.  var ny;\
  5349.  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
  5350.   num = 1;\
  5351.   for(var p = 1 ;p < yminor;p++){\
  5352.     ny = y + num*minor_step_y;\
  5353.     ctx.moveTo(zero_x,ny);\
  5354.     ctx.lineTo(xsize,ny);\
  5355.     num++;\
  5356.    };\
  5357.  };\
  5358.  ctx.stroke();\
  5359.  ctx.closePath();\
  5360.  ctx.lineWidth = 2;\
  5361.  ctx.beginPath();\
  5362.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  5363.  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
  5364.   ctx.moveTo(zero_x,y);\
  5365.   ctx.lineTo(zero_x+12,y);\
  5366.  };\
  5367.  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
  5368.   ctx.moveTo(zero_x,y);\
  5369.   ctx.lineTo(zero_x+6,y);\
  5370.  };\
  5371.  ctx.stroke();\
  5372.  ctx.closePath();\
  5373. };\
  5374. ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
  5375. if( typeof legend%d  !== 'undefined' ){\
  5376.  ctx.globalAlpha = 1.0;\
  5377.  var y_offset = 2*font_size;\
  5378.  var txt;var txt_size;\
  5379.  var x_offset = xsize - 2*font_size;\
  5380.  var l_length = legend%d.length;var barcolor = new Array();\
  5381.  if( typeof legendcolors%d !== 'undefined' ){\
  5382.   for(var p = 0 ; p < l_length ; p++){\
  5383.    barcolor[p] = legendcolors%d[p];\
  5384.   };\
  5385.  }else{\
  5386.   if( barcolor.length == 0 ){\
  5387.    for(var p = 0 ; p < l_length ; p++){\
  5388.     barcolor[p] = stroke_color;\
  5389.    };\
  5390.   };\
  5391.  };\
  5392.  for(var p = 0; p < l_length; p++){\
  5393.   ctx.fillStyle = barcolor[p];\
  5394.   txt = legend%d[p];\
  5395.   txt_size = ctx.measureText(txt).width;\
  5396.   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
  5397.   y_offset = parseInt(y_offset + 1.5*font_size);\
  5398.  };\
  5399. };\
  5400. if( typeof xaxislabel !== 'undefined' ){\
  5401.   ctx.fillStyle = \'#000000\';\
  5402.   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
  5403.   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
  5404. };\
  5405. if( typeof yaxislabel !== 'undefined'){\
  5406.   ctx.save();\
  5407.   ctx.fillStyle = \'#000000\';\
  5408.   var txt_size = ctx.measureText(yaxislabel).width;\
  5409.   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
  5410.   ctx.rotate(-0.5*Math.PI);\
  5411.   ctx.fillText(yaxislabel,0,0);\
  5412.   ctx.restore();\
  5413. };\
  5414. };\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);
  5415.     break;
  5416.  
  5417.     case DRAW_GRID:/* not used for userdraw */
  5418. fprintf(js_include_file,"\n<!-- draw grid -->\n\
  5419. 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){\
  5420. 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);};\
  5421. var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
  5422. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5423. ctx.save();\
  5424. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  5425. if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
  5426. var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5427. ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
  5428. var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
  5429. ctx.font = font_family;\
  5430. var barcolor = new Array();\
  5431. var xstep = xsize*xmajor/(xmax - xmin);\
  5432. var ystep = ysize*ymajor/(ymax - ymin);\
  5433. var x2step = xstep / xminor;\
  5434. var y2step = ystep / yminor;\
  5435. var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
  5436. if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
  5437. if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
  5438. ctx.beginPath();\
  5439. ctx.lineWidth = line_width;\
  5440. ctx.strokeStyle = stroke_color;\
  5441. for(var p = zero_x ; p < xsize; p = p + xstep){\
  5442. ctx.moveTo(p,0);\
  5443. ctx.lineTo(p,ysize);\
  5444. };\
  5445. for(var p = zero_x ; p > 0; p = p - xstep){\
  5446. ctx.moveTo(p,0);\
  5447. ctx.lineTo(p,ysize);\
  5448. };\
  5449. for(var p = zero_y ; p < ysize; p = p + ystep){\
  5450. ctx.moveTo(0,p);\
  5451. ctx.lineTo(xsize,p);\
  5452. };\
  5453. for(var p = zero_y ; p > 0; p = p - ystep){\
  5454. ctx.moveTo(0,p);\
  5455. ctx.lineTo(xsize,p);\
  5456. };\
  5457. if( typeof xaxislabel !== 'undefined' ){\
  5458. ctx.save();\
  5459. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  5460. var corr =  ctx.measureText(xaxislabel).width;\
  5461. ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\
  5462. ctx.restore();\
  5463. };\
  5464. if( typeof yaxislabel !== 'undefined' ){\
  5465. ctx.save();\
  5466. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  5467. var corr =  ctx.measureText(yaxislabel).width;\
  5468. ctx.translate(zero_x+tics_length + font_size,corr+font_size);\
  5469. ctx.rotate(-0.5*Math.PI);\
  5470. ctx.fillText(yaxislabel,0,0);\
  5471. ctx.restore();\
  5472. };\
  5473. ctx.stroke();\
  5474. ctx.closePath();\
  5475. if( use_axis == 1 ){\
  5476. ctx.save();\
  5477. ctx.beginPath();\
  5478. ctx.strokeStyle = stroke_color;\
  5479. ctx.lineWidth = 0.6*line_width;\
  5480. for(var p = zero_x ; p < xsize; p = p + x2step){\
  5481.  ctx.moveTo(p,0);\
  5482.  ctx.lineTo(p,ysize);\
  5483. };\
  5484. for(var p = zero_x ; p > 0; p = p - x2step){\
  5485.  ctx.moveTo(p,0);\
  5486.  ctx.lineTo(p,ysize);\
  5487. };\
  5488. for(var p = zero_y ; p < ysize; p = p + y2step){\
  5489.  ctx.moveTo(0,p);\
  5490.  ctx.lineTo(xsize,p);\
  5491. };\
  5492. for(var p = zero_y ; p > 0; p = p - y2step){\
  5493.  ctx.moveTo(0,p);\
  5494.  ctx.lineTo(xsize,p);\
  5495. };\
  5496. ctx.stroke();\
  5497. ctx.closePath();\
  5498. ctx.beginPath();\
  5499. ctx.lineWidth = 2*line_width;\
  5500. ctx.strokeStyle = axis_color;\
  5501. ctx.moveTo(0,zero_y);\
  5502. ctx.lineTo(xsize,zero_y);\
  5503. ctx.moveTo(zero_x,0);\
  5504. ctx.lineTo(zero_x,ysize);\
  5505. ctx.stroke();\
  5506. ctx.closePath();\
  5507. ctx.lineWidth = line_width+0.5;\
  5508. ctx.beginPath();\
  5509. for(var p = zero_x ; p < xsize; p = p + xstep){\
  5510.  ctx.moveTo(p,zero_y-tics_length);\
  5511.  ctx.lineTo(p,zero_y+tics_length);\
  5512. };\
  5513. for(var p = zero_x ; p > 0; p = p - xstep){\
  5514.  ctx.moveTo(p,zero_y-tics_length);\
  5515.  ctx.lineTo(p,zero_y+tics_length);\
  5516. };\
  5517. for(var p = zero_y ; p < ysize; p = p + ystep){\
  5518.  ctx.moveTo(zero_x-tics_length,p);\
  5519.  ctx.lineTo(zero_x+tics_length,p);\
  5520. };\
  5521. for(var p = zero_y ; p > 0; p = p - ystep){\
  5522.  ctx.moveTo(zero_x-tics_length,p);\
  5523.  ctx.lineTo(zero_x+tics_length,p);\
  5524. };\
  5525. for(var p = zero_x ; p < xsize; p = p + x2step){\
  5526.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  5527.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  5528. };\
  5529. for(var p = zero_x ; p > 0; p = p - x2step){\
  5530.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  5531.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  5532. };\
  5533. for(var p = zero_y ; p < ysize; p = p + y2step){\
  5534.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  5535.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  5536. };\
  5537. for(var p = zero_y ; p > 0; p = p - y2step){\
  5538.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  5539.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  5540. };\
  5541. ctx.stroke();\
  5542. ctx.closePath();\
  5543. ctx.restore();\
  5544. };\
  5545. if( use_axis_numbering == 1 ){\
  5546. ctx.save();\
  5547. ctx.fillColor = axis_color;\
  5548. ctx.strokeStyle = axis_color;\
  5549. ctx.lineWidth = 2*line_width;\
  5550. ctx.font = font_family;\
  5551. var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
  5552. if( x_strings != null ){\
  5553.  var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  5554.  ctx.beginPath();\
  5555.  for(var p = 0 ; p < len ; p = p+2){\
  5556.   var x_nums = x2px(eval(x_strings[p]));\
  5557.   var x_text = x_strings[p+1];\
  5558.   corr = ctx.measureText(x_text).width;\
  5559.   skip = 1.2*corr/xstep;\
  5560.   if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
  5561.   if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
  5562.   ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
  5563.   ctx.moveTo(x_nums,zero_y - tics_length);\
  5564.   ctx.lineTo(x_nums,zero_y + tics_length);\
  5565.  };\
  5566.  ctx.closePath();\
  5567. }\
  5568. else\
  5569. {\
  5570.  skip = 1;cnt = px2x(zero_x);\
  5571.  prec = Math.log(precision)/(Math.log(10));\
  5572.  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
  5573.  for( var p = zero_x ; p < xsize ; p = p+xstep){\
  5574.   if(skip == 0 ){\
  5575.    disp_cnt = cnt.toFixed(prec);\
  5576.    corr = ctx.measureText(disp_cnt).width;\
  5577.    skip = parseInt(1.2*corr/xstep);\
  5578.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  5579.   }\
  5580.   else\
  5581.   {\
  5582.    skip--;\
  5583.   };\
  5584.   cnt = cnt + xmajor;\
  5585.  };\
  5586.  cnt = px2x(zero_x);skip = 1;\
  5587.  for( var p = zero_x ; p > 0 ; p = p-xstep){\
  5588.   if(skip == 0 ){\
  5589.    disp_cnt = cnt.toFixed(prec);\
  5590.    corr = ctx.measureText(disp_cnt).width;\
  5591.    skip = parseInt(1.2*corr/xstep);\
  5592.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  5593.   }\
  5594.   else\
  5595.   {\
  5596.    skip--;\
  5597.   };\
  5598.   cnt = cnt - xmajor;\
  5599.  };\
  5600. };\
  5601. if( y_strings != null ){\
  5602.  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
  5603.  ctx.beginPath();\
  5604.  for(var p = 0 ; p < len ; p = p+2){\
  5605.   var y_nums = y2px(eval(y_strings[p]));\
  5606.   var y_text = y_strings[p+1];\
  5607.   corr = 2 + tics_length + ctx.measureText(y_text).width;\
  5608.   if( corr > zero_x){corr = parseInt(zero_x+2); }\
  5609.   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
  5610.   ctx.moveTo(zero_x - tics_length,y_nums);\
  5611.   ctx.lineTo(zero_x + tics_length,y_nums);\
  5612.  };\
  5613.  ctx.closePath();\
  5614. }\
  5615. else\
  5616. {\
  5617.  if(f_x == 1){ corr = 1.5*tics_length; }\
  5618.  cnt = px2y(zero_y);skip = 1;\
  5619.  for( var p = zero_y ; p < ysize ; p = p+ystep){\
  5620.   if(skip == 0 ){\
  5621.    skip = parseInt(1.4*font_size/ystep);\
  5622.    disp_cnt = cnt.toFixed(prec);\
  5623.    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  5624.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  5625.   }\
  5626.   else\
  5627.   {\
  5628.    skip--;\
  5629.   };\
  5630.   cnt = cnt - ymajor;\
  5631.  };\
  5632.  corr = 0;cnt = px2y(zero_y);skip = 1;\
  5633.  if(f_x == 1){ corr = 1.5*tics_length; }\
  5634.  for( var p = zero_y ; p > 0 ; p = p-ystep){\
  5635.   if(skip == 0 ){\
  5636.    skip = parseInt(1.4*font_size/ystep);\
  5637.    disp_cnt = cnt.toFixed(prec);\
  5638.    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  5639.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  5640.   }\
  5641.   else\
  5642.   {\
  5643.    skip--;\
  5644.   };\
  5645.   cnt = cnt + ymajor;\
  5646.  };\
  5647. };\
  5648. ctx.stroke();\
  5649. ctx.restore();\
  5650. };\
  5651. if( typeof legend0  !== 'undefined' ){\
  5652. ctx.save();\
  5653. ctx.globalAlpha = 1.0;\
  5654. ctx.font = \"bold \"+font_size+\"px Ariel\";\
  5655. var y_offset = 2*font_size;\
  5656. var txt;var txt_size;\
  5657. var x_offset = xsize - 2*font_size;\
  5658. var l_length = legend0.length;\
  5659. if( typeof legendcolors0 !== 'undefined' ){\
  5660.  for(var p = 0 ; p < l_length ; p++){\
  5661.    barcolor[p] = legendcolors0[p];\
  5662.  };\
  5663. }\
  5664. else\
  5665. {\
  5666.  if( barcolor.length == 0 ){\
  5667.   for(var p = 0 ; p < l_length ; p++){\
  5668.    barcolor[p] = stroke_color;\
  5669.   };\
  5670.  };\
  5671. };\
  5672. for(var p = 0; p < l_length; p++){\
  5673.  ctx.fillStyle = barcolor[p];\
  5674.  txt = legend0[p];\
  5675.  txt_size = ctx.measureText(txt).width;\
  5676.  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
  5677.  y_offset = parseInt(y_offset + 1.5*font_size);\
  5678. };\
  5679. ctx.restore();\
  5680. };\
  5681. if( typeof barchart_0  !== 'undefined' ){\
  5682. ctx.save();\
  5683. var num_barcharts = 0;\
  5684. var bar_name = eval('barchart_0');\
  5685. while( typeof bar_name !== 'undefined' ){\
  5686.    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
  5687. };\
  5688. var bar_width = parseInt(0.8*xstep/(num_barcharts));\
  5689. for(var i=0 ; i< num_barcharts ; i++){\
  5690.  bar_name = eval('barchart_'+i);\
  5691.  var bar_x = new Array();\
  5692.  var bar_y = new Array();\
  5693.  var lb = bar_name.length;\
  5694.  var idx = 0;\
  5695.  var dx = parseInt(0.5*i*bar_width);\
  5696.  for( var p = 0 ; p < lb ; p = p + 3 ){\
  5697.   bar_x[idx] = x2px(bar_name[p]);\
  5698.   bar_y[idx] = y2px(bar_name[p+1]);\
  5699.   barcolor[idx] = bar_name[p+2];\
  5700.   idx++;\
  5701.  };\
  5702.  ctx.globalAlpha = fill_opacity;\
  5703.  ctx.beginPath();\
  5704.  for( var p = 0; p < idx ; p++ ){\
  5705.   ctx.strokeStyle = barcolor[p];\
  5706.   ctx.fillStyle = barcolor[p];\
  5707.   ctx.rect(bar_x[p]-0.4*xstep+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
  5708.  };\
  5709.  ctx.fill();\
  5710.  ctx.stroke();\
  5711.  ctx.closePath();\
  5712. };\
  5713. ctx.restore();\
  5714. };\
  5715. if( typeof linegraph_0 !== 'undefined' ){\
  5716. ctx.save();\
  5717. ctx.globalAlpha = 1.0;\
  5718. var i = 0;\
  5719. var line_name = eval('linegraph_'+i);\
  5720. while ( typeof line_name !== 'undefined' ){\
  5721.  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
  5722.  ctx.lineWidth = parseInt(line_name[1]);\
  5723.  if(line_name[2] == \"1\"){\
  5724.   var d1 = parseInt(line_name[3]);\
  5725.   var d2 = parseInt(line_name[4]);\
  5726.   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
  5727.  }\
  5728.  else\
  5729.  {\
  5730.  if(ctx.setLineDash){ctx.setLineDash = null;}\
  5731.  if(ctx.mozDash){ctx.mozDash = null;}\
  5732.  };\
  5733.  var data_x = new Array();\
  5734.  var data_y = new Array();\
  5735.  var lb = line_name.length;\
  5736.  var idx = 0;\
  5737.  for( var p = 5 ; p < lb ; p = p + 2 ){\
  5738.   data_x[idx] = x2px(line_name[p]);\
  5739.   data_y[idx] = y2px(line_name[p+1]);\
  5740.   idx++;\
  5741.  };\
  5742.  for( var p = 0; p < idx ; p++){\
  5743.   ctx.beginPath();\
  5744.   ctx.moveTo(data_x[p],data_y[p]);\
  5745.   ctx.lineTo(data_x[p+1],data_y[p+1]);\
  5746.   ctx.stroke();\
  5747.   ctx.closePath();\
  5748.  };\
  5749.  i++;\
  5750.  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
  5751. };\
  5752. ctx.restore();\
  5753. };\
  5754. return;\
  5755. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  5756.     break;
  5757.    
  5758.     case DRAW_PIECHART:
  5759. fprintf(js_include_file,"\n<!-- draw piecharts -->\n\
  5760. function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family){\
  5761. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5762.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5763. }\
  5764. else\
  5765. {\
  5766.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5767. };\
  5768. var ld = data_color_list.length;\
  5769. var sum = 0;\
  5770. var idx = 0;\
  5771. var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
  5772. var colors = new Array();\
  5773. var data = new Array();\
  5774. for(var p = 0;p < ld; p = p + 2){\
  5775.  data[idx] = parseFloat(data_color_list[p]);\
  5776.  sum = sum + data[idx];\
  5777.  colors[idx] = data_color_list[p+1];\
  5778.  idx++;\
  5779. };\
  5780. var ctx = obj.getContext(\"2d\");\
  5781. ctx.save();\
  5782. var angle;\
  5783. var angle_end = 0;\
  5784. var offset = Math.PI / 2;\
  5785. ctx.globalAlpha = fill_opacity;\
  5786. for(var p=0; p < idx; p++){\
  5787.  ctx.beginPath();\
  5788.  ctx.fillStyle = colors[p];\
  5789.  ctx.moveTo(x_center,y_center);\
  5790.  angle = Math.PI * (2 * data[p] / sum);\
  5791.  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
  5792.  ctx.lineTo(x_center, y_center);\
  5793.  ctx.fill();\
  5794.  ctx.closePath();\
  5795.  angle_end  = angle_end + angle;\
  5796. };\
  5797. if(typeof legend0 !== 'undefined'){\
  5798.  var legenda = eval(\"legend\"+legend_cnt);\
  5799.  ctx.globalAlpha = 1.0;\
  5800.  ctx.font = font_family;\
  5801.  var y_offset = font_size; \
  5802.  var x_offset = 0;\
  5803.  var txt;var txt_size;\
  5804.  for(var p = 0; p < idx; p++){\
  5805.   ctx.fillStyle = colors[p];\
  5806.   txt = legenda[p];\
  5807.   txt_size = ctx.measureText(txt).width;\
  5808.   if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
  5809.   ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
  5810.   y_offset = parseInt(y_offset + 1.5*font_size);\
  5811.  };\
  5812. };\
  5813. ctx.restore();\
  5814. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5815.    
  5816.     break;
  5817.     case DRAW_ARCS:
  5818. fprintf(js_include_file,"\n<!-- draw arcs -->\n\
  5819. 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){\
  5820. ctx.save();\
  5821. if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  5822. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  5823. if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  5824. if(end < start){var tmp = end;end = start;start=tmp;};\
  5825. start = 360 - start;\
  5826. end = 360 - end;\
  5827. ctx.lineWidth = line_width;\
  5828. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5829. ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  5830. ctx.beginPath();\
  5831. ctx.moveTo(xc,yc);\
  5832. ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  5833. ctx.lineTo(xc,yc);\
  5834. ctx.closePath();\
  5835. if( use_filled == 1 ){\
  5836.  ctx.fill();\
  5837. };\
  5838. ctx.stroke();\
  5839. ctx.restore();\
  5840. };");
  5841.    
  5842.     break;
  5843.     case DRAW_CENTERSTRING:
  5844. fprintf(js_include_file,"\n<!-- draw centerstring -->\n\
  5845. var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
  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. ctx.save();\
  5856. ctx.font = font_family;\
  5857. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5858. var stringwidth = ctx.measureText(text).width;\
  5859. var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
  5860. ctx.fillText(text,x,y2px(y));\
  5861. return;\
  5862. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5863.     break;
  5864.     case DRAW_TEXTS:
  5865. fprintf(js_include_file,"\n<!-- draw text -->\n\
  5866. 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){\
  5867.  var obj;\
  5868.  if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5869.   obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5870.  }\
  5871.  else\
  5872.  {\
  5873.   obj = create_canvas%d(canvas_type,xsize,ysize);\
  5874.  };\
  5875.  var ctx = obj.getContext(\"2d\");\
  5876.  if(angle2 == 0 && angle != 0){\
  5877.   ctx.save();\
  5878.   if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5879.   if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5880.  };\
  5881.  if( font_family.indexOf('px') != null ){\
  5882.   ctx.font = font_family;\
  5883.  }\
  5884.  else\
  5885.  {\
  5886.   ctx.font = font_family;\
  5887.  };\
  5888.  ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5889.  if(angle2 != 0){\
  5890.   ctx.save();\
  5891.   ctx.translate(x,y);\
  5892.   ctx.rotate((360-angle2)*(Math.PI / 180));\
  5893.   ctx.fillText(text,0,0);\
  5894.   ctx.restore();\
  5895.  }else{ctx.fillText(text,x,y);};\
  5896. ctx.restore();\
  5897. return;\
  5898. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5899.     break;
  5900.     case DRAW_CURVE:
  5901. fprintf(js_include_file,"\n<!-- draw curve -->\n\
  5902. 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){\
  5903. var obj;\
  5904. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5905.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5906. }\
  5907. else\
  5908. {\
  5909.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5910. };\
  5911. var ctx = obj.getContext(\"2d\");\
  5912. ctx.save();\
  5913. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  5914. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5915. ctx.beginPath();ctx.lineWidth = line_width;\
  5916. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5917. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5918. ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
  5919. for(var p = 1 ; p < x_points.length ; p++){\
  5920.  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
  5921.  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
  5922.  }\
  5923.  else\
  5924.  {\
  5925.   ctx.stroke();\
  5926.   ctx.beginPath();\
  5927.   p++;\
  5928.   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
  5929.  };\
  5930. };\
  5931. ctx.stroke();\
  5932. ctx.restore();\
  5933. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5934.     break;
  5935.    
  5936.     case DRAW_INPUTS:
  5937. fprintf(js_include_file,"\n<!-- draw input fields -->\n\
  5938. var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\
  5939. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  5940. var input = document.createElement(\"input\");\
  5941. input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  5942. input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  5943. input.setAttribute(\"size\",size);\
  5944. input.setAttribute(\"value\",value);\
  5945. if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
  5946. canvas_div.appendChild(input);};");
  5947.     break;
  5948.    
  5949.     case DRAW_TEXTAREAS:
  5950. fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
  5951. var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
  5952. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  5953. var textarea = document.createElement(\"textarea\");\
  5954. textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  5955. textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  5956. textarea.setAttribute(\"cols\",cols);\
  5957. textarea.setAttribute(\"rows\",rows);\
  5958. textarea.value = value;\
  5959. if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
  5960. canvas_div.appendChild(textarea);};");
  5961.     break;
  5962.    
  5963. case DRAW_PIXELS:
  5964. fprintf(js_include_file,"\n<!-- draw pixel -->\n\
  5965. var draw_setpixel = function(x,y,color,opacity,pixelsize){\
  5966. var canvas = create_canvas%d(10,xsize,ysize);\
  5967. var d = 0.5*pixelsize;\
  5968. var ctx = canvas.getContext(\"2d\");\
  5969. ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
  5970. ctx.clearRect(0,0,xsize,ysize);\
  5971. for(var p=0; p<x.length;p++){\
  5972.  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
  5973. };\
  5974. ctx.fill();ctx.stroke();\
  5975. };",canvas_root_id);
  5976. break;
  5977.  
  5978. case DRAW_CLOCK:
  5979. fprintf(js_include_file,"\n<!-- begin command clock -->\n\
  5980. var clock_canvas = create_canvas%d(%d,xsize,ysize);\
  5981. var clock_ctx = clock_canvas.getContext(\"2d\");\
  5982. var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
  5983. clock_ctx.save();\
  5984. clock_ctx.clearRect(xc-radius,yc-radius,xc+radius,yc+radius);\
  5985. clock_ctx.globalAlpha = clock_bg_opacity;\
  5986. this.type = type || 0;\
  5987. this.interaction = interaction || 0;\
  5988. this.H = H;\
  5989. this.M = M;\
  5990. this.S = S;\
  5991. if(this.S == -1){this.S = 59;this.M = this.M - 1;};\
  5992. if(this.M == -1){this.M = 59;this.H = this.H - 1;};\
  5993. if(this.H == -1){this.H = 11;};\
  5994. this.xc = xc || xsize/2;\
  5995. this.yc = yc || ysize/2;\
  5996. this.radius = radius || xsize/4;\
  5997. var font_size = parseInt(0.2*this.radius);\
  5998. this.H_color = h_color || \"blue\";\
  5999. this.M_color = m_color || \"blue\";\
  6000. this.S_color = s_color || \"blue\";\
  6001. this.fg_color = fg_color || \"red\";\
  6002. this.bg_color = bg_color || \"white\";\
  6003. clock_ctx.translate(this.xc,this.yc);\
  6004. clock_ctx.beginPath();\
  6005. clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
  6006. clock_ctx.fillStyle = this.bg_color;\
  6007. clock_ctx.fill();\
  6008. clock_ctx.closePath();\
  6009. clock_ctx.beginPath();\
  6010. clock_ctx.font = font_size+\"px Arial\";\
  6011. clock_ctx.fillStyle = this.fg_color;\
  6012. clock_ctx.textAlign = \"center\";\
  6013. clock_ctx.textBaseline = 'middle';\
  6014. var angle;var x1,y1,x2,y2;\
  6015. var angle_cos;var angle_sin;\
  6016. clock_ctx.globalAlpha = clock_fg_opacity;\
  6017. switch(type){\
  6018. case 0:clock_ctx.beginPath();\
  6019. for(var p = 1; p <= 12 ; p++){\
  6020.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  6021.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  6022.  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  6023.  clock_ctx.moveTo(x1,y1);\
  6024.  clock_ctx.lineTo(x2,y2);\
  6025. };\
  6026. for(var p = 1; p <= 60 ; p++){\
  6027.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  6028.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  6029.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  6030.  clock_ctx.moveTo(x1,y1);\
  6031.  clock_ctx.lineTo(x2,y2);\
  6032. };\
  6033. clock_ctx.closePath();\
  6034. clock_ctx.stroke();\
  6035. break;\
  6036. case 1:\
  6037. 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;\
  6038. case 2:\
  6039. 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);};\
  6040. clock_ctx.beginPath();\
  6041. for(var p = 1; p <= 12 ; p++){\
  6042.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  6043.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  6044.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  6045.  clock_ctx.moveTo(x1,y1);\
  6046.  clock_ctx.lineTo(x2,y2);\
  6047. };\
  6048. for(var p = 1; p <= 60 ; p++){\
  6049.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  6050.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  6051.  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  6052.  clock_ctx.moveTo(x1,y1);\
  6053.  clock_ctx.lineTo(x2,y2);\
  6054. };\
  6055. clock_ctx.closePath();\
  6056. clock_ctx.stroke();\
  6057. break;\
  6058. };\
  6059. angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
  6060. clock_ctx.rotate(angle);\
  6061. clock_ctx.beginPath();\
  6062. clock_ctx.moveTo(-3, -2);\
  6063. clock_ctx.lineTo(-3, 2);\
  6064. clock_ctx.lineTo(this.radius * 0.7, 1);\
  6065. clock_ctx.lineTo(this.radius  * 0.7, -1);\
  6066. clock_ctx.fillStyle = this.H_color;\
  6067. clock_ctx.fill();\
  6068. clock_ctx.rotate(-angle);\
  6069. angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
  6070. clock_ctx.rotate(angle);\
  6071. clock_ctx.beginPath();\
  6072. clock_ctx.moveTo(-3, -2);\
  6073. clock_ctx.lineTo(-3, 2);\
  6074. clock_ctx.lineTo(this.radius  * 0.8, 1);\
  6075. clock_ctx.lineTo(this.radius  * 0.8, -1);\
  6076. clock_ctx.fillStyle = this.M_color;\
  6077. clock_ctx.fill();\
  6078. clock_ctx.rotate(-angle);\
  6079. angle = (this.S - 15) * 2 * Math.PI / 60;\
  6080. clock_ctx.rotate(angle);\
  6081. clock_ctx.beginPath();\
  6082. clock_ctx.moveTo(0,0);\
  6083. clock_ctx.lineTo(this.radius  * 0.95, 0);\
  6084. clock_ctx.lineTo(this.radius  * 0.9, -1);\
  6085. clock_ctx.strokeStyle = this.S_color;\
  6086. clock_ctx.stroke();\
  6087. clock_ctx.restore();\
  6088. };",canvas_root_id,CLOCK_CANVAS);
  6089. break;
  6090.  
  6091. case DRAW_LATTICE:
  6092. fprintf(js_include_file,"\n<!-- draw lattice -->\n\
  6093. 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){\
  6094. var obj;\
  6095. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6096.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6097. }\
  6098. else\
  6099. {\
  6100.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6101. };\
  6102. var ctx = obj.getContext(\"2d\");\
  6103. ctx.save();\
  6104. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  6105. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  6106. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6107. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  6108. var radius = line_width;\
  6109. var x = 0;\
  6110. var y = 0;\
  6111. var x_step_px = xsize/(xmax-xmin);\
  6112. var y_step_px = ysize/(ymax-ymin);\
  6113. var xv1 = dx1*x_step_px;\
  6114. var yv1 = dy1*y_step_px;\
  6115. var xv2 = dx2*x_step_px;\
  6116. var yv2 = dy2*y_step_px;\
  6117. for(var p = 0; p < n1 ;p++){\
  6118.  x = p*xv1 + x0;\
  6119.  y = p*yv1 + y0;\
  6120.  for(var c = 0; c < n2 ; c++){\
  6121.   ctx.beginPath();\
  6122.   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
  6123.   ctx.fill();\
  6124.   ctx.stroke();\
  6125.   ctx.closePath();\
  6126.  };\
  6127. };\
  6128. ctx.restore();\
  6129. return;\
  6130. };",canvas_root_id,canvas_root_id,canvas_root_id);
  6131.     break;
  6132. case DRAW_XYLOGSCALE:
  6133. fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\
  6134. 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){\
  6135. var obj;\
  6136. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6137.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6138. }\
  6139. else\
  6140. {\
  6141.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6142. };\
  6143. var ctx = obj.getContext(\"2d\");\
  6144. ctx.clearRect(0,0,xsize,ysize);\
  6145. ctx.save();\
  6146. var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
  6147. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  6148. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  6149. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  6150. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  6151. if(use_axis_numbering == 1){\
  6152.  ctx.font = font_family;\
  6153.  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
  6154.  ymarge = parseInt(1.5*font_size);\
  6155.  ctx.save();\
  6156.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  6157.  ctx.rect(0,0,xmarge,ysize);\
  6158.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  6159.  ctx.fill();\
  6160.  ctx.restore();\
  6161. }else{xmarge = 0;ymarge = 0;};\
  6162. if( typeof xaxislabel !== 'undefined' ){\
  6163.  ctx.save();\
  6164.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6165.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6166.  corr =  ctx.measureText(xaxislabel).width;\
  6167.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  6168.  ctx.restore();\
  6169. };\
  6170. if( typeof yaxislabel !== 'undefined' ){\
  6171.  ctx.save();\
  6172.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6173.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6174.  corr = ctx.measureText(yaxislabel).width;\
  6175.  ctx.translate(xmarge+font_size,corr+font_size);\
  6176.  ctx.rotate(-0.5*Math.PI);\
  6177.  ctx.fillText(yaxislabel,0,0);\
  6178.  ctx.restore();\
  6179. };\
  6180. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6181. ctx.lineWidth = line_width;\
  6182. for(var p = x_min; p <= x_max ; p++){\
  6183.  num = Math.pow(xlogbase,p);\
  6184.  for(var i = 1 ; i < xlogbase ; i++){\
  6185.   x_e = x2px(i*num);\
  6186.   if( i == 1 ){\
  6187.    ctx.lineWidth = line_width;\
  6188.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6189.    if( use_axis_numbering == 1 && p > x_min){\
  6190.      xtxt = xlogbase+'^'+p.toFixed(0);\
  6191.      corr = 0.5*(ctx.measureText(xtxt).width);\
  6192.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  6193.    };\
  6194.   }else{\
  6195.    ctx.lineWidth = 0.2*line_width;\
  6196.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6197.   };\
  6198.   if( x_e >= xmarge ){\
  6199.    ctx.beginPath();\
  6200.    ctx.moveTo(x_e,0);\
  6201.    ctx.lineTo(x_e,ysize - ymarge);\
  6202.    ctx.stroke();\
  6203.    ctx.closePath();\
  6204.   };\
  6205.  };\
  6206. };\
  6207. for(var p = y_min; p <= y_max ; p++){\
  6208.  num = Math.pow(ylogbase,p);\
  6209.  for(var i = 1 ; i < ylogbase ; i++){\
  6210.   y_e = y2px(i*num);\
  6211.   if( i == 1 ){\
  6212.    ctx.lineWidth = line_width;\
  6213.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6214.    if( use_axis_numbering == 1 && p > y_min){\
  6215.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  6216.    };\
  6217.   }else{\
  6218.    ctx.lineWidth = 0.2*line_width;\
  6219.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6220.   };\
  6221.   ctx.beginPath();\
  6222.   ctx.moveTo(xmarge,y_e);\
  6223.   ctx.lineTo(xsize,y_e);\
  6224.   ctx.stroke();\
  6225.   ctx.closePath();\
  6226.  };\
  6227. };\
  6228. ctx.restore();\
  6229. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  6230.     break;
  6231.  
  6232. case DRAW_XLOGSCALE:
  6233. fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\
  6234. 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){\
  6235. var obj;\
  6236. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6237.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6238. }\
  6239. else\
  6240. {\
  6241.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6242. };\
  6243. var ctx = obj.getContext(\"2d\");\
  6244. ctx.clearRect(0,0,xsize,ysize);\
  6245. ctx.save();\
  6246. ctx.lineWidth = line_width;\
  6247. var prec = Math.log(precision)/Math.log(10);\
  6248. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  6249. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  6250. var y_min = 0;var y_max = ysize;var x_e;var corr;\
  6251. var xtxt;var ytxt;var num;var xmarge;var ymarge;\
  6252. if(use_axis_numbering == 1){\
  6253.  ctx.font = font_family;\
  6254.  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
  6255.  ymarge = parseInt(1.5*font_size);\
  6256.  ctx.save();\
  6257.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  6258.  ctx.rect(0,0,xmarge,ysize);\
  6259.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  6260.  ctx.fill();\
  6261.  ctx.restore();\
  6262. }else{xmarge = 0;ymarge = 0;};\
  6263. if( typeof xaxislabel !== 'undefined' ){\
  6264.  ctx.save();\
  6265.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6266.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6267.  corr =  ctx.measureText(xaxislabel).width;\
  6268.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  6269.  ctx.restore();\
  6270. };\
  6271. if( typeof yaxislabel !== 'undefined' ){\
  6272.  ctx.save();\
  6273.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6274.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6275.  corr = ctx.measureText(yaxislabel).width;\
  6276.  ctx.translate(xmarge+font_size,corr+font_size);\
  6277.  ctx.rotate(-0.5*Math.PI);\
  6278.  ctx.fillText(yaxislabel,0,0);\
  6279.  ctx.restore();\
  6280. };\
  6281. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6282. ctx.lineWidth = line_width;\
  6283. for(var p = x_min; p <= x_max ; p++){\
  6284.  num = Math.pow(xlogbase,p);\
  6285.  for(var i = 1 ; i < xlogbase ; i++){\
  6286.   x_e = x2px(i*num);\
  6287.   if( i == 1 ){\
  6288.     ctx.lineWidth = line_width;\
  6289.     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6290.    if( use_axis_numbering == 1 && p > x_min ){\
  6291.      xtxt = xlogbase+'^'+p.toFixed(0);\
  6292.      corr = 0.5*(ctx.measureText(xtxt).width);\
  6293.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  6294.    };\
  6295.   }else{\
  6296.    ctx.lineWidth = 0.2*line_width;\
  6297.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6298.   };\
  6299.   if( x_e >= xmarge ){\
  6300.    ctx.beginPath();\
  6301.    ctx.moveTo(x_e,0);\
  6302.    ctx.lineTo(x_e,ysize - ymarge);\
  6303.    ctx.stroke();\
  6304.    ctx.closePath();\
  6305.   };\
  6306.  };\
  6307. };\
  6308. var stepy = Math.abs(y2px(ymajor) - y2px(0));\
  6309. var minor_step = stepy / yminor;\
  6310. for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
  6311.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6312.  ctx.lineWidth = line_width;\
  6313.  ctx.beginPath();\
  6314.  ctx.moveTo(xmarge,y);\
  6315.  ctx.lineTo(xsize,y);\
  6316.  ctx.stroke();\
  6317.  ctx.closePath();\
  6318.  if( use_axis_numbering == 1){\
  6319.   ytxt = (px2y(y)).toFixed(prec);\
  6320.   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
  6321.  };\
  6322.  for(var dy = 1 ; dy < yminor ; dy++){\
  6323.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6324.   ctx.lineWidth = 0.2*line_width;\
  6325.   ctx.beginPath();\
  6326.   ctx.moveTo(xmarge,y+dy*minor_step);\
  6327.   ctx.lineTo(xsize,y+dy*minor_step);\
  6328.   ctx.stroke();\
  6329.   ctx.closePath();\
  6330.  };\
  6331. };\
  6332. ctx.restore();\
  6333. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  6334.     break;
  6335. case DRAW_YLOGSCALE:
  6336. fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\
  6337. 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){\
  6338. var obj;\
  6339. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6340.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  6341. }\
  6342. else\
  6343. {\
  6344.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  6345. };\
  6346. var ctx = obj.getContext(\"2d\");\
  6347. ctx.clearRect(0,0,xsize,ysize);\
  6348. ctx.save();\
  6349. ctx.lineWidth = line_width;\
  6350. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  6351. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  6352. var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
  6353. if(use_axis_numbering == 1){\
  6354.  ctx.font = font_family;\
  6355.  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
  6356.  ymarge = 2*font_size;\
  6357.  ctx.save();\
  6358.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  6359.  ctx.rect(0,0,xmarge,ysize);\
  6360.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  6361.  ctx.fill();\
  6362.  ctx.restore();\
  6363. }else{xmarge = 0;ymarge = 0;};\
  6364. if( typeof xaxislabel !== 'undefined' ){\
  6365.  ctx.save();\
  6366.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6367.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6368.  corr =  ctx.measureText(xaxislabel).width;\
  6369.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  6370.  ctx.restore();\
  6371. };\
  6372. if( typeof yaxislabel !== 'undefined' ){\
  6373.  ctx.save();\
  6374.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  6375.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6376.  corr = ctx.measureText(yaxislabel).width;\
  6377.  ctx.translate(xmarge+font_size,corr+font_size);\
  6378.  ctx.rotate(-0.5*Math.PI);\
  6379.  ctx.fillText(yaxislabel,0,0);\
  6380.  ctx.restore();\
  6381. };\
  6382. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  6383. ctx.lineWidth = line_width;\
  6384. for(var p = y_min; p <= y_max ; p++){\
  6385.  num = Math.pow(ylogbase,p);\
  6386.  for(var i = 1 ; i < ylogbase ; i++){\
  6387.   y_e = y2px(i*num);\
  6388.   if( i == 1 ){\
  6389.    ctx.lineWidth = line_width;\
  6390.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6391.    if( use_axis_numbering == 1 && p > y_min){\
  6392.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  6393.    };\
  6394.   }else{\
  6395.    ctx.lineWidth = 0.2*line_width;\
  6396.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6397.   };\
  6398.   ctx.beginPath();\
  6399.   ctx.moveTo(xmarge,y_e);\
  6400.   ctx.lineTo(xsize,y_e);\
  6401.   ctx.stroke();\
  6402.   ctx.closePath();\
  6403.  };\
  6404. };\
  6405. var stepx = Math.abs(x2px(xmajor) - x2px(0));\
  6406. var minor_step = stepx / xminor;\
  6407. var prec = Math.log(precision)/Math.log(10);\
  6408. var xtxt;var corr;var flip = 0;\
  6409. for(var x = stepx ; x < xsize ; x = x + stepx){\
  6410.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  6411.  ctx.lineWidth = line_width;\
  6412.  ctx.beginPath();\
  6413.  ctx.moveTo(x,ysize-ymarge);\
  6414.  ctx.lineTo(x,0);\
  6415.  ctx.stroke();\
  6416.  ctx.closePath();\
  6417.  if( use_axis_numbering == 1){\
  6418.   xtxt = (px2x(x)).toFixed(prec);\
  6419.   corr = 0.5*(ctx.measureText(xtxt).width);\
  6420.   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
  6421.   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
  6422.  };\
  6423.  for(var dx = 1 ; dx < xminor ; dx++){\
  6424.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  6425.   ctx.lineWidth = 0.2*line_width;\
  6426.   ctx.beginPath();\
  6427.   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
  6428.   ctx.lineTo(x+dx*minor_step,0);\
  6429.   ctx.stroke();\
  6430.   ctx.closePath();\
  6431.  };\
  6432. };\
  6433. ctx.restore();\
  6434. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  6435.     break;
  6436.     default:break;
  6437.    }
  6438.   }
  6439.  }
  6440.   return;
  6441. }
  6442.  
  6443. void check_string_length(int L){
  6444.  if(L<1 || L > MAX_BUFFER-1){
  6445.   canvas_error("problem with your arguments to command...");
  6446.  }
  6447.  return;
  6448. }
  6449.  
  6450.  
  6451. int get_token(FILE *infile){
  6452.         int     c,i=0;
  6453.         char    temp[MAX_INT], *input_type;
  6454.         char    *line="line",
  6455.         *audio="audio",
  6456.         *blink="blink",
  6457.         *arrowhead="arrowhead",
  6458.         *crosshairsize="crosshairsize",
  6459.         *crosshair="crosshair",
  6460.         *crosshairs="crosshairs",
  6461.         *audioobject="audioobject",
  6462.         *style="style",
  6463.         *mouse="mouse",
  6464.         *mousex="mousex",
  6465.         *mousey="mousey",
  6466.         *mouse_display="display",
  6467.         *mouse_degree="mouse_degree",
  6468.         *userdraw="userdraw",
  6469.         *highlight="highlight",
  6470.         *http="http",
  6471.         *rays="rays",
  6472.         *dashtype="dashtype",
  6473.         *dashed="dashed",
  6474.         *filled="filled",
  6475.         *lattice="lattice",
  6476.         *parallel="parallel",
  6477.         *segment="segment",
  6478.         *dsegment="dsegment",
  6479.         *seg="seg",
  6480.         *bgimage="bgimage",
  6481.         *bgcolor="bgcolor",
  6482.         *strokecolor="strokecolor",
  6483.         *backgroundimage="backgroundimage",
  6484.         *text="text",
  6485.         *textup="textup",
  6486.         *mouseprecision="mouseprecision",
  6487.         *precision="precision",
  6488.         *plotsteps="plotsteps",
  6489.         *plotstep="plotstep",
  6490.         *tsteps="tsteps",
  6491.         *curve="curve",
  6492.         *dcurve="dcurve",
  6493.         *plot="plot",
  6494.         *dplot="dplot",
  6495.         *levelcurve="levelcurve",
  6496.         *fontsize="fontsize",
  6497.         *fontcolor="fontcolor",
  6498.         *axis="axis",
  6499.         *axisnumbering="axisnumbering",
  6500.         *axisnumbers="axisnumbers",
  6501.         *arrow="arrow",
  6502.         *darrow="darrow",
  6503.         *arrow2="arrow2",
  6504.         *darrow2="darrow2",
  6505.         *zoom="zoom",
  6506.         *grid="grid",
  6507.         *hline="hline",
  6508.         *dhline="dhline",
  6509.         *drag="drag",
  6510.         *horizontalline="horizontalline",
  6511.         *vline="vline",
  6512.         *dvline="dvline",
  6513.         *verticalline="verticalline",
  6514.         *triangle="triangle",
  6515.         *ftriangle="ftriangle",
  6516.         *mathml="mathml",
  6517.         *html="html",
  6518.         *input="input",
  6519.         *button="button",
  6520.         *inputstyle="inputstyle",
  6521.         *textarea="textarea",
  6522.         *trange="trange",
  6523.         *ranget="ranget",
  6524.         *xrange="xrange",
  6525.         *yrange="yrange",
  6526.         *rangex="rangex",
  6527.         *rangey="rangey",
  6528.         *polyline="polyline",
  6529.         *lines="lines",
  6530.         *poly="poly",
  6531.         *polygon="polygon",
  6532.         *fpolygon="fpolygon",
  6533.         *fpoly="fpoly",
  6534.         *filledpoly="filledpoly",
  6535.         *filledpolygon="filledpolygon",
  6536.         *rect="rect",
  6537.         *frect="frect",
  6538.         *rectangle="rectangle",
  6539.         *frectangle="frectangle",
  6540.         *square="square",
  6541.         *fsquare="fsquare",
  6542.         *dline="dline",
  6543.         *arc="arc",
  6544.         *filledarc="filledarc",
  6545.         *size="size",
  6546.         *string="string",
  6547.         *stringup="stringup",
  6548.         *copy="copy",
  6549.         *copyresized="copyresized",
  6550.         *opacity="opacity",
  6551.         *transparent="transparent",
  6552.         *fill="fill",
  6553.         *point="point",
  6554.         *points="points",
  6555.         *linewidth="linewidth",
  6556.         *circle="circle",
  6557.         *fcircle="fcircle",
  6558.         *disk="disk",
  6559.         *comment="#",
  6560.         *end="end",
  6561.         *ellipse="ellipse",
  6562.         *fellipse="fellipse",
  6563.         *rotate="rotate",
  6564.         *affine="affine",
  6565.         *killaffine="killaffine",
  6566.         *fontfamily="fontfamily",
  6567.         *fillcolor="fillcolor",
  6568.         *clicktile="clicktile",
  6569.         *clicktile_colors="clicktile_colors",
  6570.         *translation="translation",
  6571.         *translate="translate",
  6572.         *killtranslation="killtranslation",
  6573.         *killtranslate="killtranslate",
  6574.         *onclick="onclick",
  6575.         *roundrect="roundrect",
  6576.         *froundrect="froundrect",
  6577.         *roundrectangle="roundrectangle",
  6578.         *patternfill="patternfill",
  6579.         *hatchfill="hatchfill",
  6580.         *diafill="diafill",
  6581.         *diamondfill="diamondfill",
  6582.         *dotfill="dotfill",
  6583.         *gridfill="gridfill",
  6584.         *imagefill="imagefill",
  6585.         *xlogbase="xlogbase",
  6586.         *ylogbase="ylogbase",
  6587.         *xlogscale="xlogscale",
  6588.         *ylogscale="ylogscale",
  6589.         *xylogscale="xylogscale",
  6590.         *intooltip="intooltip",
  6591.         *replyformat="replyformat",
  6592.         *floodfill="floodfill",
  6593.         *filltoborder="filltoborder",
  6594.         *clickfill="clickfill",
  6595.         *setpixel="setpixel",
  6596.         *pixels="pixels",
  6597.         *pixelsize="pixelsize",
  6598.         *clickfillmarge="clickfillmarge",
  6599.         *xaxis="xaxis",
  6600.         *yaxis="yaxis",
  6601.         *xaxistext="xaxistext",
  6602.         *yaxistext="yaxistext",
  6603.         *piechart="piechart",
  6604.         *legend="legend",
  6605.         *legendcolors="legendcolors",
  6606.         *xlabel="xlabel",
  6607.         *ylabel="ylabel",
  6608.         *barchart="barchart",
  6609.         *linegraph="linegraph",
  6610.         *clock="clock",
  6611.         *animate="animate",
  6612.         *video="video",
  6613.         *status="status",
  6614.         *nostatus="nostatus",
  6615.         *snaptogrid="snaptogrid",
  6616.         *xsnaptogrid="xsnaptogrid",
  6617.         *ysnaptogrid="ysnaptogrid",
  6618.         *userinput_xy="userinput_xy",
  6619.         *usertextarea_xy="usertextarea_xy",
  6620.         *jsmath="jsmath",
  6621.         *trace_jscurve="trace_jscurve",
  6622.         *setlimits="setlimits",
  6623.         *jscurve="jscurve",
  6624.         *jsplot="jsplot",
  6625.         *sgraph="sgraph",
  6626.         *title="title",
  6627.         *centerstring="centerstring",
  6628.         *xunit="xunit",
  6629.         *yunit="yunit",
  6630.         *slider="slider",
  6631.         *killslider="killslider",
  6632.         *angle="angle";
  6633.  
  6634.         while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')){
  6635.             if( i == 0 && (c == ' ' || c == '\t') ){
  6636.         continue; /* white spaces or tabs allowed before first command identifier */
  6637.             }
  6638.             else
  6639.             {
  6640.         if( c == ' ' || c == '\t' ){
  6641.             break;
  6642.         }
  6643.         else
  6644.         {
  6645.             temp[i] = c;
  6646.             if(i > MAX_INT - 2){canvas_error("command string too long !");}
  6647.             i++;
  6648.         }
  6649.             }
  6650.             if(temp[0] == '#') break;
  6651.         }
  6652.         if (c == EOF) finished = 1;
  6653.  
  6654.         if (c == '\n' || c == '\r') {
  6655.         line_number++;
  6656.         if (i == 0) { return EMPTY; }
  6657.         } else if (c == EOF) {
  6658.         return 0;
  6659.         }
  6660.  
  6661.         temp[i]='\0';
  6662.         input_type=(char*)my_newmem(strlen(temp));
  6663.         snprintf(input_type,sizeof(temp),"%s",temp);
  6664.  
  6665.         if( strcmp(input_type, size) == 0 ){
  6666.         free(input_type);
  6667.         return SIZE;
  6668.         }
  6669.         if( strcmp(input_type, xrange) == 0 ){
  6670.         free(input_type);
  6671.         return XRANGE;
  6672.         }
  6673.         if( strcmp(input_type, rangex) == 0 ){
  6674.         free(input_type);
  6675.         return XRANGE;
  6676.         }
  6677.         if( strcmp(input_type, trange) == 0 ){
  6678.         free(input_type);
  6679.         return TRANGE;
  6680.         }
  6681.         if( strcmp(input_type, ranget) == 0 ){
  6682.         free(input_type);
  6683.         return TRANGE;
  6684.         }
  6685.         if( strcmp(input_type, yrange) == 0 ){
  6686.         free(input_type);
  6687.         return YRANGE;
  6688.         }
  6689.         if( strcmp(input_type, rangey) == 0 ){
  6690.         free(input_type);
  6691.         return YRANGE;
  6692.         }
  6693.         if( strcmp(input_type, linewidth) == 0 ){
  6694.         free(input_type);
  6695.         return LINEWIDTH;
  6696.         }
  6697.         if( strcmp(input_type, dashed) == 0 ){
  6698.         free(input_type);
  6699.         return DASHED;
  6700.         }
  6701.         if( strcmp(input_type, dashtype) == 0 ){
  6702.         free(input_type);
  6703.         return DASHTYPE;
  6704.         }
  6705.         if( strcmp(input_type, axisnumbering) == 0 ){
  6706.         free(input_type);
  6707.         return AXIS_NUMBERING;
  6708.         }
  6709.         if( strcmp(input_type, axisnumbers) == 0 ){
  6710.         free(input_type);
  6711.         return AXIS_NUMBERING;
  6712.         }
  6713.         if( strcmp(input_type, axis) == 0 ){
  6714.         free(input_type);
  6715.         return AXIS;
  6716.         }
  6717.         if( strcmp(input_type, grid) == 0 ){
  6718.         free(input_type);
  6719.         return GRID;
  6720.         }
  6721.         if( strcmp(input_type, parallel) == 0 ){
  6722.         free(input_type);
  6723.         return PARALLEL;
  6724.         }
  6725.         if( strcmp(input_type, hline) == 0 ||  strcmp(input_type, horizontalline) == 0 ){
  6726.         free(input_type);
  6727.         return HLINE;
  6728.         }
  6729.         if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
  6730.         free(input_type);
  6731.         return VLINE;
  6732.         }
  6733.         if( strcmp(input_type, line) == 0 ){
  6734.         free(input_type);
  6735.         return LINE;
  6736.         }
  6737.         if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
  6738.         free(input_type);
  6739.         return SEGMENT;
  6740.         }
  6741.         if( strcmp(input_type, dsegment) == 0 ){
  6742.         free(input_type);
  6743.         use_dashed = TRUE;
  6744.         return SEGMENT;
  6745.         }
  6746.         if( strcmp(input_type, crosshairsize) == 0 ){
  6747.         free(input_type);
  6748.         return CROSSHAIRSIZE;
  6749.         }
  6750.         if( strcmp(input_type, arrowhead) == 0 ){
  6751.         free(input_type);
  6752.         return ARROWHEAD;
  6753.         }
  6754.         if( strcmp(input_type, crosshairs) == 0 ){
  6755.         free(input_type);
  6756.         return CROSSHAIRS;
  6757.         }
  6758.         if( strcmp(input_type, crosshair) == 0 ){
  6759.         free(input_type);
  6760.         return CROSSHAIR;
  6761.         }
  6762.         if( strcmp(input_type, onclick) == 0 ){
  6763.         free(input_type);
  6764.         return ONCLICK;
  6765.         }
  6766.         if( strcmp(input_type, drag) == 0 ){
  6767.         free(input_type);
  6768.         return DRAG;
  6769.         }
  6770.         if( strcmp(input_type, userdraw) == 0 ){
  6771.         free(input_type);
  6772.         return USERDRAW;
  6773.         }
  6774.         if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
  6775.         free(input_type);
  6776.         return STYLE;
  6777.         }
  6778.         if( strcmp(input_type, fillcolor) == 0 ){
  6779.         free(input_type);
  6780.         return FILLCOLOR;
  6781.         }
  6782.         if( strcmp(input_type, strokecolor) == 0 ){
  6783.         free(input_type);
  6784.         return STROKECOLOR;
  6785.         }
  6786.         if( strcmp(input_type, filled) == 0  ){
  6787.         free(input_type);
  6788.         return FILLED;
  6789.         }
  6790.         if( strcmp(input_type, http) == 0 ){
  6791.         free(input_type);
  6792.         return HTTP;
  6793.         }
  6794.         if( strcmp(input_type, rays) == 0 ){
  6795.         free(input_type);
  6796.         return RAYS;
  6797.         }
  6798.         if( strcmp(input_type, lattice) == 0 ){
  6799.         free(input_type);
  6800.         return LATTICE;
  6801.         }
  6802.         if( strcmp(input_type, bgimage) == 0 ){
  6803.         free(input_type);
  6804.         return BGIMAGE;
  6805.         }
  6806.         if( strcmp(input_type, bgcolor) == 0 ){
  6807.         free(input_type);
  6808.         return BGCOLOR;
  6809.         }
  6810.         if( strcmp(input_type, backgroundimage) == 0 ){
  6811.         free(input_type);
  6812.         return BGIMAGE;
  6813.         }
  6814.         if( strcmp(input_type, text) == 0 ){
  6815.         free(input_type);
  6816.         return FLY_TEXT;
  6817.         }
  6818.         if( strcmp(input_type, textup) == 0 ){
  6819.         free(input_type);
  6820.         return FLY_TEXTUP;
  6821.         }
  6822.         if( strcmp(input_type, mouse) == 0 ){
  6823.         free(input_type);
  6824.         return MOUSE;
  6825.         }
  6826.         if( strcmp(input_type, mousex) == 0 ){
  6827.         free(input_type);
  6828.         return MOUSEX;
  6829.         }
  6830.         if( strcmp(input_type, mousey) == 0 ){
  6831.         free(input_type);
  6832.         return MOUSEY;
  6833.         }
  6834.         if( strcmp(input_type, mouse_degree) == 0 ){
  6835.         free(input_type);
  6836.         return MOUSE_DEGREE;
  6837.         }
  6838.         if( strcmp(input_type, mouse_display) == 0 ){
  6839.         free(input_type);
  6840.         return MOUSE_DISPLAY;
  6841.         }
  6842.         if( strcmp(input_type, mouseprecision) == 0 ){
  6843.         free(input_type);
  6844.         return MOUSE_PRECISION;
  6845.         }
  6846.         if( strcmp(input_type, precision) == 0 ){
  6847.         free(input_type);
  6848.         return MOUSE_PRECISION;
  6849.         }
  6850.         if( strcmp(input_type, curve) == 0 ){
  6851.         free(input_type);
  6852.         return CURVE;
  6853.         }
  6854.         if( strcmp(input_type, dcurve) == 0 ){
  6855.         use_dashed = TRUE;
  6856.         free(input_type);
  6857.         return CURVE;
  6858.         }
  6859.         if( strcmp(input_type, plot) == 0 ){
  6860.         free(input_type);
  6861.         return CURVE;
  6862.         }
  6863.         if( strcmp(input_type, dplot) == 0 ){
  6864.         use_dashed = TRUE;
  6865.         free(input_type);
  6866.         return CURVE;
  6867.         }
  6868.         if( strcmp(input_type, levelcurve) == 0 ){
  6869.         free(input_type);
  6870.         return LEVELCURVE;
  6871.         }
  6872.         if( strcmp(input_type, plotsteps) == 0 ){
  6873.         free(input_type);
  6874.         return PLOTSTEPS;
  6875.         }
  6876.         if( strcmp(input_type, plotstep) == 0 ){
  6877.         free(input_type);
  6878.         return PLOTSTEPS;
  6879.         }
  6880.         if( strcmp(input_type, tsteps) == 0 ){
  6881.         free(input_type);
  6882.         return PLOTSTEPS;
  6883.         }
  6884.         if( strcmp(input_type, fontsize) == 0 ){
  6885.         free(input_type);
  6886.         return FONTSIZE;
  6887.         }
  6888.         if( strcmp(input_type, fontcolor) == 0 ){
  6889.         free(input_type);
  6890.         return FONTCOLOR;
  6891.         }
  6892.         if( strcmp(input_type, arrow) == 0 ){
  6893.         free(input_type);
  6894.         return ARROW;
  6895.         }
  6896.         if( strcmp(input_type, arrow2) == 0 ){
  6897.         free(input_type);
  6898.         return ARROW2;
  6899.         }
  6900.         if( strcmp(input_type, darrow) == 0 ){
  6901.         free(input_type);
  6902.         use_dashed = TRUE;
  6903.         return ARROW;
  6904.         }
  6905.         if( strcmp(input_type, darrow2) == 0 ){
  6906.         free(input_type);
  6907.         use_dashed = TRUE;
  6908.         return ARROW2;
  6909.         }
  6910.         if( strcmp(input_type, zoom) == 0 ){
  6911.         free(input_type);
  6912.         return ZOOM;
  6913.         }
  6914.         if( strcmp(input_type, triangle) == 0 ){
  6915.         free(input_type);
  6916.         return TRIANGLE;
  6917.         }
  6918.         if( strcmp(input_type, ftriangle) == 0 ){
  6919.         free(input_type);
  6920.         use_filled = TRUE;
  6921.         return TRIANGLE;
  6922.         }
  6923.         if( strcmp(input_type, input) == 0 ){
  6924.         free(input_type);
  6925.         return INPUT;
  6926.         }
  6927.         if( strcmp(input_type, inputstyle) == 0 ){
  6928.         free(input_type);
  6929.         return INPUTSTYLE;
  6930.         }
  6931.         if( strcmp(input_type, textarea) == 0 ){
  6932.         free(input_type);
  6933.         return TEXTAREA;
  6934.         }
  6935.         if( strcmp(input_type, mathml) == 0 ){
  6936.         free(input_type);
  6937.         return MATHML;
  6938.         }
  6939.         if( strcmp(input_type, html) == 0 ){
  6940.         free(input_type);
  6941.         return MATHML;
  6942.         }
  6943.         if( strcmp(input_type, fontfamily) == 0 ){
  6944.         free(input_type);
  6945.         return FONTFAMILY;
  6946.         }
  6947.         if( strcmp(input_type, lines) == 0  ||  strcmp(input_type, polyline) == 0 ){
  6948.         free(input_type);
  6949.         return POLYLINE;
  6950.         }
  6951.         if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
  6952.         free(input_type);
  6953.         return RECT;
  6954.         }
  6955.         if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
  6956.         free(input_type);
  6957.         return ROUNDRECT;
  6958.         }
  6959.         if( strcmp(input_type, froundrect) == 0 ){
  6960.         free(input_type);
  6961.         use_filled = TRUE;
  6962.         return ROUNDRECT;
  6963.         }
  6964.         if( strcmp(input_type, square) == 0 ){
  6965.         free(input_type);
  6966.         return SQUARE;
  6967.         }
  6968.         if( strcmp(input_type, fsquare) == 0 ){
  6969.         free(input_type);
  6970.         use_filled = TRUE;
  6971.         return SQUARE;
  6972.         }
  6973.         if( strcmp(input_type, dline) == 0 ){
  6974.         use_dashed = TRUE;
  6975.         free(input_type);
  6976.         return LINE;
  6977.         }
  6978.         if( strcmp(input_type, dvline) == 0 ){
  6979.         use_dashed = TRUE;
  6980.         free(input_type);
  6981.         return VLINE;
  6982.         }
  6983.         if( strcmp(input_type, dhline) == 0 ){
  6984.         use_dashed = TRUE;
  6985.         free(input_type);
  6986.         return HLINE;
  6987.         }
  6988.         if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
  6989.         use_filled = TRUE;
  6990.         free(input_type);
  6991.         return RECT;
  6992.         }
  6993.         if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
  6994.         use_filled = TRUE;
  6995.         free(input_type);
  6996.         return CIRCLE;
  6997.         }
  6998.         if( strcmp(input_type, circle) == 0 ){
  6999.         free(input_type);
  7000.         return CIRCLE;
  7001.         }
  7002.         if( strcmp(input_type, point) == 0 ){
  7003.         free(input_type);
  7004.         return POINT;
  7005.         }
  7006.         if( strcmp(input_type, points) == 0 ){
  7007.         free(input_type);
  7008.         return POINTS;
  7009.         }
  7010.         if( strcmp(input_type, filledarc) == 0 ){
  7011.         use_filled = TRUE;
  7012.         free(input_type);
  7013.         return ARC;
  7014.         }
  7015.         if( strcmp(input_type, arc) == 0 ){
  7016.         free(input_type);
  7017.         return ARC;
  7018.         }
  7019.         if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
  7020.         free(input_type);
  7021.         return POLY;
  7022.         }
  7023.         if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
  7024.         use_filled = TRUE;
  7025.         free(input_type);
  7026.         return POLY;
  7027.         }
  7028.         if( strcmp(input_type, ellipse) == 0){
  7029.         free(input_type);
  7030.         return ELLIPSE;
  7031.         }
  7032.         if( strcmp(input_type, fill) == 0 ){
  7033.         free(input_type);
  7034.         return FLOODFILL;
  7035.         }
  7036.         if( strcmp(input_type, string) == 0 ){
  7037.         free(input_type);
  7038.         return STRING;
  7039.         }
  7040.         if( strcmp(input_type, stringup) == 0 ){
  7041.         free(input_type);
  7042.         return STRINGUP;
  7043.         }
  7044.         if( strcmp(input_type, opacity) == 0 ){
  7045.         free(input_type);
  7046.         return OPACITY;
  7047.         }
  7048.         if( strcmp(input_type, comment) == 0){
  7049.         free(input_type);
  7050.         return COMMENT;
  7051.         }
  7052.         if( strcmp(input_type, end) == 0){
  7053.         free(input_type);
  7054.         return END;
  7055.         }
  7056.         if( strcmp(input_type, fellipse) == 0){
  7057.         free(input_type);
  7058.         use_filled = TRUE;
  7059.         return ELLIPSE;
  7060.         }      
  7061.         if( strcmp(input_type, blink) == 0 ){
  7062.         free(input_type);
  7063.         return BLINK;
  7064.         }
  7065.         if( strcmp(input_type, button) == 0){
  7066.         free(input_type);
  7067.         return BUTTON;
  7068.         }
  7069.         if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
  7070.         free(input_type);
  7071.         return TRANSLATION;
  7072.         }
  7073.         if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
  7074.         free(input_type);
  7075.         return KILLTRANSLATION;
  7076.         }
  7077.         if( strcmp(input_type, rotate) == 0){
  7078.         free(input_type);
  7079.         return ROTATE;
  7080.         }
  7081.         if( strcmp(input_type, affine) == 0){
  7082.         free(input_type);
  7083.         return AFFINE;
  7084.         }
  7085.         if( strcmp(input_type, killaffine) == 0){
  7086.         free(input_type);
  7087.         return KILLAFFINE;
  7088.         }
  7089.         if( strcmp(input_type, audio) == 0 ){
  7090.         free(input_type);
  7091.         return AUDIO;
  7092.         }
  7093.         if( strcmp(input_type, audioobject) == 0 ){
  7094.         free(input_type);
  7095.         return AUDIOOBJECT;
  7096.         }
  7097.         if( strcmp(input_type, slider) == 0 ){
  7098.         free(input_type);
  7099.         return SLIDER;
  7100.         }
  7101.         if( strcmp(input_type, killslider) == 0 ){
  7102.         free(input_type);
  7103.         return KILLSLIDER;
  7104.         }
  7105.         if( strcmp(input_type, copy) == 0 ){
  7106.         free(input_type);
  7107.         return COPY;
  7108.         }
  7109.         if( strcmp(input_type, copyresized) == 0 ){
  7110.         free(input_type);
  7111.         return COPYRESIZED;
  7112.         }
  7113.         if( strcmp(input_type, patternfill) == 0 ){
  7114.         free(input_type);
  7115.         return PATTERNFILL;
  7116.         }
  7117.         if( strcmp(input_type, hatchfill) == 0 ){
  7118.         free(input_type);
  7119.         return HATCHFILL;
  7120.         }
  7121.         if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
  7122.         free(input_type);
  7123.         return DIAMONDFILL;
  7124.         }
  7125.         if( strcmp(input_type, dotfill) == 0 ){
  7126.         free(input_type);
  7127.         return DOTFILL;
  7128.         }
  7129.         if( strcmp(input_type, gridfill) == 0 ){
  7130.         free(input_type);
  7131.         return GRIDFILL;
  7132.         }
  7133.         if( strcmp(input_type, imagefill) == 0 ){
  7134.         free(input_type);
  7135.         return IMAGEFILL;
  7136.         }
  7137.         if( strcmp(input_type, clicktile_colors) == 0 ){
  7138.         free(input_type);
  7139.         return CLICKTILE_COLORS;
  7140.         }
  7141.         if( strcmp(input_type, clicktile) == 0 ){
  7142.         free(input_type);
  7143.         return CLICKTILE;
  7144.         }
  7145.         if( strcmp(input_type, xlogscale) == 0 ){
  7146.         free(input_type);
  7147.         return XLOGSCALE;
  7148.         }
  7149.         if( strcmp(input_type, ylogscale) == 0 ){
  7150.         free(input_type);
  7151.         return YLOGSCALE;
  7152.         }
  7153.         if( strcmp(input_type, xylogscale) == 0 ){
  7154.         free(input_type);
  7155.         return XYLOGSCALE;
  7156.         }
  7157.         if( strcmp(input_type, ylogscale) == 0 ){
  7158.         free(input_type);
  7159.         return YLOGSCALE;
  7160.         }
  7161.         if( strcmp(input_type, xlogbase) == 0 ){
  7162.         free(input_type);
  7163.         return XLOGBASE;
  7164.         }
  7165.         if( strcmp(input_type, ylogbase) == 0 ){
  7166.         free(input_type);
  7167.         return YLOGBASE;
  7168.         }
  7169.         if( strcmp(input_type, intooltip) == 0 ){
  7170.         free(input_type);
  7171.         return INTOOLTIP;
  7172.         }
  7173.         if( strcmp(input_type,video) == 0 ){
  7174.         free(input_type);
  7175.         return VIDEO;
  7176.         }
  7177.         if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
  7178.         free(input_type);
  7179.         return FLOODFILL;
  7180.         }      
  7181.         if( strcmp(input_type,filltoborder) == 0 ){
  7182.         free(input_type);
  7183.         return FILLTOBORDER;
  7184.         }      
  7185.         if( strcmp(input_type,clickfill) == 0 ){
  7186.         free(input_type);
  7187.         return CLICKFILL;
  7188.         }      
  7189.         if( strcmp(input_type, replyformat) == 0 ){
  7190.         free(input_type);
  7191.         return REPLYFORMAT;
  7192.         }
  7193.         if( strcmp(input_type, pixelsize) == 0 ){
  7194.         free(input_type);
  7195.         return PIXELSIZE;
  7196.         }
  7197.         if( strcmp(input_type, setpixel) == 0 ){
  7198.         free(input_type);
  7199.         return SETPIXEL;
  7200.         }
  7201.         if( strcmp(input_type, pixels) == 0 ){
  7202.         free(input_type);
  7203.         return PIXELS;
  7204.         }
  7205.         if( strcmp(input_type, clickfillmarge) == 0 ){
  7206.         free(input_type);
  7207.         return CLICKFILLMARGE;
  7208.         }
  7209.         if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
  7210.         free(input_type);
  7211.         return X_AXIS_STRINGS;
  7212.         }
  7213.         if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
  7214.         free(input_type);
  7215.         return Y_AXIS_STRINGS;
  7216.         }
  7217.         if( strcmp(input_type, piechart) == 0  ){
  7218.         free(input_type);
  7219.         return PIECHART;
  7220.         }
  7221.         if( strcmp(input_type, barchart) == 0  ){
  7222.         free(input_type);
  7223.         return BARCHART;
  7224.         }
  7225.         if( strcmp(input_type, linegraph) == 0  ){
  7226.         free(input_type);
  7227.         return LINEGRAPH;
  7228.         }
  7229.         if( strcmp(input_type, clock) == 0  ){
  7230.         free(input_type);
  7231.         return CLOCK;
  7232.         }
  7233.         if( strcmp(input_type, legend) == 0  ){
  7234.         free(input_type);
  7235.         return LEGEND;
  7236.         }
  7237.         if( strcmp(input_type, legendcolors) == 0  ){
  7238.         free(input_type);
  7239.         return LEGENDCOLORS;
  7240.         }
  7241.         if( strcmp(input_type, xlabel) == 0  ){
  7242.         free(input_type);
  7243.         return XLABEL;
  7244.         }
  7245.         if( strcmp(input_type, ylabel) == 0  ){
  7246.         free(input_type);
  7247.         return YLABEL;
  7248.         }
  7249.         if( strcmp(input_type, animate) == 0  ){
  7250.         free(input_type);
  7251.         return ANIMATE;
  7252.         }
  7253.         /* these are bitmap related flydraw commmands...must be removed. eventually */
  7254.         if( strcmp(input_type, transparent) == 0 ){
  7255.         free(input_type);
  7256.         return TRANSPARENT;
  7257.         }
  7258.         if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
  7259.         free(input_type);
  7260.         return STATUS;
  7261.         }
  7262.         if( strcmp(input_type, snaptogrid) == 0 ){
  7263.         free(input_type);
  7264.         return SNAPTOGRID;
  7265.         }
  7266.         if( strcmp(input_type, xsnaptogrid) == 0 ){
  7267.         free(input_type);
  7268.         return XSNAPTOGRID;
  7269.         }
  7270.         if( strcmp(input_type, ysnaptogrid) == 0 ){
  7271.         free(input_type);
  7272.         return YSNAPTOGRID;
  7273.         }
  7274.         if( strcmp(input_type, userinput_xy) == 0 ){
  7275.         free(input_type);
  7276.         return USERINPUT_XY;
  7277.         }
  7278.         if( strcmp(input_type, usertextarea_xy) == 0 ){
  7279.         free(input_type);
  7280.         return USERTEXTAREA_XY;
  7281.         }
  7282.         if( strcmp(input_type, sgraph) == 0 ){
  7283.         free(input_type);
  7284.         return SGRAPH;
  7285.         }
  7286.         if( strcmp(input_type, jsmath) == 0 ){
  7287.         free(input_type);
  7288.         return JSMATH;
  7289.         }
  7290.         if( strcmp(input_type, trace_jscurve) == 0 ){
  7291.         free(input_type);
  7292.         return TRACE_JSCURVE;
  7293.         }
  7294.         if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
  7295.         free(input_type);
  7296.         return JSCURVE;
  7297.         }
  7298.         if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
  7299.         free(input_type);
  7300.         return CENTERSTRING;
  7301.         }
  7302.         if( strcmp(input_type, setlimits) == 0 ){
  7303.         free(input_type);
  7304.         return SETLIMITS;
  7305.         }
  7306.         if( strcmp(input_type, xunit) == 0 ){
  7307.         free(input_type);
  7308.         return XUNIT;
  7309.         }
  7310.         if( strcmp(input_type, yunit) == 0 ){
  7311.         free(input_type);
  7312.         return YUNIT;
  7313.         }
  7314.         if( strcmp(input_type, angle) == 0 ){
  7315.         free(input_type);
  7316.         return ANGLE;
  7317.         }
  7318.         free(input_type);
  7319.         ungetc(c,infile);
  7320.         return 0;
  7321. }
  7322.  
  7323.