Subversion Repositories wimsdev

Rev

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