Subversion Repositories wimsdev

Rev

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