Subversion Repositories wimsdev

Rev

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