Subversion Repositories wimsdev

Rev

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