Subversion Repositories wimsdev

Rev

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