Subversion Repositories wimsdev

Rev

Rev 12311 | Rev 13371 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*27/7/2013 version 0.01
  2. "Inspired" by FLY program: http://martin.gleeson.com/fly
  3. *********************************************************************************
  4. * J.M. Evers 7/2013                                                             *
  5. * This is all just amateur scriblings... So no copyrights.                      *
  6. * This source code file, and compiled objects derived from it,                  *
  7. * can be used and distributed without restriction, including for commercial use *
  8. * No warrenty whatsoever                                                        *
  9. *********************************************************************************
  10. */
  11. #include "canvasdraw.h"
  12.  
  13. /******************************************************************************
  14. **  Internal Functions
  15. ******************************************************************************/
  16. void    add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */
  17. void    sync_input(FILE *infile);/* proceed with inputfile */
  18. void    add_javascript_function(int js_function[], int canvas_root_id);
  19. void    reset();/* reset some global variables like "use_filled" , "use_dashed" */
  20. int     get_token(FILE *infile); /* read next char until EOL*/
  21. /*
  22. int     x2px(double x);
  23. int     y2px(double y);
  24. */
  25. double  px2x(int x);
  26. double  px2y(int y);
  27. double  get_real(FILE *infile,int last); /* read a value; calculation and symbols allowed */
  28. char    *str_replace ( const char *word, const char *sub_word, const char *rep_word );
  29. char    *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */
  30. char    *get_string(FILE *infile,int last); /* get the string at the end of a command */
  31. char    *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as  separator */
  32. char    *convert_hex2rgb(char *hexcolor);
  33. void    add_read_canvas(int canvas_root_id,int reply_format,int reply_precision);
  34. void    make_js_include(int canvas_root_id);
  35. void    check_string_length(int length);/* checks if the length of string argument of command is correct */
  36. FILE    *js_include_file;
  37. FILE    *get_file(int *line_number, char **filename);
  38. FILE    *infile;    /* will be stdin */
  39. /******************************************************************************
  40. ** global
  41. ******************************************************************************/
  42. int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */
  43. int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */
  44. /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */
  45. int xsize = 320;
  46. int ysize = 320;
  47. double xmin = 0.0;
  48. double xmax = 320.0;
  49. double ymin = 0.0;
  50. double ymax = 320.0;
  51. double tmax = 0;
  52. double tmin = 0;
  53. /* flag to indicate parsing of line status */
  54. int done = FALSE;
  55. int type; /* eg command number */
  56. int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/
  57. int slider = 0;/* slider=1 : x-values ; slider=2 : y-values;slider=3 angle values */
  58. int use_affine = FALSE;
  59. int use_rotate = FALSE;
  60. int use_filled = 0; /* 0:no fill , 1:fill,2=grid?,3=hatch?,4=diamond?,5=dot?,6=image? */
  61. int use_dashed = FALSE; /* dashing not natively supported in firefox  , for now... */
  62.  
  63. char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */
  64. char *getfile_cmd = "";
  65. /******************************************************************************
  66. ** Main Program
  67. ******************************************************************************/
  68. int main(int argc, char *argv[]){
  69.     /* need unique id for every call to canvasdraw : rand(); is too slow...will result in many identical id's */
  70.     struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);
  71.     unsigned int canvas_root_id = (unsigned int) tv.tv_usec;
  72.     infile = stdin;/* read flyscript via stdin */
  73.     int i,c;
  74.     double double_data[MAX_INT+1];
  75.     int int_data[MAX_INT+1];
  76.     for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;}
  77.     int use_parametric = FALSE;/* will be reset after parametric plotting */
  78.     int use_offset = FALSE;/* use_offset only for text shape objects... 0=none;1=yoffset;2=xoffset;3=xyoffset;4=centered*/
  79.     int use_axis = FALSE;
  80.     int use_axis_numbering = -1;
  81.     int use_pan_and_zoom = FALSE;
  82.     int use_safe_eval = FALSE; /* if true, add just once : js function to evaluate userinput values for plotting etc */
  83.     int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */
  84.     int use_js_plot = FALSE; /* if true , let js-engine plot the curve */
  85.     int jsplot_cnt = 0; /* keepint track on the curve identity */
  86.     int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */
  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.May be redefined before every object */
  90.     int use_userdraw = FALSE; /* flag to indicate user interaction */
  91.     int drag_type = -1;/* 0,1,2 : xy,x,y */
  92.     int use_tooltip = -1; /* 1= tooltip 2= popup window*/
  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 = "font-family:Ariel;text-align:center;color:blue;font-size:12px;background-color:orange;";
  103.     char *flytext = "";
  104.     char *affine_matrix = "[1,0,0,1,0,0]";
  105.     char *function_label = "f(x)=";
  106.     int use_pattern = 0; /* used in drag&drop library : grid=2,hatch=3,diamond=4,dot=5*/
  107.     int canvas_type = DRAG_CANVAS; /* to use a specific canvas  for filling etc */
  108.     int pixelsize = 1;
  109.     int reply_format = 0;
  110.     int input_cnt = 0;
  111.     int ext_img_cnt = 0;
  112.     int slider_cnt = 0;
  113.     int fill_cnt = 0;
  114.     int font_size = 12;/* this may lead to problems when using something like "fontfamily Italic 24px Ariel" the "font_size" value is not substituted into fontfamily !! */
  115.     int fly_font_size = 12; /*fly_font_size is relative to this... */
  116.     int dashtype[2] = { 4 , 4 }; /* just line_px and space_px : may have more arguments...if needed in future */
  117.     int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */
  118.     for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
  119.     int arrow_head = 8; /* size in px needed for arrow based  userdraw:  "userdraw arrow,color" */
  120.     int crosshair_size = 5; /* size in px*/
  121.     int plot_steps = 250;/* the js-arrays with x_data_points and y_data_points will have size 250 each: use with care !!! use jscurve when precise plots are required  */
  122.     int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange :just to flag an error message */
  123.     int click_cnt = 0; /*counter to identify the "onclick" ojects ; 0 is first object set onclick: reply[click_cnt]=1 when clicked ; otherwise reply[click_cnt]=0 ; click_cnt is only increased when another object is set  again */
  124.     int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
  125.     int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
  126.     int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/
  127.     int boxplot_cnt = 0;
  128.     int numberline_cnt = 0;
  129.     int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc  */
  130.     int reply_precision = 100; /* used for precision of student answers / drawings */
  131.     double angle = 0.0;
  132.     char *rotation_center = "null";
  133.     int clickfillmarge = 20; /* in pixels : if the 'remove click' is within this marge, the filling is removed */
  134.     int use_animate = 0; /* used for jscurve / js parametric  */
  135.     int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/
  136.     int use_slider_display = 0; /* in case of a slider, should we display its value ?*/
  137.     size_t string_length = 0; /* measure the size of the user input fly-string */
  138.     double stroke_opacity = 0.8; /* use some opacity as default */
  139.     double fill_opacity = 0.8;/* use some opacity as default */
  140.     char *URL = "http://localhost/images";
  141.     char *slider_function_x = "x";
  142.     char *slider_function_y = "y";
  143.     memset(buffer,'\0',MAX_BUFFER);
  144.     void *tmp_buffer = "";
  145.     /* default writing a unzipped js-include file into wims getfile directory */
  146.     char *w_wims_session = getenv("w_wims_session");
  147.     if(  w_wims_session == NULL || *w_wims_session == 0 ){canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");}
  148.     int L0=strlen(w_wims_session) + 21;
  149.     char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
  150.     snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
  151.     mode_t process_mask = umask(0); /* check if file exists */
  152.     int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
  153.     if( result == 0 || errno == EEXIST ){
  154.      umask(process_mask); /* be sure to set correct permission */
  155.      char *w_session = getenv("w_session");
  156.      int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
  157.      getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
  158.      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 */
  159.     /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
  160.     /* now write file into getfile dir*/
  161.     char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */
  162.     int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
  163.     char *location = my_newmem(L2); /* create memory to fit string precisely */
  164.     snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
  165.     js_include_file = fopen(location,"w");/* open the file location for writing */
  166.     /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */
  167.     if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );}
  168.  
  169. /* ----------------------------------------------------- */
  170.  
  171. /* while more lines to process */
  172.  
  173.     while(!finished){
  174.         if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
  175.         type = get_token(infile);
  176.         done = FALSE;
  177.         /*
  178.         @ canvasdraw
  179.         @ 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...)
  180.         @ general syntax <ul><li>The transparency of all objects can be controlled by command <a href="#opacity">'opacity [0-255],[0,255]'</a></il><li>line width of any object can be controlled by command <a href="#linewidth">'linewidth int'</a></li><li>any may be dashed by using keyword <a href="#dashed">'dashed'</a> before the object command.<br />the dashing type can be controled by command <a href="#dashtype">'dashtype int,int'</a></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 <a href="#filled">'filled'</a> before the object command.<br />The fill colour of 'non_userdraw' objects will be the stroke colour...(flydraw harmonization 19/10/2013)<br />non-solid filling (grid,hatch,diamond,dot,text) is provided using command <a href="#fillpattern">fillpattern a_pattern</a><br />for <a href="#filltoborder">filltoborder x0,y0,color</a> or <a href="#filltoborder">fill x0,y0,color</a> type filling (eg fill a region around x0,y0 with color until a border is encountered),<br />there are non-solid pattern fill analogues:<ul><li><a href="#gridfill">gridfill x,y,dx,dy,color</a></li><li><a href="#hatchfill">hatchfill x,y,dx,dy,color</a></li><li><a href="#diamondfill">diamondfill x,y,dx,dy,color</a></li><li><a href="#dotfill">dotfill x,y,dx,dy,color</a></li><li><a href="#textfill">textfill x,y,color,sometext_or_char</a></li></ul></li><li>all draggable objects may have a <a href="#slider">slider</a> 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 <a href="#drag">'drag x/y/xy'</a><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 <a href="#zoom">zoom</a> and will be translated in case of panning</li><li> a 'onclick object' can be set 'clickable' by the preceding keyword <a href="#onclick">'onclick'</a><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 (instead 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><li>almost every <a href="#userdraw">"userdraw object,color"</a>  or <a href="#multidraw">"multidraw"</a> command 'family' may be combined with keywords <a href="#snaptogrid">"snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command "snaptopoints x1,y1,x2,y2,..."  </li><li>every draggable | onclick object may be combined with keywords <a href="#snaptogrid">snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command "snaptopoints x1,y1,x2,y2,..."  </li><li>almost every command for a single object has a multiple objects counterpart:<br /><ul>general syntaxrule:<li><em>single_object</em> x1,y1,...,color</li><li><em>multi_object</em> color,x1,y1,...</li></ul><li>All inputfields or textareas generated, can be styled individually using command <a href="#inputstyle">'inputstyle some_css'</a><br/>the fontsize used for labeling these elements can be controlled by command <a href="fontsize">'fontsize int'</a> <br />command 'fontfamily' is <b>not</b> active for these elements </li></ul>
  181.         @ If needed multiple interactive scripts may be used in a single webpage.<br />A function 'read_canvas()' and / or 'read_dragdrop()' can read all interactive userdata from these images.<br />The global array 'canvas_scripts' will contain all unique random "canvas_root_id" of the included scripts.<br />The included local javascript "read" functions "read_canvas%d()" and "read_dragdrop%d()" will have this "%d = canvas_root_id"<br />e.g. canvas_scripts[0] will be the random id of the first script in the page and will thus provide a function<br />fun = eval("read_canvas"+canvas_scripts[0]) to read user based drawings / inputfield in this first image.<br />The read_dragdrop is analogue.<br />If the default reply formatting is not suitable, use command <a href='#replyformat'>'replyformat'</a> to format the replies for an individual canvas script,<br />To read all user interactions from all included canvas scripts , use something like:<br /><em>function read_all_canvas_images(){<br />&nbsp;var script_len = canvas_scripts.length;<br />&nbsp;var draw_reply = "";<br />&nbsp;var found_result = false;<br />&nbsp;for(var p = 0 ; p < script_len ; p++){<br />&nbsp;&nbsp;var fun = eval("read_canvas"+canvas_scripts[p]);<br />&nbsp;&nbsp;if( typeof fun === 'function'){<br />&nbsp;&nbsp;&nbsp;var result = fun();<br />&nbsp;&nbsp;&nbsp;if( result&nbsp;&nbsp;&& result.length != 0){<br />&nbsp;&nbsp;&nbsp;&nbsp;if(script_len == 1 ){ return result;};<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;found_result = true;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;draw_reply = draw_reply + result + "\\n";<br />&nbsp;&nbsp;&nbsp;&nbsp;};<br />&nbsp;&nbsp;&nbsp;};<br />&nbsp;&nbsp;};<br />&nbsp;if( found_result ){return draw_reply;}else{return null;};<br />};</em>
  182.         @ you can check the javascript reply format in the wims tool <a href="http://localhost/wims/wims.cgi?lang=en&module=tool/directexec">direct exec</a>
  183.         @ for usage within OEF (without anstype "draw"), something like this (a popup function plotter) will work:<br /><small>\\text{popup_grapher=wims(exec canvasdraw <br />popup<br />size 400,400<br />xrange -10,10<br />yrange -10,10<br />axis<br />axisnumbering<br />opacity 100,100<br />grid 2,2,grey,2,2,6,black<br />snaptogrid<br />linewidth 2<br />jsplot red,5*sin(1/x)<br />strokecolor green<br />functionlabel f(x)=<br />userinput function<br />mouse blue,22<br />)<br />}<br />\\statement{<br />\\popup_grapher<br />}</small>
  184.         @ be aware that older browsers will probably not work correctly<br />no effort has been undertaken to add glue code for older browsers !! <br />in any case it's not wise to use older browsers...not just for canvasdraw
  185.         @ if you find flaws, errors or other incompatibilities -not those mentioned in this document- send <a href='mailto:jm.evers-at-schaersvoorde.nl'>me</a> an email with screenshots and the generated javascript include file.
  186.         @ there is limited support for touch devices : touchstart,touchmove and touchend in commands <a href="#userdraw">userdraw primitives </a>, <a href="#protractor">protractor</a> and <a href="#ruler">ruler</a><br />only single finger gestures are supported (for now)<br />for more accurate user-interaction with canvasdraw on touch devices: use the command family <a href="userinput_xy">userinput</a>
  187.         */
  188.         switch(type){
  189.         case END:
  190.         finished = 1;
  191.         done = TRUE;
  192.         break;
  193.         case 0:
  194.             sync_input(infile);
  195.             break;
  196.  
  197.         case CENTERED:
  198.          use_offset = 4;
  199.          /*
  200.          @ centered
  201.          @ keyword ; to place the text centered (in width and height) on the text coordinates(x:y)
  202.          @ may be used for text exactly centered on it's (x;y)
  203.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  204.          @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-library)
  205.          @%centered%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red
  206.         */
  207.         break;
  208.  
  209.         case COMMENT:
  210.             sync_input(infile);
  211.             break;
  212.         case AFFINE:
  213.         /*
  214.          @ affine a,b,c,d,tx,ty
  215.          @ defines a transformation matrix for subsequent objects
  216.          @ images drawn by setting skew params a &amp; d will be very different from Flydraw's "affine a,b,c,d,e,tx,ty" !!
  217.          @ use keyword 'killaffine' to end the transformation
  218.          @ note 1: only 'draggable' / 'noclick' objects can be transformed.
  219.          @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet)
  220.          @ note 3: no matrix operations on the transformation matrix implemented (yet)
  221.          @ a : Scales the drawings horizontally
  222.          @ b : Skews the drawings horizontally
  223.          @ c : Skews the drawings vertically
  224.          @ d : Scales the drawings vertically
  225.          @ tx: Moves the drawings horizontally in xrange coordinate system
  226.          @ ty: Moves the drawings vertically in yrange coordinate system
  227.          @ the data precision may be set by preceding command "precision int"
  228.          @%affine%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%fcircle 5,5,40,blue%affine 1,0,0,1,-10,-10%fcircle 5,5,40,green
  229.         */
  230.             for(i = 0 ; i<6;i++){
  231.                 switch(i){
  232.                     case 0: double_data[0] = get_real(infile,0);break;
  233.                     case 1: double_data[1] = get_real(infile,0);break;
  234.                     case 2: double_data[2] = get_real(infile,0);break;
  235.                     case 3: double_data[3] = get_real(infile,0);break;
  236.                     case 4: double_data[4] = get_real(infile,0);break;
  237.                     case 5: double_data[5] = get_real(infile,1);
  238.                         use_affine = TRUE;
  239.                         decimals = find_number_of_digits(precision);
  240.                         string_length = snprintf(NULL,0,     "[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f] ",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4]*xsize/(xmax - xmin),decimals,-1*double_data[5]*ysize/(ymax - ymin));
  241.                         check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
  242.                         snprintf(affine_matrix,string_length,"[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f] ",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4]*xsize/(xmax - xmin),decimals,-1*double_data[5]*ysize/(ymax - ymin));
  243.                         break;
  244.                     default: break;
  245.                 }
  246.             }
  247.         break;
  248.  
  249.         case ANGLE:
  250.         /*
  251.          @ angle xc,yc,width,start_angle,end_angle,color
  252.          @ width is in x-range
  253.          @ will zoom in/out
  254.          @ if size is controlled by command <a href='#slider'>'slider'</a> use radians to set limits of slider.
  255.          @%angle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%angle 0,0,4,10,135,blue
  256.         */
  257.             for(i=0;i<7;i++){
  258.                 switch(i){
  259.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  260.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  261.                     case 2:double_data[2] = get_real(infile,0);break; /* width in pixels ! */
  262.                     case 3:double_data[3] = get_real(infile,0);break; /* start angle in degrees */
  263.                     case 4:double_data[4] = get_real(infile,0);break; /* end angle in degrees */
  264.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  265.                         decimals = find_number_of_digits(precision);
  266.                         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,%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,rotation_center,use_offset,use_pattern);
  267.                         reset();
  268.                     break;
  269.                 }
  270.             }
  271.             break;
  272.  
  273.         case ANIMATE:
  274.         /*
  275.          @ animate
  276.          @ keyword
  277.          @ the animated point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber'
  278.          @ use linewidth to adjust size of the points
  279.          @ will animate a point on the next jsplot/jscurve command
  280.          @ only usable for command jsplot (normal functions or parametric)
  281.          @ moves repeatedly from xmin to xmax or incase of a parametric function from tmin to tmax (set trange)
  282.          @%animate%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%linewidth 4%fillcolor red%animate%trange -2*pi,2*pi%linewidth 1%opacity 255,50%canvastype 100%fill 1.2,1.2,red%canvastype 101%fill -1.2,-1.2,blue%jsplot blue,7*cos(x),5*sin(2*x)
  283.         */
  284.             use_animate = 1;
  285.             fprintf(js_include_file,"\nvar trace_canvas  = create_canvas%d(%d,xsize,ysize);var trace_ctx = trace_canvas.getContext('2d');trace_ctx.fillStyle = 'rgba(%s,%f)';trace_ctx.strokeStyle = 'rgba(%s,%f)';trace_ctx.lineWidth = %d;var anim_pos = 0;function animate_this(){trace_ctx.clearRect(0,0,xsize,ysize);trace_ctx.fillRect(x_anim_points[anim_pos]-%d, y_anim_points[anim_pos]-%d,%d,%d);setTimeout(function(){requestAnimationFrame(animate_this);anim_pos++}, 50);if(anim_pos > animation_steps){anim_pos = 0;};};",canvas_root_id,ANIMATE_CANVAS,fill_color,fill_opacity,stroke_color,stroke_opacity,line_width,line_width,line_width,2*line_width,2*line_width);
  286.             break;
  287.  
  288.         case ARC:
  289.         /*
  290.          @ arc xc,yc,x-width,y-height,start_angle,end_angle,color
  291.          @ can <b>not</b> be set "onclick" or "drag xy"
  292.          @ <b>attention</b>: width in height in x/y-range
  293.          @%arc%size 400,400%xrange -10,10%yrange -10,10%arc 0,0,4,4,10,135,red%zoom blue
  294.         */
  295.             for(i=0;i<7;i++){
  296.                 switch(i){
  297.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  298.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  299.                     case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */
  300.                     case 3:double_data[3] = get_real(infile,0);break; /* height y-range no pixels ! */
  301.                     case 4:double_data[4] = get_real(infile,0);break; /* start angle in degrees */
  302.                     case 5:double_data[5] = get_real(infile,0);break; /* end angle in degrees */
  303.                     case 6:stroke_color = get_color(infile,1);/* name or hex color */
  304.                     /* in Shape library:
  305.                         x[0] = x[1] = xc = double_data[0]
  306.                         y[0] = y[1] = yc = double_data[1]
  307.                         w[0] = width = double_data[2]
  308.                         w[1] = height = double_data[3]
  309.                         h[0] = start_angle = double_data[4]
  310.                         h[1] = end_angle = double_data[5]
  311.                     */
  312.                         decimals = find_number_of_digits(precision);
  313.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,12,[%.*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,%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[3],decimals,double_data[4],decimals,double_data[5],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,rotation_center,use_offset,use_pattern);
  314.                         reset();
  315.                     break;
  316.                 }
  317.             }
  318.             break;
  319.         case ARROW:
  320.         /*
  321.         @ arrow x1,y1,x2,y2,h,color
  322.         @ alternative : vector
  323.         @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color'
  324.         @ use command 'linewidth int' to adjust thickness of the arrow
  325.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  326.         @%arrow%size 400,400%xrange -10,10%yrange -10,10%drag xy%arrow 0,0,4,3,8,blue%
  327.         */
  328.             for(i=0;i<6;i++){
  329.                 switch(i){
  330.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  331.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  332.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  333.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  334.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  335.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  336.                         decimals = find_number_of_digits(precision);
  337.                         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,%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,rotation_center,use_offset,use_pattern);
  338.                         if(onclick > 0){click_cnt++;}
  339.                         /* click_cnt++;*/
  340.                         reset();
  341.                         break;
  342.                 }
  343.             }
  344.             break;
  345.  
  346.         case ARROWS:
  347.         /*
  348.         @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n
  349.         @ alternative : vectors
  350.         @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
  351.         @ use command 'linewidth int' to adjust thickness of the arrow
  352.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  353.         @%arrows%size 400,400%xrange -10,10%yrange -10,10%onclick%arrows red,8,0,0,4,3,0,0,2,4,0,0,-2,4,0,0,-3,-4,0,0,3,-2%
  354.         */
  355.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  356.             fill_color = stroke_color;
  357.             arrow_head = (int) get_real(infile,0);/* h */
  358.             i=0;
  359.             while( ! done ){     /* get next item until EOL*/
  360.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  361.                 if(i%2 == 0 ){
  362.                     double_data[i] = get_real(infile,0); /* x */
  363.                 }
  364.                 else
  365.                 {
  366.                     double_data[i] = get_real(infile,1); /* y */
  367.                 }
  368.                 i++;
  369.             }
  370.             decimals = find_number_of_digits(precision);
  371.             for(c = 0 ; c < i-1 ; c = c+4){
  372.                 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,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+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,rotation_center,use_offset,use_pattern);
  373.                 if(onclick > 0){click_cnt++;}
  374.                 /* click_cnt++; */
  375.             }
  376.             reset();
  377.             break;
  378.  
  379.         case ARROW2:
  380.         /*
  381.         @ arrow2 x1,y1,x2,y2,h,color
  382.         @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and  in color 'color'
  383.         @ use command 'arrowhead int' to adjust the arrow head size
  384.         @ use command 'linewidth int' to adjust thickness of the arrow
  385.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  386.         @%arrow2%size 400,400%xrange -10,10%yrange -10,10%drag xy%arrow2 0,0,4,3,8,blue%
  387.         */
  388.             for(i=0;i<6;i++){
  389.                 switch(i){
  390.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  391.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  392.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  393.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  394.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  395.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  396.                         decimals = find_number_of_digits(precision);
  397.                         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,%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,rotation_center,use_offset,use_pattern);
  398.                         if(onclick > 0){click_cnt++;}
  399.                         /* click_cnt++;*/
  400.                         reset();
  401.                         break;
  402.                 }
  403.             }
  404.             break;
  405.  
  406.         case ARROWS2:
  407.         /*
  408.         @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n
  409.         @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
  410.         @ use command 'linewidth int' to adjust thickness of the arrows
  411.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  412.         @%arrows2%size 400,400%xrange -10,10%yrange -10,10%onclick%arrows2 red,8,0,0,4,3,1,1,2,4,2,2,-2,4,3,3,-3,-4,0,0,3,-2%
  413.         */
  414.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  415.             fill_color = stroke_color;
  416.             arrow_head = (int) get_real(infile,0);/* h */
  417.             i=0;
  418.             while( ! done ){     /* get next item until EOL*/
  419.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  420.                 if(i%2 == 0 ){
  421.                     double_data[i] = get_real(infile,0); /* x */
  422.                 }
  423.                 else
  424.                 {
  425.                     double_data[i] = get_real(infile,1); /* y */
  426.                 }
  427.                 i++;
  428.             }
  429.             decimals = find_number_of_digits(precision);
  430.             for(c = 0 ; c < i-1 ; c = c+4){
  431.                 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,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+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,rotation_center,use_offset,use_pattern);
  432.                 if(onclick > 0){click_cnt++;}
  433.                 /* click_cnt++; */
  434.  
  435.             }
  436.             reset();
  437.             break;
  438.         case ARROWHEAD:
  439.         /*
  440.         @ arrowhead int
  441.         @ default 8 (pixels)
  442.         */
  443.             arrow_head = (int) (get_real(infile,1));
  444.             break;
  445.  
  446.         case AUDIO:
  447.         /*
  448.         @ audio x,y,w,h,loop,visible,audiofile location
  449.         @ x,y : left top corner of audio element (in xrange / yrange)
  450.         @ w,y : width and height in pixels
  451.         @ loop : 0 or 1 ( 1 = loop audio fragment)
  452.         @ visible : 0 or 1 (1 = show controls)
  453.         @ audio format may be in *.mp3 or *.ogg
  454.         @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format)
  455.         @ if you are using *.ogg : be aware that Microsoft based systems not support it natively
  456.         @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
  457.         */
  458.             if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
  459.             for(i=0;i<7;i++){
  460.                 switch(i){
  461.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  462.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  463.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  464.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  465.                     case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
  466.                     case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
  467.                     case 6:
  468.                     temp = get_string(infile,1);
  469.                     if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
  470.                     if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
  471.                     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);
  472.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  473.                     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);
  474.                     add_to_buffer(tmp_buffer);
  475.                     break;
  476.                     default:break;
  477.                 }
  478.             }
  479.             reset();
  480.             break;
  481.  
  482.  
  483.         case AXIS_NUMBERING:
  484.         /*
  485.             @ axisnumbering
  486.             @ keyword (no arguments required)
  487.             @ for special numbering of x-axis or y-axis see grid related commands <a href="#axis">axis</a>  <a href="#xaxis">xaxis</a> , <a href="#xaxisup">xaxisup</a>, <a href="#noxaxis">noxaxis</a> ,<a href="#yaxis">yaxis</a> , <a href="#yaxisup">yaxisup</a>, <a href="#noyaxis">noyaxis</a>
  488.             @ to be used before command grid (see <a href="#grid">command grid</a>)
  489.         */
  490.             use_axis_numbering++;
  491.             break;
  492.         case AXIS:
  493.         /*
  494.             @ axis
  495.             @ keyword (no arguments required)
  496.             @ to be used before command grid (see <a href="#grid">command grid</a>)
  497.  
  498.         */
  499.             use_axis = TRUE;
  500.             break;
  501.  
  502.         case BARCHART:
  503.         /*
  504.         @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
  505.         @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a>
  506.         @ can be used together with freestyle x-axis/y-axis texts : see commands <a href='#xaxis'>'xaxis'</a>,<a href='#xaxisup'>'xaxisup'</a> and <a href='#yaxis'>'yaxis'</a>
  507.         @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner
  508.         @ multiple barchart command may be used in a single script
  509.         @ also see command <a href='#piechart'>'piechart'</a>
  510.         @ note: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
  511.         @%barchart%size 400,400%xrange -1,10%yrange -2,14%legend legend Z:legend A:this is B:C:D:E:F:G:H:X%legendcolors green:red:orange:lightblue:cyan:gold:purple:darkred:yellow:lightgreen%xaxis 0:Z:1:A:2:B:3:C:4:D:5:E:6:F:7:G:8:H:9:X%noyaxis%precision 1%fontfamily bold 15px Ariel%grid 1,1,white%barchart 0:5.5:green:2:5.5:red:4:6.5:orange:6:8:lightblue:8:11:cyan:1:5.5:gold:3:9:purple:5:4:darkred:7:7:yellow:9:1:lightgreen%mouse red,14
  512.         */
  513.             temp = get_string(infile,1);
  514.             if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
  515.             fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
  516.             barchart_cnt++;
  517.             reset();
  518.             break;
  519.  
  520.         case BEZIER:
  521.         /*
  522.         @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end
  523.         @ draw a bezier curve between points, starting from (x_start:y_start)
  524.         @ can <b>not</b> be dragged or set onclick
  525.         */
  526.             if( js_function[DRAW_BEZIER] != 1 ){ js_function[DRAW_BEZIER] = 1;}
  527.             decimals = find_number_of_digits(precision);
  528.             for(i = 0 ; i < 9; i++){
  529.                 switch(i){
  530.                     case 0: stroke_color = get_color(infile,0);break;
  531.                     case 1: double_data[0] = get_real(infile,0);break;/* start x */
  532.                     case 2: double_data[1] = get_real(infile,0);break;/* start y */
  533.                     case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */
  534.                     case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */
  535.                     case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */
  536.                     case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */
  537.                     case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */
  538.                     case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */
  539.                         string_length = snprintf(NULL,0,"draw_bezier(%d,%d,[%f,%f,%f,%f,%f,%f,%f,%f],\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],double_data[6],double_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,use_affine,affine_matrix);
  540.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  541.                         snprintf(tmp_buffer,string_length,"draw_bezier(%d,%d,[%f,%f,%f,%f,%f,%f,%f,%f],\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],double_data[6],double_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,use_affine,affine_matrix);
  542.                         add_to_buffer(tmp_buffer);
  543.                         break;
  544.                     default: break;
  545.                 }
  546.             }
  547.             reset();
  548.             break;
  549.  
  550.  
  551.         case BGCOLOR:
  552.         /*
  553.          @ bgcolor colorname or #hex
  554.          @ use this color as background of the "div" containing the canvas(es)
  555.          @%bgcolor%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue
  556.         */
  557.         /* [255,255,255]*/
  558.             bgcolor = get_string(infile,1);
  559.             if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
  560.                 int found = 0;
  561.                 for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  562.                     if( strcmp( colors[i].name , bgcolor ) == 0 ){
  563.                         bgcolor = colors[i].hex;
  564.                         found = 1;
  565.                         break;
  566.                     }
  567.                 }
  568.                 if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");}
  569.             }
  570.             fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
  571.             break;
  572.  
  573.         case BGIMAGE:
  574.         /*
  575.          @ bgimage image_location
  576.          @ use an image as background .<br />technical: we use the background of 'canvas_div'
  577.          @ the background image will be resized to match "width = xsize" and "height = ysize"
  578.          @%bgimage%size 400,400%xrange -10,10%yrange -10,10%bgimage https://wims.unice.fr/wims/gifs/en.gif
  579.         */
  580.         URL = get_string(infile,1);
  581.         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);
  582.             break;
  583.  
  584.         case BLINK:
  585.         /*
  586.          @ blink time(seconds)
  587.          @ NOT IMPLEMETED -YET
  588.         */
  589.             break;
  590.  
  591.         case BOXPLOT:
  592.         /*
  593.         @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max
  594.         @ example :<br />xrange 0,300<br />yrange 0,10<br />boxplot x,4,8,120,160,170,220,245<br />meaning: create a boxplot in x-direction, with height 4 (in yrange) and centered around line y=8
  595.         @ example :<br />xrange 0,10<br />yrange 0,300<br />boxplot y,4,8,120,160,170,220,245<br />meaning: create a boxplot in y-direction, with width 4 (in xrange) and centered around line x=8
  596.         @ use command <a href='#filled'>'filled'</a> to fill the box<br /><b>note:</b> the strokecolor is used for filling Q1, the fillcolor is used for filling Q3
  597.         @ use command <a href='#fillpattern'>'fillpattern some_pattern'</a> to use a (diamond for Q1, hatch for Q3) pattern.
  598.         @ use command <a href='#opacity'>'opacity'</a> to adjust fill_opacity of stroke and fill colours
  599.         @ use command <a href='#legend'>'legend'</a> to automatically create a legend <br />unicode allowed in legend<br />use command 'fontfamily' to set the font of the legend.
  600.         @ there is no limit to the number of boxplots used.
  601.         @ can <b>not</b> be set draggable (<a href='#onclick'>'onclick'</a> is not ready ,yet)
  602.         @ use keyword <a href="#userboxplot">'userboxplot'</a> before command boxplot, if a pupil must draw a boxplot (using his own min,Q1,median,Q3,max data)
  603.         @ use keyword <a href="#userboxplotdata">'userboxplotdata'</a> before command boxplot, if a pupil must generate the data by some means.
  604.         @ use command <a href="#boxplotdata">'boxplotdata'</a> when the boxplot should be drawn from wims-generated raw statistical date
  605.         @%boxplot_1%size 400,400%xrange 0,300%yrange 0,10%opacity 120,50%filled%fillcolor orange%strokecolor blue%linewidth 2%boxplot x,4,8,120,160,170,220,245
  606.         @%boxplot_2%size 400,400%xrange 0,10%yrange 0,300%opacity 120,50%filled%fillcolor orange%strokecolor blue%linewidth 2%boxplot y,4,8,120,160,170,220,245
  607.         */
  608.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  609.             for(i=0;i<8;i++){
  610.                 switch(i){
  611.                     case 0: temp = get_string_argument(infile,0);
  612.                             if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */
  613.                     case 1: double_data[0] = get_real(infile,0);break;/* height | width  */
  614.                     case 2:
  615.                     if( js_function[DRAW_JSBOXPLOT] == 0 ){
  616.                      double_data[1] = get_real(infile,0);
  617.                      fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */
  618.                     }
  619.                     else
  620.                     {
  621.                      double_data[1] = get_real(infile,1);
  622.                      double_data[2] = 1;
  623.                      double_data[3] = 1;
  624.                      double_data[4] = 1;
  625.                      double_data[5] = 1;
  626.                      double_data[6] = 1;
  627.                      double_data[7] = 1;
  628.                      i=8;
  629.                     }
  630.                     break;/* center value x or y */
  631.                     case 3: double_data[2] = get_real(infile,0); break;/* min */
  632.                     case 4: double_data[3] = get_real(infile,0); break;/* Q1 */
  633.                     case 5: double_data[4] = get_real(infile,0); break;/* median */
  634.                     case 6: double_data[5] = get_real(infile,0); break;/* Q3 */
  635.                     case 7: double_data[6] = get_real(infile,1); break;/* max */
  636.                     default:break;
  637.                 }
  638.             }
  639.             decimals = find_number_of_digits(precision);
  640.             /*function draw_boxplot(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1)*/
  641.             string_length = snprintf(NULL,0,  "draw_boxplot(%d,%d,%.*f,%.*f,[%.*f,%.*f,%.*f,%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d);\n",BOXPLOT_CANVAS+boxplot_cnt,int_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],decimals,double_data[6],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1]);
  642.             check_string_length(string_length);
  643.             tmp_buffer = my_newmem(string_length+1);
  644.             snprintf(tmp_buffer,string_length,  "draw_boxplot(%d,%d,%.*f,%.*f,[%.*f,%.*f,%.*f,%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d);\n",BOXPLOT_CANVAS+boxplot_cnt,int_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],decimals,double_data[6],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1]);
  645.             add_to_buffer(tmp_buffer);
  646.             boxplot_cnt++;
  647.             reset();
  648.         break;
  649.         case BOXPLOTDATA:
  650.         /*
  651.         @ boxplotdata some_data
  652.         @ 'some_data' are a list of numbers separated by a comma "," (items)
  653.         @ only be used before command 'boxplot': the command <a href="#boxplot">'boxplot'</a> will provide the boxplot drawing of the data.
  654.         @ xrange 0,100<br />yrange 0,10<br />boxplotdata 11,22,13,15,23,43,12,12,14,2,45,32,44,13,21,24,13,19,35,21,24,23<br />boxplot x,4,5
  655.         @ note: wims will not check your data input | format. use js-error console to debug any problems.
  656.         @ a javascript function 'statistics()' will parse the data and calculate the values [min,Q1,median,Q3,max] and hand them to the boxplot draw function.
  657.         */
  658.             if( js_function[DRAW_JSBOXPLOT] != 1 ){ js_function[DRAW_JSBOXPLOT] = 1;}
  659.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  660.             fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1));
  661.  
  662.         break;
  663.  
  664.         case CANVASTYPE:
  665.          canvas_type = (int) (get_real(infile,1));
  666.         /*
  667.         @ canvastype TYPE
  668.         @ for now only usefull before commands  filltoborder / floodfill / clickfill etc operations<br />Only the images of this TYPE will be scanned and filled
  669.         @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas)
  670.         @ use another TYPE, if you know what you are doing...
  671.         @ other possible canvasses (transparent PNG pictures xsize x ysize on top of each other)<ul><li> EXTERNAL_IMAGE_CANVAS  0</li><li> BG_CANVAS    1</li><li> STATIC_CANVAS        2</li><li> MOUSE_CANVAS 3</li><li> GRID_CANVAS  4</li><li> DRAG_CANVAS  5</li><li> DRAW_CANVAS  6</li><li> TEXT_CANVAS  7</li><li> CLOCK_CANVAS 8</li><li> ANIMATE_CANVAS       9</li><li> TRACE_CANVAS 10</li><li>BOXPLOT_CANVAS 11</li><li> JSPLOT_CANVAS     100  , will increase with every call</li><li> FILL_CANVAS       200  , will increase with every call </li><li> USERDRAW_JSPLOT 300  , will increase with every call </li><li>CLICKFILL_CANVAS 400  , will increase with every call/click</li><li>BOXPLOT_CANVAS 500  , will increase with every call</li></ul>
  672.         */
  673.         break;
  674.  
  675.         case CENTERSTRING:
  676.         /*
  677.          @ centerstring color,y-value,the text string
  678.          @ title color,y-value,the text string
  679.          @ draw a string centered on the canvas at y = y-value
  680.          @ can not be set "onclick" or "drag xy" (...)
  681.          @ unicode supported: centerstring red,5,\\u2232
  682.          @ use a command like 'fontfamily italic 24pt Ariel' <br />to set fonts on browser that support font change
  683.          @%centerstring%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue%fontfamily italic 22pt Courier%centerstring blue,7,the center
  684.         */
  685.             if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;}
  686.             for(i=0;i<3;i++){
  687.                 switch(i){
  688.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  689.                     case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
  690.                     case 2: temp = get_string_argument(infile,1);
  691.                             /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
  692.                             decimals = find_number_of_digits(precision);
  693.                             string_length = snprintf(NULL,0,
  694.                             "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
  695.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  696.                             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);
  697.                             add_to_buffer(tmp_buffer);
  698.                             break;
  699.                     default:break;
  700.                 }
  701.             }
  702.             break;
  703.  
  704.  
  705.         case CIRCLE:
  706.         /*
  707.         @ circle xc,yc,width (2*r in pixels),color
  708.         @ use command 'fcircle xc,yc,d,color'
  709.         @ alternative: disk for a filled circle
  710.         @ use command 'fillcolor color' to set the fillcolor
  711.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  712.         @ will shrink / expand on zoom out / zoom in
  713.         @%circle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%drag xy%circle 0,0,60,red%zoom red
  714.         */
  715.             for(i=0;i<4;i++){
  716.                 switch(i){
  717.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  718.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  719.                     case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out : radius in 'dx' xrange*/
  720.                     case 3: stroke_color = get_color(infile,1);/* name or hex color */
  721.                         decimals = find_number_of_digits(precision);
  722.                         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,%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,rotation_center,use_offset,use_pattern);
  723.                         if(onclick > 0){click_cnt++;}
  724.                         /* click_cnt++;*/
  725.                         reset();
  726.                         break;
  727.                     default : break;
  728.                 }
  729.             }
  730.             break;
  731.  
  732.         case CIRCLES:
  733.         /*
  734.         @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n
  735.         @ <b>attention</b> r = radius in x-range (!)
  736.         @ use keyword 'filled' or command 'fcircles' to produce solid circles
  737.         @ alternative : disks for filled circles
  738.         @ use command 'fillcolor color' to set the fillcolor
  739.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (individually)
  740.         @ will shrink / expand on zoom out / zoom in
  741.         @%circles%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%drag xy%circles blue,0,0,2,2,2,3,-3,-3,3,3,3,4,3,-4,2%zoom red
  742.         */
  743.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  744.             fill_color = stroke_color;
  745.             i=1;
  746.             while( ! done ){     /* get next item until EOL*/
  747.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  748.                 switch (i%3){
  749.                  case 1:double_data[i-1] = get_real(infile,0);break; /* x */
  750.                  case 2:double_data[i-1] = get_real(infile,0);break; /* y */
  751.                  case 0:double_data[i-1] = get_real(infile,1);break; /* r */
  752.                 }
  753.                 i++;
  754.             }
  755.             decimals = find_number_of_digits(precision);
  756.             for(c = 0 ; c < i-1 ; c = c+3){
  757.                 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,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[c+2],double_data[c+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,rotation_center,use_offset,use_pattern);
  758.                 if(onclick > 0){click_cnt++;}
  759.                 /* click_cnt++; */
  760.             }
  761.             reset();
  762.             break;
  763.         case CLEARBUTTON:
  764.         /*
  765.          @ clearbutton value
  766.          @ alternative : delete
  767.          @ alternative : erase
  768.          @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text 'value'
  769.          @ <b>attention</b> command 'clearbutton' is incompatible with <a href="multidraw">multidraw</a> based drawings<br/>(in 'multidraw' there is always a remove_object_button for every drawprimitive)
  770.          @ normally <a href="#userdraw">userdraw</a> primitives have the option to use middle/right mouse button on<br /> a point of the object to remove this specific object...this clear button will remove all drawings
  771.          @ uses the tooltip placeholder div element: may not be used with command 'intooltip'
  772.          @ use command <a href="#inputstyle">'inputstyle'</a> to style the button...
  773.          @ the clearbutton will have id="canvas_scripts[%d]" ; starting with %d=0 for the first script<br />to change the style of all "clearbutton" of all included canvasdraw scripts, use something like<br /><em>if(document.getElementById("clearbutton"+canvas_scripts[0])){<br />&nbsp;var p = 0;<br />&nbsp;while(document.getElementById("clearbutton"+canvas_scripts[p])){<br />&nbsp;&nbsp;document.getElementById("clearbutton"+canvas_scripts[p]).className="some_class_name";<br />&nbsp;&nbsp;&lt;!&minus;&minus; or document.getElementById("clearbutton"+canvas_scripts[p]).setAttribute("style","some_style"); &minus;&minus;&gt;<br />&nbsp;&nbsp;p++;<br />&nbsp;};<br />};<br />
  774.          @%clearbutton%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%userdraw circles,red%clearbutton Remove All
  775.         */
  776.         if(reply_format == 29){/* eg multidraw is selected */
  777.          canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw");
  778.         }
  779.             add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1));
  780.         break;
  781.  
  782.         case CLOCK:
  783.         /*
  784.         @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
  785.         @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency
  786.         @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments
  787.         @ colors are optional: if not defined, default values will be used<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,green,blue,black,yellow
  788.         @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
  789.         @ 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><li>3: no prefab buttons...create your own buttons (or other means) to make the clock(s) adjustable by javascript function set_clock(num,type,diff)<br />wherein: num = clock id (starts with 0) ; type = 1 (hours) ; type = 2 (minutes) ; type = 3 (seconds) <br />and diff = the increment of 'type' (positive or negative) </li></ul>
  790.         @ canvasdraw will not check validity of colornames...the javascript console is your best friend
  791.         @ no combinations with other reply_types allowed, for now
  792.         @ if interactive is set to '1', 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
  793.         @ note: if you need multiple -interactive- clocks on a webpage, use multiple 'clock' commands in a single script !<br />and <i>not multiple canvas scripts</i> in a single page
  794.         @ note: clocks will not zoom or pan, when using command <a href='#zoom'>'zoom'</a>
  795.         @%clock_1%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,0,0,red,green,blue,lightgrey,black
  796.         @%clock_2%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,1,1,red,green,blue,lightgrey,black
  797.         @%clock_3%size 400,400%xrange -10,10%yrange -10,10%clock -5,0,80,4,35,45,2,2,red,green,blue,lightgrey,black%clock 5,0,80,3,15,65,2,2,red,green,blue,lightgrey,black
  798.         @%clock_4%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,0,0,red,green,blue,lightgrey,black
  799.         @%clock_5%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,1,1,red,green,blue,lightgrey,black
  800.         @%clock_6%size 400,400%xrange -10,10%yrange -10,10%clock -5,0,80,4,35,45,2,2,red,green,blue,lightgrey,black%clock 5,0,80,8,55,15,2,2,red,green,blue,lightgrey,black
  801.         @%clock_7%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,2,0,red,green,blue,lightgrey,black
  802.         */
  803.             if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
  804.  
  805.         /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
  806.             for(i=0;i<9;i++){
  807.              switch(i){
  808.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
  809.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
  810.               case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
  811.               case 3: int_data[3] = get_real(infile,0);break;/* hours */
  812.               case 4: int_data[4] = get_real(infile,0);break;/* minutes */
  813.               case 5: int_data[5] = get_real(infile,0);break;/* seconds */
  814.               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 */
  815.               case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/
  816.                 switch(int_data[7]){
  817.                     case 0:break;
  818.                     case 1:if(clock_cnt == 0){
  819.                            if( reply_format == 0 ){
  820.                             reply_format = 18; /* user sets clock */
  821.                             /* 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");
  822.                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  823.                                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");
  824.                                add_to_buffer(tmp_buffer);
  825.                            */
  826.                             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");
  827.                            }
  828.                            else
  829.                            {
  830.                             canvas_error("interactive clock may not be used together with other reply_types...");
  831.                            }
  832.                           }
  833.                           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);
  834.                     break;
  835.                     case 3:if(clock_cnt == 0){
  836.                             if( reply_format == 0 ){
  837.                              reply_format = 18; /* user sets clock */
  838.                              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,1,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n");
  839.                             }
  840.                             else
  841.                             {
  842.                              canvas_error("interactive clock may not be used together with other reply_types...");
  843.                             }
  844.                            }
  845.                             /*
  846.                             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);
  847.                            */
  848.                     break;
  849.                     case 2:if( reply_format == 0 ){
  850.                                 reply_format = 19; /* "onclick */
  851.                                 fprintf(js_include_file,"\n<!-- begin onclick handler for clocks -->\nvar reply = new Array();canvas_div.addEventListener( 'mousedown', user_click,false);\n\nfunction user_click(evt){if(evt.which == 1){var canvas_rect = clock_canvas.getBoundingClientRect();var x = evt.clientX - canvas_rect.left;var y = evt.clientY - canvas_rect.top;var p = 0;var name;var t = true;while(t){try{name = eval('clocks'+p);if( x < name.xc + name.radius && x > name.xc - name.radius ){if( y < name.yc + name.radius && y > name.yc - name.radius ){reply[0] = p;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,\"lightblue\",name.fg_color);};}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);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);};p++;}catch(e){t=false;};};};};\n");
  852.                             }
  853.                             else
  854.                             {
  855.                                 if( reply_format != 19){
  856.                                    canvas_error("clickable clock(s) may not be used together with other reply_types...");
  857.                                  }
  858.                             }
  859.                      break;
  860.                      default: canvas_error("interactive must be set 0,1 or 2");break;
  861.                 }
  862.                 break;
  863.                 case 8:
  864.                         if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock() , for now it's OK */
  865.                             fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
  866.                         }
  867.                         temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/
  868.                         if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
  869.                         else{
  870.                         /* h_color,m_color,s_color,bg_color,fg_color */
  871.                         temp = ",black\",\"black\",\"black\",\"white\",\"black";}
  872.                         string_length = snprintf(NULL,0,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp);
  873.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  874.                         snprintf(tmp_buffer,string_length,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp);
  875.                         add_to_buffer(tmp_buffer);
  876.                         fprintf(js_include_file,"var clocks%d;",clock_cnt);
  877.                         clock_cnt++;
  878.                         break;
  879.                 default:break;
  880.              }
  881.             }
  882.             break;
  883.  
  884.  
  885.         case COLORPALETTE:
  886.         /*
  887.          @ colorpalette color_name_1,color_name_2,...,color_name_8
  888.          @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a>
  889.          @ can be used with command <a href='#userdraw'>'userdraw clickfill,color'</a> when more than one fillcolor is wanted.<br />in that case use for example <a href='#replyformat'>replyformat 10</a> ... reply=x1:y1:color1,x2:y2:color2...<br />the pupil can choose from the given colors by clicking small coloured buttons.<br /> the click coordinates and corresponding fillcolor will be stored in read_canvas()...when using the appropriate replyformat.<br />the first color of the palette is color=0
  890.          @ make sure to include the 'remove button' by using command <a href='#clearbutton'>clearbutton some_text</a>
  891.         */
  892.             if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");}
  893.             fprintf(js_include_file,"var multifillcolors = [];var palettecolors = [");
  894.             while( ! done ){
  895.                 temp = get_color(infile,1);
  896.                 fprintf(js_include_file,"\"%s\",",temp);
  897.             }
  898.             fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */
  899.             add_color_palette(js_include_file,canvas_root_id,input_style);
  900.             break;
  901.        
  902.         case COPY:
  903.         /*
  904.         @ copy x,y,x1,y1,x2,y2,[filename URL]
  905.         @ The image may be "bitmap" or "SVG"
  906.         @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
  907.         @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
  908.         @ [filename] is the URL of the image
  909.         @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
  910.         @ if command <a href="#drag">'drag x/y/xy'</a> 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 valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords 'snaptogrid','xsnaptogrid','ysnaptogrid' or 'snaptopoints x1,y1,x2,y2...'
  911.         @ if keyword <a href="#onclick">'onclick'</a> is set before command 'copy' the image(s) is clickable (marked with a green rectangle around the image)<br />use 'read_dragdrop' to get the number of the clicked image(s)<br />use command 'clearbutton some_text' to reset the reply/click array.<br />example: 4 images; student clicked on image 2 and 3 : reply = 0,1,1,0<br />after clicking the clear button: reply = 0,0,0,0<br />May be mixed with commands 'drag x|y|xy' (use javascript read_canvas to get the new coordinates
  912.         @ 'onclick' for external images may be mixed with canvas generated stuff (like lines,curves etc)
  913.         @ you may draw / userdraw / drag other stuff on top of an "imported" image
  914.         @%copy%size 400,400%xrange -10,10%yrange -10,10%onclick%copy -5,5,-1,-1,-1,-1,https://wims.unice.fr/wims/gifs/fr.gif%onclick%copy 5,5,-1,-1,-1,-1,https://wims.unice.fr/wims/gifs/en.gif%onclick%copy 5,-5,-1,-1,-1,-1,https://wims.unice.fr/wims/gifs/it.gif%onclick%copy -5,-5,-1,-1,-1,-1,https://wims.unice.fr/wims/gifs/cn.gif
  915.         */
  916.             for(i = 0 ; i<7;i++){
  917.                 switch(i){
  918.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
  919.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
  920.                     case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
  921.                     case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
  922.                     case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
  923.                     case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
  924.                     case 6: URL = get_string(infile,1);
  925.                             int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
  926.                             int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
  927.                             if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  928.                             int_data[9] = click_cnt;
  929.                             if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
  930.                                  if( reply_format == 0 ){ reply_format = 20; }
  931.                                  int_data[8] = 2;/* drag & drop */
  932.                             }
  933.                             else
  934.                             {
  935.                                 if( onclick == 1  ){
  936.                                     reply_format = 20;
  937.                                     int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
  938.                                     click_cnt++; /* will also be used in dragstuff ! */
  939.                                 }
  940.                                 else
  941.                                 {
  942.                                     int_data[8] = 0; /* just static image */
  943.                                 }
  944.                             }
  945. /*
  946. function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,ext_img_cnt,resizable,draggable,click_cnt)
  947. */
  948.                             string_length = snprintf(NULL,0,  "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%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,int_data[8],int_data[9]);
  949.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  950.                             snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%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,int_data[8],int_data[9]);
  951.                             drag_type = -1; /* reset the drag_type indicator */
  952.                             ext_img_cnt++;
  953.                             onclick=0;
  954.                             add_to_buffer(tmp_buffer);
  955.                             break;
  956.                     default: break;
  957.                 }
  958.             }
  959.             break;
  960. /*
  961. HTML5 specs:
  962. context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  963. img     Specifies the image, canvas, or video element to use
  964. sx      The x coordinate where to start clipping : x1 = int_data[0]
  965. sy      The y coordinate where to start clipping : x2 = int_data[1]
  966. swidth  The width of the clipped image : int_data[2] - int_data[0]
  967. sheight The height of the clipped image : int_data[3] - int_data[1]
  968. x       The x coordinate where to place the image on the canvas : dx1 = int_data[4]
  969. y       The y coordinate where to place the image on the canvas : dy1 = int_data[5]
  970. width   The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6]
  971. height  The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7]
  972. */
  973.         case COPYRESIZED:
  974.         /*
  975.         @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
  976.         @ The image may be any "bitmap" or "SVG"
  977.         @ 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
  978.         @ (dx1:dy1) must be left top corner; (dx2 :dy2) must be right bottom corner of inserted image
  979.         @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
  980.         @ URL is normal URL of network reachable image file location<br />(as seen from public_html-root or network reachable 'http://some_server/my_images/test.gif'<br />(eg no special wims paths are searched !!)
  981.         @ if command <a href="#drag">'drag x/y/xy'</a> 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 valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords 'snaptogrid','xsnaptogrid','ysnaptogrid' or 'snaptopoints x1,y1,x2,y2...'
  982.         @ if keyword <a href="#onclick">'onclick'</a> is set before command 'copy' the image(s) is clickable (marked with a green rectangle around the image)<br />use 'read_dragdrop' to get the number of the clicked image(s)<br />use command 'clearbutton some_text' to reset the reply/click array.<br />example: 4 images; student clicked on image 2 and 3 : reply = 0,1,1,0<br />after clicking the clear button: reply = 0,0,0,0<br />May be mixed with commands 'drag x|y|xy' (use javascript read_canvas to get the new coordinates
  983.         @ 'onclick' for external images may be mixed with canvas generated stuff (like lines,curves etc)
  984.         @ you may draw / userdraw / drag stuff on top of an "imported" image
  985.         */
  986.             for(i = 0 ; i<9;i++){
  987.                 switch(i){
  988.                     case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
  989.                     case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
  990.                     case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
  991.                     case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
  992.                     case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
  993.                     case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
  994.                     case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
  995.                     case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
  996.                     case 8: URL = get_string(infile,1);
  997.                             /* flag error when wrong diagonal:  copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */
  998.                             if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){
  999.                                 canvas_error("in copyresized , use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! ");
  1000.                             }
  1001.                             int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */
  1002.                             int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */
  1003.                             int_data[6] = abs(int_data[6] - int_data[4]);/* width */
  1004.                             int_data[7] = abs(int_data[7] - int_data[5]);/* height */
  1005.                             if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  1006.                             int_data[9] = click_cnt;
  1007.                             if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
  1008.                                  if( reply_format == 0 ){ reply_format = 20; }
  1009.                                  int_data[8] = 2;/* drag & drop */
  1010.                             }
  1011.                             else
  1012.                             {
  1013.                                 if( onclick == 1  ){
  1014.                                     reply_format = 20;
  1015.                                     int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
  1016.                                     click_cnt++; /* will also be used in dragstuff ! */
  1017.                                 }
  1018.                                 else
  1019.                                 {
  1020.                                     int_data[8] = 0; /* just static image */
  1021.                                 }
  1022.                             }
  1023. /*
  1024. (URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt)
  1025. URL,[2],[3],[6],    [7], [4],[5],[6],[7],ext_img_cnt,1,    [8],      [9]
  1026. */
  1027.                             string_length = snprintf(NULL,0,  "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%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,int_data[8],int_data[9]);
  1028.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1029.                             snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%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,int_data[8],int_data[9]);
  1030.                             drag_type = -1; /* reset the drag_type indicator */
  1031.                             ext_img_cnt++;
  1032.                             onclick=0;
  1033.                             add_to_buffer(tmp_buffer);
  1034.                             break;
  1035.                     default: break;
  1036.                 }
  1037.             }
  1038.             break;
  1039.  
  1040.  
  1041.         case CROSSHAIR:
  1042.         /*
  1043.         @ crosshair x,y,color
  1044.         @ draw a single crosshair point at (x;y) in color 'color'
  1045.         @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
  1046.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1047.         @%crosshair%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 2%onclick%crosshair 0,0,red%linewidth 1%onclick%crosshair 1,1,blue%linewidth 3%onclick%crosshair 3,3,green%linewidth 4%xrosshair 4,4,orange
  1048.         */
  1049.             for(i=0;i<3;i++){
  1050.                 switch(i){
  1051.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  1052.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  1053.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  1054.                         decimals = find_number_of_digits(precision);
  1055.                         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,%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,rotation_center,use_offset,use_pattern);
  1056.                         if(onclick > 0){click_cnt++;}
  1057.                         /* click_cnt++ */
  1058.                         reset();
  1059.                         break;
  1060.                     default:break;
  1061.                 }
  1062.             }
  1063.             break;
  1064.  
  1065.         case CROSSHAIRS:
  1066.         /*
  1067.         @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
  1068.         @ draw multiple crosshair points at given coordinates in color 'color'
  1069.         @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
  1070.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  1071.         @%crosshairs_1%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%snaptogrid%linewidth 2%drag xy%crosshairs red,0,0,1,1,2,2,3,3%drag x%crosshairs blue,0,1,1,2,2,3,3,4
  1072.         @%crosshairs_2%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 2%onclick%crosshairs red,0,0,1,1,2,2,3,3%onclick%crosshairs blue,0,1,1,2,2,3,3,4
  1073. */
  1074.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1075.             fill_color = stroke_color;
  1076.             i=0;
  1077.             while( ! done ){     /* get next item until EOL*/
  1078.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1079.                 if(i%2 == 0 ){
  1080.                     double_data[i] = get_real(infile,0); /* x */
  1081.                 }
  1082.                 else
  1083.                 {
  1084.                     double_data[i] = get_real(infile,1); /* y */
  1085.                 }
  1086.                 i++;
  1087.             }
  1088.             decimals = find_number_of_digits(precision);
  1089.             for(c=0 ; c < i-1 ; c = c+2){
  1090.                 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,%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,rotation_center,use_offset,use_pattern);
  1091.                 if(onclick > 0){click_cnt++;}
  1092.                 /* click_cnt++; */
  1093.             }
  1094.             reset();
  1095.             break;
  1096.  
  1097.         case CROSSHAIRSIZE:
  1098.         /*
  1099.         @ crosshairsize int
  1100.         @ default 8 (px)
  1101.         */
  1102.             crosshair_size = (int) (get_real(infile,1));
  1103.             break;
  1104.  
  1105.         case CURSOR:
  1106.         /*
  1107.         @ cursor 'some CSS cursor_style'
  1108.         @ alternative : pointer
  1109.         @ style can be any valid CSS property value, like crosshair,grabbing,move etc
  1110.         @ wims will not check the validity of your cursor declaration
  1111.         */
  1112.             fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1));
  1113.             break;
  1114.  
  1115.         case CURVE:
  1116.         /*
  1117.          @ curve color,formula(x)
  1118.          @ alernative : plot color,formula(x)
  1119.          @ use command <a href="#trange">trange</a> in parametric functions before command curve / plot  (trange -pi,pi)<br />curve color,formula1(t),formula2(t)
  1120.          @ use command <a href="#precision">"precision" </a>to ncrease the number of digits of the plotted points
  1121.          @ use command <a href="#plotsteps">"plotsteps"</a> to increase / decrease the amount of plotted points (default 150)
  1122.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1123.          @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">"jsplot"'</a><br />(command "curve" will only calculate points within the xrange)
  1124.          @%curve%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%xlabel x-axis%ylabel y-axis%precision 1%grid 2,2,grey,2,2,6,grey%precision 1000%curve red,4*sqrt(x)%curve green,2*sqrt(abs(x)%curve blue,3*1/sqrt(x)%curve orange,4*sin(4/x)%dashed%curve red,4*cos(x)
  1125.         */
  1126.             if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
  1127.                 use_parametric = FALSE;
  1128.                 stroke_color = get_color(infile,0);
  1129.                 char *fun1 = get_string_argument(infile,0);
  1130.                 char *fun2 = get_string_argument(infile,1);
  1131.                 if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
  1132.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,9,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",click_cnt,onclick,drag_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,rotation_center,use_offset,use_pattern);
  1133.             }
  1134.             else
  1135.             {
  1136.                 stroke_color = get_color(infile,0);
  1137.                 char *fun1 = get_string_argument(infile,1);
  1138.                 if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  1139.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,9,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",click_cnt,onclick,drag_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,rotation_center,use_offset,use_pattern);
  1140.             }
  1141.             if(onclick > 0){click_cnt++;}
  1142.             /* click_cnt++; */
  1143.             reset();
  1144.             break;
  1145.  
  1146.         case DASHED:
  1147.         /*
  1148.         @ dashed
  1149.         @ keyword (no arguments required)
  1150.         @ next object will be drawn with a dashed line
  1151.         @ change dashing scheme by using command <a href="#dashtype">dashtype</a>
  1152.         @%dashed%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%line -5,-5,-5,5,red%dashtype 1,1%dline -4,-5,-4,5,green%dashtype 2,2%dline -3,-5,-3,5,blue%dashtype 3,3%dline 0,-5,0,5,orange%dashtype 4,4%dline 3,-5,3,5,brown
  1153.         */
  1154.             use_dashed = TRUE;
  1155.             break;
  1156.  
  1157.         case DASHTYPE:
  1158.         /*
  1159.         @ dashtype line_width_px,space_width_px
  1160.         @ every indiviual object may have its own dashtype, if needed...
  1161.         @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype
  1162.         @ default value "dashtype 2,2" e.g. 2px line and 2px space
  1163.         @ html5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable
  1164.         */
  1165.             for(i=0;i<2;i++){
  1166.                 switch(i){
  1167.                     case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
  1168.                     case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
  1169.                 }
  1170.             }
  1171.         break;
  1172.  
  1173.         case DIAMONDFILL:
  1174.         /*
  1175.         @ diamondfill x0,y0,dx,dy,color
  1176.         @ x0,y0 in xrange / yrange
  1177.         @ distances dx,dy in pixels
  1178.         @ there is also a command <a href="userdraw">userdraw diamondfill,color</a>
  1179.         @%diamondfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%circles red,-4,0,6,4,0,6%linewidth 1%diamondfill 0,0,5,8,blue%diamondfill 0,7,8,8,lightgreen
  1180.         */
  1181.             if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
  1182.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1183.              js_function[DRAW_FILLTOBORDER] = 1;
  1184.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1185.             }
  1186.             decimals = find_number_of_digits(precision);
  1187.             for(i=0;i<5;i++){
  1188.                 switch(i){
  1189.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  1190.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  1191.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1192.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1193.                     case 4: stroke_color = get_color(infile,1);
  1194.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  1195.                     string_length = snprintf(NULL,0,  "draw_diamondfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1196.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1197.                     snprintf(tmp_buffer,string_length,"draw_diamondfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1198.                     add_to_buffer(tmp_buffer);
  1199.                     fill_cnt++;
  1200.                     break;
  1201.                     default:break;
  1202.                 }
  1203.             }
  1204.             reset();
  1205.         break;
  1206.  
  1207.         case DOTFILL:
  1208.         /*
  1209.         @ dotfill x0,y0,dx,dy,color
  1210.         @ x0,y0 in xrange / yrange
  1211.         @ distances dx,dy in pixels
  1212.         @ radius of dots is linewidth
  1213.         @ there is also a command <a href="userdraw">userdraw dotfill,color</a>
  1214.         @%dotfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%circles red,-4,0,6,4,0,6%dotfill 0,0,5,8,blue%dotfill 0,7,8,8,lightgreen
  1215.         */
  1216.             if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
  1217.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1218.              js_function[DRAW_FILLTOBORDER] = 1;
  1219.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1220.             }
  1221.             decimals = find_number_of_digits(precision);
  1222.             for(i=0;i<5;i++){
  1223.                 switch(i){
  1224.                     case 0: double_data[0] = get_real(infile,0); break; /* x in px */
  1225.                     case 1: double_data[1] = get_real(infile,0); break; /* y in py */
  1226.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1227.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1228.                     case 4: stroke_color = get_color(infile,1);
  1229.                     /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
  1230.                     string_length = snprintf(NULL,0,  "draw_dotfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1231.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1232.                     snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1233.                     add_to_buffer(tmp_buffer);
  1234.                     fill_cnt++;
  1235.                     break;
  1236.                     default:break;
  1237.                 }
  1238.             }
  1239.             reset();
  1240.         break;
  1241.  
  1242.         case DRAG:
  1243.         /*
  1244.          @ drag [x][y][xy]
  1245.          @ the next object will be draggable in x / y / xy direction
  1246.          @ the displacement can be read by 'javascript:read_dragdrop();'
  1247.          @ the precision (default 2 decimals) in the student reply may be set with command <a href="#precision">'precision'.</a><br />Use this 'precision' command before this command 'drag x|y|xy' !
  1248.          @ 'onclick' and 'drag x|y|xy' may be combined (for different objects: a single object can either be onclick or drag , not both )
  1249.          @ 'multi_objects' will be numbered in the given x/y-sequence (example: points red,0,0,1,1,2,2,3,3 : point (0:0) is object_number 1)
  1250.          @ <b>attention</b>: static objects and 'onclick/drag' objects of the same type (like point,circle,etc) with the same coordinates (e.g. objects that overlap) will give problems in the 'recognition algorithm')<br />in this example<br /><em>linewidth 4<br />point 0,0,red<br />drag xy<br />point 0,0,blue<br /></em>the blue point will not be recognised as draggable !<br /><em>linewidth 4<br />drag xy<br />point 0,0,red<br />drag xy<br />point 0,0,blue<br /></em>both points will be recognised
  1251.          @ the answer is  : drag_or_onclick_object_number : Xorg : Yorg : Xnew : Ynew<br />wherein object_number is the sequence number of the draggable &amp; onclick objects in your script.<br />Only draggable & onclick objects will have an object_number (e.g things like point,crosshair,line,segment,circle,rect,triangle...etc)
  1252.          @ use keyword 'snaptogrid' , 'xsnaptogrid' , 'ysnaptogrid' or command 'snaptopoints x1,y1,x2,y2,...' to switch from free to discrete movement
  1253.          @ 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.
  1254.          @ 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 !!
  1255.          @%drag_x%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 200,40%drag x%linewidth 2%circles blue,-5,0,3,0,0,2,5,0,4,0,4,3,0,-3,4  
  1256.          @%drag_y%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 200,40%drag y%linewidth 2%circles blue,-5,0,3,0,0,2,5,0,4,0,4,3,0,-3,4  
  1257.          @%drag_xy%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 200,40%drag xy%linewidth 2%circles blue,-5,0,3,0,0,2,5,0,4,0,4,3,0,-3,4  
  1258.         */
  1259.             temp = get_string(infile,1);
  1260.             if(strstr(temp,"xy") != NULL ){
  1261.                 drag_type = 0;
  1262.             }
  1263.             else
  1264.             {
  1265.                 if(strstr(temp,"x") != NULL ){
  1266.                     drag_type = 1;
  1267.                 }
  1268.                 else
  1269.                 {
  1270.                     drag_type = 2;
  1271.                 }
  1272.             }
  1273.             /* assuming all drag&drop coordinates the same precision: so set only once */
  1274.             if( print_drag_params_only_once == FALSE ){
  1275.              fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;\n",precision);
  1276.              print_drag_params_only_once = TRUE;
  1277.             }
  1278.             onclick = 2;
  1279.             /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
  1280.             break;
  1281.  
  1282.         case ELLIPSE:
  1283.         /*
  1284.         @ ellipse xc,yc,radius_x,radius_y,color
  1285.         @ a ellipse with center xc/yc in x/y-range
  1286.         @ radius_x and radius_y are in pixels
  1287.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1288.         @ will shrink / expand on zoom out / zoom in
  1289.         */
  1290.             for(i=0;i<5;i++){
  1291.                 switch(i){
  1292.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  1293.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  1294.                     case 2:double_data[2] = get_real(infile,0);break; /* rx -> px  */
  1295.                     case 3:double_data[3] = get_real(infile,0);break; /* ry -> px  */
  1296.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  1297.                         decimals = find_number_of_digits(precision);
  1298.                         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,%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,rotation_center,use_offset,use_pattern);
  1299.                         if(onclick > 0){click_cnt++;}
  1300.                         /* click_cnt++; */
  1301.                         reset();
  1302.                     break;
  1303.                 }
  1304.             }
  1305.             break;
  1306.            
  1307.         case ELLIPSES:
  1308.         /*
  1309.         @ ellipses color,xc1,yc1,radius_x1,radius_y1,xc2,yc2,radius_x2,radius_y2,xc3,yc3,radius_x3,radius_y3,...
  1310.         @ a ellipses with center xc/yc in x/y-range
  1311.         @ radius_x and radius_y are in pixels
  1312.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1313.         @ will shrink / expand on zoom out / zoom in
  1314.         @%ellipses%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%opacity 200,40%ellipses red,-3,0,2,4,0,0,4,2,3,0,6,2
  1315.         */
  1316.            
  1317.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1318.             fill_color = stroke_color;
  1319.             i=1;
  1320.             while( ! done ){     /* get next item until EOL*/
  1321.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1322.                 switch (i%4){
  1323.                  case 1:double_data[i-1] = get_real(infile,0);break; /* x */
  1324.                  case 2:double_data[i-1] = get_real(infile,0);break; /* y */
  1325.                  case 3:double_data[i-1] = get_real(infile,0);break; /* rx */
  1326.                  case 0:double_data[i-1] = get_real(infile,1);break; /* ry */
  1327.                  default: break;
  1328.                 }
  1329.                 i++;
  1330.             }
  1331.             decimals = find_number_of_digits(precision);
  1332.             for(c = 0 ; c < i-1 ; c = c+4){
  1333.              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,%s,%d,%d));\n", click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],decimals,double_data[c+2],decimals,double_data[c+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,rotation_center,use_offset,use_pattern);
  1334.              if(onclick > 0){click_cnt++;} /* click_cnt++; */
  1335.             }
  1336.             reset();
  1337.             break;
  1338.  
  1339.         case FILLALL:
  1340.         /*
  1341.         @ fillall color,x1,y1,x2,y2...x_n,y_n
  1342.         @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color'
  1343.         @ any other colors (objects) in the <a href="#canvastype>canvastype</a> will act as border to the bucket fill
  1344.         @ use this command  after all boundary objects are declared.
  1345.         @ Use command 'userdraw clickfill,color' for user click driven flood fill.
  1346.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1347.         @ note: the fill-family of commands are very (client) cpu intensive operations!<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..
  1348.         @%fillall%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%vlines black,-5,0,-5,0,-4,0,-4,0,3,0,3,0%hlines black,-5,0,-5,0,-5,4,-5,4,-5,-2,-5,-2%circles green,0,0,2,3,3,5,-5,-5,3%opacity 240,50%fillall blue,1,1,8,8,-8,-8
  1349.         */
  1350.             decimals = find_number_of_digits(precision);
  1351.             fill_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1352.             i=0;
  1353.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1354.              js_function[DRAW_FILLTOBORDER] = 1;
  1355.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1356.             }
  1357.             while( ! done ){     /* get next item until EOL*/
  1358.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1359.                 if(i%2 == 0 ){
  1360.                     double_data[i] = get_real(infile,0); /* x */
  1361.                 }
  1362.                 else
  1363.                 {
  1364.                     double_data[i] = get_real(infile,1); /* y */
  1365.                     string_length = snprintf(NULL,0,  "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[i-1],decimals,double_data[i],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt);
  1366.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1367.                     snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[i-1],decimals,double_data[i],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt);
  1368.                     add_to_buffer(tmp_buffer);
  1369.                     fill_cnt++;
  1370.                 }
  1371.                 i++;
  1372.             }
  1373.         break;
  1374.  
  1375.         case FILLED:
  1376.         /*
  1377.         @ filled
  1378.         @ keyword (no arguments required)
  1379.         @ the next 'fillable' object (only the next !) will be filled
  1380.         @ use command <a href="fillcolor">"fillcolor color"</a> to set fillcolor
  1381.         @ use <a href="#fillpattern">fillpattern</a> for non-solid color filling.
  1382.         @ use command "opacity 0-255,0-255" to set stroke and fill-opacity
  1383.         @ 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 !
  1384.         */
  1385.             use_filled = 1;
  1386.             use_pattern = 0;
  1387.             break;
  1388.  
  1389.         case FILLCOLOR:
  1390.         /*
  1391.         @ fillcolor colorname or #hex
  1392.         @ set the color : mainly used for command 'userdraw obj,stroke_color'
  1393.         @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...)
  1394.         @ see <a href="#fillpattern">fillpattern</a> for non-solid color filling.
  1395.         */
  1396.             fill_color = get_color(infile,1);
  1397.             use_pattern = 0;
  1398.             break;
  1399.  
  1400.         case FILLPATTERN:
  1401.         /*
  1402.         @ fillpattern grid | hatch | diamond | dot | image-url
  1403.         @ use a pattern as fillstyle
  1404.         @ suitable for all fillable object including the <a href="#userdraw">'userdraw objects' family</a>
  1405.         @ noy -yet- implemented in the <a href="#multidraw">multidraw objects family</a>...(will probably be too complex)
  1406.         @ the fillcolor is set by the object command, for example:<br />size 370,370<br />xrange -5,5<br />yrange -5,5<br />opacity 165,150<br />fillpattern grid<br />fcircle -6,3,160,blue<br />fillpattern dot<br />fcircle -3,-3,160,red<br />fillpattern hatch<br />fcircle 0,3,160,green<br />filpattern diamond<br />fcircle 3,-3,160,cyan<br />userdraw dotfill,blue<br />zoom red<br />
  1407.         @ the pattern dimensions are hardcoded (linewidth ,radius,dx,dy are fixed)
  1408.         @ the pattern color is set by command <a href='#fillcolor'>fillcolor</a> and <a href='#opacity'>opacity</a>
  1409.         @ see <a href="#fillcolor">fillcolor</a> for solid color filling.
  1410.         @ when using an image-url , make sure it contains an '/' in the filename...'fillpattern $$module_dir/gifs/test.jpg' will fill the next fillable object with this image.|<br />the argument to html5 canvas routine 'createPattern(img,argument)' is set to 'repeat'<br />e.g. if the image is smaller then the canvas, multiple copies will be used to fill the area ( e.g. ctx.fillStyle() = pattern)<br />for example:<br />size 150,150<br />xrange -5,5<br />yrange -5,5<br />drag xy<br />fillpattern gifs/en.gif<br />fcircle 0,0,100,red<br />fillpattern gifs/nl.gif<br />drag xy<br />fcircle -3,2,100,green<br />fillpattern gifs/cn.gif<br />drag xy<br />fcircle 3,2,100,green<br />
  1411.         @ fillpattern is also active for <a href="#userdraw">userdraw object,color"</a>...<br />the userdraw family a has also 'clickfill type' (e.g. an object gets filled between boundaries, when clicked) commands like:<br />'userdraw dotfill,color'<br />'userdraw hatchfill,color' etc
  1412.         @%fillpattern%size 400,400%xrange -5,5%yrange -5,5%opacity 165,150%fillpattern grid%fcircle -6,3,160,blue%fillpattern dot%fcircle -3,-3,160,red%fillpattern hatch%fcircle 0,3,160,green%filpattern diamond%fcircle 3,-3,160,cyan%zoom red
  1413.         */
  1414.             temp = get_string(infile,1);
  1415.             if( strstr(temp,"grid") != 0 ){ use_pattern = 2;use_filled = 2;} /* use_pattern is used in dragstuff library */
  1416.             else
  1417.             if( strstr(temp,"hatch") != 0 ){ use_pattern = 3;use_filled = 3;}
  1418.             else
  1419.             if( strstr(temp,"diamond") != 0 ){ use_pattern = 4;use_filled = 4;}
  1420.             else
  1421.             if( strstr(temp,"dot") != 0 ){ use_pattern = 5;use_filled = 5;}
  1422.             else
  1423.             if( strstr(temp,"/") != 0 ){ use_pattern = 6;use_filled = 0;if( js_function[ADD_LOAD_IMAGE] != 1 ){ js_function[ADD_LOAD_IMAGE] = 1; add_js_load_image(js_include_file,canvas_root_id);} fprintf(js_include_file,"get_image_from_url(\"%s\"); ",temp); }
  1424.             else
  1425.             canvas_error("fillpattern unknown or typo...choose grid,hatch,diamond of dot...");     
  1426.             break;
  1427.         case FILLTOBORDER:
  1428.         /*
  1429.         @ filltoborder x,y,bordercolor,color
  1430.         @ fill the region  of point (x:y)  with color 'color'
  1431.         @ any other color will not act as border to the bucket fill
  1432.         @ use this command  after all boundary objects are declared.
  1433.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1434.         @ 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..
  1435.         @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a>
  1436.         @%filltoborder%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%filltoborder 6,6,blue,blue%filltoborder 6,-6,blue,red
  1437.         */
  1438.             for(i=0 ;i < 4 ; i++){
  1439.                 switch(i){
  1440.                     case 0:double_data[0] = get_real(infile,0);break;
  1441.                     case 1:double_data[1] = get_real(infile,0);break;
  1442.                     case 2:bgcolor = get_color(infile,0);break;
  1443.                     case 3:fill_color = get_color(infile,1);
  1444.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1445.                                 js_function[DRAW_FILLTOBORDER] = 1;
  1446.                                 add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1447.                            }
  1448.                            decimals = find_number_of_digits(precision);
  1449.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  1450.                            string_length = snprintf(NULL,0,  "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt);
  1451.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1452.                            snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt);
  1453.                            add_to_buffer(tmp_buffer);
  1454.                            fill_cnt++;
  1455.                            break;
  1456.                     default:break;
  1457.                 }
  1458.             }
  1459.             reset();
  1460.         break;
  1461.         case FLOODFILL:
  1462.         /*
  1463.         @ floodfill x,y,color
  1464.         @ alternative : fill x,y,color
  1465.         @ fill the region of point (x:y) with color 'color'
  1466.         @ any other color or size of picture (borders of picture) will act as border to the bucket fill
  1467.         @ use this command  after all boundary objects are declared.
  1468.         @ Use command 'userdraw clickfill,color' for user click driven flood fill.
  1469.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1470.         @ 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..
  1471.         @%floodfill%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%floodfill 6,6,blue%floodfill 6,-6,red
  1472.         */
  1473.             for(i=0 ;i < 4 ; i++){
  1474.                 switch(i){
  1475.                     case 0:double_data[0] = get_real(infile,0);break;
  1476.                     case 1:double_data[1] = get_real(infile,0);break;
  1477.                     case 2:fill_color = get_color(infile,1);
  1478.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1479.                                 js_function[DRAW_FILLTOBORDER] = 1;
  1480.                                 add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1481.                            }
  1482.                            decimals = find_number_of_digits(precision);
  1483.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  1484.                            string_length = snprintf(NULL,0,  "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt);
  1485.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1486.                            snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt);
  1487.                            add_to_buffer(tmp_buffer);
  1488.                            fill_cnt++;
  1489.                            break;
  1490.                     default:break;
  1491.                 }
  1492.             }
  1493.             reset();
  1494.         break;
  1495.  
  1496.         case FONTCOLOR:
  1497.         /*
  1498.          @ fontcolor color
  1499.          @ color: hexcolor or colorname
  1500.          @ default: black
  1501.          @ example usage: x/y-axis text
  1502.         */
  1503.             font_color = get_color(infile,1);
  1504.             break;
  1505.  
  1506.         case FONTFAMILY:
  1507.         /*
  1508.          @ fontfamily font_description
  1509.          @ set the font family; for browsers that support it
  1510.          @ font_description: Ariel ,Courier, Helvetica etc
  1511.          @ 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 34pt Ariel
  1512.          @ use correct syntax : 'font style' 'font size'pt 'fontfamily'
  1513.         */
  1514.             font_family = get_string(infile,1);
  1515.             break;
  1516.  
  1517.         case FONTSIZE:
  1518.         /*
  1519.          @ fontsize font_size
  1520.          @ default value 12
  1521.          @ note:for some macro's (like grid | legend | xaxistext | xlabel etc) sometimes command <a href="#fontfamily">"fontfamily"</a> can be used for some specific font-setting<br />this is however not always very straight forward...so just try and see what happens
  1522.         */
  1523.             font_size = (int) (get_real(infile,1));
  1524.             break;
  1525.  
  1526.         case FUNCTION_LABEL:
  1527.         /*
  1528.          @ functionlabel 'some string'
  1529.          @ default value "f(x)="
  1530.          @ no mathml allowed (just ascii string)
  1531.          @ use command 'fontsize int' to adjust the size
  1532.          @ use command 'strokecolor colorname' to adjust the labels (individually, if needed)
  1533.          @ if needed, use before every command 'userinput function | inputfield | textarea'
  1534.         */
  1535.             function_label = get_string_argument(infile,1);
  1536.             break;
  1537.  
  1538.         case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px) ,axis/tickscolor]*/
  1539.         /*
  1540.          @ grid step_x,step_y,gridcolor
  1541.          @ if keywords <a href="#axis">"axis"</a> or <a href="#axisnumbering">"axisnumbering"</a> 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
  1542.          @ in that case, use command <a href="#fontcolor">"fontcolor"</a>, <a href="#fontsize">"fontsize"</a> and / or <a href="#fontfamily">"fontfamily"</a> to adjust font <br />defaults: black,12,Ariel
  1543.          @ 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)
  1544.          @ can <b>not</b> be set <a href="#onclick">"onclick"</a> or <a href="#drag">"drag xy"</a>
  1545.          @ use commands <a href="#xlabel">'xlabel some_string'</a> and/or <a href="#ylabel">'ylabel some_string'</a> to label axis;<br />use command "fontsize" to adjust size:the font family is non-configurable 'italic your_fontsize px Ariel' !
  1546.          @ see commands (see <a href="#xaxis">"xaxis" or xaxistext"</a>, <a href="#yaxis">"yaxis" or "yaxistext"</a> to set tailormade values on axis (the used font is set by <a href="fontfamily">command fontfamily</a>; default '12px Ariel')
  1547.          @ see command <a href="#legend">"legend"</a>to set a legend for the graph ;<br />use command <a href="#fontsize">"fontsize"</a> to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel')
  1548.          @%grid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%zoom red
  1549.          @%grid_axis%size 400,400%xrange -10,10%yrange -10,10%axis%grid 1,1,grey,2,2,6,black%zoom red
  1550.          @%grid_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red
  1551.          @%grid_axis_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red
  1552.         */
  1553.             if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
  1554.             if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
  1555.             for(i=0;i<4;i++){
  1556.                 switch(i){
  1557.                     case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
  1558.                     case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
  1559.                     case 2:
  1560.                     if( use_axis == TRUE ){
  1561.                         stroke_color = get_color(infile,0);
  1562.                         done = FALSE;
  1563.                         int_data[0] = (int) (get_real(infile,0));/* xminor */
  1564.                         int_data[1] = (int) (get_real(infile,0));/* yminor */
  1565.                         int_data[2] = (int) (get_real(infile,0));/* tic_length */
  1566.                         fill_color = get_color(infile,1); /* used as axis_color*/
  1567.                     }
  1568.                     else
  1569.                     {
  1570.                         int_data[0] = 1;
  1571.                         int_data[1] = 1;
  1572.                         stroke_color = get_color(infile,1);
  1573.                         fill_color = stroke_color;
  1574.                     }
  1575.                     if( double_data[0] <= 0 ||  double_data[1] <= 0 ||  int_data[0] <= 0 ||  int_data[1] <= 0 ){canvas_error("major or minor ticks must be positive !");}
  1576.                     /* set snap_x snap_y values in pixels */
  1577.                     fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
  1578.                     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);
  1579.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1580.                     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);
  1581.                     add_to_buffer(tmp_buffer);
  1582.                     break;
  1583.                 }
  1584.             }
  1585.             reset();
  1586.             break;
  1587.         case GRIDFILL:
  1588.         /*
  1589.         @ gridfill x0,y0,dx,dy,color
  1590.         @ x0,y0 in xrange / yrange
  1591.         @ distances dx,dy in pixels
  1592.         @ there is also a command <a href="userdraw">userdraw gridfill,color</a>
  1593.         @%gridfill%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%gridfill 6,6,10,10,blue%gridfill 6,-6,6,6,red
  1594.  
  1595.         */
  1596.             if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
  1597.             decimals = find_number_of_digits(precision);
  1598.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1599.              js_function[DRAW_FILLTOBORDER] = 1;
  1600.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1601.             }
  1602.             for(i=0;i<5;i++){
  1603.                 switch(i){
  1604.                     case 0: double_data[0] = get_real(infile,0); break; /* x  */
  1605.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  1606.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1607.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1608.                     case 4: stroke_color = get_color(infile,1);
  1609.                     string_length = snprintf(NULL,0,  "draw_gridfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1610.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1611.                     snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1612.                     add_to_buffer(tmp_buffer);
  1613.                     fill_cnt++;
  1614.                     break;
  1615.                     default:break;
  1616.                 }
  1617.             }
  1618.             reset();
  1619.         break;
  1620.  
  1621.         case HALFLINE:
  1622.         /*
  1623.         @ demiline x1,y1,x2,y2,color
  1624.         @ alternative : halfline
  1625.         @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex)
  1626.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1627.         @%halfline%size 400,400%xrange -10,10%yrange -10,10%halfline -5,5,0,0,red%halfline -5,-5,0,0,blue
  1628.         */
  1629.             for(i=0;i<5;i++){
  1630.                 switch(i){
  1631.                     case 0: double_data[0]= get_real(infile,0);break; /* x-values */
  1632.                     case 1: double_data[1]= get_real(infile,0);break; /* y-values */
  1633.                     case 2: double_data[10]= get_real(infile,0);break; /* x-values */
  1634.                     case 3: double_data[11]= get_real(infile,0);break; /* y-values */
  1635.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  1636.                     if(double_data[0] == double_data[10]){ /* vertical halfline */
  1637.                         if(double_data[1] < double_data[11]){
  1638.                          double_data[3] = ymax + 1000;
  1639.                         }
  1640.                         else
  1641.                         {
  1642.                          double_data[3] = ymin - 1000;
  1643.                         }
  1644.                         double_data[2] = double_data[0];
  1645.                     }
  1646.                     else
  1647.                     { /* horizontal halfline*/
  1648.                      if( double_data[1] == double_data[11] ){
  1649.                       if( double_data[0] < double_data[10] ){
  1650.                         double_data[2] = xmax + 1000; /* halfline to the right */
  1651.                       }
  1652.                       else
  1653.                       {
  1654.                         double_data[2] = xmin - 1000; /* halfline to the left */
  1655.                       }
  1656.                       double_data[3] = double_data[1];
  1657.                      }
  1658.                      else
  1659.                      {
  1660.                       /* any other halfline */
  1661.                       /* slope */
  1662.                       double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
  1663.                       /* const */
  1664.                       double_data[13] = double_data[1] - double_data[12]*double_data[0];
  1665.                       if( double_data[0] < double_data[10] ){
  1666.                        double_data[2] = double_data[2] + 1000;
  1667.                       }
  1668.                       else
  1669.                       {
  1670.                        double_data[2] = double_data[2] - 1000;
  1671.                       }
  1672.                       double_data[3] = double_data[12]*double_data[2] + double_data[13];
  1673.                      }
  1674.                     }
  1675.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%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,rotation_center,use_offset,use_pattern);
  1676.                     if(onclick > 0){click_cnt++;}
  1677.                     /* click_cnt++; */
  1678.                     reset();
  1679.                     break;
  1680.                 }
  1681.             }
  1682.             break;
  1683.  
  1684.         case HALFLINES:
  1685.         /*
  1686.         @ demilines color,x1,y1,x2,y2,....
  1687.         @ alternative : halflines
  1688.         @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc etc
  1689.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually
  1690.         @%halflines%size 400,400%xrange -10,10%yrange -10,10%halflines red,-5,5,0,0,-5,-5,0,0
  1691.         */
  1692.             stroke_color=get_color(infile,0);
  1693.             fill_color = stroke_color;
  1694.             i=0;
  1695.             while( ! done ){     /* get next item until EOL*/
  1696.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1697.                 if(i%2 == 0 ){
  1698.                     double_data[i] = get_real(infile,0); /* x */
  1699.                 }
  1700.                 else
  1701.                 {
  1702.                     double_data[i] = get_real(infile,1); /* y */
  1703.                 }
  1704.                 i++;
  1705.             }
  1706.             decimals = find_number_of_digits(precision);
  1707.             for(c = 0 ; c < i-1 ; c = c+4){
  1708.                 if( double_data[c] == double_data[c+2] ){ /* vertical line*/
  1709.                     if(double_data[c+1] < double_data[c+3]){ /* upright halfline */
  1710.                         double_data[c+3] = ymax + 1000;
  1711.                     }
  1712.                     else
  1713.                     {
  1714.                      double_data[c+3] = ymin - 1000;/* descending halfline */
  1715.                     }
  1716.                 }
  1717.                 else
  1718.                 {
  1719.                     if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  1720.                         if(double_data[c] < double_data[c+2] ){ /* halfline to the right */
  1721.                             double_data[c+2] = xmax+100;
  1722.                         }
  1723.                         else
  1724.                         {
  1725.                             double_data[c+2] = xmin-1000; /* halfline to the right */
  1726.                         }
  1727.                     }
  1728.                     else
  1729.                     {
  1730.                         /* m */
  1731.                         double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  1732.                         /* q */
  1733.                         double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  1734.                         if(double_data[c] < double_data[c+2]){ /* to the right */
  1735.                             double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it's just segment */
  1736.                             double_data[c+3] = (m)*(double_data[c+2])+(q);
  1737.                         }
  1738.                         else
  1739.                         { /* to the left */
  1740.                             double_data[c+2] = xmin - 1000;
  1741.                             double_data[c+3] = (m)*(double_data[c+2])+(q);
  1742.                         }
  1743.                     }
  1744.                 }
  1745.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+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,rotation_center,use_offset,use_pattern);
  1746.                 if(onclick > 0){click_cnt++;}
  1747.                 /* click_cnt++; */
  1748.             }
  1749.             reset();
  1750.             break;
  1751.         case HATCHFILL:
  1752.         /*
  1753.         @ hatchfill x0,y0,dx,dy,color
  1754.         @ x0,y0 in xrange / yrange
  1755.         @ distances dx,dy in pixels
  1756.         @ there is also a command <a href="userdraw">userdraw hatchfill,color</a>
  1757.         @%hatchfill%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%hatchfill 6,6,10,10,blue%hatchfill 6,-6,6,6,red
  1758.         */
  1759.             if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
  1760.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1761.              js_function[DRAW_FILLTOBORDER] = 1;
  1762.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1763.             }
  1764.             decimals = find_number_of_digits(precision);
  1765.             for(i=0;i<5;i++){
  1766.                 switch(i){
  1767.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  1768.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  1769.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1770.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1771.                     case 4: stroke_color = get_color(infile,1);
  1772.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  1773.                     string_length = snprintf(NULL,0,  "draw_hatchfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1774.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1775.                     snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1776.                     add_to_buffer(tmp_buffer);
  1777.                     fill_cnt++;
  1778.                     break;
  1779.                     default:break;
  1780.                 }
  1781.             }
  1782.             reset();
  1783.         break;
  1784.  
  1785.         case HLINE:
  1786.         /*
  1787.         @ hline x,y,color
  1788.         @ alternative : horizontalline
  1789.         @ draw a horizontal line through point (x:y) in color 'color'
  1790.         @ or use command <a href='#curve'>'curve color,formula'</a> to draw the line <br />(uses more points to draw the line; is however better draggable)
  1791.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1792.         @%hline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hline 0,0,red%dhline 0,5,blue
  1793.         */
  1794.             for(i=0;i<3;i++) {
  1795.                 switch(i){
  1796.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  1797.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  1798.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  1799.                     double_data[3] = double_data[1];
  1800.                     decimals = find_number_of_digits(precision);
  1801.                     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,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,100*xmin,decimals,100*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,rotation_center,use_offset,use_pattern);
  1802.                     if(onclick > 0){click_cnt++;}
  1803.                     /* click_cnt++; */
  1804.                     reset();
  1805.                     break;
  1806.                 }
  1807.             }
  1808.             break;
  1809.  
  1810.         case HLINES:
  1811.         /*
  1812.         @ hlines color,x1,y1,x2,y2,...
  1813.         @ alternative : horizontallines
  1814.         @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color'
  1815.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  1816.         @%hlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hlines red,0,0,0,5,0,-5
  1817.         */
  1818.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1819.             fill_color = stroke_color;
  1820.             i=0;
  1821.             while( ! done ){     /* get next item until EOL*/
  1822.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1823.                 if(i%2 == 0 ){
  1824.                     double_data[i] = get_real(infile,0); /* x */
  1825.                 }
  1826.                 else
  1827.                 {
  1828.                     double_data[i] = get_real(infile,1); /* y */
  1829.                 }
  1830.                 i++;
  1831.             }
  1832.             decimals = find_number_of_digits(precision);
  1833.             for(c = 0 ; c < i-1 ; c = c+2){
  1834.                 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,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,xmin,decimals,xmax,decimals,double_data[c+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,rotation_center,use_offset,use_pattern);
  1835.                 if(onclick > 0){click_cnt++;}
  1836.                 /* click_cnt++; */
  1837.             }
  1838.             reset();
  1839.             break;
  1840.         case HTTP:
  1841.         /*
  1842.          @ http x1,y1,x2,y2,http://some_adress.com
  1843.          @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2)
  1844.          @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe
  1845.          @ can <b>not</b> be 'set onclick' or 'drag xy'
  1846.          @%http%size 400,400%xrange -10,10%yrange -10,10%http 0,10,10,0,http://wims.unice.fr%opacity 200,50%drag xy%fcircle 0,0,100,green
  1847.         */
  1848.             if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}
  1849.             for(i=0;i<5;i++){
  1850.                 switch(i){
  1851.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  1852.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  1853.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  1854.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  1855.                     case 4: decimals = find_number_of_digits(precision);
  1856.                             temp = get_string(infile,1);
  1857.                             if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
  1858.                             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);
  1859.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+2);
  1860.                             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);
  1861.                             add_to_buffer(tmp_buffer);
  1862.                     break;
  1863.                 }
  1864.             }
  1865.             reset();
  1866.             break;
  1867.         case HTML:
  1868.         /*
  1869.          @ html x1,y1,x2,y2,html_string
  1870.          @ all tags are allowed<br /> html-code using inputfields could be read using your own javascript-code. Do not use id's like 'canvas_input0' etc.
  1871.          @ can be set onclick <br />(however dragging not supported)
  1872.          @%html%size 400,400%xrange -10,10%yrange -10,10%html 0,10,10,0,<table style="border:solid 2px;background-color:yellow"><tr><th>qwerty</th><th>qwerty</th></tr><tr><td>qwerty</td><td>qwerty</td></tr><tr><td>qwerty</td><td>qwerty</td></tr><tr><td>qwerty</td><td>qwerty</td></tr><tr><td>qwerty</td><td>qwerty</td></tr></table> %opacity 200,50%drag xy%fcircle 0,0,100,green
  1873.         */
  1874.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  1875.             for(i=0;i<5;i++){
  1876.                 switch(i){
  1877.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  1878.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  1879.                     case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed : overflow  */
  1880.                     case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed : overflow */
  1881.                     case 4: decimals = find_number_of_digits(precision);
  1882.                             temp = get_string(infile,1);
  1883.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  1884.                             string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity);
  1885.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1886.                             snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity);
  1887.                             add_to_buffer(tmp_buffer);
  1888.                             if(onclick == 1 || onclick == 2 ){click_cnt++;}
  1889.                             break;
  1890.                     default:break;
  1891.                 }
  1892.             }
  1893.             reset();
  1894.             break;
  1895.  
  1896.         case IMAGEFILL:
  1897.         /*
  1898.         @ imagefill x,y,scaling to xsize &times; ysize?,image_url
  1899.         @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
  1900.         @ scaling to xsize &times; ysize ? ... 1 = yes 0 = no
  1901.         @ After pattern filling ,the fill-color should be reset !
  1902.         @ wims getins / image from class directory : imagefill 80,80,my_image.gif
  1903.         @ normal url : imagefill 80,80,0,$module_dir/gifs/my_image.gif
  1904.         @ normal url : imagefill 80,80,1,http://adres/a/b/c/my_image.jpg
  1905.         @ if dx,dy is larger than the image, the whole image will be background to the next object.
  1906.         @%imagefill%size 400,400%xrange -10,10%yrange -10,10%circles blue,0,0,2,1,1,2%imagefill 1.5,1.5,0,https://wims.unice.fr/wims/gifs/en.gif
  1907.         */
  1908.             if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
  1909.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1910.              js_function[DRAW_FILLTOBORDER] = 1;
  1911.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1912.             }
  1913.             for(i=0 ;i < 4 ; i++){
  1914.                 switch(i){
  1915.                     case 0:int_data[0] = (int) (get_real(infile,0));break;
  1916.                     case 1:int_data[1] = (int) (get_real(infile,0));break;
  1917.                     case 2:int_data[2] = (int) (get_real(infile,0));break; /* 0 | 1 */
  1918.                     case 3: URL = get_string_argument(infile,1);
  1919.                             string_length = snprintf(NULL,0,  "draw_imagefill(%d,%d,%d,\"%s\",%d,%d,%d,%d);\n",STATIC_CANVAS+fill_cnt,int_data[0],int_data[1],URL,xsize,ysize,use_userdraw,int_data[2]);
  1920.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1921.                             snprintf(tmp_buffer,string_length,"draw_imagefill(%d,%d,%d,\"%s\",%d,%d,%d,%d);\n",STATIC_CANVAS+fill_cnt,int_data[0],int_data[1],URL,xsize,ysize,use_userdraw,int_data[2]);
  1922.                             add_to_buffer(tmp_buffer);
  1923.                             fill_cnt++;
  1924.                     break;
  1925.                 }
  1926.             }
  1927.             reset();
  1928.         break;
  1929.  
  1930.         case INPUTSTYLE:
  1931.         /*
  1932.         @ inputstyle style_description
  1933.         @ may be used before any 'style-able' html object.(like inputfields or buttons)<br />or any html objects that are generated by some canvasdraw commands
  1934.         @%inputstyle%size 400,400%xrange -10,10%yrange -10,10%inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt;text-align:center%input 0,0,10,1,Hello
  1935.         */
  1936.             input_style = get_string(infile,1);
  1937.             break;
  1938.         case INPUT:
  1939.         /*
  1940.          @ input x,y,size,editable,value
  1941.          @ to set inputfield "readonly", use editable = 0
  1942.          @ only active inputfields (editable = 1) will be read with read_canvas();
  1943.          @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be cleared and set readonly<br />override this by keyword <a href="#status">'status'</a>
  1944.          @ may be further controlled by <a href="#inputstyle">"inputstyle"</a> (inputcss is not yet implemented...)
  1945.          @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
  1946.          @ use keyword <a href='#xoffset'>xoffset | centered</a> if the inputfield should be centered on (x:y)<br /> default is the left top corner is (x:y)
  1947.          @%input%size 400,400%xrange -10,10%yrange -10,10%input 1,2,14,1,hello world
  1948.         */
  1949.         if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  1950.             for(i = 0 ; i<5;i++){
  1951.                 switch(i){
  1952.                     case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
  1953.                     case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
  1954.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
  1955.                     case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
  1956.                     case 4:
  1957.                             temp = get_string_argument(infile,1);
  1958.                             string_length = snprintf(NULL,0,  "draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\",%d);\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp,use_offset);
  1959.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1960.                             snprintf(tmp_buffer,string_length,"draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\",%d);\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp,use_offset);
  1961.                             add_to_buffer(tmp_buffer);
  1962.                             input_cnt++;break;
  1963.                     default: break;
  1964.                 }
  1965.             }
  1966.             if(reply_format == 0 ){reply_format = 15;}
  1967.             reset();
  1968.             break;
  1969.  
  1970.         case INTOOLTIP:
  1971.             /*
  1972.             @ intooltip link_text
  1973.             @ link_text is a single line (span-element)
  1974.             @ link_text may also be an image URL 'http://some_server/images/my_image.png' or '$module_dir/gifs/my_image.jpg'
  1975.             @ link_text may contain HTML markup
  1976.             @ the canvas will be displayed in a tooltip on 'link_text'
  1977.             @ the canvas is default transparent: use command <a href="#bgcolor">'bgcolor color'</a> to adjust background-color<br />the link text will also be shown with this 'bgcolor'.
  1978.             @ many 'userinput stuff' will use the tooltip_placeholder_div element...only one is defined in the wims-page<br />and are therefor these commands are mutually exclusive.<br />keep this in mind...
  1979.             @%intooltip%size 400,400%xrange -10,10%yrange -10,10%string black,0,0,HelloWorld%intooltip <b>CLICK HERE</b>
  1980.             */
  1981.             if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");}
  1982.             if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");}
  1983.             tooltip_text = get_string(infile,1);
  1984.             if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
  1985.             use_tooltip = 1;
  1986.             break;
  1987.  
  1988.         case JSCURVE:
  1989.         /*
  1990.          @ jscurve color,formula1(x),formula2(x),formula3(x),...
  1991.          @ alternative : jsplot color,formula(x)
  1992.          @ your function will be plotted by the javascript engine of the client browser
  1993.          @ if <a href='trange'>trange</a> is defined, the two functions will be plotted parametric<br /><b>note</b>: use <i>x</i> as variable...and not <i>t</i>. Use keyword <a href='#animate'>animate</a> to animate a point on the curve
  1994.          @ use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e
  1995.          @ use parenthesis and rawmath : use 2*x instead of 2x ; use 2^(sin(x))...etc etc<br />use error console to debug any errors...
  1996.          @ <b>attention</b> : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot !
  1997.          @ no validity check is done by wims.
  1998.          @ 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
  1999.          @ zooming & panning is better than for curves produced by command <a href="#curve">curve color,formula</a> because for avery change in x/y-range the curve is recalculated in javascript
  2000.          @ use keyword <a href='animate'>animate</a> for animating a point on the curve
  2001.          @ use command 'trace_jscurve formula(x)` for tracing
  2002.          @ use command 'jsmath  formula(x)` for calculating and displaying indiviual points on the curve
  2003.          @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet)
  2004.          @ commands plotjump / plotstep are not active for 'jscurve'
  2005.          @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve.
  2006.          @ plotting multiple js-curves on the same canvas <br/>(for example if you want to use 'userdraw clickfill,color' on <a href="#canvastype">canvastype</a> number 111 ,use :<br/> jscurve red,fun1(x),fun2(x)...fun_n(x)<br />  you must specify individual multistrokecolors &amp; multistrokeopacity &amp; multilinewidth for these multiple js-curves to use different colors.<br />otherwise all curves will be the same color...<br />use commands like: <a href="#multistrokecolors">multistrokecolors</a>,<a href="#multilinewidth">multilinewidth</a>, <a href="#multidash">multidash</a><br />, <a href="multistrokeopacity">multistroke</a><br />the <b>color</b> given for the command "jscurve <b>color</b>,formulas(x)" will not be used in that case...<br />but the color argument must still be given in any case (otherwise syntax error...)
  2007.          @%jscurve%size 400,400%xrange -10,10%yrange -10,10%multicolors red,green,blue,orange%multilinewidth 1,1,1%multistrokeopacity 0.5,0.8,1.0%jscurve red,sin(x),1/sin(x),sin(x^2)
  2008.         */
  2009.             stroke_color = get_color(infile,0);
  2010.             if( use_js_math == FALSE){/* add this stuff only once...*/
  2011.                 add_to_js_math(js_include_file);
  2012.                 use_js_math = TRUE;
  2013.             }
  2014.             if( use_js_plot == FALSE){
  2015.                 use_js_plot = TRUE;
  2016.                 add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  2017.             }
  2018.             int use_paramteric = 0;
  2019.             if( tmin != 0 && tmax !=0){use_parametric = 1;}
  2020.             temp = get_string(infile,1);
  2021.             temp = str_replace(temp,",","\",\"");
  2022.             string_length = snprintf(NULL,0,  "jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],tmin,tmax,plot_steps,use_parametric,use_animate);
  2023.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2024.             snprintf(tmp_buffer,string_length,"jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],tmin,tmax,plot_steps,use_parametric,use_animate);
  2025.             add_to_buffer(tmp_buffer);
  2026.             jsplot_cnt++;
  2027.              /* we need to create multiple canvasses, so we may zoom and pan ?? */
  2028.         break;
  2029.  
  2030.         case JSMATH:
  2031.         /*
  2032.             @ jsmath some_math_function
  2033.             @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
  2034.             @ 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
  2035.             @ use command 'inputstyle some_css' for styling the display fields. Use command 'fontsize int' to size the labels 'x' and 'y'
  2036.             @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x instead 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...
  2037.             @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
  2038.             @%jsmath%size 400,400%xrange -10,10%yrange -10,10%jsplot blue,sin(x^2)%jsmath sin(x^2)
  2039.         */
  2040.             if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  2041.             if( use_js_math == FALSE){
  2042.                 add_to_js_math(js_include_file);
  2043.                 use_js_math = TRUE;
  2044.             }
  2045.             add_calc_y(js_include_file,canvas_root_id,get_string(infile,1),font_size,input_style);
  2046.             break;
  2047.         case KILLAFFINE:
  2048.         /*
  2049.         @ killaffine
  2050.         @ keyword : resets the transformation matrix to 1,0,0,1,0,0
  2051.         */
  2052.             use_affine = FALSE;
  2053.             snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
  2054.             break;
  2055.  
  2056.         case KILLROTATE:
  2057.         /*
  2058.          @ killrotate will reset the command <a href="#rotationcenter">rotationcenter xc,yc</a>
  2059.          @ a following rotate command will have the first object point as rotation center
  2060.          @ if not set, the rotation center will remain unchanged
  2061.         */
  2062.             rotation_center= my_newmem(6);
  2063.             snprintf(rotation_center,5,"null");
  2064.          break;
  2065.  
  2066.         case KILLSLIDER:
  2067.         /*
  2068.          @ killslider
  2069.          @ keyword (no arguments required)
  2070.          @ ends grouping of object under a previously defined slider
  2071.         */
  2072.             slider = 0;
  2073.             break;
  2074.  
  2075.         case KILLTRANSLATION:
  2076.         /*
  2077.          @ killtranslation
  2078.          @ alternative : killtranslate
  2079.          @ resets the translation matrix to 1,0,0,1,0,0
  2080.         */
  2081.             use_affine = FALSE;
  2082.             snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
  2083.             break;
  2084.  
  2085.         case LINE:
  2086.         /*
  2087.         @ line x1,y1,x2,y2,color
  2088.         @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
  2089.         @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
  2090.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2091.         @%line%size 400,400%xrange -10,10%yrange -10,10%line 0,1,2,-1,green
  2092.         */
  2093.             for(i=0;i<5;i++){
  2094.                 switch(i){
  2095.                     case 0: double_data[10]= get_real(infile,0);break; /* x-values */
  2096.                     case 1: double_data[11]= get_real(infile,0);break; /* y-values */
  2097.                     case 2: double_data[12]= get_real(infile,0);break; /* x-values */
  2098.                     case 3: double_data[13]= get_real(infile,0);break; /* y-values */
  2099.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  2100.                     if( double_data[10] == double_data[12] ){ /* vertical line*/
  2101.                         double_data[1] = xmin;
  2102.                         double_data[3] = ymax;
  2103.                         double_data[0] = double_data[10];
  2104.                         double_data[2] = double_data[10];
  2105.                     }
  2106.                     else
  2107.                     {
  2108.                         if( double_data[11] == double_data[13] ){ /* horizontal line */
  2109.                             double_data[1] = double_data[11];
  2110.                             double_data[3] = double_data[11];
  2111.                             double_data[0] = ymin;
  2112.                             double_data[2] = xmax;
  2113.                         }
  2114.                         else
  2115.                         {
  2116.                         /* m */
  2117.                         double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
  2118.                         /* q */
  2119.                         double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
  2120.  
  2121.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  2122.  
  2123.                             double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
  2124.                             double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
  2125.                             double_data[0] = xmin;
  2126.                             double_data[2] = xmax;
  2127.                         }
  2128.                     }
  2129.                     decimals = find_number_of_digits(precision);
  2130.                     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,%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,rotation_center,use_offset,use_pattern);
  2131.                     if(onclick > 0){click_cnt++;}
  2132.                     /* click_cnt++;*/
  2133.                     reset();
  2134.                     break;
  2135.                 }
  2136.             }
  2137.             break;
  2138.  
  2139.         case LINES:
  2140.         /*
  2141.         @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n
  2142.         @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color'
  2143.         @ or use multiple commands 'curve color,formula' or "jscurve color,formule" to draw the line <br />(uses more points to draw the line; is however better draggable)
  2144.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2145.         @ <b>attention</b>: the flydraw command "lines" is equivalent to canvasdraw command <a href="#polyline">"polyline"</a>
  2146.         @%lines%size 400,400%xrange -10,10%yrange -10,10%lines green,0,1,1,3,0,0,1,3,0,0,-2,1
  2147.         */
  2148.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  2149.             fill_color = stroke_color;
  2150.             i=0;
  2151.             while( ! done ){     /* get next item until EOL*/
  2152.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2153.                 if(i%2 == 0 ){
  2154.                     double_data[i] = get_real(infile,0); /* x */
  2155.                 }
  2156.                 else
  2157.                 {
  2158.                     double_data[i] = get_real(infile,1); /* y */
  2159.                 }
  2160.                 i++;
  2161.             }
  2162.             decimals = find_number_of_digits(precision);
  2163.             for(c = 0 ; c < i-1 ; c = c+4){
  2164.                 if( double_data[c] == double_data[c+2] ){ /* vertical line*/
  2165.                     double_data[c+1] = xmin;
  2166.                     double_data[c+3] = ymax;
  2167.                     double_data[c+2] = double_data[c];
  2168.                 }
  2169.                 else
  2170.                 {
  2171.                     if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  2172.                         double_data[c+3] = double_data[c+1];
  2173.                         double_data[c] = ymin;
  2174.                         double_data[c+2] = xmax;
  2175.                     }
  2176.                     else
  2177.                     {
  2178.                         /* m */
  2179.                         double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  2180.                         /* q */
  2181.                         double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  2182.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  2183.                         double_data[c+1] = (m)*(xmin)+(q);
  2184.                         double_data[c+3] = (m)*(xmax)+(q);
  2185.                         double_data[c] = xmin;
  2186.                         double_data[c+2] = xmax;
  2187.                     }
  2188.                 }
  2189.                 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,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+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,rotation_center,use_offset,use_pattern);
  2190.                 if(onclick > 0){click_cnt++;}
  2191.                 /* click_cnt++; */
  2192.             }
  2193.             reset();
  2194.             break;
  2195.  
  2196.  
  2197.         case LINEWIDTH:
  2198.         /*
  2199.         @ linewidth int
  2200.         @ default 1
  2201.         @%linewidth%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%line -5,-5,-5,5,red%linewidth 2%line -4,-5,-4,5,green%linewidth 3%line -3,-5,-3,5,blue%linewidth 4%line -2,-5,-2,5,orange%linewidth 1%line -1,-5,-1,5,brown%linewidth 5%line 1,-5,1,5,cyan%linewidth 6%line 3,-5,3,5,purple%linewidth 7%line 5,-5,5,5,black
  2202.         */
  2203.             line_width = (int) (get_real(infile,1));
  2204.             break;
  2205.  
  2206.         case LATTICE:
  2207.         /*
  2208.          @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
  2209.          @ can <b>not</b> be set "onclick" or "drag xy"
  2210.          @%lattice%size 400,400%xrange -10,10%yrange -10,10%fillcolor red%linewidth 2%lattice -10,-10,0,1,1,1,10,10,red%fillcolor blue%lattice 10,-10,0,1,-1,1,10,10,blue
  2211.         */
  2212.             if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
  2213.             for( i = 0; i<9; i++){
  2214.                 switch(i){
  2215.                     case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
  2216.                     case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
  2217.                     case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
  2218.                     case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
  2219.                     case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
  2220.                     case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
  2221.                     case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
  2222.                     case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
  2223.                     case 8: stroke_color=get_color(infile,1);
  2224.                         decimals = find_number_of_digits(precision);
  2225.                         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,%d); ",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix,use_filled);
  2226.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2227.                         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,%d); ",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix,use_filled);
  2228.                         add_to_buffer(tmp_buffer);break;
  2229.                     default:break;
  2230.                 }
  2231.             }
  2232.             reset();
  2233.             break;
  2234.  
  2235.         case LEVELCURVE:
  2236.         /*
  2237.         @ levelcurve color,expression in x/y,l1,l2,...
  2238.         @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
  2239.         @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...)
  2240.         @ 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
  2241.         @ note : the arrays for holding the javascript data are limited in size
  2242.         @ note : reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...)
  2243.         @%levelcurve%size 400,400%xrange -10,10%yrange -10,10%levelcurve red,x*y,1,2,3,4
  2244.         */
  2245.             fill_color = get_color(infile,0);
  2246.             char *fun1 = get_string_argument(infile,0);
  2247.             if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  2248.             i = 0;
  2249.             done = FALSE;
  2250.             while( !done ){
  2251.              double_data[i] = get_real(infile,1);
  2252.              i++;
  2253.             }
  2254.             for(c = 0 ; c < i; c++){
  2255.              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,%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,rotation_center,use_offset,use_pattern);
  2256.              if(onclick > 0){click_cnt++;}
  2257.              /* click_cnt++; */
  2258.             }
  2259.             reset();
  2260.             break;
  2261.  
  2262.         case LEGEND:
  2263.         /*
  2264.         @ legend string1:string2:string3....string_n
  2265.         @ will be used to create a legend for a graph
  2266.         @ also see command <a href='#piechart'>'piechart'</a>
  2267.         @ will use the same colors per default as used in the graphs : use command <a href='#legendcolors'>'legendcolors'</a> to override the default
  2268.         @ use command <a href="#fontsize">fontsize</a> to adjust. (command "fontfamily" is not active for command "legend")
  2269.         @%legend%size 400,400%xrange -10,10%yrange -10,10%fontsize 8%legend legend 1:legend 2:legend 3%%legendcolors red:green:bluegrid 1,1,grey
  2270.         */
  2271.             temp = get_string(infile,1);
  2272.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2273.             legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */
  2274.             fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
  2275.             break;
  2276.  
  2277.         case LEGENDCOLORS:
  2278.         /*
  2279.         @ legendcolors color1:color2:color3:...:color_n
  2280.         @ 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
  2281.         @ make sure the number of colours match the number of legend items
  2282.         @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
  2283.         @%legencolors%size 400,400%xrange -10,10%yrange -10,10%fontsize 8%legend legend 1:legend 2:legend 3%legendcolors red:green:blue%grid 1,1,grey
  2284.         */
  2285.             if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
  2286.             temp = get_string(infile,1);
  2287.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2288.             fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
  2289.             break;
  2290.  
  2291.         case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
  2292.         /*
  2293.         @ linegraph x1:y1:x2:y2...x_n:y_n
  2294.         @ will plot your data in a graph
  2295.         @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a>
  2296.         @ can be used together with freestyle x-axis/y-axis texts : see commands <a href='#xaxis'>'xaxis'</a>,<a href='#xaxisup'>'xaxisup'</a> and <a href='#yaxis'>'yaxis'</a>
  2297.         @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner
  2298.         @ also see command <a href='#piechart'>'piechart'</a>
  2299.         @ multiple linegraphs may be used in a single plot
  2300.         @ note: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
  2301.         @ <ul><li>use command <a href='#strokecolor'>'strokecolor'</a> before a command 'linegraph' to set the color of this graph</li><li>use command <a href='#linewidth'>'linewidth'</a> before command 'linegraph' to set linewidth of this graph</li><li>use keyword <a href='#dashed'>'dashed'</a> before command 'linegraph' to set dashing of the graph</li><li>if dashing is set, use command <a href='#dashtype'>'dashtype'</a> before command 'linegraph' to set the type of dashing of the (individual) graph</li></ul>
  2302.         @%linegraph%size 400,400%xrange -10,10%yrange -10,10%strokecolor red%linegraph -10:1:-5:-1:3:3:10:-5%strokecolor blue%linegraph -10:-1:-5:1:3:-3:10:5%dashed%strokecolor green%linegraph -10:2:-5:-2:3:4:10:2%grid 1,1,grey
  2303.         */
  2304.             temp = get_string(infile,1);
  2305.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2306.             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);
  2307.             linegraph_cnt++;
  2308.             reset();
  2309.             break;
  2310.  
  2311.         case MATHML:
  2312.         /*
  2313.         @ mathml x1,y1,x2,y2,mathml_string
  2314.         @ mathml will be displayed in a rectangle left top (x1:y1)...<br />x2 and y2 are still needed, but not used as the right bottom corner of the embedded div element.
  2315.         @ in case of drag(xy|x|y) | onclick the div rectangle left to corner will be the drag-anchor  of the mathml object
  2316.         @ can be set onclick <br />javascript:read_dragdrop(); will return click numbers of mathml-objects<br />if 4 click_able object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object
  2317.         @ can be set draggable<br /> the javascript:read_dragdrop() will return all coordinates <br />in same order as the canvas script: unmoved object will have their original coordinates...
  2318.         @ snaptogrid is supported...snaptopoints will work, but use with care...due to the primitive dragging<br />technically: the dragstuff library is not used...the mathml is embedded in a new div element and not in the html5-canvas
  2319.         @ when clicked, the mathml object will be drawn in red color; the div background color will be determined by the <a href="#fillcolor">'fillcolor'</a> and <a href="#opacity">'opacity'</a> settings
  2320.         @ userdraw may be combined with 'mathml' ; the read_canvas() will contain the drawing.
  2321.         @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick  mathml
  2322.         @ other drag objects (circles/rects etc) are supported , but read_dragdrop() will probably be difficult to interpret...
  2323.         @ 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 /><b>attention</b>: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();"
  2324.         @ 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....
  2325.         @%mathml_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%strokecolor red%mathml -5,5,0,0,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml366290"><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex"  columnalign=" left "  columnlines=" none "  rowlines=" none "  ><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mn>2</mn></mfrac></mstyle><mo>&sdot;</mo><msup><mi>x</mi> <mn>2</mn></msup></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><msup><mi>x</mi> <mn>2</mn></msup></mrow></mfrac></mstyle></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>%onclick%strokecolor blue%mathml 5,5,0,0,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml580175" ><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex"  columnalign=" left "  columnlines=" none "  rowlines=" none "  ><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></mfrac></mstyle></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span> 
  2326.         @%mathml_drag%size 400,400%xrange -10,10%yrange -10,10%drag xy%strokecolor red%mathml -5,5,0,0,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml366290"><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex"  columnalign=" left "  columnlines=" none "  rowlines=" none "  ><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mn>2</mn></mfrac></mstyle><mo>&sdot;</mo><msup><mi>x</mi> <mn>2</mn></msup></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><msup><mi>x</mi> <mn>2</mn></msup></mrow></mfrac></mstyle></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>%drag xy%strokecolor blue%mathml 5,5,0,0,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml580175" ><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex"  columnalign=" left "  columnlines=" none "  rowlines=" none "  ><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></mfrac></mstyle></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>%#click left top corner...than drag...      
  2327.         */
  2328.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  2329.             for(i=0;i<5;i++){
  2330.                 switch(i){
  2331.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2332.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2333.                     case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed : overflow  */
  2334.                     case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed : overflow */
  2335.                     case 4: decimals = find_number_of_digits(precision);
  2336.                             temp = get_string(infile,1);
  2337.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2338.                             string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity);
  2339.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2340.                             snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity);
  2341.                             add_to_buffer(tmp_buffer);
  2342.                             if(onclick == 1 || onclick == 2 ){click_cnt++;}
  2343.                             /*
  2344.                              in case inputs are present , trigger adding the read_mathml()
  2345.                              if no other reply_format is defined
  2346.                              note: all other reply types will include a reading of elements with id='mathml'+p)
  2347.                              */
  2348.                             if(strstr(temp,"mathml0") != NULL){
  2349.                              if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
  2350.                             }
  2351.                             break;
  2352.                     default:break;
  2353.                 }
  2354.             }
  2355.             reset();
  2356.             break;
  2357.  
  2358.         case MOUSE:
  2359.         /*
  2360.          @ mouse color,fontsize
  2361.          @ will display the cursor (x:y) coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
  2362.          @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2363.          @%mouse%size 400,400%xrange -10,10%yrange -10,10%mouse red,22
  2364.         */
  2365.             stroke_color = get_color(infile,0);
  2366.             font_size = (int) (get_real(infile,1));
  2367.             tmp_buffer = my_newmem(26);
  2368.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2369.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
  2370.             break;
  2371.  
  2372.  
  2373.         case MOUSE_DEGREE:
  2374.         /*
  2375.          @ mouse_degree color,fontsize
  2376.          @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in 'color' and 'font size'<br /> using a fontfamily Ariel
  2377.          @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
  2378.          @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2379.          @%mouse_degree%size 400,400%xrange -10,10%yrange -10,10%userdraw arc,blue%precision 100000%mouse_degree red,22
  2380.         */
  2381.             stroke_color = get_color(infile,0);
  2382.             font_size = (int) (get_real(infile,1));
  2383.             tmp_buffer = my_newmem(26);
  2384.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2385.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
  2386.             js_function[JS_FIND_ANGLE] = 1;
  2387.             break;
  2388.         case MOUSE_DISPLAY:
  2389.         /*
  2390.          @ display TYPE,color,fontsize
  2391.          @ TYPE may be x | y | xy | degree | radian | radius
  2392.          @ 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 or radians for commands "userdraw arc,color" or protractor , ruler (if set dynamic)
  2393.          @ use commands 'xunit' and / or 'yunit' to add the units to the mouse values.<br />The "degree | radian" will always have the appropriate symbol)
  2394.          @ just like commands 'mouse','mousex','mousey','mouse_degree'...only other name)
  2395.          @%display_x%size 400,400%xrange -10,10%yrange -10,10%xunit \\u212B%display x,red,22
  2396.          @%display_y%size 400,400%xrange -10,10%yrange -10,10%yunit seconds%display y,red,22
  2397.          @%display_xy%size 400,400%xrange -10,10%yrange -10,10%xunit centimetre%yunit seconds%display xy,red,22%userdraw segemens,blue
  2398.          @%display_deg%size 400,400%xrange -10,10%yrange -10,10%display degree,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
  2399.          @%display_rad%size 400,400%xrange -10,10%yrange -10,10%display radian,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
  2400.          @%display_radius%size 400,400%xrange -10,10%yrange -10,10%xunit cm%xunit \\u212b%display radius,red,22%userdraw circle,blue
  2401.         */
  2402.         temp = get_string_argument(infile,0);
  2403.         if( strstr(temp,"xy") != NULL ){
  2404.             int_data[0] = 2;
  2405.         }else{
  2406.             if( strstr(temp,"y") != NULL ){
  2407.                 int_data[0] = 1;
  2408.             }else{
  2409.                 if( strstr(temp,"x") != NULL ){
  2410.                     int_data[0] = 0;
  2411.                 }else{
  2412.                     if(strstr(temp,"degree") != NULL){
  2413.                         int_data[0] = 3;
  2414.                         js_function[JS_FIND_ANGLE] = 1;
  2415.                     }else{
  2416.                         if(strstr(temp,"radian") != NULL){
  2417.                             int_data[0] = 4;
  2418.                             js_function[JS_FIND_ANGLE] = 1;
  2419.                         }else{
  2420.                             if(strstr(temp,"radius") != NULL){
  2421.                                 int_data[0] = 5;
  2422.                             }else{
  2423.                                 int_data[0] = 2;
  2424.                             }
  2425.                         }
  2426.                     }
  2427.                 }
  2428.             }
  2429.         }
  2430.         stroke_color = get_color(infile,0);
  2431.         font_size = (int) (get_real(infile,1));
  2432.         tmp_buffer = my_newmem(26);
  2433.         snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2434.         add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
  2435.         break;
  2436.  
  2437.         case MOUSE_PRECISION:
  2438.         /*
  2439.             @ precision int
  2440.             @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
  2441.             @ may be used / changed before every object
  2442.             @ In case of user interaction (like 'userdraw' or 'multidraw') this value will be used to determine the amount of decimals in the reply / answer
  2443.             @%precision%size 400,400%xrange -10,10%yrange -10,10%precision 1%userdraw segement,red
  2444.         */
  2445.             precision = (int) (get_real(infile,1));
  2446.             if(precision < 1 ){precision = 1;};
  2447.             break;
  2448.  
  2449.         case MOUSEX:
  2450.         /*
  2451.          @ mousex color,fontsize
  2452.          @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using the fontfamily Ariel
  2453.          @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2454.  
  2455.         */
  2456.             stroke_color = get_color(infile,0);
  2457.             font_size = (int) (get_real(infile,1));
  2458.             tmp_buffer = my_newmem(26);
  2459.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2460.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
  2461.             break;
  2462.         case MOUSEY:
  2463.         /*
  2464.          @ mousey color,fontsize
  2465.          @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
  2466.          @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2467.  
  2468.         */
  2469.             stroke_color = get_color(infile,0);
  2470.             font_size = (int) (get_real(infile,1));
  2471.             tmp_buffer = my_newmem(26);
  2472.             snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2473.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
  2474.             break;
  2475.  
  2476.         case MULTIDASH:
  2477.         /*
  2478.          @ multidash 0,1,1
  2479.          @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <em>'multifill points,circle,segments'</em>, are dashed
  2480.          @ use before command <a href='#multidraw'>'multidraw'</a>
  2481.          @ if not set all objects will be set 'not dashed'...<br />unless a generic keyword <em>'dashed'</em> was given before command <em>'multidraw'</em>
  2482.          @ the dash-type is not -yet- adjustable <br />(e.g. command <em>dashtype line_px,space_px</em> will give no control over multidraw objects)
  2483.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  2484.          @ always use the same sequence as is used for 'multidraw'
  2485.         */
  2486.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2487.             temp = get_string(infile,1);
  2488.             temp = str_replace(temp,",","\",\"");
  2489.             fprintf(js_include_file,"var multidash = [\"%s\"];",temp);
  2490.             reset();/* if command 'dashed' was given...reset to not-dashed */
  2491.             break;
  2492.  
  2493.         case MULTIDRAW:
  2494.         /*
  2495.          @ multidraw obj_type_1,obj_type_2...obj_type_11
  2496.          @ for simple single object user drawings you could also use command <a href="#userdraw">'userdraw'</a>
  2497.          @ implemented obj_types:<ul><li>point | points </li><li>circle | circles </li><li>line | lines </li><li>segment | segments </li><li>arrow | arrows <br />use command 'arrowhead int' for size (default value 8 pixels)</li><li>rect | rects </li><li>closedpoly<br /><b>only one</b> closedpolygon may be drawn.The number of 'corner points' is not preset (e.g. not limited,freestyle)<br />the polygone is closed when clicking on the first point again..(+/- 10px) </li><li>triangle | triangles</li><li>parallelogram | parallelograms</li><li>poly[3-9] | polys[3-9] draw 3...9 point polygone(s): polys3 is of course triangles </li></ul>
  2498.          @ additionally objects may be user labelled, using obj_type 'text'...<br />in this case allways a text input field and if <a href='#multiuserinput'> multiuserinput=1 </a> also (x:y) inputfields will be added to the page.<br />use commands 'fontfamily' and 'fontcolor' to adjust. (command 'multistrokeopacity' may be set to adjust text opacity)<br />note: text is always centered on the mouse-click or user-input coordinates !<br />note: no keyboard listeners are used
  2499.          @ it makes no sense using something like "multidraw point,points" ... <br />something like "multidraw polys4,polys7" will only result in drawing a '4 point polygone' and not a '7 point polygone' : this is a design flaw and not a feature...
  2500.          @ 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)
  2501.          @ buttons for changing the obj_type (and incase of 'multiuserinput' , some inputfields and buttons) <br />will be present in the reserved div 'tooltip_div' and can be styled using command 'inputstyle some_css'
  2502.          @ the button label will be default the 'object primitive name' (like 'point', 'circles').<br />If you want a different label (e.g. an other language) ,use command 'multilabel'<br />for example in dutch: <br /><em>multilabel cirkel,lijnstuk,punten,STOP<br />multidraw circle,segment,points</em><br />(see command <a href='#multilabel'>'multilabel'</a> for more details)
  2503.          @ multidraw is incompatible with command 'tooltip' (the reserved div_area is used for the multidraw control buttons)
  2504.          @ all 'multidraw' drawings will scale on zooming.<br />this in contrast to the command <a href="#userdraw">'userdraw'</a>.
  2505.          @ wims will <b>not</b> check the amount or validity of your command arguments ! <br />( use javascript console to debug any typo's )
  2506.          @ a local function read_canvas%d will read all userbased drawings.<br />The output is always a 11 lines string with fixed sequence.<br/>line 1 = points_x+";"+points_y+"\\n"<br/>line 2 = circles_x+";"+circlespoint_y+";"+multi_radius+"\\n"<br/>line 3 = segments_x+";"+segments_y+"\\n"<br/>line 4 = arrows_x+";"+arrows_y+"\\n"<br/>line 5 = lines_x+";"+lines_y+"\\n"<br/>line 6 = triangles_x+";"+triangles_y+"\\n"<br/>line 7 = polys[3-9]_x+";"+polys[3-9]_y+"\\n"<br/>line 8 = rects_x +";"+rects_y+"\\n"<br />line 9 = closedpoly_x+";"+closedpoly_y+"\\n"<br/>line 10 = parallelogram_x+";"+parallelogram_y"\\n"<br/>line 11 = text_x+";"+text_y+";"+text"\\n"<br/>The x/y-data are in x/y-coordinate system and display precision may be set by a previous command 'precision 0 | 10 | 100 | 1000...'<br />In case of circles the radius is -for the time being- rounded to pixels<br /><b>use the wims "direct exec" tool to see the format of the reply</b>
  2507.          @ It is best to prepare / format the student reply in clientside javascript.<br />However in wims language you could use something like this<br />for example you are interested in the polys5 drawings of a pupil (the pupil may draw multiple poly5 objects...)<br />note: the reply for 2 poly5's is:  x11,x12,x13,x14,x15,x21,x22,x23,x24,x25 ; y11,y12,y13,y14,y15,y21,y22,y23,y24,y25<br />rep = !line 7 of reply <br />rep = !translate ';' to '\\n' in $rep <br />pts = 5 # 5 points for polygon <br />x_rep = !line 1 of $rep <br />y_rep = !line 2 of $rep <br />tot = !itemcnt $x_rep <br />num_poly = $[$tot/$pts] <br />idx = 0 <br />!for p=1 to $num_poly <br />&nbsp;!for s=1 to $pts <br />&nbsp;&nbsp;!increase idx <br />&nbsp;&nbsp;X = !item $idx of $x_rep <br />&nbsp;&nbsp;Y = !item $idx of $y_rep <br />&nbsp;&nbsp;# do some checking <br />&nbsp;!next s <br />!next p <br />
  2508.          @ <b>attention</b>: for command argument 'closedpoly' only one polygone can be drawn.<br />The last point (e.g. the point clicked near the first point) of the array is removed.
  2509.          @ <em>technical: all 10 'draw primitives' + 'text' will have their own -transparent- PNG bitmap canvas. <br />So for example there can be a points_canvas entirely separated from a line_canvas.<br />This to avoid the need for a complete redraw when something is drawn to the canvas...(eg only the object_type_canvas is redrawn)<br />This in contrast too many very slow do-it-all HTML5 canvas javascript libraries.<br />The mouselisteners are attached to the canvas-div element.</em>
  2510.          @%multidraw%size 400,400%xrange -10,10%yrange -10,10%multidash 1,0%multilinewidth 1,2%multistrokecolors red,blue%multisnaptogrid 1,1%multilabel LINES,CIRCLES,STOP DRAWING%multidraw lines,circles
  2511.          @%multidraw_all%size 400,400%xrange -5,5%yrange -5,5%hline 0,0,black%vline 0,0,black%grid 1,1,grey%filled%dashed%snaptogrid%fillcolor orange%opacity 200,50%drag xy%fcircle 0,0,50,red%multifillcolors orange,yellow,red,green,lightgreen,orange,red%multistrokecolors red,green,blue,orange,cyan,green,blue%multilinewidth 3,2,1,3,2,1,3%multistrokeopacity 0.8,0.7,0.6,0.5,0.6,0.7,0.4%multifillopacity 0.2,0.2,0.6,0.5,0.4,0.5,0.2%multiuserinput 1,0,1,0,1,0,1%multifill 1,0,1,0,1,0,0%multilabel POLYGON,POINTS,CIRCLES,SEGMENTS,POLY5,LINES,VECTORS,stop drawing%multidraw closedpoly,points,circles,segments,poly5,lines,arrows
  2512.         */
  2513.         //    if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2514.             if( use_userdraw == TRUE ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");}
  2515.             use_userdraw = TRUE;
  2516.             /* LET OP max 6 DRAW PRIMITIVES + TEXT */
  2517.             temp = get_string(infile,1);
  2518.             temp = str_replace(temp,",","\",\"");
  2519.             /* if these are not set, set the default values for the 6 (!!!)  draw_primitives + draw_text */
  2520.             fprintf(js_include_file,"\
  2521.             if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null  ){ var multistrokecolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\
  2522.             if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){ var multifillcolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\
  2523.             if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null ){ var multistrokeopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\
  2524.             if( typeof(multifillopacity) === 'undefined' &&  multifillopacity == null ){ var multifillopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\
  2525.             if( typeof(multilinewidth) === 'undefined' && multilinewidth == null ){ var multilinewidth = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
  2526.             if( typeof(multifill) === 'undefined' && multifill == null ){ var multifill = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
  2527.             if( typeof(multidash) === 'undefined' && multidash == null ){ var multidash = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
  2528.             if( typeof(multilabel) === 'undefined' && multilabel == null ){ var multilabel = [\"%s\",\"stop drawing\"];};\
  2529.             if( typeof(multiuserinput) === 'undefined' && multiuserinput == null ){ var multiuserinput= ['0','0','0','0','0','0','0','0'];};\
  2530.             if( typeof(multisnaptogrid) == 'undefined' && multisnaptogrid == null){var multisnaptogrid;if( x_use_snap_to_grid == 1 && y_use_snap_to_grid == 1){ multisnaptogrid = [1,1,1,1,1,1,1];}else{if( x_use_snap_to_grid == 1 ){ multisnaptogrid = [2,2,2,2,2,2,2];}else{if( y_use_snap_to_grid == 1 ){ multisnaptogrid = [3,3,3,3,3,3,3];}else{ multisnaptogrid = [0,0,0,0,0,0,0];};};};};\
  2531.             var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';",
  2532.             stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,
  2533.             fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,
  2534.             stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,
  2535.             fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,
  2536.             line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,
  2537.             use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,
  2538.             use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,
  2539.             temp,arrow_head,font_color,font_family);
  2540.  
  2541.             if(strstr(temp,"text") != NULL){
  2542.              if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  2543.             }
  2544.  
  2545.             /* the canvasses range from 1000 ... 1008 */
  2546.             add_js_multidraw(js_include_file,canvas_root_id,temp,input_style);
  2547.             reply_precision = precision;
  2548.             if( reply_format == 0){reply_format = 29;}
  2549.             reset();/* if command 'filled' / 'dashed' was given...reset all */
  2550.             break;
  2551.         case MULTILABEL:
  2552.         /*
  2553.          @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text'
  2554.          @ use before command <a href='#multidraw'>'multidraw'</a>
  2555.          @ if not set all labels (e.g. the value='' of input type 'button') will be set by the english names for the draw_primitives (like 'point','circle'...)
  2556.          @ the 'stop drawing' button text <b>must</b> be the last item on the 'multilabel' -list <br />for example:<br /><em>multilabel punten,lijnen,Stop met Tekenen<br />multidraw points,lines</em>
  2557.          @ all buttons can be 'styled' by using commant 'inputstyle'<br /><b>note:</b><em>If you want to add some CSS style to the buttons...<br />the id's of the 'draw buttons' are their english command argument<br />(e.g. id="canvasdraw_points" for the draw points button).<br />the id of the 'stop drawing' button is "canvasdraw_stop_drawing".<br />the id of the "OK" button is"canvasdraw_ok_button"</em>
  2558.          @ wims will not check the amount or validity of your input
  2559.          @ always use the same sequence as is used for 'multidraw'
  2560.         */
  2561.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2562.             temp = get_string(infile,1);
  2563.             temp = str_replace(temp,",","\",\"");
  2564.             fprintf(js_include_file,"var multilabel = [\"%s\"];",temp);
  2565.             break;
  2566.         case MULTILINEWIDTH:
  2567.         /*
  2568.          @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8
  2569.          @ use before command <a href='#multidraw'>'multidraw'</a>
  2570.          @ if not set all line width will be set by a previous command <em>'linewidth int'</em>
  2571.          @ use these up to 7 different line widths for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em>
  2572.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  2573.          @ always use the same sequence as is used for 'multidraw'
  2574.         */
  2575.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2576.             temp = get_string(infile,1);
  2577.             temp = str_replace(temp,",","\",\"");
  2578.             fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp);
  2579.             break;
  2580.         case MULTIFILL:
  2581.         /*
  2582.          @ multifill 0,0,1,0,1,0,0
  2583.          @ meaning draw objects no. 3 and 5, in the list of command 'multifill', are filled<br />(if the object is fillable...and not a line,segment,arrow or point...)
  2584.          @ use before command <a href='#multidraw'>'multidraw'</a>
  2585.          @ if not set all objects -except point|points-  will be set 'not filled'...<br />unless a command 'filled' was given before command 'multifill'
  2586.          @ only suitable for draw_primitives like 'circle | circles' , 'triangle | triangles' and 'polygon'
  2587.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  2588.          @ always use the same sequence as is used for 'multidraw'
  2589.         */
  2590.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2591.             temp = get_string(infile,1);
  2592.             temp = str_replace(temp,",","\",\"");
  2593.             fprintf(js_include_file,"var multifill = [\"%s\"];",temp);
  2594.             break;
  2595.  
  2596.         case MULTIFILLCOLORS:
  2597.         /*
  2598.          @ multifillcolors color_name_1,color_name_2,...,color_name_8
  2599.          @ use before command <a href='#multidraw'>'multidraw'</a>
  2600.          @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be 'stroke_color' , 'fill_opacity'
  2601.          @ use these up to 6 colors for the draw primitives used by command 'multidraw obj_type_1,obj_type_2...obj_type_n
  2602.          @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
  2603.          @ always use the same sequence as is used for 'multidraw'
  2604.          @ can also be used with command <a href='#userdraw'>'userdraw clickfill,color'</a> when more than one fillcolor is wanted.<br />in that case use for example <a href='#replyformat'>replyformat 10</a> ... reply=x1:y1:color1,x2:y2:color2...<br />the colors will restart at the first color, when there are more fill-clicks than multi-fill-colors<br />if more control over the used colours is wanted , see command <a href='#colorpalette'>colorpalette color1,color2...</a>
  2605.         */
  2606.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2607.             fprintf(js_include_file,"var multifillcolors = [");
  2608.             while( ! done ){
  2609.                 temp = get_color(infile,1);
  2610.                 fprintf(js_include_file,"\"%s\",",temp);
  2611.             }
  2612.             fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
  2613.             break;
  2614.  
  2615.         case MULTIFILLOPACITY:
  2616.         /*
  2617.          @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8
  2618.          @ float values 0 - 1 or integer values 0 - 255
  2619.          @ use before command <a href='#multidraw'>'multidraw'</a>
  2620.          @ if not set all fill opacity_ will be set by previous command <em>'opacity int,int'</em> and keyword <em>'filled'</em>
  2621.          @ use these up to 7 different stroke opacities for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_y</em>
  2622.          @ wims will not check the amount or validity of your input
  2623.          @ always use the same sequence as is used for 'multidraw'
  2624.         */
  2625.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2626.             temp = get_string(infile,1);
  2627.             temp = str_replace(temp,",","\",\"");
  2628.             fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp);
  2629.             break;
  2630.         case MULTISNAPTOGRID:
  2631.         /*
  2632.          @ multisnaptogrid 0,1,1
  2633.          @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <em>'multifill points,circle,segments'</em>, will snap to the xy-grid (default 1 in x/y-coordinate system: see command <a href='#snaptogrid'>'snaptogrid'</a>)
  2634.          @ only the x-values snap_to_grid: <em>multisnaptogrid 0,2,2</em>
  2635.          @ only the y-values snap_to_grid: <em>multisnaptogrid 0,3,3</em>
  2636.          @ mixing allowed: <em>multisnaptogrid 1,2,3,0</em> e.g. the first object will snap to the xy-grid, the second draw object will snap to the x-values, the third object will snap to the y-valeus of the grid, the last object may be placed anywhere on the canvas
  2637.          @ use before command <a href='#multidraw'>'multidraw'</a>
  2638.          @ if not set all objects will be set 'no snap'...<br />unless a generic command 'snaptogrid' was given before command 'multidraw'
  2639.          @ commands <a href='#xsnaptogrid'>'xsnaptogrid'</a>, <a href='#ysnaptogrid'>'ysnaptogrid'</a>, <a href='#snaptofunction'>'snaptofunction'</a> and <a href='#snaptopoints'>'snaptopoints</a> x1,y1,x2,y2...' are <b>not</b> supported at this time
  2640.          @ always use the same sequence as is used for 'multidraw'
  2641.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  2642.         */
  2643.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2644.             temp = get_string(infile,1);
  2645.             temp = str_replace(temp,",","\",\"");
  2646.             fprintf(js_include_file,"var multisnaptogrid = [\"%s\"];",temp);
  2647.             reset();/* if command 'dashed' was given...reset to not-dashed */
  2648.             break;
  2649.         case MULTISTROKECOLORS:
  2650.         /*
  2651.          @ multistrokecolors color_name_1,color_name_2,...,color_name_8
  2652.          @ use before command <a href='#multidraw'>'multidraw'</a>
  2653.          @ if not set all colors will be 'stroke_color' , 'stroke_opacity'
  2654.          @ use these up to 6 colors for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em>
  2655.          @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
  2656.          @ always use the same sequence as is used for 'multidraw'
  2657.         */
  2658.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2659.             fprintf(js_include_file,"var multistrokecolors = [");
  2660.             while( ! done ){
  2661.                 temp = get_color(infile,1);
  2662.                 fprintf(js_include_file,"\"%s\",",temp);
  2663.             }
  2664.             fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
  2665.             break;
  2666.         case MULTISTROKEOPACITY:
  2667.         /*
  2668.          @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7
  2669.          @ float values 0 - 1 or integer values 0 - 255
  2670.          @ use before command <a href='#multidraw'>'multidraw'</a>
  2671.          @ if not set all stroke opacity_ will be set by previous command <em>'opacity int,int'</em>
  2672.          @ use these up to 7 different stroke opacities for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em>
  2673.          @ wims will not check the amount or validity of your input
  2674.          @ always use the same sequence as is used for 'multidraw'
  2675.         */
  2676.             if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2677.             temp = get_string(infile,1);
  2678.             temp = str_replace(temp,",","\",\"");
  2679.             fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp);
  2680.             break;
  2681.  
  2682.         case MULTIUSERINPUT:
  2683.         /*
  2684.         @ multiuserinput 0,1,1,0
  2685.         @ meaning, when the command 'multidraw' is used <br />multidraw circles,points,lines,triangles<br />objects 'points' and 'lines' may additionally be 'drawn' by direct input (inputfields)<br/>all other objects must be drawn with a mouse
  2686.         @ in case of circle | circles a third inputfield for Radius (R) is added.<br />the radius must be in the x/y coordinate system (x-range) and <b>not</b> in pixels...students don't think in pixels.<br />note: R-values will not snap-to-grid
  2687.         @ in case of line(s) | segment(s) | arrow(s) the user should write <b>x1:y1</b> in the first inputfield and <b/>x2:y2</b> in the second.<br />These 'hints' are pre-filled into the input field.<br />other coordinate delimiters are ";" and "," e.g. <b>x1;y1</b> or <b>x1,y1</b>.<br />An error message (alert box) will popup when things are not correctly...
  2688.         @ in case of a triangle | poly3, three inputfields are provided.
  2689.         @ in case of 'text' and multiuserinput=1 , 3 inputfields will be shown : x,y,text
  2690.         @ in case of 'text' and multiuserinput=0 , 1 inputfield will be shown : text ... a mouse click will place the text on the canvas.
  2691.         @ may be styled using command <a href="#inputstyle">"inputstyle"</a>
  2692.         @ an additional button 'stop drawing' may be used to combine userbased drawings with 'drag&amp;drop' or 'onclick' elements
  2693.         @ when exercise if finished (status=done) the buttons will not be shown.<br />To override this default behaviour use command / keyword 'status'
  2694.         @ use before command <a href='#multidraw'>'multidraw'</a>
  2695.         @ always use the same sequence as is used for 'multidraw'
  2696.         */
  2697.             /* simple rawmath and input check */
  2698.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  2699.             temp = get_string(infile,1);
  2700.             temp = str_replace(temp,",","\",\"");
  2701.             fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp);
  2702.             break;
  2703.  
  2704.         case NOXAXIS:
  2705.         /*
  2706.         @ noaxis
  2707.         @ keyword
  2708.         @ if set, the automatic x-axis numbering will be ignored
  2709.         @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="grid">grid</a>
  2710.         @ to be used before command grid (see <a href="#grid">command grid</a>)
  2711.         */
  2712.             fprintf(js_include_file,"x_strings = {};x_strings_up = [];\n");
  2713.             use_axis_numbering = -1;
  2714.             break;
  2715.         case NOYAXIS:
  2716.         /*
  2717.         @ noayis
  2718.         @ keyword
  2719.         @ if set, the automatic y-axis numbering will be ignored
  2720.         @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="grid">grid</a>
  2721.         @ to be used before command grid (see <a href="#grid">command grid</a>)
  2722.         */
  2723.             fprintf(js_include_file,"y_strings = {};\n");
  2724.             break;
  2725.         case NUMBERLINE:
  2726.         /*
  2727.         @ numberline x0,x1,xmajor,xminor,y0,y1
  2728.         @ numberline is using xrange/yrange system for all dimensions
  2729.         @ multiple numberlines are allowed ; combinations with command <a href='#grid'>grid</a> is allowed; multiple commands <a href='#xaxis'>xaxis numbering</a> are allowed
  2730.         @ x0 is start x-value in xrange
  2731.         @ x1 is end x-value in xrange
  2732.         @ xmajor is step for major division
  2733.         @ xminor is divisor of xmajor; using small (30% of major tick) tick marks: this behaviour is 'hardcoded'
  2734.         @ is xminor is an even divisor, an extra tickmark (60% of major tick) is added to the numberline : this behaviour is 'hardcoded'
  2735.         @ y0 is bottom of numberline; y1 endpoint of major tics
  2736.         @ use command <a href="#linewidth">linewidth</a> to control appearance
  2737.         @ use <a href="#strokecolor">strokecolor</a> and <a href="#opacity">opacity</a> to controle measure line
  2738.         @ for all ticks linewidth and color / opacity are identical.
  2739.         @ if command <a href="#xaxis">xaxis</a> or <a href="#xaxisup">xaxisup</a> is not defined, the labeling will be on major ticks: x0...x1
  2740.         @ use <a href="#fontfamily">fontfamily</a> and <a href="#fontcolor">fontcolor</a> to control fonts settings
  2741.         @ may be used together with <a href="#userdraw">userdraw</a> , <a href="#multidraw">multidraw</a> and <a href="#drag">user drag</a> command family for the extra object drawn onto the numberline
  2742.         @ <a href="#snaptogrid">snaptogrid, snaptopoints etc</a> and <a href="#zoom">zooming and panning</a> is supported
  2743.         @ onclick and dragging of the numberline are not -yet- supported
  2744.         @ note: incase of multiple numberlines, make sure the numberline without special x-axis numbering (e.g. ranging from xmin to xmax) comes first !
  2745.         @%numberline%size 400,400%xrange -10,10%yrange -10,10%precision 1%strokecolor black%numberline -8,8,1,6,-4,-3.5%strokecolor red%xaxis -4:AA:-2:BB:2:CC:4:DD%numberline -8,8,1,2,4,4.5%strokecolor green%xaxisup -4:AAA:-2:BBB:2:CCC:4:DDD%numberline -8,8,1,3,2,2.5%strokecolor blue%xaxis -4:AAAA:-2:BBBB:2:CCCC:4:DDDD%numberline -8,8,1,4,0,0.5%strokecolor brown%xaxis -4:AAAAA:-2:BBBBB:2:CCCCC:4:DDDDD%numberline -8,8,1,5,-2,-1.5%zoom red      
  2746.         */
  2747.             if( js_function[DRAW_NUMBERLINE] != 1 ){ js_function[DRAW_NUMBERLINE] = 1;}
  2748.             for(i=0;i<6;i++){
  2749.                 switch(i){
  2750.                     case 0: double_data[0] = get_real(infile,0);break;/* xmin */
  2751.                     case 1: double_data[1] = get_real(infile,0);break;/* xmax */
  2752.                     case 2: double_data[2] = get_real(infile,0);break;/* xmajor */
  2753.                     case 3: double_data[3] = get_real(infile,0);break;/* xminor */
  2754.                     case 4: double_data[4] = get_real(infile,0);break;/* ymin */
  2755.                     case 5: double_data[5] = get_real(infile,1);/* ymax */
  2756.                             /*
  2757.                             var draw_numberline%d = function(canvas_type,xmin,xmax,xmajor,xminor,ymin,ymax,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor);
  2758.                             */
  2759.                             fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[2] / double_data[3],double_data[5] - double_data[4] );
  2760.                             string_length = snprintf(NULL,0,"\ndraw_numberline(%d,%d,%f,%f,%f,%f,%f,%f,%d,\"%s\",%f,\"%s\",\"%s\",%d);   ",NUMBERLINE_CANVAS+numberline_cnt,use_axis_numbering,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],line_width,stroke_color,stroke_opacity,font_family,font_color,precision);
  2761.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2762.                             snprintf(tmp_buffer,string_length,"\ndraw_numberline(%d,%d,%f,%f,%f,%f,%f,%f,%d,\"%s\",%f,\"%s\",\"%s\",%d);  ",NUMBERLINE_CANVAS+numberline_cnt,use_axis_numbering,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],line_width,stroke_color,stroke_opacity,font_family,font_color,precision);
  2763.                             add_to_buffer(tmp_buffer);
  2764.                             numberline_cnt++;
  2765.                             break;
  2766.                     default:break;
  2767.                 }
  2768.             }
  2769.             reset();
  2770.             break;
  2771.  
  2772.             break;
  2773.         case OPACITY:
  2774.         /*
  2775.         @ opacity 0-255,0-255
  2776.         @ opacity 0.0 - 1.0,0.0 - 1.0
  2777.         @ alternative : transparent
  2778.         @ first item is stroke opacity, second is fill opacity
  2779.         @%opacity%size 400,400%xrange -10,10%yrange -10,10%fillcolor red%opacity 255,50%fcircle 0,0,100,blue
  2780.         */
  2781.             for(i = 0 ; i<2;i++){
  2782.                 switch(i){
  2783.                     case 0: double_data[0]= get_real(infile,0);break;
  2784.                     case 1: double_data[1]= get_real(infile,1);break;
  2785.                     default: break;
  2786.                 }
  2787.             }
  2788.             if( double_data[0] > 255 ||  double_data[1] > 255  ){ canvas_error("opacity [0 - 255] , [0 - 255] ");}/* typo or non-RGB ? */
  2789.             if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = 0.0;} /* 0.0 - 1.0 */
  2790.             if( double_data[1] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = 0.0;} /* 0.0 - 1.0 */
  2791.             break;
  2792.  
  2793.         case ONCLICK:
  2794.         /*
  2795.          @ onclick
  2796.          @ keyword (no arguments required)
  2797.          @ if the next object is clicked, its 'object onclick_or_drag sequence number' in fly script is returned <br /> by javascript:read_canvas();
  2798.          @ onclick seqeuence numbering starts at '0'.<br />e.g. if there are 6 objects set onclick, the first onclick object will have id-number '0', the last id-number '5'
  2799.          @ line based objects will show an increase in line width<br />font based objects will show the text in 'bold' when clicked.
  2800.          @ the click zone (accuracy) is determined by 2&times; the line width of the object
  2801.          @ onclick and <a href="#drag">drag x|y|xy</a> may be combined in a single flyscript <br />(although a single object can <b>not</b> be onclick and draggable at the same time...)
  2802.          @ note: not all objects may be set onclick
  2803.          @%onclick%size 400,400%xrange -10,10%yrange -10,10%opacity 255,60%linewidth 3%onclick%fcircles blue,-3,3,1,1,2,2,3,1,1%onclick%ftriangles red,-4,-4,-4,0,-3,-2,0,0,4,0,2,-4%onclick%frects green,-4,4,-2,2,1,-1,3,-4
  2804.         */
  2805.             fprintf(js_include_file,"use_dragdrop_reply = true;");
  2806.             onclick = 1;
  2807.  
  2808.             break;
  2809.  
  2810.         case PARALLEL:
  2811.         /*
  2812.          @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
  2813.          @ can <b>not</b> be set "onclick" or "drag xy"
  2814.          @%parallel%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red
  2815.         */
  2816.             for( i = 0;i < 8; i++ ){
  2817.                 switch(i){
  2818.                     case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
  2819.                     case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
  2820.                     case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
  2821.                     case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
  2822.                     case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
  2823.                     case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
  2824.                     case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
  2825.                     case 7: stroke_color=get_color(infile,1);/* name or hex color */
  2826.                     decimals = find_number_of_digits(precision);
  2827.                     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,%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,rotation_center,use_offset,use_pattern);
  2828.                     if(onclick > 0){click_cnt++;}
  2829.                     /* click_cnt++*/;
  2830.                     reset();
  2831.                     break;
  2832.                     default: break;
  2833.                 }
  2834.             }
  2835.             break;
  2836.  
  2837.  
  2838.         case PLOTSTEPS:
  2839.             /*
  2840.              @ plotsteps a_number
  2841.              @ default 150
  2842.              @ only used for commands <a href="#curve">"curve / plot"</a> and  <a href="#levelcurve">"levelcurve"</a>
  2843.              @ use with care !
  2844.             */
  2845.             plot_steps = (int) (get_real(infile,1));
  2846.             break;
  2847.        
  2848.         case POINT:
  2849.         /*
  2850.         @ point x,y,color
  2851.         @ draw a single point at (x;y) in color 'color'
  2852.         @ use command 'linewidth int'  to adust size
  2853.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2854.         @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming)
  2855.         @ attention: in case of command <a href="#rotate">'rotate angle'</a> a point has rotation center (0:0) in x/y-range
  2856.         @%point%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 1%onclick%point 0,0,red%linewidth 2%onclick%point 1,1,blue%linewidth 3%onclick%point 3,3,green%linewidth 4%point 4,4,orange
  2857.         */
  2858.             for(i=0;i<3;i++){
  2859.                 switch(i){
  2860.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  2861.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  2862.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  2863.                     decimals = find_number_of_digits(precision);
  2864.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],1.5*line_width,line_width,1.5*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,rotation_center,use_offset,use_pattern);
  2865.                     /* click_cnt++; */
  2866.                     if(onclick > 0){click_cnt++;}
  2867.                     break;
  2868.                     default: break;
  2869.                 }
  2870.             }
  2871.             reset();
  2872.             break;
  2873.  
  2874.         case POINTS:
  2875.         /*
  2876.         @ points color,x1,y1,x2,y2,...,x_n,y_n
  2877.         @ draw multiple points at given coordinates in color 'color'
  2878.         @ use command 'linewidth int'  to adust size
  2879.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  2880.         @ attention: in case of command <a href="#rotate">'rotate angle'</a> the points have rotation center (0:0) in x/y-range
  2881.         @%points_1%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%snaptogrid%linewidth 1%drag xy%points red,0,0,1,1,2,2,3,3%drag x%points blue,0,1,1,2,2,3,3,4
  2882.         @%points_2%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 1%onclick%points red,0,0,1,1,2,2,3,3%onclick%points blue,0,1,1,2,2,3,3,4
  2883.         */
  2884.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  2885.             fill_color = stroke_color;
  2886.             i=0;
  2887.             while( ! done ){     /* get next item until EOL*/
  2888.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2889.                 if(i%2 == 0 ){
  2890.                     double_data[i] = get_real(infile,0); /* x */
  2891.                 }
  2892.                 else
  2893.                 {
  2894.                     double_data[i] = get_real(infile,1); /* y */
  2895.                 }
  2896.                 i++;
  2897.             }
  2898.             decimals = find_number_of_digits(precision);
  2899.             for(c = 0 ; c < i-1 ; c = c+2){
  2900.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],1.5*line_width,line_width,1.5*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,rotation_center,use_offset,use_pattern);
  2901.                 /* click_cnt++; */
  2902.                 if(onclick > 0){click_cnt++;}
  2903.             }
  2904.             reset();
  2905.             break;
  2906.  
  2907.         case POLY:
  2908.         /*
  2909.         @ poly color,x1,y1,x2,y2...x_n,y_n
  2910.         @ polygon color,x1,y1,x2,y2...x_n,y_n
  2911.         @ draw closed polygon
  2912.         @ use command 'fpoly' to fill it or use keyword <a href='#filled'>'filled'</a>
  2913.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2914.         @%polygon_1%size 400,400%xrange -10,10%yrange -10,10%opacity 255,25%fillcolor orange%filled%linewidth 2%drag xy%snaptogrid%poly blue,0,0,1,3,3,1,2,4,-1,3
  2915.         @%polygon_2%size 400,400%xrange -10,10%yrange -10,10%opacity 255,25%fillcolor orange%filled%linewidth 1%onclick%poly green,0,0,1,3,3,1,2,4,-1,3
  2916.         */
  2917.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  2918.             i=0;
  2919.             c=0;
  2920.             while( ! done ){     /* get next item until EOL*/
  2921.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2922.                 for( c = 0 ; c < 2; c++){
  2923.                     if(c == 0 ){
  2924.                         double_data[i] = get_real(infile,0);
  2925.                         i++;
  2926.                     }
  2927.                     else
  2928.                     {
  2929.                         double_data[i] = get_real(infile,1);
  2930.                         i++;
  2931.                     }
  2932.                 }
  2933.             }
  2934.             /* draw path :  closed & optional filled */
  2935.                 decimals = find_number_of_digits(precision);
  2936.                 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,%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,rotation_center,use_offset,use_pattern);
  2937.                 if(onclick > 0){click_cnt++;}
  2938.                 /* click_cnt++; */
  2939.                 reset();
  2940.             break;
  2941.  
  2942.         case POLYLINE:
  2943.         /*
  2944.         @ polyline color,x1,y1,x2,y2...x_n,y_n
  2945.         @ brokenline color,x1,y1,x2,y2...x_n,y_n
  2946.         @ path color,x1,y1,x2,y2...x_n,y_n
  2947.         @ remark: there is <b>no</b> command polylines | brokenlines | paths ... just use multiple commands "polyline ,x1,y1,x2,y2...x_n,y_n"
  2948.         @ remark: there are commands "userdraw path(s),color" and "userdraw polyline,color"... these are two entirely different things !<br />the path(s) userdraw commands may be used for freehand drawing(s)<br />the polyline userdraw command is analogue to this polyline|brokenline command
  2949.         @ the command interconnects the points in the given order with a line (canvasdraw will not close the drawing: use command <a href="#poly">polygon</a> for this)
  2950.         @ use command <a href='#segments'>'segments'</a> for a series of segments.<br />these may be clicked/dragged individually
  2951.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2952.         @%polyline_1%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%snaptogrid%polyline blue,0,0,1,3,3,1,2,4,-1,3
  2953.         @%polyline_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%onclick%polyline green,0,0,1,3,3,1,2,4,-1,3
  2954.         */
  2955.        
  2956.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  2957.             i=0;
  2958.             c=0;
  2959.             while( ! done ){     /* get next item until EOL*/
  2960.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2961.                 for( c = 0 ; c < 2; c++){
  2962.                     if(c == 0 ){
  2963.                         double_data[i] = get_real(infile,0);
  2964.                         i++;
  2965.                     }
  2966.                     else
  2967.                     {
  2968.                         double_data[i] = get_real(infile,1);
  2969.                         i++;
  2970.                     }
  2971.                 }
  2972.             }
  2973.             /* draw path : not closed & not filled */
  2974.             decimals = find_number_of_digits(precision);
  2975.             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,%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,rotation_center,use_offset,use_pattern);
  2976.             if(onclick > 0){click_cnt++;}
  2977.             /* click_cnt++;*/
  2978.             reset();
  2979.             break;
  2980.  
  2981.         case POPUP:
  2982.             /*
  2983.             @ popup
  2984.             @ keyword (no arguments)
  2985.             @ if fly-script starts with keyword 'popup', the canvas image will be exclusively in a popup window (xsize px &times; ysize px)
  2986.             @ if keyword 'popup' is used after command 'size xsize,ysize' the canvas will also be displayed in a popup window with size 'xsize &times; ysize'
  2987.             @ the popup window will be embedded into the page as a 'normal' image , when 'status=done' ; override with keyword <a href="#status"> 'nostatus'</a>
  2988.             @ to access the read_canvas and read_dragdrop functions in a popup window, use:<br /><em><br /> function read_all(){<br /> if( typeof popup !== 'undefined' ){<br />  var fun1 = popup['read_dragdrop'+canvas_scripts[0]];<br />  var fun2 = popup['read_canvas'+canvas_scripts[0]];<br />   popup.close();<br />  return "dragdrop="+fun1()+"\\ncanvas="+fun2();<br /> };<br /></em>
  2989.             @ to set a canvasdraw produced <a href="#clock">clock</a> or multiple clocks...use something like:<br /><em>popup.set_clock(clock_id,type,diff);</em><br />as js-function for a button (or something else) in your document page.<br />wherein <b>clock_id</b> starts with 0 for the first clock<br /><b>type</b> is 1 for Hours,2 for Minutes and 3 for Seconds<br /><b>diff</b> is the increment (positive or negative) per click
  2990.             @%popup%popup%size 400,400%xrange -2*pi,2*pi%yrange -5,5%precision 0%axis%axisnumbering%opacity 100,190%grid 1,1,grey,2,2,5,black%linewidth 4%fillcolor blue%trange -pi,pi%animate%linewidth 1%precision 1000%jsplot red,4*cos(2*x),2*sin(3*x-pi/6)%strokecolor green%functionlabel f(x)=%userinput function
  2991.             */
  2992.             use_tooltip = 2;
  2993.             break;
  2994.  
  2995.         case PROTRACTOR:
  2996.         /*
  2997.          @ protractor x,y,x_width,type,mode,use_a_scale
  2998.          @ x,y are the initial location
  2999.          @ x_width : give the width in x-coordinate system (e.g. not in pixels !)
  3000.          @ type = 1 : a triangle range  0 - 180<br />type = 2 : a circle shape 0 - 360
  3001.          @ mode : use -1 to set the protractor interactive (mouse movement of protractor)<br />use mode = '0&deg; - 360&deg;' to set the protractor with a static angle of some value
  3002.          @ if the value of the user_rotation angle is to be shown...use command <a href='#display'>display degree,color,fontsize</a><a href='#display'>display radian,color,fontsize</a>
  3003.          @ use_scale = 1 : the protractor will have some scale values printed; use_scale=0 to disable
  3004.          @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor...
  3005.          @ commands <em>stroke_color | fill_color | linewidth | opacity | font_family</em> will determine the looks of the protractor.
  3006.          @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command 'precision' to set the reply precision.
  3007.          @ if combined with a ruler, use replyformat = 32
  3008.          @ command <em>snap_to_grid</em> may be used to assist the pupil at placing the protractor
  3009.          @ when using command 'zoom' , pay <b>attention</b> to the size and symmetry of your canvas<br />...to avoid a partial image, locate the start position near the center of the visual canvas<br /><em>technical:<br /> the actual 'protractor' is just a static generated image in a new canvas-memory<br />This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas.<br />That is the reason for the 'high-speed dragging and rotating'.<br />I've limited its size to xsize &times; ysize e.g. the same size as the visual canvas... </em>
  3010.          @ only one protractor allowed (for the time being)
  3011.          @ usage: first left click on the protractor will activate dragging;<br />a second left click will activate rotating (just move mouse around)<br />a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br />a next click will restart this sequence...
  3012.          @%protractor%size 400,400%xrange -5,10%yrange -5,10%hline 0,0,black%vline 0,0,black%fillcolor orange%opacity 255,40%protractor 2,-2,6,0,-1,1,1
  3013.         */
  3014.             for( i = 0;i < 6; i++ ){
  3015.                 switch(i){
  3016.                     case 0: double_data[0] = get_real(infile,0);break; /* x-center */
  3017.                     case 1: double_data[1] = get_real(infile,0);break; /* y-center */
  3018.                     case 2: double_data[2] = get_real(infile,0);break; /* x-width */
  3019.                     case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */
  3020.                     case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */
  3021.                     case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */
  3022.                     decimals = find_number_of_digits(precision);
  3023.                     if( int_data[1] < 0 ){ js_function[JS_FIND_ANGLE] = 1;}
  3024.                     add_js_protractor(js_include_file,canvas_root_id,int_data[0],double_data[0],double_data[1],double_data[2],font_family,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width,int_data[2],int_data[1]);
  3025.  
  3026.                     string_length = snprintf(NULL,0,";protractor%d(); ",canvas_root_id);
  3027.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3028.                     snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id);
  3029.                     add_to_buffer(tmp_buffer);
  3030.                     reply_precision = precision;
  3031.                     /* no reply from protractor if non-interactive */
  3032.                     if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;}
  3033.                     break;
  3034.                     default: break;
  3035.                 }
  3036.             }
  3037.             break;
  3038.  
  3039.         case PIXELS:
  3040.         /*
  3041.         @ pixels color,x1,y1,x2,y2,x3,y3...
  3042.         @ draw rectangular "points" with diameter 1 pixel
  3043.         @ pixels can <b>not</b> be dragged or clicked
  3044.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  3045.         @%pixels%size 400,400%opacity 255,255%pixelsize 5%pixels red,1,1,2,2,3,3,4,4,5,5,10,10,20,20,30,30,40,40,50,50,60,60,70,70,80,80,90,90,100,100,120,120,140,140,160,160,180,180,200,200,240,240,280,280,320,320,360,360,400,400%#NOTE pixelsize=5...otherwise you will not see them clearly...
  3046.         */
  3047.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  3048.             stroke_color=get_color(infile,0);
  3049.             i=0;
  3050.             c=0;
  3051.             while( ! done ){     /* get next item until EOL*/
  3052.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3053.                 for( c = 0 ; c < 2; c++){
  3054.                     if(c == 0 ){
  3055.                         double_data[i] = get_real(infile,0);
  3056.                         i++;
  3057.                     }
  3058.                     else
  3059.                     {
  3060.                         double_data[i] = get_real(infile,1);
  3061.                         i++;
  3062.                     }
  3063.                 }
  3064.             }
  3065.             decimals = find_number_of_digits(precision);
  3066.             /*  *double_xy2js_array(double xy[],int len,int decimals) */
  3067.             string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  3068.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3069.             snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  3070.             add_to_buffer(tmp_buffer);
  3071.             reset();
  3072.             break;
  3073.  
  3074.         case PIXELSIZE:
  3075.         /*
  3076.         @ pixelsize int
  3077.         @ in case you want to deviate from default pixelsize = 1(...)
  3078.         @ pixelsize 100 is of course a filled rectangle 100px &times; 100px
  3079.         */
  3080.             pixelsize = (int) get_real(infile,1);
  3081.         break;
  3082.  
  3083.         case PIECHART:
  3084.         /*
  3085.         @ piechart xc,yc,radius,'data+colorlist'
  3086.         @ (xc : yc) center of circle diagram in xrange/yrange
  3087.         @ radius in pixels
  3088.         @ 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
  3089.         @ example data+colorlist : 32:red:65:green:23:black:43:orange:43:yellow:14:white
  3090.         @ the number of colors must match the number of data.
  3091.         @ if defined <a href='#fillpattern'>'fillpattern some_pattern'</a> then the pie pieces will be filled with the respective color and a fill pattern...<br />the pattern is cycled from the 4 pattern primitives: grid,hatch,diamond,dot,grid,hatch,diamond,dot,...
  3092.         @ use command "<a href='#opacity'>'opacity'</a> to adjust fill_opacity of colours
  3093.         @ use command <a href='#legend'>'legend'</a> 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.
  3094.         @ use command <a href='centered'>'centered'</a> to place <a href='#legend'>'legend'</a> text inside the piechart. The text is using the same color as the pie segment: use (fill) opacity to enhance visibility.
  3095.         @%piechart_1%size 300,200%xrange -10,10%yrange -10,10%legend cars:motorcycles:bicycles:trikes%opacity 255,120%piechart -5,0,75,22:red:8:blue:63:green:7:purple%
  3096.         @%piechart_2%size 200,200%xrange -10,10%yrange -10,10%fontfamily 16px Ariel%centered%legend cars:motorcycles:bicycles:trikes%opacity 255,60%piechart 0,0,100,22:red:8:blue:63:green:7:purple
  3097.         */
  3098.             if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}
  3099.             for(i=0;i<5;i++){
  3100.                 switch(i){
  3101.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  3102.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  3103.                     case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
  3104.                     case 3: temp = get_string(infile,1);
  3105.                             if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
  3106.                             string_length = snprintf(NULL,0,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\",%d,%d);\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family,use_filled,use_offset);
  3107.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3108.                             snprintf(tmp_buffer,string_length,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\",%d,%d);\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family,use_filled,use_offset);
  3109.                             add_to_buffer(tmp_buffer);
  3110.                            break;
  3111.                     default:break;
  3112.                 }
  3113.             }
  3114.             reset();
  3115.         break;
  3116.  
  3117.         case RAYS:
  3118.         /*
  3119.          @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
  3120.          @ draw rays in color 'color' and center (xc:yc)
  3121.          @ may be set draggable or onclick (every individual ray)
  3122.          @%rays_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%rays blue,0,0,3,9,-3,5,-4,0,4,-9,7,9,-8,1,-1,-9
  3123.          @%rays_drag_xy%size 400,400%xrange -10,10%yrange -10,10%drag xy%rays blue,0,0,3,9,-3,5,-4,0,4,-9,7,9,-8,1,-1,-9
  3124.         */
  3125.             stroke_color=get_color(infile,0);
  3126.             fill_color = stroke_color;
  3127.             double_data[0] = get_real(infile,0);/* xc */
  3128.             double_data[1] = get_real(infile,0);/* yc */
  3129.             i=2;
  3130.             while( ! done ){     /* get next item until EOL*/
  3131.                 if(i > MAX_INT - 1){canvas_error("in command rays too many points / rays in argument: repeat command multiple times to fit");}
  3132.                 if(i%2 == 0 ){
  3133.                     double_data[i] = get_real(infile,0); /* x */
  3134.                 }
  3135.                 else
  3136.                 {
  3137.                     double_data[i] = get_real(infile,1); /* y */
  3138.                 }
  3139.             fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
  3140.                 i++;
  3141.             }
  3142.  
  3143.             if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
  3144.             decimals = find_number_of_digits(precision);
  3145.             for(c=2; c<i;c = c+2){
  3146.                 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,%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,rotation_center,use_offset,use_pattern);
  3147.                 /* click_cnt++; */
  3148.                 if(onclick > 0){click_cnt++;}
  3149.             }
  3150.             reset();
  3151.             break;
  3152.  
  3153.         case RECT:
  3154.         /*
  3155.         @ rect x1,y1,x2,y2,color
  3156.         @ use command 'frect x1,y1,x2,y2,color' for a filled rectangle
  3157.         @ use command/keyword  <a href='#filled'>'filled'</a> before command 'rect x1,y1,x2,y2,color'
  3158.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3159.         @%rect%size 400,400%xrange -10,10%yrange -10,10%rect 0,0,4,-4,green%rect 0,5,4,1,red
  3160.         */
  3161.             for(i=0;i<5;i++){
  3162.                 switch(i){
  3163.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  3164.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  3165.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  3166.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  3167.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  3168.                         decimals = find_number_of_digits(precision);
  3169.                         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,%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,rotation_center,use_offset,use_pattern);
  3170.                         if(onclick > 0){click_cnt++;}
  3171.                         /* click_cnt++; */
  3172.                         reset();
  3173.                         break;
  3174.                 }
  3175.             }
  3176.             break;
  3177.  
  3178.         case RECTS:
  3179.         /*
  3180.         @ rects color,x1,y1,x2,y2,.....
  3181.         @ use command 'frect color,x1,y1,x2,y2,.....' for a filled rectangle
  3182.         @ use command/keyword  <a href='#filled'>'filled'</a> before command 'rects color,x1,y1,x2,y2,....'
  3183.         @ use command 'fillcolor color' before 'frects' to set the fill colour.
  3184.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  3185.         @%rects%size 400,400%xrange -10,10%yrange -10,10%rects red,0,0,4,-4,0,5,4,1
  3186.         */
  3187.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3188.             fill_color = stroke_color;
  3189.             i=0;
  3190.             while( ! done ){     /* get next item until EOL*/
  3191.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3192.                 if(i%2 == 0 ){
  3193.                     double_data[i] = get_real(infile,0); /* x */
  3194.                 }
  3195.                 else
  3196.                 {
  3197.                     double_data[i] = get_real(infile,1); /* y */
  3198.                 }
  3199.                 i++;
  3200.             }
  3201.             decimals = find_number_of_digits(precision);
  3202.             for(c = 0 ; c < i-1 ; c = c+4){
  3203.                 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,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+2],decimals,double_data[c],decimals,double_data[c+1],decimals,double_data[c+1],decimals,double_data[c+3],decimals,double_data[c+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,rotation_center,use_offset,use_pattern);
  3204.                 if(onclick > 0){click_cnt++;}
  3205.                 /* click_cnt++; */
  3206.             }
  3207.             reset();
  3208.             break;
  3209.  
  3210.         case REPLYFORMAT:
  3211.         /*
  3212.         @ replyformat number
  3213.         @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop()
  3214.         @ default values should be fine !
  3215.         @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing
  3216.         @ the last value for 'precision int' will be used to calculate  the reply coordinates, if needed (read_canvas();)
  3217.         @ 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 \\n x2,y2,text2...\\n...x_n,y_n,text_n <br /> x/y-values are in xrang/yrange</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>20 = read_canvas() will reply "object_number:x:y" of external images : object_number of the first draggable external image in the fly-script starts with 0 <br />e.g. expect something like 0:-5:4,1:6:2,2:-2:-5 <br /> the first image position is (-5:4) , the second image position is (6:2) and the third image position is (-2:-5)        <li>21 = (x1:y1) (x2:y2) ... (x_n:y_n)<br />verbatim coordinate return</li><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>23 : can only be used for drawtype 'polyline'<br />a typical click sequence in drawtype polyline is x1,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>24 = read all inputfield values: even those set 'readonly'</li><li>25 = angle1,angle2...angle_n : will return the radius (one or many) of the user drawn circle segment in degrees </li><li>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  x1,y1,text1 \\n x2,y2,text2...\\n...x_n,y_n,text_n</li><li>28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n <br />x / y / r in  xrange / yrange coordinate system: may be used to reinput into command 'circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n'<br /> will not return anything else (e.g. no inputfields , text etc)</li></ul>
  3218.  
  3219.         */
  3220.          reply_format = (int) get_real(infile,1);
  3221.          reply_precision = precision;
  3222.         break;
  3223.  
  3224.         case ROUNDRECT:
  3225.         /*
  3226.         @ roundrect x1,y1,x2,y2,radius in px,color
  3227.         @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle
  3228.         @ use command/keyword  <a href='#filled'>'filled'</a> before command 'roundrect x1,y1,x2,y2,radius,color'
  3229.         @ fillcolor will be identical to 'color'
  3230.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3231.         @%roundrect%size 400,400%xrange -10,10%yrange -10,10%roundrect 0,0,4,-4,20,green%roundrect 0,5,4,1,10,red
  3232.         */
  3233.             for(i=0;i<6;i++){
  3234.                 switch(i){
  3235.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  3236.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  3237.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  3238.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  3239.                     case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
  3240.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  3241.                         /* ensure no inverted roundrect is produced... */
  3242.                         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];}
  3243.                         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];}
  3244.                         decimals = find_number_of_digits(precision);
  3245.                         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,%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,rotation_center,use_offset,use_pattern);
  3246.                         if(onclick > 0){click_cnt++;}
  3247.                         /* click_cnt++;*/
  3248.                         reset();
  3249.                     break;
  3250.                 }
  3251.             }
  3252.             break;
  3253.  
  3254.         case ROUNDRECTS:
  3255.         /*
  3256.         @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,....
  3257.         @ for filled roundrects use command/keyword <a href='#filled'>'filled'</a> before command
  3258.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  3259.         @%roundrects%size 400,400%xrange -10,10%yrange -10,10%roundrects blue,0,0,4,-4,20,0,5,4,1,10
  3260.         */
  3261.  
  3262.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3263.             int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */
  3264.             fill_color = stroke_color;
  3265.             i=0;
  3266.             while( ! done ){     /* get next item until EOL*/
  3267.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3268.                 if(i%2 == 0 ){
  3269.                     double_data[i] = get_real(infile,0); /* x */
  3270.                 }
  3271.                 else
  3272.                 {
  3273.                     double_data[i] = get_real(infile,1); /* y */
  3274.                 }
  3275.                 i++;
  3276.             }
  3277.             decimals = find_number_of_digits(precision);
  3278.             for(c = 0 ; c < i-1 ; c = c+4){
  3279.                 /* ensure no inverted roundrect is produced... */
  3280.                 if( double_data[c] > double_data[c+2] ){double_data[c+4] = double_data[c];double_data[c] = double_data[c+2];double_data[c+2] = double_data[c+4];}
  3281.                 if( double_data[c+3] > double_data[c+1] ){double_data[c+4] = double_data[c+1];double_data[c+1] = double_data[c+3];double_data[c+3] = double_data[c+4];}
  3282.                 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,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+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,rotation_center,use_offset,use_pattern);
  3283.                 if(onclick > 0){click_cnt++;}
  3284.                 /* click_cnt++; */
  3285.             }
  3286.             reset();
  3287.             break;
  3288.  
  3289.         case RULER:
  3290.         /*
  3291.         @ ruler x,y,x-width ,y-height,mode
  3292.         @ x,y are the initial location
  3293.         @ x-width , y-height are the ruler dimensions width &amp; height in xy-coordinate system
  3294.         @ the ruler scale is by definition the x-scale, set by command 'xrange'<br />for example: a ruler x-width of 6 will have a scale ranging from 0 to 6
  3295.         @ mode : use -1 to set the ruler interactive (eg mouse movement of ruler; drag &amp; rotate)<br />use mode = '0&deg; - 360&deg;' to set the ruler with a static angle of some value
  3296.         @ if combined with a protractor, use replyformat = 32
  3297.         @ only one ruler allowed (for the time being)
  3298.         @ when using command 'zoom' , pay <b>attention</b> to the size and symmetry of your canvas<br />...to avoid a partial image, locate the start position near the center of the visual canvas<br /><em>technical:<br /> the actual 'ruler' is just a static generated image in a new canvas-memory<br />This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas.<br />That is the reason for the 'high-speed dragging and rotating'.<br />I've limited its size to xsize &times; ysize e.g. the same size as the visual canvas... </em>
  3299.         @ usage: first left click on the ruler will activate dragging;<br />a second left click will activate rotating (just move mouse around)<br />a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br />a next click will restart this sequence...
  3300.         @%ruler_interactive%size 800,400%xrange -10,10%yrange -10,10%strokecolor blue%opacity 200,50%filled%fillcolor lightgrey%ruler -9,0,10,2,-1%display degree,blue,22%zoom red
  3301.         @%ruler_set_degree_45%size 800,400%xrange -10,10%yrange -10,10%strokecolor blue%opacity 200,50%filled%fillcolor lightgrey%ruler 0,0,10,2,45%zoom red
  3302.         @%ruler_set_degree_125%size 800,400%xrange -10,10%yrange -10,10%strokecolor blue%opacity 200,50%filled%fillcolor lightgrey%ruler 0,0,10,2,125%zoom red
  3303.         */
  3304.             for( i = 0;i < 5; i++ ){
  3305.                 switch(i){
  3306.                     case 0: double_data[0] = get_real(infile,0);break; /* x-center */
  3307.                     case 1: double_data[1] = get_real(infile,0);break; /* y-center */
  3308.                     case 2: double_data[2] = get_real(infile,0);break; /* x-width */
  3309.                     case 3: double_data[3] = get_real(infile,0);break; /* y-width */
  3310.                     case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */
  3311.                     decimals = find_number_of_digits(precision);
  3312.                     if( int_data[0] < 0 ){
  3313.                       if( js_function[JS_FIND_ANGLE] != 1 ){  js_function[JS_FIND_ANGLE] = 1; }
  3314.                     }
  3315.                     add_js_ruler(js_include_file,canvas_root_id,double_data[0],double_data[1],double_data[2],double_data[3],font_family,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width,int_data[0]);
  3316.                     string_length = snprintf(NULL,0,";ruler%d(); ",canvas_root_id);
  3317.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3318.                     snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id);
  3319.                     add_to_buffer(tmp_buffer);
  3320.                     reply_precision = precision;
  3321.                     /* no reply from ruler if non-interactive */
  3322.                     if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;}
  3323.                     break;
  3324.                     default: break;
  3325.                 }
  3326.             }
  3327.             break;
  3328.  
  3329.         case RESETOFFSET:
  3330.         /*
  3331.          @ resetoffset
  3332.          @ keyword ; use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text
  3333.          @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy
  3334.         */
  3335.          use_offset = 0;
  3336.          break;
  3337.  
  3338.         case ROTATE:
  3339.         /*
  3340.          @ rotate rotation_angle
  3341.          @ angle in degrees
  3342.          @ (only) the next object will be rotated is given angle
  3343.          @ positive values rotate counter clockwise
  3344.          @ attention: all objects will be rotated around their first point...<br /><em>rotate 45</em><br /> <em>triangle 1,1,5,1,3,4,red</em><br />will rotate 45 degrees around point (1:1)
  3345.          @ if another rotation center is needed, use command <a href="#rotationcenter">'rotationcenter xc,yc'</a>.<br />to reset this rotationcenter, use keyword <a href="killrotate">'killrotate'</a>
  3346.          @ attention: rotate will mess up the interactivity of the rotated object <br />e.g. if combined with command <a href="#drag">"drag xy"</a> or keyword <a href="onclick">"onclick"</a> : the mouse recognises the original -unrotated- coordinates of the object
  3347.          @%rotate-1%size 400,400%xrange -10,10%yrange -10,10%fpoly yellow,0,0,4,3,2,5%rotate 45%fpoly violet,0,0,4,3,2,5%killrotate%rotate 90%fpoly violet,0,0,4,3,2,5%
  3348.         */
  3349.             use_rotate = TRUE;
  3350.             angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */
  3351.             break;
  3352.         case ROTATION_CENTER:
  3353.         /*
  3354.         @ rotationcenter x_center,y_center
  3355.         @ define an rotation center in your x/y-coordinate system
  3356.         @ wims will not check the validity of your input; use javascript console to debug any erors
  3357.         @ if not defined a rotation will be around the first point of an object
  3358.         @ to be used before command <a href="#rotate">rotate</a>
  3359.         @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given
  3360.         @%rotatationcenter%size 400,400%xrange -10,10%yrange -10,10%rotationcenter 3,3%fpoly yellow,0,0,4,3,2,5%rotate 45%fpoly violet,0,0,4,3,2,5%mouse red,22
  3361.         */
  3362.             temp = get_string(infile,1);
  3363.             string_length = snprintf(NULL,0,"[ %s ]",temp);
  3364.             check_string_length(string_length);
  3365.             rotation_center = my_newmem(string_length+1);
  3366.             snprintf(rotation_center,string_length,"[%s]",temp);
  3367.             break;
  3368.  
  3369.         case SIZE:
  3370.             /*
  3371.             @ size width,height
  3372.             @ set canvas size in pixels
  3373.             @ mandatory first command (can only be preceded by keyword <a href="#popup">'popup'</a>)
  3374.             @ 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
  3375.             */
  3376.             found_size_command = 1;
  3377.             /* using fabs : however "xsize == int" : so "xsize = abs( (int) get_real(infile,0))" would be the idea... */
  3378.             xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
  3379.             ysize = (int)(fabs(round(get_real(infile,1))));
  3380.             /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
  3381.             xmin = 0;xmax = xsize;
  3382.             ymin = 0;ymax = ysize;
  3383.  
  3384. /*
  3385.  The sequence in which stuff is finally printed is important !!
  3386. */
  3387. fprintf(stdout,"\n\
  3388. <script type=\"text/javascript\">\n\
  3389. /*<![CDATA[*/\n\
  3390. if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\
  3391. if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\
  3392. if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\
  3393. canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\
  3394. ",canvas_root_id);
  3395.  
  3396. /* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */
  3397. if( use_tooltip != 2){
  3398.  fprintf(stdout,"<!-- canvasdraw div  -->\n\
  3399. <div tabindex=\"0\" id=\"canvas_div%d\" style=\"position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" oncontextmenu=\"return false;\"></div>\n\
  3400. <!-- tooltip and input placeholder  -->\n\
  3401. <div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\
  3402. <!-- include actual object code via include file -->\n\
  3403. <script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd);
  3404. }
  3405. else
  3406. {
  3407. /*
  3408. set canvas_div invisible and do not include placeholder in main html page :
  3409. the js-include will also be in a popup window...to be shown when wims $status = done
  3410. */
  3411.  fprintf(stdout,"<!-- canvasdraw div invisible  -->\n\
  3412. <div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\
  3413. <div id=\"tooltip_placeholder_div%d\" style=\"display:none;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\
  3414. <!-- include actual object code via include file -->\n\
  3415. <script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd);
  3416. }
  3417.  
  3418. /* these must be global...it's all really very poor javascript :( */
  3419. fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n\
  3420. \"use strict\";\n\
  3421. <!-- these variables and functions must be global -->\n\
  3422. var read_dragdrop%d;\
  3423. var read_canvas%d;\
  3424. var set_clock;\
  3425. var clear_draw_area%d;\
  3426. var update_draw_area%d;\
  3427. var draw_boxplot;\
  3428. var redraw_all%d;\
  3429. var userdraw_primitive;\n\
  3430. var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\
  3431. var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\
  3432. var xsize = %d;\
  3433. var ysize = %d;\
  3434. var precision = 100;\
  3435. var canvas_div = document.getElementById(\"canvas_div%d\");\
  3436. 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;};\
  3437. 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;};\
  3438. 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);};};\
  3439. 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);};};\
  3440. 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);};};\
  3441. 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);};};\
  3442. function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
  3443. function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
  3444. function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\
  3445. 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) ));};\
  3446. 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;};\
  3447. 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;};\
  3448. var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));\
  3449. var x_use_snap_to_grid = 0;var y_use_snap_to_grid = 0;var snap_x = 1;var snap_y = 1;\
  3450. var use_snap_to_points = 0;\
  3451. function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
  3452. function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\
  3453. var xlogbase = 10;\
  3454. var ylogbase = 10;\
  3455. var use_xlogscale = 0;\
  3456. var use_ylogscale = 0;\
  3457. var x_strings = {};var x_strings_up = [];\
  3458. var y_strings = null;\
  3459. var use_pan_and_zoom = 0;\
  3460. var use_jsmath = 0;\
  3461. var xstart = 0;\
  3462. var ystart = 0;\
  3463. var unit_x=\" \";\
  3464. var unit_y=\" \";\
  3465. var external_canvas = create_canvas%d(%d,xsize,ysize);\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,EXTERNAL_IMAGE_CANVAS);
  3466. /* default add the drag code : nearly always used ...*/
  3467.   add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
  3468.  
  3469.             break;
  3470.  
  3471.  
  3472.         case SEGMENT:
  3473.         /*
  3474.         @ segment x1,y1,x2,y2,color
  3475.         @ alternative : seg
  3476.         @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color'
  3477.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3478.         @%segment_onclick%size 400,400%xrange -10,10%yrange -10,10%segment%linewidth 2%onclick%segment 1,1,-9,3,green
  3479.         @%segment_drag_y%size 400,400%xrange -10,10%yrange -10,10%segment%linewidth 2%drag y%segment 1,1,-9,3,green
  3480.         */
  3481.             for(i=0;i<5;i++) {
  3482.                 switch(i){
  3483.                     case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
  3484.                     case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
  3485.                     case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
  3486.                     case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
  3487.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  3488.                         decimals = find_number_of_digits(precision);
  3489.                         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,%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,rotation_center,use_offset,use_pattern);
  3490.                         if(onclick > 0){click_cnt++;}
  3491.                         /* click_cnt++; */
  3492.                         reset();
  3493.                         break;
  3494.                     default: break;
  3495.                 }
  3496.             }
  3497.             break;
  3498.  
  3499.         case SEGMENTS:
  3500.         /*
  3501.         @ segments color,x1,y1,x2,y2,...,x_n,y_n
  3502.         @ alternative : segs
  3503.         @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color 'color'
  3504.         @ use command 'linewidth int'  to adust size
  3505.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  3506.         @%segments_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segments green,1,1,3,3,0,0,-3,3,1,1,4,-1,-5,5,-3,-1
  3507.         @%segments_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segments green,1,1,3,3,0,0,-3,3,1,1,4,-1,-5,5,-3,-1
  3508.         */
  3509.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3510.             fill_color = stroke_color;
  3511.             i=0;
  3512.             while( ! done ){     /* get next item until EOL*/
  3513.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3514.                 if(i%2 == 0 ){
  3515.                     double_data[i] = get_real(infile,0); /* x */
  3516.                 }
  3517.                 else
  3518.                 {
  3519.                     double_data[i] = get_real(infile,1); /* y */
  3520.                 }
  3521.                 i++;
  3522.             }
  3523.             decimals = find_number_of_digits(precision);
  3524.             for(c = 0 ; c < i-1 ; c = c+4){
  3525.                 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,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+1],decimals,double_data[c+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,rotation_center,use_offset,use_pattern);
  3526.                 if(onclick > 0){click_cnt++;}
  3527.                 /* click_cnt++;*/
  3528.             }
  3529.             reset();
  3530.             break;
  3531.  
  3532.         case SETLIMITS:
  3533.         /*
  3534.             @ setlimits
  3535.             @ keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button
  3536.             @ may be used for inputfield based zooming / panning
  3537.             @ may be styled using command <a href="#inputstyle">inputstyle</a>
  3538.             @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to 'xlabel' etc
  3539.             @ note:the input value will not be checked on validity
  3540.             @%setlimits%size 400,400%xrange -10,10%yrange -10,10%precision 1%xlabel T%ylabel H%axis%axisnumbering%grid 2,2,grey,2,2,5,grey%precision 100%multistrokecolors red,green,blue,orange%multilinewidth 1,1,2,2%multistrokeopacity 0.6,0.7,0.8,0.9%jsplot red,1/x,-1,x,1/(x-3),1/(x+3)%setlimits
  3541.         */
  3542.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  3543.             add_setlimits(js_include_file,canvas_root_id,font_size,input_style);
  3544.             /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
  3545.             use_pan_and_zoom = TRUE;
  3546.             done = TRUE;
  3547.             break;
  3548.  
  3549.         case SETPIXEL:
  3550.         /*
  3551.         @ setpixel x,y,color
  3552.         @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange
  3553.         @ pixels can <b>not</b> be dragged or clicked
  3554.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  3555.         @%setpixel%size 400,400%xrange -10,10%yrange -10,10%setpixel 1,1,red%pixelsize 2%setpixel 2,2,green%pixelsize 3%setpixel 3,3,blue%
  3556.         */
  3557.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  3558.             for(i=0;i<3;i++){
  3559.                 switch(i){
  3560.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  3561.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  3562.                     case 2: stroke_color = get_color(infile,1);
  3563.                            string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  3564.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3565.                            snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  3566.                            add_to_buffer(tmp_buffer);
  3567.                            break;
  3568.                     default:break;
  3569.                 }
  3570.             }
  3571.             reset();
  3572.         break;
  3573.  
  3574.  
  3575.         case SLIDER:
  3576.         /*
  3577.         @ slider start_value,end_value,width px,height px,<em>type</em>,label
  3578.         @ <em>type</em> may be : xy,x,y,angle
  3579.         @ if a slider value display is desired, use for argument <em>type</em>:<br />xy display<br />x display<br />y display<br />angle radian<br />angle degree
  3580.         @ if a unit (or something like that...) for x/y-value display is needed, use commands 'xunit' and / or 'yunit'
  3581.         @ if the translation should be performed using a function, use for type: xy function,x function,y function<br />use commands sliderfunction_x and/or sliderfunction_y before the slider command to define the functions<br />example:<br />sliderfunction_x x^2<br />sliderfunction_y y^2<br />slider -5,5,100,100,xy function,Some_Text<br />...some stuff to slide<br />killslider<br />sliderfunction_x x^2-2<br />slider -15,15,100,10,x function,Some_Other_Text<br />...more stuff to slide<br />killslider<br />... etc
  3582.         @ use command 'slider' before draggable/clickable objects.
  3583.         @ drag and drop may be combined with rotation slider<br />for example an arrow rotated by a slider may be placed anywhere (drag&drop)<em>size 300,300<br />xrange -5,5<br />yrange -5,5<br />grid 1,1,grey<br />linewidth 3<br />drag xy<br />fillcolor orange<br />strokecolor blue<br />slider 0,2*pi,250,30,angle degrees,Rotate arrow<br />arrow 2,2,5,5,8,red</em>
  3584.         @ no slider for a math function, these can be traced using command 'trace_jscurve some_function_in_x'
  3585.         @ 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'
  3586.         @ amount of sliders is not limited.
  3587.         @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value'
  3588.         @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page
  3589.         @ every draggable object may have its own slider (no limit in amount of sliders)
  3590.         @ label: some slider text
  3591.         @ use fillcolor for slider ball
  3592.         @ use strokecolor for slider bar
  3593.         @ use fontfamily / fontcolor to set used fonts
  3594.         @ use opacity (only fill opacity will be used) to set transparency
  3595.         @ the slider canvas will be added to the 'tooltip div' : so incompatible with command tooltip ; setlimits etc
  3596.         */
  3597.             slider_cnt++;/* slider starts at 1 */
  3598.             for(i=0; i<6 ; i++){
  3599.                 switch(i){
  3600.                     case 0: double_data[0] = get_real(infile,0);break; /* start value */
  3601.                     case 1: double_data[1] = get_real(infile,0);break; /* end value */
  3602.                     case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
  3603.                     case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
  3604.                     case 4: temp = get_string_argument(infile,0); /* type : xy,x,y,angle */
  3605.                             if(strstr(temp,"xy")!= 0){
  3606.                                 slider = 4;
  3607.                             }
  3608.                             else
  3609.                             {
  3610.                                 if(strstr(temp,"x") != 0){
  3611.                                     slider = 1;
  3612.                                 }
  3613.                                 else
  3614.                                 {
  3615.                                     if(strstr(temp,"y") != 0){
  3616.                                         slider = 2;
  3617.                                     }
  3618.                                     else
  3619.                                     {
  3620.                                         if(strstr(temp,"angle") != 0){ /* angle diplay radian */
  3621.                                             slider = 3;
  3622.                                         }
  3623.                                         else
  3624.                                         {
  3625.                                             canvas_error("slider can be of type: xy,x,y,angle,fun_x:fun_y");
  3626.                                         }
  3627.                                     }
  3628.                                 }
  3629.                             }
  3630.                             if(strstr(temp,"display")!=0){
  3631.                                 if( slider == 4 ){ /* show x:y */
  3632.                                     use_slider_display = 1; /* show x xy values in canvas window */
  3633.                                 }
  3634.                                 else
  3635.                                 {
  3636.                                     if( slider == 1 ){ /* show only x -values */
  3637.                                      use_slider_display = 10;
  3638.                                     }
  3639.                                     else
  3640.                                     {
  3641.                                      use_slider_display = 11; /* show only y -values*/
  3642.                                     }
  3643.                                 }
  3644.                             }
  3645.                             else
  3646.                             {
  3647.                                 if(strstr(temp,"degree")!= 0){
  3648.                                     use_slider_display = 2; /* show angle values in canvas window */
  3649.                                 }
  3650.                                 else
  3651.                                 {
  3652.                                     if(strstr(temp,"radian")!=0){
  3653.                                         use_slider_display = 3; /* show radian values in canvas window */
  3654.                                     }
  3655.                                 }
  3656.                             }
  3657.                             if(use_slider_display != 0 && slider_cnt == 1){ /*add just once the display js-code */
  3658.                                 add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity);
  3659.                             }
  3660.                             if(strstr(temp,"fun")!= 0){
  3661.                                 if( use_js_math == FALSE){/* add this stuff only once...*/
  3662.                                     add_to_js_math(js_include_file); use_js_math = TRUE;
  3663.                                 }
  3664.                                 fprintf(js_include_file,"var slider_function%d = {x:to_js_math('%s'),y:to_js_math('%s')};",slider_cnt,slider_function_x,slider_function_y);
  3665.                                 slider_function_x = "x";slider_function_y = "y";/* reset the functions for next slider...*/
  3666.                             }
  3667.                             else
  3668.                             {
  3669.                                 fprintf(js_include_file,"var slider_function%d = {x:'x',y:'y'};",slider_cnt);
  3670.                                 /* we must define these, otherwise 'use stict' will cause an error */
  3671.                             }
  3672.                     break;
  3673.                     case 5: /* some string used for slider description  */
  3674.                             if(slider == 4){
  3675.                                 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);
  3676.                             }
  3677.                             else
  3678.                             {
  3679.                                 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);
  3680.                             }
  3681.                     break;
  3682.                 }
  3683.              }
  3684.             break;
  3685.         case SLIDER_X:
  3686.         /*
  3687.          @ sliderfunction_x some_function_in_x
  3688.          @ default value "x"
  3689.          @ the x-value of the slider object(s) will be calculated with this function.
  3690.          @ default is the x-slider value itself
  3691.          @ only used by command 'slider'
  3692.          @ define before a slider command !
  3693.         */
  3694.          slider_function_x = get_string(infile,1);
  3695.         break;
  3696.         case SLIDER_Y:
  3697.          slider_function_y = get_string(infile,1);
  3698.          /*
  3699.          @ sliderfunction_y some_function_in_y
  3700.          @ default value "y"
  3701.          @ the y-value of the slider object(s) will be calculated with this function.
  3702.          @ only used by command 'slider'
  3703.          @ define before a slider command !
  3704.          */
  3705.         break;
  3706.         case SGRAPH:
  3707.         /*
  3708.          @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
  3709.          @ primitive implementation of a 'broken scale' graph...
  3710.          @ 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 />
  3711.          @%sgraph%size 400,400%xrange 0,10000%yrange 0,100%sgraph 9000,50,100,10,4,4,grey,blue%userinput_xy%linewidth 2%userdraw segments,red%precision 0%mouse blue,22
  3712.         */
  3713.             if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
  3714.             for(i = 0 ; i < 8 ;i++){
  3715.                 switch(i){
  3716.                     case 0:double_data[0] = get_real(infile,0);break;
  3717.                     case 1:double_data[1] = get_real(infile,0);break;
  3718.                     case 2:double_data[2] = get_real(infile,0);break;
  3719.                     case 3:double_data[3] = get_real(infile,0);break;
  3720.                     case 4:int_data[0] = (int)(get_real(infile,0));break;
  3721.                     case 5:int_data[1] = (int)(get_real(infile,0));break;
  3722.                     case 6:stroke_color = get_color(infile,0);break;
  3723.                     case 7:font_color = get_color(infile,1);
  3724.                     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);
  3725.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3726.                     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);
  3727.                     add_to_buffer(tmp_buffer);
  3728.                     break;
  3729.                     default:break;
  3730.                 }
  3731.             }
  3732.             /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
  3733.             break;
  3734.  
  3735.         case SNAPTOFUNCTION:
  3736.         /*
  3737.         @ snaptofunction some_function_in_x,some_funtion_in_y
  3738.         @ alternative : snaptofun some_function_in_x,some_funtion_in_y
  3739.         @ the next object will snap to the calculated values
  3740.         @ if you want only modification of y-values,just use: snaptofunction x,5*sin(1/y)
  3741.         @ if you want only modification of x-values,just use: snaptofunction 5*sin(1/x),y
  3742.         @ for now only one instance of 'snaptofunction' is allowed
  3743.         @ use rawmath on your functions: no validity checking is done by wims !
  3744.         @ note: switching x and y coordinates?<br />snaptofunction y,x
  3745.         */
  3746.         temp = get_string_argument(infile,0);
  3747.         fprintf(js_include_file,"\nuse_snap_to_points = 2;");
  3748.         if( use_js_math == FALSE){/* add this stuff only once...*/
  3749.             add_to_js_math(js_include_file); use_js_math = TRUE;
  3750.         }
  3751.         fprintf(js_include_file,"var snap_fun = {x:to_js_math('%s'),y:to_js_math('%s')};function snap_to_fun(px,py){ var x = px2x(px); var y = px2y(py); return [ x2px(eval(snap_fun.x)) , y2px(eval(snap_fun.y)) ];};",temp,get_string(infile,1));
  3752.         break;
  3753.         case SNAPTOPOINTS:
  3754.         /*
  3755.         @ snaptopoints x1,y1,x2,y2,x3,y3....
  3756.         @ a userdraw object will snap to these points.
  3757.         @ the array size (e.g. the number of points) of command 'snaptopoints' is limited by constant MAX_INT (canvasdraw.h)
  3758.         @ a draggable object (use command "drag  x|y|xy") will snap to the clossed of these points when dragged (mouseup)
  3759.         @ other options: use keyword "snaptogrid", "xsnaptogrid" or "ysnaptogrid"
  3760.         @%snaptopoints%size 400,400%xrange -5,5%yrange -5,5%colorpalette red,green,blue,orange%snaptopoints -1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%linewidth 2%points red,-1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%userdraw arrows,red
  3761.         */
  3762.             i = 0;
  3763.             while( ! done ){     /* get next item until EOL*/
  3764.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3765.                 if(i%2 == 0 ){
  3766.                     double_data[i] = get_real(infile,0); /* x */
  3767.                 }
  3768.                 else
  3769.                 {
  3770.                     double_data[i] = get_real(infile,1); /* y */
  3771.                 }
  3772.                 i++;
  3773.             }
  3774.             decimals = find_number_of_digits(precision);
  3775.             fprintf(js_include_file,"\nuse_snap_to_points = 1;\nfunction find_min_diff(x,y,X,Y){var diff = 100000000;var chk;var idx = 0;for(var p = 0 ; p < %d ; p++){chk = distance(x,y,X[p],Y[p]);if( chk  < diff ){ diff = chk; idx = p;};};return idx;};\nfunction snap_to_points(x,y){x = px2x(x); y = px2y(y);var points = [%s];var xpoints = points[0];var ypoints = points[1];var idx = find_min_diff(x,y,xpoints,ypoints);x = xpoints[idx];y = ypoints[idx];return [x2px(x),y2px(y)];};\n",(int) (0.5*i),double_xy2js_array(double_data,i,decimals));
  3776.         break;
  3777.  
  3778.         case SNAPTOGRID:
  3779.         /*
  3780.          @ snaptogrid
  3781.          @ keyword (no arguments required)
  3782.          @ a draggable object (use command "drag  x|y|xy") will snap to the given grid when dragged (mouseup)
  3783.          @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
  3784.          @ if no grid is defined ,points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1)
  3785.          @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
  3786.          @ if xminor / yminor is defined,(use keyword 'axis' to activate the minor steps) 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 />
  3787.          @%snaptogrid_1%size 400,400%xrange -5,5%yrange -5,5%axis%axisnumbering%precision 1%grid 1,1,grey,2,2,6,grey%linewidth 2%snaptogrid%userdraw crosshairs,blue%mouse red,22
  3788.          @%snaptogrid_2%size 400,400%xrange -5,5%yrange -5,5%axis%axisnumbering%precision 1%grid 1,1,grey,4,1,6,grey%linewidth 1%snaptogrid%userdraw crosshairs,blue%mouse red,22
  3789.         */
  3790.         fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;");
  3791.         break;
  3792.  
  3793.         case SQUARE:
  3794.         /*
  3795.         @ square x,y,side (px) ,color
  3796.         @ draw a square with left top corner (x:y) with side 'side' in color 'color'
  3797.         @ use command 'fsquare x,y,side,color' for a filled square
  3798.         @ use command/keyword  <a href='#filled'>'filled'</a> before command 'square x,y,side,color'
  3799.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3800.         @%square%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%filled%fillcolor blue%square 0,0,120,green
  3801.         */
  3802.             for(i=0;i<4;i++){
  3803.                 switch(i){
  3804.                     case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
  3805.                     case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
  3806.                     case 2:double_data[2] = get_real(infile,0);break; /* width in px */
  3807.                     case 3:stroke_color = get_color(infile,1);/* name or hex color */
  3808.                            decimals = find_number_of_digits(precision);
  3809.                            double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
  3810.                            double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
  3811.                            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,%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,rotation_center,use_offset,use_pattern);
  3812.                            if(onclick > 0){click_cnt++;}/* click_cnt++; */
  3813.                            reset();break;
  3814.                     default: break;
  3815.                 }
  3816.             }
  3817.             break;
  3818.            
  3819.         case STATUS:
  3820.         /*
  3821.         @ status
  3822.         @ keyword
  3823.         @ alernative : nostatus
  3824.         @ used to override the effects of "status=done" in wims (answer.phtml)
  3825.         @ affects 'readonly' in inputfields / textarea's in canvasimage and all userdraw based commands
  3826.         @ 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'
  3827.         */
  3828.  
  3829.             fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
  3830.             break;
  3831.  
  3832.         case STRING:
  3833.         /*
  3834.          @ string color,x,y,the text string
  3835.          @ may be set "onclick" or "drag xy"
  3836.          @ unicode supported: string red,0,0,\\u2232
  3837.          @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
  3838.          @%string%size 400,400%xrange -10,10%yrange -10,10%fontfamily 14px Ariel%crosshair -3,-3,red%crosshair 3,3,blue%string red,-3,-3,Hello World%fontfamily Italic 18px Ariel%string red,3,3,Hello World%fontfamily 22pt STIX%string black,-10,8,\\u03B1 \\u03B2 \\u03B3 \\u03B4 \\u03B5 \\u03B6 \\u03B7 \\u03B8 \\u03B9 \\u03BA \\u03BB \\u03BC \\u03BD \\u03BE \\u03BF
  3839.         */
  3840.             for(i=0;i<5;i++){
  3841.                 switch(i){
  3842.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  3843.                     case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
  3844.                     case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
  3845.                     case 3: decimals = find_number_of_digits(precision);
  3846.                         temp = get_string_argument(infile,1);
  3847.                         decimals = find_number_of_digits(precision);
  3848.                         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,%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,rotation_center,use_offset,use_pattern);
  3849.                         if(onclick > 0){click_cnt++;}
  3850.                         /* click_cnt++;*/
  3851.                         reset();
  3852.                         break;
  3853.                     default:break;
  3854.                 }
  3855.             }
  3856.             break;
  3857.  
  3858.         case STRINGUP:
  3859.         /*
  3860.          @ stringup color,x,y,rotation_degrees,the text string
  3861.          @ can <b>not</b> be set "onclick" or "drag xy" (because of translation matrix...mouse incompatible)
  3862.          @ unicode supported: stringup red,0,0,45,\\u2232
  3863.          @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change
  3864.          @ you could use keyword <a href='#yoffset'>yoffset</a> to -sometimes- do a small correction of text placement under/above a point<br />(e.g. text &amp; point have thesame coordinates)
  3865.          @%stringup%size 400,400%xrange -10,10%yrange -10,10%fontfamily 14px Ariel%crosshair -3,0,red%crosshair 3,0,blue%stringup red,-3,0,-90,Hello World%stringup red,-3,0,-45,Hello World%stringup red,-3,0,45,Hello World%stringup red,-3,0,90,Hello World%stringup blue,3,0,-90,Hello World%stringup blue,3,0,-45,Hello World%stringup blue,3,0,45,Hello World%stringup blue,3,0,90,Hello World
  3866.  
  3867.         */
  3868.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library : rotate / mouse issues */
  3869.             for(i=0;i<6;i++){
  3870.                 switch(i){
  3871.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  3872.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  3873.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  3874.                     case 3: double_data[0] = get_real(infile,0);break;/* rotation */
  3875.                     case 4: decimals = find_number_of_digits(precision);
  3876.                             temp = get_string_argument(infile,1);
  3877.                             string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix,use_offset);
  3878.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3879.                             snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix,use_offset);
  3880.                             add_to_buffer(tmp_buffer);
  3881.                             break;
  3882.                     default:break;
  3883.                 }
  3884.             }
  3885.             reset();
  3886.             break;
  3887.  
  3888.         case STYLE:
  3889.         /*
  3890.          @ highlight color,opacity,linewidth
  3891.          @ NOT IMPLEMENTED
  3892.          @ use command "onclick" : when the object receives a userclick it will increase its linewidth
  3893.         */
  3894.             break;
  3895.  
  3896.  
  3897.         case STROKECOLOR:
  3898.         /*
  3899.         @ strokecolor colorname or #hex
  3900.         @ to be used for commands that do not supply a color argument (like command 'linegraph')
  3901.         */
  3902.             stroke_color = get_color(infile,1);
  3903.             break;
  3904.  
  3905.         case FLY_TEXT:
  3906.         /*
  3907.         @ text fontcolor,x,y,font,text_string
  3908.         @ font may be described by keywords : giant,huge,normal,small,tiny
  3909.         @ use command 'fontsize' to increase base fontsize for these keywords
  3910.         @ may be set "onclick" or "drag xy"
  3911.         @ backwards compatible with flydraw
  3912.         @ unicode supported: text red,0,0,huge,\\u2232
  3913.         @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element
  3914.         @ 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.
  3915.         @%text%size 400,400%xrange -10,10%yrange -10,10%fontsize 14%onclick%drag xy%text green,-4,-4,small,Hello World%drag xy%text red,-4,-2,large,Hello World%drag xy%text blue,-4,0,huge,Hello World%drag xy%text green,-4,3,giant,Hello World%drag xy
  3916.         */
  3917.             for(i = 0; i < 5 ;i++){
  3918.                 switch(i){
  3919.                     case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
  3920.                     case 1: double_data[0] = get_real(infile,0);break; /* x */
  3921.                     case 2: double_data[1] = get_real(infile,0);break; /* y */
  3922.                     case 3: fly_font = get_string_argument(infile,0);
  3923.                             if(strcmp(fly_font,"giant") == 0){
  3924.                                 fly_font_size = (int)(font_size + 24);
  3925.                             }
  3926.                             else
  3927.                             {
  3928.                                 if(strcmp(fly_font,"huge") == 0){
  3929.                                     fly_font_size = (int)(font_size + 14);
  3930.                                 }
  3931.                                 else
  3932.                                 {
  3933.                                     if(strcmp(fly_font,"large") == 0){
  3934.                                         fly_font_size = (int)(font_size + 6);
  3935.                                         }
  3936.                                         else
  3937.                                         {
  3938.                                             if(strcmp(fly_font,"small") == 0){
  3939.                                                 fly_font_size = (int)(font_size - 4);
  3940.                                                 if(fly_font_size<0){fly_font_size = 8;}
  3941.                                         }
  3942.                                     }
  3943.                                 }
  3944.                             }
  3945.                             break;
  3946.                     case 4:
  3947.                         temp = get_string_argument(infile,1);
  3948.                         decimals = find_number_of_digits(precision);
  3949.                         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,%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,fly_font_size,"null",use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern);
  3950.                         if(onclick > 0){click_cnt++;}
  3951.                         /* click_cnt++;*/
  3952.                         reset();
  3953.                         break;
  3954.                     default:break;
  3955.                 }
  3956.             }
  3957.             break;
  3958.         case TEXTAREA:
  3959.         /*
  3960.          @ textarea x,y,cols,rows,readonly,value
  3961.          @ may be further controlled by <a href="#inputstyle">"inputstyle"</a>
  3962.          @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be cleared and set readonly<br />override this by keyword <a href="#status">'status'.</a>
  3963.          @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
  3964.          @ keyword 'xoffset | centered' is not active for commande 'textarea'
  3965.          @%textarea%size 400,400%xrange -10,10%yrange -10,10%inputstyle color:red;background-color:lightblue;font-size:14px;text-align:center%textarea -3,-2,6,3,1,?%inputstyle color:blue;background-color:yellow;font-size:14px;text-align:center%textarea 0,-2,8,2,1,?
  3966.         */
  3967.             if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}
  3968.             for(i = 0 ; i<6;i++){
  3969.                 switch(i){
  3970.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
  3971.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
  3972.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
  3973.                     case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
  3974.                     case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
  3975.                     case 5: temp = get_string_argument(infile,1);
  3976.                             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);
  3977.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  3978.                             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);
  3979.                             add_to_buffer(tmp_buffer);
  3980.                             input_cnt++;break;
  3981.                     default: break;
  3982.                 }
  3983.             }
  3984.             if(reply_format == 0 ){reply_format = 15;}
  3985.             reset();
  3986.             break;
  3987.  
  3988.         case TEXTFILL:
  3989.         /*
  3990.         @ textfill x0,y0,color,some_text
  3991.         @ x0,y0 in xrange / yrange
  3992.         @ color will be used for the font color
  3993.         @ use command <a href="#fontfamily">fontfamily</a> to set font type and size
  3994.         @ there is also a command <a href="#userdraw">userdraw textfill,color,some_text</a>
  3995.         @%textfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fontfamily 24pt Ariel%circles red,0,0,3,3,3,6%textfill 4,4,blue, HALLO
  3996.         */
  3997.  
  3998.             js_function[DRAW_TEXTFILL] = 1;
  3999.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  4000.              js_function[DRAW_FILLTOBORDER] = 1;
  4001.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  4002.             }
  4003.             decimals = find_number_of_digits(precision);
  4004.             for(i=0;i<4;i++){
  4005.                 switch(i){
  4006.                     case 0: double_data[0] = get_real(infile,0); break; /* x in px */
  4007.                     case 1: double_data[1] = get_real(infile,0); break; /* y in py */
  4008.                     case 2: font_color = get_color(infile,0); break;
  4009.                     case 3: temp = get_string(infile,1);
  4010.                     string_length = snprintf(NULL,0,"draw_textfill(%d,%*.f,%*.f,'%s','%s',%d,%d,'%s',false); ",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],font_color,font_family,xsize,ysize,temp);
  4011.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4012.                     snprintf(tmp_buffer,string_length,"draw_textfill(%d,%*.f,%*.f,'%s','%s',%d,%d,'%s',false); ",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],font_color,font_family,xsize,ysize,temp);
  4013.                     add_to_buffer(tmp_buffer);
  4014.                     fill_cnt++;
  4015.                     break;
  4016.                     default:break;
  4017.                 }
  4018.             }
  4019.             reset();
  4020.         break;
  4021.  
  4022.  
  4023.         case FLY_TEXTUP:
  4024.         /*
  4025.          @ textup fontcolor,x,y,font,text_string
  4026.          @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
  4027.          @ font may be described by keywords : giant,huge,normal,small,tiny
  4028.          @ use command 'fontsize' to increase base fontsize for the keywords
  4029.          @ backwards compatible with flydraw
  4030.          @ unicode supported: textup red,0,0,huge,\\u2232
  4031.          @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element
  4032.          @ 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.
  4033.         */
  4034.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
  4035.             for(i = 0; i<5 ;i++){
  4036.                 switch(i){
  4037.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  4038.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  4039.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  4040.                     case 3: fly_font = get_string_argument(infile,0);
  4041.                             if(strcmp(fly_font,"giant") == 0){
  4042.                                 fly_font_size = (int)(font_size + 24);
  4043.                             }
  4044.                             else
  4045.                             {
  4046.                                 if(strcmp(fly_font,"huge") == 0){
  4047.                                     fly_font_size = (int)(font_size + 14);
  4048.                                 }
  4049.                                 else
  4050.                                 {
  4051.                                     if(strcmp(fly_font,"large") == 0){
  4052.                                         fly_font_size = (int)(font_size + 6);
  4053.                                         }
  4054.                                         else
  4055.                                         {
  4056.                                             if(strcmp(fly_font,"small") == 0){
  4057.                                                 fly_font_size = (int)(font_size - 4);
  4058.                                                 if(fly_font_size<0){fly_font_size = 8;}
  4059.                                         }
  4060.                                     }
  4061.                                 }
  4062.                             }
  4063.                             break;
  4064.                     case 4:
  4065.                     decimals = find_number_of_digits(precision);
  4066.                     temp = get_string_argument(infile,1);
  4067.                     string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix,use_offset);
  4068.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4069.                     snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix,use_offset);
  4070.                     add_to_buffer(tmp_buffer);
  4071.                     break;
  4072.                     default:break;
  4073.                 }
  4074.             }
  4075.             reset();
  4076.             break;
  4077.  
  4078.  
  4079.         case TRACE_JSCURVE:
  4080.         /*
  4081.          @ trace_jscurve some_math_function
  4082.          @ will use a crosshair to trace the jsmath curve
  4083.          @ two inputfields will display the current x/y-values (numerical evaluation by javascript)
  4084.          @ default labels 'x' and 'y'<br />use commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' to customize the labels for the input fields
  4085.          @ use commands fontsize and inputstyle to format the fonts for labels and inputfields.
  4086.          @ use commands linewidth,strokecolor,crosshairsize to adjust the corsshair.
  4087.          @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x instead 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...
  4088.         @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
  4089.         */
  4090.             if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  4091.             if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4092.             if( use_js_math == FALSE){
  4093.                 add_to_js_math(js_include_file);
  4094.                 use_js_math = TRUE;
  4095.             }
  4096.             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,input_style);
  4097.             break;
  4098.  
  4099.  
  4100.         case TRANGE:
  4101.         /*
  4102.         @ trange tmin,tmax
  4103.         @ alternative : ranget
  4104.         @ default -2,2
  4105.         */
  4106.             use_parametric = TRUE;
  4107.             for(i = 0 ; i<2; i++){
  4108.                 switch(i){
  4109.                     case 0: tmin = get_real(infile,0);break;
  4110.                     case 1: tmax = get_real(infile,1);break;
  4111.                     default: break;
  4112.                 }
  4113.             }
  4114.             if(tmin >= tmax ){canvas_error(" trange is not OK : tmin &lt; tmax!\n");}
  4115.             break;
  4116.         case TRANSLATION:
  4117.         /*
  4118.          @ translation tx,ty
  4119.          @ alternative : translate
  4120.          @ will translate the next objects tx in xrange and ty in yrange
  4121.          @ use command 'killtranstation' to end the command
  4122.         */
  4123.             for(i = 0 ; i<2;i++){
  4124.                 switch(i){
  4125.                     case 0: double_data[0] = get_real(infile,0);break;
  4126.                     case 1: double_data[1] = get_real(infile,1);
  4127.                         use_affine = TRUE;
  4128.                         decimals = find_number_of_digits(precision);
  4129.                         string_length = snprintf(NULL,0, "[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin));
  4130.                         check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
  4131.                         snprintf(affine_matrix,string_length,"[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin));
  4132.                         break;
  4133.                     default: break;
  4134.                 }
  4135.             }
  4136.         break;
  4137.  
  4138.         case TRIANGLE:
  4139.         /*
  4140.          @ triangle x1,y1,x2,y2,x3,y3,color
  4141.          @ use ftriangle or keyword <a href='#filled'>'filled'</a> for a solid triangle
  4142.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4143.         */
  4144.             for(i=0;i<7;i++){
  4145.                 switch(i){
  4146.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  4147.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  4148.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  4149.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  4150.                     case 4: double_data[4] = get_real(infile,0);break; /* x */
  4151.                     case 5: double_data[5] = get_real(infile,0);break; /* y */
  4152.                     case 6: stroke_color = get_color(infile,1);/* name or hex color */
  4153.                         decimals = find_number_of_digits(precision);
  4154.                         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,%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,rotation_center,use_offset,use_pattern);
  4155.                         if(onclick > 0){click_cnt++;}
  4156.                         /* click_cnt++;*/
  4157.                         reset();
  4158.                         break;
  4159.                     default: break;
  4160.                 }
  4161.             }
  4162.             break;
  4163.         case TRIANGLES:
  4164.         /*
  4165.          @ triangles color,x1,y1,x2,y2,x3,y3,...
  4166.          @ use ftriangles or keyword <a href='#filled'>'filled'</a> for solid triangles
  4167.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  4168.         */
  4169.             stroke_color = get_color(infile,0);/* name or hex color */
  4170.             i = 0;
  4171.             decimals = find_number_of_digits(precision);
  4172.             while( ! done ){
  4173.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4174.                 double_data[0] = get_real(infile,0); /* x1 */
  4175.                 double_data[1] = get_real(infile,0); /* y1 */
  4176.                 double_data[2] = get_real(infile,0); /* x2 */
  4177.                 double_data[3] = get_real(infile,0); /* y2 */
  4178.                 double_data[4] = get_real(infile,0); /* x3 */
  4179.                 double_data[5] = get_real(infile,1); /* y3 */
  4180.                 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,%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,rotation_center,use_offset,use_pattern);
  4181.                 if(onclick > 0){click_cnt++;}
  4182.                 i = i + 6;
  4183.             }
  4184.             reset();
  4185.             break;
  4186.         case USERBOXPLOT:
  4187.         /*
  4188.          @ userboxplot
  4189.          @ keyword, no arguments
  4190.          @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a>
  4191.          @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the 'draw_boxplot' function
  4192.          @ for example:<br />put the canvas-script into a html element with id='boxplot'and set style='display:none'<br />define a variable called 'student_boxplot' and fill it with the 5 student-data (from inputfields or something)<br />var student_boxplot = new Array(5)<br />function show_boxplot(){<br />student_boxplot[0] = min;<br />student_boxplot[1] = Q1;<br />student_boxplot[2] = median;<br />student_boxplot[3] = Q3;<br />student_boxplot[4] = max;<br />document.getElementById('boxplot').style.display = "block";<br />draw_boxplot(12345,1,2.00,5.00,[0,0,0,0,0],4,"0,0,255",0.78,"255,165,0",0.60,1,0,1,1);<br />};<br />In the canvas-script the function draw_boxplot has the following arguments:<br />draw_boxplot=function(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1)
  4193.         */
  4194.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  4195.             fprintf(js_include_file,"var boxplot_source = 3;\n");
  4196.             js_function[DRAW_JSBOXPLOT] = 2;
  4197.         break;
  4198.  
  4199.         case USERBOXPLOTDATA:
  4200.         /*
  4201.          @ userboxplotdata
  4202.          @ keyword, no arguments
  4203.          @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a>
  4204.          @ if set, the student will have to generate some statistical data. These data should be put in a named array "student_boxplot_data"
  4205.          @ "min,Q1,median,Q3,max" are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot.
  4206.          @ see command <a href="#userboxplot">'userboxplot'</a> for calling 'draw_boxplot()'
  4207.         */
  4208.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  4209.             fprintf(js_include_file,"var boxplot_source = 2;\n");
  4210.             js_function[DRAW_JSBOXPLOT] = 1;
  4211.  
  4212.         break;
  4213.  
  4214.         case USERDRAW:
  4215.         /*
  4216.         @ userdraw object_type,color
  4217.         @ only a single object_type is allowed.
  4218.         @ for multiple object user drawings use command <a href="#multidraw">'multidraw'</a>
  4219.         @ implemented object_type: <ul><li>point</li><li>points</li><li>crosshair</li><li>crosshairs</li><li>line</li><li>lines</li><li>vline</li><li>vlines</li><li>hline</li><li>hlines</li><li>demiline</li><li>demilines</li><li>segment</li><li>segments</li><li>polyline | brokenline </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] (e.g poly3 ... poly7...poly9 </li><li>rect</li><li>roundrect</li><li>rects</li><li>roundrects</li><li>freehandline | path</li><li>freehandlines | paths</li><li>clickfill : fill the clicked area with color<br />multiple areas may be selected <br />multiple colors may be provided using commands <a href='#colorpalette'>colorpalette color1,color2,color3,...</a> or <a href='#multifillcolors'>multifillcolors color1,color2,color_3,...</a> use <a href='#replyformat'>replyformat 10</a> for checking the user click color ... reply=x1:y1:color1,x2:y2:color2...<br/>attention: this will <b>not</b> work for pattern filling, because the pattern image is only generated once and after creation can not be changed !<br />the opacity of this image on a separate canvas is set to 0.01 and not 0 (!!)...in the 'fill algorithm' the opacity of the matching pixels is set to 1</li><li>dotfill : fill the clicked area with a dot pattern; use command linewidth to change dot size</li><li>diamondfill : fill the clicked area with a diamond pattern</li><li>hatchfill : fill the clicked area with a hatch pattern</li><li>gridfill : fill the clicked area with a grid pattern</li><li>textfill: fill the clicked area with a repeating string<br />userdraw textfill,blue,some_text<br />use command <a href="#fontfamily">fontfamily</a> to adjust text style and size</li><li>'clickfill | pattern filling' in general:<br />the clicks may be set <a href="#snaptogrid">'snaptogrid'</a><br />can be used together with command <a href="#floodfill">'floodfill' or 'fill'</a><br /><b>always</b> use together with command <a href="clearbutton">'clearbutton some_text'</a> for removal of all click_colored areas<br />the function read_canvas() will return the click coordinates in the sequence of the user clicks<br />use command <a href="#canvastype">'canvastype'</a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)</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>
  4220.         @ 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)
  4221.         @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />"backspace / delete / esc" will remove typed text if the mouse is clicked non the text.<br />You will need to hit "enter" to add the text to the array "userdraw_txt"<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
  4222.         @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
  4223.         @ note: all objects will be removed -after a javascript confirm box- when clicked on an object point with middle or right mouse button (e.g. event.which != 1 : all buttons but left)
  4224.         @ use a prefix 'filled' or 'f' to set fillable objects filled. (fcircles,filledcircles etc)
  4225.         @ for non solid filling, use command <a href="#fillpattern">fillpattern grid,hatch,diamond,dot</a>
  4226.         @ use "opacity int,int"  and "fillcolor color" to trigger coloured filling of fillable objects
  4227.         @ use command "dashed" and/or "dashtype int,int" to trigger dashing
  4228.         @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas();
  4229.         @ may be combined with onclick or drag xy  of other components of flyscript objects (although not very usefull...)
  4230.         @ may be combined with keyword 'userinput_xy'
  4231.         @ 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.!<br />use command <a href="#multidraw">multidraw</a> is this is a problem for you...
  4232.         @%userdraw_canvastype_a%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%snaptogrid%replyformat 10%colorpalette orange,yellow,red,green,lightgreen,blue,lightblue,cyan%canvastype 4%userdraw clickfill,blue%clearbutton REMOVE LAST RECTANGLE
  4233.         @%userdraw_canvastype_b%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%canvastype 4%snaptogrid%replyformat 10%userdraw dotfill,blue%clearbutton REMOVE LAST RECTANGLE
  4234.         @%userdraw_rect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw rect,green
  4235.         @%userdraw_rects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw rects,green
  4236.         @%userdraw_frect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw frect,green
  4237.         @%userdraw_frects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw frects,green
  4238.         @%userdraw_roundrect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw roundrect,green
  4239.         @%userdraw_roundrects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw roundrects,green
  4240.         @%userdraw_froundrect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw froundrect,green
  4241.         @%userdraw_froundrects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw froundrects,green
  4242.         @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
  4243.         @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
  4244.         @%userdraw_vline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vline,green
  4245.         @%userdraw_vlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vlines,green
  4246.         @%userdraw_hline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hline,green
  4247.         @%userdraw_hlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hlines,green
  4248.         @%userdraw_demiline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demiline,green
  4249.         @%userdraw_demilines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demilines,green
  4250.         @%userdraw_arc%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw arc,green
  4251.         @%userdraw_arcs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw arcs,green
  4252.         @%userdraw_point%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw point,green
  4253.         @%userdraw_points%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw points,green
  4254.         @%userdraw_arrow%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow,green
  4255.         @%userdraw_arrows%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows,green
  4256.         @%userdraw_arrow2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow2,green
  4257.         @%userdraw_arrows2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows2,green
  4258.         @%userdraw_crosshair%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshair,green
  4259.         @%userdraw_crosshairs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshairs,green
  4260.         @%userdraw_circle%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw circle,green
  4261.         @%userdraw_circles%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw circles,green
  4262.         @%userdraw_segment%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segment,green
  4263.         @%userdraw_segments%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segments,green
  4264.         @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
  4265.         @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
  4266.         @%userdraw_triangle%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw triangle,green
  4267.         @%userdraw_poly5%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw poly5,green
  4268.         @%userdraw_filled_poly5%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%filled%userdraw poly5,green
  4269.         @%userdraw_poly7%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw poly7,green
  4270.         @%userdraw_filled_poly7%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%filled%userdraw poly7,green
  4271.         @%userdraw_polyline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw polyline,green
  4272.         @%userdraw_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandline,green
  4273.         @%userdraw_filled_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%filled%userdraw freehandline,green
  4274.         @%userdraw_freehandlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandlines,green
  4275.         @%userdraw_input%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw input,green
  4276.         @%userdraw_inputs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw inputs,green
  4277.         @%userdraw_text%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%fontfamily 42px Courier%userdraw text,green
  4278.         */
  4279.             if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
  4280.                 canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");
  4281.             }
  4282.             reply_precision = precision;
  4283.             use_userdraw = TRUE;
  4284.             fprintf(js_include_file,"\n<!-- begin userdraw mouse events -->\n\
  4285.             userdraw_x = new Array();userdraw_y = new Array();\
  4286.             userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\
  4287.             var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;\
  4288.             if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\
  4289.             if(wims_status != \"done\"){\
  4290.             canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\
  4291.             canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\
  4292.             canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
  4293.             canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\
  4294.             canvas_div.addEventListener(\"touchend\"  ,function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
  4295.             }\n<!-- end userdraw mouse & touch events -->",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
  4296.             draw_type = get_string_argument(infile,0);
  4297.             stroke_color = get_color(infile,1);
  4298.             if( strcmp(draw_type,"point") == 0 ){
  4299.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4300.                 if(reply_format == 0 ){reply_format = 8;}
  4301.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  4302. /*
  4303. type = 0 : a point ...radius is fixed                                                                                  
  4304. type = 1 : a circle ... read inputfield userinput_r                                                                    
  4305. num = 1 : a single point / circle                                                                                      
  4306. num = 2 : multiple points / circles
  4307. */
  4308.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4309.                 if(use_input_xy == 1){
  4310.                     add_input_circle(js_include_file,0,1);
  4311.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4312.                 }
  4313.                 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);
  4314.             }
  4315.             else
  4316.             if( strcmp(draw_type,"points") == 0 ){
  4317.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4318.                 if(reply_format == 0 ){reply_format = 8;}
  4319.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  4320.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4321.                 if(use_input_xy == 1){
  4322.                     add_input_circle(js_include_file,0,2);
  4323.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4324.                 }
  4325.                 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);
  4326.             }
  4327.             else
  4328.             if( strcmp(draw_type,"segment") == 0 ){
  4329.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4330.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  4331.                 if(reply_format == 0){reply_format = 11;}
  4332.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4333.                 if(use_input_xy == 1){
  4334.                     add_input_segment(js_include_file,1);
  4335.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4336.                 }
  4337.                 add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  4338.             }
  4339.             else
  4340.             if( strcmp(draw_type,"polyline") == 0 ||  strcmp(draw_type,"brokenline") == 0 ){
  4341.                 if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
  4342.                 if(reply_format == 0){reply_format = 23;}
  4343.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4344.                 if( use_input_xy == 1 ){
  4345.                     add_input_polyline(js_include_file);
  4346.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4347.                 }
  4348.                 add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  4349.             }
  4350.             else
  4351.             if( strcmp(draw_type,"segments") == 0 ){
  4352.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4353.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  4354.                 if(reply_format == 0){reply_format = 11;}
  4355.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4356.                 if(use_input_xy == 1){
  4357.                     add_input_segment(js_include_file,2);
  4358.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4359.                 }
  4360.                 add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  4361.             }
  4362.             else
  4363.             if( strcmp(draw_type,"circle") == 0 || strcmp(draw_type,"fcircle") == 0  || strcmp(draw_type,"filledcircle") == 0 ){
  4364.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4365.                 if(reply_format == 0){reply_format = 10;}
  4366.                 if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}}
  4367.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  4368.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4369.                 if(use_input_xy == 1){
  4370. /*
  4371. type = 0 : a point ...radius is fixed                                                                                  
  4372. type = 1 : a circle ... read inputfield userinput_r                                                                    
  4373. num = 1 : a single point / circle                                                                                      
  4374. num = 2 : multiple points / circles
  4375. */
  4376.                     add_input_circle(js_include_file,1,1);
  4377.                     add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
  4378.                 }
  4379.                 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]);
  4380.             }
  4381.             else
  4382.             if( strcmp(draw_type,"circles") == 0 || strcmp(draw_type,"fcircles") == 0 || strcmp(draw_type,"filledcircles") == 0 ){
  4383.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4384.                 if(reply_format == 0){reply_format = 10;}
  4385.                 if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4386.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  4387.                 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]);
  4388.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4389.                 if(use_input_xy == 1){
  4390.                     add_input_circle(js_include_file,1,2);
  4391.                     add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
  4392.                 }
  4393.             }
  4394.             else
  4395.             if(strcmp(draw_type,"crosshair") == 0 ){
  4396.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  4397.                 if(reply_format == 0){reply_format = 8;}
  4398.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  4399.                 add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
  4400.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4401.                 if(use_input_xy == 1){
  4402.                     add_input_crosshair(js_include_file,1);
  4403.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4404.                 }
  4405.             }
  4406.             else
  4407.             if(strcmp(draw_type,"crosshairs") == 0 ){
  4408.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  4409.                 if(reply_format == 0){reply_format = 8;}
  4410.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  4411.                 add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
  4412.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4413.                 if(use_input_xy == 1){
  4414.                     add_input_crosshair(js_include_file,2);
  4415.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4416.                 }
  4417.             }
  4418.             else
  4419.             if(strcmp(draw_type,"freehandline") == 0 ){
  4420.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4421.                 if(reply_format == 0){reply_format = 6;}
  4422.                 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]);
  4423.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4424.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4425.             }
  4426.             else
  4427.             if(strcmp(draw_type,"freehandlines") == 0 ){
  4428.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4429.                 if(reply_format == 0){reply_format = 6;}
  4430.                 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]);
  4431.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4432.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4433.             }
  4434.             else
  4435.             if(strcmp(draw_type,"path") == 0 || strcmp(draw_type,"fpath") == 0 || strcmp(draw_type,"filledpath") == 0 ){
  4436.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4437.                 if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4438.                 if(reply_format == 0){reply_format = 6;}
  4439.                 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]);
  4440.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4441.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4442.             }
  4443.             else
  4444.             if(strcmp(draw_type,"paths") == 0 || strcmp(draw_type,"fpaths") == 0  || strcmp(draw_type,"filledpaths") == 0 ){
  4445.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4446.                 if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4447.                 if(reply_format == 0){reply_format = 6;}
  4448.                 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]);
  4449.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4450.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4451.             }
  4452.             else
  4453.             if(strcmp(draw_type,"arrows") == 0 ){
  4454.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  4455.                 if(reply_format == 0){reply_format = 11;}
  4456.                 add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  4457.                 if(use_input_xy == 1){
  4458.                     add_input_arrow(js_include_file,2);
  4459.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4460.                 }
  4461.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4462.             }
  4463.             else
  4464.             if(strcmp(draw_type,"arrows2") == 0 ){
  4465.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  4466.                 if(reply_format == 0){reply_format = 11;}
  4467.                 add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  4468.                 if(use_input_xy == 1){
  4469.                     add_input_arrow(js_include_file,1);
  4470.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4471.                 }
  4472.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4473.             }
  4474.             else
  4475.             if(strcmp(draw_type,"arrow2") == 0 ){
  4476.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  4477.                 if(reply_format == 0){reply_format = 11;}
  4478.                 add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  4479.                 if(use_input_xy == 1){
  4480.                     add_input_arrow(js_include_file,1);
  4481.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4482.                 }
  4483.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4484.             }
  4485.             else
  4486.             if(strcmp(draw_type,"arrow") == 0 ){
  4487.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  4488.                 if(reply_format == 0){reply_format = 11;}
  4489.                 add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  4490.                 if(use_input_xy == 1){
  4491.                     add_input_arrow(js_include_file,1);
  4492.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4493.                 }
  4494.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4495.             }
  4496.             else
  4497.             if(strcmp(draw_type,"polygon") == 0 || strcmp(draw_type,"fpolygon") == 0 || strcmp(draw_type,"filledpolygon") == 0){
  4498.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4499.                 if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4500.                 if(reply_format == 0){reply_format = 2;}
  4501.                 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]);
  4502.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4503.                 if(use_input_xy == 2){
  4504.                   add_textarea_polygon(js_include_file);
  4505.                   add_textarea_xy(js_include_file,canvas_root_id,input_style);
  4506.                 }
  4507.             }
  4508.             else
  4509.             if(strncmp(draw_type,"poly",4) == 0){
  4510.                 if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
  4511.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4512.                 if(reply_format == 0){reply_format = 2;}
  4513.                 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]);
  4514.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4515.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4516.             }
  4517.             else
  4518.             if(strcmp(draw_type,"triangle") == 0 || strcmp(draw_type,"ftriangle") == 0 || strcmp(draw_type,"filledtriangle") == 0){
  4519.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4520.                 if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4521.                 if(reply_format == 0){reply_format = 2;}
  4522.                 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]);
  4523.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4524.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4525.             }
  4526.             else
  4527.             if( strcmp(draw_type,"hline") == 0 ){
  4528.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4529.                 if(reply_format == 0){reply_format = 11;}
  4530.                 add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  4531.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4532.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4533.             }
  4534.             else
  4535.             if( strcmp(draw_type,"hlines") == 0 ){
  4536.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4537.                 if(reply_format == 0){reply_format = 11;}
  4538.                 add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  4539.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4540.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4541.             }
  4542.             else
  4543.             if( strcmp(draw_type,"vline") == 0 ){
  4544.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4545.                 if(reply_format == 0){reply_format = 11;}
  4546.                 add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  4547.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4548.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4549.             }
  4550.             else
  4551.             if( strcmp(draw_type,"vlines") == 0 ){
  4552.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4553.                 if(reply_format == 0){reply_format = 11;}
  4554.                 add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  4555.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4556.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4557.             }
  4558.             else
  4559.             if( strcmp(draw_type,"line") == 0 ){
  4560.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4561.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4562.                 if(reply_format == 0){reply_format = 11;}
  4563.                 add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  4564.                 if( use_input_xy == 1 ){
  4565.                     add_input_line(js_include_file,1);
  4566.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4567.                 }
  4568.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4569.             }
  4570.             else
  4571.             if( strcmp(draw_type,"lines") == 0 ){
  4572.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4573.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4574.                 if(reply_format == 0){reply_format = 11;}
  4575.                 add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  4576.                 if( use_input_xy == 1 ){
  4577.                     add_input_line(js_include_file,2);
  4578.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4579.                 }
  4580.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4581.             }
  4582.             else
  4583.             if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"halflines") == 0 ){
  4584.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4585.                 if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
  4586.                 if(reply_format == 0){reply_format = 11;}
  4587.                 add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  4588.                 if( use_input_xy == 1 ){
  4589.                     add_input_demiline(js_include_file,2);
  4590.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4591.                 }
  4592.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4593.             }
  4594.             else
  4595.             if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"halfline") == 0 ){
  4596.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4597.                 if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
  4598.                 if(reply_format == 0){reply_format = 11;}
  4599.                 add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  4600.                 if( use_input_xy == 1 ){
  4601.                     add_input_demiline(js_include_file,1);
  4602.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4603.                 }
  4604.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4605.             }
  4606.             else
  4607.             if( strcmp(draw_type,"rects") == 0 || strcmp(draw_type,"frects") == 0  || strcmp(draw_type,"filledrects") == 0 ){
  4608.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  4609.                 if(strstr(draw_type,"f") != NULL){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4610.                 if(reply_format == 0){reply_format = 2;}
  4611.                 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]);
  4612.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4613.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4614.             }
  4615.             else
  4616.             if( strcmp(draw_type,"roundrects") == 0 ||  strcmp(draw_type,"froundrects") == 0  ||  strcmp(draw_type,"filledroundrects") == 0){
  4617.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  4618.                 if( strstr(draw_type,"f") != NULL ){ if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4619.                 if(reply_format == 0){reply_format = 2;}
  4620.                 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]);
  4621.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4622.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4623.             }
  4624.             else
  4625.             if( strcmp(draw_type,"rect") == 0 || strcmp(draw_type,"frect") == 0 || strcmp(draw_type,"filledrect") == 0 ){
  4626.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  4627.                 if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4628.                 if(reply_format == 0){reply_format = 2;}
  4629.                 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]);
  4630.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4631.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4632.             }
  4633.             else
  4634.             if( strcmp(draw_type,"roundrect") == 0 || strcmp(draw_type,"froundrect") == 0  || strcmp(draw_type,"filledroundrect") == 0){
  4635.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  4636.                 if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}}
  4637.                 if(reply_format == 0){reply_format = 2;}
  4638.                 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]);
  4639.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4640.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4641.             }
  4642.             else
  4643.             if( strcmp(draw_type,"arcs") == 0 || strcmp(draw_type,"farcs") == 0  || strcmp(draw_type,"filledarcs") == 0 ){
  4644.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  4645.                 if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
  4646.                 if( strstr(draw_type,"f") != NULL ){use_filled =1;}
  4647.                 if(reply_format == 0){reply_format = 25;}
  4648.                 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]);
  4649.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4650.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4651.             }
  4652.             else
  4653.             if( strcmp(draw_type,"arc") == 0 || strcmp(draw_type,"farc") == 0 || strcmp(draw_type,"filledarc") == 0){
  4654.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  4655.                 if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
  4656.                 if( strstr(draw_type,"f") != NULL ){use_filled =1;}
  4657.                 if(reply_format == 0){reply_format = 25;}
  4658.                 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]);
  4659.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4660.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4661.             }
  4662.             else
  4663.             if( strcmp(draw_type,"text") == 0){
  4664.                 if(reply_format == 0){reply_format = 17;}
  4665.                 add_js_text(js_include_file,canvas_root_id,font_size,font_family,stroke_color,stroke_opacity);
  4666.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4667.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4668.             }
  4669.             else
  4670.             if( strcmp(draw_type,"inputs") == 0){
  4671.                 if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  4672.                 if(reply_format == 0){reply_format = 27;}
  4673.                 add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width,use_offset);
  4674.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4675.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4676.             }
  4677.             else
  4678.             if( strcmp(draw_type,"input") == 0){
  4679.                 if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  4680.                 if(reply_format == 0){reply_format = 27;}
  4681.                 add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width,use_offset);
  4682.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4683.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4684.             }
  4685.             else /* attention: THIS NEEDS TO BE LAST ! */
  4686.             if( strstr(draw_type,"fill") != NULL ){
  4687.                 decimals = find_number_of_digits(precision);
  4688.                 add_js_clickfill(js_include_file,canvas_root_id,stroke_color,(int) (fill_opacity/0.0039215));
  4689.                 if( reply_format == 0){reply_format = 22;}
  4690.                 if( js_function[DRAW_FILLTOBORDER] != 1 ){js_function[DRAW_FILLTOBORDER] = 1;add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);}
  4691.                 if( strcmp(draw_type,"gridfill") == 0){js_function[DRAW_GRIDFILL] = 1;string_length = snprintf(NULL,0,"draw_gridfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);  ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;}
  4692.                 if( strcmp(draw_type,"diamondfill") == 0){js_function[DRAW_DIAMONDFILL] = 1;string_length = snprintf(NULL,0,"draw_diamondfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);  ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_diamondfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;}
  4693.                 if( strcmp(draw_type,"dotfill") == 0){js_function[DRAW_DOTFILL] = 1;string_length = snprintf(NULL,0,"draw_dotfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);  ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;}
  4694.                 if( strcmp(draw_type,"hatchfill") == 0){js_function[DRAW_HATCHFILL] = 1;string_length = snprintf(NULL,0,"draw_hatchfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);  ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;}
  4695.                 if( strcmp(draw_type,"textfill") == 0){js_function[DRAW_TEXTFILL] = 1;temp = get_string(infile,1);string_length = snprintf(NULL,0,"draw_textfill(%d,%d,%d,'%s','%s',%d,%d,'%s',true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),stroke_color,font_family,xsize,ysize,temp);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_textfill(%d,%d,%d,'%s','%s',%d,%d,'%s',true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),stroke_color,font_family,xsize,ysize,temp);add_to_buffer(tmp_buffer);fill_cnt++;}
  4696.             }
  4697.             else
  4698.             {
  4699.                 canvas_error("unknown drawtype or typo? ");
  4700.             }
  4701.             reset();
  4702.         break;
  4703.  
  4704.         case USERINPUT:
  4705.         /*
  4706.          @ userinput function | textarea | inputfield
  4707.          @ alternative : userinput_function
  4708.          @ alternative : userinput_textarea
  4709.          @ alternative : userinput_xy
  4710.          @ textarea and inputfield are only usable in combination with some 'userdraw draw_ type'
  4711.          @ function may be used any time (e.g. without userdraw)
  4712.          @ multiple 'userinput function' commands may be used.
  4713.          @ use command "functionlabel some_string" to define the inputfield text : default value "f(x)="
  4714.          @ use command 'strokecolor some_color' to adjust the plot / functionlabel color
  4715.          @ use command 'inputstyle some_css' to adjust the inputfields
  4716.          @ use command 'fontsize int' to adjust the label fonts. (default 12px)
  4717.          @ the user input for the function will be corrected by a simple 'rawmath' implementation...<br />an error message will be shown if javascript can not interpret the user input
  4718.          @%userinput%size 400,400%xrange -10,10%yrange -10,10%functionlabel some_label=%grid 1,1,grey%inputstyle color:blue;text-align:center%userinput function
  4719.          @%userinput%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%userinput inputfield%userdraw points,blue
  4720.          @%userinput%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%userinput textarea%userdraw points,blue
  4721.         */
  4722.             temp = get_string_argument(infile,1);
  4723.             if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
  4724.              if( js_function[DRAW_JSFUNCTION] != 1 ){
  4725.               add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */
  4726.               js_function[DRAW_JSFUNCTION] = 1;
  4727.               if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  4728.               add_input_jsfunction(js_include_file,canvas_root_id,input_style,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size);
  4729.               input_cnt++;
  4730.              }
  4731.              else
  4732.              {
  4733.               /* no need to add DRAW_JSFUNCTION , just call it with the parameters */
  4734.               fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size);
  4735.               input_cnt++;
  4736.              }
  4737.              if( use_js_math == FALSE){/* add this stuff only once...*/
  4738.               add_to_js_math(js_include_file);
  4739.               use_js_math = TRUE;
  4740.              }
  4741.              if( use_js_plot == FALSE){
  4742.               use_js_plot = TRUE;
  4743.               add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  4744.              }
  4745.             }
  4746.             else
  4747.             {
  4748.              if(strstr(temp,"inputfield") != 0 ){
  4749.               if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
  4750.               if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  4751.               use_input_xy = 1;
  4752.              }
  4753.              else
  4754.              {
  4755.               if(strstr(temp,"textarea") != 0 ){
  4756.                if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
  4757.                if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  4758.                use_input_xy = 2;
  4759.               }
  4760.               else
  4761.               {
  4762.                 canvas_error("userinput argument may be \"function,inputfield,textarea\"");
  4763.               }
  4764.              }
  4765.             }
  4766.             break;
  4767.         case USERINPUT_XY:
  4768.         /*
  4769.         @ userinput_xy
  4770.         @ keyword (no arguments required)
  4771.         @ to be used in combination with command "userdraw object_type,color"
  4772.         @ 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)
  4773.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  4774.         @ 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.
  4775.         @ can <b>not</b> be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields
  4776.         @ user drawings will not zoom on zooming (or pan on panning)
  4777.         @ use command 'inputstyle some_css' to adjust the inputarea.
  4778.         @ use command 'fontsize int' to adjust the text labels (if needed)
  4779.         */
  4780.             /* add simple eval check to avoid code injection with unprotected eval(string) */
  4781.             if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
  4782.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  4783.             use_input_xy = 1;
  4784.             break;
  4785.  
  4786.         case USERINPUT_FUNCTION:
  4787.         /*
  4788.         @ userinput_function
  4789.         @ keyword (no arguments required)
  4790.         @ if set , a inputfield will be added to the page
  4791.         @ repeat keyword for more function input fields
  4792.         @ the userinput value will be plotted in the canvas
  4793.         @ this value may be read with 'read_canvas()'. <br />for do it yourself js-scripters : If this is the first inputfield in the script, its id is canvas_input0
  4794.         @ use before this command 'userinput_function',<br />commands like 'inputstyle some_css' , 'xlabel some_description' , 'opacity int,int' , 'linewidth int' , 'dashed' and 'dashtype int,int' to modify
  4795.         @ fontsize can be set using command 'fontsize int'
  4796.         @ incompatible with command 'intooltip link_text_or_image' : it uses the tooltip div for adding the inputfield
  4797.         */
  4798.             if( js_function[DRAW_JSFUNCTION] != 1 ){
  4799.              js_function[DRAW_JSFUNCTION] = 1;
  4800.              add_rawmath(js_include_file);
  4801.              if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  4802.              add_input_jsfunction(js_include_file,canvas_root_id,input_style,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size);
  4803.              input_cnt++;
  4804.             }
  4805.             else
  4806.             {
  4807.               /* no need to add DRAW_JSFUNCTION , just call it with the parameters */
  4808.              fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size);
  4809.              input_cnt++;
  4810.             }
  4811.             if( use_js_math == FALSE){/* add this stuff only once...*/
  4812.              add_to_js_math(js_include_file);
  4813.              use_js_math = TRUE;
  4814.             }
  4815.             if( use_js_plot == FALSE){
  4816.              use_js_plot = TRUE;
  4817.              add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  4818.             }
  4819.             break;
  4820.  
  4821.  
  4822.  
  4823.         case USERTEXTAREA_XY:
  4824.         /*
  4825.         @ usertextarea_xy
  4826.         @ keyword (no arguments required)
  4827.         @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being...
  4828.         @ if set two textareas are added to the document<br />(one for x-values , one for y-values)
  4829.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  4830.         @ user drawings will not zoom on zooming (or pan on panning)
  4831.         @ use command 'inputstyle some_css' to adjust the inputarea.
  4832.         @ use command 'fontsize int' to adjust the text labels (if needed)
  4833.         */
  4834.             if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
  4835.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  4836.             use_input_xy = 2;
  4837.             break;
  4838.  
  4839.         case VLINE:
  4840.         /*
  4841.         @ vline x,y,color
  4842.         @ alternative : verticalline
  4843.         @ draw a vertical line through point (x:y) in color 'color'
  4844.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4845.         @%vline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%vline 0,0,red%onclick%vline 1,0,orange%onclick%vline 2,0,blue%onclick%vline 3,0,green
  4846.         */
  4847.             for(i=0;i<3;i++) {
  4848.                 switch(i){
  4849.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  4850.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  4851.                     case 2: stroke_color=get_color(infile,1);/* name or hex color */
  4852.                         double_data[2] = double_data[0];
  4853.                         decimals = find_number_of_digits(precision);
  4854.                         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,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,100*ymin,decimals,100*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,rotation_center,use_offset,use_pattern);
  4855.                         if(onclick > 0){click_cnt++;}
  4856.                         /* click_cnt++; */
  4857.                         reset();
  4858.                     break;
  4859.                 }
  4860.             }
  4861.             break;
  4862.  
  4863.         case VLINES:
  4864.         /*
  4865.         @ vlines color,x1,y1,x2,y2....
  4866.         @ alternative : verticallines
  4867.         @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color'
  4868.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  4869.         @%vline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%vlines red,1,0,2,0,3,0,4,0
  4870.         */
  4871.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  4872.             fill_color = stroke_color;
  4873.             i=0;
  4874.             while( ! done ){     /* get next item until EOL*/
  4875.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4876.                 if(i%2 == 0 ){
  4877.                     double_data[i] = get_real(infile,0); /* x */
  4878.                 }
  4879.                 else
  4880.                 {
  4881.                     double_data[i] = get_real(infile,1); /* y */
  4882.                 }
  4883.                 i++;
  4884.             }
  4885.             decimals = find_number_of_digits(precision);
  4886.             for(c = 0 ; c < i-1 ; c = c+2){
  4887.                 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,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c],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,rotation_center,use_offset,use_pattern);
  4888.                 if(onclick > 0){click_cnt++;}
  4889.                 /* click_cnt++; */
  4890.             }
  4891.             reset();
  4892.             break;
  4893.  
  4894.         case VIDEO:
  4895.         /*
  4896.         @ video x,y,w,h,videofile location
  4897.         @ x,y : left top corner of audio element (in xrange / yrange)
  4898.         @ w,y : width and height in pixels
  4899.         @ video format may be in *.mp4 (todo:other formats)
  4900.         @%video%size 400,400%xrange -10,10%yrange -10,10%video 0,0,120,120,myvideo.mp4
  4901.         */
  4902.             if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
  4903.             for(i=0;i<5;i++){
  4904.                 switch(i){
  4905.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  4906.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  4907.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  4908.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  4909.                     case 4: temp = get_string(infile,1);
  4910.                             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);
  4911.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  4912.                             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);
  4913.                             add_to_buffer(tmp_buffer);
  4914.                             break;
  4915.                     default:break;
  4916.                 }
  4917.             }
  4918.             reset();
  4919.             break;
  4920.  
  4921.         case X_AXIS_STRINGS:
  4922.         /*
  4923.          @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  4924.          @ alternative : xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  4925.          @ usable for commands <a href="numberline">numberline</a> and <a href="grid">grid</a> or combinations thereof
  4926.          @ use these x-axis num1...num_n values instead of default xmin...xmax
  4927.          @ in case of command 'grid' . there is no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  4928.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a>
  4929.          @ use command "fontcolor", "fontfamily" to adjust font <br />defaults: black,12,Ariel<br />note: command "fontsize" is not active for this command.("fontsize" can be used for the <a href="#legend">"legend"</a> in a <a href="#grid">grid</a>)
  4930.          @ a javascript error message will flag non-matching value:name pairs
  4931.          @ if the 'x-axis words' are too big and will overlap, a simple alternating offset will be applied
  4932.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  4933.          @%xaxistext%size 400,400%xrange -10,10%yrange -10,10%xrange 0,13%yrange -100,500%axis%xaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%#'xmajor' steps should be synchronised with numbers eg. "1" in this example%grid 1,100,grey,1,4,6,grey
  4934.         */
  4935.             use_axis_numbering++;
  4936.             temp = get_string(infile,1);
  4937.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  4938.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  4939.             fprintf(js_include_file,"x_strings[%d] = [\"%s\"];x_strings_up[%d] = null;",use_axis_numbering,temp,use_axis_numbering);
  4940.             break;
  4941.         case X_AXIS_STRINGS_UP:
  4942.         /*
  4943.          @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  4944.          @ alternative : xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  4945.          @ the text will be rotated 90&deg; up
  4946.          @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  4947.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a>
  4948.          @ use these x-axis num1...num_n values instead of default xmin...xmax
  4949.          @ use command "fontcolor","fontfamily" to adjust font <br />defaults: black,12,Ariel<br />note: command "fontsize" is not active for this command.("fontsize" can be used for the <a href="#legend">"legend"</a> in a <a href="#grid">grid</a>)
  4950.          @ a javascript error message will flag non-matching value:name pairs
  4951.          @ if the 'x-axis words' are too big, they will overlap the graph<br /> (in this case the text will start from ysize upwards)
  4952.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  4953.          @ type7%:xaxisuptext%xrange 0,13%yrange -100,500%axis%xaxisup 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%#'xmajor' steps should be synchronised with numbers eg. "1" in this example%grid 1,100,grey,1,4,6,grey
  4954.         */
  4955.             use_axis_numbering++;
  4956.             temp = get_string(infile,1);
  4957.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  4958.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  4959.             fprintf(js_include_file,"x_strings_up[%d] = 1;x_strings[%d] = [\"%s\"];",use_axis_numbering,use_axis_numbering,temp);
  4960.             break;
  4961.  
  4962.         case XERRORBARS:
  4963.         /*
  4964.         @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
  4965.         @ draw multiple points with x-errorbars E1 (error value left from point) and E2 (error value right from point) at given coordinates in color 'color'
  4966.         @ the errors E1 and E2 values are in xrange.
  4967.         @ use command 'linewidth int' to adust size
  4968.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  4969.         @%xerrorbars%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%xerrorbars red,0.8,1.3,0,0,1,1,2,3,3,2,4,5,5,2,6,1,-1,-2,-2,0,-3,2,-4,4,-5,-1
  4970.  
  4971.         */
  4972.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  4973.             fill_color = stroke_color;
  4974.             i=0;
  4975.             while( ! done ){     /* get next item until EOL*/
  4976.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4977.                 if(i%2 == 0 ){
  4978.                     double_data[i] = get_real(infile,0); /* x */
  4979.                 }
  4980.                 else
  4981.                 {
  4982.                     double_data[i] = get_real(infile,1); /* y */
  4983.                 }
  4984.                 i++;
  4985.             }
  4986.             decimals = find_number_of_digits(precision);
  4987.             for(c = 2 ; c < i-1 ; c = c+2){
  4988.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,20,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],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,rotation_center,use_offset,use_pattern);
  4989.                 /* click_cnt++; */
  4990.                 if(onclick > 0){click_cnt++;}
  4991.             }
  4992.             reset();
  4993.             break;
  4994.  
  4995.         case XRANGE:
  4996.         /*
  4997.         @ xrange xmin,xmax
  4998.         @ alternative : rangex
  4999.         @ if not given: 0,xsize (eg in pixels)
  5000.         */
  5001.             for(i = 0 ; i<2; i++){
  5002.                 switch(i){
  5003.                     case 0: xmin = get_real(infile,0);break;
  5004.                     case 1: xmax = get_real(infile,1);break;
  5005.                     default: break;
  5006.                 }
  5007.             }
  5008.             if(xmin >= xmax){canvas_error(" xrange is not OK : xmin &lt; xmax !\n");}
  5009.             fprintf(js_include_file,"var xmin = %f;var xmax = %f;\n",xmin,xmax);
  5010.             found_size_command++;
  5011.             break;
  5012.  
  5013.  
  5014.  
  5015.         case XSNAPTOGRID:
  5016.         /*
  5017.          @ xsnaptogrid
  5018.          @ keyword (no arguments required)
  5019.          @ a draggable object (use command "drag  x|y|xy") will snap to the given x-grid values when dragged (mouseup)
  5020.          @ in case of userdraw the drawn points will snap to xmajor grid
  5021.          @ if no grid is defined ,points will snap to every integer xrange value. (eg snap_x=1)
  5022.          @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
  5023.          @ if xminor is defined (use keyword 'axis' to activate xminor), 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 />
  5024.          @%xsnaptogrid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%xsnaptogrid%userdraw segments,red%precision 1%display x,red,12
  5025.          @%xsnaptogrid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%drag x%points red,0,0,0,0,0,0,0,0,0,0
  5026.  
  5027.         */
  5028.         fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 0;");
  5029.         break;
  5030.  
  5031.         case XOFFSET:
  5032.         /*
  5033.          @ xoffset
  5034.          @ keyword ; to place the text centered above the text coordinates(x:y) ...
  5035.          @ may be used for points or other things requiring centered labels
  5036.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5037.          @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-library)
  5038.         @%xoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red
  5039.         */
  5040.          use_offset = 2;
  5041.          break;
  5042.  
  5043.         case XYOFFSET:
  5044.         /*
  5045.          @ xyoffset
  5046.          @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily
  5047.          @ may be used for points or other things requiring labels
  5048.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5049.          @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy
  5050.          @ in case of inputfields the inputfield will be centered x and y on it's coordinates.<br />for example:<br />inputs 1,1,10,? <br />point 1,1,red <br /> the point will be completely invisible<br />note: keyword 'xyoffset' will also provide centering if used with <a href='#@userdraw'>input(s),color</a>  
  5051.          @%xyoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red
  5052.         */
  5053.          use_offset = 3;
  5054.          break;
  5055.  
  5056.         case XUNIT:
  5057.         /*
  5058.          @ xunit some_unit_for_x-values
  5059.          @ unicode allowed (no html code)
  5060.          @ use together with command <a href='#display'>display or mouse</a>
  5061.          @ will display the cursor x-coordinate in 'unit'
  5062.          @%xunit%size 400,400%xrange -10,10%yrange -10,10%xunit cm \\u00B2%grid 2,2,grey%linewidth 2%userdraw segments,blue%display x,blue,18
  5063.         */
  5064.             fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
  5065.             break;
  5066.  
  5067.         case XLABEL:
  5068.         /*
  5069.         @ xlabel some_string
  5070.         @ will be used to create a label for the x-axis (label is in quadrant I)
  5071.         @ can only be used together with command 'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering'
  5072.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command "fontsize" to adjust.<br />(command "fontfamily" is not active for this command)
  5073.         @ see <a href='#ylabel'>ylabel</a>
  5074.         @%xlabel%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%xlabel cm\u00B2 %ylabel v\u00B2 %precision 1%grid 2,2,grey,2,2,5,grey
  5075.         */
  5076.             temp = get_string(infile,1);
  5077.             fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
  5078.             break;
  5079.  
  5080.         case XLOGBASE:
  5081.         /*
  5082.         @ xlogbase number
  5083.         @ sets the logbase number for the x-axis
  5084.         @ default value 10
  5085.         @ use together with commands xlogscale / xylogscale
  5086.         */
  5087.             fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
  5088.             break;
  5089.  
  5090.         case XLOGSCALE:
  5091.         /*
  5092.          @ xlogscale ymajor,yminor,majorcolor,minorcolor
  5093.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  5094.          @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
  5095.          @ the linewidth is set using command 'linewidth int'
  5096.          @ the opacity of major / minor grid lines is set by command <a href='#opacity'>'opacity</a>'
  5097.          @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number'
  5098.          @ 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>
  5099.          @ note: the complete canvas will be used for the 'log paper'
  5100.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5101.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  5102.          @ note: when using something like 'xrange 0.0001,0.01'...combined with commands <a href='#mouse'>'mouse'</a> and/or <a href='#userdraw'>'userdraw</a>...<br /> make sure the <a href='#precision'>precision</a> is set accordingly
  5103.          @ note: in case of userdraw , the use of keyword <a href='#userinput_xy'>'userinput_xy'</a> may be handy !
  5104.          @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
  5105.          @%xlogscale%size 400,400%xrange 10,50000%yrange -5,5%xlabel x-axis%ylabel y-axis%xlogscale 10,1,black,grey%display x,red,22
  5106.         */
  5107.             use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5108.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5109.             if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
  5110.             for(i=0;i<4;i++){
  5111.                 switch(i){
  5112.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  5113.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  5114.                     case 2: stroke_color = get_color(infile,0); break;
  5115.                     case 3: fill_color = get_color(infile,1);
  5116.                         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);
  5117.                         tmp_buffer = my_newmem(string_length+1);
  5118.                         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);
  5119.                         fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
  5120.                         add_to_buffer(tmp_buffer);
  5121.                         break;
  5122.                     default:break;
  5123.                 }
  5124.             }
  5125.             break;
  5126.  
  5127.         case XYLOGSCALE:
  5128.         /*
  5129.          @ xylogscale majorcolor,minorcolor
  5130.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  5131.          @ the linewidth is set using command 'linewidth int'
  5132.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  5133.          @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number'
  5134.          @ 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>
  5135.          @ note: the complete canvas will be used for the 'log paper'
  5136.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5137.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  5138.          @ 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')
  5139.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  5140.          @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
  5141.          @%xylogscale%size 400,400%xrange 10,50000%yrange 10,50000%xlabel x-axis%ylabel y-axis%xyogscale black,grey%display xy,red,22
  5142.         */
  5143.             use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5144.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5145.             if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
  5146.             for(i=0;i<2;i++){
  5147.                 switch(i){
  5148.                     case 0: stroke_color = get_color(infile,0); break;
  5149.                     case 1: fill_color = get_color(infile,1);
  5150.                         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);
  5151.                         tmp_buffer = my_newmem(string_length+1);
  5152.                         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);
  5153.                         fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
  5154.                         add_to_buffer(tmp_buffer);
  5155.                         break;
  5156.                     default:break;
  5157.                 }
  5158.             }
  5159.         break;
  5160.  
  5161.  
  5162.         case Y_AXIS_STRINGS:
  5163.         /*
  5164.          @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5165.          @ alternativ : yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5166.          @ use command "fontcolor", "fontfamily" to adjust font <br />defaults: black,12,Ariel<br /> note: command "fontsize" is not active for this command.("fontsize" can be used for the <a href="#legend">"legend"</a> in a <a href="#grid">grid</a>)
  5167.          @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5168.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a>
  5169.          @ use these y-axis num1...num_n  values instead of default ymin...ymax
  5170.          @ a javascript error message will flag non-matching value:name pairs
  5171.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  5172.          @%yaxistext%size 400,400%yrange 0,13%xrange -100,500%axis%yaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%#'ymajor' steps should be synchronised with numbers eg. "1" in this example%grid 100,1,grey,4,1,6,grey
  5173.         */
  5174.             temp = get_string(infile,1);
  5175.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5176.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5177.             fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
  5178.             use_axis_numbering++;
  5179.             break;
  5180.  
  5181.  
  5182.         case YERRORBARS:
  5183.         /*
  5184.         @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
  5185.         @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color 'color'
  5186.         @ the errors E1 and E2 values are in yrange.
  5187.         @ use command 'linewidth int' to adust size
  5188.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  5189.         @%yerrorbars%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%yerrorbars red,0.8,1.3,0,0,1,1,2,3,3,2,4,5,5,2,6,1,-1,-2,-2,0,-3,2,-4,4,-5,-1
  5190.         */
  5191.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5192.             fill_color = stroke_color;
  5193.             i=0;
  5194.             while( ! done ){     /* get next item until EOL*/
  5195.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5196.                 if(i%2 == 0 ){
  5197.                     double_data[i] = get_real(infile,0); /* x */
  5198.                 }
  5199.                 else
  5200.                 {
  5201.                     double_data[i] = get_real(infile,1); /* y */
  5202.                 }
  5203.                 i++;
  5204.             }
  5205.             for(c = 2 ; c < i-1 ; c = c+2){
  5206.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,19,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],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,rotation_center,use_offset,use_pattern);
  5207.                 /* click_cnt++; */
  5208.                 if(onclick > 0){click_cnt++;}
  5209.             }
  5210.             decimals = find_number_of_digits(precision);
  5211.             reset();
  5212.             break;
  5213.         case YOFFSET:
  5214.         /*
  5215.          @ yoffset
  5216.          @ keyword ; to place the text centered above the text coordinates(x:y) ...
  5217.          @ may be used for points or other things requiring centered labels
  5218.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5219.          @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-library)
  5220.          @%yoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red
  5221.         */
  5222.          use_offset = 1;
  5223.          break;
  5224.  
  5225.         case YRANGE:
  5226.         /*
  5227.         @ yrange ymin,ymax
  5228.         @ alternative : rangey
  5229.         @ if not given 0,ysize (eg in pixels)
  5230.         */
  5231.             for(i = 0 ; i<2; i++){
  5232.                 switch(i){
  5233.                     case 0: ymin = get_real(infile,0);break;
  5234.                     case 1: ymax = get_real(infile,1);break;
  5235.                     default: break;
  5236.                 }
  5237.             }
  5238.             if(ymin >= ymax){canvas_error(" yrange is not OK : ymin &lt; ymax !\n");}
  5239.             fprintf(js_include_file,"var ymin = %f;var ymax = %f;\n",ymin,ymax);
  5240.             found_size_command++;
  5241.             break;
  5242.  
  5243.         case YSNAPTOGRID:
  5244.         /*
  5245.          @ ysnaptogrid
  5246.          @ keyword (no arguments required)
  5247.          @ a draggable object (use command "drag  x|y|xy") will snap to the given y-grid values when dragged (mouseup)
  5248.          @ in case of userdraw the drawn points will snap to ymajor grid
  5249.          @ if no grid is defined ,points will snap to every integer yrange value. (eg snap_y=1)
  5250.          @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
  5251.          @ if yminor is defined (use keyword 'axis' to activate yminor), 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 />
  5252.          @%ysnaptogrid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%userdraw crosshairs,blue%inputstyle font-size:8px;color:blue%clearbutton delete all crosshairs
  5253.          @%ysnaptogrid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%drag y%points red,0,0,0,0,0,0,0,0,0,0
  5254.         */
  5255.         fprintf(js_include_file,"\nx_use_snap_to_grid = 0;y_use_snap_to_grid = 1;");
  5256.         break;
  5257.  
  5258.         case YLABEL:
  5259.         /*
  5260.         @ ylabel some_string
  5261.         @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
  5262.         @ can only be used together with command <a href="#grid">'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering'
  5263.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command "fontsize" to adjust.<br />(command "fontfamily" is not active for this command)
  5264.         @%ylabel%size 400,400%xrange -10,10%yrange -10,10%fontsize 8%axis%axisnumbering%precision 1%xlabel x-axis%ylabel y-axis%grid 1,1,grey,2,2,2,red
  5265.         */
  5266.             temp = get_string(infile,1);
  5267.             fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
  5268.             break;
  5269.         case YLOGBASE:
  5270.         /*
  5271.         @ ylogbase number
  5272.         @ sets the logbase number for the y-axis
  5273.         @ default value 10
  5274.         @ use together with commands ylogscale / xylogscale
  5275.         */
  5276.             fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
  5277.             break;
  5278.         case YLOGSCALE:
  5279.         /*
  5280.          @ ylogscale xmajor,xminor,majorcolor,minorcolor
  5281.          @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
  5282.          @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
  5283.          @ the linewidth is set using command 'linewidth int'
  5284.          @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
  5285.          @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number'
  5286.          @ 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>
  5287.          @ note: the complete canvas will be used for the 'log paper'
  5288.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5289.          @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
  5290.          @ 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')
  5291.          @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
  5292.          @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
  5293.         */
  5294.             use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5295.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5296.             if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
  5297.             for(i=0;i<4;i++){
  5298.                 switch(i){
  5299.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  5300.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  5301.                     case 2: stroke_color = get_color(infile,0); break;
  5302.                     case 3: fill_color = get_color(infile,1);
  5303.                         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);
  5304.                         tmp_buffer = my_newmem(string_length+1);
  5305.                         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);
  5306.                         fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
  5307.                         add_to_buffer(tmp_buffer);
  5308.                         break;
  5309.                     default:break;
  5310.                 }
  5311.             }
  5312.             break;
  5313.  
  5314.         case YUNIT:
  5315.         /*
  5316.          @ yunit some_unit_for_y-values
  5317.          @ unicode allowed (no html code)
  5318.          @ use together with command mousey
  5319.          @ will display the cursor y-coordinate in 'unit'
  5320.         */
  5321.             fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
  5322.             break;
  5323.  
  5324.         case ZOOM:
  5325.         /*
  5326.          @ zoom button_color
  5327.          @ introduce a very small 'controlpanel' at the lower right corner
  5328.          @ giving six 15&times;15px 'active' rectangle areas<br />(for &times;,leftarrow,rightarrow,uparrow,downarrow and a '-' and a '+' sign ) for zooming and/or panning of the image
  5329.          @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings.
  5330.          @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible
  5331.          @ command 'opacity' may be used to set stroke_opacity of 'buttons
  5332.          @ note: use command 'zoom' at the end of your script code (the same is true for command 'mouse')
  5333.          @ note: only objects that may be set draggable / clickable will be zoomed / panned
  5334.          @ 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 !!
  5335.         */
  5336.             fprintf(js_include_file,"use_pan_and_zoom = 1;");
  5337.             use_pan_and_zoom = TRUE;
  5338.             stroke_color = get_color(infile,1);
  5339.             /* we use BG_CANVAS (0) */
  5340.             add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
  5341.             done = TRUE;
  5342.             break;
  5343.  
  5344. /* ready */
  5345.         default:sync_input(infile);
  5346.         break;
  5347.     }
  5348.   }
  5349.   /* we are done parsing script file */
  5350.   /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */
  5351.   if( found_size_command == 1 ){
  5352.     fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
  5353.   }
  5354.   else
  5355.   {
  5356.     if( found_size_command != 3 ){
  5357.      canvas_error("Please specify both xrange and yrange ...");
  5358.     }
  5359.   }
  5360.  
  5361.   /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable/clickable shapes / objects  ! */
  5362.   add_javascript_function(js_function,canvas_root_id);
  5363.    /* add read_canvas() etc functions if needed */
  5364.   if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);}
  5365.   if( use_pan_and_zoom == TRUE ){
  5366.   /* in case of zooming ... */
  5367.   fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\
  5368.  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
  5369.  var ymin_start=ymin;var ymax_start=xmax;\
  5370.  var zoom_x_increment=0;var zoom_y_increment=0;\
  5371.  var pan_x_increment=0;var pan_y_increment=0;\
  5372.  if(use_ylogscale == 0 ){\
  5373.   zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (ymax - ymin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\
  5374.  }else{\
  5375.   zoom_x_increment = (xmax - xmin)/20;\
  5376.   pan_x_increment = (xmax - xmin)/20;\
  5377.  };\
  5378.  var zoom_xy=[xmin,xmax,ymin,ymax];\
  5379.  function start_canvas%d(type){\
  5380.   zoom_xy=[xmin,xmax,ymin,ymax];\
  5381.   switch(type){\
  5382.    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
  5383.    case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\
  5384.    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
  5385.    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
  5386.    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
  5387.    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
  5388.    case 6:xmin = xmin_start; xmax = xmax_start;ymin = ymin_start;ymax = ymax_start;break;\
  5389.    default:break;\
  5390.   };\
  5391.   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
  5392.   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
  5393.   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){};\
  5394.   if(typeof(redraw_all%d) === 'function' ){redraw_all%d(zoom_xy);}\
  5395.   %s ;\
  5396.  };\
  5397.  start_canvas%d(333);\
  5398. };\
  5399. \n<!-- end wims_canvas_function -->\n\
  5400. wims_canvas_function%d();\n",precision,canvas_root_id,canvas_root_id,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
  5401.   }
  5402.   else
  5403.   {
  5404.   /* no zoom, just add buffer */
  5405.   fprintf(js_include_file,"\n<!-- add buffer -->\n\
  5406.  %s\
  5407. };\n\
  5408. <!-- end wims_canvas_function -->\n\
  5409. wims_canvas_function%d();\n",buffer,canvas_root_id);
  5410.   }
  5411. /* done writing the javascript include file */
  5412. fclose(js_include_file);
  5413.  
  5414. }
  5415.  
  5416. /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
  5417.  if( use_tooltip > 0 ){
  5418.   if( use_tooltip == 1 ){
  5419.    add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
  5420.   }
  5421.   else
  5422.   {
  5423.    if( use_tooltip == 2 ){
  5424.     add_js_popup(canvas_root_id,xsize,ysize,getfile_cmd);
  5425.    }
  5426.   }
  5427.  }
  5428. exit(EXIT_SUCCESS);
  5429. }
  5430. /* end main() */
  5431.  
  5432. /******************************************************************************
  5433. **
  5434. **  sync_input
  5435. **
  5436. **  synchronises input line - reads to end of line, leaving file pointer
  5437. **  at first character of next line.
  5438. **
  5439. **  Used by:
  5440. **  main program - error handling.
  5441. **
  5442. ******************************************************************************/
  5443. void sync_input(FILE *infile)
  5444. {
  5445.         int c = 0;
  5446.  
  5447.         if( c == '\n' || c == ';' ) return;
  5448.         while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
  5449.         if( c == EOF ) finished = 1;
  5450.         if( c == '\n' || c == '\r' || c == ';') line_number++;
  5451.         return;
  5452. }
  5453.  
  5454. /******************************************************************************/
  5455.  
  5456. char *str_replace(const char *str, const char *old, const char *new){
  5457. /* http://creativeandcritical.net/str-replace-c/ */
  5458.     if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
  5459.     char *ret, *r;
  5460.     const char *p, *q;
  5461.     size_t oldlen = strlen(old);
  5462.     size_t count = 0;
  5463.     size_t retlen = 0;
  5464.     size_t newlen = strlen(new);
  5465.     if (oldlen != newlen){
  5466.         for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
  5467.             count++;
  5468.             retlen = p - str + strlen(p) + count * (newlen - oldlen);
  5469.         }
  5470.     }
  5471.     else
  5472.     {
  5473.         retlen = strlen(str);
  5474.     }
  5475.  
  5476.     if ((ret = malloc(retlen + 1)) == NULL){
  5477.         ret = NULL;
  5478.         canvas_error("string argument is NULL");
  5479.     }
  5480.     else
  5481.     {
  5482.         for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
  5483.             size_t l = q - p;
  5484.             memcpy(r, p, l);
  5485.             r += l;
  5486.             memcpy(r, new, newlen);
  5487.             r += newlen;
  5488.         }
  5489.         strcpy(r, p);
  5490.     }
  5491.     return ret;
  5492. }
  5493.  
  5494. /******************************************************************************/
  5495.  
  5496. char *get_color(FILE *infile , int last){
  5497.     int c,i = 0,is_hex = 0;
  5498.     char temp[MAX_COLOR_STRING], *string;
  5499.     const char *not_allowed = "0123456789";
  5500.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' )  && ( c != '\t' ) ){
  5501.         if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
  5502.         if( c == '#' ){
  5503.             is_hex = 1;
  5504.         }
  5505.         if( c != ' '){
  5506.             if( is_hex == 0 ){if(strchr(not_allowed,c) != 0){canvas_error("found something like a number...but is should have been a colour or #hex color number...<br />Do not use R,G,B !!! ");}}
  5507.             temp[i]=tolower(c);
  5508.             i++;
  5509.         }
  5510.     }
  5511.     if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
  5512.     if( c == '\n' || c == ';'  || c == '\t' ){ done = TRUE; line_number++; }
  5513.     if( c == EOF ){finished = 1;}
  5514.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  5515.     temp[i]='\0';
  5516.     if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
  5517.     if( is_hex == 1 ){
  5518.         char red[3], green[3], blue[3];
  5519.         red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
  5520.         green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
  5521.         blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
  5522.         int r = (int) strtol(red,   NULL, 16);
  5523.         int g = (int) strtol(green, NULL, 16);
  5524.         int b = (int) strtol(blue,  NULL, 16);
  5525.         string = (char *)my_newmem(12);
  5526.         snprintf(string,11,"%d,%d,%d",r,g,b);
  5527.         return string;
  5528.     }
  5529.     else
  5530.     {
  5531.         string = (char *)my_newmem(sizeof(temp));
  5532.         snprintf(string,sizeof(temp),"%s",temp);
  5533.         for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  5534.             if( strcmp( colors[i].name , string ) == 0 ){
  5535.                 return colors[i].rgb;
  5536.             }
  5537.         }
  5538.         canvas_error("I was expecting a color name or hexnumber...but found nothing.");
  5539.     }
  5540.     return "0,0,255";
  5541. }
  5542.  
  5543. char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
  5544.     int c,i=0;
  5545.     char  temp[MAX_BUFFER], *string;
  5546.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){
  5547.         temp[i]=c;
  5548.         i++;
  5549.         if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
  5550.     }
  5551.     if( ( c == '\n' ||  c == '\t'  || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  5552.     if( c == '\n' ||  c == '\t') { done = TRUE; line_number++; }
  5553.     if( c == EOF ) {finished = 1;}
  5554.     temp[i]='\0';
  5555.     if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing !!");}
  5556.     string=(char *)my_newmem(strlen(temp));
  5557.     snprintf(string,sizeof(temp),"%s",temp);
  5558.     return string;
  5559. }
  5560.  
  5561. char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
  5562.     int c,i=0;
  5563.     char temp[MAX_BUFFER], *string;
  5564.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){
  5565.         temp[i]=c;
  5566.         i++;
  5567.         if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
  5568.     }
  5569.     if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
  5570.     if( c == '\n' || c == '\t' ) { line_number++; }
  5571.     if( c == EOF ) {finished = 1;}
  5572.     if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");}
  5573.     temp[i]='\0';
  5574. /*
  5575.     17.10.2014 removed (question Perrin)
  5576.     may cause some unwanted effects...
  5577.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
  5578. */
  5579.     string=(char *)my_newmem(sizeof(temp));
  5580.     snprintf(string,sizeof(temp),"%s",temp);
  5581.     done = TRUE;
  5582.     return string;
  5583. }
  5584.  
  5585. double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
  5586.     int c,i=0,found_calc = 0;
  5587.     double y;
  5588.     char tmp[MAX_INT];
  5589.     /*
  5590.      these things are 'allowed functions' : *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs
  5591.      but there should be a better way to avoid segfaults !
  5592.     */
  5593.     const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/
  5594.     const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */
  5595.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){
  5596.      if( c != ' ' ){
  5597.       if( i == 0 &&  c == '+' ){
  5598.        continue;
  5599.       }
  5600.       else
  5601.       {
  5602.        c = tolower(c);
  5603.        if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");}
  5604.        if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */
  5605.        tmp[i] = c;
  5606.        i++;
  5607.       }
  5608.      }
  5609.      if( i > MAX_INT - 1){canvas_error("number too large");}
  5610.     }
  5611.     if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
  5612.     if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; }
  5613.     if( c == EOF ){done = TRUE ; finished = 1;}
  5614.     tmp[i]='\0';
  5615.     if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
  5616.     if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */
  5617.      void *f = eval_create(tmp);
  5618.      assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  5619.      y = eval_x(f, 1);
  5620.      /* if function is bogus; y = 1 : so no core dumps */
  5621.      eval_destroy(f);
  5622.     }
  5623.     else
  5624.     {
  5625.      y = atof(tmp);
  5626.     }
  5627.     return y;
  5628. }
  5629.  
  5630.  
  5631. void canvas_error(char *msg){
  5632.     fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number,msg);
  5633.     finished = 1;
  5634.     exit(EXIT_SUCCESS);
  5635. }
  5636.  
  5637.  
  5638. /* convert x/y coordinates to pixel */
  5639. int x2px(double x){
  5640.  return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
  5641. }
  5642.  
  5643. int y2px(double y){
  5644.  return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
  5645. }
  5646.  
  5647. double px2x(int x){
  5648.  return (x*(xmax - xmin)/xsize + xmin);
  5649. }
  5650. double px2y(int y){
  5651.  return (y*(ymax - ymin)/ysize + ymin);
  5652. }
  5653.  
  5654. void add_to_buffer(char *tmp){
  5655.  if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
  5656.  /*  do we have enough space left in buffer[MAX_BUFFER] ? */
  5657.  int space_left = (int) (sizeof(buffer) - strlen(buffer));
  5658.  if( space_left > strlen(tmp)){
  5659.   strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
  5660.  }
  5661.  else
  5662.  {
  5663.   canvas_error("buffer is too big\n");
  5664.  }
  5665.  tmp = NULL;free(tmp);
  5666.  return;
  5667. }
  5668.  
  5669. void reset(){
  5670.  if(use_filled == TRUE){use_filled = FALSE;}
  5671.  if(use_dashed == TRUE){use_dashed = FALSE;}
  5672.  if(use_rotate == TRUE){use_rotate = FALSE;}
  5673.  onclick = 0;
  5674. }
  5675.  
  5676.  
  5677.  
  5678. /* What reply format in read_canvas();
  5679.  
  5680. note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
  5681. 1 = x1,x2,x3,x4....x_n
  5682.     y1,y2,y3,y4....y_n
  5683.  
  5684.     x/y in pixels
  5685.  
  5686. 2 = x1,x2,x3,x4....x_n
  5687.     y1,y2,y3,y4....y_n
  5688.     x/y in  xrange / yrange coordinate system
  5689.  
  5690. 3 = x1,x2,x3,x4....x_n
  5691.     y1,y2,y3,y4....y_n
  5692.     r1,r2,r3,r4....r_n
  5693.  
  5694.     x/y in pixels
  5695.     r in pixels
  5696.  
  5697. 4 = x1,x2,x3,x4....x_n
  5698.     y1,y2,y3,y4....y_n
  5699.     r1,r2,r3,r4....r_n
  5700.  
  5701.     x/y in  xrange / yrange coordinate system
  5702.     r in pixels
  5703.  
  5704. 5 = Ax1,Ax2,Ax3,Ax4....Ax_n
  5705.     Ay1,Ay2,Ay3,Ay4....Ay_n
  5706.     Bx1,Bx2,Bx3,Bx4....Bx_n
  5707.     By1,By2,By3,By4....By_n
  5708.     Cx1,Cx2,Cx3,Cx4....Cx_n
  5709.     Cy1,Cy2,Cy3,Cy4....Cy_n
  5710.     ....
  5711.     Zx1,Zx2,Zx3,Zx4....Zx_n
  5712.     Zy1,Zy2,Zy3,Zy4....Zy_n
  5713.  
  5714.     x/y in pixels
  5715.  
  5716. 6 = Ax1,Ax2,Ax3,Ax4....Ax_n
  5717.     Ay1,Ay2,Ay3,Ay4....Ay_n
  5718.     Bx1,Bx2,Bx3,Bx4....Bx_n
  5719.     By1,By2,By3,By4....By_n
  5720.     Cx1,Cx2,Cx3,Cx4....Cx_n
  5721.     Cy1,Cy2,Cy3,Cy4....Cy_n
  5722.     ....
  5723.     Zx1,Zx2,Zx3,Zx4....Zx_n
  5724.     Zy1,Zy2,Zy3,Zy4....Zy_n
  5725.  
  5726.     x/y in  xrange / yrange coordinate system
  5727.  
  5728. 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  5729.  
  5730.     x/y in pixels
  5731.  
  5732. 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  5733.  
  5734.     x/y in  xrange / yrange coordinate system
  5735.  
  5736. 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
  5737.  
  5738.     x/y in pixels
  5739.  
  5740. 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
  5741.  
  5742.     x/y in  xrange / yrange coordinate system
  5743.  
  5744. 11 = Ax1,Ay1,Ax2,Ay2
  5745.      Bx1,By1,Bx2,By2
  5746.      Cx1,Cy1,Cx2,Cy2
  5747.      Dx1,Dy1,Dx2,Dy2
  5748.      ......
  5749.      Zx1,Zy1,Zx2,Zy2
  5750.  
  5751.     x/y in  xrange / yrange coordinate system
  5752.  
  5753. 12 = Ax1,Ay1,Ax2,Ay2
  5754.      Bx1,By1,Bx2,By2
  5755.      Cx1,Cy1,Cx2,Cy2
  5756.      Dx1,Dy1,Dx2,Dy2
  5757.      ......
  5758.      Zx1,Zy1,Zx2,Zy2
  5759.  
  5760.     x/y in pixels
  5761.  
  5762. 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
  5763.  
  5764.     x/y in  xrange / yrange coordinate system
  5765. 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
  5766.     x/y in pixels
  5767. 15 = reply from inputfields,textareas
  5768.     reply1,reply2,reply3,...,reply_n
  5769.     only fields set write (a.g. will not read 'readonly' inputfield values'
  5770.  
  5771. 16 = read mathml inputfields only
  5772.  
  5773. 17 = read userdraw text only (x1,y1,text1\nx2,y2,text2..\n.x_n,y_n,text_n
  5774.  when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
  5775.  
  5776. 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
  5777. 19 = return clicked object number (analogue to shape-library onclick)
  5778. 20 = return x/y-data in x-range/y-range of all 'draggable' images
  5779. 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
  5780. 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
  5781.     x/y in  xrange / yrange coordinate system
  5782. 23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
  5783. 24 = read all inputfield values: even those set 'readonly'
  5784. 25 = return all userdrawn arcs in degrees:
  5785. 26 = return all userdrawn arcs in radians:
  5786. 27 = return (only) userdraw inputfields array: x1,y1,text1 \n x2,y2,text2...
  5787. 28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
  5788.     x/y/r in  xrange / yrange coordinate system: may be used to reinput into command
  5789.     'circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n'
  5790.     will not return anything else (e.g. no inputfields , text etc)
  5791. 29 = mulidraw read :
  5792.  
  5793. */
  5794.  
  5795.  
  5796. void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){
  5797. /* just 1 reply type allowed */
  5798. fprintf(js_include_file,"\
  5799. \n<!-- begin set_reply_precision() -->\n\
  5800. function set_reply_precision(){\
  5801. var len = userdraw_x.length;\
  5802. var prec = %d;\
  5803. for(var p = 0 ; p < len ; p++ ){\
  5804.  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
  5805.  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
  5806. };\
  5807. len = userdraw_radius.length;\
  5808. if( len > 0 ){\
  5809.  for(var p = 0 ; p < len ; p++ ){\
  5810.   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
  5811.  };\
  5812. };\
  5813. };",reply_precision);
  5814.  
  5815. switch(type_reply){
  5816. /*
  5817. answers may have:
  5818. x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
  5819. */
  5820.     case 1: fprintf(js_include_file,"\
  5821. \n<!-- begin function 1 read_canvas%d() -->\n\
  5822. read_canvas%d = function(){\
  5823. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  5824. set_reply_precision();\
  5825. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  5826.  var p = 0;var input_reply = new Array();\
  5827.  if( document.getElementById(\"canvas_input0\")){\
  5828.   var t = 0;\
  5829.   while(document.getElementById(\"canvas_input\"+t)){\
  5830.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5831.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5832.     p++;\
  5833.    };\
  5834.    t++;\
  5835.   };\
  5836.  };\
  5837.  if( typeof(userdraw_text) !== 'undefined' ){\
  5838.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
  5839.  }\
  5840.  else\
  5841.  {\
  5842.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
  5843.  }\
  5844. }\
  5845. else\
  5846. {\
  5847.  if( typeof(userdraw_text) !== 'undefined' ){\
  5848.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
  5849.  }\
  5850.  else\
  5851.  {\
  5852.   return userdraw_x+\"\\n\"+userdraw_y;\
  5853.  }\
  5854. };\
  5855. };\n\
  5856. <!-- end function 1 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5857.     break;
  5858.     case 2: fprintf(js_include_file,"\
  5859. \n<!-- begin function 2 read_canvas%d() -->\n\
  5860. read_canvas%d = function(){\
  5861. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  5862. set_reply_precision();\
  5863. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  5864. var prec = %d;\
  5865. while(userdraw_x[p]){\
  5866.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  5867.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  5868.  p++;\
  5869. };\
  5870. if(p == 0){return;};\
  5871. if( document.getElementById(\"canvas_input0\")){\
  5872.  var p = 0;var input_reply = new Array();\
  5873.  if( document.getElementById(\"canvas_input0\")){\
  5874.   var t = 0;\
  5875.   while(document.getElementById(\"canvas_input\"+t)){\
  5876.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5877.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5878.     p++;\
  5879.    };\
  5880.    t++;\
  5881.   };\
  5882.  };\
  5883.  if( typeof(userdraw_text) !== 'undefined' ){\
  5884.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5885.  }\
  5886.  else\
  5887.  {\
  5888.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  5889.  }\
  5890. }\
  5891. else\
  5892. {\
  5893.  if( typeof(userdraw_text) !== 'undefined' ){\
  5894.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  5895.  }\
  5896.  else\
  5897.  {\
  5898.   return reply_x+\"\\n\"+reply_y;\
  5899.  };\
  5900. };\
  5901. };\n\
  5902. <!-- end function 2 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  5903.     break;
  5904.     case 3: fprintf(js_include_file,"\
  5905. \n<!-- begin function 3 read_canvas%d() -->\n\
  5906. read_canvas%d = function(){\
  5907. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  5908. set_reply_precision();\
  5909. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  5910.  var p = 0;var input_reply = new Array();\
  5911.  if( document.getElementById(\"canvas_input0\")){\
  5912.   var t = 0;\
  5913.   while(document.getElementById(\"canvas_input\"+t)){\
  5914.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5915.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5916.     p++;\
  5917.    };\
  5918.    t++;\
  5919.   };\
  5920.  };\
  5921.  if( typeof(userdraw_text) !== 'undefined' ){\
  5922.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5923.  }\
  5924.  else\
  5925.  {\
  5926.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  5927.  }\
  5928. }\
  5929. else\
  5930. {\
  5931.  if( typeof(userdraw_text) !== 'undefined' ){\
  5932.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
  5933.  }\
  5934.  else\
  5935.  {\
  5936.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
  5937.  }\
  5938. }\
  5939. };\n\
  5940. <!-- end function 3 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  5941.     break;
  5942.     case 4: fprintf(js_include_file,"\
  5943. \n<!-- begin function 4 read_canvas%d() -->\n\
  5944. read_canvas%d = function(){\
  5945. var prec = %d;\
  5946. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  5947. while(userdraw_x[p]){\
  5948.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  5949.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
  5950.  p++;\
  5951. };\
  5952. if(p == 0){return;};\
  5953. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  5954.  var p = 0;var input_reply = new Array();\
  5955.  if( document.getElementById(\"canvas_input0\")){\
  5956.   var t = 0;\
  5957.   while(document.getElementById(\"canvas_input\"+t)){\
  5958.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  5959.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  5960.     p++;\
  5961.    };\
  5962.    t++;\
  5963.   };\
  5964.  };\
  5965.  if( typeof(userdraw_text) !== 'undefined' ){\
  5966.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  5967.  }\
  5968.  else\
  5969.  {\
  5970.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  5971.  }\
  5972. }\
  5973. else\
  5974. {\
  5975.  if( typeof(userdraw_text) !== 'undefined' ){\
  5976.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
  5977.  }\
  5978.  else\
  5979.  {\
  5980.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
  5981.  }\
  5982. };\
  5983. };\n\
  5984. <!-- end function 4 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  5985.     break;
  5986.     /*
  5987.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  5988.         used for userdraw multiple paths
  5989.     */
  5990.     case 5: fprintf(js_include_file,"\
  5991. \n<!-- begin function 5 read_canvas%d() -->\n\
  5992. read_canvas%d = function(){\
  5993. set_reply_precision();\
  5994. var p = 0;\
  5995. var reply = \"\";\
  5996. for(p = 0; p < userdraw_x.length;p++){\
  5997.  if(userdraw_x[p] != null ){\
  5998.   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
  5999.  };\
  6000. };\
  6001. if(p == 0){return;};\
  6002. userdraw_x = [];userdraw_y = [];\
  6003. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6004.  var p = 0;var input_reply = new Array();\
  6005.  if( document.getElementById(\"canvas_input0\")){\
  6006.   var t = 0;\
  6007.   while(document.getElementById(\"canvas_input\"+t)){\
  6008.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6009.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6010.     p++;\
  6011.    };\
  6012.    t++;\
  6013.   };\
  6014.  };\
  6015.  if( typeof(userdraw_text) !== 'undefined' ){\
  6016.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6017.  }\
  6018.  else\
  6019.  {\
  6020.   return reply +\"\\n\"+input_reply;\
  6021.  }\
  6022. }\
  6023. else\
  6024. {\
  6025.  if( typeof(userdraw_text) !== 'undefined' ){\
  6026.   return reply+\"\\n\"+userdraw_text;\
  6027.  }\
  6028.  else\
  6029.  {\
  6030.   return reply;\
  6031.  }\
  6032. };\
  6033. };\n\
  6034. <!-- end function 5 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  6035.     break;
  6036.     /*
  6037.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  6038.         used for userdraw multiple paths
  6039.     */
  6040.     case 6: fprintf(js_include_file,"\
  6041. \n<!-- begin function 6 read_canvas%d() -->\n\
  6042. read_canvas%d = function(){\
  6043. var p = 0;\
  6044. var reply = \"\";\
  6045. var tmp_x = new Array();\
  6046. var tmp_y = new Array();\
  6047. var prec = %d;\
  6048. for(p = 0 ; p < userdraw_x.length; p++){\
  6049.  tmp_x = userdraw_x[p];\
  6050.  tmp_y = userdraw_y[p];\
  6051.  if(tmp_x != null){\
  6052.   for(var i = 0 ; i < tmp_x.length ; i++){\
  6053.    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
  6054.    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
  6055.   };\
  6056.   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
  6057.  };\
  6058. };\
  6059. if(p == 0){return;};\
  6060. userdraw_x = [];userdraw_y = [];\
  6061. if( document.getElementById(\"canvas_input0\") ){\
  6062.  var p = 0;var input_reply = new Array();\
  6063.  if( document.getElementById(\"canvas_input0\")){\
  6064.   var t = 0;\
  6065.   while(document.getElementById(\"canvas_input\"+t)){\
  6066.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6067.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6068.     p++;\
  6069.    };\
  6070.    t++;\
  6071.   };\
  6072.  };\
  6073.  if( typeof(userdraw_text) !== 'undefined' ){\
  6074.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6075.  }\
  6076.  else\
  6077.  {\
  6078.   return reply +\"\\n\"+input_reply;\
  6079.  }\
  6080. }\
  6081. else\
  6082. {\
  6083.  if( typeof(userdraw_text) !== 'undefined' ){\
  6084.   return reply +\"\\n\"+userdraw_text;\
  6085.  }\
  6086.  else\
  6087.  {\
  6088.   return reply;\
  6089.  }\
  6090. };\
  6091. };\n\
  6092. <!-- end function 6 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6093.     break;
  6094.     case 7: fprintf(js_include_file,"\
  6095. \n<!-- begin function 7 read_canvas%d() -->\n\
  6096. read_canvas%d = function(){\
  6097. set_reply_precision();\
  6098. var reply = new Array();\
  6099. var p = 0;\
  6100. while(userdraw_x[p]){\
  6101.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
  6102.  p++;\
  6103. };\
  6104. if(p == 0){return;};\
  6105. if( document.getElementById(\"canvas_input0\") ){\
  6106.  var p = 0;var input_reply = new Array();\
  6107.  if( document.getElementById(\"canvas_input0\")){\
  6108.   var t = 0;\
  6109.   while(document.getElementById(\"canvas_input\"+t)){\
  6110.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6111.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6112.     p++;\
  6113.    };\
  6114.    t++;\
  6115.   };\
  6116.  };\
  6117.  if( typeof(userdraw_text) !== 'undefined' ){\
  6118.   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6119.  }\
  6120.  else\
  6121.  {\
  6122.   return reply+\"\\n\"+input_reply;\
  6123.  }\
  6124. }\
  6125. else\
  6126. {\
  6127.  if( typeof(userdraw_text) !== 'undefined' ){\
  6128.   return reply+\"\\n\"+userdraw_text;\
  6129.  }\
  6130.  else\
  6131.  {\
  6132.   return reply;\
  6133.  }\
  6134. };\
  6135. };\n\
  6136. <!-- end function 7 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  6137.     break;
  6138.     case 8: fprintf(js_include_file,"\
  6139. \n<!-- begin function 8 read_canvas%d() -->\n\
  6140. read_canvas%d = function(){\
  6141. var reply = new Array();\
  6142. var p = 0;\
  6143. var prec = %d;\
  6144. while(userdraw_x[p]){\
  6145.  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  6146.  p++;\
  6147. };\
  6148. if(p == 0){return;};\
  6149. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6150.  var p = 0;var input_reply = new Array();\
  6151.  if( document.getElementById(\"canvas_input0\")){\
  6152.   var t = 0;\
  6153.   while(document.getElementById(\"canvas_input\"+t)){\
  6154.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6155.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6156.     p++;\
  6157.    };\
  6158.    t++;\
  6159.   };\
  6160.  };\
  6161.  if( typeof(userdraw_text) !== 'undefined' ){\
  6162.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6163.  }\
  6164.  else\
  6165.  {\
  6166.   return reply +\"\\n\"+input_reply;\
  6167.  }\
  6168. }\
  6169. else\
  6170. {\
  6171.  if( typeof(userdraw_text) !== 'undefined' ){\
  6172.   return reply +\"\\n\"+userdraw_text;\
  6173.  }\
  6174.  else\
  6175.  {\
  6176.   return reply;\
  6177.  }\
  6178. };\
  6179. };\n\
  6180. <!-- end function 8 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6181.     break;
  6182.     case 9: fprintf(js_include_file,"\
  6183. \n<!-- begin function 9 read_canvas%d() -->\n\
  6184. read_canvas%d = function(){\
  6185. set_reply_precision();\
  6186. var reply = new Array();\
  6187. var p = 0;\
  6188. while(userdraw_x[p]){\
  6189.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
  6190.  p++;\
  6191. };\
  6192. if(p == 0){return;};\
  6193. if( document.getElementById(\"canvas_input0\") ){\
  6194.  var p = 0;var input_reply = new Array();\
  6195.  if( document.getElementById(\"canvas_input0\")){\
  6196.   var t = 0;\
  6197.   while(document.getElementById(\"canvas_input\"+t)){\
  6198.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6199.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6200.     p++;\
  6201.    };\
  6202.    t++;\
  6203.   };\
  6204.  };\
  6205.  if( typeof(userdraw_text) !== 'undefined' ){\
  6206.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6207.  }\
  6208.  else\
  6209.  {\
  6210.   return reply +\"\\n\"+input_reply;\
  6211.  }\
  6212. }\
  6213. else\
  6214. {\
  6215.  if( typeof(userdraw_text) !== 'undefined' ){\
  6216.   return reply +\"\\n\"+userdraw_text;\
  6217.  }\
  6218.  else\
  6219.  {\
  6220.   return reply;\
  6221.  }\
  6222. };\
  6223. };\n\
  6224. <!-- end function 9 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  6225.     break;
  6226.     case 10: fprintf(js_include_file,"\
  6227. \n<!-- begin function 10 read_canvas%d() -->\n\
  6228. read_canvas%d = function(){\
  6229. var reply = new Array();\
  6230. var p = 0;\
  6231. var prec = %d;\
  6232. while(userdraw_x[p]){\
  6233.  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;\
  6234.  p++;\
  6235. };\
  6236. if(p == 0){return;};\
  6237. if( document.getElementById(\"canvas_input0\") ){\
  6238.  var p = 0;var input_reply = new Array();\
  6239.  if( document.getElementById(\"canvas_input0\")){\
  6240.   var t = 0;\
  6241.   while(document.getElementById(\"canvas_input\"+t)){\
  6242.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6243.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6244.     p++;\
  6245.    };\
  6246.    t++;\
  6247.   };\
  6248.  };\
  6249.  if( typeof(userdraw_text) !== 'undefined' ){\
  6250.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6251.  }\
  6252.  else\
  6253.  {\
  6254.   return reply +\"\\n\"+input_reply;\
  6255.  }\
  6256. }\
  6257. else\
  6258. {\
  6259.  if( typeof(userdraw_text) !== 'undefined' ){\
  6260.   return reply +\"\\n\"+userdraw_text;\
  6261.  }\
  6262.  else\
  6263.  {\
  6264.   return reply;\
  6265.  }\
  6266. };\
  6267. };\n\
  6268. <!-- end function 10 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6269.     break;
  6270.     case 11: fprintf(js_include_file,"\
  6271. \n<!-- begin function 11 read_canvas%d() -->\n\
  6272. read_canvas%d = function(){\
  6273. var reply = \"\";\
  6274. var p = 0;\
  6275. var prec = %d;\
  6276. while(userdraw_x[p]){\
  6277.  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\" ;\
  6278.  p = p+2;\
  6279. };\
  6280. if(p == 0){return;};\
  6281. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6282.  var p = 0;var input_reply = new Array();\
  6283.  if( document.getElementById(\"canvas_input0\")){\
  6284.   var t = 0;\
  6285.   while(document.getElementById(\"canvas_input\"+t)){\
  6286.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6287.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6288.     p++;\
  6289.    };\
  6290.    t++;\
  6291.   };\
  6292.  };\
  6293.  if( typeof(userdraw_text) !== 'undefined' ){\
  6294.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6295.  }\
  6296.  else\
  6297.  {\
  6298.   return reply +\"\\n\"+input_reply;\
  6299.  }\
  6300. }\
  6301. else\
  6302. {\
  6303.  if( typeof(userdraw_text) !== 'undefined' ){\
  6304.   return reply +\"\\n\"+userdraw_text;\
  6305.  }\
  6306.  else\
  6307.  {\
  6308.   return reply;\
  6309.  }\
  6310. };\
  6311. };\n\
  6312. <!-- end function 11 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6313.     break;
  6314.     case 12: fprintf(js_include_file,"\
  6315. \n<!-- begin function 12 read_canvas%d() -->\n\
  6316. read_canvas%d = function(){\
  6317. set_reply_precision();\
  6318. var reply = \"\";\
  6319. var p = 0;\
  6320. for(p = 0; p< userdraw_x.lenght;p = p+2){\
  6321.  if(userdraw_x[p] != null){\
  6322.    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
  6323.  };\
  6324. };\
  6325. if(p == 0){return;};\
  6326. if( document.getElementById(\"canvas_input0\") ){\
  6327.  var p = 0;var input_reply = new Array();\
  6328.  if( document.getElementById(\"canvas_input0\")){\
  6329.   var t = 0;\
  6330.   while(document.getElementById(\"canvas_input\"+t)){\
  6331.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6332.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6333.     p++;\
  6334.    };\
  6335.    t++;\
  6336.   };\
  6337.  };\
  6338.  if( typeof(userdraw_text) !== 'undefined' ){\
  6339.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6340.  }\
  6341.  else\
  6342.  {\
  6343.   return reply +\"\\n\"+input_reply;\
  6344.  }\
  6345. }\
  6346. else\
  6347. {\
  6348.  if( typeof(userdraw_text) !== 'undefined' ){\
  6349.   return reply +\"\\n\"+userdraw_text\
  6350.  }\
  6351.  else\
  6352.  {\
  6353.   return reply;\
  6354.  }\
  6355. };\
  6356. };\n\
  6357. <!-- end function 12 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  6358.     break;
  6359.     case 13: fprintf(js_include_file,"\
  6360. \n<!-- begin function 13 read_canvas%d() -->\n\
  6361. read_canvas%d = function(){\
  6362. var reply = new Array();\
  6363. var p = 0;var i = 0;\
  6364. var prec = %d;\
  6365. while(userdraw_x[p]){\
  6366.  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;\
  6367.  p = p+2;i++;\
  6368. };\
  6369. if(p == 0){return;};\
  6370. if( document.getElementById(\"canvas_input0\") ){\
  6371.  var p = 0;var input_reply = new Array();\
  6372.  if( document.getElementById(\"canvas_input0\")){\
  6373.   var t = 0;\
  6374.   while(document.getElementById(\"canvas_input\"+t)){\
  6375.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6376.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6377.     p++;\
  6378.    };\
  6379.    t++;\
  6380.   };\
  6381.  };\
  6382.  if( typeof(userdraw_text) !== 'undefined' ){\
  6383.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6384.  }\
  6385.  else\
  6386.  {\
  6387.   return reply +\"\\n\"+input_reply;\
  6388.  }\
  6389. }\
  6390. else\
  6391. {\
  6392.  if( typeof(userdraw_text) !== 'undefined' ){\
  6393.   return reply +\"\\n\"+userdraw_text\
  6394.  }\
  6395.  else\
  6396.  {\
  6397.   return reply;\
  6398.  }\
  6399. };\
  6400. };\n\
  6401. <!-- end function 13 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6402.     break;
  6403.     case 14: fprintf(js_include_file,"\
  6404. \n<!-- begin function 14 read_canvas%d() -->\n\
  6405. read_canvas%d = function(){\
  6406. set_reply_precision();\
  6407. var reply = new Array();\
  6408. var p = 0;var i = 0;\
  6409. while(userdraw_x[p]){\
  6410.  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
  6411.  p = p+2;i++;\
  6412. };\
  6413. if(p == 0){return;};\
  6414. if( document.getElementById(\"canvas_input0\") ){\
  6415.  var p = 0;var input_reply = new Array();\
  6416.  if( document.getElementById(\"canvas_input0\")){\
  6417.   var t = 0;\
  6418.   while(document.getElementById(\"canvas_input\"+t)){\
  6419.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6420.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6421.     p++;\
  6422.    };\
  6423.    t++;\
  6424.   };\
  6425.  };\
  6426.  if( typeof(userdraw_text) !== 'undefined' ){\
  6427.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6428.  }\
  6429.  else\
  6430.  {\
  6431.   return reply +\"\\n\"+input_reply;\
  6432.  }\
  6433. }\
  6434. else\
  6435. {\
  6436.  if( typeof(userdraw_text) !== 'undefined' ){\
  6437.   return reply +\"\\n\"+userdraw_text;\
  6438.  }\
  6439.  else\
  6440.  {\
  6441.   return reply;\
  6442.  }\
  6443. };\
  6444. };\n\
  6445. <!-- end function 14 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  6446.     break;
  6447.     case 15: fprintf(js_include_file,"\
  6448. \n<!-- begin function 15  read_canvas%d() -->\n\
  6449. read_canvas%d = function(){\
  6450. var input_reply = new Array();\
  6451. var p = 0;\
  6452. if( document.getElementById(\"canvas_input0\")){\
  6453.  var t = 0;\
  6454.  while(document.getElementById(\"canvas_input\"+t)){\
  6455.   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6456.    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6457.    p++;\
  6458.   };\
  6459.   t++;\
  6460.  };\
  6461. };\
  6462. if( typeof(userdraw_text) !== 'undefined' ){\
  6463.   return input_reply +\"\\n\"+userdraw_text;\
  6464. }\
  6465. else\
  6466. {\
  6467.  return input_reply;\
  6468. };\
  6469. };\n\
  6470. <!-- end function 15 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  6471.     break;
  6472.     case 16: fprintf(js_include_file,"\
  6473. \n<!-- begin function 16 read_mathml() -->\n\
  6474. function read_mathml(){\
  6475. var reply = new Array();\
  6476. var p = 0;\
  6477. if( document.getElementById(\"mathml0\")){\
  6478.  while(document.getElementById(\"mathml\"+p)){\
  6479.   reply[p] = document.getElementById(\"mathml\"+p).value;\
  6480.   p++;\
  6481.  };\
  6482. };\
  6483. return reply;\
  6484. };\
  6485. this.read_mathml = read_mathml;\n\
  6486. <!-- end function 16 read_mathml() -->");
  6487.     break;
  6488.     case 17:  fprintf(js_include_file,"\
  6489. \n<!-- begin function 17 read_canvas%d() -->\n\
  6490. read_canvas%d = function(){\
  6491. var len = userdraw_x.length;\
  6492. if( len == 0){alert(\"no text typed...\");return;}\
  6493. var rep = px2x(userdraw_x[0])+\",\"+px2y(userdraw_y[0])+\",\"+userdraw_text[0];\
  6494. for(var p = 1 ; p < len ; p++){\
  6495.  rep = rep + \"\\n\" + px2x(userdraw_x[p]) + \",\" + px2y(userdraw_y[p]) + \",\" + userdraw_text[p];\
  6496. };\
  6497. return rep;\
  6498. };\n\
  6499. <!-- end function 17 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  6500.     break;
  6501.     case 18: fprintf(js_include_file,"\
  6502. \n<!-- javascript has no real modulo function -->\n\
  6503. function mod(n, m){\
  6504. var m = parseInt(((n %% m) + m) %% m);\
  6505. return m;\
  6506. };\
  6507. \n<!-- begin function 18 read_canvas%d() -->\n\
  6508. read_canvas%d = function(){\
  6509. var p = 0;\
  6510. var reply = new Array();\
  6511. var name;\
  6512. var t = true;\
  6513. var h;var m;var s;\
  6514. while(t){\
  6515.  try{\
  6516.   name = eval('clocks'+p);\
  6517.   h = name.H;m = name.M;s = name.S;\
  6518.   h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\
  6519.   reply[p] = h+\":\"+m+\":\"+s;\
  6520.   p++;\
  6521.  }catch(e){t=false;};\
  6522. };\
  6523. if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
  6524. return reply;\
  6525. };\n\
  6526. <!-- end function 18 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  6527.     break;
  6528.     case 19: fprintf(js_include_file,"\
  6529. \n<!-- begin function 19 read_canvas%d() -->\n\
  6530. read_canvas%d = function(){\
  6531. return reply[0];\
  6532. };\n\
  6533. <!-- end function 19 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  6534.     break;
  6535.     case 20: fprintf(js_include_file,"\
  6536. \n<!-- begin function 20 read_canvas%d() -->\n\
  6537. read_canvas%d = function(){\
  6538. var prec = %d;\
  6539. var len  = ext_drag_images.length;\
  6540. var reply = new Array(len);\
  6541. for(var p = 0 ; p < len ; p++){\
  6542.    var img = ext_drag_images[p];\
  6543.    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  6544. };\
  6545. return reply;\
  6546. };\n\
  6547. <!-- end function 20 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6548.     break;
  6549.     case 21: fprintf(js_include_file,"\
  6550. \n<!-- begin function 21 read_canvas%d() -->\n\
  6551. read_canvas%d = function(){\
  6552. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  6553. var reply_coord = new Array();var p = 0;\
  6554. var prec = %d;\
  6555. while(userdraw_x[p]){\
  6556.  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
  6557.  p++;\
  6558. };\
  6559. if(p == 0){return;};\
  6560. if( document.getElementById(\"canvas_input0\") ){\
  6561.  var p = 0;var input_reply = new Array();\
  6562.  if( document.getElementById(\"canvas_input0\")){\
  6563.   var t = 0;\
  6564.   while(document.getElementById(\"canvas_input\"+t)){\
  6565.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6566.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6567.     p++;\
  6568.    };\
  6569.    t++;\
  6570.   };\
  6571.  };\
  6572.  if( typeof(userdraw_text) !== 'undefined' ){\
  6573.   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6574.  }\
  6575.  else\
  6576.  {\
  6577.   return reply_coord+\"\\n\"+input_reply;\
  6578.  }\
  6579. }\
  6580. else\
  6581. {\
  6582.  if( typeof(userdraw_text) !== 'undefined' ){\
  6583.   return reply_coord+\"\\n\"+userdraw_text;\
  6584.  }\
  6585.  else\
  6586.  {\
  6587.   return reply_coord;\
  6588.  };\
  6589. };\
  6590. };\n\
  6591. <!-- end function 21 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6592.     break;
  6593.     case 22: fprintf(js_include_file,"\
  6594. \n<!-- begin function 22 read_canvas%d() -->\n\
  6595. read_canvas%d = function(){\
  6596. var reply = new Array();\
  6597. var lu = userdraw_x.length;\
  6598. if(lu == 0){return;};\
  6599. var idx = 0;\
  6600. var prec = %d;\
  6601. for(var p = 0 ; p < lu ; p++){\
  6602.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
  6603.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
  6604. };\
  6605. if( document.getElementById(\"canvas_input0\") ){\
  6606.  var p = 0;var input_reply = new Array();\
  6607.  if( document.getElementById(\"canvas_input0\")){\
  6608.   var t = 0;\
  6609.   while(document.getElementById(\"canvas_input\"+t)){\
  6610.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6611.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6612.     p++;\
  6613.    };\
  6614.    t++;\
  6615.   };\
  6616.  };\
  6617.  if( typeof(userdraw_text) !== 'undefined' ){\
  6618.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6619.  }\
  6620.  else\
  6621.  {\
  6622.   return reply +\"\\n\"+input_reply;\
  6623.  }\
  6624. }\
  6625. else\
  6626. {\
  6627.  if( typeof(userdraw_text) !== 'undefined' ){\
  6628.   return reply +\"\\n\"+userdraw_text;\
  6629.  }\
  6630.  else\
  6631.  {\
  6632.   return reply;\
  6633.  }\
  6634. };\
  6635. };\n\
  6636. <!-- end function 22 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6637.     break;
  6638.     case 23: fprintf(js_include_file,"\
  6639. \n<!-- begin function 23 read_canvas%d() default 5 px marge -->\n\
  6640. read_canvas%d = function(){\
  6641. if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
  6642. var lu = userdraw_x.length;\
  6643. if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
  6644. var reply_x = new Array();var reply_y = new Array();\
  6645. var marge = 5;var p = 0;\
  6646. var prec = %d;\
  6647. for(var i = 0; i < lu - 1 ; i++ ){\
  6648.  if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\
  6649.   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
  6650.   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
  6651.   p++;\
  6652.  };\
  6653.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\
  6654. };\
  6655. if( document.getElementById(\"canvas_input0\")){\
  6656.  var p = 0;var input_reply = new Array();\
  6657.  if( document.getElementById(\"canvas_input0\")){\
  6658.   var t = 0;\
  6659.   while(document.getElementById(\"canvas_input\"+t)){\
  6660.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6661.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6662.     p++;\
  6663.    };\
  6664.    t++;\
  6665.   };\
  6666.  };\
  6667.  if( typeof(userdraw_text) !== 'undefined' ){\
  6668.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6669.  }\
  6670.  else\
  6671.  {\
  6672.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  6673.  }\
  6674. }\
  6675. else\
  6676. {\
  6677.  if( typeof(userdraw_text) !== 'undefined' ){\
  6678.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  6679.  }\
  6680.  else\
  6681.  {\
  6682.   return reply_x+\"\\n\"+reply_y;\
  6683.  };\
  6684. };\
  6685. };\n\
  6686. <!-- end function 23 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6687.     break;
  6688.     case 24: fprintf(js_include_file,"\n\
  6689. <!-- begin function 24  read_canvas%d() -->\n\
  6690. read_canvas%d = function(){\
  6691. var input_reply = new Array();\
  6692. var p = 0;\
  6693. if( document.getElementById(\"canvas_input0\")){\
  6694.  while(document.getElementById(\"canvas_input\"+p)){\
  6695.    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
  6696.    p++;\
  6697.  };\
  6698.  return input_reply;\
  6699. };\
  6700. };\n\
  6701. <!-- end function 24 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
  6702.     break;
  6703.     case 25:
  6704.     fprintf(js_include_file,"\n<!-- begin function 25 read_canvas%d() : angle(s) in degrees-->\n\
  6705. read_canvas%d = function(){\
  6706. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  6707. var lu = userdraw_radius.length;\
  6708. var prec = %d;\
  6709. var angle_reply = new Array(lu);\
  6710. for(var p = 0 ; p < lu ; p++){\
  6711.  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
  6712. };\
  6713. return angle_reply;\
  6714. };\n\
  6715. <!-- end function 25 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6716.     break;
  6717.     case 26:
  6718.     fprintf(js_include_file,"\n<!-- begin function 26 read_canvas%d() : angle(s) in radians-->\n\
  6719. read_canvas%d = function(){\
  6720. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  6721. var lu = userdraw_radius.length;\
  6722. var prec = %d;\
  6723. var angle_reply = new Array(lu);\
  6724. for(var p = 0 ; p < lu ; p++){\
  6725.  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
  6726. };\
  6727. return angle_reply;\
  6728. };\n\
  6729. <!-- end function 26 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6730.     break;
  6731.     case 27:
  6732.     fprintf(js_include_file,"\n<!-- begin function 27 read_canvas%d()  : inputfield(s) location and their values : -->\n\
  6733. read_canvas%d = function(){\
  6734. var lu = userdraw_x.length;\
  6735. if( lu < 1){alert(\"nothing drawn...\");return;}\
  6736. set_reply_precision();\
  6737. var prec = %d;\
  6738. var rep = (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\",\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\",\"+ document.getElementById(\"canvas_input\"+p).value;\
  6739. for(var p = 0 ; p < lu ; p++){\
  6740.   rep = rep = \"\\n\" + (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\":\"+ document.getElementById(\"canvas_input\"+p).value;\
  6741. };\
  6742. return rep;\
  6743. };\n\
  6744. <!-- end function 27 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6745.     break;
  6746.     case 28:
  6747.     fprintf(js_include_file,"\n<!-- begin function 28 read_canvas%d() -->\n\
  6748. read_canvas%d = function(){\
  6749. var prec = %d;\
  6750. var reply = new Array();var p = 0;\
  6751. var idx = 0;\
  6752. while(userdraw_x[p]){\
  6753.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  6754.  idx++;\
  6755.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  6756.  idx++;\
  6757.  reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\
  6758.  idx++;\
  6759.  p++;\
  6760. };\
  6761. if( p == 0){alert(\"nothing drawn...\");return;}\
  6762. return reply;\
  6763. };\n\
  6764. <!-- end function 28 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6765.     break;
  6766.     case 29:
  6767.     fprintf(js_include_file,"\n<!-- begin function 29 read_canvas%d() -->\n\
  6768. function xy_precision(array_x,array_y){\
  6769. var len = array_x.length;\
  6770. var x_array = new Array(len);\
  6771. var y_array = new Array(len);\
  6772. var prec = %d;\
  6773. for(var p = 0 ; p < len ; p++ ){\
  6774.  x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\
  6775.  y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\
  6776. };\
  6777. return x_array+\";\"+y_array;\
  6778. };\n\
  6779. function round_to_pixel(array_r){\
  6780. var len = array_r.length;\
  6781. for(var p = 0 ; p < len ; p++ ){\
  6782.  array_r[p] = Math.round(array_r[p]);\
  6783. };\
  6784. return array_r;\
  6785. };\
  6786. read_canvas%d = function(){\
  6787. var reply=\" \";\
  6788. if( points_x && points_x.length > 0 ){reply = reply + xy_precision(points_x,points_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6789. if( circles_x && circles_x.length > 0 ){ reply = reply + xy_precision(circles_x,circles_y)+\";\"+round_to_pixel(multi_radius)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6790. if( segments_x && segments_x.length > 0 ){ reply = reply +  xy_precision(segments_x,segments_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6791. if( arrows_x && arrows_x.length > 0 ){ reply = reply +  xy_precision(arrows_x,arrows_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6792. if( lines_x && lines_x.length > 0 ){ reply = reply + xy_precision(lines_x,lines_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6793. if( triangles_x && triangles_x.length > 0){ reply = reply + xy_precision(triangles_x,triangles_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6794. if( polys_x && polys_x.length > 0){ reply = reply + xy_precision(polys_x,polys_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6795. if( rects_x && rects_x.length > 0 ){ reply = reply + xy_precision(rects_x,rects_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6796. if( closedpoly_x && closedpoly_x.length > 0){ closedpoly_x.pop();closedpoly_y.pop();reply = reply + xy_precision(closedpoly_x,closedpoly_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6797. if( parallelogram_x && parallelogram_x.length > 0){ reply = reply + xy_precision(parallelogram_x,parallelogram_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6798. if( text_x && text_x.length > 0){ reply = reply + xy_precision(text_x,text_y)+\";\"+text_abc+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
  6799. return reply;\
  6800. };\n\
  6801. <!-- end function 29 read_canvas%d() -->",canvas_root_id,reply_precision,canvas_root_id,canvas_root_id);
  6802.     break;
  6803.     case 30:
  6804.     fprintf(js_include_file,"\n<!-- begin function 30 read_canvas%d() -->\n\
  6805. read_canvas%d = function(){\
  6806. var reply = new Array(3);\
  6807. var prec = %d;\
  6808. reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
  6809. reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
  6810. reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\
  6811. return reply;\
  6812. };\n\
  6813. <!-- end function 30 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6814.     break;
  6815.     case 31:
  6816.     fprintf(js_include_file,"\n<!-- begin function 31 read_canvas%d() -->\n\
  6817. read_canvas%d = function(){\
  6818. var reply = new Array(3);\
  6819. var prec = %d;\
  6820. reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
  6821. reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
  6822. reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
  6823. return reply;\
  6824. };\n\
  6825. <!-- end function 31 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6826.     break;
  6827.     case 32:
  6828.     fprintf(js_include_file,"\n<!-- begin function 32 read_canvas%d() -->\n\
  6829. read_canvas%d = function(){\
  6830. var reply = new Array(6);\
  6831. var prec = %d;\
  6832. reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
  6833. reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
  6834. reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
  6835. reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
  6836. reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
  6837. reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\
  6838. return reply;\
  6839. };\n\
  6840. <!-- end function 32 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6841.     break;
  6842.     default: canvas_error("hmmm unknown replyformat...");break;
  6843. }
  6844.  return;
  6845. }
  6846.  
  6847.  
  6848. /*
  6849.  add drawfunction :
  6850.  - functions used by userdraw_primitives (circle,rect,path,triangle...)
  6851.  - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
  6852.  - grid / mathml
  6853.  - will not scale or zoom in
  6854.  - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
  6855.  - is printed directly into 'js_include_file'
  6856. */
  6857.  
  6858. void add_javascript_function(int js_function[],int canvas_root_id){
  6859. int i;
  6860. for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
  6861.  if( js_function[i] == 1){
  6862.     switch(i){
  6863.     case JS_FIND_ANGLE:
  6864.     fprintf(js_include_file,"\n\
  6865. <!-- function find_angle() -->\n\
  6866. function find_angle(xc,yc,x1,y1){\
  6867. var dx = x1 - xc;\
  6868. var dy = yc - y1;\
  6869. if( dx > 0 && dy < 0){ return Math.atan(-1*dy/dx);};\
  6870. if( dx < 0 && dy < 0){ return Math.PI + Math.atan(-1*dy/dx);};\
  6871. if( dx < 0 && dy > 0){ return Math.PI + Math.atan(-1*dy/dx);};\
  6872. if( dx > 0 && dy > 0){ return 2*Math.PI + Math.atan(-1*dy/dx);};};");
  6873.     break;
  6874.     case DRAW_EXTERNAL_IMAGE:
  6875. /* the external_canvas is already created: it needs to be FIRST in order to do some drawing onto it
  6876.  draw_external_image(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,int_data[8],int_data[9]);
  6877. */
  6878. fprintf(js_include_file,"\n<!-- drag external images --->\n\
  6879. var external_ctx = external_canvas.getContext(\"2d\");\
  6880. var external_canvas_rect = external_canvas.getBoundingClientRect();\
  6881. canvas_div.addEventListener(\"mousedown\",setxy,false);\
  6882. canvas_div.addEventListener(\"mouseup\",dragstop,false);\
  6883. canvas_div.addEventListener(\"mousemove\",dragxy,false);\
  6884. var selected_image = null;\
  6885. var ext_image_cnt = 0;\
  6886. var ext_drag_images = new Array();\
  6887. function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt){\
  6888. ext_image_cnt = idx;\
  6889. if(draggable == 1 ){\
  6890.  reply[click_cnt] = 0;\
  6891. };\
  6892. var image = new Image();\
  6893. image.src = URL;\
  6894. image.onload = function(){\
  6895.  if( sx < 1 ){ sx = 0; };\
  6896.  if( sy < 1 ){ sy = 0; };\
  6897.  if( swidth < 1 ){swidth = image.width;};\
  6898.  if( sheight < 1 ){sheight = image.height;};\
  6899.  if( width < 1 ){width = image.width;};\
  6900.  if( height < 1 ){height = image.height;};\
  6901.  if( resizable == 0 ){\
  6902.   if( swidth > image.width ){ swidth = image.width; };\
  6903.   if( sheight > image.height){ sheight = image.height;};\
  6904.   if( width > image.width ){ width = image.width; };\
  6905.   if( height > image.height){ height = image.height;};\
  6906.  };\
  6907.  var img = new Array(11);\
  6908.  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
  6909.  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;img[10] = click_cnt;\
  6910.  ext_drag_images[idx] = img;\
  6911.  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  6912. };\
  6913. };\
  6914. function dragstop(evt){\
  6915. selected_image = null;return;\
  6916. };\
  6917. function dragxy(evt){\
  6918. if( selected_image != null ){\
  6919.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  6920.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  6921.  var s_img = ext_drag_images[selected_image];\
  6922.  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\
  6923.  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\
  6924.  if( use_snap_to_points == 1){\
  6925.   var img_xy = snap_to_points(s_img[6],s_img[7]);\
  6926.   s_img[6] = img_xy[0];s_img[7] = img_xy[1];\
  6927.  }\
  6928.  else\
  6929.  {\
  6930.   if( x_use_snap_to_grid == 1 ){\
  6931.    s_img[6] = snap_to_x(s_img[6]);\
  6932.   };\
  6933.   if( y_use_snap_to_grid == 1 ){\
  6934.    s_img[7] = snap_to_x(s_img[7]);\
  6935.   };\
  6936.  };\
  6937.  ext_drag_images[selected_image] = s_img;\
  6938.  external_ctx.clearRect(0,0,xsize,ysize);\
  6939.  for(var i = 0; i <= ext_image_cnt ; i++){\
  6940.   var img = ext_drag_images[i];\
  6941.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  6942.  };\
  6943. };\
  6944. };\
  6945. function setxy(evt){\
  6946. if( ! selected_image && evt.which == 1 ){\
  6947.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
  6948.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
  6949.  var xm = evt.clientX - external_canvas_rect.left + xoff;\
  6950.  var ym = evt.clientY - external_canvas_rect.top + yoff;\
  6951.  var img;\
  6952.  for(var p = 0 ; p <= ext_image_cnt ; p++){\
  6953.   if( ext_drag_images[p] ){\
  6954.    img = ext_drag_images[p];\
  6955.    if( img[0] != 0 ){\
  6956.     if( xm > img[6] && xm < img[6] + img[8]){\
  6957.      if( ym > img[7] && ym < img[7] + img[9]){\
  6958.       if( img[0] == 1){\
  6959.        if( reply[img[10]] == 1 ){\
  6960.         reply[img[10]] = 0;external_ctx.strokeStyle = '#ffffff';\
  6961.        }\
  6962.        else\
  6963.        {\
  6964.         reply[img[10]] = 1;external_ctx.strokeStyle = '#00ff00';\
  6965.        };\
  6966.        external_ctx.lineWidth = 6;\
  6967.        external_ctx.beginPath();\
  6968.        external_ctx.rect(img[6],img[7],img[8],img[9]);\
  6969.        external_ctx.closePath();\
  6970.        external_ctx.stroke();\
  6971.        return;\
  6972.       }\
  6973.       else\
  6974.       {\
  6975.        img[6] = xm;\
  6976.        img[7] = ym;\
  6977.        ext_drag_images[p] = img;\
  6978.        selected_image = p;\
  6979.        dragxy(evt);\
  6980.       };\
  6981.      };\
  6982.     };\
  6983.    };\
  6984.   };\
  6985.  };\
  6986. }\
  6987. else\
  6988. {\
  6989.  selected_image = null;\
  6990. };\
  6991. };");
  6992.     break;
  6993.     case DRAW_BEZIER:
  6994. fprintf(js_include_file,"\n<!-- draw bezier curve -->\n\
  6995. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  6996. var draw_bezier = function(canvas_type,linewidth,xy_points,fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
  6997. var obj;\
  6998. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  6999.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  7000. }\
  7001. else\
  7002. {\
  7003.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  7004. };\
  7005. var ctx = obj.getContext(\"2d\");\
  7006. ctx.save();\
  7007. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7008. ctx.lineWidth = linewidth;\
  7009. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7010. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  7011. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  7012. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7013. ctx.beginPath();\
  7014. ctx.moveTo(x2px(xy_points[0]),y2px(xy_points[1]));\
  7015. ctx.bezierCurveTo(x2px(xy_points[2]),y2px(xy_points[3]),x2px(xy_points[4]),y2px(xy_points[5]),x2px(xy_points[6]),y2px(xy_points[7]));\
  7016. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7017. if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
  7018. ctx.stroke();\
  7019. ctx.restore();\
  7020. };\n",canvas_root_id,canvas_root_id,canvas_root_id);
  7021.     break;
  7022.    
  7023.     case DRAW_GRIDFILL:/* not used for userdraw */
  7024. fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
  7025. var grid_fill_pattern;\
  7026. var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize,use_userdraw){\
  7027. if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
  7028. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7029. var fc = %d+canvas_type;\n\
  7030. fill_canvas_no.push(fc);\
  7031. var obj = create_canvas%d(fc,xsize,ysize);\n\
  7032. var ctx = obj.getContext('2d');\n\
  7033. var x,y;\
  7034. ctx.fillStyle='rgba(255,255,255,0.01)';\n\
  7035. ctx.rect(0,0,xsize,ysize);\n\
  7036. ctx.fill();\n\
  7037. ctx.lineWidth = linewidth;\
  7038. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7039. ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
  7040. for( x = 0 ; x < xsize ; x = x + dx ){\
  7041.  ctx.beginPath();\
  7042.  ctx.moveTo(x,0);\
  7043.  ctx.lineTo(x,ysize);\
  7044.  ctx.closePath();\
  7045.  ctx.stroke();\
  7046. };\
  7047. for( y = 0 ; y < ysize; y = y + dy ){\
  7048.  ctx.beginPath();\
  7049.  ctx.moveTo(0,y);\
  7050.  ctx.lineTo(xsize,y);\
  7051.  ctx.closePath();\
  7052.  ctx.stroke();\
  7053. };\
  7054. if( use_userdraw ){\
  7055.  grid_fill_pattern = ctx;\
  7056. }\
  7057. else\
  7058. {\
  7059.  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};return;\
  7060. };",canvas_root_id,canvas_root_id);
  7061.     break;
  7062.  
  7063.     case DRAW_IMAGEFILL:/* not  used for userdraw */
  7064. fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
  7065. var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize,use_userdraw,use_scaling){\
  7066. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7067. var fc = %d+canvas_type;\
  7068. fill_canvas_no.push(fc);\
  7069. var obj = create_canvas%d(fc,xsize,ysize);\
  7070. var ctx = obj.getContext('2d');\
  7071. var img = new Image();\
  7072. img.src = URL;\
  7073. obj.style.visibility = 'hidden';\
  7074. img.onload = function(){\
  7075.  if( use_scaling == 1 ){\
  7076.   ctx.drawImage(img,x0,y0,xsize,ysize);\
  7077.  }else{\
  7078.   var w0 = img.width;var h0 = img.height;var w;var h;\
  7079.   for( w = x0; w < xsize ; w = w + w0 ){\
  7080.    for( h = y0; h < ysize; h = h + h0){\
  7081.      ctx.drawImage(img,w,h,w0,h0);\
  7082.    };\
  7083.   };\
  7084.  };\
  7085.  if( use_userdraw ){\
  7086.   image_pattern = ctx;\
  7087.  }\
  7088.  else\
  7089.  {\
  7090.   setTimeout(function(){ filltoborder( x0,y0,'red','red',canvas_type,true,ctx); },500);\
  7091.  };\
  7092. };\
  7093. };",canvas_root_id,canvas_root_id);
  7094.     break;
  7095.  
  7096.     case DRAW_DOTFILL:/* not  used for userdraw */
  7097. fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
  7098. var dot_fill_pattern;\
  7099. var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize,use_userdraw){\n\
  7100. if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
  7101. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7102. var fc = %d+canvas_type;\
  7103. fill_canvas_no.push(fc);\
  7104. var obj = create_canvas%d(fc,xsize,ysize);\
  7105. var ctx = obj.getContext('2d');\
  7106. var x,y;\
  7107. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7108. ctx.rect(0,0,xsize,ysize);\
  7109. ctx.fill();\
  7110. ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\
  7111. ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
  7112. for( x = 0 ; x < xsize ; x = x + dx ){\
  7113.  for( y = 0 ; y < ysize ; y = y + dy ){\
  7114.   ctx.beginPath();\
  7115.   ctx.arc(x,y,radius,0,2*Math.PI,false);\
  7116.   ctx.closePath();\
  7117.   ctx.fill();\
  7118.  };\
  7119. };\
  7120. if( use_userdraw ){\
  7121.  dot_fill_pattern = ctx;\
  7122. }\
  7123. else\
  7124. {\
  7125. setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);\
  7126. };\
  7127. return;\
  7128. };",canvas_root_id,canvas_root_id);
  7129.     break;
  7130.  
  7131.     case DRAW_TEXTFILL:/* not  used for userdraw */
  7132. fprintf(js_include_file,"\n<!-- draw textfill -->\n\
  7133. var text_fill_pattern;\
  7134. var draw_textfill = function(canvas_type,x0,y0,color,fontfamily,xsize,ysize,txt,use_userdraw){\n\
  7135. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7136. var fc = %d+canvas_type;\
  7137. fill_canvas_no.push(fc);\
  7138. var obj = create_canvas%d(fc,xsize,ysize);\
  7139. var ctx = obj.getContext('2d');\
  7140. ctx.font = fontfamily;\
  7141. var dx = (ctx.measureText(txt)).width;\
  7142. var dy = parseInt(fontfamily)+2;\
  7143. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7144. ctx.rect(0,0,xsize,ysize);\
  7145. ctx.fill();\
  7146. ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\
  7147. for(var x = 0 ; x < xsize ; x = x + dx ){\
  7148.  for(var y = 0 ; y < ysize ; y = y + dy ){\
  7149.   ctx.fillText(txt,x,y);\
  7150.  };\
  7151. };\
  7152. if( use_userdraw ){\
  7153.  text_fill_pattern = ctx;\
  7154. }\
  7155. else\
  7156. {\
  7157. setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
  7158. return;};",canvas_root_id,canvas_root_id);
  7159.     break;
  7160.  
  7161.     case DRAW_DIAMONDFILL:/* not used for userdraw */
  7162. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  7163. var diamond_fill_pattern;\
  7164. var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\
  7165. if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
  7166. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7167. var fc = %d+canvas_type;\
  7168. fill_canvas_no.push(fc);\
  7169. var obj = create_canvas%d(fc,xsize,ysize);\
  7170. var ctx = obj.getContext('2d');\
  7171. var x;\
  7172. var y;\
  7173. ctx.lineWidth = linewidth;\
  7174. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7175. ctx.rect(0,0,xsize,ysize);\
  7176. ctx.fill();\
  7177. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7178. ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
  7179. y = ysize;\
  7180. ctx.beginPath();\
  7181. for( x = 0 ; x < xsize ; x = x + dx ){\
  7182.  ctx.moveTo(x,0);\
  7183.  ctx.lineTo(xsize,y);\
  7184.  y = y - dy;\
  7185. };\
  7186. y=0;\
  7187. for( x = xsize ; x > 0 ; x = x - dx){\
  7188.  ctx.moveTo(x,ysize);\
  7189.  ctx.lineTo(0,y);\
  7190.  y = y + dy;\
  7191. };\
  7192. y = 0;\
  7193. for( x = 0 ; x < xsize ; x = x + dx ){\
  7194.  ctx.moveTo(x,0);\
  7195.  ctx.lineTo(0,y);\
  7196.  y = y + dy;\
  7197. };\
  7198. y = 0;\
  7199. for( x = 0 ; x < xsize ; x = x + dx ){\
  7200.  ctx.moveTo(xsize,y);\
  7201.  ctx.lineTo(x,ysize);\
  7202.  y = y + dy;\
  7203. };\
  7204. ctx.closePath();\
  7205. ctx.stroke();\
  7206. if( use_userdraw ){\
  7207.  diamond_fill_pattern = ctx;\
  7208. }\
  7209. else\
  7210. {\
  7211.  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
  7212. return;\
  7213. }",canvas_root_id,canvas_root_id);
  7214.     break;
  7215.  
  7216.     case DRAW_HATCHFILL:/* not used for userdraw */
  7217. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  7218. var hatch_fill_pattern;\
  7219. var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\
  7220. if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
  7221. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7222. var fc = %d+canvas_type;\
  7223. fill_canvas_no.push(fc);\
  7224. var obj = create_canvas%d(fc,xsize,ysize);\
  7225. var ctx = obj.getContext('2d');\
  7226. var x,y;\
  7227. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7228. ctx.rect(0,0,xsize,ysize);\
  7229. ctx.fill();\
  7230. ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
  7231. ctx.lineWidth = linewidth;\
  7232. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7233. y = ysize;\
  7234. ctx.beginPath();\
  7235. for( x = 0 ; x < xsize ; x = x + dx ){\
  7236.  ctx.moveTo(x,0);\
  7237.  ctx.lineTo(xsize,y);\
  7238.  y = y - dy;\
  7239. };\
  7240. y = 0;\
  7241. for( x = xsize ; x >= dx ; x = x - dx){\
  7242.  ctx.moveTo(x,ysize);\
  7243.  ctx.lineTo(0,y);\
  7244.  y = y + dy;\
  7245. };\
  7246. ctx.closePath();\
  7247. ctx.stroke();\
  7248. if( use_userdraw ){\
  7249.  hatch_fill_pattern = ctx;\
  7250. }\
  7251. else\
  7252. {\
  7253.  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
  7254. return;\
  7255. };",canvas_root_id,canvas_root_id);
  7256.     break;
  7257.     case DRAW_CIRCLES:/*  used for userdraw */
  7258. fprintf(js_include_file,"\n<!-- draw circles -->\n\
  7259. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7260. 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){\
  7261. ctx.save();\
  7262. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7263. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7264. ctx.lineWidth = line_width;\
  7265. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7266. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\n\
  7267. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7268. if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
  7269. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7270. for(var p = 0 ; p < x_points.length ; p++ ){\
  7271.  ctx.beginPath();\
  7272.  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
  7273.  ctx.closePath();\
  7274.  if(use_filled != 0 ){ctx.fill();};\
  7275.  ctx.stroke();\
  7276. }\
  7277. ctx.restore();\
  7278. return;\
  7279. };");
  7280.     break;
  7281.     case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
  7282. fprintf(js_include_file,"\n<!-- draw polyline -->\n\
  7283. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7284. 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){\
  7285. ctx.save();\
  7286. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7287. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7288. ctx.lineWidth = line_width;\
  7289. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7290. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7291. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7292. ctx.clearRect(0,0,xsize,ysize);\
  7293. ctx.beginPath();\
  7294. for(var p = 0 ; p < x_points.length-1 ; p++ ){\
  7295.  ctx.moveTo(x_points[p],y_points[p]);\
  7296.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  7297. }\
  7298. ctx.closePath();\
  7299. ctx.stroke();\
  7300. for(var p = 0 ; p < x_points.length ; p++ ){\
  7301.  ctx.beginPath();\
  7302.  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
  7303.  ctx.closePath();ctx.fill();ctx.stroke();\
  7304. };\
  7305. ctx.restore();\
  7306. return;\
  7307. };");
  7308.     break;
  7309.  
  7310.     case DRAW_SEGMENTS:/*  used for userdraw */
  7311. fprintf(js_include_file,"\n<!-- draw segments -->\n\
  7312. 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){\
  7313. ctx.save();\
  7314. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7315. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7316. ctx.lineWidth = line_width;\
  7317. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7318. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7319. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7320. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  7321.  ctx.beginPath();\
  7322.  ctx.moveTo(x_points[p],y_points[p]);\
  7323.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  7324.  ctx.closePath();\
  7325.  ctx.stroke();\
  7326.  }\
  7327.  ctx.restore();\
  7328.  return;\
  7329. };");
  7330.     break;
  7331.  
  7332.     case DRAW_LINES:/*  used for userdraw */
  7333. fprintf(js_include_file,"\n<!-- draw lines -->\n\
  7334. function calc_line(x1,x2,y1,y2){\
  7335. var marge = 2;\
  7336. if(x1 < x2+marge && x1>x2-marge){\
  7337.  return [x1,0,x1,ysize];\
  7338. };\
  7339. if(y1 < y2+marge && y1>y2-marge){\
  7340.  return [0,y1,xsize,y1];\
  7341. };\
  7342. var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
  7343. var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
  7344. return [0,Y1,xsize,Y2];\
  7345. };\
  7346. 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){\
  7347. ctx.save();\
  7348. var line = new Array(4);\
  7349. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7350. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7351. ctx.lineWidth = line_width;\
  7352. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7353. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7354. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7355. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  7356.  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
  7357.  ctx.beginPath();\
  7358.  ctx.moveTo(line[0],line[1]);\
  7359.  ctx.lineTo(line[2],line[3]);\
  7360.  ctx.closePath();\
  7361.  ctx.stroke();\
  7362.  }\
  7363.  ctx.restore();\
  7364.  return;\
  7365. };");
  7366.     break;
  7367.  
  7368.     case DRAW_DEMILINES:/*  used for userdraw */
  7369. fprintf(js_include_file,"\n<!-- draw demilines -->\n\
  7370. function find_inf_point(x1,y1,x2,y2){\
  7371. if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\
  7372. var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\
  7373. if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\
  7374. };\
  7375. var draw_demilines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
  7376. ctx.save();\
  7377. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7378. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7379. ctx.lineWidth = line_width;\
  7380. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7381. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7382. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7383. var pair = new Array(4);\
  7384. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  7385.  pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\
  7386.  ctx.beginPath();\
  7387.  ctx.moveTo(pair[0],pair[1]);\
  7388.  ctx.lineTo(pair[2],pair[3]);\
  7389.  ctx.closePath();\
  7390.  ctx.stroke();\
  7391.  }\
  7392.  ctx.restore();\
  7393.  return;\
  7394. };");
  7395.     break;
  7396.  
  7397.     case DRAW_CROSSHAIRS:/*  used for userdraw */
  7398. fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
  7399. var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\
  7400. ctx.save();\
  7401. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7402. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7403. ctx.lineWidth = line_width;\
  7404. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7405. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7406. var x1,x2,y1,y2;\
  7407. for(var p = 0 ; p < x_points.length ; p++ ){\
  7408.  x1 = x_points[p] - crosshair_size;\
  7409.  x2 = x_points[p] + crosshair_size;\
  7410.  y1 = y_points[p] - crosshair_size;\
  7411.  y2 = y_points[p] + crosshair_size;\
  7412.  ctx.beginPath();\
  7413.  ctx.moveTo(x1,y1);\
  7414.  ctx.lineTo(x2,y2);\
  7415.  ctx.closePath();\
  7416.  ctx.stroke();\
  7417.  ctx.beginPath();\
  7418.  ctx.moveTo(x2,y1);\
  7419.  ctx.lineTo(x1,y2);\
  7420.  ctx.closePath();\
  7421.  ctx.stroke();\
  7422. }\
  7423. ctx.restore();\
  7424.  return;\
  7425. };");
  7426.     break;
  7427.  
  7428.     case DRAW_RECTS:/*  used for userdraw */
  7429. fprintf(js_include_file,"\n<!-- draw rects -->\n\
  7430. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7431. 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){\
  7432. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7433. ctx.save();\
  7434. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7435. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7436. ctx.lineWidth = line_width;\
  7437. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7438. ctx.strokeStyle = 'rgba('+stroke_color+','+stroke_opacity+')';\
  7439. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
  7440. if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
  7441. for(var p = 0 ; p < x_points.length ; p = p + 2){\
  7442.  ctx.beginPath();\
  7443.  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
  7444.  ctx.closePath();\
  7445.  if(use_filled != 0 ){ctx.fill();}\
  7446.  ctx.stroke();\
  7447. };\
  7448. ctx.restore();\
  7449. return;\
  7450. };");
  7451.     break;
  7452.  
  7453.     case DRAW_ROUNDRECTS:/*  used for userdraw */
  7454. fprintf(js_include_file,"\n<!-- draw round rects -->\n\
  7455. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7456. 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){\
  7457. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7458. ctx.save();\
  7459. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7460. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7461. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7462. ctx.lineWidth = line_width;\
  7463. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7464. if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
  7465. var x,y,w,h,r;\
  7466. for(var p = 0; p < x_points.length; p = p+2){\
  7467.  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);\
  7468.  ctx.beginPath();ctx.moveTo(x + r, y);\
  7469.  ctx.lineTo(x + w - r, y);\
  7470.  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
  7471.  ctx.lineTo(x + w, y + h - r);\
  7472.  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
  7473.  ctx.lineTo(x + r, y + h);\
  7474.  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
  7475.  ctx.lineTo(x, y + r);\
  7476.  ctx.quadraticCurveTo(x, y, x + r, y);\
  7477.  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
  7478.  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7479.  if( use_filled != 0 ){ctx.fill();};\
  7480.  ctx.stroke();\
  7481. }\
  7482. ctx.restore();\
  7483. };");
  7484.     break;
  7485.  
  7486.     case DRAW_ELLIPSES:/* not  used for userdraw */
  7487. fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
  7488. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7489. 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){\
  7490. var obj;\
  7491. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  7492.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  7493. }\
  7494. else\
  7495. {\
  7496.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  7497. };\
  7498. var ctx = obj.getContext(\"2d\");\
  7499. ctx.save();\
  7500. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7501. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7502. if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
  7503. var cx,cy,ry,rx;\
  7504. ctx.lineWidth = line_width;\
  7505. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7506. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7507. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7508. for(var p=0;p< x_points.length;p = p+2){\
  7509.  ctx.beginPath();\
  7510.  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
  7511.  ctx.translate(cx - rx, cy - ry);\
  7512.  ctx.scale(rx, ry);\
  7513.  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
  7514.  if( use_filled != 0 ){ctx.fill();}\
  7515.  ctx.stroke();\
  7516. };\
  7517. ctx.restore();\
  7518. };",canvas_root_id,canvas_root_id,canvas_root_id);
  7519.     break;
  7520.  
  7521.     case DRAW_PATHS: /*  used for userdraw */
  7522. fprintf(js_include_file,"\n<!-- draw paths -->\n\
  7523. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7524. 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){\
  7525. ctx.save();\
  7526. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7527. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7528. ctx.lineWidth = line_width;\
  7529. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7530. ctx.lineJoin = \"round\";\
  7531. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7532. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7533. if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
  7534. ctx.beginPath();\
  7535. ctx.moveTo(x_points[0],y_points[0]);\
  7536. for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
  7537. if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
  7538. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7539. if(use_filled != 0){ctx.fill();}\
  7540. ctx.stroke();\
  7541. ctx.restore();\
  7542. return;\
  7543. };");
  7544.  
  7545.     break;
  7546.     case DRAW_ARROWS:/*  used for userdraw */
  7547. fprintf(js_include_file,"\n<!-- draw arrows -->\n\
  7548. 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){\
  7549. ctx.save();\
  7550. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7551. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7552. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7553. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7554. ctx.lineWidth = line_width;\
  7555. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7556. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7557. ctx.lineCap = \"round\";\
  7558. var x1,y1,x2,y2,dx,dy,len;\
  7559. for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
  7560.   ctx.save();\
  7561.   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
  7562.   len = Math.sqrt(dx*dx+dy*dy);\
  7563.   ctx.translate(x2,y2);\
  7564.   ctx.rotate(Math.atan2(dy,dx));\
  7565.   ctx.lineCap = \"round\";\
  7566.   ctx.beginPath();\
  7567.   ctx.moveTo(0,0);\
  7568.   ctx.lineTo(-len,0);\
  7569.   ctx.closePath();\
  7570.   ctx.stroke();\
  7571.   ctx.beginPath();\
  7572.   ctx.moveTo(0,0);\
  7573.   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  7574.   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  7575.   ctx.closePath();\
  7576.   ctx.fill();\
  7577.   ctx.restore();\
  7578.   if( type == 2 ){\
  7579.     ctx.save();\
  7580.     ctx.translate(x1,y1);\
  7581.     ctx.rotate(Math.atan2(-dy,-dx));\
  7582.     ctx.beginPath();\
  7583.     ctx.moveTo(0,0);\
  7584.     ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\
  7585.     ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\
  7586.     ctx.closePath();\
  7587.     ctx.stroke();\
  7588.     ctx.fill();\
  7589.     ctx.restore();\
  7590.   };\
  7591.  };\
  7592.  ctx.restore();\
  7593.  return;\
  7594. };");
  7595.     break;
  7596.  
  7597.     case DRAW_VIDEO:/* not  used for userdraw */
  7598. fprintf(js_include_file,"\n<!-- draw video -->\n\
  7599. var draw_video = function(canvas_root_id,x,y,w,h,URL){\
  7600. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  7601. var video_div = document.createElement(\"div\");\
  7602. canvas_div.appendChild(video_div);\
  7603. video_div.style.position = \"absolute\";\
  7604. video_div.style.left = x+\"px\";\
  7605. video_div.style.top = y+\"px\";\
  7606. video_div.style.width = w+\"px\";\
  7607. video_div.style.height = h+\"px\";\
  7608. var video = document.createElement(\"video\");\
  7609. video_div.appendChild(video);\
  7610. video.style.width = w+\"px\";\
  7611. video.style.height = h+\"px\";\
  7612. video.autobuffer = true;\
  7613. video.controls = true;video.autoplay = false;\
  7614. var src = document.createElement(\"source\");\
  7615. src.type = \"video/mp4\";\
  7616. src.src = URL;\
  7617. video.appendChild(src);\
  7618. video.load();\
  7619. return;\
  7620. };");
  7621.     break;
  7622.  
  7623.     case DRAW_AUDIO:/* not used for userdraw */
  7624. fprintf(js_include_file,"\n<!-- draw audio -->\n\
  7625. var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
  7626. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  7627. var audio_div = document.createElement(\"div\");\
  7628. canvas_div.appendChild(audio_div);\
  7629. audio_div.style.position = \"absolute\";\
  7630. audio_div.style.left = x+\"px\";\
  7631. audio_div.style.top = y+\"px\";\
  7632. audio_div.style.width = w+\"px\";\
  7633. audio_div.style.height = h+\"px\";\
  7634. var audio = document.createElement(\"audio\");\
  7635. audio_div.appendChild(audio);\
  7636. audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
  7637. audio.autobuffer = true;\
  7638. if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;};\
  7639. if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;};\
  7640. var src1 = document.createElement(\"source\");\
  7641. src1.type = \"audio/ogg\";\
  7642. src1.src = URL1;\
  7643. audio.appendChild(src1);\
  7644. var src2 = document.createElement(\"source\");\
  7645. src2.type = \"audio/mpeg\";\
  7646. src2.src = URL2;\
  7647. audio.appendChild(src2);\
  7648. audio.load();\
  7649. return;\
  7650. };");
  7651.     break;
  7652.  
  7653.     case DRAW_HTTP:/* not  used for userdraw */
  7654. fprintf(js_include_file,"\n<!-- draw http -->\n\
  7655. var draw_http = function(canvas_root_id,x,y,w,h,URL){\
  7656. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  7657. var http_div = document.createElement(\"div\");\
  7658. var iframe = document.createElement(\"iframe\");\
  7659. canvas_div.appendChild(http_div);\
  7660. http_div.appendChild(iframe);\
  7661. iframe.src = URL;\
  7662. iframe.setAttribute(\"width\",w);\
  7663. iframe.setAttribute(\"height\",h);\
  7664. return;\
  7665. };");
  7666.     break;
  7667.  
  7668.     case DRAW_XML: /*
  7669.     onclick=1 : click
  7670.     onclick=2 drag
  7671.     xy:drag_type = 0;
  7672.     x:    drag_type = 1;
  7673.     y:    drag_type = 2;
  7674.     */
  7675.  
  7676. fprintf(js_include_file,"\n<!-- draw xml -->\n\
  7677. var draw_xml = function(canvas_root_id,x,y,mathml,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity){\
  7678. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  7679. var xml_div = document.createElement(\"div\");\
  7680. canvas_div.appendChild(xml_div);\
  7681. xml_div.innerHTML = mathml;\
  7682. xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7683. var color_org = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7684. var back_color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7685. var no_color = \"rgba(255,255,255,0)\";\
  7686. xml_div.style.position = \"absolute\"; xml_div.style.left = x+\"px\";xml_div.style.top = y+\"px\";\
  7687. var dragging = false;\
  7688. if( onclick == 2 ){reply[click_cnt] = px2x(x)+','+px2y(y);};\
  7689. if( onclick == 1 ){reply[click_cnt] = 0;};\
  7690. if( onclick == 2 ){\
  7691.  xml_div.onclick = function(){\
  7692.   canvas_div.onclick = function(evt){if(dragging){dragging = false;xml_div.style.color = color_org; xml_div.style.backgroundColor = no_color;}else{dragging = true;xml_div.style.color = 'red';xml_div.style.backgroundColor = back_color;};};\
  7693.   canvas_div.onmousemove = function(evt){\
  7694.    if(!dragging){return;};\
  7695.    var x1;var y1;\
  7696.    var mouse = dragstuff.getMouse(evt,xml_div);\
  7697.    switch(drag_type){\
  7698.     case 0: x1 = mouse.x;y1 = mouse.y;break;\
  7699.     case 1: x1 = mouse.x;y1 = y;break;\
  7700.     case 2: x1 = x;y1 = mouse.y;break;\
  7701.     default:x1 = x;y1 = y; break;\
  7702.    };\
  7703.    if( x_use_snap_to_grid == 1 ){ x1 = snap_to_x(x1);};\
  7704.    if( y_use_snap_to_grid == 1 ){ y1 = snap_to_y(y1);};\
  7705.    if( use_snap_to_points != 0 ){ var xy = new Array(2);if( use_snap_to_points == 1 ){xy = snap_to_points(x1,y1);}else{xy = snap_to_fun(x1,y1);};x1 = xy[0];y1 = xy[1];};\
  7706.    xml_div.style.left = x1 + 'px';xml_div.style.top = y1 + 'px';\
  7707.    reply[click_cnt] = px2x(x1)+','+px2y(y1);\
  7708.   };\
  7709.  };\
  7710. };\
  7711. if(onclick == 1){\
  7712.  xml_div.onclick = function(){\
  7713.  if(reply[click_cnt] == 0){ reply[click_cnt] = 1; xml_div.style.color = 'red';xml_div.style.backgroundColor = back_color;}else{reply[click_cnt] = 0;xml_div.style.color = color_org;xml_div.style.backgroundColor = no_color;};};\
  7714. };\
  7715. return;\
  7716. };");
  7717.     break;
  7718.     case DRAW_SGRAPH:
  7719. /*
  7720.  xstart = given
  7721.  ystart = given
  7722.  sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
  7723. */
  7724. fprintf(js_include_file,"\n<!-- draw sgraph -->\n\
  7725. var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
  7726. 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);};\
  7727. var ctx = obj.getContext(\"2d\");\
  7728. ctx.font = fontfamily;\
  7729. var minor_opacity = 0.8*opacity;\
  7730. ctx.clearRect(0,0,xsize,ysize);\
  7731. var zero_x = 0.1*xsize;\
  7732. var zero_y = 0.9*ysize;\
  7733. var snor_x;var snor_y;\
  7734. if( xstart != xmin){\
  7735.  snor_x = 0.1*xsize;\
  7736. }\
  7737. else\
  7738. {\
  7739.  snor_x = 0;\
  7740.  xstart = xmin;\
  7741. };\
  7742. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  7743. ctx.lineWidth = 2;\
  7744. ctx.beginPath();\
  7745. ctx.moveTo(xsize,zero_y);\
  7746. ctx.lineTo(zero_x,zero_y);\
  7747. ctx.lineTo(zero_x,0);\
  7748. ctx.stroke();\
  7749. ctx.closePath();\
  7750. ctx.beginPath();\
  7751. ctx.moveTo(zero_x,zero_y);\
  7752. ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
  7753. ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
  7754. ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
  7755. ctx.lineTo(zero_x + snor_x,zero_y);\
  7756. ctx.stroke();\
  7757. ctx.closePath();\
  7758. ctx.beginPath();\
  7759. var num = xstart;\
  7760. var flipflop = 1;\
  7761. var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
  7762. var txtsize;var txt_marge=step_x - 5;\
  7763. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  7764.  txtsize = ctx.measureText(num).width;\
  7765.  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
  7766.  if( flipflop == 1){\
  7767.   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
  7768.  }\
  7769.  else\
  7770.  {\
  7771.   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
  7772.  };\
  7773.  num = num + xmajor;\
  7774. };\
  7775. ctx.stroke();\
  7776. ctx.closePath();\
  7777. ctx.lineWidth = 1;\
  7778. ctx.beginPath();\
  7779. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  7780.   ctx.moveTo(x,zero_y);\
  7781.   ctx.lineTo(x,0);\
  7782. };\
  7783. ctx.stroke();\
  7784. ctx.closePath();\
  7785. if( xminor > 1){\
  7786.  ctx.lineWidth = 0.5;\
  7787.  ctx.beginPath();\
  7788.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  7789.  var minor_step_x = step_x / xminor;\
  7790.  var nx;\
  7791.  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
  7792.    num = 1;\
  7793.    for(var p = 1 ; p < xminor ; p++){\
  7794.     nx = x + num*minor_step_x;\
  7795.     ctx.moveTo(nx,zero_y);\
  7796.     ctx.lineTo(nx,0);\
  7797.     num++;\
  7798.    };\
  7799.  };\
  7800.  ctx.stroke();\
  7801.  ctx.closePath();\
  7802.  ctx.beginPath();\
  7803.  ctx.lineWidth = 2;\
  7804.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  7805.  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  7806.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
  7807.  };\
  7808.  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
  7809.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
  7810.  };\
  7811.  ctx.stroke();\
  7812.  ctx.closePath();\
  7813.  ctx.lineWidth = 0.5;\
  7814. };\
  7815. xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
  7816. if( ystart != ymin){\
  7817.  snor_y = 0.1*ysize;\
  7818. }\
  7819. else\
  7820. {\
  7821.  snor_y = 0;\
  7822.  ystart = ymin;\
  7823. };\
  7824. ctx.lineWidth = 2;\
  7825. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  7826. ctx.beginPath();\
  7827. ctx.moveTo(zero_x,zero_y);\
  7828. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
  7829. ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
  7830. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
  7831. ctx.lineTo(zero_x,zero_y - snor_y);\
  7832. ctx.stroke();\
  7833. ctx.closePath();\
  7834. ctx.beginPath();\
  7835. ctx.lineWidth = 1;\
  7836. num = ystart;\
  7837. var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
  7838. for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
  7839.  ctx.moveTo(zero_x,y);\
  7840.  ctx.lineTo(xsize,y);\
  7841.  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
  7842.  num = num + ymajor;\
  7843. };\
  7844. ctx.stroke();\
  7845. ctx.closePath();\
  7846. if( yminor > 1){\
  7847.  ctx.lineWidth = 0.5;\
  7848.  ctx.beginPath();\
  7849.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  7850.  var minor_step_y = step_y / yminor;\
  7851.  var ny;\
  7852.  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
  7853.   num = 1;\
  7854.   for(var p = 1 ;p < yminor;p++){\
  7855.     ny = y + num*minor_step_y;\
  7856.     ctx.moveTo(zero_x,ny);\
  7857.     ctx.lineTo(xsize,ny);\
  7858.     num++;\
  7859.    };\
  7860.  };\
  7861.  ctx.stroke();\
  7862.  ctx.closePath();\
  7863.  ctx.lineWidth = 2;\
  7864.  ctx.beginPath();\
  7865.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  7866.  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
  7867.   ctx.moveTo(zero_x,y);\
  7868.   ctx.lineTo(zero_x+12,y);\
  7869.  };\
  7870.  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
  7871.   ctx.moveTo(zero_x,y);\
  7872.   ctx.lineTo(zero_x+6,y);\
  7873.  };\
  7874.  ctx.stroke();\
  7875.  ctx.closePath();\
  7876. };\
  7877. ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
  7878. if( typeof(legend%d)  !== 'undefined' ){\
  7879.  ctx.globalAlpha = 1.0;\
  7880.  var y_offset = 2*font_size;\
  7881.  var txt;var txt_size;\
  7882.  var x_offset = xsize - 2*font_size;\
  7883.  var l_length = legend%d.length;var barcolor = new Array();\
  7884.  if( typeof(legendcolors%d) !== 'undefined' ){\
  7885.   for(var p = 0 ; p < l_length ; p++){\
  7886.    barcolor[p] = legendcolors%d[p];\
  7887.   };\
  7888.  }else{\
  7889.   if( barcolor.length == 0 ){\
  7890.    for(var p = 0 ; p < l_length ; p++){\
  7891.     barcolor[p] = stroke_color;\
  7892.    };\
  7893.   };\
  7894.  };\
  7895.  for(var p = 0; p < l_length; p++){\
  7896.   ctx.fillStyle = barcolor[p];\
  7897.   txt = legend%d[p];\
  7898.   txt_size = ctx.measureText(txt).width;\
  7899.   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
  7900.   y_offset = parseInt(y_offset + 1.5*font_size);\
  7901.  };\
  7902. };\
  7903. if( typeof(xaxislabel) !== 'undefined' ){\
  7904.   ctx.fillStyle = \'#000000\';\
  7905.   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
  7906.   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
  7907. };\
  7908. if( typeof(yaxislabel) !== 'undefined'){\
  7909.   ctx.save();\
  7910.   ctx.fillStyle = \'#000000\';\
  7911.   var txt_size = ctx.measureText(yaxislabel).width;\
  7912.   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
  7913.   ctx.rotate(-0.5*Math.PI);\
  7914.   ctx.fillText(yaxislabel,0,0);\
  7915.   ctx.restore();\
  7916. };\
  7917. };\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);
  7918.     break;
  7919.     case DRAW_NUMBERLINE:
  7920. fprintf(js_include_file,"\n<!-- draw numberline -->\n\
  7921. var draw_numberline = function(canvas_type,use_axis_numbering,x0,x1,xmajor,xminor,y0,y1,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor,precision){\
  7922. var obj = create_canvas%d(canvas_type,xsize,ysize);\
  7923. var ctx = obj.getContext(\"2d\");\
  7924. ctx.lineWidth = linewidth || 1;\
  7925. ctx.strokeStyle = \"rgba(\"+strokecolor+\",\"+strokeopacity+\")\";\
  7926. ctx.font = fontfamily || 'Ariel 12px';\
  7927. var fontsize = parseInt(ctx.font);\
  7928. ctx.fillStyle =  \"rgba(\"+fontcolor+\",\"+strokeopacity+\")\";\
  7929. x1 = x2px(x1);\
  7930. x0 = x2px(x0);\
  7931. y0 = y2px(y0);\
  7932. y1 = y2px(y1);\
  7933. var sub_devision = -1;\
  7934. if( xminor%%2 == 0 ){ sub_devision = xminor/2; };\
  7935. var ybase1 = parseInt( y0 + fontsize + 2 );\
  7936. var ybase2 = parseInt( ybase1 + fontsize + 2 );\
  7937. var yh = Math.abs(parseInt( y0 - 0.3*(y0 -y1)));\
  7938. var ys = Math.abs(parseInt( y0 - 0.6*(y0 -y1)));\
  7939. xmajor = x2px(xmajor) - x2px(0);\
  7940. var i;var len;var p;\
  7941. xminor = xmajor / xminor;\
  7942. ctx.beginPath();\
  7943. for(p = x0 ; p < x1 ; p = p + xmajor){\
  7944.  ctx.moveTo(p,y0);ctx.lineTo(p,y1);i = 0;\
  7945.  for(var s = p ; s < p + xmajor ; s = s + xminor ){\
  7946.   ctx.moveTo(s,y0);\
  7947.   if( sub_devision == i){ ctx.lineTo(s,ys); } else { ctx.lineTo(s,yh); };\
  7948.   i++;\
  7949.  };\
  7950. };\
  7951. ctx.moveTo(p,y0);ctx.lineTo(p,y1);\
  7952. ctx.closePath();\
  7953. ctx.stroke();\
  7954. if( use_axis_numbering >-1 ){\
  7955.  var str = x_strings[use_axis_numbering];\
  7956.  len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  7957.  var corr;var x_nums;var x_text;var flipflop = 0;var off = ybase1;\
  7958.  ctx.beginPath();\
  7959.  if( x_strings_up[use_axis_numbering] == null){\
  7960.   for(var p = 0 ; p < len ; p = p+2){\
  7961.    var x_nums = x2px(eval(str[p]));\
  7962.    var x_text = str[p+1];\
  7963.    corr = ctx.measureText(x_text).width;\
  7964.    if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\
  7965.    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),off);\
  7966.   };\
  7967.  }\
  7968.  else\
  7969.  {\
  7970.   for(var p = 0 ; p < len ; p = p+2){\
  7971.    x_nums = x2px(eval(str[p]));\
  7972.    x_text = str[p+1];\
  7973.    corr = ctx.measureText(x_text).width + ybase1 - fontsize;\
  7974.    ctx.save();\
  7975.    ctx.translate(x_nums+0.5*fontsize, corr);\
  7976.    ctx.rotate(-1.5708);\
  7977.    ctx.fillText(x_text,0,0);\
  7978.    ctx.restore();\
  7979.   };\
  7980.  }\
  7981. }\
  7982. else\
  7983. {\
  7984.  var corr;var num;var flipflop = 0;var off = ybase1;\
  7985.  var prec = parseInt(Math.log(precision)/Math.log(10));\
  7986.  for(var p = x0 ; p < x1+xmajor ; p = p+xmajor){\
  7987.   num = (px2x(p)).toFixed(prec);\
  7988.   corr = ctx.measureText(num).width;\
  7989.   if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\
  7990.   ctx.fillText(num,parseInt(p - 0.5*corr),off);\
  7991.  };\
  7992. };\
  7993. };",canvas_root_id);
  7994.     break;
  7995.     case DRAW_GRID:/* not used for userdraw */
  7996. fprintf(js_include_file,"\n<!-- draw grid -->\n\
  7997. 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){\
  7998. 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);};\
  7999. var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
  8000. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  8001. ctx.save();\
  8002. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  8003. if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
  8004. var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8005. ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
  8006. var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
  8007. ctx.font = font_family;\
  8008. var barcolor = new Array();\
  8009. var xstep = xsize*xmajor/(xmax - xmin);\
  8010. var ystep = ysize*ymajor/(ymax - ymin);\
  8011. var x2step = xstep / xminor;\
  8012. var y2step = ystep / yminor;\
  8013. var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
  8014. if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
  8015. if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
  8016. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  8017. ctx.beginPath();\
  8018. ctx.lineWidth = line_width;\
  8019. ctx.strokeStyle = stroke_color;\
  8020. for(var p = zero_x ; p < xsize; p = p + xstep){\
  8021. ctx.moveTo(p,0);\
  8022. ctx.lineTo(p,ysize);\
  8023. };\
  8024. for(var p = zero_x ; p > 0; p = p - xstep){\
  8025. ctx.moveTo(p,0);\
  8026. ctx.lineTo(p,ysize);\
  8027. };\
  8028. for(var p = zero_y ; p < ysize; p = p + ystep){\
  8029. ctx.moveTo(0,p);\
  8030. ctx.lineTo(xsize,p);\
  8031. };\
  8032. for(var p = zero_y ; p > 0; p = p - ystep){\
  8033. ctx.moveTo(0,p);\
  8034. ctx.lineTo(xsize,p);\
  8035. };\
  8036. if( typeof(xaxislabel) !== 'undefined' ){\
  8037. ctx.save();\
  8038. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  8039. var corr =  parseInt(1.1*ctx.measureText(xaxislabel).width);\
  8040. ctx.fillText(xaxislabel,xsize - corr,zero_y - tics_length - 0.4*font_size);\
  8041. ctx.restore();\
  8042. };\
  8043. if( typeof(yaxislabel) !== 'undefined' ){\
  8044. ctx.save();\
  8045. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  8046. var corr = parseInt(ctx.measureText(yaxislabel).width + font_size);\
  8047. ctx.translate(zero_x+tics_length + font_size,corr);\
  8048. ctx.rotate(-0.5*Math.PI);\
  8049. ctx.fillText(yaxislabel,0,0);\
  8050. ctx.restore();\
  8051. };\
  8052. ctx.stroke();\
  8053. ctx.closePath();\
  8054. if( use_axis == 1 ){\
  8055. ctx.save();\
  8056. ctx.beginPath();\
  8057. ctx.strokeStyle = stroke_color;\
  8058. ctx.lineWidth = 0.6*line_width;\
  8059. for(var p = zero_x ; p < xsize; p = p + x2step){\
  8060.  ctx.moveTo(p,0);\
  8061.  ctx.lineTo(p,ysize);\
  8062. };\
  8063. for(var p = zero_x ; p > 0; p = p - x2step){\
  8064.  ctx.moveTo(p,0);\
  8065.  ctx.lineTo(p,ysize);\
  8066. };\
  8067. for(var p = zero_y ; p < ysize; p = p + y2step){\
  8068.  ctx.moveTo(0,p);\
  8069.  ctx.lineTo(xsize,p);\
  8070. };\
  8071. for(var p = zero_y ; p > 0; p = p - y2step){\
  8072.  ctx.moveTo(0,p);\
  8073.  ctx.lineTo(xsize,p);\
  8074. };\
  8075. ctx.stroke();\
  8076. ctx.closePath();\
  8077. ctx.beginPath();\
  8078. ctx.lineWidth = 2*line_width;\
  8079. ctx.strokeStyle = axis_color;\
  8080. ctx.moveTo(0,zero_y);\
  8081. ctx.lineTo(xsize,zero_y);\
  8082. ctx.moveTo(zero_x,0);\
  8083. ctx.lineTo(zero_x,ysize);\
  8084. ctx.stroke();\
  8085. ctx.closePath();\
  8086. ctx.lineWidth = line_width+0.5;\
  8087. ctx.beginPath();\
  8088. for(var p = zero_x ; p < xsize; p = p + xstep){\
  8089.  ctx.moveTo(p,zero_y-tics_length);\
  8090.  ctx.lineTo(p,zero_y+tics_length);\
  8091. };\
  8092. for(var p = zero_x ; p > 0; p = p - xstep){\
  8093.  ctx.moveTo(p,zero_y-tics_length);\
  8094.  ctx.lineTo(p,zero_y+tics_length);\
  8095. };\
  8096. for(var p = zero_y ; p < ysize; p = p + ystep){\
  8097.  ctx.moveTo(zero_x-tics_length,p);\
  8098.  ctx.lineTo(zero_x+tics_length,p);\
  8099. };\
  8100. for(var p = zero_y ; p > 0; p = p - ystep){\
  8101.  ctx.moveTo(zero_x-tics_length,p);\
  8102.  ctx.lineTo(zero_x+tics_length,p);\
  8103. };\
  8104. for(var p = zero_x ; p < xsize; p = p + x2step){\
  8105.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  8106.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  8107. };\
  8108. for(var p = zero_x ; p > 0; p = p - x2step){\
  8109.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  8110.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  8111. };\
  8112. for(var p = zero_y ; p < ysize; p = p + y2step){\
  8113.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  8114.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  8115. };\
  8116. for(var p = zero_y ; p > 0; p = p - y2step){\
  8117.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  8118.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  8119. };\
  8120. ctx.stroke();\
  8121. ctx.closePath();\
  8122. ctx.restore();\
  8123. };\
  8124. if( use_axis_numbering != -1 ){\
  8125. ctx.save();\
  8126. ctx.fillColor = axis_color;\
  8127. ctx.strokeStyle = axis_color;\
  8128. ctx.lineWidth = 2*line_width;\
  8129. ctx.font = font_family;\
  8130. var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
  8131. if( x_strings[use_axis_numbering] != null ){\
  8132.  var str = x_strings[use_axis_numbering];\
  8133.  var len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  8134.  ctx.beginPath();\
  8135.  if( x_strings_up[use_axis_numbering] == null){\
  8136.   for(var p = 0 ; p < len ; p = p+2){\
  8137.    var x_nums = x2px(eval(str[p]));\
  8138.    var x_text = str[p+1];\
  8139.    corr = ctx.measureText(x_text).width;\
  8140.    skip = 1.2*corr/xstep;\
  8141.    if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
  8142.    if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
  8143.    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
  8144.    ctx.moveTo(x_nums,zero_y - tics_length);\
  8145.    ctx.lineTo(x_nums,zero_y + tics_length);\
  8146.   };\
  8147.  }\
  8148.  else\
  8149.  {\
  8150.   for(var p = 0 ; p < len ; p = p+2){\
  8151.    var x_nums = x2px(eval(str[p]));\
  8152.    var x_text = str[p+1];\
  8153.    corr = 2 + tics_length + zero_y + ctx.measureText(x_text).width;\
  8154.    if( corr > ysize ){corr = ysize;};\
  8155.    ctx.save();\
  8156.    ctx.translate(x_nums+0.25*font_size, corr);\
  8157.    ctx.rotate(-1.5708);\
  8158.    ctx.fillText(x_text,0,0);\
  8159.    ctx.restore();\
  8160.    ctx.moveTo(x_nums,zero_y - tics_length);\
  8161.    ctx.lineTo(x_nums,zero_y + tics_length);\
  8162.   };\
  8163.  };\
  8164.  ctx.closePath();\
  8165. }\
  8166. else\
  8167. {\
  8168.  skip = 1;cnt = px2x(zero_x);\
  8169.  prec = Math.log(precision)/(Math.log(10));\
  8170.  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
  8171.  for( var p = zero_x ; p < xsize ; p = p+xstep){\
  8172.   if(skip == 0 ){\
  8173.    disp_cnt = cnt.toFixed(prec);\
  8174.    corr = ctx.measureText(disp_cnt).width;\
  8175.    skip = parseInt(1.2*corr/xstep);\
  8176.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  8177.   }\
  8178.   else\
  8179.   {\
  8180.    skip--;\
  8181.   };\
  8182.   cnt = cnt + xmajor;\
  8183.  };\
  8184.  cnt = px2x(zero_x);skip = 1;\
  8185.  for( var p = zero_x ; p > 0 ; p = p-xstep){\
  8186.   if(skip == 0 ){\
  8187.    disp_cnt = cnt.toFixed(prec);\
  8188.    corr = ctx.measureText(disp_cnt).width;\
  8189.    skip = parseInt(1.2*corr/xstep);\
  8190.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  8191.   }\
  8192.   else\
  8193.   {\
  8194.    skip--;\
  8195.   };\
  8196.   cnt = cnt - xmajor;\
  8197.  };\
  8198. };\
  8199. if( y_strings != null ){\
  8200.  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
  8201.  ctx.beginPath();\
  8202.  for(var p = 0 ; p < len ; p = p+2){\
  8203.   var y_nums = y2px(eval(y_strings[p]));\
  8204.   var y_text = y_strings[p+1];\
  8205.   corr = 2 + tics_length + ctx.measureText(y_text).width;\
  8206.   if( corr > zero_x){corr = parseInt(zero_x+2); }\
  8207.   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
  8208.   ctx.moveTo(zero_x - tics_length,y_nums);\
  8209.   ctx.lineTo(zero_x + tics_length,y_nums);\
  8210.  };\
  8211.  ctx.closePath();\
  8212. }\
  8213. else\
  8214. {\
  8215.  if(f_x == 1){ corr = 1.5*tics_length; }\
  8216.  cnt = px2y(zero_y);skip = 1;\
  8217.  for( var p = zero_y ; p < ysize ; p = p+ystep){\
  8218.   if(skip == 0 ){\
  8219.    skip = parseInt(1.4*font_size/ystep);\
  8220.    disp_cnt = cnt.toFixed(prec);\
  8221.    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  8222.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  8223.   }\
  8224.   else\
  8225.   {\
  8226.    skip--;\
  8227.   };\
  8228.   cnt = cnt - ymajor;\
  8229.  };\
  8230.  corr = 0;cnt = px2y(zero_y);skip = 1;\
  8231.  if(f_x == 1){ corr = 1.5*tics_length; }\
  8232.  for( var p = zero_y ; p > 0 ; p = p-ystep){\
  8233.   if(skip == 0 ){\
  8234.    skip = parseInt(1.4*font_size/ystep);\
  8235.    disp_cnt = cnt.toFixed(prec);\
  8236.    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  8237.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  8238.   }\
  8239.   else\
  8240.   {\
  8241.    skip--;\
  8242.   };\
  8243.   cnt = cnt + ymajor;\
  8244.  };\
  8245. };\
  8246. ctx.stroke();\
  8247. ctx.restore();\
  8248. };\
  8249. if( typeof(legend0)  !== 'undefined' ){\
  8250. ctx.save();\
  8251. ctx.globalAlpha = 1.0;\
  8252. ctx.font = \"bold \"+font_size+\"px Ariel\";\
  8253. var y_offset = 2*font_size;\
  8254. var txt;var txt_size;\
  8255. var x_offset = xsize - 2*font_size;\
  8256. var l_length = legend0.length;\
  8257. if( typeof(legendcolors0) !== 'undefined' ){\
  8258.  for(var p = 0 ; p < l_length ; p++){\
  8259.    barcolor[p] = legendcolors0[p];\
  8260.  };\
  8261. }\
  8262. else\
  8263. {\
  8264.  if( barcolor.length == 0 ){\
  8265.   for(var p = 0 ; p < l_length ; p++){\
  8266.    barcolor[p] = stroke_color;\
  8267.   };\
  8268.  };\
  8269. };\
  8270. for(var p = 0; p < l_length; p++){\
  8271.  ctx.fillStyle = barcolor[p];\
  8272.  txt = legend0[p];\
  8273.  txt_size = ctx.measureText(txt).width;\
  8274.  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
  8275.  y_offset = parseInt(y_offset + 1.5*font_size);\
  8276. };\
  8277. ctx.restore();\
  8278. };\
  8279. if( typeof(barchart_0)  !== 'undefined' ){\
  8280. ctx.save();\
  8281. var num_barcharts = 0;\
  8282. var bar_name = eval('barchart_0');\
  8283. while( typeof(bar_name) !== 'undefined' ){\
  8284.    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
  8285. };\
  8286. var bar_width = parseInt(0.8*x2step/(num_barcharts));\
  8287. for(var i=0 ; i< num_barcharts ; i++){\
  8288.  bar_name = eval('barchart_'+i);\
  8289.  var bar_x = new Array();\
  8290.  var bar_y = new Array();\
  8291.  var lb = bar_name.length;\
  8292.  var idx = 0;\
  8293.  var dx = parseInt(0.5*i*bar_width);\
  8294.  for( var p = 0 ; p < lb ; p = p + 3 ){\
  8295.   bar_x[idx] = x2px(bar_name[p]);\
  8296.   bar_y[idx] = y2px(bar_name[p+1]);\
  8297.   barcolor[idx] = bar_name[p+2];\
  8298.   idx++;\
  8299.  };\
  8300.  ctx.globalAlpha = fill_opacity;\
  8301.  for( var p = 0; p < idx ; p++ ){\
  8302.   ctx.beginPath();\
  8303.   ctx.strokeStyle = barcolor[p];\
  8304.   ctx.fillStyle = barcolor[p];\
  8305.   ctx.rect(bar_x[p]-0.4*x2step+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
  8306.   ctx.fill();\
  8307.   ctx.stroke();\
  8308.   ctx.closePath();\
  8309.  };\
  8310. };\
  8311. ctx.restore();\
  8312. };\
  8313. if( typeof(linegraph_0) !== 'undefined' ){\
  8314. ctx.save();\
  8315. ctx.globalAlpha = 1.0;\
  8316. var i = 0;\
  8317. var line_name = eval('linegraph_'+i);\
  8318. while ( typeof(line_name) !== 'undefined' ){\
  8319.  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
  8320.  ctx.lineWidth = parseInt(line_name[1]);\
  8321.  if(line_name[2] == \"1\"){\
  8322.   var d1 = parseInt(line_name[3]);\
  8323.   var d2 = parseInt(line_name[4]);\
  8324.   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
  8325.  }\
  8326.  else\
  8327.  {\
  8328.  if(ctx.setLineDash){ctx.setLineDash = null;}\
  8329.  if(ctx.mozDash){ctx.mozDash = null;}\
  8330.  };\
  8331.  var data_x = new Array();\
  8332.  var data_y = new Array();\
  8333.  var lb = line_name.length;\
  8334.  var idx = 0;\
  8335.  for( var p = 5 ; p < lb ; p = p + 2 ){\
  8336.   data_x[idx] = x2px(line_name[p]);\
  8337.   data_y[idx] = y2px(line_name[p+1]);\
  8338.   idx++;\
  8339.  };\
  8340.  for( var p = 0; p < idx ; p++){\
  8341.   ctx.beginPath();\
  8342.   ctx.moveTo(data_x[p],data_y[p]);\
  8343.   ctx.lineTo(data_x[p+1],data_y[p+1]);\
  8344.   ctx.stroke();\
  8345.   ctx.closePath();\
  8346.  };\
  8347.  i++;\
  8348.  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
  8349. };\
  8350. ctx.restore();\
  8351. };\
  8352. return;\
  8353. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  8354.     break;
  8355.  
  8356.     case DRAW_PIECHART:
  8357. fprintf(js_include_file,"\n<!-- draw piecharts -->\n\
  8358. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  8359. function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family,use_filled,use_offset){\
  8360. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8361.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8362. }\
  8363. else\
  8364. {\
  8365.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8366. };\
  8367. var center_text = use_offset || 0;\
  8368. var ld = data_color_list.length;\
  8369. var sum = 0;\
  8370. var idx = 0;\
  8371. var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
  8372. var colors = new Array();\
  8373. var data = new Array();\
  8374. for(var p = 0;p < ld; p = p + 2){\
  8375.  data[idx] = parseFloat(data_color_list[p]);\
  8376.  sum = sum + data[idx];\
  8377.  colors[idx] = data_color_list[p+1];\
  8378.  idx++;\
  8379. };\
  8380. if( use_filled > 1 ){\
  8381.  var i = 2;\
  8382.  for(var p = 0 ;  p < idx ; p++){\
  8383.   if(i > 5 ){ i = 2; };\
  8384.   var pat = create_Pattern(0,0,i,colors[p]); all_fill_patterns[p] = pat;i++;\
  8385.  };\
  8386. };\
  8387. var ctx = obj.getContext(\"2d\");\
  8388. ctx.save();\
  8389. var angle;\
  8390. var angle_end = 0;\
  8391. var offset = Math.PI / 2;\
  8392. ctx.globalAlpha = fill_opacity;\
  8393. var angles = [];\
  8394. for(var p=0; p < idx; p++){\
  8395.  ctx.beginPath();\
  8396.  ctx.moveTo(x_center,y_center);\
  8397.  angle = Math.PI * (2 * data[p] / sum);\
  8398.  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
  8399.  ctx.lineTo(x_center, y_center);\
  8400.  if( use_filled > 1 ){ ctx.fillStyle = all_fill_patterns[p]; }else{ ctx.fillStyle = colors[p];};\
  8401.  ctx.fill();\
  8402.  ctx.closePath();\
  8403.  angles.push(angle_end + angle - offset);\
  8404.  angle_end  = angle_end + angle;\
  8405. };\
  8406. if(typeof(legend0) !== 'undefined'){\
  8407.  var legenda = eval(\"legend\"+legend_cnt);\
  8408.  ctx.globalAlpha = 1.0;\
  8409.  ctx.font = font_family;\
  8410.  var y_offset = font_size;\
  8411.  var x_offset = 0;\
  8412.  var txt;var txt_size;\
  8413.  for(var p = 0; p < idx; p++){\
  8414.   ctx.fillStyle = colors[p];\
  8415.   txt = legenda[p];\
  8416.   txt_size = ctx.measureText(txt).width + 2;\
  8417.   if(center_text == 4){\
  8418.    ctx.save();\
  8419.    ctx.translate(x_center, y_center);\
  8420.    ctx.rotate(angles[p]);\
  8421.    ctx.fillText(txt,radius-txt_size,0);\
  8422.    ctx.restore();\
  8423.   }\
  8424.   else\
  8425.   {\
  8426.    if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
  8427.    ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
  8428.    y_offset = parseInt(y_offset + 1.5*font_size);\
  8429.   };\
  8430.  };\
  8431. };\
  8432. ctx.restore();\
  8433. };",canvas_root_id,canvas_root_id,canvas_root_id);
  8434.     break;
  8435.     case DRAW_JSBOXPLOT:
  8436. fprintf(js_include_file,"\n<!-- draw jsboxplots -->\n\
  8437. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  8438. function statistics(data){\
  8439. var len = data.length;\
  8440. var min = 10000000;\
  8441. var max = -10000000;\
  8442. var sum = 0;var d;\
  8443. for(var i=0;i<len;i++){\
  8444.  d = data[i];\
  8445.  if(d < min){min = d;}else{if(d > max){max = d;};};\
  8446.  sum+= parseFloat(data[i]);\
  8447. };\
  8448. var mean = parseFloat(sum/len);\
  8449. var variance = 0;\
  8450. for(var i=0;i<len;i++){\
  8451.  d = data[i];\
  8452.  variance += (d - mean)*(d - mean);\
  8453. };\
  8454. variance = parseFloat(variance / len);\
  8455. var std = Math.sqrt(variance);\
  8456. data.sort(function(a,b){return a - b;});\
  8457. var median;var Q1;var Q3;\
  8458. var half = Math.floor(0.5*len);\
  8459. var q1 = Math.floor(0.25*len);\
  8460. var q3 = Math.floor(0.75*len);\
  8461. var half = Math.floor(0.5*len);\
  8462. if(len %%2 == 1){\
  8463.  median = data[half];\
  8464.  Q1 = data[q1];\
  8465.  Q3 = data[q3];\
  8466. }\
  8467. else\
  8468. {\
  8469.  median = (data[half - 1] + data[half] )/2;\
  8470.  Q1 = (data[q1 - 1] + data[q1] )/2;\
  8471.  Q3 = (data[q3 - 1] + data[q3] )/2;\
  8472. };\
  8473. return [min,Q1,median,Q3,max];\
  8474. };");
  8475.     break;
  8476.     case DRAW_BOXPLOT:
  8477. fprintf(js_include_file,"\n<!-- draw boxplots -->\n\
  8478. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  8479. draw_boxplot = function(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1){\
  8480. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8481.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8482. }\
  8483. else\
  8484. {\
  8485.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8486. };\
  8487. var ctx = obj.getContext(\"2d\");\
  8488. ctx.clearRect(0,0,xsize,ysize);\
  8489. ctx.save();\
  8490. ctx.lineWidth = line_width;\
  8491. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  8492. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8493. var colors = new Array(2);\
  8494. colors[0] = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  8495. colors[1] = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8496. if( use_filled > 1 ){\
  8497.   var pat = create_Pattern(0,0,3,colors[0]);\
  8498.   all_fill_patterns[0] = pat;\
  8499.   pat = create_Pattern(0,0,4,colors[1]);\
  8500.   all_fill_patterns[1] = pat;\
  8501. };\
  8502. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  8503. var hh = 0.25*hw;\
  8504. switch(boxplot_source){\
  8505.  case 1: if( typeof(jsboxplot_data) === 'undefined'){return;};data = statistics(jsboxplot_data);break;\
  8506.  case 2: if( typeof(student_boxplot_data) === 'undefined'){return;};data = statistics(student_boxplot_data);break;\
  8507.  case 3: if( typeof(student_boxplot) === 'undefined'){return;};data = student_boxplot;break;\
  8508.  default: break;\
  8509. };\
  8510. var min,Q1,median,Q3,max;\
  8511. if(xy == 1 ){\
  8512.  min=x2px(data[0]);Q1=x2px(data[1]);median=x2px(data[2]);Q3=x2px(data[3]);max=x2px(data[4]);\
  8513.  hh = Math.abs(y2px(hh) - y2px(ystart));\
  8514.  hw = Math.abs(y2px(hw) - y2px(ystart));\
  8515.  cxy = y2px(cxy);\
  8516.  ctx.beginPath();\
  8517.  ctx.moveTo(min,cxy);\
  8518.  ctx.lineTo(Q1,cxy);\
  8519.  ctx.moveTo(Q3,cxy);\
  8520.  ctx.lineTo(max,cxy);\
  8521.  ctx.moveTo(min,cxy+hh);\
  8522.  ctx.lineTo(min,cxy-hh);\
  8523.  ctx.moveTo(max,cxy+hh);\
  8524.  ctx.lineTo(max,cxy-hh);\
  8525.  ctx.closePath();\
  8526.  ctx.stroke();\
  8527.  ctx.beginPath();\
  8528.  ctx.rect(Q1,cxy-2*hh,median-Q1,hw);\
  8529.  ctx.closePath();\
  8530.  if( use_filled != 0 ){\
  8531.   if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\
  8532.   ctx.fill();\
  8533.  };\
  8534.  ctx.stroke();\
  8535.  ctx.beginPath();\
  8536.  ctx.rect(median,cxy-2*hh,Q3-median,hw);\
  8537.  ctx.closePath();\
  8538.  if( use_filled != 0 ){\
  8539.   if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\
  8540.   ctx.fill();\
  8541.  };\
  8542.  ctx.stroke();\
  8543. }else{\
  8544.  min=y2px(data[0]);Q1=y2px(data[1]);median=y2px(data[2]);Q3=y2px(data[3]);max=y2px(data[4]);\
  8545.  hh = Math.abs(x2px(hh) - x2px(xstart));\
  8546.  hw = Math.abs(x2px(hw) - x2px(xstart));\
  8547.  cxy = x2px(cxy);\
  8548.  ctx.beginPath();\
  8549.  ctx.moveTo(cxy,min);\
  8550.  ctx.lineTo(cxy,Q1);\
  8551.  ctx.moveTo(cxy,Q3);\
  8552.  ctx.lineTo(cxy,max);\
  8553.  ctx.moveTo(cxy + hh,min);\
  8554.  ctx.lineTo(cxy - hh,min);\
  8555.  ctx.moveTo(cxy + hh,max);\
  8556.  ctx.lineTo(cxy - hh,max);\
  8557.  ctx.closePath;\
  8558.  ctx.stroke();\
  8559.  ctx.beginPath();\
  8560.  ctx.rect(cxy - 2*hh,Q1,hw,median - Q1);\
  8561.  ctx.closePath();\
  8562.  if( use_filled != 0 ){\
  8563.   if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\
  8564.   ctx.fill();\
  8565.  };\
  8566.  ctx.stroke();\
  8567.  ctx.beginPath();\
  8568.  ctx.rect(cxy - 2*hh,median,hw,Q3 - median);\
  8569.  ctx.closePath();\
  8570.  if( use_filled != 0 ){\
  8571.   if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\
  8572.   ctx.fill();\
  8573.  };\
  8574.  ctx.stroke();\
  8575. };\
  8576. ctx.restore();};",canvas_root_id,canvas_root_id,canvas_root_id);
  8577.     break;
  8578.     case DRAW_ARCS:
  8579. fprintf(js_include_file,"\n<!-- draw arcs -->\n\
  8580. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  8581. 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){\
  8582. ctx.save();\
  8583. if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  8584. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  8585. if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  8586. if(end < start){var tmp = end;end = start;start=tmp;};\
  8587. start = 360 - start;\
  8588. end = 360 - end;\
  8589. ctx.lineWidth = line_width;\
  8590. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  8591. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8592. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  8593. if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
  8594. ctx.beginPath();\
  8595. ctx.moveTo(xc,yc);\
  8596. ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  8597. ctx.lineTo(xc,yc);\
  8598. ctx.closePath();\
  8599. if( use_filled != 0 ){ctx.fill();};\
  8600. ctx.stroke();\
  8601. ctx.restore();\
  8602. };");
  8603.  
  8604.     break;
  8605.     case DRAW_CENTERSTRING:
  8606. fprintf(js_include_file,"\n<!-- draw centerstring -->\n\
  8607. var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
  8608. var obj;\
  8609. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8610.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8611. }\
  8612. else\
  8613. {\
  8614.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8615. };\
  8616. var ctx = obj.getContext(\"2d\");\
  8617. ctx.save();\
  8618. ctx.clearRect(0,0,xsize,ysize);\
  8619. ctx.font = font_family;\
  8620. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8621. var stringwidth = ctx.measureText(text).width;\
  8622. var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
  8623. ctx.fillText(text,x,y2px(y));\
  8624. ctx.restore();\
  8625. return;\
  8626. };",canvas_root_id,canvas_root_id,canvas_root_id);
  8627.     break;
  8628.     case DRAW_TEXTS:
  8629. fprintf(js_include_file,"\n<!-- draw text -->\n\
  8630. 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,use_offset){\
  8631. var obj;\
  8632. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8633.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8634. }\
  8635. else\
  8636. {\
  8637.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8638. };\
  8639. var ctx = obj.getContext(\"2d\");\
  8640. if( font_family != 'null' ){\
  8641.  ctx.font = font_family;\
  8642. }\
  8643. else\
  8644. {\
  8645.  ctx.font = font_size+'px Ariel';\
  8646. };\
  8647. if( use_offset == 3 ){if(angle2 < 0 ){ y = y + 0.8*font_size; x = x + (Math.cos(angle2))*font_size; }else{y = y - 0.8*font_size; x = x + (Math.sin(angle2))*font_size;};};\
  8648. if(angle2 == 0 && angle != 0){\
  8649.  ctx.save();\
  8650.  if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  8651.  if(use_rotate == 1 ){\
  8652.  ctx.rotate(angle*Math.PI/180);};\
  8653.  ctx.restore();\
  8654. };\
  8655. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8656. if(angle2 != 0){\
  8657.  ctx.save();\
  8658.  ctx.translate(x,y);\
  8659.  ctx.rotate((360-angle2)*(Math.PI / 180));\
  8660.  ctx.fillText(text,0,0);\
  8661.  ctx.restore();\
  8662. }\
  8663. else\
  8664. {\
  8665.  ctx.fillText(text,x,y);\
  8666. };\
  8667. return;\
  8668. };",canvas_root_id,canvas_root_id,canvas_root_id);
  8669.     break;
  8670.     case DRAW_CURVE:
  8671. fprintf(js_include_file,"\n<!-- draw curve -->\n\
  8672. 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){\
  8673. var obj;\
  8674. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8675.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8676. }\
  8677. else\
  8678. {\
  8679.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8680. };\
  8681. var ctx = obj.getContext(\"2d\");\
  8682. ctx.save();\
  8683. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  8684. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  8685. ctx.beginPath();ctx.lineWidth = line_width;\
  8686. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  8687. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  8688. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8689. ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
  8690. for(var p = 1 ; p < x_points.length ; p++){\
  8691.  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
  8692.  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
  8693.  }\
  8694.  else\
  8695.  {\
  8696.   ctx.stroke();\
  8697.   ctx.beginPath();\
  8698.   p++;\
  8699.   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
  8700.  };\
  8701. };\
  8702. ctx.stroke();\
  8703. ctx.restore();\
  8704. };",canvas_root_id,canvas_root_id,canvas_root_id);
  8705.     break;
  8706.  
  8707.     case DRAW_INPUTS:
  8708. fprintf(js_include_file,"\n<!-- draw input fields -->\n\
  8709. var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value,use_offset){\
  8710. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  8711. var input = document.createElement(\"input\");\
  8712. input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  8713. input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  8714. input.setAttribute(\"size\",size);\
  8715. input.setAttribute(\"value\",value);\
  8716. if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
  8717. canvas_div.appendChild(input);\
  8718. if(use_offset != 0 ){ center_input('canvas_input'+input_cnt,x,y,style);};\
  8719. };\
  8720. function center_input(id,x,y,style){\
  8721. var inp = document.getElementById(id);\
  8722. var pos = inp.getBoundingClientRect();\
  8723. var center_x = parseInt(x - 0.5*(pos.width));\
  8724. var center_y = parseInt(y - 0.5*(pos.height));\
  8725. try{ inp.setAttribute(\"style\",\"position:absolute;left:\"+center_x+\"px;top:\"+center_y+\"px;\"+style );}\
  8726. catch(e){return;};\
  8727. };");
  8728.     break;
  8729.  
  8730.     case DRAW_TEXTAREAS:
  8731. fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
  8732. var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
  8733. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  8734. var textarea = document.createElement(\"textarea\");\
  8735. textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  8736. textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  8737. textarea.setAttribute(\"cols\",cols);\
  8738. textarea.setAttribute(\"rows\",rows);\
  8739. textarea.value = value;\
  8740. if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
  8741. canvas_div.appendChild(textarea);};");
  8742.     break;
  8743.  
  8744. case DRAW_PIXELS:
  8745. fprintf(js_include_file,"\n<!-- draw pixel -->\n\
  8746. var draw_setpixel = function(x,y,color,opacity,pixelsize){\
  8747. var idx = 2000+Math.ceil(1000*(Math.random()));\
  8748. var canvas = create_canvas%d(idx,xsize,ysize);\
  8749. var d = 0.5*pixelsize;\
  8750. var ctx = canvas.getContext(\"2d\");\
  8751. if(pixelsize%%2 == 1){ ctx.translate(0.5,0.5);};\
  8752. ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
  8753. ctx.clearRect(0,0,xsize,ysize);\
  8754. for(var p=0; p<x.length;p++){\
  8755.  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
  8756. };\
  8757. ctx.fill();ctx.stroke();\
  8758. };",canvas_root_id);
  8759. break;
  8760.  
  8761. case DRAW_CLOCK:
  8762. fprintf(js_include_file,"\n<!-- begin command clock -->\n\
  8763. var clock_canvas = create_canvas%d(%d,xsize,ysize);\
  8764. var clock_ctx = clock_canvas.getContext(\"2d\");\
  8765. var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
  8766. clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\
  8767. clock_ctx.save();\
  8768. clock_ctx.globalAlpha = clock_bg_opacity;\
  8769. this.type = type || 0;\
  8770. this.interaction = interaction || 0;\
  8771. this.H = H;\
  8772. this.M = M;\
  8773. this.S = S;\
  8774. this.xc = xc || xsize/2;\
  8775. this.yc = yc || ysize/2;\
  8776. this.radius = radius || xsize/4;\
  8777. var font_size = parseInt(0.2*this.radius);\
  8778. this.H_color = h_color || \"black\";\
  8779. this.M_color = m_color || \"black\";\
  8780. this.S_color = s_color || \"black\";\
  8781. this.fg_color = fg_color || \"black\";\
  8782. this.bg_color = bg_color || \"white\";\
  8783. clock_ctx.translate(this.xc,this.yc);\
  8784. clock_ctx.beginPath();\
  8785. clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
  8786. clock_ctx.fillStyle = this.bg_color;\
  8787. clock_ctx.fill();\
  8788. clock_ctx.closePath();\
  8789. clock_ctx.beginPath();\
  8790. clock_ctx.font = font_size+\"px Arial\";\
  8791. clock_ctx.fillStyle = this.fg_color;\
  8792. clock_ctx.textAlign = \"center\";\
  8793. clock_ctx.textBaseline = 'middle';\
  8794. var angle;var x1,y1,x2,y2;\
  8795. var angle_cos;var angle_sin;\
  8796. clock_ctx.globalAlpha = clock_fg_opacity;\
  8797. switch(type){\
  8798. case 0:clock_ctx.beginPath();\
  8799. for(var p = 1; p <= 12 ; p++){\
  8800.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  8801.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  8802.  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  8803.  clock_ctx.moveTo(x1,y1);\
  8804.  clock_ctx.lineTo(x2,y2);\
  8805. };\
  8806. for(var p = 1; p <= 60 ; p++){\
  8807.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  8808.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  8809.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  8810.  clock_ctx.moveTo(x1,y1);\
  8811.  clock_ctx.lineTo(x2,y2);\
  8812. };\
  8813. clock_ctx.closePath();\
  8814. clock_ctx.stroke();\
  8815. break;\
  8816. case 1:\
  8817. 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;\
  8818. case 2:\
  8819. 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);};\
  8820. clock_ctx.beginPath();\
  8821. for(var p = 1; p <= 12 ; p++){\
  8822.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  8823.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  8824.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  8825.  clock_ctx.moveTo(x1,y1);\
  8826.  clock_ctx.lineTo(x2,y2);\
  8827. };\
  8828. for(var p = 1; p <= 60 ; p++){\
  8829.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  8830.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  8831.  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  8832.  clock_ctx.moveTo(x1,y1);\
  8833.  clock_ctx.lineTo(x2,y2);\
  8834. };\
  8835. clock_ctx.closePath();\
  8836. clock_ctx.stroke();\
  8837. break;\
  8838. };\
  8839. angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
  8840. clock_ctx.rotate(angle);\
  8841. clock_ctx.beginPath();\
  8842. clock_ctx.moveTo(-3, -2);\
  8843. clock_ctx.lineTo(-3, 2);\
  8844. clock_ctx.lineTo(this.radius * 0.6, 1);\
  8845. clock_ctx.lineTo(this.radius  * 0.6, -1);\
  8846. clock_ctx.fillStyle = this.H_color;\
  8847. clock_ctx.fill();\
  8848. clock_ctx.rotate(-angle);\
  8849. angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
  8850. clock_ctx.rotate(angle);\
  8851. clock_ctx.beginPath();\
  8852. clock_ctx.moveTo(-3, -2);\
  8853. clock_ctx.lineTo(-3, 2);\
  8854. clock_ctx.lineTo(this.radius  * 0.8, 1);\
  8855. clock_ctx.lineTo(this.radius  * 0.8, -1);\
  8856. clock_ctx.fillStyle = this.M_color;\
  8857. clock_ctx.fill();\
  8858. clock_ctx.rotate(-angle);\
  8859. angle = (this.S - 15) * 2 * Math.PI / 60;\
  8860. clock_ctx.rotate(angle);\
  8861. clock_ctx.beginPath();\
  8862. clock_ctx.moveTo(0,0);\
  8863. clock_ctx.lineTo(this.radius  * 0.9, 1);\
  8864. clock_ctx.lineTo(this.radius  * 0.9, -1);\
  8865. clock_ctx.strokeStyle = this.S_color;\
  8866. clock_ctx.stroke();\
  8867. clock_ctx.restore();\
  8868. };",canvas_root_id,CLOCK_CANVAS);
  8869. break;
  8870.  
  8871. case DRAW_LATTICE:
  8872. fprintf(js_include_file,"\n<!-- draw lattice -->\n\
  8873. 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,use_filled){\
  8874. var obj;\
  8875. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8876.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8877. }\
  8878. else\
  8879. {\
  8880.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8881. };\
  8882. var ctx = obj.getContext(\"2d\");\
  8883. ctx.save();\
  8884. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  8885. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  8886. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  8887. if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
  8888. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8889. var radius = line_width;\
  8890. var x = 0;\
  8891. var y = 0;\
  8892. var x_step_px = xsize/(xmax-xmin);\
  8893. var y_step_px = ysize/(ymax-ymin);\
  8894. var xv1 = dx1*x_step_px;\
  8895. var yv1 = dy1*y_step_px;\
  8896. var xv2 = dx2*x_step_px;\
  8897. var yv2 = dy2*y_step_px;\
  8898. for(var p = 0; p < n1 ;p++){\
  8899.  x = p*xv1 + x0;\
  8900.  y = p*yv1 + y0;\
  8901.  for(var c = 0; c < n2 ; c++){\
  8902.   ctx.beginPath();\
  8903.   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
  8904.   ctx.fill();\
  8905.   ctx.stroke();\
  8906.   ctx.closePath();\
  8907.  };\
  8908. };\
  8909. ctx.restore();\
  8910. return;\
  8911. };",canvas_root_id,canvas_root_id,canvas_root_id);
  8912.     break;
  8913. case DRAW_XYLOGSCALE:
  8914. fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\
  8915. 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){\
  8916. var obj;\
  8917. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8918.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8919. }\
  8920. else\
  8921. {\
  8922.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8923. };\
  8924. var ctx = obj.getContext(\"2d\");\
  8925. ctx.clearRect(0,0,xsize,ysize);\
  8926. ctx.save();\
  8927. var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
  8928. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  8929. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  8930. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  8931. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  8932. if(use_axis_numbering != -1){\
  8933.  ctx.font = font_family;\
  8934.  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
  8935.  ymarge = parseInt(1.5*font_size);\
  8936.  ctx.save();\
  8937.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  8938.  ctx.rect(0,0,xmarge,ysize);\
  8939.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  8940.  ctx.fill();\
  8941.  ctx.restore();\
  8942. }else{xmarge = 0;ymarge = 0;};\
  8943. if( typeof(xaxislabel) !== 'undefined' ){\
  8944.  ctx.save();\
  8945.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  8946.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  8947.  corr =  ctx.measureText(xaxislabel).width;\
  8948.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  8949.  ctx.restore();\
  8950. };\
  8951. if( typeof(yaxislabel) !== 'undefined' ){\
  8952.  ctx.save();\
  8953.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  8954.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  8955.  corr = ctx.measureText(yaxislabel).width;\
  8956.  ctx.translate(xmarge+font_size,corr+font_size);\
  8957.  ctx.rotate(-0.5*Math.PI);\
  8958.  ctx.fillText(yaxislabel,0,0);\
  8959.  ctx.restore();\
  8960. };\
  8961. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  8962. ctx.lineWidth = line_width;\
  8963. for(var p = x_min; p <= x_max ; p++){\
  8964.  num = Math.pow(xlogbase,p);\
  8965.  for(var i = 1 ; i < xlogbase ; i++){\
  8966.   x_e = x2px(i*num);\
  8967.   if( i == 1 ){\
  8968.    ctx.lineWidth = line_width;\
  8969.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  8970.    if( use_axis_numbering != -1 && p > x_min){\
  8971.      xtxt = xlogbase+'^'+p.toFixed(0);\
  8972.      corr = 0.5*(ctx.measureText(xtxt).width);\
  8973.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  8974.    };\
  8975.   }else{\
  8976.    ctx.lineWidth = 0.2*line_width;\
  8977.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  8978.   };\
  8979.   if( x_e >= xmarge ){\
  8980.    ctx.beginPath();\
  8981.    ctx.moveTo(x_e,0);\
  8982.    ctx.lineTo(x_e,ysize - ymarge);\
  8983.    ctx.stroke();\
  8984.    ctx.closePath();\
  8985.   };\
  8986.  };\
  8987. };\
  8988. for(var p = y_min; p <= y_max ; p++){\
  8989.  num = Math.pow(ylogbase,p);\
  8990.  for(var i = 1 ; i < ylogbase ; i++){\
  8991.   y_e = y2px(i*num);\
  8992.   if( i == 1 ){\
  8993.    ctx.lineWidth = line_width;\
  8994.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  8995.    if( use_axis_numbering != -1 && p > y_min){\
  8996.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  8997.    };\
  8998.   }else{\
  8999.    ctx.lineWidth = 0.2*line_width;\
  9000.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9001.   };\
  9002.   ctx.beginPath();\
  9003.   ctx.moveTo(xmarge,y_e);\
  9004.   ctx.lineTo(xsize,y_e);\
  9005.   ctx.stroke();\
  9006.   ctx.closePath();\
  9007.  };\
  9008. };\
  9009. ctx.restore();\
  9010. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  9011.     break;
  9012.  
  9013. case DRAW_XLOGSCALE:
  9014. fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\
  9015. 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){\
  9016. var obj;\
  9017. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9018.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9019. }\
  9020. else\
  9021. {\
  9022.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9023. };\
  9024. var ctx = obj.getContext(\"2d\");\
  9025. ctx.clearRect(0,0,xsize,ysize);\
  9026. ctx.save();\
  9027. ctx.lineWidth = line_width;\
  9028. var prec = Math.log(precision)/Math.log(10);\
  9029. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  9030. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  9031. var y_min = 0;var y_max = ysize;var x_e;var corr;\
  9032. var xtxt;var ytxt;var num;var xmarge;var ymarge;\
  9033. if(use_axis_numbering != -1){\
  9034.  ctx.font = font_family;\
  9035.  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
  9036.  ymarge = parseInt(1.5*font_size);\
  9037.  ctx.save();\
  9038.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  9039.  ctx.rect(0,0,xmarge,ysize);\
  9040.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  9041.  ctx.fill();\
  9042.  ctx.restore();\
  9043. }else{xmarge = 0;ymarge = 0;};\
  9044. if( typeof(xaxislabel) !== 'undefined' ){\
  9045.  ctx.save();\
  9046.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  9047.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9048.  corr =  ctx.measureText(xaxislabel).width;\
  9049.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  9050.  ctx.restore();\
  9051. };\
  9052. if( typeof(yaxislabel) !== 'undefined' ){\
  9053.  ctx.save();\
  9054.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  9055.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9056.  corr = ctx.measureText(yaxislabel).width;\
  9057.  ctx.translate(xmarge+font_size,corr+font_size);\
  9058.  ctx.rotate(-0.5*Math.PI);\
  9059.  ctx.fillText(yaxislabel,0,0);\
  9060.  ctx.restore();\
  9061. };\
  9062. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9063. ctx.lineWidth = line_width;\
  9064. for(var p = x_min; p <= x_max ; p++){\
  9065.  num = Math.pow(xlogbase,p);\
  9066.  for(var i = 1 ; i < xlogbase ; i++){\
  9067.   x_e = x2px(i*num);\
  9068.   if( i == 1 ){\
  9069.     ctx.lineWidth = line_width;\
  9070.     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9071.    if( use_axis_numbering != -1 && p > x_min ){\
  9072.      xtxt = xlogbase+'^'+p.toFixed(0);\
  9073.      corr = 0.5*(ctx.measureText(xtxt).width);\
  9074.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  9075.    };\
  9076.   }else{\
  9077.    ctx.lineWidth = 0.2*line_width;\
  9078.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9079.   };\
  9080.   if( x_e >= xmarge ){\
  9081.    ctx.beginPath();\
  9082.    ctx.moveTo(x_e,0);\
  9083.    ctx.lineTo(x_e,ysize - ymarge);\
  9084.    ctx.stroke();\
  9085.    ctx.closePath();\
  9086.   };\
  9087.  };\
  9088. };\
  9089. var stepy = Math.abs(y2px(ymajor) - y2px(0));\
  9090. var minor_step = stepy / yminor;\
  9091. for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
  9092.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9093.  ctx.lineWidth = line_width;\
  9094.  ctx.beginPath();\
  9095.  ctx.moveTo(xmarge,y);\
  9096.  ctx.lineTo(xsize,y);\
  9097.  ctx.stroke();\
  9098.  ctx.closePath();\
  9099.  if( use_axis_numbering != -1){\
  9100.   ytxt = (px2y(y)).toFixed(prec);\
  9101.   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
  9102.  };\
  9103.  for(var dy = 1 ; dy < yminor ; dy++){\
  9104.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9105.   ctx.lineWidth = 0.2*line_width;\
  9106.   ctx.beginPath();\
  9107.   ctx.moveTo(xmarge,y+dy*minor_step);\
  9108.   ctx.lineTo(xsize,y+dy*minor_step);\
  9109.   ctx.stroke();\
  9110.   ctx.closePath();\
  9111.  };\
  9112. };\
  9113. ctx.restore();\
  9114. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  9115.     break;
  9116. case DRAW_YLOGSCALE:
  9117. fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\
  9118. 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){\
  9119. var obj;\
  9120. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9121.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9122. }\
  9123. else\
  9124. {\
  9125.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9126. };\
  9127. var ctx = obj.getContext(\"2d\");\
  9128. ctx.clearRect(0,0,xsize,ysize);\
  9129. ctx.save();\
  9130. ctx.lineWidth = line_width;\
  9131. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  9132. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  9133. var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
  9134. if(use_axis_numbering != -1){\
  9135.  ctx.font = font_family;\
  9136.  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
  9137.  ymarge = 2*font_size;\
  9138.  ctx.save();\
  9139.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  9140.  ctx.rect(0,0,xmarge,ysize);\
  9141.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  9142.  ctx.fill();\
  9143.  ctx.restore();\
  9144. }else{xmarge = 0;ymarge = 0;};\
  9145. if( typeof(xaxislabel) !== 'undefined' ){\
  9146.  ctx.save();\
  9147.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  9148.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9149.  corr =  ctx.measureText(xaxislabel).width;\
  9150.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  9151.  ctx.restore();\
  9152. };\
  9153. if( typeof(yaxislabel) !== 'undefined' ){\
  9154.  ctx.save();\
  9155.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  9156.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9157.  corr = ctx.measureText(yaxislabel).width;\
  9158.  ctx.translate(xmarge+font_size,corr+font_size);\
  9159.  ctx.rotate(-0.5*Math.PI);\
  9160.  ctx.fillText(yaxislabel,0,0);\
  9161.  ctx.restore();\
  9162. };\
  9163. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9164. ctx.lineWidth = line_width;\
  9165. for(var p = y_min; p <= y_max ; p++){\
  9166.  num = Math.pow(ylogbase,p);\
  9167.  for(var i = 1 ; i < ylogbase ; i++){\
  9168.   y_e = y2px(i*num);\
  9169.   if( i == 1 ){\
  9170.    ctx.lineWidth = line_width;\
  9171.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9172.    if( use_axis_numbering != -1 && p > y_min){\
  9173.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  9174.    };\
  9175.   }else{\
  9176.    ctx.lineWidth = 0.2*line_width;\
  9177.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9178.   };\
  9179.   ctx.beginPath();\
  9180.   ctx.moveTo(xmarge,y_e);\
  9181.   ctx.lineTo(xsize,y_e);\
  9182.   ctx.stroke();\
  9183.   ctx.closePath();\
  9184.  };\
  9185. };\
  9186. var stepx = Math.abs(x2px(xmajor) - x2px(0));\
  9187. var minor_step = stepx / xminor;\
  9188. var prec = Math.log(precision)/Math.log(10);\
  9189. var xtxt;var corr;var flip = 0;\
  9190. for(var x = stepx ; x < xsize ; x = x + stepx){\
  9191.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9192.  ctx.lineWidth = line_width;\
  9193.  ctx.beginPath();\
  9194.  ctx.moveTo(x,ysize-ymarge);\
  9195.  ctx.lineTo(x,0);\
  9196.  ctx.stroke();\
  9197.  ctx.closePath();\
  9198.  if( use_axis_numbering != -1){\
  9199.   xtxt = (px2x(x)).toFixed(prec);\
  9200.   corr = 0.5*(ctx.measureText(xtxt).width);\
  9201.   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
  9202.   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
  9203.  };\
  9204.  for(var dx = 1 ; dx < xminor ; dx++){\
  9205.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9206.   ctx.lineWidth = 0.2*line_width;\
  9207.   ctx.beginPath();\
  9208.   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
  9209.   ctx.lineTo(x+dx*minor_step,0);\
  9210.   ctx.stroke();\
  9211.   ctx.closePath();\
  9212.  };\
  9213. };\
  9214. ctx.restore();\
  9215. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  9216.     break;
  9217.  
  9218.     default:break;
  9219.    }
  9220.   }
  9221.  }
  9222.   return;
  9223. }
  9224.  
  9225. void check_string_length(int L){
  9226.  if( L > MAX_BUFFER-1){
  9227.   canvas_error("problem with your arguments to command...");
  9228.  }
  9229.  return;
  9230. }
  9231.  
  9232.  
  9233. int get_token(FILE *infile){
  9234.         int     c,i=0;
  9235.         char    temp[MAX_INT], *input_type;
  9236.         char    *line="line",
  9237.         *audio="audio",
  9238.         *blink="blink",
  9239.         *arrowhead="arrowhead",
  9240.         *crosshairsize="crosshairsize",
  9241.         *crosshair="crosshair",
  9242.         *crosshairs="crosshairs",
  9243.         *audioobject="audioobject",
  9244.         *style="style",
  9245.         *mouse="mouse",
  9246.         *mousex="mousex",
  9247.         *mousey="mousey",
  9248.         *mouse_display="display",
  9249.         *mouse_degree="mouse_degree",
  9250.         *userdraw="userdraw",
  9251.         *highlight="highlight",
  9252.         *http="http",
  9253.         *rays="rays",
  9254.         *dashtype="dashtype",
  9255.         *dashed="dashed",
  9256.         *filled="filled",
  9257.         *lattice="lattice",
  9258.         *parallel="parallel",
  9259.         *segment="segment",
  9260.         *segments="segments",
  9261.         *dsegment="dsegment",
  9262.         *dsegments="dsegments",
  9263.         *seg="seg",
  9264.         *segs="segs",
  9265.         *bgimage="bgimage",
  9266.         *bgcolor="bgcolor",
  9267.         *strokecolor="strokecolor",
  9268.         *backgroundimage="backgroundimage",
  9269.         *text="text",
  9270.         *textup="textup",
  9271.         *mouseprecision="mouseprecision",
  9272.         *precision="precision",
  9273.         *plotsteps="plotsteps",
  9274.         *plotstep="plotstep",
  9275.         *tsteps="tsteps",
  9276.         *curve="curve",
  9277.         *dcurve="dcurve",
  9278.         *plot="plot",
  9279.         *dplot="dplot",
  9280.         *levelcurve="levelcurve",
  9281.         *fontsize="fontsize",
  9282.         *fontcolor="fontcolor",
  9283.         *axis="axis",
  9284.         *axisnumbering="axisnumbering",
  9285.         *axisnumbers="axisnumbers",
  9286.         *arrow="arrow",
  9287.         *vector="vector",
  9288.         *vectors="vectors",
  9289.         *darrow="darrow",
  9290.         *arrow2="arrow2",
  9291.         *darrow2="darrow2",
  9292.         *arrows="arrows",
  9293.         *arrows2="arrows2",
  9294.         *zoom="zoom",
  9295.         *grid="grid",
  9296.         *hline="hline",
  9297.         *dhline="dhline",
  9298.         *drag="drag",
  9299.         *horizontalline="horizontalline",
  9300.         *horizontallines="horizontallines",
  9301.         *vline="vline",
  9302.         *dvline="dvline",
  9303.         *verticalline="verticalline",
  9304.         *verticallines="verticallines",
  9305.         *triangle="triangle",
  9306.         *triangles="triangles",
  9307.         *ftriangle="ftriangle",
  9308.         *ftriangles="ftriangles",
  9309.         *mathml="mathml",
  9310.         *html="html",
  9311.         *input="input",
  9312.         *clearbutton="clearbutton",
  9313.         *erase="erase",
  9314.         *delete="delete",
  9315.         *inputstyle="inputstyle",
  9316.         *textarea="textarea",
  9317.         *trange="trange",
  9318.         *ranget="ranget",
  9319.         *xrange="xrange",
  9320.         *yrange="yrange",
  9321.         *rangex="rangex",
  9322.         *rangey="rangey",
  9323.         *path="path",
  9324.         *polyline="polyline",
  9325.         *brokenline="brokenline",
  9326.         *lines="lines",
  9327.         *poly="poly",
  9328.         *polygon="polygon",
  9329.         *fpolygon="fpolygon",
  9330.         *fpoly="fpoly",
  9331.         *filledpoly="filledpoly",
  9332.         *filledpolygon="filledpolygon",
  9333.         *rect="rect",
  9334.         *frect="frect",
  9335.         *rectangle="rectangle",
  9336.         *frectangle="frectangle",
  9337.         *square="square",
  9338.         *fsquare="fsquare",
  9339.         *fsquares="fsquares",
  9340.         *rects="rects",
  9341.         *frects="frects",
  9342.         *dline="dline",
  9343.         *arc="arc",
  9344.         *filledarc="filledarc",
  9345.         *farc="farc",
  9346.         *size="size",
  9347.         *string="string",
  9348.         *stringup="stringup",
  9349.         *copy="copy",
  9350.         *copyresized="copyresized",
  9351.         *opacity="opacity",
  9352.         *transparent="transparent",
  9353.         *fill="fill",
  9354.         *point="point",
  9355.         *points="points",
  9356.         *linewidth="linewidth",
  9357.         *circle="circle",
  9358.         *circles="circles",
  9359.         *fcircle="fcircle",
  9360.         *fcircles="fcircles",
  9361.         *disk="disk",
  9362.         *disks="disks",
  9363.         *comment="#",
  9364.         *end="end",
  9365.         *ellipse="ellipse",
  9366.         *ellipses="ellipses",
  9367.         *fellipse="fellipse",
  9368.         *rotate="rotate",
  9369.         *affine="affine",
  9370.         *rotationcenter="rotationcenter",
  9371.         *killrotate="killrotate",
  9372.         *killaffine="killaffine",
  9373.         *fontfamily="fontfamily",
  9374.         *fillcolor="fillcolor",
  9375.         *clicktile="clicktile",
  9376.         *clicktile_colors="clicktile_colors",
  9377.         *translation="translation",
  9378.         *translate="translate",
  9379.         *killtranslation="killtranslation",
  9380.         *killtranslate="killtranslate",
  9381.         *onclick="onclick",
  9382.         *roundrects="roundrects",
  9383.         *roundrect="roundrect",
  9384.         *froundrect="froundrect",
  9385.         *froundrects="froundrects",
  9386.         *roundrectangle="roundrectangle",
  9387.         *patternfill="patternfill",
  9388.         *hatchfill="hatchfill",
  9389.         *diafill="diafill",
  9390.         *diamondfill="diamondfill",
  9391.         *dotfill="dotfill",
  9392.         *textfill="textfill",
  9393.         *gridfill="gridfill",
  9394.         *imagefill="imagefill",
  9395.         *xlogbase="xlogbase",
  9396.         *ylogbase="ylogbase",
  9397.         *xlogscale="xlogscale",
  9398.         *ylogscale="ylogscale",
  9399.         *xylogscale="xylogscale",
  9400.         *intooltip="intooltip",
  9401.         *popup="popup",
  9402.         *replyformat="replyformat",
  9403.         *floodfill="floodfill",
  9404.         *fillall="fillall",
  9405.         *filltoborder="filltoborder",
  9406.         *setpixel="setpixel",
  9407.         *pixels="pixels",
  9408.         *pixelsize="pixelsize",
  9409.         *xaxis="xaxis",
  9410.         *xaxisup="xaxisup",
  9411.         *yaxis="yaxis",
  9412.         *xaxistext="xaxistext",
  9413.         *xaxistextup="xaxistextup",
  9414.         *yaxistext="yaxistext",
  9415.         *piechart="piechart",
  9416.         *boxplot="boxplot",
  9417.         *boxplotdata="boxplotdata",
  9418.         *userboxplot="userboxplot",
  9419.         *userboxplotdata="userboxplotdata",
  9420.         *legend="legend",
  9421.         *legendcolors="legendcolors",
  9422.         *xlabel="xlabel",
  9423.         *ylabel="ylabel",
  9424.         *barchart="barchart",
  9425.         *linegraph="linegraph",
  9426.         *clock="clock",
  9427.         *animate="animate",
  9428.         *video="video",
  9429.         *status="status",
  9430.         *nostatus="nostatus",
  9431.         *snaptogrid="snaptogrid",
  9432.         *xsnaptogrid="xsnaptogrid",
  9433.         *ysnaptogrid="ysnaptogrid",
  9434.         *snaptopoints="snaptopoints",
  9435.         *snaptofunction="snaptofunction",
  9436.         *snaptofun="snaptofun",
  9437.         *userinput_xy="userinput_xy",
  9438.         *userinput_function="userinput_function",
  9439.         *usertextarea_xy="usertextarea_xy",
  9440.         *userinput="userinput",
  9441.         *jsmath="jsmath",
  9442.         *trace_jscurve="trace_jscurve",
  9443.         *setlimits="setlimits",
  9444.         *jscurve="jscurve",
  9445.         *jsplot="jsplot",
  9446.         *sgraph="sgraph",
  9447.         *title="title",
  9448.         *centerstring="centerstring",
  9449.         *xunit="xunit",
  9450.         *yunit="yunit",
  9451.         *slider="slider",
  9452.         *killslider="killslider",
  9453.         *angle="angle",
  9454.         *halflines="halflines",
  9455.         *demilines="demilines",
  9456.         *halfline="halfline",
  9457.         *demiline="demiline",
  9458.         *hlines="hlines",
  9459.         *vlines="vlines",
  9460.         *bezier="bezier",
  9461.         *functionlabel="functionlabel",
  9462.         *sliderfunction_x="sliderfunction_x",
  9463.         *sliderfunction_y="sliderfunction_y",
  9464.         *multidraw="multidraw",
  9465.         *multilinewidth="multilinewidth",
  9466.         *multistrokecolors="multistrokecolors",
  9467.         *multifillcolors="multifillcolors",
  9468.         *multistrokeopacity="multistrokeopacity",
  9469.         *multifillopacity="multifillopacity",
  9470.         *multifill="multifill",
  9471.         *multidash="multidash",
  9472.         *multilabel="multilabel",
  9473.         *multiuserinput="multiuserinput",
  9474.         *multisnaptogrid="multisnaptogrid",
  9475.         *protractor="protractor",
  9476.         *ruler="ruler",
  9477.         *cursor="cursor",
  9478.         *pointer="pointer",
  9479.         *yerrorbars="yerrorbars",
  9480.         *xerrorbars="xerrorbars",
  9481.         *noxaxis="noxaxis",
  9482.         *noyaxis="noyaxis",
  9483.         *colorpalette="colorpalette",
  9484.         *yoffset="yoffset",
  9485.         *xoffset="xoffset",
  9486.         *centered="centered",
  9487.         *xyoffset="xyoffset",
  9488.         *resetoffset="resetoffset",
  9489.         *fillpattern="fillpattern",
  9490.         *numberline="numberline",
  9491.         *canvastype="canvastype";
  9492.  
  9493.         while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){
  9494.          if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */
  9495.          }else{
  9496.           if( c == ' ' ){
  9497.             break;
  9498.           }else{
  9499.            temp[i] = c;
  9500.            if(i > MAX_INT - 2){canvas_error("command string too long !");}
  9501.            i++;
  9502.           }
  9503.          }
  9504.          if(temp[0] == '#'){ break; }
  9505.         }
  9506.         if (c == '\n' || c == '\r' || c == '\t' ){  line_number++; }
  9507.         if (c == EOF) {finished=1;return 0;}
  9508.  
  9509.         temp[i]='\0';
  9510.         input_type=(char*)my_newmem(strlen(temp));
  9511.         snprintf(input_type,sizeof(temp),"%s",temp);
  9512. /* fprintf(stdout,"temp = %s <br/>",input_type); */
  9513.         if( strcmp(input_type, size) == 0 ){
  9514.         free(input_type);
  9515.         return SIZE;
  9516.         }
  9517.         if( strcmp(input_type, xrange) == 0 ){
  9518.         free(input_type);
  9519.         return XRANGE;
  9520.         }
  9521.         if( strcmp(input_type, rangex) == 0 ){
  9522.         free(input_type);
  9523.         return XRANGE;
  9524.         }
  9525.         if( strcmp(input_type, trange) == 0 ){
  9526.         free(input_type);
  9527.         return TRANGE;
  9528.         }
  9529.         if( strcmp(input_type, ranget) == 0 ){
  9530.         free(input_type);
  9531.         return TRANGE;
  9532.         }
  9533.         if( strcmp(input_type, yrange) == 0 ){
  9534.         free(input_type);
  9535.         return YRANGE;
  9536.         }
  9537.         if( strcmp(input_type, rangey) == 0 ){
  9538.         free(input_type);
  9539.         return YRANGE;
  9540.         }
  9541.         if( strcmp(input_type, linewidth) == 0 ){
  9542.         free(input_type);
  9543.         return LINEWIDTH;
  9544.         }
  9545.         if( strcmp(input_type, dashed) == 0 ){
  9546.         free(input_type);
  9547.         return DASHED;
  9548.         }
  9549.         if( strcmp(input_type, dashtype) == 0 ){
  9550.         free(input_type);
  9551.         return DASHTYPE;
  9552.         }
  9553.         if( strcmp(input_type, axisnumbering) == 0 ){
  9554.         free(input_type);
  9555.         return AXIS_NUMBERING;
  9556.         }
  9557.         if( strcmp(input_type, axisnumbers) == 0 ){
  9558.         free(input_type);
  9559.         return AXIS_NUMBERING;
  9560.         }
  9561.         if( strcmp(input_type, axis) == 0 ){
  9562.         free(input_type);
  9563.         return AXIS;
  9564.         }
  9565.         if( strcmp(input_type, grid) == 0 ){
  9566.         free(input_type);
  9567.         return GRID;
  9568.         }
  9569.         if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){
  9570.         free(input_type);
  9571.         return HLINES;
  9572.         }
  9573.         if( strcmp(input_type, vlines) == 0 ||  strcmp(input_type, verticallines) == 0 ){
  9574.         free(input_type);
  9575.         return VLINES;
  9576.         }
  9577.         if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){
  9578.         free(input_type);
  9579.         return HLINE;
  9580.         }
  9581.         if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
  9582.         free(input_type);
  9583.         return VLINE;
  9584.         }
  9585.         if( strcmp(input_type, line) == 0 ){
  9586.         free(input_type);
  9587.         return LINE;
  9588.         }
  9589.         if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){
  9590.         free(input_type);
  9591.         return SEGMENTS;
  9592.         }
  9593.         if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
  9594.         free(input_type);
  9595.         return SEGMENT;
  9596.         }
  9597.         if( strcmp(input_type, dsegments) == 0 ){
  9598.         free(input_type);
  9599.         use_dashed = TRUE;
  9600.         return SEGMENTS;
  9601.         }
  9602.         if( strcmp(input_type, dsegment) == 0 ){
  9603.         free(input_type);
  9604.         use_dashed = TRUE;
  9605.         return SEGMENT;
  9606.         }
  9607.         if( strcmp(input_type, crosshairsize) == 0 ){
  9608.         free(input_type);
  9609.         return CROSSHAIRSIZE;
  9610.         }
  9611.         if( strcmp(input_type, arrowhead) == 0 ){
  9612.         free(input_type);
  9613.         return ARROWHEAD;
  9614.         }
  9615.         if( strcmp(input_type, crosshairs) == 0 ){
  9616.         free(input_type);
  9617.         return CROSSHAIRS;
  9618.         }
  9619.         if( strcmp(input_type, crosshair) == 0 ){
  9620.         free(input_type);
  9621.         return CROSSHAIR;
  9622.         }
  9623.         if( strcmp(input_type, onclick) == 0 ){
  9624.         free(input_type);
  9625.         return ONCLICK;
  9626.         }
  9627.         if( strcmp(input_type, drag) == 0 ){
  9628.         free(input_type);
  9629.         return DRAG;
  9630.         }
  9631.         if( strcmp(input_type, userdraw) == 0 ){
  9632.         free(input_type);
  9633.         return USERDRAW;
  9634.         }
  9635.         if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
  9636.         free(input_type);
  9637.         return STYLE;
  9638.         }
  9639.         if( strcmp(input_type, fillcolor) == 0 ){
  9640.         free(input_type);
  9641.         return FILLCOLOR;
  9642.         }
  9643.         if( strcmp(input_type, strokecolor) == 0 ){
  9644.         free(input_type);
  9645.         return STROKECOLOR;
  9646.         }
  9647.         if( strcmp(input_type, filled) == 0  ){
  9648.         free(input_type);
  9649.         return FILLED;
  9650.         }
  9651.         if( strcmp(input_type, http) == 0 ){
  9652.         free(input_type);
  9653.         return HTTP;
  9654.         }
  9655.         if( strcmp(input_type, rays) == 0 ){
  9656.         free(input_type);
  9657.         return RAYS;
  9658.         }
  9659.         if( strcmp(input_type, lattice) == 0 ){
  9660.         free(input_type);
  9661.         return LATTICE;
  9662.         }
  9663.         if( strcmp(input_type, bgimage) == 0 ){
  9664.         free(input_type);
  9665.         return BGIMAGE;
  9666.         }
  9667.         if( strcmp(input_type, bgcolor) == 0 ){
  9668.         free(input_type);
  9669.         return BGCOLOR;
  9670.         }
  9671.         if( strcmp(input_type, backgroundimage) == 0 ){
  9672.         free(input_type);
  9673.         return BGIMAGE;
  9674.         }
  9675.         if( strcmp(input_type, text) == 0 ){
  9676.         free(input_type);
  9677.         return FLY_TEXT;
  9678.         }
  9679.         if( strcmp(input_type, textup) == 0 ){
  9680.         free(input_type);
  9681.         return FLY_TEXTUP;
  9682.         }
  9683.         if( strcmp(input_type, mouse) == 0 ){
  9684.         free(input_type);
  9685.         return MOUSE;
  9686.         }
  9687.         if( strcmp(input_type, mousex) == 0 ){
  9688.         free(input_type);
  9689.         return MOUSEX;
  9690.         }
  9691.         if( strcmp(input_type, mousey) == 0 ){
  9692.         free(input_type);
  9693.         return MOUSEY;
  9694.         }
  9695.         if( strcmp(input_type, mouse_degree) == 0 ){
  9696.         free(input_type);
  9697.         return MOUSE_DEGREE;
  9698.         }
  9699.         if( strcmp(input_type, mouse_display) == 0 ){
  9700.         free(input_type);
  9701.         return MOUSE_DISPLAY;
  9702.         }
  9703.         if( strcmp(input_type, mouseprecision) == 0 ){
  9704.         free(input_type);
  9705.         return MOUSE_PRECISION;
  9706.         }
  9707.         if( strcmp(input_type, precision) == 0 ){
  9708.         free(input_type);
  9709.         return MOUSE_PRECISION;
  9710.         }
  9711.         if( strcmp(input_type, curve) == 0 ){
  9712.         free(input_type);
  9713.         return CURVE;
  9714.         }
  9715.         if( strcmp(input_type, dcurve) == 0 ){
  9716.         use_dashed = TRUE;
  9717.         free(input_type);
  9718.         return CURVE;
  9719.         }
  9720.         if( strcmp(input_type, plot) == 0 ){
  9721.         free(input_type);
  9722.         return CURVE;
  9723.         }
  9724.         if( strcmp(input_type, dplot) == 0 ){
  9725.         use_dashed = TRUE;
  9726.         free(input_type);
  9727.         return CURVE;
  9728.         }
  9729.         if( strcmp(input_type, levelcurve) == 0 ){
  9730.         free(input_type);
  9731.         return LEVELCURVE;
  9732.         }
  9733.         if( strcmp(input_type, plotsteps) == 0 ){
  9734.         free(input_type);
  9735.         return PLOTSTEPS;
  9736.         }
  9737.         if( strcmp(input_type, plotstep) == 0 ){
  9738.         free(input_type);
  9739.         return PLOTSTEPS;
  9740.         }
  9741.         if( strcmp(input_type, tsteps) == 0 ){
  9742.         free(input_type);
  9743.         return PLOTSTEPS;
  9744.         }
  9745.         if( strcmp(input_type, fontsize) == 0 ){
  9746.         free(input_type);
  9747.         return FONTSIZE;
  9748.         }
  9749.         if( strcmp(input_type, fontcolor) == 0 ){
  9750.         free(input_type);
  9751.         return FONTCOLOR;
  9752.         }
  9753.         if( strcmp(input_type, arrow2) == 0 ){
  9754.         free(input_type);
  9755.         return ARROW2;
  9756.         }
  9757.         if( strcmp(input_type, darrow) == 0 ){
  9758.         free(input_type);
  9759.         use_dashed = TRUE;
  9760.         return ARROW;
  9761.         }
  9762.         if( strcmp(input_type, darrow2) == 0 ){
  9763.         free(input_type);
  9764.         use_dashed = TRUE;
  9765.         return ARROW2;
  9766.         }
  9767.         if( strcmp(input_type, arrows2) == 0 ){
  9768.         free(input_type);
  9769.         return ARROWS2;
  9770.         }
  9771.         if( strcmp(input_type, arrows) == 0  || strcmp(input_type, vectors) == 0 ){
  9772.         free(input_type);
  9773.         return ARROWS;
  9774.         }
  9775.         if( strcmp(input_type, arrow) == 0 ||  strcmp(input_type, vector) == 0 ){
  9776.         free(input_type);
  9777.         return ARROW;
  9778.         }
  9779.         if( strcmp(input_type, zoom) == 0 ){
  9780.         free(input_type);
  9781.         return ZOOM;
  9782.         }
  9783.         if( strcmp(input_type, triangle) == 0 ){
  9784.         free(input_type);
  9785.         return TRIANGLE;
  9786.         }
  9787.         if( strcmp(input_type, triangles) == 0 ){
  9788.         free(input_type);
  9789.         return TRIANGLES;
  9790.         }
  9791.         if( strcmp(input_type, ftriangles) == 0 ){
  9792.         free(input_type);
  9793.         use_filled = TRUE;
  9794.         return TRIANGLES;
  9795.         }
  9796.         if( strcmp(input_type, ftriangle) == 0 ){
  9797.         free(input_type);
  9798.         use_filled = TRUE;
  9799.         return TRIANGLE;
  9800.         }
  9801.         if( strcmp(input_type, input) == 0 ){
  9802.         free(input_type);
  9803.         return INPUT;
  9804.         }
  9805.         if( strcmp(input_type, inputstyle) == 0 ){
  9806.         free(input_type);
  9807.         return INPUTSTYLE;
  9808.         }
  9809.         if( strcmp(input_type, textarea) == 0 ){
  9810.         free(input_type);
  9811.         return TEXTAREA;
  9812.         }
  9813.         if( strcmp(input_type, mathml) == 0 ){
  9814.         free(input_type);
  9815.         return MATHML;
  9816.         }
  9817.         if( strcmp(input_type, html) == 0 ){
  9818.         free(input_type);
  9819.         return MATHML;
  9820.         }
  9821.         if( strcmp(input_type, fontfamily) == 0 ){
  9822.         free(input_type);
  9823.         return FONTFAMILY;
  9824.         }
  9825.         if( strcmp(input_type, polyline) == 0 ||  strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){
  9826.         free(input_type);
  9827.         return POLYLINE;
  9828.         }
  9829.         if( strcmp(input_type, lines) == 0 ){
  9830.         free(input_type);
  9831.         return LINES;
  9832.         }
  9833.         if( strcmp(input_type, rects) == 0){
  9834.         free(input_type);
  9835.         return RECTS;
  9836.         }
  9837.         if( strcmp(input_type, frects) == 0 ){
  9838.         free(input_type);
  9839.         use_filled = TRUE;
  9840.         return RECTS;
  9841.         }
  9842.         if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
  9843.         free(input_type);
  9844.         return RECT;
  9845.         }
  9846.         if( strcmp(input_type, square) == 0 ){
  9847.         free(input_type);
  9848.         return SQUARE;
  9849.         }
  9850.         if( strcmp(input_type, fsquare) == 0 ){
  9851.         free(input_type);
  9852.         use_filled = TRUE;
  9853.         return SQUARE;
  9854.         }
  9855.         if( strcmp(input_type, fsquares) == 0 ){
  9856.         free(input_type);
  9857.         use_filled = TRUE;
  9858.         return RECTS;
  9859.         }
  9860.         if( strcmp(input_type, roundrects) == 0 ){
  9861.         free(input_type);
  9862.         return ROUNDRECTS;
  9863.         }
  9864.         if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
  9865.         free(input_type);
  9866.         return ROUNDRECT;
  9867.         }
  9868.         if( strcmp(input_type, froundrects) == 0 ){
  9869.         free(input_type);
  9870.         use_filled = TRUE;
  9871.         return ROUNDRECTS;
  9872.         }
  9873.         if( strcmp(input_type, froundrect) == 0 ){
  9874.         free(input_type);
  9875.         use_filled = TRUE;
  9876.         return ROUNDRECT;
  9877.         }
  9878.         if( strcmp(input_type, dline) == 0 ){
  9879.         use_dashed = TRUE;
  9880.         free(input_type);
  9881.         return LINE;
  9882.         }
  9883.         if( strcmp(input_type, dvline) == 0 ){
  9884.         use_dashed = TRUE;
  9885.         free(input_type);
  9886.         return VLINE;
  9887.         }
  9888.         if( strcmp(input_type, dhline) == 0 ){
  9889.         use_dashed = TRUE;
  9890.         free(input_type);
  9891.         return HLINE;
  9892.         }
  9893.         if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0  ){
  9894.         free(input_type);
  9895.         return HALFLINES;
  9896.         }
  9897.         if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0  ){
  9898.         free(input_type);
  9899.         return HALFLINE;
  9900.         }
  9901.         if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
  9902.         use_filled = TRUE;
  9903.         free(input_type);
  9904.         return RECT;
  9905.         }
  9906.         if( strcmp(input_type, circles) == 0 ){
  9907.         free(input_type);
  9908.         return CIRCLES;
  9909.         }
  9910.         if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
  9911.         use_filled = TRUE;
  9912.         free(input_type);
  9913.         return CIRCLE;
  9914.         }
  9915.         if( strcmp(input_type, fcircles) == 0  ||  strcmp(input_type, disks) == 0 ){
  9916.         use_filled = TRUE;
  9917.         free(input_type);
  9918.         return CIRCLES;
  9919.         }
  9920.         if( strcmp(input_type, circle) == 0 ){
  9921.         free(input_type);
  9922.         return CIRCLE;
  9923.         }
  9924.         if( strcmp(input_type, point) == 0 ){
  9925.         free(input_type);
  9926.         return POINT;
  9927.         }
  9928.         if( strcmp(input_type, points) == 0 ){
  9929.         free(input_type);
  9930.         return POINTS;
  9931.         }
  9932.         if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){
  9933.         use_filled = TRUE;
  9934.         free(input_type);
  9935.         return ARC;
  9936.         }
  9937.         if( strcmp(input_type, arc) == 0 ){
  9938.         free(input_type);
  9939.         return ARC;
  9940.         }
  9941.         if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
  9942.         free(input_type);
  9943.         return POLY;
  9944.         }
  9945.         if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
  9946.         use_filled = TRUE;
  9947.         free(input_type);
  9948.         return POLY;
  9949.         }
  9950.         if( strcmp(input_type, ellipse) == 0){
  9951.         free(input_type);
  9952.         return ELLIPSE;
  9953.         }
  9954.         if( strcmp(input_type, ellipses) == 0){
  9955.         free(input_type);
  9956.         return ELLIPSES;
  9957.         }
  9958.         if( strcmp(input_type, string) == 0 ){
  9959.         free(input_type);
  9960.         return STRING;
  9961.         }
  9962.         if( strcmp(input_type, stringup) == 0 ){
  9963.         free(input_type);
  9964.         return STRINGUP;
  9965.         }
  9966.         if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){
  9967.         free(input_type);
  9968.         return OPACITY;
  9969.         }
  9970.         if( strcmp(input_type, comment) == 0){
  9971.         free(input_type);
  9972.         return COMMENT;
  9973.         }
  9974.         if( strcmp(input_type, fellipse) == 0){
  9975.         free(input_type);
  9976.         use_filled = TRUE;
  9977.         return ELLIPSE;
  9978.         }
  9979.         if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){
  9980.         free(input_type);
  9981.         return CLEARBUTTON;
  9982.         }
  9983.         if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
  9984.         free(input_type);
  9985.         return TRANSLATION;
  9986.         }
  9987.         if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
  9988.         free(input_type);
  9989.         return KILLTRANSLATION;
  9990.         }
  9991.         if( strcmp(input_type, rotate) == 0){
  9992.         free(input_type);
  9993.         return ROTATE;
  9994.         }
  9995.         if( strcmp(input_type, killrotate) == 0){
  9996.         free(input_type);
  9997.         return KILLROTATE;
  9998.         }
  9999.         if( strcmp(input_type, rotationcenter) == 0){
  10000.         free(input_type);
  10001.         return ROTATION_CENTER;
  10002.         }
  10003.         if( strcmp(input_type, affine) == 0){
  10004.         free(input_type);
  10005.         return AFFINE;
  10006.         }
  10007.         if( strcmp(input_type, killaffine) == 0){
  10008.         free(input_type);
  10009.         return KILLAFFINE;
  10010.         }
  10011.         if( strcmp(input_type, slider) == 0 ){
  10012.         free(input_type);
  10013.         return SLIDER;
  10014.         }
  10015.         if( strcmp(input_type, killslider) == 0 ){
  10016.         free(input_type);
  10017.         return KILLSLIDER;
  10018.         }
  10019.         if( strcmp(input_type, copy) == 0 ){
  10020.         free(input_type);
  10021.         return COPY;
  10022.         }
  10023.         if( strcmp(input_type, copyresized) == 0 ){
  10024.         free(input_type);
  10025.         return COPYRESIZED;
  10026.         }
  10027.         if( strcmp(input_type, xlogscale) == 0 ){
  10028.         free(input_type);
  10029.         return XLOGSCALE;
  10030.         }
  10031.         if( strcmp(input_type, ylogscale) == 0 ){
  10032.         free(input_type);
  10033.         return YLOGSCALE;
  10034.         }
  10035.         if( strcmp(input_type, xylogscale) == 0 ){
  10036.         free(input_type);
  10037.         return XYLOGSCALE;
  10038.         }
  10039.         if( strcmp(input_type, ylogscale) == 0 ){
  10040.         free(input_type);
  10041.         return YLOGSCALE;
  10042.         }
  10043.         if( strcmp(input_type, xlogbase) == 0 ){
  10044.         free(input_type);
  10045.         return XLOGBASE;
  10046.         }
  10047.         if( strcmp(input_type, ylogbase) == 0 ){
  10048.         free(input_type);
  10049.         return YLOGBASE;
  10050.         }
  10051.         if( strcmp(input_type, intooltip) == 0 ){
  10052.         free(input_type);
  10053.         return INTOOLTIP;
  10054.         }
  10055.         if( strcmp(input_type, popup) == 0 ){
  10056.         free(input_type);
  10057.         return POPUP;
  10058.         }
  10059.         if( strcmp(input_type,video) == 0 ){
  10060.         free(input_type);
  10061.         return VIDEO;
  10062.         }
  10063.         if( strcmp(input_type,fillall) == 0 ){
  10064.         free(input_type);
  10065.         return FILLALL;
  10066.         }
  10067.         if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
  10068.         free(input_type);
  10069.         return FLOODFILL;
  10070.         }
  10071.         if( strcmp(input_type,filltoborder) == 0 ){
  10072.         free(input_type);
  10073.         return FILLTOBORDER;
  10074.         }
  10075.         if( strcmp(input_type, replyformat) == 0 ){
  10076.         free(input_type);
  10077.         return REPLYFORMAT;
  10078.         }
  10079.         if( strcmp(input_type, pixelsize) == 0 ){
  10080.         free(input_type);
  10081.         return PIXELSIZE;
  10082.         }
  10083.         if( strcmp(input_type, setpixel) == 0 ){
  10084.         free(input_type);
  10085.         return SETPIXEL;
  10086.         }
  10087.         if( strcmp(input_type, pixels) == 0 ){
  10088.         free(input_type);
  10089.         return PIXELS;
  10090.         }
  10091.         if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
  10092.         free(input_type);
  10093.         return X_AXIS_STRINGS;
  10094.         }
  10095.         if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){
  10096.         free(input_type);
  10097.         return X_AXIS_STRINGS_UP;
  10098.         }
  10099.         if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
  10100.         free(input_type);
  10101.         return Y_AXIS_STRINGS;
  10102.         }
  10103.         if( strcmp(input_type, legend) == 0  ){
  10104.         free(input_type);
  10105.         return LEGEND;
  10106.         }
  10107.         if( strcmp(input_type, legendcolors) == 0  ){
  10108.         free(input_type);
  10109.         return LEGENDCOLORS;
  10110.         }
  10111.         if( strcmp(input_type, xlabel) == 0  ){
  10112.         free(input_type);
  10113.         return XLABEL;
  10114.         }
  10115.         if( strcmp(input_type, ylabel) == 0  ){
  10116.         free(input_type);
  10117.         return YLABEL;
  10118.         }
  10119.         if( strcmp(input_type, bezier) == 0  ){
  10120.         free(input_type);
  10121.         return BEZIER;
  10122.         }
  10123.         if( strcmp(input_type, animate) == 0  ){
  10124.         free(input_type);
  10125.         return ANIMATE;
  10126.         }
  10127.         /* these are bitmap related flydraw commands...must be removed. eventually */
  10128.         if( strcmp(input_type, transparent) == 0 ){
  10129.         free(input_type);
  10130.         return TRANSPARENT;
  10131.         }
  10132.         if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
  10133.         free(input_type);
  10134.         return STATUS;
  10135.         }
  10136.         if( strcmp(input_type, xsnaptogrid) == 0 ){
  10137.         free(input_type);
  10138.         return XSNAPTOGRID;
  10139.         }
  10140.         if( strcmp(input_type, ysnaptogrid) == 0 ){
  10141.         free(input_type);
  10142.         return YSNAPTOGRID;
  10143.         }
  10144.         if( strcmp(input_type, snaptogrid) == 0 ){
  10145.         free(input_type);
  10146.         return SNAPTOGRID;
  10147.         }
  10148.         if( strcmp(input_type, snaptopoints) == 0 ){
  10149.         free(input_type);
  10150.         return SNAPTOPOINTS;
  10151.         }
  10152.         if( strcmp(input_type, snaptofunction) == 0  || strcmp(input_type, snaptofun) == 0 ){
  10153.         free(input_type);
  10154.         return SNAPTOFUNCTION;
  10155.         }
  10156.         if( strcmp(input_type, userinput_xy) == 0 ){
  10157.         free(input_type);
  10158.         return USERINPUT_XY;
  10159.         }
  10160.         if( strcmp(input_type, userinput_function) == 0 ){
  10161.         free(input_type);
  10162.         return USERINPUT_FUNCTION;
  10163.         }
  10164.         if( strcmp(input_type, usertextarea_xy) == 0 ){
  10165.         free(input_type);
  10166.         return USERTEXTAREA_XY;
  10167.         }
  10168.         if( strcmp(input_type, userinput) == 0 ){
  10169.         free(input_type);
  10170.         return USERINPUT;
  10171.         }
  10172.         if( strcmp(input_type, angle) == 0 ){
  10173.         free(input_type);
  10174.         return ANGLE;
  10175.         }
  10176.         if( strcmp(input_type, functionlabel) == 0 ){
  10177.         free(input_type);
  10178.         return FUNCTION_LABEL;
  10179.         }
  10180.         if( strcmp(input_type, sliderfunction_x) == 0 ){
  10181.         free(input_type);
  10182.         return SLIDER_X;
  10183.         }
  10184.         if( strcmp(input_type, sliderfunction_y) == 0 ){
  10185.         free(input_type);
  10186.         return SLIDER_Y;
  10187.         }
  10188.         if( strcmp(input_type, multidraw) == 0 ){
  10189.         free(input_type);
  10190.         return MULTIDRAW;
  10191.         }
  10192.         if( strcmp(input_type, multistrokeopacity) == 0 ){
  10193.         free(input_type);
  10194.         return MULTISTROKEOPACITY;
  10195.         }
  10196.         if( strcmp(input_type, multifillopacity) == 0 ){
  10197.         free(input_type);
  10198.         return MULTIFILLOPACITY;
  10199.         }
  10200.         if( strcmp(input_type, multilinewidth) == 0 ){
  10201.         free(input_type);
  10202.         return MULTILINEWIDTH;
  10203.         }
  10204.         if( strcmp(input_type, multistrokecolors) == 0 ){
  10205.         free(input_type);
  10206.         return MULTISTROKECOLORS;
  10207.         }
  10208.         if( strcmp(input_type, multifill) == 0 ){
  10209.         free(input_type);
  10210.         return MULTIFILL;
  10211.         }
  10212.         if( strcmp(input_type, multifillcolors) == 0 ){
  10213.         free(input_type);
  10214.         return MULTIFILLCOLORS;
  10215.         }
  10216.         if( strcmp(input_type, multilabel) == 0 ){
  10217.         free(input_type);
  10218.         return MULTILABEL;
  10219.         }
  10220.         if( strcmp(input_type, multidash) == 0 ){
  10221.         free(input_type);
  10222.         return MULTIDASH;
  10223.         }
  10224.         if( strcmp(input_type, multisnaptogrid) == 0 ){
  10225.         free(input_type);
  10226.         return MULTISNAPTOGRID;
  10227.         }
  10228.         if( strcmp(input_type, multiuserinput) == 0 ){
  10229.         free(input_type);
  10230.         return MULTIUSERINPUT;
  10231.         }
  10232.         if( strcmp(input_type, parallel) == 0 ){
  10233.         free(input_type);
  10234.         return PARALLEL;
  10235.         }
  10236.         if( strcmp(input_type, protractor) == 0 ){
  10237.         free(input_type);
  10238.         return PROTRACTOR;
  10239.         }
  10240.         if( strcmp(input_type, ruler) == 0 ){
  10241.         free(input_type);
  10242.         return RULER;
  10243.         }
  10244.         if( strcmp(input_type, cursor) == 0 ||  strcmp(input_type, pointer) == 0 ){
  10245.         free(input_type);
  10246.         return CURSOR;
  10247.         }
  10248.         if( strcmp(input_type, sgraph) == 0 ){
  10249.         free(input_type);
  10250.         return SGRAPH;
  10251.         }
  10252.         if( strcmp(input_type, jsmath) == 0 ){
  10253.         free(input_type);
  10254.         return JSMATH;
  10255.         }
  10256.         if( strcmp(input_type, trace_jscurve) == 0 ){
  10257.         free(input_type);
  10258.         return TRACE_JSCURVE;
  10259.         }
  10260.         if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
  10261.         free(input_type);
  10262.         return JSCURVE;
  10263.         }
  10264.         if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
  10265.         free(input_type);
  10266.         return CENTERSTRING;
  10267.         }
  10268.         if( strcmp(input_type, setlimits) == 0 ){
  10269.         free(input_type);
  10270.         return SETLIMITS;
  10271.         }
  10272.         if( strcmp(input_type, xunit) == 0 ){
  10273.         free(input_type);
  10274.         return XUNIT;
  10275.         }
  10276.         if( strcmp(input_type, yunit) == 0 ){
  10277.         free(input_type);
  10278.         return YUNIT;
  10279.         }
  10280.         if( strcmp(input_type, fill) == 0 ){
  10281.         free(input_type);
  10282.         return FLOODFILL;
  10283.         }
  10284.         if( strcmp(input_type, end) == 0){
  10285.         free(input_type);
  10286.         return END;
  10287.         }
  10288.         if( strcmp(input_type, blink) == 0 ){
  10289.         free(input_type);
  10290.         return BLINK;
  10291.         }
  10292.         if( strcmp(input_type, audio) == 0 ){
  10293.         free(input_type);
  10294.         return AUDIO;
  10295.         }
  10296.         if( strcmp(input_type, audioobject) == 0 ){
  10297.         free(input_type);
  10298.         return AUDIOOBJECT;
  10299.         }
  10300.         if( strcmp(input_type, patternfill) == 0 ){
  10301.         free(input_type);
  10302.         return PATTERNFILL;
  10303.         }
  10304.         if( strcmp(input_type, hatchfill) == 0 ){
  10305.         free(input_type);
  10306.         return HATCHFILL;
  10307.         }
  10308.         if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
  10309.         free(input_type);
  10310.         return DIAMONDFILL;
  10311.         }
  10312.         if( strcmp(input_type, dotfill) == 0 ){
  10313.         free(input_type);
  10314.         return DOTFILL;
  10315.         }
  10316.         if( strcmp(input_type, textfill) == 0 ){
  10317.         free(input_type);
  10318.         return TEXTFILL;
  10319.         }
  10320.         if( strcmp(input_type, gridfill) == 0 ){
  10321.         free(input_type);
  10322.         return GRIDFILL;
  10323.         }
  10324.         if( strcmp(input_type, imagefill) == 0 ){
  10325.         free(input_type);
  10326.         return IMAGEFILL;
  10327.         }
  10328.         if( strcmp(input_type, clicktile_colors) == 0 ){
  10329.         free(input_type);
  10330.         return CLICKTILE_COLORS;
  10331.         }
  10332.         if( strcmp(input_type, clicktile) == 0 ){
  10333.         free(input_type);
  10334.         return CLICKTILE;
  10335.         }
  10336.         if( strcmp(input_type, piechart) == 0  ){
  10337.         free(input_type);
  10338.         return PIECHART;
  10339.         }
  10340.         if( strcmp(input_type, boxplot) == 0  ){
  10341.         free(input_type);
  10342.         return BOXPLOT;
  10343.         }
  10344.         if( strcmp(input_type, boxplotdata) == 0  ){
  10345.         free(input_type);
  10346.         return BOXPLOTDATA;
  10347.         }
  10348.         if( strcmp(input_type, userboxplot) == 0  ){
  10349.         free(input_type);
  10350.         return USERBOXPLOT;
  10351.         }
  10352.         if( strcmp(input_type, userboxplotdata) == 0  ){
  10353.         free(input_type);
  10354.         return USERBOXPLOT;
  10355.         }
  10356.         if( strcmp(input_type, barchart) == 0  ){
  10357.         free(input_type);
  10358.         return BARCHART;
  10359.         }
  10360.         if( strcmp(input_type, linegraph) == 0  ){
  10361.         free(input_type);
  10362.         return LINEGRAPH;
  10363.         }
  10364.         if( strcmp(input_type, clock) == 0  ){
  10365.         free(input_type);
  10366.         return CLOCK;
  10367.         }
  10368.         if( strcmp(input_type, yerrorbars) == 0  ){
  10369.         free(input_type);
  10370.         return YERRORBARS;
  10371.         }
  10372.         if( strcmp(input_type, xerrorbars) == 0  ){
  10373.         free(input_type);
  10374.         return XERRORBARS;
  10375.         }
  10376.         if( strcmp(input_type, canvastype) == 0  ){
  10377.         free(input_type);
  10378.         return CANVASTYPE;
  10379.         }
  10380.         if( strcmp(input_type, noyaxis) == 0  ){
  10381.         free(input_type);
  10382.         return NOYAXIS;
  10383.         }
  10384.         if( strcmp(input_type, noxaxis) == 0  ){
  10385.         free(input_type);
  10386.         return NOXAXIS;
  10387.         }
  10388.         if( strcmp(input_type, colorpalette) == 0  ){
  10389.         free(input_type);
  10390.         return COLORPALETTE;
  10391.         }
  10392.         if( strcmp(input_type, resetoffset) == 0  ){
  10393.         free(input_type);
  10394.         return RESETOFFSET;
  10395.         }
  10396.         if( strcmp(input_type, xyoffset) == 0  ){
  10397.         free(input_type);
  10398.         return XYOFFSET;
  10399.         }
  10400.         if( strcmp(input_type, centered) == 0 ){
  10401.         free(input_type);
  10402.         return CENTERED;
  10403.         }
  10404.         if( strcmp(input_type, yoffset) == 0   ){
  10405.         free(input_type);
  10406.         return YOFFSET;
  10407.         }
  10408.         if( strcmp(input_type, xoffset) == 0   ){
  10409.         free(input_type);
  10410.         return XOFFSET;
  10411.         }
  10412.         if( strcmp(input_type, fillpattern) == 0 ){
  10413.         free(input_type);
  10414.         return FILLPATTERN;
  10415.         }
  10416.         if( strcmp(input_type, numberline) == 0 ){
  10417.         free(input_type);
  10418.         return NUMBERLINE;
  10419.         }
  10420.         free(input_type);
  10421.         ungetc(c,infile);
  10422.         return 0;
  10423. }
  10424.