Subversion Repositories wimsdev

Rev

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