Subversion Repositories wimsdev

Rev

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