Subversion Repositories wimsdev

Rev

Rev 7792 | Rev 7797 | 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 = 250;
  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_start=xmin;var xmax_start=xmax;\
  2709.  var ymin_start=ymin;var ymax_start=xmax;\
  2710.  var zoom_x_increment=0;var zoom_y_increment=0;\
  2711.  var pan_x_increment=0;var pan_y_increment=0;\
  2712.  if(use_ylogscale == 0 ){\
  2713.   zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (xmax - xmin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\
  2714.  }else{\
  2715.   zoom_x_increment = (xmax - xmin)/20;\
  2716.   pan_x_increment = (xmax - xmin)/20;\
  2717.  };\
  2718.  function start_canvas%d(type){\
  2719.   switch(type){\
  2720.    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
  2721.    case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\
  2722.    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
  2723.    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
  2724.    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
  2725.    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
  2726.    case 6:location.reload();break;\
  2727.    default:break;\
  2728.   };\
  2729.   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
  2730.   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
  2731.   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){}\
  2732.   %s\
  2733.  };\
  2734. };\n\
  2735. <!-- end wims_canvas_function -->\n\
  2736. wims_canvas_function%d();\n",precision,canvas_root_id,buffer,canvas_root_id);
  2737. /* done writing the javascript include file */
  2738. fclose(js_include_file);
  2739.  
  2740. }
  2741.  
  2742. /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
  2743. if(use_tooltip == TRUE){
  2744.   add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
  2745. }
  2746. exit(EXIT_SUCCESS);
  2747. }
  2748. /* end main() */
  2749.  
  2750. /******************************************************************************
  2751. **
  2752. **  sync_input
  2753. **
  2754. **  synchronises input line - reads to end of line, leaving file pointer
  2755. **  at first character of next line.
  2756. **
  2757. **  Used by:
  2758. **  main program - error handling.
  2759. **
  2760. ******************************************************************************/
  2761. void sync_input(FILE *infile)
  2762. {
  2763.         int c = 0;
  2764.  
  2765.         if( c == '\n' || c == ';' ) return;
  2766.         while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
  2767.         if( c == EOF ) finished = 1;
  2768.         if( c == '\n' || c == '\r' || c == ';') line_number++;
  2769.         return;
  2770. }
  2771.  
  2772. /******************************************************************************/
  2773.  
  2774. char *str_replace(const char *str, const char *old, const char *new){
  2775. /* http://creativeandcritical.net/str-replace-c/ */
  2776.     if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
  2777.     char *ret, *r;
  2778.     const char *p, *q;
  2779.     size_t oldlen = strlen(old);
  2780.     size_t count = 0;
  2781.     size_t retlen = 0;
  2782.     size_t newlen = strlen(new);
  2783.     if (oldlen != newlen){
  2784.         for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
  2785.             count++;
  2786.             retlen = p - str + strlen(p) + count * (newlen - oldlen);
  2787.         }
  2788.     }
  2789.     else
  2790.     {
  2791.         retlen = strlen(str);
  2792.     }
  2793.    
  2794.     if ((ret = malloc(retlen + 1)) == NULL){
  2795.         ret = NULL;
  2796.         canvas_error("string argument is NULL");
  2797.     }
  2798.     else
  2799.     {
  2800.         for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
  2801.             size_t l = q - p;
  2802.             memcpy(r, p, l);
  2803.             r += l;
  2804.             memcpy(r, new, newlen);
  2805.             r += newlen;
  2806.         }
  2807.         strcpy(r, p);
  2808.     }
  2809.     return ret;
  2810. }
  2811.  
  2812. /******************************************************************************/
  2813. /*
  2814. avoid the use of ctypes.h for tolower() toupper();
  2815. it gives trouble in FreeBSD 9.0 / 9.1 when used in a chroot environment (C library bug) : Undefined symbol "_ThreadRuneLocale"
  2816. Upper case -> Lower case : c = c - 'A'+ 'a';
  2817. Lower case ->  Upper case  c = c + 'A'  - 'a';
  2818. */
  2819. int tolower(int c){
  2820.  if(c <= 'Z'){
  2821.   if (c >= 'A'){
  2822.    return c - 'A' + 'a';
  2823.   }
  2824.  }
  2825.  return c;
  2826. }
  2827.  
  2828. int toupper(int c){
  2829.  if(c >= 'a' && c <= 'z'){
  2830.    return c + 'A' - 'a';
  2831.  }
  2832.  return c;
  2833. }
  2834.  
  2835. char *get_color(FILE *infile , int last){
  2836.     int c,i = 0,is_hex = 0;
  2837.     char temp[MAX_COLOR_STRING], *string;
  2838.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){
  2839.         if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
  2840.         if( c == '#' ){
  2841.             is_hex = 1;
  2842.         }
  2843.         if( c != ' '){
  2844.             temp[i]=tolower(c);
  2845.             i++;
  2846.         }
  2847.     }
  2848.     if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
  2849.     if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
  2850.     if( c == EOF ){finished = 1;}
  2851.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  2852.     temp[i]='\0';
  2853.     if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
  2854.     if( is_hex == 1 ){
  2855.         char red[3], green[3], blue[3];
  2856.         red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
  2857.         green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
  2858.         blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
  2859.         int r = (int) strtol(red,   NULL, 16);
  2860.         int g = (int) strtol(green, NULL, 16);
  2861.         int b = (int) strtol(blue,  NULL, 16);
  2862.         string = (char *)my_newmem(12);
  2863.         snprintf(string,11,"%d,%d,%d",r,g,b);
  2864.         return string;
  2865.     }
  2866.     else
  2867.     {
  2868.         string = (char *)my_newmem(sizeof(temp));
  2869.         snprintf(string,sizeof(temp),"%s",temp);
  2870.         for( i = 0; i <= NUMBER_OF_COLORNAMES ; i++ ){
  2871.             if( strcmp( colors[i].name , string ) == 0 ){
  2872.                 return colors[i].rgb;
  2873.             }
  2874.         }
  2875.     }
  2876.     /* not found...return error */
  2877.     free(string);string = NULL;
  2878.     canvas_error("I was expecting a color name or hexnumber...but found nothing.");
  2879.     return NULL;
  2880. }
  2881.  
  2882. char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
  2883.     int c,i=0;
  2884.     char  temp[MAX_BUFFER], *string;
  2885.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){
  2886.         temp[i]=c;
  2887.         i++;
  2888.         if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
  2889.     }
  2890.     if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  2891.     if( c == '\n') { done = TRUE; line_number++; }
  2892.     if( c == EOF ) {
  2893.         finished = 1;
  2894.         if( last != 1 ){ canvas_error("expected more arguments");}
  2895.     }
  2896.     temp[i]='\0';
  2897.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");}
  2898.     string=(char *)my_newmem(strlen(temp));
  2899.     snprintf(string,sizeof(temp),"%s",temp);
  2900.     return string;
  2901. }
  2902.  
  2903. char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
  2904.     int c,i=0;
  2905.     char temp[MAX_BUFFER], *string;
  2906.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',')){
  2907.         temp[i]=c;
  2908.         i++;
  2909.         if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
  2910.     }
  2911.     if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
  2912.     if( c == '\n') { line_number++; }
  2913.     if( c == EOF ) {finished = 1;}
  2914.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  2915.     temp[i]='\0';
  2916.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
  2917.     string=(char *)my_newmem(sizeof(temp));
  2918.     snprintf(string,sizeof(temp),"%s",temp);
  2919.     done = TRUE;
  2920.     return string;
  2921. }
  2922.  
  2923. double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
  2924.     int c,i=0,found_calc = 0;
  2925.     double y;
  2926.     char tmp[MAX_INT];
  2927.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){
  2928.      if( c != ' ' ){
  2929.      /*
  2930.      libmatheval will segfault when for example: "xrange -10,+10" or "xrange -10,10+" is used
  2931.      We will check after assert() if it's a NULL pointer...and exit program via :
  2932.      canvas_error("I'm having trouble parsing your \"expression\" ");
  2933.      */
  2934.       if( i == 0 &&  c == '+' ){
  2935.        continue;
  2936.       }
  2937.       else
  2938.       {
  2939.        if(canvas_iscalculation(c) != 0){
  2940.         found_calc = 1;
  2941.         c = tolower(c);
  2942.        }
  2943.        tmp[i] = c;
  2944.        i++;
  2945.       }
  2946.      }
  2947.      if( i > MAX_INT - 1){canvas_error("number too large");}
  2948.     }
  2949.     if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
  2950.     if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
  2951.     if( c == EOF ){done = TRUE ; finished = 1;}
  2952.     tmp[i]='\0';
  2953.     if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
  2954.     if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */
  2955.      void *f = evaluator_create(tmp);
  2956.      assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  2957.      y = evaluator_evaluate_x(f, 1);
  2958.      /* if function is bogus; y = 1 : so no core dumps */
  2959.      evaluator_destroy(f);
  2960.     }
  2961.     else
  2962.     {
  2963.      y = atof(tmp);
  2964.     }
  2965.     return y;
  2966. }
  2967. void canvas_error(char *msg){
  2968.     fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg);
  2969.     finished = 1;
  2970.     exit(EXIT_SUCCESS);
  2971. }
  2972.  
  2973.  
  2974. /* convert x/y coordinates to pixel */
  2975. int x2px(double x){
  2976.  return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
  2977. }
  2978.  
  2979. int y2px(double y){
  2980.  return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
  2981. }
  2982.  
  2983. double px2x(int x){
  2984.  return (x*(xmax - xmin)/xsize + xmin);
  2985. }
  2986. double px2y(int y){
  2987.  return (y*(ymax - ymin)/ysize + ymin);
  2988. }
  2989.  
  2990. void add_to_buffer(char *tmp){
  2991.  if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
  2992.  /*  do we have enough space left in buffer[MAX_BUFFER] ? */
  2993.  int space_left = (int) (sizeof(buffer) - strlen(buffer));
  2994.  if( space_left > strlen(tmp)){
  2995.   strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
  2996.  }
  2997.  else
  2998.  {
  2999.   canvas_error("buffer is too big\n");
  3000.  }
  3001.  tmp = NULL;free(tmp);
  3002.  return;
  3003. }
  3004.  
  3005. void reset(){
  3006.  if(use_filled == TRUE){use_filled = FALSE;}
  3007.  if(use_dashed == TRUE){use_dashed = FALSE;}
  3008.  if(use_translate == TRUE){use_translate = FALSE;}
  3009.  if(use_rotate == TRUE){use_rotate = FALSE;}
  3010.  onclick = 0;
  3011. }
  3012.  
  3013.  
  3014.  
  3015. /* What reply format in read_canvas();
  3016.  
  3017. note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
  3018. 1 = x1,x2,x3,x4....x_n
  3019.     y1,y2,y3,y4....y_n
  3020.  
  3021.     x/y in pixels
  3022.  
  3023. 2 = x1,x2,x3,x4....x_n
  3024.     y1,y2,y3,y4....y_n
  3025.     x/y in  xrange / yrange coordinate system
  3026.  
  3027. 3 = x1,x2,x3,x4....x_n
  3028.     y1,y2,y3,y4....y_n
  3029.     r1,r2,r3,r4....r_n
  3030.  
  3031.     x/y in pixels
  3032.     r in pixels
  3033.  
  3034. 4 = x1,x2,x3,x4....x_n
  3035.     y1,y2,y3,y4....y_n
  3036.     r1,r2,r3,r4....r_n
  3037.  
  3038.     x/y in  xrange / yrange coordinate system
  3039.     r in pixels
  3040.  
  3041. 5 = Ax1,Ax2,Ax3,Ax4....Ax_n
  3042.     Ay1,Ay2,Ay3,Ay4....Ay_n
  3043.     Bx1,Bx2,Bx3,Bx4....Bx_n
  3044.     By1,By2,By3,By4....By_n
  3045.     Cx1,Cx2,Cx3,Cx4....Cx_n
  3046.     Cy1,Cy2,Cy3,Cy4....Cy_n
  3047.     ....
  3048.     Zx1,Zx2,Zx3,Zx4....Zx_n
  3049.     Zy1,Zy2,Zy3,Zy4....Zy_n
  3050.    
  3051.     x/y in pixels
  3052.  
  3053. 6 = Ax1,Ax2,Ax3,Ax4....Ax_n
  3054.     Ay1,Ay2,Ay3,Ay4....Ay_n
  3055.     Bx1,Bx2,Bx3,Bx4....Bx_n
  3056.     By1,By2,By3,By4....By_n
  3057.     Cx1,Cx2,Cx3,Cx4....Cx_n
  3058.     Cy1,Cy2,Cy3,Cy4....Cy_n
  3059.     ....
  3060.     Zx1,Zx2,Zx3,Zx4....Zx_n
  3061.     Zy1,Zy2,Zy3,Zy4....Zy_n
  3062.  
  3063.     x/y in  xrange / yrange coordinate system
  3064.    
  3065. 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  3066.    
  3067.     x/y in pixels
  3068.  
  3069. 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  3070.    
  3071.     x/y in  xrange / yrange coordinate system
  3072.  
  3073. 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n    
  3074.  
  3075.     x/y in pixels
  3076.  
  3077. 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n    
  3078.  
  3079.     x/y in  xrange / yrange coordinate system
  3080.  
  3081. 11 = Ax1,Ay1,Ax2,Ay2
  3082.      Bx1,By1,Bx2,By2
  3083.      Cx1,Cy1,Cx2,Cy2
  3084.      Dx1,Dy1,Dx2,Dy2
  3085.      ......
  3086.      Zx1,Zy1,Zx2,Zy2
  3087.      
  3088.     x/y in  xrange / yrange coordinate system
  3089.  
  3090. 12 = Ax1,Ay1,Ax2,Ay2
  3091.      Bx1,By1,Bx2,By2
  3092.      Cx1,Cy1,Cx2,Cy2
  3093.      Dx1,Dy1,Dx2,Dy2
  3094.      ......
  3095.      Zx1,Zy1,Zx2,Zy2
  3096.      
  3097.     x/y in pixels
  3098.  
  3099. 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
  3100.  
  3101.     x/y in  xrange / yrange coordinate system
  3102. 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
  3103.     x/y in pixels
  3104. 15 = reply from inputfields,textareas
  3105.     reply1,reply2,reply3,...,reply_n
  3106.  
  3107. 16 = read mathml inputfields only
  3108.  
  3109. 17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n
  3110.  when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
  3111.  
  3112. 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
  3113. 19 = return clicked object number (analogue to shape-library onclick)
  3114. 20 = return x/y-data in x-range/y-range of all 'draggable' images
  3115. 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
  3116. 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
  3117.     x/y in  xrange / yrange coordinate system
  3118. 23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
  3119. */
  3120.  
  3121.  
  3122. void add_read_canvas(int type_reply){
  3123. /* just 1 reply type allowed */
  3124. switch(type_reply){
  3125. /*  TO DO
  3126. !!!!  NEED TO SIMPLIFY !!!!  
  3127. answers may have:
  3128. x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
  3129. */
  3130.     case 1: fprintf(js_include_file,"\
  3131. \n<!-- begin function 1 read_canvas() -->\n\
  3132. function read_canvas(){\
  3133. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3134. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3135.  var p = 0;var input_reply = new Array();\
  3136.  if( document.getElementById(\"canvas_input0\")){\
  3137.   var t = 0;\
  3138.   while(document.getElementById(\"canvas_input\"+t)){\
  3139.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3140.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3141.     p++;\
  3142.    };\
  3143.    t++;\
  3144.   };\
  3145.  };\
  3146.  if( typeof userdraw_text != 'undefined' ){\
  3147.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
  3148.  }\
  3149.  else\
  3150.  {\
  3151.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
  3152.  }\
  3153. }\
  3154. else\
  3155. {\
  3156.  if( typeof userdraw_text != 'undefined' ){\
  3157.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
  3158.  }\
  3159.  else\
  3160.  {\
  3161.   return userdraw_x+\"\\n\"+userdraw_y;\
  3162.  }\
  3163. };\
  3164. };\
  3165. this.read_canvas = read_canvas;\n\
  3166. <!-- end function 1 read_canvas() -->");
  3167.     break;
  3168.     case 2: fprintf(js_include_file,"\
  3169. \n<!-- begin function 2 read_canvas() -->\n\
  3170. function read_canvas(){\
  3171. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3172. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  3173. while(userdraw_x[p]){\
  3174.  reply_x[p] = px2x(userdraw_x[p]);\
  3175.  reply_y[p] = px2y(userdraw_y[p]);\
  3176.  p++;\
  3177. };\
  3178. if(p == 0){alert(\"nothing drawn...\");return;};\
  3179. if( document.getElementById(\"canvas_input0\")){\
  3180.  var p = 0;var input_reply = new Array();\
  3181.  if( document.getElementById(\"canvas_input0\")){\
  3182.   var t = 0;\
  3183.   while(document.getElementById(\"canvas_input\"+t)){\
  3184.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3185.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3186.     p++;\
  3187.    };\
  3188.    t++;\
  3189.   };\
  3190.  };\
  3191.  if( typeof userdraw_text != 'undefined' ){\
  3192.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3193.  }\
  3194.  else\
  3195.  {\
  3196.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  3197.  }\
  3198. }\
  3199. else\
  3200. {\
  3201.  if( typeof userdraw_text != 'undefined' ){\
  3202.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  3203.  }\
  3204.  else\
  3205.  {\
  3206.   return reply_x+\"\\n\"+reply_y;\
  3207.  };\
  3208. };\
  3209. };\
  3210. this.read_canvas = read_canvas;\n\
  3211. <!-- end function 2 read_canvas() -->");
  3212.     break;
  3213.     case 3: fprintf(js_include_file,"\
  3214. \n<!-- begin function 3 read_canvas() -->\n\
  3215. function read_canvas(){\
  3216. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3217. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3218.  var p = 0;var input_reply = new Array();\
  3219.  if( document.getElementById(\"canvas_input0\")){\
  3220.   var t = 0;\
  3221.   while(document.getElementById(\"canvas_input\"+t)){\
  3222.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3223.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3224.     p++;\
  3225.    };\
  3226.    t++;\
  3227.   };\
  3228.  };\
  3229.  if( typeof userdraw_text != 'undefined' ){\
  3230.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3231.  }\
  3232.  else\
  3233.  {\
  3234.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  3235.  }\
  3236. }\
  3237. else\
  3238. {\
  3239.  if( typeof userdraw_text != 'undefined' ){\
  3240.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
  3241.  }\
  3242.  else\
  3243.  {\
  3244.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
  3245.  }\
  3246. }\
  3247. };\
  3248. this.read_canvas = read_canvas;\n\
  3249. <!-- end function 3 read_canvas() -->");
  3250.     break;
  3251.     case 4: fprintf(js_include_file,"\
  3252. \n<!-- begin function 4 read_canvas() -->\n\
  3253. function read_canvas(){\
  3254. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  3255. while(userdraw_x[p]){\
  3256.  reply_x[p] = px2x(userdraw_x[p]);\
  3257.  reply_y[p] = px2y(userdraw_y[p]);\
  3258.  p++;\
  3259. };\
  3260. if(p == 0){alert(\"nothing drawn...\");return;};\
  3261. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3262.  var p = 0;var input_reply = new Array();\
  3263.  if( document.getElementById(\"canvas_input0\")){\
  3264.   var t = 0;\
  3265.   while(document.getElementById(\"canvas_input\"+t)){\
  3266.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3267.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3268.     p++;\
  3269.    };\
  3270.    t++;\
  3271.   };\
  3272.  };\
  3273.  if( typeof userdraw_text != 'undefined' ){\
  3274.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3275.  }\
  3276.  else\
  3277.  {\
  3278.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  3279.  }\
  3280. }\
  3281. else\
  3282. {\
  3283.  if( typeof userdraw_text != 'undefined' ){\
  3284.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
  3285.  }\
  3286.  else\
  3287.  {\
  3288.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
  3289.  }\
  3290. };\
  3291. };\
  3292. this.read_canvas = read_canvas;\n\
  3293. <!-- end function 4 read_canvas() -->");
  3294.     break;
  3295.     /*
  3296.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  3297.         used for userdraw multiple paths
  3298.     */
  3299.     case 5: fprintf(js_include_file,"\
  3300. \n<!-- begin function 5 read_canvas() -->\n\
  3301. function read_canvas(){\
  3302. var p = 0;\
  3303. var reply = \"\";\
  3304. for(p = 0; p < userdraw_x.length;p++){\
  3305.  if(userdraw_x[p] != null ){\
  3306.   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
  3307.  };\
  3308. };\
  3309. if(p == 0){alert(\"nothing drawn...\");return;};\
  3310. userdraw_x = [];userdraw_y = [];\
  3311. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3312.  var p = 0;var input_reply = new Array();\
  3313.  if( document.getElementById(\"canvas_input0\")){\
  3314.   var t = 0;\
  3315.   while(document.getElementById(\"canvas_input\"+t)){\
  3316.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3317.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3318.     p++;\
  3319.    };\
  3320.    t++;\
  3321.   };\
  3322.  };\
  3323.  if( typeof userdraw_text != 'undefined' ){\
  3324.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3325.  }\
  3326.  else\
  3327.  {\
  3328.   return reply +\"\\n\"+input_reply;\
  3329.  }\
  3330. }\
  3331. else\
  3332. {\
  3333.  if( typeof userdraw_text != 'undefined' ){\
  3334.   return reply+\"\\n\"+userdraw_text;\
  3335.  }\
  3336.  else\
  3337.  {\
  3338.   return reply;\
  3339.  }\
  3340. };\
  3341. };\
  3342. this.read_canvas = rdad_canvas;\n\
  3343. <!-- end function 5 read_canvas() -->");
  3344.     break;
  3345.     /*
  3346.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  3347.         used for userdraw multiple paths
  3348.     */
  3349.     case 6: fprintf(js_include_file,"\
  3350. \n<!-- begin function 6 read_canvas() -->\n\
  3351. function read_canvas(){\
  3352. var p = 0;\
  3353. var reply = \"\";\
  3354. var tmp_x = new Array();\
  3355. var tmp_y = new Array();\
  3356. for(p = 0 ; p < userdraw_x.length; p++){\
  3357.  tmp_x = userdraw_x[p];\
  3358.  tmp_y = userdraw_y[p];\
  3359.  if(tmp_x != null){\
  3360.   for(var i = 0 ; i < tmp_x.length ; i++){\
  3361.    tmp_x[i] = px2x(tmp_x[i]);\
  3362.    tmp_y[i] = px2y(tmp_y[i]);\
  3363.   };\
  3364.   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
  3365.  };\
  3366. };\
  3367. if(p == 0){alert(\"nothing drawn...\");return;};\
  3368. userdraw_x = [];userdraw_y = [];\
  3369. if( document.getElementById(\"canvas_input0\") ){\
  3370.  var p = 0;var input_reply = new Array();\
  3371.  if( document.getElementById(\"canvas_input0\")){\
  3372.   var t = 0;\
  3373.   while(document.getElementById(\"canvas_input\"+t)){\
  3374.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3375.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3376.     p++;\
  3377.    };\
  3378.    t++;\
  3379.   };\
  3380.  };\
  3381.  if( typeof userdraw_text != 'undefined' ){\
  3382.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3383.  }\
  3384.  else\
  3385.  {\
  3386.   return reply +\"\\n\"+input_reply;\
  3387.  }\
  3388. }\
  3389. else\
  3390. {\
  3391.  if( typeof userdraw_text != 'undefined' ){\
  3392.   return reply +\"\\n\"+userdraw_text;\
  3393.  }\
  3394.  else\
  3395.  {\
  3396.   return reply;\
  3397.  }\
  3398. };\
  3399. };\
  3400. this.read_canvas = read_canvas;\n\
  3401. <!-- end function 6 read_canvas() -->");
  3402.     break;
  3403.     case 7: fprintf(js_include_file,"\
  3404. \n<!-- begin function 7 read_canvas() -->\n\
  3405. function read_canvas(){\
  3406. var reply = new Array();\
  3407. var p = 0;\
  3408. while(userdraw_x[p]){\
  3409.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
  3410.  p++;\
  3411. };\
  3412. if(p == 0){alert(\"nothing drawn...\");return;};\
  3413. if( document.getElementById(\"canvas_input0\") ){\
  3414.  var p = 0;var input_reply = new Array();\
  3415.  if( document.getElementById(\"canvas_input0\")){\
  3416.   var t = 0;\
  3417.   while(document.getElementById(\"canvas_input\"+t)){\
  3418.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3419.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3420.     p++;\
  3421.    };\
  3422.    t++;\
  3423.   };\
  3424.  };\
  3425.  if( typeof userdraw_text != 'undefined' ){\
  3426.   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3427.  }\
  3428.  else\
  3429.  {\
  3430.   return reply+\"\\n\"+input_reply;\
  3431.  }\
  3432. };\
  3433. else\
  3434. {\
  3435.  if( typeof userdraw_text != 'undefined' ){\
  3436.   return reply+\"\\n\"+userdraw_text;\
  3437.  }\
  3438.  else\
  3439.  {\
  3440.   return reply;\
  3441.  }\
  3442. };\
  3443. };\
  3444. this.read_canvas = read_canvas;\n\
  3445. <!-- end function 7 read_canvas() -->");
  3446.     break;
  3447.     case 8: fprintf(js_include_file,"\
  3448. \n<!-- begin function 8 read_canvas() -->\n\
  3449. function read_canvas(){\
  3450. var reply = new Array();\
  3451. var p = 0;\
  3452. while(userdraw_x[p]){\
  3453.  reply[p] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]);\
  3454.  p++;\
  3455. };\
  3456. if(p == 0){alert(\"nothing drawn...\");return;};\
  3457. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3458.  var p = 0;var input_reply = new Array();\
  3459.  if( document.getElementById(\"canvas_input0\")){\
  3460.   var t = 0;\
  3461.   while(document.getElementById(\"canvas_input\"+t)){\
  3462.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3463.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3464.     p++;\
  3465.    };\
  3466.    t++;\
  3467.   };\
  3468.  };\
  3469.  if( typeof userdraw_text != 'undefined' ){\
  3470.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3471.  }\
  3472.  else\
  3473.  {\
  3474.   return reply +\"\\n\"+input_reply;\
  3475.  }\
  3476. }\
  3477. else\
  3478. {\
  3479.  if( typeof userdraw_text != 'undefined' ){\
  3480.   return reply +\"\\n\"+userdraw_text;\
  3481.  }\
  3482.  else\
  3483.  {\
  3484.   return reply;\
  3485.  }\
  3486. };\
  3487. };\
  3488. this.read_canvas = read_canvas;\n\
  3489. <!-- end function 8 read_canvas() -->");
  3490.     break;
  3491.     case 9: fprintf(js_include_file,"\
  3492. \n<!-- begin function 9 read_canvas() -->\n\
  3493. function read_canvas(){\
  3494. var reply = new Array();\
  3495. var p = 0;\
  3496. while(userdraw_x[p]){\
  3497.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
  3498.  p++;\
  3499. };\
  3500. if(p == 0){alert(\"nothing drawn...\");return;};\
  3501. if( document.getElementById(\"canvas_input0\") ){\
  3502.  var p = 0;var input_reply = new Array();\
  3503.  if( document.getElementById(\"canvas_input0\")){\
  3504.   var t = 0;\
  3505.   while(document.getElementById(\"canvas_input\"+t)){\
  3506.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3507.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3508.     p++;\
  3509.    };\
  3510.    t++;\
  3511.   };\
  3512.  };\
  3513.  if( typeof userdraw_text != 'undefined' ){\
  3514.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3515.  }\
  3516.  else\
  3517.  {\
  3518.   return reply +\"\\n\"+input_reply;\
  3519.  }\
  3520. }\
  3521. else\
  3522. {\
  3523.  if( typeof userdraw_text != 'undefined' ){\
  3524.   return reply +\"\\n\"+userdraw_text;\
  3525.  }\
  3526.  else\
  3527.  {\
  3528.   return reply;\
  3529.  }\
  3530. };\
  3531. };\
  3532. this.read_canvas = read_canvas;\n\
  3533. <!-- end function 9 read_canvas() -->");
  3534.     break;
  3535.     case 10: fprintf(js_include_file,"\
  3536. \n<!-- begin function 10 read_canvas() -->\n\
  3537. function read_canvas(){\
  3538. var reply = new Array();\
  3539. var p = 0;\
  3540. while(userdraw_x[p]){\
  3541.  reply[p] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]) +\":\" + userdraw_radius[p];\
  3542.  p++;\
  3543. };\
  3544. if(p == 0){alert(\"nothing drawn...\");return;};\
  3545. if( document.getElementById(\"canvas_input0\") ){\
  3546.  var p = 0;var input_reply = new Array();\
  3547.  if( document.getElementById(\"canvas_input0\")){\
  3548.   var t = 0;\
  3549.   while(document.getElementById(\"canvas_input\"+t)){\
  3550.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3551.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3552.     p++;\
  3553.    };\
  3554.    t++;\
  3555.   };\
  3556.  };\
  3557.  if( typeof userdraw_text != 'undefined' ){\
  3558.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3559.  }\
  3560.  else\
  3561.  {\
  3562.   return reply +\"\\n\"+input_reply;\
  3563.  }\
  3564. }\
  3565. else\
  3566. {\
  3567.  if( typeof userdraw_text != 'undefined' ){\
  3568.   return reply +\"\\n\"+userdraw_text;\
  3569.  }\
  3570.  else\
  3571.  {\
  3572.   return reply;\
  3573.  }\
  3574. };\
  3575. };\
  3576. this.read_canvas = read_canvas;\n\
  3577. <!-- end function 10 read_canvas() -->");
  3578.     break;
  3579.     case 11: fprintf(js_include_file,"\
  3580. \n<!-- begin function 11 read_canvas() -->\n\
  3581. function read_canvas(){\
  3582. var reply = \"\";\
  3583. var p = 0;\
  3584. while(userdraw_x[p]){\
  3585.  reply = reply + px2x(userdraw_x[p]) +\",\" + px2y(userdraw_y[p]) +\",\" + px2x(userdraw_x[p+1]) +\",\" + px2y(userdraw_y[p+1]) +\"\\n\" ;\
  3586.  p = p+2;\
  3587. };\
  3588. if(p == 0){alert(\"nothing drawn...\");return;};\
  3589. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3590.  var p = 0;var input_reply = new Array();\
  3591.  if( document.getElementById(\"canvas_input0\")){\
  3592.   var t = 0;\
  3593.   while(document.getElementById(\"canvas_input\"+t)){\
  3594.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3595.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3596.     p++;\
  3597.    };\
  3598.    t++;\
  3599.   };\
  3600.  };\
  3601.  if( typeof userdraw_text != 'undefined' ){\
  3602.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3603.  }\
  3604.  else\
  3605.  {\
  3606.   return reply +\"\\n\"+input_reply;\
  3607.  }\
  3608. }\
  3609. else\
  3610. {\
  3611.  if( typeof userdraw_text != 'undefined' ){\
  3612.   return reply +\"\\n\"+userdraw_text;\
  3613.  }\
  3614.  else\
  3615.  {\
  3616.   return reply;\
  3617.  }\
  3618. };\
  3619. };\
  3620. this.read_canvas = read_canvas;\n\
  3621. <!-- end function 11 read_canvas() -->");
  3622.     break;
  3623.     case 12: fprintf(js_include_file,"\
  3624. \n<!-- begin function 12 read_canvas() -->\n\
  3625. function read_canvas(){\
  3626. var reply = \"\";\
  3627. var p = 0;\
  3628. for(p = 0; p< userdraw_x.lenght;p = p+2){\
  3629.  if(userdraw_x[p] != null){\
  3630.    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
  3631.  };\
  3632. };\
  3633. if(p == 0){alert(\"nothing drawn...\");return;};\
  3634. if( document.getElementById(\"canvas_input0\") ){\
  3635.  var p = 0;var input_reply = new Array();\
  3636.  if( document.getElementById(\"canvas_input0\")){\
  3637.   var t = 0;\
  3638.   while(document.getElementById(\"canvas_input\"+t)){\
  3639.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3640.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3641.     p++;\
  3642.    };\
  3643.    t++;\
  3644.   };\
  3645.  };\
  3646.  if( typeof userdraw_text != 'undefined' ){\
  3647.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3648.  }\
  3649.  else\
  3650.  {\
  3651.   return reply +\"\\n\"+input_reply;\
  3652.  }\
  3653. }\
  3654. else\
  3655. {\
  3656.  if( typeof userdraw_text != 'undefined' ){\
  3657.   return reply +\"\\n\"+userdraw_text\
  3658.  }\
  3659.  else\
  3660.  {\
  3661.   return reply;\
  3662.  }\
  3663. };\
  3664. };\
  3665. this.read_canvas = read_canvas;\n\
  3666. <!-- end function 12 read_canvas() -->");
  3667.     break;
  3668.     case 13: fprintf(js_include_file,"\
  3669. \n<!-- begin function 13 read_canvas() -->\n\
  3670. function read_canvas(){\
  3671. var reply = new Array();\
  3672. var p = 0;var i = 0;\
  3673. while(userdraw_x[p]){\
  3674.  reply[i] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]) +\":\" + px2x(userdraw_x[p+1]) +\":\" + px2y(userdraw_y[p+1]);\
  3675.  p = p+2;i++;\
  3676. };\
  3677. if(p == 0){alert(\"nothing drawn...\");return;};\
  3678. if( document.getElementById(\"canvas_input0\") ){\
  3679.  var p = 0;var input_reply = new Array();\
  3680.  if( document.getElementById(\"canvas_input0\")){\
  3681.   var t = 0;\
  3682.   while(document.getElementById(\"canvas_input\"+t)){\
  3683.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3684.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3685.     p++;\
  3686.    };\
  3687.    t++;\
  3688.   };\
  3689.  };\
  3690.  if( typeof userdraw_text != 'undefined' ){\
  3691.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3692.  }\
  3693.  else\
  3694.  {\
  3695.   return reply +\"\\n\"+input_reply;\
  3696.  }\
  3697. }\
  3698. else\
  3699. {\
  3700.  if( typeof userdraw_text != 'undefined' ){\
  3701.   return reply +\"\\n\"+userdraw_text\
  3702.  }\
  3703.  else\
  3704.  {\
  3705.   return reply;\
  3706.  }\
  3707. };\
  3708. };\
  3709. this.read_canvas = read_canvas;\n\
  3710. <!-- end function 13 read_canvas() -->");
  3711.     break;
  3712.     case 14: fprintf(js_include_file,"\
  3713. \n<!-- begin function 14 read_canvas() -->\n\
  3714. function read_canvas(){\
  3715. var reply = new Array();\
  3716. var p = 0;var i = 0;\
  3717. while(userdraw_x[p]){\
  3718.  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
  3719.  p = p+2;i++;\
  3720. };\
  3721. if(p == 0){alert(\"nothing drawn...\");return;};\
  3722. if( document.getElementById(\"canvas_input0\") ){\
  3723.  var p = 0;var input_reply = new Array();\
  3724.  if( document.getElementById(\"canvas_input0\")){\
  3725.   var t = 0;\
  3726.   while(document.getElementById(\"canvas_input\"+t)){\
  3727.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3728.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3729.     p++;\
  3730.    };\
  3731.    t++;\
  3732.   };\
  3733.  };\
  3734.  if( typeof userdraw_text != 'undefined' ){\
  3735.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3736.  }\
  3737.  else\
  3738.  {\
  3739.   return reply +\"\\n\"+input_reply;\
  3740.  }\
  3741. }\
  3742. else\
  3743. {\
  3744.  if( typeof userdraw_text != 'undefined' ){\
  3745.   return reply +\"\\n\"+userdraw_text;\
  3746.  }\
  3747.  else\
  3748.  {\
  3749.   return reply;\
  3750.  }\
  3751. };\
  3752. };\
  3753. this.read_canvas = read_canvas;\n\
  3754. <!-- end function 14 read_canvas() -->");
  3755.     break;
  3756.     case 15: fprintf(js_include_file,"\
  3757. \n<!-- begin function 15  read_canvas() -->\n\
  3758. function read_canvas(){\
  3759. var input_reply = new Array();\
  3760. var p = 0;\
  3761. if( document.getElementById(\"canvas_input0\")){\
  3762.  var t = 0;\
  3763.  while(document.getElementById(\"canvas_input\"+t)){\
  3764.   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3765.    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3766.    p++;\
  3767.   };\
  3768.   t++;\
  3769.  };\
  3770. };\
  3771. if( typeof userdraw_text != 'undefined' ){\
  3772.   return input_reply +\"\\n\"+userdraw_text;\
  3773. }\
  3774. else\
  3775. {\
  3776.  return input_reply;\
  3777. };\
  3778. };\
  3779. this.read_canvas = read_canvas;\n\
  3780. <!-- end function 15 read_canvas() -->");
  3781.     break;
  3782.     case 16: fprintf(js_include_file,"\
  3783. \n<!-- begin function 16 read_mathml() -->\n\
  3784. function read_mathml(){\
  3785. var reply = new Array();\
  3786. var p = 0;\
  3787. if( document.getElementById(\"mathml0\")){\
  3788.  while(document.getElementById(\"mathml\"+p)){\
  3789.   reply[p] = document.getElementById(\"mathml\"+p).value;\
  3790.   p++;\
  3791.  };\
  3792. };\
  3793. return reply;\
  3794. };\
  3795. this.read_mathml = read_mathml;\n\
  3796. <!-- end function 16 read_mathml() -->");
  3797.     break;
  3798.     case 17:  fprintf(js_include_file,"\
  3799. \n<!-- begin function 17 read_canvas() -->\n\
  3800. function read_canvas(){\
  3801. if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\
  3802. return userdraw_text;\
  3803. };\
  3804. this.read_canvas = read_canvas;\n\
  3805. <!-- end function 17 read_canvas() -->");
  3806.     break;
  3807.     case 18: fprintf(js_include_file,"\
  3808. \n<!-- begin function 18 read_canvas() -->\n\
  3809. function read_canvas(){\
  3810. var p = 0;\
  3811. var reply = new Array();\
  3812. var name;\
  3813. var t = true;\
  3814. while(t){\
  3815.  try{ name = eval('clocks'+p);\
  3816.  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;};\
  3817. };\
  3818. if( p == 0){alert(\"clock(s) not modified...\");return;}\
  3819. return reply;\
  3820. };\
  3821. this.read_canvas = read_canvas;\n\
  3822. <!-- end function 18 read_canvas() -->");
  3823.     break;
  3824.     case 19: fprintf(js_include_file,"\
  3825. \n<!-- begin function 19 read_canvas() -->\n\
  3826. function read_canvas(){\
  3827. return reply[0];\
  3828. };\
  3829. this.read_canvas = read_canvas;\n\
  3830. <!-- end function 19 read_canvas() -->");
  3831.     case 20: fprintf(js_include_file,"\
  3832. \n<!-- begin function 20 read_canvas() -->\n\
  3833. function read_canvas(){\
  3834. var len  = ext_drag_images.length;\
  3835. var reply = new Array(len);\
  3836. for(var p = 0 ; p < len ; p++){\
  3837.    var img = ext_drag_images[p];\
  3838.    reply[p] = px2x(img[6])+\":\"+px2y(img[7]);\
  3839. };\
  3840. return reply;\
  3841. };\
  3842. this.read_canvas = read_canvas;\n\
  3843. <!-- end function 20 read_canvas() -->");
  3844.     break;
  3845.     case 21: fprintf(js_include_file,"\
  3846. \n<!-- begin function 21 read_canvas() -->\n\
  3847. function read_canvas(){\
  3848. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3849. var reply_coord = new Array();var p = 0;\
  3850. while(userdraw_x[p]){\
  3851.  reply_coord[p] = \"(\"+px2x(userdraw_x[p])+\":\"+px2y(userdraw_y[p])+\")\";\
  3852.  p++;\
  3853. };\
  3854. if(p == 0){alert(\"nothing drawn...\");return;};\
  3855. if( document.getElementById(\"canvas_input0\") ){\
  3856.  var p = 0;var input_reply = new Array();\
  3857.  if( document.getElementById(\"canvas_input0\")){\
  3858.   var t = 0;\
  3859.   while(document.getElementById(\"canvas_input\"+t)){\
  3860.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3861.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3862.     p++;\
  3863.    };\
  3864.    t++;\
  3865.   };\
  3866.  };\
  3867.  if( typeof userdraw_text != 'undefined' ){\
  3868.   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3869.  }\
  3870.  else\
  3871.  {\
  3872.   return reply_coord+\"\\n\"+input_reply;\
  3873.  }\
  3874. }\
  3875. else\
  3876. {\
  3877.  if( typeof userdraw_text != 'undefined' ){\
  3878.   return reply_coord+\"\\n\"+userdraw_text;\
  3879.  }\
  3880.  else\
  3881.  {\
  3882.   return reply_coord;\
  3883.  };\
  3884. };\
  3885. };\
  3886. this.read_canvas = read_canvas;\n\
  3887. <!-- end function 21 read_canvas() -->");
  3888.     break;
  3889.     case 22: fprintf(js_include_file,"\
  3890. \n<!-- begin function 22 read_canvas() -->\n\
  3891. function read_canvas(){\
  3892. var reply = new Array();\
  3893. var p = 0;\
  3894. var idx = 0;\
  3895. while(userdraw_x[p]){\
  3896.  reply[idx] = px2x(userdraw_x[p]);\
  3897.  idx++;\
  3898.  reply[idx] = px2y(userdraw_y[p]);\
  3899.  idx++;p++;\
  3900. };\
  3901. if(p == 0){alert(\"nothing drawn...\");return;};\
  3902. if( document.getElementById(\"canvas_input0\") ){\
  3903.  var p = 0;var input_reply = new Array();\
  3904.  if( document.getElementById(\"canvas_input0\")){\
  3905.   var t = 0;\
  3906.   while(document.getElementById(\"canvas_input\"+t)){\
  3907.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3908.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3909.     p++;\
  3910.    };\
  3911.    t++;\
  3912.   };\
  3913.  };\
  3914.  if( typeof userdraw_text != 'undefined' ){\
  3915.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3916.  }\
  3917.  else\
  3918.  {\
  3919.   return reply +\"\\n\"+input_reply;\
  3920.  }\
  3921. }\
  3922. else\
  3923. {\
  3924.  if( typeof userdraw_text != 'undefined' ){\
  3925.   return reply +\"\\n\"+userdraw_text;\
  3926.  }\
  3927.  else\
  3928.  {\
  3929.   return reply;\
  3930.  }\
  3931. };\
  3932. };\
  3933. this.read_canvas = read_canvas;\n\
  3934. <!-- end function 22 read_canvas() -->");
  3935.     break;
  3936.     case 23: fprintf(js_include_file,"\
  3937. \n<!-- begin function 23 read_canvas() default 5 px marge -->\n\
  3938. function read_canvas(){\
  3939. if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
  3940. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  3941. var lu = userdraw_x.length;\
  3942. if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
  3943. var marge = 5;\
  3944. reply_x[p] = px2x(userdraw_x[0]);reply_y[p] = px2y(userdraw_y[0]);p++;\
  3945. for(var i = 0; i < lu - 1 ; i++ ){\
  3946.  if( (userdraw_x[i] < (userdraw_x[i+1] + marge)) && (userdraw_x[i] > (userdraw_x[i+1] - marge)) ){\
  3947.   if( (userdraw_y[i] < (userdraw_y[i+1] + marge)) && (userdraw_y[i] > (userdraw_y[i+1] - marge)) ){\
  3948.    reply_x[p] = px2x(userdraw_x[i]);reply_y[p] = px2y(userdraw_y[i]);\
  3949.    if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
  3950.    p++;\
  3951.   };\
  3952.  };\
  3953. };\
  3954. if( document.getElementById(\"canvas_input0\")){\
  3955.  var p = 0;var input_reply = new Array();\
  3956.  if( document.getElementById(\"canvas_input0\")){\
  3957.   var t = 0;\
  3958.   while(document.getElementById(\"canvas_input\"+t)){\
  3959.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3960.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3961.     p++;\
  3962.    };\
  3963.    t++;\
  3964.   };\
  3965.  };\
  3966.  if( typeof userdraw_text != 'undefined' ){\
  3967.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3968.  }\
  3969.  else\
  3970.  {\
  3971.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  3972.  }\
  3973. }\
  3974. else\
  3975. {\
  3976.  if( typeof userdraw_text != 'undefined' ){\
  3977.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  3978.  }\
  3979.  else\
  3980.  {\
  3981.   return reply_x+\"\\n\"+reply_y;\
  3982.  };\
  3983. };\
  3984. };\
  3985. this.read_canvas = read_canvas;\n\
  3986. <!-- end function 23 read_canvas() -->");
  3987.     break;
  3988.  
  3989.     default: canvas_error("hmmm unknown replyformat...");break;
  3990. }
  3991.  return;
  3992. }
  3993.  
  3994.  
  3995. /*
  3996.  add drawfunction :
  3997.  - functions used by userdraw_primitives (circle,rect,path,triangle...)
  3998.  - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
  3999.  - grid / mathml
  4000.  - will not scale or zoom in
  4001.  - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
  4002.  - is printed directly into 'js_include_file'
  4003. */
  4004.  
  4005. void add_javascript_functions(int js_functions[],int canvas_root_id){
  4006. int i;
  4007. for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
  4008.  if( js_functions[i] == 1){
  4009.     switch(i){
  4010.     case DRAG_EXTERNAL_IMAGE:
  4011. fprintf(js_include_file,"\n<!-- drag external images --->\n\
  4012. var external_canvas = create_canvas%d(7,xsize,ysize);\
  4013. var external_ctx = external_canvas.getContext(\"2d\");\
  4014. var external_canvas_rect = external_canvas.getBoundingClientRect();\
  4015. canvas_div.addEventListener(\"mousedown\",setxy,false);\
  4016. canvas_div.addEventListener(\"mouseup\",dragstop,false);\
  4017. canvas_div.addEventListener(\"mousemove\",dragxy,false);\
  4018. var selected_image = null;\
  4019. var ext_image_cnt = 0;\
  4020. var ext_drag_images = new Array();\
  4021. function drag_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,draggable){\
  4022. ext_image_cnt = idx;\
  4023. var image = new Image();\
  4024. image.src = URL;\
  4025. image.onload = function(){\
  4026.  if( x0 < 1 ){ x0 = 0; };if( y0 < 1 ){ y0 = 0; };if( sx < 1 ){ sx = 0; };if( sy < 1 ){ sy = 0; };\
  4027.  if( width < 1 ){ width = image.width; };if( height < 1 ){ height = image.height; };\
  4028.  if( swidth < 1 ){ swidth = image.width; };if( sheight < 1 ){ sheight = image.height; };\
  4029.  img = new Array(10);\
  4030.  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
  4031.  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;\
  4032.  ext_drag_images[idx] = img;\
  4033.  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  4034. };\
  4035. };\
  4036. function dragstop(evt){\
  4037. selected_image = null;return;\
  4038. };\
  4039. function dragxy(evt){\
  4040. if( selected_image != null ){\
  4041.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  4042.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  4043.  var s_img = ext_drag_images[selected_image];\
  4044.  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\
  4045.  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\
  4046.  ext_drag_images[selected_image] = s_img;\
  4047.  external_ctx.clearRect(0,0,xsize,ysize);\
  4048.  for(var i = 0; i <= ext_image_cnt ; i++){\
  4049.   var img = ext_drag_images[i];\
  4050.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  4051.  };\
  4052. };\
  4053. };\
  4054. function setxy(evt){\
  4055. if( ! selected_image && evt.which == 1 ){\
  4056.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  4057.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  4058.  var xm = evt.clientX - external_canvas_rect.left + xoff;\
  4059.  var ym = evt.clientY - external_canvas_rect.top + yoff;\
  4060.  for(var p = 0 ; p <= ext_image_cnt ; p++){\
  4061.   var img = ext_drag_images[p];\
  4062.   if( img[0] == 1 ){\
  4063.    var w = img.width;\
  4064.    var h = img.height;\
  4065.    if( xm > img[6] && xm < img[6] + img[4]){\
  4066.     if( ym > img[7] && ym < img[7] + img[5]){\
  4067.      img[6] = xm;\
  4068.      img[7] = ym;\
  4069.      ext_drag_images[p] = img;\
  4070.      selected_image = p;\
  4071.      dragxy(evt);\
  4072.     };\
  4073.    };\
  4074.   };\
  4075.  };\
  4076. }\
  4077. else\
  4078. {\
  4079.  selected_image = null;\
  4080. };\
  4081. };",canvas_root_id);
  4082.     break;
  4083.  
  4084.     case DRAW_EXTERNAL_IMAGE:
  4085. fprintf(js_include_file,"\n<!-- draw external images -->\n\
  4086. draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\
  4087. var image = new Image();\
  4088. image.src = URL;\
  4089. var canvas_bg_div = document.getElementById(\"canvas_div%d\");\
  4090. image.onload = function(){\
  4091.  if( x0 < 1 ){ x0 = 0; };\
  4092.  if( y0 < 1 ){ y0 = 0; };\
  4093.  if( sx < 1 ){ sx = 0; };\
  4094.  if( sy < 1 ){ sy = 0; };\
  4095.  if( width < 1 ){ width = image.width;};\
  4096.  if( height < 1 ){ height = image.height;};\
  4097.  if( swidth < 1 ){ swidth = image.width;};\
  4098.  if( sheight < 1 ){ sheight = image.height;};\
  4099.  var ml = x0 - sx;\
  4100.  var mh = y0 - sy;\
  4101.  canvas_bg_div.style.backgroundPosition= \"left \"+ml+\"px top \"+mh+\"px\";\
  4102.  canvas_bg_div.style.backgroundSize = width+\"px \"+height+\"px\";\
  4103.  canvas_bg_div.style.backgroundRepeat = \"no-repeat\";\
  4104.  canvas_bg_div.style.backgroundPosition= sx+\"px \"+sy+\"px\";\
  4105.  canvas_bg_div.style.backgroundImage = \"url(\" + URL + \")\";\
  4106. };\
  4107. };",canvas_root_id);    
  4108.     break;
  4109.    
  4110.     case DRAW_ZOOM_BUTTONS: /* 6 rectangles 15x15 px  forbidden zone for drawing : y < ysize - 15*/
  4111. fprintf(js_include_file,"\n<!-- draw zoom buttons -->\n\
  4112. draw_zoom_buttons = function(canvas_type,color,opacity){\
  4113. var obj;\
  4114. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4115.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4116. }\
  4117. else\
  4118. {\
  4119.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4120. };\
  4121. var ctx = obj.getContext(\"2d\");\
  4122. ctx.font =\"18px Ariel\";\
  4123. ctx.textAlign = \"right\";\
  4124. ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  4125. ctx.fillText(\"+\",xsize,ysize);\
  4126. ctx.fillText(\"\\u2212\",xsize - 15,ysize);\
  4127. ctx.fillText(\"\\u2192\",xsize - 30,ysize-2);\
  4128. ctx.fillText(\"\\u2190\",xsize - 45,ysize-2);\
  4129. ctx.fillText(\"\\u2191\",xsize - 60,ysize-2);\
  4130. ctx.fillText(\"\\u2193\",xsize - 75,ysize-2);\
  4131. ctx.fillText(\"\\u00D7\",xsize - 90,ysize-2);\
  4132. ctx.stroke();\
  4133. };",canvas_root_id,canvas_root_id,canvas_root_id);
  4134.    
  4135.     break;
  4136.     case DRAW_GRIDFILL:/* not used for userdraw */
  4137. fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
  4138. draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\
  4139. var obj;\
  4140. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4141.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4142. }\
  4143. else\
  4144. {\
  4145.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4146. };\
  4147. var ctx = obj.getContext(\"2d\");\
  4148. var x,y;\
  4149. ctx.save();\
  4150. ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  4151. snap_x = dx;snap_y = dy;\
  4152. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  4153.    ctx.moveTo(x,y0);\
  4154.    ctx.lineTo(x,ysize);\
  4155. };\
  4156. for( y = y0 ; y < ysize+dy; y = y + dy ){\
  4157.    ctx.moveTo(x0,y);\
  4158.    ctx.lineTo(xsize,y);\
  4159. };\
  4160. ctx.stroke();\
  4161. ctx.restore();\
  4162. return;};",canvas_root_id,canvas_root_id,canvas_root_id);
  4163.     break;
  4164.    
  4165.     case DRAW_IMAGEFILL:/* not  used for userdraw */
  4166. fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
  4167. draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\
  4168. var obj;\
  4169. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4170.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4171. }\
  4172. else\
  4173. {\
  4174.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4175. };\
  4176. var ctx = obj.getContext(\"2d\");\
  4177. ctx.save();\
  4178. var img = new Image();\
  4179. img.src = URL;\
  4180. img.onload = function(){\
  4181.  if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\
  4182.    ctx.drawImage(img,x0,y0,xsize,ysize);\
  4183.  }\
  4184.  else\
  4185.  {\
  4186.    var repeat = \"repeat\";\
  4187.    if(img.width > xsize - x0){\
  4188.         repeat = \"repeat-y\";\
  4189.    }\
  4190.    else\
  4191.    {\
  4192.     if( img.height > ysize -x0 ){\
  4193.      repeat = \"repeat-x\";\
  4194.     }\
  4195.    }\
  4196.    var pattern = ctx.createPattern(img,repeat);\
  4197.    ctx.rect(x0,y0,xsize,ysize);\
  4198.    ctx.fillStyle = pattern;\
  4199.  }\
  4200.  ctx.fill();\
  4201. };\
  4202. ctx.restore();\
  4203. return;\
  4204. };",canvas_root_id,canvas_root_id,canvas_root_id);
  4205.     break;
  4206.    
  4207.     case DRAW_DOTFILL:/* not  used for userdraw */
  4208. fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
  4209. draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\
  4210. var obj;\
  4211. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4212.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4213. }\
  4214. else\
  4215. {\
  4216.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4217. };\
  4218. var ctx = obj.getContext(\"2d\");\
  4219. var x,y;\
  4220. ctx.closePath();\
  4221. ctx.save();\
  4222. snap_x = dx;snap_y = dy;\
  4223. ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  4224. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  4225.  for( y = y0 ; y < ysize+dy ; y = y + dy ){\
  4226.   ctx.arc(x,y,radius,0,2*Math.PI,false);\
  4227.   ctx.closePath();\
  4228.  }\
  4229. }\
  4230. ctx.fill();\
  4231. ctx.restore();\
  4232. return;};",canvas_root_id,canvas_root_id,canvas_root_id);
  4233.     break;
  4234.  
  4235.     case DRAW_DIAMONDFILL:/* not used for userdraw */
  4236. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  4237. draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  4238.  var obj;\
  4239. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4240.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4241. }\
  4242. else\
  4243. {\
  4244.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4245. };\
  4246. var ctx = obj.getContext(\"2d\");\
  4247. var x;\
  4248. var y;\
  4249. ctx.save();\
  4250. ctx.lineWidth = linewidth;\
  4251. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4252. y = ysize;\
  4253. for( x = x0 ; x < xsize ; x = x + dx ){\
  4254.  ctx.moveTo(x,y0);\
  4255.  ctx.lineTo(xsize,y);\
  4256.  y = y - dy;\
  4257. };\
  4258. y = y0;\
  4259. for( x = xsize ; x > 0 ; x = x - dx){\
  4260.  ctx.moveTo(x,ysize);\
  4261.  ctx.lineTo(x0,y);\
  4262.  y = y + dy;\
  4263. };\
  4264. x = x0;\
  4265. for( y = y0 ; y < ysize ; y = y + dy ){\
  4266.  ctx.moveTo(xsize,y);\
  4267.  ctx.lineTo(x,ysize);\
  4268.  x = x + dx;\
  4269. };\
  4270. x = xsize;\
  4271. for( y = ysize ; y > y0 ; y = y - dy ){\
  4272.  ctx.moveTo(x,y0);\
  4273.  ctx.lineTo(x0,y);\
  4274.  x = x - dx;\
  4275. };\
  4276. ctx.stroke();\
  4277. ctx.restore();\
  4278. return;\
  4279. }",canvas_root_id,canvas_root_id,canvas_root_id);
  4280.     break;
  4281.    
  4282.     case DRAW_HATCHFILL:/* not used for userdraw */
  4283. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  4284. draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  4285.  var obj;\
  4286. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4287.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4288. }\
  4289. else\
  4290. {\
  4291.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4292. };\
  4293. var ctx = obj.getContext(\"2d\");\
  4294. var x;\
  4295. var y;\
  4296. ctx.save();\
  4297. ctx.lineWidth = linewidth;\
  4298. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4299. y = ysize;\
  4300. for( x = x0 ; x < xsize ; x = x + dx ){\
  4301.  ctx.moveTo(x,y0);\
  4302.  ctx.lineTo(xsize,y);\
  4303.  y = y - dy;\
  4304. };\
  4305. y = y0;\
  4306. for( x = xsize ; x >= dx ; x = x - dx){\
  4307.  ctx.moveTo(x,ysize);\
  4308.  ctx.lineTo(x0,y);\
  4309.  y = y + dy;\
  4310. };\
  4311. ctx.stroke();\
  4312. ctx.restore();\
  4313. return;\
  4314. };",canvas_root_id,canvas_root_id,canvas_root_id);
  4315.     break;
  4316.     case DRAW_CIRCLES:/*  used for userdraw */
  4317. fprintf(js_include_file,"\n<!-- draw circles -->\n\
  4318. 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){\
  4319. ctx.save();\
  4320. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4321. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4322. ctx.lineWidth = line_width;\
  4323. for(var p = 0 ; p < x_points.length ; p++ ){\
  4324.  ctx.beginPath();\
  4325.  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
  4326.  ctx.closePath();\
  4327.  if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4328.  if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  4329.  ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4330.  ctx.stroke();\
  4331. }\
  4332. ctx.restore();\
  4333. return;\
  4334. };");
  4335.     break;
  4336.     case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
  4337. fprintf(js_include_file,"\n<!-- draw polyline -->\n\
  4338. draw_polyline = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\
  4339. ctx.save();\
  4340. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4341. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4342. ctx.lineWidth = line_width;\
  4343. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4344. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4345. ctx.clearRect(0,0,xsize,ysize);\
  4346. ctx.beginPath();\
  4347. for(var p = 0 ; p < x_points.length-1 ; p++ ){\
  4348.  ctx.moveTo(x_points[p],y_points[p]);\
  4349.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  4350. }\
  4351. ctx.closePath();\
  4352. ctx.stroke();\
  4353. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4354. for(var p = 0 ; p < x_points.length ; p++ ){\
  4355.  ctx.beginPath();\
  4356.  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
  4357.  ctx.closePath();ctx.fill();ctx.stroke();\
  4358. };\
  4359. ctx.restore();\
  4360. return;\
  4361. };");
  4362.     break;
  4363.    
  4364.     case DRAW_SEGMENTS:/*  used for userdraw */
  4365. fprintf(js_include_file,"\n<!-- draw segments -->\n\
  4366. draw_segments = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\
  4367. ctx.save();\
  4368. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4369. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4370. ctx.lineWidth = line_width;\
  4371. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4372. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4373. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  4374.  ctx.beginPath();\
  4375.  ctx.moveTo(x_points[p],y_points[p]);\
  4376.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  4377.  ctx.closePath();\
  4378.  ctx.stroke();\
  4379.  }\
  4380.  ctx.restore();\
  4381.  return;\
  4382. };");
  4383.     break;
  4384.    
  4385.     case DRAW_LINES:/*  used for userdraw */
  4386. fprintf(js_include_file,"\n<!-- draw lines -->\n\
  4387. function calc_line(x1,x2,y1,y2){\
  4388. var marge = 2;\
  4389. if(x1 < x2+marge && x1>x2-marge){\
  4390.  return [x1,0,x1,ysize];\
  4391. };\
  4392. if(y1 < y2+marge && y1>y2-marge){\
  4393.  return [0,y1,xsize,y1];\
  4394. };\
  4395. var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
  4396. var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
  4397. return [0,Y1,xsize,Y2];\
  4398. };\
  4399. draw_lines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\
  4400. ctx.save();\
  4401. var line = new Array(4);\
  4402. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4403. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4404. ctx.lineWidth = line_width;\
  4405. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4406. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4407. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  4408.  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
  4409.  ctx.beginPath();\
  4410.  ctx.moveTo(line[0],line[1]);\
  4411.  ctx.lineTo(line[2],line[3]);\
  4412.  ctx.closePath();\
  4413.  ctx.stroke();\
  4414.  }\
  4415.  ctx.restore();\
  4416.  return;\
  4417. };");
  4418.     break;
  4419.  
  4420.     case DRAW_CROSSHAIRS:/*  used for userdraw */
  4421. fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
  4422. draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_translate,vector){\
  4423. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4424. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4425. ctx.lineWidth = line_width;\
  4426. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4427. var x1,x2,y1,y2;\
  4428. for(var p = 0 ; p < x_points.length ; p++ ){\
  4429.  x1 = x_points[p] - crosshair_size;\
  4430.  x2 = x_points[p] + crosshair_size;\
  4431.  y1 = y_points[p] - crosshair_size;\
  4432.  y2 = y_points[p] + crosshair_size;\
  4433.  ctx.beginPath();\
  4434.  ctx.moveTo(x1,y1);\
  4435.  ctx.lineTo(x2,y2);\
  4436.  ctx.closePath();\
  4437.  ctx.stroke();\
  4438.  ctx.beginPath();\
  4439.  ctx.moveTo(x2,y1);\
  4440.  ctx.lineTo(x1,y2);\
  4441.  ctx.closePath();\
  4442.  ctx.stroke();\
  4443. }\
  4444. ctx.restore();\
  4445.  return;\
  4446. };");
  4447.     break;
  4448.  
  4449.     case DRAW_RECTS:/*  used for userdraw */
  4450. fprintf(js_include_file,"\n<!-- draw rects -->\n\
  4451. 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){\
  4452. ctx.save();\
  4453. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4454. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4455. ctx.lineWidth = line_width;\
  4456. ctx.strokeStyle = \"rgba('+stroke_color+','+stroke_opacity+')\";\
  4457. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
  4458. for(var p = 0 ; p < x_points.length ; p = p + 2){\
  4459.  ctx.beginPath();\
  4460.  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
  4461.  ctx.closePath();\
  4462.  if(use_filled == 1 ){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  4463.  ctx.stroke();\
  4464. };\
  4465. ctx.restore();\
  4466. return;\
  4467. };");
  4468.     break;
  4469.  
  4470.     case DRAW_ROUNDRECTS:/*  used for userdraw */
  4471. fprintf(js_include_file,"\n<!-- draw round rects -->\n\
  4472. 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){\
  4473. ctx.save();\
  4474. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4475. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4476. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4477. var x,y,w,h,r;\
  4478. for(var p = 0; p < x_points.length; p = p+2){\
  4479.  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);\
  4480.  ctx.beginPath();ctx.moveTo(x + r, y);\
  4481.  ctx.lineTo(x + w - r, y);\
  4482.  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
  4483.  ctx.lineTo(x + w, y + h - r);\
  4484.  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
  4485.  ctx.lineTo(x + r, y + h);\
  4486.  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
  4487.  ctx.lineTo(x, y + r);\
  4488.  ctx.quadraticCurveTo(x, y, x + r, y);\
  4489.  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
  4490.  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4491.  if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\
  4492.  ctx.stroke();\
  4493. }\
  4494. ctx.restore();\
  4495. };");
  4496.     break;
  4497.  
  4498.     case DRAW_ELLIPSES:/* not  used for userdraw */
  4499. fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
  4500. 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){\
  4501. var obj;\
  4502. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4503.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4504. }\
  4505. else\
  4506. {\
  4507.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4508. };\
  4509. var ctx = obj.getContext(\"2d\");\
  4510. ctx.save();\
  4511. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4512. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4513. var cx,cy,ry,rx;\
  4514. ctx.lineWidth = line_width;\
  4515. if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\
  4516. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4517. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4518. for(var p=0;p< x_points.length;p = p+2){\
  4519.  ctx.beginPath();\
  4520.  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
  4521.  ctx.translate(cx - rx, cy - ry);\
  4522.  ctx.scale(rx, ry);\
  4523.  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
  4524.  if( use_filled == 1 ){ctx.fill();}\
  4525.  ctx.stroke();\
  4526. };\
  4527. ctx.restore();\
  4528. };",canvas_root_id,canvas_root_id,canvas_root_id);
  4529.     break;
  4530.  
  4531.     case DRAW_PATHS: /*  used for userdraw */
  4532. fprintf(js_include_file,"\n<!-- draw paths -->\n\
  4533. 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){\
  4534. ctx.save();\
  4535. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4536. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4537. ctx.lineWidth = line_width;\
  4538. ctx.lineJoin = \"round\";\
  4539. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4540. ctx.beginPath();\
  4541. ctx.moveTo(x_points[0],y_points[0]);\
  4542. for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
  4543. if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
  4544. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4545. if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  4546. ctx.stroke();\
  4547. ctx.restore();\
  4548. return;\
  4549. };");
  4550.    
  4551.     break;
  4552.     case DRAW_ARROWS:/*  used for userdraw */
  4553. fprintf(js_include_file,"\n<!-- draw arrows -->\n\
  4554. 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){\
  4555. ctx.save();\
  4556. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4557. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4558. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4559. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4560. ctx.lineWidth = line_width;\
  4561. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4562. ctx.lineCap = \"round\";\
  4563. ctx.save();\
  4564. var x1,y1,x2,y2,dx,dy,len;\
  4565. for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
  4566.   ctx.restore();ctx.save();\
  4567.   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
  4568.   len = Math.sqrt(dx*dx+dy*dy);\
  4569.   ctx.translate(x2,y2);\
  4570.   ctx.rotate(Math.atan2(dy,dx));\
  4571.   ctx.lineCap = \"round\";\
  4572.   ctx.beginPath();\
  4573.   ctx.moveTo(0,0);\
  4574.   ctx.lineTo(-len,0);\
  4575.   ctx.closePath();\
  4576.   ctx.stroke();\
  4577.   ctx.beginPath();\
  4578.   ctx.moveTo(0,0);\
  4579.   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  4580.   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  4581.   ctx.closePath();\
  4582.   ctx.fill();\
  4583.   if( type == 2 ){\
  4584.     ctx.restore();\
  4585.     ctx.save();\
  4586.     ctx.translate(x1,y1);\
  4587.     ctx.rotate(Math.atan2(-dy,-dx));\
  4588.     ctx.beginPath();\
  4589.     ctx.moveTo(0,0);\
  4590.     ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  4591.     ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  4592.     ctx.closePath();\
  4593.     ctx.stroke();\
  4594.     ctx.fill();\
  4595.   }\
  4596.  }\
  4597.  ctx.restore();\
  4598.  return;\
  4599. };");
  4600.     break;
  4601.  
  4602.     case DRAW_VIDEO:/* not  used for userdraw */
  4603. fprintf(js_include_file,"\n<!-- draw video -->\n\
  4604. draw_video = function(canvas_root_id,x,y,w,h,URL){\
  4605. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  4606. var video_div = document.createElement(\"div\");\
  4607. canvas_div.appendChild(video_div);\
  4608. video_div.style.position = \"absolute\";\
  4609. video_div.style.left = x+\"px\";\
  4610. video_div.style.top = y+\"px\";\
  4611. video_div.style.width = w+\"px\";\
  4612. video_div.style.height = h+\"px\";\
  4613. var video = document.createElement(\"video\");\
  4614. video_div.appendChild(video);\
  4615. video.style.width = w+\"px\";\
  4616. video.style.height = h+\"px\";\
  4617. video.autobuffer = true;\
  4618. video.controls = true;video.autoplay = false;\
  4619. var src = document.createElement(\"source\");\
  4620. src.type = \"video/mp4\";\
  4621. src.src = URL;\
  4622. video.appendChild(src);\
  4623. video.load();\
  4624. return;\
  4625. };");    
  4626.     break;
  4627.    
  4628.     case DRAW_AUDIO:/* not used for userdraw */
  4629. fprintf(js_include_file,"\n<!-- draw audio -->\n\
  4630. draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
  4631. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  4632. var audio_div = document.createElement(\"div\");\
  4633. canvas_div.appendChild(audio_div);\
  4634. audio_div.style.position = \"absolute\";\
  4635. audio_div.style.left = x+\"px\";\
  4636. audio_div.style.top = y+\"px\";\
  4637. audio_div.style.width = w+\"px\";\
  4638. audio_div.style.height = h+\"px\";\
  4639. var audio = document.createElement(\"audio\");\
  4640. audio_div.appendChild(audio);\
  4641. audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
  4642. audio.autobuffer = true;\
  4643. if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;}\
  4644. if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;}\
  4645. var src1 = document.createElement(\"source\");\
  4646. src1.type = \"audio/ogg\";\
  4647. src1.src = URL1;\
  4648. audio.appendChild(src1);\
  4649. var src2 = document.createElement(\"source\");\
  4650. src2.type = \"audio/mpeg\";\
  4651. src2.src = URL2;\
  4652. audio.appendChild(src2);\
  4653. audio.load();\
  4654. return;\
  4655. };");
  4656.     break;
  4657.    
  4658.     case DRAW_HTTP:/* not  used for userdraw */
  4659. fprintf(js_include_file,"\n<!-- draw http -->\n\
  4660. draw_http = function(canvas_root_id,x,y,w,h,URL){\
  4661. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  4662. var http_div = document.createElement(\"div\");\
  4663. var iframe = document.createElement(\"iframe\");\
  4664. canvas_div.appendChild(http_div);\
  4665. http_div.appendChild(iframe);\
  4666. iframe.src = URL;\
  4667. iframe.setAttribute(\"width\",w);\
  4668. iframe.setAttribute(\"height\",h);\
  4669. return;\
  4670. };");
  4671.     break;
  4672.    
  4673.     case DRAW_XML:
  4674. fprintf(js_include_file,"\n<!-- draw xml -->\n\
  4675. draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick){\
  4676. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  4677. var xml_div = document.createElement(\"div\");\
  4678. canvas_div.appendChild(xml_div);\
  4679. xml_div.innerHTML = mathml;\
  4680. if(onclick != 0){\
  4681.  xml_div.onclick = function(){\
  4682.   reply[0] = onclick;\
  4683.   alert(\"send \"+onclick+\" ?\");\
  4684.  };\
  4685. };\
  4686. xml_div.style.position = \"absolute\";\
  4687. xml_div.style.left = x+\"px\";\
  4688. xml_div.style.top = y+\"px\";\
  4689. xml_div.style.width = w+\"px\";\
  4690. xml_div.style.height = h+\"px\";\
  4691. return;\
  4692. };"
  4693. );
  4694.     break;
  4695.     case DRAW_SGRAPH:
  4696. /*
  4697.  xstart = given
  4698.  ystart = given
  4699.  sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
  4700. */
  4701. fprintf(js_include_file,"\n<!-- draw sgraph -->\n\
  4702. draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
  4703. 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);};\
  4704. var ctx = obj.getContext(\"2d\");\
  4705. ctx.font = fontfamily;\
  4706. var minor_opacity = 0.8*opacity;\
  4707. ctx.clearRect(0,0,xsize,ysize);\
  4708. var d_x =  1.8*font_size;\
  4709. var d_y =  ctx.measureText(\"+ymax+\").width;\
  4710. var dx = xsize / (xmax - xmin);\
  4711. var dy = ysize / (ymax - ymin);\
  4712. var zero_x = d_y + dx;\
  4713. var zero_y = ysize - dy - d_x;\
  4714. var snor_x;\
  4715. if( xstart != xmin){\
  4716.  snor_x = 0.1*xsize;\
  4717. }\
  4718. else\
  4719. {\
  4720.  snor_x = 0;\
  4721.  xstart = xmin;\
  4722. };\
  4723. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  4724. ctx.lineWidth = 2;\
  4725. ctx.beginPath();\
  4726. ctx.moveTo(xsize,zero_y);\
  4727. ctx.lineTo(zero_x,zero_y);\
  4728. ctx.lineTo(zero_x,0);\
  4729. ctx.stroke();\
  4730. ctx.closePath();\
  4731. ctx.beginPath();\
  4732. ctx.moveTo(zero_x,zero_y);\
  4733. ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
  4734. ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
  4735. ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
  4736. ctx.lineTo(zero_x + snor_x,zero_y);\
  4737. ctx.stroke();\
  4738. ctx.closePath();\
  4739. ctx.beginPath();\
  4740. var num = xstart;\
  4741. var flipflop = 1;\
  4742. var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
  4743. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  4744.   if( 0.5*ctx.measureText(num).width > step_x ){\
  4745.    if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};\
  4746.   };\
  4747.   if( flipflop == 1){\
  4748.    ctx.fillText(num,x - 0.5*ctx.measureText(num).width,zero_y+font_size);\
  4749.   }\
  4750.   else\
  4751.   {\
  4752.    ctx.fillText(num,x - 0.5*ctx.measureText(num).width,zero_y+2*font_size);\
  4753.   }\
  4754.   num = num + xmajor;\
  4755. };\
  4756. ctx.stroke();\
  4757. ctx.closePath();\
  4758. ctx.lineWidth = 1;\
  4759. ctx.beginPath();\
  4760. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  4761.   ctx.moveTo(x,zero_y);\
  4762.   ctx.lineTo(x,0);\
  4763. };\
  4764. ctx.stroke();\
  4765. ctx.closePath();\
  4766. if( xminor > 1){\
  4767.  ctx.lineWidth = 0.5;\
  4768.  ctx.beginPath();\
  4769.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  4770.  var minor_step_x = step_x / xminor;\
  4771.  var nx;\
  4772.  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
  4773.    num = 1;\
  4774.    for(var p = 1 ; p < xminor ; p++){\
  4775.     nx = x + num*minor_step_x;\
  4776.     ctx.moveTo(nx,zero_y);\
  4777.     ctx.lineTo(nx,0);\
  4778.     num++;\
  4779.    };\
  4780.  };\
  4781.  ctx.stroke();\
  4782.  ctx.closePath();\
  4783.  ctx.beginPath();\
  4784.  ctx.lineWidth = 2;\
  4785.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  4786.  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  4787.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
  4788.  };\
  4789.  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
  4790.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
  4791.  };\
  4792.  ctx.stroke();\
  4793.  ctx.closePath();\
  4794.  ctx.lineWidth = 0.5;\
  4795. };\
  4796. xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
  4797. if( ystart != ymin){\
  4798.  snor_y = 0.1*ysize;\
  4799. }\
  4800. else\
  4801. {\
  4802.  snor_y = 0;\
  4803.  ystart = ymin;\
  4804. };\
  4805. ctx.lineWidth = 2;\
  4806. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  4807. ctx.beginPath();\
  4808. ctx.moveTo(zero_x,zero_y);\
  4809. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
  4810. ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
  4811. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
  4812. ctx.lineTo(zero_x,zero_y - snor_y);\
  4813. ctx.stroke();\
  4814. ctx.closePath();\
  4815. ctx.beginPath();\
  4816. ctx.lineWidth = 1;\
  4817. num = ystart;\
  4818. var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
  4819. for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
  4820.  ctx.moveTo(zero_x,y);\
  4821.  ctx.lineTo(xsize,y);\
  4822.  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
  4823.  num = num + ymajor;\
  4824. };\
  4825. ctx.stroke();\
  4826. ctx.closePath();\
  4827. if( yminor > 1){\
  4828.  ctx.lineWidth = 0.5;\
  4829.  ctx.beginPath();\
  4830.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  4831.  var minor_step_y = step_y / yminor;\
  4832.  var ny;\
  4833.  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
  4834.   num = 1;\
  4835.   for(var p = 1 ;p < yminor;p++){\
  4836.     ny = y + num*minor_step_y;\
  4837.     ctx.moveTo(zero_x,ny);\
  4838.     ctx.lineTo(xsize,ny);\
  4839.     num++;\
  4840.    };\
  4841.  };\
  4842.  ctx.stroke();\
  4843.  ctx.closePath();\
  4844.  ctx.lineWidth = 2;\
  4845.  ctx.beginPath();\
  4846.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  4847.  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
  4848.   ctx.moveTo(zero_x,y);\
  4849.   ctx.lineTo(zero_x+12,y);\
  4850.  };\
  4851.  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
  4852.   ctx.moveTo(zero_x,y);\
  4853.   ctx.lineTo(zero_x+6,y);\
  4854.  };\
  4855.  ctx.stroke();\
  4856.  ctx.closePath();\
  4857. };\
  4858. ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
  4859. if( typeof legend%d  !== 'undefined' ){\
  4860.  ctx.globalAlpha = 1.0;\
  4861.  var y_offset = 2*font_size;\
  4862.  var txt;var txt_size;\
  4863.  var x_offset = xsize - 2*font_size;\
  4864.  var l_length = legend%d.length;var barcolor = new Array();\
  4865.  if( typeof legendcolors%d !== 'undefined' ){\
  4866.   for(var p = 0 ; p < l_length ; p++){\
  4867.    barcolor[p] = legendcolors%d[p];\
  4868.   };\
  4869.  }else{\
  4870.   if( barcolor.length == 0 ){\
  4871.    for(var p = 0 ; p < l_length ; p++){\
  4872.     barcolor[p] = stroke_color;\
  4873.    };\
  4874.   };\
  4875.  };\
  4876.  for(var p = 0; p < l_length; p++){\
  4877.   ctx.fillStyle = barcolor[p];\
  4878.   txt = legend%d[p];\
  4879.   txt_size = ctx.measureText(txt).width;\
  4880.   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
  4881.   y_offset = parseInt(y_offset + 1.5*font_size);\
  4882.  };\
  4883. };\
  4884. if( typeof xaxislabel !== 'undefined' ){\
  4885.   ctx.fillStyle = \'#000000\';\
  4886.   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
  4887.   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
  4888. };\
  4889. if( typeof yaxislabel !== 'undefined'){\
  4890.   ctx.save();\
  4891.   ctx.fillStyle = \'#000000\';\
  4892.   var txt_size = ctx.measureText(yaxislabel).width;\
  4893.   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
  4894.   ctx.rotate(-0.5*Math.PI);\
  4895.   ctx.fillText(yaxislabel,0,0);\
  4896.   ctx.save();\
  4897. };\
  4898. };\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);
  4899.     break;
  4900.  
  4901.     case DRAW_GRID:/* not used for userdraw */
  4902. fprintf(js_include_file,"\n<!-- draw grid -->\n\
  4903. 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){\
  4904. var obj;\
  4905. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4906. obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4907. }\
  4908. else\
  4909. {\
  4910. obj = create_canvas%d(canvas_type,xsize,ysize);\
  4911. };\
  4912. var ctx = obj.getContext(\"2d\");\
  4913. ctx.clearRect(0,0,xsize,ysize);\
  4914. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4915. ctx.save();\
  4916. if( use_translate == 1 ){ctx.translate(vector[0],vector[1]);};\
  4917. if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
  4918. var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4919. ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
  4920. var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
  4921. ctx.font = font_family;\
  4922. var xstep = xsize*xmajor/(xmax - xmin);\
  4923. var ystep = ysize*ymajor/(ymax - ymin);\
  4924. var x2step = xstep / xminor;\
  4925. var y2step = ystep / yminor;\
  4926. var zero_x;var zero_y;var f_x;var f_y;\
  4927. if(xmin < 0 ){zero_x = x2px(0);f_x = 1;}else{zero_x = x2px(xmin);f_x = -1;}\
  4928. if(ymin < 0 ){zero_y = y2px(0);f_y = 1;}else{zero_y = y2px(ymin);f_y = -1;}\
  4929. ctx.beginPath();\
  4930. ctx.lineWidth = line_width;\
  4931. ctx.strokeStyle = stroke_color;\
  4932. for(var p = zero_x ; p < xsize; p = p + xstep){\
  4933. ctx.moveTo(p,0);\
  4934. ctx.lineTo(p,ysize);\
  4935. };\
  4936. for(var p = zero_x ; p > 0; p = p - xstep){\
  4937. ctx.moveTo(p,0);\
  4938. ctx.lineTo(p,ysize);\
  4939. };\
  4940. for(var p = zero_y ; p < ysize; p = p + ystep){\
  4941. ctx.moveTo(0,p);\
  4942. ctx.lineTo(xsize,p);\
  4943. };\
  4944. for(var p = zero_y ; p > 0; p = p - ystep){\
  4945. ctx.moveTo(0,p);\
  4946. ctx.lineTo(xsize,p);\
  4947. };\
  4948. if( typeof xaxislabel !== 'undefined' ){\
  4949. ctx.save();\
  4950. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  4951. var corr =  ctx.measureText(xaxislabel).width;\
  4952. ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\
  4953. ctx.restore();\
  4954. };\
  4955. if( typeof yaxislabel !== 'undefined' ){\
  4956. ctx.save();\
  4957. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  4958. corr =  ctx.measureText(yaxislabel).width;\
  4959. ctx.translate(zero_x+tics_length + font_size,corr+font_size);\
  4960. ctx.rotate(-0.5*Math.PI);\
  4961. ctx.fillText(yaxislabel,0,0);\
  4962. ctx.restore();\
  4963. };\
  4964. ctx.stroke();\
  4965. ctx.closePath();\
  4966. if( use_axis == 1 ){\
  4967. ctx.beginPath();\
  4968. ctx.strokeStyle = stroke_color;\
  4969. ctx.lineWidth = 0.6*line_width;\
  4970. for(var p = zero_x ; p < xsize; p = p + x2step){\
  4971.  ctx.moveTo(p,0);\
  4972.  ctx.lineTo(p,ysize);\
  4973. };\
  4974. for(var p = zero_x ; p > 0; p = p - x2step){\
  4975.  ctx.moveTo(p,0);\
  4976.  ctx.lineTo(p,ysize);\
  4977. };\
  4978. for(var p = zero_y ; p < ysize; p = p + y2step){\
  4979.  ctx.moveTo(0,p);\
  4980.  ctx.lineTo(xsize,p);\
  4981. };\
  4982. for(var p = zero_y ; p > 0; p = p - y2step){\
  4983.  ctx.moveTo(0,p);\
  4984.  ctx.lineTo(xsize,p);\
  4985. };\
  4986. ctx.stroke();\
  4987. ctx.closePath();\
  4988. ctx.beginPath();\
  4989. ctx.lineWidth = 2*line_width;\
  4990. ctx.strokeStyle = axis_color;\
  4991. ctx.moveTo(0,zero_y);\
  4992. ctx.lineTo(xsize,zero_y);\
  4993. ctx.moveTo(zero_x,0);\
  4994. ctx.lineTo(zero_x,ysize);\
  4995. ctx.stroke();\
  4996. ctx.closePath();\
  4997. ctx.lineWidth = line_width+0.5;\
  4998. ctx.beginPath();\
  4999. for(var p = zero_x ; p < xsize; p = p + xstep){\
  5000.  ctx.moveTo(p,zero_y-tics_length);\
  5001.  ctx.lineTo(p,zero_y+tics_length);\
  5002. };\
  5003. for(var p = zero_x ; p > 0; p = p - xstep){\
  5004.  ctx.moveTo(p,zero_y-tics_length);\
  5005.  ctx.lineTo(p,zero_y+tics_length);\
  5006. };\
  5007. for(var p = zero_y ; p < ysize; p = p + ystep){\
  5008.  ctx.moveTo(zero_x-tics_length,p);\
  5009.  ctx.lineTo(zero_x+tics_length,p);\
  5010. };\
  5011. for(var p = zero_y ; p > 0; p = p - ystep){\
  5012.  ctx.moveTo(zero_x-tics_length,p);\
  5013.  ctx.lineTo(zero_x+tics_length,p);\
  5014. };\
  5015. for(var p = zero_x ; p < xsize; p = p + x2step){\
  5016.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  5017.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  5018. };\
  5019. for(var p = zero_x ; p > 0; p = p - x2step){\
  5020.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  5021.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  5022. };\
  5023. for(var p = zero_y ; p < ysize; p = p + y2step){\
  5024.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  5025.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  5026. };\
  5027. for(var p = zero_y ; p > 0; p = p - y2step){\
  5028.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  5029.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  5030. };\
  5031. ctx.stroke();\
  5032. ctx.closePath();\
  5033. if( use_axis_numbering == 1 ){\
  5034.  var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
  5035.  if( x_strings != null ){\
  5036.   var f = 1.4;\
  5037.   var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  5038.   for(var p = 0 ; p < len ; p = p+2){\
  5039.     var x_nums = x2px(eval(x_strings[p]));\
  5040.     var x_text = x_strings[p+1];\
  5041.     corr = ctx.measureText(x_text).width;\
  5042.     skip = 1.2*corr/xstep;\
  5043.     if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
  5044.     if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
  5045.     ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
  5046.   }\
  5047.  }\
  5048.  else\
  5049.  {\
  5050.   corr=0;skip = 1;cnt = px2x(zero_x);\
  5051.   prec = Math.log(precision)/(Math.log(10));\
  5052.   for( var p = zero_x ; p < xsize ; p = p+xstep){\
  5053.    if(skip == 0 ){\
  5054.      disp_cnt = cnt.toFixed(prec);\
  5055.      corr = ctx.measureText(disp_cnt).width;\
  5056.      skip = parseInt(1.2*corr/xstep);\
  5057.      ctx.fillText(disp_cnt,p-0.5*corr,parseInt(zero_y+(1.4*f_x*font_size)));\
  5058.    }\
  5059.    else\
  5060.    {\
  5061.     skip--;\
  5062.    };\
  5063.    cnt = cnt + xmajor;\
  5064.   };\
  5065.   cnt = px2x(zero_x);skip = 1;\
  5066.   for( var p = zero_x ; p > 0 ; p = p-xstep){\
  5067.    if(skip == 0 ){\
  5068.     disp_cnt = cnt.toFixed(prec);\
  5069.     corr = ctx.measureText(disp_cnt).width;\
  5070.     skip = parseInt(1.2*corr/xstep);\
  5071.     ctx.fillText(disp_cnt,p-0.5*corr,parseInt(zero_y+(1.4*f_x*font_size)));\
  5072.    }\
  5073.    else\
  5074.    {\
  5075.     skip--;\
  5076.    };\
  5077.    cnt = cnt - xmajor;\
  5078.   };\
  5079.  };\
  5080.  if( y_strings != null ){\
  5081.   var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
  5082.   for(var p = 0 ; p < len ; p = p+2){\
  5083.    var y_nums = y2px(eval(y_strings[p]));\
  5084.    var y_text = y_strings[p+1];\
  5085.    var f = 1.4;\
  5086.    corr = 2 + tics_length + ctx.measureText(y_text).width;\
  5087.    if( corr > zero_x){corr = parseInt(zero_x+2); }\
  5088.    ctx.fillText(y_text,zero_x - corr,y_nums);\
  5089.   };\
  5090.  }\
  5091.  else\
  5092.  {\
  5093.   corr = 0;cnt = px2y(zero_y);skip = 1;\
  5094.   for( var p = zero_y ; p < ysize ; p = p+ystep){\
  5095.    if(skip == 0 ){\
  5096.     skip = parseInt(1.4*font_size/ystep);\
  5097.     disp_cnt = cnt.toFixed(prec);\
  5098.     if(f_y == 1){corr = 2 + tics_length + ctx.measureText(disp_cnt).width;}\
  5099.     ctx.fillText(disp_cnt,parseInt(zero_x - corr),parseInt(p+(0.4*font_size)));\
  5100.    }\
  5101.    else\
  5102.    {\
  5103.     skip--;\
  5104.    };\
  5105.    cnt = cnt - ymajor;\
  5106.   }\
  5107.   corr = 0;cnt = px2y(zero_y);skip = 1;\
  5108.   for( var p = zero_y ; p > 0 ; p = p-ystep){\
  5109.    if(skip == 0 ){\
  5110.     skip = parseInt(1.4*font_size/ystep);\
  5111.     disp_cnt = cnt.toFixed(prec);\
  5112.     if(f_y == 1){corr = 2 + tics_length + ctx.measureText(disp_cnt).width;}\
  5113.     ctx.fillText(disp_cnt,parseInt(zero_x - corr),parseInt(p+(0.4*font_size)));\
  5114.    }\
  5115.    else\
  5116.    {\
  5117.     skip--;\
  5118.    };\
  5119.    cnt = cnt + ymajor;\
  5120.   }\
  5121.  };\
  5122. };\
  5123. ctx.strokeStyle = stroke_color;\
  5124. ctx.lineWidth = 2;\
  5125. ctx.beginPath();\
  5126. ctx.rect(0,0,xsize,ysize);\
  5127. ctx.closePath();\
  5128. ctx.stroke();\
  5129. };\
  5130. if( typeof linegraph_0 !== 'undefined' ){\
  5131. ctx.restore();\
  5132. ctx.save();\
  5133. ctx.globalAlpha = 1.0;\
  5134. var i = 0;\
  5135. var line_name = eval('linegraph_'+i);\
  5136. while ( typeof line_name !== 'undefined' ){\
  5137.  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
  5138.  ctx.lineWidth = parseInt(line_name[1]);\
  5139.  if(line_name[2] == \"1\"){\
  5140.   var d1 = parseInt(line_name[3]);\
  5141.   var d2 = parseInt(line_name[4]);\
  5142.   if(ctx.setLineDash){ ctx.setLineDash(d1,d2); } else { ctx.mozDash = [d1,d2];};\
  5143.  }\
  5144.  else\
  5145.  {\
  5146.  if(ctx.setLineDash){ctx.setLineDash = null;}\
  5147.  if(ctx.mozDash){ctx.mozDash = null;}\
  5148.  };\
  5149.  var data_x = new Array();\
  5150.  var data_y = new Array();\
  5151.  var lb = line_name.length;\
  5152.  var idx = 0;\
  5153.  for( var p = 5 ; p < lb ; p = p + 2 ){\
  5154.   data_x[idx] = x2px(line_name[p]);\
  5155.   data_y[idx] = y2px(line_name[p+1]);\
  5156.   idx++;\
  5157.  };\
  5158.  for( var p = 0; p < idx ; p++){\
  5159.   ctx.beginPath();\
  5160.   ctx.moveTo(data_x[p],data_y[p]);\
  5161.   ctx.lineTo(data_x[p+1],data_y[p+1]);\
  5162.   ctx.stroke();\
  5163.   ctx.closePath();\
  5164.  };\
  5165.  i++;\
  5166.  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
  5167. };\
  5168. };\
  5169. var barcolor = new Array();\
  5170. if( typeof barchart%d  !== 'undefined' ){\
  5171. ctx.restore();\
  5172. ctx.save();\
  5173. ctx.globalAlpha = 1.0;\
  5174. var bar_x = new Array();\
  5175. var bar_y = new Array();\
  5176. var lb = barchart%d.length;\
  5177. var idx = 0;\
  5178. for( var p = 0 ; p < lb ; p = p + 3 ){\
  5179.  bar_x[idx] = x2px(barchart%d[p]);\
  5180.  bar_y[idx] = y2px(barchart%d[p+1]);\
  5181.  barcolor[idx] = barchart%d[p+2];\
  5182.  idx++;\
  5183. };\
  5184. var dx = parseInt(0.6*xstep);\
  5185. ctx.globalAlpha = fill_opacity;\
  5186. for( var p = 0; p < idx ; p++ ){\
  5187.  ctx.beginPath();\
  5188.  ctx.strokeStyle = barcolor[p];\
  5189.  ctx.fillStyle = barcolor[p];\
  5190.  ctx.rect(bar_x[p]-0.5*dx,bar_y[p],dx,zero_y - bar_y[p]);\
  5191.  ctx.fill();\
  5192.  ctx.stroke();\
  5193.  ctx.closePath();\
  5194. };\
  5195. };\
  5196. if( typeof legend%d  !== 'undefined' ){\
  5197. ctx.globalAlpha = 1.0;\
  5198. ctx.font = \"bold \"+font_size+\"px Ariel\";\
  5199. var y_offset = 2*font_size;\
  5200. var txt;var txt_size;\
  5201. var x_offset = xsize - 2*font_size;\
  5202. var l_length = legend%d.length;\
  5203. if( typeof legendcolors%d !== 'undefined' ){\
  5204.  for(var p = 0 ; p < l_length ; p++){\
  5205.    barcolor[p] = legendcolors%d[p];\
  5206.  };\
  5207. }else{\
  5208.  if( barcolor.length == 0 ){\
  5209.   for(var p = 0 ; p < l_length ; p++){\
  5210.    barcolor[p] = stroke_color;\
  5211.   };\
  5212.  };\
  5213. };\
  5214. for(var p = 0; p < l_length; p++){\
  5215.  ctx.fillStyle = barcolor[p];\
  5216.  txt = legend%d[p];\
  5217.  txt_size = ctx.measureText(txt).width;\
  5218.  ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
  5219.  y_offset = parseInt(y_offset + 1.5*font_size);\
  5220. };\
  5221. };\
  5222. ctx.restore();\
  5223. return;\
  5224. };",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);
  5225.     break;
  5226.    
  5227.     case DRAW_PIECHART:
  5228. fprintf(js_include_file,"\n<!-- draw piechars -->\n\
  5229. function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,font_size,font_family){\
  5230. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5231.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5232. }\
  5233. else\
  5234. {\
  5235.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5236. };\
  5237. var ld = data_color_list.length;\
  5238. var sum = 0;\
  5239. var idx = 0;\
  5240. var colors = new Array();\
  5241. var data = new Array();\
  5242. for(var p = 0;p < ld; p = p + 2){\
  5243.  data[idx] = parseFloat(data_color_list[p]);\
  5244.  sum = sum + data[idx];\
  5245.  colors[idx] = data_color_list[p+1];\
  5246.  idx++;\
  5247. };\
  5248. var ctx = obj.getContext(\"2d\");\
  5249. ctx.save();\
  5250. var angle;\
  5251. var angle_end = 0;\
  5252. var offset = Math.PI / 2;\
  5253. ctx.globalAlpha = fill_opacity;\
  5254. for(var p=0; p < idx; p++){\
  5255.  ctx.beginPath();\
  5256.  ctx.fillStyle = colors[p];\
  5257.  ctx.moveTo(x_center,y_center);\
  5258.  angle = Math.PI * (2 * data[p] / sum);\
  5259.  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
  5260.  ctx.lineTo(x_center, y_center);\
  5261.  ctx.fill();\
  5262.  ctx.closePath();\
  5263.  angle_end  = angle_end + angle;\
  5264. };\
  5265. if( typeof legend%d  !== 'undefined' ){\
  5266.  ctx.globalAlpha = 1.0;\
  5267.  ctx.font = font_size+\"px \"+font_family;\
  5268.  var y_offset = font_size; \
  5269.  var x_offset = 0;\
  5270.  var txt;var txt_size;\
  5271.  for(var p = 0; p < idx; p++){\
  5272.   ctx.fillStyle = colors[p];\
  5273.   txt = legend%d[p];\
  5274.   txt_size = ctx.measureText(txt).width;\
  5275.   if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
  5276.   ctx.fillText(legend%d[p],x_center + radius - x_offset, y_center - radius + y_offset);\
  5277.   y_offset = parseInt(y_offset + 1.5*font_size);\
  5278.  };\
  5279. };\
  5280. ctx.restore();\
  5281. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  5282.    
  5283.     break;
  5284.     case DRAW_ARCS:
  5285. fprintf(js_include_file,"\n<!-- draw arcs -->\n\
  5286. 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){\
  5287. var obj;\
  5288. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5289.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5290. }\
  5291. else\
  5292. {\
  5293.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5294. };\
  5295. var ctx = obj.getContext(\"2d\");\
  5296. ctx.save();\
  5297. if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  5298. if( use_translate == 1 ){ctx.translate(vector[0],vector[1]);};\
  5299. if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  5300. if(end < start){var tmp = end;end = start;start=tmp;};\
  5301. start=360-start;\
  5302. end=360-end;\
  5303. ctx.lineWidth = line_width;\
  5304. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5305. if( use_filled == 1 ){\
  5306.  ctx.beginPath();\
  5307.  ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  5308.  var x1 = xc + r*Math.cos(Math.PI*start/180);\
  5309.  var y1 = yc + r*Math.sin(Math.PI*start/180);\
  5310.  var x2 = xc + r*Math.cos(Math.PI*end/180);\
  5311.  var y2 = yc + r*Math.sin(Math.PI*end/180);\
  5312.  ctx.beginPath();\
  5313.  ctx.moveTo(x1,y1);\
  5314.  ctx.lineTo(xc,yc);\
  5315.  ctx.moveTo(xc,yc);\
  5316.  ctx.lineTo(x2,y2);\
  5317.  ctx.closePath();\
  5318.  ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  5319.  ctx.fill();\
  5320.  ctx.stroke();\
  5321. }\
  5322. else\
  5323. {\
  5324.    ctx.beginPath();\
  5325.    ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  5326.    ctx.stroke();\
  5327.    ctx.closePath();\
  5328. }\
  5329. ctx.restore();\
  5330. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5331.    
  5332.     break;
  5333.     case DRAW_TEXTS:
  5334. fprintf(js_include_file,"\n<!-- draw text -->\n\
  5335. draw_text = function(canvas_type,x,y,font_size,font_family,stroke_color,stroke_opacity,angle2,text,use_rotate,angle,use_translate,vector){\
  5336.  var obj;\
  5337.  if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5338.   obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5339.  }\
  5340.  else\
  5341.  {\
  5342.   obj = create_canvas%d(canvas_type,xsize,ysize);\
  5343.  };\
  5344.  var ctx = obj.getContext(\"2d\");\
  5345.  if(angle2 == 0 && angle != 0){\
  5346.   ctx.save();\
  5347.   if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  5348.   if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5349.  };\
  5350.  if( font_family.indexOf('px') != null ){\
  5351.   ctx.font = font_family;\
  5352.  }\
  5353.  else\
  5354.  {\
  5355.   ctx.font = \"+font_size+'px '+font_family \";\
  5356.  };\
  5357.  ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5358.  if(angle2 != 0){\
  5359.   ctx.save();\
  5360.   ctx.translate(x,y);\
  5361.   ctx.rotate((360-angle2)*(Math.PI / 180));\
  5362.   ctx.fillText(text,0,0);\
  5363.   ctx.restore();\
  5364.  }else{ctx.fillText(text,x,y);};\
  5365. ctx.restore();\
  5366. return;\
  5367. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5368.    
  5369.     break;
  5370.     case DRAW_CURVE:
  5371. fprintf(js_include_file,"\n<!-- draw curve -->\n\
  5372. 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){\
  5373. var obj;\
  5374. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5375.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5376. }\
  5377. else\
  5378. {\
  5379.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5380. };\
  5381. var ctx = obj.getContext(\"2d\");\
  5382. ctx.save();\
  5383. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  5384. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5385. ctx.beginPath();ctx.lineWidth = line_width;\
  5386. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  5387. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5388. ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
  5389. for(var p = 1 ; p < x_points.length ; p++){\
  5390.  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
  5391.  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
  5392.  }\
  5393.  else\
  5394.  {\
  5395.   ctx.stroke();\
  5396.   ctx.beginPath();\
  5397.   p++;\
  5398.   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
  5399.  };\
  5400. };\
  5401. ctx.stroke();\
  5402. ctx.restore();\
  5403. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5404.     break;
  5405.    
  5406.     case DRAW_INPUTS:
  5407. fprintf(js_include_file,"\n<!-- draw input fields -->\n\
  5408. draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\
  5409. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  5410. var input = document.createElement(\"input\");\
  5411. input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  5412. input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  5413. input.setAttribute(\"size\",size);\
  5414. input.setAttribute(\"value\",value);\
  5415. if( readonly == 0 ){ input.setAttribute(\"readonly\",\"readonly\");};\
  5416. canvas_div.appendChild(input);};");
  5417.     break;
  5418.    
  5419.     case DRAW_TEXTAREAS:
  5420. fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
  5421. draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
  5422. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  5423. var textarea = document.createElement(\"textarea\");\
  5424. textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  5425. textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  5426. textarea.setAttribute(\"cols\",cols);\
  5427. textarea.setAttribute(\"rows\",rows);\
  5428. textarea.innerHTML = value;\
  5429. canvas_div.appendChild(textarea);};");
  5430.     break;
  5431.    
  5432. case DRAW_PIXELS:
  5433. fprintf(js_include_file,"\n<!-- draw pixel -->\n\
  5434. draw_setpixel = function(x,y,color,opacity,pixelsize){\
  5435. var canvas = create_canvas%d(10,xsize,ysize);\
  5436. var d = 0.5*pixelsize;\
  5437. var ctx = canvas.getContext(\"2d\");\
  5438. ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
  5439. ctx.clearRect(0,0,xsize,ysize);\
  5440. for(var p=0; p<x.length;p++){\
  5441.  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
  5442. };\
  5443. ctx.fill();ctx.stroke();\
  5444. };",canvas_root_id);
  5445. break;
  5446.  
  5447. case DRAW_CLOCK:
  5448. fprintf(js_include_file,"\n<!-- begin command clock -->\n\
  5449. var clock_canvas = create_canvas%d(%d,xsize,ysize);\
  5450. var clock_ctx = clock_canvas.getContext(\"2d\");\
  5451. var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
  5452. clock_ctx.save();\
  5453. this.type = type || 0;\
  5454. this.interaction = interaction || 0;\
  5455. this.H = H || parseInt(110*(Math.random()));\
  5456. this.M = M || parseInt(590*(Math.random()));\
  5457. this.S = S || parseInt(590*(Math.random()));\
  5458. this.xc = xc || xsize/2;\
  5459. this.yc = yc || ysize/2;\
  5460. this.radius = radius || xsize/4;\
  5461. var font_size = parseInt(0.2*this.radius);\
  5462. this.H_color = h_color || \"blue\";\
  5463. this.M_color = m_color || \"blue\";\
  5464. this.S_color = s_color || \"blue\";\
  5465. this.fg_color = fg_color || \"red\";\
  5466. this.bg_color = bg_color || \"white\";\
  5467. clock_ctx.translate(this.xc,this.yc);\
  5468. clock_ctx.beginPath();\
  5469. clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
  5470. clock_ctx.fillStyle = this.bg_color;\
  5471. clock_ctx.fill();\
  5472. clock_ctx.closePath();\
  5473. clock_ctx.beginPath();\
  5474. clock_ctx.font = font_size+\"px Arial\";\
  5475. clock_ctx.fillStyle = this.fg_color;\
  5476. clock_ctx.textAlign = \"center\";\
  5477. clock_ctx.textBaseline = 'middle';\
  5478. var angle;var x1,y1,x2,y2;\
  5479. var angle_cos;var angle_sin;\
  5480. switch(type){\
  5481. case 0:clock_ctx.beginPath();\
  5482. for(var p = 1; p <= 12 ; p++){\
  5483.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  5484.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  5485.  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  5486.  clock_ctx.moveTo(x1,y1);\
  5487.  clock_ctx.lineTo(x2,y2);\
  5488. };\
  5489. for(var p = 1; p <= 60 ; p++){\
  5490.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  5491.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  5492.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  5493.  clock_ctx.moveTo(x1,y1);\
  5494.  clock_ctx.lineTo(x2,y2);\
  5495. };\
  5496. clock_ctx.closePath();\
  5497. clock_ctx.stroke();\
  5498. break;\
  5499. case 1:\
  5500. 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;\
  5501. 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);};\
  5502. clock_ctx.beginPath();\
  5503. for(var p = 1; p <= 12 ; p++){\
  5504.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  5505.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  5506.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  5507.  clock_ctx.moveTo(x1,y1);\
  5508.  clock_ctx.lineTo(x2,y2);\
  5509. };\
  5510. for(var p = 1; p <= 60 ; p++){\
  5511.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  5512.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  5513.  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  5514.  clock_ctx.moveTo(x1,y1);\
  5515.  clock_ctx.lineTo(x2,y2);\
  5516. };\
  5517. clock_ctx.closePath();\
  5518. clock_ctx.stroke();\
  5519. break;\
  5520. };\
  5521. angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
  5522. clock_ctx.rotate(angle);\
  5523. clock_ctx.beginPath();\
  5524. clock_ctx.moveTo(-3, -2);\
  5525. clock_ctx.lineTo(-3, 2);\
  5526. clock_ctx.lineTo(this.radius * 0.7, 1);\
  5527. clock_ctx.lineTo(this.radius  * 0.7, -1);\
  5528. clock_ctx.fillStyle = this.H_color;\
  5529. clock_ctx.fill();\
  5530. clock_ctx.rotate(-angle);\
  5531. angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
  5532. clock_ctx.rotate(angle);\
  5533. clock_ctx.beginPath();\
  5534. clock_ctx.moveTo(-3, -2);\
  5535. clock_ctx.lineTo(-3, 2);\
  5536. clock_ctx.lineTo(this.radius  * 0.8, 1);\
  5537. clock_ctx.lineTo(this.radius  * 0.8, -1);\
  5538. clock_ctx.fillStyle = this.M_color;\
  5539. clock_ctx.fill();\
  5540. clock_ctx.rotate(-angle);\
  5541. angle = (this.S - 15) * 2 * Math.PI / 60;\
  5542. clock_ctx.rotate(angle);\
  5543. clock_ctx.beginPath();\
  5544. clock_ctx.moveTo(0,0);\
  5545. clock_ctx.lineTo(this.radius  * 0.95, 0);\
  5546. clock_ctx.lineTo(this.radius  * 0.9, -1);\
  5547. clock_ctx.strokeStyle = this.S_color;\
  5548. clock_ctx.stroke();\
  5549. clock_ctx.restore();\
  5550. };",canvas_root_id,CLOCK_CANVAS);
  5551. break;
  5552.  
  5553. case DRAW_LATTICE:
  5554. fprintf(js_include_file,"\n<!-- draw lattice -->\n\
  5555. 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){\
  5556. var obj;\
  5557. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  5558.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  5559. }\
  5560. else\
  5561. {\
  5562.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  5563. };\
  5564. var ctx = obj.getContext(\"2d\");\
  5565. ctx.save();\
  5566. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  5567. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  5568. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5569. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  5570. var radius = line_width;\
  5571. var x = 0;\
  5572. var y = 0;\
  5573. var x_step_px = xsize/(xmax-xmin);\
  5574. var y_step_px = ysize/(ymax-ymin);\
  5575. var xv1 = dx1*x_step_px;\
  5576. var yv1 = dy1*y_step_px;\
  5577. var xv2 = dx2*x_step_px;\
  5578. var yv2 = dy2*y_step_px;\
  5579. for(var p = 0; p < n1 ;p++){\
  5580.  x = p*xv1 + x0;\
  5581.  y = p*yv1 + y0;\
  5582.  for(var c = 0; c < n2 ; c++){\
  5583.   ctx.beginPath();\
  5584.   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
  5585.   ctx.fill();\
  5586.   ctx.stroke();\
  5587.   ctx.closePath();\
  5588.  };\
  5589. };\
  5590. ctx.restore();\
  5591. return;\
  5592. };",canvas_root_id,canvas_root_id,canvas_root_id);
  5593.     break;
  5594. case DRAW_XYLOGSCALE:
  5595. fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\
  5596. 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\
  5597. var obj;\n\
  5598. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\
  5599.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\
  5600. }\n\
  5601. else\n\
  5602. {\n\
  5603.  obj = create_canvas%d(canvas_type,xsize,ysize);\n\
  5604. };\n\
  5605. var ctx = obj.getContext(\"2d\");\n\
  5606. ctx.clearRect(0,0,xsize,ysize);\
  5607. ctx.save();\n\
  5608. var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
  5609. var x_min = Math.log(xmin)/Math.log(xlogbase);\n\
  5610. var x_max = Math.log(xmax)/Math.log(xlogbase);\n\
  5611. var y_min = Math.log(ymin)/Math.log(ylogbase);\n\
  5612. var y_max = Math.log(ymax)/Math.log(ylogbase);\n\
  5613. if(use_axis_numbering == 1){\
  5614.  ctx.font = font_family;\n\
  5615.  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\n\
  5616.  ymarge = parseInt(1.5*font_size);\n\
  5617.  ctx.save();\n\
  5618.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\n\
  5619.  ctx.rect(0,0,xmarge,ysize);\n\
  5620.  ctx.rect(0,ysize-ymarge,xsize,ysize);\n\
  5621.  ctx.fill();\n\
  5622.  ctx.restore();\n\
  5623. }else{xmarge = 0;ymarge = 0;};\n\
  5624. if( typeof xaxislabel !== 'undefined' ){\
  5625.  ctx.save();\n\
  5626.  ctx.font = \"italic \"+font_size+\"px Ariel\";\n\
  5627.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5628.  corr =  ctx.measureText(xaxislabel).width;\n\
  5629.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\n\
  5630.  ctx.restore();\n\
  5631. };\n\
  5632. if( typeof yaxislabel !== 'undefined' ){\
  5633.  ctx.save();\n\
  5634.  ctx.font = \"italic \"+font_size+\"px Ariel\";\n\
  5635.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5636.  corr = ctx.measureText(yaxislabel).width;\n\
  5637.  ctx.translate(xmarge+font_size,corr+font_size);\n\
  5638.  ctx.rotate(-0.5*Math.PI);\n\
  5639.  ctx.fillText(yaxislabel,0,0);\n\
  5640.  ctx.restore();\n\
  5641. };\n\
  5642. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5643. ctx.lineWidth = line_width;\n\n\
  5644. for(var p = x_min; p <= x_max ; p++){\n\
  5645.  num = Math.pow(xlogbase,p);\n\n\
  5646.  for(var i = 1 ; i < xlogbase ; i++){\n\
  5647.   x_e = x2px(i*num);\n\n\
  5648.   if( i == 1 ){\
  5649.    ctx.lineWidth = line_width;\n\n\
  5650.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\n\
  5651.    if( use_axis_numbering == 1 && p > x_min){\
  5652.      xtxt = xlogbase+'^'+p.toFixed(0);\n\
  5653.      corr = 0.5*(ctx.measureText(xtxt).width);\n\
  5654.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\n\
  5655.    };\n\
  5656.   }else{\
  5657.    ctx.lineWidth = 0.2*line_width;\n\n\
  5658.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\n\
  5659.   };\n\
  5660.   if( x_e >= xmarge ){\
  5661.    ctx.beginPath();\n\
  5662.    ctx.moveTo(x_e,0);\n\
  5663.    ctx.lineTo(x_e,ysize - ymarge);\n\n\
  5664.    ctx.stroke();\n\
  5665.    ctx.closePath();\n\
  5666.   };\
  5667.  };\n\
  5668. };\n\
  5669. for(var p = y_min; p <= y_max ; p++){\n\
  5670.  num = Math.pow(ylogbase,p);\n\
  5671.  for(var i = 1 ; i < ylogbase ; i++){\n\
  5672.   y_e = y2px(i*num);\n\
  5673.   if( i == 1 ){\n\
  5674.    ctx.lineWidth = line_width;\n\
  5675.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  5676.    if( use_axis_numbering == 1 && p > y_min){\n\
  5677.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\n\
  5678.    };\n\
  5679.   }else{\n\
  5680.    ctx.lineWidth = 0.2*line_width;\n\
  5681.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\n\
  5682.   };\n\
  5683.   ctx.beginPath();\n\
  5684.   ctx.moveTo(xmarge,y_e);\n\
  5685.   ctx.lineTo(xsize,y_e);\n\
  5686.   ctx.stroke();\n\
  5687.   ctx.closePath();\n\
  5688.  };\n\
  5689. };\n\
  5690. ctx.restore();\
  5691. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  5692.     break;
  5693.  
  5694. case DRAW_XLOGSCALE:
  5695. fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\
  5696. 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\
  5697. var obj;\n\
  5698. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\
  5699.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\
  5700. }\n\
  5701. else\n\
  5702. {\n\
  5703.  obj = create_canvas%d(canvas_type,xsize,ysize);\n\
  5704. };\n\
  5705. var ctx = obj.getContext(\"2d\");\n\
  5706. ctx.clearRect(0,0,xsize,ysize);\
  5707. ctx.save();\n\
  5708. ctx.lineWidth = line_width;\n\
  5709. var prec = Math.log(precision)/Math.log(10);\
  5710. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  5711. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  5712. var y_min = 0;var y_max = ysize;var x_e;var corr;\
  5713. var xtxt;var ytxt;var num;var xmarge;var ymarge;\
  5714. if(use_axis_numbering == 1){\
  5715.  ctx.font = font_family;\n\
  5716.  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\n\
  5717.  ymarge = parseInt(1.5*font_size);\n\
  5718.  ctx.save();\n\
  5719.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\n\
  5720.  ctx.rect(0,0,xmarge,ysize);\n\
  5721.  ctx.rect(0,ysize-ymarge,xsize,ysize);\n\
  5722.  ctx.fill();\n\
  5723.  ctx.restore();\n\
  5724. }else{xmarge = 0;ymarge = 0;};\n\
  5725. if( typeof xaxislabel !== 'undefined' ){\
  5726.  ctx.save();\n\
  5727.  ctx.font = \"italic \"+font_size+\"px Ariel\";\n\
  5728.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5729.  corr =  ctx.measureText(xaxislabel).width;\n\
  5730.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\n\
  5731.  ctx.restore();\n\
  5732. };\n\
  5733. if( typeof yaxislabel !== 'undefined' ){\
  5734.  ctx.save();\n\
  5735.  ctx.font = \"italic \"+font_size+\"px Ariel\";\n\
  5736.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5737.  corr = ctx.measureText(yaxislabel).width;\n\
  5738.  ctx.translate(xmarge+font_size,corr+font_size);\n\
  5739.  ctx.rotate(-0.5*Math.PI);\n\
  5740.  ctx.fillText(yaxislabel,0,0);\n\
  5741.  ctx.restore();\n\
  5742. };\n\
  5743. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5744. ctx.lineWidth = line_width;\n\n\
  5745. for(var p = x_min; p <= x_max ; p++){\n\
  5746.  num = Math.pow(xlogbase,p);\n\
  5747.  for(var i = 1 ; i < xlogbase ; i++){\n\
  5748.   x_e = x2px(i*num);\n\
  5749.   if( i == 1 ){\
  5750.     ctx.lineWidth = line_width;\n\
  5751.     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  5752.    if( use_axis_numbering == 1 && p > x_min ){\
  5753.      xtxt = xlogbase+'^'+p.toFixed(0);\
  5754.      corr = 0.5*(ctx.measureText(xtxt).width);\
  5755.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  5756.    };\
  5757.   }else{\
  5758.    ctx.lineWidth = 0.2*line_width;\n\
  5759.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  5760.   };\
  5761.   if( x_e >= xmarge ){\
  5762.    ctx.beginPath();\n\
  5763.    ctx.moveTo(x_e,0);\n\
  5764.    ctx.lineTo(x_e,ysize - ymarge);\n\n\
  5765.    ctx.stroke();\n\
  5766.    ctx.closePath();\n\
  5767.   };\
  5768.  };\
  5769. };\n\
  5770. var stepy = Math.abs(y2px(ymajor) - y2px(0));\
  5771. var minor_step = stepy / yminor;\
  5772. for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
  5773.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  5774.  ctx.lineWidth = line_width;\n\
  5775.  ctx.beginPath();\n\
  5776.  ctx.moveTo(xmarge,y);\n\
  5777.  ctx.lineTo(xsize,y);\n\
  5778.  ctx.stroke();\n\
  5779.  ctx.closePath();\n\
  5780.  if( use_axis_numbering == 1){\
  5781.   ytxt = (px2y(y)).toFixed(prec);\
  5782.   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
  5783.  };\
  5784.  for(var dy = 1 ; dy < yminor ; dy++){\
  5785.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  5786.   ctx.lineWidth = 0.2*line_width;\n\
  5787.   ctx.beginPath();\n\
  5788.   ctx.moveTo(xmarge,y+dy*minor_step);\
  5789.   ctx.lineTo(xsize,y+dy*minor_step);\n\
  5790.   ctx.stroke();\n\
  5791.   ctx.closePath();\n\
  5792.  };\
  5793. };\
  5794. ctx.restore();\n\
  5795. };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  5796.     break;
  5797. case DRAW_YLOGSCALE:
  5798. fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\
  5799. 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\
  5800. var obj;\n\
  5801. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\
  5802.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\
  5803. }\n\
  5804. else\n\
  5805. {\n\
  5806.  obj = create_canvas%d(canvas_type,xsize,ysize);\n\
  5807. };\n\
  5808. var ctx = obj.getContext(\"2d\");\n\
  5809. ctx.clearRect(0,0,xsize,ysize);\
  5810. ctx.save();\n\
  5811. ctx.lineWidth = line_width;\n\
  5812. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  5813. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  5814. var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;\
  5815. if(use_axis_numbering == 1){\
  5816.  ctx.font = font_family;\n\
  5817.  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\n\
  5818.  ymarge = 2*font_size;\n\
  5819.  ctx.save();\n\
  5820.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\n\
  5821.  ctx.rect(0,0,xmarge,ysize);\n\
  5822.  ctx.rect(0,ysize-ymarge,xsize,ysize);\n\
  5823.  ctx.fill();\n\
  5824.  ctx.restore();\n\
  5825. }else{xmarge = 0;ymarge = 0;};\n\
  5826. if( typeof xaxislabel !== 'undefined' ){\
  5827.  ctx.save();\n\
  5828.  ctx.font = \"italic \"+font_size+\"px Ariel\";\n\
  5829.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5830.  corr =  ctx.measureText(xaxislabel).width;\n\
  5831.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\n\
  5832.  ctx.restore();\n\
  5833. };\n\
  5834. if( typeof yaxislabel !== 'undefined' ){\
  5835.  ctx.save();\n\
  5836.  ctx.font = \"italic \"+font_size+\"px Ariel\";\n\
  5837.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5838.  corr = ctx.measureText(yaxislabel).width;\n\
  5839.  ctx.translate(xmarge+font_size,corr+font_size);\n\
  5840.  ctx.rotate(-0.5*Math.PI);\n\
  5841.  ctx.fillText(yaxislabel,0,0);\n\
  5842.  ctx.restore();\n\
  5843. };\n\
  5844. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\n\
  5845. ctx.lineWidth = line_width;\n\n\
  5846. for(var p = y_min; p <= y_max ; p++){\n\
  5847.  num = Math.pow(ylogbase,p);\n\
  5848.  for(var i = 1 ; i < ylogbase ; i++){\n\
  5849.   y_e = y2px(i*num);\n\
  5850.   if( i == 1 ){\
  5851.    ctx.lineWidth = line_width;\n\
  5852.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  5853.    if( use_axis_numbering == 1 && p > y_min){\
  5854.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  5855.    };\
  5856.   }else{\
  5857.    ctx.lineWidth = 0.2*line_width;\n\
  5858.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  5859.   };\
  5860.   ctx.beginPath();\n\
  5861.   ctx.moveTo(xmarge,y_e);\n\
  5862.   ctx.lineTo(xsize,y_e);\n\
  5863.   ctx.stroke();\n\
  5864.   ctx.closePath();\n\
  5865.  };\n\
  5866. };\n\
  5867. var stepx = Math.abs(x2px(xmajor) - x2px(0));\
  5868. var minor_step = stepx / xminor;\
  5869. var prec = Math.log(precision)/Math.log(10);\
  5870. var xtxt;var corr;var flip = 0;\
  5871. for(var x = stepx ; x < xsize ; x = x + stepx){\
  5872.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  5873.  ctx.lineWidth = line_width;\n\
  5874.  ctx.beginPath();\n\
  5875.  ctx.moveTo(x,ysize-ymarge);\n\
  5876.  ctx.lineTo(x,0);\n\
  5877.  ctx.stroke();\n\
  5878.  ctx.closePath();\n\
  5879.  if( use_axis_numbering == 1){\
  5880.   xtxt = (px2x(x)).toFixed(prec);\
  5881.   corr = 0.5*(ctx.measureText(xtxt).width);\
  5882.   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
  5883.   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
  5884.  };\
  5885.  for(var dx = 1 ; dx < xminor ; dx++){\
  5886.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  5887.   ctx.lineWidth = 0.2*line_width;\n\
  5888.   ctx.beginPath();\n\
  5889.   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
  5890.   ctx.lineTo(x+dx*minor_step,0);\n\
  5891.   ctx.stroke();\n\
  5892.   ctx.closePath();\n\
  5893.  };\
  5894. };\
  5895. ctx.restore();\n\
  5896. };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  5897.  
  5898.     break;
  5899.  
  5900.  
  5901.     default:break;
  5902.    }
  5903.   }
  5904.  }
  5905.   return;
  5906. }
  5907.  
  5908. void check_string_length(int L){
  5909.  if(L<1 || L > MAX_BUFFER-1){
  5910.   canvas_error("problem with your arguments to command...");
  5911.  }
  5912.  return;
  5913. }
  5914.  
  5915.  
  5916. int get_token(FILE *infile){
  5917.         int     c,i=0;
  5918.         char    temp[MAX_INT], *input_type;
  5919.         char    *line="line",
  5920.         *audio="audio",
  5921.         *blink="blink",
  5922.         *arrowhead="arrowhead",
  5923.         *crosshairsize="crosshairsize",
  5924.         *crosshair="crosshair",
  5925.         *crosshairs="crosshairs",
  5926.         *audioobject="audioobject",
  5927.         *style="style",
  5928.         *mouse="mouse",
  5929.         *userdraw="userdraw",
  5930.         *highlight="highlight",
  5931.         *http="http",
  5932.         *rays="rays",
  5933.         *dashtype="dashtype",
  5934.         *dashed="dashed",
  5935.         *filled="filled",
  5936.         *lattice="lattice",
  5937.         *parallel="parallel",
  5938.         *segment="segment",
  5939.         *dsegment="dsegment",
  5940.         *seg="seg",
  5941.         *bgimage="bgimage",
  5942.         *bgcolor="bgcolor",
  5943.         *strokecolor="strokecolor",
  5944.         *backgroundimage="backgroundimage",
  5945.         *text="text",
  5946.         *textup="textup",
  5947.         *mouseprecision="mouseprecision",
  5948.         *precision="precision",
  5949.         *plotsteps="plotsteps",
  5950.         *plotstep="plotstep",
  5951.         *tsteps="tsteps",
  5952.         *curve="curve",
  5953.         *dcurve="dcurve",
  5954.         *plot="plot",
  5955.         *dplot="dplot",
  5956.         *levelcurve="levelcurve",
  5957.         *fontsize="fontsize",
  5958.         *fontcolor="fontcolor",
  5959.         *axis="axis",
  5960.         *axisnumbering="axisnumbering",
  5961.         *axisnumbers="axisnumbers",
  5962.         *arrow="arrow",
  5963.         *darrow="darrow",
  5964.         *arrow2="arrow2",
  5965.         *darrow2="darrow2",
  5966.         *zoom="zoom",
  5967.         *grid="grid",
  5968.         *hline="hline",
  5969.         *dhline="dhline",
  5970.         *drag="drag",
  5971.         *horizontalline="horizontalline",
  5972.         *vline="vline",
  5973.         *dvline="dvline",
  5974.         *verticalline="verticalline",
  5975.         *triangle="triangle",
  5976.         *ftriangle="ftriangle",
  5977.         *mathml="mathml",
  5978.         *html="html",
  5979.         *input="input",
  5980.         *button="button",
  5981.         *inputstyle="inputstyle",
  5982.         *textarea="textarea",
  5983.         *trange="trange",
  5984.         *ranget="ranget",
  5985.         *xrange="xrange",
  5986.         *yrange="yrange",
  5987.         *rangex="rangex",
  5988.         *rangey="rangey",
  5989.         *polyline="polyline",
  5990.         *lines="lines",
  5991.         *poly="poly",
  5992.         *polygon="polygon",
  5993.         *fpolygon="fpolygon",
  5994.         *fpoly="fpoly",
  5995.         *filledpoly="filledpoly",
  5996.         *filledpolygon="filledpolygon",
  5997.         *rect="rect",
  5998.         *frect="frect",
  5999.         *rectangle="rectangle",
  6000.         *frectangle="frectangle",
  6001.         *square="square",
  6002.         *fsquare="fsquare",
  6003.         *dline="dline",
  6004.         *arc="arc",
  6005.         *filledarc="filledarc",
  6006.         *size="size",
  6007.         *string="string",
  6008.         *stringup="stringup",
  6009.         *copy="copy",
  6010.         *copyresized="copyresized",
  6011.         *opacity="opacity",
  6012.         *transparent="transparent",
  6013.         *fill="fill",
  6014.         *slider="slider",
  6015.         *point="point",
  6016.         *points="points",
  6017.         *linewidth="linewidth",
  6018.         *circle="circle",
  6019.         *fcircle="fcircle",
  6020.         *disk="disk",
  6021.         *comment="#",
  6022.         *end="end",
  6023.         *ellipse="ellipse",
  6024.         *fellipse="fellipse",
  6025.         *rotate="rotate",
  6026.         *affine="affine",
  6027.         *killaffine="killaffine",
  6028.         *fontfamily="fontfamily",
  6029.         *fillcolor="fillcolor",
  6030.         *clicktile="clicktile",
  6031.         *clicktile_colors="clicktile_colors",
  6032.         *translation="translation",
  6033.         *translate="translate",
  6034.         *killtranslation="killtranslation",
  6035.         *killtranslate="killtranslate",
  6036.         *onclick="onclick",
  6037.         *roundrect="roundrect",
  6038.         *froundrect="froundrect",
  6039.         *roundrectangle="roundrectangle",
  6040.         *patternfill="patternfill",
  6041.         *hatchfill="hatchfill",
  6042.         *diafill="diafill",
  6043.         *diamondfill="diamondfill",
  6044.         *dotfill="dotfill",
  6045.         *gridfill="gridfill",
  6046.         *imagefill="imagefill",
  6047.         *xlogbase="xlogbase",
  6048.         *ylogbase="ylogbase",
  6049.         *xlogscale="xlogscale",
  6050.         *ylogscale="ylogscale",
  6051.         *xylogscale="xylogscale",
  6052.         *intooltip="intooltip",
  6053.         *replyformat="replyformat",
  6054.         *floodfill="floodfill",
  6055.         *filltoborder="filltoborder",
  6056.         *clickfill="clickfill",
  6057.         *setpixel="setpixel",
  6058.         *pixels="pixels",
  6059.         *pixelsize="pixelsize",
  6060.         *clickfillmarge="clickfillmarge",
  6061.         *xaxis="xaxis",
  6062.         *yaxis="yaxis",
  6063.         *xaxistext="xaxistext",
  6064.         *yaxistext="yaxistext",
  6065.         *piechart="piechart",
  6066.         *legend="legend",
  6067.         *legendcolors="legendcolors",
  6068.         *xlabel="xlabel",
  6069.         *ylabel="ylabel",
  6070.         *barchart="barchart",
  6071.         *linegraph="linegraph",
  6072.         *clock="clock",
  6073.         *animate="animate",
  6074.         *video="video",
  6075.         *status="status",
  6076.         *snaptogrid="snaptogrid",
  6077.         *xsnaptogrid="xsnaptogrid",
  6078.         *ysnaptogrid="ysnaptogrid",
  6079.         *userinput_xy="userinput_xy",
  6080.         *usertextarea_xy="usertextarea_xy",
  6081.         *sgraph="sgraph";
  6082.  
  6083.         while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')){
  6084.             if( i == 0 && (c == ' ' || c == '\t') ){
  6085.         continue; /* white spaces or tabs allowed before first command identifier */
  6086.             }
  6087.             else
  6088.             {
  6089.         if( c == ' ' || c == '\t' ){
  6090.             break;
  6091.         }
  6092.         else
  6093.         {
  6094.             temp[i] = c;
  6095.             if(i > MAX_INT - 2){canvas_error("command string too long !");}
  6096.             i++;
  6097.         }
  6098.             }
  6099.             if(temp[0] == '#') break;
  6100.         }
  6101.         if (c == EOF) finished = 1;
  6102.  
  6103.         if (c == '\n' || c == '\r') {
  6104.         line_number++;
  6105.         if (i == 0) { return EMPTY; }
  6106.         } else if (c == EOF) {
  6107.         return 0;
  6108.         }
  6109.  
  6110.         temp[i]='\0';
  6111.         input_type=(char*)my_newmem(strlen(temp));
  6112.         snprintf(input_type,sizeof(temp),"%s",temp);
  6113.  
  6114.         if( strcmp(input_type, size) == 0 ){
  6115.         free(input_type);
  6116.         return SIZE;
  6117.         }
  6118.         if( strcmp(input_type, xrange) == 0 ){
  6119.         free(input_type);
  6120.         return XRANGE;
  6121.         }
  6122.         if( strcmp(input_type, rangex) == 0 ){
  6123.         free(input_type);
  6124.         return XRANGE;
  6125.         }
  6126.         if( strcmp(input_type, trange) == 0 ){
  6127.         free(input_type);
  6128.         return TRANGE;
  6129.         }
  6130.         if( strcmp(input_type, ranget) == 0 ){
  6131.         free(input_type);
  6132.         return TRANGE;
  6133.         }
  6134.         if( strcmp(input_type, yrange) == 0 ){
  6135.         free(input_type);
  6136.         return YRANGE;
  6137.         }
  6138.         if( strcmp(input_type, rangey) == 0 ){
  6139.         free(input_type);
  6140.         return YRANGE;
  6141.         }
  6142.         if( strcmp(input_type, linewidth) == 0 ){
  6143.         free(input_type);
  6144.         return LINEWIDTH;
  6145.         }
  6146.         if( strcmp(input_type, dashed) == 0 ){
  6147.         free(input_type);
  6148.         return DASHED;
  6149.         }
  6150.         if( strcmp(input_type, dashtype) == 0 ){
  6151.         free(input_type);
  6152.         return DASHTYPE;
  6153.         }
  6154.         if( strcmp(input_type, axisnumbering) == 0 ){
  6155.         free(input_type);
  6156.         return AXIS_NUMBERING;
  6157.         }
  6158.         if( strcmp(input_type, axisnumbers) == 0 ){
  6159.         free(input_type);
  6160.         return AXIS_NUMBERING;
  6161.         }
  6162.         if( strcmp(input_type, axis) == 0 ){
  6163.         free(input_type);
  6164.         return AXIS;
  6165.         }
  6166.         if( strcmp(input_type, grid) == 0 ){
  6167.         free(input_type);
  6168.         return GRID;
  6169.         }
  6170.         if( strcmp(input_type, parallel) == 0 ){
  6171.         free(input_type);
  6172.         return PARALLEL;
  6173.         }
  6174.         if( strcmp(input_type, hline) == 0 ||  strcmp(input_type, horizontalline) == 0 ){
  6175.         free(input_type);
  6176.         return HLINE;
  6177.         }
  6178.         if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
  6179.         free(input_type);
  6180.         return VLINE;
  6181.         }
  6182.         if( strcmp(input_type, line) == 0 ){
  6183.         free(input_type);
  6184.         return LINE;
  6185.         }
  6186.         if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
  6187.         free(input_type);
  6188.         return SEGMENT;
  6189.         }
  6190.         if( strcmp(input_type, dsegment) == 0 ){
  6191.         free(input_type);
  6192.         use_dashed = TRUE;
  6193.         return SEGMENT;
  6194.         }
  6195.         if( strcmp(input_type, crosshairsize) == 0 ){
  6196.         free(input_type);
  6197.         return CROSSHAIRSIZE;
  6198.         }
  6199.         if( strcmp(input_type, arrowhead) == 0 ){
  6200.         free(input_type);
  6201.         return ARROWHEAD;
  6202.         }
  6203.         if( strcmp(input_type, crosshairs) == 0 ){
  6204.         free(input_type);
  6205.         return CROSSHAIRS;
  6206.         }
  6207.         if( strcmp(input_type, crosshair) == 0 ){
  6208.         free(input_type);
  6209.         return CROSSHAIR;
  6210.         }
  6211.         if( strcmp(input_type, onclick) == 0 ){
  6212.         free(input_type);
  6213.         return ONCLICK;
  6214.         }
  6215.         if( strcmp(input_type, drag) == 0 ){
  6216.         free(input_type);
  6217.         return DRAG;
  6218.         }
  6219.         if( strcmp(input_type, userdraw) == 0 ){
  6220.         free(input_type);
  6221.         return USERDRAW;
  6222.         }
  6223.         if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
  6224.         free(input_type);
  6225.         return STYLE;
  6226.         }
  6227.         if( strcmp(input_type, fillcolor) == 0 ){
  6228.         free(input_type);
  6229.         return FILLCOLOR;
  6230.         }
  6231.         if( strcmp(input_type, strokecolor) == 0 ){
  6232.         free(input_type);
  6233.         return STROKECOLOR;
  6234.         }
  6235.         if( strcmp(input_type, filled) == 0  ){
  6236.         free(input_type);
  6237.         return FILLED;
  6238.         }
  6239.         if( strcmp(input_type, http) == 0 ){
  6240.         free(input_type);
  6241.         return HTTP;
  6242.         }
  6243.         if( strcmp(input_type, rays) == 0 ){
  6244.         free(input_type);
  6245.         return RAYS;
  6246.         }
  6247.         if( strcmp(input_type, lattice) == 0 ){
  6248.         free(input_type);
  6249.         return LATTICE;
  6250.         }
  6251.         if( strcmp(input_type, bgimage) == 0 ){
  6252.         free(input_type);
  6253.         return BGIMAGE;
  6254.         }
  6255.         if( strcmp(input_type, bgcolor) == 0 ){
  6256.         free(input_type);
  6257.         return BGCOLOR;
  6258.         }
  6259.         if( strcmp(input_type, backgroundimage) == 0 ){
  6260.         free(input_type);
  6261.         return BGIMAGE;
  6262.         }
  6263.         if( strcmp(input_type, text) == 0 ){
  6264.         free(input_type);
  6265.         return FLY_TEXT;
  6266.         }
  6267.         if( strcmp(input_type, textup) == 0 ){
  6268.         free(input_type);
  6269.         return FLY_TEXTUP;
  6270.         }
  6271.         if( strcmp(input_type, mouse) == 0 ){
  6272.         free(input_type);
  6273.         return MOUSE;
  6274.         }
  6275.         if( strcmp(input_type, mouseprecision) == 0 ){
  6276.         free(input_type);
  6277.         return MOUSE_PRECISION;
  6278.         }
  6279.         if( strcmp(input_type, precision) == 0 ){
  6280.         free(input_type);
  6281.         return MOUSE_PRECISION;
  6282.         }
  6283.         if( strcmp(input_type, curve) == 0 ){
  6284.         free(input_type);
  6285.         return CURVE;
  6286.         }
  6287.         if( strcmp(input_type, dcurve) == 0 ){
  6288.         use_dashed = TRUE;
  6289.         free(input_type);
  6290.         return CURVE;
  6291.         }
  6292.         if( strcmp(input_type, plot) == 0 ){
  6293.         free(input_type);
  6294.         return CURVE;
  6295.         }
  6296.         if( strcmp(input_type, dplot) == 0 ){
  6297.         use_dashed = TRUE;
  6298.         free(input_type);
  6299.         return CURVE;
  6300.         }
  6301.         if( strcmp(input_type, levelcurve) == 0 ){
  6302.         free(input_type);
  6303.         return LEVELCURVE;
  6304.         }
  6305.         if( strcmp(input_type, plotsteps) == 0 ){
  6306.         free(input_type);
  6307.         return PLOTSTEPS;
  6308.         }
  6309.         if( strcmp(input_type, plotstep) == 0 ){
  6310.         free(input_type);
  6311.         return PLOTSTEPS;
  6312.         }
  6313.         if( strcmp(input_type, tsteps) == 0 ){
  6314.         free(input_type);
  6315.         return PLOTSTEPS;
  6316.         }
  6317.         if( strcmp(input_type, fontsize) == 0 ){
  6318.         free(input_type);
  6319.         return FONTSIZE;
  6320.         }
  6321.         if( strcmp(input_type, fontcolor) == 0 ){
  6322.         free(input_type);
  6323.         return FONTCOLOR;
  6324.         }
  6325.         if( strcmp(input_type, arrow) == 0 ){
  6326.         free(input_type);
  6327.         return ARROW;
  6328.         }
  6329.         if( strcmp(input_type, arrow2) == 0 ){
  6330.         free(input_type);
  6331.         return ARROW2;
  6332.         }
  6333.         if( strcmp(input_type, darrow) == 0 ){
  6334.         free(input_type);
  6335.         return ARROW;
  6336.         }
  6337.         if( strcmp(input_type, darrow2) == 0 ){
  6338.         free(input_type);
  6339.         use_dashed = TRUE;
  6340.         return ARROW2;
  6341.         }
  6342.         if( strcmp(input_type, zoom) == 0 ){
  6343.         free(input_type);
  6344.         return ZOOM;
  6345.         }
  6346.         if( strcmp(input_type, triangle) == 0 ){
  6347.         free(input_type);
  6348.         return TRIANGLE;
  6349.         }
  6350.         if( strcmp(input_type, ftriangle) == 0 ){
  6351.         free(input_type);
  6352.         use_filled = TRUE;
  6353.         return TRIANGLE;
  6354.         }
  6355.         if( strcmp(input_type, input) == 0 ){
  6356.         free(input_type);
  6357.         return INPUT;
  6358.         }
  6359.         if( strcmp(input_type, inputstyle) == 0 ){
  6360.         free(input_type);
  6361.         return INPUTSTYLE;
  6362.         }
  6363.         if( strcmp(input_type, textarea) == 0 ){
  6364.         free(input_type);
  6365.         return TEXTAREA;
  6366.         }
  6367.         if( strcmp(input_type, mathml) == 0 ){
  6368.         free(input_type);
  6369.         return MATHML;
  6370.         }
  6371.         if( strcmp(input_type, html) == 0 ){
  6372.         free(input_type);
  6373.         return MATHML;
  6374.         }
  6375.         if( strcmp(input_type, fontfamily) == 0 ){
  6376.         free(input_type);
  6377.         return FONTFAMILY;
  6378.         }
  6379.         if( strcmp(input_type, lines) == 0  ||  strcmp(input_type, polyline) == 0 ){
  6380.         free(input_type);
  6381.         return POLYLINE;
  6382.         }
  6383.         if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
  6384.         free(input_type);
  6385.         return RECT;
  6386.         }
  6387.         if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
  6388.         free(input_type);
  6389.         return ROUNDRECT;
  6390.         }
  6391.         if( strcmp(input_type, froundrect) == 0 ){
  6392.         free(input_type);
  6393.         use_filled = TRUE;
  6394.         return ROUNDRECT;
  6395.         }
  6396.         if( strcmp(input_type, square) == 0 ){
  6397.         free(input_type);
  6398.         return SQUARE;
  6399.         }
  6400.         if( strcmp(input_type, fsquare) == 0 ){
  6401.         free(input_type);
  6402.         use_filled = TRUE;
  6403.         return SQUARE;
  6404.         }
  6405.         if( strcmp(input_type, dline) == 0 ){
  6406.         use_dashed = TRUE;
  6407.         free(input_type);
  6408.         return LINE;
  6409.         }
  6410.         if( strcmp(input_type, dvline) == 0 ){
  6411.         use_dashed = TRUE;
  6412.         free(input_type);
  6413.         return VLINE;
  6414.         }
  6415.         if( strcmp(input_type, dhline) == 0 ){
  6416.         use_dashed = TRUE;
  6417.         free(input_type);
  6418.         return HLINE;
  6419.         }
  6420.         if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
  6421.         use_filled = TRUE;
  6422.         free(input_type);
  6423.         return RECT;
  6424.         }
  6425.         if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
  6426.         use_filled = TRUE;
  6427.         free(input_type);
  6428.         return CIRCLE;
  6429.         }
  6430.         if( strcmp(input_type, circle) == 0 ){
  6431.         free(input_type);
  6432.         return CIRCLE;
  6433.         }
  6434.         if( strcmp(input_type, point) == 0 ){
  6435.         free(input_type);
  6436.         return POINT;
  6437.         }
  6438.         if( strcmp(input_type, points) == 0 ){
  6439.         free(input_type);
  6440.         return POINTS;
  6441.         }
  6442.         if( strcmp(input_type, filledarc) == 0 ){
  6443.         use_filled = TRUE;
  6444.         free(input_type);
  6445.         return ARC;
  6446.         }
  6447.         if( strcmp(input_type, arc) == 0 ){
  6448.         free(input_type);
  6449.         return ARC;
  6450.         }
  6451.         if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
  6452.         free(input_type);
  6453.         return POLY;
  6454.         }
  6455.         if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
  6456.         use_filled = TRUE;
  6457.         free(input_type);
  6458.         return POLY;
  6459.         }
  6460.         if( strcmp(input_type, ellipse) == 0){
  6461.         free(input_type);
  6462.         return ELLIPSE;
  6463.         }
  6464.         if( strcmp(input_type, fill) == 0 ){
  6465.         free(input_type);
  6466.         return FLOODFILL;
  6467.         }
  6468.         if( strcmp(input_type, string) == 0 ){
  6469.         free(input_type);
  6470.         return STRING;
  6471.         }
  6472.         if( strcmp(input_type, stringup) == 0 ){
  6473.         free(input_type);
  6474.         return STRINGUP;
  6475.         }
  6476.         if( strcmp(input_type, opacity) == 0 ){
  6477.         free(input_type);
  6478.         return OPACITY;
  6479.         }
  6480.         if( strcmp(input_type, comment) == 0){
  6481.         free(input_type);
  6482.         return COMMENT;
  6483.         }
  6484.         if( strcmp(input_type, end) == 0){
  6485.         free(input_type);
  6486.         return END;
  6487.         }
  6488.         if( strcmp(input_type, fellipse) == 0){
  6489.         free(input_type);
  6490.         use_filled = TRUE;
  6491.         return ELLIPSE;
  6492.         }      
  6493.         if( strcmp(input_type, blink) == 0 ){
  6494.         free(input_type);
  6495.         return BLINK;
  6496.         }
  6497.         if( strcmp(input_type, button) == 0){
  6498.         free(input_type);
  6499.         return BUTTON;
  6500.         }
  6501.         if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
  6502.         free(input_type);
  6503.         return TRANSLATION;
  6504.         }
  6505.         if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
  6506.         free(input_type);
  6507.         return KILLTRANSLATION;
  6508.         }
  6509.         if( strcmp(input_type, rotate) == 0){
  6510.         free(input_type);
  6511.         return ROTATE;
  6512.         }
  6513.         if( strcmp(input_type, affine) == 0){
  6514.         free(input_type);
  6515.         return AFFINE;
  6516.         }
  6517.         if( strcmp(input_type, killaffine) == 0){
  6518.         free(input_type);
  6519.         return KILLAFFINE;
  6520.         }
  6521.         if( strcmp(input_type, audio) == 0 ){
  6522.         free(input_type);
  6523.         return AUDIO;
  6524.         }
  6525.         if( strcmp(input_type, audioobject) == 0 ){
  6526.         free(input_type);
  6527.         return AUDIOOBJECT;
  6528.         }
  6529.         if( strcmp(input_type, slider) == 0 ){
  6530.         free(input_type);
  6531.         return SLIDER;
  6532.         }
  6533.         if( strcmp(input_type, copy) == 0 ){
  6534.         free(input_type);
  6535.         return COPY;
  6536.         }
  6537.         if( strcmp(input_type, copyresized) == 0 ){
  6538.         free(input_type);
  6539.         return COPYRESIZED;
  6540.         }
  6541.         if( strcmp(input_type, patternfill) == 0 ){
  6542.         free(input_type);
  6543.         return PATTERNFILL;
  6544.         }
  6545.         if( strcmp(input_type, hatchfill) == 0 ){
  6546.         free(input_type);
  6547.         return HATCHFILL;
  6548.         }
  6549.         if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
  6550.         free(input_type);
  6551.         return DIAMONDFILL;
  6552.         }
  6553.         if( strcmp(input_type, dotfill) == 0 ){
  6554.         free(input_type);
  6555.         return DOTFILL;
  6556.         }
  6557.         if( strcmp(input_type, gridfill) == 0 ){
  6558.         free(input_type);
  6559.         return GRIDFILL;
  6560.         }
  6561.         if( strcmp(input_type, imagefill) == 0 ){
  6562.         free(input_type);
  6563.         return IMAGEFILL;
  6564.         }
  6565.         if( strcmp(input_type, clicktile_colors) == 0 ){
  6566.         free(input_type);
  6567.         return CLICKTILE_COLORS;
  6568.         }
  6569.         if( strcmp(input_type, clicktile) == 0 ){
  6570.         free(input_type);
  6571.         return CLICKTILE;
  6572.         }
  6573.         if( strcmp(input_type, xlogscale) == 0 ){
  6574.         free(input_type);
  6575.         return XLOGSCALE;
  6576.         }
  6577.         if( strcmp(input_type, ylogscale) == 0 ){
  6578.         free(input_type);
  6579.         return YLOGSCALE;
  6580.         }
  6581.         if( strcmp(input_type, xylogscale) == 0 ){
  6582.         free(input_type);
  6583.         return XYLOGSCALE;
  6584.         }
  6585.         if( strcmp(input_type, ylogscale) == 0 ){
  6586.         free(input_type);
  6587.         return YLOGSCALE;
  6588.         }
  6589.         if( strcmp(input_type, xlogbase) == 0 ){
  6590.         free(input_type);
  6591.         return XLOGBASE;
  6592.         }
  6593.         if( strcmp(input_type, ylogbase) == 0 ){
  6594.         free(input_type);
  6595.         return YLOGBASE;
  6596.         }
  6597.         if( strcmp(input_type, intooltip) == 0 ){
  6598.         free(input_type);
  6599.         return INTOOLTIP;
  6600.         }
  6601.         if( strcmp(input_type,video) == 0 ){
  6602.         free(input_type);
  6603.         return VIDEO;
  6604.         }
  6605.         if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
  6606.         free(input_type);
  6607.         return FLOODFILL;
  6608.         }      
  6609.         if( strcmp(input_type,filltoborder) == 0 ){
  6610.         free(input_type);
  6611.         return FILLTOBORDER;
  6612.         }      
  6613.         if( strcmp(input_type,clickfill) == 0 ){
  6614.         free(input_type);
  6615.         return CLICKFILL;
  6616.         }      
  6617.         if( strcmp(input_type, replyformat) == 0 ){
  6618.         free(input_type);
  6619.         return REPLYFORMAT;
  6620.         }
  6621.         if( strcmp(input_type, pixelsize) == 0 ){
  6622.         free(input_type);
  6623.         return PIXELSIZE;
  6624.         }
  6625.         if( strcmp(input_type, setpixel) == 0 ){
  6626.         free(input_type);
  6627.         return SETPIXEL;
  6628.         }
  6629.         if( strcmp(input_type, pixels) == 0 ){
  6630.         free(input_type);
  6631.         return PIXELS;
  6632.         }
  6633.         if( strcmp(input_type, clickfillmarge) == 0 ){
  6634.         free(input_type);
  6635.         return CLICKFILLMARGE;
  6636.         }
  6637.         if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
  6638.         free(input_type);
  6639.         return X_AXIS_STRINGS;
  6640.         }
  6641.         if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
  6642.         free(input_type);
  6643.         return Y_AXIS_STRINGS;
  6644.         }
  6645.         if( strcmp(input_type, piechart) == 0  ){
  6646.         free(input_type);
  6647.         return PIECHART;
  6648.         }
  6649.         if( strcmp(input_type, barchart) == 0  ){
  6650.         free(input_type);
  6651.         return BARCHART;
  6652.         }
  6653.         if( strcmp(input_type, linegraph) == 0  ){
  6654.         free(input_type);
  6655.         return LINEGRAPH;
  6656.         }
  6657.         if( strcmp(input_type, clock) == 0  ){
  6658.         free(input_type);
  6659.         return CLOCK;
  6660.         }
  6661.         if( strcmp(input_type, legend) == 0  ){
  6662.         free(input_type);
  6663.         return LEGEND;
  6664.         }
  6665.         if( strcmp(input_type, legendcolors) == 0  ){
  6666.         free(input_type);
  6667.         return LEGENDCOLORS;
  6668.         }
  6669.         if( strcmp(input_type, xlabel) == 0  ){
  6670.         free(input_type);
  6671.         return XLABEL;
  6672.         }
  6673.         if( strcmp(input_type, ylabel) == 0  ){
  6674.         free(input_type);
  6675.         return YLABEL;
  6676.         }
  6677.         if( strcmp(input_type, animate) == 0  ){
  6678.         free(input_type);
  6679.         return ANIMATE;
  6680.         }
  6681.         /* these are bitmap related flydraw commmands...must be removed. eventually */
  6682.         if( strcmp(input_type, transparent) == 0 ){
  6683.         free(input_type);
  6684.         return TRANSPARENT;
  6685.         }
  6686.         if( strcmp(input_type, status) == 0 ){
  6687.         free(input_type);
  6688.         return STATUS;
  6689.         }
  6690.         if( strcmp(input_type, snaptogrid) == 0 ){
  6691.         free(input_type);
  6692.         return SNAPTOGRID;
  6693.         }
  6694.         if( strcmp(input_type, xsnaptogrid) == 0 ){
  6695.         free(input_type);
  6696.         return XSNAPTOGRID;
  6697.         }
  6698.         if( strcmp(input_type, ysnaptogrid) == 0 ){
  6699.         free(input_type);
  6700.         return YSNAPTOGRID;
  6701.         }
  6702.         if( strcmp(input_type, userinput_xy) == 0 ){
  6703.         free(input_type);
  6704.         return USERINPUT_XY;
  6705.         }
  6706.         if( strcmp(input_type, usertextarea_xy) == 0 ){
  6707.         free(input_type);
  6708.         return USERTEXTAREA_XY;
  6709.         }
  6710.         if( strcmp(input_type, sgraph) == 0 ){
  6711.         free(input_type);
  6712.         return SGRAPH;
  6713.         }
  6714.         free(input_type);
  6715.         ungetc(c,infile);
  6716.         return 0;
  6717. }
  6718.  
  6719.  
  6720.