Subversion Repositories wimsdev

Rev

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