Subversion Repositories wimsdev

Rev

Rev 14408 | Rev 14543 | 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. char *slider_type="0";
  58. int slider_cnt = 0;
  59. int active_sliders[MAX_SLIDERS];
  60. char *current_sliders = "[-1]";
  61. int use_affine = FALSE;
  62. int use_rotate = FALSE;
  63. int use_filled = 0; /* 0:no fill, 1:fill,2=grid?,3=hatch?,4=diamond?,5=dot?,6=image? */
  64. int use_dashed = FALSE; /* dashing not natively supported in firefox, for now... */
  65.  
  66. char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */
  67. char *getfile_cmd = "";
  68. /******************************************************************************
  69. ** Main Program
  70. ******************************************************************************/
  71. int main(int argc, char *argv[]){
  72.     /* need unique id for every call to canvasdraw: rand(); is too slow...will result in many identical id's */
  73.     struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);
  74.     unsigned int canvas_root_id = (unsigned int) tv.tv_usec;
  75.     infile = stdin;/* read flyscript via stdin */
  76.     int i,c;
  77.     double double_data[MAX_INT+1];
  78.     int int_data[MAX_INT+1];
  79.     for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;}
  80.     for(i=0;i<MAX_SLIDERS;i++){active_sliders[i]=-1;}
  81.     int use_parametric = FALSE;/* will be reset after parametric plotting */
  82.     int use_axis = FALSE;
  83.     int use_axis_numbering = -1;
  84.     int use_snap = 0; /* 0 = none 1=grid: 2=x-grid: 3=y-grid: 4=snap to points */
  85.     int use_offset = 0;/* use_offset only for text shape objects... 0=none;1=yoffset;2=xoffset;3=xyoffset;4=centered*/
  86.     int use_pan_and_zoom = FALSE;
  87.     int use_safe_eval = FALSE; /* if true, add just once: js function to evaluate userinput values for plotting etc */
  88.     int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */
  89.     int use_js_plot = FALSE; /* if true, let js-engine plot the curve */
  90.     int jsplot_cnt = 0; /* keepint track on the curve identity */
  91.     int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */
  92.     int include_special_OEF_reply = FALSE; /* used for including extra read_canvas_images();*/
  93.     int line_width = 1;
  94.     int decimals = 2;
  95.     int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */
  96.     int use_userdraw = FALSE; /* flag to indicate user interaction */
  97.     int drag_type = -1;/* 0,1,2: xy,x,y */
  98.     int use_tooltip = -1; /* 1= tooltip 2= popup window*/
  99.     char *tooltip_text = "Click here";
  100.     char *temp = ""; /* */
  101.     char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
  102.     char *stroke_color = "255,0,0";
  103.     char *fill_color = "255,255,255";
  104.     char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
  105.     char *font_color = "#00000";
  106.     char *draw_type = "points";
  107.     char *fly_font = "normal";
  108.     char *input_style = "font-family:Ariel;text-align:center;color:blue;font-size:12px;background-color:orange;";
  109.     char *flytext = "";
  110.     char *affine_matrix = "[1,0,0,1,0,0]";
  111.     char *function_label = "f(x)=";
  112.     int use_pattern = 0; /* used in drag&drop library: grid=2,hatch=3,diamond=4,dot=5*/
  113.     int canvas_type = DRAG_CANVAS; /* to use a specific canvas  for filling etc */
  114.     int pixelsize = 1;
  115.     int reply_format = 0;
  116.     int input_cnt = 0;
  117.     int ext_img_cnt = 0;
  118.     int fill_cnt = 0;
  119.     int font_size = 12;/* this may lead to problems when using something like <code>fontfamily Italic 24px Ariel</code> the ''fontsize`` value is not substituted into fontfamily !! */
  120.     int fly_font_size = 12; /*fly_font_size is relative to this... */
  121.     int dashtype[2] = { 4 , 4 }; /* just line_px and space_px: may have more arguments...if needed in future */
  122.     int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis: only once per object type */
  123.     for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
  124.     int arrow_head = 8; /* size in px needed for arrow based  userdraw:  "userdraw arrow,color" */
  125.     int crosshair_size = 5; /* size in px*/
  126.     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  */
  127.     int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange: just to flag an error message */
  128.     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 */
  129.     int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
  130.     int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
  131.     int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/
  132.     int boxplot_cnt = 0;
  133.     int numberline_cnt = 0;
  134.     int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc  */
  135.     int reply_precision = 100; /* used for precision of student answers / drawings */
  136.     double angle = 0.0;
  137.     char *rotation_center = "null";
  138.     int use_animate = 0; /* used for jscurve / js parametric  */
  139.     int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/
  140.     int use_slider_display = 0; /* in case of a slider, should we display its value ?*/
  141.     size_t string_length = 0; /* measure the size of the user input fly-string */
  142.     double stroke_opacity = 0.8; /* use some opacity as default */
  143.     double fill_opacity = 0.5;/* use some opacity as default */
  144.     char *URL = "http://localhost/images";
  145.     char *slider_function_x = "x";
  146.     char *slider_function_y = "y";
  147.     memset(buffer,'\0',MAX_BUFFER);
  148.     void *tmp_buffer = "";
  149.     /* default writing a unzipped js-include file into wims getfile directory */
  150.     char *w_wims_session = getenv("w_wims_session");
  151.     if(  w_wims_session == NULL || *w_wims_session == 0 ){canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");}
  152.     int L0=strlen(w_wims_session) + 21;
  153.     char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
  154.     snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
  155.     mode_t process_mask = umask(0); /* check if file exists */
  156.     int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
  157.     if( result == 0 || errno == EEXIST ){
  158.      umask(process_mask); /* be sure to set correct permission */
  159.      char *w_session = getenv("w_session");
  160.      int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
  161.      getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
  162.      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 */
  163.     /* write the include tag to html page:<script src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
  164.     /* now write file into getfile dir*/
  165.     char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims": we need absolute path for location */
  166.     int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
  167.     char *location = my_newmem(L2); /* create memory to fit string precisely */
  168.     snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
  169.     js_include_file = fopen(location,"w");/* open the file location for writing */
  170.     /* check on opening...if nogood: mount readonly? disk full? permissions not set correctly? */
  171.     if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN: could not write to javascript include file...check your system logfiles !" );}
  172.     char *user_agent = getenv("HTTP_USER_AGENT");
  173.     int browser_type = 1;/* GECKO */
  174.     if( (strcasestr(user_agent,"khtml" ) != NULL) || (strcasestr(user_agent,"opera" ) != NULL) || (strcasestr(user_agent,"trident" ) != NULL) ){ browser_type = 0; }
  175.  
  176. /* ----------------------------------------------------- */
  177.  
  178. /* while more lines to process */
  179.  
  180.     while(!finished){
  181.         if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
  182.         type = get_token(infile);
  183.         done = FALSE;
  184.         /*
  185.         @ canvasdraw
  186.         @ will try use the same syntax as@ 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`` (like ''frect``,''fcircle``,''ftriangle`` ...) 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>. Commands with only numeric or colour arguments may be using a '';`` as command separator (instead of a new line). 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 <code>snaptopoints x1,y1,x2,y2,...</code></li><li>every draggable | onclick object may be combined with keywords <a href="#snaptogrid">snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command <code>snaptopoints x1,y1,x2,y2,...</code></li><li>almost every command for a single object has a multiple objects counterpart:<br /><ul>general syntax rule:<li><code>single_object x1,y1,...,color</code></li><li><code>multi_object color,x1,y1,...</code></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 <code>fontfamily</code> is <b>not</b> active for these elements</li></ul>
  187.         @ If needed multiple interactive scripts may be used in a single webpage.<br />A function <code>read_canvas()</code> and / or <code>read_dragdrop()</code> can read all interactive userdata from these images.<br />The global array <code>canvas_scripts</code> 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 /><code>fun = eval("read_canvas"+canvas_scripts[0])</code> 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 /><code>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" 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...) ;<br />&nbsp;&nbsp;&nbsp;&nbsp;};<br />&nbsp;&nbsp;&nbsp;};<br />&nbsp;&nbsp;};<br />&nbsp;if( found_result ){return draw_reply;}else{return null;};<br />};</code>
  188.         @ 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>
  189.         @ for usage within OEF (without anstype ''draw``), something like this (a popup function plotter) will work:<br /><code>\\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 />}</code>.
  190.         @ 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 is not wise to use older browsers...not just for canvasdraw.
  191.         @ 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.
  192.         @ 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>. Only single finger gestures are supported (for now). For more accurate user-interaction (numeric, eg keyboard driven drawings) with canvasdraw on touch devices: use the command family <a href="#userinput_xy">userinput</a>.
  193.         */
  194.         switch(type){
  195.         case END:
  196.         finished = 1;
  197.         done = TRUE;
  198.         break;
  199.         case 0:
  200.             sync_input(infile);
  201.             break;
  202.  
  203.         case CENTERED:
  204.          use_offset = 4;
  205.          /*
  206.          @ centered
  207.          @ keyword ; to place the text centered (in width and height) on the text coordinates(x:y)
  208.          @ may be used for text exactly centered on its (x;y)
  209.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  210.          @ 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``)
  211.          @%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
  212.         */
  213.         break;
  214.  
  215.         case COMMENT:
  216.             sync_input(infile);
  217.             break;
  218.         case AFFINE:
  219.         /*
  220.          @ affine a,b,c,d,tx,ty
  221.          @ defines a transformation matrix for subsequent objects
  222.          @ follows the HTML5 / Canvas transformation standards<br />note: images drawn by setting skew params a &amp; d will thus be very different from Flydraw's "affine a,b,c,d,e,tx,ty" !!
  223.          @ use keyword <a href='#killaffine'>killaffine</a> to end the transformation...the next objects will be drawn in the original x/y-range
  224.          @ note 1: only ''draggable`` / ''onclick`` type of objects (e.g. objects in the ''drag/drop/onclick-library``) can be transformed.
  225.          @ note 2: do not use <code>onclick</code> or <code>drag xy</code> with tranformation / rotation objects: the mouse coordinates do not get transformed (yet)
  226.          @ note 3: no matrix operations on the transformation matrix implemented (yet)
  227.          @ a: Scales the drawings horizontally
  228.          @ b: Skews the drawings horizontally
  229.          @ c: Skews the drawings vertically
  230.          @ d: Scales the drawings vertically
  231.          @ tx: Moves the drawings horizontally in xrange coordinate system
  232.          @ ty: Moves the drawings vertically in yrange coordinate system
  233.          @ the data precision may be set by preceding command ''precision int``
  234.          @%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
  235.         */
  236.             for(i = 0 ; i<6;i++){
  237.                 switch(i){
  238.                     case 0: double_data[0] = get_real(infile,0);break;
  239.                     case 1: double_data[1] = get_real(infile,0);break;
  240.                     case 2: double_data[2] = get_real(infile,0);break;
  241.                     case 3: double_data[3] = get_real(infile,0);break;
  242.                     case 4: double_data[4] = get_real(infile,0);break;
  243.                     case 5: double_data[5] = get_real(infile,1);
  244.                         use_affine = TRUE;
  245.                         decimals = find_number_of_digits(precision);
  246.                         string_length = 1 + 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));
  247.                         check_string_length(string_length);affine_matrix = my_newmem(string_length);
  248.                         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));
  249.                         break;
  250.                     default: break;
  251.                 }
  252.             }
  253.         break;
  254.  
  255.         case ALLOW_DUPLICATES:
  256.         /*
  257.          @ duplicates || allowdups
  258.          @ keyword (no arguments)
  259.          @ only useful in case of a <a href="#multidraw">multidraw</a> student reply.
  260.          @ only useful in default <a href="#replyformat">replyformat</a> (eg in case of a not specified replyformat).
  261.          @ if set, duplicate (x:y) coordinates will not be removed from the student reply.
  262.          @ technical: a javascript variable "allow_duplicate_answer = 1;" is declared.
  263.          @ the default for command multidraw is : removal of duplicates.
  264.         */
  265.          fprintf(js_include_file,"var allow_duplicate_answers = 1;");
  266.         break;
  267.  
  268.  
  269.         case ANGLE:
  270.         /*
  271.          @ angle xc,yc,width,start_angle,end_angle,color
  272.          @ width is in x-range
  273.          @ angles are in degrees
  274.          @ not compatible with ''flydraw``
  275.          @ will zoom in/out
  276.          @ if angle size is controlled by command <a href='#slider'>slider</a>, use radians to set limits of slider
  277.          @ in case of a slider, command ''angle`` is always active ,controlled by the previous slider.
  278.          @%angle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%angle 0,0,4,10,135,blue
  279.          @%angle_slider%size 400,400%xrange -10,10%yrange -10,10%# click on the arrow to activate slider%grid 1,1,grey%linewidth 3%fillcolor black%strokecolor yellow%rotationcenter 0,0%fontsize 24%centerstring red,8,click on the arrow to activate slider%slider -pi,pi,400,30,angle degrees,Rotate arrow%arrow 0,0,8,0,8,blue%fillpattern diamond%angle 0,0,4,0,0,red
  280.         */
  281.             for(i=0;i<7;i++){
  282.                 switch(i){
  283.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  284.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  285.                     case 2:double_data[2] = get_real(infile,0);break; /* width x-range ! */
  286.                     case 3:double_data[3] = 0.0174532925*(get_real(infile,0));break; /* start angle in degrees -> radians  */
  287.                     case 4:double_data[4] = 0.0174532925*(get_real(infile,0));break; /* end angle in degrees -> radians */
  288.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  289.                         decimals = find_number_of_digits(precision);
  290.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  291.                         reset();
  292.                     break;
  293.                 }
  294.             }
  295.             if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  296.             /* click_cnt++;*/
  297.  
  298.             break;
  299.  
  300.         case ANIMATE:
  301.         /*
  302.          @ animate
  303.          @ keyword
  304.          @ the animated point is a filled rectangle ; adjust colour with command <code>fillcolor colorname/hexnumber</code>
  305.          @ use linewidth to adjust size of the points
  306.          @ will animate a point on -only- the next <a href='#jsplot'>jsplot/jscurve command</a>. Only a single call to <code>animate</code> is allowed...in case of multiple <code>animate</code> keywords, only the last one is valid
  307.          @ only usable for command jsplot (normal functions or parametric)<br />no other object/thing can be animated -for now
  308.          @ moves repeatedly from <a href='#xrange'>xmin to xmax</a> or in case of a parametric function from <a href='#trange'>tmin to tmax</a>
  309.          @ use commands <a href='#multilinewidth'>multilinewidth</a>, <a href='#multistrokecolor'>multistrokecolor</a> etc in case of multiple animated functions.<br/ >use multiple functions as argument in a single call to <a href='#jsplot'>jsplot color,fun1,fun2,fun3...fun_n</a>
  310.          @%animate_1%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)
  311.          @%animate_2%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%multistrokecolors blue,blue,green,green,orange,orange%multilinewidth 2,2,3,3,1,1%jsplot blue,7*cos(x),5*sin(2*x),9*sin(x),5*cos(x),x^2,x
  312.         */
  313.             use_animate++;
  314.             if( use_animate == 1 ){
  315.             fprintf(js_include_file,"\nvar trace_canvas  = create_canvas%d(%d,xsize,ysize);\
  316.             var trace_ctx = trace_canvas.getContext('2d');\
  317.             trace_ctx.fillStyle = 'rgba(%s,%f)';\
  318.             trace_ctx.strokeStyle = 'rgba(%s,%f)';\
  319.             trace_ctx.lineWidth = %d;var anim_pos = 0;\n\
  320.             function animate_this(){\
  321.              var sync;\
  322.              var synchrone = Math.floor(animation_steps/animation_funs);\
  323.              trace_ctx.clearRect(0,0,xsize,ysize);\
  324.              for(var p=0; p<animation_funs;p++){\
  325.               sync = p*synchrone;\
  326.               trace_ctx.fillRect(x_anim_points[sync+anim_pos]-%d, y_anim_points[sync+anim_pos]-%d,%d,%d);\
  327.              };\
  328.              setTimeout(function(){\
  329.               requestAnimationFrame(animate_this);  anim_pos++;}, 50\
  330.              );\
  331.              if(anim_pos >= animation_steps){anim_pos = 0;};\
  332.              };",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);
  333.             }
  334.             else
  335.             {
  336.                 canvas_error("animate can only be used once<br />multiple curves may be animated using something like:<br />jsplot red,sin(x),cos(x),x^2,sin(2*x)");
  337.             }
  338.             break;
  339.  
  340.         case ARC:
  341.         /*
  342.          @ arc xc,yc,x-width,y-height,start_angle,end_angle,color
  343.          @ can not be set ''onclick`` or ''drag xy``
  344.          @ compatible with ''flydraw``
  345.          @ attention: width &amp; height in x/y-range
  346.          @ better use command <a href='#angle'>angle</a> for use with a <a href='#slider'>slider</a>
  347.          @%arc%size 400,400%xrange -10,10%yrange -10,10%arc 0,0,4,4,10,135,red%zoom blue
  348.          @%arc_filled%size 400,400%xrange -10,10%yrange -10,10%opacity 255,60%filled%fillcolor green%arc 0,0,4,4,10,135,red
  349.         */
  350.             for(i=0;i<7;i++){
  351.                 switch(i){
  352.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  353.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  354.                     case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */
  355.                     case 3:double_data[3] = get_real(infile,0);break; /* height y-range no pixels ! */
  356.                     case 4:double_data[4] = get_real(infile,0);break; /* start angle in degrees */
  357.                     case 5:double_data[5] = get_real(infile,0);break; /* end angle in degrees */
  358.                     case 6:stroke_color = get_color(infile,1);/* name or hex color */
  359.                     /* in Shape library:
  360.                         x[0] = x[1] = xc = double_data[0]
  361.                         y[0] = y[1] = yc = double_data[1]
  362.                         w[0] = width = double_data[2]
  363.                         w[1] = height = double_data[3]
  364.                         h[0] = start_angle = double_data[4]
  365.                         h[1] = end_angle = double_data[5]
  366.                     */
  367.                         decimals = find_number_of_digits(precision);
  368.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  369.                         reset();
  370.                     break;
  371.                 }
  372.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  373.                 /* click_cnt++;*/
  374.  
  375.             }
  376.             break;
  377.         case ARROW:
  378.         /*
  379.         @ arrow x1,y1,x2,y2,h,color
  380.         @ alternative: <code>vector</code>
  381.         @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color ''color``
  382.         @ use command <code>linewidth int</code> to adjust thickness of the arrow
  383.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  384.         @%arrow_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%arrow 0,0,4,3,8,blue%drag xy%arrow 0,0,-4,3,8,green%drag xy%arrow 0,0,4,-3,8,orange%drag xy%arrow 0,0,-4,-3,8,cyan
  385.         @%arrow_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%arrow 0,0,4,4,8,blue%onclick%arrow 0,0,-4,5,8,green%onclick%arrow 0,0,4,-6,8,orange%onclick%arrow 0,0,-4,-2,8,cyan
  386.         */
  387.             for(i=0;i<6;i++){
  388.                 switch(i){
  389.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  390.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  391.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  392.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  393.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  394.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  395.                         decimals = find_number_of_digits(precision);
  396.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  397.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  398.                         /* click_cnt++;*/
  399.                         reset();
  400.                         break;
  401.                 }
  402.             }
  403.             break;
  404.  
  405.         case ARROWS:
  406.         /*
  407.         @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n
  408.         @ alternative: <code>vectors</code>
  409.         @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color ''color``.
  410.         @ use command <code>linewidth int</code> to adjust thickness of the arrow
  411.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  412.         @%arrows_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%arrows red,8,0,0,4,3,0,0,2,4,0,0,-2,4,0,0,-3,-4,0,0,3,-2%
  413.         @%arrows_drag%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%arrows red,8,0,0,4,3,0,0,2,4,0,0,-2,4,0,0,-3,-4,0,0,3,-2%
  414.         @%arrows_drag_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%# Click arrow(s) to activate %slider 0,2*pi,300,30,angle degrees,Rotate%slider -5,5*pi,300,30,x display,move in x-direction%slider -10,10*pi,300,30,y display,move in y-direction%arrows red,8,0,0,4,3,0,0,2,4,0,0,-2,4,0,0,-3,-4,0,0,3,-2%
  415.         */
  416.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  417.             fill_color = stroke_color;
  418.             arrow_head = (int) get_real(infile,0);/* h */
  419.             i=0;
  420.             while( ! done ){     /* get next item until EOL*/
  421.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  422.                 if(i%2 == 0 ){
  423.                     double_data[i] = get_real(infile,0); /* x */
  424.                 }
  425.                 else
  426.                 {
  427.                     double_data[i] = get_real(infile,1); /* y */
  428.                 }
  429.                 i++;
  430.             }
  431.             decimals = find_number_of_digits(precision);
  432.             for(c = 0 ; c < i-1 ; c = c+4){
  433.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  434.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  435.                 /* click_cnt++; */
  436.             }
  437.             reset();
  438.             break;
  439.  
  440.         case ARROW2:
  441.         /*
  442.         @ arrow2 x1,y1,x2,y2,h,color
  443.         @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color ''color``
  444.         @ use command <code>arrowhead int</code> to adjust the arrow head size
  445.         @ use command <code>linewidth int</code> to adjust thickness of the arrow
  446.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  447.         @%arrow2%size 400,400%xrange -10,10%yrange -10,10%drag xy%arrow2 0,0,4,3,8,blue%
  448.         */
  449.             for(i=0;i<6;i++){
  450.                 switch(i){
  451.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  452.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  453.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  454.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  455.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  456.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  457.                         decimals = find_number_of_digits(precision);
  458.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  459.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  460.                         /* click_cnt++;*/
  461.                         reset();
  462.                         break;
  463.                 }
  464.             }
  465.             break;
  466.  
  467.         case ARROWS2:
  468.         /*
  469.         @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n
  470.         @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color ''color``
  471.         @ use command <code>linewidth int</code> to adjust thickness of the arrows
  472.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  473.         @%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%
  474.         */
  475.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  476.             fill_color = stroke_color;
  477.             arrow_head = (int) get_real(infile,0);/* h */
  478.             i=0;
  479.             while( ! done ){     /* get next item until EOL*/
  480.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  481.                 if(i%2 == 0 ){
  482.                     double_data[i] = get_real(infile,0); /* x */
  483.                 }
  484.                 else
  485.                 {
  486.                     double_data[i] = get_real(infile,1); /* y */
  487.                 }
  488.                 i++;
  489.             }
  490.             decimals = find_number_of_digits(precision);
  491.             for(c = 0 ; c < i-1 ; c = c+4){
  492.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  493.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  494.                 /* click_cnt++; */
  495.  
  496.             }
  497.             reset();
  498.             break;
  499.         case ARROWHEAD:
  500.         /*
  501.         @ arrowhead int
  502.         @ default 8 (pixels)
  503.         */
  504.             arrow_head = (int) (get_real(infile,1));
  505.             break;
  506.  
  507.         case AUDIO:
  508.         /*
  509.         @ audio x,y,w,h,loop,visible,audiofile location
  510.         @ x,y: left top corner of audio element (in xrange / yrange)
  511.         @ w,y: width and height in pixels
  512.         @ loop: 0 or 1 ( 1 = loop audio fragment)
  513.         @ visible: 0 or 1 (1 = show controls)
  514.         @ audio format may be in *.mp3 or *.ogg
  515.         @ If you are using *.mp3: be aware that FireFox will not (never) play this ! (Pattented format)
  516.         @ if you are using *.ogg: be aware that Microsoft based systems not support it natively
  517.         @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
  518.         */
  519.             if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
  520.             for(i=0;i<7;i++){
  521.                 switch(i){
  522.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  523.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  524.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  525.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  526.                     case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
  527.                     case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
  528.                     case 6:
  529.                     temp = get_string(infile,1);
  530.                     if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
  531.                     if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
  532.                     string_length = 1 + 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);
  533.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  534.                     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);
  535.                     add_to_buffer(tmp_buffer);
  536.                     break;
  537.                     default:break;
  538.                 }
  539.             }
  540.             reset();
  541.             break;
  542.  
  543.  
  544.         case AXIS_NUMBERING:
  545.         /*
  546.             @ axisnumbering
  547.             @ keyword (no arguments required)
  548.             @ 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>
  549.             @ to be used before command grid (see <a href="#grid">command grid</a>)
  550.         */
  551.             use_axis_numbering++;
  552.             break;
  553.         case AXIS:
  554.         /*
  555.             @ axis
  556.             @ keyword (no arguments required)
  557.             @ to be used before command grid (see <a href="#grid">command grid</a>)
  558.  
  559.         */
  560.             use_axis = TRUE;
  561.             break;
  562.  
  563.         case BARCHART:
  564.         /*
  565.         @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
  566.         @ may <b>only</b> to be used together with command <a href='#grid'>grid</a>
  567.         @ 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>
  568.         @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner
  569.         @ multiple barchart command may be used in a single script
  570.         @ also see command <a href='#piechart'>piechart</a>
  571.         @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble...
  572.         @%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
  573.         */
  574.             temp = get_string(infile,1);
  575.             if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
  576.             fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
  577.             barchart_cnt++;
  578.             reset();
  579.             break;
  580.  
  581.         case BEZIER:
  582.         /*
  583.         @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end
  584.         @ draw a bezier curve between points, starting from (x_start:y_start)
  585.         @ can <b>not</b> be dragged or set onclick
  586.         */
  587.             if( js_function[DRAW_BEZIER] != 1 ){ js_function[DRAW_BEZIER] = 1;}
  588.             decimals = find_number_of_digits(precision);
  589.             for(i = 0 ; i < 9; i++){
  590.                 switch(i){
  591.                     case 0: stroke_color = get_color(infile,0);break;
  592.                     case 1: double_data[0] = get_real(infile,0);break;/* start x */
  593.                     case 2: double_data[1] = get_real(infile,0);break;/* start y */
  594.                     case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */
  595.                     case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */
  596.                     case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */
  597.                     case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */
  598.                     case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */
  599.                     case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */
  600.                         string_length = 1 + 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);
  601.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  602.                         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);
  603.                         add_to_buffer(tmp_buffer);
  604.                         break;
  605.                     default: break;
  606.                 }
  607.             }
  608.             reset();
  609.             break;
  610.  
  611.  
  612.         case BGCOLOR:
  613.         /*
  614.          @ bgcolor colorname or #hex
  615.          @ use this color as background of the "div" containing the canvas(es)
  616.          @%bgcolor%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue
  617.         */
  618.         /* [255,255,255]*/
  619.             bgcolor = get_string(infile,1);
  620.             if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
  621.                 int found = 0;
  622.                 for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  623.                     if( strcmp( colors[i].name , bgcolor ) == 0 ){
  624.                         bgcolor = colors[i].hex;
  625.                         found = 1;
  626.                         break;
  627.                     }
  628.                 }
  629.                 if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list: use hexcolor...something like #a0ffc4");}
  630.             }
  631.             fprintf(js_include_file,"/* set background color of canvas div */\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
  632.             break;
  633.  
  634.         case BGIMAGE:
  635.         /*
  636.          @ bgimage image_location
  637.          @ use an image as background; technical: we use the background of ''canvas_div``
  638.          @ the background image will be resized to match "width = xsize" and "height = ysize"
  639.          @%bgimage%size 400,400%xrange -10,10%yrange -10,10%bgimage https://wims.unice.fr/wims/gifs/en.gif
  640.         */
  641.         URL = get_string(infile,1);
  642.         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);
  643.             break;
  644.  
  645.         case BLINK:
  646.         /*
  647.          @ blink time(seconds)
  648.          @ NOT IMPLEMETED -YET
  649.         */
  650.             break;
  651.  
  652.         case BOXPLOT:
  653.         /*
  654.         @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max
  655.         @ example:<br /><code>xrange 0,300<br />yrange 0,10<br />boxplot x,4,8,120,160,170,220,245</code><br />meaning: create a boxplot in x-direction, with height 4 (in yrange) and centered around line y=8
  656.         @ example:<br /><code>xrange 0,10<br />yrange 0,300<br />boxplot y,4,8,120,160,170,220,245</code><br />meaning: create a boxplot in y-direction, with width 4 (in xrange) and centered around line x=8
  657.         @ 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
  658.         @ use command <a href='#fillpattern'>fillpattern some_pattern</a> to use a (diamond for Q1, hatch for Q3) pattern.
  659.         @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of stroke and fill colours
  660.         @ use command <a href='#legend'>legend</a> to automatically create a legend <br />unicode allowed in legend<br />use command <a href='#fontfamily'>fontfamily</a> to set the font of the legend.
  661.         @ there is no limit to the number of boxplots used.
  662.         @ can <b>not</b> be set draggable and <a href='#onclick'>onclick</a> is not ready yet
  663.         @ 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)
  664.         @ use keyword <a href="#userboxplotdata">userboxplotdata</a> before command boxplot, if a pupil must generate the data by some means.
  665.         @ use command <a href="#boxplotdata">boxplotdata</a> when the boxplot should be drawn from wims-generated raw statistical date
  666.         @%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
  667.         @%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
  668.         @%boxplot_3%size 400,400%xrange 0,100%yrange 0,10%fillpattern hatch%linewidth 3%fillcolor red%strokecolor green%boxplot x,1,2,4,14,27,39,66%strokecolor blue%boxplot x,1,4,15,45,50,66,87%strokecolor red%boxplot x,1,6,45,70,80,90,100%strokecolor orange%boxplot x,1,8,28,38,48,56,77%mouse red,16
  669.         */
  670.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  671.             for(i=0;i<8;i++){
  672.                 switch(i){
  673.                     case 0: temp = get_string_argument(infile,0);
  674.                             if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */
  675.                     case 1: double_data[0] = get_real(infile,0);break;/* height | width  */
  676.                     case 2:
  677.                     if( js_function[DRAW_JSBOXPLOT] == 0 ){
  678.                      double_data[1] = get_real(infile,0);
  679.                      fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */
  680.                     }
  681.                     else
  682.                     {
  683.                      double_data[1] = get_real(infile,1);
  684.                      double_data[2] = 1;
  685.                      double_data[3] = 1;
  686.                      double_data[4] = 1;
  687.                      double_data[5] = 1;
  688.                      double_data[6] = 1;
  689.                      double_data[7] = 1;
  690.                      i=8;
  691.                     }
  692.                     break;/* center value x or y */
  693.                     case 3: double_data[2] = get_real(infile,0); break;/* min */
  694.                     case 4: double_data[3] = get_real(infile,0); break;/* Q1 */
  695.                     case 5: double_data[4] = get_real(infile,0); break;/* median */
  696.                     case 6: double_data[5] = get_real(infile,0); break;/* Q3 */
  697.                     case 7: double_data[6] = get_real(infile,1); break;/* max */
  698.                     default:break;
  699.                 }
  700.             }
  701.             decimals = find_number_of_digits(precision);
  702.             /*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)*/
  703.             string_length = 1 + 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]);
  704.             check_string_length(string_length);
  705.             tmp_buffer = my_newmem(string_length);
  706.             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]);
  707.             add_to_buffer(tmp_buffer);
  708.             boxplot_cnt++;
  709.             reset();
  710.         break;
  711.         case BOXPLOTDATA:
  712.         /*
  713.         @ boxplotdata some_data
  714.         @ ''some_data``are a list of numbers separated by a comma "," (items)
  715.         @ only be used before command <code>boxplot</code>: the command <a href="#boxplot">boxplot</a> will provide the boxplot drawing of the data.
  716.         @ 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
  717.         @ note: wims will not check your data input | format. use js-error console to debug any problems.
  718.         @ a javascript function <code>statistics()</code> will parse the data and calculate the values [min,Q1,median,Q3,max] and hand them to the boxplot draw function.
  719.         @ only a single call to <code>boxplotdata</code> can be made. If multiple boxplots should be present in a single canvas, then use multiple calls to command <a href='#boxplot'>boxplot</a>
  720.         @%boxplotdata%size 400,400%xrange 0,100%yrange 0,10%strokecolor orange%fillpattern hatch%linewidth 3%strokecolor green%boxplotdata 11,22,13,15,23,43,12,12,14,2,45,32,44,13,21,24,13,19,35,21,24,23%boxplot x,2,2%mouse red,16
  721.         */
  722.             if( js_function[DRAW_JSBOXPLOT] != 1 ){ js_function[DRAW_JSBOXPLOT] = 1;}
  723.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  724.             fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1));
  725.  
  726.         break;
  727.  
  728.         case CANVASTYPE:
  729.          canvas_type = (int) (get_real(infile,1));
  730.         /*
  731.         @ canvastype TYPE
  732.         @ for now only useful before commands filltoborder / floodfill / clickfill etc operations<br />Only the images of this TYPE will be scanned and filled
  733.         @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas)
  734.         @ use another TYPE, if you know what you are doing...
  735.         @ 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>
  736.         */
  737.         break;
  738.  
  739.         case CENTERSTRING:
  740.         /*
  741.          @ centerstring color,y-value,the text string
  742.          @ title color,y-value,the text string
  743.          @ draw a string centered on the canvas at y = y-value
  744.          @ can not be set ''onclick`` or ''drag xy`` (...)
  745.          @ unicode supported: <code>centerstring red,5,\\u2232</code>
  746.          @ use a command like <code>fontfamily italic 24pt Ariel</code> to set fonts on browser that support font change
  747.          @%centerstring%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue%fontfamily italic 22pt Courier%centerstring blue,7,the center
  748.         */
  749.             if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;}
  750.             for(i=0;i<3;i++){
  751.                 switch(i){
  752.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  753.                     case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
  754.                     case 2: temp = get_string_argument(infile,1);
  755.                             /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
  756.                             decimals = find_number_of_digits(precision);
  757.                             string_length = 1 + snprintf(NULL,0,
  758.                             "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
  759.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  760.                             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);
  761.                             add_to_buffer(tmp_buffer);
  762.                             break;
  763.                     default:break;
  764.                 }
  765.             }
  766.             break;
  767.  
  768.  
  769.         case CIRCLE:
  770.         /*
  771.         @ circle xc,yc,width (2*r in pixels),color
  772.         @ alernative: use command <code>fcircle xc,yc,d,color</code> for a filled circle.
  773.         @ use command <code>fillcolor color</code> to set the fillcolor.
  774.         @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a>
  775.         @ will shrink / expand on zoom out / zoom in.
  776.         @%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
  777.         */
  778.             for(i=0;i<4;i++){
  779.                 switch(i){
  780.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  781.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  782.                     case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out: radius in 'dx' xrange*/
  783.                     case 3: stroke_color = get_color(infile,1);/* name or hex color */
  784.                         decimals = find_number_of_digits(precision);
  785.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  786.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  787.                         /* click_cnt++;*/
  788.                         reset();
  789.                         break;
  790.                     default : break;
  791.                 }
  792.             }
  793.             break;
  794.  
  795.         case CIRCLES:
  796.         /*
  797.         @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n
  798.         @ <b>attention</b> r = radius in x-range (!)
  799.         @ use keyword <code>filled</code> or command <code>fcircles</code> to produce solid circles
  800.         @ alternative: disks for filled circles
  801.         @ use command <code>fillcolor color</code> to set the fillcolor
  802.         @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> (individually)
  803.         @ will shrink / expand on zoom out / zoom in
  804.         @%circles_drag%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
  805.         @%circles_onclick%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%onclick%circles blue,0,0,2,2,2,3,-3,-3,3,3,3,4,3,-4,2%zoom red
  806.         @%circles_drag_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%# Click circles(s) to activate%opacity 200,50%fillcolor orange%rotationcenter 2,3%slider 0,2*pi,300,30,angle degrees,Rotate%slider -5,5*pi,300,30,x display,move in x-direction%slider -10,10*pi,300,30,y display,move in y-direction%fcircles blue,0,0,0.5,2,2,1,-3,-3,1.5,3,3,0.5,3,-4,0.5
  807.         */
  808.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  809.             fill_color = stroke_color;
  810.             i=1;
  811.             while( ! done ){     /* get next item until EOL*/
  812.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  813.                 switch (i%3){
  814.                  case 1:double_data[i-1] = get_real(infile,0);break; /* x */
  815.                  case 2:double_data[i-1] = get_real(infile,0);break; /* y */
  816.                  case 0:double_data[i-1] = get_real(infile,1);break; /* r */
  817.                 }
  818.                 i++;
  819.             }
  820.             decimals = find_number_of_digits(precision);
  821.             for(c = 0 ; c < i-1 ; c = c+3){
  822.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  823.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  824.                 /* click_cnt++; */
  825.             }
  826.             reset();
  827.             break;
  828.         case CLEARBUTTON:
  829.         /*
  830.          @ clearbutton value
  831.          @ alternative: <code>delete</code>
  832.          @ alternative: <code>erase</code>
  833.          @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text ''value``.
  834.          @ <b>attention</b> command <code>clearbutton</code> is incompatible with <a href="#multidraw">multidraw</a> based drawings (in <code>multidraw</code>, there is a remove_object_button for every draw primitive).
  835.          @ normally <a href="#userdraw">userdraw</a> primitives have the option to use middle/right mouse button on a point of the object to remove this specific object...this clear button will remove all drawings
  836.          @ uses the tooltip placeholder div element: may not be used with command <code>intooltip</code>
  837.          @ use command <a href="#inputstyle">inputstyle</a> to style the button...
  838.          @ the clearbutton will have id="canvas_scripts[%d]" ; starting with %d=0 for the first script to change the style of all ''clearbutton`` of all included canvasdraw scripts, use something like<br /><code>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;</code> or <code>document.getElementById("clearbutton"+canvas_scripts[p]).setAttribute("style","some_style"); &minus;&minus;&gt;<br />&nbsp;&nbsp;p++;<br />&nbsp;};<br />};</code>
  839.          @%clearbutton%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%userdraw circles,red%clearbutton Remove All
  840.         */
  841.         if(reply_format == 29){/* eg multidraw is selected */
  842.         // canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw");
  843.         }
  844.             add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1));
  845.         break;
  846.  
  847.         case CLOCK:
  848.         /*
  849.         @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
  850.         @ use command <code>opacity stroke-opacity,fill-opacity</code> to adjust foreground (stroke) and background (fill) transparency
  851.         @ type hourglass:<br />type = 0: only segments<br />type = 1: only numbers<br />type = 2: numbers and segments
  852.         @ 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
  853.         @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
  854.         @ 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>
  855.         @ canvasdraw will not check validity of colornames...the javascript console is your best friend
  856.         @ no combinations with other reply_types allowed, for now
  857.         @ 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
  858.         @ 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
  859.         @ note: clocks will not zoom or pan, when using command <a href='#zoom'>zoom</a>
  860.         @%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
  861.         @%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
  862.         @%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
  863.         @%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
  864.         @%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
  865.         @%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
  866.         @%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
  867.         */
  868.             if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
  869.  
  870.         /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
  871.             for(i=0;i<9;i++){
  872.              switch(i){
  873.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
  874.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
  875.               case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
  876.               case 3: int_data[3] = get_real(infile,0);break;/* hours */
  877.               case 4: int_data[4] = get_real(infile,0);break;/* minutes */
  878.               case 5: int_data[5] = get_real(infile,0);break;/* seconds */
  879.               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 */
  880.               case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/
  881.                 switch(int_data[7]){
  882.                     case 0:break;
  883.                     case 1:if(clock_cnt == 0){
  884.                            if( reply_format == 0 ){
  885.                             reply_format = 18; /* user sets clock */
  886.                             /* string_length = 1 + 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");
  887.                                check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  888.                                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");
  889.                                add_to_buffer(tmp_buffer);
  890.                            */
  891.                             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");
  892.                            }
  893.                            else
  894.                            {
  895.                             canvas_error("interactive clock may not be used together with other reply_types...");
  896.                            }
  897.                           }
  898.                           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);
  899.                     break;
  900.                     case 3:if(clock_cnt == 0){
  901.                             if( reply_format == 0 ){
  902.                              reply_format = 18; /* user sets clock */
  903.                              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");
  904.                             }
  905.                             else
  906.                             {
  907.                              canvas_error("interactive clock may not be used together with other reply_types...");
  908.                             }
  909.                            }
  910.                             /*
  911.                             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);
  912.                            */
  913.                     break;
  914.                     case 2:if( reply_format == 0 ){
  915.                                 reply_format = 19; /* "onclick */
  916.                                 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");
  917.                             }
  918.                             else
  919.                             {
  920.                                 if( reply_format != 19){
  921.                                    canvas_error("clickable clock(s) may not be used together with other reply_types...");
  922.                                  }
  923.                             }
  924.                      break;
  925.                      default: canvas_error("interactive must be set 0,1 or 2");break;
  926.                 }
  927.                 break;
  928.                 case 8:
  929.                         if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock(), for now it's OK */
  930.                             fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
  931.                         }
  932.                         temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/
  933.                         if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
  934.                         else{
  935.                         /* h_color,m_color,s_color,bg_color,fg_color */
  936.                         temp = ",black\",\"black\",\"black\",\"white\",\"black";}
  937.                         string_length = 1 + 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);
  938.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  939.                         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);
  940.                         add_to_buffer(tmp_buffer);
  941.                         fprintf(js_include_file,"var clocks%d;",clock_cnt);
  942.                         clock_cnt++;
  943.                         break;
  944.                 default:break;
  945.              }
  946.             }
  947.             break;
  948.  
  949.  
  950.         case COLORPALETTE:
  951.         /*
  952.          @ colorpalette color_name_1,color_name_2,...,color_name_8
  953.          @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a>
  954.          @ 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
  955.          @ make sure to include the ''remove button`` by using command <a href='#clearbutton'>clearbutton some_text</a>
  956.         */
  957.             if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");}
  958.             fprintf(js_include_file,"var multifillcolors = [];var palettecolors = [");
  959.             while( ! done ){
  960.                 temp = get_color(infile,1);
  961.                 fprintf(js_include_file,"\"%s\",",temp);
  962.             }
  963.             fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */
  964.             add_color_palette(js_include_file,canvas_root_id,input_style);
  965.             break;
  966.  
  967.         case COPY:
  968.         /*
  969.         @ copy x,y,x1,y1,x2,y2,[filename URL]
  970.         @ The image may be "bitmap" or "SVG"
  971.         @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
  972.         @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
  973.         @ [filename] is the URL of the image
  974.         @ URL is normal URL of network reachable image file location (eg special url for ''classexo`` not -yet- implemented)
  975.         @ if command <a href="#drag">drag x/y/xy</a> is set before command ''copy``, the images will be draggable. Javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images. 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 <code>snaptopoints x1,y1,x2,y2...</code>.
  976.         @ 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
  977.         @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves etc)
  978.         @ you may draw / userdraw / drag other stuff on top of an "imported" image
  979.         @ when set draggable, there will be special function <code>read_canvas_images()</code> now dragging external images may be combined with <code>read_canvas()</code> from <a href='#userdraw'>userdraw</a> or <a href='#multidraw'>multidraw</a>. Set command <a href='#precision'>precision</a> before command ''copy``<br />note: when dragging the image anchor is the center of the picture, this cannot be changed (it is a feature and not a flaw!)
  980.         @ use keyword <a href='#centered'>centered</a> before command ''copy`` to place image center at given coordinates.
  981.         @%copy_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%copy -5,5,-1,-1,-1,-1,gifs/fr.gif%onclick%copy 5,5,-1,-1,-1,-1,gifs/en.gif%onclick%copy 5,-5,-1,-1,-1,-1,gifs/it.gif%onclick%copy -5,-5,-1,-1,-1,-1,gifs/cn.gif
  982.         @%copy_drag_xy%size 400,400%xrange -10,10%yrange -10,10%# attention: left mouse click on the image will activate dragging...%# keep left mouse button pressed while moving the image !%drag xy%copy -5,5,-1,-1,-1,-1,gifs/fr.gif%drag xy%copy 5,5,-1,-1,-1,-1,gifs/en.gif%drag xy%copy 5,-5,-1,-1,-1,-1,gifs/it.gif%drag xy%copy -5,-5,-1,-1,-1,-1,gifs/cn.gif
  983.         @%copy_drag_xy_snaptogrid%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%# attention: left mouse click on the image will activate dragging...%# keep left mouse button pressed while moving the image !%drag xy%# a function read_canvas_images() %copy -6,6,-1,-1,-1,-1,gifs/fr.gif%snaptogrid%drag xy%copy 6,6,-1,-1,-1,-1,gifs/en.gif%snaptogrid%drag xy%copy 6,-6,-1,-1,-1,-1,gifs/it.gif%snaptogrid%drag xy%copy -6,-6,-1,-1,-1,-1,gifs/cn.gif
  984.         */
  985.             for(i = 0 ; i<7;i++){
  986.                 switch(i){
  987.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
  988.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
  989.                     case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
  990.                     case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
  991.                     case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
  992.                     case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
  993.                     case 6: URL = get_string(infile,1);
  994.                             int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
  995.                             int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
  996.                             if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  997.                             int_data[9] = click_cnt;
  998.                             if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
  999.                                  //if( reply_format == 0 ){ reply_format = 20; }
  1000.                                  int_data[8] = 2;/* drag & drop */
  1001.                                  if(use_offset == 0 ){use_offset = 4;} /* mouse is attached to the center of the image !! */
  1002.                             }
  1003.                             else
  1004.                             {
  1005.                                 if( onclick == 1  ){
  1006.                                 //    reply_format = 20;
  1007.                                     int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
  1008.                                     click_cnt++; /* will also be used in dragstuff ! */
  1009.                                 }
  1010.                                 else
  1011.                                 {
  1012.                                     int_data[8] = 0; /* just static image */
  1013.                                 }
  1014.                             }
  1015.                             if( include_special_OEF_reply == FALSE){
  1016.                              if( int_data[8] == 1 || int_data[8] == 2 ){
  1017.                               include_special_OEF_reply = TRUE;
  1018.                               fprintf(js_include_file,"\
  1019.                               \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\
  1020.                               read_canvas_images = function(){\
  1021.                                var prec = %d;\
  1022.                                var len  = ext_drag_images.length;\
  1023.                                var reply = new Array(len);\
  1024.                                for(var p = 0 ; p < len ; p++){\
  1025.                                 var img = ext_drag_images[p];\
  1026.                                 reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  1027.                                };\
  1028.                                return reply;\
  1029.                               };\n\
  1030.                               /* end function 34 read_canvas_images() */",reply_precision);
  1031.                              }
  1032.                             }
  1033. /*
  1034. function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt,centered,use_snap){\
  1035. */
  1036.                             string_length = 1 + snprintf(NULL,0,  "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9],use_offset,use_snap);
  1037.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1038.                             snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9],use_offset,use_snap);
  1039.                             add_to_buffer(tmp_buffer);
  1040.                             drag_type = -1; /* reset the drag_type indicator */
  1041.                             ext_img_cnt++;
  1042.                             onclick=0;
  1043.                             use_offset=0;
  1044.                             reset();
  1045.                             break;
  1046.                     default: break;
  1047.                 }
  1048.             }
  1049.             break;
  1050. /*
  1051. HTML5 specs:
  1052. context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  1053. img     Specifies the image, canvas, or video element to use
  1054. sx      The x coordinate where to start clipping: x1 = int_data[0]
  1055. sy      The y coordinate where to start clipping: x2 = int_data[1]
  1056. swidth  The width of the clipped image: int_data[2] - int_data[0]
  1057. sheight The height of the clipped image: int_data[3] - int_data[1]
  1058. x       The x coordinate where to place the image on the canvas: dx1 = int_data[4]
  1059. y       The y coordinate where to place the image on the canvas: dy1 = int_data[5]
  1060. width   The width of the image to use (stretch or reduce the image): dx2 - dx1 = int_data[6]
  1061. height  The height of the image to use (stretch or reduce the image): dy2 - dy1 = int_data[7]
  1062. */
  1063.         case COPYRESIZED:
  1064.         /*
  1065.         @ copyresized x1,y1,x2,y2,dx1,dy1,dx2,dy2,image_file_url
  1066.         @ The image may be any "bitmap" or "SVG"
  1067.         @ 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
  1068.         @ (dx1:dy1) must be left top corner; (dx2:dy2) must be right bottom corner of inserted image
  1069.         @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
  1070.         @ 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 !!)
  1071.         @ if command <a href="#drag">drag x/y/xy</a> is set before command ''copy``, the images will be draggable. Javascript <code>function read_canvas();</code> will return the x/y coordinate data in xrange/yrange of all -including non draggable- images. The command drag is only valid for the next image. Draggable / non-draggable images may be mixed. May be used together with preceding keywords ''snaptogrid``, ''xsnaptogrid``, ''ysnaptogrid`` or <code>snaptopoints x1,y1,x2,y2...</code>
  1072.         @ 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
  1073.         @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves etc).
  1074.         @ you may draw / userdraw / drag stuff on top of an "imported" image.
  1075.         @ when set draggable, there will be special function 'read_canvas_images()'<br />now dragging external images may be combined with 'read_canvas()' from <a href='#userdraw'>userdraw</a> or <a href='#multidraw'>multidraw</a><br />set command <a href='#precision'>precision</a> before command ''copy``.
  1076.         @ use keyword <a href='#centered'>centered</a> before command ''copyresized`` to place image center at given coordinates.
  1077.         */
  1078.             for(i = 0 ; i<9;i++){
  1079.                 switch(i){
  1080.                     case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
  1081.                     case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
  1082.                     case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
  1083.                     case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
  1084.                     case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
  1085.                     case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
  1086.                     case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
  1087.                     case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
  1088.                     case 8: URL = get_string(infile,1);
  1089.                             /* flag error when wrong diagonal:  copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */
  1090.                             if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){
  1091.                                 canvas_error("in copyresized , use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! ");
  1092.                             }
  1093.                             int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */
  1094.                             int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */
  1095.                             int_data[6] = abs(int_data[6] - int_data[4]);/* width */
  1096.                             int_data[7] = abs(int_data[7] - int_data[5]);/* height */
  1097.                             if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  1098.                             int_data[9] = click_cnt;
  1099.                             if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
  1100.                                 // if( reply_format == 0 ){ reply_format = 20; }
  1101.                                  int_data[8] = 2;/* drag & drop */
  1102.                             }
  1103.                             else
  1104.                             {
  1105.                                 if( onclick == 1  ){
  1106.                                 //    reply_format = 20;
  1107.                                     int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
  1108.                                     click_cnt++; /* will also be used in dragstuff ! */
  1109.                                 }
  1110.                                 else
  1111.                                 {
  1112.                                     int_data[8] = 0; /* just static image */
  1113.                                 }
  1114.                             }
  1115.                             if( include_special_OEF_reply == FALSE){
  1116.                              if( int_data[8] == 1 || int_data[8] == 2 ){
  1117.                               include_special_OEF_reply = TRUE;
  1118.                               fprintf(js_include_file,"\
  1119.                               \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\
  1120.                               read_canvas_images = function(){\
  1121.                                var prec = %d;\
  1122.                                var len  = ext_drag_images.length;\
  1123.                                var reply = new Array(len);\
  1124.                                for(var p = 0 ; p < len ; p++){\
  1125.                                 var img = ext_drag_images[p];\
  1126.                                 reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  1127.                                };\
  1128.                                return reply;\
  1129.                               };\n\
  1130.                               /* end function 34 read_canvas_images() */",reply_precision);
  1131.                              }
  1132.                             }
  1133.  
  1134. /*
  1135. (URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt)
  1136. URL,[2],[3],[6],    [7], [4],[5],[6],[7],ext_img_cnt,1,    [8],      [9]
  1137. */
  1138.                             string_length = 1 + snprintf(NULL,0,  "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9],use_offset,use_snap);
  1139.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1140.                             snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9],use_offset,use_snap);
  1141.                             add_to_buffer(tmp_buffer);
  1142.                             drag_type = -1; /* reset the drag_type indicator */
  1143.                             ext_img_cnt++;
  1144.                             onclick=0;
  1145.                             use_offset=0;
  1146.                             reset();
  1147.                             break;
  1148.                     default: break;
  1149.                 }
  1150.             }
  1151.             reset();
  1152.             break;
  1153.  
  1154.         case CROSSHAIR:
  1155.         /*
  1156.         @ crosshair x,y,color
  1157.         @ draw a single crosshair point at (x;y) in color ''color``
  1158.         @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust
  1159.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1160.         @%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
  1161.         */
  1162.             for(i=0;i<3;i++){
  1163.                 switch(i){
  1164.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  1165.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  1166.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  1167.                         decimals = find_number_of_digits(precision);
  1168.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  1169.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1170.                         /* click_cnt++ */
  1171.                         reset();
  1172.                         break;
  1173.                     default:break;
  1174.                 }
  1175.             }
  1176.             break;
  1177.  
  1178.         case CROSSHAIRS:
  1179.         /*
  1180.         @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
  1181.         @ draw multiple crosshair points at given coordinates in color ''color``
  1182.         @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust
  1183.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  1184.         @%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
  1185.         @%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
  1186. */
  1187.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1188.             fill_color = stroke_color;
  1189.             i=0;
  1190.             while( ! done ){     /* get next item until EOL*/
  1191.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1192.                 if(i%2 == 0 ){
  1193.                     double_data[i] = get_real(infile,0); /* x */
  1194.                 }
  1195.                 else
  1196.                 {
  1197.                     double_data[i] = get_real(infile,1); /* y */
  1198.                 }
  1199.                 i++;
  1200.             }
  1201.             decimals = find_number_of_digits(precision);
  1202.             for(c=0 ; c < i-1 ; c = c+2){
  1203.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  1204.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1205.                 /* click_cnt++; */
  1206.             }
  1207.             reset();
  1208.             break;
  1209.  
  1210.         case CROSSHAIRSIZE:
  1211.         /*
  1212.         @ crosshairsize int
  1213.         @ default 8 (px)
  1214.         */
  1215.             crosshair_size = (int) (get_real(infile,1));
  1216.             break;
  1217.  
  1218.         case CURSOR:
  1219.         /*
  1220.         @ cursor some CSS cursor_style
  1221.         @ alternative: <code>pointer</code>
  1222.         @ style can be any valid CSS property value
  1223.         @ choose from these types:<br />alias,all-scroll,auto,cell,context-menu,col-resize,copy,crosshair,default,e-resize,<br />ew-resize,grab,grabbing,help,move,n-resize,ne-resize,nesw-resize,ns-resize,nw-resize,<br />nwse-resize,no-drop,none,not-allowed,pointer,progress,row-resize,s-resize,se-resize,<br />sw-resize,text,url(myBall.cur),auto,vertical-text,w-resize,wait,zoom-in,zoom-out,initial
  1224.         @ note: wims will not check the validity of your cursor declaration
  1225.         @%cursor_css%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 3%drag xy%opacity 200,75%fcircles blue,-5,5,3,-4,-2,6,0,0,5,3,4,2,4,-5,4
  1226.         */
  1227.             fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1));
  1228.             break;
  1229.  
  1230.         case CURVE:
  1231.         /*
  1232.          @ curve color,formula(x)
  1233.          @ alternative: <code>plot color,formula(x)</code>
  1234.          @ use command <a href="#trange">trange</a> in parametric functions before command curve / plot <code>trange -pi,pi<br />curve color,formula1(t),formula2(t)</code>
  1235.          @ use command <a href="#precision">precision</a> to increase the number of digits of the plotted points
  1236.          @ use command <a href="#plotsteps">plotsteps</a> to increase / decrease the amount of plotted points (default 150)
  1237.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1238.          @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">jsplot</a> (command ''curve`` will only calculate points within the xrange)
  1239.          @%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)
  1240.         */
  1241.             if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
  1242.                 use_parametric = FALSE;
  1243.                 stroke_color = get_color(infile,0);
  1244.                 char *fun1 = get_string_argument(infile,0);
  1245.                 char *fun2 = get_string_argument(infile,1);
  1246.                 if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
  1247.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,9,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  1248.             }
  1249.             else
  1250.             {
  1251.                 stroke_color = get_color(infile,0);
  1252.                 char *fun1 = get_string_argument(infile,1);
  1253.                 if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  1254.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,9,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  1255.             }
  1256.             if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1257.             /* click_cnt++; */
  1258.             reset();
  1259.             break;
  1260.     case CURVEDARROW:
  1261.     /*
  1262.     @ curvedarrow x1,y1,xc,yc,x2,y2,color
  1263.     @ draw a single headed curved arrow from (x1:y1) in direction of (xc:yc) to point (x2:y2). Note: the curve will <b>not go through</b> point (xc:yc).
  1264.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1265.     @ use command <code>linewidth int</code> to adjust thickness of the arrow.
  1266.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>.
  1267.     @%curvedarrow_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrow -5,0,0,10,5,0,blue
  1268.     @%curvedarrow_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%curvedarrow -5,0,0,-10,5,0,blue%onclick%curvedarrow -8,0,0,5,8,3,green
  1269.  
  1270. h[0] = arrowhead
  1271. h[1] = type: 1 = single 2=double arrow
  1272. function Shape(click_cnt,onclick,direction,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,current_sliders,rotation_center,use_offset,use_pattern)
  1273.     */
  1274.             for(i=0;i<7;i++){
  1275.             switch(i){
  1276.                 case 0: double_data[0] = get_real(infile,0);break; /* x1 */
  1277.                 case 1: double_data[1] = get_real(infile,0);break; /* y1 */
  1278.                 case 2: double_data[2] = get_real(infile,0);break; /* xc */
  1279.                 case 3: double_data[3] = get_real(infile,0);break; /* yc */
  1280.                 case 4: double_data[4] = get_real(infile,0);break; /* y3 */
  1281.                 case 5: double_data[5] = get_real(infile,0);break; /* y3 */
  1282.                 case 6: stroke_color = get_color(infile,1);/* name or hex color */
  1283.                 decimals = find_number_of_digits(precision);
  1284.             fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,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,current_sliders,rotation_center,use_offset,use_pattern);
  1285.             if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1286.             /* click_cnt++;*/
  1287.             reset();
  1288.             break;
  1289.             }
  1290.             }
  1291.             break;
  1292.  
  1293.     case CURVEDARROW2:
  1294.     /*
  1295.     @ curvedarrow2 x1,y1,xc,yc,x2,y2,color
  1296.     @ draw a double headed curved arrow from (x1:y1) in direction of (xc:yc) to point (x2:y2)<br /> note: the curve will <b>not go through</b> point (xc:yc)
  1297.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1298.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1299.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1300.     @%curvedarrow_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrow2 -5,0,0,10,5,0,blue
  1301.     @%curvedarrow_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%cuvedarrow2 -5,0,0,-10,5,0,blue%onclick%curvedarrow -8,0,0,5,8,3,green
  1302.  
  1303. h[0] = arrowhead
  1304. h[1] = type: 1 = single 2=double arrow
  1305. function Shape(click_cnt,onclick,direction,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,current_sliders,rotation_center,use_offset,use_pattern)
  1306.     */
  1307.             for(i=0;i<7;i++){
  1308.             switch(i){
  1309.                 case 0: double_data[0] = get_real(infile,0);break; /* x1 */
  1310.                 case 1: double_data[1] = get_real(infile,0);break; /* y1 */
  1311.                 case 2: double_data[2] = get_real(infile,0);break; /* xc */
  1312.                 case 3: double_data[3] = get_real(infile,0);break; /* yc */
  1313.                 case 4: double_data[4] = get_real(infile,0);break; /* y3 */
  1314.                 case 5: double_data[5] = get_real(infile,0);break; /* y3 */
  1315.                 case 6: stroke_color = get_color(infile,1);/* name or hex color */
  1316.                 decimals = find_number_of_digits(precision);
  1317.             fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,2,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,current_sliders,rotation_center,use_offset,use_pattern);
  1318.             if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1319.             /* click_cnt++;*/
  1320.             reset();
  1321.             break;
  1322.             }
  1323.             }
  1324.             break;
  1325.     case CURVEDARROWS:
  1326.     /*
  1327.     @ curvedarrows color,x1,y1,xc,yc,x2,y2,...,x_(n-1),y_(n-1),xc,yc,x_n,y_n
  1328.     @ draw curved arrows from (x1:y1) in direction of (xc:yc) to point (x2:y2), etc<br /> note: the curve will <b>not go through</b> point (xc:yc)
  1329.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1330.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1331.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1332.     @%curvedarrows_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrows red,-8,0,0,8,8,0,-5,5,0,-10,6,3
  1333.     @%curvedarrows_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%curvedarrows red,-8,0,0,8,8,0,-5,5,0,-10,6,3
  1334.  
  1335. h[0] = arrowhead
  1336. h[1] = type: 1 = single 2=double arrow
  1337. function Shape(click_cnt,onclick,direction,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,current_sliders,rotation_center,use_offset,use_pattern)
  1338.     */
  1339.         stroke_color = get_color(infile,0);/* name or hex color */
  1340.         i = 0;
  1341.         decimals = find_number_of_digits(precision);
  1342.         while( ! done ){
  1343.         if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1344.         double_data[0] = get_real(infile,0); /* x1 */
  1345.         double_data[1] = get_real(infile,0); /* y1 */
  1346.         double_data[2] = get_real(infile,0); /* xc */
  1347.         double_data[3] = get_real(infile,0); /* yc */
  1348.         double_data[4] = get_real(infile,0); /* x3 */
  1349.         double_data[5] = get_real(infile,1); /* y3 */
  1350.         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,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,current_sliders,rotation_center,use_offset,use_pattern);
  1351.         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1352.         i = i + 6;
  1353.             }
  1354.             reset();
  1355.             break;
  1356.  
  1357.     case CURVEDARROWS2:
  1358.     /*
  1359.     @ curvedarrows2 color,x1,y1,xc,yc,x2,y2,...x_(n-1),y_(n-1),xc,yc,x_n,y_n
  1360.     @ draw double headed curved arrows from (x1:y1) in direction of (xc:yc) to point (x2:y2), etc. <br /> note: the curve will <b>not go through</b> point (xc:yc)
  1361.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1362.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1363.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1364.     @%curvedarrows2_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrows2 red,-8,0,0,8,8,0,-5,5,0,-10,6,3
  1365.     @%curvedarrows2_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%curvedarrow -5,0,0,-10,5,0,blue%onclick%curvedarrows2 red,-8,0,0,8,8,0,-5,5,0,-10,6,3
  1366.  
  1367. h[0] = arrowhead
  1368. h[1] = type: 1 = single 2=double arrow
  1369. function Shape(click_cnt,onclick,direction,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,current_sliders,rotation_center,use_offset,use_pattern)
  1370.     */
  1371.         stroke_color = get_color(infile,0);/* name or hex color */
  1372.         i = 0;
  1373.         decimals = find_number_of_digits(precision);
  1374.         while( ! done ){
  1375.         if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1376.         double_data[0] = get_real(infile,0); /* x1 */
  1377.         double_data[1] = get_real(infile,0); /* y1 */
  1378.         double_data[2] = get_real(infile,0); /* xc */
  1379.         double_data[3] = get_real(infile,0); /* yc */
  1380.         double_data[4] = get_real(infile,0); /* x3 */
  1381.         double_data[5] = get_real(infile,1); /* y3 */
  1382.         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,2,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,current_sliders,rotation_center,use_offset,use_pattern);
  1383.         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1384.         i = i + 6;
  1385.             }
  1386.             reset();
  1387.             break;
  1388.         case DASHED:
  1389.         /*
  1390.         @ dashed
  1391.         @ keyword (no arguments required)
  1392.         @ next object will be drawn with a dashed line
  1393.         @ change dashing scheme by using command <a href="#dashtype">dashtype</a>
  1394.         @%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
  1395.         */
  1396.             use_dashed = TRUE;
  1397.             break;
  1398.  
  1399.         case DASHTYPE:
  1400.         /*
  1401.         @ dashtype line_width_px,space_width_px
  1402.         @ every indiviual object may have its own dashtype, if needed...
  1403.         @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype
  1404.         @ default value <code>dashtype 2,2</code> e.g. 2px line and 2px space
  1405.         @ HTML5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable
  1406.         @%dashtype%size 400,400%xrange -10,10%yrange -10,10%dashtype 1,1%dhline 0,9,red%dashtype 2,2%dhline 0,8,red%dashtype 4,4%dhline 0,7,red%dashtype 6,6%dhline 0,6,red%dashtype 8,8%dhline 0,5,red%dashtype 10,10%dhline 0,4,red%dashtype 1,2%dhline 0,3,red%dashtype 2,4%dhline 0,2,red%dashtype 3,6%dhline 0,1,red%dashtype 4,8%dhline 0,0,red%linewidth 2%dashtype 1,1%dhline 0,-9,red%dashtype 2,2%dhline 0,-8,red%dashtype 4,4%dhline 0,-7,red%dashtype 6,6%dhline 0,-6,red%dashtype 8,8%dhline 0,-5,red%dashtype 10,10%dhline 0,-4,red%dashtype 1,2%dhline 0,-3,red%dashtype 2,4%dhline 0,-2,red%dashtype 4,8%dhline 0,-1,red
  1407.         */
  1408.             for(i=0;i<2;i++){
  1409.                 switch(i){
  1410.                     case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
  1411.                     case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
  1412.                 }
  1413.             }
  1414.         break;
  1415.  
  1416.         case DIAMONDFILL:
  1417.         /*
  1418.         @ diamondfill x0,y0,dx,dy,color
  1419.         @ x0,y0 in xrange / yrange
  1420.         @ distances dx,dy in pixels
  1421.         @ there is also a command <a href="#userdraw">userdraw diamondfill,color</a>
  1422.         @%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
  1423.         */
  1424.             if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
  1425.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1426.              js_function[DRAW_FILLTOBORDER] = 1;
  1427.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1428.             }
  1429.             decimals = find_number_of_digits(precision);
  1430.             for(i=0;i<5;i++){
  1431.                 switch(i){
  1432.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  1433.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  1434.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1435.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1436.                     case 4: stroke_color = get_color(infile,1);
  1437.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  1438.                     string_length = 1 + 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);
  1439.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1440.                     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);
  1441.                     add_to_buffer(tmp_buffer);
  1442.                     fill_cnt++;
  1443.                     break;
  1444.                     default:break;
  1445.                 }
  1446.             }
  1447.             reset();
  1448.         break;
  1449.  
  1450.         case DOTFILL:
  1451.         /*
  1452.         @ dotfill x0,y0,dx,dy,color
  1453.         @ x0,y0 in xrange / yrange
  1454.         @ distances dx,dy in pixels
  1455.         @ radius of dots is linewidth
  1456.         @ there is also a command <a href="#userdraw">userdraw dotfill,color</a>
  1457.         @%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
  1458.         */
  1459.             if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
  1460.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1461.              js_function[DRAW_FILLTOBORDER] = 1;
  1462.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1463.             }
  1464.             decimals = find_number_of_digits(precision);
  1465.             for(i=0;i<5;i++){
  1466.                 switch(i){
  1467.                     case 0: double_data[0] = get_real(infile,0); break; /* x in px */
  1468.                     case 1: double_data[1] = get_real(infile,0); break; /* y in py */
  1469.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1470.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1471.                     case 4: stroke_color = get_color(infile,1);
  1472.                     /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
  1473.                     string_length = 1 + 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);
  1474.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1475.                     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);
  1476.                     add_to_buffer(tmp_buffer);
  1477.                     fill_cnt++;
  1478.                     break;
  1479.                     default:break;
  1480.                 }
  1481.             }
  1482.             reset();
  1483.         break;
  1484.  
  1485.         case DRAG:
  1486.         /*
  1487.          @ drag [x][y][xy]
  1488.          @ the next object will be draggable in x / y / xy direction
  1489.          @ the displacement can be read by <code>javascript:read_dragdrop();</code>
  1490.          @ 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' !
  1491.          @ <a href='#onclick'>onclick</a> and ''drag x|y|xy`` may be combined (for different objects: a single object can either be onclick or drag, not both )
  1492.          @ ''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)
  1493.          @ <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``) in this example <code>linewidth 4<br />point 0,0,red<br />drag xy<br />point 0,0,blue</code><br />the red point will not be recognised as draggable ! in the example <code>linewidth 4<br />drag xy<br />point 0,0,red<br />drag xy<br />point 0,0,blue</code>both points will be recognised
  1494.          @ 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)
  1495.          @ use keyword <a href='#snaptogrid'>snaptogrid<a/>, <a href='#xsnaptogrid'>xsnaptogrid</a>, <a href='#ysnaptogrid'>ysnaptogrid</a> or command <a href='#snaptopoints'>snaptopoints x1,y1,x2,y2,...</a> to switch from free to discrete movement
  1496.          @ 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.
  1497.          @ note: in case an object is dragged, zooming or panning will cause the coordinates to be reset to the original position: e.g. dragging / panning will get lost (array with ''drag data`` is erased). This is a design flaw and not a feature !!
  1498.          @%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
  1499.          @%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
  1500.          @%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
  1501.         */
  1502.             temp = get_string(infile,1);
  1503.             if(strstr(temp,"xy") != NULL ){
  1504.                 drag_type = 0;
  1505.             }
  1506.             else
  1507.             {
  1508.                 if(strstr(temp,"x") != NULL ){
  1509.                     drag_type = 1;
  1510.                 }
  1511.                 else
  1512.                 {
  1513.                     drag_type = 2;
  1514.                 }
  1515.             }
  1516.             /* assuming all drag&drop coordinates the same precision: so set only once */
  1517.             if( print_drag_params_only_once == FALSE ){
  1518.              fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;\n",precision);
  1519.              print_drag_params_only_once = TRUE;
  1520.             }
  1521.             onclick = 2;
  1522.             /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
  1523.             break;
  1524.  
  1525.         case ELLIPSE:
  1526.         /*
  1527.         @ ellipse xc,yc,radius_x,radius_y,color
  1528.         @ an ellipse with center xc/yc in x/y-range
  1529.         @ radius_x and radius_y are in pixels
  1530.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1531.         @ will shrink / expand on zoom out / zoom in
  1532.         @%ellipse%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%opacity 200,40%linewidth 3%drag xy%ellipse 0,0,6,4,green%zoom blue
  1533.         */
  1534.             for(i=0;i<5;i++){
  1535.                 switch(i){
  1536.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  1537.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  1538.                     case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */
  1539.                     case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */
  1540.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  1541.                         decimals = find_number_of_digits(precision);
  1542.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  1543.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1544.                         /* click_cnt++; */
  1545.                         reset();
  1546.                     break;
  1547.                 }
  1548.             }
  1549.             break;
  1550.  
  1551.         case ELLIPSES:
  1552.         /*
  1553.         @ ellipses color,xc1,yc1,radius_x1,radius_y1,xc2,yc2,radius_x2,radius_y2,xc3,yc3,radius_x3,radius_y3,...
  1554.         @ ellipses with center xc1/yc1 in x/y-range, radius_x1 and radius_y1 are in pixels, etc
  1555.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1556.         @ will shrink / expand on zoom out / zoom in
  1557.         @%ellipses%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%opacity 200,40%linewidth 3%onclick%ellipses red,-3,0,2,4,0,0,4,2,3,0,6,2
  1558.         */
  1559.  
  1560.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1561.             fill_color = stroke_color;
  1562.             i=1;
  1563.             while( ! done ){     /* get next item until EOL*/
  1564.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1565.                 switch (i%4){
  1566.                  case 1:double_data[i-1] = get_real(infile,0);break; /* x */
  1567.                  case 2:double_data[i-1] = get_real(infile,0);break; /* y */
  1568.                  case 3:double_data[i-1] = get_real(infile,0);break; /* rx */
  1569.                  case 0:double_data[i-1] = get_real(infile,1);break; /* ry */
  1570.                  default: break;
  1571.                 }
  1572.                 i++;
  1573.             }
  1574.             decimals = find_number_of_digits(precision);
  1575.             for(c = 0 ; c < i-1 ; c = c+4){
  1576.              fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  1577.              if(onclick > 0 || slider_cnt > 0){click_cnt++;} /* click_cnt++; */
  1578.             }
  1579.             reset();
  1580.             break;
  1581.  
  1582.         case FILLALL:
  1583.         /*
  1584.         @ fillall color,x1,y1,x2,y2...x_n,y_n
  1585.         @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color ''color``.
  1586.         @ any other colors (objects) in the <a href='#canvastype'>canvastype</a> will act as border to the bucket fill.
  1587.         @ use this command after all boundary objects are declared.
  1588.         @ Use command ''userdraw clickfill,color`` for user click driven flood fill.
  1589.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5).
  1590.         @ note: the fill-family of commands are very (client) cpu intensive operations!<br />filling is done pixel by pixel 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..
  1591.         @%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
  1592.         */
  1593.             decimals = find_number_of_digits(precision);
  1594.             fill_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1595.             i=0;
  1596.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1597.              js_function[DRAW_FILLTOBORDER] = 1;
  1598.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1599.             }
  1600.             while( ! done ){     /* get next item until EOL*/
  1601.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1602.                 if(i%2 == 0 ){
  1603.                     double_data[i] = get_real(infile,0); /* x */
  1604.                 }
  1605.                 else
  1606.                 {
  1607.                     double_data[i] = get_real(infile,1); /* y */
  1608.                     string_length = 1 + 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);
  1609.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1610.                     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);
  1611.                     add_to_buffer(tmp_buffer);
  1612.                     fill_cnt++;
  1613.                 }
  1614.                 i++;
  1615.             }
  1616.         break;
  1617.  
  1618.         case FILLED:
  1619.         /*
  1620.         @ filled
  1621.         @ keyword (no arguments required)
  1622.         @ the next ''fillable`` object (only the next !) will be filled
  1623.         @ use command <a href="#fillcolor">fillcolor color</a> to set fillcolor
  1624.         @ use <a href="#fillpattern">fillpattern</a> for non-solid color filling.
  1625.         @ use command <code>opacity 0-255,0-255</code> to set stroke and fill-opacity
  1626.         @ use command <a href='#fill'>fill x,y,color</a> or <a href="#floodfill">floodfill x,y,color</a> to fill the space around (x;y) with color <br />pixel operation implemented in javascript: use with care !
  1627.         */
  1628.             use_filled = 1;
  1629.             use_pattern = 0;
  1630.             break;
  1631.  
  1632.         case FILLCOLOR:
  1633.         /*
  1634.         @ fillcolor colorname or #hex
  1635.         @ set the color: mainly used for command ''userdraw obj,stroke_color``
  1636.         @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...)
  1637.         @ see <a href="#fillpattern">fillpattern</a> for non-solid color filling.
  1638.         */
  1639.             fill_color = get_color(infile,1);
  1640.             use_pattern = 0;
  1641.             break;
  1642.  
  1643.         case FILLPATTERN:
  1644.         /*
  1645.         @ fillpattern grid | hatch | diamond | dot | image-url
  1646.         @ use a pattern as fillstyle
  1647.         @ suitable for all fillable object including the <a href="#userdraw">userdraw objects' family</a>
  1648.         @ not -yet- implemented in the <a href="#multidraw">multidraw objects family</a>...(will probably be too complex)
  1649.         @ the fillcolor is set by the object command, for example:<br /><code>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</code>
  1650.         @ the pattern dimensions are hardcoded (linewidth, radius,dx,dy are fixed)
  1651.         @ the pattern color is set by command <a href='#fillcolor'>fillcolor</a> and <a href='#opacity'>opacity</a>
  1652.         @ see <a href="#fillcolor">fillcolor</a> for solid color filling.
  1653.         @ 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`` 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 /><code>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</code>
  1654.         @ 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``, ''userdraw hatchfill,color`` etc.
  1655.         @%fillpattern_1%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
  1656.         @%fillpattern_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%fillcolor green%fillpattern hatch%#fillpattern dot,diamond,grid,imageurl%userdraw fcircle,red
  1657.         */
  1658.             temp = get_string(infile,1);
  1659.             if( strstr(temp,"grid") != 0 ){ use_pattern = 2;use_filled = 2;} /* use_pattern is used in dragstuff library */
  1660.             else
  1661.             if( strstr(temp,"hatch") != 0 ){ use_pattern = 3;use_filled = 3;}
  1662.             else
  1663.             if( strstr(temp,"diamond") != 0 ){ use_pattern = 4;use_filled = 4;}
  1664.             else
  1665.             if( strstr(temp,"dot") != 0 ){ use_pattern = 5;use_filled = 5;}
  1666.             else
  1667.             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); }
  1668.             else
  1669.             canvas_error("fillpattern unknown or typo...choose grid,hatch,diamond of dot...");
  1670.             break;
  1671.         case FILLTOBORDER:
  1672.         /*
  1673.         @ filltoborder x,y,bordercolor,color
  1674.         @ fill the region of point (x:y) with color ''color``
  1675.         @ any other color will not act as border to the bucket fill
  1676.         @ use this command after all boundary objects are declared.
  1677.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1678.         @ note: filltoborder is a very (client) cpu intensive operation!<br />filling is done pixel by pixel 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..
  1679.         @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a>
  1680.         @%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
  1681.         */
  1682.             for(i=0 ;i < 4 ; i++){
  1683.                 switch(i){
  1684.                     case 0:double_data[0] = get_real(infile,0);break;
  1685.                     case 1:double_data[1] = get_real(infile,0);break;
  1686.                     case 2:bgcolor = get_color(infile,0);break;
  1687.                     case 3:fill_color = get_color(infile,1);
  1688.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1689.                                 js_function[DRAW_FILLTOBORDER] = 1;
  1690.                                 add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1691.                            }
  1692.                            decimals = find_number_of_digits(precision);
  1693.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  1694.                            string_length = 1 + 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);
  1695.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1696.                            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);
  1697.                            add_to_buffer(tmp_buffer);
  1698.                            fill_cnt++;
  1699.                            break;
  1700.                     default:break;
  1701.                 }
  1702.             }
  1703.             reset();
  1704.         break;
  1705.         case FLOODFILL:
  1706.         /*
  1707.         @ floodfill x,y,color
  1708.         @ alternative: <code>fill x,y,color</code>
  1709.         @ fill the region of point (x:y) with color ''color``
  1710.         @ any other color or size of picture (borders of picture) will act as border to the bucket fill
  1711.         @ use this command after all boundary objects are declared.
  1712.         @ Use command <code>userdraw clickfill,color</code> for user click driven flood fill.
  1713.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1714.         @ note: floodfill is a very (client) cpu intensive operation!<br />filling is done pixel by pixel 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..
  1715.         @%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
  1716.         */
  1717.             for(i=0 ;i < 4 ; i++){
  1718.                 switch(i){
  1719.                     case 0:double_data[0] = get_real(infile,0);break;
  1720.                     case 1:double_data[1] = get_real(infile,0);break;
  1721.                     case 2:fill_color = get_color(infile,1);
  1722.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1723.                                 js_function[DRAW_FILLTOBORDER] = 1;
  1724.                                 add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1725.                            }
  1726.                            decimals = find_number_of_digits(precision);
  1727.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  1728.                            string_length = 1 + 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);
  1729.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1730.                            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);
  1731.                            add_to_buffer(tmp_buffer);
  1732.                            fill_cnt++;
  1733.                            break;
  1734.                     default:break;
  1735.                 }
  1736.             }
  1737.             reset();
  1738.         break;
  1739.  
  1740.         case FONTCOLOR:
  1741.         /*
  1742.          @ fontcolor color
  1743.          @ color: hexcolor or colorname
  1744.          @ default: black
  1745.          @ use command <a href="#fontfamily'>fontfamily</a> to deviate from default font type
  1746.          @%fontcolor%size 400,400%xrange -10,10%yrange -10,10%fontcolor red%#note: use command fontfamily to change size and shape%axis%axisnumbering%grid 2,2,grey,2,2,4,grey
  1747.         */
  1748.             font_color = get_color(infile,1);
  1749.             break;
  1750.  
  1751.         case FONTFAMILY:
  1752.         /*
  1753.          @ fontfamily font_description
  1754.          @ set the font family; for browsers that support it
  1755.          @ font_description: Ariel, Courier, Helvetica etc
  1756.          @ in case commands <code>string color,x,y,the string</code>, <code>stringup color,x,y,rotation,the string</code>, ''fontfamily`` can be something like:<code>fontfamily italic 34pt Ariel</code>. Use correct syntax: ''font style``, ''font size pt``, ''fontfamily``
  1757.          @%fontfamily%size 400,400%xrange -10,10%yrange -10,10  %fontfamily Bold 10pt Ariel%string blue,-9,9,10 pt Ariel%fontfamily Italic 20pt Ariel%string blue,0,9,20 pt Ariel%fontfamily Bold 10pt Helvetica%string blue,-9,5,10 pt Helvetica%fontfamily Italic 20pt Helvetica%string blue,0,5,20 pt Helvetica %fontfamily Bold 10pt Courier%string blue,-9,0,10 pt Courier%fontfamily Italic 20pt Courier%string blue,0,0,20 pt Courier%fontfamily Bold 10pt Fixed%string blue,-9,-5,10 pt Fixed%fontfamily Italic 20pt Fixed%string blue,0,-5,20 pt Fixed %fontfamily Bold 10pt Times%string blue,-9,-9,10 pt Times%fontfamily Italic 20pt Times%string blue,0,-9,20 pt Times
  1758.  
  1759.         */
  1760.             font_family = get_string(infile,1);
  1761.             break;
  1762.  
  1763.         case FONTSIZE:
  1764.         /*
  1765.          @ fontsize font_size
  1766.          @ default value 12
  1767.          @ note: for some macros (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
  1768.         */
  1769.             font_size = (int) (get_real(infile,1));
  1770.             break;
  1771.  
  1772.         case FUNCTION_LABEL:
  1773.         /*
  1774.          @ functionlabel some string
  1775.          @ default value ''f(x)=``
  1776.          @ no mathml allowed (just ascii string)
  1777.          @ use command <a href='#fontsize'>fontsize int</a> to adjust the size
  1778.          @ use command <a href='#strokecolor'>strokecolor colorname</a> to adjust the labels (individually, if needed)
  1779.          @ if needed, use before every command <a href='#userinput'>userinput function | inputfield | textarea</a>
  1780.          @ no limit in amount of inputfields for userbased function plotting
  1781.         */
  1782.             function_label = get_string_argument(infile,1);
  1783.             break;
  1784.  
  1785.         case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px), axis/tickscolor]*/
  1786.         /*
  1787.          @ grid step_x,step_y,gridcolor
  1788.          @ if keywords <a href="#axis">axis</a> or <a href="#axisnumbering">axisnumbering</a> are set, use: <code>grid step_x,step_y,major_color,minor_x,minor_y,tics height in px,axis_color</code> minor x step = step_x / minor_x
  1789.          @ 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; defaults: black,12,Ariel
  1790.          @ if xmin > 0 and/or ymin > 0 and zooming / panning is not active: be aware that the x/y-axis numbering and x/y major/minor tic marks will not be visual as they are placed under the x-axis and left to the y-axis (in Quadrant II and IV)
  1791.          @ can <b>not</b> be set <a href="#onclick">onclick</a> or <a href="#drag">drag xy</a>
  1792.          @ use commands <a href="#xlabel">xlabel some_string</a> and/or <a href="#ylabel">ylabel some_string</a> to label axis; use command ''fontsize`` to adjust size: the font family is non-configurable 'italic your_fontsize px Ariel' !
  1793.          @ see commands <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 command <a href="#fontfamily">fontfamily</a>; default '12px Ariel')
  1794.          @ see command <a href="#legend">legend</a> to set a legend for the graph; use command <a href="#fontsize">fontsize</a> to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel')
  1795.          @%grid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%zoom red
  1796.          @%grid_axis%size 400,400%xrange -10,10%yrange -10,10%axis%grid 1,1,grey,2,2,6,black%zoom red
  1797.          @%grid_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red
  1798.          @%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
  1799.         */
  1800.             if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
  1801.             if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
  1802.             for(i=0;i<4;i++){
  1803.                 switch(i){
  1804.                     case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
  1805.                     case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
  1806.                     case 2:
  1807.                     if( use_axis == TRUE ){
  1808.                         stroke_color = get_color(infile,0);
  1809.                         done = FALSE;
  1810.                         int_data[0] = (int) (get_real(infile,0));/* xminor */
  1811.                         int_data[1] = (int) (get_real(infile,0));/* yminor */
  1812.                         int_data[2] = (int) (get_real(infile,0));/* tic_length */
  1813.                         fill_color = get_color(infile,1); /* used as axis_color*/
  1814.                     }
  1815.                     else
  1816.                     {
  1817.                         int_data[0] = 1;
  1818.                         int_data[1] = 1;
  1819.                         stroke_color = get_color(infile,1);
  1820.                         fill_color = stroke_color;
  1821.                     }
  1822.                     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 !");}
  1823.                     /* set snap_x snap_y values in pixels */
  1824.                     fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
  1825.                     string_length = 1 + 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);
  1826.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1827.                     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);
  1828.                     add_to_buffer(tmp_buffer);
  1829.                     break;
  1830.                 }
  1831.             }
  1832.             reset();
  1833.             break;
  1834.         case GRIDFILL:
  1835.         /*
  1836.         @ gridfill x0,y0,dx,dy,color
  1837.         @ x0,y0 in xrange / yrange
  1838.         @ distances dx,dy in pixels
  1839.         @ there is also a command <a href="#userdraw">userdraw gridfill,color</a>
  1840.         @%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
  1841.  
  1842.         */
  1843.             if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
  1844.             decimals = find_number_of_digits(precision);
  1845.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1846.              js_function[DRAW_FILLTOBORDER] = 1;
  1847.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1848.             }
  1849.             for(i=0;i<5;i++){
  1850.                 switch(i){
  1851.                     case 0: double_data[0] = get_real(infile,0); break; /* x  */
  1852.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  1853.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1854.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1855.                     case 4: stroke_color = get_color(infile,1);
  1856.                     string_length = 1 + 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);
  1857.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1858.                     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);
  1859.                     add_to_buffer(tmp_buffer);
  1860.                     fill_cnt++;
  1861.                     break;
  1862.                     default:break;
  1863.                 }
  1864.             }
  1865.             reset();
  1866.         break;
  1867.  
  1868.         case HALFLINE:
  1869.         /*
  1870.         @ demiline x1,y1,x2,y2,color
  1871.         @ alternative: <code>halfline</code>
  1872.         @ draws a halfline starting in (x1:y1) and through (x2:y2) in color ''color`` (colorname or hex)
  1873.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1874.         @%halfline%size 400,400%xrange -10,10%yrange -10,10%halfline -5,5,0,0,red%halfline -5,-5,0,0,blue
  1875.         */
  1876.             for(i=0;i<5;i++){
  1877.                 switch(i){
  1878.                     case 0: double_data[0]= get_real(infile,0);break; /* x-values */
  1879.                     case 1: double_data[1]= get_real(infile,0);break; /* y-values */
  1880.                     case 2: double_data[10]= get_real(infile,0);break; /* x-values */
  1881.                     case 3: double_data[11]= get_real(infile,0);break; /* y-values */
  1882.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  1883.                     if(double_data[0] == double_data[10]){ /* vertical halfline */
  1884.                         if(double_data[1] < double_data[11]){
  1885.                          double_data[3] = ymax + 1000;
  1886.                         }
  1887.                         else
  1888.                         {
  1889.                          double_data[3] = ymin - 1000;
  1890.                         }
  1891.                         double_data[2] = double_data[0];
  1892.                     }
  1893.                     else
  1894.                     { /* horizontal halfline*/
  1895.                      if( double_data[1] == double_data[11] ){
  1896.                       if( double_data[0] < double_data[10] ){
  1897.                         double_data[2] = xmax + 1000; /* halfline to the right */
  1898.                       }
  1899.                       else
  1900.                       {
  1901.                         double_data[2] = xmin - 1000; /* halfline to the left */
  1902.                       }
  1903.                       double_data[3] = double_data[1];
  1904.                      }
  1905.                      else
  1906.                      {
  1907.                       /* any other halfline */
  1908.                       /* slope */
  1909.                       double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
  1910.                       /* const */
  1911.                       double_data[13] = double_data[1] - double_data[12]*double_data[0];
  1912.                       if( double_data[0] < double_data[10] ){
  1913.                        double_data[2] = double_data[2] + 1000;
  1914.                       }
  1915.                       else
  1916.                       {
  1917.                        double_data[2] = double_data[2] - 1000;
  1918.                       }
  1919.                       double_data[3] = double_data[12]*double_data[2] + double_data[13];
  1920.                      }
  1921.                     }
  1922.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  1923.                     if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1924.                     /* click_cnt++; */
  1925.                     reset();
  1926.                     break;
  1927.                 }
  1928.             }
  1929.             break;
  1930.  
  1931.         case HALFLINES:
  1932.         /*
  1933.         @ demilines color,x1,y1,x2,y2,....
  1934.         @ alternative: <code>halflines</code>
  1935.         @ draws halflines starting in (x1:y1) and through (x2:y2) in color ''color`` (colorname or hex) etc
  1936.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually
  1937.         @%halflines%size 400,400%xrange -10,10%yrange -10,10%halflines red,-5,5,0,0,-5,-5,0,0
  1938.         */
  1939.             stroke_color=get_color(infile,0);
  1940.             fill_color = stroke_color;
  1941.             i=0;
  1942.             while( ! done ){     /* get next item until EOL*/
  1943.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1944.                 if(i%2 == 0 ){
  1945.                     double_data[i] = get_real(infile,0); /* x */
  1946.                 }
  1947.                 else
  1948.                 {
  1949.                     double_data[i] = get_real(infile,1); /* y */
  1950.                 }
  1951.                 i++;
  1952.             }
  1953.             decimals = find_number_of_digits(precision);
  1954.             for(c = 0 ; c < i-1 ; c = c+4){
  1955.                 if( double_data[c] == double_data[c+2] ){ /* vertical line*/
  1956.                     if(double_data[c+1] < double_data[c+3]){ /* upright halfline */
  1957.                         double_data[c+3] = ymax + 1000;
  1958.                     }
  1959.                     else
  1960.                     {
  1961.                      double_data[c+3] = ymin - 1000;/* descending halfline */
  1962.                     }
  1963.                 }
  1964.                 else
  1965.                 {
  1966.                     if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  1967.                         if(double_data[c] < double_data[c+2] ){ /* halfline to the right */
  1968.                             double_data[c+2] = xmax+100;
  1969.                         }
  1970.                         else
  1971.                         {
  1972.                             double_data[c+2] = xmin-1000; /* halfline to the right */
  1973.                         }
  1974.                     }
  1975.                     else
  1976.                     {
  1977.                         /* m */
  1978.                         double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  1979.                         /* q */
  1980.                         double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  1981.                         if(double_data[c] < double_data[c+2]){ /* to the right */
  1982.                             double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it is just segment */
  1983.                             double_data[c+3] = (m)*(double_data[c+2])+(q);
  1984.                         }
  1985.                         else
  1986.                         { /* to the left */
  1987.                             double_data[c+2] = xmin - 1000;
  1988.                             double_data[c+3] = (m)*(double_data[c+2])+(q);
  1989.                         }
  1990.                     }
  1991.                 }
  1992.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  1993.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1994.                 /* click_cnt++; */
  1995.             }
  1996.             reset();
  1997.             break;
  1998.         case HATCHFILL:
  1999.         /*
  2000.         @ hatchfill x0,y0,dx,dy,color
  2001.         @ x0,y0 in xrange / yrange
  2002.         @ distances dx,dy in pixels
  2003.         @ there is also a command <a href="#userdraw">userdraw hatchfill,color</a>
  2004.         @%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
  2005.         */
  2006.             if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
  2007.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2008.              js_function[DRAW_FILLTOBORDER] = 1;
  2009.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  2010.             }
  2011.             decimals = find_number_of_digits(precision);
  2012.             for(i=0;i<5;i++){
  2013.                 switch(i){
  2014.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  2015.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  2016.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  2017.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2018.                     case 4: stroke_color = get_color(infile,1);
  2019.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2020.                     string_length = 1 + 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);
  2021.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2022.                     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);
  2023.                     add_to_buffer(tmp_buffer);
  2024.                     fill_cnt++;
  2025.                     break;
  2026.                     default:break;
  2027.                 }
  2028.             }
  2029.             reset();
  2030.         break;
  2031.  
  2032.         case HLINE:
  2033.         /*
  2034.         @ hline x,y,color
  2035.         @ alternative: <code>horizontalline</code>
  2036.         @ draw a horizontal line through point (x:y) in color ''color``
  2037.         @ or use command <a href='#curve'>curve color,formula</a> to draw the line (uses more points to draw the line; is however better draggable).
  2038.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2039.         @%hline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hline 0,0,red%dhline 0,5,blue
  2040.         */
  2041.             for(i=0;i<3;i++) {
  2042.                 switch(i){
  2043.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  2044.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  2045.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  2046.                     double_data[3] = double_data[1];
  2047.                     decimals = find_number_of_digits(precision);
  2048.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  2049.                     if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  2050.                     /* click_cnt++; */
  2051.                     reset();
  2052.                     break;
  2053.                 }
  2054.             }
  2055.             break;
  2056.  
  2057.         case HLINES:
  2058.         /*
  2059.         @ hlines color,x1,y1,x2,y2,...
  2060.         @ alternative: <code>horizontallines</code>
  2061.         @ draw horizontal lines through points (x1:y1)...(xn:yn) in color ''color``
  2062.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  2063.         @%hlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hlines red,0,0,0,5,0,-5
  2064.         */
  2065.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  2066.             fill_color = stroke_color;
  2067.             i=0;
  2068.             while( ! done ){     /* get next item until EOL*/
  2069.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2070.                 if(i%2 == 0 ){
  2071.                     double_data[i] = get_real(infile,0); /* x */
  2072.                 }
  2073.                 else
  2074.                 {
  2075.                     double_data[i] = get_real(infile,1); /* y */
  2076.                 }
  2077.                 i++;
  2078.             }
  2079.             decimals = find_number_of_digits(precision);
  2080.             for(c = 0 ; c < i-1 ; c = c+2){
  2081.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  2082.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  2083.                 /* click_cnt++; */
  2084.             }
  2085.             reset();
  2086.             break;
  2087.         case HTTP:
  2088.         /*
  2089.          @ http x1,y1,x2,y2,http://some_adress.com
  2090.          @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1), right bottom (x2:y2)
  2091.          @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe
  2092.          @ can <b>not</b> be ''set onclick`` or ''drag xy``
  2093.          @%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
  2094.         */
  2095.             if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}
  2096.             for(i=0;i<5;i++){
  2097.                 switch(i){
  2098.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2099.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2100.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  2101.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  2102.                     case 4: decimals = find_number_of_digits(precision);
  2103.                             temp = get_string(infile,1);
  2104.                             if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
  2105.                             string_length = 1 + 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);
  2106.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+2);
  2107.                             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);
  2108.                             add_to_buffer(tmp_buffer);
  2109.                     break;
  2110.                 }
  2111.             }
  2112.             reset();
  2113.             break;
  2114.         case HTML:
  2115.         /*
  2116.          @ html x1,y1,x2,y2,html_string
  2117.          @ all tags are allowed, html code using inputfields could be read using your own javascript code. Do not use ids like 'canvas_input0' etc.
  2118.          @ can be set onclick (however dragging not supported)
  2119.          @ use keyword <a href='#centered'>centered</a> to center the html object on (x1:y1)
  2120.          @%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
  2121.         */
  2122.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  2123.             for(i=0;i<5;i++){
  2124.                 switch(i){
  2125.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2126.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2127.                     case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed: overflow  */
  2128.                     case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed: overflow */
  2129.                     case 4: decimals = find_number_of_digits(precision);
  2130.                             temp = get_string(infile,1);
  2131.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2132.                             string_length = 1 + snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
  2133.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2134.                             snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
  2135.                             add_to_buffer(tmp_buffer);
  2136.                             if(onclick == 1 || onclick == 2 ){click_cnt++;}
  2137.                             use_offset = 0;
  2138.                             break;
  2139.                     default:break;
  2140.                 }
  2141.             }
  2142.             break;
  2143.  
  2144.         case IMAGEFILL:
  2145.         /*
  2146.         @ imagefill x,y,scaling to xsize &times; ysize?,image_url
  2147.         @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
  2148.         @ scaling to xsize &times; ysize ? ... 1 = yes 0 = no
  2149.         @ After pattern filling, the fill-color should be reset !
  2150.         @ wims getins / image from class directory: imagefill 80,80,my_image.gif
  2151.         @ normal url: imagefill 80,80,0,$module_dir/gifs/my_image.gif
  2152.         @ normal url: imagefill 80,80,1,http://adres/a/b/c/my_image.jpg
  2153.         @ if dx,dy is larger than the image, the whole image will be background to the next object.
  2154.         @%imagefill_tile%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,5,3,2,5%imagefill 1.5,1.5,0,gifs/en.gif%imagefill -5,5,0,gifs/logo/wimsedu.png
  2155.         @%imagefill_scale%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,5,3,2,5%imagefill 1.5,1.5,1,gifs/en.gif%imagefill -5,5,1,gifs/logo/wimsedu.png
  2156.         */
  2157.             if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
  2158.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2159.              js_function[DRAW_FILLTOBORDER] = 1;
  2160.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  2161.             }
  2162.             for(i=0 ;i < 4 ; i++){
  2163.                 switch(i){
  2164.                     case 0:int_data[0] = (int) (get_real(infile,0));break;
  2165.                     case 1:int_data[1] = (int) (get_real(infile,0));break;
  2166.                     case 2:int_data[2] = (int) (get_real(infile,0));break; /* 0 | 1 */
  2167.                     case 3: URL = get_string_argument(infile,1);
  2168.                             string_length = 1 + 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]);
  2169.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2170.                             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]);
  2171.                             add_to_buffer(tmp_buffer);
  2172.                             fill_cnt++;
  2173.                     break;
  2174.                 }
  2175.             }
  2176.             reset();
  2177.         break;
  2178.  
  2179.         case IMAGEPALETTE:
  2180.         /*
  2181.          @ imagepalette image1,image2,image3,...
  2182.          @ if used before and together with command <a href='#multidraw'>multidraw images,..,..., etc</a> the image will be presented in a small table in the ''control panel``.
  2183.          @%imagepalette%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%copy 0,0,-1,-1,-1,-1,gifs/images/skull_and_crossbones50.png%fontcolor green%fontfamily Bold 42pt Ariel%imagepalette gifs/ca.gif,gifs/en.gif,gifs/nl.gif,gifs/fr.gif,gifs/cn.gif,gifs/de.gif,gifs/kh.gif,gifs/it.gif%multiuserinput 0,0,1%inputstyle color:blue;%multisnaptogrid 1,1,1%multilinewidth 0,4,0%# attention: use unicode text input without the slash %# \u222D ---> u222D at least will sometimes work%# otherwise cut&past unicode symbols into inputfield...%multilabel TEXT,REACTION ARROW,FLAGS,STOP DRAWING%multidraw text,arrow,images
  2184.          */
  2185.            temp = get_string(infile,1);
  2186.            temp = str_replace(temp,",","\",\"");
  2187.             if( use_tooltip == 1 ){canvas_error("command 'imagepalette' is incompatible with command 'intooltip tip_text',as they use the same div-element ");}
  2188.             fprintf(js_include_file,"\nvar current_id;var imagepalette = [\" %s \"];\n",temp);
  2189.         break;
  2190.  
  2191.         case INPUTSTYLE:
  2192.         /*
  2193.         @ inputstyle style_description
  2194.         @ may be used before any ''style-able`` html object (like inputfields or buttons) or any html objects that are generated by some canvasdraw commands
  2195.         @%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
  2196.         */
  2197.             input_style = get_string(infile,1);
  2198.             break;
  2199.         case INPUT:
  2200.         /*
  2201.          @ input x,y,size,editable,value
  2202.          @ to set inputfield "readonly", use editable = 0
  2203.          @ only active inputfields (editable = 1) will be read with read_canvas();
  2204.          @ if ''&#36;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>.
  2205.          @ may be further controlled by <a href="#inputstyle">inputstyle</a> (inputcss is not yet implemented...)
  2206.          @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
  2207.          @ 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)
  2208.          @ if the student must place an inputfield(s) somewhere on the canvas, use command <a href="#userdraw">userdraw input,color</a> or make use of a command like <a href="#userdraw">userdraw text,color</a>
  2209.          @%input%size 400,400%xrange -10,10%yrange -10,10%linewidth 6%point 1,2,red%input 1,2,5,1, ?%point -5,5,red%input -5,5,5,1, ?%point 6,-5,red%input 6,-5,5,1, ?%point -5,-8,red%input -5,-8,5,1, ?
  2210.         */
  2211.         if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  2212.             for(i = 0 ; i<5;i++){
  2213.                 switch(i){
  2214.                     case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
  2215.                     case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
  2216.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
  2217.                     case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
  2218.                     case 4:
  2219.                             temp = get_string_argument(infile,1);
  2220.                             string_length = 1 + 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);
  2221.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2222.                             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);
  2223.                             add_to_buffer(tmp_buffer);
  2224.                             input_cnt++;break;
  2225.                     default: break;
  2226.                 }
  2227.             }
  2228.             if(reply_format == 0 ){reply_format = 15;}
  2229.             reset();
  2230.             break;
  2231.  
  2232.         case INTOOLTIP:
  2233.             /*
  2234.             @ intooltip link_text
  2235.             @ link_text is a single line (span-element)
  2236.             @ link_text may also be an image URL ''http://some_server/images/my_image.png`` or ''$module_dir/gifs/my_image.jpg``
  2237.             @ link_text may contain HTML markup
  2238.             @ the canvas will be displayed in a tooltip on ''link_text``
  2239.             @ the canvas is default transparent: use command <a href="#bgcolor">bgcolor color</a> to adjust background-color, the link text will also be shown with this ''bgcolor``.
  2240.             @ many ''userinput stuff`` will use the tooltip_placeholder_div element...only one is defined in the wims-page<br />and are therefore these commands are mutually exclusive.<br />keep this in mind...
  2241.             @%intooltip%size 400,400%xrange -10,10%yrange -10,10%fontfamily Bold 42pt Courier%string black,0,0,Hello World%intooltip <span style="background-color:black;color:white;font-style:bold;font-size:48pt;">CLICK <br />HERE</span>
  2242.             */
  2243.             if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");}
  2244.             if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");}
  2245.             tooltip_text = get_string(infile,1);
  2246.             if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
  2247.             use_tooltip = 1;
  2248.             break;
  2249.  
  2250.         case JSCURVE:
  2251.         /*
  2252.          @ jscurve color,formula1(x),formula2(x),formula3(x),...
  2253.          @ alternative: <code>jsplot color,formula(x)</code>
  2254.          @ your function will be plotted by the javascript engine of the client browser
  2255.          @ 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
  2256.          @ use only basic math in your curve: <code>sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e</code>
  2257.          @ use parenthesis and rawmath: use 2*x instead of 2x ; use 2^(sin(x))...etc etc (use error console to debug any errors...)
  2258.          @ <b>attention</b>: last ''precision`` command in the canvasdraw script determines the calculation precision of the javascript curve plot !
  2259.          @ no validity check is done by wims.
  2260.          @ 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
  2261.          @ 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
  2262.          @ use keyword <a href='animate'>animate</a> for animating a point on the curve
  2263.          @ use command ''trace_jscurve formula(x)`` for tracing
  2264.          @ use command ''jsmath formula(x)`` for calculating and displaying indiviual points on the curve
  2265.          @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet)
  2266.          @ commands plotjump / plotstep are not active for ''jscurve``
  2267.          @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve.
  2268.          @ plotting multiple js-curves on the same canvas (for example if you want to use 'userdraw clickfill,color' on <a href="#canvastype">canvastype</a> number 111, use:<br/> <code>jscurve red,fun1(x),fun2(x)...fun_n(x)</code>, you must specify individual multistrokecolors &amp; multistrokeopacity &amp; multilinewidth for these multiple js-curves to use different colors. Otherwise all curves will be the same color... Use commands like: <a href="#multistrokecolors">multistrokecolors</a>, <a href="#multilinewidth">multilinewidth</a>, <a href="#multidash">multidash</a>, <a href="#multistrokeopacity">multistroke</a>, <b>color</b> given for the command <code>jscurve color,formulas(x)</code> will not be used in that case... but the color argument must still be given in any case (otherwise syntax error...)
  2269.          @%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)
  2270.         */
  2271.             stroke_color = get_color(infile,0);
  2272.             if( use_js_math == FALSE){/* add this stuff only once...*/
  2273.                 add_to_js_math(js_include_file);
  2274.                 use_js_math = TRUE;
  2275.             }
  2276.             if( use_js_plot == FALSE){
  2277.                 use_js_plot = TRUE;
  2278.                 add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  2279.             }
  2280.             int use_paramteric = 0;
  2281.             if( tmin != 0 && tmax !=0){use_parametric = 1;}
  2282.             temp = get_string(infile,1);
  2283.             temp = str_replace(temp,",","\",\"");
  2284.             string_length = 1 + 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);
  2285.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2286.             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);
  2287.             add_to_buffer(tmp_buffer);
  2288.             jsplot_cnt++;
  2289.              /* we need to create multiple canvasses, so we may zoom and pan ?? */
  2290.         break;
  2291.  
  2292.         case JSMATH:
  2293.         /*
  2294.             @ jsmath some_math_function
  2295.             @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
  2296.             @ default labels ''x`` and ''y``; the commands ''xlabel some_x_axis_name`` and ''ylabel some_y_axis_name`` will set the label for the input fields
  2297.             @ use command 'inputstyle some_css' for styling the display fields. Use command 'fontsize int' to size the labels ''x`` and ''y``
  2298.             @ 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...
  2299.             @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
  2300.             @%jsmath%size 400,400%xrange -10,10%yrange -10,10%jsplot blue,sin(x^2)%jsmath sin(x^2)
  2301.         */
  2302.             if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  2303.             if( use_js_math == FALSE){
  2304.                 add_to_js_math(js_include_file);
  2305.                 use_js_math = TRUE;
  2306.             }
  2307.             add_calc_y(js_include_file,canvas_root_id,get_string(infile,1),font_size,input_style);
  2308.             break;
  2309.         case KILLAFFINE:
  2310.         /*
  2311.         @ killaffine
  2312.         @ keyword: resets the transformation matrix to 1,0,0,1,0,0
  2313.         */
  2314.             use_affine = FALSE;
  2315.             snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
  2316.             break;
  2317.  
  2318.         case KILLROTATE:
  2319.         /*
  2320.          @ killrotate
  2321.          @ will reset the command <a href="#rotationcenter">rotationcenter xc,yc</a>
  2322.          @ a following rotate command will have the first object point as rotation center
  2323.          @ if not set, the rotation center will remain unchanged
  2324.         */
  2325.             rotation_center= my_newmem(6);
  2326.             snprintf(rotation_center,5,"null");
  2327.          break;
  2328.  
  2329.         case KILLSLIDER:
  2330.         /*
  2331.          @ killslider
  2332.          @ keyword (no arguments required)
  2333.          @ ends grouping of object under a previously defined slider
  2334.         */
  2335.             slider_type = "0";
  2336.             current_sliders = "[-1]";
  2337.             for(i=0;i<slider_cnt;i++){active_sliders[i]=-1;}
  2338.             break;
  2339.  
  2340.         case KILLTRANSLATION:
  2341.         /*
  2342.          @ killtranslation
  2343.          @ alternative: <code>killtranslate</code>
  2344.          @ resets the translation matrix to 1,0,0,1,0,0
  2345.         */
  2346.             use_affine = FALSE;
  2347.             snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
  2348.             break;
  2349.         case LATEX:
  2350.         /*
  2351.          @ latex x,y,latex string
  2352.          @ can be set onclick: <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects<br />if 4 clickable objects are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object
  2353.          @ can be set draggable: <code>javascript:read_dragdrop();</code> will return all coordinates in the same order as the canvas script: unmoved object will have their original coordinates...
  2354.          @ 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
  2355.          @ 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
  2356.          @ userdraw may be combined with ''mathml`` ; the read_canvas() will contain the drawing.
  2357.          @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick mathml
  2358.          @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret...
  2359.          @ 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 <code>javascript:read_mathml();</code>. <b>attention</b>: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();"
  2360.          @ If other inputfields (command input / command textarea) or userdraw are performed, the function read_canvas() will not read mathml. Use some generic function to read it....
  2361.          @ use keyword <a href='#centered'>centered</a> to center the katex div object on (x1:y1)
  2362.          @%latex_drag%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%snaptogrid%strokecolor red%drag xy%latex -6,5,\\frac{1}{2}+ \\frac{\\pi}{2}%strokecolor blue%drag xy%snaptogrid%latex -3,5,\\frac{1}{3}+ \\frac{\\pi}{3}%strokecolor green%drag xy%snaptogrid%latex 0,5,\\frac{1}{4}+ \\frac{\\pi}{4}%strokecolor orange%drag xy%snaptogrid%latex 3,5,\\frac{1}{5}+ \\frac{\\pi}{6}
  2363.          @%latex_onclick%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%strokecolor red%onclick%latex -6,5,\\frac{1}{2}+ \\frac{\\pi}{2}%strokecolor blue%onclick%latex -3,5,\\frac{1}{3}+ \\frac{\\pi}{3}%strokecolor green%onclick%latex 0,5,\\frac{1}{4}+ \\frac{\\pi}{4}%strokecolor orange%onclick%latex 3,5,\\frac{1}{5}+ \\frac{\\pi}{6}
  2364.         */
  2365.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  2366.             drag_type=-1; /* hmmm */
  2367.             for(i=0;i<4;i++){
  2368.                 switch(i){
  2369.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2370.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2371.                     case 2: decimals = find_number_of_digits(precision);
  2372.                             temp = get_string(infile,1);
  2373. /*          !!!! UNTIL MATHJAX IS REPLACED BY KATEX !!!!       */
  2374. //                          browser_type = 1;
  2375.                             if(browser_type == 1 ){ /* GECKO needs  TEX --> MML  */
  2376.                              temp = getMML(temp);
  2377.                              if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2378.                              string_length = 1 + snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
  2379.                              check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2380.                              snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
  2381.                             }
  2382.                             else
  2383.                             {
  2384.                              if( strstr(temp,"\\") != 0 ){ temp = str_replace(temp,"\\","\\\\"); }
  2385.                              string_length = 1 + snprintf(NULL,0,"draw_xml(%d,%d,%d,\"<div name='zoom_0' class='wims_katex' id='katex%d'>%s</div>\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],click_cnt,temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
  2386.                              check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2387.                              snprintf(tmp_buffer,string_length,  "draw_xml(%d,%d,%d,\"<div name='zoom_0' class='wims_katex' id='katex%d'>%s</div>\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],click_cnt,temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
  2388.                             }
  2389.                             add_to_buffer(tmp_buffer);
  2390.                             if(onclick == 1 || onclick == 2 ){click_cnt++;}
  2391.                             use_offset = 0;
  2392.                             break;
  2393.                     default:break;
  2394.                 }
  2395.             }
  2396.             break;
  2397.         case LATTICE:
  2398.         /*
  2399.          @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
  2400.          @ can <b>not</b> be set ''onclick`` or ''drag xy``
  2401.          @%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
  2402.         */
  2403.             if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
  2404.             for( i = 0; i<9; i++){
  2405.                 switch(i){
  2406.                     case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
  2407.                     case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
  2408.                     case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
  2409.                     case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
  2410.                     case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
  2411.                     case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
  2412.                     case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
  2413.                     case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
  2414.                     case 8: stroke_color=get_color(infile,1);
  2415.                         decimals = find_number_of_digits(precision);
  2416.                         string_length = 1 + 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);
  2417.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2418.                         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);
  2419.                         add_to_buffer(tmp_buffer);break;
  2420.                     default:break;
  2421.                 }
  2422.             }
  2423.             reset();
  2424.             break;
  2425.  
  2426.         case LINE:
  2427.         /*
  2428.         @ line x1,y1,x2,y2,color
  2429.         @ draw a line through points (x1:y1)--(x2:y2) in color ''color``
  2430.         @ or use command ''curve color,formula`` to draw the line (uses more points to draw the line; is however better draggable).
  2431.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2432.         @%line%size 400,400%xrange -10,10%yrange -10,10%line 0,1,2,-1,green
  2433.         */
  2434.             for(i=0;i<5;i++){
  2435.                 switch(i){
  2436.                     case 0: double_data[10]= get_real(infile,0);break; /* x-values */
  2437.                     case 1: double_data[11]= get_real(infile,0);break; /* y-values */
  2438.                     case 2: double_data[12]= get_real(infile,0);break; /* x-values */
  2439.                     case 3: double_data[13]= get_real(infile,0);break; /* y-values */
  2440.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  2441.                     if( double_data[10] == double_data[12] ){ /* vertical line*/
  2442.                         double_data[1] = xmin;
  2443.                         double_data[3] = ymax;
  2444.                         double_data[0] = double_data[10];
  2445.                         double_data[2] = double_data[10];
  2446.                     }
  2447.                     else
  2448.                     {
  2449.                         if( double_data[11] == double_data[13] ){ /* horizontal line */
  2450.                             double_data[1] = double_data[11];
  2451.                             double_data[3] = double_data[11];
  2452.                             double_data[0] = ymin;
  2453.                             double_data[2] = xmax;
  2454.                         }
  2455.                         else
  2456.                         {
  2457.                         /* m */
  2458.                         double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
  2459.                         /* q */
  2460.                         double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
  2461.  
  2462.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  2463.  
  2464.                             double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
  2465.                             double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
  2466.                             double_data[0] = xmin;
  2467.                             double_data[2] = xmax;
  2468.                         }
  2469.                     }
  2470.                     decimals = find_number_of_digits(precision);
  2471.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  2472.                     if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  2473.                     /* click_cnt++;*/
  2474.                     reset();
  2475.                     break;
  2476.                 }
  2477.             }
  2478.             break;
  2479.  
  2480.         case LINES:
  2481.         /*
  2482.         @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n
  2483.         @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color ''color``
  2484.         @ or use multiple commands ''curve color,formula`` or ''jscurve color,formule`` to draw the line (uses more points to draw the line; is however better draggable).
  2485.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2486.         @ <b>attention</b>: the flydraw command ''lines`` is equivalent to canvasdraw command <a href="#polyline">polyline</a>
  2487.         @%lines%size 400,400%xrange -10,10%yrange -10,10%lines green,0,1,1,3,0,0,1,3,0,0,-2,1
  2488.         */
  2489.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  2490.             fill_color = stroke_color;
  2491.             i=0;
  2492.             while( ! done ){     /* get next item until EOL*/
  2493.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2494.                 if(i%2 == 0 ){
  2495.                     double_data[i] = get_real(infile,0); /* x */
  2496.                 }
  2497.                 else
  2498.                 {
  2499.                     double_data[i] = get_real(infile,1); /* y */
  2500.                 }
  2501.                 i++;
  2502.             }
  2503.             decimals = find_number_of_digits(precision);
  2504.             for(c = 0 ; c < i-1 ; c = c+4){
  2505.                 if( double_data[c] == double_data[c+2] ){ /* vertical line*/
  2506.                     double_data[c+1] = xmin;
  2507.                     double_data[c+3] = ymax;
  2508.                     double_data[c+2] = double_data[c];
  2509.                 }
  2510.                 else
  2511.                 {
  2512.                     if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  2513.                         double_data[c+3] = double_data[c+1];
  2514.                         double_data[c] = ymin;
  2515.                         double_data[c+2] = xmax;
  2516.                     }
  2517.                     else
  2518.                     {
  2519.                         /* m */
  2520.                         double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  2521.                         /* q */
  2522.                         double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  2523.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  2524.                         double_data[c+1] = (m)*(xmin)+(q);
  2525.                         double_data[c+3] = (m)*(xmax)+(q);
  2526.                         double_data[c] = xmin;
  2527.                         double_data[c+2] = xmax;
  2528.                     }
  2529.                 }
  2530.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  2531.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  2532.                 /* click_cnt++; */
  2533.             }
  2534.             reset();
  2535.             break;
  2536.  
  2537.  
  2538.         case LINEWIDTH:
  2539.         /*
  2540.         @ linewidth int
  2541.         @ default 1
  2542.         @%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
  2543.         */
  2544.             line_width = (int) (get_real(infile,1));
  2545.             break;
  2546.  
  2547.         case LEVELCURVE:
  2548.         /*
  2549.         @ levelcurve color,expression in x/y,l1,l2,...
  2550.         @ draws very primitive level curves for expression, with levels l1,l2,l3,...,ln
  2551.         @ the quality is <b>not to be compared</b> with the Flydraw levelcurve (choose flydraw if you want quality...).
  2552.         @ every individual level curve may be set ''onclick / drag xy`` e.g. every single level curve (l1,l2,l3...l_n) has a unique identifier.
  2553.         @ note: the arrays for holding the javascript data are limited in size.
  2554.         @ note: reduce image size if javascript data arrays get overloaded (command ''plotsteps int`` will not control the data size of the plot...).
  2555.         @%levelcurve%size 400,400%xrange -10,10%yrange -10,10%levelcurve red,x*y,1,2,3,4
  2556.         */
  2557.             fill_color = get_color(infile,0);
  2558.             char *fun1 = get_string_argument(infile,0);
  2559.             if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  2560.             i = 0;
  2561.             done = FALSE;
  2562.             while( !done ){
  2563.              double_data[i] = get_real(infile,1);
  2564.              i++;
  2565.             }
  2566.             for(c = 0 ; c < i; c++){
  2567.              fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,16,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  2568.              if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  2569.              /* click_cnt++; */
  2570.             }
  2571.             reset();
  2572.             break;
  2573.  
  2574.         case LEGEND:
  2575.         /*
  2576.         @ legend string1:string2:string3....string_n
  2577.         @ will be used to create a legend for a graph
  2578.         @ also see command <a href='#piechart'>piechart</a>
  2579.         @ will use the same colors per default as used in the graphs; use command <a href='#legendcolors'>legendcolors</a> to override the default
  2580.         @ use command <a href="#fontsize">fontsize</a> to adjust. (command ''fontfamily`` is not active for command ''legend``).
  2581.         @%legend%size 400,400%xrange -10,10%yrange -10,10%bgcolor white%fontsize 16%legend legend 1:legend 2:legend 3:legend 4:this is legend 5:legend 6:another legend abc%legendcolors red:green:blue%grid 1,1,white%# note: command "grid" is mandatory%# just set grid invisible if not wanted
  2582.         */
  2583.             temp = get_string(infile,1);
  2584.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2585.             legend_cnt++; /* attention: starts with -1: it will be used in piechart etc */
  2586.             fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
  2587.             break;
  2588.  
  2589.         case LEGENDCOLORS:
  2590.         /*
  2591.         @ legendcolors color1:color2:color3:...:color_n
  2592.         @ will be used to color a legend: use this command after the legend command ! e.g. <code>legend test1:test2:test3<br />legendcolors blue:red:orange</code>.
  2593.         @ make sure the number of colors match the number of legend items
  2594.         @ command ''legend`` in case of ''piechart`` and ''barchart`` will use these colours per default (no need to specify ''legendcolors``).
  2595.         @%legendcolors%size 400,400%xrange -10,10%yrange -10,10%fontsize 18%legend legend 1:legend 2:legend 3%legendcolors red:green:blue%grid 1,1,grey
  2596.         */
  2597.             if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
  2598.             temp = get_string(infile,1);
  2599.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2600.             fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
  2601.             break;
  2602.  
  2603.         case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed', 'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
  2604.         /*
  2605.         @ linegraph x1:y1:x2:y2...x_n:y_n
  2606.         @ will plot your data in a graph
  2607.         @ may <b>only</b> to be used together with command <a href='#grid'>grid</a>
  2608.         @ 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>
  2609.         @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner
  2610.         @ also see command <a href='#piechart'>piechart</a>
  2611.         @ multiple linegraphs may be used in a single plot
  2612.         @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble...
  2613.         @ <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>
  2614.         @%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
  2615.         */
  2616.             temp = get_string(infile,1);
  2617.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2618.             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);
  2619.             linegraph_cnt++;
  2620.             reset();
  2621.             break;
  2622.  
  2623.         case MATHML:
  2624.         /*
  2625.         @ mathml x1,y1,x2,y2,mathml_string
  2626.         @ this command is special for GECKO browsers, and it makes use of Native Mathml
  2627.         @ For use with all browsers, use command <a href='#latex'>latex</a>
  2628.         @ the mathml object is centered at (x1:y1)
  2629.         @ the ''mathml_string`` can be produced using WIMS commands like ''texmath`` followed by ''mathmlmath``... or write correct TeX and use only ''mathmlmath``
  2630.         @ 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.
  2631.         @ in case of drag(xy|x|y) | onclick the div rectangle left to corner will be the drag-anchor of the mathml object
  2632.         @ can be set onclick <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects; if 4 clickable object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object
  2633.         @ can be set draggable: <code>javascript:read_dragdrop()</code> will return all coordinates in same order as the canvas script: unmoved objects will have their original coordinates...
  2634.         @ snaptogrid is supported...snaptopoints will work, but use with care... due to the primitive dragging. Technically: the dragstuff library is not used... the mathml is embedded in a new div element and not in the html5-canvas.
  2635.         @ 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.
  2636.         @ userdraw may be combined with ''mathml`` ; the read_canvas() will contain the drawing.
  2637.         @ draggable or onclick ''external images`` from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick mathml
  2638.         @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret...
  2639.         @ 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();"
  2640.         @ 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....
  2641.         @ use keyword <a href='#centered'>centered</a> to center the mathml/xml object on (x1:y1)
  2642.         @%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>
  2643.         @%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...then drag...
  2644.         */
  2645.             if( browser_type == 0 ){ break;} /* should use command latex */
  2646.             if(use_offset == 0){use_offset = 4;} /* always centered if not otherwise stated ! */
  2647.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  2648.             for(i=0;i<5;i++){
  2649.                 switch(i){
  2650.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2651.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2652.                     case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed: overflow  */
  2653.                     case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed: overflow */
  2654.                     case 4: decimals = find_number_of_digits(precision);
  2655.                             temp = get_string(infile,1);
  2656.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2657.                             string_length = 1 + snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
  2658.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2659.                             snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
  2660.                             add_to_buffer(tmp_buffer);
  2661.                             if(onclick == 1 || onclick == 2 ){click_cnt++;}
  2662.                             use_offset=0;
  2663.                             /*
  2664.                              in case inputs are present, trigger adding the read_mathml()
  2665.                              if no other reply_format is defined
  2666.                              note: all other reply types will include a reading of elements with id='mathml'+p)
  2667.                              */
  2668.                             if(strstr(temp,"mathml0") != NULL){
  2669.                              if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
  2670.                             }
  2671.                             break;
  2672.                     default:break;
  2673.                 }
  2674.             }
  2675.             break;
  2676.  
  2677.         case MOUSE:
  2678.         /*
  2679.          @ mouse color,fontsize
  2680.          @ will display the cursor (x:y) coordinates in ''color`` and ''fontsize`` using default fontfamily Ariel
  2681.          @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``)
  2682.          @%mouse%size 400,400%xrange -10,10%yrange -10,10%mouse red,22
  2683.         */
  2684.             stroke_color = get_color(infile,0);
  2685.             font_size = (int) (get_real(infile,1));
  2686.             tmp_buffer = my_newmem(26);
  2687.             snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2688.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
  2689.             break;
  2690.  
  2691.  
  2692.         case MOUSE_DEGREE:
  2693.         /*
  2694.          @ mouse_degree color,fontsize
  2695.          @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in ''color`` and ''font size`` using a fontfamily Ariel
  2696.          @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
  2697.          @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``)
  2698.          @%mouse_degree%size 400,400%xrange -10,10%yrange -10,10%userdraw arc,blue%precision 100000%mouse_degree red,22
  2699.         */
  2700.             stroke_color = get_color(infile,0);
  2701.             font_size = (int) (get_real(infile,1));
  2702.             tmp_buffer = my_newmem(26);
  2703.             snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2704.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
  2705.             js_function[JS_FIND_ANGLE] = 1;
  2706.             break;
  2707.         case MOUSE_DISPLAY:
  2708.         /*
  2709.          @ display TYPE,color,fontsize
  2710.          @ TYPE may be <code>x | y | xy | degree | radian | radius</code>.
  2711.          @ will display the mouse cursor coordinates as x-only,y-only,(x:y), the radius of a circle (this only in case <code>userdraw circle(s),color</code>) or the angle in degrees or radians for commands <code>userdraw arc,color</code> or protractor, ruler (if set dynamic).
  2712.          @ use commands ''xunit`` and / or ''yunit`` to add the units to the mouse values. The ''degree | radian`` will always have the appropriate symbol).
  2713.          @ just like commands ''mouse``, ''mousex``, ''mousey``, ''mouse_degree``... only other name
  2714.          @%display_x%size 400,400%xrange -10,10%yrange -10,10%xunit \\u212B%display x,red,22
  2715.          @%display_y%size 400,400%xrange -10,10%yrange -10,10%yunit seconds%display y,red,22
  2716.          @%display_xy%size 400,400%xrange -10,10%yrange -10,10%xunit centimetre%yunit seconds%display xy,red,22%userdraw segments,blue
  2717.          @%display_deg%size 400,400%xrange -10,10%yrange -10,10%display degree,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
  2718.          @%display_rad%size 400,400%xrange -10,10%yrange -10,10%display radian,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
  2719.          @%display_radius%size 400,400%xrange -10,10%yrange -10,10%xunit cm%xunit \\u212b%display radius,red,22%userdraw circle,blue
  2720.         */
  2721.         temp = get_string_argument(infile,0);
  2722.         if( strstr(temp,"xy") != NULL ){
  2723.             int_data[0] = 2;
  2724.         }else{
  2725.             if( strstr(temp,"y") != NULL ){
  2726.                 int_data[0] = 1;
  2727.             }else{
  2728.                 if( strstr(temp,"x") != NULL ){
  2729.                     int_data[0] = 0;
  2730.                 }else{
  2731.                     if(strstr(temp,"degree") != NULL){
  2732.                         int_data[0] = 3;
  2733.                         js_function[JS_FIND_ANGLE] = 1;
  2734.                     }else{
  2735.                         if(strstr(temp,"radian") != NULL){
  2736.                             int_data[0] = 4;
  2737.                             js_function[JS_FIND_ANGLE] = 1;
  2738.                         }else{
  2739.                             if(strstr(temp,"radius") != NULL){
  2740.                                 int_data[0] = 5;
  2741.                             }else{
  2742.                                 int_data[0] = 2;
  2743.                             }
  2744.                         }
  2745.                     }
  2746.                 }
  2747.             }
  2748.         }
  2749.         stroke_color = get_color(infile,0);
  2750.         font_size = (int) (get_real(infile,1));
  2751.         tmp_buffer = my_newmem(26);
  2752.         snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2753.         add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
  2754.         break;
  2755.  
  2756.         case MOUSE_PRECISION:
  2757.         /*
  2758.             @ precision int
  2759.             @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
  2760.             @ may be used / changed before every object
  2761.             @ In case of user interaction (like ''userdraw`` or ''multidraw``), this value will be used to determine the amount of decimals in the reply / answer.
  2762.             @%precision%size 400,400%xrange -10,10%yrange -10,10%precision 1%userdraw segment,red
  2763.         */
  2764.             precision = (int) (get_real(infile,1));
  2765.             if(precision < 1 ){precision = 1;};
  2766.             break;
  2767.  
  2768.         case MOUSEX:
  2769.         /*
  2770.          @ mousex color,fontsize
  2771.          @ will display the cursor x-coordinate in ''color`` and ''font size`` using the fontfamily Ariel.
  2772.          @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``).
  2773.  
  2774.         */
  2775.             stroke_color = get_color(infile,0);
  2776.             font_size = (int) (get_real(infile,1));
  2777.             tmp_buffer = my_newmem(26);
  2778.             snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2779.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
  2780.             break;
  2781.         case MOUSEY:
  2782.         /*
  2783.          @ mousey color,fontsize
  2784.          @ will display the cursor y-coordinate in ''color`` and ''font size`` using default fontfamily Ariel.
  2785.          @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``).
  2786.  
  2787.         */
  2788.             stroke_color = get_color(infile,0);
  2789.             font_size = (int) (get_real(infile,1));
  2790.             tmp_buffer = my_newmem(26);
  2791.             snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2792.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
  2793.             break;
  2794.  
  2795.         case MULTIDASH:
  2796.         /*
  2797.          @ multidash 0,1,1
  2798.          @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <code>multifill points,circle,segments</code>, are dashed
  2799.          @ use before command <a href='#multidraw'>multidraw</a>
  2800.          @ if not set all objects will be set ''not dashed``... unless a generic keyword ''dashed`` was given before command ''multidraw``
  2801.          @ the dash-type is not -yet- adjustable (e.g. command <code>dashtype line_px,space_px</code> will give no control over multidraw objects)
  2802.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  2803.          @ always use the same sequence as is used for ''multidraw``
  2804.         */
  2805.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2806.             temp = get_string(infile,1);
  2807.             temp = str_replace(temp,",","\",\"");
  2808.             fprintf(js_include_file,"var multidash = [\"%s\"];",temp);
  2809.             reset();/* if command 'dashed' was given...reset to not-dashed */
  2810.             break;
  2811.  
  2812.         case MULTIDRAW:
  2813.         /*
  2814.          @ multidraw obj_type_1,obj_type_2...obj_type_11
  2815.          @ for simple single object user drawings you could also use command <a href="#userdraw">userdraw</a>
  2816.          @ implemented obj_types:<ul><li>''point | points``</li><li>''circle | circles``</li><li>''line | lines``</li><li>''segment | segments``</li><li>''arrow | arrows`` (use command ''arrowhead int`` for size, default value 8 pixels)</li><li>''curvedarrow | curvedarrows``</li><li>''rect | rects``</li><li>''closedpoly``: <b>only one</b> closedpolygon may be drawn.The number of corner points is not preset (e.g. not limited, freestyle), the polygon 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><li>''images``</li></ul>
  2817.          @ additionally objects may be user labelled, using obj_type ''text``... in this case always 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
  2818.          @ it makes no sense using something like <code>multidraw point,points</code> ... <br />something like <code>multidraw polys4,polys7</code> will only result in drawing a ''4 point polygone`` and not a ''7 point polygone``: this is a design flaw and not a feature...
  2819.          @ note: mouselisteners are only active if "&#36;status != done " (eg only drawing in an active/non-finished exercise). To overrule, use command/keyword ''status`` (no arguments required).
  2820.          @ buttons for changing the obj_type (and in case 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``.
  2821.          @ the button label will be default the ''object primitive name`` (like ''point``, ''circles``). If you want a different label (e.g. an other language), use command ''multilabel``. For example in dutch: <code>multilabel cirkel,lijnstuk,punten,STOP<br />multidraw circle,segment,points</code> (see command <a href='#multilabel'>multilabel</a> for more details).
  2822.          @ a right mouse button click will remove the last drawn object of the selected drawing type. All other type of objects are not removed
  2823.          @ multidraw is incompatible with command ''tooltip`` (the reserved div_area is used for the multidraw control buttons).
  2824.          @ all ''multidraw`` drawings will scale on zooming, this in contrast to the command <a href="#userdraw">userdraw</a>.
  2825.          @ wims will <b>not</b> check the amount or validity of your command arguments ! use javascript console to debug any typo.
  2826.          @ a local function <code>read_canvas%d</code> will read all userbased drawings. The output is always a 16 lines string with fixed sequence.<br/>line 1 = points_x+";"+points_y+"\\n"<br/>line 2 = circles_x+";"+circles_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 />line 12 = image_x+";"+image_y+";"+image_id<br />line 13 = curvedarrows_x +";"+ curvedarrows_y +"\\n"<br />line 14 = curvedarrows2_x +";"+ curvedarrows2_y +"\\n"<br />line 15 = userdraw_x +";"+userdraw_y + "\\n" note: this is for single ''userdraw object,color`` and ''replyformat 29``<br/>line 16 = userdraw_x +";"+userdraw_y +";"+userdraw_radius + "\\n" note: this is for single ''userdraw object,color`` and ''replyformat 29``<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>
  2827.          @ It is best to prepare / format the student reply in clientside javascript. However in wims language you could use something like this: 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 />
  2828.          @ <b>attention</b>: for command argument ''closedpoly``, only one polygone can be drawn. The last point (e.g. the point clicked near the first point) of the array is removed.
  2829.          @ technical: all 10 ''draw primitives`` + ''text`` will have their own -transparent- PNG bitmap canvas. So for example there can be a points_canvas entirely separated from a line_canvas. This to avoid the need for a complete redraw when something is drawn to the canvas...(eg only the object_type_canvas is redrawn), this in contrast too many very slow do-it-all HTML5 canvas javascript libraries. The mouselisteners are attached to the canvas-div element.
  2830.          @ a special object type is ''images``.<br />if used together with <a href='#imagepalette'>imagepalette</a> a image table will be integrated in the 'control section' of multidraw (set <code>multiuserinput 1</code> for ''images``) if not used with <a href='#imagepalette'>imagepalette</a>, provide the images or div's (&lt;img&gt; tag with bitmap or SVG or anything in a div element) somewhere on the html exercise page, with an onclick handler like:<br /><code>&lt;img src='gifs/images/dog.svg' onclick='javascript:place_image_on_canvas(this.id);' id="ext_image_1" /&gt;<br />&lt;img src='gifs/fish.png' onclick='javascript:place_image_on_canvas(this.id);' id="another" /&gt;</code><br />etc ... when activating the multidraw ''image`` button, the images can be selected (left mouse button/onclick) and placed on the canvas...left mouse click. Using div's will enable you -amongst other content- to add math typesetting from the exercise page onto the canvas.
  2831.          @ When you are not content with the default ''multidraw control panel``, you can create your own interface, using a few javascript functions to call the drawprimitives, delete things and ''stop drawing`` in case you also want to drag&drop stuff...</br>To activate this feature, use <a href='#multilabel'>multilabel NOCONTROLS</a><br />The object types are internally represented by the following numbers (making typos will render your exercise null and void)<br/>point = 0<br />points =1<br />circle = 2<br />circles = 3<br />line = 4<br />lines = 5<br />segment = 6<br />segments = 7<br />arrow = 8<br />arrows = 9<br />triangle = 10<br />triangles = 11<br />closedspoly = 12<br />text = 13<br />rect = 14<br />rects = 15<br />poly[3-9] = 16<br />polys[3-9] = 17<br />parallelogram = 18<br />parallelograms = 19<br />images       = 20<br />curvedarrow = 21<br />curvedarrows = 22<br />curvedarrow2 = 23<br />curvedarrows2 = 24<br />controls for example:<br /><code>&lt;input type='button' onclick='javascript:userdraw_primitive=null' value='STOP DRAWING' /&gt;<br />&lt;input type='button' onclick='javascript:userdraw_primitive=24;multidraw_click_cnt = 0;' value='start drawing curvedarrows2' /&gt; <br />&lt;input type='button' onclick='javascript:var fun=eval("clear_draw_area"+canvas_scripts[0]);fun(24,0);' value='REMOVE LAST CURVEDARROW ' /&gt; </code><br/> If using multiple canvas scripts in a single page, loop through the <code>canvas_scripts[n]</code>. <br />note: if using NOCONTROLS and just a single draw primitive (for example, just: ''multidraw circles``), the object may be drawn directly (analogue to ''userdraw circles,color``). And since a right mouse button click will always remove the last drawn object of the current object type, there is no need for a special "remove button".
  2832.          @%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
  2833.          @%multidraw_images%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%drag xy%# use special function to read the drag coordinates%copy 0,0,-1,-1,-1,-1,gifs/images/skull_and_crossbones50.png%fontcolor green%fontfamily Bold 42pt Ariel%imagepalette gifs/ca.gif,gifs/en.gif,gifs/nl.gif,gifs/fr.gif,gifs/cn.gif,gifs/de.gif,gifs/kh.gif,gifs/it.gif%multiuserinput 0,0,1%inputstyle color:blue;%multisnaptogrid 1,1,1%multilinewidth 0,4,0%# attention: use unicode text input without the slash %# \u222D ---> u222D at least will sometimes work%# otherwise cut&past unicode symbols into inputfield...%multilabel TEXT,REACTION ARROW,FLAGS,STOP DRAWING%multidraw text,arrow,images
  2834.          @%multidraw_demo%size 800,800%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%inputstyle color:blue;%fontfamily Italic 42pt Ariel%precision 1%opacity 200,50%snaptogrid%linewidth 3%filled%multistrokecolors red,green,blue,orange,yellow,purple,black,cyan,red,green,blue,orange,green,purple,black,cyan%multifillcolors red,green,blue,orange,yellow,purple,black,cyan,red,green,blue,orange,brown,purple%imagepalette gifs/ca.gif,gifs/en.gif,gifs/nl.gif,gifs/fr.gif,gifs/cn.gif,gifs/de.gif,gifs/kh.gif,gifs/it.gif%multidraw closedpoly,segments,rect,parallelogram,triangles,poly5,points,lines,arrows,circles,text,curvedarrows,curvedarrows2,images
  2835.          @%multidraw_NOCONTROLS%size 400,400%%xrange -10,10%yrange -10,10%grid 2,2,grey%linewidth 3%strokecolor green%fillcolor blue%filled%opacity 255,60%multilabel NOCONTROLS%multidraw circles%# RIGHT MOUSE CLICK REMOVES LAST OBJECT
  2836.         */
  2837.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2838.             if( use_userdraw == TRUE ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");}
  2839.             use_userdraw = TRUE;
  2840.             /* LET OP max 6 DRAW PRIMITIVES + TEXT */
  2841.             temp = get_string(infile,1);
  2842.             temp = str_replace(temp,",","\",\"");
  2843.             /* if these are not set, set the default values for the 18 (more than enough !)  draw_primitives + draw_text */
  2844.                 /* int use_snap = 0;  0 = none 1=grid: 2=x-grid: 3=y-grid: 4=snap to points */
  2845.  
  2846.             fprintf(js_include_file,"\
  2847.             if( typeof(multisnaptogrid) == 'undefined' && multisnaptogrid == null){var multisnaptogrid = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];}\
  2848.             if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null  ){ var multistrokecolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\
  2849.             if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){ var multifillcolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\
  2850.             if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null ){ var multistrokeopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f','%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\
  2851.             if( typeof(multifillopacity) === 'undefined' &&  multifillopacity == null ){ var multifillopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f','%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\
  2852.             if( typeof(multilinewidth) === 'undefined' && multilinewidth == null ){ var multilinewidth = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
  2853.             if( typeof(multifill) === 'undefined' && multifill == null ){ var multifill = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
  2854.             if( typeof(multidash) === 'undefined' && multidash == null ){ var multidash = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
  2855.             if( typeof(multilabel) === 'undefined' && multilabel == null ){ var multilabel = [\"%s\",\"stop drawing\"];};\
  2856.             if( typeof(multiuserinput) === 'undefined' && multiuserinput == null ){ var multiuserinput = ['0','0','0','0','0','0','0','0'];};\
  2857.             var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';",
  2858.             use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,
  2859.             stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,
  2860.             fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,
  2861.             stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,
  2862.             fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,
  2863.             line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,
  2864.             use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,
  2865.             use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,
  2866.             temp,arrow_head,font_color,font_family);
  2867.  
  2868.             if(strstr(temp,"text") != NULL){
  2869.              if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  2870.             }
  2871.  
  2872.             /* the canvasses range from 1000 ... 1008 */
  2873.             add_js_multidraw(js_include_file,canvas_root_id,temp,input_style,use_offset);
  2874.             reply_precision = precision;
  2875.             if( reply_format == 0){reply_format = 29;}
  2876.             reset();/* if command 'filled' / 'dashed' was given...reset all */
  2877.             break;
  2878.         case MULTILABEL:
  2879.         /*
  2880.          @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text'
  2881.          @ use before command <a href='#multidraw'>multidraw</a>
  2882.          @ 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``...)
  2883.          @ the ''stop drawing`` button text <b>must</b> be the last item on the ''multilabel`` -list <br />for example:<br /><code>multilabel punten,lijnen,Stop met Tekenen<br />multidraw points,lines</code>
  2884.          @ all buttons can be ''styled`` by using command <code>inputstyle</code><br /><b>note:</b>If you want to add some CSS style to the buttons... The id's of the ''draw buttons`` are their english command argument (e.g. id="canvasdraw_points" for the draw points button). The id of the ''stop drawing`` button is ''canvasdraw_stop_drawing``, the id of the "OK" button is ''canvasdraw_ok_button``.
  2885.          @ wims will not check the amount or validity of your input.
  2886.          @ always use the same sequence as is used for ''multidraw``.
  2887.          @ if you don't want the controls, and want to write your own interface, set <code>multilabel NOCONTROLS</code>.
  2888.         */
  2889.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2890.             temp = get_string(infile,1);
  2891.             temp = str_replace(temp,",","\",\"");
  2892.             fprintf(js_include_file,"var multilabel = [\"%s\"];",temp);
  2893.             break;
  2894.         case MULTILINEWIDTH:
  2895.         /*
  2896.          @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8
  2897.          @ use before command <a href='#multidraw'>multidraw</a>
  2898.          @ if not set all line widths will be set by a previous command ''linewidth int``
  2899.          @ use these up to 7 different line widths for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_7</code>
  2900.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  2901.          @ always use the same sequence as is used for ''multidraw``
  2902.         */
  2903.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2904.             temp = get_string(infile,1);
  2905.             temp = str_replace(temp,",","\",\"");
  2906.             fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp);
  2907.             break;
  2908.         case MULTIFILL:
  2909.         /*
  2910.          @ multifill 0,0,1,0,1,0,0
  2911.          @ meaning draw objects no. 3 and 5, in the list of command ''multifill``, are filled (if the object is fillable...and not a line,segment,arrow or point...)
  2912.          @ use before command <a href='#multidraw'>multidraw</a>
  2913.          @ if not set all objects -except point|points- will be set ''not filled``... unless a command <code>filled</code> was given before command <code>multifill</code>
  2914.          @ only suitable for draw_primitives like ''circle | circles``, ''triangle | triangles`` and ''polygon``
  2915.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  2916.          @ always use the same sequence as is used for ''multidraw``
  2917.         */
  2918.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2919.             temp = get_string(infile,1);
  2920.             temp = str_replace(temp,",","\",\"");
  2921.             fprintf(js_include_file,"var multifill = [\"%s\"];",temp);
  2922.             break;
  2923.  
  2924.         case MULTIFILLCOLORS:
  2925.         /*
  2926.          @ multifillcolors color_name_1,color_name_2,...,color_name_8
  2927.          @ use before command <a href='#multidraw'>multidraw</a>
  2928.          @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be ''stroke_color``, ''fill_opacity``
  2929.          @ use these up to 6 colors for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_n</code>
  2930.          @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
  2931.          @ always use the same sequence as is used for ''multidraw``
  2932.          @ 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> ... <code>reply=x1:y1:color1,x2:y2:color2...</code> The colors will restart at the first color, when there are more fill-clicks than multi-fill-colors. If more control over the used colours is wanted, see command <a href='#colorpalette'>colorpalette color1,color2...</a>
  2933.         */
  2934.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2935.             fprintf(js_include_file,"var multifillcolors = [");
  2936.             while( ! done ){
  2937.                 temp = get_color(infile,1);
  2938.                 fprintf(js_include_file,"\"%s\",",temp);
  2939.             }
  2940.             fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
  2941.             break;
  2942.  
  2943.         case MULTIFILLOPACITY:
  2944.         /*
  2945.          @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8
  2946.          @ float values 0 - 1 or integer values 0 - 255
  2947.          @ use before command <a href='#multidraw'>multidraw</a>
  2948.          @ if not set all fill opacity_ will be set by previous command <code>opacity int,int</code> and keyword ''filled``
  2949.          @ use these up to 7 different stroke opacities for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_y</code>
  2950.          @ wims will not check the amount or validity of your input
  2951.          @ always use the same sequence as is used for ''multidraw``
  2952.         */
  2953.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2954.             temp = get_string(infile,1);
  2955.             temp = str_replace(temp,",","\",\"");
  2956.             fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp);
  2957.             break;
  2958.         case MULTISNAPTOGRID:
  2959.         /*
  2960.          @ multisnaptogrid 0,1,1
  2961.          @ alternative: <code>multisnap</code>
  2962.          @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <code>multifill points,circle,segments</code>, will snap to the xy-grid (default 1 in x/y-coordinate system: see command <a href='#snaptogrid'>snaptogrid</a>)
  2963.          @ freehand drawing...specify precision for reply: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code>
  2964.          @ only the xy-values snap_to_grid: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code>
  2965.          @ only the x-values snap_to_grid: all objects snap to x-grid <code>multisnaptogrid 2,2,2,...</code>
  2966.          @ only the y-values snap_to_grid: all objects snap to y-grid <code>multisnaptogrid 3,3,3,...</code>
  2967.          @ if <a href='#snaptopoints'>snaptopoints</a> is defined: all objects snap to points <code>multisnaptogrid 4,4,4,...</code> <br /><b>make sure to define the points to snap on...</b> use command <a href='#snaptopoints'>snaptopoints</a>
  2968.          @ <code>multisnaptogrid 0,1,2,3,4<br />multidraw text,arrow,line,circle,image</code><br />''text`` is free hand, ''arrow`` is snap to grid, ''line`` is snap to x-grid, ''circle`` is snap to y-grid, ''image`` is snap to points defined by command <a href='#snaptopoints'>snaptopoints</a>
  2969.          @ use before command <a href='#multidraw'>multidraw</a>.
  2970.          @ attention: if not set all objects will be set ''no snap``... unless a generic command ''snaptogrid`` was given before command ''multidraw``.
  2971.          @ commands <a href='#xsnaptogrid'>xsnaptogrid</a>, <a href='#ysnaptogrid'>ysnaptogrid</a>, <a href='#snaptofunction'>snaptofunction</a> are <b>not</b> supported amd only functional for command <a href='#userdraw'>userdraw</a>
  2972.          @ always use the same sequence as is used for ''multidraw``
  2973.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  2974.         */
  2975.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2976.             temp = get_string(infile,1);
  2977.             fprintf(js_include_file,"var multisnaptogrid = [%s];",temp);
  2978.             reset();/* if command ''dashed`` was given...reset to not-dashed */
  2979.             break;
  2980.         case MULTISTROKECOLORS:
  2981.         /*
  2982.          @ multistrokecolors color_name_1,color_name_2,...,color_name_8
  2983.          @ use before command <a href='#multidraw'>multidraw</a>
  2984.          @ if not set all colors will be ''stroke_color``, ''stroke_opacity``
  2985.          @ use these up to 6 colors for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_7</code>
  2986.          @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
  2987.          @ always use the same sequence as is used for ''multidraw``
  2988.         */
  2989.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2990.             fprintf(js_include_file,"var multistrokecolors = [");
  2991.             while( ! done ){
  2992.                 temp = get_color(infile,1);
  2993.                 fprintf(js_include_file,"\"%s\",",temp);
  2994.             }
  2995.             fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
  2996.             break;
  2997.         case MULTISTROKEOPACITY:
  2998.         /*
  2999.          @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7
  3000.          @ float values 0 - 1 or integer values 0 - 255
  3001.          @ use before command <a href='#multidraw'>multidraw</a>
  3002.          @ if not set all stroke opacity_ will be set by previous command <code>opacity int,int</code>
  3003.          @ use these up to 7 different stroke opacities for the draw primitives used by command <code>multidraw obj_type_1, obj_type_2, ..., obj_type_7</code>
  3004.          @ wims will not check the amount or validity of your input
  3005.          @ always use the same sequence as is used for ''multidraw``
  3006.         */
  3007.             if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3008.             temp = get_string(infile,1);
  3009.             temp = str_replace(temp,",","\",\"");
  3010.             fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp);
  3011.             break;
  3012.  
  3013.         case MULTIUSERINPUT:
  3014.         /*
  3015.         @ multiuserinput 0,1,1,0
  3016.         @ alternative: <code>multiinput</code>
  3017.         @ meaning, when the command ''multidraw`` is used <code>multidraw circles,points,lines,triangles</code>, objects ''points`` and ''lines`` may additionally be ''drawn`` by direct input (inputfields). All other objects must be drawn with a mouse.
  3018.         @ in case of ''circle | circles`` a third inputfield for Radius (R) is added. 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
  3019.         @ 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...
  3020.         @ in case of a ''triangle | poly3``, three inputfields are provided.
  3021.         @ in case of ''text`` and ''multiuserinput=1, 3`` inputfields will be shown: ''x,y,text``
  3022.         @ in case of ''text`` and ''multiuserinput=0, 1`` inputfield will be shown: text ... a mouse click will place the text on the canvas.
  3023.         @ may be styled using command <a href="#inputstyle">inputstyle</a>
  3024.         @ an additional button ''stop drawing`` may be used to combine userbased drawings with ''drag&amp;drop`` or ''onclick`` elements
  3025.         @ when exercise is finished (status=done), the buttons will not be shown. To override this default behaviour use command / keyword ''status``
  3026.         @ use before command <a href='#multidraw'>multidraw</a>.
  3027.         @ always use the same sequence as is used for ''multidraw``.
  3028.         */
  3029.             /* simple rawmath and input check */
  3030.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  3031.             temp = get_string(infile,1);
  3032.             temp = str_replace(temp,",","\",\"");
  3033.             fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp);
  3034.             break;
  3035.  
  3036.         case NOXAXIS:
  3037.         /*
  3038.         @ noxaxis
  3039.         @ keyword
  3040.         @ if set, the automatic x-axis numbering will be ignored
  3041.         @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>)
  3042.         @ to be used before command grid (see <a href="#grid">command grid</a>)
  3043.         */
  3044.             fprintf(js_include_file,"x_strings = {};x_strings_up = [];\n");
  3045.             use_axis_numbering = -1;
  3046.             break;
  3047.         case NOYAXIS:
  3048.         /*
  3049.         @ noyaxis
  3050.         @ keyword
  3051.         @ if set, the automatic y-axis numbering will be ignored
  3052.         @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>)
  3053.         @ to be used before command grid (see <a href="#grid">command grid</a>)
  3054.         */
  3055.             fprintf(js_include_file,"y_strings = {};\n");
  3056.             break;
  3057.         case NUMBERLINE:
  3058.         /*
  3059.         @ numberline x0,x1,xmajor,xminor,y0,y1
  3060.         @ numberline is using xrange/yrange system for all dimensions
  3061.         @ multiple numberlines are allowed ; combinations with command <a href='#grid'>grid</a> is allowed; multiple commands <a href='#xaxis'>xaxis numbering</a> are allowed
  3062.         @ x0 is start x-value in xrange
  3063.         @ x1 is end x-value in xrange
  3064.         @ xmajor is step for major division
  3065.         @ xminor is divisor of xmajor; using small (30% of major tick) tick marks: this behaviour is ''hardcoded``
  3066.         @ is xminor is an even divisor, an extra tickmark (60% of major tick) is added to the numberline: this behaviour is ''hardcoded``
  3067.         @ y0 is bottom of numberline; y1 endpoint of major tics
  3068.         @ use command <a href="#linewidth">linewidth</a> to control appearance
  3069.         @ use <a href="#strokecolor">strokecolor</a> and <a href="#opacity">opacity</a> to controle measure line
  3070.         @ for all ticks linewidth and color / opacity are identical.
  3071.         @ 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
  3072.         @ use <a href="#fontfamily">fontfamily</a> and <a href="#fontcolor">fontcolor</a> to control fonts settings
  3073.         @ 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
  3074.         @ <a href="#snaptogrid">snaptogrid, snaptopoints etc</a> and <a href="#zoom">zooming and panning</a> is supported
  3075.         @ onclick and dragging of the numberline are not -yet- supported
  3076.         @ note: in case of multiple numberlines, make sure the numberline without special x-axis numbering (e.g. ranging from xmin to xmax) comes first !
  3077.         @%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
  3078.         */
  3079.             if( js_function[DRAW_NUMBERLINE] != 1 ){ js_function[DRAW_NUMBERLINE] = 1;}
  3080.             for(i=0;i<6;i++){
  3081.                 switch(i){
  3082.                     case 0: double_data[0] = get_real(infile,0);break;/* xmin */
  3083.                     case 1: double_data[1] = get_real(infile,0);break;/* xmax */
  3084.                     case 2: double_data[2] = get_real(infile,0);break;/* xmajor */
  3085.                     case 3: double_data[3] = get_real(infile,0);break;/* xminor */
  3086.                     case 4: double_data[4] = get_real(infile,0);break;/* ymin */
  3087.                     case 5: double_data[5] = get_real(infile,1);/* ymax */
  3088.                             /*
  3089.                             var draw_numberline%d = function(canvas_type,xmin,xmax,xmajor,xminor,ymin,ymax,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor);
  3090.                             */
  3091.                             fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[2] / double_data[3],double_data[5] - double_data[4] );
  3092.                             string_length = 1 + 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);
  3093.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3094.                             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);
  3095.                             add_to_buffer(tmp_buffer);
  3096.                             numberline_cnt++;
  3097.                             break;
  3098.                     default:break;
  3099.                 }
  3100.             }
  3101.             reset();
  3102.             break;
  3103.  
  3104.             break;
  3105.         case OPACITY:
  3106.         /*
  3107.         @ opacity [0-255],[0-255]
  3108.         @ opacity [0.0 - 1.0],[0.0 - 1.0]
  3109.         @ alternative: <code>transparent</code>
  3110.         @ first item is stroke opacity, second is fill opacity
  3111.         @%opacity%size 400,400%xrange -10,10%yrange -10,10%opacity 255,0%fcircle -10,0,100,blue%opacity 250,50%fcircle -5,0,100,blue%opacity 200,100%fcircle 0,0,100,blue%opacity 150,150%fcircle 5,0,100,blue%opacity 100,200%fcircle 10,0,100,blue
  3112.         */
  3113.             for(i = 0 ; i<2;i++){
  3114.                 switch(i){
  3115.                     case 0: double_data[0]= get_real(infile,0);break;
  3116.                     case 1: double_data[1]= get_real(infile,1);break;
  3117.                     default: break;
  3118.                 }
  3119.             }
  3120.             if( double_data[0] > 255 ||  double_data[1] > 255  || double_data[0] < 0 || double_data[1] < 0 ){ canvas_error("opacity [0 - 255] , [0 - 255] ");}/* typo or non-RGB ? */
  3121.             if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = 0.0;} /* 0.0 - 1.0 */
  3122.             if( double_data[1] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = 0.0;} /* 0.0 - 1.0 */
  3123.             break;
  3124.  
  3125.         case ONCLICK:
  3126.         /*
  3127.          @ onclick
  3128.          @ keyword (no arguments required)
  3129.          @ if the next object is clicked, its ''object onclick_or_drag sequence number`` in fly script is returned by <code>javascript:read_canvas();</code>
  3130.          @ onclick seqeuence numbering starts at ''0``, e.g. if there are 6 objects set onclick, the first onclick object will have id-number ''0``, the last id-number ''5``
  3131.          @ line based objects will show an increase in line width<br />font based objects will show the text in ''bold`` when clicked.
  3132.          @ the click zone (accuracy) is determined by 2&times; the line width of the object
  3133.          @ onclick and <a href="#drag">drag x|y|xy</a> may be combined in a single flyscript (although a single object can <b>not</b> be onclick and draggable at the same time...)
  3134.          @ note: not all objects may be set onclick
  3135.          @%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
  3136.         */
  3137.             fprintf(js_include_file,"use_dragdrop_reply = true;");
  3138.             onclick = 1;
  3139.  
  3140.             break;
  3141.  
  3142.         case PARALLEL:
  3143.         /*
  3144.          @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
  3145.          @ can <b>not</b> be set ''onclick`` or ''drag xy``
  3146.          @%parallel%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red
  3147.         */
  3148.             for( i = 0;i < 8; i++ ){
  3149.                 switch(i){
  3150.                     case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
  3151.                     case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
  3152.                     case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
  3153.                     case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
  3154.                     case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
  3155.                     case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
  3156.                     case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
  3157.                     case 7: stroke_color=get_color(infile,1);/* name or hex color */
  3158.                     decimals = find_number_of_digits(precision);
  3159.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  3160.                     if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3161.                     /* click_cnt++*/;
  3162.                     reset();
  3163.                     break;
  3164.                     default: break;
  3165.                 }
  3166.             }
  3167.             break;
  3168.  
  3169.  
  3170.         case PLOTSTEPS:
  3171.             /*
  3172.              @ plotsteps a_number
  3173.              @ default 150
  3174.              @ only used for commands <a href="#curve">curve / plot</a> and <a href="#levelcurve">levelcurve</a>
  3175.              @ use with care !
  3176.             */
  3177.             plot_steps = (int) (get_real(infile,1));
  3178.             break;
  3179.  
  3180.         case POINT:
  3181.         /*
  3182.         @ point x,y,color
  3183.         @ draw a single point at (x;y) in color ''color``
  3184.         @ use command <code>linewidth int</code> to adjust size
  3185.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3186.         @ will not resize on zooming (command <code>circle x,y,r,color</code> will resize on zooming)
  3187.         @ attention: in case of command <a href="#rotate">rotate angle</a> a point has rotation center (0:0) in x/y-range
  3188.         @%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
  3189.         */
  3190.             for(i=0;i<3;i++){
  3191.                 switch(i){
  3192.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  3193.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  3194.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  3195.                     decimals = find_number_of_digits(precision);
  3196.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  3197.                     /* click_cnt++; */
  3198.                     if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3199.                     break;
  3200.                     default: break;
  3201.                 }
  3202.             }
  3203.             reset();
  3204.             break;
  3205.  
  3206.         case POINTS:
  3207.         /*
  3208.         @ points color,x1,y1,x2,y2,...,x_n,y_n
  3209.         @ draw multiple points at given coordinates in color ''color``
  3210.         @ use command <code>linewidth int</code> to adjust size
  3211.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  3212.         @ attention: in case of command <a href="#rotate">rotate angle</a> the points have rotation center (0:0) in x/y-range
  3213.         @%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
  3214.         @%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
  3215.         */
  3216.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3217.             fill_color = stroke_color;
  3218.             i=0;
  3219.             while( ! done ){     /* get next item until EOL*/
  3220.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3221.                 if(i%2 == 0 ){
  3222.                     double_data[i] = get_real(infile,0); /* x */
  3223.                 }
  3224.                 else
  3225.                 {
  3226.                     double_data[i] = get_real(infile,1); /* y */
  3227.                 }
  3228.                 i++;
  3229.             }
  3230.             decimals = find_number_of_digits(precision);
  3231.             for(c = 0 ; c < i-1 ; c = c+2){
  3232.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  3233.                 /* click_cnt++; */
  3234.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3235.             }
  3236.             reset();
  3237.             break;
  3238.  
  3239.         case POLY:
  3240.         /*
  3241.         @ poly color,x1,y1,x2,y2...x_n,y_n
  3242.         @ polygon color,x1,y1,x2,y2...x_n,y_n
  3243.         @ draw closed polygon
  3244.         @ use command ''fpoly`` to fill it or use keyword <a href='#filled'>filled</a>
  3245.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3246.         @%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
  3247.         @%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
  3248.         */
  3249.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3250.             i=0;
  3251.             c=0;
  3252.             while( ! done ){     /* get next item until EOL*/
  3253.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3254.                 for( c = 0 ; c < 2; c++){
  3255.                     if(c == 0 ){
  3256.                         double_data[i] = get_real(infile,0);
  3257.                         i++;
  3258.                     }
  3259.                     else
  3260.                     {
  3261.                         double_data[i] = get_real(infile,1);
  3262.                         i++;
  3263.                     }
  3264.                 }
  3265.             }
  3266.             /* draw path:  closed & optional filled */
  3267.                 decimals = find_number_of_digits(precision);
  3268.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  3269.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3270.                 /* click_cnt++; */
  3271.                 reset();
  3272.             break;
  3273.  
  3274.         case POLYLINE:
  3275.         /*
  3276.         @ polyline color,x1,y1,x2,y2...x_n,y_n
  3277.         @ brokenline color,x1,y1,x2,y2...x_n,y_n
  3278.         @ path color,x1,y1,x2,y2...x_n,y_n
  3279.         @ remark: there is <b>no</b> command polylines | brokenlines | paths ... just use multiple commands <code>polyline, x1,y1,x2,y2...x_n,y_n</code>
  3280.         @ remark: there are commands <code>userdraw path(s),color</code> and <code>userdraw polyline,color</code>... these are two entirely different things ! the path(s) userdraw commands may be used for freehand drawing(s)<br />the polyline userdraw command is analogue to this polyline|brokenline command
  3281.         @ 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)
  3282.         @ use command <a href='#segments'>segments</a> for a series of segments. These may be clicked/dragged individually
  3283.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3284.         @%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
  3285.         @%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
  3286.         */
  3287.  
  3288.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3289.             i=0;
  3290.             c=0;
  3291.             while( ! done ){     /* get next item until EOL*/
  3292.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3293.                 for( c = 0 ; c < 2; c++){
  3294.                     if(c == 0 ){
  3295.                         double_data[i] = get_real(infile,0);
  3296.                         i++;
  3297.                     }
  3298.                     else
  3299.                     {
  3300.                         double_data[i] = get_real(infile,1);
  3301.                         i++;
  3302.                     }
  3303.                 }
  3304.             }
  3305.             /* draw path: not closed & not filled */
  3306.             decimals = find_number_of_digits(precision);
  3307.             fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  3308.             if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3309.             /* click_cnt++;*/
  3310.             reset();
  3311.             break;
  3312.  
  3313.         case POPUP:
  3314.             /*
  3315.             @ popup
  3316.             @ keyword (no arguments)
  3317.             @ if fly-script starts with keyword ''popup``, the canvas image will be exclusively in a popup window (xsize px &times; ysize px)
  3318.             @ if keyword ''popup`` is used after command <code>size xsize,ysize</code> the canvas will also be displayed in a popup window with size ''xsize &times; ysize``
  3319.             @ the popup window will be embedded into the page as a ''normal`` image, when ''status=done``; override with keyword <a href="#status">nostatus</a>
  3320.             @ to access the read_canvas and read_dragdrop functions in a popup window, use: <code> 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 /> };</code>
  3321.             @ to set a canvasdraw produced <a href="#clock">clock</a> or multiple clocks...use something like: <code>popup.set_clock(clock_id,type,diff);</code> as js-function for a button (or something else) in your document page.<br />where in <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
  3322.             @%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
  3323.             */
  3324.             use_tooltip = 2;
  3325.             break;
  3326.  
  3327.         case PROTRACTOR:
  3328.         /*
  3329.          @ protractor x,y,x_width,type,mode,use_a_scale
  3330.          @ x,y are the initial location
  3331.          @ x_width: give the width in x-coordinate system (e.g. not in pixels !)
  3332.          @ type = 1: a triangle range 0 - 180<br />type = 2: a circle shape 0 - 360
  3333.          @ 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
  3334.          @ 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>
  3335.          @ use_scale = 1: the protractor will have some scale values printed; use_scale=0 to disable
  3336.          @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor...
  3337.          @ commands ''stroke_color | fill_color | linewidth | opacity | font_family`` will determine the looks of the protractor.
  3338.          @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command ''precision`` to set the reply precision.
  3339.          @ if combined with a ruler, use replyformat = 32
  3340.          @ command <code>snap_to_grid</code> may be used to assist the pupil at placing the protractor
  3341.          @ 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 />technical: 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...
  3342.          @ only one protractor allowed (for the time being)
  3343.          @ usage: first left click on the protractor will activate dragging; a second left click will activate rotating (just move mouse around); a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3); a next click will restart this sequence...
  3344.          @%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
  3345.         */
  3346.             for( i = 0;i < 6; i++ ){
  3347.                 switch(i){
  3348.                     case 0: double_data[0] = get_real(infile,0);break; /* x-center */
  3349.                     case 1: double_data[1] = get_real(infile,0);break; /* y-center */
  3350.                     case 2: double_data[2] = get_real(infile,0);break; /* x-width */
  3351.                     case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */
  3352.                     case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */
  3353.                     case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */
  3354.                     decimals = find_number_of_digits(precision);
  3355.                     if( int_data[1] < 0 ){ js_function[JS_FIND_ANGLE] = 1;}
  3356.                     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],use_snap);
  3357.  
  3358.                     string_length = 1 + snprintf(NULL,0,";protractor%d(); ",canvas_root_id);
  3359.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3360.                     snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id);
  3361.                     add_to_buffer(tmp_buffer);
  3362.                     reply_precision = precision;
  3363.                     /* no reply from protractor if non-interactive */
  3364.                     if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;}
  3365.                     break;
  3366.                     default: break;
  3367.                 }
  3368.             }
  3369.             break;
  3370.  
  3371.         case PIXELS:
  3372.         /*
  3373.         @ pixels color,x1,y1,x2,y2,x3,y3...
  3374.         @ draw rectangular "points" with diameter 1 pixel
  3375.         @ pixels can <b>not</b> be dragged or clicked
  3376.         @ "pixelsize = 1" may be changed by command <code>pixelsize int</code>
  3377.         @%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...
  3378.         */
  3379.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  3380.             stroke_color=get_color(infile,0);
  3381.             i=0;
  3382.             c=0;
  3383.             while( ! done ){     /* get next item until EOL*/
  3384.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3385.                 for( c = 0 ; c < 2; c++){
  3386.                     if(c == 0 ){
  3387.                         double_data[i] = get_real(infile,0);
  3388.                         i++;
  3389.                     }
  3390.                     else
  3391.                     {
  3392.                         double_data[i] = get_real(infile,1);
  3393.                         i++;
  3394.                     }
  3395.                 }
  3396.             }
  3397.             decimals = find_number_of_digits(precision);
  3398.             /*  *double_xy2js_array(double xy[],int len,int decimals) */
  3399.             string_length = 1 + snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  3400.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3401.             snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  3402.             add_to_buffer(tmp_buffer);
  3403.             reset();
  3404.             break;
  3405.  
  3406.         case PIXELSIZE:
  3407.         /*
  3408.         @ pixelsize int
  3409.         @ in case you want to deviate from default pixelsize = 1(...)
  3410.         @ pixelsize 100 is of course a filled rectangle 100px &times; 100px
  3411.         */
  3412.             pixelsize = (int) get_real(infile,1);
  3413.         break;
  3414.  
  3415.         case PIECHART:
  3416.         /*
  3417.         @ piechart xc,yc,radius,'data+colorlist'
  3418.         @ (xc: yc) center of circle diagram in xrange/yrange
  3419.         @ radius in pixels
  3420.         @ 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
  3421.         @ example data+colorlist: 32:red:65:green:23:black:43:orange:43:yellow:14:white
  3422.         @ the number of colors must match the number of data.
  3423.         @ 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,...
  3424.         @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of colours
  3425.         @ use command <a href='#legend'>legend</a> to automatically create a legend using the same colours as pie segments; unicode allowed in legend; expect javascript trouble if the amount of ''pie-slices``, ''pie-colors``, ''pie-legend-titles`` do not match, a javascript console is your best friend...<br />use command ''fontfamily`` to set the font of the legend.
  3426.         @ 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.
  3427.         @%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%
  3428.         @%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
  3429.         */
  3430.             if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}
  3431.             for(i=0;i<5;i++){
  3432.                 switch(i){
  3433.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  3434.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  3435.                     case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
  3436.                     case 3: temp = get_string(infile,1);
  3437.                             if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
  3438.                             string_length = 1 + 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);
  3439.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3440.                             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);
  3441.                             add_to_buffer(tmp_buffer);
  3442.                            break;
  3443.                     default:break;
  3444.                 }
  3445.             }
  3446.             reset();
  3447.         break;
  3448.  
  3449.         case RAYS:
  3450.         /*
  3451.          @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
  3452.          @ draw rays in color ''color`` and center (xc:yc)
  3453.          @ may be set draggable or onclick (every individual ray)
  3454.          @%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
  3455.          @%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
  3456.         */
  3457.             stroke_color=get_color(infile,0);
  3458.             fill_color = stroke_color;
  3459.             double_data[0] = get_real(infile,0);/* xc */
  3460.             double_data[1] = get_real(infile,0);/* yc */
  3461.             i=2;
  3462.             while( ! done ){     /* get next item until EOL*/
  3463.                 if(i > MAX_INT - 1){canvas_error("in command rays too many points / rays in argument: repeat command multiple times to fit");}
  3464.                 if(i%2 == 0 ){
  3465.                     double_data[i] = get_real(infile,0); /* x */
  3466.                 }
  3467.                 else
  3468.                 {
  3469.                     double_data[i] = get_real(infile,1); /* y */
  3470.                 }
  3471.             fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
  3472.                 i++;
  3473.             }
  3474.  
  3475.             if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
  3476.             decimals = find_number_of_digits(precision);
  3477.             for(c=2; c<i;c = c+2){
  3478.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  3479.                 /* click_cnt++; */
  3480.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3481.             }
  3482.             reset();
  3483.             break;
  3484.  
  3485.         case RECT:
  3486.         /*
  3487.         @ rect x1,y1,x2,y2,color
  3488.         @ use command <code>frect x1,y1,x2,y2,color</code> for a filled rectangle
  3489.         @ use command/keyword <a href='#filled'>filled</a> before command <code>rect x1,y1,x2,y2,color</code>
  3490.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3491.         @%rect%size 400,400%xrange -10,10%yrange -10,10%rect 0,0,4,-4,green%rect 0,5,4,1,red
  3492.         */
  3493.             for(i=0;i<5;i++){
  3494.                 switch(i){
  3495.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  3496.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  3497.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  3498.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  3499.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  3500.                         decimals = find_number_of_digits(precision);
  3501.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  3502.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3503.                         /* click_cnt++; */
  3504.                         reset();
  3505.                         break;
  3506.                 }
  3507.             }
  3508.             break;
  3509.  
  3510.         case RECTS:
  3511.         /*
  3512.         @ rects color,x1,y1,x2,y2,.....
  3513.         @ use command <code>frect color,x1,y1,x2,y2,.....</code> for a filled rectangle
  3514.         @ use command/keyword <a href='#filled'>filled</a> before command <code>rects color,x1,y1,x2,y2,....</code>
  3515.         @ use command <code>fillcolor color</code> before ''frects`` to set the fill colour.
  3516.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  3517.         @%rects%size 400,400%xrange -10,10%yrange -10,10%rects red,0,0,4,-4,0,5,4,1
  3518.         */
  3519.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3520.             fill_color = stroke_color;
  3521.             i=0;
  3522.             while( ! done ){     /* get next item until EOL*/
  3523.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3524.                 if(i%2 == 0 ){
  3525.                     double_data[i] = get_real(infile,0); /* x */
  3526.                 }
  3527.                 else
  3528.                 {
  3529.                     double_data[i] = get_real(infile,1); /* y */
  3530.                 }
  3531.                 i++;
  3532.             }
  3533.             decimals = find_number_of_digits(precision);
  3534.             for(c = 0 ; c < i-1 ; c = c+4){
  3535.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  3536.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3537.                 /* click_cnt++; */
  3538.             }
  3539.             reset();
  3540.             break;
  3541.  
  3542.         case REPLYFORMAT:
  3543.         /*
  3544.         @ replyformat number
  3545.         @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop()
  3546.         @ default values should be fine !
  3547.         @ use command <code>precision [0,1,10,100,1000,10000...]</code> before command ''replyformat`` to set the desired number of decimals in the student reply / drawing
  3548.         @ the last value for ''precision int`` will be used to calculate the reply coordinates, if needed (read_canvas();)
  3549.         @ choose<ul><li>replyformat 1: <code>x1,x2,x3,x4....x_n<br />y1,y2,y3,y4....y_n</code> x/y in pixels</li><li>replyformat 2: <code> x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 3: <code> x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n</code> x/y in pixels, r in pixels</li><li>replyformat 4: <code> x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n</code> x/y in xrange / yrange coordinate system, r in pixels</li><li>replyformat 5: <code> 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</code> x/y in pixels</li><li>replyformat 6: <code> 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</code> x/y in xrange / yrange coordinate system</li><li>replyformat 7: <code> x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n</code> x/y in pixels</li><li>replyformat 8: <code> x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 9: <code> x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n</code> x/y in pixels</li><li>replyformat 10: <code> x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 11: <code> 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</code> x/y in xrange / yrange coordinate system</li><li>replyformat 12: <code> 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</code> x/y in pixels</li><li>replyformat 13: <code> Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2</code> x/y in xrange / yrange coordinate system</li><li>replyformat 14: <code> Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2</code> x/y in pixels</li><li>replyformat 15: reply from inputfields,textareas <code>reply1,reply2,reply3,...,reply_n</code></li><li>replyformat 16: mathml input fields</li><li>replyformat 17: read ''userdraw text,color`` only <code>x1,y1,text1 \\n x2,y2,text2...\\n...x_n,y_n,text_n </code> x/y-values are in xrange/yrange</li><li>replyformat 18: read_canvas() will read all interactive clocks in <codeWH1:M1:S1,H2:M2:S2...Hn:Mn:Sn</code></li><li>replyformat 19: read_canvas() will return the object number of marked / clicked object (clock), analogue to (shape library) onclick command</li><li>replyformat 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, e.g. expect something like 0:-5:4,1:6:2,2:-2:-5, the first image position is (-5:4), the second image position is (6:2) and the third image position is (-2:-5)         <li>replyformat 21: <code> (x1:y1) (x2:y2) ... (x_n:y_n)</code> verbatim coordinate return</li><li>replyformat 22: returns an array .... <code>reply[0]=x1 reply[1]=y1 reply[2]=x2 reply[3]=y2 ... reply[n-1]=x_n reply[n]=y_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 23: can only be used for drawtype ''polyline``. 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 gives <code>x1,y1,x2,y2,x3,y3,.....x(n-1),y(n-1),xn,yn</code>; multiple occurences will be filtered out. The reply will be in x-y-range (xreply \\n yreply)</li><li>replyformat 24: read all inputfield values: even those set ''readonly``</li><li>replyformat 25: <code> angle1,angle2;...;angle_n</code> will return the radius (one or many) of the user drawn circle segment in degrees</li><li>replyformat 26: <code> rad1,rad2,...rad_n</code> will return the radius (one or many) of the user drawn circle segment in radians</li><li>replyformat 27: return (only) userdraw inputfields <code>x1,y1,text1<br /> x2,y2,text2...<br />...x_n,y_n,textn</code></li><li>replyformat 28: <code> x1,y1,r1,x2,y2,r2...x_n,y_n,r_n</code> x / y / r in xrange / yrange coordinate system: may be used to reinput into command <code>circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n</code> will not return anything else (e.g. no inputfields, text etc)</li><li>replyformat 34: a special for OEF and dragging external images -included via commands <a href='#copy'>copy</a> or <a href='#copyresized'>copyresized</a> there will be an extra function <code>read_canvas_images()</code> for reading the coordinates of the images.<br />for now this is a unique function, e.g. there is no ''canvas id`` linked to it. (TO DO !!! 18/5/2019)</li></ul>
  3550.         */
  3551.          reply_format = (int) get_real(infile,1);
  3552.          reply_precision = precision;
  3553.         break;
  3554.  
  3555.         case ROUNDRECT:
  3556.         /*
  3557.         @ roundrect x1,y1,x2,y2,radius in px,color
  3558.         @ use command <code>froundrect x1,y1,x2,y2,radius,color</code> for a filled rectangle
  3559.         @ use command/keyword <a href='#filled'>filled</a> before command <code>roundrect x1,y1,x2,y2,radius,color</code>
  3560.         @ fillcolor will be identical to ''color``
  3561.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3562.         @%roundrect%size 400,400%xrange -10,10%yrange -10,10%roundrect 0,0,4,-4,20,green%roundrect 0,5,4,1,10,red
  3563.         */
  3564.             for(i=0;i<6;i++){
  3565.                 switch(i){
  3566.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  3567.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  3568.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  3569.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  3570.                     case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
  3571.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  3572.                         /* ensure no inverted roundrect is produced... */
  3573.                         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];}
  3574.                         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];}
  3575.                         decimals = find_number_of_digits(precision);
  3576.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  3577.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3578.                         /* click_cnt++;*/
  3579.                         reset();
  3580.                     break;
  3581.                 }
  3582.             }
  3583.             break;
  3584.  
  3585.         case ROUNDRECTS:
  3586.         /*
  3587.         @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,....
  3588.         @ for filled roundrects use command/keyword <a href='#filled'>filled</a> before command
  3589.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  3590.         @%roundrects%size 400,400%xrange -10,10%yrange -10,10%roundrects blue,5,0,0,4,-4,5,4,1,2
  3591.         */
  3592.  
  3593.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3594.             int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */
  3595.             fill_color = stroke_color;
  3596.             i=0;
  3597.             while( ! done ){     /* get next item until EOL*/
  3598.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3599.                 if(i%2 == 0 ){
  3600.                     double_data[i] = get_real(infile,0); /* x */
  3601.                 }
  3602.                 else
  3603.                 {
  3604.                     double_data[i] = get_real(infile,1); /* y */
  3605.                 }
  3606.                 i++;
  3607.             }
  3608.             decimals = find_number_of_digits(precision);
  3609.             for(c = 0 ; c < i-1 ; c = c+4){
  3610.                 /* ensure no inverted roundrect is produced... */
  3611.                 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];}
  3612.                 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];}
  3613.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  3614.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3615.                 /* click_cnt++; */
  3616.             }
  3617.             reset();
  3618.             break;
  3619.  
  3620.         case RULER:
  3621.         /*
  3622.         @ ruler x,y,x-width,y-height,mode
  3623.         @ x,y are the initial location
  3624.         @ x-width, y-height are the ruler dimensions width &amp; height in xy-coordinate system
  3625.         @ the ruler scale is by definition the x-scale, set by command ''xrange``. For example: a ruler x-width of 6 will have a scale ranging from 0 to 6
  3626.         @ 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
  3627.         @ if combined with a protractor, use replyformat = 32
  3628.         @ only one ruler allowed (for the time being)
  3629.         @ when using command ''zoom``, pay <b>attention</b> to the size and symmetry of your canvas to avoid a partial image, locate the start position near the center of the visual canvas; technical: the actual ''ruler`` is just a static generated image in a new canvas-memory. This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas. That is the reason for the ''high-speed dragging and rotating``. I have limited its size to xsize &times; ysize e.g. the same size as the visual canvas...
  3630.         @ usage: first left click on the ruler will activate dragging; a second left click will activate rotating (just move mouse around), a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3), a next click will restart this sequence...
  3631.         @%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
  3632.         @%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
  3633.         @%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
  3634.         */
  3635.             for( i = 0;i < 5; i++ ){
  3636.                 switch(i){
  3637.                     case 0: double_data[0] = get_real(infile,0);break; /* x-center */
  3638.                     case 1: double_data[1] = get_real(infile,0);break; /* y-center */
  3639.                     case 2: double_data[2] = get_real(infile,0);break; /* x-width */
  3640.                     case 3: double_data[3] = get_real(infile,0);break; /* y-width */
  3641.                     case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */
  3642.                     decimals = find_number_of_digits(precision);
  3643.                     if( int_data[0] < 0 ){
  3644.                       if( js_function[JS_FIND_ANGLE] != 1 ){  js_function[JS_FIND_ANGLE] = 1; }
  3645.                     }
  3646.                     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],use_snap);
  3647.                     string_length = 1 + snprintf(NULL,0,";ruler%d(); ",canvas_root_id);
  3648.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3649.                     snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id);
  3650.                     add_to_buffer(tmp_buffer);
  3651.                     reply_precision = precision;
  3652.                     /* no reply from ruler if non-interactive */
  3653.                     if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;}
  3654.                     break;
  3655.                     default: break;
  3656.                 }
  3657.             }
  3658.             break;
  3659.  
  3660.         case RESETOFFSET:
  3661.         /*
  3662.          @ resetoffset
  3663.          @ keyword
  3664.          @ use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text
  3665.          @ 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).
  3666.         */
  3667.          use_offset = 0;
  3668.          break;
  3669.  
  3670.         case ROTATE:
  3671.         /*
  3672.          @ rotate rotation_angle
  3673.          @ angle in degrees
  3674.          @ (only) the next object will be rotated is given angle
  3675.          @ positive values rotate counter clockwise
  3676.          @ attention: all objects will be rotated around their first point...<br /><code>rotate 45<br />triangle 1,1,5,1,3,4,red</code><br />will rotate 45 degrees around point (1:1)
  3677.          @ 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>
  3678.          @ 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
  3679.          @%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%
  3680.         */
  3681.             use_rotate = TRUE;
  3682.             angle = -1*(get_real(infile,1));/* -1: to be compatible with Flydraw... */
  3683.             break;
  3684.         case ROTATION_CENTER:
  3685.         /*
  3686.         @ rotationcenter x_center,y_center
  3687.         @ define an rotation center in your x/y-coordinate system
  3688.         @ wims will not check the validity of your input; use javascript console to debug any erors
  3689.         @ if not defined a rotation will be around the first point of an object
  3690.         @ to be used before command <a href="#rotate">rotate</a>
  3691.         @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given
  3692.         @%rotationcenter%size 400,400%xrange -5,10%yrange -5,10%circles green,3,3,4.25%rotationcenter 3,3%opacity 255,80%fpoly yellow,0,0,4,3,2,5%rotate 45%fpoly violet,0,0,4,3,2,5%rotate 90%fpoly lightblue,0,0,4,3,2,5%rotate 135%fpoly blue,0,0,4,3,2,5%rotate 180%fpoly orange,0,0,4,3,2,5%rotate 225%fpoly green,0,0,4,3,2,5%rotate 270%fpoly cyan,0,0,4,3,2,5%rotate 315%fpoly purple,0,0,4,3,2,5%linewidth 3%point 3,3,red%mouse red,22
  3693.         @%rotationcenter_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fillcolor black%strokecolor yellow%rotationcenter 0,0%fontsize 24%slider 0,2*pi,400,30,angle degrees,rotate...%plot red,5*sin(x)%filled%linewidth 1%opacity 150,50%fillcolor orange%angle 0,0,pi,0,0,blue
  3694.         */
  3695.             temp = get_string(infile,1);
  3696.             string_length = 1 + snprintf(NULL,0,"[ %s ]",temp);
  3697.             check_string_length(string_length);
  3698.             rotation_center = my_newmem(string_length);
  3699.             snprintf(rotation_center,string_length,"[%s]",temp);
  3700.             break;
  3701.  
  3702.         case SIZE:
  3703.             /*
  3704.             @ size width,height
  3705.             @ set canvas size in pixels
  3706.             @ mandatory first command (can only be preceded by keyword <a href="#popup">popup</a>)
  3707.             @ 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
  3708.             */
  3709.             found_size_command = 1;
  3710.             /* using fabs: however "xsize == int": so "xsize = abs( (int) get_real(infile,0))" would be the idea... */
  3711.             xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
  3712.             ysize = (int)(fabs(round(get_real(infile,1))));
  3713.             /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
  3714.             xmin = 0;xmax = xsize;
  3715.             ymin = 0;ymax = ysize;
  3716.  
  3717. /*
  3718.  The sequence in which stuff is finally printed is important !!
  3719. */
  3720. fprintf(stdout,"\n\
  3721. <script>\n\
  3722. /*<![CDATA[*/\n\
  3723. if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\
  3724. if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\
  3725. if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\
  3726. canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\
  3727. ",canvas_root_id);
  3728.  
  3729. /* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */
  3730. if( use_tooltip != 2){
  3731.  fprintf(stdout,"<!-- canvasdraw div  -->\n\
  3732. <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\
  3733. <!-- tooltip and input placeholder  -->\n\
  3734. <div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\
  3735. <!-- include actual object code via include file -->\n\
  3736. <script id=\"canvas_script%d\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd);
  3737. }
  3738. else
  3739. {
  3740. /*
  3741. set canvas_div invisible and do not include placeholder in main html page:
  3742. the js-include will also be in a popup window...to be shown when wims $status = done
  3743. */
  3744.  fprintf(stdout,"<!-- canvasdraw div invisible  -->\n\
  3745. <div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\
  3746. <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>\
  3747. <!-- include actual object code via include file -->\n\
  3748. <script id=\"canvas_script%d\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd);
  3749. }
  3750.  
  3751. /* these must be global...it is all really very poor javascript:( */
  3752. fprintf(js_include_file,"\n/* begin generated javascript include for canvasdraw */\n\
  3753. \"use strict\";\n\
  3754. /* these variables and functions must be global */\n\
  3755. var read_dragdrop%d;\
  3756. var read_canvas_images;\
  3757. var read_canvas%d;\
  3758. var set_clock;\
  3759. var clear_draw_area%d;\
  3760. var update_draw_area%d;\
  3761. var place_image_on_canvas;\
  3762. var draw_boxplot;\
  3763. var redraw_all%d;\
  3764. var userdraw_primitive;\n\
  3765. var wims_canvas_function%d = function(){\n/* common used stuff */\n\
  3766. var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\
  3767. var xsize = %d;\
  3768. var ysize = %d;\
  3769. var precision = 100;\
  3770. var canvas_div = document.getElementById(\"canvas_div%d\");\
  3771. 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;};\
  3772. 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;};\
  3773. 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);};};\
  3774. 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);};};\
  3775. 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);};};\
  3776. 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);};};\
  3777. function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
  3778. function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
  3779. function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\
  3780. 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) ));};\
  3781. 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;};\
  3782. function slide(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = parseInt(obj.x[p] + dx);obj.y[p] = parseInt(obj.y[p] + dy);};return obj;};\
  3783. var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));var snap_x = 1;var snap_y = 1;\
  3784. function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
  3785. function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\
  3786. function multisnap_check(x,y,snap){switch(snap){case 1:return [snap_to_x(x),snap_to_y(y)];break;case 2:return [snap_to_x(x),y];break;case 3:return [x,snap_to_y(y)];break;case 4:return snap_to_points(x,y);break;default: return [x,y];break;};};\
  3787. var xlogbase = 10;\
  3788. var ylogbase = 10;\
  3789. var use_xlogscale = 0;\
  3790. var use_ylogscale = 0;\
  3791. var x_strings = {};var x_strings_up = [];\
  3792. var y_strings = null;\
  3793. var use_pan_and_zoom = 0;\
  3794. var use_jsmath = 0;\
  3795. var xstart = 0;\
  3796. var ystart = 0;\
  3797. var unit_x=\" \";\
  3798. var unit_y=\" \";\
  3799. var external_canvas = create_canvas%d(%d,xsize,ysize);",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);
  3800. /* default add the drag code: nearly always used ...*/
  3801.   add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
  3802.  
  3803.             break;
  3804.  
  3805.  
  3806.         case SEGMENT:
  3807.         /*
  3808.         @ segment x1,y1,x2,y2,color
  3809.         @ alternative: <code>seg</code>
  3810.         @ draw a line segment between points (x1:y1)--(x2:y2) in color ''color``
  3811.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3812.         @%segment_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segment 1,1,-9,3,green
  3813.         @%segment_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segment 1,1,-9,3,green
  3814.         */
  3815.             for(i=0;i<5;i++) {
  3816.                 switch(i){
  3817.                     case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
  3818.                     case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
  3819.                     case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
  3820.                     case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
  3821.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  3822.                         decimals = find_number_of_digits(precision);
  3823.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  3824.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3825.                         /* click_cnt++; */
  3826.                         reset();
  3827.                         break;
  3828.                     default: break;
  3829.                 }
  3830.             }
  3831.             break;
  3832.  
  3833.         case SEGMENTS:
  3834.         /*
  3835.         @ segments color,x1,y1,x2,y2,...,x_n,y_n
  3836.         @ alternative: <code>segs</code>
  3837.         @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color ''color``
  3838.         @ use command ''linewidth int'' to adust size
  3839.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  3840.         @%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
  3841.         @%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
  3842.         */
  3843.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3844.             fill_color = stroke_color;
  3845.             i=0;
  3846.             while( ! done ){     /* get next item until EOL*/
  3847.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3848.                 if(i%2 == 0 ){
  3849.                     double_data[i] = get_real(infile,0); /* x */
  3850.                 }
  3851.                 else
  3852.                 {
  3853.                     double_data[i] = get_real(infile,1); /* y */
  3854.                 }
  3855.                 i++;
  3856.             }
  3857.             decimals = find_number_of_digits(precision);
  3858.             for(c = 0 ; c < i-1 ; c = c+4){
  3859.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  3860.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3861.                 /* click_cnt++;*/
  3862.             }
  3863.             reset();
  3864.             break;
  3865.  
  3866.         case SETLIMITS:
  3867.         /*
  3868.             @ setlimits
  3869.             @ keyword: if set, it will produce 4 inputfields for ''xmin,xmax,ymin,ymax`` and an ''ok`` button
  3870.             @ may be used for inputfield based zooming / panning
  3871.             @ may be styled using command <a href="#inputstyle">inputstyle</a>
  3872.             @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to ''xlabel`` etc
  3873.             @ note: the input value will not be checked on validity
  3874.             @%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
  3875.         */
  3876.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  3877.             add_setlimits(js_include_file,canvas_root_id,font_size,input_style);
  3878.             /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
  3879.             use_pan_and_zoom = TRUE;
  3880.             done = TRUE;
  3881.             break;
  3882.  
  3883.         case SETPIXEL:
  3884.         /*
  3885.         @ setpixel x,y,color
  3886.         @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange
  3887.         @ pixels can <b>not</b> be dragged or clicked
  3888.         @ "pixelsize = 1" may be changed by command <code>pixelsize int</code>
  3889.         @%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%
  3890.         */
  3891.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  3892.             for(i=0;i<3;i++){
  3893.                 switch(i){
  3894.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  3895.                     case 1: double_data[1] = get_real(infile,0); break; /* y */
  3896.                     case 2: stroke_color = get_color(infile,1);
  3897.                            string_length = 1 + snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  3898.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3899.                            snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  3900.                            add_to_buffer(tmp_buffer);
  3901.                            break;
  3902.                     default:break;
  3903.                 }
  3904.             }
  3905.             reset();
  3906.         break;
  3907.         case SLIDER:
  3908.         /*
  3909.         @ slider start_value,end_value,width px,height px,type,label
  3910.         @ type may be: ''xy,x,y,angle``
  3911.         @ 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
  3912.         @ if a unit (or something like that...) for x/y-value display is needed, use commands ''xunit`` and / or ''yunit``
  3913.         @ 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 /><code>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... etc</code>
  3914.         @ use command ''slider`` before draggable/clickable objects.
  3915.         @ drag and drop may be combined with rotation slider<br />for example an arrow rotated by a slider may be placed anywhere (drag&drop)<br /><code>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</code>
  3916.         @ no slider for a math function, these can be traced using command ''trace_jscurve some_function_in_x``
  3917.         @ 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``
  3918.         @ amount of sliders is not limited.
  3919.         @ a slider can not be set ''snaptogrid`` or other ''snapto*`` : you may always use 'drag xy' in combination with the slider objects
  3920.         @ <code>javascript:read_dragdrop();</code> will return an array with ''object_number:slider_value``
  3921.         @ type=xy: will produce a 2D ''slider`` [rectangle width x heigh px] in your web page
  3922.         @ every draggable object may have its own slider (no limit in amount of sliders)
  3923.         @ label: some slider text
  3924.         @ use fillcolor for slider ball
  3925.         @ use strokecolor for slider bar
  3926.         @ use fontfamily / fontcolor to set used fonts
  3927.         @ use opacity (only fill opacity will be used) to set transparency
  3928.         @ the slider canvas will be added to the ''tooltip div``: so incompatible with command tooltip ; setlimits etc
  3929.         @%slider_angle%size 300,300%xrange -5,5%yrange -5,5%grid 1,1,grey%linewidth 3%fillcolor orange%strokecolor blue%slider 0,2*pi,300,30,angle degrees,Rotate arrow%arrow 0,0,4.5,0,8,red%opacity 200,100%frect -4,4,1,-1,blue%killslider%frect -4,4,1,-1,blue
  3930.         @%slider_x%size 300,300%xrange -5,5%yrange -5,5%grid 1,1,grey%linewidth 3%fillcolor orange%strokecolor blue%slider 0,2*pi,300,30,x,move arrow%arrow 0,0,4.5,0,8,red%opacity 200,100%frect -4,4,1,-1,blue%killslider%frect -4,4,1,-1,blue%display x,red,12
  3931.         @%slider_x_y_angle%size 300,300%xrange -5,5%yrange -5,5%grid 1,1,grey%linewidth 3%fillcolor orange%strokecolor blue%slider 0,2*pi,300,30,angle degrees,Rotate arrow%arrow 0,0,4.5,0,8,red%killslider%opacity 200,100%slider -2,2,300,30,x,move blue rectangle%frect -4,4,1,-1,blue%killslider%slider -2,2,300,30,y,move green rectangle%frect -4,4,1,-1,green
  3932.         */
  3933.             int_data[2] = 0; /* --> show_display = 0; */
  3934.             for(i=0; i<6 ; i++){
  3935.                 switch(i){
  3936.                     case 0: double_data[0] = get_real(infile,0);break; /* start value */
  3937.                     case 1: double_data[1] = get_real(infile,0);break; /* end value */
  3938.                     case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
  3939.                     case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
  3940.                     case 4: temp = get_string_argument(infile,0); /* type: xy,x,y,angle */
  3941.                             if( ( strstr(temp,"displ")!=0 ||  strstr(temp,"deg")!=0 ||  strstr(temp,"rad")!=0 ) && int_data[2] == 0 ){
  3942.                                 add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity);
  3943.                             }
  3944.                             if(strstr(temp,"angle")!= 0){slider_type="R";if( strstr(temp,"rad")!= 0){int_data[2] = 3;}if( strstr(temp,"deg")!= 0){int_data[2] = 4;}}
  3945.                             else
  3946.                             if(strstr(temp,"xy") != 0){slider_type = "XY";if( strstr(temp,"disp")!= 0){int_data[2] = 5;}}
  3947.                             else
  3948.                             if(strstr(temp,"x") != 0){slider_type = "X";if( strstr(temp,"disp")!= 0){int_data[2] = 1;}}
  3949.                             else
  3950.                             if(strstr(temp,"y") != 0){slider_type = "Y";if( strstr(temp,"disp")!= 0){int_data[2] = 2;}}
  3951.                             else
  3952.                             canvas_error("slider can be of type: xy,x,y,angle,fun_x:fun_y");
  3953.                             break;
  3954.                     case 5: temp = get_string_argument(infile,1); /* slider label */ break;
  3955.                 }
  3956.              }
  3957. /*
  3958. function add_slider(type,titletext,id,width,height,linewidth,fillcolor,strokecolor,opacity,min,max,fun,fontfamily)
  3959. */
  3960.             if(slider_cnt == 0){
  3961.              add_slider(js_include_file,canvas_root_id);
  3962.              active_sliders[0] = 0;
  3963.             }
  3964.             string_length = 1 + snprintf(NULL,0,"slider%d = new slider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,null,'%s',%d);\n",slider_cnt,slider_type,temp,slider_cnt,int_data[0],int_data[1],line_width,fill_color,stroke_color,fill_opacity,stroke_opacity,double_data[0],double_data[1],font_family,int_data[2]);
  3965.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3966.             snprintf(tmp_buffer,string_length  ,"slider%d = new slider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,null,'%s',%d);\n",slider_cnt,slider_type,temp,slider_cnt,int_data[0],int_data[1],line_width,fill_color,stroke_color,fill_opacity,stroke_opacity,double_data[0],double_data[1],font_family,int_data[2]);
  3967.             add_to_buffer(tmp_buffer);
  3968.             fprintf(js_include_file,"var slider%d;",slider_cnt);
  3969.             /* increment here */
  3970.             slider_cnt++;
  3971.             active_sliders[slider_cnt] = slider_cnt;
  3972.             current_sliders = data2js_array(active_sliders,slider_cnt);
  3973.         break;
  3974.  
  3975.         case SLIDER_X:
  3976.         /*
  3977.          @ sliderfunction_x some_function_in_x
  3978.          @ default value "x"
  3979.          @ the x-value of the slider object will be calculated with this function.
  3980.          @ default is the x-slider value itself
  3981.          @ only used by command ''slider``
  3982.          @ define before a slider command !
  3983.         */
  3984.          slider_function_x = get_string(infile,1);
  3985.         break;
  3986.         case SLIDER_Y:
  3987.          slider_function_y = get_string(infile,1);
  3988.          /*
  3989.          @ sliderfunction_y some_function_in_y
  3990.          @ default value "y"
  3991.          @ the y-value of the slider object(s) will be calculated with this function.
  3992.          @ only used by command ''slider``
  3993.          @ define before a slider command !
  3994.          */
  3995.         break;
  3996.         case SGRAPH:
  3997.         /*
  3998.          @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
  3999.          @ primitive implementation of a ''broken scale`` graph...
  4000.          @ 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 />
  4001.          @%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
  4002.         */
  4003.             if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
  4004.             for(i = 0 ; i < 8 ;i++){
  4005.                 switch(i){
  4006.                     case 0:double_data[0] = get_real(infile,0);break;
  4007.                     case 1:double_data[1] = get_real(infile,0);break;
  4008.                     case 2:double_data[2] = get_real(infile,0);break;
  4009.                     case 3:double_data[3] = get_real(infile,0);break;
  4010.                     case 4:int_data[0] = (int)(get_real(infile,0));break;
  4011.                     case 5:int_data[1] = (int)(get_real(infile,0));break;
  4012.                     case 6:stroke_color = get_color(infile,0);break;
  4013.                     case 7:font_color = get_color(infile,1);
  4014.                     string_length = 1 + 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);
  4015.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4016.                     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);
  4017.                     add_to_buffer(tmp_buffer);
  4018.                     break;
  4019.                     default:break;
  4020.                 }
  4021.             }
  4022.             /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
  4023.             break;
  4024.  
  4025.         case SNAPTOFUNCTION:
  4026.         /*
  4027.         @ snaptofunction some_function_in_x,some_funtion_in_y
  4028.         @ alternative: <code>snaptofun some_function_in_x,some_funtion_in_y</code>
  4029.         @ the next object will snap to the calculated values
  4030.         @ note: snaptofun is probably not really useful feature...
  4031.         @ if you want only modification of y-values,just use: <code>snaptofunction x,5*sin(1/y)</code>
  4032.         @ if you want only modification of x-values,just use: <code>snaptofunction 5*sin(1/x),y</code>
  4033.         @ for now only one instance of ''snaptofunction`` is allowed
  4034.         @ use rawmath on your functions: no validity checking is done by wims !
  4035.         @ note: switching x and y coordinates? <code>snaptofunction y,x</code>
  4036.         @%snaptofunction_1%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%snaptofunction x,5*sin(x)%linewidth 3%crosshairsize 6%userdraw crosshairs,red%linewidth 2%curve blue,5*sin(x)%xunit = x-value%display x,blue,22
  4037.         @%snaptofunction_2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%snaptofunction y^2-9,y%#snaptofunction y^2-9,abs(y)%linewidth 3%crosshairsize 6%userdraw crosshairs,red%linewidth 2%curve blue,sqrt(x+9)%curve blue,-1*sqrt(x+9)%yunit = y-value%display y,blue,22
  4038.         */
  4039.         temp = get_string_argument(infile,0);
  4040.         use_snap = 2;
  4041.         if( use_js_math == FALSE){/* add this stuff only once...*/
  4042.             add_to_js_math(js_include_file); use_js_math = TRUE;
  4043.         }
  4044.         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));
  4045.         break;
  4046.         case SNAPTOPOINTS:
  4047.         /*
  4048.         @ snaptopoints x1,y1,x2,y2,x3,y3....
  4049.         @ a userdraw object will snap to these points.
  4050.         @ the array size (e.g. the number of points) of command ''snaptopoints`` is limited by constant MAX_INT (canvasdraw.h)
  4051.         @ a draggable object (use command ''drag x|y|xy``) will snap to the closed of these points when dragged (mouseup)
  4052.         @ other options: use keyword ''snaptogrid``, ''xsnaptogrid`` or ''ysnaptogrid``
  4053.         @%snaptopoints%size 400,400%xrange -5,5%yrange -5,5%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
  4054.         */
  4055.             i = 0;
  4056.             use_snap = 4;
  4057.             while( ! done ){     /* get next item until EOL*/
  4058.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4059.                 if(i%2 == 0 ){
  4060.                     double_data[i] = get_real(infile,0); /* x */
  4061.                 }
  4062.                 else
  4063.                 {
  4064.                     double_data[i] = get_real(infile,1); /* y */
  4065.                 }
  4066.                 i++;
  4067.             }
  4068.             decimals = find_number_of_digits(precision);
  4069.             fprintf(js_include_file,"function 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;};function 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)];};",(int) (0.5*i),double_xy2js_array(double_data,i,decimals));
  4070.         break;
  4071.  
  4072.         case SNAPTOGRID:
  4073.         /*
  4074.          @ snaptogrid
  4075.          @ keyword (no arguments required)
  4076.          @ a draggable object (use command ''drag x|y|xy``) will snap to the given grid when dragged (mouseup)
  4077.          @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
  4078.          @ if no grid is defined, points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1)
  4079.          @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
  4080.          @ 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 <code>snaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red</code> will snap on x=0, x=0.5, x=1, x=1.5 .... will snap on y=0, y=0.25 y=0.5 y=0.75 ...
  4081.          @%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
  4082.          @%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
  4083.         */
  4084.         use_snap = 1;
  4085.         break;
  4086.  
  4087.         case SQUARE:
  4088.         /*
  4089.         @ square x,y,side (px),color
  4090.         @ draw a square with left top corner (x:y) with side ''side`` in color ''color``
  4091.         @ use command <code>fsquare x,y,side,color</code> for a filled square
  4092.         @ use command/keyword <a href='#filled'>filled</a> before command <code>square x,y,side,color</code>
  4093.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4094.         @%square%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%filled%fillcolor blue%square 0,0,120,green
  4095.         */
  4096.             for(i=0;i<4;i++){
  4097.                 switch(i){
  4098.                     case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
  4099.                     case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
  4100.                     case 2:double_data[2] = get_real(infile,0);break; /* width in px */
  4101.                     case 3:stroke_color = get_color(infile,1);/* name or hex color */
  4102.                            decimals = find_number_of_digits(precision);
  4103.                            double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
  4104.                            double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
  4105.                            fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  4106.                            if(onclick > 0 || slider_cnt > 0){click_cnt++;}/* click_cnt++; */
  4107.                            reset();break;
  4108.                     default: break;
  4109.                 }
  4110.             }
  4111.             break;
  4112.  
  4113.         case STATUS:
  4114.         /*
  4115.         @ status
  4116.         @ keyword
  4117.         @ alernative: nostatus
  4118.         @ used to override the effects of ''status=done`` in wims (answer.phtml)
  4119.         @ affects ''readonly`` in inputfields / textareas in canvasimage and all userdraw based commands
  4120.         @ e.g.: if keyword ''status`` is set, the pupil will be able to modify the canvas when the ''wims &#36;status variable`` is set to ''done``
  4121.         */
  4122.  
  4123.             fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
  4124.             break;
  4125.  
  4126.         case STRING:
  4127.         /*
  4128.          @ string color,x,y,the text string
  4129.          @ may be set ''onclick`` or ''drag xy``
  4130.          @ unicode supported: <code>string red,0,0,\\u2232</code>
  4131.          @ use a command like <code>fontfamily italic 24px Ariel</code> to set fonts on browser that support font change
  4132.          @%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
  4133.         */
  4134.             for(i=0;i<5;i++){
  4135.                 switch(i){
  4136.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  4137.                     case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
  4138.                     case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
  4139.                     case 3: decimals = find_number_of_digits(precision);
  4140.                         temp = get_string_argument(infile,1);
  4141.                         decimals = find_number_of_digits(precision);
  4142.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  4143.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  4144.                         onclick = 0;
  4145.                         use_offset = 0;
  4146.                         reset();;
  4147.                         break;
  4148.                     default:break;
  4149.                 }
  4150.             }
  4151.             break;
  4152.  
  4153.         case STRINGUP:
  4154.         /*
  4155.          @ stringup color,x,y,rotation_degrees,the text string
  4156.          @ can <b>not</b> be set ''onclick`` or ''drag xy`` (because of translation matrix...mouse incompatible).
  4157.          @ unicode supported: <code>stringup red,0,0,45,\\u2232</code>.
  4158.          @ use a command like <code>fontfamily bold 34px Courier</code> to set fonts on browser that support font change.
  4159.          @ you could use keyword <a href='#yoffset'>yoffset</a> to -sometimes- do a small correction of text placement under/above a point (e.g. text &amp; point have the same coordinates).
  4160.          @%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
  4161.  
  4162.         */
  4163.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library: rotate / mouse issues */
  4164.             for(i=0;i<6;i++){
  4165.                 switch(i){
  4166.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  4167.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  4168.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  4169.                     case 3: double_data[0] = get_real(infile,0);break;/* rotation */
  4170.                     case 4: decimals = find_number_of_digits(precision);
  4171.                             temp = get_string_argument(infile,1);
  4172.                             string_length = 1 + 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);
  4173.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4174.                             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);
  4175.                             add_to_buffer(tmp_buffer);
  4176.                             use_offset=0;
  4177.                             reset();
  4178.                             break;
  4179.                     default:break;
  4180.                 }
  4181.             }
  4182.             break;
  4183.  
  4184.         case STYLE:
  4185.         /*
  4186.          @ highlight color,opacity,linewidth
  4187.          @ NOT IMPLEMENTED
  4188.          @ use command ''onclick``: when the object receives a userclick it will increase its linewidth
  4189.         */
  4190.             break;
  4191.  
  4192.  
  4193.         case STROKECOLOR:
  4194.         /*
  4195.         @ strokecolor colorname or #hex
  4196.         @ to be used for commands that do not supply a color argument (like command ''linegraph``)
  4197.         */
  4198.             stroke_color = get_color(infile,1);
  4199.             break;
  4200.  
  4201.         case FLY_TEXT:
  4202.         /*
  4203.         @ text fontcolor,x,y,font,text_string
  4204.         @ font may be described by keywords: giant,huge,normal,small,tiny
  4205.         @ use command ''fontsize`` to increase base fontsize for these keywords
  4206.         @ may be set ''onclick`` or ''drag xy``
  4207.         @ backwards compatible with flydraw
  4208.         @ unicode supported: text red,0,0,huge,\\u2232
  4209.         @ use command ''string`` combined with ''fontfamily`` for a more fine grained control over html5 canvas text element
  4210.         @ Avoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``, ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Ariel</code>. In that case reset ''fontfamily`` to something lke ''fontfamily Ariel`` before the old flydraw commands.
  4211.         @%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
  4212.         */
  4213.             for(i = 0; i < 5 ;i++){
  4214.                 switch(i){
  4215.                     case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
  4216.                     case 1: double_data[0] = get_real(infile,0);break; /* x */
  4217.                     case 2: double_data[1] = get_real(infile,0);break; /* y */
  4218.                     case 3: fly_font = get_string_argument(infile,0);
  4219.                             if(strcmp(fly_font,"giant") == 0){
  4220.                                 fly_font_size = (int)(font_size + 24);
  4221.                             }
  4222.                             else
  4223.                             {
  4224.                                 if(strcmp(fly_font,"huge") == 0){
  4225.                                     fly_font_size = (int)(font_size + 14);
  4226.                                 }
  4227.                                 else
  4228.                                 {
  4229.                                     if(strcmp(fly_font,"large") == 0){
  4230.                                         fly_font_size = (int)(font_size + 6);
  4231.                                         }
  4232.                                         else
  4233.                                         {
  4234.                                             if(strcmp(fly_font,"small") == 0){
  4235.                                                 fly_font_size = (int)(font_size - 4);
  4236.                                                 if(fly_font_size<0){fly_font_size = 8;}
  4237.                                         }
  4238.                                     }
  4239.                                 }
  4240.                             }
  4241.                             break;
  4242.                     case 4:
  4243.                         temp = get_string_argument(infile,1);
  4244.                         decimals = find_number_of_digits(precision);
  4245.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,%s,%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  4246.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  4247.                         onclick=0;
  4248.                         use_offset = 0;
  4249.                         reset();
  4250.                         break;
  4251.                     default:break;
  4252.                 }
  4253.             }
  4254.             break;
  4255.         case TEXTAREA:
  4256.         /*
  4257.          @ textarea x,y,cols,rows,readonly,value
  4258.          @ may be further controlled by <a href="#inputstyle">inputstyle</a>
  4259.          @ if ''&#36;status=done`` (e.g. in answer.phtml) the inputfield will be cleared and set readonly. Override this by keyword <a href="#status">status</a>.
  4260.          @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (<code>javascript:read_canvas();</code>)
  4261.          @ keyword ''xoffset | centered`` is not active for command ''textarea``
  4262.          @%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,?
  4263.         */
  4264.             if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}
  4265.             for(i = 0 ; i<6;i++){
  4266.                 switch(i){
  4267.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
  4268.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
  4269.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
  4270.                     case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
  4271.                     case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
  4272.                     case 5: temp = get_string_argument(infile,1);
  4273.                             string_length = 1 + 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);
  4274.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4275.                             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);
  4276.                             add_to_buffer(tmp_buffer);
  4277.                             input_cnt++;break;
  4278.                     default: break;
  4279.                 }
  4280.             }
  4281.             if(reply_format == 0 ){reply_format = 15;}
  4282.             reset();
  4283.             break;
  4284.  
  4285.         case TEXTFILL:
  4286.         /*
  4287.         @ textfill x0,y0,color,some_text
  4288.         @ x0,y0 in xrange / yrange
  4289.         @ color will be used for the font color
  4290.         @ use command <a href="#fontfamily">fontfamily</a> to set font type and size
  4291.         @ there is also a command <a href="#userdraw">userdraw textfill,color,some_text</a>
  4292.         @%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,HELLO WORLD
  4293.         */
  4294.  
  4295.             js_function[DRAW_TEXTFILL] = 1;
  4296.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  4297.              js_function[DRAW_FILLTOBORDER] = 1;
  4298.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  4299.             }
  4300.             decimals = find_number_of_digits(precision);
  4301.             for(i=0;i<4;i++){
  4302.                 switch(i){
  4303.                     case 0: double_data[0] = get_real(infile,0); break; /* x in px */
  4304.                     case 1: double_data[1] = get_real(infile,0); break; /* y in py */
  4305.                     case 2: font_color = get_color(infile,0); break;
  4306.                     case 3: temp = get_string(infile,1);
  4307.                     string_length = 1 + 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);
  4308.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4309.                     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);
  4310.                     add_to_buffer(tmp_buffer);
  4311.                     fill_cnt++;
  4312.                     break;
  4313.                     default:break;
  4314.                 }
  4315.             }
  4316.             reset();
  4317.         break;
  4318.  
  4319.  
  4320.         case FLY_TEXTUP:
  4321.         /*
  4322.          @ textup fontcolor,x,y,font,text_string
  4323.          @ can <b>not</b> be set ''onclick`` or ''drag xy`` (because of translaton matrix...mouse incompatible)
  4324.          @ font may be described by keywords: giant,huge,normal,small,tiny
  4325.          @ use command ''fontsize`` to increase base fontsize for the keywords
  4326.          @ backwards compatible with flydraw
  4327.          @ unicode supported: textup red,0,0,huge,\\u2232
  4328.          @ use command ''stringup`` and ''fontfamily`` for a more fine grained control over html5 canvas text element
  4329.          @ Avoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``; ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Ariel</code>. In that case reset ''fontfamily`` to something like ''fontfamily Ariel`` before the old flydraw commands.
  4330.         */
  4331.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
  4332.             for(i = 0; i<5 ;i++){
  4333.                 switch(i){
  4334.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  4335.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  4336.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  4337.                     case 3: fly_font = get_string_argument(infile,0);
  4338.                             if(strcmp(fly_font,"giant") == 0){
  4339.                                 fly_font_size = (int)(font_size + 24);
  4340.                             }
  4341.                             else
  4342.                             {
  4343.                                 if(strcmp(fly_font,"huge") == 0){
  4344.                                     fly_font_size = (int)(font_size + 14);
  4345.                                 }
  4346.                                 else
  4347.                                 {
  4348.                                     if(strcmp(fly_font,"large") == 0){
  4349.                                         fly_font_size = (int)(font_size + 6);
  4350.                                         }
  4351.                                         else
  4352.                                         {
  4353.                                             if(strcmp(fly_font,"small") == 0){
  4354.                                                 fly_font_size = (int)(font_size - 4);
  4355.                                                 if(fly_font_size<0){fly_font_size = 8;}
  4356.                                         }
  4357.                                     }
  4358.                                 }
  4359.                             }
  4360.                             break;
  4361.                     case 4:
  4362.                     decimals = find_number_of_digits(precision);
  4363.                     temp = get_string_argument(infile,1);
  4364.                     string_length = 1 + 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);
  4365.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4366.                     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);
  4367.                     add_to_buffer(tmp_buffer);
  4368.                     reset();use_offset = 0;
  4369.                     break;
  4370.                     default:break;
  4371.                 }
  4372.             }
  4373.             break;
  4374.  
  4375.  
  4376.         case TRACE_JSCURVE:
  4377.         /*
  4378.          @ trace_jscurve some_math_function
  4379.          @ will use a crosshair to trace the jsmath curve
  4380.          @ two inputfields will display the current x/y-values (numerical evaluation by javascript)
  4381.          @ default labels ''x`` and ''y``; use commands ''xlabel some_x_axis_name`` and ''ylabel some_y_axis_name`` to customize the labels for the input fields
  4382.          @ use commands fontsize and inputstyle to format the fonts for labels and inputfields.
  4383.          @ use commands ''linewidth, strokecolor, crosshairsize`` to adjust the corsshair.
  4384.          @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath: use 2*x instead of 2x etc etc no check is done on the validity of your function and/or syntax (use error console to debug any errors...)
  4385.          @ be aware that the formulas of the plotted function(s) can be found in the page javascript source
  4386.          @%trace_jscurve%size 400,400%xrange -10,10%yrange -10,10%precision 0%axis%axisnumbering%grid 2,2,grey,2,2,5,gray%recision 100%inputstyle color:blue;%linewidth 4%crosshairsize 8%trace_jscurve 5*sin(0.1*x^2)%linewidth 1%jsplot red,5*sin(0.1*x^2)%#only one curve can be traced
  4387.         */
  4388.             if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  4389.             if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4390.             if( use_js_math == FALSE){
  4391.                 add_to_js_math(js_include_file);
  4392.                 use_js_math = TRUE;
  4393.             }
  4394.             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);
  4395.             break;
  4396.  
  4397.  
  4398.         case TRANGE:
  4399.         /*
  4400.         @ trange tmin,tmax
  4401.         @ alternative: <code>ranget</code>
  4402.         @ default -2,2
  4403.         */
  4404.             use_parametric = TRUE;
  4405.             for(i = 0 ; i<2; i++){
  4406.                 switch(i){
  4407.                     case 0: tmin = get_real(infile,0);break;
  4408.                     case 1: tmax = get_real(infile,1);break;
  4409.                     default: break;
  4410.                 }
  4411.             }
  4412.             if(tmin >= tmax ){canvas_error(" trange is not OK: tmin &lt; tmax!\n");}
  4413.             break;
  4414.         case TRANSLATION:
  4415.         /*
  4416.          @ translation tx,ty
  4417.          @ alternative: <code>translate</code>
  4418.          @ will translate the next objects tx in xrange and ty in yrange
  4419.          @ use command ''killtranstation`` to end the command
  4420.          @%translation%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%fillpattern grid%ftriangle -6,6,8,6,5,1,blue%translation 2,2%ftriangle -6,6,8,6,5,1,red
  4421.         */
  4422.             for(i = 0 ; i<2;i++){
  4423.                 switch(i){
  4424.                     case 0: double_data[0] = get_real(infile,0);break;
  4425.                     case 1: double_data[1] = get_real(infile,1);
  4426.                         use_affine = TRUE;
  4427.                         decimals = find_number_of_digits(precision);
  4428.                         string_length = 1 + snprintf(NULL,0, "[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin));
  4429.                         check_string_length(string_length);affine_matrix = my_newmem(string_length);
  4430.                         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));
  4431.                         break;
  4432.                     default: break;
  4433.                 }
  4434.             }
  4435.         break;
  4436.  
  4437.         case TRIANGLE:
  4438.         /*
  4439.          @ triangle x1,y1,x2,y2,x3,y3,color
  4440.          @ use ftriangle or keyword <a href='#filled'>filled</a> for a solid triangle
  4441.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4442.          @%triangle%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%opacity 250,150%drag xy%triangle 0,0,-4,4,6,8,red%drag xy%ftriangle 0,0,-4,-4,6,-8,red%fillpattern grid%drag xy%ftriangle -6,6,8,6,5,1,blue
  4443.         */
  4444.             for(i=0;i<7;i++){
  4445.                 switch(i){
  4446.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  4447.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  4448.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  4449.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  4450.                     case 4: double_data[4] = get_real(infile,0);break; /* x */
  4451.                     case 5: double_data[5] = get_real(infile,0);break; /* y */
  4452.                     case 6: stroke_color = get_color(infile,1);/* name or hex color */
  4453.                         decimals = find_number_of_digits(precision);
  4454.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  4455.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  4456.                         /* click_cnt++;*/
  4457.                         reset();
  4458.                         break;
  4459.                     default: break;
  4460.                 }
  4461.             }
  4462.             break;
  4463.         case TRIANGLES:
  4464.         /*
  4465.          @ triangles color,x1,y1,x2,y2,x3,y3,...
  4466.          @ use ftriangles or keyword <a href='#filled'>filled</a> for solid triangles
  4467.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  4468.          @%triangles%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%onclick%triangles red,0,0,-4,4,6,8,0,0,-4,-4,6,-8,-6,6,8,6,5,1%# the same as 3 calls to command triangle
  4469.         */
  4470.             stroke_color = get_color(infile,0);/* name or hex color */
  4471.             i = 0;
  4472.             decimals = find_number_of_digits(precision);
  4473.             while( ! done ){
  4474.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4475.                 double_data[0] = get_real(infile,0); /* x1 */
  4476.                 double_data[1] = get_real(infile,0); /* y1 */
  4477.                 double_data[2] = get_real(infile,0); /* x2 */
  4478.                 double_data[3] = get_real(infile,0); /* y2 */
  4479.                 double_data[4] = get_real(infile,0); /* x3 */
  4480.                 double_data[5] = get_real(infile,1); /* y3 */
  4481.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  4482.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  4483.                 i = i + 6;
  4484.             }
  4485.             reset();
  4486.             break;
  4487.         case USERBOXPLOT:
  4488.         /*
  4489.          @ userboxplot
  4490.          @ keyword, no arguments
  4491.          @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a>
  4492.          @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the ''draw_boxplot`` function
  4493.          @ for example: 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 /><code>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 />};</code><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)
  4494.         */
  4495.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  4496.             fprintf(js_include_file,"var boxplot_source = 3;\n");
  4497.             js_function[DRAW_JSBOXPLOT] = 2;
  4498.         break;
  4499.  
  4500.         case USERBOXPLOTDATA:
  4501.         /*
  4502.          @ userboxplotdata
  4503.          @ keyword, no arguments
  4504.          @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a>
  4505.          @ if set, the student will have to generate some statistical data. These data should be put in a named array ''student_boxplot_data``
  4506.          @ ''min,Q1,median,Q3,max`` are calculated by a js-function and the ''draw_boxplot`` function will draw a boxplot.
  4507.          @ see command <a href="#userboxplot">userboxplot</a> for calling 'draw_boxplot()'
  4508.         */
  4509.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  4510.             fprintf(js_include_file,"var boxplot_source = 2;\n");
  4511.             js_function[DRAW_JSBOXPLOT] = 1;
  4512.  
  4513.         break;
  4514.  
  4515.         case USERDRAW:
  4516.         /*
  4517.         @ userdraw object_type,color
  4518.         @ only a single object_type is allowed.
  4519.         @ for multiple different ''userdraw`` objects in an exercise, use command <a href="#multidraw">multidraw</a>
  4520.         @ 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>''curvedarrow``</li><li>''curvedarrows``</li><li>''curvedarrow2``</li><li>''curvedarrows2``</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``. Multiple areas may be selected, 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 ! 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 <code>userdraw textfill,blue,some_text</code>. use command <a href="#fontfamily">fontfamily</a> to adjust text style and size</li><li>''clickfill | pattern filling`` in general: 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``: place a single inputfield on ''canvas`` ; use commands ''inputstyle`` for css styling; use command ''linewidth`` for adjusting the input field size (default 1)</li><li>''inputs``: place multiple inputfield; placing inputfields on top of each other is not possible.</li></ul>
  4521.         @ note: mouselisteners are only active if ''&#36;status != done`` (eg only drawing in an active/non-finished exercise) <br /> to overrule use command/keyword ''status`` (no arguments required)
  4522.         @ 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 on 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
  4523.         @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
  4524.         @ 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)
  4525.         @ use a prefix <a href='#filled'>filled</a> or ''f`` to set fillable objects filled. (fcircles, filledcircles, etc)
  4526.         @ for non solid filling, use command <a href="#fillpattern">fillpattern grid,hatch,diamond,dot</a>
  4527.         @ use <a href='#opacity'>opacity int,int</a> and <a href='#fillcolor'>fillcolor color</a> to trigger coloured filling of fillable objects
  4528.         @ use command ''dashed`` and/or ''dashtype int,int`` to trigger dashing
  4529.         @ use command ''replyformat int`` to control / adjust output formatting of javascript function read_canvas(); (the defaults should be fine...)
  4530.         @ may be combined with onclick or drag xy of other components of flyscript objects (although not very useful...)
  4531.         @ may be combined with keyword <a href='#userinput_xy'>userinput_xy</a>
  4532.         @ may be combined width the <a href='#snaptogrid'>snaptogrid snaptopoints </a> etc, to simplify the checking of the student reply
  4533.         @ the cursor may be appropriately styled using command <a href='cursor'>cursor</a>
  4534.         @ 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 widh userdraw! use command <a href="#multidraw">multidraw</a> is this is a problem for you...
  4535.         @ note: the default replyformat for ''userdraw input(s),color`` used format x1;y1;text1 \n x2;y2;test2 \n x_n;y_n;text_n (e.g. it is not a comma separated array...use ''direct exec`` to test)
  4536.         @ note: a special case is ''userdraw images,boguscolor``. Images (bitmap or svg or div) present in the exercise page and the img/svg/div-tag with an unique 'id' and <code>onclick='javascript:place_image_on_canvas(this.id)'</code> can be placed onto the canvas.<br />The ''id`` and (x;y) coordinates will be returned using read_canvas();<br /> native MathML, MathJax or KaTeX typesetting may be included in div's.(experiments; wims_modules svn version only!)
  4537.         @%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
  4538.         @%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
  4539.         @%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
  4540.         @%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
  4541.         @%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
  4542.         @%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
  4543.         @%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
  4544.         @%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
  4545.         @%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
  4546.         @%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
  4547.         @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
  4548.         @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
  4549.         @%userdraw_vline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vline,green
  4550.         @%userdraw_vlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vlines,green
  4551.         @%userdraw_hline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hline,green
  4552.         @%userdraw_hlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hlines,green
  4553.         @%userdraw_demiline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demiline,green
  4554.         @%userdraw_demilines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demilines,green
  4555.         @%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
  4556.         @%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
  4557.         @%userdraw_point%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw point,green
  4558.         @%userdraw_points%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw points,green
  4559.         @%userdraw_arrow%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow,green
  4560.         @%userdraw_arrows%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows,green
  4561.         @%userdraw_arrow2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow2,green
  4562.         @%userdraw_arrows2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows2,green
  4563.         @%userdraw_curvedarrow%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrow,red%clearbutton REMOVE ALL ARROWS
  4564.         @%userdraw_curvedarrows%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrows,red%clearbutton REMOVE ALL ARROWS
  4565.         @%userdraw_curvedarrow2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrow2,red%clearbutton REMOVE ALL ARROWS
  4566.         @%userdraw_curvedarrows2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrows2,red%clearbutton REMOVE ALL ARROWS
  4567.         @%userdraw_crosshair%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshair,green
  4568.         @%userdraw_crosshairs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshairs,green
  4569.         @%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
  4570.         @%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
  4571.         @%userdraw_segment%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segment,green
  4572.         @%userdraw_segments%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segments,green
  4573.         @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
  4574.         @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
  4575.         @%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
  4576.         @%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
  4577.         @%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
  4578.         @%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
  4579.         @%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
  4580.         @%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
  4581.         @%userdraw_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandline,green
  4582.         @%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
  4583.         @%userdraw_freehandlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandlines,green
  4584.         @%userdraw_input%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw input,green
  4585.         @%userdraw_inputs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw inputs,green
  4586.         @%userdraw_text%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%fontfamily 42px Courier%userdraw text,green
  4587.         @%userdraw_clickfill_colorpalette%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,4,1,1,6,3,3,3,-3,-3,5%opacity 255,120%colorpalette red,green,yellow,blue%userdraw clickfill,green
  4588.         @%userdraw_clickfill_1%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,4,1,1,6,3,3,3,-3,-3,5%opacity 255,120%userdraw clickfill,green
  4589.         @%userdraw_clickfill_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%circles blue,0,0,2,1,1,5,5,5,4,-5,5,6,5,-5,6%userdraw hatchfill,red%#userdraw dotfill,red%#userdraw diamonefill,red%#userdraw gridfill,red
  4590.         @%userdraw_clickfill_2%size 400,400%xrange -10,10%yrange -10,10%bgcolor white%# to get nice click coordinates take invisible ''grid`` and use ''snaptogrid`` %grid 1,1,white%snaptogrid%circles blue,0,0,2,1,1,5,5,5,4,-5,5,6,5,-5,6%userdraw gridfill,red
  4591.         */
  4592.             if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
  4593.                 canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");
  4594.             }
  4595.             reply_precision = precision;
  4596.             use_userdraw = TRUE;
  4597.             fprintf(js_include_file,"\n/* begin userdraw mouse events */\n\
  4598.             userdraw_x = new Array();userdraw_y = new Array();\
  4599.             userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\
  4600.             var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;\
  4601.             if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\
  4602.             if(wims_status != \"done\"){\
  4603.              canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\
  4604.              canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\
  4605.              canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
  4606.              canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\
  4607.             }\n/* end userdraw mouse & touch events */",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
  4608.  
  4609. //           canvas_div.addEventListener(\"touchend\"  ,function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);
  4610.             draw_type = get_string_argument(infile,0);
  4611.             stroke_color = get_color(infile,1);
  4612.             if( strcmp(draw_type,"point") == 0 ){
  4613.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4614.                 if(reply_format == 0 ){reply_format = 8;}
  4615.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  4616. /*
  4617. type = 0: a point ...radius is fixed
  4618. type = 1: a circle ... read inputfield userinput_r
  4619. num = 1: a single point / circle
  4620. num = 2: multiple points / circles
  4621. */
  4622.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4623.                 if(use_input_xy == 1){
  4624.                     add_input_circle(js_include_file,0,1);
  4625.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4626.                 }
  4627.                 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,use_snap);
  4628.             }
  4629.             else
  4630.             if( strcmp(draw_type,"points") == 0 ){
  4631.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4632.                 if(reply_format == 0 ){reply_format = 8;}
  4633.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  4634.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4635.                 if(use_input_xy == 1){
  4636.                     add_input_circle(js_include_file,0,2);
  4637.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4638.                 }
  4639.                 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,use_snap);
  4640.             }
  4641.             else
  4642.             if( strcmp(draw_type,"segment") == 0 ){
  4643.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4644.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  4645.                 if(reply_format == 0){reply_format = 11;}
  4646.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4647.                 if(use_input_xy == 1){
  4648.                     add_input_segment(js_include_file,1);
  4649.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4650.                 }
  4651.                 add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4652.             }
  4653.             else
  4654.             if( strcmp(draw_type,"polyline") == 0 ||  strcmp(draw_type,"brokenline") == 0 ){
  4655.                 if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
  4656.                 if(reply_format == 0){reply_format = 23;}
  4657.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4658.                 if( use_input_xy == 1 ){
  4659.                     add_input_polyline(js_include_file);
  4660.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4661.                 }
  4662.                 add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4663.             }
  4664.             else
  4665.             if( strcmp(draw_type,"segments") == 0 ){
  4666.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4667.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  4668.                 if(reply_format == 0){reply_format = 11;}
  4669.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4670.                 if(use_input_xy == 1){
  4671.                     add_input_segment(js_include_file,2);
  4672.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4673.                 }
  4674.                 add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4675.             }
  4676.             else
  4677.             if( strcmp(draw_type,"circle") == 0 || strcmp(draw_type,"fcircle") == 0  || strcmp(draw_type,"filledcircle") == 0 ){
  4678.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4679.                 if(reply_format == 0){reply_format = 10;}
  4680.                 if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}}
  4681.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  4682.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4683.                 if(use_input_xy == 1){
  4684. /*
  4685. type = 0: a point ...radius is fixed
  4686. type = 1: a circle ... read inputfield userinput_r
  4687. num = 1: a single point / circle
  4688. num = 2: multiple points / circles
  4689. */
  4690.                     add_input_circle(js_include_file,1,1);
  4691.                     add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
  4692.                 }
  4693.                 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],use_snap);
  4694.             }
  4695.             else
  4696.             if( strcmp(draw_type,"circles") == 0 || strcmp(draw_type,"fcircles") == 0 || strcmp(draw_type,"filledcircles") == 0 ){
  4697.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4698.                 if(reply_format == 0){reply_format = 10;}
  4699.                 if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4700.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  4701.                 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],use_snap);
  4702.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4703.                 if(use_input_xy == 1){
  4704.                     add_input_circle(js_include_file,1,2);
  4705.                     add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
  4706.                 }
  4707.             }
  4708.             else
  4709.             if(strcmp(draw_type,"crosshair") == 0 ){
  4710.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  4711.                 if(reply_format == 0){reply_format = 8;}
  4712.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  4713.                 add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity,use_snap);
  4714.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4715.                 if(use_input_xy == 1){
  4716.                     add_input_crosshair(js_include_file,1);
  4717.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4718.                 }
  4719.             }
  4720.             else
  4721.             if(strcmp(draw_type,"crosshairs") == 0 ){
  4722.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  4723.                 if(reply_format == 0){reply_format = 8;}
  4724.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  4725.                 add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity,use_snap);
  4726.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4727.                 if(use_input_xy == 1){
  4728.                     add_input_crosshair(js_include_file,2);
  4729.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4730.                 }
  4731.             }
  4732.             else
  4733.             if(strcmp(draw_type,"freehandline") == 0 ){
  4734.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4735.                 if(reply_format == 0){reply_format = 6;}
  4736.                 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],use_snap);
  4737.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4738.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4739.             }
  4740.             else
  4741.             if(strcmp(draw_type,"freehandlines") == 0 ){
  4742.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4743.                 if(reply_format == 0){reply_format = 6;}
  4744.                 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],use_snap);
  4745.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4746.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4747.             }
  4748.             else
  4749.             if(strcmp(draw_type,"path") == 0 || strcmp(draw_type,"fpath") == 0 || strcmp(draw_type,"filledpath") == 0 ){
  4750.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4751.                 if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4752.                 if(reply_format == 0){reply_format = 6;}
  4753.                 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],use_snap);
  4754.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4755.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4756.             }
  4757.             else
  4758.             if(strcmp(draw_type,"paths") == 0 || strcmp(draw_type,"fpaths") == 0  || strcmp(draw_type,"filledpaths") == 0 ){
  4759.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4760.                 if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4761.                 if(reply_format == 0){reply_format = 6;}
  4762.                 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],use_snap);
  4763.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4764.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4765.             }
  4766.             else
  4767.             if(strcmp(draw_type,"arrows") == 0 ){
  4768.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  4769.                 if(reply_format == 0){reply_format = 11;}
  4770.                 add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap);
  4771.                 if(use_input_xy == 1){
  4772.                     add_input_arrow(js_include_file,2);
  4773.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4774.                 }
  4775.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4776.             }
  4777.             else
  4778.             if(strcmp(draw_type,"arrows2") == 0 ){
  4779.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  4780.                 if(reply_format == 0){reply_format = 11;}
  4781.                 add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap);
  4782.                 if(use_input_xy == 1){
  4783.                     add_input_arrow(js_include_file,1);
  4784.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4785.                 }
  4786.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4787.             }
  4788.             else
  4789.             if(strcmp(draw_type,"arrow2") == 0 ){
  4790.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  4791.                 if(reply_format == 0){reply_format = 11;}
  4792.                 add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap);
  4793.                 if(use_input_xy == 1){
  4794.                     add_input_arrow(js_include_file,1);
  4795.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4796.                 }
  4797.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4798.             }
  4799.             else
  4800.             if(strcmp(draw_type,"arrow") == 0 ){
  4801.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  4802.                 if(reply_format == 0){reply_format = 11;}
  4803.                 add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap);
  4804.                 if(use_input_xy == 1){
  4805.                     add_input_arrow(js_include_file,1);
  4806.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4807.                 }
  4808.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4809.             }
  4810.             else
  4811.             if( strcmp(draw_type,"curvedarrow2") == 0 ){
  4812.                 if(reply_format == 0){reply_format = 2;}
  4813.                 add_js_curvedarrow(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,2,use_snap);
  4814.                 if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4815.             }
  4816.             else
  4817.             if( strcmp(draw_type,"curvedarrows2") == 0 ){
  4818.                 if(reply_format == 0){reply_format = 2;}
  4819.                 add_js_curvedarrow(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,2,use_snap);
  4820.                 if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4821.             }
  4822.             else
  4823.             if( strcmp(draw_type,"curvedarrows") == 0 ){
  4824.                 if(reply_format == 0){reply_format = 2;}
  4825.                 add_js_curvedarrow(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,1,use_snap);
  4826.                 if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4827.             }
  4828.             else
  4829.             if( strcmp(draw_type,"curvedarrow") == 0 ){
  4830.                 if(reply_format == 0){reply_format = 2;}
  4831.                 add_js_curvedarrow(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,1,use_snap);
  4832.                 if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4833.             }
  4834.             else
  4835.             if(strcmp(draw_type,"polygon") == 0 || strcmp(draw_type,"fpolygon") == 0 || strcmp(draw_type,"filledpolygon") == 0){
  4836.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4837.                 if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4838.                 if(reply_format == 0){reply_format = 2;}
  4839.                 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],use_snap);
  4840.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4841.                 if(use_input_xy == 2){
  4842.                   add_textarea_polygon(js_include_file);
  4843.                   add_textarea_xy(js_include_file,canvas_root_id,input_style);
  4844.                 }
  4845.             }
  4846.             else
  4847.             if(strncmp(draw_type,"poly",4) == 0){
  4848.                 if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
  4849.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4850.                 if(reply_format == 0){reply_format = 2;}
  4851.                 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],use_snap);
  4852.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4853.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4854.             }
  4855.             else
  4856.             if(strcmp(draw_type,"triangle") == 0 || strcmp(draw_type,"ftriangle") == 0 || strcmp(draw_type,"filledtriangle") == 0){
  4857.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4858.                 if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4859.                 if(reply_format == 0){reply_format = 2;}
  4860.                 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],use_snap);
  4861.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4862.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4863.             }
  4864.             else
  4865.             if( strcmp(draw_type,"hline") == 0 ){
  4866.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4867.                 if(reply_format == 0){reply_format = 11;}
  4868.                 add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4869.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4870.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4871.             }
  4872.             else
  4873.             if( strcmp(draw_type,"hlines") == 0 ){
  4874.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4875.                 if(reply_format == 0){reply_format = 11;}
  4876.                 add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4877.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4878.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4879.             }
  4880.             else
  4881.             if( strcmp(draw_type,"vline") == 0 ){
  4882.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4883.                 if(reply_format == 0){reply_format = 11;}
  4884.                 add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4885.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4886.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4887.             }
  4888.             else
  4889.             if( strcmp(draw_type,"vlines") == 0 ){
  4890.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4891.                 if(reply_format == 0){reply_format = 11;}
  4892.                 add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4893.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4894.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4895.             }
  4896.             else
  4897.             if( strcmp(draw_type,"line") == 0 ){
  4898.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4899.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4900.                 if(reply_format == 0){reply_format = 11;}
  4901.                 add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4902.                 if( use_input_xy == 1 ){
  4903.                     add_input_line(js_include_file,1);
  4904.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4905.                 }
  4906.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4907.             }
  4908.             else
  4909.             if( strcmp(draw_type,"lines") == 0 ){
  4910.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4911.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4912.                 if(reply_format == 0){reply_format = 11;}
  4913.                 add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4914.                 if( use_input_xy == 1 ){
  4915.                     add_input_line(js_include_file,2);
  4916.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4917.                 }
  4918.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4919.             }
  4920.             else
  4921.             if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"halflines") == 0 ){
  4922.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4923.                 if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
  4924.                 if(reply_format == 0){reply_format = 11;}
  4925.                 add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4926.                 if( use_input_xy == 1 ){
  4927.                     add_input_demiline(js_include_file,2);
  4928.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4929.                 }
  4930.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4931.             }
  4932.             else
  4933.             if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"halfline") == 0 ){
  4934.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4935.                 if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
  4936.                 if(reply_format == 0){reply_format = 11;}
  4937.                 add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4938.                 if( use_input_xy == 1 ){
  4939.                     add_input_demiline(js_include_file,1);
  4940.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4941.                 }
  4942.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4943.             }
  4944.             else
  4945.             if( strcmp(draw_type,"rects") == 0 || strcmp(draw_type,"frects") == 0  || strcmp(draw_type,"filledrects") == 0 ){
  4946.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  4947.                 if(strstr(draw_type,"f") != NULL){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4948.                 if(reply_format == 0){reply_format = 2;}
  4949.                 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],use_snap);
  4950.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4951.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4952.             }
  4953.             else
  4954.             if( strcmp(draw_type,"roundrects") == 0 ||  strcmp(draw_type,"froundrects") == 0  ||  strcmp(draw_type,"filledroundrects") == 0){
  4955.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  4956.                 if( strstr(draw_type,"f") != NULL ){ if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4957.                 if(reply_format == 0){reply_format = 2;}
  4958.                 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],use_snap);
  4959.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4960.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4961.             }
  4962.             else
  4963.             if( strcmp(draw_type,"rect") == 0 || strcmp(draw_type,"frect") == 0 || strcmp(draw_type,"filledrect") == 0 ){
  4964.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  4965.                 if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4966.                 if(reply_format == 0){reply_format = 2;}
  4967.                 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],use_snap);
  4968.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4969.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4970.             }
  4971.             else
  4972.             if( strcmp(draw_type,"roundrect") == 0 || strcmp(draw_type,"froundrect") == 0  || strcmp(draw_type,"filledroundrect") == 0){
  4973.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  4974.                 if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}}
  4975.                 if(reply_format == 0){reply_format = 2;}
  4976.                 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],use_snap);
  4977.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4978.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4979.             }
  4980.             else
  4981.             if( strcmp(draw_type,"arcs") == 0 || strcmp(draw_type,"farcs") == 0  || strcmp(draw_type,"filledarcs") == 0 ){
  4982.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  4983.                 if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
  4984.                 if( strstr(draw_type,"f") != NULL ){use_filled =1;}
  4985.                 if(reply_format == 0){reply_format = 25;}
  4986.                 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],use_filled,use_snap);
  4987.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4988.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4989.             }
  4990.             else
  4991.             if( strcmp(draw_type,"arc") == 0 || strcmp(draw_type,"farc") == 0 || strcmp(draw_type,"filledarc") == 0){
  4992.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  4993.                 if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
  4994.                 if( strstr(draw_type,"f") != NULL ){use_filled =1;}
  4995.                 if(reply_format == 0){reply_format = 25;}
  4996.                 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],use_filled,use_snap);
  4997.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4998.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4999.             }
  5000.             else
  5001.             if( strcmp(draw_type,"text") == 0){
  5002.                 if(reply_format == 0){reply_format = 17;}
  5003.                 add_js_text(js_include_file,canvas_root_id,font_size,font_family,stroke_color,stroke_opacity,use_snap);
  5004.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  5005.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  5006.             }
  5007.             else
  5008.             if( strcmp(draw_type,"images") == 0){
  5009.                 if(reply_format == 0){reply_format = 29;}
  5010.                 add_js_images(js_include_file,canvas_root_id,use_offset,use_snap);
  5011.             }
  5012.             else
  5013.             if( strcmp(draw_type,"inputs") == 0){
  5014.                 if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  5015.                 if(reply_format == 0){reply_format = 27;}
  5016.                 add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width,use_offset,use_snap);
  5017.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  5018.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  5019.             }
  5020.             else
  5021.             if( strcmp(draw_type,"input") == 0){
  5022.                 if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  5023.                 if(reply_format == 0){reply_format = 27;}
  5024.                 add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width,use_offset,use_snap);
  5025.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  5026.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  5027.             }
  5028.             else /* attention: THIS NEEDS TO BE LAST ! */
  5029.             if( strstr(draw_type,"fill") != NULL ){
  5030.                 decimals = find_number_of_digits(precision);
  5031.                 add_js_clickfill(js_include_file,canvas_root_id,stroke_color,(int) (fill_opacity/0.0039215),use_snap);
  5032.                 if( reply_format == 0){reply_format = 10;}
  5033.                 if( js_function[DRAW_FILLTOBORDER] != 1 ){js_function[DRAW_FILLTOBORDER] = 1;add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);}
  5034.                 if( strcmp(draw_type,"gridfill") == 0){js_function[DRAW_GRIDFILL] = 1;string_length = 1 + 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);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++;}
  5035.                 if( strcmp(draw_type,"diamondfill") == 0){js_function[DRAW_DIAMONDFILL] = 1;string_length = 1 + 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);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++;}
  5036.                 if( strcmp(draw_type,"dotfill") == 0){js_function[DRAW_DOTFILL] = 1;string_length = 1 + 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);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++;}
  5037.                 if( strcmp(draw_type,"hatchfill") == 0){js_function[DRAW_HATCHFILL] = 1;string_length = 1 + 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);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++;}
  5038.                 if( strcmp(draw_type,"textfill") == 0){js_function[DRAW_TEXTFILL] = 1;temp = get_string(infile,1);string_length = 1 + 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);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++;}
  5039.             }
  5040.             else
  5041.             {
  5042.                 canvas_error("unknown drawtype or typo? ");
  5043.             }
  5044.             reset();
  5045.         break;
  5046.  
  5047.         case USERINPUT:
  5048.         /*
  5049.          @ userinput function inputfield
  5050.          @ alternative: <code>userinput_function</code>
  5051.          @ alternative: <code>userinput_xy</code>
  5052.          @ textarea and inputfield are only usable in combination with some ''userdraw draw_ type``
  5053.          @ function may be used any time (e.g. without userdraw)
  5054.          @ multiple ''userinput function`` commands may be used.
  5055.          @ use command <code>functionlabel some_string</code> to define the inputfield text: default value "f(x)="
  5056.          @ use command <code>strokecolor some_color</code> to adjust the plot / functionlabel color
  5057.          @ use command <code>inputstyle some_css</code> to adjust the inputfields
  5058.          @ use command <code>fontsize int</code> to adjust the label fonts. (default 12px)
  5059.          @ 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
  5060.          @%userinput_function%size 400,400%xrange -10,10%yrange -10,10%functionlabel your function g(x)=%axis%axisnumbering%xlabel x-axis%ylabel y-axis%grid 2,2,grey,3,3,5,grey%inputstyle color:blue;text-align:center%userinput function%# note: number of function inputs not limited
  5061.          @%userinput_points%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%# adding 2 inputfields for x and y%userinput inputfield%userdraw points,blue
  5062.          @%userinput_arrows%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%#adding 4 inputfields for (x1;y1)---(x2;y2)%userinput inputfieldd%userdraw arrows,blue
  5063.          @%userinput_combined%size 400,400%xrange -10,10%yrange -10,10%functionlabel your function g(x)=%axis%axisnumbering%xlabel x-axis%ylabel y-axis%precision 0%grid 2,2,grey,3,3,5,grey%inputstyle color:blue;text-align:center%precision 1000%strokecolor red%opacity 255,255%userinput function%# note: number of function inputs not limited%userdraw line,blue
  5064.         */
  5065.             temp = get_string_argument(infile,1);
  5066.             if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
  5067.              if( js_function[DRAW_JSFUNCTION] != 1 ){
  5068.               add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */
  5069.               js_function[DRAW_JSFUNCTION] = 1;
  5070.               if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  5071.               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);
  5072.               input_cnt++;
  5073.              }
  5074.              else
  5075.              {
  5076.               /* no need to add DRAW_JSFUNCTION, just call it with the parameters */
  5077.               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);
  5078.               input_cnt++;
  5079.              }
  5080.              if( use_js_math == FALSE){/* add this stuff only once...*/
  5081.               add_to_js_math(js_include_file);
  5082.               use_js_math = TRUE;
  5083.              }
  5084.              if( use_js_plot == FALSE){
  5085.               use_js_plot = TRUE;
  5086.               add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  5087.              }
  5088.             }
  5089.             else
  5090.             {
  5091.              if(strstr(temp,"inputfield") != 0 ){
  5092.               if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
  5093.               if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  5094.               use_input_xy = 1;
  5095.              }
  5096.              else
  5097.              {
  5098.               if(strstr(temp,"textarea") != 0 ){
  5099.                if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
  5100.                if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  5101.                use_input_xy = 2;
  5102.               }
  5103.               else
  5104.               {
  5105.                 canvas_error("userinput argument may be \"function,inputfield,textarea\"");
  5106.               }
  5107.              }
  5108.             }
  5109.             break;
  5110.         case USERINPUT_XY:
  5111.         /*
  5112.         @ userinput_xy
  5113.         @ keyword (no arguments required)
  5114.         @ to be used in combination with command "userdraw object_type,color"
  5115.         @ 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)
  5116.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  5117.         @ 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.
  5118.         @ can <b>not</b> be combined with command ''intooltip tiptext`` <br />note: the ''tooltip div element`` is used for placing inputfields
  5119.         @ user drawings will not zoom on zooming (or pan on panning)
  5120.         @ use command inputstyle some_css`` to adjust the inputarea.
  5121.         @ use command ''fontsize int`` to adjust the text labels (if needed)
  5122.         @%userinput_xy%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 0%grid 2,2,grey,3,3,6,black%# provides inputfields for (x1:y1)---(x2:y2)%userinput_xy%linewidth 2%precision 1000%userdraw lines,blue
  5123.         */
  5124.             /* add simple eval check to avoid code injection with unprotected eval(string) */
  5125.             if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
  5126.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  5127.             use_input_xy = 1;
  5128.             break;
  5129.  
  5130.         case USERINPUT_FUNCTION:
  5131.         /*
  5132.         @ userinput_function
  5133.         @ keyword (no arguments required)
  5134.         @ if set, a inputfield will be added to the page
  5135.         @ repeat keyword for more function input fields
  5136.         @ the userinput value will be plotted in the canvas
  5137.         @ this value may be read with <code>read_canvas()</code>. <br />for do it yourself js-scripters: If this is the first inputfield in the script, its id is canvas_input0
  5138.         @ 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
  5139.         @ fontsize can be set using command ''fontsize int``
  5140.         @ incompatible with command ''intooltip link_text_or_image``: it uses the tooltip div for adding the inputfield
  5141.         @%userinput_function%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%xlabel x-axis%ylabel y-axis%precision 0%grid 2,2,grey,2,2,5,grey%precision 1000%linewidth 2%# first inputfield%inputstyle color:blue;text-align:center;font-family:Italic;%strokecolor blue%functionlabel g(x)=%userinput function%# second inputfield%inputstyle color:green;text-align:center;font-family:Italic;%strokecolor green%functionlabel h(x)=%userinput function%# third inputfield%inputstyle color:purple;text-align:center;font-family:Italic;%strokecolor purple%functionlabel k(x)=%userinput function%# no limit in number of function inputfields
  5142.         */
  5143.             if( js_function[DRAW_JSFUNCTION] != 1 ){
  5144.              js_function[DRAW_JSFUNCTION] = 1;
  5145.              add_rawmath(js_include_file);
  5146.              if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  5147.              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);
  5148.              input_cnt++;
  5149.             }
  5150.             else
  5151.             {
  5152.               /* no need to add DRAW_JSFUNCTION, just call it with the parameters */
  5153.              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);
  5154.              input_cnt++;
  5155.             }
  5156.             if( use_js_math == FALSE){/* add this stuff only once...*/
  5157.              add_to_js_math(js_include_file);
  5158.              use_js_math = TRUE;
  5159.             }
  5160.             if( use_js_plot == FALSE){
  5161.              use_js_plot = TRUE;
  5162.              add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  5163.             }
  5164.             break;
  5165.  
  5166.  
  5167.  
  5168.         case USERTEXTAREA_XY:
  5169.         /*
  5170.         @ usertextarea_xy
  5171.         @ NOT IMPLEMENTED !!
  5172.         @ keyword (no arguments required)
  5173.         @ to be used in combination with command <code>userdraw object_type,color</code> wherein object_type is only segment / polyline for the time being...
  5174.         @ if set two textareas are added to the document (one for x-values, one for y-values)
  5175.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  5176.         @ user drawings will not zoom on zooming (or pan on panning)
  5177.         @ use command ''inputstyle some_css`` to adjust the inputarea.
  5178.         @ use command ''fontsize int`` to adjust the text labels (if needed)
  5179.         */
  5180.             if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
  5181.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  5182.             use_input_xy = 2;
  5183.             break;
  5184.  
  5185.         case VLINE:
  5186.         /*
  5187.         @ vline x,y,color
  5188.         @ alternative: <code>verticalline</code>
  5189.         @ draw a vertical line through point (x:y) in color ''color``
  5190.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  5191.         @%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
  5192.         */
  5193.             for(i=0;i<3;i++) {
  5194.                 switch(i){
  5195.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  5196.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  5197.                     case 2: stroke_color=get_color(infile,1);/* name or hex color */
  5198.                         double_data[2] = double_data[0];
  5199.                         decimals = find_number_of_digits(precision);
  5200.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  5201.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  5202.                         /* click_cnt++; */
  5203.                         reset();
  5204.                     break;
  5205.                 }
  5206.             }
  5207.             break;
  5208.  
  5209.         case VLINES:
  5210.         /*
  5211.         @ vlines color,x1,y1,x2,y2....
  5212.         @ alternative: <code>verticallines</code>
  5213.         @ draw vertical lines through points (x1:y1),(x2:y2)... in color ''color``
  5214.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  5215.         @%vlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%vlines red,1,0,2,0,3,0,4,0
  5216.         */
  5217.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5218.             fill_color = stroke_color;
  5219.             i=0;
  5220.             while( ! done ){     /* get next item until EOL*/
  5221.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5222.                 if(i%2 == 0 ){
  5223.                     double_data[i] = get_real(infile,0); /* x */
  5224.                 }
  5225.                 else
  5226.                 {
  5227.                     double_data[i] = get_real(infile,1); /* y */
  5228.                 }
  5229.                 i++;
  5230.             }
  5231.             decimals = find_number_of_digits(precision);
  5232.             for(c = 0 ; c < i-1 ; c = c+2){
  5233.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  5234.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  5235.                 /* click_cnt++; */
  5236.             }
  5237.             reset();
  5238.             break;
  5239.  
  5240.         case VIDEO:
  5241.         /*
  5242.         @ video x,y,w,h,videofile location
  5243.         @ x,y: left top corner of audio element (in xrange / yrange)
  5244.         @ w,y: width and height in pixels
  5245.         @ video format may be in *.mp4 (todo: other formats)
  5246.         @%video%size 400,400%xrange -10,10%yrange -10,10%opacity 200,100%frect -9,9,6,-6,green%video -5,5,200,200,http://techslides.com/demos/sample-videos/small.mp4
  5247.         */
  5248.             if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
  5249.             for(i=0;i<5;i++){
  5250.                 switch(i){
  5251.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  5252.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */
  5253.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  5254.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  5255.                     case 4: temp = get_string(infile,1);
  5256.                             string_length = 1 + 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);
  5257.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5258.                             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);
  5259.                             add_to_buffer(tmp_buffer);
  5260.                             break;
  5261.                     default:break;
  5262.                 }
  5263.             }
  5264.             reset();
  5265.             break;
  5266.  
  5267.         case X_AXIS_STRINGS:
  5268.         /*
  5269.          @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5270.          @ alternative: <code>xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code>
  5271.          @ usable for commands <a href="#numberline">numberline</a> and <a href="#grid">grid</a> or combinations thereof
  5272.          @ use these x-axis num1...num_n values instead of default xmin...xmax
  5273.          @ in case of command ''grid``. there is no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5274.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
  5275.          @ 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>)
  5276.          @ a javascript error message will flag non-matching value:name pairs
  5277.          @ if the ''x-axis words`` are too big and will overlap, a simple alternating offset will be applied
  5278.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  5279.          @ ''xmajor`` steps should be synchronised with numbers eg. ''1`` in the next example <code>grid 1,100,grey,1,4,6,grey</code>
  5280.          @%xaxistext%size 800,200%xrange -1,13%yrange -5,10%axis%xaxistext 1:january:2:february:3:march:4:april:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%grid 1,4,grey,1,2,10,red
  5281.         */
  5282.             use_axis_numbering++;
  5283.             temp = get_string(infile,1);
  5284.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5285.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5286.             fprintf(js_include_file,"x_strings[%d] = [\"%s\"];x_strings_up[%d] = null;",use_axis_numbering,temp,use_axis_numbering);
  5287.             break;
  5288.         case X_AXIS_STRINGS_UP:
  5289.         /*
  5290.          @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5291.          @ alternative: <code>xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code>
  5292.          @ the text will be rotated 90&deg; up
  5293.          @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5294.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
  5295.          @ use these x-axis num1...num_n values instead of default xmin...xmax
  5296.          @ use command ''fontcolor``, <a href="#fontfamily">fontfamily</a> 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>)
  5297.          @ a javascript error message will flag non-matching value:name pairs
  5298.          @ if the ''x-axis words`` are too big, they will overlap the graph<br /> (in this case the text will start from ysize upwards)
  5299.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  5300.          @''xmajor`` steps should be synchronised with numbers eg. "1" in the next example <code>grid 1,100,grey,1,4,6,grey</code>
  5301.          @%xaxistextup%size 800,300%xrange -1,13%yrange -10,10%fontfamily Italic 18pt Courier%axis%xaxistextup 1:january:2:february:3:march:4:april:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%grid 1,4,grey,1,2,10,red
  5302.         */
  5303.             use_axis_numbering++;
  5304.             temp = get_string(infile,1);
  5305.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5306.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5307.             fprintf(js_include_file,"x_strings_up[%d] = 1;x_strings[%d] = [\"%s\"];",use_axis_numbering,use_axis_numbering,temp);
  5308.             break;
  5309.  
  5310.         case XERRORBARS:
  5311.         /*
  5312.         @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
  5313.         @ 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``.
  5314.         @ the errors E1 and E2 values are in xrange.
  5315.         @ use command ''linewidth int`` to adust size
  5316.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  5317.         @%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
  5318.  
  5319.         */
  5320.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5321.             fill_color = stroke_color;
  5322.             i=0;
  5323.             while( ! done ){     /* get next item until EOL*/
  5324.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5325.                 if(i%2 == 0 ){
  5326.                     double_data[i] = get_real(infile,0); /* x */
  5327.                 }
  5328.                 else
  5329.                 {
  5330.                     double_data[i] = get_real(infile,1); /* y */
  5331.                 }
  5332.                 i++;
  5333.             }
  5334.             decimals = find_number_of_digits(precision);
  5335.             for(c = 2 ; c < i-1 ; c = c+2){
  5336.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,20,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  5337.                 /* click_cnt++; */
  5338.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  5339.             }
  5340.             reset();
  5341.             break;
  5342.  
  5343.         case XRANGE:
  5344.         /*
  5345.         @ xrange xmin,xmax
  5346.         @ alternative: <code>rangex</code>
  5347.         @ if not given: 0,xsize (eg in pixels)
  5348.         */
  5349.             for(i = 0 ; i<2; i++){
  5350.                 switch(i){
  5351.                     case 0: xmin = get_real(infile,0);break;
  5352.                     case 1: xmax = get_real(infile,1);break;
  5353.                     default: break;
  5354.                 }
  5355.             }
  5356.             if(xmin >= xmax){canvas_error(" xrange is not OK: xmin &lt; xmax !\n");}
  5357.             fprintf(js_include_file,"var xmin = %f;var xmax = %f;\n",xmin,xmax);
  5358.             found_size_command++;
  5359.             break;
  5360.  
  5361.  
  5362.  
  5363.         case XSNAPTOGRID:
  5364.         /*
  5365.          @ xsnaptogrid
  5366.          @ keyword (no arguments required)
  5367.          @ a draggable object (use command ''drag x|y|xy``) will snap to the given x-grid values when dragged (mouseup).
  5368.          @ in case of userdraw the drawn points will snap to xmajor grid.
  5369.          @ if no grid is defined, points will snap to every integer xrange value. (eg snap_x=1)
  5370.          @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
  5371.          @ 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, <code>xsnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red</code><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 ...
  5372.          @%xsnaptogrid_1%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
  5373.          @%xsnaptogrid_2%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
  5374.  
  5375.         */
  5376.         use_snap = 2;
  5377.         break;
  5378.  
  5379.         case XOFFSET:
  5380.         /*
  5381.          @ xoffset
  5382.          @ keyword ; to place the text centered above the text coordinates(x:y) ...
  5383.          @ may be used for points or other things requiring centered labels
  5384.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5385.          @ 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)
  5386.         @%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
  5387.         */
  5388.          use_offset = 2;
  5389.          break;
  5390.  
  5391.         case XYOFFSET:
  5392.         /*
  5393.          @ xyoffset
  5394.          @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily
  5395.          @ may be used for points or other things requiring labels
  5396.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5397.          @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy
  5398.          @ in case of inputfields the inputfield will be centered x and y on its 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>
  5399.          @%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
  5400.         */
  5401.          use_offset = 3;
  5402.          break;
  5403.  
  5404.         case XUNIT:
  5405.         /*
  5406.          @ xunit some_unit_for_x-values
  5407.          @ unicode allowed (no html code)
  5408.          @ use together with command <a href='#display'>display or mouse</a>
  5409.          @ will display the cursor x-coordinate in ''unit``
  5410.          @%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
  5411.         */
  5412.             fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
  5413.             break;
  5414.  
  5415.         case XLABEL:
  5416.         /*
  5417.         @ xlabel some_string
  5418.         @ will be used to create a label for the x-axis (label is in quadrant I).
  5419.         @ can only be used together with command ''grid``<br />not depending on keywords ''axis`` and ''axisnumbering``.
  5420.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command ''fontsize`` to adjust (command ''fontfamily`` is not active for this command).
  5421.         @ see <a href='z#ylabel'>ylabel</a>.
  5422.         @%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
  5423.         */
  5424.             temp = get_string(infile,1);
  5425.             fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
  5426.             break;
  5427.  
  5428.         case XLOGBASE:
  5429.         /*
  5430.         @ xlogbase number
  5431.         @ sets the logbase number for the x-axis
  5432.         @ default value 10
  5433.         @ use together with commands xlogscale / xylogscale
  5434.         */
  5435.             fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
  5436.             break;
  5437.  
  5438.         case XLOGSCALE:
  5439.         /*
  5440.          @ xlogscale ymajor,yminor,majorcolor,minorcolor
  5441.          @ the x/y-range are set using commands <code>xrange xmin,xmax</code> and <code>yrange ymin,ymax</code>
  5442.          @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
  5443.          @ the linewidth is set using command ''linewidth int``
  5444.          @ the opacity of major / minor grid lines is set by command <a href='#opacity'>opacity</a>
  5445.          @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number``
  5446.          @ 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>
  5447.          @ note: the complete canvas will be used for the ''log paper``
  5448.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5449.          @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\
  5450.          @ 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
  5451.          @ note: in case of userdraw, the use of keyword <a href='#userinput_xy'>userinput_xy</a> may be handy !
  5452.          @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
  5453.          @%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
  5454.         */
  5455.             use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5456.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5457.             if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
  5458.             for(i=0;i<4;i++){
  5459.                 switch(i){
  5460.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  5461.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  5462.                     case 2: stroke_color = get_color(infile,0); break;
  5463.                     case 3: fill_color = get_color(infile,1);
  5464.                         string_length = 1 + 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);
  5465.                         tmp_buffer = my_newmem(string_length);
  5466.                         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);
  5467.                         fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
  5468.                         add_to_buffer(tmp_buffer);
  5469.                         break;
  5470.                     default:break;
  5471.                 }
  5472.             }
  5473.             break;
  5474.  
  5475.         case XYLOGSCALE:
  5476.         /*
  5477.          @ xylogscale majorcolor,minorcolor
  5478.          @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax``
  5479.          @ the linewidth is set using command ''linewidth int``
  5480.          @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]``
  5481.          @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number`` and/or ''ylogbase number``
  5482.          @ 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>
  5483.          @ note: the complete canvas will be used for the ''log paper``
  5484.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5485.          @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\
  5486.          @ 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``)
  5487.          @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy !
  5488.          @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
  5489.          @%xylogscale%size 400,400%xrange 10,50000%yrange 10,50000%xlabel x-axis%ylabel y-axis%xylogscale black,grey%display xy,red,22
  5490.         */
  5491.             use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5492.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5493.             if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
  5494.             for(i=0;i<2;i++){
  5495.                 switch(i){
  5496.                     case 0: stroke_color = get_color(infile,0); break;
  5497.                     case 1: fill_color = get_color(infile,1);
  5498.                         string_length = 1 + 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);
  5499.                         tmp_buffer = my_newmem(string_length);
  5500.                         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);
  5501.                         fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
  5502.                         add_to_buffer(tmp_buffer);
  5503.                         break;
  5504.                     default:break;
  5505.                 }
  5506.             }
  5507.         break;
  5508.  
  5509.  
  5510.         case Y_AXIS_STRINGS:
  5511.         /*
  5512.          @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5513.          @ alternative: <code>yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code>
  5514.          @ 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>)
  5515.          @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5516.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
  5517.          @ use these y-axis num1...num_n values instead of default ymin...ymax
  5518.          @ a javascript error message will flag non-matching value:name pairs
  5519.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  5520.          @%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
  5521.         */
  5522.             temp = get_string(infile,1);
  5523.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5524.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5525.             fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
  5526.             use_axis_numbering++;
  5527.             break;
  5528.  
  5529.  
  5530.         case YERRORBARS:
  5531.         /*
  5532.         @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
  5533.         @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color ''color``.
  5534.         @ the errors E1 and E2 values are in yrange.
  5535.         @ use command ''linewidth int`` to adust size
  5536.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  5537.         @%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
  5538.         */
  5539.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5540.             fill_color = stroke_color;
  5541.             i=0;
  5542.             while( ! done ){     /* get next item until EOL*/
  5543.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5544.                 if(i%2 == 0 ){
  5545.                     double_data[i] = get_real(infile,0); /* x */
  5546.                 }
  5547.                 else
  5548.                 {
  5549.                     double_data[i] = get_real(infile,1); /* y */
  5550.                 }
  5551.                 i++;
  5552.             }
  5553.             for(c = 2 ; c < i-1 ; c = c+2){
  5554.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,19,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%s,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,current_sliders,rotation_center,use_offset,use_pattern);
  5555.                 /* click_cnt++; */
  5556.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  5557.             }
  5558.             decimals = find_number_of_digits(precision);
  5559.             reset();
  5560.             break;
  5561.         case YOFFSET:
  5562.         /*
  5563.          @ yoffset
  5564.          @ keyword; to place the text centered above the text coordinates(x:y) ...
  5565.          @ may be used for points or other things requiring centered labels
  5566.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5567.          @ 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)
  5568.          @%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
  5569.         */
  5570.          use_offset = 1;
  5571.          break;
  5572.  
  5573.         case YRANGE:
  5574.         /*
  5575.         @ yrange ymin,ymax
  5576.         @ alternative: <code>rangey</code>
  5577.         @ if not given 0,ysize (eg in pixels)
  5578.         */
  5579.             for(i = 0 ; i<2; i++){
  5580.                 switch(i){
  5581.                     case 0: ymin = get_real(infile,0);break;
  5582.                     case 1: ymax = get_real(infile,1);break;
  5583.                     default: break;
  5584.                 }
  5585.             }
  5586.             if(ymin >= ymax){canvas_error(" yrange is not OK: ymin &lt; ymax !\n");}
  5587.             fprintf(js_include_file,"var ymin = %f;var ymax = %f;\n",ymin,ymax);
  5588.             found_size_command++;
  5589.             break;
  5590.  
  5591.         case YSNAPTOGRID:
  5592.         /*
  5593.          @ ysnaptogrid
  5594.          @ keyword (no arguments required)
  5595.          @ a draggable object (use command ''drag x|y|xy``) will snap to the given y-grid values when dragged (mouseup)
  5596.          @ in case of userdraw the drawn points will snap to ymajor grid
  5597.          @ if no grid is defined, points will snap to every integer yrange value. (eg snap_y=1)
  5598.          @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
  5599.          @ 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 /><code>ysnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red</code><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 />
  5600.          @%ysnaptogrid_1%size 400,400%xrange -10,10%yrange -10,10%ysnaptogrid%grid 1,1,grey%linewidth 2%userdraw crosshairs,blue%inputstyle font-size:8px;color:blue%clearbutton delete all crosshairs
  5601.          @%ysnaptogrid_2%size 400,400%xrange -10,10%yrange -10,10%ysnaptogrid%grid 1,1,grey%linewidth 3%drag y%points red,0,0,0,0,0,0,0,0,0,0
  5602.         */
  5603.         use_snap = 3;
  5604.         break;
  5605.  
  5606.         case YLABEL:
  5607.         /*
  5608.         @ ylabel some_string
  5609.         @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
  5610.         @ can only be used together with command <a href="#grid">grid</a><br />not depending on keywords ''axis`` and ''axisnumbering``
  5611.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command ''fontsize`` to adjust (command ''fontsize`` is not active for this command)
  5612.         @%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
  5613.         */
  5614.             temp = get_string(infile,1);
  5615.             fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
  5616.             break;
  5617.         case YLOGBASE:
  5618.         /*
  5619.         @ ylogbase number
  5620.         @ sets the logbase number for the y-axis
  5621.         @ default value 10
  5622.         @ use together with commands ylogscale / xylogscale
  5623.         */
  5624.             fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
  5625.             break;
  5626.         case YLOGSCALE:
  5627.         /*
  5628.          @ ylogscale xmajor,xminor,majorcolor,minorcolor
  5629.          @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax``
  5630.          @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
  5631.          @ the linewidth is set using command ''linewidth int``
  5632.          @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]``
  5633.          @ default logbase number = 10 ... when needed, set the logbase number with command ''ylogbase number``
  5634.          @ 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 color</li></ul>
  5635.          @ note: the complete canvas will be used for the ''log paper``
  5636.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5637.          @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\
  5638.          @ 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``)
  5639.          @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy !
  5640.          @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
  5641.         */
  5642.             use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5643.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5644.             if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
  5645.             for(i=0;i<4;i++){
  5646.                 switch(i){
  5647.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  5648.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  5649.                     case 2: stroke_color = get_color(infile,0); break;
  5650.                     case 3: fill_color = get_color(infile,1);
  5651.                         string_length = 1 + 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);
  5652.                         tmp_buffer = my_newmem(string_length);
  5653.                         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);
  5654.                         fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
  5655.                         add_to_buffer(tmp_buffer);
  5656.                         break;
  5657.                     default:break;
  5658.                 }
  5659.             }
  5660.             break;
  5661.  
  5662.         case YUNIT:
  5663.         /*
  5664.          @ yunit some_unit_for_y-values
  5665.          @ unicode allowed (no html code)
  5666.          @ use together with command mousey
  5667.          @ will display the cursor y-coordinate in ''unit``
  5668.         */
  5669.             fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
  5670.             break;
  5671.  
  5672.         case ZOOM:
  5673.         /*
  5674.          @ zoom button_color
  5675.          @ introduce a very small ''controlpanel`` at the lower right corner
  5676.          @ 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
  5677.          @ the ''x`` symbol will do a <code>location.reload</code> of the page, and thus reset all canvas drawings.
  5678.          @ choose an appropriate color, so the small ''x,arrows,-,+`` are clearly visible
  5679.          @ command ''opacity`` may be used to set stroke_opacity of buttons
  5680.          @ note: use command ''zoom`` at the end of your script code (the same is true for command ''mouse``)
  5681.          @ note: only objects that may be set draggable / clickable will be zoomed / panned
  5682.          @ note: when an object is dragged, zooming / panning will cause the coordinates to be reset to the original position: e.g. dragging / panning will get lost. (array with ''drag data`` is erased). This is a design flaw and not a feature !!
  5683.         */
  5684.             fprintf(js_include_file,"use_pan_and_zoom = 1;");
  5685.             use_pan_and_zoom = TRUE;
  5686.             stroke_color = get_color(infile,1);
  5687.             /* we use BG_CANVAS (0) */
  5688.             add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
  5689.             done = TRUE;
  5690.             break;
  5691.  
  5692. /* ready */
  5693.         default:sync_input(infile);
  5694.         break;
  5695.     }
  5696.   }
  5697.   /* we are done parsing script file */
  5698.   /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize: Quadrant I */
  5699.   if( found_size_command == 1 ){
  5700.     fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
  5701.   }
  5702.   else
  5703.   {
  5704.     if( found_size_command != 3 ){
  5705.      canvas_error("Please specify both xrange and yrange ...");
  5706.     }
  5707.   }
  5708.  
  5709.   /* if needed, add generic draw functions (grid / xml etc) to buffer: these are no draggable/clickable shapes / objects  ! */
  5710.   add_javascript_function(js_function,canvas_root_id);
  5711.    /* add read_canvas() etc functions if needed */
  5712.   if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);}
  5713.   if( use_pan_and_zoom == TRUE ){
  5714.   /* in case of zooming ... */
  5715.   fprintf(js_include_file,"\n/* some extra global stuff : need to rethink panning and zooming !!! */\n\
  5716.  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
  5717.  var ymin_start=ymin;var ymax_start=xmax;\
  5718.  var zoom_x_increment=0;var zoom_y_increment=0;\
  5719.  var pan_x_increment=0;var pan_y_increment=0;\
  5720.  if(use_ylogscale == 0 ){\
  5721.   zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (ymax - ymin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\
  5722.  }else{\
  5723.   zoom_x_increment = (xmax - xmin)/20;\
  5724.   pan_x_increment = (xmax - xmin)/20;\
  5725.  };\
  5726.  var zoom_xy=[xmin,xmax,ymin,ymax];\
  5727.  function start_canvas%d(type){\
  5728.   zoom_xy=[xmin,xmax,ymin,ymax];\
  5729.   switch(type){\
  5730.    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
  5731.    case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\
  5732.    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
  5733.    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
  5734.    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
  5735.    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
  5736.    case 6:xmin = xmin_start; xmax = xmax_start;ymin = ymin_start;ymax = ymax_start;break;\
  5737.    default:break;\
  5738.   };\
  5739.   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
  5740.   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
  5741.   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){};\
  5742.   if(typeof(redraw_all%d) === 'function' ){redraw_all%d(zoom_xy);}\
  5743.   %s ;\
  5744.  };\
  5745.  start_canvas%d(333);\
  5746. };\
  5747. \n/* end wims_canvas_function */\n\
  5748. wims_canvas_function%d();\n",precision,canvas_root_id,canvas_root_id,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
  5749.   }
  5750.   else
  5751.   {
  5752.   /* no zoom, just add buffer */
  5753.   fprintf(js_include_file,"\n/* add buffer */\n\
  5754.  %s\
  5755. };\n\
  5756. /* end wims_canvas_function */\n\
  5757. wims_canvas_function%d();\n",buffer,canvas_root_id);
  5758.   }
  5759. /* done writing the javascript include file */
  5760. fclose(js_include_file);
  5761.  
  5762. }
  5763.  
  5764. /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
  5765.  if( use_tooltip > 0 ){
  5766.   if( use_tooltip == 1 ){
  5767.    add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
  5768.   }
  5769.   else
  5770.   {
  5771.    if( use_tooltip == 2 ){
  5772.     add_js_popup(canvas_root_id,xsize,ysize,getfile_cmd);
  5773.    }
  5774.   }
  5775.  }
  5776. exit(EXIT_SUCCESS);
  5777. }
  5778. /* end main() */
  5779.  
  5780. /******************************************************************************
  5781. **
  5782. **  sync_input
  5783. **
  5784. **  synchronises input line - reads to end of line, leaving file pointer
  5785. **  at first character of next line.
  5786. **
  5787. **  Used by:
  5788. **  main program - error handling.
  5789. **
  5790. ******************************************************************************/
  5791. void sync_input(FILE *infile)
  5792. {
  5793.         int c = 0;
  5794.  
  5795.         if( c == '\n' || c == ';' ) return;
  5796.         while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
  5797.         if( c == EOF ) finished = 1;
  5798.         if( c == '\n' || c == '\r' || c == ';') line_number++;
  5799.         return;
  5800. }
  5801.  
  5802. /******************************************************************************/
  5803.  
  5804. char *str_replace(const char *str, const char *old, const char *new){
  5805. /* http://creativeandcritical.net/str-replace-c/ */
  5806.     if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
  5807.     char *ret, *r;
  5808.     const char *p, *q;
  5809.     size_t oldlen = strlen(old);
  5810.     size_t count = 0;
  5811.     size_t retlen = 0;
  5812.     size_t newlen = strlen(new);
  5813.     if (oldlen != newlen){
  5814.         for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
  5815.             count++;
  5816.             retlen = p - str + strlen(p) + count * (newlen - oldlen);
  5817.         }
  5818.     }
  5819.     else
  5820.     {
  5821.         retlen = strlen(str);
  5822.     }
  5823.  
  5824.     if ((ret = malloc(retlen + 1)) == NULL){
  5825.         ret = NULL;
  5826.         canvas_error("string argument is NULL");
  5827.     }
  5828.     else
  5829.     {
  5830.         for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
  5831.             size_t l = q - p;
  5832.             memcpy(r, p, l);
  5833.             r += l;
  5834.             memcpy(r, new, newlen);
  5835.             r += newlen;
  5836.         }
  5837.         strcpy(r, p);
  5838.     }
  5839.     return ret;
  5840. }
  5841.  
  5842. /******************************************************************************/
  5843.  
  5844. char *get_color(FILE *infile , int last){
  5845.     int c,i = 0,is_hex = 0;
  5846.     char temp[MAX_COLOR_STRING], *string;
  5847.     const char *not_allowed = "0123456789";
  5848.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' )  && ( c != '\t' ) ){
  5849.         if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
  5850.         if( c == '#' ){
  5851.             is_hex = 1;
  5852.         }
  5853.         if( c != ' '){
  5854.             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 !!! ");}}
  5855.             temp[i]=tolower(c);
  5856.             i++;
  5857.         }
  5858.     }
  5859.     if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
  5860.     if( c == '\n' || c == ';'  || c == '\t' ){ done = TRUE; line_number++; }
  5861.     if( c == EOF ){finished = 1;}
  5862.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  5863.     temp[i]='\0';
  5864.     if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
  5865.     if( is_hex == 1 ){
  5866.         char red[3], green[3], blue[3];
  5867.         red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
  5868.         green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
  5869.         blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
  5870.         int r = (int) strtol(red,   NULL, 16);
  5871.         int g = (int) strtol(green, NULL, 16);
  5872.         int b = (int) strtol(blue,  NULL, 16);
  5873.         int L0 = 1+snprintf(NULL,0,"%d,%d,%d",r,g,b);
  5874.         string = my_newmem(L0);
  5875.         snprintf(string,L0,"%d,%d,%d",r,g,b);
  5876.         return string;
  5877.     }
  5878.     else
  5879.     {
  5880.         string = (char *)my_newmem(sizeof(temp));
  5881.         snprintf(string,sizeof(temp),"%s",temp);
  5882.         for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  5883.             if( strcmp( colors[i].name , string ) == 0 ){
  5884.                 return colors[i].rgb;
  5885.             }
  5886.         }
  5887.         canvas_error("I was expecting a color name or hexnumber...but found nothing.");
  5888.     }
  5889.     return "0,0,255";
  5890. }
  5891.  
  5892. char *get_string(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */
  5893.     int c,i=0;
  5894.     char  temp[MAX_BUFFER], *string;
  5895.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){
  5896.         temp[i]=c;
  5897.         i++;
  5898.         if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
  5899.     }
  5900.     if( ( c == '\n' ||  c == '\t'  || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  5901.     if( c == '\n' ||  c == '\t') { done = TRUE; line_number++; }
  5902.     if( c == EOF ) {finished = 1;}
  5903.     temp[i]='\0';
  5904.     if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing !!");}
  5905.     string=(char *)my_newmem(strlen(temp));
  5906.     snprintf(string,sizeof(temp),"%s",temp);
  5907.     return string;
  5908. }
  5909.  
  5910. char *get_string_argument(FILE *infile,int last){  /* last = 0: more arguments ; last=1 final argument */
  5911.     int c,i=0;
  5912.     char temp[MAX_BUFFER], *string;
  5913.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){
  5914.         temp[i]=c;
  5915.         i++;
  5916.         if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
  5917.     }
  5918.     if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
  5919.     if( c == '\n' || c == '\t' ) { line_number++; }
  5920.     if( c == EOF ) {finished = 1;}
  5921.     if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");}
  5922.     temp[i]='\0';
  5923. /*
  5924.     17.10.2014 removed (question Perrin)
  5925.     may cause some unwanted effects...
  5926.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma), but found nothing !!");}
  5927. */
  5928.     string=(char *)my_newmem(sizeof(temp));
  5929.     snprintf(string,sizeof(temp),"%s",temp);
  5930.     done = TRUE;
  5931.     return string;
  5932. }
  5933.  
  5934. double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0: more arguments ; last=1 final argument */
  5935.     int c,i=0,found_calc = 0;
  5936.     double y;
  5937.     char tmp[MAX_INT];
  5938.     /*
  5939.      these things are 'allowed functions': *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs
  5940.      but there should be a better way to avoid segfaults !
  5941.     */
  5942.     const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/
  5943.     const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */
  5944.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){
  5945.      if( c != ' ' ){
  5946.       if( i == 0 &&  c == '+' ){
  5947.        continue;
  5948.       }
  5949.       else
  5950.       {
  5951.        c = tolower(c);
  5952.        if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");}
  5953.        if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */
  5954.        tmp[i] = c;
  5955.        i++;
  5956.       }
  5957.      }
  5958.      if( i > MAX_INT - 1){canvas_error("number too large");}
  5959.     }
  5960.     if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
  5961.     if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; }
  5962.     if( c == EOF ){done = TRUE ; finished = 1;}
  5963.     tmp[i]='\0';
  5964.     if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
  5965.     if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */
  5966.      void *f = eval_create(tmp);
  5967.      assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  5968.      y = eval_x(f, 1);
  5969.      /* if function is bogus; y = 1: so no core dumps */
  5970.      eval_destroy(f);
  5971.     }
  5972.     else
  5973.     {
  5974.      y = atof(tmp);
  5975.     }
  5976.     return y;
  5977. }
  5978.  
  5979.  
  5980. void canvas_error(char *msg){
  5981.     fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d: %s</span><hr />",line_number,msg);
  5982.     finished = 1;
  5983.     exit(EXIT_SUCCESS);
  5984. }
  5985.  
  5986.  
  5987. /* convert x/y coordinates to pixel */
  5988. int x2px(double x){
  5989.  return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
  5990. }
  5991.  
  5992. int y2px(double y){
  5993.  return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
  5994. }
  5995.  
  5996. double px2x(int x){
  5997.  return (x*(xmax - xmin)/xsize + xmin);
  5998. }
  5999. double px2y(int y){
  6000.  return (y*(ymax - ymin)/ysize + ymin);
  6001. }
  6002.  
  6003. void add_to_buffer(char *tmp){
  6004.  if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
  6005.  /*  do we have enough space left in buffer[MAX_BUFFER] ? */
  6006.  int space_left = (int) (sizeof(buffer) - strlen(buffer));
  6007.  if( space_left > strlen(tmp)){
  6008.   strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
  6009.  }
  6010.  else
  6011.  {
  6012.   canvas_error("buffer is too big\n");
  6013.  }
  6014.  tmp = NULL;free(tmp);
  6015.  return;
  6016. }
  6017.  
  6018. void reset(){
  6019.  use_filled = FALSE;
  6020.  use_dashed = FALSE;
  6021.  use_rotate = FALSE;
  6022.  onclick = 0;
  6023. }
  6024.  
  6025.  
  6026.  
  6027. /* What reply format in read_canvas();
  6028.  
  6029. note: if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
  6030. 1 = x1,x2,x3,x4....x_n
  6031.     y1,y2,y3,y4....y_n
  6032.  
  6033.     x/y in pixels
  6034.  
  6035. 2 = x1,x2,x3,x4....x_n
  6036.     y1,y2,y3,y4....y_n
  6037.     x/y in xrange / yrange coordinate system
  6038.  
  6039. 3 = x1,x2,x3,x4....x_n
  6040.     y1,y2,y3,y4....y_n
  6041.     r1,r2,r3,r4....r_n
  6042.  
  6043.     x/y in pixels
  6044.     r in pixels
  6045.  
  6046. 4 = x1,x2,x3,x4....x_n
  6047.     y1,y2,y3,y4....y_n
  6048.     r1,r2,r3,r4....r_n
  6049.  
  6050.     x/y in xrange / yrange coordinate system
  6051.     r in pixels
  6052.  
  6053. 5 = Ax1,Ax2,Ax3,Ax4....Ax_n
  6054.     Ay1,Ay2,Ay3,Ay4....Ay_n
  6055.     Bx1,Bx2,Bx3,Bx4....Bx_n
  6056.     By1,By2,By3,By4....By_n
  6057.     Cx1,Cx2,Cx3,Cx4....Cx_n
  6058.     Cy1,Cy2,Cy3,Cy4....Cy_n
  6059.     ....
  6060.     Zx1,Zx2,Zx3,Zx4....Zx_n
  6061.     Zy1,Zy2,Zy3,Zy4....Zy_n
  6062.  
  6063.     x/y in pixels
  6064.  
  6065. 6 = Ax1,Ax2,Ax3,Ax4....Ax_n
  6066.     Ay1,Ay2,Ay3,Ay4....Ay_n
  6067.     Bx1,Bx2,Bx3,Bx4....Bx_n
  6068.     By1,By2,By3,By4....By_n
  6069.     Cx1,Cx2,Cx3,Cx4....Cx_n
  6070.     Cy1,Cy2,Cy3,Cy4....Cy_n
  6071.     ....
  6072.     Zx1,Zx2,Zx3,Zx4....Zx_n
  6073.     Zy1,Zy2,Zy3,Zy4....Zy_n
  6074.  
  6075.     x/y in xrange / yrange coordinate system
  6076.  
  6077. 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  6078.  
  6079.     x/y in pixels
  6080.  
  6081. 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  6082.  
  6083.     x/y in xrange / yrange coordinate system
  6084.  
  6085. 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
  6086.  
  6087.     x/y in pixels
  6088.  
  6089. 10 = x1 ; y1 ;r1 \n x2;y2;r2 \n x3;y3;r3 \n ...x_n:y_n:r_n \n
  6090.  
  6091.     x/y in xrange / yrange coordinate system
  6092.     r is userdraw_radius
  6093.  
  6094. 11 = Ax1,Ay1,Ax2,Ay2
  6095.      Bx1,By1,Bx2,By2
  6096.      Cx1,Cy1,Cx2,Cy2
  6097.      Dx1,Dy1,Dx2,Dy2
  6098.      ......
  6099.      Zx1,Zy1,Zx2,Zy2
  6100.  
  6101.     x/y in  xrange / yrange coordinate system
  6102.  
  6103. 12 = Ax1,Ay1,Ax2,Ay2
  6104.      Bx1,By1,Bx2,By2
  6105.      Cx1,Cy1,Cx2,Cy2
  6106.      Dx1,Dy1,Dx2,Dy2
  6107.      ......
  6108.      Zx1,Zy1,Zx2,Zy2
  6109.  
  6110.     x/y in pixels
  6111.  
  6112. 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ..., Zx1:Zy1:Zx2:Zy2
  6113.  
  6114.     x/y in xrange / yrange coordinate system
  6115. 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
  6116.     x/y in pixels
  6117. 15 = reply from inputfields,textareas
  6118.     reply1,reply2,reply3,...,reply_n
  6119.     only fields set write (e.g. will not read readonly inputfield values.
  6120.  
  6121. 16 = read mathml inputfields only
  6122.  
  6123. 17 = read userdraw text only (x1,y1,text1\nx2,y2,text2..\n.x_n,y_n,text_n
  6124.  when ready: calculate size_t of string via snprintf(NULL,0,"blah blah...");
  6125.  
  6126. 18 = read clock(s): H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
  6127. 19 = return clicked object number (analogue to shape-library onclick)
  6128. 20 = return x/y-data in x-range/y-range of all ''draggable`` images
  6129. 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
  6130. 22 = array: x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
  6131.     x/y in xrange / yrange coordinate system
  6132. 23 = answertype for a polyline: remove multiple occurences due to reclick on a point to create next polyline segment
  6133. 24 = read all inputfield values: even those set <code>readonly</code>
  6134. 25 = return all userdrawn arcs in degrees:
  6135. 26 = return all userdrawn arcs in radians:
  6136. 27 = return (only) userdraw inputfields array: x1,y1,text1 \n x2,y2,text2...
  6137. 28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
  6138.     x/y/r in xrange / yrange coordinate system: may be used to reinput into command
  6139.     circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
  6140.     will not return anything else (e.g. no inputfields, text etc)
  6141. 29 = mulidraw read:
  6142.  
  6143. */
  6144.  
  6145. /*
  6146. SCHAERSVOORDE: replyformat 2,7,8,21,22,23,24
  6147. USERDRAW DEFAULTS: 2,6,8,10,11,15,16,17,18,19,20,23,24,25,27,29,31
  6148. OEF: 22,23,28
  6149. */
  6150. void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){
  6151. /* just 1 reply type allowed...except for format 34 !!!  */
  6152. fprintf(js_include_file,"\
  6153. \n/* begin set_reply_precision() */\n\
  6154. function set_reply_precision(){\
  6155. var len = userdraw_x.length;\
  6156. var prec = %d;\
  6157. for(var p = 0 ; p < len ; p++ ){\
  6158.  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
  6159.  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
  6160. };\
  6161. len = userdraw_radius.length;\
  6162. if( len > 0 ){\
  6163.  for(var p = 0 ; p < len ; p++ ){\
  6164.   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
  6165.  };\
  6166. };\
  6167. };",reply_precision);
  6168.  
  6169. switch(type_reply){
  6170. /*
  6171. answers may have:
  6172. x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
  6173. */
  6174.     case 1: fprintf(js_include_file,"\
  6175. \n/* begin function 1 read_canvas%d() */\n\
  6176. read_canvas%d = function(){\
  6177. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  6178. set_reply_precision();\
  6179. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6180.  var p = 0;var input_reply = new Array();\
  6181.  if( document.getElementById(\"canvas_input0\")){\
  6182.   var t = 0;\
  6183.   while(document.getElementById(\"canvas_input\"+t)){\
  6184.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6185.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6186.     p++;\
  6187.    };\
  6188.    t++;\
  6189.   };\
  6190.  };\
  6191.  if( typeof(userdraw_text) !== 'undefined' ){\
  6192.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
  6193.  }\
  6194.  else\
  6195.  {\
  6196.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
  6197.  }\
  6198. }\
  6199. else\
  6200. {\
  6201.  if( typeof(userdraw_text) !== 'undefined' ){\
  6202.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
  6203.  }\
  6204.  else\
  6205.  {\
  6206.   return userdraw_x+\"\\n\"+userdraw_y;\
  6207.  }\
  6208. };\
  6209. };\n\
  6210. /* end function 1 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6211.     break;
  6212.     case 2: fprintf(js_include_file,"\
  6213. \n/* begin function 2 read_canvas%d() */\n\
  6214. read_canvas%d = function(){\
  6215. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  6216. set_reply_precision();\
  6217. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  6218. var prec = %d;\
  6219. while(userdraw_x[p]){\
  6220.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  6221.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  6222.  p++;\
  6223. };\
  6224. if(p == 0){return;};\
  6225. if( document.getElementById(\"canvas_input0\")){\
  6226.  var p = 0;var input_reply = new Array();\
  6227.  if( document.getElementById(\"canvas_input0\")){\
  6228.   var t = 0;\
  6229.   while(document.getElementById(\"canvas_input\"+t)){\
  6230.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6231.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6232.     p++;\
  6233.    };\
  6234.    t++;\
  6235.   };\
  6236.  };\
  6237.  if( typeof(userdraw_text) !== 'undefined' ){\
  6238.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6239.  }\
  6240.  else\
  6241.  {\
  6242.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  6243.  }\
  6244. }\
  6245. else\
  6246. {\
  6247.  if( typeof(userdraw_text) !== 'undefined' ){\
  6248.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  6249.  }\
  6250.  else\
  6251.  {\
  6252.   return reply_x+\"\\n\"+reply_y;\
  6253.  };\
  6254. };\
  6255. };\n\
  6256. /* end function 2 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6257.     break;
  6258.     case 3: fprintf(js_include_file,"\
  6259. \n/* begin function 3 read_canvas%d() */\n\
  6260. read_canvas%d = function(){\
  6261. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  6262. set_reply_precision();\
  6263. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6264.  var p = 0;var input_reply = new Array();\
  6265.  if( document.getElementById(\"canvas_input0\")){\
  6266.   var t = 0;\
  6267.   while(document.getElementById(\"canvas_input\"+t)){\
  6268.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6269.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6270.     p++;\
  6271.    };\
  6272.    t++;\
  6273.   };\
  6274.  };\
  6275.  if( typeof(userdraw_text) !== 'undefined' ){\
  6276.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6277.  }\
  6278.  else\
  6279.  {\
  6280.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  6281.  }\
  6282. }\
  6283. else\
  6284. {\
  6285.  if( typeof(userdraw_text) !== 'undefined' ){\
  6286.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
  6287.  }\
  6288.  else\
  6289.  {\
  6290.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
  6291.  }\
  6292. }\
  6293. };\n\
  6294. /* end function 3 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6295.     break;
  6296.     case 4: fprintf(js_include_file,"\
  6297. \n/* begin function 4 read_canvas%d() */\n\
  6298. read_canvas%d = function(){\
  6299. var prec = %d;\
  6300. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  6301. while(userdraw_x[p]){\
  6302.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  6303.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
  6304.  p++;\
  6305. };\
  6306. if(p == 0){return;};\
  6307. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6308.  var p = 0;var input_reply = new Array();\
  6309.  if( document.getElementById(\"canvas_input0\")){\
  6310.   var t = 0;\
  6311.   while(document.getElementById(\"canvas_input\"+t)){\
  6312.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6313.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6314.     p++;\
  6315.    };\
  6316.    t++;\
  6317.   };\
  6318.  };\
  6319.  if( typeof(userdraw_text) !== 'undefined' ){\
  6320.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6321.  }\
  6322.  else\
  6323.  {\
  6324.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  6325.  }\
  6326. }\
  6327. else\
  6328. {\
  6329.  if( typeof(userdraw_text) !== 'undefined' ){\
  6330.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
  6331.  }\
  6332.  else\
  6333.  {\
  6334.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
  6335.  }\
  6336. };\
  6337. };\n\
  6338. /* end function 4 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6339.     break;
  6340.     /*
  6341.         attention: we reset userdraw_x / userdraw_y: because  userdraw_x = [][] userdraw_y = [][]
  6342.         used for userdraw multiple paths
  6343.     */
  6344.     case 5: fprintf(js_include_file,"\
  6345. \n/* begin function 5 read_canvas%d() */\n\
  6346. read_canvas%d = function(){\
  6347. set_reply_precision();\
  6348. var p = 0;\
  6349. var reply = \"\";\
  6350. for(p = 0; p < userdraw_x.length;p++){\
  6351.  if(userdraw_x[p] != null ){\
  6352.   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
  6353.  };\
  6354. };\
  6355. if(p == 0){return;};\
  6356. userdraw_x = [];userdraw_y = [];\
  6357. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6358.  var p = 0;var input_reply = new Array();\
  6359.  if( document.getElementById(\"canvas_input0\")){\
  6360.   var t = 0;\
  6361.   while(document.getElementById(\"canvas_input\"+t)){\
  6362.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6363.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6364.     p++;\
  6365.    };\
  6366.    t++;\
  6367.   };\
  6368.  };\
  6369.  if( typeof(userdraw_text) !== 'undefined' ){\
  6370.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6371.  }\
  6372.  else\
  6373.  {\
  6374.   return reply +\"\\n\"+input_reply;\
  6375.  }\
  6376. }\
  6377. else\
  6378. {\
  6379.  if( typeof(userdraw_text) !== 'undefined' ){\
  6380.   return reply+\"\\n\"+userdraw_text;\
  6381.  }\
  6382.  else\
  6383.  {\
  6384.   return reply;\
  6385.  }\
  6386. };\
  6387. };\n\
  6388. /* end function 5 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6389.     break;
  6390.     /*
  6391.         attention: we reset userdraw_x / userdraw_y: because userdraw_x = [][] userdraw_y = [][]
  6392.         used for userdraw multiple paths
  6393.     */
  6394.     case 6: fprintf(js_include_file,"\
  6395. \n/* begin function 6 read_canvas%d() */\n\
  6396. read_canvas%d = function(){\
  6397. var p = 0;\
  6398. var reply = \"\";\
  6399. var tmp_x = new Array();\
  6400. var tmp_y = new Array();\
  6401. var prec = %d;\
  6402. for(p = 0 ; p < userdraw_x.length; p++){\
  6403.  tmp_x = userdraw_x[p];\
  6404.  tmp_y = userdraw_y[p];\
  6405.  if(tmp_x != null){\
  6406.   for(var i = 0 ; i < tmp_x.length ; i++){\
  6407.    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
  6408.    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
  6409.   };\
  6410.   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
  6411.  };\
  6412. };\
  6413. if(p == 0){return;};\
  6414. userdraw_x = [];userdraw_y = [];\
  6415. if( document.getElementById(\"canvas_input0\") ){\
  6416.  var p = 0;var input_reply = new Array();\
  6417.  if( document.getElementById(\"canvas_input0\")){\
  6418.   var t = 0;\
  6419.   while(document.getElementById(\"canvas_input\"+t)){\
  6420.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6421.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6422.     p++;\
  6423.    };\
  6424.    t++;\
  6425.   };\
  6426.  };\
  6427.  if( typeof(userdraw_text) !== 'undefined' ){\
  6428.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6429.  }\
  6430.  else\
  6431.  {\
  6432.   return reply +\"\\n\"+input_reply;\
  6433.  }\
  6434. }\
  6435. else\
  6436. {\
  6437.  if( typeof(userdraw_text) !== 'undefined' ){\
  6438.   return reply +\"\\n\"+userdraw_text;\
  6439.  }\
  6440.  else\
  6441.  {\
  6442.   return reply;\
  6443.  }\
  6444. };\
  6445. };\n\
  6446. /* end function 6 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6447.     break;
  6448.     case 7: fprintf(js_include_file,"\
  6449. \n/* begin function 7 read_canvas%d() */\n\
  6450. read_canvas%d = function(){\
  6451. set_reply_precision();\
  6452. var reply = new Array();\
  6453. var p = 0;\
  6454. while(userdraw_x[p]){\
  6455.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
  6456.  p++;\
  6457. };\
  6458. if(p == 0){return;};\
  6459. if( document.getElementById(\"canvas_input0\") ){\
  6460.  var p = 0;var input_reply = new Array();\
  6461.  if( document.getElementById(\"canvas_input0\")){\
  6462.   var t = 0;\
  6463.   while(document.getElementById(\"canvas_input\"+t)){\
  6464.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6465.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6466.     p++;\
  6467.    };\
  6468.    t++;\
  6469.   };\
  6470.  };\
  6471.  if( typeof(userdraw_text) !== 'undefined' ){\
  6472.   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6473.  }\
  6474.  else\
  6475.  {\
  6476.   return reply+\"\\n\"+input_reply;\
  6477.  }\
  6478. }\
  6479. else\
  6480. {\
  6481.  if( typeof(userdraw_text) !== 'undefined' ){\
  6482.   return reply+\"\\n\"+userdraw_text;\
  6483.  }\
  6484.  else\
  6485.  {\
  6486.   return reply;\
  6487.  }\
  6488. };\
  6489. };\n\
  6490. /* end function 7 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6491.     break;
  6492.     case 8: fprintf(js_include_file,"\
  6493. \n/* begin function 8 read_canvas%d() */\n\
  6494. read_canvas%d = function(){\
  6495. var reply = new Array();\
  6496. var p = 0;\
  6497. var prec = %d;\
  6498. while(userdraw_x[p]){\
  6499.  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  6500.  p++;\
  6501. };\
  6502. if(p == 0){return;};\
  6503. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6504.  var p = 0;var input_reply = new Array();\
  6505.  if( document.getElementById(\"canvas_input0\")){\
  6506.   var t = 0;\
  6507.   while(document.getElementById(\"canvas_input\"+t)){\
  6508.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6509.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6510.     p++;\
  6511.    };\
  6512.    t++;\
  6513.   };\
  6514.  };\
  6515.  if( typeof(userdraw_text) !== 'undefined' ){\
  6516.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6517.  }\
  6518.  else\
  6519.  {\
  6520.   return reply +\"\\n\"+input_reply;\
  6521.  }\
  6522. }\
  6523. else\
  6524. {\
  6525.  if( typeof(userdraw_text) !== 'undefined' ){\
  6526.   return reply +\"\\n\"+userdraw_text;\
  6527.  }\
  6528.  else\
  6529.  {\
  6530.   return reply;\
  6531.  }\
  6532. };\
  6533. };\n\
  6534. /* end function 8 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6535.     break;
  6536.     case 9: fprintf(js_include_file,"\
  6537. \n/* begin function 9 read_canvas%d() */\n\
  6538. read_canvas%d = function(){\
  6539. set_reply_precision();\
  6540. var reply = new Array();\
  6541. var p = 0;\
  6542. while(userdraw_x[p]){\
  6543.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
  6544.  p++;\
  6545. };\
  6546. if(p == 0){return;};\
  6547. if( document.getElementById(\"canvas_input0\") ){\
  6548.  var p = 0;var input_reply = new Array();\
  6549.  if( document.getElementById(\"canvas_input0\")){\
  6550.   var t = 0;\
  6551.   while(document.getElementById(\"canvas_input\"+t)){\
  6552.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6553.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6554.     p++;\
  6555.    };\
  6556.    t++;\
  6557.   };\
  6558.  };\
  6559.  if( typeof(userdraw_text) !== 'undefined' ){\
  6560.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6561.  }\
  6562.  else\
  6563.  {\
  6564.   return reply +\"\\n\"+input_reply;\
  6565.  }\
  6566. }\
  6567. else\
  6568. {\
  6569.  if( typeof(userdraw_text) !== 'undefined' ){\
  6570.   return reply +\"\\n\"+userdraw_text;\
  6571.  }\
  6572.  else\
  6573.  {\
  6574.   return reply;\
  6575.  }\
  6576. };\
  6577. };\n\
  6578. /* end function 9 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6579.     break;
  6580.     case 10: fprintf(js_include_file,"\
  6581. \n/* begin function 10 read_canvas%d() */\n\
  6582. read_canvas%d = function(){\
  6583. var reply = new Array();\
  6584. var p = 0;\
  6585. var prec = %d;\
  6586. var reply = \"\";\
  6587. while(userdraw_x[p]){\
  6588.  reply = reply + (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\";\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec + \";\" + (Math.round(prec*userdraw_radius[p]))/prec + \"\\n\";\
  6589.  p++;\
  6590. };\
  6591. if(p == 0){return;};\
  6592. return reply;\
  6593. };\n\
  6594. /* end function 10 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6595.     break;
  6596.     case 11: fprintf(js_include_file,"\
  6597. \n/* begin function 11 read_canvas%d() */\n\
  6598. read_canvas%d = function(){\
  6599. var reply = \"\";\
  6600. var p = 0;\
  6601. var prec = %d;\
  6602. while(userdraw_x[p+1]){\
  6603.  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\" ;\
  6604.  p = p+2;\
  6605. };\
  6606. if(p == 0){return;};\
  6607. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6608.  var p = 0;var input_reply = new Array();\
  6609.  if( document.getElementById(\"canvas_input0\")){\
  6610.   var t = 0;\
  6611.   while(document.getElementById(\"canvas_input\"+t)){\
  6612.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6613.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6614.     p++;\
  6615.    };\
  6616.    t++;\
  6617.   };\
  6618.  };\
  6619.  if( typeof(userdraw_text) !== 'undefined' ){\
  6620.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6621.  }\
  6622.  else\
  6623.  {\
  6624.   return reply +\"\\n\"+input_reply;\
  6625.  }\
  6626. }\
  6627. else\
  6628. {\
  6629.  if( typeof(userdraw_text) !== 'undefined' ){\
  6630.   return reply +\"\\n\"+userdraw_text;\
  6631.  }\
  6632.  else\
  6633.  {\
  6634.   return reply;\
  6635.  }\
  6636. };\
  6637. };\n\
  6638. /* end function 11 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6639.     break;
  6640.     case 12: fprintf(js_include_file,"\
  6641. \n/* begin function 12 read_canvas%d() */\n\
  6642. read_canvas%d = function(){\
  6643. set_reply_precision();\
  6644. var reply = \"\";\
  6645. var p = 0;\
  6646. while(userdraw_x[p+1]){\
  6647. reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
  6648. p=p+2;\
  6649. };\
  6650. };\
  6651. if(p == 0){return;};\
  6652. if( document.getElementById(\"canvas_input0\") ){\
  6653.  var p = 0;var input_reply = new Array();\
  6654.  if( document.getElementById(\"canvas_input0\")){\
  6655.   var t = 0;\
  6656.   while(document.getElementById(\"canvas_input\"+t)){\
  6657.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6658.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6659.     p++;\
  6660.    };\
  6661.    t++;\
  6662.   };\
  6663.  };\
  6664.  if( typeof(userdraw_text) !== 'undefined' ){\
  6665.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6666.  }\
  6667.  else\
  6668.  {\
  6669.   return reply +\"\\n\"+input_reply;\
  6670.  }\
  6671. }\
  6672. else\
  6673. {\
  6674.  if( typeof(userdraw_text) !== 'undefined' ){\
  6675.   return reply +\"\\n\"+userdraw_text\
  6676.  }\
  6677.  else\
  6678.  {\
  6679.   return reply;\
  6680.  }\
  6681. };\
  6682. };\n\
  6683. /* end function 12 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6684.     break;
  6685.     case 13: fprintf(js_include_file,"\
  6686. \n/* begin function 13 read_canvas%d() */\n\
  6687. read_canvas%d = function(){\
  6688. var reply = new Array();\
  6689. var p = 0;var i = 0;\
  6690. var prec = %d;\
  6691. while(userdraw_x[p+1]){\
  6692.  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;\
  6693.  p = p+2;i++;\
  6694. };\
  6695. if(p == 0){return;};\
  6696. if( document.getElementById(\"canvas_input0\") ){\
  6697.  var p = 0;var input_reply = new Array();\
  6698.  if( document.getElementById(\"canvas_input0\")){\
  6699.   var t = 0;\
  6700.   while(document.getElementById(\"canvas_input\"+t)){\
  6701.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6702.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6703.     p++;\
  6704.    };\
  6705.    t++;\
  6706.   };\
  6707.  };\
  6708.  if( typeof(userdraw_text) !== 'undefined' ){\
  6709.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6710.  }\
  6711.  else\
  6712.  {\
  6713.   return reply +\"\\n\"+input_reply;\
  6714.  }\
  6715. }\
  6716. else\
  6717. {\
  6718.  if( typeof(userdraw_text) !== 'undefined' ){\
  6719.   return reply +\"\\n\"+userdraw_text\
  6720.  }\
  6721.  else\
  6722.  {\
  6723.   return reply;\
  6724.  }\
  6725. };\
  6726. };\n\
  6727. /* end function 13 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6728.     break;
  6729.     case 14: fprintf(js_include_file,"\
  6730. \n/* begin function 14 read_canvas%d() */\n\
  6731. read_canvas%d = function(){\
  6732. set_reply_precision();\
  6733. var reply = new Array();\
  6734. var p = 0;var i = 0;\
  6735. while(userdraw_x[p+1]){\
  6736.  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
  6737.  p = p+2;i++;\
  6738. };\
  6739. if(p == 0){return;};\
  6740. if( document.getElementById(\"canvas_input0\") ){\
  6741.  var p = 0;var input_reply = new Array();\
  6742.  if( document.getElementById(\"canvas_input0\")){\
  6743.   var t = 0;\
  6744.   while(document.getElementById(\"canvas_input\"+t)){\
  6745.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6746.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6747.     p++;\
  6748.    };\
  6749.    t++;\
  6750.   };\
  6751.  };\
  6752.  if( typeof(userdraw_text) !== 'undefined' ){\
  6753.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6754.  }\
  6755.  else\
  6756.  {\
  6757.   return reply +\"\\n\"+input_reply;\
  6758.  }\
  6759. }\
  6760. else\
  6761. {\
  6762.  if( typeof(userdraw_text) !== 'undefined' ){\
  6763.   return reply +\"\\n\"+userdraw_text;\
  6764.  }\
  6765.  else\
  6766.  {\
  6767.   return reply;\
  6768.  }\
  6769. };\
  6770. };\n\
  6771. /* end function 14 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6772.     break;
  6773.     case 15: fprintf(js_include_file,"\
  6774. \n/* begin function 15  read_canvas%d() */\n\
  6775. read_canvas%d = function(){\
  6776. var input_reply = new Array();\
  6777. var p = 0;\
  6778. if( document.getElementById(\"canvas_input0\")){\
  6779.  var t = 0;\
  6780.  while(document.getElementById(\"canvas_input\"+t)){\
  6781.   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6782.    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6783.    p++;\
  6784.   };\
  6785.   t++;\
  6786.  };\
  6787. };\
  6788. if( typeof(userdraw_text) !== 'undefined' ){\
  6789.   return input_reply +\"\\n\"+userdraw_text;\
  6790. }\
  6791. else\
  6792. {\
  6793.  return input_reply;\
  6794. };\
  6795. };\n\
  6796. /* end function 15 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6797.     break;
  6798.     case 16: fprintf(js_include_file,"\
  6799. \n/* begin function 16 read_mathml() */\n\
  6800. function read_mathml(){\
  6801. var reply = new Array();\
  6802. var p = 0;\
  6803. if( document.getElementById(\"mathml0\")){\
  6804.  while(document.getElementById(\"mathml\"+p)){\
  6805.   reply[p] = document.getElementById(\"mathml\"+p).value;\
  6806.   p++;\
  6807.  };\
  6808. };\
  6809. return reply;\
  6810. };\
  6811. this.read_mathml = read_mathml;\n\
  6812. /* end function 16 read_mathml() */");
  6813.     break;
  6814.     case 17:  fprintf(js_include_file,"\
  6815. \n/* begin function 17 read_canvas%d() */\n\
  6816. read_canvas%d = function(){\
  6817. var len = userdraw_x.length;\
  6818. if( len == 0){alert(\"no text typed...\");return;}\
  6819. var rep = px2x(userdraw_x[0])+\",\"+px2y(userdraw_y[0])+\",\"+userdraw_text[0];\
  6820. for(var p = 1 ; p < len ; p++){\
  6821.  rep = rep + \"\\n\" + px2x(userdraw_x[p]) + \",\" + px2y(userdraw_y[p]) + \",\" + userdraw_text[p];\
  6822. };\
  6823. return rep;\
  6824. };\n\
  6825. /* end function 17 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6826.     break;
  6827.     case 18: fprintf(js_include_file,"\
  6828. \n/* javascript has no real modulo function */\n\
  6829. function mod(n, m){\
  6830. var m = parseInt(((n %% m) + m) %% m);\
  6831. return m;\
  6832. };\
  6833. \n/* begin function 18 read_canvas%d() */\n\
  6834. read_canvas%d = function(){\
  6835. var p = 0;\
  6836. var reply = new Array();\
  6837. var name;\
  6838. var t = true;\
  6839. var h;var m;var s;\
  6840. while(t){\
  6841.  try{\
  6842.   name = eval('clocks'+p);\
  6843.   h = name.H;m = name.M;s = name.S;\
  6844.   h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\
  6845.   reply[p] = h+\":\"+m+\":\"+s;\
  6846.   p++;\
  6847.  }catch(e){t=false;};\
  6848. };\
  6849. if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
  6850. return reply;\
  6851. };\n\
  6852. /* end function 18 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6853.     break;
  6854.     case 19: fprintf(js_include_file,"\
  6855. \n/* begin function 19 read_canvas%d() */\n\
  6856. read_canvas%d = function(){\
  6857. return reply[0];\
  6858. };\n\
  6859. /* end function 19 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6860.     break;
  6861.     case 20: fprintf(js_include_file,"\
  6862. \n/* begin function 20 read_canvas%d() */\n\
  6863. read_canvas%d = function(){\
  6864. var prec = %d;\
  6865. var len  = ext_drag_images.length;\
  6866. var reply = new Array(len);\
  6867. for(var p = 0 ; p < len ; p++){\
  6868.    var img = ext_drag_images[p];\
  6869.    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  6870. };\
  6871. return reply;\
  6872. };\n\
  6873. /* end function 20 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6874.     break;
  6875.     case 21: fprintf(js_include_file,"\
  6876. \n/* begin function 21 read_canvas%d() */\n\
  6877. read_canvas%d = function(){\
  6878. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  6879. var reply_coord = new Array();var p = 0;\
  6880. var prec = %d;\
  6881. while(userdraw_x[p]){\
  6882.  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
  6883.  p++;\
  6884. };\
  6885. if(p == 0){return;};\
  6886. if( document.getElementById(\"canvas_input0\") ){\
  6887.  var p = 0;var input_reply = new Array();\
  6888.  if( document.getElementById(\"canvas_input0\")){\
  6889.   var t = 0;\
  6890.   while(document.getElementById(\"canvas_input\"+t)){\
  6891.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6892.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6893.     p++;\
  6894.    };\
  6895.    t++;\
  6896.   };\
  6897.  };\
  6898.  if( typeof(userdraw_text) !== 'undefined' ){\
  6899.   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6900.  }\
  6901.  else\
  6902.  {\
  6903.   return reply_coord+\"\\n\"+input_reply;\
  6904.  }\
  6905. }\
  6906. else\
  6907. {\
  6908.  if( typeof(userdraw_text) !== 'undefined' ){\
  6909.   return reply_coord+\"\\n\"+userdraw_text;\
  6910.  }\
  6911.  else\
  6912.  {\
  6913.   return reply_coord;\
  6914.  };\
  6915. };\
  6916. };\n\
  6917. /* end function 21 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6918.     break;
  6919.     case 22: fprintf(js_include_file,"\
  6920. \n/* begin function 22 read_canvas%d() */\n\
  6921. read_canvas%d = function(){\
  6922. var reply = new Array();\
  6923. var lu = userdraw_x.length;\
  6924. if(lu == 0){return;};\
  6925. var idx = 0;\
  6926. var prec = %d;\
  6927. for(var p = 0 ; p < lu ; p++){\
  6928.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
  6929.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
  6930. };\
  6931. if( document.getElementById(\"canvas_input0\") ){\
  6932.  var p = 0;var input_reply = new Array();\
  6933.  if( document.getElementById(\"canvas_input0\")){\
  6934.   var t = 0;\
  6935.   while(document.getElementById(\"canvas_input\"+t)){\
  6936.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6937.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6938.     p++;\
  6939.    };\
  6940.    t++;\
  6941.   };\
  6942.  };\
  6943.  if( typeof(userdraw_text) !== 'undefined' ){\
  6944.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6945.  }\
  6946.  else\
  6947.  {\
  6948.   return reply +\"\\n\"+input_reply;\
  6949.  }\
  6950. }\
  6951. else\
  6952. {\
  6953.  if( typeof(userdraw_text) !== 'undefined' ){\
  6954.   return reply +\"\\n\"+userdraw_text;\
  6955.  }\
  6956.  else\
  6957.  {\
  6958.   return reply;\
  6959.  }\
  6960. };\
  6961. };\n\
  6962. /* end function 22 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6963.     break;
  6964.     case 23: fprintf(js_include_file,"\
  6965. \n/* begin function 23 read_canvas%d() default 5 px marge */\n\
  6966. read_canvas%d = function(){\
  6967. if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
  6968. var lu = userdraw_x.length;\
  6969. if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
  6970. var reply_x = new Array();var reply_y = new Array();\
  6971. var marge = 5;var p = 0;\
  6972. var prec = %d;\
  6973. for(var i = 0; i < lu - 1 ; i++ ){\
  6974.  if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\
  6975.   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
  6976.   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
  6977.   p++;\
  6978.  };\
  6979.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\
  6980. };\
  6981. if( document.getElementById(\"canvas_input0\")){\
  6982.  var p = 0;var input_reply = new Array();\
  6983.  if( document.getElementById(\"canvas_input0\")){\
  6984.   var t = 0;\
  6985.   while(document.getElementById(\"canvas_input\"+t)){\
  6986.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6987.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6988.     p++;\
  6989.    };\
  6990.    t++;\
  6991.   };\
  6992.  };\
  6993.  if( typeof(userdraw_text) !== 'undefined' ){\
  6994.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6995.  }\
  6996.  else\
  6997.  {\
  6998.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  6999.  }\
  7000. }\
  7001. else\
  7002. {\
  7003.  if( typeof(userdraw_text) !== 'undefined' ){\
  7004.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  7005.  }\
  7006.  else\
  7007.  {\
  7008.   return reply_x+\"\\n\"+reply_y;\
  7009.  };\
  7010. };\
  7011. };\n\
  7012. /* end function 23 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7013.     break;
  7014.     case 24: fprintf(js_include_file,"\n\
  7015. /* begin function 24  read_canvas%d() */\n\
  7016. read_canvas%d = function(){\
  7017. var input_reply = new Array();\
  7018. var p = 0;\
  7019. if( document.getElementById(\"canvas_input0\")){\
  7020.  while(document.getElementById(\"canvas_input\"+p)){\
  7021.    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
  7022.    p++;\
  7023.  };\
  7024.  return input_reply;\
  7025. };\
  7026. };\n\
  7027. /* end function 24 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  7028.     break;
  7029.     case 25:
  7030.     fprintf(js_include_file,"\n/* begin function 25 read_canvas%d(): angle(s) in degrees */\n\
  7031. read_canvas%d = function(){\
  7032. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  7033. var lu = userdraw_radius.length;\
  7034. var prec = %d;\
  7035. var angle_reply = new Array(lu);\
  7036. for(var p = 0 ; p < lu ; p++){\
  7037.  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
  7038. };\
  7039. return angle_reply;\
  7040. };\n\
  7041. /* end function 25 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7042.     break;
  7043.     case 26:
  7044.     fprintf(js_include_file,"\n/* begin function 26 read_canvas%d(): angle(s) in radians */\n\
  7045. read_canvas%d = function(){\
  7046. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  7047. var lu = userdraw_radius.length;\
  7048. var prec = %d;\
  7049. var angle_reply = new Array(lu);\
  7050. for(var p = 0 ; p < lu ; p++){\
  7051.  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
  7052. };\
  7053. return angle_reply;\
  7054. };\n\
  7055. /* end function 26 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7056.     break;
  7057.     case 27:
  7058.     fprintf(js_include_file,"\n/* begin function 27 read_canvas%d(): inputfield(s) location and their values: */\n\
  7059. read_canvas%d = function(){\
  7060. var lu = userdraw_x.length;\
  7061. if( lu < 1){alert(\"nothing drawn...\");return;};\
  7062. set_reply_precision();\
  7063. var prec = %d;var rep = \"\";\
  7064. for(var p = 0 ; p < lu ; p++){\
  7065.   rep = rep + (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\";\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\";\"+ document.getElementById(\"canvas_input\"+p).value + \"\\n\";\
  7066. };\
  7067. return rep;\
  7068. };\n\
  7069. /* end function 27 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7070.     break;
  7071.     case 28:
  7072.     fprintf(js_include_file,"\n/* begin function 28 read_canvas%d() */\n\
  7073. read_canvas%d = function(){\
  7074. var prec = %d;\
  7075. var reply = new Array();var p = 0;\
  7076. var idx = 0;\
  7077. while(userdraw_x[p]){\
  7078.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  7079.  idx++;\
  7080.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  7081.  idx++;\
  7082.  reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\
  7083.  idx++;\
  7084.  p++;\
  7085. };\
  7086. if( p == 0){alert(\"nothing drawn...\");return;}\
  7087. return reply;\
  7088. };\n\
  7089. /* end function 28 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7090.     break;
  7091.     case 29:
  7092.     fprintf(js_include_file,"\n/* begin function 29 read_canvas%d() */\n\
  7093. function x_precision(array_x){\
  7094. var len = array_x.length;\
  7095. var x_array = new Array(len);\
  7096. var prec = %d;\
  7097. for(var p = 0 ; p < len ; p++ ){\
  7098.  x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\
  7099. };\
  7100. return x_array;\
  7101. };\
  7102. function y_precision(array_y){\
  7103. var len = array_y.length;\
  7104. var y_array = new Array(len);\
  7105. var prec = %d;\
  7106. for(var p = 0 ; p < len ; p++ ){\
  7107.  y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\
  7108. };\
  7109. return y_array;\
  7110. };\
  7111. function radius_to_x(array_r){\
  7112. var len = array_r.length;\
  7113. var ff = (xmax - xmin)/xsize;\
  7114. var r_array = new Array(len);\
  7115. var prec = %d;\
  7116. for(var p = 0 ; p < len ; p++ ){\
  7117.  r_array[p] = (Math.round(prec*(ff*(array_r[p]))))/prec;\
  7118. };\
  7119. return r_array;\
  7120. };\
  7121. read_canvas%d = function(){\
  7122. function uniq_fast(arr){\
  7123.  var seen = {};\
  7124.  var out = [];\
  7125.  var len = arr.length;\
  7126.  var j = 0;\
  7127.  for(var i = 0; i < len; i++){\
  7128.   var item = arr[i];\
  7129.   if(seen[item] !== 1) {\
  7130.    seen[item] = 1;out[j++] = item;\
  7131.   };\
  7132.  };\
  7133.  return out;\
  7134. };\
  7135. function list_unique(arr1,arr2,arr3){\
  7136.  if( typeof( allow_duplicate_answers ) === 'number' ){ return [ x_precision(arr1),y_precision(arr2),arr3 ];};\
  7137.  var len1 = arr1.length;\
  7138.  if(len1 != arr2.length){alert('mismatch in number of x and y values...');return;};\
  7139.  var sum = [];var R1=[];var R2=[];\
  7140.  arr1 = x_precision(arr1);\
  7141.  arr2 = y_precision(arr2);\
  7142.  if(arr3 == null){\
  7143.   for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]; };\
  7144.   sum = uniq_fast(sum);var len2=sum.length;\
  7145.   for(var p=0;p<len2;p++){\
  7146.    var tmp = (sum[p]).split('#');\
  7147.    R1[p] = tmp[0];\
  7148.    R2[p] = tmp[1];\
  7149.   };\
  7150.   return [R1,R2];\
  7151.  }else{\
  7152.   var R3 = [];\
  7153.   for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]+'#'+arr3[p];};\
  7154.   sum = uniq_fast(sum);var len2=sum.length;\
  7155.   for(var p=0;p<len2;p++){\
  7156.    var tmp = (sum[p]).split('#');\
  7157.    R1[p] = tmp[0];\
  7158.    R2[p] = tmp[1];\
  7159.    R3[p] = tmp[2];\
  7160.   };\
  7161.   return [R1,R2,R3];\
  7162.  };\
  7163. };\
  7164. var reply=\" \";\
  7165. if(  typeof(points_x) === 'object' && points_x.length > 0 ){var xyz = list_unique(points_x,points_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
  7166. if(  typeof(circles_x) === 'object' && circles_x.length > 0 ){var xyz = list_unique(circles_x,circles_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+radius_to_x(multi_radius)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  7167. if(  typeof(segments_x) === 'object' && segments_x.length > 0 ){ var xyz = list_unique(segments_x,segments_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
  7168. if(  typeof(arrows_x) === 'object' && arrows_x.length > 0 ){var xyz = list_unique(arrows_x,arrows_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  7169. if(  typeof(lines_x) === 'object' && lines_x.length > 0 ){ var xyz = list_unique(lines_x,lines_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  7170. if(  typeof(triangles_x) === 'object' && triangles_x.length > 0){var xyz = list_unique(triangles_x,triangles_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  7171. if(  typeof(polys_x) === 'object' && polys_x.length > 0){ var xyz = list_unique(polys_x,polys_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  7172. if(  typeof(rects_x) === 'object' && rects_x.length > 0 ){var xyz = list_unique(rects_x,rects_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  7173. if(  typeof(closedpoly_x) === 'object' && closedpoly_x.length > 0){ closedpoly_x.pop();closedpoly_y.pop();var xyz = list_unique(closedpoly_x,closedpoly_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
  7174. if(  typeof(parallelogram_x) === 'object' && parallelogram_x.length > 0){var xyz = list_unique(parallelogram_x,parallelogram_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  7175. if(  typeof(text_x) === 'object' && text_x.length > 0){var xyz = list_unique(text_x,text_y,text_abc);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
  7176. if(  typeof(images_x) === 'object' && images_x.length > 0){var xyz = list_unique(images_x,images_y,images_id);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
  7177. if(  typeof(curvedarrows_x) === 'object' && curvedarrows_x.length > 0){var xyz = list_unique(curvedarrows_x,curvedarrows_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\";};\
  7178. if(  typeof(curvedarrows2_x) === 'object' && curvedarrows2_x.length > 0){var xyz = list_unique(curvedarrows2_x,curvedarrows2_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\";};\
  7179. if(  typeof(userdraw_x) === 'object' && userdraw_radius.x> 0){var xyz = list_unique(userdraw_x,userdraw_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; return reply;;};\
  7180. if(  typeof(userdraw_radius) === 'object' && userdraw_radius.length > 0){var xyz = list_unique(userdraw_x,userdraw_y,userdraw_radius);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\"; return reply;;};\
  7181. return reply;\
  7182. };\
  7183. /* end function 29 read_canvas%d() */",canvas_root_id,reply_precision,reply_precision,reply_precision,canvas_root_id,canvas_root_id);
  7184.     break;
  7185.     case 30:
  7186.     fprintf(js_include_file,"\n/* begin function 30 read_canvas%d() */\n\
  7187. read_canvas%d = function(){\
  7188. var reply = new Array(3);\
  7189. var prec = %d;\
  7190. reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
  7191. reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
  7192. reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\
  7193. return reply;\
  7194. };\n\
  7195. /* end function 30 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7196.     break;
  7197.     case 31:
  7198.     fprintf(js_include_file,"\n/* begin function 31 read_canvas%d() */\n\
  7199. read_canvas%d = function(){\
  7200. var reply = new Array(3);\
  7201. var prec = %d;\
  7202. reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
  7203. reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
  7204. reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
  7205. return reply;\
  7206. };\n\
  7207. /* end function 31 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7208.     break;
  7209.     case 32:
  7210.     fprintf(js_include_file,"\n/* begin function 32 read_canvas%d() */\n\
  7211. read_canvas%d = function(){\
  7212. var reply = new Array(6);\
  7213. var prec = %d;\
  7214. reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
  7215. reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
  7216. reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
  7217. reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
  7218. reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
  7219. reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\
  7220. return reply;\
  7221. };\n\
  7222. /* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7223.     break;
  7224.     case 33:
  7225.     fprintf(js_include_file,"\n/* begin function 33 read_canvas%d() */\n\
  7226. read_canvas%d = function(){\
  7227. var reply = userdraw_x+'\\n'+userdraw_y;\
  7228. return reply;\
  7229. };\n\
  7230. /* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  7231.     break;
  7232.     case 34: fprintf(js_include_file,"\
  7233. \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\
  7234. var read_canvas_images = function(){\
  7235. var prec = %d;\
  7236. var len  = ext_drag_images.length;\
  7237. var reply = new Array(len);\
  7238. for(var p = 0 ; p < len ; p++){\
  7239.    var img = ext_drag_images[p];\
  7240.    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  7241. };\
  7242. return reply;\
  7243. };\n\
  7244. /* end function 20 read_canvas_images() */",reply_precision);
  7245.     break;
  7246.  
  7247.     default: canvas_error("hmmm unknown replyformat...");break;
  7248. }
  7249.  return;
  7250. }
  7251.  
  7252.  
  7253. /*
  7254.  add drawfunction:
  7255.  - functions used by userdraw_primitives (circle,rect,path,triangle...)
  7256.  - things not covered by the drag&drop library (static objects like parallel, lattice, gridfill, imagefill)
  7257.  - grid / mathml
  7258.  - will not scale or zoom in
  7259.  - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
  7260.  - is printed directly into 'js_include_file'
  7261. */
  7262.  
  7263. void add_javascript_function(int js_function[],int canvas_root_id){
  7264. int i;
  7265. for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
  7266.  if( js_function[i] == 1){
  7267.     switch(i){
  7268.     case JS_FIND_ANGLE:
  7269.     fprintf(js_include_file,"\n\
  7270. /* function find_angle() */\n\
  7271. function find_angle(xc,yc,x1,y1){var dx = x1 - xc;var dy = yc - y1;return Math.atan2(dx,dy);};");
  7272.     break;
  7273.     case DRAW_EXTERNAL_IMAGE:
  7274. /*
  7275. the external_canvas is already created: it needs to be FIRST in order to do some drawing onto it
  7276. only drag_xy !
  7277. snaptogrid | xsnaptogrid | ysnaptogrid works
  7278. 14/5/2019
  7279. on heavy styled wims (unice.fr etc problems with mouse?
  7280. now uniform method of retreiving mouse coordinates dragstuff.getMouse()
  7281. */
  7282. fprintf(js_include_file,"\n/* drag external images */\n\
  7283. var external_ctx = external_canvas.getContext(\"2d\");\
  7284. var external_canvas_rect = external_canvas.getBoundingClientRect();\
  7285. canvas_div.addEventListener(\"mousedown\",setxy,false);\
  7286. canvas_div.addEventListener(\"mouseup\",dragstop,false);\
  7287. canvas_div.addEventListener(\"mousemove\",dragxy,false);\
  7288. var selected_image = null;\
  7289. var ext_image_cnt = 0;\
  7290. var ext_drag_images = new Array();\
  7291. var ext_centered = 0;\
  7292. function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt,centered,use_snap){\
  7293. ext_centered = centered;\
  7294. ext_image_cnt = idx;\
  7295. if(draggable == 1 ){\
  7296.  reply[click_cnt] = 0;\
  7297. };\
  7298. var image = new Image();\
  7299. image.src = URL;\
  7300. image.onload = function(){\
  7301.  if( sx < 1 ){ sx = 0; };\
  7302.  if( sy < 1 ){ sy = 0; };\
  7303.  if( swidth < 1 ){swidth = image.width;};\
  7304.  if( sheight < 1 ){sheight = image.height;};\
  7305.  if( width < 1 ){width = image.width;};\
  7306.  if( height < 1 ){height = image.height;};\
  7307.  if( resizable == 0 ){\
  7308.   if( swidth > image.width ){ swidth = image.width; };\
  7309.   if( sheight > image.height){ sheight = image.height;};\
  7310.   if( width > image.width ){ width = image.width; };\
  7311.   if( height > image.height){ height = image.height;};\
  7312.  };\
  7313.  var img = new Array(12);\
  7314.  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
  7315.  img[8] = width;img[9] = height;img[10] = click_cnt;img[11] = use_snap;\
  7316.  img[6] = x0;img[7] = y0;\
  7317.  ext_drag_images[idx] = img;\
  7318.  if(centered == 4){\
  7319.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],parseInt(img[6] - 0.5*img[8]),parseInt(img[7] - 0.5*img[9]),img[8],img[9]);\
  7320.  }else{\
  7321.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  7322.  };\
  7323. };\
  7324. };\
  7325. function dragstop(evt){\
  7326. selected_image = null;return;\
  7327. };\
  7328. function dragxy(evt){\
  7329. if( selected_image != null ){\
  7330.  var s_img = ext_drag_images[selected_image];\
  7331.  var mouse = dragstuff.getMouse(evt,external_canvas);\
  7332.  var xy = multisnap_check(mouse.x,mouse.y,s_img[11]);\
  7333.  xy[0] = parseInt(xy[0] - 0.5*s_img[8]);\
  7334.  xy[1] = parseInt(xy[1] - 0.5*s_img[9]);\
  7335.  s_img[6] = xy[0];s_img[7] = xy[1];\
  7336.  ext_drag_images[selected_image] = s_img;\
  7337.  external_ctx.clearRect(0,0,xsize,ysize);\
  7338.  for(var i = 0; i <= ext_image_cnt ; i++){\
  7339.   var img = ext_drag_images[i];\
  7340.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  7341.  };\
  7342. };\
  7343. };\
  7344. function setxy(evt){\
  7345. if( ! selected_image && evt.which == 1 ){\
  7346.  var mouse = dragstuff.getMouse(evt,external_canvas);\
  7347.  var xm = mouse.x;\
  7348.  var ym = mouse.y;\
  7349.  var img;var xmarge;var ymarge;\
  7350.  for(var p = 0 ; p <= ext_image_cnt ; p++){\
  7351.   if( ext_drag_images[p] ){\
  7352.    img = ext_drag_images[p];\
  7353.    if( img[0] != 0 ){\
  7354.     xmarge = 0.5*img[8];ymarge = 0.5*img[9];\
  7355.     if( xm > img[6] - xmarge && xm < img[6] + img[8]){\
  7356.      if( ym > img[7] - ymarge && ym < img[7] + img[9]){\
  7357.       if( img[0] == 1){\
  7358.        if( reply[img[10]] == 1 ){\
  7359.         reply[img[10]] = 0;external_ctx.strokeStyle = '#ffffff';\
  7360.        }\
  7361.        else\
  7362.        {\
  7363.         reply[img[10]] = 1;external_ctx.strokeStyle = '#00ff00';\
  7364.        };\
  7365.        external_ctx.lineWidth = 4;\
  7366.        external_ctx.beginPath();\
  7367.        external_ctx.rect(img[6],img[7],img[8],img[9]);\
  7368.        external_ctx.closePath();\
  7369.        external_ctx.stroke();\
  7370.        return;\
  7371.       }\
  7372.       else\
  7373.       {\
  7374.        img[6] = xm;\
  7375.        img[7] = ym;\
  7376.        ext_drag_images[p] = img;\
  7377.        selected_image = p;\
  7378.        dragxy(evt);\
  7379.       };\
  7380.      };\
  7381.     };\
  7382.    };\
  7383.   };\
  7384.  };\
  7385. }\
  7386. else\
  7387. {\
  7388.  selected_image = null;\
  7389. };\
  7390. };");
  7391.     break;
  7392.     case DRAW_BEZIER:
  7393. fprintf(js_include_file,"\n/* draw bezier curve */\n\
  7394. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7395. 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){\
  7396. var obj;\
  7397. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  7398.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  7399. }\
  7400. else\
  7401. {\
  7402.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  7403. };\
  7404. var ctx = obj.getContext(\"2d\");\
  7405. ctx.save();\
  7406. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7407. ctx.lineWidth = linewidth;\
  7408. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7409. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  7410. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  7411. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7412. ctx.beginPath();\
  7413. ctx.moveTo(x2px(xy_points[0]),y2px(xy_points[1]));\
  7414. 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]));\
  7415. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7416. 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;};\
  7417. ctx.stroke();\
  7418. ctx.restore();\
  7419. };\n",canvas_root_id,canvas_root_id,canvas_root_id);
  7420.     break;
  7421.  
  7422.     case DRAW_GRIDFILL:/* not used for userdraw */
  7423. fprintf(js_include_file,"\n/* draw gridfill */\n\
  7424. var grid_fill_pattern;\
  7425. var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize,use_userdraw){\
  7426. if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
  7427. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7428. var fc = %d+canvas_type;\
  7429. fill_canvas_no.push(fc);\
  7430. var obj = create_canvas%d(fc,xsize,ysize);\
  7431. var ctx = obj.getContext('2d');\
  7432. var x,y;\
  7433. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7434. ctx.rect(0,0,xsize,ysize);\
  7435. ctx.fill();\
  7436. ctx.lineWidth = linewidth;\
  7437. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7438. ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
  7439. for( x = 0 ; x < xsize ; x = x + dx ){\
  7440.  ctx.beginPath();\
  7441.  ctx.moveTo(x,0);\
  7442.  ctx.lineTo(x,ysize);\
  7443.  ctx.closePath();\
  7444.  ctx.stroke();\
  7445. };\
  7446. for( y = 0 ; y < ysize; y = y + dy ){\
  7447.  ctx.beginPath();\
  7448.  ctx.moveTo(0,y);\
  7449.  ctx.lineTo(xsize,y);\
  7450.  ctx.closePath();\
  7451.  ctx.stroke();\
  7452. };\
  7453. if( use_userdraw ){\
  7454.  grid_fill_pattern = ctx;\
  7455. }\
  7456. else\
  7457. {\
  7458.  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};return;\
  7459. };",canvas_root_id,canvas_root_id);
  7460.     break;
  7461.  
  7462.     case DRAW_IMAGEFILL:/* not  used for userdraw */
  7463. fprintf(js_include_file,"\n/* draw imagefill */\n\
  7464. var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize,use_userdraw,use_scaling){\
  7465. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7466. var fc = %d+canvas_type;\
  7467. fill_canvas_no.push(fc);\
  7468. var obj = create_canvas%d(fc,xsize,ysize);\
  7469. var ctx = obj.getContext('2d');\
  7470. var img = new Image();\
  7471. img.src = URL;\
  7472. obj.style.visibility = 'hidden';\
  7473. img.onload = function(){\
  7474.  if( use_scaling == 1 ){\
  7475.   ctx.drawImage(img,x0,y0,xsize,ysize);\
  7476.  }else{\
  7477.   var w0 = img.width;var h0 = img.height;var w;var h;\
  7478.   for( w = x0; w < xsize ; w = w + w0 ){\
  7479.    for( h = y0; h < ysize; h = h + h0){\
  7480.      ctx.drawImage(img,w,h,w0,h0);\
  7481.    };\
  7482.   };\
  7483.  };\
  7484.  if( use_userdraw ){\
  7485.   image_pattern = ctx;\
  7486.  }\
  7487.  else\
  7488.  {\
  7489.   setTimeout(function(){ filltoborder( x0,y0,'red','red',canvas_type,true,ctx); },500);\
  7490.  };\
  7491. };\
  7492. };",canvas_root_id,canvas_root_id);
  7493.     break;
  7494.  
  7495.     case DRAW_DOTFILL:/* not  used for userdraw */
  7496. fprintf(js_include_file,"\n/* draw dotfill */\n\
  7497. var dot_fill_pattern;\
  7498. var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize,use_userdraw){\n\
  7499. if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
  7500. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7501. var fc = %d+canvas_type;\
  7502. fill_canvas_no.push(fc);\
  7503. var obj = create_canvas%d(fc,xsize,ysize);\
  7504. var ctx = obj.getContext('2d');\
  7505. var x,y;\
  7506. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7507. ctx.rect(0,0,xsize,ysize);\
  7508. ctx.fill();\
  7509. ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\
  7510. ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
  7511. for( x = 0 ; x < xsize ; x = x + dx ){\
  7512.  for( y = 0 ; y < ysize ; y = y + dy ){\
  7513.   ctx.beginPath();\
  7514.   ctx.arc(x,y,radius,0,2*Math.PI,false);\
  7515.   ctx.closePath();\
  7516.   ctx.fill();\
  7517.  };\
  7518. };\
  7519. if( use_userdraw ){\
  7520.  dot_fill_pattern = ctx;\
  7521. }\
  7522. else\
  7523. {\
  7524. setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);\
  7525. };\
  7526. return;\
  7527. };",canvas_root_id,canvas_root_id);
  7528.     break;
  7529.  
  7530.     case DRAW_TEXTFILL:/* not  used for userdraw */
  7531. fprintf(js_include_file,"\n/* draw textfill */\n\
  7532. var text_fill_pattern;\
  7533. var draw_textfill = function(canvas_type,x0,y0,color,fontfamily,xsize,ysize,txt,use_userdraw){\n\
  7534. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7535. var fc = %d+canvas_type;\
  7536. fill_canvas_no.push(fc);\
  7537. var obj = create_canvas%d(fc,xsize,ysize);\
  7538. var ctx = obj.getContext('2d');\
  7539. ctx.font = fontfamily;\
  7540. var dx = (ctx.measureText(txt)).width;\
  7541. var dy = parseInt(fontfamily)+2;\
  7542. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7543. ctx.rect(0,0,xsize,ysize);\
  7544. ctx.fill();\
  7545. ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\
  7546. for(var x = 0 ; x < xsize ; x = x + dx ){\
  7547.  for(var y = 0 ; y < ysize ; y = y + dy ){\
  7548.   ctx.fillText(txt,x,y);\
  7549.  };\
  7550. };\
  7551. if( use_userdraw ){\
  7552.  text_fill_pattern = ctx;\
  7553. }\
  7554. else\
  7555. {\
  7556. setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
  7557. return;};",canvas_root_id,canvas_root_id);
  7558.     break;
  7559.  
  7560.     case DRAW_DIAMONDFILL:/* not used for userdraw */
  7561. fprintf(js_include_file,"\n/* draw hatch fill */\n\
  7562. var diamond_fill_pattern;\
  7563. var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\
  7564. if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
  7565. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7566. var fc = %d+canvas_type;\
  7567. fill_canvas_no.push(fc);\
  7568. var obj = create_canvas%d(fc,xsize,ysize);\
  7569. var ctx = obj.getContext('2d');\
  7570. var x;\
  7571. var y;\
  7572. ctx.lineWidth = linewidth;\
  7573. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7574. ctx.rect(0,0,xsize,ysize);\
  7575. ctx.fill();\
  7576. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7577. ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
  7578. y = ysize;\
  7579. ctx.beginPath();\
  7580. for( x = 0 ; x < xsize ; x = x + dx ){\
  7581.  ctx.moveTo(x,0);\
  7582.  ctx.lineTo(xsize,y);\
  7583.  y = y - dy;\
  7584. };\
  7585. y=0;\
  7586. for( x = xsize ; x > 0 ; x = x - dx){\
  7587.  ctx.moveTo(x,ysize);\
  7588.  ctx.lineTo(0,y);\
  7589.  y = y + dy;\
  7590. };\
  7591. y = 0;\
  7592. for( x = 0 ; x < xsize ; x = x + dx ){\
  7593.  ctx.moveTo(x,0);\
  7594.  ctx.lineTo(0,y);\
  7595.  y = y + dy;\
  7596. };\
  7597. y = 0;\
  7598. for( x = 0 ; x < xsize ; x = x + dx ){\
  7599.  ctx.moveTo(xsize,y);\
  7600.  ctx.lineTo(x,ysize);\
  7601.  y = y + dy;\
  7602. };\
  7603. ctx.closePath();\
  7604. ctx.stroke();\
  7605. if( use_userdraw ){\
  7606.  diamond_fill_pattern = ctx;\
  7607. }\
  7608. else\
  7609. {\
  7610.  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
  7611. return;\
  7612. }",canvas_root_id,canvas_root_id);
  7613.     break;
  7614.  
  7615.     case DRAW_HATCHFILL:/* not used for userdraw */
  7616. fprintf(js_include_file,"\n/* draw hatch fill */\n\
  7617. var hatch_fill_pattern;\
  7618. var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\
  7619. if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
  7620. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7621. var fc = %d+canvas_type;\
  7622. fill_canvas_no.push(fc);\
  7623. var obj = create_canvas%d(fc,xsize,ysize);\
  7624. var ctx = obj.getContext('2d');\
  7625. var x,y;\
  7626. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7627. ctx.rect(0,0,xsize,ysize);\
  7628. ctx.fill();\
  7629. ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
  7630. ctx.lineWidth = linewidth;\
  7631. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7632. y = ysize;\
  7633. ctx.beginPath();\
  7634. for( x = 0 ; x < xsize ; x = x + dx ){\
  7635.  ctx.moveTo(x,0);\
  7636.  ctx.lineTo(xsize,y);\
  7637.  y = y - dy;\
  7638. };\
  7639. y = 0;\
  7640. for( x = xsize ; x >= dx ; x = x - dx){\
  7641.  ctx.moveTo(x,ysize);\
  7642.  ctx.lineTo(0,y);\
  7643.  y = y + dy;\
  7644. };\
  7645. ctx.closePath();\
  7646. ctx.stroke();\
  7647. if( use_userdraw ){\
  7648.  hatch_fill_pattern = ctx;\
  7649. }\
  7650. else\
  7651. {\
  7652.  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
  7653. return;\
  7654. };",canvas_root_id,canvas_root_id);
  7655.     break;
  7656.     case DRAW_CIRCLES:/*  used for userdraw */
  7657. fprintf(js_include_file,"\n/* draw circles */\n\
  7658. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7659. 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){\
  7660. ctx.save();\
  7661. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7662. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7663. ctx.lineWidth = line_width;\
  7664. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7665. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7666. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7667. 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;};\
  7668. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7669. for(var p = 0 ; p < x_points.length ; p++ ){\
  7670.  ctx.beginPath();\
  7671.  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
  7672.  ctx.closePath();\
  7673.  if(use_filled != 0 ){ctx.fill();};\
  7674.  ctx.stroke();\
  7675. }\
  7676. ctx.restore();\
  7677. return;\
  7678. };");
  7679.     break;
  7680.     case DRAW_POLYLINE:/* user for userdraw: draw lines through points */
  7681. fprintf(js_include_file,"\n/* draw polyline */\n\
  7682. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7683. 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){\
  7684. ctx.save();\
  7685. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7686. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7687. ctx.lineWidth = line_width;\
  7688. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7689. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7690. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7691. ctx.clearRect(0,0,xsize,ysize);\
  7692. ctx.beginPath();\
  7693. for(var p = 0 ; p < x_points.length-1 ; p++ ){\
  7694.  ctx.moveTo(x_points[p],y_points[p]);\
  7695.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  7696. }\
  7697. ctx.closePath();\
  7698. ctx.stroke();\
  7699. for(var p = 0 ; p < x_points.length ; p++ ){\
  7700.  ctx.beginPath();\
  7701.  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
  7702.  ctx.closePath();ctx.fill();ctx.stroke();\
  7703. };\
  7704. ctx.restore();\
  7705. return;\
  7706. };");
  7707.     break;
  7708.  
  7709.     case DRAW_SEGMENTS:/*  used for userdraw */
  7710. fprintf(js_include_file,"\n/* draw segments */\n\
  7711. 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){\
  7712. ctx.save();\
  7713. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7714. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7715. ctx.lineWidth = line_width;\
  7716. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7717. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7718. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7719. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  7720.  ctx.beginPath();\
  7721.  ctx.moveTo(x_points[p],y_points[p]);\
  7722.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  7723.  ctx.closePath();\
  7724.  ctx.stroke();\
  7725.  }\
  7726.  ctx.restore();\
  7727.  return;\
  7728. };");
  7729.     break;
  7730.  
  7731.     case DRAW_LINES:/*  used for userdraw */
  7732. fprintf(js_include_file,"\n/* draw lines */\n\
  7733. function calc_line(x1,x2,y1,y2){\
  7734. var marge = 2;\
  7735. if(x1 < x2+marge && x1>x2-marge){\
  7736.  return [x1,0,x1,ysize];\
  7737. };\
  7738. if(y1 < y2+marge && y1>y2-marge){\
  7739.  return [0,y1,xsize,y1];\
  7740. };\
  7741. var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
  7742. var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
  7743. return [0,Y1,xsize,Y2];\
  7744. };\
  7745. 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){\
  7746. ctx.save();\
  7747. var line = new Array(4);\
  7748. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7749. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7750. ctx.lineWidth = line_width;\
  7751. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7752. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7753. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7754. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  7755.  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
  7756.  ctx.beginPath();\
  7757.  ctx.moveTo(line[0],line[1]);\
  7758.  ctx.lineTo(line[2],line[3]);\
  7759.  ctx.closePath();\
  7760.  ctx.stroke();\
  7761.  }\
  7762.  ctx.restore();\
  7763.  return;\
  7764. };");
  7765.     break;
  7766.  
  7767.     case DRAW_DEMILINES:/*  used for userdraw */
  7768. fprintf(js_include_file,"\n/* draw demilines */\n\
  7769. function find_inf_point(x1,y1,x2,y2){\
  7770. if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\
  7771. var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\
  7772. if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\
  7773. };\
  7774. 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){\
  7775. ctx.save();\
  7776. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7777. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7778. ctx.lineWidth = line_width;\
  7779. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7780. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7781. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7782. var pair = new Array(4);\
  7783. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  7784.  pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\
  7785.  ctx.beginPath();\
  7786.  ctx.moveTo(pair[0],pair[1]);\
  7787.  ctx.lineTo(pair[2],pair[3]);\
  7788.  ctx.closePath();\
  7789.  ctx.stroke();\
  7790.  }\
  7791.  ctx.restore();\
  7792.  return;\
  7793. };");
  7794.     break;
  7795.  
  7796.     case DRAW_CROSSHAIRS:/*  used for userdraw */
  7797. fprintf(js_include_file,"\n/* draw crosshairs  */\n\
  7798. var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\
  7799. ctx.save();\
  7800. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7801. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7802. ctx.lineWidth = line_width;\
  7803. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7804. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7805. var x1,x2,y1,y2;\
  7806. for(var p = 0 ; p < x_points.length ; p++ ){\
  7807.  x1 = x_points[p] - crosshair_size;\
  7808.  x2 = x_points[p] + crosshair_size;\
  7809.  y1 = y_points[p] - crosshair_size;\
  7810.  y2 = y_points[p] + crosshair_size;\
  7811.  ctx.beginPath();\
  7812.  ctx.moveTo(x1,y1);\
  7813.  ctx.lineTo(x2,y2);\
  7814.  ctx.closePath();\
  7815.  ctx.stroke();\
  7816.  ctx.beginPath();\
  7817.  ctx.moveTo(x2,y1);\
  7818.  ctx.lineTo(x1,y2);\
  7819.  ctx.closePath();\
  7820.  ctx.stroke();\
  7821. }\
  7822. ctx.restore();\
  7823.  return;\
  7824. };");
  7825.     break;
  7826.  
  7827.     case DRAW_RECTS:/*  used for userdraw */
  7828. fprintf(js_include_file,"\n/* draw rects */\n\
  7829. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7830. 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){\
  7831. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7832. ctx.save();\
  7833. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7834. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7835. ctx.lineWidth = line_width;\
  7836. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7837. ctx.strokeStyle = 'rgba('+stroke_color+','+stroke_opacity+')';\
  7838. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
  7839. 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;};\
  7840. for(var p = 0 ; p < x_points.length ; p = p + 2){\
  7841.  ctx.beginPath();\
  7842.  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
  7843.  ctx.closePath();\
  7844.  if(use_filled != 0 ){ctx.fill();}\
  7845.  ctx.stroke();\
  7846. };\
  7847. ctx.restore();\
  7848. return;\
  7849. };");
  7850.     break;
  7851.  
  7852.     case DRAW_ROUNDRECTS:/*  used for userdraw */
  7853. fprintf(js_include_file,"\n/* draw round rects */\n\
  7854. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7855. 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){\
  7856. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7857. ctx.save();\
  7858. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7859. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7860. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7861. ctx.lineWidth = line_width;\
  7862. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7863. 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;};\
  7864. var x,y,w,h,r;\
  7865. for(var p = 0; p < x_points.length; p = p+2){\
  7866.  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);\
  7867.  ctx.beginPath();ctx.moveTo(x + r, y);\
  7868.  ctx.lineTo(x + w - r, y);\
  7869.  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
  7870.  ctx.lineTo(x + w, y + h - r);\
  7871.  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
  7872.  ctx.lineTo(x + r, y + h);\
  7873.  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
  7874.  ctx.lineTo(x, y + r);\
  7875.  ctx.quadraticCurveTo(x, y, x + r, y);\
  7876.  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
  7877.  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7878.  if( use_filled != 0 ){ctx.fill();};\
  7879.  ctx.stroke();\
  7880. }\
  7881. ctx.restore();\
  7882. };");
  7883.     break;
  7884.  
  7885.     case DRAW_ELLIPSES:/* not  used for userdraw */
  7886. fprintf(js_include_file,"\n/* draw ellipses */\n\
  7887. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7888. 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){\
  7889. var obj;\
  7890. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  7891.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  7892. }\
  7893. else\
  7894. {\
  7895.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  7896. };\
  7897. var ctx = obj.getContext(\"2d\");\
  7898. ctx.save();\
  7899. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7900. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7901. 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;};\
  7902. var cx,cy,ry,rx;\
  7903. ctx.lineWidth = line_width;\
  7904. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7905. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7906. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7907. for(var p=0;p< x_points.length;p = p+2){\
  7908.  ctx.beginPath();\
  7909.  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
  7910.  ctx.translate(cx - rx, cy - ry);\
  7911.  ctx.scale(rx, ry);\
  7912.  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
  7913.  if( use_filled != 0 ){ctx.fill();}\
  7914.  ctx.stroke();\
  7915. };\
  7916. ctx.restore();\
  7917. };",canvas_root_id,canvas_root_id,canvas_root_id);
  7918.     break;
  7919.  
  7920.     case DRAW_PATHS: /*  used for userdraw */
  7921. fprintf(js_include_file,"\n/* draw paths */\n\
  7922. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7923. 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){\
  7924. ctx.save();\
  7925. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7926. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7927. ctx.lineWidth = line_width;\
  7928. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7929. ctx.lineJoin = \"round\";\
  7930. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7931. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7932. 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;};\
  7933. ctx.beginPath();\
  7934. ctx.moveTo(x_points[0],y_points[0]);\
  7935. for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
  7936. if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
  7937. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7938. if(use_filled != 0){ctx.fill();}\
  7939. ctx.stroke();\
  7940. ctx.restore();\
  7941. return;\
  7942. };");
  7943.  
  7944.     break;
  7945.     case DRAW_ARROWS:/*  used for userdraw */
  7946. fprintf(js_include_file,"\n/* draw arrows */\n\
  7947. 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){\
  7948. ctx.save();\
  7949. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7950. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7951. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7952. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7953. ctx.lineWidth = line_width;\
  7954. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7955. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7956. ctx.lineCap = \"round\";\
  7957. var x1,y1,x2,y2,dx,dy,len;\
  7958. for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
  7959.   ctx.save();\
  7960.   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
  7961.   len = Math.sqrt(dx*dx+dy*dy);\
  7962.   ctx.translate(x2,y2);\
  7963.   ctx.rotate(Math.atan2(dy,dx));\
  7964.   ctx.lineCap = \"round\";\
  7965.   ctx.beginPath();\
  7966.   ctx.moveTo(0,0);\
  7967.   ctx.lineTo(-len,0);\
  7968.   ctx.closePath();\
  7969.   ctx.stroke();\
  7970.   ctx.beginPath();\
  7971.   ctx.moveTo(0,0);\
  7972.   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  7973.   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  7974.   ctx.closePath();\
  7975.   ctx.fill();\
  7976.   ctx.restore();\
  7977.   if( type == 2 ){\
  7978.     ctx.save();\
  7979.     ctx.translate(x1,y1);\
  7980.     ctx.rotate(Math.atan2(-dy,-dx));\
  7981.     ctx.beginPath();\
  7982.     ctx.moveTo(0,0);\
  7983.     ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\
  7984.     ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\
  7985.     ctx.closePath();\
  7986.     ctx.stroke();\
  7987.     ctx.fill();\
  7988.     ctx.restore();\
  7989.   };\
  7990.  };\
  7991.  ctx.restore();\
  7992.  return;\
  7993. };");
  7994.     break;
  7995.  
  7996.     case DRAW_VIDEO:/* not  used for userdraw */
  7997. fprintf(js_include_file,"\n/* draw video */\n\
  7998. var draw_video = function(canvas_root_id,x,y,w,h,URL){\
  7999. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  8000. var video_div = document.createElement(\"div\");\
  8001. canvas_div.appendChild(video_div);\
  8002. video_div.style.position = \"absolute\";\
  8003. video_div.style.left = x+\"px\";\
  8004. video_div.style.top = y+\"px\";\
  8005. video_div.style.width = w+\"px\";\
  8006. video_div.style.height = h+\"px\";\
  8007. var video = document.createElement(\"video\");\
  8008. video_div.appendChild(video);\
  8009. video.style.width = w+\"px\";\
  8010. video.style.height = h+\"px\";\
  8011. video.autobuffer = true;\
  8012. video.controls = true;video.autoplay = false;\
  8013. var src = document.createElement(\"source\");\
  8014. src.type = \"video/mp4\";\
  8015. src.src = URL;\
  8016. video.appendChild(src);\
  8017. video.load();\
  8018. return;\
  8019. };");
  8020.     break;
  8021.  
  8022.     case DRAW_AUDIO:/* not used for userdraw */
  8023. fprintf(js_include_file,"\n/* draw audio */\n\
  8024. var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
  8025. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  8026. var audio_div = document.createElement(\"div\");\
  8027. canvas_div.appendChild(audio_div);\
  8028. audio_div.style.position = \"absolute\";\
  8029. audio_div.style.left = x+\"px\";\
  8030. audio_div.style.top = y+\"px\";\
  8031. audio_div.style.width = w+\"px\";\
  8032. audio_div.style.height = h+\"px\";\
  8033. var audio = document.createElement(\"audio\");\
  8034. audio_div.appendChild(audio);\
  8035. audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
  8036. audio.autobuffer = true;\
  8037. if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;};\
  8038. if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;};\
  8039. var src1 = document.createElement(\"source\");\
  8040. src1.type = \"audio/ogg\";\
  8041. src1.src = URL1;\
  8042. audio.appendChild(src1);\
  8043. var src2 = document.createElement(\"source\");\
  8044. src2.type = \"audio/mpeg\";\
  8045. src2.src = URL2;\
  8046. audio.appendChild(src2);\
  8047. audio.load();\
  8048. return;\
  8049. };");
  8050.     break;
  8051.  
  8052.     case DRAW_HTTP:/* not  used for userdraw */
  8053. fprintf(js_include_file,"\n/* draw http */\n\
  8054. var draw_http = function(canvas_root_id,x,y,w,h,URL){\
  8055. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  8056. var http_div = document.createElement(\"div\");\
  8057. var iframe = document.createElement(\"iframe\");\
  8058. canvas_div.appendChild(http_div);\
  8059. http_div.appendChild(iframe);\
  8060. iframe.src = URL;\
  8061. iframe.setAttribute(\"width\",w);\
  8062. iframe.setAttribute(\"height\",h);\
  8063. return;\
  8064. };");
  8065.     break;
  8066.  
  8067.     case DRAW_XML: /*
  8068.     onclick=1: click
  8069.     onclick=2 drag ==> always centered (use_offset=4)
  8070.     xy:drag_type = 0;
  8071.     x:    drag_type = 1;
  8072.     y:    drag_type = 2;
  8073.     */
  8074.  
  8075. fprintf(js_include_file,"\n/* draw xml */\n\
  8076. var draw_xml = function(canvas_root_id,x,y,mathml,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,centered,use_snap){\
  8077. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  8078. var xml_div = document.createElement(\"div\");\
  8079. canvas_div.appendChild(xml_div);\
  8080. xml_div.innerHTML = mathml;\
  8081. xml_div.style.position = \"absolute\"; xml_div.style.left = x+\"px\";xml_div.style.top = y+\"px\";\
  8082. var factor = 1;\
  8083. if( centered > 0 ){ factor = 0.5;};\
  8084. var xml_div_width = factor*(parseInt(window.getComputedStyle(xml_div).width , 10));\
  8085. var xml_div_height = factor*(parseInt(window.getComputedStyle(xml_div).height ,10));\
  8086. xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8087. var color_org = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8088. var back_color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  8089. var no_color = \"rgba(255,255,255,0)\";\
  8090. var dragging = false;\
  8091. if( onclick == 2 ){reply[click_cnt] = px2x(x)+','+px2y(y);};\
  8092. if( onclick == 1 ){reply[click_cnt] = 0;};\
  8093. if( onclick == 2 ){\
  8094.  xml_div.onclick = function(){\
  8095.   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;};};\
  8096.   canvas_div.onmousemove = function(evt){\
  8097.    if(!dragging){return;};\
  8098.    var x1;var y1;\
  8099.    var mouse = dragstuff.getMouse(evt,xml_div);\
  8100.    var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
  8101.    switch(drag_type){\
  8102.     case 0: x1 = xy[0]-xml_div_width;y1=xy[1]-xml_div_height;break;\
  8103.     case 1: x1 = xy[0]-xml_div_width;y1 = y;break;\
  8104.     case 2: x1 = x;y1 = xy[1]-xml_div_height;break;\
  8105.     default:x1 = xy[0];y1 = xy[1]; break;\
  8106.    };\
  8107.    xml_div.style.left = x1 + 'px';xml_div.style.top = y1 + 'px';\
  8108.    reply[click_cnt] = px2x(xy[0])+','+px2y(xy[1]);\
  8109.   };\
  8110.  };\
  8111. };\
  8112. if(onclick == 1){\
  8113.  xml_div.onclick = function(){\
  8114.  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;};};\
  8115. };\
  8116. return;\
  8117. };");
  8118.     break;
  8119.     case DRAW_SGRAPH:
  8120. /*
  8121.  xstart = given
  8122.  ystart = given
  8123.  sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
  8124. */
  8125. fprintf(js_include_file,"\n/* draw sgraph */\n\
  8126. var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
  8127. 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);};\
  8128. var ctx = obj.getContext(\"2d\");\
  8129. ctx.font = fontfamily;\
  8130. var minor_opacity = 0.8*opacity;\
  8131. ctx.clearRect(0,0,xsize,ysize);\
  8132. var zero_x = 0.1*xsize;\
  8133. var zero_y = 0.9*ysize;\
  8134. var snor_x;var snor_y;\
  8135. if( xstart != xmin){\
  8136.  snor_x = 0.1*xsize;\
  8137. }\
  8138. else\
  8139. {\
  8140.  snor_x = 0;\
  8141.  xstart = xmin;\
  8142. };\
  8143. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  8144. ctx.lineWidth = 2;\
  8145. ctx.beginPath();\
  8146. ctx.moveTo(xsize,zero_y);\
  8147. ctx.lineTo(zero_x,zero_y);\
  8148. ctx.lineTo(zero_x,0);\
  8149. ctx.stroke();\
  8150. ctx.closePath();\
  8151. ctx.beginPath();\
  8152. ctx.moveTo(zero_x,zero_y);\
  8153. ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
  8154. ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
  8155. ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
  8156. ctx.lineTo(zero_x + snor_x,zero_y);\
  8157. ctx.stroke();\
  8158. ctx.closePath();\
  8159. ctx.beginPath();\
  8160. var num = xstart;\
  8161. var flipflop = 1;\
  8162. var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
  8163. var txtsize;var txt_marge=step_x - 5;\
  8164. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  8165.  txtsize = ctx.measureText(num).width;\
  8166.  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
  8167.  if( flipflop == 1){\
  8168.   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
  8169.  }\
  8170.  else\
  8171.  {\
  8172.   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
  8173.  };\
  8174.  num = num + xmajor;\
  8175. };\
  8176. ctx.stroke();\
  8177. ctx.closePath();\
  8178. ctx.lineWidth = 1;\
  8179. ctx.beginPath();\
  8180. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  8181.   ctx.moveTo(x,zero_y);\
  8182.   ctx.lineTo(x,0);\
  8183. };\
  8184. ctx.stroke();\
  8185. ctx.closePath();\
  8186. if( xminor > 1){\
  8187.  ctx.lineWidth = 0.5;\
  8188.  ctx.beginPath();\
  8189.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  8190.  var minor_step_x = step_x / xminor;\
  8191.  var nx;\
  8192.  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
  8193.    num = 1;\
  8194.    for(var p = 1 ; p < xminor ; p++){\
  8195.     nx = x + num*minor_step_x;\
  8196.     ctx.moveTo(nx,zero_y);\
  8197.     ctx.lineTo(nx,0);\
  8198.     num++;\
  8199.    };\
  8200.  };\
  8201.  ctx.stroke();\
  8202.  ctx.closePath();\
  8203.  ctx.beginPath();\
  8204.  ctx.lineWidth = 2;\
  8205.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  8206.  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  8207.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
  8208.  };\
  8209.  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
  8210.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
  8211.  };\
  8212.  ctx.stroke();\
  8213.  ctx.closePath();\
  8214.  ctx.lineWidth = 0.5;\
  8215. };\
  8216. xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
  8217. if( ystart != ymin){\
  8218.  snor_y = 0.1*ysize;\
  8219. }\
  8220. else\
  8221. {\
  8222.  snor_y = 0;\
  8223.  ystart = ymin;\
  8224. };\
  8225. ctx.lineWidth = 2;\
  8226. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  8227. ctx.beginPath();\
  8228. ctx.moveTo(zero_x,zero_y);\
  8229. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
  8230. ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
  8231. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
  8232. ctx.lineTo(zero_x,zero_y - snor_y);\
  8233. ctx.stroke();\
  8234. ctx.closePath();\
  8235. ctx.beginPath();\
  8236. ctx.lineWidth = 1;\
  8237. num = ystart;\
  8238. var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
  8239. for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
  8240.  ctx.moveTo(zero_x,y);\
  8241.  ctx.lineTo(xsize,y);\
  8242.  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
  8243.  num = num + ymajor;\
  8244. };\
  8245. ctx.stroke();\
  8246. ctx.closePath();\
  8247. if( yminor > 1){\
  8248.  ctx.lineWidth = 0.5;\
  8249.  ctx.beginPath();\
  8250.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  8251.  var minor_step_y = step_y / yminor;\
  8252.  var ny;\
  8253.  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
  8254.   num = 1;\
  8255.   for(var p = 1 ;p < yminor;p++){\
  8256.     ny = y + num*minor_step_y;\
  8257.     ctx.moveTo(zero_x,ny);\
  8258.     ctx.lineTo(xsize,ny);\
  8259.     num++;\
  8260.    };\
  8261.  };\
  8262.  ctx.stroke();\
  8263.  ctx.closePath();\
  8264.  ctx.lineWidth = 2;\
  8265.  ctx.beginPath();\
  8266.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  8267.  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
  8268.   ctx.moveTo(zero_x,y);\
  8269.   ctx.lineTo(zero_x+12,y);\
  8270.  };\
  8271.  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
  8272.   ctx.moveTo(zero_x,y);\
  8273.   ctx.lineTo(zero_x+6,y);\
  8274.  };\
  8275.  ctx.stroke();\
  8276.  ctx.closePath();\
  8277. };\
  8278. ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
  8279. if( typeof(legend%d)  !== 'undefined' ){\
  8280.  ctx.globalAlpha = 1.0;\
  8281.  var y_offset = 2*font_size;\
  8282.  var txt;var txt_size;\
  8283.  var x_offset = xsize - 2*font_size;\
  8284.  var l_length = legend%d.length;var barcolor = new Array();\
  8285.  if( typeof(legendcolors%d) !== 'undefined' ){\
  8286.   for(var p = 0 ; p < l_length ; p++){\
  8287.    barcolor[p] = legendcolors%d[p];\
  8288.   };\
  8289.  }else{\
  8290.   if( barcolor.length == 0 ){\
  8291.    for(var p = 0 ; p < l_length ; p++){\
  8292.     barcolor[p] = stroke_color;\
  8293.    };\
  8294.   };\
  8295.  };\
  8296.  for(var p = 0; p < l_length; p++){\
  8297.   ctx.fillStyle = barcolor[p];\
  8298.   txt = legend%d[p];\
  8299.   txt_size = ctx.measureText(txt).width;\
  8300.   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
  8301.   y_offset = parseInt(y_offset + 1.5*font_size);\
  8302.  };\
  8303. };\
  8304. if( typeof(xaxislabel) !== 'undefined' ){\
  8305.   ctx.fillStyle = \'#000000\';\
  8306.   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
  8307.   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
  8308. };\
  8309. if( typeof(yaxislabel) !== 'undefined'){\
  8310.   ctx.save();\
  8311.   ctx.fillStyle = \'#000000\';\
  8312.   var txt_size = ctx.measureText(yaxislabel).width;\
  8313.   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
  8314.   ctx.rotate(-0.5*Math.PI);\
  8315.   ctx.fillText(yaxislabel,0,0);\
  8316.   ctx.restore();\
  8317. };\
  8318. };\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);
  8319.     break;
  8320.     case DRAW_NUMBERLINE:
  8321. fprintf(js_include_file,"\n/* draw numberline */\n\
  8322. var draw_numberline = function(canvas_type,use_axis_numbering,x0,x1,xmajor,xminor,y0,y1,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor,precision){\
  8323. var obj = create_canvas%d(canvas_type,xsize,ysize);\
  8324. var ctx = obj.getContext(\"2d\");\
  8325. ctx.lineWidth = linewidth || 1;\
  8326. ctx.strokeStyle = \"rgba(\"+strokecolor+\",\"+strokeopacity+\")\";\
  8327. ctx.font = fontfamily || 'Ariel 12px';\
  8328. var fontsize = parseInt(ctx.font);\
  8329. ctx.fillStyle =  \"rgba(\"+fontcolor+\",\"+strokeopacity+\")\";\
  8330. x1 = x2px(x1);\
  8331. x0 = x2px(x0);\
  8332. y0 = y2px(y0);\
  8333. y1 = y2px(y1);\
  8334. var sub_devision = -1;\
  8335. if( xminor%%2 == 0 ){ sub_devision = xminor/2; };\
  8336. var ybase1 = parseInt( y0 + fontsize + 2 );\
  8337. var ybase2 = parseInt( ybase1 + fontsize + 2 );\
  8338. var yh = Math.abs(parseInt( y0 - 0.3*(y0 -y1)));\
  8339. var ys = Math.abs(parseInt( y0 - 0.6*(y0 -y1)));\
  8340. xmajor = x2px(xmajor) - x2px(0);\
  8341. var i;var len;var p;\
  8342. xminor = xmajor / xminor;\
  8343. ctx.beginPath();\
  8344. for(p = x0 ; p < x1 ; p = p + xmajor){\
  8345.  ctx.moveTo(p,y0);ctx.lineTo(p,y1);i = 0;\
  8346.  for(var s = p ; s < p + xmajor ; s = s + xminor ){\
  8347.   ctx.moveTo(s,y0);\
  8348.   if( sub_devision == i){ ctx.lineTo(s,ys); } else { ctx.lineTo(s,yh); };\
  8349.   i++;\
  8350.  };\
  8351. };\
  8352. ctx.moveTo(p,y0);ctx.lineTo(p,y1);\
  8353. ctx.closePath();\
  8354. ctx.stroke();\
  8355. if( use_axis_numbering >-1 ){\
  8356.  var str = x_strings[use_axis_numbering];\
  8357.  len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  8358.  var corr;var x_nums;var x_text;var flipflop = 0;var off = ybase1;\
  8359.  ctx.beginPath();\
  8360.  if( x_strings_up[use_axis_numbering] == null){\
  8361.   for(var p = 0 ; p < len ; p = p+2){\
  8362.    var x_nums = x2px(eval(str[p]));\
  8363.    var x_text = str[p+1];\
  8364.    corr = ctx.measureText(x_text).width;\
  8365.    if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\
  8366.    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),off);\
  8367.   };\
  8368.  }\
  8369.  else\
  8370.  {\
  8371.   for(var p = 0 ; p < len ; p = p+2){\
  8372.    x_nums = x2px(eval(str[p]));\
  8373.    x_text = str[p+1];\
  8374.    corr = ctx.measureText(x_text).width + ybase1 - fontsize;\
  8375.    ctx.save();\
  8376.    ctx.translate(x_nums+0.5*fontsize, corr);\
  8377.    ctx.rotate(-1.5708);\
  8378.    ctx.fillText(x_text,0,0);\
  8379.    ctx.restore();\
  8380.   };\
  8381.  }\
  8382. }\
  8383. else\
  8384. {\
  8385.  var corr;var num;var flipflop = 0;var off = ybase1;\
  8386.  var prec = parseInt(Math.log(precision)/Math.log(10));\
  8387.  for(var p = x0 ; p < x1+xmajor ; p = p+xmajor){\
  8388.   num = (px2x(p)).toFixed(prec);\
  8389.   corr = ctx.measureText(num).width;\
  8390.   if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\
  8391.   ctx.fillText(num,parseInt(p - 0.5*corr),off);\
  8392.  };\
  8393. };\
  8394. };",canvas_root_id);
  8395.     break;
  8396.     case DRAW_GRID:/* not used for userdraw */
  8397. fprintf(js_include_file,"\n/* draw grid */\n\
  8398. 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){\
  8399. 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);};\
  8400. var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
  8401. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  8402. ctx.save();\
  8403. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  8404. if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
  8405. var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8406. ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
  8407. var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
  8408. ctx.font = font_family;\
  8409. var barcolor = new Array();\
  8410. var xstep = xsize*xmajor/(xmax - xmin);\
  8411. var ystep = ysize*ymajor/(ymax - ymin);\
  8412. var x2step = xstep / xminor;\
  8413. var y2step = ystep / yminor;\
  8414. var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
  8415. if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
  8416. if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
  8417. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  8418. ctx.beginPath();\
  8419. ctx.lineWidth = line_width;\
  8420. ctx.strokeStyle = stroke_color;\
  8421. for(var p = zero_x ; p < xsize; p = p + xstep){\
  8422. ctx.moveTo(p,0);\
  8423. ctx.lineTo(p,ysize);\
  8424. };\
  8425. for(var p = zero_x ; p > 0; p = p - xstep){\
  8426. ctx.moveTo(p,0);\
  8427. ctx.lineTo(p,ysize);\
  8428. };\
  8429. for(var p = zero_y ; p < ysize; p = p + ystep){\
  8430. ctx.moveTo(0,p);\
  8431. ctx.lineTo(xsize,p);\
  8432. };\
  8433. for(var p = zero_y ; p > 0; p = p - ystep){\
  8434. ctx.moveTo(0,p);\
  8435. ctx.lineTo(xsize,p);\
  8436. };\
  8437. if( typeof(xaxislabel) !== 'undefined' ){\
  8438. ctx.save();\
  8439. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  8440. var corr =  parseInt(1.1*ctx.measureText(xaxislabel).width);\
  8441. ctx.fillText(xaxislabel,xsize - corr,zero_y - tics_length - 0.4*font_size);\
  8442. ctx.restore();\
  8443. };\
  8444. if( typeof(yaxislabel) !== 'undefined' ){\
  8445. ctx.save();\
  8446. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  8447. var corr = parseInt(ctx.measureText(yaxislabel).width + font_size);\
  8448. ctx.translate(zero_x+tics_length + font_size,corr);\
  8449. ctx.rotate(-0.5*Math.PI);\
  8450. ctx.fillText(yaxislabel,0,0);\
  8451. ctx.restore();\
  8452. };\
  8453. ctx.stroke();\
  8454. ctx.closePath();\
  8455. if( use_axis == 1 ){\
  8456. ctx.save();\
  8457. ctx.beginPath();\
  8458. ctx.strokeStyle = stroke_color;\
  8459. ctx.lineWidth = 0.6*line_width;\
  8460. for(var p = zero_x ; p < xsize; p = p + x2step){\
  8461.  ctx.moveTo(p,0);\
  8462.  ctx.lineTo(p,ysize);\
  8463. };\
  8464. for(var p = zero_x ; p > 0; p = p - x2step){\
  8465.  ctx.moveTo(p,0);\
  8466.  ctx.lineTo(p,ysize);\
  8467. };\
  8468. for(var p = zero_y ; p < ysize; p = p + y2step){\
  8469.  ctx.moveTo(0,p);\
  8470.  ctx.lineTo(xsize,p);\
  8471. };\
  8472. for(var p = zero_y ; p > 0; p = p - y2step){\
  8473.  ctx.moveTo(0,p);\
  8474.  ctx.lineTo(xsize,p);\
  8475. };\
  8476. ctx.stroke();\
  8477. ctx.closePath();\
  8478. ctx.beginPath();\
  8479. ctx.lineWidth = 2*line_width;\
  8480. ctx.strokeStyle = axis_color;\
  8481. ctx.moveTo(0,zero_y);\
  8482. ctx.lineTo(xsize,zero_y);\
  8483. ctx.moveTo(zero_x,0);\
  8484. ctx.lineTo(zero_x,ysize);\
  8485. ctx.stroke();\
  8486. ctx.closePath();\
  8487. ctx.lineWidth = line_width+0.5;\
  8488. ctx.beginPath();\
  8489. for(var p = zero_x ; p < xsize; p = p + xstep){\
  8490.  ctx.moveTo(p,zero_y-tics_length);\
  8491.  ctx.lineTo(p,zero_y+tics_length);\
  8492. };\
  8493. for(var p = zero_x ; p > 0; p = p - xstep){\
  8494.  ctx.moveTo(p,zero_y-tics_length);\
  8495.  ctx.lineTo(p,zero_y+tics_length);\
  8496. };\
  8497. for(var p = zero_y ; p < ysize; p = p + ystep){\
  8498.  ctx.moveTo(zero_x-tics_length,p);\
  8499.  ctx.lineTo(zero_x+tics_length,p);\
  8500. };\
  8501. for(var p = zero_y ; p > 0; p = p - ystep){\
  8502.  ctx.moveTo(zero_x-tics_length,p);\
  8503.  ctx.lineTo(zero_x+tics_length,p);\
  8504. };\
  8505. for(var p = zero_x ; p < xsize; p = p + x2step){\
  8506.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  8507.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  8508. };\
  8509. for(var p = zero_x ; p > 0; p = p - x2step){\
  8510.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  8511.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  8512. };\
  8513. for(var p = zero_y ; p < ysize; p = p + y2step){\
  8514.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  8515.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  8516. };\
  8517. for(var p = zero_y ; p > 0; p = p - y2step){\
  8518.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  8519.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  8520. };\
  8521. ctx.stroke();\
  8522. ctx.closePath();\
  8523. ctx.restore();\
  8524. };\
  8525. if( use_axis_numbering != -1 ){\
  8526. ctx.save();\
  8527. ctx.fillColor = axis_color;\
  8528. ctx.strokeStyle = axis_color;\
  8529. ctx.lineWidth = 2*line_width;\
  8530. ctx.font = font_family;\
  8531. var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
  8532. if( x_strings[use_axis_numbering] != null ){\
  8533.  var str = x_strings[use_axis_numbering];\
  8534.  var len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  8535.  ctx.beginPath();\
  8536.  if( x_strings_up[use_axis_numbering] == null){\
  8537.   for(var p = 0 ; p < len ; p = p+2){\
  8538.    var x_nums = x2px(eval(str[p]));\
  8539.    var x_text = str[p+1];\
  8540.    corr = ctx.measureText(x_text).width;\
  8541.    skip = 1.2*corr/xstep;\
  8542.    if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
  8543.    if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
  8544.    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
  8545.    ctx.moveTo(x_nums,zero_y - tics_length);\
  8546.    ctx.lineTo(x_nums,zero_y + tics_length);\
  8547.   };\
  8548.  }\
  8549.  else\
  8550.  {\
  8551.   for(var p = 0 ; p < len ; p = p+2){\
  8552.    var x_nums = x2px(eval(str[p]));\
  8553.    var x_text = str[p+1];\
  8554.    corr = 2 + tics_length + zero_y + ctx.measureText(x_text).width;\
  8555.    if( corr > ysize ){corr = ysize;};\
  8556.    ctx.save();\
  8557.    ctx.translate(x_nums+0.25*font_size, corr);\
  8558.    ctx.rotate(-1.5708);\
  8559.    ctx.fillText(x_text,0,0);\
  8560.    ctx.restore();\
  8561.    ctx.moveTo(x_nums,zero_y - tics_length);\
  8562.    ctx.lineTo(x_nums,zero_y + tics_length);\
  8563.   };\
  8564.  };\
  8565.  ctx.closePath();\
  8566. }\
  8567. else\
  8568. {\
  8569.  skip = 1;cnt = px2x(zero_x);\
  8570.  prec = Math.log(precision)/(Math.log(10));\
  8571.  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
  8572.  for( var p = zero_x ; p < xsize ; p = p+xstep){\
  8573.   if(skip == 0 ){\
  8574.    disp_cnt = cnt.toFixed(prec);\
  8575.    corr = ctx.measureText(disp_cnt).width;\
  8576.    skip = parseInt(1.2*corr/xstep);\
  8577.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  8578.   }\
  8579.   else\
  8580.   {\
  8581.    skip--;\
  8582.   };\
  8583.   cnt = cnt + xmajor;\
  8584.  };\
  8585.  cnt = px2x(zero_x);skip = 1;\
  8586.  for( var p = zero_x ; p > 0 ; p = p-xstep){\
  8587.   if(skip == 0 ){\
  8588.    disp_cnt = cnt.toFixed(prec);\
  8589.    corr = ctx.measureText(disp_cnt).width;\
  8590.    skip = parseInt(1.2*corr/xstep);\
  8591.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  8592.   }\
  8593.   else\
  8594.   {\
  8595.    skip--;\
  8596.   };\
  8597.   cnt = cnt - xmajor;\
  8598.  };\
  8599. };\
  8600. if( y_strings != null ){\
  8601.  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
  8602.  ctx.beginPath();\
  8603.  for(var p = 0 ; p < len ; p = p+2){\
  8604.   var y_nums = y2px(eval(y_strings[p]));\
  8605.   var y_text = y_strings[p+1];\
  8606.   corr = 2 + tics_length + ctx.measureText(y_text).width;\
  8607.   if( corr > zero_x){corr = parseInt(zero_x+2); }\
  8608.   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
  8609.   ctx.moveTo(zero_x - tics_length,y_nums);\
  8610.   ctx.lineTo(zero_x + tics_length,y_nums);\
  8611.  };\
  8612.  ctx.closePath();\
  8613. }\
  8614. else\
  8615. {\
  8616.  if(f_x == 1){ corr = 1.5*tics_length; }\
  8617.  cnt = px2y(zero_y);skip = 1;\
  8618.  for( var p = zero_y ; p < ysize ; p = p+ystep){\
  8619.   if(skip == 0 ){\
  8620.    skip = parseInt(1.4*font_size/ystep);\
  8621.    disp_cnt = cnt.toFixed(prec);\
  8622.    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  8623.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  8624.   }\
  8625.   else\
  8626.   {\
  8627.    skip--;\
  8628.   };\
  8629.   cnt = cnt - ymajor;\
  8630.  };\
  8631.  corr = 0;cnt = px2y(zero_y);skip = 1;\
  8632.  if(f_x == 1){ corr = 1.5*tics_length; }\
  8633.  for( var p = zero_y ; p > 0 ; p = p-ystep){\
  8634.   if(skip == 0 ){\
  8635.    skip = parseInt(1.4*font_size/ystep);\
  8636.    disp_cnt = cnt.toFixed(prec);\
  8637.    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  8638.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  8639.   }\
  8640.   else\
  8641.   {\
  8642.    skip--;\
  8643.   };\
  8644.   cnt = cnt + ymajor;\
  8645.  };\
  8646. };\
  8647. ctx.stroke();\
  8648. ctx.restore();\
  8649. };\
  8650. if( typeof(legend0)  !== 'undefined' ){\
  8651. ctx.save();\
  8652. ctx.globalAlpha = 1.0;\
  8653. ctx.font = \"bold \"+font_size+\"px Ariel\";\
  8654. var y_offset = 2*font_size;\
  8655. var txt;var txt_size;\
  8656. var x_offset = xsize - 2*font_size;\
  8657. var l_length = legend0.length;\
  8658. if( typeof(legendcolors0) !== 'undefined' ){\
  8659.  for(var p = 0 ; p < l_length ; p++){\
  8660.    barcolor[p] = legendcolors0[p];\
  8661.  };\
  8662. }\
  8663. else\
  8664. {\
  8665.  if( barcolor.length == 0 ){\
  8666.   for(var p = 0 ; p < l_length ; p++){\
  8667.    barcolor[p] = stroke_color;\
  8668.   };\
  8669.  };\
  8670. };\
  8671. for(var p = 0; p < l_length; p++){\
  8672.  ctx.fillStyle = barcolor[p];\
  8673.  txt = legend0[p];\
  8674.  txt_size = ctx.measureText(txt).width;\
  8675.  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
  8676.  y_offset = parseInt(y_offset + 1.5*font_size);\
  8677. };\
  8678. ctx.restore();\
  8679. };\
  8680. if( typeof(barchart_0)  !== 'undefined' ){\
  8681. ctx.save();\
  8682. var num_barcharts = 0;\
  8683. var bar_name = eval('barchart_0');\
  8684. while( typeof(bar_name) !== 'undefined' ){\
  8685.    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
  8686. };\
  8687. var bar_width = parseInt(0.8*x2step/(num_barcharts));\
  8688. for(var i=0 ; i< num_barcharts ; i++){\
  8689.  bar_name = eval('barchart_'+i);\
  8690.  var bar_x = new Array();\
  8691.  var bar_y = new Array();\
  8692.  var lb = bar_name.length;\
  8693.  var idx = 0;\
  8694.  var dx = parseInt(0.5*i*bar_width);\
  8695.  for( var p = 0 ; p < lb ; p = p + 3 ){\
  8696.   bar_x[idx] = x2px(bar_name[p]);\
  8697.   bar_y[idx] = y2px(bar_name[p+1]);\
  8698.   barcolor[idx] = bar_name[p+2];\
  8699.   idx++;\
  8700.  };\
  8701.  ctx.globalAlpha = fill_opacity;\
  8702.  for( var p = 0; p < idx ; p++ ){\
  8703.   ctx.beginPath();\
  8704.   ctx.strokeStyle = barcolor[p];\
  8705.   ctx.fillStyle = barcolor[p];\
  8706.   ctx.rect(bar_x[p]-0.4*x2step+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
  8707.   ctx.fill();\
  8708.   ctx.stroke();\
  8709.   ctx.closePath();\
  8710.  };\
  8711. };\
  8712. ctx.restore();\
  8713. };\
  8714. if( typeof(linegraph_0) !== 'undefined' ){\
  8715. ctx.save();\
  8716. ctx.globalAlpha = 1.0;\
  8717. var i = 0;\
  8718. var line_name = eval('linegraph_'+i);\
  8719. while ( typeof(line_name) !== 'undefined' ){\
  8720.  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
  8721.  ctx.lineWidth = parseInt(line_name[1]);\
  8722.  if(line_name[2] == \"1\"){\
  8723.   var d1 = parseInt(line_name[3]);\
  8724.   var d2 = parseInt(line_name[4]);\
  8725.   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
  8726.  }\
  8727.  else\
  8728.  {\
  8729.  if(ctx.setLineDash){ctx.setLineDash = null;}\
  8730.  if(ctx.mozDash){ctx.mozDash = null;}\
  8731.  };\
  8732.  var data_x = new Array();\
  8733.  var data_y = new Array();\
  8734.  var lb = line_name.length;\
  8735.  var idx = 0;\
  8736.  for( var p = 5 ; p < lb ; p = p + 2 ){\
  8737.   data_x[idx] = x2px(line_name[p]);\
  8738.   data_y[idx] = y2px(line_name[p+1]);\
  8739.   idx++;\
  8740.  };\
  8741.  for( var p = 0; p < idx ; p++){\
  8742.   ctx.beginPath();\
  8743.   ctx.moveTo(data_x[p],data_y[p]);\
  8744.   ctx.lineTo(data_x[p+1],data_y[p+1]);\
  8745.   ctx.stroke();\
  8746.   ctx.closePath();\
  8747.  };\
  8748.  i++;\
  8749.  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
  8750. };\
  8751. ctx.restore();\
  8752. };\
  8753. return;\
  8754. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  8755.     break;
  8756.  
  8757.     case DRAW_PIECHART:
  8758. fprintf(js_include_file,"\n/* draw piecharts */\n\
  8759. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  8760. function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family,use_filled,use_offset){\
  8761. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8762.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8763. }\
  8764. else\
  8765. {\
  8766.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8767. };\
  8768. var center_text = use_offset || 0;\
  8769. var ld = data_color_list.length;\
  8770. var sum = 0;\
  8771. var idx = 0;\
  8772. var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
  8773. var colors = new Array();\
  8774. var data = new Array();\
  8775. for(var p = 0;p < ld; p = p + 2){\
  8776.  data[idx] = parseFloat(data_color_list[p]);\
  8777.  sum = sum + data[idx];\
  8778.  colors[idx] = data_color_list[p+1];\
  8779.  idx++;\
  8780. };\
  8781. if( use_filled > 1 ){\
  8782.  var i = 2;\
  8783.  for(var p = 0 ;  p < idx ; p++){\
  8784.   if(i > 5 ){ i = 2; };\
  8785.   var pat = create_Pattern(0,0,i,colors[p]); all_fill_patterns[p] = pat;i++;\
  8786.  };\
  8787. };\
  8788. var ctx = obj.getContext(\"2d\");\
  8789. ctx.save();\
  8790. var angle;\
  8791. var angle_end = 0;\
  8792. var offset = Math.PI / 2;\
  8793. ctx.globalAlpha = fill_opacity;\
  8794. var angles = [];\
  8795. for(var p=0; p < idx; p++){\
  8796.  ctx.beginPath();\
  8797.  ctx.moveTo(x_center,y_center);\
  8798.  angle = Math.PI * (2 * data[p] / sum);\
  8799.  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
  8800.  ctx.lineTo(x_center, y_center);\
  8801.  if( use_filled > 1 ){ ctx.fillStyle = all_fill_patterns[p]; }else{ ctx.fillStyle = colors[p];};\
  8802.  ctx.fill();\
  8803.  ctx.closePath();\
  8804.  angles.push(angle_end + angle - offset);\
  8805.  angle_end  = angle_end + angle;\
  8806. };\
  8807. if(typeof(legend0) !== 'undefined'){\
  8808.  var legenda = eval(\"legend\"+legend_cnt);\
  8809.  ctx.globalAlpha = 1.0;\
  8810.  ctx.font = font_family;\
  8811.  var y_offset = font_size;\
  8812.  var x_offset = 0;\
  8813.  var txt;var txt_size;\
  8814.  for(var p = 0; p < idx; p++){\
  8815.   ctx.fillStyle = colors[p];\
  8816.   txt = legenda[p];\
  8817.   txt_size = ctx.measureText(txt).width + 2;\
  8818.   if(center_text == 4){\
  8819.    ctx.save();\
  8820.    ctx.translate(x_center, y_center);\
  8821.    ctx.rotate(angles[p]);\
  8822.    ctx.fillText(txt,radius-txt_size,0);\
  8823.    ctx.restore();\
  8824.   }\
  8825.   else\
  8826.   {\
  8827.    if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
  8828.    ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
  8829.    y_offset = parseInt(y_offset + 1.5*font_size);\
  8830.   };\
  8831.  };\
  8832. };\
  8833. ctx.restore();\
  8834. };",canvas_root_id,canvas_root_id,canvas_root_id);
  8835.     break;
  8836.     case DRAW_JSBOXPLOT:
  8837. fprintf(js_include_file,"\n/* draw jsboxplots */\n\
  8838. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  8839. function statistics(data){\
  8840. var len = data.length;\
  8841. var min = 10000000;\
  8842. var max = -10000000;\
  8843. var sum = 0;var d;\
  8844. for(var i=0;i<len;i++){\
  8845.  d = data[i];\
  8846.  if(d < min){min = d;}else{if(d > max){max = d;};};\
  8847.  sum+= parseFloat(data[i]);\
  8848. };\
  8849. var mean = parseFloat(sum/len);\
  8850. var variance = 0;\
  8851. for(var i=0;i<len;i++){\
  8852.  d = data[i];\
  8853.  variance += (d - mean)*(d - mean);\
  8854. };\
  8855. variance = parseFloat(variance / len);\
  8856. var std = Math.sqrt(variance);\
  8857. data.sort(function(a,b){return a - b;});\
  8858. var median;var Q1;var Q3;\
  8859. var half = Math.floor(0.5*len);\
  8860. var q1 = Math.floor(0.25*len);\
  8861. var q3 = Math.floor(0.75*len);\
  8862. var half = Math.floor(0.5*len);\
  8863. if(len %%2 == 1){\
  8864.  median = data[half];\
  8865.  Q1 = data[q1];\
  8866.  Q3 = data[q3];\
  8867. }\
  8868. else\
  8869. {\
  8870.  median = (data[half - 1] + data[half] )/2;\
  8871.  Q1 = (data[q1 - 1] + data[q1] )/2;\
  8872.  Q3 = (data[q3 - 1] + data[q3] )/2;\
  8873. };\
  8874. return [min,Q1,median,Q3,max];\
  8875. };");
  8876.     break;
  8877.     case DRAW_BOXPLOT:
  8878. fprintf(js_include_file,"\n/* draw boxplots */\n\
  8879. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  8880. 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){\
  8881. 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);};\
  8882. var ctx = obj.getContext(\"2d\");\
  8883. ctx.clearRect(0,0,xsize,ysize);\
  8884. ctx.save();\
  8885. ctx.lineWidth = line_width;\
  8886. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  8887. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8888. var colors = new Array(2);\
  8889. colors[0] = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  8890. colors[1] = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8891. if( use_filled > 1 ){\
  8892.   var pat = create_Pattern(0,0,3,colors[0]);\
  8893.   all_fill_patterns[0] = pat;\
  8894.   pat = create_Pattern(0,0,4,colors[1]);\
  8895.   all_fill_patterns[1] = pat;\
  8896. };\
  8897. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  8898. var hh = 0.25*hw;\
  8899. switch(boxplot_source){\
  8900.  case 1: if( typeof(jsboxplot_data) === 'undefined'){return;};data = statistics(jsboxplot_data);break;\
  8901.  case 2: if( typeof(student_boxplot_data) === 'undefined'){return;};data = statistics(student_boxplot_data);break;\
  8902.  case 3: if( typeof(student_boxplot) === 'undefined'){return;};data = student_boxplot;break;\
  8903.  default: break;\
  8904. };\
  8905. var min,Q1,median,Q3,max;\
  8906. if(xy == 1 ){\
  8907.  min=x2px(data[0]);Q1=x2px(data[1]);median=x2px(data[2]);Q3=x2px(data[3]);max=x2px(data[4]);\
  8908.  hh = Math.abs(y2px(hh) - y2px(ystart));\
  8909.  hw = Math.abs(y2px(hw) - y2px(ystart));\
  8910.  cxy = y2px(cxy);\
  8911.  ctx.beginPath();\
  8912.  ctx.moveTo(min,cxy);\
  8913.  ctx.lineTo(Q1,cxy);\
  8914.  ctx.moveTo(Q3,cxy);\
  8915.  ctx.lineTo(max,cxy);\
  8916.  ctx.moveTo(min,cxy+hh);\
  8917.  ctx.lineTo(min,cxy-hh);\
  8918.  ctx.moveTo(max,cxy+hh);\
  8919.  ctx.lineTo(max,cxy-hh);\
  8920.  ctx.closePath();\
  8921.  ctx.stroke();\
  8922.  ctx.beginPath();\
  8923.  ctx.rect(Q1,cxy-2*hh,median-Q1,hw);\
  8924.  ctx.closePath();\
  8925.  if( use_filled != 0 ){\
  8926.   if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\
  8927.   ctx.fill();\
  8928.  };\
  8929.  ctx.stroke();\
  8930.  ctx.beginPath();\
  8931.  ctx.rect(median,cxy-2*hh,Q3-median,hw);\
  8932.  ctx.closePath();\
  8933.  if( use_filled != 0 ){\
  8934.   if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\
  8935.   ctx.fill();\
  8936.  };\
  8937.  ctx.stroke();\
  8938. }else{\
  8939.  min=y2px(data[0]);Q1=y2px(data[1]);median=y2px(data[2]);Q3=y2px(data[3]);max=y2px(data[4]);\
  8940.  hh = Math.abs(x2px(hh) - x2px(xstart));\
  8941.  hw = Math.abs(x2px(hw) - x2px(xstart));\
  8942.  cxy = x2px(cxy);\
  8943.  ctx.beginPath();\
  8944.  ctx.moveTo(cxy,min);\
  8945.  ctx.lineTo(cxy,Q1);\
  8946.  ctx.moveTo(cxy,Q3);\
  8947.  ctx.lineTo(cxy,max);\
  8948.  ctx.moveTo(cxy + hh,min);\
  8949.  ctx.lineTo(cxy - hh,min);\
  8950.  ctx.moveTo(cxy + hh,max);\
  8951.  ctx.lineTo(cxy - hh,max);\
  8952.  ctx.closePath;\
  8953.  ctx.stroke();\
  8954.  ctx.beginPath();\
  8955.  ctx.rect(cxy - 2*hh,Q1,hw,median - Q1);\
  8956.  ctx.closePath();\
  8957.  if( use_filled != 0 ){\
  8958.   if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\
  8959.   ctx.fill();\
  8960.  };\
  8961.  ctx.stroke();\
  8962.  ctx.beginPath();\
  8963.  ctx.rect(cxy - 2*hh,median,hw,Q3 - median);\
  8964.  ctx.closePath();\
  8965.  if( use_filled != 0 ){\
  8966.   if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\
  8967.   ctx.fill();\
  8968.  };\
  8969.  ctx.stroke();\
  8970. };\
  8971. ctx.restore();};",canvas_root_id,canvas_root_id,canvas_root_id);
  8972.     break;
  8973.     case DRAW_ARCS:
  8974. fprintf(js_include_file,"\n/* draw arcs */\n\
  8975. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  8976. 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){\
  8977. ctx.save();\
  8978. if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  8979. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  8980. if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  8981. if(end < start){var tmp = end;end = start;start=tmp;};\
  8982. start = 360 - start;\
  8983. end = 360 - end;\
  8984. ctx.lineWidth = line_width;\
  8985. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  8986. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8987. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  8988. 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;};\
  8989. ctx.beginPath();\
  8990. ctx.moveTo(xc,yc);\
  8991. ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  8992. ctx.lineTo(xc,yc);\
  8993. ctx.closePath();\
  8994. if( use_filled != 0 ){ctx.fill();};\
  8995. ctx.stroke();\
  8996. ctx.restore();\
  8997. };");
  8998.  
  8999.     break;
  9000.     case DRAW_CENTERSTRING:
  9001. fprintf(js_include_file,"\n/* draw centerstring */\n\
  9002. var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
  9003. var obj;\
  9004. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9005.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9006. }\
  9007. else\
  9008. {\
  9009.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9010. };\
  9011. var ctx = obj.getContext(\"2d\");\
  9012. ctx.save();\
  9013. ctx.clearRect(0,0,xsize,ysize);\
  9014. ctx.font = font_family;\
  9015. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  9016. var stringwidth = ctx.measureText(text).width;\
  9017. var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
  9018. ctx.fillText(text,x,y2px(y));\
  9019. ctx.restore();\
  9020. return;\
  9021. };",canvas_root_id,canvas_root_id,canvas_root_id);
  9022.     break;
  9023.     case DRAW_TEXTS:
  9024. fprintf(js_include_file,"\n/* draw text */\n\
  9025. 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){\
  9026. var obj;\
  9027. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9028.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9029. }\
  9030. else\
  9031. {\
  9032.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9033. };\
  9034. var ctx = obj.getContext(\"2d\");\
  9035. if( font_family != 'null' ){\
  9036.  ctx.font = font_family;\
  9037. }\
  9038. else\
  9039. {\
  9040.  ctx.font = font_size+'px Ariel';\
  9041. };\
  9042. 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;};};\
  9043. if(angle2 == 0 && angle != 0){\
  9044.  ctx.save();\
  9045.  if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  9046.  if(use_rotate == 1 ){\
  9047.  ctx.rotate(angle*Math.PI/180);};\
  9048.  ctx.restore();\
  9049. };\
  9050. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  9051. if(angle2 != 0){\
  9052.  ctx.save();\
  9053.  ctx.translate(x,y);\
  9054.  ctx.rotate((360-angle2)*(Math.PI / 180));\
  9055.  ctx.fillText(text,0,0);\
  9056.  ctx.restore();\
  9057. }\
  9058. else\
  9059. {\
  9060.  ctx.fillText(text,x,y);\
  9061. };\
  9062. return;\
  9063. };",canvas_root_id,canvas_root_id,canvas_root_id);
  9064.     break;
  9065.     case DRAW_CURVE:
  9066. fprintf(js_include_file,"\n/* draw curve */\n\
  9067. 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){\
  9068. var obj;\
  9069. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9070.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9071. }\
  9072. else\
  9073. {\
  9074.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9075. };\
  9076. var ctx = obj.getContext(\"2d\");\
  9077. ctx.save();\
  9078. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  9079. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  9080. ctx.beginPath();ctx.lineWidth = line_width;\
  9081. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  9082. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  9083. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  9084. ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
  9085. for(var p = 1 ; p < x_points.length ; p++){\
  9086.  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
  9087.  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
  9088.  }\
  9089.  else\
  9090.  {\
  9091.   ctx.stroke();\
  9092.   ctx.beginPath();\
  9093.   p++;\
  9094.   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
  9095.  };\
  9096. };\
  9097. ctx.stroke();\
  9098. ctx.restore();\
  9099. };",canvas_root_id,canvas_root_id,canvas_root_id);
  9100.     break;
  9101.  
  9102.     case DRAW_INPUTS:
  9103. fprintf(js_include_file,"\n/* draw input fields */\n\
  9104. var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value,use_offset){\
  9105. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  9106. var input = document.createElement(\"input\");\
  9107. input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  9108. input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  9109. input.setAttribute(\"size\",size);\
  9110. input.setAttribute(\"value\",value);\
  9111. input.addEventListener(\"touchstart\", function(e){this.focus();},false);\
  9112. if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
  9113. canvas_div.appendChild(input);\
  9114. if(use_offset != 0 ){ center_input('canvas_input'+input_cnt,x,y,style);};\
  9115. };\
  9116. function center_input(id,x,y,style){\
  9117. var inp = document.getElementById(id);\
  9118. var pos = inp.getBoundingClientRect();\
  9119. var center_x = parseInt(x - 0.5*(pos.width));\
  9120. var center_y = parseInt(y - 0.5*(pos.height));\
  9121. try{ inp.setAttribute(\"style\",\"position:absolute;left:\"+center_x+\"px;top:\"+center_y+\"px;\"+style );}\
  9122. catch(e){return;};\
  9123. };");
  9124.     break;
  9125.  
  9126.     case DRAW_TEXTAREAS:
  9127. fprintf(js_include_file,"\n/* draw text area inputfields */\n\
  9128. var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
  9129. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  9130. var textarea = document.createElement(\"textarea\");\
  9131. textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  9132. textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  9133. textarea.setAttribute(\"cols\",cols);\
  9134. textarea.setAttribute(\"rows\",rows);\
  9135. textarea.value = value;\
  9136. if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
  9137. canvas_div.appendChild(textarea);};");
  9138.     break;
  9139.  
  9140. case DRAW_PIXELS:
  9141. fprintf(js_include_file,"\n/* draw pixel */\n\
  9142. var draw_setpixel = function(x,y,color,opacity,pixelsize){\
  9143. var idx = 2000+Math.ceil(1000*(Math.random()));\
  9144. var canvas = create_canvas%d(idx,xsize,ysize);\
  9145. var d = 0.5*pixelsize;\
  9146. var ctx = canvas.getContext(\"2d\");\
  9147. if(pixelsize%%2 == 1){ ctx.translate(0.5,0.5);};\
  9148. ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
  9149. ctx.clearRect(0,0,xsize,ysize);\
  9150. for(var p=0; p<x.length;p++){\
  9151.  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
  9152. };\
  9153. ctx.fill();ctx.stroke();\
  9154. };",canvas_root_id);
  9155. break;
  9156.  
  9157. case DRAW_CLOCK:
  9158. fprintf(js_include_file,"\n/* begin command clock */\n\
  9159. var clock_canvas = create_canvas%d(%d,xsize,ysize);\
  9160. var clock_ctx = clock_canvas.getContext(\"2d\");\
  9161. var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
  9162. clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\
  9163. clock_ctx.save();\
  9164. clock_ctx.globalAlpha = clock_bg_opacity;\
  9165. this.type = type || 0;\
  9166. this.interaction = interaction || 0;\
  9167. this.H = H;\
  9168. this.M = M;\
  9169. this.S = S;\
  9170. this.xc = xc || xsize/2;\
  9171. this.yc = yc || ysize/2;\
  9172. this.radius = radius || xsize/4;\
  9173. var font_size = parseInt(0.2*this.radius);\
  9174. this.H_color = h_color || \"black\";\
  9175. this.M_color = m_color || \"black\";\
  9176. this.S_color = s_color || \"black\";\
  9177. this.fg_color = fg_color || \"black\";\
  9178. this.bg_color = bg_color || \"white\";\
  9179. clock_ctx.translate(this.xc,this.yc);\
  9180. clock_ctx.beginPath();\
  9181. clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
  9182. clock_ctx.fillStyle = this.bg_color;\
  9183. clock_ctx.fill();\
  9184. clock_ctx.closePath();\
  9185. clock_ctx.beginPath();\
  9186. clock_ctx.font = font_size+\"px Arial\";\
  9187. clock_ctx.fillStyle = this.fg_color;\
  9188. clock_ctx.textAlign = \"center\";\
  9189. clock_ctx.textBaseline = 'middle';\
  9190. var angle;var x1,y1,x2,y2;\
  9191. var angle_cos;var angle_sin;\
  9192. clock_ctx.globalAlpha = clock_fg_opacity;\
  9193. switch(type){\
  9194. case 0:clock_ctx.beginPath();\
  9195. for(var p = 1; p <= 12 ; p++){\
  9196.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  9197.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  9198.  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  9199.  clock_ctx.moveTo(x1,y1);\
  9200.  clock_ctx.lineTo(x2,y2);\
  9201. };\
  9202. for(var p = 1; p <= 60 ; p++){\
  9203.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  9204.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  9205.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  9206.  clock_ctx.moveTo(x1,y1);\
  9207.  clock_ctx.lineTo(x2,y2);\
  9208. };\
  9209. clock_ctx.closePath();\
  9210. clock_ctx.stroke();\
  9211. break;\
  9212. case 1:\
  9213. 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;\
  9214. case 2:\
  9215. 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);};\
  9216. clock_ctx.beginPath();\
  9217. for(var p = 1; p <= 12 ; p++){\
  9218.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  9219.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  9220.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  9221.  clock_ctx.moveTo(x1,y1);\
  9222.  clock_ctx.lineTo(x2,y2);\
  9223. };\
  9224. for(var p = 1; p <= 60 ; p++){\
  9225.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  9226.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  9227.  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  9228.  clock_ctx.moveTo(x1,y1);\
  9229.  clock_ctx.lineTo(x2,y2);\
  9230. };\
  9231. clock_ctx.closePath();\
  9232. clock_ctx.stroke();\
  9233. break;\
  9234. };\
  9235. angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
  9236. clock_ctx.rotate(angle);\
  9237. clock_ctx.beginPath();\
  9238. clock_ctx.moveTo(-3, -2);\
  9239. clock_ctx.lineTo(-3, 2);\
  9240. clock_ctx.lineTo(this.radius * 0.6, 1);\
  9241. clock_ctx.lineTo(this.radius  * 0.6, -1);\
  9242. clock_ctx.fillStyle = this.H_color;\
  9243. clock_ctx.fill();\
  9244. clock_ctx.rotate(-angle);\
  9245. angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
  9246. clock_ctx.rotate(angle);\
  9247. clock_ctx.beginPath();\
  9248. clock_ctx.moveTo(-3, -2);\
  9249. clock_ctx.lineTo(-3, 2);\
  9250. clock_ctx.lineTo(this.radius  * 0.8, 1);\
  9251. clock_ctx.lineTo(this.radius  * 0.8, -1);\
  9252. clock_ctx.fillStyle = this.M_color;\
  9253. clock_ctx.fill();\
  9254. clock_ctx.rotate(-angle);\
  9255. angle = (this.S - 15) * 2 * Math.PI / 60;\
  9256. clock_ctx.rotate(angle);\
  9257. clock_ctx.beginPath();\
  9258. clock_ctx.moveTo(0,0);\
  9259. clock_ctx.lineTo(this.radius  * 0.9, 1);\
  9260. clock_ctx.lineTo(this.radius  * 0.9, -1);\
  9261. clock_ctx.strokeStyle = this.S_color;\
  9262. clock_ctx.stroke();\
  9263. clock_ctx.restore();\
  9264. };",canvas_root_id,CLOCK_CANVAS);
  9265. break;
  9266.  
  9267. case DRAW_LATTICE:
  9268. fprintf(js_include_file,"\n/* draw lattice */\n\
  9269. 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){\
  9270. var obj;\
  9271. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9272.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9273. }\
  9274. else\
  9275. {\
  9276.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9277. };\
  9278. var ctx = obj.getContext(\"2d\");\
  9279. ctx.save();\
  9280. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  9281. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  9282. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  9283. 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;};\
  9284. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  9285. var radius = line_width;\
  9286. var x = 0;\
  9287. var y = 0;\
  9288. var x_step_px = xsize/(xmax-xmin);\
  9289. var y_step_px = ysize/(ymax-ymin);\
  9290. var xv1 = dx1*x_step_px;\
  9291. var yv1 = dy1*y_step_px;\
  9292. var xv2 = dx2*x_step_px;\
  9293. var yv2 = dy2*y_step_px;\
  9294. for(var p = 0; p < n1 ;p++){\
  9295.  x = p*xv1 + x0;\
  9296.  y = p*yv1 + y0;\
  9297.  for(var c = 0; c < n2 ; c++){\
  9298.   ctx.beginPath();\
  9299.   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
  9300.   ctx.fill();\
  9301.   ctx.stroke();\
  9302.   ctx.closePath();\
  9303.  };\
  9304. };\
  9305. ctx.restore();\
  9306. return;\
  9307. };",canvas_root_id,canvas_root_id,canvas_root_id);
  9308.     break;
  9309. case DRAW_XYLOGSCALE:
  9310. fprintf(js_include_file,"\n/* draw xylogscale */\n\
  9311. 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){\
  9312. var obj;\
  9313. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9314.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9315. }\
  9316. else\
  9317. {\
  9318.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9319. };\
  9320. var ctx = obj.getContext(\"2d\");\
  9321. ctx.clearRect(0,0,xsize,ysize);\
  9322. ctx.save();\
  9323. var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
  9324. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  9325. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  9326. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  9327. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  9328. if(use_axis_numbering != -1){\
  9329.  ctx.font = font_family;\
  9330.  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
  9331.  ymarge = parseInt(1.5*font_size);\
  9332.  ctx.save();\
  9333.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  9334.  ctx.rect(0,0,xmarge,ysize);\
  9335.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  9336.  ctx.fill();\
  9337.  ctx.restore();\
  9338. }else{xmarge = 0;ymarge = 0;};\
  9339. if( typeof(xaxislabel) !== 'undefined' ){\
  9340.  ctx.save();\
  9341.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  9342.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9343.  corr =  ctx.measureText(xaxislabel).width;\
  9344.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  9345.  ctx.restore();\
  9346. };\
  9347. if( typeof(yaxislabel) !== 'undefined' ){\
  9348.  ctx.save();\
  9349.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  9350.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9351.  corr = ctx.measureText(yaxislabel).width;\
  9352.  ctx.translate(xmarge+font_size,corr+font_size);\
  9353.  ctx.rotate(-0.5*Math.PI);\
  9354.  ctx.fillText(yaxislabel,0,0);\
  9355.  ctx.restore();\
  9356. };\
  9357. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9358. ctx.lineWidth = line_width;\
  9359. for(var p = x_min; p <= x_max ; p++){\
  9360.  num = Math.pow(xlogbase,p);\
  9361.  for(var i = 1 ; i < xlogbase ; i++){\
  9362.   x_e = x2px(i*num);\
  9363.   if( i == 1 ){\
  9364.    ctx.lineWidth = line_width;\
  9365.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9366.    if( use_axis_numbering != -1 && p > x_min){\
  9367.      xtxt = xlogbase+'^'+p.toFixed(0);\
  9368.      corr = 0.5*(ctx.measureText(xtxt).width);\
  9369.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  9370.    };\
  9371.   }else{\
  9372.    ctx.lineWidth = 0.2*line_width;\
  9373.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9374.   };\
  9375.   if( x_e >= xmarge ){\
  9376.    ctx.beginPath();\
  9377.    ctx.moveTo(x_e,0);\
  9378.    ctx.lineTo(x_e,ysize - ymarge);\
  9379.    ctx.stroke();\
  9380.    ctx.closePath();\
  9381.   };\
  9382.  };\
  9383. };\
  9384. for(var p = y_min; p <= y_max ; p++){\
  9385.  num = Math.pow(ylogbase,p);\
  9386.  for(var i = 1 ; i < ylogbase ; i++){\
  9387.   y_e = y2px(i*num);\
  9388.   if( i == 1 ){\
  9389.    ctx.lineWidth = line_width;\
  9390.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9391.    if( use_axis_numbering != -1 && p > y_min){\
  9392.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  9393.    };\
  9394.   }else{\
  9395.    ctx.lineWidth = 0.2*line_width;\
  9396.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9397.   };\
  9398.   ctx.beginPath();\
  9399.   ctx.moveTo(xmarge,y_e);\
  9400.   ctx.lineTo(xsize,y_e);\
  9401.   ctx.stroke();\
  9402.   ctx.closePath();\
  9403.  };\
  9404. };\
  9405. ctx.restore();\
  9406. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  9407.     break;
  9408.  
  9409. case DRAW_XLOGSCALE:
  9410. fprintf(js_include_file,"\n/* draw xlogscale */\n\
  9411. 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){\
  9412. var obj;\
  9413. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9414.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9415. }\
  9416. else\
  9417. {\
  9418.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9419. };\
  9420. var ctx = obj.getContext(\"2d\");\
  9421. ctx.clearRect(0,0,xsize,ysize);\
  9422. ctx.save();\
  9423. ctx.lineWidth = line_width;\
  9424. var prec = Math.log(precision)/Math.log(10);\
  9425. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  9426. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  9427. var y_min = 0;var y_max = ysize;var x_e;var corr;\
  9428. var xtxt;var ytxt;var num;var xmarge;var ymarge;\
  9429. if(use_axis_numbering != -1){\
  9430.  ctx.font = font_family;\
  9431.  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
  9432.  ymarge = parseInt(1.5*font_size);\
  9433.  ctx.save();\
  9434.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  9435.  ctx.rect(0,0,xmarge,ysize);\
  9436.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  9437.  ctx.fill();\
  9438.  ctx.restore();\
  9439. }else{xmarge = 0;ymarge = 0;};\
  9440. if( typeof(xaxislabel) !== 'undefined' ){\
  9441.  ctx.save();\
  9442.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  9443.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9444.  corr =  ctx.measureText(xaxislabel).width;\
  9445.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  9446.  ctx.restore();\
  9447. };\
  9448. if( typeof(yaxislabel) !== 'undefined' ){\
  9449.  ctx.save();\
  9450.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  9451.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9452.  corr = ctx.measureText(yaxislabel).width;\
  9453.  ctx.translate(xmarge+font_size,corr+font_size);\
  9454.  ctx.rotate(-0.5*Math.PI);\
  9455.  ctx.fillText(yaxislabel,0,0);\
  9456.  ctx.restore();\
  9457. };\
  9458. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9459. ctx.lineWidth = line_width;\
  9460. for(var p = x_min; p <= x_max ; p++){\
  9461.  num = Math.pow(xlogbase,p);\
  9462.  for(var i = 1 ; i < xlogbase ; i++){\
  9463.   x_e = x2px(i*num);\
  9464.   if( i == 1 ){\
  9465.     ctx.lineWidth = line_width;\
  9466.     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9467.    if( use_axis_numbering != -1 && p > x_min ){\
  9468.      xtxt = xlogbase+'^'+p.toFixed(0);\
  9469.      corr = 0.5*(ctx.measureText(xtxt).width);\
  9470.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  9471.    };\
  9472.   }else{\
  9473.    ctx.lineWidth = 0.2*line_width;\
  9474.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9475.   };\
  9476.   if( x_e >= xmarge ){\
  9477.    ctx.beginPath();\
  9478.    ctx.moveTo(x_e,0);\
  9479.    ctx.lineTo(x_e,ysize - ymarge);\
  9480.    ctx.stroke();\
  9481.    ctx.closePath();\
  9482.   };\
  9483.  };\
  9484. };\
  9485. var stepy = Math.abs(y2px(ymajor) - y2px(0));\
  9486. var minor_step = stepy / yminor;\
  9487. for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
  9488.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9489.  ctx.lineWidth = line_width;\
  9490.  ctx.beginPath();\
  9491.  ctx.moveTo(xmarge,y);\
  9492.  ctx.lineTo(xsize,y);\
  9493.  ctx.stroke();\
  9494.  ctx.closePath();\
  9495.  if( use_axis_numbering != -1){\
  9496.   ytxt = (px2y(y)).toFixed(prec);\
  9497.   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
  9498.  };\
  9499.  for(var dy = 1 ; dy < yminor ; dy++){\
  9500.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9501.   ctx.lineWidth = 0.2*line_width;\
  9502.   ctx.beginPath();\
  9503.   ctx.moveTo(xmarge,y+dy*minor_step);\
  9504.   ctx.lineTo(xsize,y+dy*minor_step);\
  9505.   ctx.stroke();\
  9506.   ctx.closePath();\
  9507.  };\
  9508. };\
  9509. ctx.restore();\
  9510. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  9511.     break;
  9512. case DRAW_YLOGSCALE:
  9513. fprintf(js_include_file,"\n/* draw ylogscale */\n\
  9514. 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){\
  9515. var obj;\
  9516. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9517.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9518. }\
  9519. else\
  9520. {\
  9521.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9522. };\
  9523. var ctx = obj.getContext(\"2d\");\
  9524. ctx.clearRect(0,0,xsize,ysize);\
  9525. ctx.save();\
  9526. ctx.lineWidth = line_width;\
  9527. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  9528. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  9529. var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
  9530. if(use_axis_numbering != -1){\
  9531.  ctx.font = font_family;\
  9532.  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
  9533.  ymarge = 2*font_size;\
  9534.  ctx.save();\
  9535.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  9536.  ctx.rect(0,0,xmarge,ysize);\
  9537.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  9538.  ctx.fill();\
  9539.  ctx.restore();\
  9540. }else{xmarge = 0;ymarge = 0;};\
  9541. if( typeof(xaxislabel) !== 'undefined' ){\
  9542.  ctx.save();\
  9543.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  9544.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9545.  corr =  ctx.measureText(xaxislabel).width;\
  9546.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  9547.  ctx.restore();\
  9548. };\
  9549. if( typeof(yaxislabel) !== 'undefined' ){\
  9550.  ctx.save();\
  9551.  ctx.font = \"italic \"+font_size+\"px Ariel\";\
  9552.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9553.  corr = ctx.measureText(yaxislabel).width;\
  9554.  ctx.translate(xmarge+font_size,corr+font_size);\
  9555.  ctx.rotate(-0.5*Math.PI);\
  9556.  ctx.fillText(yaxislabel,0,0);\
  9557.  ctx.restore();\
  9558. };\
  9559. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9560. ctx.lineWidth = line_width;\
  9561. for(var p = y_min; p <= y_max ; p++){\
  9562.  num = Math.pow(ylogbase,p);\
  9563.  for(var i = 1 ; i < ylogbase ; i++){\
  9564.   y_e = y2px(i*num);\
  9565.   if( i == 1 ){\
  9566.    ctx.lineWidth = line_width;\
  9567.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9568.    if( use_axis_numbering != -1 && p > y_min){\
  9569.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  9570.    };\
  9571.   }else{\
  9572.    ctx.lineWidth = 0.2*line_width;\
  9573.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9574.   };\
  9575.   ctx.beginPath();\
  9576.   ctx.moveTo(xmarge,y_e);\
  9577.   ctx.lineTo(xsize,y_e);\
  9578.   ctx.stroke();\
  9579.   ctx.closePath();\
  9580.  };\
  9581. };\
  9582. var stepx = Math.abs(x2px(xmajor) - x2px(0));\
  9583. var minor_step = stepx / xminor;\
  9584. var prec = Math.log(precision)/Math.log(10);\
  9585. var xtxt;var corr;var flip = 0;\
  9586. for(var x = stepx ; x < xsize ; x = x + stepx){\
  9587.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9588.  ctx.lineWidth = line_width;\
  9589.  ctx.beginPath();\
  9590.  ctx.moveTo(x,ysize-ymarge);\
  9591.  ctx.lineTo(x,0);\
  9592.  ctx.stroke();\
  9593.  ctx.closePath();\
  9594.  if( use_axis_numbering != -1){\
  9595.   xtxt = (px2x(x)).toFixed(prec);\
  9596.   corr = 0.5*(ctx.measureText(xtxt).width);\
  9597.   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
  9598.   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
  9599.  };\
  9600.  for(var dx = 1 ; dx < xminor ; dx++){\
  9601.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9602.   ctx.lineWidth = 0.2*line_width;\
  9603.   ctx.beginPath();\
  9604.   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
  9605.   ctx.lineTo(x+dx*minor_step,0);\
  9606.   ctx.stroke();\
  9607.   ctx.closePath();\
  9608.  };\
  9609. };\
  9610. ctx.restore();\
  9611. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  9612.     break;
  9613.  
  9614.     default:break;
  9615.    }
  9616.   }
  9617.  }
  9618.   return;
  9619. }
  9620.  
  9621. void check_string_length(int L){
  9622.  if( L > MAX_BUFFER-1){
  9623.   canvas_error("problem with your arguments to command...");
  9624.  }
  9625.  return;
  9626. }
  9627.  
  9628.  
  9629. int get_token(FILE *infile){
  9630.         int     c,i=0;
  9631.         char    temp[MAX_INT], *input_type;
  9632.         char    *line="line",
  9633.         *audio="audio",
  9634.         *blink="blink",
  9635.         *arrowhead="arrowhead",
  9636.         *crosshairsize="crosshairsize",
  9637.         *crosshair="crosshair",
  9638.         *crosshairs="crosshairs",
  9639.         *audioobject="audioobject",
  9640.         *style="style",
  9641.         *mouse="mouse",
  9642.         *mousex="mousex",
  9643.         *mousey="mousey",
  9644.         *mouse_display="display",
  9645.         *mouse_degree="mouse_degree",
  9646.         *userdraw="userdraw",
  9647.         *highlight="highlight",
  9648.         *http="http",
  9649.         *rays="rays",
  9650.         *dashtype="dashtype",
  9651.         *dashed="dashed",
  9652.         *filled="filled",
  9653.         *lattice="lattice",
  9654.         *parallel="parallel",
  9655.         *segment="segment",
  9656.         *segments="segments",
  9657.         *dsegment="dsegment",
  9658.         *dsegments="dsegments",
  9659.         *seg="seg",
  9660.         *segs="segs",
  9661.         *bgimage="bgimage",
  9662.         *bgcolor="bgcolor",
  9663.         *strokecolor="strokecolor",
  9664.         *backgroundimage="backgroundimage",
  9665.         *text="text",
  9666.         *textup="textup",
  9667.         *mouseprecision="mouseprecision",
  9668.         *precision="precision",
  9669.         *plotsteps="plotsteps",
  9670.         *plotstep="plotstep",
  9671.         *tsteps="tsteps",
  9672.         *curve="curve",
  9673.         *dcurve="dcurve",
  9674.         *curvedarrow="curvedarrow",
  9675.         *curvedarrows="curvedarrows",
  9676.         *curvedarrow2="curvedarrow2",
  9677.         *curvedarrows2="curvedarrows2",
  9678.         *plot="plot",
  9679.         *dplot="dplot",
  9680.         *levelcurve="levelcurve",
  9681.         *fontsize="fontsize",
  9682.         *fontcolor="fontcolor",
  9683.         *axis="axis",
  9684.         *axisnumbering="axisnumbering",
  9685.         *axisnumbers="axisnumbers",
  9686.         *arrow="arrow",
  9687.         *vector="vector",
  9688.         *vectors="vectors",
  9689.         *darrow="darrow",
  9690.         *arrow2="arrow2",
  9691.         *darrow2="darrow2",
  9692.         *arrows="arrows",
  9693.         *arrows2="arrows2",
  9694.         *zoom="zoom",
  9695.         *grid="grid",
  9696.         *hline="hline",
  9697.         *dhline="dhline",
  9698.         *drag="drag",
  9699.         *horizontalline="horizontalline",
  9700.         *horizontallines="horizontallines",
  9701.         *vline="vline",
  9702.         *dvline="dvline",
  9703.         *verticalline="verticalline",
  9704.         *verticallines="verticallines",
  9705.         *triangle="triangle",
  9706.         *triangles="triangles",
  9707.         *ftriangle="ftriangle",
  9708.         *ftriangles="ftriangles",
  9709.         *mathml="mathml",
  9710.         *html="html",
  9711.         *input="input",
  9712.         *clearbutton="clearbutton",
  9713.         *erase="erase",
  9714.         *delete="delete",
  9715.         *inputstyle="inputstyle",
  9716.         *textarea="textarea",
  9717.         *trange="trange",
  9718.         *ranget="ranget",
  9719.         *xrange="xrange",
  9720.         *yrange="yrange",
  9721.         *rangex="rangex",
  9722.         *rangey="rangey",
  9723.         *path="path",
  9724.         *polyline="polyline",
  9725.         *brokenline="brokenline",
  9726.         *lines="lines",
  9727.         *poly="poly",
  9728.         *polygon="polygon",
  9729.         *fpolygon="fpolygon",
  9730.         *fpoly="fpoly",
  9731.         *filledpoly="filledpoly",
  9732.         *filledpolygon="filledpolygon",
  9733.         *rect="rect",
  9734.         *frect="frect",
  9735.         *rectangle="rectangle",
  9736.         *frectangle="frectangle",
  9737.         *square="square",
  9738.         *fsquare="fsquare",
  9739.         *fsquares="fsquares",
  9740.         *rects="rects",
  9741.         *frects="frects",
  9742.         *dline="dline",
  9743.         *arc="arc",
  9744.         *filledarc="filledarc",
  9745.         *farc="farc",
  9746.         *size="size",
  9747.         *string="string",
  9748.         *stringup="stringup",
  9749.         *copy="copy",
  9750.         *copyresized="copyresized",
  9751.         *opacity="opacity",
  9752.         *transparent="transparent",
  9753.         *fill="fill",
  9754.         *point="point",
  9755.         *points="points",
  9756.         *linewidth="linewidth",
  9757.         *circle="circle",
  9758.         *circles="circles",
  9759.         *fcircle="fcircle",
  9760.         *fcircles="fcircles",
  9761.         *disk="disk",
  9762.         *disks="disks",
  9763.         *comment="#",
  9764.         *end="end",
  9765.         *ellipse="ellipse",
  9766.         *ellipses="ellipses",
  9767.         *fellipse="fellipse",
  9768.         *rotate="rotate",
  9769.         *affine="affine",
  9770.         *rotationcenter="rotationcenter",
  9771.         *killrotate="killrotate",
  9772.         *killaffine="killaffine",
  9773.         *fontfamily="fontfamily",
  9774.         *fillcolor="fillcolor",
  9775.         *clicktile="clicktile",
  9776.         *clicktile_colors="clicktile_colors",
  9777.         *translation="translation",
  9778.         *translate="translate",
  9779.         *killtranslation="killtranslation",
  9780.         *killtranslate="killtranslate",
  9781.         *onclick="onclick",
  9782.         *roundrects="roundrects",
  9783.         *roundrect="roundrect",
  9784.         *froundrect="froundrect",
  9785.         *froundrects="froundrects",
  9786.         *roundrectangle="roundrectangle",
  9787.         *patternfill="patternfill",
  9788.         *hatchfill="hatchfill",
  9789.         *diafill="diafill",
  9790.         *diamondfill="diamondfill",
  9791.         *dotfill="dotfill",
  9792.         *textfill="textfill",
  9793.         *gridfill="gridfill",
  9794.         *imagefill="imagefill",
  9795.         *xlogbase="xlogbase",
  9796.         *ylogbase="ylogbase",
  9797.         *xlogscale="xlogscale",
  9798.         *ylogscale="ylogscale",
  9799.         *xylogscale="xylogscale",
  9800.         *intooltip="intooltip",
  9801.         *popup="popup",
  9802.         *replyformat="replyformat",
  9803.         *floodfill="floodfill",
  9804.         *fillall="fillall",
  9805.         *filltoborder="filltoborder",
  9806.         *setpixel="setpixel",
  9807.         *pixels="pixels",
  9808.         *pixelsize="pixelsize",
  9809.         *xaxis="xaxis",
  9810.         *xaxisup="xaxisup",
  9811.         *yaxis="yaxis",
  9812.         *xaxistext="xaxistext",
  9813.         *xaxistextup="xaxistextup",
  9814.         *yaxistext="yaxistext",
  9815.         *piechart="piechart",
  9816.         *boxplot="boxplot",
  9817.         *boxplotdata="boxplotdata",
  9818.         *userboxplot="userboxplot",
  9819.         *userboxplotdata="userboxplotdata",
  9820.         *legend="legend",
  9821.         *legendcolors="legendcolors",
  9822.         *xlabel="xlabel",
  9823.         *ylabel="ylabel",
  9824.         *barchart="barchart",
  9825.         *linegraph="linegraph",
  9826.         *clock="clock",
  9827.         *animate="animate",
  9828.         *video="video",
  9829.         *status="status",
  9830.         *nostatus="nostatus",
  9831.         *snaptogrid="snaptogrid",
  9832.         *xsnaptogrid="xsnaptogrid",
  9833.         *ysnaptogrid="ysnaptogrid",
  9834.         *snaptopoints="snaptopoints",
  9835.         *snaptofunction="snaptofunction",
  9836.         *snaptofun="snaptofun",
  9837.         *userinput_xy="userinput_xy",
  9838.         *userinput_function="userinput_function",
  9839.         *usertextarea_xy="usertextarea_xy",
  9840.         *userinput="userinput",
  9841.         *jsmath="jsmath",
  9842.         *trace_jscurve="trace_jscurve",
  9843.         *setlimits="setlimits",
  9844.         *jscurve="jscurve",
  9845.         *jsplot="jsplot",
  9846.         *sgraph="sgraph",
  9847.         *title="title",
  9848.         *centerstring="centerstring",
  9849.         *xunit="xunit",
  9850.         *yunit="yunit",
  9851.         *slider="slider",
  9852.         *killslider="killslider",
  9853.         *angle="angle",
  9854.         *halflines="halflines",
  9855.         *demilines="demilines",
  9856.         *halfline="halfline",
  9857.         *demiline="demiline",
  9858.         *hlines="hlines",
  9859.         *vlines="vlines",
  9860.         *bezier="bezier",
  9861.         *functionlabel="functionlabel",
  9862.         *sliderfunction_x="sliderfunction_x",
  9863.         *sliderfunction_y="sliderfunction_y",
  9864.         *multidraw="multidraw",
  9865.         *multilinewidth="multilinewidth",
  9866.         *multistrokecolors="multistrokecolors",
  9867.         *multifillcolors="multifillcolors",
  9868.         *multistrokeopacity="multistrokeopacity",
  9869.         *multifillopacity="multifillopacity",
  9870.         *multifill="multifill",
  9871.         *multidash="multidash",
  9872.         *multilabel="multilabel",
  9873.         *multiuserinput="multiuserinput",
  9874.         *multiinput="multiinput",
  9875.         *multisnaptogrid="multisnaptogrid",
  9876.         *multisnap="multisnap",
  9877.         *protractor="protractor",
  9878.         *ruler="ruler",
  9879.         *cursor="cursor",
  9880.         *pointer="pointer",
  9881.         *yerrorbars="yerrorbars",
  9882.         *xerrorbars="xerrorbars",
  9883.         *noxaxis="noxaxis",
  9884.         *noyaxis="noyaxis",
  9885.         *colorpalette="colorpalette",
  9886.         *imagepalette="imagepalette",
  9887.         *yoffset="yoffset",
  9888.         *xoffset="xoffset",
  9889.         *latex="latex",
  9890.         *centered="centered",
  9891.         *xyoffset="xyoffset",
  9892.         *resetoffset="resetoffset",
  9893.         *fillpattern="fillpattern",
  9894.         *numberline="numberline",
  9895.         *duplicates="duplicates",
  9896.         *allowdups="allowdups",
  9897.         *canvastype="canvastype";
  9898.  
  9899.         while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){
  9900.          if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */
  9901.          }else{
  9902.           if( c == ' ' ){
  9903.             break;
  9904.           }else{
  9905.            temp[i] = c;
  9906.            if(i > MAX_INT - 2){canvas_error("command string too long !");}
  9907.            i++;
  9908.           }
  9909.          }
  9910.          if(temp[0] == '#'){ break; }
  9911.         }
  9912.         if (c == '\n' || c == '\r' || c == '\t' ){  line_number++; }
  9913.         if (c == EOF) {finished=1;return 0;}
  9914.  
  9915.         temp[i]='\0';
  9916.         input_type=(char*)my_newmem(strlen(temp));
  9917.         snprintf(input_type,sizeof(temp),"%s",temp);
  9918. /* fprintf(stdout,"temp = %s <br/>",input_type); */
  9919.         if( strcmp(input_type, size) == 0 ){
  9920.         free(input_type);
  9921.         return SIZE;
  9922.         }
  9923.         if( strcmp(input_type, xrange) == 0 ){
  9924.         free(input_type);
  9925.         return XRANGE;
  9926.         }
  9927.         if( strcmp(input_type, rangex) == 0 ){
  9928.         free(input_type);
  9929.         return XRANGE;
  9930.         }
  9931.         if( strcmp(input_type, trange) == 0 ){
  9932.         free(input_type);
  9933.         return TRANGE;
  9934.         }
  9935.         if( strcmp(input_type, ranget) == 0 ){
  9936.         free(input_type);
  9937.         return TRANGE;
  9938.         }
  9939.         if( strcmp(input_type, yrange) == 0 ){
  9940.         free(input_type);
  9941.         return YRANGE;
  9942.         }
  9943.         if( strcmp(input_type, rangey) == 0 ){
  9944.         free(input_type);
  9945.         return YRANGE;
  9946.         }
  9947.         if( strcmp(input_type, linewidth) == 0 ){
  9948.         free(input_type);
  9949.         return LINEWIDTH;
  9950.         }
  9951.         if( strcmp(input_type, dashed) == 0 ){
  9952.         free(input_type);
  9953.         return DASHED;
  9954.         }
  9955.         if( strcmp(input_type, dashtype) == 0 ){
  9956.         free(input_type);
  9957.         return DASHTYPE;
  9958.         }
  9959.         if( strcmp(input_type, axisnumbering) == 0 ){
  9960.         free(input_type);
  9961.         return AXIS_NUMBERING;
  9962.         }
  9963.         if( strcmp(input_type, axisnumbers) == 0 ){
  9964.         free(input_type);
  9965.         return AXIS_NUMBERING;
  9966.         }
  9967.         if( strcmp(input_type, axis) == 0 ){
  9968.         free(input_type);
  9969.         return AXIS;
  9970.         }
  9971.         if( strcmp(input_type, grid) == 0 ){
  9972.         free(input_type);
  9973.         return GRID;
  9974.         }
  9975.         if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){
  9976.         free(input_type);
  9977.         return HLINES;
  9978.         }
  9979.         if( strcmp(input_type, vlines) == 0 ||  strcmp(input_type, verticallines) == 0 ){
  9980.         free(input_type);
  9981.         return VLINES;
  9982.         }
  9983.         if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){
  9984.         free(input_type);
  9985.         return HLINE;
  9986.         }
  9987.         if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
  9988.         free(input_type);
  9989.         return VLINE;
  9990.         }
  9991.         if( strcmp(input_type, line) == 0 ){
  9992.         free(input_type);
  9993.         return LINE;
  9994.         }
  9995.         if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){
  9996.         free(input_type);
  9997.         return SEGMENTS;
  9998.         }
  9999.         if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
  10000.         free(input_type);
  10001.         return SEGMENT;
  10002.         }
  10003.         if( strcmp(input_type, dsegments) == 0 ){
  10004.         free(input_type);
  10005.         use_dashed = TRUE;
  10006.         return SEGMENTS;
  10007.         }
  10008.         if( strcmp(input_type, dsegment) == 0 ){
  10009.         free(input_type);
  10010.         use_dashed = TRUE;
  10011.         return SEGMENT;
  10012.         }
  10013.         if( strcmp(input_type, crosshairsize) == 0 ){
  10014.         free(input_type);
  10015.         return CROSSHAIRSIZE;
  10016.         }
  10017.         if( strcmp(input_type, arrowhead) == 0 ){
  10018.         free(input_type);
  10019.         return ARROWHEAD;
  10020.         }
  10021.         if( strcmp(input_type, crosshairs) == 0 ){
  10022.         free(input_type);
  10023.         return CROSSHAIRS;
  10024.         }
  10025.         if( strcmp(input_type, crosshair) == 0 ){
  10026.         free(input_type);
  10027.         return CROSSHAIR;
  10028.         }
  10029.         if( strcmp(input_type, onclick) == 0 ){
  10030.         free(input_type);
  10031.         return ONCLICK;
  10032.         }
  10033.         if( strcmp(input_type, drag) == 0 ){
  10034.         free(input_type);
  10035.         return DRAG;
  10036.         }
  10037.         if( strcmp(input_type, userdraw) == 0 ){
  10038.         free(input_type);
  10039.         return USERDRAW;
  10040.         }
  10041.         if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
  10042.         free(input_type);
  10043.         return STYLE;
  10044.         }
  10045.         if( strcmp(input_type, fillcolor) == 0 ){
  10046.         free(input_type);
  10047.         return FILLCOLOR;
  10048.         }
  10049.         if( strcmp(input_type, strokecolor) == 0 ){
  10050.         free(input_type);
  10051.         return STROKECOLOR;
  10052.         }
  10053.         if( strcmp(input_type, filled) == 0  ){
  10054.         free(input_type);
  10055.         return FILLED;
  10056.         }
  10057.         if( strcmp(input_type, http) == 0 ){
  10058.         free(input_type);
  10059.         return HTTP;
  10060.         }
  10061.         if( strcmp(input_type, rays) == 0 ){
  10062.         free(input_type);
  10063.         return RAYS;
  10064.         }
  10065.         if( strcmp(input_type, lattice) == 0 ){
  10066.         free(input_type);
  10067.         return LATTICE;
  10068.         }
  10069.         if( strcmp(input_type, bgimage) == 0 ){
  10070.         free(input_type);
  10071.         return BGIMAGE;
  10072.         }
  10073.         if( strcmp(input_type, bgcolor) == 0 ){
  10074.         free(input_type);
  10075.         return BGCOLOR;
  10076.         }
  10077.         if( strcmp(input_type, backgroundimage) == 0 ){
  10078.         free(input_type);
  10079.         return BGIMAGE;
  10080.         }
  10081.         if( strcmp(input_type, text) == 0 ){
  10082.         free(input_type);
  10083.         return FLY_TEXT;
  10084.         }
  10085.         if( strcmp(input_type, textup) == 0 ){
  10086.         free(input_type);
  10087.         return FLY_TEXTUP;
  10088.         }
  10089.         if( strcmp(input_type, mouse) == 0 ){
  10090.         free(input_type);
  10091.         return MOUSE;
  10092.         }
  10093.         if( strcmp(input_type, mousex) == 0 ){
  10094.         free(input_type);
  10095.         return MOUSEX;
  10096.         }
  10097.         if( strcmp(input_type, mousey) == 0 ){
  10098.         free(input_type);
  10099.         return MOUSEY;
  10100.         }
  10101.         if( strcmp(input_type, mouse_degree) == 0 ){
  10102.         free(input_type);
  10103.         return MOUSE_DEGREE;
  10104.         }
  10105.         if( strcmp(input_type, mouse_display) == 0 ){
  10106.         free(input_type);
  10107.         return MOUSE_DISPLAY;
  10108.         }
  10109.         if( strcmp(input_type, mouseprecision) == 0 ){
  10110.         free(input_type);
  10111.         return MOUSE_PRECISION;
  10112.         }
  10113.         if( strcmp(input_type, precision) == 0 ){
  10114.         free(input_type);
  10115.         return MOUSE_PRECISION;
  10116.         }
  10117.         if( strcmp(input_type, curve) == 0 ){
  10118.         free(input_type);
  10119.         return CURVE;
  10120.         }
  10121.         if( strcmp(input_type, dcurve) == 0 ){
  10122.         use_dashed = TRUE;
  10123.         free(input_type);
  10124.         return CURVE;
  10125.         }
  10126.         if( strcmp(input_type, plot) == 0 ){
  10127.         free(input_type);
  10128.         return CURVE;
  10129.         }
  10130.         if( strcmp(input_type, dplot) == 0 ){
  10131.         use_dashed = TRUE;
  10132.         free(input_type);
  10133.         return CURVE;
  10134.         }
  10135.         if( strcmp(input_type, levelcurve) == 0 ){
  10136.         free(input_type);
  10137.         return LEVELCURVE;
  10138.         }
  10139.         if( strcmp(input_type, plotsteps) == 0 ){
  10140.         free(input_type);
  10141.         return PLOTSTEPS;
  10142.         }
  10143.         if( strcmp(input_type, plotstep) == 0 ){
  10144.         free(input_type);
  10145.         return PLOTSTEPS;
  10146.         }
  10147.         if( strcmp(input_type, tsteps) == 0 ){
  10148.         free(input_type);
  10149.         return PLOTSTEPS;
  10150.         }
  10151.         if( strcmp(input_type, fontsize) == 0 ){
  10152.         free(input_type);
  10153.         return FONTSIZE;
  10154.         }
  10155.         if( strcmp(input_type, fontcolor) == 0 ){
  10156.         free(input_type);
  10157.         return FONTCOLOR;
  10158.         }
  10159.         if( strcmp(input_type, arrow2) == 0 ){
  10160.         free(input_type);
  10161.         return ARROW2;
  10162.         }
  10163.         if( strcmp(input_type, darrow) == 0 ){
  10164.         free(input_type);
  10165.         use_dashed = TRUE;
  10166.         return ARROW;
  10167.         }
  10168.         if( strcmp(input_type, darrow2) == 0 ){
  10169.         free(input_type);
  10170.         use_dashed = TRUE;
  10171.         return ARROW2;
  10172.         }
  10173.         if( strcmp(input_type, arrows2) == 0 ){
  10174.         free(input_type);
  10175.         return ARROWS2;
  10176.         }
  10177.         if( strcmp(input_type, arrows) == 0  || strcmp(input_type, vectors) == 0 ){
  10178.         free(input_type);
  10179.         return ARROWS;
  10180.         }
  10181.         if( strcmp(input_type, arrow) == 0 ||  strcmp(input_type, vector) == 0 ){
  10182.         free(input_type);
  10183.         return ARROW;
  10184.         }
  10185.         if( strcmp(input_type, zoom) == 0 ){
  10186.         free(input_type);
  10187.         return ZOOM;
  10188.         }
  10189.         if( strcmp(input_type, triangle) == 0 ){
  10190.         free(input_type);
  10191.         return TRIANGLE;
  10192.         }
  10193.         if( strcmp(input_type, triangles) == 0 ){
  10194.         free(input_type);
  10195.         return TRIANGLES;
  10196.         }
  10197.         if( strcmp(input_type, ftriangles) == 0 ){
  10198.         free(input_type);
  10199.         use_filled = TRUE;
  10200.         return TRIANGLES;
  10201.         }
  10202.         if( strcmp(input_type, ftriangle) == 0 ){
  10203.         free(input_type);
  10204.         use_filled = TRUE;
  10205.         return TRIANGLE;
  10206.         }
  10207.         if( strcmp(input_type, input) == 0 ){
  10208.         free(input_type);
  10209.         return INPUT;
  10210.         }
  10211.         if( strcmp(input_type, inputstyle) == 0 ){
  10212.         free(input_type);
  10213.         return INPUTSTYLE;
  10214.         }
  10215.         if( strcmp(input_type, textarea) == 0 ){
  10216.         free(input_type);
  10217.         return TEXTAREA;
  10218.         }
  10219.         if( strcmp(input_type, mathml) == 0 ){
  10220.         free(input_type);
  10221.         return MATHML;
  10222.         }
  10223.         if( strcmp(input_type, html) == 0 ){
  10224.         free(input_type);
  10225.         return MATHML;
  10226.         }
  10227.         if( strcmp(input_type, fontfamily) == 0 ){
  10228.         free(input_type);
  10229.         return FONTFAMILY;
  10230.         }
  10231.         if( strcmp(input_type, polyline) == 0 ||  strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){
  10232.         free(input_type);
  10233.         return POLYLINE;
  10234.         }
  10235.         if( strcmp(input_type, lines) == 0 ){
  10236.         free(input_type);
  10237.         return LINES;
  10238.         }
  10239.         if( strcmp(input_type, rects) == 0){
  10240.         free(input_type);
  10241.         return RECTS;
  10242.         }
  10243.         if( strcmp(input_type, frects) == 0 ){
  10244.         free(input_type);
  10245.         use_filled = TRUE;
  10246.         return RECTS;
  10247.         }
  10248.         if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
  10249.         free(input_type);
  10250.         return RECT;
  10251.         }
  10252.         if( strcmp(input_type, square) == 0 ){
  10253.         free(input_type);
  10254.         return SQUARE;
  10255.         }
  10256.         if( strcmp(input_type, fsquare) == 0 ){
  10257.         free(input_type);
  10258.         use_filled = TRUE;
  10259.         return SQUARE;
  10260.         }
  10261.         if( strcmp(input_type, fsquares) == 0 ){
  10262.         free(input_type);
  10263.         use_filled = TRUE;
  10264.         return RECTS;
  10265.         }
  10266.         if( strcmp(input_type, roundrects) == 0 ){
  10267.         free(input_type);
  10268.         return ROUNDRECTS;
  10269.         }
  10270.         if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
  10271.         free(input_type);
  10272.         return ROUNDRECT;
  10273.         }
  10274.         if( strcmp(input_type, froundrects) == 0 ){
  10275.         free(input_type);
  10276.         use_filled = TRUE;
  10277.         return ROUNDRECTS;
  10278.         }
  10279.         if( strcmp(input_type, froundrect) == 0 ){
  10280.         free(input_type);
  10281.         use_filled = TRUE;
  10282.         return ROUNDRECT;
  10283.         }
  10284.         if( strcmp(input_type, dline) == 0 ){
  10285.         use_dashed = TRUE;
  10286.         free(input_type);
  10287.         return LINE;
  10288.         }
  10289.         if( strcmp(input_type, dvline) == 0 ){
  10290.         use_dashed = TRUE;
  10291.         free(input_type);
  10292.         return VLINE;
  10293.         }
  10294.         if( strcmp(input_type, dhline) == 0 ){
  10295.         use_dashed = TRUE;
  10296.         free(input_type);
  10297.         return HLINE;
  10298.         }
  10299.         if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0  ){
  10300.         free(input_type);
  10301.         return HALFLINES;
  10302.         }
  10303.         if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0  ){
  10304.         free(input_type);
  10305.         return HALFLINE;
  10306.         }
  10307.         if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
  10308.         use_filled = TRUE;
  10309.         free(input_type);
  10310.         return RECT;
  10311.         }
  10312.         if( strcmp(input_type, circles) == 0 ){
  10313.         free(input_type);
  10314.         return CIRCLES;
  10315.         }
  10316.         if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
  10317.         use_filled = TRUE;
  10318.         free(input_type);
  10319.         return CIRCLE;
  10320.         }
  10321.         if( strcmp(input_type, fcircles) == 0  ||  strcmp(input_type, disks) == 0 ){
  10322.         use_filled = TRUE;
  10323.         free(input_type);
  10324.         return CIRCLES;
  10325.         }
  10326.         if( strcmp(input_type, circle) == 0 ){
  10327.         free(input_type);
  10328.         return CIRCLE;
  10329.         }
  10330.         if( strcmp(input_type, point) == 0 ){
  10331.         free(input_type);
  10332.         return POINT;
  10333.         }
  10334.         if( strcmp(input_type, points) == 0 ){
  10335.         free(input_type);
  10336.         return POINTS;
  10337.         }
  10338.         if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){
  10339.         use_filled = TRUE;
  10340.         free(input_type);
  10341.         return ARC;
  10342.         }
  10343.         if( strcmp(input_type, arc) == 0 ){
  10344.         free(input_type);
  10345.         return ARC;
  10346.         }
  10347.         if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
  10348.         free(input_type);
  10349.         return POLY;
  10350.         }
  10351.         if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
  10352.         use_filled = TRUE;
  10353.         free(input_type);
  10354.         return POLY;
  10355.         }
  10356.         if( strcmp(input_type, ellipse) == 0){
  10357.         free(input_type);
  10358.         return ELLIPSE;
  10359.         }
  10360.         if( strcmp(input_type, ellipses) == 0){
  10361.         free(input_type);
  10362.         return ELLIPSES;
  10363.         }
  10364.         if( strcmp(input_type, string) == 0 ){
  10365.         free(input_type);
  10366.         return STRING;
  10367.         }
  10368.         if( strcmp(input_type, stringup) == 0 ){
  10369.         free(input_type);
  10370.         return STRINGUP;
  10371.         }
  10372.         if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){
  10373.         free(input_type);
  10374.         return OPACITY;
  10375.         }
  10376.         if( strcmp(input_type, comment) == 0){
  10377.         free(input_type);
  10378.         return COMMENT;
  10379.         }
  10380.         if( strcmp(input_type, fellipse) == 0){
  10381.         free(input_type);
  10382.         use_filled = TRUE;
  10383.         return ELLIPSE;
  10384.         }
  10385.         if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){
  10386.         free(input_type);
  10387.         return CLEARBUTTON;
  10388.         }
  10389.         if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
  10390.         free(input_type);
  10391.         return TRANSLATION;
  10392.         }
  10393.         if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
  10394.         free(input_type);
  10395.         return KILLTRANSLATION;
  10396.         }
  10397.         if( strcmp(input_type, rotate) == 0){
  10398.         free(input_type);
  10399.         return ROTATE;
  10400.         }
  10401.         if( strcmp(input_type, killrotate) == 0){
  10402.         free(input_type);
  10403.         return KILLROTATE;
  10404.         }
  10405.         if( strcmp(input_type, rotationcenter) == 0){
  10406.         free(input_type);
  10407.         return ROTATION_CENTER;
  10408.         }
  10409.         if( strcmp(input_type, affine) == 0){
  10410.         free(input_type);
  10411.         return AFFINE;
  10412.         }
  10413.         if( strcmp(input_type, killaffine) == 0){
  10414.         free(input_type);
  10415.         return KILLAFFINE;
  10416.         }
  10417.         if( strcmp(input_type, slider) == 0 ){
  10418.         free(input_type);
  10419.         return SLIDER;
  10420.         }
  10421.         if( strcmp(input_type, killslider) == 0 ){
  10422.         free(input_type);
  10423.         return KILLSLIDER;
  10424.         }
  10425.         if( strcmp(input_type, copy) == 0 ){
  10426.         free(input_type);
  10427.         return COPY;
  10428.         }
  10429.         if( strcmp(input_type, copyresized) == 0 ){
  10430.         free(input_type);
  10431.         return COPYRESIZED;
  10432.         }
  10433.         if( strcmp(input_type, xlogscale) == 0 ){
  10434.         free(input_type);
  10435.         return XLOGSCALE;
  10436.         }
  10437.         if( strcmp(input_type, ylogscale) == 0 ){
  10438.         free(input_type);
  10439.         return YLOGSCALE;
  10440.         }
  10441.         if( strcmp(input_type, xylogscale) == 0 ){
  10442.         free(input_type);
  10443.         return XYLOGSCALE;
  10444.         }
  10445.         if( strcmp(input_type, ylogscale) == 0 ){
  10446.         free(input_type);
  10447.         return YLOGSCALE;
  10448.         }
  10449.         if( strcmp(input_type, xlogbase) == 0 ){
  10450.         free(input_type);
  10451.         return XLOGBASE;
  10452.         }
  10453.         if( strcmp(input_type, ylogbase) == 0 ){
  10454.         free(input_type);
  10455.         return YLOGBASE;
  10456.         }
  10457.         if( strcmp(input_type, intooltip) == 0 ){
  10458.         free(input_type);
  10459.         return INTOOLTIP;
  10460.         }
  10461.         if( strcmp(input_type, popup) == 0 ){
  10462.         free(input_type);
  10463.         return POPUP;
  10464.         }
  10465.         if( strcmp(input_type,video) == 0 ){
  10466.         free(input_type);
  10467.         return VIDEO;
  10468.         }
  10469.         if( strcmp(input_type,latex) == 0 ){
  10470.         free(input_type);
  10471.         return LATEX;
  10472.         }
  10473.         if( strcmp(input_type,fillall) == 0 ){
  10474.         free(input_type);
  10475.         return FILLALL;
  10476.         }
  10477.         if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
  10478.         free(input_type);
  10479.         return FLOODFILL;
  10480.         }
  10481.         if( strcmp(input_type,filltoborder) == 0 ){
  10482.         free(input_type);
  10483.         return FILLTOBORDER;
  10484.         }
  10485.         if( strcmp(input_type, curvedarrow2) == 0 ){
  10486.         free(input_type);
  10487.         return CURVEDARROW2;
  10488.         }
  10489.         if( strcmp(input_type, curvedarrow) == 0 ){
  10490.         free(input_type);
  10491.         return CURVEDARROW;
  10492.         }
  10493.         if( strcmp(input_type, curvedarrows) == 0 ){
  10494.         free(input_type);
  10495.         return CURVEDARROWS;
  10496.         }
  10497.         if( strcmp(input_type, curvedarrows2) == 0 ){
  10498.         free(input_type);
  10499.         return CURVEDARROWS2;
  10500.         }
  10501.         if( strcmp(input_type, replyformat) == 0 ){
  10502.         free(input_type);
  10503.         return REPLYFORMAT;
  10504.         }
  10505.         if( strcmp(input_type, pixelsize) == 0 ){
  10506.         free(input_type);
  10507.         return PIXELSIZE;
  10508.         }
  10509.         if( strcmp(input_type, setpixel) == 0 ){
  10510.         free(input_type);
  10511.         return SETPIXEL;
  10512.         }
  10513.         if( strcmp(input_type, pixels) == 0 ){
  10514.         free(input_type);
  10515.         return PIXELS;
  10516.         }
  10517.         if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
  10518.         free(input_type);
  10519.         return X_AXIS_STRINGS;
  10520.         }
  10521.         if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){
  10522.         free(input_type);
  10523.         return X_AXIS_STRINGS_UP;
  10524.         }
  10525.         if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
  10526.         free(input_type);
  10527.         return Y_AXIS_STRINGS;
  10528.         }
  10529.         if( strcmp(input_type, legend) == 0  ){
  10530.         free(input_type);
  10531.         return LEGEND;
  10532.         }
  10533.         if( strcmp(input_type, legendcolors) == 0  ){
  10534.         free(input_type);
  10535.         return LEGENDCOLORS;
  10536.         }
  10537.         if( strcmp(input_type, xlabel) == 0  ){
  10538.         free(input_type);
  10539.         return XLABEL;
  10540.         }
  10541.         if( strcmp(input_type, ylabel) == 0  ){
  10542.         free(input_type);
  10543.         return YLABEL;
  10544.         }
  10545.         if( strcmp(input_type, bezier) == 0  ){
  10546.         free(input_type);
  10547.         return BEZIER;
  10548.         }
  10549.         if( strcmp(input_type, animate) == 0  ){
  10550.         free(input_type);
  10551.         return ANIMATE;
  10552.         }
  10553.         /* these are bitmap related flydraw commands...must be removed. eventually */
  10554.         if( strcmp(input_type, transparent) == 0 ){
  10555.         free(input_type);
  10556.         return TRANSPARENT;
  10557.         }
  10558.         if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
  10559.         free(input_type);
  10560.         return STATUS;
  10561.         }
  10562.         if( strcmp(input_type, xsnaptogrid) == 0 ){
  10563.         free(input_type);
  10564.         return XSNAPTOGRID;
  10565.         }
  10566.         if( strcmp(input_type, ysnaptogrid) == 0 ){
  10567.         free(input_type);
  10568.         return YSNAPTOGRID;
  10569.         }
  10570.         if( strcmp(input_type, snaptogrid) == 0 ){
  10571.         free(input_type);
  10572.         return SNAPTOGRID;
  10573.         }
  10574.         if( strcmp(input_type, snaptopoints) == 0 ){
  10575.         free(input_type);
  10576.         return SNAPTOPOINTS;
  10577.         }
  10578.         if( strcmp(input_type, snaptofunction) == 0  || strcmp(input_type, snaptofun) == 0 ){
  10579.         free(input_type);
  10580.         return SNAPTOFUNCTION;
  10581.         }
  10582.         if( strcmp(input_type, userinput_xy) == 0 ){
  10583.         free(input_type);
  10584.         return USERINPUT_XY;
  10585.         }
  10586.         if( strcmp(input_type, userinput_function) == 0 ){
  10587.         free(input_type);
  10588.         return USERINPUT_FUNCTION;
  10589.         }
  10590.         if( strcmp(input_type, usertextarea_xy) == 0 ){
  10591.         free(input_type);
  10592.         return USERTEXTAREA_XY;
  10593.         }
  10594.         if( strcmp(input_type, userinput) == 0 ){
  10595.         free(input_type);
  10596.         return USERINPUT;
  10597.         }
  10598.         if( strcmp(input_type, angle) == 0 ){
  10599.         free(input_type);
  10600.         return ANGLE;
  10601.         }
  10602.         if( strcmp(input_type, functionlabel) == 0 ){
  10603.         free(input_type);
  10604.         return FUNCTION_LABEL;
  10605.         }
  10606.         if( strcmp(input_type, sliderfunction_x) == 0 ){
  10607.         free(input_type);
  10608.         return SLIDER_X;
  10609.         }
  10610.         if( strcmp(input_type, sliderfunction_y) == 0 ){
  10611.         free(input_type);
  10612.         return SLIDER_Y;
  10613.         }
  10614.         if( strcmp(input_type, multidraw) == 0 ){
  10615.         free(input_type);
  10616.         return MULTIDRAW;
  10617.         }
  10618.         if( strcmp(input_type, multistrokeopacity) == 0 ){
  10619.         free(input_type);
  10620.         return MULTISTROKEOPACITY;
  10621.         }
  10622.         if( strcmp(input_type, multifillopacity) == 0 ){
  10623.         free(input_type);
  10624.         return MULTIFILLOPACITY;
  10625.         }
  10626.         if( strcmp(input_type, multilinewidth) == 0 ){
  10627.         free(input_type);
  10628.         return MULTILINEWIDTH;
  10629.         }
  10630.         if( strcmp(input_type, multistrokecolors) == 0 ){
  10631.         free(input_type);
  10632.         return MULTISTROKECOLORS;
  10633.         }
  10634.         if( strcmp(input_type, multifill) == 0 ){
  10635.         free(input_type);
  10636.         return MULTIFILL;
  10637.         }
  10638.         if( strcmp(input_type, multifillcolors) == 0 ){
  10639.         free(input_type);
  10640.         return MULTIFILLCOLORS;
  10641.         }
  10642.         if( strcmp(input_type, multilabel) == 0 ){
  10643.         free(input_type);
  10644.         return MULTILABEL;
  10645.         }
  10646.         if( strcmp(input_type, multidash) == 0 ){
  10647.         free(input_type);
  10648.         return MULTIDASH;
  10649.         }
  10650.         if( strcmp(input_type, multisnaptogrid) == 0  ||  strcmp(input_type, multisnap) == 0 ){
  10651.         free(input_type);
  10652.         return MULTISNAPTOGRID;
  10653.         }
  10654.         if( strcmp(input_type, multiuserinput) == 0 || strcmp(input_type, multiinput) == 0  ){
  10655.         free(input_type);
  10656.         return MULTIUSERINPUT;
  10657.         }
  10658.         if( strcmp(input_type, parallel) == 0 ){
  10659.         free(input_type);
  10660.         return PARALLEL;
  10661.         }
  10662.         if( strcmp(input_type, protractor) == 0 ){
  10663.         free(input_type);
  10664.         return PROTRACTOR;
  10665.         }
  10666.         if( strcmp(input_type, ruler) == 0 ){
  10667.         free(input_type);
  10668.         return RULER;
  10669.         }
  10670.         if( strcmp(input_type, cursor) == 0 ||  strcmp(input_type, pointer) == 0 ){
  10671.         free(input_type);
  10672.         return CURSOR;
  10673.         }
  10674.         if( strcmp(input_type, sgraph) == 0 ){
  10675.         free(input_type);
  10676.         return SGRAPH;
  10677.         }
  10678.         if( strcmp(input_type, jsmath) == 0 ){
  10679.         free(input_type);
  10680.         return JSMATH;
  10681.         }
  10682.         if( strcmp(input_type, trace_jscurve) == 0 ){
  10683.         free(input_type);
  10684.         return TRACE_JSCURVE;
  10685.         }
  10686.         if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
  10687.         free(input_type);
  10688.         return JSCURVE;
  10689.         }
  10690.         if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
  10691.         free(input_type);
  10692.         return CENTERSTRING;
  10693.         }
  10694.         if( strcmp(input_type, setlimits) == 0 ){
  10695.         free(input_type);
  10696.         return SETLIMITS;
  10697.         }
  10698.         if( strcmp(input_type, xunit) == 0 ){
  10699.         free(input_type);
  10700.         return XUNIT;
  10701.         }
  10702.         if( strcmp(input_type, yunit) == 0 ){
  10703.         free(input_type);
  10704.         return YUNIT;
  10705.         }
  10706.         if( strcmp(input_type, fill) == 0 ){
  10707.         free(input_type);
  10708.         return FLOODFILL;
  10709.         }
  10710.         if( strcmp(input_type, end) == 0){
  10711.         free(input_type);
  10712.         return END;
  10713.         }
  10714.         if( strcmp(input_type, blink) == 0 ){
  10715.         free(input_type);
  10716.         return BLINK;
  10717.         }
  10718.         if( strcmp(input_type, audio) == 0 ){
  10719.         free(input_type);
  10720.         return AUDIO;
  10721.         }
  10722.         if( strcmp(input_type, audioobject) == 0 ){
  10723.         free(input_type);
  10724.         return AUDIOOBJECT;
  10725.         }
  10726.         if( strcmp(input_type, patternfill) == 0 ){
  10727.         free(input_type);
  10728.         return PATTERNFILL;
  10729.         }
  10730.         if( strcmp(input_type, hatchfill) == 0 ){
  10731.         free(input_type);
  10732.         return HATCHFILL;
  10733.         }
  10734.         if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
  10735.         free(input_type);
  10736.         return DIAMONDFILL;
  10737.         }
  10738.         if( strcmp(input_type, dotfill) == 0 ){
  10739.         free(input_type);
  10740.         return DOTFILL;
  10741.         }
  10742.         if( strcmp(input_type, textfill) == 0 ){
  10743.         free(input_type);
  10744.         return TEXTFILL;
  10745.         }
  10746.         if( strcmp(input_type, gridfill) == 0 ){
  10747.         free(input_type);
  10748.         return GRIDFILL;
  10749.         }
  10750.         if( strcmp(input_type, imagefill) == 0 ){
  10751.         free(input_type);
  10752.         return IMAGEFILL;
  10753.         }
  10754.         if( strcmp(input_type, clicktile_colors) == 0 ){
  10755.         free(input_type);
  10756.         return CLICKTILE_COLORS;
  10757.         }
  10758.         if( strcmp(input_type, clicktile) == 0 ){
  10759.         free(input_type);
  10760.         return CLICKTILE;
  10761.         }
  10762.         if( strcmp(input_type, piechart) == 0  ){
  10763.         free(input_type);
  10764.         return PIECHART;
  10765.         }
  10766.         if( strcmp(input_type, boxplot) == 0  ){
  10767.         free(input_type);
  10768.         return BOXPLOT;
  10769.         }
  10770.         if( strcmp(input_type, boxplotdata) == 0  ){
  10771.         free(input_type);
  10772.         return BOXPLOTDATA;
  10773.         }
  10774.         if( strcmp(input_type, userboxplot) == 0  ){
  10775.         free(input_type);
  10776.         return USERBOXPLOT;
  10777.         }
  10778.         if( strcmp(input_type, userboxplotdata) == 0  ){
  10779.         free(input_type);
  10780.         return USERBOXPLOT;
  10781.         }
  10782.         if( strcmp(input_type, barchart) == 0  ){
  10783.         free(input_type);
  10784.         return BARCHART;
  10785.         }
  10786.         if( strcmp(input_type, linegraph) == 0  ){
  10787.         free(input_type);
  10788.         return LINEGRAPH;
  10789.         }
  10790.         if( strcmp(input_type, clock) == 0  ){
  10791.         free(input_type);
  10792.         return CLOCK;
  10793.         }
  10794.         if( strcmp(input_type, yerrorbars) == 0  ){
  10795.         free(input_type);
  10796.         return YERRORBARS;
  10797.         }
  10798.         if( strcmp(input_type, xerrorbars) == 0  ){
  10799.         free(input_type);
  10800.         return XERRORBARS;
  10801.         }
  10802.         if( strcmp(input_type, canvastype) == 0  ){
  10803.         free(input_type);
  10804.         return CANVASTYPE;
  10805.         }
  10806.         if( strcmp(input_type, noyaxis) == 0  ){
  10807.         free(input_type);
  10808.         return NOYAXIS;
  10809.         }
  10810.         if( strcmp(input_type, noxaxis) == 0  ){
  10811.         free(input_type);
  10812.         return NOXAXIS;
  10813.         }
  10814.         if( strcmp(input_type, colorpalette) == 0  ){
  10815.         free(input_type);
  10816.         return COLORPALETTE;
  10817.         }
  10818.         if( strcmp(input_type, imagepalette) == 0  ){
  10819.         free(input_type);
  10820.         return IMAGEPALETTE;
  10821.         }
  10822.         if( strcmp(input_type, resetoffset) == 0  ){
  10823.         free(input_type);
  10824.         return RESETOFFSET;
  10825.         }
  10826.         if( strcmp(input_type, xyoffset) == 0  ){
  10827.         free(input_type);
  10828.         return XYOFFSET;
  10829.         }
  10830.         if( strcmp(input_type, centered) == 0 ){
  10831.         free(input_type);
  10832.         return CENTERED;
  10833.         }
  10834.         if( strcmp(input_type, yoffset) == 0   ){
  10835.         free(input_type);
  10836.         return YOFFSET;
  10837.         }
  10838.         if( strcmp(input_type, xoffset) == 0   ){
  10839.         free(input_type);
  10840.         return XOFFSET;
  10841.         }
  10842.         if( strcmp(input_type, fillpattern) == 0 ){
  10843.         free(input_type);
  10844.         return FILLPATTERN;
  10845.         }
  10846.         if( strcmp(input_type, numberline) == 0 ){
  10847.         free(input_type);
  10848.         return NUMBERLINE;
  10849.         }
  10850.         if( strcmp(input_type, duplicates) == 0 || strcmp(input_type, allowdups) == 0 ){
  10851.         free(input_type);
  10852.         return ALLOW_DUPLICATES;
  10853.         }
  10854.         free(input_type);
  10855.         ungetc(c,infile);
  10856.         return 0;
  10857. }
  10858.  
  10859.  
  10860.  
  10861.  
  10862.  
  10863.  
  10864.  
  10865.  
  10866.  
  10867.  
  10868.  
  10869.  
  10870.  
  10871.  
  10872.