Subversion Repositories wimsdev

Rev

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