Subversion Repositories wimsdev

Rev

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