Subversion Repositories wimsdev

Rev

Rev 14840 | Rev 14951 | 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 warranty 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 print_dragdrop_reply_only_once = FALSE;/* avoid multiple useless identical lines to be printed */
  93.     int include_special_OEF_reply = FALSE; /* used for including extra read_canvas_images();*/
  94.     int line_width = 1;
  95.     int decimals = 2;
  96.     int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */
  97.     int use_userdraw = FALSE; /* flag to indicate user interaction */
  98.     int drag_type = -1;/* 0,1,2: xy,x,y */
  99.     int use_tooltip = -1; /* 1= tooltip 2= popup window*/
  100.     char *tooltip_text = "Click here";
  101.     char *temp = ""; /* */
  102.     char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
  103.     char *stroke_color = "255,0,0";
  104.     char *fill_color = "255,255,255";
  105.     char *font_family = "12px Arial"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
  106.     char *font_color = "#00000";
  107.     char *draw_type = "points";
  108.     char *fly_font = "normal";
  109.     char *input_style = "font-family:Arial;text-align:center;color:blue;font-size:12px;background-color:orange;";
  110.     char *flytext = "";
  111.     char *affine_matrix = "[1,0,0,1,0,0]";
  112.     char *function_label = "f(x)=";
  113.     int use_pattern = 0; /* used in drag&drop library: grid=2,hatch=3,diamond=4,dot=5*/
  114.     int canvas_type = DRAG_CANVAS; /* to use a specific canvas  for filling etc */
  115.     int pixelsize = 1;
  116.     int reply_format = 0;
  117.     int input_cnt = 0;
  118.     int ext_img_cnt = 0;
  119.     int fill_cnt = 0;
  120.     int font_size = 12;/* this may lead to problems when using something like <code>fontfamily Italic 24px Arial</code> the ''fontsize`` value is not substituted into fontfamily !! */
  121.     int fly_font_size = 12; /*fly_font_size is relative to this... */
  122.     int dashtype[2] = { 4 , 4 }; /* just line_px and space_px: may have more arguments...if needed in future */
  123.     int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis: only once per object type */
  124.     for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
  125.     int arrow_head = 8; /* size in px needed for arrow based  userdraw:  "userdraw arrow,color" */
  126.     int crosshair_size = 5; /* size in px*/
  127.     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  */
  128.     int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange: just to flag an error message */
  129.     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 */
  130.     int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
  131.     int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
  132.     int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/
  133.     int boxplot_cnt = 0;
  134.     int numberline_cnt = 0;
  135.     int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc  */
  136.     int reply_precision = 100; /* used for precision of student answers / drawings */
  137.     double angle = 0.0;
  138.     char *rotation_center = "null";
  139.     int use_animate = 0; /* used for jscurve / js parametric  */
  140.     int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/
  141.     int use_slider_display = 0; /* in case of a slider, should we display its value ?*/
  142.     size_t string_length = 0; /* measure the size of the user input fly-string */
  143.     double stroke_opacity = 0.8; /* use some opacity as default */
  144.     double fill_opacity = 0.5;/* use some opacity as default */
  145.     char *URL = "http://localhost/images";
  146.     char *slider_function_x = "x";
  147.     char *slider_function_y = "y";
  148.     memset(buffer,'\0',MAX_BUFFER);
  149.     void *tmp_buffer = "";
  150.     /* default writing a unzipped js-include file into wims getfile directory */
  151.     char *w_wims_session = getenv("w_wims_session");
  152.     if(  w_wims_session == NULL || *w_wims_session == 0 ){canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");}
  153.     int L0=strlen(w_wims_session) + 21;
  154.     char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
  155.     snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
  156.     mode_t process_mask = umask(0); /* check if file exists */
  157.     int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
  158.     if( result == 0 || errno == EEXIST ){
  159.      umask(process_mask); /* be sure to set correct permission */
  160.      char *w_session = getenv("w_session");
  161.      int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
  162.      getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
  163.      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 */
  164.     /* write the include tag to html page:<script src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
  165.     /* now write file into getfile dir*/
  166.     char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims": we need absolute path for location */
  167.     int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
  168.     char *location = my_newmem(L2); /* create memory to fit string precisely */
  169.     snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
  170.     js_include_file = fopen(location,"w");/* open the file location for writing */
  171.     /* check on opening...if nogood: mount readonly? disk full? permissions not set correctly? */
  172.     if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN: could not write to javascript include file...check your system logfiles !" );}
  173.     char *user_agent = getenv("HTTP_USER_AGENT");
  174.     int browser_type = 1;/* GECKO */
  175.     if( (strcasestr(user_agent,"khtml" )) || (strcasestr(user_agent,"opera" )) || (strcasestr(user_agent,"trident" )) ){ browser_type = 0; }
  176.  
  177. /* ----------------------------------------------------- */
  178.  
  179. /* while more lines to process */
  180.  
  181.     while(!finished){
  182.         if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
  183.         type = get_token(infile);
  184.         done = FALSE;
  185.         /*
  186.         @ canvasdraw
  187.         @ 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>
  188.         @ 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>
  189.         @ 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>
  190.         @ 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>.
  191.         @ 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.
  192.         @ 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.
  193.         @ 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>.
  194.         */
  195.         switch(type){
  196.         case END:
  197.         finished = 1;
  198.         done = TRUE;
  199.         break;
  200.         case 0:
  201.             sync_input(infile);
  202.             break;
  203.  
  204.         case CENTERED:
  205.          use_offset = 4;
  206.          /*
  207.          @ centered
  208.          @ keyword ; to place the text centered (in width and height) on the text coordinates(x:y)
  209.          @ may be used for text exactly centered on its (x;y)
  210.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  211.          @ 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``)
  212.          @%centered%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Arial%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
  213.         */
  214.         break;
  215.  
  216.         case COMMENT:
  217.             sync_input(infile);
  218.             break;
  219.         case AFFINE:
  220.         /*
  221.          @ affine a,b,c,d,tx,ty
  222.          @ defines a transformation matrix for subsequent objects
  223.          @ 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" !!
  224.          @ use keyword <a href='#killaffine'>killaffine</a> to end the transformation...the next objects will be drawn in the original x/y-range
  225.          @ note 1: only ''draggable`` / ''onclick`` type of objects (e.g. objects in the ''drag/drop/onclick-library``) can be transformed.
  226.          @ note 2: do not <code>drag xy</code> with tranformation / rotation objects: the mouse coordinates do not get transformed (yet)
  227.          @ note 3: ''onclick`` is supported on all transformations (mouse coordinates are corrected)
  228.          @ a: Scales the drawings horizontally
  229.          @ b: Skews the drawings horizontally
  230.          @ c: Skews the drawings vertically
  231.          @ d: Scales the drawings vertically
  232.          @ tx: Moves the drawings horizontally in xrange coordinate system
  233.          @ ty: Moves the drawings vertically in yrange coordinate system
  234.          @ the data precision may be set by preceding command ''precision int``
  235.          (cos, sin, -sin, cos, 0, 0);
  236.          @%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
  237.         */
  238.             for(i = 0 ; i<6;i++){
  239.                 switch(i){
  240.                     case 0: double_data[0] = get_real(infile,0);break;
  241.                     case 1: double_data[1] = get_real(infile,0);break;
  242.                     case 2: double_data[2] = get_real(infile,0);break;
  243.                     case 3: double_data[3] = get_real(infile,0);break;
  244.                     case 4: double_data[4] = get_real(infile,0);break;
  245.                     case 5: double_data[5] = get_real(infile,1);
  246.                         use_affine = TRUE;
  247.                         decimals = find_number_of_digits(precision);
  248.                         string_length = 1 + snprintf(NULL,0, "[%.*f,%.*f,%.*f,%.*f,%d,%d]",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],(int) (double_data[4]*xsize/(xmax - xmin)),(int) (-1*double_data[5]*ysize/(ymax - ymin)));
  249.                         check_string_length(string_length);affine_matrix = my_newmem(string_length);
  250.                         snprintf(affine_matrix,string_length,"[%.*f,%.*f,%.*f,%.*f,%d,%d]",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],(int) (double_data[4]*xsize/(xmax - xmin)),(int) (-1*double_data[5]*ysize/(ymax - ymin)));
  251.                         if( js_function[ADD_JS_TRANSFORM_MOUSE] != 1 ){ js_function[ADD_JS_TRANSFORM_MOUSE] = 1;}
  252.                         break;
  253.                     default: break;
  254.                 }
  255.             }
  256.         break;
  257.  
  258.         case ALLOW_DUPLICATES:
  259.         /*
  260.          @ duplicates || allowdups
  261.          @ keyword (no arguments)
  262.          @ only useful in case of a <a href="#multidraw">multidraw</a> student reply.
  263.          @ only useful in default <a href="#replyformat">replyformat</a> (eg in case of a not specified replyformat).
  264.          @ if set, duplicate (x:y) coordinates will not be removed from the student reply.
  265.          @ technical: a javascript variable "allow_duplicate_answer = 1;" is declared.
  266.          @ the default for command multidraw is : removal of duplicates.
  267.         */
  268.          fprintf(js_include_file,"var allow_duplicate_answers = 1;");
  269.         break;
  270.  
  271.  
  272.         case ANGLE:
  273.         /*
  274.          @ angle xc,yc,width,start_angle,end_angle,color
  275.          @ width is in x-range
  276.          @ angles are in degrees
  277.          @ not compatible with ''flydraw``
  278.          @ will zoom in/out
  279.          @ if angle size is controlled by command <a href='#slider'>slider</a>, use radians to set limits of slider
  280.          @ in case of a slider, command ''angle`` is always active ,controlled by the previous slider.
  281.          @%angle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%angle 0,0,4,10,135,blue
  282.          @%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
  283.         */
  284.             for(i=0;i<7;i++){
  285.                 switch(i){
  286.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  287.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  288.                     case 2:double_data[2] = get_real(infile,0);break; /* width x-range ! */
  289.                     case 3:double_data[3] = 0.0174532925*(get_real(infile,0));break; /* start angle in degrees -> radians  */
  290.                     case 4:double_data[4] = 0.0174532925*(get_real(infile,0));break; /* end angle in degrees -> radians */
  291.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  292.                         decimals = find_number_of_digits(precision);
  293.                         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);
  294.                         reset();
  295.                     break;
  296.                 }
  297.             }
  298.             if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  299.             /* click_cnt++;*/
  300.  
  301.             break;
  302.  
  303.         case ANIMATE:
  304.         /*
  305.          @ animate
  306.          @ keyword
  307.          @ the animated point is a filled rectangle ; adjust colour with command <code>fillcolor colorname/hexnumber</code>
  308.          @ use linewidth to adjust size of the points
  309.          @ 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
  310.          @ only usable for command jsplot (normal functions or parametric)<br />no other object/thing can be animated -for now
  311.          @ 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>
  312.          @ use commands <a href='#multilinewidth'>multilinewidth</a>, <a href='#multistrokecolor'>multistrokecolor or multicolors or colors</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>
  313.          @%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)
  314.          @%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
  315.         */
  316.             use_animate++;
  317.             if( use_animate == 1 ){
  318.             fprintf(js_include_file,"\nvar trace_canvas  = create_canvas%d(%d,xsize,ysize);\
  319.             var trace_ctx = trace_canvas.getContext('2d');\
  320.             trace_ctx.fillStyle = 'rgba(%s,%f)';\
  321.             trace_ctx.strokeStyle = 'rgba(%s,%f)';\
  322.             trace_ctx.lineWidth = %d;var anim_pos = 0;\n\
  323.             function animate_this(){\
  324.              var sync;\
  325.              var synchrone = Math.floor(animation_steps/animation_funs);\
  326.              trace_ctx.clearRect(0,0,xsize,ysize);\
  327.              for(var p=0; p<animation_funs;p++){\
  328.               sync = p*synchrone;\
  329.               trace_ctx.fillRect(x_anim_points[sync+anim_pos]-%d, y_anim_points[sync+anim_pos]-%d,%d,%d);\
  330.              };\
  331.              setTimeout(function(){\
  332.               requestAnimationFrame(animate_this);  anim_pos++;}, 50\
  333.              );\
  334.              if(anim_pos >= animation_steps){anim_pos = 0;};\
  335.              };",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);
  336.             }
  337.             else
  338.             {
  339.                 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)");
  340.             }
  341.             break;
  342.  
  343.         case ARC:
  344.         /*
  345.          @ arc xc,yc,x-width,y-height,start_angle,end_angle,color
  346.          @ can not be set ''onclick`` or ''drag xy``
  347.          @ compatible with ''flydraw``
  348.          @ attention: width &amp; height in x/y-range
  349.          @ better use command <a href='#angle'>angle</a> for use with a <a href='#slider'>slider</a>
  350.          @%arc%size 400,400%xrange -10,10%yrange -10,10%arc 0,0,4,4,10,135,red%zoom blue
  351.          @%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
  352.         */
  353.             for(i=0;i<7;i++){
  354.                 switch(i){
  355.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  356.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  357.                     case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */
  358.                     case 3:double_data[3] = get_real(infile,0);break; /* height y-range no pixels ! */
  359.                     case 4:double_data[4] = get_real(infile,0);break; /* start angle in degrees */
  360.                     case 5:double_data[5] = get_real(infile,0);break; /* end angle in degrees */
  361.                     case 6:stroke_color = get_color(infile,1);/* name or hex color */
  362.                     /* in Shape library:
  363.                         x[0] = x[1] = xc = double_data[0]
  364.                         y[0] = y[1] = yc = double_data[1]
  365.                         w[0] = width = double_data[2]
  366.                         w[1] = height = double_data[3]
  367.                         h[0] = start_angle = double_data[4]
  368.                         h[1] = end_angle = double_data[5]
  369.                     */
  370.                         decimals = find_number_of_digits(precision);
  371.                         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);
  372.                         reset();
  373.                     break;
  374.                 }
  375.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  376.                 /* click_cnt++;*/
  377.  
  378.             }
  379.             break;
  380.         case ARROW:
  381.         /*
  382.         @ arrow x1,y1,x2,y2,h,color
  383.         @ alternative: <code>vector</code>
  384.         @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color ''color``
  385.         @ use command <code>linewidth int</code> to adjust thickness of the arrow
  386.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  387.         @%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
  388.         @%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
  389.         */
  390.             for(i=0;i<6;i++){
  391.                 switch(i){
  392.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  393.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  394.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  395.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  396.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  397.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  398.                         decimals = find_number_of_digits(precision);
  399.                         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);
  400.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  401.                         /* click_cnt++;*/
  402.                         reset();
  403.                         break;
  404.                 }
  405.             }
  406.             break;
  407.  
  408.         case ARROWS:
  409.         /*
  410.         @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n
  411.         @ alternative: <code>vectors</code>
  412.         @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color ''color``.
  413.         @ use command <code>linewidth int</code> to adjust thickness of the arrow
  414.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  415.         @%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%
  416.         @%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%
  417.         @%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%
  418.         */
  419.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  420.             fill_color = stroke_color;
  421.             arrow_head = (int) get_real(infile,0);/* h */
  422.             i=0;
  423.             while( ! done ){     /* get next item until EOL*/
  424.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  425.                 if(i%2 == 0 ){
  426.                     double_data[i] = get_real(infile,0); /* x */
  427.                 }
  428.                 else
  429.                 {
  430.                     double_data[i] = get_real(infile,1); /* y */
  431.                 }
  432.                 i++;
  433.             }
  434.             decimals = find_number_of_digits(precision);
  435.             for(c = 0 ; c < i-1 ; c = c+4){
  436.                 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);
  437.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  438.                 /* click_cnt++; */
  439.             }
  440.             reset();
  441.             break;
  442.  
  443.         case ARROW2:
  444.         /*
  445.         @ arrow2 x1,y1,x2,y2,h,color
  446.         @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color ''color``
  447.         @ use command <code>arrowhead int</code> to adjust the arrow head size
  448.         @ use command <code>linewidth int</code> to adjust thickness of the arrow
  449.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  450.         @%arrow2%size 400,400%xrange -10,10%yrange -10,10%drag xy%arrow2 0,0,4,3,8,blue%
  451.         */
  452.             for(i=0;i<6;i++){
  453.                 switch(i){
  454.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  455.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  456.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  457.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  458.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  459.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  460.                         decimals = find_number_of_digits(precision);
  461.                         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);
  462.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  463.                         /* click_cnt++;*/
  464.                         reset();
  465.                         break;
  466.                 }
  467.             }
  468.             break;
  469.  
  470.         case ARROWS2:
  471.         /*
  472.         @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n
  473.         @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color ''color``
  474.         @ use command <code>linewidth int</code> to adjust thickness of the arrows
  475.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  476.         @%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%
  477.         */
  478.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  479.             fill_color = stroke_color;
  480.             arrow_head = (int) get_real(infile,0);/* h */
  481.             i=0;
  482.             while( ! done ){     /* get next item until EOL*/
  483.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  484.                 if(i%2 == 0 ){
  485.                     double_data[i] = get_real(infile,0); /* x */
  486.                 }
  487.                 else
  488.                 {
  489.                     double_data[i] = get_real(infile,1); /* y */
  490.                 }
  491.                 i++;
  492.             }
  493.             decimals = find_number_of_digits(precision);
  494.             for(c = 0 ; c < i-1 ; c = c+4){
  495.                 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);
  496.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  497.                 /* click_cnt++; */
  498.  
  499.             }
  500.             reset();
  501.             break;
  502.         case ARROWHEAD:
  503.         /*
  504.         @ arrowhead int
  505.         @ default 8 (pixels)
  506.         */
  507.             arrow_head = (int) (get_real(infile,1));
  508.             break;
  509.  
  510.         case AUDIO:
  511.         /*
  512.         @ audio x,y,w,h,loop,visible,audiofile location
  513.         @ x,y: left top corner of audio element (in xrange / yrange)
  514.         @ w,y: width and height in pixels
  515.         @ loop: 0 or 1 ( 1 = loop audio fragment)
  516.         @ visible: 0 or 1 (1 = show controls)
  517.         @ audio format may be in *.mp3 or *.ogg
  518.         @ If you are using *.mp3: be aware that FireFox will not (never) play this ! (Pattented format)
  519.         @ if you are using *.ogg: be aware that Microsoft based systems not support it natively
  520.         @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
  521.         */
  522.             if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
  523.             for(i=0;i<7;i++){
  524.                 switch(i){
  525.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  526.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  527.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  528.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  529.                     case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
  530.                     case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
  531.                     case 6:
  532.                     temp = get_string(infile,1);
  533.                     if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
  534.                     if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
  535.                     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);
  536.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  537.                     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);
  538.                     add_to_buffer(tmp_buffer);
  539.                     break;
  540.                     default:break;
  541.                 }
  542.             }
  543.             reset();
  544.             break;
  545.  
  546.  
  547.         case AXIS_NUMBERING:
  548.         /*
  549.             @ axisnumbering
  550.             @ keyword (no arguments required)
  551.             @ 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>
  552.             @ to be used before command grid (see <a href="#grid">command grid</a>)
  553.         */
  554.             use_axis_numbering++;
  555.             break;
  556.         case AXIS:
  557.         /*
  558.             @ axis
  559.             @ keyword (no arguments required)
  560.             @ to be used before command grid (see <a href="#grid">command grid</a>)
  561.  
  562.         */
  563.             use_axis = TRUE;
  564.             break;
  565.  
  566.         case BARCHART:
  567.         /*
  568.         @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
  569.         @ may <b>only</b> to be used together with command <a href='#grid'>grid</a>
  570.         @ 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>
  571.         @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner
  572.         @ multiple barchart command may be used in a single script
  573.         @ also see command <a href='#piechart'>piechart</a>
  574.         @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble...
  575.         @%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 Arial%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
  576.         */
  577.             temp = get_string(infile,1);
  578.             if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
  579.             fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
  580.             barchart_cnt++;
  581.             reset();
  582.             break;
  583.  
  584.         case BEZIER:
  585.         /*
  586.         @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end
  587.         @ draw a bezier curve between points, starting from (x_start:y_start)
  588.         @ can <b>not</b> be dragged or set onclick
  589.         */
  590.             if( js_function[DRAW_BEZIER] != 1 ){ js_function[DRAW_BEZIER] = 1;}
  591.             decimals = find_number_of_digits(precision);
  592.             for(i = 0 ; i < 9; i++){
  593.                 switch(i){
  594.                     case 0: stroke_color = get_color(infile,0);break;
  595.                     case 1: double_data[0] = get_real(infile,0);break;/* start x */
  596.                     case 2: double_data[1] = get_real(infile,0);break;/* start y */
  597.                     case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */
  598.                     case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */
  599.                     case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */
  600.                     case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */
  601.                     case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */
  602.                     case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */
  603.                         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);
  604.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  605.                         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);
  606.                         add_to_buffer(tmp_buffer);
  607.                         break;
  608.                     default: break;
  609.                 }
  610.             }
  611.             reset();
  612.             break;
  613.  
  614.  
  615.         case BGCOLOR:
  616.         /*
  617.          @ bgcolor colorname or #hex
  618.          @ use this color as background of the "div" containing the canvas(es)
  619.          @%bgcolor%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue
  620.         */
  621.         /* [255,255,255]*/
  622.             bgcolor = get_string(infile,1);
  623.             if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
  624.                 int found = 0;
  625.                 for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  626.                     if( strcmp( colors[i].name , bgcolor ) == 0 ){
  627.                         bgcolor = colors[i].hex;
  628.                         found = 1;
  629.                         break;
  630.                     }
  631.                 }
  632.                 if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list: use hexcolor...something like #a0ffc4");}
  633.             }
  634.             fprintf(js_include_file,"/* set background color of canvas div */\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
  635.             break;
  636.  
  637.         case BGIMAGE:
  638.         /*
  639.          @ bgimage image_location
  640.          @ use an image as background; technical: we use the background of ''canvas_div``
  641.          @ the background image will be resized to match "width = xsize" and "height = ysize"
  642.          @%bgimage%size 400,400%xrange -10,10%yrange -10,10%bgimage https://wims.unice.fr/wims/gifs/en.gif
  643.         */
  644.         URL = get_string(infile,1);
  645.         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);
  646.             break;
  647.  
  648.         case BLINK:
  649.         /*
  650.          @ blink time(seconds)
  651.          @ NOT IMPLEMETED -YET
  652.         */
  653.             break;
  654.  
  655.         case BOXPLOT:
  656.         /*
  657.         @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max
  658.         @ 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
  659.         @ 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
  660.         @ 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
  661.         @ use command <a href='#fillpattern'>fillpattern some_pattern</a> to use a (diamond for Q1, hatch for Q3) pattern.
  662.         @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of stroke and fill colours
  663.         @ 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.
  664.         @ there is no limit to the number of boxplots used.
  665.         @ can <b>not</b> be set draggable and <a href='#onclick'>onclick</a> is not ready yet
  666.         @ 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)
  667.         @ use keyword <a href="#userboxplotdata">userboxplotdata</a> before command boxplot, if a pupil must generate the data by some means.
  668.         @ use command <a href="#boxplotdata">boxplotdata</a> when the boxplot should be drawn from wims-generated raw statistical date
  669.         @%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
  670.         @%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
  671.         @%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
  672.         */
  673.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  674.             for(i=0;i<8;i++){
  675.                 switch(i){
  676.                     case 0: temp = get_string_argument(infile,0);
  677.                             if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */
  678.                     case 1: double_data[0] = get_real(infile,0);break;/* height | width  */
  679.                     case 2:
  680.                     if( js_function[DRAW_JSBOXPLOT] == 0 ){
  681.                      double_data[1] = get_real(infile,0);
  682.                      fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */
  683.                     }
  684.                     else
  685.                     {
  686.                      double_data[1] = get_real(infile,1);
  687.                      double_data[2] = 1;
  688.                      double_data[3] = 1;
  689.                      double_data[4] = 1;
  690.                      double_data[5] = 1;
  691.                      double_data[6] = 1;
  692.                      double_data[7] = 1;
  693.                      i=8;
  694.                     }
  695.                     break;/* center value x or y */
  696.                     case 3: double_data[2] = get_real(infile,0); break;/* min */
  697.                     case 4: double_data[3] = get_real(infile,0); break;/* Q1 */
  698.                     case 5: double_data[4] = get_real(infile,0); break;/* median */
  699.                     case 6: double_data[5] = get_real(infile,0); break;/* Q3 */
  700.                     case 7: double_data[6] = get_real(infile,1); break;/* max */
  701.                     default:break;
  702.                 }
  703.             }
  704.             decimals = find_number_of_digits(precision);
  705.             /*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)*/
  706.             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]);
  707.             check_string_length(string_length);
  708.             tmp_buffer = my_newmem(string_length);
  709.             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]);
  710.             add_to_buffer(tmp_buffer);
  711.             boxplot_cnt++;
  712.             reset();
  713.         break;
  714.         case BOXPLOTDATA:
  715.         /*
  716.         @ boxplotdata some_data
  717.         @ ''some_data``are a list of numbers separated by a comma "," (items)
  718.         @ only be used before command <code>boxplot</code>: the command <a href="#boxplot">boxplot</a> will provide the boxplot drawing of the data.
  719.         @ 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
  720.         @ note: wims will not check your data input | format. use js-error console to debug any problems.
  721.         @ 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.
  722.         @ 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>
  723.         @%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
  724.         */
  725.             if( js_function[DRAW_JSBOXPLOT] != 1 ){ js_function[DRAW_JSBOXPLOT] = 1;}
  726.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  727.             fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1));
  728.  
  729.         break;
  730.  
  731.         case CANVASTYPE:
  732.          canvas_type = (int) (get_real(infile,1));
  733.         /*
  734.         @ canvastype TYPE
  735.         @ for now only useful before commands filltoborder / floodfill / clickfill etc operations<br />Only the images of this TYPE will be scanned and filled
  736.         @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas)
  737.         @ use another TYPE, if you know what you are doing...
  738.         @ 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>
  739.         */
  740.         break;
  741.  
  742.         case CENTERSTRING:
  743.         /*
  744.          @ centerstring color,y-value,the text string
  745.          @ title color,y-value,the text string
  746.          @ draw a string centered on the canvas at y = y-value
  747.          @ can not be set ''onclick`` or ''drag xy`` (...)
  748.          @ unicode supported: <code>centerstring red,5,\\u2232</code>
  749.          @ use a command like <code>fontfamily italic 24pt Arial</code> to set fonts on browser that support font change
  750.          @%centerstring%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue%fontfamily italic 22pt Courier%centerstring blue,7,the center
  751.         */
  752.             if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;}
  753.             for(i=0;i<3;i++){
  754.                 switch(i){
  755.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  756.                     case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
  757.                     case 2: temp = get_string_argument(infile,1);
  758.                             /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
  759.                             decimals = find_number_of_digits(precision);
  760.                             string_length = 1 + snprintf(NULL,0,
  761.                             "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
  762.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  763.                             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);
  764.                             add_to_buffer(tmp_buffer);
  765.                             break;
  766.                     default:break;
  767.                 }
  768.             }
  769.             break;
  770.  
  771.  
  772.         case CIRCLE:
  773.         /*
  774.         @ circle xc,yc,width (2*r in pixels),color
  775.         @ alernative: use command <code>fcircle xc,yc,d,color</code> for a filled circle.
  776.         @ use command <code>fillcolor color</code> to set the fillcolor.
  777.         @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a>
  778.         @ will shrink / expand on zoom out / zoom in.
  779.         @%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
  780.         */
  781.             for(i=0;i<4;i++){
  782.                 switch(i){
  783.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  784.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  785.                     case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out: radius in 'dx' xrange*/
  786.                     case 3: stroke_color = get_color(infile,1);/* name or hex color */
  787.                         decimals = find_number_of_digits(precision);
  788.                         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);
  789.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  790.                         /* click_cnt++;*/
  791.                         reset();
  792.                         break;
  793.                     default : break;
  794.                 }
  795.             }
  796.             break;
  797.  
  798.         case CIRCLES:
  799.         /*
  800.         @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n
  801.         @ <b>attention</b> r = radius in x-range (!)
  802.         @ use keyword <code>filled</code> or command <code>fcircles</code> to produce solid circles
  803.         @ alternative: disks for filled circles
  804.         @ use command <code>fillcolor color</code> to set the fillcolor
  805.         @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> (individually)
  806.         @ will shrink / expand on zoom out / zoom in
  807.         @%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
  808.         @%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
  809.         @%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
  810.         */
  811.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  812.             fill_color = stroke_color;
  813.             i=1;
  814.             while( ! done ){     /* get next item until EOL*/
  815.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  816.                 switch (i%3){
  817.                  case 1:double_data[i-1] = get_real(infile,0);break; /* x */
  818.                  case 2:double_data[i-1] = get_real(infile,0);break; /* y */
  819.                  case 0:double_data[i-1] = get_real(infile,1);break; /* r */
  820.                 }
  821.                 i++;
  822.             }
  823.             decimals = find_number_of_digits(precision);
  824.             for(c = 0 ; c < i-1 ; c = c+3){
  825.                 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);
  826.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  827.                 /* click_cnt++; */
  828.             }
  829.             reset();
  830.             break;
  831.         case CLEARBUTTON:
  832.         /*
  833.          @ clearbutton value
  834.          @ alternative: <code>delete</code>
  835.          @ alternative: <code>erase</code>
  836.          @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text ''value``.
  837.          @ <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).
  838.          @ 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
  839.          @ uses the tooltip placeholder div element: may not be used with command <code>intooltip</code>
  840.          @ use command <a href="#inputstyle">inputstyle</a> to style the button...
  841.          @ 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>
  842.          @%clearbutton%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%userdraw circles,red%clearbutton Remove All
  843.         */
  844.         if(reply_format == 29){/* eg multidraw is selected */
  845.         // canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw");
  846.         }
  847.             add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1));
  848.         break;
  849.  
  850.         case CLOCK:
  851.         /*
  852.         @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
  853.         @ use command <code>opacity stroke-opacity,fill-opacity</code> to adjust foreground (stroke) and background (fill) transparency
  854.         @ type hourglass:<br />type = 0: only segments<br />type = 1: only numbers<br />type = 2: numbers and segments
  855.         @ 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
  856.         @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
  857.         @ 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>
  858.         @ canvasdraw will not check validity of colornames...the javascript console is your best friend
  859.         @ no combinations with other reply_types allowed, for now
  860.         @ 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
  861.         @ 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
  862.         @ note: clocks will not zoom or pan, when using command <a href='#zoom'>zoom</a>
  863.         @%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
  864.         @%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
  865.         @%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
  866.         @%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
  867.         @%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
  868.         @%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
  869.         @%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
  870.         */
  871.             if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
  872.  
  873.         /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
  874.             for(i=0;i<9;i++){
  875.              switch(i){
  876.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
  877.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
  878.               case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
  879.               case 3: int_data[3] = get_real(infile,0);break;/* hours */
  880.               case 4: int_data[4] = get_real(infile,0);break;/* minutes */
  881.               case 5: int_data[5] = get_real(infile,0);break;/* seconds */
  882.               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 */
  883.               case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/
  884.                 switch(int_data[7]){
  885.                     case 0:break;
  886.                     case 1:if(clock_cnt == 0){
  887.                            if( reply_format == 0 ){
  888.                             reply_format = 18; /* user sets clock */
  889.                             /* 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");
  890.                                check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  891.                                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");
  892.                                add_to_buffer(tmp_buffer);
  893.                            */
  894.                             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");
  895.                            }
  896.                            else
  897.                            {
  898.                             canvas_error("interactive clock may not be used together with other reply_types...");
  899.                            }
  900.                           }
  901.                           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);
  902.                     break;
  903.                     case 3:if(clock_cnt == 0){
  904.                             if( reply_format == 0 ){
  905.                              reply_format = 18; /* user sets clock */
  906.                              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");
  907.                             }
  908.                             else
  909.                             {
  910.                              canvas_error("interactive clock may not be used together with other reply_types...");
  911.                             }
  912.                            }
  913.                             /*
  914.                             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);
  915.                            */
  916.                     break;
  917.                     case 2:if( reply_format == 0 ){
  918.                                 reply_format = 19; /* "onclick */
  919.                                 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");
  920.                             }
  921.                             else
  922.                             {
  923.                                 if( reply_format != 19){
  924.                                    canvas_error("clickable clock(s) may not be used together with other reply_types...");
  925.                                  }
  926.                             }
  927.                      break;
  928.                      default: canvas_error("interactive must be set 0,1 or 2");break;
  929.                 }
  930.                 break;
  931.                 case 8:
  932.                         if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock(), for now it's OK */
  933.                             fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
  934.                         }
  935.                         temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/
  936.                         if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
  937.                         else{
  938.                         /* h_color,m_color,s_color,bg_color,fg_color */
  939.                         temp = ",black\",\"black\",\"black\",\"white\",\"black";}
  940.                         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);
  941.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  942.                         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);
  943.                         add_to_buffer(tmp_buffer);
  944.                         fprintf(js_include_file,"var clocks%d;",clock_cnt);
  945.                         clock_cnt++;
  946.                         break;
  947.                 default:break;
  948.              }
  949.             }
  950.             break;
  951.  
  952.  
  953.         case COLORPALETTE:
  954.         /*
  955.          @ colorpalette color_name_1,color_name_2,...,color_name_8
  956.          @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a>
  957.          @ 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
  958.          @ make sure to include the ''remove button`` by using command <a href='#clearbutton'>clearbutton some_text</a>
  959.         */
  960.             if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");}
  961.             fprintf(js_include_file,"var multifillcolors = [];var palettecolors = [");
  962.             while( ! done ){
  963.                 temp = get_color(infile,1);
  964.                 fprintf(js_include_file,"\"%s\",",temp);
  965.             }
  966.             fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */
  967.             add_color_palette(js_include_file,canvas_root_id,input_style);
  968.             break;
  969.  
  970.         case COPY:
  971.         /*
  972.         @ copy x,y,x1,y1,x2,y2,[filename URL]
  973.         @ The image may be "bitmap" or "SVG"
  974.         @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
  975.         @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
  976.         @ [filename] is the URL of the image
  977.         @ URL is normal URL of network reachable image file location (eg special url for ''classexo`` not -yet- implemented)
  978.         @ 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>.
  979.         @ 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
  980.         @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves etc)
  981.         @ you may draw / userdraw / drag other stuff on top of an "imported" image
  982.         @ 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!)
  983.         @ use keyword <a href='#centered'>centered</a> before command ''copy`` to place image center at given coordinates.
  984.         @%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
  985.         @%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
  986.         @%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
  987.         */
  988.             for(i = 0 ; i<7;i++){
  989.                 switch(i){
  990.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
  991.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
  992.                     case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
  993.                     case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
  994.                     case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
  995.                     case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
  996.                     case 6: URL = get_string(infile,1);
  997.                             int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
  998.                             int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
  999.                             if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  1000.                             int_data[9] = click_cnt;
  1001.                             if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
  1002.                                  //if( reply_format == 0 ){ reply_format = 20; }
  1003.                                  int_data[8] = 2;/* drag & drop */
  1004.                                  if(use_offset == 0 ){use_offset = 4;} /* mouse is attached to the center of the image !! */
  1005.                             }
  1006.                             else
  1007.                             {
  1008.                                 if( onclick == 1  ){
  1009.                                 //    reply_format = 20;
  1010.                                     int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
  1011.                                     click_cnt++; /* will also be used in dragstuff ! */
  1012.                                 }
  1013.                                 else
  1014.                                 {
  1015.                                     int_data[8] = 0; /* just static image */
  1016.                                 }
  1017.                             }
  1018.                             if( include_special_OEF_reply == FALSE){
  1019.                              if( int_data[8] == 1 || int_data[8] == 2 ){
  1020.                               include_special_OEF_reply = TRUE;
  1021.                               fprintf(js_include_file,"\
  1022.                               \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\
  1023.                               read_canvas_images = function(){\
  1024.                                var prec = %d;\
  1025.                                var len  = ext_drag_images.length;\
  1026.                                var reply = new Array(len);\
  1027.                                for(var p = 0 ; p < len ; p++){\
  1028.                                 var img = ext_drag_images[p];\
  1029.                                 reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  1030.                                };\
  1031.                                return reply;\
  1032.                               };\n\
  1033.                               /* end function 34 read_canvas_images() */",reply_precision);
  1034.                              }
  1035.                             }
  1036. /*
  1037. function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt,centered,use_snap){\
  1038. */
  1039.                             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);
  1040.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1041.                             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);
  1042.                             add_to_buffer(tmp_buffer);
  1043.                             drag_type = -1; /* reset the drag_type indicator */
  1044.                             ext_img_cnt++;
  1045.                             onclick=0;
  1046.                             use_offset=0;
  1047.                             reset();
  1048.                             break;
  1049.                     default: break;
  1050.                 }
  1051.             }
  1052.             break;
  1053. /*
  1054. HTML5 specs:
  1055. context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  1056. img     Specifies the image, canvas, or video element to use
  1057. sx      The x coordinate where to start clipping: x1 = int_data[0]
  1058. sy      The y coordinate where to start clipping: x2 = int_data[1]
  1059. swidth  The width of the clipped image: int_data[2] - int_data[0]
  1060. sheight The height of the clipped image: int_data[3] - int_data[1]
  1061. x       The x coordinate where to place the image on the canvas: dx1 = int_data[4]
  1062. y       The y coordinate where to place the image on the canvas: dy1 = int_data[5]
  1063. width   The width of the image to use (stretch or reduce the image): dx2 - dx1 = int_data[6]
  1064. height  The height of the image to use (stretch or reduce the image): dy2 - dy1 = int_data[7]
  1065. */
  1066.         case COPYRESIZED:
  1067.         /*
  1068.         @ copyresized x1,y1,x2,y2,dx1,dy1,dx2,dy2,image_file_url
  1069.         @ The image may be any "bitmap" or "SVG"
  1070.         @ 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
  1071.         @ (dx1:dy1) must be left top corner; (dx2:dy2) must be right bottom corner of inserted image
  1072.         @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
  1073.         @ URL is normal URL of network reachable image file location (as seen from public_html-root or network reachable 'http://some_server/my_images/test.gif', eg no special wims paths are searched !!)
  1074.         @ 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>
  1075.         @ 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
  1076.         @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines, curves etc).
  1077.         @ you may draw / userdraw / drag stuff on top of an "imported" image.
  1078.         @ 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``.
  1079.         @ use keyword <a href='#centered'>centered</a> before command ''copyresized`` to place image center at given coordinates.
  1080.         */
  1081.             for(i = 0 ; i<9;i++){
  1082.                 switch(i){
  1083.                     case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
  1084.                     case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
  1085.                     case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
  1086.                     case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
  1087.                     case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
  1088.                     case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
  1089.                     case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
  1090.                     case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
  1091.                     case 8: URL = get_string(infile,1);
  1092.                             /* flag error when wrong diagonal:  copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */
  1093.                             if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){
  1094.                                 canvas_error("in copyresized , use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! ");
  1095.                             }
  1096.                             int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */
  1097.                             int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */
  1098.                             int_data[6] = abs(int_data[6] - int_data[4]);/* width */
  1099.                             int_data[7] = abs(int_data[7] - int_data[5]);/* height */
  1100.                             if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  1101.                             int_data[9] = click_cnt;
  1102.                             if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
  1103.                                 // if( reply_format == 0 ){ reply_format = 20; }
  1104.                                  int_data[8] = 2;/* drag & drop */
  1105.                             }
  1106.                             else
  1107.                             {
  1108.                                 if( onclick == 1  ){
  1109.                                 //    reply_format = 20;
  1110.                                     int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
  1111.                                     click_cnt++; /* will also be used in dragstuff ! */
  1112.                                 }
  1113.                                 else
  1114.                                 {
  1115.                                     int_data[8] = 0; /* just static image */
  1116.                                 }
  1117.                             }
  1118.                             if( include_special_OEF_reply == FALSE){
  1119.                              if( int_data[8] == 1 || int_data[8] == 2 ){
  1120.                               include_special_OEF_reply = TRUE;
  1121.                               fprintf(js_include_file,"\
  1122.                               \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\
  1123.                               read_canvas_images = function(){\
  1124.                                var prec = %d;\
  1125.                                var len  = ext_drag_images.length;\
  1126.                                var reply = new Array(len);\
  1127.                                for(var p = 0 ; p < len ; p++){\
  1128.                                 var img = ext_drag_images[p];\
  1129.                                 reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  1130.                                };\
  1131.                                return reply;\
  1132.                               };\n\
  1133.                               /* end function 34 read_canvas_images() */",reply_precision);
  1134.                              }
  1135.                             }
  1136.  
  1137. /*
  1138. (URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt)
  1139. URL,[2],[3],[6],    [7], [4],[5],[6],[7],ext_img_cnt,1,    [8],      [9]
  1140. */
  1141.                             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);
  1142.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1143.                             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);
  1144.                             add_to_buffer(tmp_buffer);
  1145.                             drag_type = -1; /* reset the drag_type indicator */
  1146.                             ext_img_cnt++;
  1147.                             onclick=0;
  1148.                             use_offset=0;
  1149.                             reset();
  1150.                             break;
  1151.                     default: break;
  1152.                 }
  1153.             }
  1154.             reset();
  1155.             break;
  1156.  
  1157.         case CROSSHAIR:
  1158.         /*
  1159.         @ crosshair x,y,color
  1160.         @ draw a single crosshair point at (x;y) in color ''color``
  1161.         @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust
  1162.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1163.         @%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
  1164.         */
  1165.             for(i=0;i<3;i++){
  1166.                 switch(i){
  1167.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  1168.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  1169.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  1170.                         decimals = find_number_of_digits(precision);
  1171.                         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);
  1172.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1173.                         /* click_cnt++ */
  1174.                         reset();
  1175.                         break;
  1176.                     default:break;
  1177.                 }
  1178.             }
  1179.             break;
  1180.  
  1181.         case CROSSHAIRS:
  1182.         /*
  1183.         @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
  1184.         @ draw multiple crosshair points at given coordinates in color ''color``
  1185.         @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust
  1186.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  1187.         @%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
  1188.         @%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
  1189. */
  1190.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1191.             fill_color = stroke_color;
  1192.             i=0;
  1193.             while( ! done ){     /* get next item until EOL*/
  1194.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1195.                 if(i%2 == 0 ){
  1196.                     double_data[i] = get_real(infile,0); /* x */
  1197.                 }
  1198.                 else
  1199.                 {
  1200.                     double_data[i] = get_real(infile,1); /* y */
  1201.                 }
  1202.                 i++;
  1203.             }
  1204.             decimals = find_number_of_digits(precision);
  1205.             for(c=0 ; c < i-1 ; c = c+2){
  1206.                 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);
  1207.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1208.                 /* click_cnt++; */
  1209.             }
  1210.             reset();
  1211.             break;
  1212.  
  1213.         case CROSSHAIRSIZE:
  1214.         /*
  1215.         @ crosshairsize int
  1216.         @ default 8 (px)
  1217.         */
  1218.             crosshair_size = (int) (get_real(infile,1));
  1219.             break;
  1220.  
  1221.         case CURSOR:
  1222.         /*
  1223.         @ cursor some CSS cursor_style
  1224.         @ alternative: <code>pointer</code>
  1225.         @ style can be any valid CSS property value
  1226.         @ 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
  1227.         @ note: wims will not check the validity of your cursor declaration
  1228.         @%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
  1229.         */
  1230.             fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1));
  1231.             break;
  1232.  
  1233.         case CURVE:
  1234.         /*
  1235.          @ curve color,formula(x)
  1236.          @ alternative: <code>plot color,formula(x)</code>
  1237.          @ 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>
  1238.          @ use command <a href="#precision">precision</a> to increase the number of digits of the plotted points
  1239.          @ use command <a href="#plotsteps">plotsteps</a> to increase / decrease the amount of plotted points (default 150)
  1240.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1241.          @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">jsplot</a> (command ''curve`` will only calculate points within the xrange)
  1242.          @%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)
  1243.         */
  1244.             if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
  1245.                 use_parametric = FALSE;
  1246.                 stroke_color = get_color(infile,0);
  1247.                 char *fun1 = get_string_argument(infile,0);
  1248.                 char *fun2 = get_string_argument(infile,1);
  1249.                 if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
  1250.                 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);
  1251.             }
  1252.             else
  1253.             {
  1254.                 stroke_color = get_color(infile,0);
  1255.                 char *fun1 = get_string_argument(infile,1);
  1256.                 if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  1257.                 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);
  1258.             }
  1259.             if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1260.             /* click_cnt++; */
  1261.             reset();
  1262.             break;
  1263.     case CURVEDARROW:
  1264.     /*
  1265.     @ curvedarrow x1,y1,xc,yc,x2,y2,color
  1266.     @ 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).
  1267.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1268.     @ use command <code>linewidth int</code> to adjust thickness of the arrow.
  1269.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>.
  1270.     @%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
  1271.     @%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
  1272.  
  1273. h[0] = arrowhead
  1274. h[1] = type: 1 = single 2=double arrow
  1275. 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)
  1276.     */
  1277.             for(i=0;i<7;i++){
  1278.             switch(i){
  1279.                 case 0: double_data[0] = get_real(infile,0);break; /* x1 */
  1280.                 case 1: double_data[1] = get_real(infile,0);break; /* y1 */
  1281.                 case 2: double_data[2] = get_real(infile,0);break; /* xc */
  1282.                 case 3: double_data[3] = get_real(infile,0);break; /* yc */
  1283.                 case 4: double_data[4] = get_real(infile,0);break; /* y3 */
  1284.                 case 5: double_data[5] = get_real(infile,0);break; /* y3 */
  1285.                 case 6: stroke_color = get_color(infile,1);/* name or hex color */
  1286.                 decimals = find_number_of_digits(precision);
  1287.             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);
  1288.             if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1289.             /* click_cnt++;*/
  1290.             reset();
  1291.             break;
  1292.             }
  1293.             }
  1294.             break;
  1295.  
  1296.     case CURVEDARROW2:
  1297.     /*
  1298.     @ curvedarrow2 x1,y1,xc,yc,x2,y2,color
  1299.     @ 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)
  1300.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1301.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1302.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1303.     @%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
  1304.     @%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
  1305.  
  1306. h[0] = arrowhead
  1307. h[1] = type: 1 = single 2=double arrow
  1308. 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)
  1309.     */
  1310.             for(i=0;i<7;i++){
  1311.             switch(i){
  1312.                 case 0: double_data[0] = get_real(infile,0);break; /* x1 */
  1313.                 case 1: double_data[1] = get_real(infile,0);break; /* y1 */
  1314.                 case 2: double_data[2] = get_real(infile,0);break; /* xc */
  1315.                 case 3: double_data[3] = get_real(infile,0);break; /* yc */
  1316.                 case 4: double_data[4] = get_real(infile,0);break; /* y3 */
  1317.                 case 5: double_data[5] = get_real(infile,0);break; /* y3 */
  1318.                 case 6: stroke_color = get_color(infile,1);/* name or hex color */
  1319.                 decimals = find_number_of_digits(precision);
  1320.             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);
  1321.             if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1322.             /* click_cnt++;*/
  1323.             reset();
  1324.             break;
  1325.             }
  1326.             }
  1327.             break;
  1328.     case CURVEDARROWS:
  1329.     /*
  1330.     @ curvedarrows color,x1,y1,xc,yc,x2,y2,...,x_(n-1),y_(n-1),xc,yc,x_n,y_n
  1331.     @ 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)
  1332.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1333.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1334.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1335.     @%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
  1336.     @%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
  1337.  
  1338. h[0] = arrowhead
  1339. h[1] = type: 1 = single 2=double arrow
  1340. 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)
  1341.     */
  1342.         stroke_color = get_color(infile,0);/* name or hex color */
  1343.         i = 0;
  1344.         decimals = find_number_of_digits(precision);
  1345.         while( ! done ){
  1346.         if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1347.         double_data[0] = get_real(infile,0); /* x1 */
  1348.         double_data[1] = get_real(infile,0); /* y1 */
  1349.         double_data[2] = get_real(infile,0); /* xc */
  1350.         double_data[3] = get_real(infile,0); /* yc */
  1351.         double_data[4] = get_real(infile,0); /* x3 */
  1352.         double_data[5] = get_real(infile,1); /* y3 */
  1353.         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);
  1354.         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1355.         i = i + 6;
  1356.             }
  1357.             reset();
  1358.             break;
  1359.  
  1360.     case CURVEDARROWS2:
  1361.     /*
  1362.     @ curvedarrows2 color,x1,y1,xc,yc,x2,y2,...x_(n-1),y_(n-1),xc,yc,x_n,y_n
  1363.     @ 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)
  1364.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1365.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1366.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1367.     @%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
  1368.     @%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
  1369.  
  1370. h[0] = arrowhead
  1371. h[1] = type: 1 = single 2=double arrow
  1372. 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)
  1373.     */
  1374.         stroke_color = get_color(infile,0);/* name or hex color */
  1375.         i = 0;
  1376.         decimals = find_number_of_digits(precision);
  1377.         while( ! done ){
  1378.         if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1379.         double_data[0] = get_real(infile,0); /* x1 */
  1380.         double_data[1] = get_real(infile,0); /* y1 */
  1381.         double_data[2] = get_real(infile,0); /* xc */
  1382.         double_data[3] = get_real(infile,0); /* yc */
  1383.         double_data[4] = get_real(infile,0); /* x3 */
  1384.         double_data[5] = get_real(infile,1); /* y3 */
  1385.         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);
  1386.         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1387.         i = i + 6;
  1388.             }
  1389.             reset();
  1390.             break;
  1391.         case DASHED:
  1392.         /*
  1393.         @ dashed
  1394.         @ keyword (no arguments required)
  1395.         @ next object will be drawn with a dashed line
  1396.         @ change dashing scheme by using command <a href="#dashtype">dashtype</a>
  1397.         @%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
  1398.         */
  1399.             use_dashed = TRUE;
  1400.             break;
  1401.  
  1402.         case DASHTYPE:
  1403.         /*
  1404.         @ dashtype line_width_px,space_width_px
  1405.         @ every indiviual object may have its own dashtype, if needed...
  1406.         @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype
  1407.         @ default value <code>dashtype 2,2</code> e.g. 2px line and 2px space
  1408.         @ HTML5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable
  1409.         @%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
  1410.         */
  1411.             for(i=0;i<2;i++){
  1412.                 switch(i){
  1413.                     case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
  1414.                     case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
  1415.                 }
  1416.             }
  1417.         break;
  1418.  
  1419.         case DIAMONDFILL:
  1420.         /*
  1421.         @ diamondfill x0,y0,dx,dy,color
  1422.         @ x0,y0 in xrange / yrange
  1423.         @ distances dx,dy in pixels
  1424.         @ there is also a command <a href="#userdraw">userdraw diamondfill,color</a>
  1425.         @%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
  1426.         */
  1427.             if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
  1428.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1429.              js_function[DRAW_FILLTOBORDER] = 1;
  1430.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1431.             }
  1432.             decimals = find_number_of_digits(precision);
  1433.             for(i=0;i<5;i++){
  1434.                 switch(i){
  1435.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  1436.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  1437.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1438.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1439.                     case 4: stroke_color = get_color(infile,1);
  1440.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  1441.                     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);
  1442.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1443.                     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);
  1444.                     add_to_buffer(tmp_buffer);
  1445.                     fill_cnt++;
  1446.                     break;
  1447.                     default:break;
  1448.                 }
  1449.             }
  1450.             reset();
  1451.         break;
  1452.  
  1453.         case DOTFILL:
  1454.         /*
  1455.         @ dotfill x0,y0,dx,dy,color
  1456.         @ x0,y0 in xrange / yrange
  1457.         @ distances dx,dy in pixels
  1458.         @ radius of dots is linewidth
  1459.         @ there is also a command <a href="#userdraw">userdraw dotfill,color</a>
  1460.         @%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
  1461.         */
  1462.             if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
  1463.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1464.              js_function[DRAW_FILLTOBORDER] = 1;
  1465.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1466.             }
  1467.             decimals = find_number_of_digits(precision);
  1468.             for(i=0;i<5;i++){
  1469.                 switch(i){
  1470.                     case 0: double_data[0] = get_real(infile,0); break; /* x in px */
  1471.                     case 1: double_data[1] = get_real(infile,0); break; /* y in py */
  1472.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1473.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1474.                     case 4: stroke_color = get_color(infile,1);
  1475.                     /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
  1476.                     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);
  1477.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1478.                     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);
  1479.                     add_to_buffer(tmp_buffer);
  1480.                     fill_cnt++;
  1481.                     break;
  1482.                     default:break;
  1483.                 }
  1484.             }
  1485.             reset();
  1486.         break;
  1487.  
  1488.         case DRAG:
  1489.         /*
  1490.          @ drag [x][y][xy]
  1491.          @ the next object will be draggable in x / y / xy direction
  1492.          @ the displacement can be read by <code>javascript:read_dragdrop();</code>
  1493.          @ 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' !
  1494.          @ <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 )
  1495.          @ ''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)
  1496.          @ <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
  1497.          @ 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)
  1498.          @ 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
  1499.          @ 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.
  1500.          @ 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 !!
  1501.          @%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
  1502.          @%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
  1503.          @%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
  1504.         */
  1505.             temp = get_string(infile,1);
  1506.             if(strstr(temp,"xy") != NULL ){
  1507.                 drag_type = 0;
  1508.             }
  1509.             else
  1510.             {
  1511.                 if(strstr(temp,"x") != NULL ){
  1512.                     drag_type = 1;
  1513.                 }
  1514.                 else
  1515.                 {
  1516.                     drag_type = 2;
  1517.                 }
  1518.             }
  1519.             /* assuming all drag&drop coordinates the same precision: so set only once */
  1520.             if( print_drag_params_only_once == FALSE ){
  1521.              fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;\n",precision);
  1522.              print_drag_params_only_once = TRUE;
  1523.             }
  1524.             onclick = 2;
  1525.             /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
  1526.             break;
  1527.  
  1528.         case ELLIPSE:
  1529.         /*
  1530.         @ ellipse xc,yc,radius_x,radius_y,color
  1531.         @ an ellipse with center xc/yc in x/y-range
  1532.         @ radius_x and radius_y are in pixels
  1533.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1534.         @ will shrink / expand on zoom out / zoom in
  1535.         @%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
  1536.         */
  1537.             for(i=0;i<5;i++){
  1538.                 switch(i){
  1539.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  1540.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  1541.                     case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */
  1542.                     case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */
  1543.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  1544.                         decimals = find_number_of_digits(precision);
  1545.                         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);
  1546.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1547.                         /* click_cnt++; */
  1548.                         reset();
  1549.                     break;
  1550.                 }
  1551.             }
  1552.             break;
  1553.  
  1554.         case ELLIPSES:
  1555.         /*
  1556.         @ ellipses color,xc1,yc1,radius_x1,radius_y1,xc2,yc2,radius_x2,radius_y2,xc3,yc3,radius_x3,radius_y3,...
  1557.         @ ellipses with center xc1/yc1 in x/y-range, radius_x1 and radius_y1 are in pixels, etc
  1558.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1559.         @ will shrink / expand on zoom out / zoom in
  1560.         @%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
  1561.         */
  1562.  
  1563.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1564.             fill_color = stroke_color;
  1565.             i=1;
  1566.             while( ! done ){     /* get next item until EOL*/
  1567.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1568.                 switch (i%4){
  1569.                  case 1:double_data[i-1] = get_real(infile,0);break; /* x */
  1570.                  case 2:double_data[i-1] = get_real(infile,0);break; /* y */
  1571.                  case 3:double_data[i-1] = get_real(infile,0);break; /* rx */
  1572.                  case 0:double_data[i-1] = get_real(infile,1);break; /* ry */
  1573.                  default: break;
  1574.                 }
  1575.                 i++;
  1576.             }
  1577.             decimals = find_number_of_digits(precision);
  1578.             for(c = 0 ; c < i-1 ; c = c+4){
  1579.              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);
  1580.              if(onclick > 0 || slider_cnt > 0){click_cnt++;} /* click_cnt++; */
  1581.             }
  1582.             reset();
  1583.             break;
  1584.  
  1585.         case FILLALL:
  1586.         /*
  1587.         @ fillall color,x1,y1,x2,y2...x_n,y_n
  1588.         @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color ''color``.
  1589.         @ any other colors (objects) in the <a href='#canvastype'>canvastype</a> will act as border to the bucket fill.
  1590.         @ use this command after all boundary objects are declared.
  1591.         @ Use command ''userdraw clickfill,color`` for user click driven flood fill.
  1592.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5).
  1593.         @ 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..
  1594.         @%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
  1595.         */
  1596.             decimals = find_number_of_digits(precision);
  1597.             fill_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1598.             i=0;
  1599.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1600.              js_function[DRAW_FILLTOBORDER] = 1;
  1601.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1602.             }
  1603.             while( ! done ){     /* get next item until EOL*/
  1604.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1605.                 if(i%2 == 0 ){
  1606.                     double_data[i] = get_real(infile,0); /* x */
  1607.                 }
  1608.                 else
  1609.                 {
  1610.                     double_data[i] = get_real(infile,1); /* y */
  1611.                     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);
  1612.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1613.                     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);
  1614.                     add_to_buffer(tmp_buffer);
  1615.                     fill_cnt++;
  1616.                 }
  1617.                 i++;
  1618.             }
  1619.         break;
  1620.  
  1621.         case FILLED:
  1622.         /*
  1623.         @ filled
  1624.         @ keyword (no arguments required)
  1625.         @ the next ''fillable`` object (only the next !) will be filled
  1626.         @ use command <a href="#fillcolor">fillcolor color</a> to set fillcolor
  1627.         @ use <a href="#fillpattern">fillpattern</a> for non-solid color filling.
  1628.         @ use command <code>opacity 0-255,0-255</code> to set stroke and fill-opacity
  1629.         @ 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 !
  1630.         */
  1631.             use_filled = 1;
  1632.             use_pattern = 0;
  1633.             break;
  1634.  
  1635.         case FILLCOLOR:
  1636.         /*
  1637.         @ fillcolor colorname or #hex
  1638.         @ set the color: mainly used for command ''userdraw obj,stroke_color``
  1639.         @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...)
  1640.         @ see <a href="#fillpattern">fillpattern</a> for non-solid color filling.
  1641.         */
  1642.             fill_color = get_color(infile,1);
  1643.             use_pattern = 0;
  1644.             break;
  1645.  
  1646.         case FILLPATTERN:
  1647.         /*
  1648.         @ fillpattern grid | hatch | diamond | dot | image-url
  1649.         @ use a pattern as fillstyle
  1650.         @ suitable for all fillable object including the <a href="#userdraw">userdraw objects' family</a>
  1651.         @ not -yet- implemented in the <a href="#multidraw">multidraw objects family</a>...(will probably be too complex)
  1652.         @ 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>
  1653.         @ the pattern dimensions are hardcoded (linewidth, radius,dx,dy are fixed)
  1654.         @ the pattern color is set by command <a href='#fillcolor'>fillcolor</a> and <a href='#opacity'>opacity</a>
  1655.         @ see <a href="#fillcolor">fillcolor</a> for solid color filling.
  1656.         @ 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>
  1657.         @ 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.
  1658.         @%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
  1659.         @%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
  1660.         */
  1661.             temp = get_string(infile,1);
  1662.             if( strstr(temp,"grid") != 0 ){ use_pattern = 2;use_filled = 2;} /* use_pattern is used in dragstuff library */
  1663.             else
  1664.             if( strstr(temp,"hatch") != 0 ){ use_pattern = 3;use_filled = 3;}
  1665.             else
  1666.             if( strstr(temp,"diamond") != 0 ){ use_pattern = 4;use_filled = 4;}
  1667.             else
  1668.             if( strstr(temp,"dot") != 0 ){ use_pattern = 5;use_filled = 5;}
  1669.             else
  1670.             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); }
  1671.             else
  1672.             canvas_error("fillpattern unknown or typo...choose grid,hatch,diamond of dot...");
  1673.             break;
  1674.         case FILLTOBORDER:
  1675.         /*
  1676.         @ filltoborder x,y,bordercolor,color
  1677.         @ fill the region of point (x:y) with color ''color``
  1678.         @ any other color will not act as border to the bucket fill
  1679.         @ use this command after all boundary objects are declared.
  1680.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1681.         @ 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..
  1682.         @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a>
  1683.         @%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
  1684.         */
  1685.             for(i=0 ;i < 4 ; i++){
  1686.                 switch(i){
  1687.                     case 0:double_data[0] = get_real(infile,0);break;
  1688.                     case 1:double_data[1] = get_real(infile,0);break;
  1689.                     case 2:bgcolor = get_color(infile,0);break;
  1690.                     case 3:fill_color = get_color(infile,1);
  1691.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1692.                                 js_function[DRAW_FILLTOBORDER] = 1;
  1693.                                 add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1694.                            }
  1695.                            decimals = find_number_of_digits(precision);
  1696.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  1697.                            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);
  1698.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1699.                            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);
  1700.                            add_to_buffer(tmp_buffer);
  1701.                            fill_cnt++;
  1702.                            break;
  1703.                     default:break;
  1704.                 }
  1705.             }
  1706.             reset();
  1707.         break;
  1708.         case FLOODFILL:
  1709.         /*
  1710.         @ floodfill x,y,color
  1711.         @ alternative: <code>fill x,y,color</code>
  1712.         @ fill the region of point (x:y) with color ''color``
  1713.         @ any other color or size of picture (borders of picture) will act as border to the bucket fill
  1714.         @ use this command after all boundary objects are declared.
  1715.         @ Use command <code>userdraw clickfill,color</code> for user click driven flood fill.
  1716.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1717.         @ 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..
  1718.         @%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
  1719.         */
  1720.             for(i=0 ;i < 4 ; i++){
  1721.                 switch(i){
  1722.                     case 0:double_data[0] = get_real(infile,0);break;
  1723.                     case 1:double_data[1] = get_real(infile,0);break;
  1724.                     case 2:fill_color = get_color(infile,1);
  1725.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1726.                                 js_function[DRAW_FILLTOBORDER] = 1;
  1727.                                 add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1728.                            }
  1729.                            decimals = find_number_of_digits(precision);
  1730.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  1731.                            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);
  1732.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1733.                            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);
  1734.                            add_to_buffer(tmp_buffer);
  1735.                            fill_cnt++;
  1736.                            break;
  1737.                     default:break;
  1738.                 }
  1739.             }
  1740.             reset();
  1741.         break;
  1742.  
  1743.         case FONTCOLOR:
  1744.         /*
  1745.          @ fontcolor color
  1746.          @ color: hexcolor or colorname
  1747.          @ default: black
  1748.          @ use command <a href="#fontfamily'>fontfamily</a> to deviate from default font type
  1749.          @%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
  1750.         */
  1751.             font_color = get_color(infile,1);
  1752.             break;
  1753.  
  1754.         case FONTFAMILY:
  1755.         /*
  1756.          @ fontfamily font_description
  1757.          @ set the font family; for browsers that support it
  1758.          @ font_description: Arial, Courier, Helvetica etc
  1759.          @ 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 Arial</code>. Use correct syntax: ''font style``, ''font size pt``, ''fontfamily``
  1760.          @%fontfamily%size 400,400%xrange -10,10%yrange -10,10  %fontfamily Bold 10pt Arial%string blue,-9,9,10 pt Arial%fontfamily Italic 20pt Arial%string blue,0,9,20 pt Arial%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
  1761.  
  1762.         */
  1763.             font_family = get_string(infile,1);
  1764.             break;
  1765.  
  1766.         case FONTSIZE:
  1767.         /*
  1768.          @ fontsize font_size
  1769.          @ default value 12
  1770.          @ 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, this is however not always very straight forward... so just try and see what happens.
  1771.         */
  1772.             font_size = (int) (get_real(infile,1));
  1773.             break;
  1774.  
  1775.         case FUNCTION_LABEL:
  1776.         /*
  1777.          @ functionlabel some string
  1778.          @ default value ''f(x)=``
  1779.          @ no mathml allowed (just ascii string)
  1780.          @ use command <a href='#fontsize'>fontsize int</a> to adjust the size
  1781.          @ use command <a href='#strokecolor'>strokecolor colorname</a> to adjust the labels (individually, if needed)
  1782.          @ if needed, use before every command <a href='#userinput'>userinput function | inputfield | textarea</a>
  1783.          @ no limit in amount of inputfields for userbased function plotting.
  1784.         */
  1785.             function_label = get_string_argument(infile,1);
  1786.             break;
  1787.  
  1788.         case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px), axis/tickscolor]*/
  1789.         /*
  1790.          @ grid step_x,step_y,gridcolor
  1791.          @ 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
  1792.          @ 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,Arial
  1793.          @ 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)
  1794.          @ can <b>not</b> be set <a href="#onclick">onclick</a> or <a href="#drag">drag xy</a>
  1795.          @ 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 Arial' !
  1796.          @ 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 Arial')
  1797.          @ 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 Arial')
  1798.          @%grid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%zoom red
  1799.          @%grid_axis%size 400,400%xrange -10,10%yrange -10,10%axis%grid 1,1,grey,2,2,6,black%zoom red
  1800.          @%grid_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red
  1801.         */
  1802.             if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
  1803.             if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
  1804.             for(i=0;i<4;i++){
  1805.                 switch(i){
  1806.                     case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
  1807.                     case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
  1808.                     case 2:
  1809.                     if( use_axis == TRUE ){
  1810.                         stroke_color = get_color(infile,0);
  1811.                         done = FALSE;
  1812.                         int_data[0] = (int) (get_real(infile,0));/* xminor */
  1813.                         int_data[1] = (int) (get_real(infile,0));/* yminor */
  1814.                         int_data[2] = (int) (get_real(infile,0));/* tic_length */
  1815.                         fill_color = get_color(infile,1); /* used as axis_color*/
  1816.                     }
  1817.                     else
  1818.                     {
  1819.                         int_data[0] = 1;
  1820.                         int_data[1] = 1;
  1821.                         stroke_color = get_color(infile,1);
  1822.                         fill_color = stroke_color;
  1823.                     }
  1824.                     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 !");}
  1825.                     /* set snap_x snap_y values in pixels */
  1826.                     fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
  1827.                     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);
  1828.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1829.                     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);
  1830.                     add_to_buffer(tmp_buffer);
  1831.                     break;
  1832.                 }
  1833.             }
  1834.             reset();
  1835.             break;
  1836.         case GRIDFILL:
  1837.         /*
  1838.         @ gridfill x0,y0,dx,dy,color
  1839.         @ x0,y0 in xrange / yrange
  1840.         @ distances dx,dy in pixels
  1841.         @ there is also a command <a href="#userdraw">userdraw gridfill,color</a>
  1842.         @%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
  1843.  
  1844.         */
  1845.             if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
  1846.             decimals = find_number_of_digits(precision);
  1847.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1848.              js_function[DRAW_FILLTOBORDER] = 1;
  1849.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  1850.             }
  1851.             for(i=0;i<5;i++){
  1852.                 switch(i){
  1853.                     case 0: double_data[0] = get_real(infile,0); break; /* x  */
  1854.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  1855.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1856.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1857.                     case 4: stroke_color = get_color(infile,1);
  1858.                     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);
  1859.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1860.                     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);
  1861.                     add_to_buffer(tmp_buffer);
  1862.                     fill_cnt++;
  1863.                     break;
  1864.                     default:break;
  1865.                 }
  1866.             }
  1867.             reset();
  1868.         break;
  1869.  
  1870.         case HALFLINE:
  1871.         /*
  1872.         @ demiline x1,y1,x2,y2,color
  1873.         @ alternative: <code>halfline</code>
  1874.         @ draws a halfline starting in (x1:y1) and through (x2:y2) in color ''color`` (colorname or hex)
  1875.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1876.         @%halfline%size 400,400%xrange -10,10%yrange -10,10%halfline -5,5,0,0,red%halfline -5,-5,0,0,blue
  1877.         */
  1878.             for(i=0;i<5;i++){
  1879.                 switch(i){
  1880.                     case 0: double_data[0]= get_real(infile,0);break; /* x-values */
  1881.                     case 1: double_data[1]= get_real(infile,0);break; /* y-values */
  1882.                     case 2: double_data[10]= get_real(infile,0);break; /* x-values */
  1883.                     case 3: double_data[11]= get_real(infile,0);break; /* y-values */
  1884.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  1885.                     if(double_data[0] == double_data[10]){ /* vertical halfline */
  1886.                         if(double_data[1] < double_data[11]){
  1887.                          double_data[3] = ymax + 1000;
  1888.                         }
  1889.                         else
  1890.                         {
  1891.                          double_data[3] = ymin - 1000;
  1892.                         }
  1893.                         double_data[2] = double_data[0];
  1894.                     }
  1895.                     else
  1896.                     { /* horizontal halfline*/
  1897.                      if( double_data[1] == double_data[11] ){
  1898.                       if( double_data[0] < double_data[10] ){
  1899.                         double_data[2] = xmax + 1000; /* halfline to the right */
  1900.                       }
  1901.                       else
  1902.                       {
  1903.                         double_data[2] = xmin - 1000; /* halfline to the left */
  1904.                       }
  1905.                       double_data[3] = double_data[1];
  1906.                      }
  1907.                      else
  1908.                      {
  1909.                       /* any other halfline */
  1910.                       /* slope */
  1911.                       double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
  1912.                       /* const */
  1913.                       double_data[13] = double_data[1] - double_data[12]*double_data[0];
  1914.                       if( double_data[0] < double_data[10] ){
  1915.                        double_data[2] = double_data[2] + 1000;
  1916.                       }
  1917.                       else
  1918.                       {
  1919.                        double_data[2] = double_data[2] - 1000;
  1920.                       }
  1921.                       double_data[3] = double_data[12]*double_data[2] + double_data[13];
  1922.                      }
  1923.                     }
  1924.                     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);
  1925.                     if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1926.                     /* click_cnt++; */
  1927.                     reset();
  1928.                     break;
  1929.                 }
  1930.             }
  1931.             break;
  1932.  
  1933.         case HALFLINES:
  1934.         /*
  1935.         @ demilines color,x1,y1,x2,y2,....
  1936.         @ alternative: <code>halflines</code>
  1937.         @ draws halflines starting in (x1:y1) and through (x2:y2) in color ''color`` (colorname or hex) etc
  1938.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually
  1939.         @%halflines%size 400,400%xrange -10,10%yrange -10,10%halflines red,-5,5,0,0,-5,-5,0,0
  1940.         */
  1941.             stroke_color=get_color(infile,0);
  1942.             fill_color = stroke_color;
  1943.             i=0;
  1944.             while( ! done ){     /* get next item until EOL*/
  1945.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1946.                 if(i%2 == 0 ){
  1947.                     double_data[i] = get_real(infile,0); /* x */
  1948.                 }
  1949.                 else
  1950.                 {
  1951.                     double_data[i] = get_real(infile,1); /* y */
  1952.                 }
  1953.                 i++;
  1954.             }
  1955.             decimals = find_number_of_digits(precision);
  1956.             for(c = 0 ; c < i-1 ; c = c+4){
  1957.                 if( double_data[c] == double_data[c+2] ){ /* vertical line*/
  1958.                     if(double_data[c+1] < double_data[c+3]){ /* upright halfline */
  1959.                         double_data[c+3] = ymax + 1000;
  1960.                     }
  1961.                     else
  1962.                     {
  1963.                      double_data[c+3] = ymin - 1000;/* descending halfline */
  1964.                     }
  1965.                 }
  1966.                 else
  1967.                 {
  1968.                     if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  1969.                         if(double_data[c] < double_data[c+2] ){ /* halfline to the right */
  1970.                             double_data[c+2] = xmax+100;
  1971.                         }
  1972.                         else
  1973.                         {
  1974.                             double_data[c+2] = xmin-1000; /* halfline to the right */
  1975.                         }
  1976.                     }
  1977.                     else
  1978.                     {
  1979.                         /* m */
  1980.                         double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  1981.                         /* q */
  1982.                         double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  1983.                         if(double_data[c] < double_data[c+2]){ /* to the right */
  1984.                             double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it is just segment */
  1985.                             double_data[c+3] = (m)*(double_data[c+2])+(q);
  1986.                         }
  1987.                         else
  1988.                         { /* to the left */
  1989.                             double_data[c+2] = xmin - 1000;
  1990.                             double_data[c+3] = (m)*(double_data[c+2])+(q);
  1991.                         }
  1992.                     }
  1993.                 }
  1994.                 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);
  1995.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  1996.                 /* click_cnt++; */
  1997.             }
  1998.             reset();
  1999.             break;
  2000.         case HATCHFILL:
  2001.         /*
  2002.         @ hatchfill x0,y0,dx,dy,color
  2003.         @ x0,y0 in xrange / yrange
  2004.         @ distances dx,dy in pixels
  2005.         @ there is also a command <a href="#userdraw">userdraw hatchfill,color</a>
  2006.         @%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
  2007.         */
  2008.             if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
  2009.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2010.              js_function[DRAW_FILLTOBORDER] = 1;
  2011.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  2012.             }
  2013.             decimals = find_number_of_digits(precision);
  2014.             for(i=0;i<5;i++){
  2015.                 switch(i){
  2016.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  2017.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  2018.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  2019.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2020.                     case 4: stroke_color = get_color(infile,1);
  2021.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2022.                     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);
  2023.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2024.                     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);
  2025.                     add_to_buffer(tmp_buffer);
  2026.                     fill_cnt++;
  2027.                     break;
  2028.                     default:break;
  2029.                 }
  2030.             }
  2031.             reset();
  2032.         break;
  2033.  
  2034.         case HLINE:
  2035.         /*
  2036.         @ hline x,y,color
  2037.         @ alternative: <code>horizontalline</code>
  2038.         @ draw a horizontal line through point (x:y) in color ''color``
  2039.         @ 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).
  2040.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2041.         @%hline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hline 0,0,red%dhline 0,5,blue
  2042.         */
  2043.             for(i=0;i<3;i++) {
  2044.                 switch(i){
  2045.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  2046.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  2047.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  2048.                     double_data[3] = double_data[1];
  2049.                     decimals = find_number_of_digits(precision);
  2050.                     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);
  2051.                     if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  2052.                     /* click_cnt++; */
  2053.                     reset();
  2054.                     break;
  2055.                 }
  2056.             }
  2057.             break;
  2058.  
  2059.         case HLINES:
  2060.         /*
  2061.         @ hlines color,x1,y1,x2,y2,...
  2062.         @ alternative: <code>horizontallines</code>
  2063.         @ draw horizontal lines through points (x1:y1)...(xn:yn) in color ''color``
  2064.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  2065.         @%hlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hlines red,0,0,0,5,0,-5
  2066.         */
  2067.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  2068.             fill_color = stroke_color;
  2069.             i=0;
  2070.             while( ! done ){     /* get next item until EOL*/
  2071.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2072.                 if(i%2 == 0 ){
  2073.                     double_data[i] = get_real(infile,0); /* x */
  2074.                 }
  2075.                 else
  2076.                 {
  2077.                     double_data[i] = get_real(infile,1); /* y */
  2078.                 }
  2079.                 i++;
  2080.             }
  2081.             decimals = find_number_of_digits(precision);
  2082.             for(c = 0 ; c < i-1 ; c = c+2){
  2083.                 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);
  2084.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  2085.                 /* click_cnt++; */
  2086.             }
  2087.             reset();
  2088.             break;
  2089.         case HTTP:
  2090.         /*
  2091.          @ http x1,y1,x2,y2,http://some_adress.com
  2092.          @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1), right bottom (x2:y2)
  2093.          @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe
  2094.          @ can <b>not</b> be ''set onclick`` or ''drag xy``
  2095.          @%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
  2096.         */
  2097.             if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}
  2098.             for(i=0;i<5;i++){
  2099.                 switch(i){
  2100.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2101.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2102.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  2103.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  2104.                     case 4: decimals = find_number_of_digits(precision);
  2105.                             temp = get_string(infile,1);
  2106.                             if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
  2107.                             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);
  2108.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+2);
  2109.                             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);
  2110.                             add_to_buffer(tmp_buffer);
  2111.                     break;
  2112.                 }
  2113.             }
  2114.             reset();
  2115.             break;
  2116.         case HTML:
  2117.         /*
  2118.          @ html x1,y1,x2,y2,html_string
  2119.          @ all tags are allowed, html code using inputfields could be read using your own javascript code. Do not use ids like 'canvas_input0' etc.
  2120.          @ can be set onclick (however dragging not supported)
  2121.          @ use keyword <a href='#centered'>centered</a> to center the html object on (x1:y1)
  2122.          @%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
  2123.         */
  2124.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  2125.             for(i=0;i<5;i++){
  2126.                 switch(i){
  2127.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2128.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2129.                     case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed: overflow  */
  2130.                     case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed: overflow */
  2131.                     case 4: decimals = find_number_of_digits(precision);
  2132.                             temp = get_string(infile,1);
  2133.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2134.                             string_length = 1 + snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%f);\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,angle);
  2135.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2136.                             snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%f);\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,angle);
  2137.                             add_to_buffer(tmp_buffer);
  2138.                             if(onclick == 1 || onclick == 2 ){click_cnt++;}
  2139.                             use_offset = 0;
  2140.                             break;
  2141.                     default:break;
  2142.                 }
  2143.             }
  2144.             break;
  2145.  
  2146.         case IMAGEFILL:
  2147.         /*
  2148.         @ imagefill x,y,scaling to xsize &times; ysize?,image_url
  2149.         @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
  2150.         @ scaling to xsize &times; ysize ? ... 1 = yes 0 = no
  2151.         @ After pattern filling, the fill-color should be reset !
  2152.         @ wims getins / image from class directory: imagefill 80,80,my_image.gif
  2153.         @ normal url: imagefill 80,80,0,$module_dir/gifs/my_image.gif
  2154.         @ normal url: imagefill 80,80,1,http://adres/a/b/c/my_image.jpg
  2155.         @ if dx,dy is larger than the image, the whole image will be background to the next object.
  2156.         @%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
  2157.         @%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
  2158.         */
  2159.             if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
  2160.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2161.              js_function[DRAW_FILLTOBORDER] = 1;
  2162.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  2163.             }
  2164.             for(i=0 ;i < 4 ; i++){
  2165.                 switch(i){
  2166.                     case 0:int_data[0] = (int) (get_real(infile,0));break;
  2167.                     case 1:int_data[1] = (int) (get_real(infile,0));break;
  2168.                     case 2:int_data[2] = (int) (get_real(infile,0));break; /* 0 | 1 */
  2169.                     case 3: URL = get_string_argument(infile,1);
  2170.                             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]);
  2171.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2172.                             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]);
  2173.                             add_to_buffer(tmp_buffer);
  2174.                             fill_cnt++;
  2175.                     break;
  2176.                 }
  2177.             }
  2178.             reset();
  2179.         break;
  2180.  
  2181.         case IMAGEPALETTE:
  2182.         /*
  2183.          @ imagepalette image1,image2,image3,...
  2184.          @ 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``.
  2185.          @%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 Arial%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
  2186.          */
  2187.            temp = get_string(infile,1);
  2188.            temp = str_replace(temp,",","\",\"");
  2189.             if( use_tooltip == 1 ){canvas_error("command 'imagepalette' is incompatible with command 'intooltip tip_text',as they use the same div-element ");}
  2190.             fprintf(js_include_file,"\nvar current_id;var imagepalette = [\" %s \"];\n",temp);
  2191.         break;
  2192.  
  2193.         case INPUTSTYLE:
  2194.         /*
  2195.         @ inputstyle style_description
  2196.         @ may be used before any ''style-able`` html object (like inputfields or buttons) or any html objects that are generated by some canvasdraw commands
  2197.         @%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
  2198.         */
  2199.             input_style = get_string(infile,1);
  2200.             break;
  2201.         case INPUT:
  2202.         /*
  2203.          @ input x,y,size,editable,value
  2204.          @ to set inputfield "readonly", use editable = 0
  2205.          @ only active inputfields (editable = 1) will be read with read_canvas();
  2206.          @ 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>.
  2207.          @ may be further controlled by <a href="#inputstyle">inputstyle</a> (inputcss is not yet implemented...)
  2208.          @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
  2209.          @ 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)
  2210.          @ 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>
  2211.          @%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, ?
  2212.         */
  2213.         if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  2214.             for(i = 0 ; i<5;i++){
  2215.                 switch(i){
  2216.                     case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
  2217.                     case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
  2218.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
  2219.                     case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
  2220.                     case 4:
  2221.                             temp = get_string_argument(infile,1);
  2222.                             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);
  2223.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2224.                             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);
  2225.                             add_to_buffer(tmp_buffer);
  2226.                             input_cnt++;break;
  2227.                     default: break;
  2228.                 }
  2229.             }
  2230.             if(reply_format == 0 ){reply_format = 15;}
  2231.             reset();
  2232.             break;
  2233.  
  2234.         case INTOOLTIP:
  2235.             /*
  2236.             @ intooltip link_text
  2237.             @ link_text is a single line (span-element)
  2238.             @ link_text may also be an image URL ''http://some_server/images/my_image.png`` or ''$module_dir/gifs/my_image.jpg``
  2239.             @ link_text may contain HTML markup
  2240.             @ the canvas will be displayed in a tooltip on ''link_text``
  2241.             @ 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``.
  2242.             @ 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...
  2243.             @%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>
  2244.             */
  2245.             if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");}
  2246.             if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");}
  2247.             tooltip_text = get_string(infile,1);
  2248.             if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
  2249.             use_tooltip = 1;
  2250.             break;
  2251.  
  2252.         case JSCURVE:
  2253.         /*
  2254.          @ jscurve color,formula1(x),formula2(x),formula3(x),...
  2255.          @ alternative: <code>jsplot color,formula(x)</code>
  2256.          @ your function will be plotted by the javascript engine of the client browser
  2257.          @ 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
  2258.          @ use only basic math in your curve: <code>sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e</code>
  2259.          @ use parenthesis and rawmath: use 2*x instead of 2x ; use 2^(sin(x))...etc etc (use error console to debug any errors...)
  2260.          @ <b>attention</b>: last ''precision`` command in the canvasdraw script determines the calculation precision of the javascript curve plot !
  2261.          @ no validity check is done by wims.
  2262.          @ 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
  2263.          @ 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
  2264.          @ use keyword <a href='animate'>animate</a> for animating a point on the curve
  2265.          @ use command ''trace_jscurve formula(x)`` for tracing
  2266.          @ use command ''jsmath formula(x)`` for calculating and displaying indiviual points on the curve
  2267.          @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet)
  2268.          @ commands plotjump / plotstep are not active for ''jscurve``
  2269.          @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve.
  2270.          @ 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...)
  2271.          @%jscurve%size 400,400%xrange -10,10%yrange -10,10%multistrokecolors red,green,blue,orange%multilinewidth 1,2,3%multistrokeopacity 0.5,0.8,1.0%jscurve red,sin(x),1/sin(x),sin(x^2)
  2272.         */
  2273.             stroke_color = get_color(infile,0);
  2274.             if( use_js_math == FALSE){/* add this stuff only once...*/
  2275.                 add_to_js_math(js_include_file);
  2276.                 use_js_math = TRUE;
  2277.             }
  2278.             if( use_js_plot == FALSE){
  2279.                 use_js_plot = TRUE;
  2280.                 add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  2281.             }
  2282.             int use_paramteric = 0;
  2283.             if( tmin != 0 && tmax !=0){use_parametric = 1;}
  2284.             temp = get_string(infile,1);
  2285.             temp = str_replace(temp,",","\",\"");
  2286.             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);
  2287.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2288.             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);
  2289.             add_to_buffer(tmp_buffer);
  2290.             jsplot_cnt++;
  2291.              /* we need to create multiple canvasses, so we may zoom and pan ?? */
  2292.         break;
  2293.  
  2294.         case JSMATH:
  2295.         /*
  2296.             @ jsmath some_math_function
  2297.             @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
  2298.             @ 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
  2299.             @ use command 'inputstyle some_css' for styling the display fields. Use command 'fontsize int' to size the labels ''x`` and ''y``
  2300.             @ 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...
  2301.             @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
  2302.             @%jsmath%size 400,400%xrange -10,10%yrange -10,10%jsplot blue,sin(x^2)%jsmath sin(x^2)
  2303.         */
  2304.             if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  2305.             if( use_js_math == FALSE){
  2306.                 add_to_js_math(js_include_file);
  2307.                 use_js_math = TRUE;
  2308.             }
  2309.             add_calc_y(js_include_file,canvas_root_id,get_string(infile,1),font_size,input_style);
  2310.             break;
  2311.         case KILLAFFINE:
  2312.         /*
  2313.         @ killaffine
  2314.         @ keyword: resets the transformation matrix to 1,0,0,1,0,0
  2315.         */
  2316.             if( use_affine == TRUE ){
  2317.              use_affine = FALSE;
  2318.              affine_matrix="[1,0,0,1,0,0]";
  2319.             }
  2320.             break;
  2321.  
  2322.         case KILLROTATE:
  2323.         /*
  2324.          @ killrotate
  2325.          @ will reset the command <a href="#rotationcenter">rotationcenter xc,yc</a>
  2326.          @ a following rotate command will have the first object point as rotation center
  2327.          @ if not set, the rotation center will remain unchanged
  2328.         */
  2329.             rotation_center="null";;
  2330.             angle = 0.0;
  2331.          break;
  2332.  
  2333.         case KILLSLIDER:
  2334.         /*
  2335.          @ killslider
  2336.          @ keyword (no arguments required)
  2337.          @ ends grouping of object under a previously defined slider
  2338.         */
  2339.             slider_type = "0";
  2340.             current_sliders = "[-1]";
  2341.             for(i=0;i<slider_cnt;i++){active_sliders[i]=-1;}
  2342.             break;
  2343.  
  2344.         case KILLTRANSLATION:
  2345.         /*
  2346.          @ killtranslation
  2347.          @ alternative: <code>killtranslate</code>
  2348.          @ resets the translation matrix to 1,0,0,1,0,0
  2349.         */
  2350.             if(use_affine == TRUE ){
  2351.              use_affine = FALSE;
  2352.              affine_matrix="[1,0,0,1,0,0]";
  2353.             }
  2354.             break;
  2355.         case LATEX:
  2356.         /*
  2357.          @ latex x,y,latex string
  2358.          @ 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
  2359.          @ 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...
  2360.          @ 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
  2361.          @ 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
  2362.          @ userdraw may be combined with ''mathml`` ; the read_canvas() will contain the drawing.
  2363.          @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick mathml
  2364.          @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret...
  2365.          @ 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();"
  2366.          @ 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....
  2367.          @ use keyword <a href='#centered'>centered</a> to center the katex div object on (x1:y1)
  2368.          @%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}
  2369.          @%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}
  2370.         */
  2371.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  2372.             drag_type=-1; /* hmmm */
  2373.             for(i=0;i<4;i++){
  2374.                 switch(i){
  2375.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2376.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2377.                     case 2: decimals = find_number_of_digits(precision);
  2378.                             temp = get_string(infile,1);
  2379. /*          !!!! UNTIL MATHJAX IS REPLACED BY KATEX !!!!       */
  2380.                             browser_type = 1;
  2381.                             if(browser_type == 1 ){ /* GECKO needs  TEX --> MML  */
  2382.                              temp = getMML(temp);
  2383.                              if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2384.                              string_length = 1 + snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%f);\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,angle);
  2385.                              check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2386.                              snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%f);\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,angle);
  2387.                             }
  2388.                             else
  2389.                             {
  2390.                              if( strstr(temp,"\\") != 0 ){ temp = str_replace(temp,"\\","\\\\"); }
  2391.                              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,%f);\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,angle);
  2392.                              check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2393.                              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,%f);\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,angle);
  2394.                             }
  2395.                             add_to_buffer(tmp_buffer);
  2396.                             if(onclick == 1 || onclick == 2 ){click_cnt++;}
  2397.                             use_offset = 0;
  2398.                             break;
  2399.                     default:break;
  2400.                 }
  2401.             }
  2402.             break;
  2403.         case LATTICE:
  2404.         /*
  2405.          @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
  2406.          @ can <b>not</b> be set ''onclick`` or ''drag xy``
  2407.          @%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
  2408.         */
  2409.             if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
  2410.             for( i = 0; i<9; i++){
  2411.                 switch(i){
  2412.                     case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
  2413.                     case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
  2414.                     case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
  2415.                     case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
  2416.                     case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
  2417.                     case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
  2418.                     case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
  2419.                     case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
  2420.                     case 8: stroke_color=get_color(infile,1);
  2421.                         decimals = find_number_of_digits(precision);
  2422.                         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);
  2423.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2424.                         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);
  2425.                         add_to_buffer(tmp_buffer);break;
  2426.                     default:break;
  2427.                 }
  2428.             }
  2429.             reset();
  2430.             break;
  2431.  
  2432.         case LINE:
  2433.         /*
  2434.         @ line x1,y1,x2,y2,color
  2435.         @ draw a line through points (x1:y1)--(x2:y2) in color ''color``
  2436.         @ or use command ''curve color,formula`` to draw the line (uses more points to draw the line; is however better draggable).
  2437.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2438.         @%line%size 400,400%xrange -10,10%yrange -10,10%line 0,1,2,-1,green
  2439.         */
  2440.             for(i=0;i<5;i++){
  2441.                 switch(i){
  2442.                     case 0: double_data[10]= get_real(infile,0);break; /* x-values */
  2443.                     case 1: double_data[11]= get_real(infile,0);break; /* y-values */
  2444.                     case 2: double_data[12]= get_real(infile,0);break; /* x-values */
  2445.                     case 3: double_data[13]= get_real(infile,0);break; /* y-values */
  2446.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  2447.                     if( double_data[10] == double_data[12] ){ /* vertical line*/
  2448.                         double_data[1] = xmin;
  2449.                         double_data[3] = ymax;
  2450.                         double_data[0] = double_data[10];
  2451.                         double_data[2] = double_data[10];
  2452.                     }
  2453.                     else
  2454.                     {
  2455.                         if( double_data[11] == double_data[13] ){ /* horizontal line */
  2456.                             double_data[1] = double_data[11];
  2457.                             double_data[3] = double_data[11];
  2458.                             double_data[0] = ymin;
  2459.                             double_data[2] = xmax;
  2460.                         }
  2461.                         else
  2462.                         {
  2463.                         /* m */
  2464.                         double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
  2465.                         /* q */
  2466.                         double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
  2467.  
  2468.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  2469.  
  2470.                             double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
  2471.                             double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
  2472.                             double_data[0] = xmin;
  2473.                             double_data[2] = xmax;
  2474.                         }
  2475.                     }
  2476.                     decimals = find_number_of_digits(precision);
  2477.                     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);
  2478.                     if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  2479.                     /* click_cnt++;*/
  2480.                     reset();
  2481.                     break;
  2482.                 }
  2483.             }
  2484.             break;
  2485.  
  2486.         case LINES:
  2487.         /*
  2488.         @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n
  2489.         @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color ''color``
  2490.         @ 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).
  2491.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2492.         @ <b>attention</b>: the flydraw command ''lines`` is equivalent to canvasdraw command <a href="#polyline">polyline</a>
  2493.         @%lines%size 400,400%xrange -10,10%yrange -10,10%lines green,0,1,1,3,0,0,1,3,0,0,-2,1
  2494.         */
  2495.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  2496.             fill_color = stroke_color;
  2497.             i=0;
  2498.             while( ! done ){     /* get next item until EOL*/
  2499.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2500.                 if(i%2 == 0 ){
  2501.                     double_data[i] = get_real(infile,0); /* x */
  2502.                 }
  2503.                 else
  2504.                 {
  2505.                     double_data[i] = get_real(infile,1); /* y */
  2506.                 }
  2507.                 i++;
  2508.             }
  2509.             decimals = find_number_of_digits(precision);
  2510.             for(c = 0 ; c < i-1 ; c = c+4){
  2511.                 if( double_data[c] == double_data[c+2] ){ /* vertical line*/
  2512.                     double_data[c+1] = xmin;
  2513.                     double_data[c+3] = ymax;
  2514.                     double_data[c+2] = double_data[c];
  2515.                 }
  2516.                 else
  2517.                 {
  2518.                     if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  2519.                         double_data[c+3] = double_data[c+1];
  2520.                         double_data[c] = ymin;
  2521.                         double_data[c+2] = xmax;
  2522.                     }
  2523.                     else
  2524.                     {
  2525.                         /* m */
  2526.                         double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  2527.                         /* q */
  2528.                         double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  2529.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  2530.                         double_data[c+1] = (m)*(xmin)+(q);
  2531.                         double_data[c+3] = (m)*(xmax)+(q);
  2532.                         double_data[c] = xmin;
  2533.                         double_data[c+2] = xmax;
  2534.                     }
  2535.                 }
  2536.                 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);
  2537.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  2538.                 /* click_cnt++; */
  2539.             }
  2540.             reset();
  2541.             break;
  2542.  
  2543.  
  2544.         case LINEWIDTH:
  2545.         /*
  2546.         @ linewidth int
  2547.         @ default 1
  2548.         @%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
  2549.         */
  2550.             line_width = (int) (get_real(infile,1));
  2551.             break;
  2552.  
  2553.         case LEVELCURVE:
  2554.         /*
  2555.         @ levelcurve color,expression in x/y,l1,l2,...
  2556.         @ draws very primitive level curves for expression, with levels l1,l2,l3,...,ln
  2557.         @ the quality is <b>not to be compared</b> with the Flydraw levelcurve (choose flydraw if you want quality...).
  2558.         @ 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.
  2559.         @ note: the arrays for holding the javascript data are limited in size.
  2560.         @ note: reduce image size if javascript data arrays get overloaded (command ''plotsteps int`` will not control the data size of the plot...).
  2561.         @%levelcurve%size 400,400%xrange -10,10%yrange -10,10%levelcurve red,x*y,1,2,3,4
  2562.         */
  2563.             fill_color = get_color(infile,0);
  2564.             char *fun1 = get_string_argument(infile,0);
  2565.             if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  2566.             i = 0;
  2567.             done = FALSE;
  2568.             while( !done ){
  2569.              double_data[i] = get_real(infile,1);
  2570.              i++;
  2571.             }
  2572.             for(c = 0 ; c < i; c++){
  2573.              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);
  2574.              if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  2575.              /* click_cnt++; */
  2576.             }
  2577.             reset();
  2578.             break;
  2579.  
  2580.         case LEGEND:
  2581.         /*
  2582.         @ legend string1:string2:string3....string_n
  2583.         @ will be used to create a legend for a graph
  2584.         @ also see command <a href='#piechart'>piechart</a>
  2585.         @ will use the same colors per default as used in the graphs; use command <a href='#legendcolors'>legendcolors</a> to override the default
  2586.         @ use command <a href="#fontsize">fontsize</a> to adjust. (command ''fontfamily`` is not active for command ''legend``).
  2587.         @%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
  2588.         */
  2589.             temp = get_string(infile,1);
  2590.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2591.             legend_cnt++; /* attention: starts with -1: it will be used in piechart etc */
  2592.             fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
  2593.             break;
  2594.  
  2595.         case LEGENDCOLORS:
  2596.         /*
  2597.         @ legendcolors color1:color2:color3:...:color_n
  2598.         @ 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>.
  2599.         @ make sure the number of colors match the number of legend items
  2600.         @ command ''legend`` in case of ''piechart`` and ''barchart`` will use these colours per default (no need to specify ''legendcolors``).
  2601.         @%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
  2602.         */
  2603.             if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
  2604.             temp = get_string(infile,1);
  2605.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2606.             fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
  2607.             break;
  2608.  
  2609.         case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed', 'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
  2610.         /*
  2611.         @ linegraph x1:y1:x2:y2...x_n:y_n
  2612.         @ will plot your data in a graph
  2613.         @ may <b>only</b> to be used together with command <a href='#grid'>grid</a>
  2614.         @ 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>
  2615.         @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner
  2616.         @ also see command <a href='#piechart'>piechart</a>
  2617.         @ multiple linegraphs may be used in a single plot
  2618.         @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble...
  2619.         @ <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>
  2620.         @%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
  2621.         */
  2622.             temp = get_string(infile,1);
  2623.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2624.             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);
  2625.             linegraph_cnt++;
  2626.             reset();
  2627.             break;
  2628.  
  2629.         case MATHML:
  2630.         /*
  2631.         @ mathml x1,y1,x2,y2,mathml_string
  2632.         @ this command is special for GECKO browsers, and it makes use of Native Mathml
  2633.         @ For use with all browsers, use command <a href='#latex'>latex</a>
  2634.         @ the mathml object is centered at (x1:y1)
  2635.         @ the ''mathml_string`` can be produced using WIMS commands like ''texmath`` followed by ''mathmlmath``... or write correct TeX and use only ''mathmlmath``
  2636.         @ 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.
  2637.         @ in case of drag(xy|x|y) | onclick the div rectangle left to corner will be the drag-anchor of the mathml object
  2638.         @ 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
  2639.         @ 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...
  2640.         @ 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.
  2641.         @ 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.
  2642.         @ userdraw may be combined with ''mathml`` ; the read_canvas() will contain the drawing.
  2643.         @ draggable or onclick ''external images`` from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick mathml
  2644.         @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret...
  2645.         @ 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();"
  2646.         @ 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....
  2647.         @ use keyword <a href='#centered'>centered</a> to center the mathml/xml object on (x1:y1)
  2648.         @%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>
  2649.         @%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...
  2650.         */
  2651.             if( browser_type == 0 ){ break;} /* should use command latex */
  2652.             if(use_offset == 0){use_offset = 4;} /* always centered if not otherwise stated ! */
  2653.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  2654.             for(i=0;i<5;i++){
  2655.                 switch(i){
  2656.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2657.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2658.                     case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed: overflow  */
  2659.                     case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed: overflow */
  2660.                     case 4: decimals = find_number_of_digits(precision);
  2661.                             temp = get_string(infile,1);
  2662.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2663.                             string_length = 1 + snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%f);\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,angle);
  2664.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2665.                             snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%f);\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,angle);
  2666.                             add_to_buffer(tmp_buffer);
  2667.                             if(onclick == 1 || onclick == 2 ){click_cnt++;}
  2668.                             use_offset=0;
  2669.                             /*
  2670.                              in case inputs are present, trigger adding the read_mathml()
  2671.                              if no other reply_format is defined
  2672.                              note: all other reply types will include a reading of elements with id='mathml'+p)
  2673.                              */
  2674.                             if(strstr(temp,"mathml0") != NULL){
  2675.                              if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
  2676.                             }
  2677.                             break;
  2678.                     default:break;
  2679.                 }
  2680.             }
  2681.             break;
  2682.  
  2683.         case MOUSE:
  2684.         /*
  2685.          @ mouse color,fontsize
  2686.          @ will display the cursor (x:y) coordinates in ''color`` and ''fontsize`` using default fontfamily Arial
  2687.          @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``)
  2688.          @%mouse%size 400,400%xrange -10,10%yrange -10,10%mouse red,22
  2689.         */
  2690.             stroke_color = get_color(infile,0);
  2691.             font_size = (int) (get_real(infile,1));
  2692.             tmp_buffer = my_newmem(26);
  2693.             snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2694.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
  2695.             break;
  2696.  
  2697.  
  2698.         case MOUSE_DEGREE:
  2699.         /*
  2700.          @ mouse_degree color,fontsize
  2701.          @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in ''color`` and ''font size`` using a fontfamily Arial
  2702.          @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
  2703.          @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``)
  2704.          @%mouse_degree%size 400,400%xrange -10,10%yrange -10,10%userdraw arc,blue%precision 100000%mouse_degree red,22
  2705.         */
  2706.             stroke_color = get_color(infile,0);
  2707.             font_size = (int) (get_real(infile,1));
  2708.             tmp_buffer = my_newmem(26);
  2709.             snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2710.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
  2711.             js_function[JS_FIND_ANGLE] = 1;
  2712.             break;
  2713.         case MOUSE_DISPLAY:
  2714.         /*
  2715.          @ display TYPE,color,fontsize
  2716.          @ TYPE may be <code>x | y | xy | degree | radian | radius</code>.
  2717.          @ 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).
  2718.          @ use commands ''xunit`` and / or ''yunit`` to add the units to the mouse values. The ''degree | radian`` will always have the appropriate symbol).
  2719.          @ just like commands ''mouse``, ''mousex``, ''mousey``, ''mouse_degree``... only other name
  2720.          @%display_x%size 400,400%xrange -10,10%yrange -10,10%xunit \\u212B%display x,red,22
  2721.          @%display_y%size 400,400%xrange -10,10%yrange -10,10%yunit seconds%display y,red,22
  2722.          @%display_xy%size 400,400%xrange -10,10%yrange -10,10%xunit centimetre%yunit seconds%display xy,red,22%userdraw segments,blue
  2723.          @%display_deg%size 400,400%xrange -10,10%yrange -10,10%display degree,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
  2724.          @%display_rad%size 400,400%xrange -10,10%yrange -10,10%display radian,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
  2725.          @%display_radius%size 400,400%xrange -10,10%yrange -10,10%xunit cm%xunit \\u212b%display radius,red,22%userdraw circle,blue
  2726.         */
  2727.         temp = get_string_argument(infile,0);
  2728.         if( strstr(temp,"xy") != NULL ){
  2729.             int_data[0] = 2;
  2730.         }else{
  2731.             if( strstr(temp,"y") != NULL ){
  2732.                 int_data[0] = 1;
  2733.             }else{
  2734.                 if( strstr(temp,"x") != NULL ){
  2735.                     int_data[0] = 0;
  2736.                 }else{
  2737.                     if(strstr(temp,"degree") != NULL){
  2738.                         int_data[0] = 3;
  2739.                         js_function[JS_FIND_ANGLE] = 1;
  2740.                     }else{
  2741.                         if(strstr(temp,"radian") != NULL){
  2742.                             int_data[0] = 4;
  2743.                             js_function[JS_FIND_ANGLE] = 1;
  2744.                         }else{
  2745.                             if(strstr(temp,"radius") != NULL){
  2746.                                 int_data[0] = 5;
  2747.                             }else{
  2748.                                 int_data[0] = 2;
  2749.                             }
  2750.                         }
  2751.                     }
  2752.                 }
  2753.             }
  2754.         }
  2755.         stroke_color = get_color(infile,0);
  2756.         font_size = (int) (get_real(infile,1));
  2757.         tmp_buffer = my_newmem(26);
  2758.         snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2759.         add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
  2760.         break;
  2761.  
  2762.         case MOUSE_PRECISION:
  2763.         /*
  2764.             @ precision int
  2765.             @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
  2766.             @ may be used / changed before every object
  2767.             @ In case of user interaction (like ''userdraw`` or ''multidraw``), this value will be used to determine the amount of decimals in the reply / answer.
  2768.             @%precision%size 400,400%xrange -10,10%yrange -10,10%precision 1%userdraw segment,red
  2769.         */
  2770.             precision = (int) (get_real(infile,1));
  2771.             if(precision < 1 ){precision = 1;};
  2772.             break;
  2773.  
  2774.         case MOUSEX:
  2775.         /*
  2776.          @ mousex color,fontsize
  2777.          @ will display the cursor x-coordinate in ''color`` and ''font size`` using the fontfamily Arial.
  2778.          @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``).
  2779.  
  2780.         */
  2781.             stroke_color = get_color(infile,0);
  2782.             font_size = (int) (get_real(infile,1));
  2783.             tmp_buffer = my_newmem(26);
  2784.             snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2785.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
  2786.             break;
  2787.         case MOUSEY:
  2788.         /*
  2789.          @ mousey color,fontsize
  2790.          @ will display the cursor y-coordinate in ''color`` and ''font size`` using default fontfamily Arial.
  2791.          @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``).
  2792.  
  2793.         */
  2794.             stroke_color = get_color(infile,0);
  2795.             font_size = (int) (get_real(infile,1));
  2796.             tmp_buffer = my_newmem(26);
  2797.             snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2798.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
  2799.             break;
  2800.  
  2801.         case MULTIDASH:
  2802.         /*
  2803.          @ multidash 0,1,1
  2804.          @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <code>multifill points,circle,segments</code>, are dashed
  2805.          @ use before command <a href='#multidraw'>multidraw</a>
  2806.          @ if not set all objects will be set ''not dashed``... unless a generic keyword ''dashed`` was given before command ''multidraw``
  2807.          @ the dash-type is not -yet- adjustable (e.g. command <code>dashtype line_px,space_px</code> will give no control over multidraw objects)
  2808.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  2809.          @ always use the same sequence as is used for ''multidraw``
  2810.         */
  2811.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2812.             temp = get_string(infile,1);
  2813.             temp = str_replace(temp,",","\",\"");
  2814.             fprintf(js_include_file,"var multidash = [\"%s\"];",temp);
  2815.             reset();/* if command 'dashed' was given...reset to not-dashed */
  2816.             break;
  2817.  
  2818.         case MULTIDRAW:
  2819.         /*
  2820.          @ multidraw obj_type_1,obj_type_2...obj_type_11
  2821.          @ for simple single object user drawings you could also use command <a href="#userdraw">userdraw</a>
  2822.          @ 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>
  2823.          @ 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
  2824.          @ 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...
  2825.          @ 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).
  2826.          @ 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``.
  2827.          @ 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).
  2828.          @ a right mouse button click will remove the last drawn object of the selected drawing type. All other type of objects are not removed
  2829.          @ multidraw is incompatible with command ''tooltip`` (the reserved div_area is used for the multidraw control buttons).
  2830.          @ all ''multidraw`` drawings will scale on zooming, this in contrast to the command <a href="#userdraw">userdraw</a>.
  2831.          @ wims will <b>not</b> check the amount or validity of your command arguments ! use javascript console to debug any typo.
  2832.          @ 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>
  2833.          @ 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 />
  2834.          @ <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.
  2835.          @ 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.
  2836.          @ 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.
  2837.          @ 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 />closedpoly = 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".
  2838.          @%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
  2839.          @%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 Arial%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
  2840.          @%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 Arial%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
  2841.          @%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
  2842.         */
  2843.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2844.             if( use_userdraw == TRUE ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");}
  2845.             use_userdraw = TRUE;
  2846.             /* LET OP max 6 DRAW PRIMITIVES + TEXT */
  2847.             temp = get_string(infile,1);
  2848.             temp = str_replace(temp,",","\",\"");
  2849.             /* if these are not set, set the default values for the 18 (more than enough!)  draw_primitives + draw_text */
  2850.                 /* int use_snap = 0;  0 = none 1=grid: 2=x-grid: 3=y-grid: 4=snap to points */
  2851.  
  2852.             fprintf(js_include_file,"\
  2853.             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'];}\
  2854.             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'];};\
  2855.             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'];};\
  2856.             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'];};\
  2857.             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'];};\
  2858.             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'];};\
  2859.             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'];};\
  2860.             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'];};\
  2861.             if( typeof(multilabel) === 'undefined' && multilabel == null ){ var multilabel = [\"%s\",\"stop drawing\"];};\
  2862.             if( typeof(multiuserinput) === 'undefined' && multiuserinput == null ){ var multiuserinput = ['0','0','0','0','0','0','0','0'];};\
  2863.             var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';",
  2864.             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,
  2865.             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,
  2866.             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,
  2867.             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,
  2868.             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,
  2869.             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,
  2870.             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,
  2871.             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,
  2872.             temp,arrow_head,font_color,font_family);
  2873.  
  2874.             if(strstr(temp,"text") != NULL){
  2875.              if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  2876.             }
  2877.  
  2878.             /* the canvasses range from 1000 ... 1008 */
  2879.             add_js_multidraw(js_include_file,canvas_root_id,temp,input_style,use_offset);
  2880.             reply_precision = precision;
  2881.             if( reply_format == 0){reply_format = 29;}
  2882.             reset();/* if command 'filled' / 'dashed' was given...reset all */
  2883.             break;
  2884.         case MULTILABEL:
  2885.         /*
  2886.          @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text'
  2887.          @ use before command <a href='#multidraw'>multidraw</a>
  2888.          @ 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``...)
  2889.          @ 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>
  2890.          @ 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``.
  2891.          @ wims will not check the amount or validity of your input.
  2892.          @ always use the same sequence as is used for ''multidraw``.
  2893.          @ if you don't want the controls, and want to write your own interface, set <code>multilabel NOCONTROLS</code>.
  2894.         */
  2895.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2896.             temp = get_string(infile,1);
  2897.             temp = str_replace(temp,",","\",\"");
  2898.             fprintf(js_include_file,"var multilabel = [\"%s\"];",temp);
  2899.             break;
  2900.         case MULTILINEWIDTH:
  2901.         /*
  2902.          @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8
  2903.          @ alternative:<code>linewidths</code>
  2904.          @ use before command <a href='#multidraw'>multidraw</a>
  2905.          @ if not set all line widths will be set by a previous command ''linewidth int``
  2906.          @ 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>
  2907.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  2908.          @ always use the same sequence as is used for ''multidraw``
  2909.         */
  2910.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2911.             temp = get_string(infile,1);
  2912.             temp = str_replace(temp,",","\",\"");
  2913.             fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp);
  2914.             break;
  2915.         case MULTIFILL:
  2916.         /*
  2917.          @ multifill 0,0,1,0,1,0,0
  2918.          @ 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...)
  2919.          @ use before command <a href='#multidraw'>multidraw</a>
  2920.          @ 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>
  2921.          @ only suitable for draw_primitives like ''circle | circles``, ''triangle | triangles`` and ''polygon``
  2922.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  2923.          @ always use the same sequence as is used for ''multidraw``
  2924.         */
  2925.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2926.             temp = get_string(infile,1);
  2927.             temp = str_replace(temp,",","\",\"");
  2928.             fprintf(js_include_file,"var multifill = [\"%s\"];",temp);
  2929.             break;
  2930.  
  2931.         case MULTIFILLCOLORS:
  2932.         /*
  2933.          @ multifillcolors color_name_1,color_name_2,...,color_name_8
  2934.          @ alternative:<code>fillcolors</code>
  2935.          @ use before command <a href='#multidraw'>multidraw</a>
  2936.          @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be ''stroke_color``, ''fill_opacity``
  2937.          @ 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>
  2938.          @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
  2939.          @ always use the same sequence as is used for ''multidraw``
  2940.          @ 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>
  2941.         */
  2942.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2943.             fprintf(js_include_file,"var multifillcolors = [");
  2944.             while( ! done ){
  2945.                 temp = get_color(infile,1);
  2946.                 fprintf(js_include_file,"\"%s\",",temp);
  2947.             }
  2948.             fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
  2949.             break;
  2950.  
  2951.         case MULTIFILLOPACITY:
  2952.         /*
  2953.          @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8
  2954.          @ float values 0 - 1 or integer values 0 - 255
  2955.          @ use before command <a href='#multidraw'>multidraw</a>
  2956.          @ if not set all fill opacity_ will be set by previous command <code>opacity int,int</code> and keyword ''filled``
  2957.          @ 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>
  2958.          @ wims will not check the amount or validity of your input
  2959.          @ always use the same sequence as is used for ''multidraw``
  2960.         */
  2961.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2962.             temp = get_string(infile,1);
  2963.             temp = str_replace(temp,",","\",\"");
  2964.             fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp);
  2965.             break;
  2966.         case MULTISNAPTOGRID:
  2967.         /*
  2968.          @ multisnaptogrid 0,1,1
  2969.          @ alternative: <code>multisnap</code>
  2970.          @ 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>)
  2971.          @ freehand drawing...specify precision for reply: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code>
  2972.          @ only the xy-values snap_to_grid: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code>
  2973.          @ only the x-values snap_to_grid: all objects snap to x-grid <code>multisnaptogrid 2,2,2,...</code>
  2974.          @ only the y-values snap_to_grid: all objects snap to y-grid <code>multisnaptogrid 3,3,3,...</code>
  2975.          @ 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>
  2976.          @ <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>
  2977.          @ use before command <a href='#multidraw'>multidraw</a>.
  2978.          @ attention: if not set all objects will be set ''no snap``... unless a generic command ''snaptogrid`` was given before command ''multidraw``.
  2979.          @ commands <a href='#xsnaptogrid'>xsnaptogrid</a>, <a href='#ysnaptogrid'>ysnaptogrid</a>, <a href='#snaptofunction'>snaptofunction</a> are <b>not</b> supported and only functional for command <a href='#userdraw'>userdraw</a>
  2980.          @ always use the same sequence as is used for ''multidraw``
  2981.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  2982.         */
  2983.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2984.             temp = get_string(infile,1);
  2985.             fprintf(js_include_file,"var multisnaptogrid = [%s];",temp);
  2986.             reset();/* if command ''dashed`` was given...reset to not-dashed */
  2987.             break;
  2988.         case MULTISTROKECOLORS:
  2989.         /*
  2990.          @ multistrokecolors color_name_1,color_name_2,...,color_name_8
  2991.          @ alternative: <code>multicolors</code> or <code>colors</code>
  2992.          @ use before command <a href='#multidraw'>multidraw</a>
  2993.          @ if not set all colors will be ''stroke_color``, ''stroke_opacity``
  2994.          @ 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>
  2995.          @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
  2996.          @ always use the same sequence as is used for ''multidraw``
  2997.         */
  2998.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  2999.             fprintf(js_include_file,"var multistrokecolors = [");
  3000.             while( ! done ){
  3001.                 temp = get_color(infile,1);
  3002.                 fprintf(js_include_file,"\"%s\",",temp);
  3003.             }
  3004.             fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
  3005.             break;
  3006.         case MULTISTROKEOPACITY:
  3007.         /*
  3008.          @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7
  3009.          @ float values 0 - 1 or integer values 0 - 255
  3010.          @ use before command <a href='#multidraw'>multidraw</a>
  3011.          @ if not set all stroke opacity_ will be set by previous command <code>opacity int,int</code>
  3012.          @ 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>
  3013.          @ wims will not check the amount or validity of your input
  3014.          @ always use the same sequence as is used for ''multidraw``
  3015.         */
  3016.             if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3017.             temp = get_string(infile,1);
  3018.             temp = str_replace(temp,",","\",\"");
  3019.             fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp);
  3020.             break;
  3021.  
  3022.         case MULTIUSERINPUT:
  3023.         /*
  3024.         @ multiuserinput 0,1,1,0
  3025.         @ alternative: <code>multiinput</code>
  3026.         @ 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.
  3027.         @ 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
  3028.         @ 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...
  3029.         @ in case of a ''triangle | poly3``, three inputfields are provided.
  3030.         @ in case of ''text`` and ''multiuserinput=1, 3`` inputfields will be shown: ''x,y,text``
  3031.         @ in case of ''text`` and ''multiuserinput=0, 1`` inputfield will be shown: text ... a mouse click will place the text on the canvas.
  3032.         @ may be styled using command <a href="#inputstyle">inputstyle</a>
  3033.         @ an additional button ''stop drawing`` may be used to combine userbased drawings with ''drag&amp;drop`` or ''onclick`` elements
  3034.         @ when exercise is finished (status=done), the buttons will not be shown. To override this default behaviour use command / keyword ''status``
  3035.         @ use before command <a href='#multidraw'>multidraw</a>.
  3036.         @ always use the same sequence as is used for ''multidraw``.
  3037.         */
  3038.             /* simple rawmath and input check */
  3039.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  3040.             temp = get_string(infile,1);
  3041.             temp = str_replace(temp,",","\",\"");
  3042.             fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp);
  3043.             break;
  3044.  
  3045.         case NOXAXIS:
  3046.         /*
  3047.         @ noxaxis
  3048.         @ keyword
  3049.         @ if set, the automatic x-axis numbering will be ignored
  3050.         @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>)
  3051.         @ to be used before command grid (see <a href="#grid">command grid</a>)
  3052.         */
  3053.             fprintf(js_include_file,"x_strings = {};x_strings_up = [];\n");
  3054.             use_axis_numbering = -1;
  3055.             break;
  3056.         case NOYAXIS:
  3057.         /*
  3058.         @ noyaxis
  3059.         @ keyword
  3060.         @ if set, the automatic y-axis numbering will be ignored
  3061.         @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>)
  3062.         @ to be used before command grid (see <a href="#grid">command grid</a>)
  3063.         */
  3064.             fprintf(js_include_file,"y_strings = {};\n");
  3065.             break;
  3066.         case NUMBERLINE:
  3067.         /*
  3068.         @ numberline x0,x1,xmajor,xminor,y0,y1
  3069.         @ numberline is using xrange/yrange system for all dimensions
  3070.         @ multiple numberlines are allowed ; combinations with command <a href='#grid'>grid</a> is allowed; multiple commands <a href='#xaxis'>xaxis numbering</a> are allowed
  3071.         @ x0 is start x-value in xrange
  3072.         @ x1 is end x-value in xrange
  3073.         @ xmajor is step for major division
  3074.         @ xminor is divisor of xmajor; using small (30% of major tick) tick marks: this behaviour is ''hardcoded``
  3075.         @ is xminor is an even divisor, an extra tickmark (60% of major tick) is added to the numberline: this behaviour is ''hardcoded``
  3076.         @ y0 is bottom of numberline; y1 endpoint of major tics
  3077.         @ use command <a href="#linewidth">linewidth</a> to control appearance
  3078.         @ use <a href="#strokecolor">strokecolor</a> and <a href="#opacity">opacity</a> to controle measure line
  3079.         @ for all ticks linewidth and color / opacity are identical.
  3080.         @ 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
  3081.         @ use <a href="#fontfamily">fontfamily</a> and <a href="#fontcolor">fontcolor</a> to control fonts settings
  3082.         @ 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
  3083.         @ <a href="#snaptogrid">snaptogrid, snaptopoints etc</a> and <a href="#zoom">zooming and panning</a> is supported
  3084.         @ onclick and dragging of the numberline are not -yet- supported
  3085.         @ note: in case of multiple numberlines, make sure the numberline without special x-axis numbering (e.g. ranging from xmin to xmax) comes first !
  3086.         @%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
  3087.         */
  3088.             if( js_function[DRAW_NUMBERLINE] != 1 ){ js_function[DRAW_NUMBERLINE] = 1;}
  3089.             for(i=0;i<6;i++){
  3090.                 switch(i){
  3091.                     case 0: double_data[0] = get_real(infile,0);break;/* xmin */
  3092.                     case 1: double_data[1] = get_real(infile,0);break;/* xmax */
  3093.                     case 2: double_data[2] = get_real(infile,0);break;/* xmajor */
  3094.                     case 3: double_data[3] = get_real(infile,0);break;/* xminor */
  3095.                     case 4: double_data[4] = get_real(infile,0);break;/* ymin */
  3096.                     case 5: double_data[5] = get_real(infile,1);/* ymax */
  3097.                             /*
  3098.                             var draw_numberline%d = function(canvas_type,xmin,xmax,xmajor,xminor,ymin,ymax,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor);
  3099.                             */
  3100.                             fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[2] / double_data[3],double_data[5] - double_data[4] );
  3101.                             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);
  3102.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3103.                             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);
  3104.                             add_to_buffer(tmp_buffer);
  3105.                             numberline_cnt++;
  3106.                             break;
  3107.                     default:break;
  3108.                 }
  3109.             }
  3110.             reset();
  3111.             break;
  3112.  
  3113.             break;
  3114.         case OPACITY:
  3115.         /*
  3116.         @ opacity [0-255],[0-255]
  3117.         @ opacity [0.0 - 1.0],[0.0 - 1.0]
  3118.         @ alternative: <code>transparent</code>
  3119.         @ first item is stroke opacity, second is fill opacity
  3120.         @%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
  3121.         */
  3122.             for(i = 0 ; i<2;i++){
  3123.                 switch(i){
  3124.                     case 0: double_data[0]= get_real(infile,0);break;
  3125.                     case 1: double_data[1]= get_real(infile,1);break;
  3126.                     default: break;
  3127.                 }
  3128.             }
  3129.             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 ? */
  3130.             if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = 0.0;} /* 0.0 - 1.0 */
  3131.             if( double_data[1] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = 0.0;} /* 0.0 - 1.0 */
  3132.             break;
  3133.  
  3134.         case ONCLICK:
  3135.         /*
  3136.          @ onclick
  3137.          @ keyword (no arguments required)
  3138.          @ if the next object is clicked, its ''object onclick_or_drag sequence number`` in fly script is returned by <code>read_dragdrop();</code>
  3139.          @ 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``
  3140.          @ line based objects will show an increase in line width<br />font based objects (e.g. text / string ) will show a slight change in text size when clicked.
  3141.          @ the click zone (accuracy) is determined by 2&times; the line width of the object
  3142.          @ 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...)
  3143.          @ in that case <code>read_dragdrop()</code> will produce a javascript array reply containing for the moved objects:<br />x_org[0],y_org[0],x_new[0],y_new[0],new_angle<br/>the unmoved draggable objects are labelled 'not_moved'. The combined 'onclick' objects are labelled '0' or '1'<br />the array index in the reply in the same order as the draggable and clickable objects appear in the canvascript.<br />See tool directexec for an example
  3144.          @ note: not all objects may be set onclick
  3145.          @ note: onclick (or drag ) can not be combined with command <a href="#rotate">rotate or translate</a> !
  3146.          @%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
  3147.          @%onclick_drag%size 400,400%######%# to see reply string, load this example in directexec %######%xrange -10,10%yrange -10,10%linewidth 3%# command text large = fontsize+6%fontsize 34-6%fontfamily 34px Arial%drag xy%circles red,-5,5,2,5,5,2,5,-5,2,-5,-5,2%onclick%string blue,-1,1,A%onclick%string blue,1,7,B%onclick%string blue,1,-1,C%onclick%string blue,-1,-7,D%onclick%text green,-8,1,large,E%onclick%text green,-6,7,large,F%onclick%text green,6,-1,large,G%onclick%text green,8,-7,large,H
  3148.         */
  3149.             if( print_drag_params_only_once == FALSE){
  3150.              fprintf(js_include_file,"use_dragdrop_reply = true;\n");
  3151.              print_drag_params_only_once = TRUE;
  3152.             }
  3153.             onclick = 1;
  3154.  
  3155.             break;
  3156.  
  3157.         case PARALLEL:
  3158.         /*
  3159.          @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
  3160.          @ can <b>not</b> be set ''onclick`` or ''drag xy``
  3161.          @%parallel%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red
  3162.         */
  3163.             for( i = 0;i < 8; i++ ){
  3164.                 switch(i){
  3165.                     case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
  3166.                     case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
  3167.                     case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
  3168.                     case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
  3169.                     case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
  3170.                     case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
  3171.                     case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
  3172.                     case 7: stroke_color=get_color(infile,1);/* name or hex color */
  3173.                     decimals = find_number_of_digits(precision);
  3174.                     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);
  3175.                     if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3176.                     /* click_cnt++*/;
  3177.                     reset();
  3178.                     break;
  3179.                     default: break;
  3180.                 }
  3181.             }
  3182.             break;
  3183.  
  3184.  
  3185.         case PLOTSTEPS:
  3186.             /*
  3187.              @ plotsteps a_number
  3188.              @ default 150
  3189.              @ only used for commands <a href="#curve">curve / plot</a> and <a href="#levelcurve">levelcurve</a>
  3190.              @ use with care !
  3191.             */
  3192.             plot_steps = (int) (get_real(infile,1));
  3193.             break;
  3194.  
  3195.         case POINT:
  3196.         /*
  3197.         @ point x,y,color
  3198.         @ draw a single point at (x;y) in color ''color``
  3199.         @ use command <code>linewidth int</code> to adjust size
  3200.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3201.         @ will not resize on zooming (command <code>circle x,y,r,color</code> will resize on zooming)
  3202.         @ attention: in case of command <a href="#rotate">rotate angle</a> a point has rotation center (0:0) in x/y-range
  3203.         @%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
  3204.         */
  3205.             for(i=0;i<3;i++){
  3206.                 switch(i){
  3207.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  3208.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  3209.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  3210.                     decimals = find_number_of_digits(precision);
  3211.                     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);
  3212.                     /* click_cnt++; */
  3213.                     if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3214.                     break;
  3215.                     default: break;
  3216.                 }
  3217.             }
  3218.             reset();
  3219.             break;
  3220.  
  3221.         case POINTS:
  3222.         /*
  3223.         @ points color,x1,y1,x2,y2,...,x_n,y_n
  3224.         @ draw multiple points at given coordinates in color ''color``
  3225.         @ use command <code>linewidth int</code> to adjust size
  3226.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  3227.         @ attention: in case of command <a href="#rotate">rotate angle</a> the points have rotation center (0:0) in x/y-range
  3228.         @%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
  3229.         @%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
  3230.         */
  3231.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3232.             fill_color = stroke_color;
  3233.             i=0;
  3234.             while( ! done ){     /* get next item until EOL*/
  3235.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3236.                 if(i%2 == 0 ){
  3237.                     double_data[i] = get_real(infile,0); /* x */
  3238.                 }
  3239.                 else
  3240.                 {
  3241.                     double_data[i] = get_real(infile,1); /* y */
  3242.                 }
  3243.                 i++;
  3244.             }
  3245.             decimals = find_number_of_digits(precision);
  3246.             for(c = 0 ; c < i-1 ; c = c+2){
  3247.                 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);
  3248.                 /* click_cnt++; */
  3249.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3250.             }
  3251.             reset();
  3252.             break;
  3253.  
  3254.         case POLY:
  3255.         /*
  3256.         @ poly color,x1,y1,x2,y2...x_n,y_n
  3257.         @ polygon color,x1,y1,x2,y2...x_n,y_n
  3258.         @ draw closed polygon
  3259.         @ use command ''fpoly`` to fill it or use keyword <a href='#filled'>filled</a>
  3260.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3261.         @%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
  3262.         @%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
  3263.         */
  3264.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3265.             i=0;
  3266.             c=0;
  3267.             while( ! done ){     /* get next item until EOL*/
  3268.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3269.                 for( c = 0 ; c < 2; c++){
  3270.                     if(c == 0 ){
  3271.                         double_data[i] = get_real(infile,0);
  3272.                         i++;
  3273.                     }
  3274.                     else
  3275.                     {
  3276.                         double_data[i] = get_real(infile,1);
  3277.                         i++;
  3278.                     }
  3279.                 }
  3280.             }
  3281.             /* draw path:  closed & optional filled */
  3282.                 decimals = find_number_of_digits(precision);
  3283.                 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);
  3284.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3285.                 /* click_cnt++; */
  3286.                 reset();
  3287.             break;
  3288.  
  3289.         case POLYLINE:
  3290.         /*
  3291.         @ polyline color,x1,y1,x2,y2...x_n,y_n
  3292.         @ brokenline color,x1,y1,x2,y2...x_n,y_n
  3293.         @ path color,x1,y1,x2,y2...x_n,y_n
  3294.         @ 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>
  3295.         @ 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
  3296.         @ 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)
  3297.         @ use command <a href='#segments'>segments</a> for a series of segments. These may be clicked/dragged individually
  3298.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3299.         @%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
  3300.         @%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
  3301.         */
  3302.  
  3303.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3304.             i=0;
  3305.             c=0;
  3306.             while( ! done ){     /* get next item until EOL*/
  3307.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3308.                 for( c = 0 ; c < 2; c++){
  3309.                     if(c == 0 ){
  3310.                         double_data[i] = get_real(infile,0);
  3311.                         i++;
  3312.                     }
  3313.                     else
  3314.                     {
  3315.                         double_data[i] = get_real(infile,1);
  3316.                         i++;
  3317.                     }
  3318.                 }
  3319.             }
  3320.             /* draw path: not closed & not filled */
  3321.             decimals = find_number_of_digits(precision);
  3322.             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);
  3323.             if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3324.             /* click_cnt++;*/
  3325.             reset();
  3326.             break;
  3327.  
  3328.         case POPUP:
  3329.             /*
  3330.             @ popup
  3331.             @ keyword (no arguments)
  3332.             @ if fly-script starts with keyword ''popup``, the canvas image will be exclusively in a popup window (xsize px &times; ysize px)
  3333.             @ 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``
  3334.             @ the popup window will be embedded into the page as a ''normal`` image, when ''status=done``; override with keyword <a href="#status">nostatus</a>
  3335.             @ 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>
  3336.             @ 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
  3337.             @%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
  3338.             */
  3339.             use_tooltip = 2;
  3340.             break;
  3341.  
  3342.         case PROTRACTOR:
  3343.         /*
  3344.          @ protractor x,y,x_width,type,mode,use_a_scale
  3345.          @ x,y are the initial location
  3346.          @ x_width: give the width in x-coordinate system (e.g. not in pixels !)
  3347.          @ type = 1: a triangle range 0 - 180<br />type = 2: a circle shape 0 - 360
  3348.          @ 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
  3349.          @ 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>
  3350.          @ use_scale = 1: the protractor will have some scale values printed; use_scale=0 to disable
  3351.          @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor...
  3352.          @ commands ''stroke_color | fill_color | linewidth | opacity | font_family`` will determine the looks of the protractor.
  3353.          @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command ''precision`` to set the reply precision.
  3354.          @ if combined with a ruler, use replyformat = 32
  3355.          @ command <code>snap_to_grid</code> may be used to assist the pupil at placing the protractor
  3356.          @ 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...
  3357.          @ only one protractor allowed (for the time being)
  3358.          @ 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...
  3359.          @%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
  3360.         */
  3361.             for( i = 0;i < 6; i++ ){
  3362.                 switch(i){
  3363.                     case 0: double_data[0] = get_real(infile,0);break; /* x-center */
  3364.                     case 1: double_data[1] = get_real(infile,0);break; /* y-center */
  3365.                     case 2: double_data[2] = get_real(infile,0);break; /* x-width */
  3366.                     case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */
  3367.                     case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */
  3368.                     case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */
  3369.                     decimals = find_number_of_digits(precision);
  3370.                     if( int_data[1] < 0 ){ js_function[JS_FIND_ANGLE] = 1;}
  3371.                     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);
  3372.  
  3373.                     string_length = 1 + snprintf(NULL,0,";protractor%d(); ",canvas_root_id);
  3374.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3375.                     snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id);
  3376.                     add_to_buffer(tmp_buffer);
  3377.                     reply_precision = precision;
  3378.                     /* no reply from protractor if non-interactive */
  3379.                     if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;}
  3380.                     break;
  3381.                     default: break;
  3382.                 }
  3383.             }
  3384.             break;
  3385.  
  3386.         case PIXELS:
  3387.         /*
  3388.         @ pixels color,x1,y1,x2,y2,x3,y3...
  3389.         @ draw rectangular "points" with diameter 1 pixel
  3390.         @ pixels can <b>not</b> be dragged or clicked
  3391.         @ "pixelsize = 1" may be changed by command <code>pixelsize int</code>
  3392.         @%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...
  3393.         */
  3394.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  3395.             stroke_color=get_color(infile,0);
  3396.             i=0;
  3397.             c=0;
  3398.             while( ! done ){     /* get next item until EOL*/
  3399.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3400.                 for( c = 0 ; c < 2; c++){
  3401.                     if(c == 0 ){
  3402.                         double_data[i] = get_real(infile,0);
  3403.                         i++;
  3404.                     }
  3405.                     else
  3406.                     {
  3407.                         double_data[i] = get_real(infile,1);
  3408.                         i++;
  3409.                     }
  3410.                 }
  3411.             }
  3412.             decimals = find_number_of_digits(precision);
  3413.             /*  *double_xy2js_array(double xy[],int len,int decimals) */
  3414.             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);
  3415.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3416.             snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  3417.             add_to_buffer(tmp_buffer);
  3418.             reset();
  3419.             break;
  3420.  
  3421.         case PIXELSIZE:
  3422.         /*
  3423.         @ pixelsize int
  3424.         @ in case you want to deviate from default pixelsize = 1(...)
  3425.         @ pixelsize 100 is of course a filled rectangle 100px &times; 100px
  3426.         */
  3427.             pixelsize = (int) get_real(infile,1);
  3428.         break;
  3429.  
  3430.         case PIECHART:
  3431.         /*
  3432.         @ piechart xc,yc,radius,'data+colorlist'
  3433.         @ (xc: yc) center of circle diagram in xrange/yrange
  3434.         @ radius in pixels
  3435.         @ 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
  3436.         @ example data+colorlist: 32:red:65:green:23:black:43:orange:43:yellow:14:white
  3437.         @ the number of colors must match the number of data.
  3438.         @ 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,...
  3439.         @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of colours
  3440.         @ 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.
  3441.         @ 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.
  3442.         @%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%
  3443.         @%piechart_2%size 200,200%xrange -10,10%yrange -10,10%fontfamily 16px Arial%centered%legend cars:motorcycles:bicycles:trikes%opacity 255,60%piechart 0,0,100,22:red:8:blue:63:green:7:purple
  3444.         */
  3445.             if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}
  3446.             for(i=0;i<5;i++){
  3447.                 switch(i){
  3448.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  3449.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  3450.                     case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
  3451.                     case 3: temp = get_string(infile,1);
  3452.                             if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
  3453.                             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);
  3454.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3455.                             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);
  3456.                             add_to_buffer(tmp_buffer);
  3457.                            break;
  3458.                     default:break;
  3459.                 }
  3460.             }
  3461.             reset();
  3462.         break;
  3463.  
  3464.         case RAYS:
  3465.         /*
  3466.          @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
  3467.          @ draw rays in color ''color`` and center (xc:yc)
  3468.          @ may be set draggable or onclick (every individual ray)
  3469.          @%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
  3470.          @%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
  3471.         */
  3472.             stroke_color=get_color(infile,0);
  3473.             fill_color = stroke_color;
  3474.             double_data[0] = get_real(infile,0);/* xc */
  3475.             double_data[1] = get_real(infile,0);/* yc */
  3476.             i=2;
  3477.             while( ! done ){     /* get next item until EOL*/
  3478.                 if(i > MAX_INT - 1){canvas_error("in command rays too many points / rays in argument: repeat command multiple times to fit");}
  3479.                 if(i%2 == 0 ){
  3480.                     double_data[i] = get_real(infile,0); /* x */
  3481.                 }
  3482.                 else
  3483.                 {
  3484.                     double_data[i] = get_real(infile,1); /* y */
  3485.                 }
  3486.             fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
  3487.                 i++;
  3488.             }
  3489.  
  3490.             if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
  3491.             decimals = find_number_of_digits(precision);
  3492.             for(c=2; c<i;c = c+2){
  3493.                 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);
  3494.                 /* click_cnt++; */
  3495.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3496.             }
  3497.             reset();
  3498.             break;
  3499.  
  3500.         case RECT:
  3501.         /*
  3502.         @ rect x1,y1,x2,y2,color
  3503.         @ use command <code>frect x1,y1,x2,y2,color</code> for a filled rectangle
  3504.         @ use command/keyword <a href='#filled'>filled</a> before command <code>rect x1,y1,x2,y2,color</code>
  3505.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3506.         @%rect%size 400,400%xrange -10,10%yrange -10,10%rect 0,0,4,-4,green%rect 0,5,4,1,red
  3507.         */
  3508.             for(i=0;i<5;i++){
  3509.                 switch(i){
  3510.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  3511.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  3512.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  3513.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  3514.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  3515.                         decimals = find_number_of_digits(precision);
  3516.                         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);
  3517.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3518.                         /* click_cnt++; */
  3519.                         reset();
  3520.                         break;
  3521.                 }
  3522.             }
  3523.             break;
  3524.  
  3525.         case RECTS:
  3526.         /*
  3527.         @ rects color,x1,y1,x2,y2,.....
  3528.         @ use command <code>frect color,x1,y1,x2,y2,.....</code> for a filled rectangle
  3529.         @ use command/keyword <a href='#filled'>filled</a> before command <code>rects color,x1,y1,x2,y2,....</code>
  3530.         @ use command <code>fillcolor color</code> before ''frects`` to set the fill colour.
  3531.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  3532.         @%rects%size 400,400%xrange -10,10%yrange -10,10%rects red,0,0,4,-4,0,5,4,1
  3533.         */
  3534.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3535.             fill_color = stroke_color;
  3536.             i=0;
  3537.             while( ! done ){     /* get next item until EOL*/
  3538.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3539.                 if(i%2 == 0 ){
  3540.                     double_data[i] = get_real(infile,0); /* x */
  3541.                 }
  3542.                 else
  3543.                 {
  3544.                     double_data[i] = get_real(infile,1); /* y */
  3545.                 }
  3546.                 i++;
  3547.             }
  3548.             decimals = find_number_of_digits(precision);
  3549.             for(c = 0 ; c < i-1 ; c = c+4){
  3550.                 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);
  3551.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3552.                 /* click_cnt++; */
  3553.             }
  3554.             reset();
  3555.             break;
  3556.  
  3557.         case REPLYFORMAT:
  3558.         /*
  3559.         @ replyformat number
  3560.         @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop()
  3561.         @ default values should be fine !
  3562.         @ 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
  3563.         @ the last value for ''precision int`` will be used to calculate the reply coordinates, if needed (read_canvas();)
  3564.         @ 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>
  3565.         */
  3566.          reply_format = (int) get_real(infile,1);
  3567.          reply_precision = precision;
  3568.         break;
  3569.  
  3570.         case RESETOFFSET:
  3571.         /*
  3572.          @ resetoffset
  3573.          @ keyword
  3574.          @ use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text
  3575.          @ 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).
  3576.         */
  3577.          use_offset = 0;
  3578.          break;
  3579.  
  3580.         case ROTATE:
  3581.         /*
  3582.          @ rotate rotation_angle
  3583.          @ angle in degrees
  3584.          @ (only) the next object will be rotated is given angle
  3585.          @ positive values rotate counter clockwise
  3586.          @ 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)
  3587.          @ 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>
  3588.          @ attention: rotate will mess up the drag interactivity of the rotated object <br />e.g. if combined with command <a href="#drag">drag xy</a> the mouse recognises the original -unrotated- coordinates of the object
  3589.          @ attention: <a href="#onclick">onclick</a> is compatible with rotate...
  3590.          @%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%
  3591.          @%rotate_onclick%size 600,300%xrange -26,88%yrange -26,26%fontsize 30%fontfamily 25px Arial%vline 26,0,black%rotate 190%onclick%string black, 6, 8,77%rotate 190%onclick%string black, -2, 10,99%rotate 190%onclick%string red, -9, 4,114%rotate 0%onclick%string black, -9, -4,81%rotate 90%onclick%string black, -2, -10,45%rotate 190%onclick%string black, 6, -8,27%rotate 45%onclick%string black, 10, 0,110%rotate 90%onclick%string black, 0, 0,44%rotate 0%onclick%string black, 68, 8,26%rotate 0%onclick%string red, 59, 10,114%rotate 90%onclick%string black, 53, 4,65%rotate 90%onclick%string black, 53, -5,76%rotate 90%onclick%string black, 61, -10,108%rotate 0%onclick%string black, 69, -7,29%rotate 0%onclick%string black, 72, 1,28%rotate 90%onclick%string black, 62, 0,21%
  3592.  
  3593.         */
  3594.             use_rotate = TRUE;
  3595.             angle = -1*(get_real(infile,1));/* -1: to be compatible with Flydraw... */
  3596.             if( js_function[ADD_JS_ROTATE_MOUSE] != 1 ){ js_function[ADD_JS_ROTATE_MOUSE] = 1;}
  3597.             break;
  3598.  
  3599.         case ROTATION_CENTER:
  3600.         /*
  3601.         @ rotationcenter x_center,y_center
  3602.         @ define an rotation center in your x/y-coordinate system
  3603.         @ wims will not check the validity of your input; use javascript console to debug any erors
  3604.         @ if not defined a rotation will be around the first point of an object
  3605.         @ to be used before command <a href="#rotate">rotate</a>
  3606.         @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given
  3607.         @%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
  3608.         @%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
  3609.         */
  3610.             temp = get_string(infile,1);
  3611.             string_length = 1 + snprintf(NULL,0,"[ %s ]",temp);
  3612.             check_string_length(string_length);
  3613.             rotation_center = my_newmem(string_length);
  3614.             snprintf(rotation_center,string_length,"[%s]",temp);
  3615.             break;
  3616.  
  3617.         case ROUNDRECT:
  3618.         /*
  3619.         @ roundrect x1,y1,x2,y2,radius in px,color
  3620.         @ use command <code>froundrect x1,y1,x2,y2,radius,color</code> for a filled rectangle
  3621.         @ use command/keyword <a href='#filled'>filled</a> before command <code>roundrect x1,y1,x2,y2,radius,color</code>
  3622.         @ fillcolor will be identical to ''color``
  3623.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3624.         @%roundrect%size 400,400%xrange -10,10%yrange -10,10%roundrect 0,0,4,-4,20,green%roundrect 0,5,4,1,10,red
  3625.         */
  3626.             for(i=0;i<6;i++){
  3627.                 switch(i){
  3628.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  3629.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  3630.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  3631.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  3632.                     case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
  3633.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  3634.                         /* ensure no inverted roundrect is produced... */
  3635.                         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];}
  3636.                         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];}
  3637.                         decimals = find_number_of_digits(precision);
  3638.                         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);
  3639.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3640.                         /* click_cnt++;*/
  3641.                         reset();
  3642.                     break;
  3643.                 }
  3644.             }
  3645.             break;
  3646.  
  3647.         case ROUNDRECTS:
  3648.         /*
  3649.         @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,....
  3650.         @ for filled roundrects use command/keyword <a href='#filled'>filled</a> before command
  3651.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  3652.         @%roundrects%size 400,400%xrange -10,10%yrange -10,10%roundrects blue,5,0,0,4,-4,5,4,1,2
  3653.         */
  3654.  
  3655.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3656.             int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */
  3657.             fill_color = stroke_color;
  3658.             i=0;
  3659.             while( ! done ){     /* get next item until EOL*/
  3660.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3661.                 if(i%2 == 0 ){
  3662.                     double_data[i] = get_real(infile,0); /* x */
  3663.                 }
  3664.                 else
  3665.                 {
  3666.                     double_data[i] = get_real(infile,1); /* y */
  3667.                 }
  3668.                 i++;
  3669.             }
  3670.             decimals = find_number_of_digits(precision);
  3671.             for(c = 0 ; c < i-1 ; c = c+4){
  3672.                 /* ensure no inverted roundrect is produced... */
  3673.                 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];}
  3674.                 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];}
  3675.                 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);
  3676.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3677.                 /* click_cnt++; */
  3678.             }
  3679.             reset();
  3680.             break;
  3681.  
  3682.         case RULER:
  3683.         /*
  3684.         @ ruler x,y,x-width,y-height,mode
  3685.         @ x,y are the initial location
  3686.         @ x-width, y-height are the ruler dimensions width &amp; height in xy-coordinate system
  3687.         @ 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
  3688.         @ 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
  3689.         @ if combined with a protractor, use replyformat = 32
  3690.         @ only one ruler allowed (for the time being)
  3691.         @ 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...
  3692.         @ 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...
  3693.         @%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
  3694.         @%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
  3695.         @%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
  3696.         */
  3697.             for( i = 0;i < 5; i++ ){
  3698.                 switch(i){
  3699.                     case 0: double_data[0] = get_real(infile,0);break; /* x-center */
  3700.                     case 1: double_data[1] = get_real(infile,0);break; /* y-center */
  3701.                     case 2: double_data[2] = get_real(infile,0);break; /* x-width */
  3702.                     case 3: double_data[3] = get_real(infile,0);break; /* y-width */
  3703.                     case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */
  3704.                     decimals = find_number_of_digits(precision);
  3705.                     if( int_data[0] < 0 ){
  3706.                       if( js_function[JS_FIND_ANGLE] != 1 ){  js_function[JS_FIND_ANGLE] = 1; }
  3707.                     }
  3708.                     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);
  3709.                     string_length = 1 + snprintf(NULL,0,";ruler%d(); ",canvas_root_id);
  3710.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3711.                     snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id);
  3712.                     add_to_buffer(tmp_buffer);
  3713.                     reply_precision = precision;
  3714.                     /* no reply from ruler if non-interactive */
  3715.                     if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;}
  3716.                     break;
  3717.                     default: break;
  3718.                 }
  3719.             }
  3720.             break;
  3721.  
  3722.  
  3723.  
  3724.         case SIZE:
  3725.             /*
  3726.             @ size width,height
  3727.             @ set canvas size in pixels
  3728.             @ mandatory first command (can only be preceded by keyword <a href="#popup">popup</a>)
  3729.             @ 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
  3730.             */
  3731.             found_size_command = 1;
  3732.             /* using fabs: however "xsize == int": so "xsize = abs( (int) get_real(infile,0))" would be the idea... */
  3733.             xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
  3734.             ysize = (int)(fabs(round(get_real(infile,1))));
  3735.             /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
  3736.             xmin = 0;xmax = xsize;
  3737.             ymin = 0;ymax = ysize;
  3738.  
  3739. /*
  3740.  The sequence in which stuff is finally printed is important !!
  3741. */
  3742. fprintf(stdout,"\n\
  3743. <script>\n\
  3744. /*<![CDATA[*/\n\
  3745. if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\
  3746. if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\
  3747. if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\
  3748. canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\
  3749. ",canvas_root_id);
  3750.  
  3751. /* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */
  3752. if( use_tooltip != 2){
  3753.  fprintf(stdout,"<!-- canvasdraw div  -->\n\
  3754. <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\
  3755. <!-- tooltip and input placeholder  -->\n\
  3756. <div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\
  3757. <!-- include actual object code via include file -->\n\
  3758. <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);
  3759. }
  3760. else
  3761. {
  3762. /*
  3763. set canvas_div invisible and do not include placeholder in main html page:
  3764. the js-include will also be in a popup window...to be shown when wims $status = done
  3765. */
  3766.  fprintf(stdout,"<!-- canvasdraw div invisible  -->\n\
  3767. <div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\
  3768. <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>\
  3769. <!-- include actual object code via include file -->\n\
  3770. <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);
  3771. }
  3772.  
  3773. /* these must be global...it is all really very poor javascript:( */
  3774. fprintf(js_include_file,"\n/* begin generated javascript include for canvasdraw */\n\
  3775. \"use strict\";\n\
  3776. /* these variables and functions must be global */\n\
  3777. var read_dragdrop%d;\
  3778. var read_canvas_images;\
  3779. var read_canvas%d;\
  3780. var set_clock;\
  3781. var clear_draw_area%d;\
  3782. var update_draw_area%d;\
  3783. var place_image_on_canvas;\
  3784. var draw_boxplot;\
  3785. var redraw_all%d;\
  3786. var userdraw_primitive;\n\
  3787. var wims_canvas_function%d = function(){\n/* common used stuff */\n\
  3788. var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\
  3789. var xsize = %d;\
  3790. var ysize = %d;\
  3791. var precision = 100;\
  3792. var canvas_div = document.getElementById(\"canvas_div%d\");\
  3793. 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;};\
  3794. 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;};\
  3795. 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);};};\
  3796. 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);};};\
  3797. 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);};};\
  3798. 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);};};\
  3799. function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
  3800. function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
  3801. function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\
  3802. 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) ));};\
  3803. 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;};\
  3804. 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;};\
  3805. var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));var snap_x = 1;var snap_y = 1;\
  3806. function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
  3807. function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\
  3808. 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;};};\
  3809. var xlogbase = 10;\
  3810. var ylogbase = 10;\
  3811. var use_xlogscale = 0;\
  3812. var use_ylogscale = 0;\
  3813. var x_strings = {};var x_strings_up = [];\
  3814. var y_strings = null;\
  3815. var use_pan_and_zoom = 0;\
  3816. var use_jsmath = 0;\
  3817. var xstart = 0;\
  3818. var ystart = 0;\
  3819. var unit_x=\" \";\
  3820. var unit_y=\" \";\
  3821. 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);
  3822. /* default add the drag code: nearly always used ...*/
  3823.   add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
  3824.  
  3825.             break;
  3826.  
  3827.  
  3828.         case SEGMENT:
  3829.         /*
  3830.         @ segment x1,y1,x2,y2,color
  3831.         @ alternative: <code>seg</code>
  3832.         @ draw a line segment between points (x1:y1)--(x2:y2) in color ''color``
  3833.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3834.         @%segment_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segment 1,1,-9,3,green
  3835.         @%segment_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segment 1,1,-9,3,green
  3836.         */
  3837.             for(i=0;i<5;i++) {
  3838.                 switch(i){
  3839.                     case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
  3840.                     case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
  3841.                     case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
  3842.                     case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
  3843.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  3844.                         decimals = find_number_of_digits(precision);
  3845.                         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);
  3846.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3847.                         /* click_cnt++; */
  3848.                         reset();
  3849.                         break;
  3850.                     default: break;
  3851.                 }
  3852.             }
  3853.             break;
  3854.  
  3855.         case SEGMENTS:
  3856.         /*
  3857.         @ segments color,x1,y1,x2,y2,...,x_n,y_n
  3858.         @ alternative: <code>segs</code>
  3859.         @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color ''color``
  3860.         @ use command ''linewidth int'' to adust size
  3861.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  3862.         @%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
  3863.         @%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
  3864.         */
  3865.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3866.             fill_color = stroke_color;
  3867.             i=0;
  3868.             while( ! done ){     /* get next item until EOL*/
  3869.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3870.                 if(i%2 == 0 ){
  3871.                     double_data[i] = get_real(infile,0); /* x */
  3872.                 }
  3873.                 else
  3874.                 {
  3875.                     double_data[i] = get_real(infile,1); /* y */
  3876.                 }
  3877.                 i++;
  3878.             }
  3879.             decimals = find_number_of_digits(precision);
  3880.             for(c = 0 ; c < i-1 ; c = c+4){
  3881.                 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);
  3882.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  3883.                 /* click_cnt++;*/
  3884.             }
  3885.             reset();
  3886.             break;
  3887.  
  3888.         case SETLIMITS:
  3889.         /*
  3890.             @ setlimits
  3891.             @ keyword: if set, it will produce 4 inputfields for ''xmin,xmax,ymin,ymax`` and an ''ok`` button
  3892.             @ may be used for inputfield based zooming / panning
  3893.             @ may be styled using command <a href="#inputstyle">inputstyle</a>
  3894.             @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to ''xlabel`` etc
  3895.             @ note: the input value will not be checked on validity
  3896.             @%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
  3897.         */
  3898.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  3899.             add_setlimits(js_include_file,canvas_root_id,font_size,input_style);
  3900.             /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
  3901.             use_pan_and_zoom = TRUE;
  3902.             done = TRUE;
  3903.             break;
  3904.  
  3905.         case SETPIXEL:
  3906.         /*
  3907.         @ setpixel x,y,color
  3908.         @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange
  3909.         @ pixels can <b>not</b> be dragged or clicked
  3910.         @ "pixelsize = 1" may be changed by command <code>pixelsize int</code>
  3911.         @%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%
  3912.         */
  3913.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  3914.             for(i=0;i<3;i++){
  3915.                 switch(i){
  3916.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  3917.                     case 1: double_data[1] = get_real(infile,0); break; /* y */
  3918.                     case 2: stroke_color = get_color(infile,1);
  3919.                            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);
  3920.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3921.                            snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  3922.                            add_to_buffer(tmp_buffer);
  3923.                            break;
  3924.                     default:break;
  3925.                 }
  3926.             }
  3927.             reset();
  3928.         break;
  3929.         case SLIDER:
  3930.         /*
  3931.         @ slider start_value,end_value,width px,height px,type,label
  3932.         @ type may be: ''xy,x,y,angle``
  3933.         @ 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
  3934.         @ if a unit (or something like that...) for x/y-value display is needed, use commands ''xunit`` and / or ''yunit``
  3935.         @ 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>
  3936.         @ use command ''slider`` before draggable/clickable objects.
  3937.         @ 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>
  3938.         @ no slider for a math function, these can be traced using command ''trace_jscurve some_function_in_x``
  3939.         @ 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``
  3940.         @ amount of sliders is not limited.
  3941.         @ a slider can not be set ''snaptogrid`` or other ''snapto*`` : you may always use 'drag xy' in combination with the slider objects
  3942.         @ <code>javascript:read_dragdrop();</code> will return an array with ''object_number:slider_value``
  3943.         @ type=xy: will produce a 2D ''slider`` [rectangle width x heigh px] in your web page
  3944.         @ every draggable object may have its own slider (no limit in amount of sliders)
  3945.         @ label: some slider text
  3946.         @ use fillcolor for slider ball
  3947.         @ use strokecolor for slider bar
  3948.         @ use fontfamily / fontcolor to set used fonts
  3949.         @ use opacity (only fill opacity will be used) to set transparency
  3950.         @ the slider canvas will be added to the ''tooltip div``: so incompatible with command tooltip ; setlimits etc
  3951.         @%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
  3952.         @%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
  3953.         @%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
  3954.         */
  3955.             int_data[2] = 0; /* --> show_display = 0; */
  3956.             for(i=0; i<6 ; i++){
  3957.                 switch(i){
  3958.                     case 0: double_data[0] = get_real(infile,0);break; /* start value */
  3959.                     case 1: double_data[1] = get_real(infile,0);break; /* end value */
  3960.                     case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
  3961.                     case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
  3962.                     case 4: temp = get_string_argument(infile,0); /* type: xy,x,y,angle */
  3963.                             if( ( strstr(temp,"displ")!=0 ||  strstr(temp,"deg")!=0 ||  strstr(temp,"rad")!=0 ) && int_data[2] == 0 ){
  3964.                                 add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity);
  3965.                             }
  3966.                             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;}}
  3967.                             else
  3968.                             if(strstr(temp,"xy") != 0){slider_type = "XY";if( strstr(temp,"disp")!= 0){int_data[2] = 5;}}
  3969.                             else
  3970.                             if(strstr(temp,"x") != 0){slider_type = "X";if( strstr(temp,"disp")!= 0){int_data[2] = 1;}}
  3971.                             else
  3972.                             if(strstr(temp,"y") != 0){slider_type = "Y";if( strstr(temp,"disp")!= 0){int_data[2] = 2;}}
  3973.                             else
  3974.                             canvas_error("slider can be of type: xy,x,y,angle,fun_x:fun_y");
  3975.                             break;
  3976.                     case 5: temp = get_string_argument(infile,1); /* slider label */ break;
  3977.                 }
  3978.              }
  3979. /*
  3980. function add_slider(type,titletext,id,width,height,linewidth,fillcolor,strokecolor,opacity,min,max,fun,fontfamily)
  3981. */
  3982.             if(slider_cnt == 0){
  3983.              add_slider(js_include_file,canvas_root_id);
  3984.              active_sliders[0] = 0;
  3985.             }
  3986.             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]);
  3987.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3988.             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]);
  3989.             add_to_buffer(tmp_buffer);
  3990.             fprintf(js_include_file,"var slider%d;",slider_cnt);
  3991.             /* increment here */
  3992.             slider_cnt++;
  3993.             active_sliders[slider_cnt] = slider_cnt;
  3994.             current_sliders = data2js_array(active_sliders,slider_cnt);
  3995.         break;
  3996.  
  3997.         case SLIDER_X:
  3998.         /*
  3999.          @ sliderfunction_x some_function_in_x
  4000.          @ default value "x"
  4001.          @ the x-value of the slider object will be calculated with this function.
  4002.          @ default is the x-slider value itself
  4003.          @ only used by command ''slider``
  4004.          @ define before a slider command !
  4005.         */
  4006.          slider_function_x = get_string(infile,1);
  4007.         break;
  4008.         case SLIDER_Y:
  4009.          slider_function_y = get_string(infile,1);
  4010.          /*
  4011.          @ sliderfunction_y some_function_in_y
  4012.          @ default value "y"
  4013.          @ the y-value of the slider object(s) will be calculated with this function.
  4014.          @ only used by command ''slider``
  4015.          @ define before a slider command !
  4016.          */
  4017.         break;
  4018.         case SGRAPH:
  4019.         /*
  4020.          @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
  4021.          @ primitive implementation of a ''broken scale`` graph...
  4022.          @ 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 />
  4023.          @%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
  4024.         */
  4025.             if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
  4026.             for(i = 0 ; i < 8 ;i++){
  4027.                 switch(i){
  4028.                     case 0:double_data[0] = get_real(infile,0);break;
  4029.                     case 1:double_data[1] = get_real(infile,0);break;
  4030.                     case 2:double_data[2] = get_real(infile,0);break;
  4031.                     case 3:double_data[3] = get_real(infile,0);break;
  4032.                     case 4:int_data[0] = (int)(get_real(infile,0));break;
  4033.                     case 5:int_data[1] = (int)(get_real(infile,0));break;
  4034.                     case 6:stroke_color = get_color(infile,0);break;
  4035.                     case 7:font_color = get_color(infile,1);
  4036.                     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);
  4037.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4038.                     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);
  4039.                     add_to_buffer(tmp_buffer);
  4040.                     break;
  4041.                     default:break;
  4042.                 }
  4043.             }
  4044.             /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
  4045.             break;
  4046.  
  4047.         case SNAPTOFUNCTION:
  4048.         /*
  4049.         @ snaptofunction some_function_in_x,some_funtion_in_y
  4050.         @ alternative: <code>snaptofun some_function_in_x,some_funtion_in_y</code>
  4051.         @ the next object will snap to the calculated values
  4052.         @ note: snaptofun is probably not really useful feature...
  4053.         @ if you want only modification of y-values,just use: <code>snaptofunction x,5*sin(1/y)</code>
  4054.         @ if you want only modification of x-values,just use: <code>snaptofunction 5*sin(1/x),y</code>
  4055.         @ for now only one instance of ''snaptofunction`` is allowed
  4056.         @ use rawmath on your functions: no validity checking is done by wims !
  4057.         @ note: switching x and y coordinates? <code>snaptofunction y,x</code>
  4058.         @%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
  4059.         @%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
  4060.         */
  4061.         temp = get_string_argument(infile,0);
  4062.         use_snap = 2;
  4063.         if( use_js_math == FALSE){/* add this stuff only once...*/
  4064.             add_to_js_math(js_include_file); use_js_math = TRUE;
  4065.         }
  4066.         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));
  4067.         break;
  4068.         case SNAPTOPOINTS:
  4069.         /*
  4070.         @ snaptopoints x1,y1,x2,y2,x3,y3....
  4071.         @ a userdraw object will snap to these points.
  4072.         @ the array size (e.g. the number of points) of command ''snaptopoints`` is limited by constant MAX_INT (canvasdraw.h)
  4073.         @ a draggable object (use command ''drag x|y|xy``) will snap to the closed of these points when dragged (mouseup)
  4074.         @ other options: use keyword ''snaptogrid``, ''xsnaptogrid`` or ''ysnaptogrid``
  4075.         @%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
  4076.         */
  4077.             i = 0;
  4078.             use_snap = 4;
  4079.             while( ! done ){     /* get next item until EOL*/
  4080.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4081.                 if(i%2 == 0 ){
  4082.                     double_data[i] = get_real(infile,0); /* x */
  4083.                 }
  4084.                 else
  4085.                 {
  4086.                     double_data[i] = get_real(infile,1); /* y */
  4087.                 }
  4088.                 i++;
  4089.             }
  4090.             decimals = find_number_of_digits(precision);
  4091.             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));
  4092.         break;
  4093.  
  4094.         case SNAPTOGRID:
  4095.         /*
  4096.          @ snaptogrid
  4097.          @ keyword (no arguments required)
  4098.          @ a draggable object (use command ''drag x|y|xy``) will snap to the given grid when dragged (mouseup)
  4099.          @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
  4100.          @ if no grid is defined, points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1)
  4101.          @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
  4102.          @ 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 ...
  4103.          @%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
  4104.          @%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
  4105.         */
  4106.         use_snap = 1;
  4107.         break;
  4108.  
  4109.         case SQUARE:
  4110.         /*
  4111.         @ square x,y,side (px),color
  4112.         @ draw a square with left top corner (x:y) with side ''side`` in color ''color``
  4113.         @ use command <code>fsquare x,y,side,color</code> for a filled square
  4114.         @ use command/keyword <a href='#filled'>filled</a> before command <code>square x,y,side,color</code>
  4115.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4116.         @%square%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%filled%fillcolor blue%square 0,0,120,green
  4117.         */
  4118.             for(i=0;i<4;i++){
  4119.                 switch(i){
  4120.                     case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
  4121.                     case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
  4122.                     case 2:double_data[2] = get_real(infile,0);break; /* width in px */
  4123.                     case 3:stroke_color = get_color(infile,1);/* name or hex color */
  4124.                            decimals = find_number_of_digits(precision);
  4125.                            double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
  4126.                            double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
  4127.                            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);
  4128.                            if(onclick > 0 || slider_cnt > 0){click_cnt++;}/* click_cnt++; */
  4129.                            reset();break;
  4130.                     default: break;
  4131.                 }
  4132.             }
  4133.             break;
  4134.  
  4135.         case STATUS:
  4136.         /*
  4137.         @ status
  4138.         @ keyword
  4139.         @ alernative: nostatus
  4140.         @ used to override the effects of ''status=done`` in wims (answer.phtml)
  4141.         @ affects ''readonly`` in inputfields / textareas in canvasimage and all userdraw based commands
  4142.         @ 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``
  4143.         */
  4144.  
  4145.             fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
  4146.             break;
  4147.  
  4148.         case STRING:
  4149.         /*
  4150.          @ string color,x,y,the text string
  4151.          @ may be set ''onclick`` or ''drag xy`` ; can not be combined with command ''rotate``
  4152.          @ note: when set ''onclick`` ,use an extra command ''fontsize`` (default: fontsize=12) to adjust the size of the clicked text-string<br />note: a clicked text string will be hardcoded : fontsize+10 in the font family courier
  4153.          @ unicode supported: <code>string red,0,0,\\u2232</code>
  4154.          @ use commands like ''centered``, ''xyoffset`` etc. for labelling objects
  4155.          @ use a command like <code>fontfamily italic 24px Arial</code> to set fonts on browser that support font change
  4156.          @%string%size 400,400%xrange -10,10%yrange -10,10%fontfamily 14px Arial%crosshair -3,-3,red%crosshair 3,3,blue%string red,-3,-3,Hello World%fontfamily Italic 18px Arial%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
  4157.         */
  4158.             for(i=0;i<5;i++){
  4159.                 switch(i){
  4160.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  4161.                     case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
  4162.                     case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
  4163.                     case 3: decimals = find_number_of_digits(precision);
  4164.                         temp = get_string_argument(infile,1);
  4165.                         decimals = find_number_of_digits(precision);
  4166.                         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);
  4167.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  4168.                         onclick = 0;
  4169.                         use_offset = 0;
  4170.                         reset();;
  4171.                         break;
  4172.                     default:break;
  4173.                 }
  4174.             }
  4175.             break;
  4176.  
  4177.         case STRINGUP:
  4178.         /*
  4179.          @ stringup color,x,y,rotation_degrees,the text string
  4180.          @ can be set ''onclick``
  4181.          @ note: when set ''onclick`` ,use an extra command ''fontsize`` (default: fontsize=12) to adjust the size of the clicked text-string<br />note: a clicked text string will be hardcoded : fontsize+10 in the font family courier
  4182.          @ can <b>not</b> be set ''drag xy`` (because of translation matrix...mouse incompatible).
  4183.          @ unicode supported: <code>stringup red,0,0,45,\\u2232</code>.
  4184.          @ use a command like <code>fontfamily bold 34px Courier</code> to set fonts on browser that support font change.
  4185.          @ 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).
  4186.          @ note: no need to ''killrotate`` after ''stringup``<br /><code>onclick<br />rotate 45<br />string red,0,0,AAAAAA<br/>killrotate<br />string red,4,4,BBBBBB</code><br />is identical with:<br /><code>onclick<br />stringup red,0,0,45,AAAAAA<br />string red,4,4,BBBBBB</code>
  4187.          @%stringup%size 400,400%xrange -10,10%yrange -10,10%fontsize 24%fontfamily 14px Arial%crosshair -3,0,red%crosshair 3,0,blue%onclick%stringup green,-3,0,-90,Click me%stringup red,-3,0,-45,Hello World%stringup red,-3,0,45,Hello World%onclick%stringup green,-3,0,90,Click me%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
  4188.  
  4189.         */
  4190.              for(i=0;i<6;i++){
  4191.                 switch(i){
  4192.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  4193.                     case 1: double_data[0] = get_real(infile,0);break; /* x */
  4194.                     case 2: double_data[1] = get_real(infile,0);break; /* y */
  4195.                     case 3: angle = -1*(get_real(infile,0));break;/* rotation */
  4196.                     case 4: decimals = find_number_of_digits(precision);
  4197.                         temp = get_string_argument(infile,1);
  4198.                         use_rotate = TRUE;
  4199.                         decimals = find_number_of_digits(precision);
  4200.                         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);
  4201.                         if(onclick > 0 || slider_cnt > 0){
  4202.                          if( js_function[ADD_JS_ROTATE_MOUSE] != 1 ){
  4203.                           js_function[ADD_JS_ROTATE_MOUSE] = 1;
  4204.                          }
  4205.                          click_cnt++;
  4206.                         }
  4207.                         onclick = 0;
  4208.                         use_offset = 0;
  4209.                         reset();
  4210.                         break;
  4211.                     default:break;
  4212.                 }
  4213.             }
  4214.             angle = 0.0;
  4215.             use_rotate = FALSE;
  4216.             break;
  4217.  
  4218.         case STYLE:
  4219.         /*
  4220.          @ highlight color,opacity,linewidth
  4221.          @ NOT IMPLEMENTED
  4222.          @ use command ''onclick``: when the object receives a userclick it will increase its linewidth
  4223.         */
  4224.             break;
  4225.  
  4226.  
  4227.         case STROKECOLOR:
  4228.         /*
  4229.         @ strokecolor colorname or #hex
  4230.         @ to be used for commands that do not supply a color argument (like command ''linegraph``)
  4231.         */
  4232.             stroke_color = get_color(infile,1);
  4233.             break;
  4234.  
  4235.         case FLY_TEXT:
  4236.         /*
  4237.         @ text fontcolor,x,y,font,text_string
  4238.         @ font may be described by keywords: giant,huge,normal,small,tiny
  4239.         @ use command ''fontsize`` to increase the base fontsize for these keywords
  4240.         @ may be set ''onclick`` or ''drag xy`` ; may not be combined with command ''rotate``
  4241.         @ backwards compatible with flydraw
  4242.         @ unicode supported: text red,0,0,huge,\\u2232
  4243.         @ use command ''string`` combined with ''fontfamily`` for a more fine grained control over html5 canvas text element
  4244.         @ Aavoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``, ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Arial</code>. In that case reset ''fontfamily`` to something lke ''fontfamily Arial`` before the old flydraw commands.
  4245.         @%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
  4246.         */
  4247.             for(i = 0; i < 5 ;i++){
  4248.                 switch(i){
  4249.                     case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
  4250.                     case 1: double_data[0] = get_real(infile,0);break; /* x */
  4251.                     case 2: double_data[1] = get_real(infile,0);break; /* y */
  4252.                     case 3: fly_font = get_string_argument(infile,0);
  4253.                             if(strcmp(fly_font,"giant") == 0){
  4254.                                 fly_font_size = (int)(font_size + 24);
  4255.                             }
  4256.                             else
  4257.                             {
  4258.                                 if(strcmp(fly_font,"huge") == 0){
  4259.                                     fly_font_size = (int)(font_size + 14);
  4260.                                 }
  4261.                                 else
  4262.                                 {
  4263.                                     if(strcmp(fly_font,"large") == 0){
  4264.                                         fly_font_size = (int)(font_size + 6);
  4265.                                         }
  4266.                                         else
  4267.                                         {
  4268.                                             if(strcmp(fly_font,"small") == 0){
  4269.                                                 fly_font_size = (int)(font_size - 4);
  4270.                                                 if(fly_font_size<0){fly_font_size = 8;}
  4271.                                         }
  4272.                                     }
  4273.                                 }
  4274.                             }
  4275.                             break;
  4276.                     case 4:
  4277.                         temp = get_string_argument(infile,1);
  4278.                         decimals = find_number_of_digits(precision);
  4279.                         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);
  4280.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  4281.                         onclick=0;
  4282.                         use_offset = 0;
  4283.                         reset();
  4284.                         break;
  4285.                     default:break;
  4286.                 }
  4287.             }
  4288.             break;
  4289.         case TEXTAREA:
  4290.         /*
  4291.          @ textarea x,y,cols,rows,readonly,value
  4292.          @ may be further controlled by <a href="#inputstyle">inputstyle</a>
  4293.          @ 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>.
  4294.          @ 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>)
  4295.          @ keyword ''xoffset | centered`` is not active for command ''textarea``
  4296.          @%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,?
  4297.         */
  4298.             if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}
  4299.             for(i = 0 ; i<6;i++){
  4300.                 switch(i){
  4301.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
  4302.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
  4303.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
  4304.                     case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
  4305.                     case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
  4306.                     case 5: temp = get_string_argument(infile,1);
  4307.                             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);
  4308.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4309.                             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);
  4310.                             add_to_buffer(tmp_buffer);
  4311.                             input_cnt++;break;
  4312.                     default: break;
  4313.                 }
  4314.             }
  4315.             if(reply_format == 0 ){reply_format = 15;}
  4316.             reset();
  4317.             break;
  4318.  
  4319.         case TEXTFILL:
  4320.         /*
  4321.         @ textfill x0,y0,color,some_text
  4322.         @ x0,y0 in xrange / yrange
  4323.         @ color will be used for the font color
  4324.         @ use command <a href="#fontfamily">fontfamily</a> to set font type and size
  4325.         @ there is also a command <a href="#userdraw">userdraw textfill,color,some_text</a>
  4326.         @%textfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fontfamily 24pt Arial%circles red,0,0,3,3,3,6%textfill 4,4,blue,HELLO WORLD
  4327.         */
  4328.  
  4329.             js_function[DRAW_TEXTFILL] = 1;
  4330.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  4331.              js_function[DRAW_FILLTOBORDER] = 1;
  4332.              add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
  4333.             }
  4334.             decimals = find_number_of_digits(precision);
  4335.             for(i=0;i<4;i++){
  4336.                 switch(i){
  4337.                     case 0: double_data[0] = get_real(infile,0); break; /* x in px */
  4338.                     case 1: double_data[1] = get_real(infile,0); break; /* y in py */
  4339.                     case 2: font_color = get_color(infile,0); break;
  4340.                     case 3: temp = get_string(infile,1);
  4341.                     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);
  4342.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4343.                     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);
  4344.                     add_to_buffer(tmp_buffer);
  4345.                     fill_cnt++;
  4346.                     break;
  4347.                     default:break;
  4348.                 }
  4349.             }
  4350.             reset();
  4351.         break;
  4352.  
  4353.  
  4354.         case FLY_TEXTUP:
  4355.         /*
  4356.          @ textup fontcolor,x,y,font,text_string
  4357.          @ can <b>not</b> be set ''onclick`` or ''drag xy`` (because of translaton matrix...mouse incompatible)
  4358.          @ font may be described by keywords: giant,huge,normal,small,tiny
  4359.          @ use command ''fontsize`` to increase base fontsize for the keywords
  4360.          @ backwards compatible with flydraw
  4361.          @ unicode supported: textup red,0,0,huge,\\u2232
  4362.          @ use command ''stringup`` and ''fontfamily`` for a more fine grained control over html5 canvas text element
  4363.          @ Avoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``; ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Arial</code>. In that case reset ''fontfamily`` to something like ''fontfamily Arial`` before the old flydraw commands.
  4364.         */
  4365.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
  4366.             for(i = 0; i<5 ;i++){
  4367.                 switch(i){
  4368.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  4369.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  4370.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  4371.                     case 3: fly_font = get_string_argument(infile,0);
  4372.                             if(strcmp(fly_font,"giant") == 0){
  4373.                                 fly_font_size = (int)(font_size + 24);
  4374.                             }
  4375.                             else
  4376.                             {
  4377.                                 if(strcmp(fly_font,"huge") == 0){
  4378.                                     fly_font_size = (int)(font_size + 14);
  4379.                                 }
  4380.                                 else
  4381.                                 {
  4382.                                     if(strcmp(fly_font,"large") == 0){
  4383.                                         fly_font_size = (int)(font_size + 6);
  4384.                                         }
  4385.                                         else
  4386.                                         {
  4387.                                             if(strcmp(fly_font,"small") == 0){
  4388.                                                 fly_font_size = (int)(font_size - 4);
  4389.                                                 if(fly_font_size<0){fly_font_size = 8;}
  4390.                                         }
  4391.                                     }
  4392.                                 }
  4393.                             }
  4394.                             break;
  4395.                     case 4:
  4396.                     decimals = find_number_of_digits(precision);
  4397.                     temp = get_string_argument(infile,1);
  4398.                     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);
  4399.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4400.                     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);
  4401.                     add_to_buffer(tmp_buffer);
  4402.                     reset();use_offset = 0;
  4403.                     break;
  4404.                     default:break;
  4405.                 }
  4406.             }
  4407.             break;
  4408.  
  4409.  
  4410.         case TRACE_JSCURVE:
  4411.         /*
  4412.          @ trace_jscurve some_math_function
  4413.          @ will use a crosshair to trace the jsmath curve
  4414.          @ two inputfields will display the current x/y-values (numerical evaluation by javascript)
  4415.          @ 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
  4416.          @ use commands fontsize and inputstyle to format the fonts for labels and inputfields.
  4417.          @ use commands ''linewidth, strokecolor, crosshairsize`` to adjust the corsshair.
  4418.          @ 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...)
  4419.          @ be aware that the formulas of the plotted function(s) can be found in the page javascript source
  4420.          @%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
  4421.         */
  4422.             if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  4423.             if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4424.             if( use_js_math == FALSE){
  4425.                 add_to_js_math(js_include_file);
  4426.                 use_js_math = TRUE;
  4427.             }
  4428.             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);
  4429.             break;
  4430.  
  4431.  
  4432.         case TRANGE:
  4433.         /*
  4434.         @ trange tmin,tmax
  4435.         @ alternative: <code>ranget</code>
  4436.         @ default -2,2
  4437.         */
  4438.             use_parametric = TRUE;
  4439.             for(i = 0 ; i<2; i++){
  4440.                 switch(i){
  4441.                     case 0: tmin = get_real(infile,0);break;
  4442.                     case 1: tmax = get_real(infile,1);break;
  4443.                     default: break;
  4444.                 }
  4445.             }
  4446.             if(tmin >= tmax ){canvas_error(" trange is not OK: tmin &lt; tmax!\n");}
  4447.             break;
  4448.         case TRANSLATION:
  4449.         /*
  4450.          @ translation tx,ty
  4451.          @ alternative: <code>translate</code>
  4452.          @ will translate the next objects tx in xrange and ty in yrange
  4453.          @ use command ''killtranstation`` to end the command
  4454.          @%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
  4455.         */
  4456.             for(i = 0 ; i<2;i++){
  4457.                 switch(i){
  4458.                     case 0: double_data[0] = get_real(infile,0);break;
  4459.                     case 1: double_data[1] = get_real(infile,1);
  4460.                         use_affine = TRUE;
  4461.                         string_length = 1 + snprintf(NULL,0, "[1,0,0,1,%d,%d]",(int)(double_data[0]*xsize/(xmax - xmin)),(int)(-1*double_data[1]*ysize/(ymax - ymin)));
  4462.                         check_string_length(string_length);affine_matrix = my_newmem(string_length);
  4463.                         snprintf(affine_matrix,string_length,"[1,0,0,1,%d,%d]",(int)(double_data[0]*xsize/(xmax - xmin)),(int)(-1*double_data[1]*ysize/(ymax - ymin)));
  4464.                         if( js_function[ADD_JS_TRANSFORM_MOUSE] != 1 ){ js_function[ADD_JS_TRANSFORM_MOUSE] = 1;}
  4465.                         break;
  4466.                     default: break;
  4467.                 }
  4468.             }
  4469.         break;
  4470.  
  4471.         case TRIANGLE:
  4472.         /*
  4473.          @ triangle x1,y1,x2,y2,x3,y3,color
  4474.          @ use ftriangle or keyword <a href='#filled'>filled</a> for a solid triangle
  4475.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4476.          @%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
  4477.         */
  4478.             for(i=0;i<7;i++){
  4479.                 switch(i){
  4480.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  4481.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  4482.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  4483.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  4484.                     case 4: double_data[4] = get_real(infile,0);break; /* x */
  4485.                     case 5: double_data[5] = get_real(infile,0);break; /* y */
  4486.                     case 6: stroke_color = get_color(infile,1);/* name or hex color */
  4487.                         decimals = find_number_of_digits(precision);
  4488.                         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);
  4489.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  4490.                         /* click_cnt++;*/
  4491.                         reset();
  4492.                         break;
  4493.                     default: break;
  4494.                 }
  4495.             }
  4496.             break;
  4497.         case TRIANGLES:
  4498.         /*
  4499.          @ triangles color,x1,y1,x2,y2,x3,y3,...
  4500.          @ use ftriangles or keyword <a href='#filled'>filled</a> for solid triangles
  4501.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  4502.          @%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
  4503.         */
  4504.             stroke_color = get_color(infile,0);/* name or hex color */
  4505.             i = 0;
  4506.             decimals = find_number_of_digits(precision);
  4507.             while( ! done ){
  4508.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4509.                 double_data[0] = get_real(infile,0); /* x1 */
  4510.                 double_data[1] = get_real(infile,0); /* y1 */
  4511.                 double_data[2] = get_real(infile,0); /* x2 */
  4512.                 double_data[3] = get_real(infile,0); /* y2 */
  4513.                 double_data[4] = get_real(infile,0); /* x3 */
  4514.                 double_data[5] = get_real(infile,1); /* y3 */
  4515.                 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);
  4516.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  4517.                 i = i + 6;
  4518.             }
  4519.             reset();
  4520.             break;
  4521.         case USERBOXPLOT:
  4522.         /*
  4523.          @ userboxplot
  4524.          @ keyword, no arguments
  4525.          @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a>
  4526.          @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the ''draw_boxplot`` function
  4527.          @ 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)
  4528.         */
  4529.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  4530.             fprintf(js_include_file,"var boxplot_source = 3;\n");
  4531.             js_function[DRAW_JSBOXPLOT] = 2;
  4532.         break;
  4533.  
  4534.         case USERBOXPLOTDATA:
  4535.         /*
  4536.          @ userboxplotdata
  4537.          @ keyword, no arguments
  4538.          @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a>
  4539.          @ if set, the student will have to generate some statistical data. These data should be put in a named array ''student_boxplot_data``
  4540.          @ ''min,Q1,median,Q3,max`` are calculated by a js-function and the ''draw_boxplot`` function will draw a boxplot.
  4541.          @ see command <a href="#userboxplot">userboxplot</a> for calling 'draw_boxplot()'
  4542.         */
  4543.             if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
  4544.             fprintf(js_include_file,"var boxplot_source = 2;\n");
  4545.             js_function[DRAW_JSBOXPLOT] = 1;
  4546.  
  4547.         break;
  4548.  
  4549.         case USERDRAW:
  4550.         /*
  4551.         @ userdraw object_type,color
  4552.         @ only a single object_type is allowed.
  4553.         @ for multiple different ''userdraw`` objects in an exercise, use command <a href="#multidraw">multidraw</a>
  4554.         @ 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>
  4555.         @ 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)
  4556.         @ 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
  4557.         @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
  4558.         @ 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)
  4559.         @ use a prefix <a href='#filled'>filled</a> or ''f`` to set fillable objects filled. (fcircles, filledcircles, etc)
  4560.         @ for non solid filling, use command <a href="#fillpattern">fillpattern grid,hatch,diamond,dot</a>
  4561.         @ use <a href='#opacity'>opacity int,int</a> and <a href='#fillcolor'>fillcolor color</a> to trigger coloured filling of fillable objects
  4562.         @ use command ''dashed`` and/or ''dashtype int,int`` to trigger dashing
  4563.         @ use command ''replyformat int`` to control / adjust output formatting of javascript function read_canvas(); (the defaults should be fine...)
  4564.         @ may be combined with onclick or drag xy of other components of flyscript objects (although not very useful...)
  4565.         @ may be combined with keyword <a href='#userinput_xy'>userinput_xy</a>
  4566.         @ may be combined width the <a href='#snaptogrid'>snaptogrid snaptopoints </a> etc, to simplify the checking of the student reply
  4567.         @ the cursor may be appropriately styled using command <a href='cursor'>cursor</a>
  4568.         @ 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...
  4569.         @ 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)
  4570.         @ 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!)
  4571.         @%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
  4572.         @%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
  4573.         @%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
  4574.         @%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
  4575.         @%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
  4576.         @%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
  4577.         @%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
  4578.         @%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
  4579.         @%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
  4580.         @%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
  4581.         @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
  4582.         @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
  4583.         @%userdraw_vline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vline,green
  4584.         @%userdraw_vlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vlines,green
  4585.         @%userdraw_hline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hline,green
  4586.         @%userdraw_hlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hlines,green
  4587.         @%userdraw_demiline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demiline,green
  4588.         @%userdraw_demilines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demilines,green
  4589.         @%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
  4590.         @%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
  4591.         @%userdraw_point%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw point,green
  4592.         @%userdraw_points%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw points,green
  4593.         @%userdraw_arrow%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow,green
  4594.         @%userdraw_arrows%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows,green
  4595.         @%userdraw_arrow2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow2,green
  4596.         @%userdraw_arrows2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows2,green
  4597.         @%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
  4598.         @%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
  4599.         @%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
  4600.         @%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
  4601.         @%userdraw_crosshair%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshair,green
  4602.         @%userdraw_crosshairs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshairs,green
  4603.         @%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
  4604.         @%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
  4605.         @%userdraw_segment%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segment,green
  4606.         @%userdraw_segments%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segments,green
  4607.         @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
  4608.         @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
  4609.         @%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
  4610.         @%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
  4611.         @%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
  4612.         @%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
  4613.         @%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
  4614.         @%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
  4615.         @%userdraw_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandline,green
  4616.         @%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
  4617.         @%userdraw_freehandlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandlines,green
  4618.         @%userdraw_input%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw input,green
  4619.         @%userdraw_inputs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw inputs,green
  4620.         @%userdraw_text%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%fontfamily 42px Courier%userdraw text,green
  4621.         @%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
  4622.         @%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
  4623.         @%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
  4624.         @%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
  4625.         */
  4626.             if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
  4627.                 canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");
  4628.             }
  4629.             reply_precision = precision;
  4630.             use_userdraw = TRUE;
  4631.             fprintf(js_include_file,"\n/* begin userdraw mouse events */\n\
  4632.             userdraw_x = new Array();userdraw_y = new Array();\
  4633.             userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\
  4634.             var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;\
  4635.             if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\
  4636.             if(wims_status != \"done\"){\
  4637.              canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\
  4638.              canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\
  4639.              canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
  4640.              canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\
  4641.             }\n/* end userdraw mouse & touch events */",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
  4642.  
  4643. //           canvas_div.addEventListener(\"touchend\"  ,function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);
  4644.             draw_type = get_string_argument(infile,0);
  4645.             stroke_color = get_color(infile,1);
  4646.             if( strcmp(draw_type,"point") == 0 ){
  4647.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4648.                 if(reply_format == 0 ){reply_format = 8;}
  4649.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  4650. /*
  4651. type = 0: a point ...radius is fixed
  4652. type = 1: a circle ... read inputfield userinput_r
  4653. num = 1: a single point / circle
  4654. num = 2: multiple points / circles
  4655. */
  4656.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4657.                 if(use_input_xy == 1){
  4658.                     add_input_circle(js_include_file,0,1);
  4659.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4660.                 }
  4661.                 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);
  4662.             }
  4663.             else
  4664.             if( strcmp(draw_type,"points") == 0 ){
  4665.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4666.                 if(reply_format == 0 ){reply_format = 8;}
  4667.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  4668.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4669.                 if(use_input_xy == 1){
  4670.                     add_input_circle(js_include_file,0,2);
  4671.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4672.                 }
  4673.                 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);
  4674.             }
  4675.             else
  4676.             if( strcmp(draw_type,"segment") == 0 ){
  4677.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4678.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  4679.                 if(reply_format == 0){reply_format = 11;}
  4680.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4681.                 if(use_input_xy == 1){
  4682.                     add_input_segment(js_include_file,1);
  4683.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4684.                 }
  4685.                 add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4686.             }
  4687.             else
  4688.             if( strcmp(draw_type,"polyline") == 0 ||  strcmp(draw_type,"brokenline") == 0 ){
  4689.                 if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
  4690.                 if(reply_format == 0){reply_format = 23;}
  4691.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4692.                 if( use_input_xy == 1 ){
  4693.                     add_input_polyline(js_include_file);
  4694.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4695.                 }
  4696.                 add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4697.             }
  4698.             else
  4699.             if( strcmp(draw_type,"segments") == 0 ){
  4700.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4701.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  4702.                 if(reply_format == 0){reply_format = 11;}
  4703.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4704.                 if(use_input_xy == 1){
  4705.                     add_input_segment(js_include_file,2);
  4706.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4707.                 }
  4708.                 add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4709.             }
  4710.             else
  4711.             if( strcmp(draw_type,"circle") == 0 || strcmp(draw_type,"fcircle") == 0  || strcmp(draw_type,"filledcircle") == 0 ){
  4712.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4713.                 if(reply_format == 0){reply_format = 10;}
  4714.                 if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}}
  4715.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  4716.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4717.                 if(use_input_xy == 1){
  4718. /*
  4719. type = 0: a point ...radius is fixed
  4720. type = 1: a circle ... read inputfield userinput_r
  4721. num = 1: a single point / circle
  4722. num = 2: multiple points / circles
  4723. */
  4724.                     add_input_circle(js_include_file,1,1);
  4725.                     add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
  4726.                 }
  4727.                 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);
  4728.             }
  4729.             else
  4730.             if( strcmp(draw_type,"circles") == 0 || strcmp(draw_type,"fcircles") == 0 || strcmp(draw_type,"filledcircles") == 0 ){
  4731.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4732.                 if(reply_format == 0){reply_format = 10;}
  4733.                 if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4734.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  4735.                 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);
  4736.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4737.                 if(use_input_xy == 1){
  4738.                     add_input_circle(js_include_file,1,2);
  4739.                     add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
  4740.                 }
  4741.             }
  4742.             else
  4743.             if(strcmp(draw_type,"crosshair") == 0 ){
  4744.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  4745.                 if(reply_format == 0){reply_format = 8;}
  4746.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  4747.                 add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity,use_snap);
  4748.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4749.                 if(use_input_xy == 1){
  4750.                     add_input_crosshair(js_include_file,1);
  4751.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4752.                 }
  4753.             }
  4754.             else
  4755.             if(strcmp(draw_type,"crosshairs") == 0 ){
  4756.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  4757.                 if(reply_format == 0){reply_format = 8;}
  4758.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  4759.                 add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity,use_snap);
  4760.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4761.                 if(use_input_xy == 1){
  4762.                     add_input_crosshair(js_include_file,2);
  4763.                     add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
  4764.                 }
  4765.             }
  4766.             else
  4767.             if(strcmp(draw_type,"freehandline") == 0 ){
  4768.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4769.                 if(reply_format == 0){reply_format = 6;}
  4770.                 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);
  4771.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4772.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4773.             }
  4774.             else
  4775.             if(strcmp(draw_type,"freehandlines") == 0 ){
  4776.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4777.                 if(reply_format == 0){reply_format = 6;}
  4778.                 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);
  4779.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4780.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4781.             }
  4782.             else
  4783.             if(strcmp(draw_type,"path") == 0 || strcmp(draw_type,"fpath") == 0 || strcmp(draw_type,"filledpath") == 0 ){
  4784.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4785.                 if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4786.                 if(reply_format == 0){reply_format = 6;}
  4787.                 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);
  4788.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4789.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4790.             }
  4791.             else
  4792.             if(strcmp(draw_type,"paths") == 0 || strcmp(draw_type,"fpaths") == 0  || strcmp(draw_type,"filledpaths") == 0 ){
  4793.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4794.                 if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4795.                 if(reply_format == 0){reply_format = 6;}
  4796.                 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);
  4797.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4798.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4799.             }
  4800.             else
  4801.             if(strcmp(draw_type,"arrows") == 0 ){
  4802.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  4803.                 if(reply_format == 0){reply_format = 11;}
  4804.                 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);
  4805.                 if(use_input_xy == 1){
  4806.                     add_input_arrow(js_include_file,2);
  4807.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4808.                 }
  4809.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4810.             }
  4811.             else
  4812.             if(strcmp(draw_type,"arrows2") == 0 ){
  4813.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  4814.                 if(reply_format == 0){reply_format = 11;}
  4815.                 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);
  4816.                 if(use_input_xy == 1){
  4817.                     add_input_arrow(js_include_file,1);
  4818.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4819.                 }
  4820.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4821.             }
  4822.             else
  4823.             if(strcmp(draw_type,"arrow2") == 0 ){
  4824.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  4825.                 if(reply_format == 0){reply_format = 11;}
  4826.                 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);
  4827.                 if(use_input_xy == 1){
  4828.                     add_input_arrow(js_include_file,1);
  4829.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4830.                 }
  4831.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4832.             }
  4833.             else
  4834.             if(strcmp(draw_type,"arrow") == 0 ){
  4835.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  4836.                 if(reply_format == 0){reply_format = 11;}
  4837.                 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);
  4838.                 if(use_input_xy == 1){
  4839.                     add_input_arrow(js_include_file,1);
  4840.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4841.                 }
  4842.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4843.             }
  4844.             else
  4845.             if( strcmp(draw_type,"curvedarrow2") == 0 ){
  4846.                 if(reply_format == 0){reply_format = 2;}
  4847.                 add_js_curvedarrow(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,2,use_snap);
  4848.                 if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4849.             }
  4850.             else
  4851.             if( strcmp(draw_type,"curvedarrows2") == 0 ){
  4852.                 if(reply_format == 0){reply_format = 2;}
  4853.                 add_js_curvedarrow(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,2,use_snap);
  4854.                 if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4855.             }
  4856.             else
  4857.             if( strcmp(draw_type,"curvedarrows") == 0 ){
  4858.                 if(reply_format == 0){reply_format = 2;}
  4859.                 add_js_curvedarrow(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,1,use_snap);
  4860.                 if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4861.             }
  4862.             else
  4863.             if( strcmp(draw_type,"curvedarrow") == 0 ){
  4864.                 if(reply_format == 0){reply_format = 2;}
  4865.                 add_js_curvedarrow(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,1,use_snap);
  4866.                 if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4867.             }
  4868.             else
  4869.             if(strcmp(draw_type,"polygon") == 0 || strcmp(draw_type,"fpolygon") == 0 || strcmp(draw_type,"filledpolygon") == 0){
  4870.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4871.                 if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4872.                 if(reply_format == 0){reply_format = 2;}
  4873.                 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);
  4874.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4875.                 if(use_input_xy == 2){
  4876.                   add_textarea_polygon(js_include_file);
  4877.                   add_textarea_xy(js_include_file,canvas_root_id,input_style);
  4878.                 }
  4879.             }
  4880.             else
  4881.             if(strncmp(draw_type,"poly",4) == 0){
  4882.                 if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
  4883.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4884.                 if(reply_format == 0){reply_format = 2;}
  4885.                 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);
  4886.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4887.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4888.             }
  4889.             else
  4890.             if(strcmp(draw_type,"triangle") == 0 || strcmp(draw_type,"ftriangle") == 0 || strcmp(draw_type,"filledtriangle") == 0){
  4891.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  4892.                 if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4893.                 if(reply_format == 0){reply_format = 2;}
  4894.                 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);
  4895.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4896.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4897.             }
  4898.             else
  4899.             if( strcmp(draw_type,"hline") == 0 ){
  4900.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4901.                 if(reply_format == 0){reply_format = 11;}
  4902.                 add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4903.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4904.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4905.             }
  4906.             else
  4907.             if( strcmp(draw_type,"hlines") == 0 ){
  4908.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4909.                 if(reply_format == 0){reply_format = 11;}
  4910.                 add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4911.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4912.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4913.             }
  4914.             else
  4915.             if( strcmp(draw_type,"vline") == 0 ){
  4916.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4917.                 if(reply_format == 0){reply_format = 11;}
  4918.                 add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4919.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4920.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4921.             }
  4922.             else
  4923.             if( strcmp(draw_type,"vlines") == 0 ){
  4924.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4925.                 if(reply_format == 0){reply_format = 11;}
  4926.                 add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4927.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4928.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4929.             }
  4930.             else
  4931.             if( strcmp(draw_type,"line") == 0 ){
  4932.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4933.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4934.                 if(reply_format == 0){reply_format = 11;}
  4935.                 add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4936.                 if( use_input_xy == 1 ){
  4937.                     add_input_line(js_include_file,1);
  4938.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4939.                 }
  4940.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4941.             }
  4942.             else
  4943.             if( strcmp(draw_type,"lines") == 0 ){
  4944.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4945.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  4946.                 if(reply_format == 0){reply_format = 11;}
  4947.                 add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4948.                 if( use_input_xy == 1 ){
  4949.                     add_input_line(js_include_file,2);
  4950.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4951.                 }
  4952.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4953.             }
  4954.             else
  4955.             if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"halflines") == 0 ){
  4956.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4957.                 if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
  4958.                 if(reply_format == 0){reply_format = 11;}
  4959.                 add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4960.                 if( use_input_xy == 1 ){
  4961.                     add_input_demiline(js_include_file,2);
  4962.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4963.                 }
  4964.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4965.             }
  4966.             else
  4967.             if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"halfline") == 0 ){
  4968.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  4969.                 if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
  4970.                 if(reply_format == 0){reply_format = 11;}
  4971.                 add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
  4972.                 if( use_input_xy == 1 ){
  4973.                     add_input_demiline(js_include_file,1);
  4974.                     add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
  4975.                 }
  4976.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4977.             }
  4978.             else
  4979.             if( strcmp(draw_type,"rects") == 0 || strcmp(draw_type,"frects") == 0  || strcmp(draw_type,"filledrects") == 0 ){
  4980.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  4981.                 if(strstr(draw_type,"f") != NULL){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4982.                 if(reply_format == 0){reply_format = 2;}
  4983.                 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);
  4984.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4985.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4986.             }
  4987.             else
  4988.             if( strcmp(draw_type,"roundrects") == 0 ||  strcmp(draw_type,"froundrects") == 0  ||  strcmp(draw_type,"filledroundrects") == 0){
  4989.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  4990.                 if( strstr(draw_type,"f") != NULL ){ if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  4991.                 if(reply_format == 0){reply_format = 2;}
  4992.                 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);
  4993.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  4994.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  4995.             }
  4996.             else
  4997.             if( strcmp(draw_type,"rect") == 0 || strcmp(draw_type,"frect") == 0 || strcmp(draw_type,"filledrect") == 0 ){
  4998.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  4999.                 if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
  5000.                 if(reply_format == 0){reply_format = 2;}
  5001.                 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);
  5002.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  5003.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  5004.             }
  5005.             else
  5006.             if( strcmp(draw_type,"roundrect") == 0 || strcmp(draw_type,"froundrect") == 0  || strcmp(draw_type,"filledroundrect") == 0){
  5007.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  5008.                 if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}}
  5009.                 if(reply_format == 0){reply_format = 2;}
  5010.                 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);
  5011.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  5012.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  5013.             }
  5014.             else
  5015.             if( strcmp(draw_type,"arcs") == 0 || strcmp(draw_type,"farcs") == 0  || strcmp(draw_type,"filledarcs") == 0 ){
  5016.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  5017.                 if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
  5018.                 if( strstr(draw_type,"f") != NULL ){use_filled =1;}
  5019.                 if(reply_format == 0){reply_format = 25;}
  5020.                 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);
  5021.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  5022.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  5023.             }
  5024.             else
  5025.             if( strcmp(draw_type,"arc") == 0 || strcmp(draw_type,"farc") == 0 || strcmp(draw_type,"filledarc") == 0){
  5026.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  5027.                 if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
  5028.                 if( strstr(draw_type,"f") != NULL ){use_filled =1;}
  5029.                 if(reply_format == 0){reply_format = 25;}
  5030.                 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);
  5031.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  5032.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  5033.             }
  5034.             else
  5035.             if( strcmp(draw_type,"text") == 0){
  5036.                 if(reply_format == 0){reply_format = 17;}
  5037.                 add_js_text(js_include_file,canvas_root_id,font_size,font_family,stroke_color,stroke_opacity,use_snap);
  5038.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  5039.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  5040.             }
  5041.             else
  5042.             if( strcmp(draw_type,"images") == 0){
  5043.                 if(reply_format == 0){reply_format = 29;}
  5044.                 add_js_images(js_include_file,canvas_root_id,use_offset,use_snap);
  5045.             }
  5046.             else
  5047.             if( strcmp(draw_type,"inputs") == 0){
  5048.                 if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  5049.                 if(reply_format == 0){reply_format = 27;}
  5050.                 add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width,use_offset,use_snap);
  5051.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  5052.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  5053.             }
  5054.             else
  5055.             if( strcmp(draw_type,"input") == 0){
  5056.                 if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
  5057.                 if(reply_format == 0){reply_format = 27;}
  5058.                 add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width,use_offset,use_snap);
  5059.                 if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
  5060.                 if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
  5061.             }
  5062.             else /* attention: THIS NEEDS TO BE LAST ! */
  5063.             if( strstr(draw_type,"fill") != NULL ){
  5064.                 decimals = find_number_of_digits(precision);
  5065.                 add_js_clickfill(js_include_file,canvas_root_id,stroke_color,(int) (fill_opacity/0.0039215),use_snap);
  5066.                 if( reply_format == 0){reply_format = 10;}
  5067.                 if( js_function[DRAW_FILLTOBORDER] != 1 ){js_function[DRAW_FILLTOBORDER] = 1;add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);}
  5068.                 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++;}
  5069.                 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++;}
  5070.                 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++;}
  5071.                 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++;}
  5072.                 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++;}
  5073.             }
  5074.             else
  5075.             {
  5076.                 canvas_error("unknown drawtype or typo? ");
  5077.             }
  5078.             reset();
  5079.         break;
  5080.  
  5081.         case USERINPUT:
  5082.         /*
  5083.          @ userinput function inputfield
  5084.          @ alternative: <code>userinput_function</code>
  5085.          @ alternative: <code>userinput_xy</code>
  5086.          @ textarea and inputfield are only usable in combination with some ''userdraw draw_ type``
  5087.          @ function may be used any time (e.g. without userdraw)
  5088.          @ multiple ''userinput function`` commands may be used.
  5089.          @ use command <code>functionlabel some_string</code> to define the inputfield text: default value "f(x)="
  5090.          @ use command <code>strokecolor some_color</code> to adjust the plot / functionlabel color
  5091.          @ use command <code>inputstyle some_css</code> to adjust the inputfields
  5092.          @ use command <code>fontsize int</code> to adjust the label fonts. (default 12px)
  5093.          @ 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
  5094.          @%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
  5095.          @%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
  5096.          @%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
  5097.          @%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
  5098.         */
  5099.             temp = get_string_argument(infile,1);
  5100.             if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
  5101.              if( js_function[DRAW_JSFUNCTION] != 1 ){
  5102.               add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */
  5103.               js_function[DRAW_JSFUNCTION] = 1;
  5104.               if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  5105.               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);
  5106.               input_cnt++;
  5107.              }
  5108.              else
  5109.              {
  5110.               /* no need to add DRAW_JSFUNCTION, just call it with the parameters */
  5111.               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);
  5112.               input_cnt++;
  5113.              }
  5114.              if( use_js_math == FALSE){/* add this stuff only once...*/
  5115.               add_to_js_math(js_include_file);
  5116.               use_js_math = TRUE;
  5117.              }
  5118.              if( use_js_plot == FALSE){
  5119.               use_js_plot = TRUE;
  5120.               add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  5121.              }
  5122.             }
  5123.             else
  5124.             {
  5125.              if(strstr(temp,"inputfield") != 0 ){
  5126.               if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
  5127.               if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  5128.               use_input_xy = 1;
  5129.              }
  5130.              else
  5131.              {
  5132.               if(strstr(temp,"textarea") != 0 ){
  5133.                if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
  5134.                if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  5135.                use_input_xy = 2;
  5136.               }
  5137.               else
  5138.               {
  5139.                 canvas_error("userinput argument may be \"function,inputfield,textarea\"");
  5140.               }
  5141.              }
  5142.             }
  5143.             break;
  5144.         case USERINPUT_XY:
  5145.         /*
  5146.         @ userinput_xy
  5147.         @ keyword (no arguments required)
  5148.         @ to be used in combination with command "userdraw object_type,color"
  5149.         @ 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)
  5150.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  5151.         @ 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.
  5152.         @ can <b>not</b> be combined with command ''intooltip tiptext`` <br />note: the ''tooltip div element`` is used for placing inputfields
  5153.         @ user drawings will not zoom on zooming (or pan on panning)
  5154.         @ use command inputstyle some_css`` to adjust the inputarea.
  5155.         @ use command ''fontsize int`` to adjust the text labels (if needed)
  5156.         @%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
  5157.         */
  5158.             /* add simple eval check to avoid code injection with unprotected eval(string) */
  5159.             if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
  5160.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  5161.             use_input_xy = 1;
  5162.             break;
  5163.  
  5164.         case USERINPUT_FUNCTION:
  5165.         /*
  5166.         @ userinput_function
  5167.         @ keyword (no arguments required)
  5168.         @ if set, a inputfield will be added to the page
  5169.         @ repeat keyword for more function input fields
  5170.         @ the userinput value will be plotted in the canvas
  5171.         @ 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
  5172.         @ 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
  5173.         @ fontsize can be set using command ''fontsize int``
  5174.         @ incompatible with command ''intooltip link_text_or_image``: it uses the tooltip div for adding the inputfield
  5175.         @%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
  5176.         */
  5177.             if( js_function[DRAW_JSFUNCTION] != 1 ){
  5178.              js_function[DRAW_JSFUNCTION] = 1;
  5179.              add_rawmath(js_include_file);
  5180.              if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  5181.              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);
  5182.              input_cnt++;
  5183.             }
  5184.             else
  5185.             {
  5186.               /* no need to add DRAW_JSFUNCTION, just call it with the parameters */
  5187.              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);
  5188.              input_cnt++;
  5189.             }
  5190.             if( use_js_math == FALSE){/* add this stuff only once...*/
  5191.              add_to_js_math(js_include_file);
  5192.              use_js_math = TRUE;
  5193.             }
  5194.             if( use_js_plot == FALSE){
  5195.              use_js_plot = TRUE;
  5196.              add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
  5197.             }
  5198.             break;
  5199.  
  5200.  
  5201.  
  5202.         case USERTEXTAREA_XY:
  5203.         /*
  5204.         @ usertextarea_xy
  5205.         @ NOT IMPLEMENTED !!
  5206.         @ keyword (no arguments required)
  5207.         @ to be used in combination with command <code>userdraw object_type,color</code> wherein object_type is only segment / polyline for the time being...
  5208.         @ if set two textareas are added to the document (one for x-values, one for y-values)
  5209.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  5210.         @ user drawings will not zoom on zooming (or pan on panning)
  5211.         @ use command ''inputstyle some_css`` to adjust the inputarea.
  5212.         @ use command ''fontsize int`` to adjust the text labels (if needed)
  5213.         */
  5214.             if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
  5215.             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
  5216.             use_input_xy = 2;
  5217.             break;
  5218.  
  5219.         case VLINE:
  5220.         /*
  5221.         @ vline x,y,color
  5222.         @ alternative: <code>verticalline</code>
  5223.         @ draw a vertical line through point (x:y) in color ''color``
  5224.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  5225.         @%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
  5226.         */
  5227.             for(i=0;i<3;i++) {
  5228.                 switch(i){
  5229.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  5230.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  5231.                     case 2: stroke_color=get_color(infile,1);/* name or hex color */
  5232.                         double_data[2] = double_data[0];
  5233.                         decimals = find_number_of_digits(precision);
  5234.                         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);
  5235.                         if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  5236.                         /* click_cnt++; */
  5237.                         reset();
  5238.                     break;
  5239.                 }
  5240.             }
  5241.             break;
  5242.  
  5243.         case VLINES:
  5244.         /*
  5245.         @ vlines color,x1,y1,x2,y2....
  5246.         @ alternative: <code>verticallines</code>
  5247.         @ draw vertical lines through points (x1:y1),(x2:y2)... in color ''color``
  5248.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  5249.         @%vlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%vlines red,1,0,2,0,3,0,4,0
  5250.         */
  5251.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5252.             fill_color = stroke_color;
  5253.             i=0;
  5254.             while( ! done ){     /* get next item until EOL*/
  5255.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5256.                 if(i%2 == 0 ){
  5257.                     double_data[i] = get_real(infile,0); /* x */
  5258.                 }
  5259.                 else
  5260.                 {
  5261.                     double_data[i] = get_real(infile,1); /* y */
  5262.                 }
  5263.                 i++;
  5264.             }
  5265.             decimals = find_number_of_digits(precision);
  5266.             for(c = 0 ; c < i-1 ; c = c+2){
  5267.                 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);
  5268.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  5269.                 /* click_cnt++; */
  5270.             }
  5271.             reset();
  5272.             break;
  5273.  
  5274.         case VIDEO:
  5275.         /*
  5276.         @ video x,y,w,h,videofile location
  5277.         @ x,y: left top corner of audio element (in xrange / yrange)
  5278.         @ w,y: width and height in pixels
  5279.         @ video format may be in *.mp4 (todo: other formats)
  5280.         @%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
  5281.         */
  5282.             if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
  5283.             for(i=0;i<5;i++){
  5284.                 switch(i){
  5285.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  5286.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */
  5287.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  5288.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  5289.                     case 4: temp = get_string(infile,1);
  5290.                             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);
  5291.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5292.                             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);
  5293.                             add_to_buffer(tmp_buffer);
  5294.                             break;
  5295.                     default:break;
  5296.                 }
  5297.             }
  5298.             reset();
  5299.             break;
  5300.  
  5301.         case X_AXIS_STRINGS:
  5302.         /*
  5303.          @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5304.          @ alternative: <code>xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code>
  5305.          @ usable for commands <a href="#numberline">numberline</a> and <a href="#grid">grid</a> or combinations thereof
  5306.          @ use these x-axis num1...num_n values instead of default xmin...xmax
  5307.          @ in case of command ''grid``. there is no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5308.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
  5309.          @ use command ''fontcolor``, ''fontfamily`` to adjust font <br />defaults: black,12,Arial<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>)
  5310.          @ a javascript error message will flag non-matching value:name pairs
  5311.          @ if the ''x-axis words`` are too big and will overlap, a simple alternating offset will be applied
  5312.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  5313.          @ ''xmajor`` steps should be synchronised with numbers eg. ''1`` in the next example <code>grid 1,100,grey,1,4,6,grey</code>
  5314.          @%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
  5315.         */
  5316.             use_axis_numbering++;
  5317.             temp = get_string(infile,1);
  5318.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5319.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5320.             fprintf(js_include_file,"x_strings[%d] = [\"%s\"];x_strings_up[%d] = null;",use_axis_numbering,temp,use_axis_numbering);
  5321.             break;
  5322.         case X_AXIS_STRINGS_UP:
  5323.         /*
  5324.          @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5325.          @ alternative: <code>xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code>
  5326.          @ the text will be rotated 90&deg; up
  5327.          @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5328.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
  5329.          @ use these x-axis num1...num_n values instead of default xmin...xmax
  5330.          @ use command ''fontcolor``, <a href="#fontfamily">fontfamily</a> to adjust font <br />defaults: black,12,Arial<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>)
  5331.          @ a javascript error message will flag non-matching value:name pairs
  5332.          @ if the ''x-axis words`` are too big, they will overlap the graph<br /> (in this case the text will start from ysize upwards)
  5333.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  5334.          @''xmajor`` steps should be synchronised with numbers eg. "1" in the next example <code>grid 1,100,grey,1,4,6,grey</code>
  5335.          @%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
  5336.         */
  5337.             use_axis_numbering++;
  5338.             temp = get_string(infile,1);
  5339.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5340.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5341.             fprintf(js_include_file,"x_strings_up[%d] = 1;x_strings[%d] = [\"%s\"];",use_axis_numbering,use_axis_numbering,temp);
  5342.             break;
  5343.  
  5344.         case XERRORBARS:
  5345.         /*
  5346.         @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
  5347.         @ 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``.
  5348.         @ the errors E1 and E2 values are in xrange.
  5349.         @ use command ''linewidth int`` to adust size
  5350.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  5351.         @%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
  5352.  
  5353.         */
  5354.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5355.             fill_color = stroke_color;
  5356.             i=0;
  5357.             while( ! done ){     /* get next item until EOL*/
  5358.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5359.                 if(i%2 == 0 ){
  5360.                     double_data[i] = get_real(infile,0); /* x */
  5361.                 }
  5362.                 else
  5363.                 {
  5364.                     double_data[i] = get_real(infile,1); /* y */
  5365.                 }
  5366.                 i++;
  5367.             }
  5368.             decimals = find_number_of_digits(precision);
  5369.             for(c = 2 ; c < i-1 ; c = c+2){
  5370.                 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);
  5371.                 /* click_cnt++; */
  5372.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  5373.             }
  5374.             reset();
  5375.             break;
  5376.  
  5377.         case XRANGE:
  5378.         /*
  5379.         @ xrange xmin,xmax
  5380.         @ alternative: <code>rangex</code>
  5381.         @ if not given: 0,xsize (eg in pixels)
  5382.         */
  5383.             for(i = 0 ; i<2; i++){
  5384.                 switch(i){
  5385.                     case 0: xmin = get_real(infile,0);break;
  5386.                     case 1: xmax = get_real(infile,1);break;
  5387.                     default: break;
  5388.                 }
  5389.             }
  5390.             if(xmin >= xmax){canvas_error(" xrange is not OK: xmin &lt; xmax !\n");}
  5391.             fprintf(js_include_file,"var xmin = %f;var xmax = %f;\n",xmin,xmax);
  5392.             found_size_command++;
  5393.             break;
  5394.  
  5395.  
  5396.  
  5397.         case XSNAPTOGRID:
  5398.         /*
  5399.          @ xsnaptogrid
  5400.          @ keyword (no arguments required)
  5401.          @ a draggable object (use command ''drag x|y|xy``) will snap to the given x-grid values when dragged (mouseup).
  5402.          @ in case of userdraw the drawn points will snap to xmajor grid.
  5403.          @ if no grid is defined, points will snap to every integer xrange value. (eg snap_x=1)
  5404.          @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
  5405.          @ 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 ...
  5406.          @%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
  5407.          @%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
  5408.  
  5409.         */
  5410.         use_snap = 2;
  5411.         break;
  5412.  
  5413.         case XOFFSET:
  5414.         /*
  5415.          @ xoffset
  5416.          @ keyword ; to place the text centered above the text coordinates(x:y) ...
  5417.          @ may be used for points or other things requiring centered labels
  5418.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5419.          @ 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)
  5420.         @%xoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Arial%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
  5421.         */
  5422.          use_offset = 2;
  5423.          break;
  5424.  
  5425.         case XYOFFSET:
  5426.         /*
  5427.          @ xyoffset
  5428.          @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily
  5429.          @ may be used for points or other things requiring labels
  5430.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5431.          @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy
  5432.          @ 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>
  5433.          @%xyoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Arial%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
  5434.         */
  5435.          use_offset = 3;
  5436.          break;
  5437.  
  5438.         case XUNIT:
  5439.         /*
  5440.          @ xunit some_unit_for_x-values
  5441.          @ unicode allowed (no html code)
  5442.          @ use together with command <a href='#display'>display or mouse</a>
  5443.          @ will display the cursor x-coordinate in ''unit``
  5444.          @%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
  5445.         */
  5446.             fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
  5447.             break;
  5448.  
  5449.         case XLABEL:
  5450.         /*
  5451.         @ xlabel some_string
  5452.         @ will be used to create a label for the x-axis (label is in quadrant I).
  5453.         @ can only be used together with command ''grid``<br />not depending on keywords ''axis`` and ''axisnumbering``.
  5454.         @ 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).
  5455.         @ see <a href='z#ylabel'>ylabel</a>.
  5456.         @%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
  5457.         */
  5458.             temp = get_string(infile,1);
  5459.             fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
  5460.             break;
  5461.  
  5462.         case XLOGBASE:
  5463.         /*
  5464.         @ xlogbase number
  5465.         @ sets the logbase number for the x-axis
  5466.         @ default value 10
  5467.         @ use together with commands xlogscale / xylogscale
  5468.         */
  5469.             fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
  5470.             break;
  5471.  
  5472.         case XLOGSCALE:
  5473.         /*
  5474.          @ xlogscale ymajor,yminor,majorcolor,minorcolor
  5475.          @ the x/y-range are set using commands <code>xrange xmin,xmax</code> and <code>yrange ymin,ymax</code>
  5476.          @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
  5477.          @ the linewidth is set using command ''linewidth int``
  5478.          @ the opacity of major / minor grid lines is set by command <a href='#opacity'>opacity</a>
  5479.          @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number``
  5480.          @ 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>
  5481.          @ note: the complete canvas will be used for the ''log paper``
  5482.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5483.          @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\
  5484.          @ 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
  5485.          @ note: in case of userdraw, the use of keyword <a href='#userinput_xy'>userinput_xy</a> may be handy !
  5486.          @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
  5487.          @%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
  5488.         */
  5489.             use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5490.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5491.             if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
  5492.             for(i=0;i<4;i++){
  5493.                 switch(i){
  5494.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  5495.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  5496.                     case 2: stroke_color = get_color(infile,0); break;
  5497.                     case 3: 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,%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);
  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,%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);
  5501.                         fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
  5502.                         add_to_buffer(tmp_buffer);
  5503.                         break;
  5504.                     default:break;
  5505.                 }
  5506.             }
  5507.             break;
  5508.  
  5509.         case XYLOGSCALE:
  5510.         /*
  5511.          @ xylogscale majorcolor,minorcolor
  5512.          @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax``
  5513.          @ the linewidth is set using command ''linewidth int``
  5514.          @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]``
  5515.          @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number`` and/or ''ylogbase number``
  5516.          @ 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>
  5517.          @ note: the complete canvas will be used for the ''log paper``
  5518.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5519.          @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\
  5520.          @ 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``)
  5521.          @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy !
  5522.          @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
  5523.          @%xylogscale%size 400,400%xrange 10,50000%yrange 10,50000%xlabel x-axis%ylabel y-axis%xylogscale black,grey%display xy,red,22
  5524.         */
  5525.             use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5526.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5527.             if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
  5528.             for(i=0;i<2;i++){
  5529.                 switch(i){
  5530.                     case 0: stroke_color = get_color(infile,0); break;
  5531.                     case 1: fill_color = get_color(infile,1);
  5532.                         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);
  5533.                         tmp_buffer = my_newmem(string_length);
  5534.                         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);
  5535.                         fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
  5536.                         add_to_buffer(tmp_buffer);
  5537.                         break;
  5538.                     default:break;
  5539.                 }
  5540.             }
  5541.         break;
  5542.  
  5543.  
  5544.         case Y_AXIS_STRINGS:
  5545.         /*
  5546.          @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5547.          @ alternative: <code>yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code>
  5548.          @ use command ''fontcolor``, ''fontfamily`` to adjust font <br />defaults: black,12,Arial<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>)
  5549.          @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5550.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
  5551.          @ use these y-axis num1...num_n values instead of default ymin...ymax
  5552.          @ a javascript error message will flag non-matching value:name pairs
  5553.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  5554.          @%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
  5555.         */
  5556.             temp = get_string(infile,1);
  5557.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5558.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5559.             fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
  5560.             use_axis_numbering++;
  5561.             break;
  5562.  
  5563.  
  5564.         case YERRORBARS:
  5565.         /*
  5566.         @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
  5567.         @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color ''color``.
  5568.         @ the errors E1 and E2 values are in yrange.
  5569.         @ use command ''linewidth int`` to adust size
  5570.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  5571.         @%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
  5572.         */
  5573.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5574.             fill_color = stroke_color;
  5575.             i=0;
  5576.             while( ! done ){     /* get next item until EOL*/
  5577.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5578.                 if(i%2 == 0 ){
  5579.                     double_data[i] = get_real(infile,0); /* x */
  5580.                 }
  5581.                 else
  5582.                 {
  5583.                     double_data[i] = get_real(infile,1); /* y */
  5584.                 }
  5585.                 i++;
  5586.             }
  5587.             for(c = 2 ; c < i-1 ; c = c+2){
  5588.                 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);
  5589.                 /* click_cnt++; */
  5590.                 if(onclick > 0 || slider_cnt > 0){click_cnt++;}
  5591.             }
  5592.             decimals = find_number_of_digits(precision);
  5593.             reset();
  5594.             break;
  5595.         case YOFFSET:
  5596.         /*
  5597.          @ yoffset
  5598.          @ keyword; to place the text centered above the text coordinates(x:y) ...
  5599.          @ may be used for points or other things requiring centered labels
  5600.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5601.          @ 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)
  5602.          @%yoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Arial%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
  5603.         */
  5604.          use_offset = 1;
  5605.          break;
  5606.  
  5607.         case YRANGE:
  5608.         /*
  5609.         @ yrange ymin,ymax
  5610.         @ alternative: <code>rangey</code>
  5611.         @ if not given 0,ysize (eg in pixels)
  5612.         */
  5613.             for(i = 0 ; i<2; i++){
  5614.                 switch(i){
  5615.                     case 0: ymin = get_real(infile,0);break;
  5616.                     case 1: ymax = get_real(infile,1);break;
  5617.                     default: break;
  5618.                 }
  5619.             }
  5620.             if(ymin >= ymax){canvas_error(" yrange is not OK: ymin &lt; ymax !\n");}
  5621.             fprintf(js_include_file,"var ymin = %f;var ymax = %f;\n",ymin,ymax);
  5622.             found_size_command++;
  5623.             break;
  5624.  
  5625.         case YSNAPTOGRID:
  5626.         /*
  5627.          @ ysnaptogrid
  5628.          @ keyword (no arguments required)
  5629.          @ a draggable object (use command ''drag x|y|xy``) will snap to the given y-grid values when dragged (mouseup)
  5630.          @ in case of userdraw the drawn points will snap to ymajor grid
  5631.          @ if no grid is defined, points will snap to every integer yrange value. (eg snap_y=1)
  5632.          @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
  5633.          @ 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 />
  5634.          @%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
  5635.          @%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
  5636.         */
  5637.         use_snap = 3;
  5638.         break;
  5639.  
  5640.         case YLABEL:
  5641.         /*
  5642.         @ ylabel some_string
  5643.         @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
  5644.         @ can only be used together with command <a href="#grid">grid</a><br />not depending on keywords ''axis`` and ''axisnumbering``
  5645.         @ 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)
  5646.         @%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
  5647.         */
  5648.             temp = get_string(infile,1);
  5649.             fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
  5650.             break;
  5651.         case YLOGBASE:
  5652.         /*
  5653.         @ ylogbase number
  5654.         @ sets the logbase number for the y-axis
  5655.         @ default value 10
  5656.         @ use together with commands ylogscale / xylogscale
  5657.         */
  5658.             fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
  5659.             break;
  5660.         case YLOGSCALE:
  5661.         /*
  5662.          @ ylogscale xmajor,xminor,majorcolor,minorcolor
  5663.          @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax``
  5664.          @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
  5665.          @ the linewidth is set using command ''linewidth int``
  5666.          @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]``
  5667.          @ default logbase number = 10 ... when needed, set the logbase number with command ''ylogbase number``
  5668.          @ 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>
  5669.          @ note: the complete canvas will be used for the ''log paper``
  5670.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5671.          @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\
  5672.          @ 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``)
  5673.          @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy !
  5674.          @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
  5675.         */
  5676.             use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5677.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5678.             if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
  5679.             for(i=0;i<4;i++){
  5680.                 switch(i){
  5681.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  5682.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  5683.                     case 2: stroke_color = get_color(infile,0); break;
  5684.                     case 3: fill_color = get_color(infile,1);
  5685.                         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);
  5686.                         tmp_buffer = my_newmem(string_length);
  5687.                         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);
  5688.                         fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
  5689.                         add_to_buffer(tmp_buffer);
  5690.                         break;
  5691.                     default:break;
  5692.                 }
  5693.             }
  5694.             break;
  5695.  
  5696.         case YUNIT:
  5697.         /*
  5698.          @ yunit some_unit_for_y-values
  5699.          @ unicode allowed (no html code)
  5700.          @ use together with command mousey
  5701.          @ will display the cursor y-coordinate in ''unit``
  5702.         */
  5703.             fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
  5704.             break;
  5705.  
  5706.         case ZOOM:
  5707.         /*
  5708.          @ zoom button_color
  5709.          @ introduce a very small ''controlpanel`` at the lower right corner
  5710.          @ 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
  5711.          @ the ''x`` symbol will do a <code>location.reload</code> of the page, and thus reset all canvas drawings.
  5712.          @ choose an appropriate color, so the small ''x,arrows,-,+`` are clearly visible
  5713.          @ command ''opacity`` may be used to set stroke_opacity of buttons
  5714.          @ note: use command ''zoom`` at the end of your script code (the same is true for command ''mouse``)
  5715.          @ note: only objects that may be set draggable / clickable will be zoomed / panned
  5716.          @ 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 !!
  5717.         */
  5718.             fprintf(js_include_file,"use_pan_and_zoom = 1;");
  5719.             use_pan_and_zoom = TRUE;
  5720.             stroke_color = get_color(infile,1);
  5721.             /* we use BG_CANVAS (0) */
  5722.             add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
  5723.             done = TRUE;
  5724.             break;
  5725.  
  5726. /* ready */
  5727.         default:sync_input(infile);
  5728.         break;
  5729.     }
  5730.   }
  5731.   /* we are done parsing script file */
  5732.   /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize: Quadrant I */
  5733.   if( found_size_command == 1 ){
  5734.     fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
  5735.   }
  5736.   else
  5737.   {
  5738.     if( found_size_command != 3 ){
  5739.      canvas_error("Please specify both xrange and yrange ...");
  5740.     }
  5741.   }
  5742.  
  5743.   /* if needed, add generic draw functions (grid / xml etc) to buffer: these are no draggable/clickable shapes / objects  ! */
  5744.   add_javascript_function(js_function,canvas_root_id);
  5745.    /* add read_canvas() etc functions if needed */
  5746.   if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);}
  5747.   if( use_pan_and_zoom == TRUE ){
  5748.   /* in case of zooming ... */
  5749.   fprintf(js_include_file,"\n/* some extra global stuff : need to rethink panning and zooming !!! */\n\
  5750.  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
  5751.  var ymin_start=ymin;var ymax_start=xmax;\
  5752.  var zoom_x_increment=0;var zoom_y_increment=0;\
  5753.  var pan_x_increment=0;var pan_y_increment=0;\
  5754.  if(use_ylogscale == 0 ){\
  5755.   zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (ymax - ymin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\
  5756.  }else{\
  5757.   zoom_x_increment = (xmax - xmin)/20;\
  5758.   pan_x_increment = (xmax - xmin)/20;\
  5759.  };\
  5760.  var zoom_xy=[xmin,xmax,ymin,ymax];\
  5761.  function start_canvas%d(type){\
  5762.   zoom_xy=[xmin,xmax,ymin,ymax];\
  5763.   switch(type){\
  5764.    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
  5765.    case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\
  5766.    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
  5767.    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
  5768.    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
  5769.    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
  5770.    case 6:xmin = xmin_start; xmax = xmax_start;ymin = ymin_start;ymax = ymax_start;break;\
  5771.    default:break;\
  5772.   };\
  5773.   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
  5774.   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
  5775.   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){};\
  5776.   if(typeof(redraw_all%d) === 'function' ){redraw_all%d(zoom_xy);}\
  5777.   %s ;\
  5778.  };\
  5779.  start_canvas%d(333);\
  5780. };\
  5781. \n/* end wims_canvas_function */\n\
  5782. wims_canvas_function%d();\n",precision,canvas_root_id,canvas_root_id,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
  5783.   }
  5784.   else
  5785.   {
  5786.   /* no zoom, just add buffer */
  5787.   fprintf(js_include_file,"\n/* add buffer */\n\
  5788.  %s\
  5789. };\n\
  5790. /* end wims_canvas_function */\n\
  5791. wims_canvas_function%d();\n",buffer,canvas_root_id);
  5792.   }
  5793. /* done writing the javascript include file */
  5794. fclose(js_include_file);
  5795.  
  5796. }
  5797.  
  5798. /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
  5799.  if( use_tooltip > 0 ){
  5800.   if( use_tooltip == 1 ){
  5801.    add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
  5802.   }
  5803.   else
  5804.   {
  5805.    if( use_tooltip == 2 ){
  5806.     add_js_popup(canvas_root_id,xsize,ysize,getfile_cmd);
  5807.    }
  5808.   }
  5809.  }
  5810. exit(EXIT_SUCCESS);
  5811. }
  5812. /* end main() */
  5813.  
  5814. /******************************************************************************
  5815. **
  5816. **  sync_input
  5817. **
  5818. **  synchronises input line - reads to end of line, leaving file pointer
  5819. **  at first character of next line.
  5820. **
  5821. **  Used by:
  5822. **  main program - error handling.
  5823. **
  5824. ******************************************************************************/
  5825. void sync_input(FILE *infile)
  5826. {
  5827.         int c = 0;
  5828.  
  5829.         if( c == '\n' || c == ';' ) return;
  5830.         while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
  5831.         if( c == EOF ) finished = 1;
  5832.         if( c == '\n' || c == '\r' || c == ';') line_number++;
  5833.         return;
  5834. }
  5835.  
  5836. /******************************************************************************/
  5837.  
  5838. char *str_replace(const char *str, const char *old, const char *new){
  5839. /* http://creativeandcritical.net/str-replace-c/ */
  5840.     if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
  5841.     char *ret, *r;
  5842.     const char *p, *q;
  5843.     size_t oldlen = strlen(old);
  5844.     size_t count = 0;
  5845.     size_t retlen = 0;
  5846.     size_t newlen = strlen(new);
  5847.     if (oldlen != newlen){
  5848.         for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
  5849.             count++;
  5850.             retlen = p - str + strlen(p) + count * (newlen - oldlen);
  5851.         }
  5852.     }
  5853.     else
  5854.     {
  5855.         retlen = strlen(str);
  5856.     }
  5857.  
  5858.     if ((ret = malloc(retlen + 1)) == NULL){
  5859.         ret = NULL;
  5860.         canvas_error("string argument is NULL");
  5861.     }
  5862.     else
  5863.     {
  5864.         for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
  5865.             size_t l = q - p;
  5866.             memcpy(r, p, l);
  5867.             r += l;
  5868.             memcpy(r, new, newlen);
  5869.             r += newlen;
  5870.         }
  5871.         strcpy(r, p);
  5872.     }
  5873.     return ret;
  5874. }
  5875.  
  5876. /******************************************************************************/
  5877.  
  5878. char *get_color(FILE *infile , int last){
  5879.     int c,i = 0,is_hex = 0;
  5880.     char temp[MAX_COLOR_STRING], *string;
  5881.     const char *not_allowed = "0123456789";
  5882.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' )  && ( c != '\t' ) ){
  5883.         if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
  5884.         if( c == '#' ){
  5885.             is_hex = 1;
  5886.         }
  5887.         if( c != ' '){
  5888.             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 !!! ");}}
  5889.             temp[i]=tolower(c);
  5890.             i++;
  5891.         }
  5892.     }
  5893.     if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
  5894.     if( c == '\n' || c == ';'  || c == '\t' ){ done = TRUE; line_number++; }
  5895.     if( c == EOF ){finished = 1;}
  5896.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  5897.     temp[i]='\0';
  5898.     if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
  5899.     if( is_hex == 1 ){
  5900.         char red[3], green[3], blue[3];
  5901.         red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
  5902.         green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
  5903.         blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
  5904.         int r = (int) strtol(red,   NULL, 16);
  5905.         int g = (int) strtol(green, NULL, 16);
  5906.         int b = (int) strtol(blue,  NULL, 16);
  5907.         int L0 = 1+snprintf(NULL,0,"%d,%d,%d",r,g,b);
  5908.         string = my_newmem(L0);
  5909.         snprintf(string,L0,"%d,%d,%d",r,g,b);
  5910.         return string;
  5911.     }
  5912.     else
  5913.     {
  5914.         string = (char *)my_newmem(sizeof(temp));
  5915.         snprintf(string,sizeof(temp),"%s",temp);
  5916.         for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  5917.             if( strcmp( colors[i].name , string ) == 0 ){
  5918.                 return colors[i].rgb;
  5919.             }
  5920.         }
  5921.         canvas_error("I was expecting a color name or hexnumber...but found nothing.");
  5922.     }
  5923.     return "0,0,255";
  5924. }
  5925.  
  5926. char *get_string(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */
  5927.     int c,i=0;
  5928.     char  temp[MAX_BUFFER], *string;
  5929.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){
  5930.         temp[i]=c;
  5931.         i++;
  5932.         if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
  5933.     }
  5934.     if( ( c == '\n' ||  c == '\t'  || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  5935.     if( c == '\n' ||  c == '\t') { done = TRUE; line_number++; }
  5936.     if( c == EOF ) {finished = 1;}
  5937.     temp[i]='\0';
  5938.     if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing !!");}
  5939.     string=(char *)my_newmem(strlen(temp));
  5940.     snprintf(string,sizeof(temp),"%s",temp);
  5941.     return string;
  5942. }
  5943.  
  5944. char *get_string_argument(FILE *infile,int last){  /* last = 0: more arguments ; last=1 final argument */
  5945.     int c,i=0;
  5946.     char temp[MAX_BUFFER], *string;
  5947.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){
  5948.         temp[i]=c;
  5949.         i++;
  5950.         if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
  5951.     }
  5952.     if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
  5953.     if( c == '\n' || c == '\t' ) { line_number++; }
  5954.     if( c == EOF ) {finished = 1;}
  5955.     if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");}
  5956.     temp[i]='\0';
  5957. /*
  5958.     17.10.2014 removed (question Perrin)
  5959.     may cause some unwanted effects...
  5960.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma), but found nothing !!");}
  5961. */
  5962.     string=(char *)my_newmem(sizeof(temp));
  5963.     snprintf(string,sizeof(temp),"%s",temp);
  5964.     done = TRUE;
  5965.     return string;
  5966. }
  5967.  
  5968. double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0: more arguments ; last=1 final argument */
  5969.     int c,i=0,found_calc = 0;
  5970.     double y;
  5971.     char tmp[MAX_INT];
  5972.     /*
  5973.      these things are 'allowed functions': *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs
  5974.      but there should be a better way to avoid segfaults !
  5975.     */
  5976.     const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/
  5977.     const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */
  5978.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){
  5979.      if( c != ' ' ){
  5980.       if( i == 0 &&  c == '+' ){
  5981.        continue;
  5982.       }
  5983.       else
  5984.       {
  5985.        c = tolower(c);
  5986.        if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");}
  5987.        if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */
  5988.        tmp[i] = c;
  5989.        i++;
  5990.       }
  5991.      }
  5992.      if( i > MAX_INT - 1){canvas_error("number too large");}
  5993.     }
  5994.     if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
  5995.     if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; }
  5996.     if( c == EOF ){done = TRUE ; finished = 1;}
  5997.     tmp[i]='\0';
  5998.     if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
  5999.     if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */
  6000.      void *f = eval_create(tmp);
  6001.      assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  6002.      y = eval_x(f, 1);
  6003.      /* if function is bogus; y = 1: so no core dumps */
  6004.      eval_destroy(f);
  6005.     }
  6006.     else
  6007.     {
  6008.      y = atof(tmp);
  6009.     }
  6010.     return y;
  6011. }
  6012.  
  6013.  
  6014. void canvas_error(char *msg){
  6015.     fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d: %s</span><hr />",line_number,msg);
  6016.     finished = 1;
  6017.     exit(EXIT_SUCCESS);
  6018. }
  6019.  
  6020.  
  6021. /* convert x/y coordinates to pixel */
  6022. int x2px(double x){
  6023.  return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
  6024. }
  6025.  
  6026. int y2px(double y){
  6027.  return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
  6028. }
  6029.  
  6030. double px2x(int x){
  6031.  return (x*(xmax - xmin)/xsize + xmin);
  6032. }
  6033. double px2y(int y){
  6034.  return (y*(ymax - ymin)/ysize + ymin);
  6035. }
  6036.  
  6037. void add_to_buffer(char *tmp){
  6038.  if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
  6039.  /*  do we have enough space left in buffer[MAX_BUFFER] ? */
  6040.  int space_left = (int) (sizeof(buffer) - strlen(buffer));
  6041.  if( space_left > strlen(tmp)){
  6042.   strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
  6043.  }
  6044.  else
  6045.  {
  6046.   canvas_error("buffer is too big\n");
  6047.  }
  6048.  tmp = NULL;free(tmp);
  6049.  return;
  6050. }
  6051.  
  6052. void reset(){
  6053.  use_filled = FALSE;
  6054.  use_dashed = FALSE;
  6055.  use_rotate = FALSE;
  6056.  onclick = 0;
  6057. }
  6058.  
  6059.  
  6060.  
  6061. /* What reply format in read_canvas();
  6062.  
  6063. note: if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
  6064. 1 = x1,x2,x3,x4....x_n
  6065.     y1,y2,y3,y4....y_n
  6066.  
  6067.     x/y in pixels
  6068.  
  6069. 2 = x1,x2,x3,x4....x_n
  6070.     y1,y2,y3,y4....y_n
  6071.     x/y in xrange / yrange coordinate system
  6072.  
  6073. 3 = x1,x2,x3,x4....x_n
  6074.     y1,y2,y3,y4....y_n
  6075.     r1,r2,r3,r4....r_n
  6076.  
  6077.     x/y in pixels
  6078.     r in pixels
  6079.  
  6080. 4 = x1,x2,x3,x4....x_n
  6081.     y1,y2,y3,y4....y_n
  6082.     r1,r2,r3,r4....r_n
  6083.  
  6084.     x/y in xrange / yrange coordinate system
  6085.     r in pixels
  6086.  
  6087. 5 = Ax1,Ax2,Ax3,Ax4....Ax_n
  6088.     Ay1,Ay2,Ay3,Ay4....Ay_n
  6089.     Bx1,Bx2,Bx3,Bx4....Bx_n
  6090.     By1,By2,By3,By4....By_n
  6091.     Cx1,Cx2,Cx3,Cx4....Cx_n
  6092.     Cy1,Cy2,Cy3,Cy4....Cy_n
  6093.     ....
  6094.     Zx1,Zx2,Zx3,Zx4....Zx_n
  6095.     Zy1,Zy2,Zy3,Zy4....Zy_n
  6096.  
  6097.     x/y in pixels
  6098.  
  6099. 6 = Ax1,Ax2,Ax3,Ax4....Ax_n
  6100.     Ay1,Ay2,Ay3,Ay4....Ay_n
  6101.     Bx1,Bx2,Bx3,Bx4....Bx_n
  6102.     By1,By2,By3,By4....By_n
  6103.     Cx1,Cx2,Cx3,Cx4....Cx_n
  6104.     Cy1,Cy2,Cy3,Cy4....Cy_n
  6105.     ....
  6106.     Zx1,Zx2,Zx3,Zx4....Zx_n
  6107.     Zy1,Zy2,Zy3,Zy4....Zy_n
  6108.  
  6109.     x/y in xrange / yrange coordinate system
  6110.  
  6111. 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  6112.  
  6113.     x/y in pixels
  6114.  
  6115. 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  6116.  
  6117.     x/y in xrange / yrange coordinate system
  6118.  
  6119. 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
  6120.  
  6121.     x/y in pixels
  6122.  
  6123. 10 = x1 ; y1 ;r1 \n x2;y2;r2 \n x3;y3;r3 \n ...x_n:y_n:r_n \n
  6124.  
  6125.     x/y in xrange / yrange coordinate system
  6126.     r is userdraw_radius
  6127.  
  6128. 11 = Ax1,Ay1,Ax2,Ay2
  6129.      Bx1,By1,Bx2,By2
  6130.      Cx1,Cy1,Cx2,Cy2
  6131.      Dx1,Dy1,Dx2,Dy2
  6132.      ......
  6133.      Zx1,Zy1,Zx2,Zy2
  6134.  
  6135.     x/y in  xrange / yrange coordinate system
  6136.  
  6137. 12 = Ax1,Ay1,Ax2,Ay2
  6138.      Bx1,By1,Bx2,By2
  6139.      Cx1,Cy1,Cx2,Cy2
  6140.      Dx1,Dy1,Dx2,Dy2
  6141.      ......
  6142.      Zx1,Zy1,Zx2,Zy2
  6143.  
  6144.     x/y in pixels
  6145.  
  6146. 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ..., Zx1:Zy1:Zx2:Zy2
  6147.  
  6148.     x/y in xrange / yrange coordinate system
  6149. 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
  6150.     x/y in pixels
  6151. 15 = reply from inputfields,textareas
  6152.     reply1,reply2,reply3,...,reply_n
  6153.     only fields set write (e.g. will not read readonly inputfield values.
  6154.  
  6155. 16 = read mathml inputfields only
  6156.  
  6157. 17 = read userdraw text only (x1,y1,text1\nx2,y2,text2..\n.x_n,y_n,text_n
  6158.  when ready: calculate size_t of string via snprintf(NULL,0,"blah blah...");
  6159.  
  6160. 18 = read clock(s): H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
  6161. 19 = return clicked object number (analogue to shape-library onclick)
  6162. 20 = return x/y-data in x-range/y-range of all ''draggable`` images
  6163. 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
  6164. 22 = array: x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
  6165.     x/y in xrange / yrange coordinate system
  6166. 23 = answertype for a polyline: remove multiple occurences due to reclick on a point to create next polyline segment
  6167. 24 = read all inputfield values: even those set <code>readonly</code>
  6168. 25 = return all userdrawn arcs in degrees:
  6169. 26 = return all userdrawn arcs in radians:
  6170. 27 = return (only) userdraw inputfields array: x1,y1,text1 \n x2,y2,text2...
  6171. 28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
  6172.     x/y/r in xrange / yrange coordinate system: may be used to reinput into command
  6173.     circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
  6174.     will not return anything else (e.g. no inputfields, text etc)
  6175. 29 = mulidraw read:
  6176.  
  6177. */
  6178.  
  6179. /*
  6180. SCHAERSVOORDE: replyformat 2,7,8,21,22,23,24
  6181. USERDRAW DEFAULTS: 2,6,8,10,11,15,16,17,18,19,20,23,24,25,27,29,31
  6182. OEF: 22,23,28
  6183. */
  6184. void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){
  6185. /* just 1 reply type allowed...except for format 34 !!!  */
  6186. fprintf(js_include_file,"\
  6187. \n/* begin set_reply_precision() */\n\
  6188. function set_reply_precision(){\
  6189. var len = userdraw_x.length;\
  6190. var prec = %d;\
  6191. for(var p = 0 ; p < len ; p++ ){\
  6192.  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
  6193.  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
  6194. };\
  6195. len = userdraw_radius.length;\
  6196. if( len > 0 ){\
  6197.  for(var p = 0 ; p < len ; p++ ){\
  6198.   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
  6199.  };\
  6200. };\
  6201. };",reply_precision);
  6202.  
  6203. switch(type_reply){
  6204. /*
  6205. answers may have:
  6206. x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
  6207. */
  6208.     case 1: fprintf(js_include_file,"\
  6209. \n/* begin function 1 read_canvas%d() */\n\
  6210. read_canvas%d = function(){\
  6211. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  6212. set_reply_precision();\
  6213. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6214.  var p = 0;var input_reply = new Array();\
  6215.  if( document.getElementById(\"canvas_input0\")){\
  6216.   var t = 0;\
  6217.   while(document.getElementById(\"canvas_input\"+t)){\
  6218.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6219.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6220.     p++;\
  6221.    };\
  6222.    t++;\
  6223.   };\
  6224.  };\
  6225.  if( typeof(userdraw_text) !== 'undefined' ){\
  6226.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
  6227.  }\
  6228.  else\
  6229.  {\
  6230.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
  6231.  }\
  6232. }\
  6233. else\
  6234. {\
  6235.  if( typeof(userdraw_text) !== 'undefined' ){\
  6236.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
  6237.  }\
  6238.  else\
  6239.  {\
  6240.   return userdraw_x+\"\\n\"+userdraw_y;\
  6241.  }\
  6242. };\
  6243. };\n\
  6244. /* end function 1 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6245.     break;
  6246.     case 2: fprintf(js_include_file,"\
  6247. \n/* begin function 2 read_canvas%d() */\n\
  6248. read_canvas%d = function(){\
  6249. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  6250. set_reply_precision();\
  6251. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  6252. var prec = %d;\
  6253. while(userdraw_x[p]){\
  6254.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  6255.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  6256.  p++;\
  6257. };\
  6258. if(p == 0){return;};\
  6259. if( document.getElementById(\"canvas_input0\")){\
  6260.  var p = 0;var input_reply = new Array();\
  6261.  if( document.getElementById(\"canvas_input0\")){\
  6262.   var t = 0;\
  6263.   while(document.getElementById(\"canvas_input\"+t)){\
  6264.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6265.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6266.     p++;\
  6267.    };\
  6268.    t++;\
  6269.   };\
  6270.  };\
  6271.  if( typeof(userdraw_text) !== 'undefined' ){\
  6272.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6273.  }\
  6274.  else\
  6275.  {\
  6276.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  6277.  }\
  6278. }\
  6279. else\
  6280. {\
  6281.  if( typeof(userdraw_text) !== 'undefined' ){\
  6282.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  6283.  }\
  6284.  else\
  6285.  {\
  6286.   return reply_x+\"\\n\"+reply_y;\
  6287.  };\
  6288. };\
  6289. };\n\
  6290. /* end function 2 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6291.     break;
  6292.     case 3: fprintf(js_include_file,"\
  6293. \n/* begin function 3 read_canvas%d() */\n\
  6294. read_canvas%d = function(){\
  6295. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  6296. set_reply_precision();\
  6297. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6298.  var p = 0;var input_reply = new Array();\
  6299.  if( document.getElementById(\"canvas_input0\")){\
  6300.   var t = 0;\
  6301.   while(document.getElementById(\"canvas_input\"+t)){\
  6302.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6303.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6304.     p++;\
  6305.    };\
  6306.    t++;\
  6307.   };\
  6308.  };\
  6309.  if( typeof(userdraw_text) !== 'undefined' ){\
  6310.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6311.  }\
  6312.  else\
  6313.  {\
  6314.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  6315.  }\
  6316. }\
  6317. else\
  6318. {\
  6319.  if( typeof(userdraw_text) !== 'undefined' ){\
  6320.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
  6321.  }\
  6322.  else\
  6323.  {\
  6324.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
  6325.  }\
  6326. }\
  6327. };\n\
  6328. /* end function 3 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6329.     break;
  6330.     case 4: fprintf(js_include_file,"\
  6331. \n/* begin function 4 read_canvas%d() */\n\
  6332. read_canvas%d = function(){\
  6333. var prec = %d;\
  6334. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  6335. while(userdraw_x[p]){\
  6336.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  6337.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
  6338.  p++;\
  6339. };\
  6340. if(p == 0){return;};\
  6341. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6342.  var p = 0;var input_reply = new Array();\
  6343.  if( document.getElementById(\"canvas_input0\")){\
  6344.   var t = 0;\
  6345.   while(document.getElementById(\"canvas_input\"+t)){\
  6346.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6347.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6348.     p++;\
  6349.    };\
  6350.    t++;\
  6351.   };\
  6352.  };\
  6353.  if( typeof(userdraw_text) !== 'undefined' ){\
  6354.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6355.  }\
  6356.  else\
  6357.  {\
  6358.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  6359.  }\
  6360. }\
  6361. else\
  6362. {\
  6363.  if( typeof(userdraw_text) !== 'undefined' ){\
  6364.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
  6365.  }\
  6366.  else\
  6367.  {\
  6368.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
  6369.  }\
  6370. };\
  6371. };\n\
  6372. /* end function 4 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6373.     break;
  6374.     /*
  6375.         attention: we reset userdraw_x / userdraw_y: because  userdraw_x = [][] userdraw_y = [][]
  6376.         used for userdraw multiple paths
  6377.     */
  6378.     case 5: fprintf(js_include_file,"\
  6379. \n/* begin function 5 read_canvas%d() */\n\
  6380. read_canvas%d = function(){\
  6381. set_reply_precision();\
  6382. var p = 0;\
  6383. var reply = \"\";\
  6384. for(p = 0; p < userdraw_x.length;p++){\
  6385.  if(userdraw_x[p] != null ){\
  6386.   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
  6387.  };\
  6388. };\
  6389. if(p == 0){return;};\
  6390. userdraw_x = [];userdraw_y = [];\
  6391. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6392.  var p = 0;var input_reply = new Array();\
  6393.  if( document.getElementById(\"canvas_input0\")){\
  6394.   var t = 0;\
  6395.   while(document.getElementById(\"canvas_input\"+t)){\
  6396.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6397.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6398.     p++;\
  6399.    };\
  6400.    t++;\
  6401.   };\
  6402.  };\
  6403.  if( typeof(userdraw_text) !== 'undefined' ){\
  6404.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6405.  }\
  6406.  else\
  6407.  {\
  6408.   return reply +\"\\n\"+input_reply;\
  6409.  }\
  6410. }\
  6411. else\
  6412. {\
  6413.  if( typeof(userdraw_text) !== 'undefined' ){\
  6414.   return reply+\"\\n\"+userdraw_text;\
  6415.  }\
  6416.  else\
  6417.  {\
  6418.   return reply;\
  6419.  }\
  6420. };\
  6421. };\n\
  6422. /* end function 5 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6423.     break;
  6424.     /*
  6425.         attention: we reset userdraw_x / userdraw_y: because userdraw_x = [][] userdraw_y = [][]
  6426.         used for userdraw multiple paths
  6427.     */
  6428.     case 6: fprintf(js_include_file,"\
  6429. \n/* begin function 6 read_canvas%d() */\n\
  6430. read_canvas%d = function(){\
  6431. var p = 0;\
  6432. var reply = \"\";\
  6433. var tmp_x = new Array();\
  6434. var tmp_y = new Array();\
  6435. var prec = %d;\
  6436. for(p = 0 ; p < userdraw_x.length; p++){\
  6437.  tmp_x = userdraw_x[p];\
  6438.  tmp_y = userdraw_y[p];\
  6439.  if(tmp_x != null){\
  6440.   for(var i = 0 ; i < tmp_x.length ; i++){\
  6441.    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
  6442.    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
  6443.   };\
  6444.   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
  6445.  };\
  6446. };\
  6447. if(p == 0){return;};\
  6448. userdraw_x = [];userdraw_y = [];\
  6449. if( document.getElementById(\"canvas_input0\") ){\
  6450.  var p = 0;var input_reply = new Array();\
  6451.  if( document.getElementById(\"canvas_input0\")){\
  6452.   var t = 0;\
  6453.   while(document.getElementById(\"canvas_input\"+t)){\
  6454.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6455.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6456.     p++;\
  6457.    };\
  6458.    t++;\
  6459.   };\
  6460.  };\
  6461.  if( typeof(userdraw_text) !== 'undefined' ){\
  6462.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6463.  }\
  6464.  else\
  6465.  {\
  6466.   return reply +\"\\n\"+input_reply;\
  6467.  }\
  6468. }\
  6469. else\
  6470. {\
  6471.  if( typeof(userdraw_text) !== 'undefined' ){\
  6472.   return reply +\"\\n\"+userdraw_text;\
  6473.  }\
  6474.  else\
  6475.  {\
  6476.   return reply;\
  6477.  }\
  6478. };\
  6479. };\n\
  6480. /* end function 6 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6481.     break;
  6482.     case 7: fprintf(js_include_file,"\
  6483. \n/* begin function 7 read_canvas%d() */\n\
  6484. read_canvas%d = function(){\
  6485. set_reply_precision();\
  6486. var reply = new Array();\
  6487. var p = 0;\
  6488. while(userdraw_x[p]){\
  6489.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
  6490.  p++;\
  6491. };\
  6492. if(p == 0){return;};\
  6493. if( document.getElementById(\"canvas_input0\") ){\
  6494.  var p = 0;var input_reply = new Array();\
  6495.  if( document.getElementById(\"canvas_input0\")){\
  6496.   var t = 0;\
  6497.   while(document.getElementById(\"canvas_input\"+t)){\
  6498.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6499.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6500.     p++;\
  6501.    };\
  6502.    t++;\
  6503.   };\
  6504.  };\
  6505.  if( typeof(userdraw_text) !== 'undefined' ){\
  6506.   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6507.  }\
  6508.  else\
  6509.  {\
  6510.   return reply+\"\\n\"+input_reply;\
  6511.  }\
  6512. }\
  6513. else\
  6514. {\
  6515.  if( typeof(userdraw_text) !== 'undefined' ){\
  6516.   return reply+\"\\n\"+userdraw_text;\
  6517.  }\
  6518.  else\
  6519.  {\
  6520.   return reply;\
  6521.  }\
  6522. };\
  6523. };\n\
  6524. /* end function 7 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6525.     break;
  6526.     case 8: fprintf(js_include_file,"\
  6527. \n/* begin function 8 read_canvas%d() */\n\
  6528. read_canvas%d = function(){\
  6529. var reply = new Array();\
  6530. var p = 0;\
  6531. var prec = %d;\
  6532. while(userdraw_x[p]){\
  6533.  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  6534.  p++;\
  6535. };\
  6536. if(p == 0){return;};\
  6537. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6538.  var p = 0;var input_reply = new Array();\
  6539.  if( document.getElementById(\"canvas_input0\")){\
  6540.   var t = 0;\
  6541.   while(document.getElementById(\"canvas_input\"+t)){\
  6542.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6543.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6544.     p++;\
  6545.    };\
  6546.    t++;\
  6547.   };\
  6548.  };\
  6549.  if( typeof(userdraw_text) !== 'undefined' ){\
  6550.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6551.  }\
  6552.  else\
  6553.  {\
  6554.   return reply +\"\\n\"+input_reply;\
  6555.  }\
  6556. }\
  6557. else\
  6558. {\
  6559.  if( typeof(userdraw_text) !== 'undefined' ){\
  6560.   return reply +\"\\n\"+userdraw_text;\
  6561.  }\
  6562.  else\
  6563.  {\
  6564.   return reply;\
  6565.  }\
  6566. };\
  6567. };\n\
  6568. /* end function 8 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6569.     break;
  6570.     case 9: fprintf(js_include_file,"\
  6571. \n/* begin function 9 read_canvas%d() */\n\
  6572. read_canvas%d = function(){\
  6573. set_reply_precision();\
  6574. var reply = new Array();\
  6575. var p = 0;\
  6576. while(userdraw_x[p]){\
  6577.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
  6578.  p++;\
  6579. };\
  6580. if(p == 0){return;};\
  6581. if( document.getElementById(\"canvas_input0\") ){\
  6582.  var p = 0;var input_reply = new Array();\
  6583.  if( document.getElementById(\"canvas_input0\")){\
  6584.   var t = 0;\
  6585.   while(document.getElementById(\"canvas_input\"+t)){\
  6586.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6587.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6588.     p++;\
  6589.    };\
  6590.    t++;\
  6591.   };\
  6592.  };\
  6593.  if( typeof(userdraw_text) !== 'undefined' ){\
  6594.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6595.  }\
  6596.  else\
  6597.  {\
  6598.   return reply +\"\\n\"+input_reply;\
  6599.  }\
  6600. }\
  6601. else\
  6602. {\
  6603.  if( typeof(userdraw_text) !== 'undefined' ){\
  6604.   return reply +\"\\n\"+userdraw_text;\
  6605.  }\
  6606.  else\
  6607.  {\
  6608.   return reply;\
  6609.  }\
  6610. };\
  6611. };\n\
  6612. /* end function 9 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6613.     break;
  6614.     case 10: fprintf(js_include_file,"\
  6615. \n/* begin function 10 read_canvas%d() */\n\
  6616. read_canvas%d = function(){\
  6617. var reply = new Array();\
  6618. var p = 0;\
  6619. var prec = %d;\
  6620. var reply = \"\";\
  6621. while(userdraw_x[p]){\
  6622.  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\";\
  6623.  p++;\
  6624. };\
  6625. if(p == 0){return;};\
  6626. return reply;\
  6627. };\n\
  6628. /* end function 10 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6629.     break;
  6630.     case 11: fprintf(js_include_file,"\
  6631. \n/* begin function 11 read_canvas%d() */\n\
  6632. read_canvas%d = function(){\
  6633. var reply = \"\";\
  6634. var p = 0;\
  6635. var prec = %d;\
  6636. while(userdraw_x[p+1]){\
  6637.  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\" ;\
  6638.  p = p+2;\
  6639. };\
  6640. if(p == 0){return;};\
  6641. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  6642.  var p = 0;var input_reply = new Array();\
  6643.  if( document.getElementById(\"canvas_input0\")){\
  6644.   var t = 0;\
  6645.   while(document.getElementById(\"canvas_input\"+t)){\
  6646.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6647.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6648.     p++;\
  6649.    };\
  6650.    t++;\
  6651.   };\
  6652.  };\
  6653.  if( typeof(userdraw_text) !== 'undefined' ){\
  6654.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6655.  }\
  6656.  else\
  6657.  {\
  6658.   return reply +\"\\n\"+input_reply;\
  6659.  }\
  6660. }\
  6661. else\
  6662. {\
  6663.  if( typeof(userdraw_text) !== 'undefined' ){\
  6664.   return reply +\"\\n\"+userdraw_text;\
  6665.  }\
  6666.  else\
  6667.  {\
  6668.   return reply;\
  6669.  }\
  6670. };\
  6671. };\n\
  6672. /* end function 11 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6673.     break;
  6674.     case 12: fprintf(js_include_file,"\
  6675. \n/* begin function 12 read_canvas%d() */\n\
  6676. read_canvas%d = function(){\
  6677. set_reply_precision();\
  6678. var reply = \"\";\
  6679. var p = 0;\
  6680. while(userdraw_x[p+1]){\
  6681. reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
  6682. p=p+2;\
  6683. };\
  6684. };\
  6685. if(p == 0){return;};\
  6686. if( document.getElementById(\"canvas_input0\") ){\
  6687.  var p = 0;var input_reply = new Array();\
  6688.  if( document.getElementById(\"canvas_input0\")){\
  6689.   var t = 0;\
  6690.   while(document.getElementById(\"canvas_input\"+t)){\
  6691.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6692.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6693.     p++;\
  6694.    };\
  6695.    t++;\
  6696.   };\
  6697.  };\
  6698.  if( typeof(userdraw_text) !== 'undefined' ){\
  6699.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6700.  }\
  6701.  else\
  6702.  {\
  6703.   return reply +\"\\n\"+input_reply;\
  6704.  }\
  6705. }\
  6706. else\
  6707. {\
  6708.  if( typeof(userdraw_text) !== 'undefined' ){\
  6709.   return reply +\"\\n\"+userdraw_text\
  6710.  }\
  6711.  else\
  6712.  {\
  6713.   return reply;\
  6714.  }\
  6715. };\
  6716. };\n\
  6717. /* end function 12 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6718.     break;
  6719.     case 13: fprintf(js_include_file,"\
  6720. \n/* begin function 13 read_canvas%d() */\n\
  6721. read_canvas%d = function(){\
  6722. var reply = new Array();\
  6723. var p = 0;var i = 0;\
  6724. var prec = %d;\
  6725. while(userdraw_x[p+1]){\
  6726.  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;\
  6727.  p = p+2;i++;\
  6728. };\
  6729. if(p == 0){return;};\
  6730. if( document.getElementById(\"canvas_input0\") ){\
  6731.  var p = 0;var input_reply = new Array();\
  6732.  if( document.getElementById(\"canvas_input0\")){\
  6733.   var t = 0;\
  6734.   while(document.getElementById(\"canvas_input\"+t)){\
  6735.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6736.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6737.     p++;\
  6738.    };\
  6739.    t++;\
  6740.   };\
  6741.  };\
  6742.  if( typeof(userdraw_text) !== 'undefined' ){\
  6743.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6744.  }\
  6745.  else\
  6746.  {\
  6747.   return reply +\"\\n\"+input_reply;\
  6748.  }\
  6749. }\
  6750. else\
  6751. {\
  6752.  if( typeof(userdraw_text) !== 'undefined' ){\
  6753.   return reply +\"\\n\"+userdraw_text\
  6754.  }\
  6755.  else\
  6756.  {\
  6757.   return reply;\
  6758.  }\
  6759. };\
  6760. };\n\
  6761. /* end function 13 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6762.     break;
  6763.     case 14: fprintf(js_include_file,"\
  6764. \n/* begin function 14 read_canvas%d() */\n\
  6765. read_canvas%d = function(){\
  6766. set_reply_precision();\
  6767. var reply = new Array();\
  6768. var p = 0;var i = 0;\
  6769. while(userdraw_x[p+1]){\
  6770.  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
  6771.  p = p+2;i++;\
  6772. };\
  6773. if(p == 0){return;};\
  6774. if( document.getElementById(\"canvas_input0\") ){\
  6775.  var p = 0;var input_reply = new Array();\
  6776.  if( document.getElementById(\"canvas_input0\")){\
  6777.   var t = 0;\
  6778.   while(document.getElementById(\"canvas_input\"+t)){\
  6779.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6780.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6781.     p++;\
  6782.    };\
  6783.    t++;\
  6784.   };\
  6785.  };\
  6786.  if( typeof(userdraw_text) !== 'undefined' ){\
  6787.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6788.  }\
  6789.  else\
  6790.  {\
  6791.   return reply +\"\\n\"+input_reply;\
  6792.  }\
  6793. }\
  6794. else\
  6795. {\
  6796.  if( typeof(userdraw_text) !== 'undefined' ){\
  6797.   return reply +\"\\n\"+userdraw_text;\
  6798.  }\
  6799.  else\
  6800.  {\
  6801.   return reply;\
  6802.  }\
  6803. };\
  6804. };\n\
  6805. /* end function 14 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6806.     break;
  6807.     case 15: fprintf(js_include_file,"\
  6808. \n/* begin function 15  read_canvas%d() */\n\
  6809. read_canvas%d = function(){\
  6810. var input_reply = new Array();\
  6811. var p = 0;\
  6812. if( document.getElementById(\"canvas_input0\")){\
  6813.  var t = 0;\
  6814.  while(document.getElementById(\"canvas_input\"+t)){\
  6815.   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6816.    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6817.    p++;\
  6818.   };\
  6819.   t++;\
  6820.  };\
  6821. };\
  6822. if( typeof(userdraw_text) !== 'undefined' ){\
  6823.   return input_reply +\"\\n\"+userdraw_text;\
  6824. }\
  6825. else\
  6826. {\
  6827.  return input_reply;\
  6828. };\
  6829. };\n\
  6830. /* end function 15 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6831.     break;
  6832.     case 16: fprintf(js_include_file,"\
  6833. \n/* begin function 16 read_mathml() */\n\
  6834. function read_mathml(){\
  6835. var reply = new Array();\
  6836. var p = 0;\
  6837. if( document.getElementById(\"mathml0\")){\
  6838.  while(document.getElementById(\"mathml\"+p)){\
  6839.   reply[p] = document.getElementById(\"mathml\"+p).value;\
  6840.   p++;\
  6841.  };\
  6842. };\
  6843. return reply;\
  6844. };\
  6845. this.read_mathml = read_mathml;\n\
  6846. /* end function 16 read_mathml() */");
  6847.     break;
  6848.     case 17:  fprintf(js_include_file,"\
  6849. \n/* begin function 17 read_canvas%d() */\n\
  6850. read_canvas%d = function(){\
  6851. var len = userdraw_x.length;\
  6852. if( len == 0){alert(\"no text typed...\");return;}\
  6853. var rep = px2x(userdraw_x[0])+\",\"+px2y(userdraw_y[0])+\",\"+userdraw_text[0];\
  6854. for(var p = 1 ; p < len ; p++){\
  6855.  rep = rep + \"\\n\" + px2x(userdraw_x[p]) + \",\" + px2y(userdraw_y[p]) + \",\" + userdraw_text[p];\
  6856. };\
  6857. return rep;\
  6858. };\n\
  6859. /* end function 17 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6860.     break;
  6861.     case 18: fprintf(js_include_file,"\
  6862. \n/* javascript has no real modulo function */\n\
  6863. function mod(n, m){\
  6864. var m = parseInt(((n %% m) + m) %% m);\
  6865. return m;\
  6866. };\
  6867. \n/* begin function 18 read_canvas%d() */\n\
  6868. read_canvas%d = function(){\
  6869. var p = 0;\
  6870. var reply = new Array();\
  6871. var name;\
  6872. var t = true;\
  6873. var h;var m;var s;\
  6874. while(t){\
  6875.  try{\
  6876.   name = eval('clocks'+p);\
  6877.   h = name.H;m = name.M;s = name.S;\
  6878.   h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\
  6879.   reply[p] = h+\":\"+m+\":\"+s;\
  6880.   p++;\
  6881.  }catch(e){t=false;};\
  6882. };\
  6883. if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
  6884. return reply;\
  6885. };\n\
  6886. /* end function 18 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6887.     break;
  6888.     case 19: fprintf(js_include_file,"\
  6889. \n/* begin function 19 read_canvas%d() */\n\
  6890. read_canvas%d = function(){\
  6891. return reply[0];\
  6892. };\n\
  6893. /* end function 19 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  6894.     break;
  6895.     case 20: fprintf(js_include_file,"\
  6896. \n/* begin function 20 read_canvas%d() */\n\
  6897. read_canvas%d = function(){\
  6898. var prec = %d;\
  6899. var len  = ext_drag_images.length;\
  6900. var reply = new Array(len);\
  6901. for(var p = 0 ; p < len ; p++){\
  6902.    var img = ext_drag_images[p];\
  6903.    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  6904. };\
  6905. return reply;\
  6906. };\n\
  6907. /* end function 20 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6908.     break;
  6909.     case 21: fprintf(js_include_file,"\
  6910. \n/* begin function 21 read_canvas%d() */\n\
  6911. read_canvas%d = function(){\
  6912. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  6913. var reply_coord = new Array();var p = 0;\
  6914. var prec = %d;\
  6915. while(userdraw_x[p]){\
  6916.  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
  6917.  p++;\
  6918. };\
  6919. if(p == 0){return;};\
  6920. if( document.getElementById(\"canvas_input0\") ){\
  6921.  var p = 0;var input_reply = new Array();\
  6922.  if( document.getElementById(\"canvas_input0\")){\
  6923.   var t = 0;\
  6924.   while(document.getElementById(\"canvas_input\"+t)){\
  6925.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6926.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6927.     p++;\
  6928.    };\
  6929.    t++;\
  6930.   };\
  6931.  };\
  6932.  if( typeof(userdraw_text) !== 'undefined' ){\
  6933.   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6934.  }\
  6935.  else\
  6936.  {\
  6937.   return reply_coord+\"\\n\"+input_reply;\
  6938.  }\
  6939. }\
  6940. else\
  6941. {\
  6942.  if( typeof(userdraw_text) !== 'undefined' ){\
  6943.   return reply_coord+\"\\n\"+userdraw_text;\
  6944.  }\
  6945.  else\
  6946.  {\
  6947.   return reply_coord;\
  6948.  };\
  6949. };\
  6950. };\n\
  6951. /* end function 21 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6952.     break;
  6953.     case 22: fprintf(js_include_file,"\
  6954. \n/* begin function 22 read_canvas%d() */\n\
  6955. read_canvas%d = function(){\
  6956. var reply = new Array();\
  6957. var lu = userdraw_x.length;\
  6958. if(lu == 0){return;};\
  6959. var idx = 0;\
  6960. var prec = %d;\
  6961. for(var p = 0 ; p < lu ; p++){\
  6962.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
  6963.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
  6964. };\
  6965. if( document.getElementById(\"canvas_input0\") ){\
  6966.  var p = 0;var input_reply = new Array();\
  6967.  if( document.getElementById(\"canvas_input0\")){\
  6968.   var t = 0;\
  6969.   while(document.getElementById(\"canvas_input\"+t)){\
  6970.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  6971.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  6972.     p++;\
  6973.    };\
  6974.    t++;\
  6975.   };\
  6976.  };\
  6977.  if( typeof(userdraw_text) !== 'undefined' ){\
  6978.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  6979.  }\
  6980.  else\
  6981.  {\
  6982.   return reply +\"\\n\"+input_reply;\
  6983.  }\
  6984. }\
  6985. else\
  6986. {\
  6987.  if( typeof(userdraw_text) !== 'undefined' ){\
  6988.   return reply +\"\\n\"+userdraw_text;\
  6989.  }\
  6990.  else\
  6991.  {\
  6992.   return reply;\
  6993.  }\
  6994. };\
  6995. };\n\
  6996. /* end function 22 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  6997.     break;
  6998.     case 23: fprintf(js_include_file,"\
  6999. \n/* begin function 23 read_canvas%d() default 5 px marge */\n\
  7000. read_canvas%d = function(){\
  7001. if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
  7002. var lu = userdraw_x.length;\
  7003. if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
  7004. var reply_x = new Array();var reply_y = new Array();\
  7005. var marge = 5;var p = 0;\
  7006. var prec = %d;\
  7007. for(var i = 0; i < lu - 1 ; i++ ){\
  7008.  if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\
  7009.   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
  7010.   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
  7011.   p++;\
  7012.  };\
  7013.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\
  7014. };\
  7015. if( document.getElementById(\"canvas_input0\")){\
  7016.  var p = 0;var input_reply = new Array();\
  7017.  if( document.getElementById(\"canvas_input0\")){\
  7018.   var t = 0;\
  7019.   while(document.getElementById(\"canvas_input\"+t)){\
  7020.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  7021.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  7022.     p++;\
  7023.    };\
  7024.    t++;\
  7025.   };\
  7026.  };\
  7027.  if( typeof(userdraw_text) !== 'undefined' ){\
  7028.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  7029.  }\
  7030.  else\
  7031.  {\
  7032.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  7033.  }\
  7034. }\
  7035. else\
  7036. {\
  7037.  if( typeof(userdraw_text) !== 'undefined' ){\
  7038.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  7039.  }\
  7040.  else\
  7041.  {\
  7042.   return reply_x+\"\\n\"+reply_y;\
  7043.  };\
  7044. };\
  7045. };\n\
  7046. /* end function 23 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7047.     break;
  7048.     case 24: fprintf(js_include_file,"\n\
  7049. /* begin function 24  read_canvas%d() */\n\
  7050. read_canvas%d = function(){\
  7051. var input_reply = new Array();\
  7052. var p = 0;\
  7053. if( document.getElementById(\"canvas_input0\")){\
  7054.  while(document.getElementById(\"canvas_input\"+p)){\
  7055.    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
  7056.    p++;\
  7057.  };\
  7058.  return input_reply;\
  7059. };\
  7060. };\n\
  7061. /* end function 24 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  7062.     break;
  7063.     case 25:
  7064.     fprintf(js_include_file,"\n/* begin function 25 read_canvas%d(): angle(s) in degrees */\n\
  7065. read_canvas%d = function(){\
  7066. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  7067. var lu = userdraw_radius.length;\
  7068. var prec = %d;\
  7069. var angle_reply = new Array(lu);\
  7070. for(var p = 0 ; p < lu ; p++){\
  7071.  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
  7072. };\
  7073. return angle_reply;\
  7074. };\n\
  7075. /* end function 25 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7076.     break;
  7077.     case 26:
  7078.     fprintf(js_include_file,"\n/* begin function 26 read_canvas%d(): angle(s) in radians */\n\
  7079. read_canvas%d = function(){\
  7080. if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
  7081. var lu = userdraw_radius.length;\
  7082. var prec = %d;\
  7083. var angle_reply = new Array(lu);\
  7084. for(var p = 0 ; p < lu ; p++){\
  7085.  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
  7086. };\
  7087. return angle_reply;\
  7088. };\n\
  7089. /* end function 26 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7090.     break;
  7091.     case 27:
  7092.     fprintf(js_include_file,"\n/* begin function 27 read_canvas%d(): inputfield(s) location and their values: */\n\
  7093. read_canvas%d = function(){\
  7094. var lu = userdraw_x.length;\
  7095. if( lu < 1){alert(\"nothing drawn...\");return;};\
  7096. set_reply_precision();\
  7097. var prec = %d;var rep = \"\";\
  7098. for(var p = 0 ; p < lu ; p++){\
  7099.   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\";\
  7100. };\
  7101. return rep;\
  7102. };\n\
  7103. /* end function 27 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7104.     break;
  7105.     case 28:
  7106.     fprintf(js_include_file,"\n/* begin function 28 read_canvas%d() */\n\
  7107. read_canvas%d = function(){\
  7108. var prec = %d;\
  7109. var reply = new Array();var p = 0;\
  7110. var idx = 0;\
  7111. while(userdraw_x[p]){\
  7112.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  7113.  idx++;\
  7114.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  7115.  idx++;\
  7116.  reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\
  7117.  idx++;\
  7118.  p++;\
  7119. };\
  7120. if( p == 0){alert(\"nothing drawn...\");return;}\
  7121. return reply;\
  7122. };\n\
  7123. /* end function 28 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7124.     break;
  7125.     case 29:
  7126.     fprintf(js_include_file,"\n/* begin function 29 read_canvas%d() */\n\
  7127. function x_precision(array_x){\
  7128. var len = array_x.length;\
  7129. var x_array = new Array(len);\
  7130. var prec = %d;\
  7131. for(var p = 0 ; p < len ; p++ ){\
  7132.  x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\
  7133. };\
  7134. return x_array;\
  7135. };\
  7136. function y_precision(array_y){\
  7137. var len = array_y.length;\
  7138. var y_array = new Array(len);\
  7139. var prec = %d;\
  7140. for(var p = 0 ; p < len ; p++ ){\
  7141.  y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\
  7142. };\
  7143. return y_array;\
  7144. };\
  7145. function radius_to_x(array_r){\
  7146. var len = array_r.length;\
  7147. var ff = (xmax - xmin)/xsize;\
  7148. var r_array = new Array(len);\
  7149. var prec = %d;\
  7150. for(var p = 0 ; p < len ; p++ ){\
  7151.  r_array[p] = (Math.round(prec*(ff*(array_r[p]))))/prec;\
  7152. };\
  7153. return r_array;\
  7154. };\
  7155. read_canvas%d = function(){\
  7156. function uniq_fast(arr){\
  7157.  var seen = {};\
  7158.  var out = [];\
  7159.  var len = arr.length;\
  7160.  var j = 0;\
  7161.  for(var i = 0; i < len; i++){\
  7162.   var item = arr[i];\
  7163.   if(seen[item] !== 1) {\
  7164.    seen[item] = 1;out[j++] = item;\
  7165.   };\
  7166.  };\
  7167.  return out;\
  7168. };\
  7169. function list_unique(arr1,arr2,arr3){\
  7170.  if( typeof( allow_duplicate_answers ) === 'number' ){ return [ x_precision(arr1),y_precision(arr2),arr3 ];};\
  7171.  var len1 = arr1.length;\
  7172.  if(len1 != arr2.length){alert('mismatch in number of x and y values...');return;};\
  7173.  var sum = [];var R1=[];var R2=[];\
  7174.  arr1 = x_precision(arr1);\
  7175.  arr2 = y_precision(arr2);\
  7176.  if(arr3 == null){\
  7177.   for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]; };\
  7178.   sum = uniq_fast(sum);var len2=sum.length;\
  7179.   for(var p=0;p<len2;p++){\
  7180.    var tmp = (sum[p]).split('#');\
  7181.    R1[p] = tmp[0];\
  7182.    R2[p] = tmp[1];\
  7183.   };\
  7184.   return [R1,R2];\
  7185.  }else{\
  7186.   var R3 = [];\
  7187.   for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]+'#'+arr3[p];};\
  7188.   sum = uniq_fast(sum);var len2=sum.length;\
  7189.   for(var p=0;p<len2;p++){\
  7190.    var tmp = (sum[p]).split('#');\
  7191.    R1[p] = tmp[0];\
  7192.    R2[p] = tmp[1];\
  7193.    R3[p] = tmp[2];\
  7194.   };\
  7195.   return [R1,R2,R3];\
  7196.  };\
  7197. };\
  7198. var reply=\" \";\
  7199. 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\"; };\
  7200. 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\"; };\
  7201. 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\"; };\
  7202. 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\"; };\
  7203. 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\"; };\
  7204. 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\"; };\
  7205. 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\"; };\
  7206. 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\"; };\
  7207. 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\"; };\
  7208. 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\"; };\
  7209. 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\"; };\
  7210. 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\"; };\
  7211. 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\";};\
  7212. 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\";};\
  7213. 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;;};\
  7214. 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;;};\
  7215. return reply;\
  7216. };\
  7217. /* end function 29 read_canvas%d() */",canvas_root_id,reply_precision,reply_precision,reply_precision,canvas_root_id,canvas_root_id);
  7218.     break;
  7219.     case 30:
  7220.     fprintf(js_include_file,"\n/* begin function 30 read_canvas%d() */\n\
  7221. read_canvas%d = function(){\
  7222. var reply = new Array(3);\
  7223. var prec = %d;\
  7224. reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
  7225. reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
  7226. reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\
  7227. return reply;\
  7228. };\n\
  7229. /* end function 30 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7230.     break;
  7231.     case 31:
  7232.     fprintf(js_include_file,"\n/* begin function 31 read_canvas%d() */\n\
  7233. read_canvas%d = function(){\
  7234. var reply = new Array(3);\
  7235. var prec = %d;\
  7236. reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
  7237. reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
  7238. reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
  7239. return reply;\
  7240. };\n\
  7241. /* end function 31 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7242.     break;
  7243.     case 32:
  7244.     fprintf(js_include_file,"\n/* begin function 32 read_canvas%d() */\n\
  7245. read_canvas%d = function(){\
  7246. var reply = new Array(6);\
  7247. var prec = %d;\
  7248. reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
  7249. reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
  7250. reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
  7251. reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
  7252. reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
  7253. reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\
  7254. return reply;\
  7255. };\n\
  7256. /* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  7257.     break;
  7258.     case 33:
  7259.     fprintf(js_include_file,"\n/* begin function 33 read_canvas%d() */\n\
  7260. read_canvas%d = function(){\
  7261. var reply = userdraw_x+'\\n'+userdraw_y;\
  7262. return reply;\
  7263. };\n\
  7264. /* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  7265.     break;
  7266.     case 34: fprintf(js_include_file,"\
  7267. \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\
  7268. var read_canvas_images = function(){\
  7269. var prec = %d;\
  7270. var len  = ext_drag_images.length;\
  7271. var reply = new Array(len);\
  7272. for(var p = 0 ; p < len ; p++){\
  7273.    var img = ext_drag_images[p];\
  7274.    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  7275. };\
  7276. return reply;\
  7277. };\n\
  7278. /* end function 20 read_canvas_images() */",reply_precision);
  7279.     break;
  7280.  
  7281.     default: canvas_error("hmmm unknown replyformat...");break;
  7282. }
  7283.  return;
  7284. }
  7285.  
  7286.  
  7287. /*
  7288.  add drawfunction:
  7289.  - functions used by userdraw_primitives (circle,rect,path,triangle...)
  7290.  - things not covered by the drag&drop library (static objects like parallel, lattice, gridfill, imagefill)
  7291.  - grid / mathml
  7292.  - will not scale or zoom in
  7293.  - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
  7294.  - is printed directly into 'js_include_file'
  7295. */
  7296.  
  7297. void add_javascript_function(int js_function[],int canvas_root_id){
  7298. int i;
  7299. for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
  7300.  if( js_function[i] == 1){
  7301.     switch(i){
  7302.     case ADD_JS_ROTATE_MOUSE:
  7303.     /* identify mouse coordinates on rotated objects
  7304.     used for command rotate : faster than transform matrix */
  7305.     fprintf(js_include_file,"\n/* begin rotate mouse */\n\
  7306. function rotate_mouse(mx,my,obj){\
  7307. if( typeof(obj.angle) === 'undefined' ){console.log('rotate_mouse() angle undefined');return {x:mx,y:my};};\
  7308. var cos = Math.cos(obj.angle);\
  7309. var sin = Math.sin(obj.angle);\
  7310. var xc = obj.rotation_center[0];\
  7311. var yc = obj.rotation_center[1];\
  7312. var x_r = parseInt((cos * (mx - xc)) + (sin * (my - yc)) + xc);\
  7313. var y_r = parseInt((cos * (my - yc)) - (sin * (mx - xc)) + yc);\
  7314. return {x:x_r,y:y_r};\
  7315. };");
  7316.      break;
  7317.     case ADD_JS_TRANSFORM_MOUSE:
  7318.     /* identify mouse coordinates on transformed objects using command affine */
  7319.     fprintf(js_include_file,"\n/* begin translate mouse */\n\
  7320. function transform_mouse(mx,my,obj){\
  7321. if( typeof(obj.affine_matrix) === 'undefined' ){console.log('translate_mouse() affine_matrix undefined');return {x:mx,y:my};};\
  7322. var m = obj.affine_matrix;\
  7323. var d = 1/(m[0]*m[3]-m[1]*m[2]);\
  7324. var im = [ m[3]*d, -m[1]*d,-m[2]*d,m[0]*d,d*(m[2]*m[5]-m[3]*m[4]),d*(m[1]*m[4]-m[0]*m[5]) ];\
  7325. return { x:mx*im[0]+my*im[2]+im[4], y:mx*im[1]+my*im[3]+im[5] };};"
  7326. );
  7327.  
  7328.      break;
  7329.     case JS_FIND_ANGLE:
  7330.     fprintf(js_include_file,"\n\
  7331. /* function find_angle() */\n\
  7332. function find_angle(xc,yc,x1,y1){var dx = x1 - xc;var dy = yc - y1;return Math.atan2(dx,dy);};");
  7333.     break;
  7334.     case DRAW_EXTERNAL_IMAGE:
  7335. /*
  7336. the external_canvas is already created: it needs to be FIRST in order to do some drawing onto it
  7337. only drag_xy !
  7338. snaptogrid | xsnaptogrid | ysnaptogrid works
  7339. 14/5/2019
  7340. on heavy styled wims (unice.fr etc problems with mouse?
  7341. now uniform method of retreiving mouse coordinates dragstuff.getMouse()
  7342. */
  7343. fprintf(js_include_file,"\n/* drag external images */\n\
  7344. var external_ctx = external_canvas.getContext(\"2d\");\
  7345. var external_canvas_rect = external_canvas.getBoundingClientRect();\
  7346. canvas_div.addEventListener(\"mousedown\",setxy,false);\
  7347. canvas_div.addEventListener(\"mouseup\",dragstop,false);\
  7348. canvas_div.addEventListener(\"mousemove\",dragxy,false);\
  7349. var selected_image = null;\
  7350. var ext_image_cnt = 0;\
  7351. var ext_drag_images = new Array();\
  7352. var ext_centered = 0;\
  7353. function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt,centered,use_snap){\
  7354. ext_centered = centered;\
  7355. ext_image_cnt = idx;\
  7356. if(draggable == 1 ){\
  7357.  reply[click_cnt] = 0;\
  7358. };\
  7359. var image = new Image();\
  7360. image.src = URL;\
  7361. image.onload = function(){\
  7362.  if( sx < 1 ){ sx = 0; };\
  7363.  if( sy < 1 ){ sy = 0; };\
  7364.  if( swidth < 1 ){swidth = image.width;};\
  7365.  if( sheight < 1 ){sheight = image.height;};\
  7366.  if( width < 1 ){width = image.width;};\
  7367.  if( height < 1 ){height = image.height;};\
  7368.  if( resizable == 0 ){\
  7369.   if( swidth > image.width ){ swidth = image.width; };\
  7370.   if( sheight > image.height){ sheight = image.height;};\
  7371.   if( width > image.width ){ width = image.width; };\
  7372.   if( height > image.height){ height = image.height;};\
  7373.  };\
  7374.  var img = new Array(12);\
  7375.  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
  7376.  img[8] = width;img[9] = height;img[10] = click_cnt;img[11] = use_snap;\
  7377.  img[6] = x0;img[7] = y0;\
  7378.  ext_drag_images[idx] = img;\
  7379.  if(centered == 4){\
  7380.   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]);\
  7381.  }else{\
  7382.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  7383.  };\
  7384. };\
  7385. };\
  7386. function dragstop(evt){\
  7387. selected_image = null;return;\
  7388. };\
  7389. function dragxy(evt){\
  7390. if( selected_image != null ){\
  7391.  var s_img = ext_drag_images[selected_image];\
  7392.  var mouse = dragstuff.getMouse(evt,external_canvas);\
  7393.  var xy = multisnap_check(mouse.x,mouse.y,s_img[11]);\
  7394.  xy[0] = parseInt(xy[0] - 0.5*s_img[8]);\
  7395.  xy[1] = parseInt(xy[1] - 0.5*s_img[9]);\
  7396.  s_img[6] = xy[0];s_img[7] = xy[1];\
  7397.  ext_drag_images[selected_image] = s_img;\
  7398.  external_ctx.clearRect(0,0,xsize,ysize);\
  7399.  for(var i = 0; i <= ext_image_cnt ; i++){\
  7400.   var img = ext_drag_images[i];\
  7401.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
  7402.  };\
  7403. };\
  7404. };\
  7405. function setxy(evt){\
  7406. if( ! selected_image && evt.which == 1 ){\
  7407.  var mouse = dragstuff.getMouse(evt,external_canvas);\
  7408.  var xm = mouse.x;\
  7409.  var ym = mouse.y;\
  7410.  var img;var xmarge;var ymarge;\
  7411.  for(var p = 0 ; p <= ext_image_cnt ; p++){\
  7412.   if( ext_drag_images[p] ){\
  7413.    img = ext_drag_images[p];\
  7414.    if( img[0] != 0 ){\
  7415.     xmarge = 0.5*img[8];ymarge = 0.5*img[9];\
  7416.     if( xm > img[6] - xmarge && xm < img[6] + img[8]){\
  7417.      if( ym > img[7] - ymarge && ym < img[7] + img[9]){\
  7418.       if( img[0] == 1){\
  7419.        if( reply[img[10]] == 1 ){\
  7420.         reply[img[10]] = 0;external_ctx.strokeStyle = '#ffffff';\
  7421.        }\
  7422.        else\
  7423.        {\
  7424.         reply[img[10]] = 1;external_ctx.strokeStyle = '#00ff00';\
  7425.        };\
  7426.        external_ctx.lineWidth = 4;\
  7427.        external_ctx.beginPath();\
  7428.        external_ctx.rect(img[6],img[7],img[8],img[9]);\
  7429.        external_ctx.closePath();\
  7430.        external_ctx.stroke();\
  7431.        return;\
  7432.       }\
  7433.       else\
  7434.       {\
  7435.        img[6] = xm;\
  7436.        img[7] = ym;\
  7437.        ext_drag_images[p] = img;\
  7438.        selected_image = p;\
  7439.        dragxy(evt);\
  7440.       };\
  7441.      };\
  7442.     };\
  7443.    };\
  7444.   };\
  7445.  };\
  7446. }\
  7447. else\
  7448. {\
  7449.  selected_image = null;\
  7450. };\
  7451. };");
  7452.     break;
  7453.     case DRAW_BEZIER:
  7454. fprintf(js_include_file,"\n/* draw bezier curve */\n\
  7455. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7456. 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){\
  7457. var obj;\
  7458. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  7459.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  7460. }\
  7461. else\
  7462. {\
  7463.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  7464. };\
  7465. var ctx = obj.getContext(\"2d\");\
  7466. ctx.save();\
  7467. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7468. ctx.lineWidth = linewidth;\
  7469. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7470. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  7471. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  7472. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7473. ctx.beginPath();\
  7474. ctx.moveTo(x2px(xy_points[0]),y2px(xy_points[1]));\
  7475. 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]));\
  7476. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7477. 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;};\
  7478. ctx.stroke();\
  7479. ctx.restore();\
  7480. };\n",canvas_root_id,canvas_root_id,canvas_root_id);
  7481.     break;
  7482.  
  7483.     case DRAW_GRIDFILL:/* not used for userdraw */
  7484. fprintf(js_include_file,"\n/* draw gridfill */\n\
  7485. var grid_fill_pattern;\
  7486. var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize,use_userdraw){\
  7487. if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
  7488. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7489. var fc = %d+canvas_type;\
  7490. fill_canvas_no.push(fc);\
  7491. var obj = create_canvas%d(fc,xsize,ysize);\
  7492. var ctx = obj.getContext('2d');\
  7493. var x,y;\
  7494. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7495. ctx.rect(0,0,xsize,ysize);\
  7496. ctx.fill();\
  7497. ctx.lineWidth = linewidth;\
  7498. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7499. ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
  7500. for( x = 0 ; x < xsize ; x = x + dx ){\
  7501.  ctx.beginPath();\
  7502.  ctx.moveTo(x,0);\
  7503.  ctx.lineTo(x,ysize);\
  7504.  ctx.closePath();\
  7505.  ctx.stroke();\
  7506. };\
  7507. for( y = 0 ; y < ysize; y = y + dy ){\
  7508.  ctx.beginPath();\
  7509.  ctx.moveTo(0,y);\
  7510.  ctx.lineTo(xsize,y);\
  7511.  ctx.closePath();\
  7512.  ctx.stroke();\
  7513. };\
  7514. if( use_userdraw ){\
  7515.  grid_fill_pattern = ctx;\
  7516. }\
  7517. else\
  7518. {\
  7519.  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};return;\
  7520. };",canvas_root_id,canvas_root_id);
  7521.     break;
  7522.  
  7523.     case DRAW_IMAGEFILL:/* not  used for userdraw */
  7524. fprintf(js_include_file,"\n/* draw imagefill */\n\
  7525. var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize,use_userdraw,use_scaling){\
  7526. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7527. var fc = %d+canvas_type;\
  7528. fill_canvas_no.push(fc);\
  7529. var obj = create_canvas%d(fc,xsize,ysize);\
  7530. var ctx = obj.getContext('2d');\
  7531. var img = new Image();\
  7532. img.src = URL;\
  7533. obj.style.visibility = 'hidden';\
  7534. img.onload = function(){\
  7535.  if( use_scaling == 1 ){\
  7536.   ctx.drawImage(img,x0,y0,xsize,ysize);\
  7537.  }else{\
  7538.   var w0 = img.width;var h0 = img.height;var w;var h;\
  7539.   for( w = x0; w < xsize ; w = w + w0 ){\
  7540.    for( h = y0; h < ysize; h = h + h0){\
  7541.      ctx.drawImage(img,w,h,w0,h0);\
  7542.    };\
  7543.   };\
  7544.  };\
  7545.  if( use_userdraw ){\
  7546.   image_pattern = ctx;\
  7547.  }\
  7548.  else\
  7549.  {\
  7550.   setTimeout(function(){ filltoborder( x0,y0,'red','red',canvas_type,true,ctx); },500);\
  7551.  };\
  7552. };\
  7553. };",canvas_root_id,canvas_root_id);
  7554.     break;
  7555.  
  7556.     case DRAW_DOTFILL:/* not  used for userdraw */
  7557. fprintf(js_include_file,"\n/* draw dotfill */\n\
  7558. var dot_fill_pattern;\
  7559. var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize,use_userdraw){\n\
  7560. if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
  7561. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7562. var fc = %d+canvas_type;\
  7563. fill_canvas_no.push(fc);\
  7564. var obj = create_canvas%d(fc,xsize,ysize);\
  7565. var ctx = obj.getContext('2d');\
  7566. var x,y;\
  7567. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7568. ctx.rect(0,0,xsize,ysize);\
  7569. ctx.fill();\
  7570. ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\
  7571. ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
  7572. for( x = 0 ; x < xsize ; x = x + dx ){\
  7573.  for( y = 0 ; y < ysize ; y = y + dy ){\
  7574.   ctx.beginPath();\
  7575.   ctx.arc(x,y,radius,0,2*Math.PI,false);\
  7576.   ctx.closePath();\
  7577.   ctx.fill();\
  7578.  };\
  7579. };\
  7580. if( use_userdraw ){\
  7581.  dot_fill_pattern = ctx;\
  7582. }\
  7583. else\
  7584. {\
  7585. setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);\
  7586. };\
  7587. return;\
  7588. };",canvas_root_id,canvas_root_id);
  7589.     break;
  7590.  
  7591.     case DRAW_TEXTFILL:/* not  used for userdraw */
  7592. fprintf(js_include_file,"\n/* draw textfill */\n\
  7593. var text_fill_pattern;\
  7594. var draw_textfill = function(canvas_type,x0,y0,color,fontfamily,xsize,ysize,txt,use_userdraw){\n\
  7595. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7596. var fc = %d+canvas_type;\
  7597. fill_canvas_no.push(fc);\
  7598. var obj = create_canvas%d(fc,xsize,ysize);\
  7599. var ctx = obj.getContext('2d');\
  7600. ctx.font = fontfamily;\
  7601. var dx = (ctx.measureText(txt)).width;\
  7602. var dy = parseInt(fontfamily)+2;\
  7603. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7604. ctx.rect(0,0,xsize,ysize);\
  7605. ctx.fill();\
  7606. ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\
  7607. for(var x = 0 ; x < xsize ; x = x + dx ){\
  7608.  for(var y = 0 ; y < ysize ; y = y + dy ){\
  7609.   ctx.fillText(txt,x,y);\
  7610.  };\
  7611. };\
  7612. if( use_userdraw ){\
  7613.  text_fill_pattern = ctx;\
  7614. }\
  7615. else\
  7616. {\
  7617. setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
  7618. return;};",canvas_root_id,canvas_root_id);
  7619.     break;
  7620.  
  7621.     case DRAW_DIAMONDFILL:/* not used for userdraw */
  7622. fprintf(js_include_file,"\n/* draw hatch fill */\n\
  7623. var diamond_fill_pattern;\
  7624. var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\
  7625. if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
  7626. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7627. var fc = %d+canvas_type;\
  7628. fill_canvas_no.push(fc);\
  7629. var obj = create_canvas%d(fc,xsize,ysize);\
  7630. var ctx = obj.getContext('2d');\
  7631. var x;\
  7632. var y;\
  7633. ctx.lineWidth = linewidth;\
  7634. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7635. ctx.rect(0,0,xsize,ysize);\
  7636. ctx.fill();\
  7637. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7638. ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
  7639. y = ysize;\
  7640. ctx.beginPath();\
  7641. for( x = 0 ; x < xsize ; x = x + dx ){\
  7642.  ctx.moveTo(x,0);\
  7643.  ctx.lineTo(xsize,y);\
  7644.  y = y - dy;\
  7645. };\
  7646. y=0;\
  7647. for( x = xsize ; x > 0 ; x = x - dx){\
  7648.  ctx.moveTo(x,ysize);\
  7649.  ctx.lineTo(0,y);\
  7650.  y = y + dy;\
  7651. };\
  7652. y = 0;\
  7653. for( x = 0 ; x < xsize ; x = x + dx ){\
  7654.  ctx.moveTo(x,0);\
  7655.  ctx.lineTo(0,y);\
  7656.  y = y + dy;\
  7657. };\
  7658. y = 0;\
  7659. for( x = 0 ; x < xsize ; x = x + dx ){\
  7660.  ctx.moveTo(xsize,y);\
  7661.  ctx.lineTo(x,ysize);\
  7662.  y = y + dy;\
  7663. };\
  7664. ctx.closePath();\
  7665. ctx.stroke();\
  7666. if( use_userdraw ){\
  7667.  diamond_fill_pattern = ctx;\
  7668. }\
  7669. else\
  7670. {\
  7671.  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
  7672. return;\
  7673. }",canvas_root_id,canvas_root_id);
  7674.     break;
  7675.  
  7676.     case DRAW_HATCHFILL:/* not used for userdraw */
  7677. fprintf(js_include_file,"\n/* draw hatch fill */\n\
  7678. var hatch_fill_pattern;\
  7679. var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\
  7680. if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
  7681. if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
  7682. var fc = %d+canvas_type;\
  7683. fill_canvas_no.push(fc);\
  7684. var obj = create_canvas%d(fc,xsize,ysize);\
  7685. var ctx = obj.getContext('2d');\
  7686. var x,y;\
  7687. ctx.fillStyle='rgba(255,255,255,0.01)';\
  7688. ctx.rect(0,0,xsize,ysize);\
  7689. ctx.fill();\
  7690. ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
  7691. ctx.lineWidth = linewidth;\
  7692. if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7693. y = ysize;\
  7694. ctx.beginPath();\
  7695. for( x = 0 ; x < xsize ; x = x + dx ){\
  7696.  ctx.moveTo(x,0);\
  7697.  ctx.lineTo(xsize,y);\
  7698.  y = y - dy;\
  7699. };\
  7700. y = 0;\
  7701. for( x = xsize ; x >= dx ; x = x - dx){\
  7702.  ctx.moveTo(x,ysize);\
  7703.  ctx.lineTo(0,y);\
  7704.  y = y + dy;\
  7705. };\
  7706. ctx.closePath();\
  7707. ctx.stroke();\
  7708. if( use_userdraw ){\
  7709.  hatch_fill_pattern = ctx;\
  7710. }\
  7711. else\
  7712. {\
  7713.  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
  7714. return;\
  7715. };",canvas_root_id,canvas_root_id);
  7716.     break;
  7717.     case DRAW_CIRCLES:/*  used for userdraw */
  7718. fprintf(js_include_file,"\n/* draw circles */\n\
  7719. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7720. 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){\
  7721. ctx.save();\
  7722. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7723. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7724. ctx.lineWidth = line_width;\
  7725. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7726. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7727. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7728. 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;};\
  7729. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7730. for(var p = 0 ; p < x_points.length ; p++ ){\
  7731.  ctx.beginPath();\
  7732.  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
  7733.  ctx.closePath();\
  7734.  if(use_filled != 0 ){ctx.fill();};\
  7735.  ctx.stroke();\
  7736. }\
  7737. ctx.restore();\
  7738. return;\
  7739. };");
  7740.     break;
  7741.     case DRAW_POLYLINE:/* user for userdraw: draw lines through points */
  7742. fprintf(js_include_file,"\n/* draw polyline */\n\
  7743. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7744. 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){\
  7745. ctx.save();\
  7746. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7747. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7748. ctx.lineWidth = line_width;\
  7749. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7750. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7751. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7752. ctx.clearRect(0,0,xsize,ysize);\
  7753. ctx.beginPath();\
  7754. for(var p = 0 ; p < x_points.length-1 ; p++ ){\
  7755.  ctx.moveTo(x_points[p],y_points[p]);\
  7756.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  7757. }\
  7758. ctx.closePath();\
  7759. ctx.stroke();\
  7760. for(var p = 0 ; p < x_points.length ; p++ ){\
  7761.  ctx.beginPath();\
  7762.  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
  7763.  ctx.closePath();ctx.fill();ctx.stroke();\
  7764. };\
  7765. ctx.restore();\
  7766. return;\
  7767. };");
  7768.     break;
  7769.  
  7770.     case DRAW_SEGMENTS:/*  used for userdraw */
  7771. fprintf(js_include_file,"\n/* draw segments */\n\
  7772. 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){\
  7773. ctx.save();\
  7774. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7775. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7776. ctx.lineWidth = line_width;\
  7777. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7778. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7779. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7780. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  7781.  ctx.beginPath();\
  7782.  ctx.moveTo(x_points[p],y_points[p]);\
  7783.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  7784.  ctx.closePath();\
  7785.  ctx.stroke();\
  7786.  }\
  7787.  ctx.restore();\
  7788.  return;\
  7789. };");
  7790.     break;
  7791.  
  7792.     case DRAW_LINES:/*  used for userdraw */
  7793. fprintf(js_include_file,"\n/* draw lines */\n\
  7794. function calc_line(x1,x2,y1,y2){\
  7795. var marge = 2;\
  7796. if(x1 < x2+marge && x1>x2-marge){\
  7797.  return [x1,0,x1,ysize];\
  7798. };\
  7799. if(y1 < y2+marge && y1>y2-marge){\
  7800.  return [0,y1,xsize,y1];\
  7801. };\
  7802. var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
  7803. var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
  7804. return [0,Y1,xsize,Y2];\
  7805. };\
  7806. 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){\
  7807. ctx.save();\
  7808. var line = new Array(4);\
  7809. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7810. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7811. ctx.lineWidth = line_width;\
  7812. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7813. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7814. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7815. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  7816.  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
  7817.  ctx.beginPath();\
  7818.  ctx.moveTo(line[0],line[1]);\
  7819.  ctx.lineTo(line[2],line[3]);\
  7820.  ctx.closePath();\
  7821.  ctx.stroke();\
  7822.  }\
  7823.  ctx.restore();\
  7824.  return;\
  7825. };");
  7826.     break;
  7827.  
  7828.     case DRAW_DEMILINES:/*  used for userdraw */
  7829. fprintf(js_include_file,"\n/* draw demilines */\n\
  7830. function find_inf_point(x1,y1,x2,y2){\
  7831. if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\
  7832. var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\
  7833. if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\
  7834. };\
  7835. 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){\
  7836. ctx.save();\
  7837. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7838. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7839. ctx.lineWidth = line_width;\
  7840. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7841. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7842. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7843. var pair = new Array(4);\
  7844. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  7845.  pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\
  7846.  ctx.beginPath();\
  7847.  ctx.moveTo(pair[0],pair[1]);\
  7848.  ctx.lineTo(pair[2],pair[3]);\
  7849.  ctx.closePath();\
  7850.  ctx.stroke();\
  7851.  }\
  7852.  ctx.restore();\
  7853.  return;\
  7854. };");
  7855.     break;
  7856.  
  7857.     case DRAW_CROSSHAIRS:/*  used for userdraw */
  7858. fprintf(js_include_file,"\n/* draw crosshairs  */\n\
  7859. var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\
  7860. ctx.save();\
  7861. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7862. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7863. ctx.lineWidth = line_width;\
  7864. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7865. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7866. var x1,x2,y1,y2;\
  7867. for(var p = 0 ; p < x_points.length ; p++ ){\
  7868.  x1 = x_points[p] - crosshair_size;\
  7869.  x2 = x_points[p] + crosshair_size;\
  7870.  y1 = y_points[p] - crosshair_size;\
  7871.  y2 = y_points[p] + crosshair_size;\
  7872.  ctx.beginPath();\
  7873.  ctx.moveTo(x1,y1);\
  7874.  ctx.lineTo(x2,y2);\
  7875.  ctx.closePath();\
  7876.  ctx.stroke();\
  7877.  ctx.beginPath();\
  7878.  ctx.moveTo(x2,y1);\
  7879.  ctx.lineTo(x1,y2);\
  7880.  ctx.closePath();\
  7881.  ctx.stroke();\
  7882. }\
  7883. ctx.restore();\
  7884.  return;\
  7885. };");
  7886.     break;
  7887.  
  7888.     case DRAW_RECTS:/*  used for userdraw */
  7889. fprintf(js_include_file,"\n/* draw rects */\n\
  7890. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7891. 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){\
  7892. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7893. ctx.save();\
  7894. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7895. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7896. ctx.lineWidth = line_width;\
  7897. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7898. ctx.strokeStyle = 'rgba('+stroke_color+','+stroke_opacity+')';\
  7899. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
  7900. 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;};\
  7901. for(var p = 0 ; p < x_points.length ; p = p + 2){\
  7902.  ctx.beginPath();\
  7903.  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
  7904.  ctx.closePath();\
  7905.  if(use_filled != 0 ){ctx.fill();}\
  7906.  ctx.stroke();\
  7907. };\
  7908. ctx.restore();\
  7909. return;\
  7910. };");
  7911.     break;
  7912.  
  7913.     case DRAW_ROUNDRECTS:/*  used for userdraw */
  7914. fprintf(js_include_file,"\n/* draw round rects */\n\
  7915. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7916. 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){\
  7917. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7918. ctx.save();\
  7919. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7920. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7921. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7922. ctx.lineWidth = line_width;\
  7923. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7924. 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;};\
  7925. var x,y,w,h,r;\
  7926. for(var p = 0; p < x_points.length; p = p+2){\
  7927.  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);\
  7928.  ctx.beginPath();ctx.moveTo(x + r, y);\
  7929.  ctx.lineTo(x + w - r, y);\
  7930.  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
  7931.  ctx.lineTo(x + w, y + h - r);\
  7932.  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
  7933.  ctx.lineTo(x + r, y + h);\
  7934.  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
  7935.  ctx.lineTo(x, y + r);\
  7936.  ctx.quadraticCurveTo(x, y, x + r, y);\
  7937.  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
  7938.  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7939.  if( use_filled != 0 ){ctx.fill();};\
  7940.  ctx.stroke();\
  7941. }\
  7942. ctx.restore();\
  7943. };");
  7944.     break;
  7945.  
  7946.     case DRAW_ELLIPSES:/* not  used for userdraw */
  7947. fprintf(js_include_file,"\n/* draw ellipses */\n\
  7948. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7949. 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){\
  7950. var obj;\
  7951. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  7952.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  7953. }\
  7954. else\
  7955. {\
  7956.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  7957. };\
  7958. var ctx = obj.getContext(\"2d\");\
  7959. ctx.save();\
  7960. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7961. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7962. 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;};\
  7963. var cx,cy,ry,rx;\
  7964. ctx.lineWidth = line_width;\
  7965. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7966. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7967. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7968. for(var p=0;p< x_points.length;p = p+2){\
  7969.  ctx.beginPath();\
  7970.  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
  7971.  ctx.translate(cx - rx, cy - ry);\
  7972.  ctx.scale(rx, ry);\
  7973.  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
  7974.  if( use_filled != 0 ){ctx.fill();}\
  7975.  ctx.stroke();\
  7976. };\
  7977. ctx.restore();\
  7978. };",canvas_root_id,canvas_root_id,canvas_root_id);
  7979.     break;
  7980.  
  7981.     case DRAW_PATHS: /*  used for userdraw */
  7982. fprintf(js_include_file,"\n/* draw paths */\n\
  7983. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  7984. 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){\
  7985. ctx.save();\
  7986. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  7987. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  7988. ctx.lineWidth = line_width;\
  7989. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  7990. ctx.lineJoin = \"round\";\
  7991. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  7992. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  7993. 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;};\
  7994. ctx.beginPath();\
  7995. ctx.moveTo(x_points[0],y_points[0]);\
  7996. for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
  7997. if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
  7998. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  7999. if(use_filled != 0){ctx.fill();}\
  8000. ctx.stroke();\
  8001. ctx.restore();\
  8002. return;\
  8003. };");
  8004.  
  8005.     break;
  8006.     case DRAW_ARROWS:/*  used for userdraw */
  8007. fprintf(js_include_file,"\n/* draw arrows */\n\
  8008. 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){\
  8009. ctx.save();\
  8010. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  8011. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  8012. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8013. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8014. ctx.lineWidth = line_width;\
  8015. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  8016. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  8017. ctx.lineCap = \"round\";\
  8018. var x1,y1,x2,y2,dx,dy,len;\
  8019. for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
  8020.   ctx.save();\
  8021.   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
  8022.   len = Math.sqrt(dx*dx+dy*dy);\
  8023.   ctx.translate(x2,y2);\
  8024.   ctx.rotate(Math.atan2(dy,dx));\
  8025.   ctx.lineCap = \"round\";\
  8026.   ctx.beginPath();\
  8027.   ctx.moveTo(0,0);\
  8028.   ctx.lineTo(-len,0);\
  8029.   ctx.closePath();\
  8030.   ctx.stroke();\
  8031.   ctx.beginPath();\
  8032.   ctx.moveTo(0,0);\
  8033.   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  8034.   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  8035.   ctx.closePath();\
  8036.   ctx.fill();\
  8037.   ctx.restore();\
  8038.   if( type == 2 ){\
  8039.     ctx.save();\
  8040.     ctx.translate(x1,y1);\
  8041.     ctx.rotate(Math.atan2(-dy,-dx));\
  8042.     ctx.beginPath();\
  8043.     ctx.moveTo(0,0);\
  8044.     ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\
  8045.     ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\
  8046.     ctx.closePath();\
  8047.     ctx.stroke();\
  8048.     ctx.fill();\
  8049.     ctx.restore();\
  8050.   };\
  8051.  };\
  8052.  ctx.restore();\
  8053.  return;\
  8054. };");
  8055.     break;
  8056.  
  8057.     case DRAW_VIDEO:/* not  used for userdraw */
  8058. fprintf(js_include_file,"\n/* draw video */\n\
  8059. var draw_video = function(canvas_root_id,x,y,w,h,URL){\
  8060. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  8061. var video_div = document.createElement(\"div\");\
  8062. canvas_div.appendChild(video_div);\
  8063. video_div.style.position = \"absolute\";\
  8064. video_div.style.left = x+\"px\";\
  8065. video_div.style.top = y+\"px\";\
  8066. video_div.style.width = w+\"px\";\
  8067. video_div.style.height = h+\"px\";\
  8068. var video = document.createElement(\"video\");\
  8069. video_div.appendChild(video);\
  8070. video.style.width = w+\"px\";\
  8071. video.style.height = h+\"px\";\
  8072. video.autobuffer = true;\
  8073. video.controls = true;video.autoplay = false;\
  8074. var src = document.createElement(\"source\");\
  8075. src.type = \"video/mp4\";\
  8076. src.src = URL;\
  8077. video.appendChild(src);\
  8078. video.load();\
  8079. return;\
  8080. };");
  8081.     break;
  8082.  
  8083.     case DRAW_AUDIO:/* not used for userdraw */
  8084. fprintf(js_include_file,"\n/* draw audio */\n\
  8085. var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
  8086. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  8087. var audio_div = document.createElement(\"div\");\
  8088. canvas_div.appendChild(audio_div);\
  8089. audio_div.style.position = \"absolute\";\
  8090. audio_div.style.left = x+\"px\";\
  8091. audio_div.style.top = y+\"px\";\
  8092. audio_div.style.width = w+\"px\";\
  8093. audio_div.style.height = h+\"px\";\
  8094. var audio = document.createElement(\"audio\");\
  8095. audio_div.appendChild(audio);\
  8096. audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
  8097. audio.autobuffer = true;\
  8098. if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;};\
  8099. if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;};\
  8100. var src1 = document.createElement(\"source\");\
  8101. src1.type = \"audio/ogg\";\
  8102. src1.src = URL1;\
  8103. audio.appendChild(src1);\
  8104. var src2 = document.createElement(\"source\");\
  8105. src2.type = \"audio/mpeg\";\
  8106. src2.src = URL2;\
  8107. audio.appendChild(src2);\
  8108. audio.load();\
  8109. return;\
  8110. };");
  8111.     break;
  8112.  
  8113.     case DRAW_HTTP:/* not  used for userdraw */
  8114. fprintf(js_include_file,"\n/* draw http */\n\
  8115. var draw_http = function(canvas_root_id,x,y,w,h,URL){\
  8116. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  8117. var http_div = document.createElement(\"div\");\
  8118. var iframe = document.createElement(\"iframe\");\
  8119. canvas_div.appendChild(http_div);\
  8120. http_div.appendChild(iframe);\
  8121. iframe.src = URL;\
  8122. iframe.setAttribute(\"width\",w);\
  8123. iframe.setAttribute(\"height\",h);\
  8124. return;\
  8125. };");
  8126.     break;
  8127.  
  8128.     case DRAW_XML: /*
  8129.     onclick=1: click
  8130.     onclick=2 drag ==> always centered (use_offset=4)
  8131.     xy:drag_type = 0;
  8132.     x:    drag_type = 1;
  8133.     y:    drag_type = 2;
  8134.     */
  8135.  
  8136. fprintf(js_include_file,"\n/* draw xml */\n\
  8137. 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,angle){\
  8138. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  8139. var xml_div = document.createElement(\"div\");\
  8140. canvas_div.appendChild(xml_div);\
  8141. xml_div.innerHTML = mathml;\
  8142. xml_div.style.position = \"absolute\"; xml_div.style.left = x+\"px\";xml_div.style.top = y+\"px\";\
  8143. xml_div.style.transform = 'rotate('+angle+'deg)';\
  8144. var factor = 1;\
  8145. if( centered > 0 ){ factor = 0.5;};\
  8146. var xml_div_width = factor*(parseInt(window.getComputedStyle(xml_div).width , 10));\
  8147. var xml_div_height = factor*(parseInt(window.getComputedStyle(xml_div).height ,10));\
  8148. xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8149. var color_org = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8150. var back_color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  8151. var no_color = \"rgba(255,255,255,0)\";\
  8152. var dragging = false;\
  8153. if( onclick == 2 ){reply[click_cnt] = px2x(x)+','+px2y(y);};\
  8154. if( onclick == 1 ){reply[click_cnt] = 0;};\
  8155. if( onclick == 2 ){\
  8156.  xml_div.onclick = function(){\
  8157.   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;};};\
  8158.   canvas_div.onmousemove = function(evt){\
  8159.    if(!dragging){return;};\
  8160.    var x1;var y1;\
  8161.    var mouse = dragstuff.getMouse(evt,xml_div);\
  8162.    var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
  8163.    switch(drag_type){\
  8164.     case 0: x1 = xy[0]-xml_div_width;y1=xy[1]-xml_div_height;break;\
  8165.     case 1: x1 = xy[0]-xml_div_width;y1 = y;break;\
  8166.     case 2: x1 = x;y1 = xy[1]-xml_div_height;break;\
  8167.     default:x1 = xy[0];y1 = xy[1]; break;\
  8168.    };\
  8169.    xml_div.style.left = x1 + 'px';xml_div.style.top = y1 + 'px';\
  8170.    reply[click_cnt] = px2x(xy[0])+','+px2y(xy[1]);\
  8171.   };\
  8172.  };\
  8173. };\
  8174. if(onclick == 1){\
  8175.  xml_div.onclick = function(){\
  8176.  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;};};\
  8177. };\
  8178. return;\
  8179. };");
  8180.     break;
  8181.     case DRAW_SGRAPH:
  8182. /*
  8183.  xstart = given
  8184.  ystart = given
  8185.  sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
  8186. */
  8187. fprintf(js_include_file,"\n/* draw sgraph */\n\
  8188. var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
  8189. 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);};\
  8190. var ctx = obj.getContext(\"2d\");\
  8191. ctx.font = fontfamily;\
  8192. var minor_opacity = 0.8*opacity;\
  8193. ctx.clearRect(0,0,xsize,ysize);\
  8194. var zero_x = 0.1*xsize;\
  8195. var zero_y = 0.9*ysize;\
  8196. var snor_x;var snor_y;\
  8197. if( xstart != xmin){\
  8198.  snor_x = 0.1*xsize;\
  8199. }\
  8200. else\
  8201. {\
  8202.  snor_x = 0;\
  8203.  xstart = xmin;\
  8204. };\
  8205. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  8206. ctx.lineWidth = 2;\
  8207. ctx.beginPath();\
  8208. ctx.moveTo(xsize,zero_y);\
  8209. ctx.lineTo(zero_x,zero_y);\
  8210. ctx.lineTo(zero_x,0);\
  8211. ctx.stroke();\
  8212. ctx.closePath();\
  8213. ctx.beginPath();\
  8214. ctx.moveTo(zero_x,zero_y);\
  8215. ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
  8216. ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
  8217. ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
  8218. ctx.lineTo(zero_x + snor_x,zero_y);\
  8219. ctx.stroke();\
  8220. ctx.closePath();\
  8221. ctx.beginPath();\
  8222. var num = xstart;\
  8223. var flipflop = 1;\
  8224. var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
  8225. var txtsize;var txt_marge=step_x - 5;\
  8226. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  8227.  txtsize = ctx.measureText(num).width;\
  8228.  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
  8229.  if( flipflop == 1){\
  8230.   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
  8231.  }\
  8232.  else\
  8233.  {\
  8234.   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
  8235.  };\
  8236.  num = num + xmajor;\
  8237. };\
  8238. ctx.stroke();\
  8239. ctx.closePath();\
  8240. ctx.lineWidth = 1;\
  8241. ctx.beginPath();\
  8242. for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  8243.   ctx.moveTo(x,zero_y);\
  8244.   ctx.lineTo(x,0);\
  8245. };\
  8246. ctx.stroke();\
  8247. ctx.closePath();\
  8248. if( xminor > 1){\
  8249.  ctx.lineWidth = 0.5;\
  8250.  ctx.beginPath();\
  8251.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  8252.  var minor_step_x = step_x / xminor;\
  8253.  var nx;\
  8254.  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
  8255.    num = 1;\
  8256.    for(var p = 1 ; p < xminor ; p++){\
  8257.     nx = x + num*minor_step_x;\
  8258.     ctx.moveTo(nx,zero_y);\
  8259.     ctx.lineTo(nx,0);\
  8260.     num++;\
  8261.    };\
  8262.  };\
  8263.  ctx.stroke();\
  8264.  ctx.closePath();\
  8265.  ctx.beginPath();\
  8266.  ctx.lineWidth = 2;\
  8267.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  8268.  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
  8269.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
  8270.  };\
  8271.  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
  8272.   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
  8273.  };\
  8274.  ctx.stroke();\
  8275.  ctx.closePath();\
  8276.  ctx.lineWidth = 0.5;\
  8277. };\
  8278. xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
  8279. if( ystart != ymin){\
  8280.  snor_y = 0.1*ysize;\
  8281. }\
  8282. else\
  8283. {\
  8284.  snor_y = 0;\
  8285.  ystart = ymin;\
  8286. };\
  8287. ctx.lineWidth = 2;\
  8288. ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  8289. ctx.beginPath();\
  8290. ctx.moveTo(zero_x,zero_y);\
  8291. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
  8292. ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
  8293. ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
  8294. ctx.lineTo(zero_x,zero_y - snor_y);\
  8295. ctx.stroke();\
  8296. ctx.closePath();\
  8297. ctx.beginPath();\
  8298. ctx.lineWidth = 1;\
  8299. num = ystart;\
  8300. var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
  8301. for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
  8302.  ctx.moveTo(zero_x,y);\
  8303.  ctx.lineTo(xsize,y);\
  8304.  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
  8305.  num = num + ymajor;\
  8306. };\
  8307. ctx.stroke();\
  8308. ctx.closePath();\
  8309. if( yminor > 1){\
  8310.  ctx.lineWidth = 0.5;\
  8311.  ctx.beginPath();\
  8312.  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
  8313.  var minor_step_y = step_y / yminor;\
  8314.  var ny;\
  8315.  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
  8316.   num = 1;\
  8317.   for(var p = 1 ;p < yminor;p++){\
  8318.     ny = y + num*minor_step_y;\
  8319.     ctx.moveTo(zero_x,ny);\
  8320.     ctx.lineTo(xsize,ny);\
  8321.     num++;\
  8322.    };\
  8323.  };\
  8324.  ctx.stroke();\
  8325.  ctx.closePath();\
  8326.  ctx.lineWidth = 2;\
  8327.  ctx.beginPath();\
  8328.  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
  8329.  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
  8330.   ctx.moveTo(zero_x,y);\
  8331.   ctx.lineTo(zero_x+12,y);\
  8332.  };\
  8333.  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
  8334.   ctx.moveTo(zero_x,y);\
  8335.   ctx.lineTo(zero_x+6,y);\
  8336.  };\
  8337.  ctx.stroke();\
  8338.  ctx.closePath();\
  8339. };\
  8340. ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
  8341. if( typeof(legend%d)  !== 'undefined' ){\
  8342.  ctx.globalAlpha = 1.0;\
  8343.  var y_offset = 2*font_size;\
  8344.  var txt;var txt_size;\
  8345.  var x_offset = xsize - 2*font_size;\
  8346.  var l_length = legend%d.length;var barcolor = new Array();\
  8347.  if( typeof(legendcolors%d) !== 'undefined' ){\
  8348.   for(var p = 0 ; p < l_length ; p++){\
  8349.    barcolor[p] = legendcolors%d[p];\
  8350.   };\
  8351.  }else{\
  8352.   if( barcolor.length == 0 ){\
  8353.    for(var p = 0 ; p < l_length ; p++){\
  8354.     barcolor[p] = stroke_color;\
  8355.    };\
  8356.   };\
  8357.  };\
  8358.  for(var p = 0; p < l_length; p++){\
  8359.   ctx.fillStyle = barcolor[p];\
  8360.   txt = legend%d[p];\
  8361.   txt_size = ctx.measureText(txt).width;\
  8362.   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
  8363.   y_offset = parseInt(y_offset + 1.5*font_size);\
  8364.  };\
  8365. };\
  8366. if( typeof(xaxislabel) !== 'undefined' ){\
  8367.   ctx.fillStyle = \'#000000\';\
  8368.   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
  8369.   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
  8370. };\
  8371. if( typeof(yaxislabel) !== 'undefined'){\
  8372.   ctx.save();\
  8373.   ctx.fillStyle = \'#000000\';\
  8374.   var txt_size = ctx.measureText(yaxislabel).width;\
  8375.   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
  8376.   ctx.rotate(-0.5*Math.PI);\
  8377.   ctx.fillText(yaxislabel,0,0);\
  8378.   ctx.restore();\
  8379. };\
  8380. };\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);
  8381.     break;
  8382.     case DRAW_NUMBERLINE:
  8383. fprintf(js_include_file,"\n/* draw numberline */\n\
  8384. var draw_numberline = function(canvas_type,use_axis_numbering,x0,x1,xmajor,xminor,y0,y1,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor,precision){\
  8385. var obj = create_canvas%d(canvas_type,xsize,ysize);\
  8386. var ctx = obj.getContext(\"2d\");\
  8387. ctx.lineWidth = linewidth || 1;\
  8388. ctx.strokeStyle = \"rgba(\"+strokecolor+\",\"+strokeopacity+\")\";\
  8389. ctx.font = fontfamily || 'Arial 12px';\
  8390. var fontsize = parseInt(ctx.font);\
  8391. ctx.fillStyle =  \"rgba(\"+fontcolor+\",\"+strokeopacity+\")\";\
  8392. x1 = x2px(x1);\
  8393. x0 = x2px(x0);\
  8394. y0 = y2px(y0);\
  8395. y1 = y2px(y1);\
  8396. var sub_devision = -1;\
  8397. if( xminor%%2 == 0 ){ sub_devision = xminor/2; };\
  8398. var ybase1 = parseInt( y0 + fontsize + 2 );\
  8399. var ybase2 = parseInt( ybase1 + fontsize + 2 );\
  8400. var yh = Math.abs(parseInt( y0 - 0.3*(y0 -y1)));\
  8401. var ys = Math.abs(parseInt( y0 - 0.6*(y0 -y1)));\
  8402. xmajor = x2px(xmajor) - x2px(0);\
  8403. var i;var len;var p;\
  8404. xminor = xmajor / xminor;\
  8405. ctx.beginPath();\
  8406. for(p = x0 ; p < x1 ; p = p + xmajor){\
  8407.  ctx.moveTo(p,y0);ctx.lineTo(p,y1);i = 0;\
  8408.  for(var s = p ; s < p + xmajor ; s = s + xminor ){\
  8409.   ctx.moveTo(s,y0);\
  8410.   if( sub_devision == i){ ctx.lineTo(s,ys); } else { ctx.lineTo(s,yh); };\
  8411.   i++;\
  8412.  };\
  8413. };\
  8414. ctx.moveTo(p,y0);ctx.lineTo(p,y1);\
  8415. ctx.closePath();\
  8416. ctx.stroke();\
  8417. if( use_axis_numbering >-1 ){\
  8418.  var str = x_strings[use_axis_numbering];\
  8419.  len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  8420.  var corr;var x_nums;var x_text;var flipflop = 0;var off = ybase1;\
  8421.  ctx.beginPath();\
  8422.  if( x_strings_up[use_axis_numbering] == null){\
  8423.   for(var p = 0 ; p < len ; p = p+2){\
  8424.    var x_nums = x2px(eval(str[p]));\
  8425.    var x_text = str[p+1];\
  8426.    corr = ctx.measureText(x_text).width;\
  8427.    if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\
  8428.    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),off);\
  8429.   };\
  8430.  }\
  8431.  else\
  8432.  {\
  8433.   for(var p = 0 ; p < len ; p = p+2){\
  8434.    x_nums = x2px(eval(str[p]));\
  8435.    x_text = str[p+1];\
  8436.    corr = ctx.measureText(x_text).width + ybase1 - fontsize;\
  8437.    ctx.save();\
  8438.    ctx.translate(x_nums+0.5*fontsize, corr);\
  8439.    ctx.rotate(-1.5708);\
  8440.    ctx.fillText(x_text,0,0);\
  8441.    ctx.restore();\
  8442.   };\
  8443.  }\
  8444. }\
  8445. else\
  8446. {\
  8447.  var corr;var num;var flipflop = 0;var off = ybase1;\
  8448.  var prec = parseInt(Math.log(precision)/Math.log(10));\
  8449.  for(var p = x0 ; p < x1+xmajor ; p = p+xmajor){\
  8450.   num = (px2x(p)).toFixed(prec);\
  8451.   corr = ctx.measureText(num).width;\
  8452.   if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\
  8453.   ctx.fillText(num,parseInt(p - 0.5*corr),off);\
  8454.  };\
  8455. };\
  8456. };",canvas_root_id);
  8457.     break;
  8458.     case DRAW_GRID:/* not used for userdraw */
  8459. fprintf(js_include_file,"\n/* draw grid */\n\
  8460. 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){\
  8461. 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);};\
  8462. var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
  8463. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  8464. ctx.save();\
  8465. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  8466. if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
  8467. var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8468. ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
  8469. var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
  8470. ctx.font = font_family;\
  8471. var barcolor = new Array();\
  8472. var xstep = xsize*xmajor/(xmax - xmin);\
  8473. var ystep = ysize*ymajor/(ymax - ymin);\
  8474. var x2step = xstep / xminor;\
  8475. var y2step = ystep / yminor;\
  8476. var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
  8477. if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
  8478. if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
  8479. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  8480. ctx.beginPath();\
  8481. ctx.lineWidth = line_width;\
  8482. ctx.strokeStyle = stroke_color;\
  8483. for(var p = zero_x ; p < xsize; p = p + xstep){\
  8484. ctx.moveTo(p,0);\
  8485. ctx.lineTo(p,ysize);\
  8486. };\
  8487. for(var p = zero_x ; p > 0; p = p - xstep){\
  8488. ctx.moveTo(p,0);\
  8489. ctx.lineTo(p,ysize);\
  8490. };\
  8491. for(var p = zero_y ; p < ysize; p = p + ystep){\
  8492. ctx.moveTo(0,p);\
  8493. ctx.lineTo(xsize,p);\
  8494. };\
  8495. for(var p = zero_y ; p > 0; p = p - ystep){\
  8496. ctx.moveTo(0,p);\
  8497. ctx.lineTo(xsize,p);\
  8498. };\
  8499. if( typeof(xaxislabel) !== 'undefined' ){\
  8500. ctx.save();\
  8501. ctx.font = \"italic \"+font_size+\"px Arial\";\
  8502. var corr =  parseInt(1.1*ctx.measureText(xaxislabel).width);\
  8503. ctx.fillText(xaxislabel,xsize - corr,zero_y - tics_length - 0.4*font_size);\
  8504. ctx.restore();\
  8505. };\
  8506. if( typeof(yaxislabel) !== 'undefined' ){\
  8507. ctx.save();\
  8508. ctx.font = \"italic \"+font_size+\"px Arial\";\
  8509. var corr = parseInt(ctx.measureText(yaxislabel).width + font_size);\
  8510. ctx.translate(zero_x+tics_length + font_size,corr);\
  8511. ctx.rotate(-0.5*Math.PI);\
  8512. ctx.fillText(yaxislabel,0,0);\
  8513. ctx.restore();\
  8514. };\
  8515. ctx.stroke();\
  8516. ctx.closePath();\
  8517. if( use_axis == 1 ){\
  8518. ctx.save();\
  8519. ctx.beginPath();\
  8520. ctx.strokeStyle = stroke_color;\
  8521. ctx.lineWidth = 0.6*line_width;\
  8522. for(var p = zero_x ; p < xsize; p = p + x2step){\
  8523.  ctx.moveTo(p,0);\
  8524.  ctx.lineTo(p,ysize);\
  8525. };\
  8526. for(var p = zero_x ; p > 0; p = p - x2step){\
  8527.  ctx.moveTo(p,0);\
  8528.  ctx.lineTo(p,ysize);\
  8529. };\
  8530. for(var p = zero_y ; p < ysize; p = p + y2step){\
  8531.  ctx.moveTo(0,p);\
  8532.  ctx.lineTo(xsize,p);\
  8533. };\
  8534. for(var p = zero_y ; p > 0; p = p - y2step){\
  8535.  ctx.moveTo(0,p);\
  8536.  ctx.lineTo(xsize,p);\
  8537. };\
  8538. ctx.stroke();\
  8539. ctx.closePath();\
  8540. ctx.beginPath();\
  8541. ctx.lineWidth = 2*line_width;\
  8542. ctx.strokeStyle = axis_color;\
  8543. ctx.moveTo(0,zero_y);\
  8544. ctx.lineTo(xsize,zero_y);\
  8545. ctx.moveTo(zero_x,0);\
  8546. ctx.lineTo(zero_x,ysize);\
  8547. ctx.stroke();\
  8548. ctx.closePath();\
  8549. ctx.lineWidth = line_width+0.5;\
  8550. ctx.beginPath();\
  8551. for(var p = zero_x ; p < xsize; p = p + xstep){\
  8552.  ctx.moveTo(p,zero_y-tics_length);\
  8553.  ctx.lineTo(p,zero_y+tics_length);\
  8554. };\
  8555. for(var p = zero_x ; p > 0; p = p - xstep){\
  8556.  ctx.moveTo(p,zero_y-tics_length);\
  8557.  ctx.lineTo(p,zero_y+tics_length);\
  8558. };\
  8559. for(var p = zero_y ; p < ysize; p = p + ystep){\
  8560.  ctx.moveTo(zero_x-tics_length,p);\
  8561.  ctx.lineTo(zero_x+tics_length,p);\
  8562. };\
  8563. for(var p = zero_y ; p > 0; p = p - ystep){\
  8564.  ctx.moveTo(zero_x-tics_length,p);\
  8565.  ctx.lineTo(zero_x+tics_length,p);\
  8566. };\
  8567. for(var p = zero_x ; p < xsize; p = p + x2step){\
  8568.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  8569.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  8570. };\
  8571. for(var p = zero_x ; p > 0; p = p - x2step){\
  8572.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  8573.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  8574. };\
  8575. for(var p = zero_y ; p < ysize; p = p + y2step){\
  8576.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  8577.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  8578. };\
  8579. for(var p = zero_y ; p > 0; p = p - y2step){\
  8580.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  8581.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  8582. };\
  8583. ctx.stroke();\
  8584. ctx.closePath();\
  8585. ctx.restore();\
  8586. };\
  8587. if( use_axis_numbering != -1 ){\
  8588. ctx.save();\
  8589. ctx.fillColor = axis_color;\
  8590. ctx.strokeStyle = axis_color;\
  8591. ctx.lineWidth = 2*line_width;\
  8592. ctx.font = font_family;\
  8593. var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
  8594. if( x_strings[use_axis_numbering] != null ){\
  8595.  var str = x_strings[use_axis_numbering];\
  8596.  var len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  8597.  ctx.beginPath();\
  8598.  if( x_strings_up[use_axis_numbering] == null){\
  8599.   for(var p = 0 ; p < len ; p = p+2){\
  8600.    var x_nums = x2px(eval(str[p]));\
  8601.    var x_text = str[p+1];\
  8602.    corr = ctx.measureText(x_text).width;\
  8603.    skip = 1.2*corr/xstep;\
  8604.    if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
  8605.    if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
  8606.    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
  8607.    ctx.moveTo(x_nums,zero_y - tics_length);\
  8608.    ctx.lineTo(x_nums,zero_y + tics_length);\
  8609.   };\
  8610.  }\
  8611.  else\
  8612.  {\
  8613.   for(var p = 0 ; p < len ; p = p+2){\
  8614.    var x_nums = x2px(eval(str[p]));\
  8615.    var x_text = str[p+1];\
  8616.    corr = 2 + tics_length + zero_y + ctx.measureText(x_text).width;\
  8617.    if( corr > ysize ){corr = ysize;};\
  8618.    ctx.save();\
  8619.    ctx.translate(x_nums+0.25*font_size, corr);\
  8620.    ctx.rotate(-1.5708);\
  8621.    ctx.fillText(x_text,0,0);\
  8622.    ctx.restore();\
  8623.    ctx.moveTo(x_nums,zero_y - tics_length);\
  8624.    ctx.lineTo(x_nums,zero_y + tics_length);\
  8625.   };\
  8626.  };\
  8627.  ctx.closePath();\
  8628. }\
  8629. else\
  8630. {\
  8631.  skip = 1;cnt = px2x(zero_x);\
  8632.  prec = Math.log(precision)/(Math.log(10));\
  8633.  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
  8634.  for( var p = zero_x ; p < xsize ; p = p+xstep){\
  8635.   if(skip == 0 ){\
  8636.    disp_cnt = cnt.toFixed(prec);\
  8637.    corr = ctx.measureText(disp_cnt).width;\
  8638.    skip = parseInt(1.2*corr/xstep);\
  8639.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  8640.   }\
  8641.   else\
  8642.   {\
  8643.    skip--;\
  8644.   };\
  8645.   cnt = cnt + xmajor;\
  8646.  };\
  8647.  cnt = px2x(zero_x);skip = 1;\
  8648.  for( var p = zero_x ; p > 0 ; p = p-xstep){\
  8649.   if(skip == 0 ){\
  8650.    disp_cnt = cnt.toFixed(prec);\
  8651.    corr = ctx.measureText(disp_cnt).width;\
  8652.    skip = parseInt(1.2*corr/xstep);\
  8653.    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
  8654.   }\
  8655.   else\
  8656.   {\
  8657.    skip--;\
  8658.   };\
  8659.   cnt = cnt - xmajor;\
  8660.  };\
  8661. };\
  8662. if( y_strings != null ){\
  8663.  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
  8664.  ctx.beginPath();\
  8665.  for(var p = 0 ; p < len ; p = p+2){\
  8666.   var y_nums = y2px(eval(y_strings[p]));\
  8667.   var y_text = y_strings[p+1];\
  8668.   corr = 2 + tics_length + ctx.measureText(y_text).width;\
  8669.   if( corr > zero_x){corr = parseInt(zero_x+2); }\
  8670.   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
  8671.   ctx.moveTo(zero_x - tics_length,y_nums);\
  8672.   ctx.lineTo(zero_x + tics_length,y_nums);\
  8673.  };\
  8674.  ctx.closePath();\
  8675. }\
  8676. else\
  8677. {\
  8678.  if(f_x == 1){ corr = 1.5*tics_length; }\
  8679.  cnt = px2y(zero_y);skip = 1;\
  8680.  for( var p = zero_y ; p < ysize ; p = p+ystep){\
  8681.   if(skip == 0 ){\
  8682.    skip = parseInt(1.4*font_size/ystep);\
  8683.    disp_cnt = cnt.toFixed(prec);\
  8684.    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  8685.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  8686.   }\
  8687.   else\
  8688.   {\
  8689.    skip--;\
  8690.   };\
  8691.   cnt = cnt - ymajor;\
  8692.  };\
  8693.  corr = 0;cnt = px2y(zero_y);skip = 1;\
  8694.  if(f_x == 1){ corr = 1.5*tics_length; }\
  8695.  for( var p = zero_y ; p > 0 ; p = p-ystep){\
  8696.   if(skip == 0 ){\
  8697.    skip = parseInt(1.4*font_size/ystep);\
  8698.    disp_cnt = cnt.toFixed(prec);\
  8699.    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
  8700.    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
  8701.   }\
  8702.   else\
  8703.   {\
  8704.    skip--;\
  8705.   };\
  8706.   cnt = cnt + ymajor;\
  8707.  };\
  8708. };\
  8709. ctx.stroke();\
  8710. ctx.restore();\
  8711. };\
  8712. if( typeof(legend0)  !== 'undefined' ){\
  8713. ctx.save();\
  8714. ctx.globalAlpha = 1.0;\
  8715. ctx.font = \"bold \"+font_size+\"px Arial\";\
  8716. var y_offset = 2*font_size;\
  8717. var txt;var txt_size;\
  8718. var x_offset = xsize - 2*font_size;\
  8719. var l_length = legend0.length;\
  8720. if( typeof(legendcolors0) !== 'undefined' ){\
  8721.  for(var p = 0 ; p < l_length ; p++){\
  8722.    barcolor[p] = legendcolors0[p];\
  8723.  };\
  8724. }\
  8725. else\
  8726. {\
  8727.  if( barcolor.length == 0 ){\
  8728.   for(var p = 0 ; p < l_length ; p++){\
  8729.    barcolor[p] = stroke_color;\
  8730.   };\
  8731.  };\
  8732. };\
  8733. for(var p = 0; p < l_length; p++){\
  8734.  ctx.fillStyle = barcolor[p];\
  8735.  txt = legend0[p];\
  8736.  txt_size = ctx.measureText(txt).width;\
  8737.  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
  8738.  y_offset = parseInt(y_offset + 1.5*font_size);\
  8739. };\
  8740. ctx.restore();\
  8741. };\
  8742. if( typeof(barchart_0)  !== 'undefined' ){\
  8743. ctx.save();\
  8744. var num_barcharts = 0;\
  8745. var bar_name = eval('barchart_0');\
  8746. while( typeof(bar_name) !== 'undefined' ){\
  8747.    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
  8748. };\
  8749. var bar_width = parseInt(0.8*x2step/(num_barcharts));\
  8750. for(var i=0 ; i< num_barcharts ; i++){\
  8751.  bar_name = eval('barchart_'+i);\
  8752.  var bar_x = new Array();\
  8753.  var bar_y = new Array();\
  8754.  var lb = bar_name.length;\
  8755.  var idx = 0;\
  8756.  var dx = parseInt(0.5*i*bar_width);\
  8757.  for( var p = 0 ; p < lb ; p = p + 3 ){\
  8758.   bar_x[idx] = x2px(bar_name[p]);\
  8759.   bar_y[idx] = y2px(bar_name[p+1]);\
  8760.   barcolor[idx] = bar_name[p+2];\
  8761.   idx++;\
  8762.  };\
  8763.  ctx.globalAlpha = fill_opacity;\
  8764.  for( var p = 0; p < idx ; p++ ){\
  8765.   ctx.beginPath();\
  8766.   ctx.strokeStyle = barcolor[p];\
  8767.   ctx.fillStyle = barcolor[p];\
  8768.   ctx.rect(bar_x[p]-0.4*x2step+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
  8769.   ctx.fill();\
  8770.   ctx.stroke();\
  8771.   ctx.closePath();\
  8772.  };\
  8773. };\
  8774. ctx.restore();\
  8775. };\
  8776. if( typeof(linegraph_0) !== 'undefined' ){\
  8777. ctx.save();\
  8778. ctx.globalAlpha = 1.0;\
  8779. var i = 0;\
  8780. var line_name = eval('linegraph_'+i);\
  8781. while ( typeof(line_name) !== 'undefined' ){\
  8782.  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
  8783.  ctx.lineWidth = parseInt(line_name[1]);\
  8784.  if(line_name[2] == \"1\"){\
  8785.   var d1 = parseInt(line_name[3]);\
  8786.   var d2 = parseInt(line_name[4]);\
  8787.   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
  8788.  }\
  8789.  else\
  8790.  {\
  8791.  if(ctx.setLineDash){ctx.setLineDash = null;}\
  8792.  if(ctx.mozDash){ctx.mozDash = null;}\
  8793.  };\
  8794.  var data_x = new Array();\
  8795.  var data_y = new Array();\
  8796.  var lb = line_name.length;\
  8797.  var idx = 0;\
  8798.  for( var p = 5 ; p < lb ; p = p + 2 ){\
  8799.   data_x[idx] = x2px(line_name[p]);\
  8800.   data_y[idx] = y2px(line_name[p+1]);\
  8801.   idx++;\
  8802.  };\
  8803.  for( var p = 0; p < idx ; p++){\
  8804.   ctx.beginPath();\
  8805.   ctx.moveTo(data_x[p],data_y[p]);\
  8806.   ctx.lineTo(data_x[p+1],data_y[p+1]);\
  8807.   ctx.stroke();\
  8808.   ctx.closePath();\
  8809.  };\
  8810.  i++;\
  8811.  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
  8812. };\
  8813. ctx.restore();\
  8814. };\
  8815. return;\
  8816. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  8817.     break;
  8818.  
  8819.     case DRAW_PIECHART:
  8820. fprintf(js_include_file,"\n/* draw piecharts */\n\
  8821. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  8822. function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family,use_filled,use_offset){\
  8823. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  8824.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  8825. }\
  8826. else\
  8827. {\
  8828.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  8829. };\
  8830. var center_text = use_offset || 0;\
  8831. var ld = data_color_list.length;\
  8832. var sum = 0;\
  8833. var idx = 0;\
  8834. var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
  8835. var colors = new Array();\
  8836. var data = new Array();\
  8837. for(var p = 0;p < ld; p = p + 2){\
  8838.  data[idx] = parseFloat(data_color_list[p]);\
  8839.  sum = sum + data[idx];\
  8840.  colors[idx] = data_color_list[p+1];\
  8841.  idx++;\
  8842. };\
  8843. if( use_filled > 1 ){\
  8844.  var i = 2;\
  8845.  for(var p = 0 ;  p < idx ; p++){\
  8846.   if(i > 5 ){ i = 2; };\
  8847.   var pat = create_Pattern(0,0,i,colors[p]); all_fill_patterns[p] = pat;i++;\
  8848.  };\
  8849. };\
  8850. var ctx = obj.getContext(\"2d\");\
  8851. ctx.save();\
  8852. var angle;\
  8853. var angle_end = 0;\
  8854. var offset = Math.PI / 2;\
  8855. ctx.globalAlpha = fill_opacity;\
  8856. var angles = [];\
  8857. for(var p=0; p < idx; p++){\
  8858.  ctx.beginPath();\
  8859.  ctx.moveTo(x_center,y_center);\
  8860.  angle = Math.PI * (2 * data[p] / sum);\
  8861.  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
  8862.  ctx.lineTo(x_center, y_center);\
  8863.  if( use_filled > 1 ){ ctx.fillStyle = all_fill_patterns[p]; }else{ ctx.fillStyle = colors[p];};\
  8864.  ctx.fill();\
  8865.  ctx.closePath();\
  8866.  angles.push(angle_end + angle - offset);\
  8867.  angle_end  = angle_end + angle;\
  8868. };\
  8869. if(typeof(legend0) !== 'undefined'){\
  8870.  var legenda = eval(\"legend\"+legend_cnt);\
  8871.  ctx.globalAlpha = 1.0;\
  8872.  ctx.font = font_family;\
  8873.  var y_offset = font_size;\
  8874.  var x_offset = 0;\
  8875.  var txt;var txt_size;\
  8876.  for(var p = 0; p < idx; p++){\
  8877.   ctx.fillStyle = colors[p];\
  8878.   txt = legenda[p];\
  8879.   txt_size = ctx.measureText(txt).width + 2;\
  8880.   if(center_text == 4){\
  8881.    ctx.save();\
  8882.    ctx.translate(x_center, y_center);\
  8883.    ctx.rotate(angles[p]);\
  8884.    ctx.fillText(txt,radius-txt_size,0);\
  8885.    ctx.restore();\
  8886.   }\
  8887.   else\
  8888.   {\
  8889.    if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
  8890.    ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
  8891.    y_offset = parseInt(y_offset + 1.5*font_size);\
  8892.   };\
  8893.  };\
  8894. };\
  8895. ctx.restore();\
  8896. };",canvas_root_id,canvas_root_id,canvas_root_id);
  8897.     break;
  8898.     case DRAW_JSBOXPLOT:
  8899. fprintf(js_include_file,"\n/* draw jsboxplots */\n\
  8900. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  8901. function statistics(data){\
  8902. var len = data.length;\
  8903. var min = 10000000;\
  8904. var max = -10000000;\
  8905. var sum = 0;var d;\
  8906. for(var i=0;i<len;i++){\
  8907.  d = data[i];\
  8908.  if(d < min){min = d;}else{if(d > max){max = d;};};\
  8909.  sum+= parseFloat(data[i]);\
  8910. };\
  8911. var mean = parseFloat(sum/len);\
  8912. var variance = 0;\
  8913. for(var i=0;i<len;i++){\
  8914.  d = data[i];\
  8915.  variance += (d - mean)*(d - mean);\
  8916. };\
  8917. variance = parseFloat(variance / len);\
  8918. var std = Math.sqrt(variance);\
  8919. data.sort(function(a,b){return a - b;});\
  8920. var median;var Q1;var Q3;\
  8921. var half = Math.floor(0.5*len);\
  8922. var q1 = Math.floor(0.25*len);\
  8923. var q3 = Math.floor(0.75*len);\
  8924. var half = Math.floor(0.5*len);\
  8925. if(len %%2 == 1){\
  8926.  median = data[half];\
  8927.  Q1 = data[q1];\
  8928.  Q3 = data[q3];\
  8929. }\
  8930. else\
  8931. {\
  8932.  median = (data[half - 1] + data[half] )/2;\
  8933.  Q1 = (data[q1 - 1] + data[q1] )/2;\
  8934.  Q3 = (data[q3 - 1] + data[q3] )/2;\
  8935. };\
  8936. return [min,Q1,median,Q3,max];\
  8937. };");
  8938.     break;
  8939.     case DRAW_BOXPLOT:
  8940. fprintf(js_include_file,"\n/* draw boxplots */\n\
  8941. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  8942. 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){\
  8943. 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);};\
  8944. var ctx = obj.getContext(\"2d\");\
  8945. ctx.clearRect(0,0,xsize,ysize);\
  8946. ctx.save();\
  8947. ctx.lineWidth = line_width;\
  8948. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  8949. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8950. var colors = new Array(2);\
  8951. colors[0] = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  8952. colors[1] = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  8953. if( use_filled > 1 ){\
  8954.   var pat = create_Pattern(0,0,3,colors[0]);\
  8955.   all_fill_patterns[0] = pat;\
  8956.   pat = create_Pattern(0,0,4,colors[1]);\
  8957.   all_fill_patterns[1] = pat;\
  8958. };\
  8959. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  8960. var hh = 0.25*hw;\
  8961. switch(boxplot_source){\
  8962.  case 1: if( typeof(jsboxplot_data) === 'undefined'){return;};data = statistics(jsboxplot_data);break;\
  8963.  case 2: if( typeof(student_boxplot_data) === 'undefined'){return;};data = statistics(student_boxplot_data);break;\
  8964.  case 3: if( typeof(student_boxplot) === 'undefined'){return;};data = student_boxplot;break;\
  8965.  default: break;\
  8966. };\
  8967. var min,Q1,median,Q3,max;\
  8968. if(xy == 1 ){\
  8969.  min=x2px(data[0]);Q1=x2px(data[1]);median=x2px(data[2]);Q3=x2px(data[3]);max=x2px(data[4]);\
  8970.  hh = Math.abs(y2px(hh) - y2px(ystart));\
  8971.  hw = Math.abs(y2px(hw) - y2px(ystart));\
  8972.  cxy = y2px(cxy);\
  8973.  ctx.beginPath();\
  8974.  ctx.moveTo(min,cxy);\
  8975.  ctx.lineTo(Q1,cxy);\
  8976.  ctx.moveTo(Q3,cxy);\
  8977.  ctx.lineTo(max,cxy);\
  8978.  ctx.moveTo(min,cxy+hh);\
  8979.  ctx.lineTo(min,cxy-hh);\
  8980.  ctx.moveTo(max,cxy+hh);\
  8981.  ctx.lineTo(max,cxy-hh);\
  8982.  ctx.closePath();\
  8983.  ctx.stroke();\
  8984.  ctx.beginPath();\
  8985.  ctx.rect(Q1,cxy-2*hh,median-Q1,hw);\
  8986.  ctx.closePath();\
  8987.  if( use_filled != 0 ){\
  8988.   if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\
  8989.   ctx.fill();\
  8990.  };\
  8991.  ctx.stroke();\
  8992.  ctx.beginPath();\
  8993.  ctx.rect(median,cxy-2*hh,Q3-median,hw);\
  8994.  ctx.closePath();\
  8995.  if( use_filled != 0 ){\
  8996.   if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\
  8997.   ctx.fill();\
  8998.  };\
  8999.  ctx.stroke();\
  9000. }else{\
  9001.  min=y2px(data[0]);Q1=y2px(data[1]);median=y2px(data[2]);Q3=y2px(data[3]);max=y2px(data[4]);\
  9002.  hh = Math.abs(x2px(hh) - x2px(xstart));\
  9003.  hw = Math.abs(x2px(hw) - x2px(xstart));\
  9004.  cxy = x2px(cxy);\
  9005.  ctx.beginPath();\
  9006.  ctx.moveTo(cxy,min);\
  9007.  ctx.lineTo(cxy,Q1);\
  9008.  ctx.moveTo(cxy,Q3);\
  9009.  ctx.lineTo(cxy,max);\
  9010.  ctx.moveTo(cxy + hh,min);\
  9011.  ctx.lineTo(cxy - hh,min);\
  9012.  ctx.moveTo(cxy + hh,max);\
  9013.  ctx.lineTo(cxy - hh,max);\
  9014.  ctx.closePath;\
  9015.  ctx.stroke();\
  9016.  ctx.beginPath();\
  9017.  ctx.rect(cxy - 2*hh,Q1,hw,median - Q1);\
  9018.  ctx.closePath();\
  9019.  if( use_filled != 0 ){\
  9020.   if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\
  9021.   ctx.fill();\
  9022.  };\
  9023.  ctx.stroke();\
  9024.  ctx.beginPath();\
  9025.  ctx.rect(cxy - 2*hh,median,hw,Q3 - median);\
  9026.  ctx.closePath();\
  9027.  if( use_filled != 0 ){\
  9028.   if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\
  9029.   ctx.fill();\
  9030.  };\
  9031.  ctx.stroke();\
  9032. };\
  9033. ctx.restore();};",canvas_root_id,canvas_root_id,canvas_root_id);
  9034.     break;
  9035.     case DRAW_ARCS:
  9036. fprintf(js_include_file,"\n/* draw arcs */\n\
  9037. if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
  9038. 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){\
  9039. ctx.save();\
  9040. if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  9041. if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
  9042. if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  9043. if(end < start){var tmp = end;end = start;start=tmp;};\
  9044. start = 360 - start;\
  9045. end = 360 - end;\
  9046. ctx.lineWidth = line_width;\
  9047. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  9048. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  9049. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  9050. 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;};\
  9051. ctx.beginPath();\
  9052. ctx.moveTo(xc,yc);\
  9053. ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  9054. ctx.lineTo(xc,yc);\
  9055. ctx.closePath();\
  9056. if( use_filled != 0 ){ctx.fill();};\
  9057. ctx.stroke();\
  9058. ctx.restore();\
  9059. };");
  9060.  
  9061.     break;
  9062.     case DRAW_CENTERSTRING:
  9063. fprintf(js_include_file,"\n/* draw centerstring */\n\
  9064. var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
  9065. var obj;\
  9066. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9067.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9068. }\
  9069. else\
  9070. {\
  9071.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9072. };\
  9073. var ctx = obj.getContext(\"2d\");\
  9074. ctx.save();\
  9075. ctx.clearRect(0,0,xsize,ysize);\
  9076. ctx.font = font_family;\
  9077. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  9078. var stringwidth = ctx.measureText(text).width;\
  9079. var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
  9080. ctx.fillText(text,x,y2px(y));\
  9081. ctx.restore();\
  9082. return;\
  9083. };",canvas_root_id,canvas_root_id,canvas_root_id);
  9084.     break;
  9085.     case DRAW_TEXTS:
  9086. fprintf(js_include_file,"\n/* draw text */\n\
  9087. 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){\
  9088. var obj;\
  9089. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9090.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9091. }\
  9092. else\
  9093. {\
  9094.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9095. };\
  9096. var ctx = obj.getContext(\"2d\");\
  9097. if( font_family != 'null' ){\
  9098.  ctx.font = font_family;\
  9099. }\
  9100. else\
  9101. {\
  9102.  ctx.font = font_size+'px Arial';\
  9103. };\
  9104. 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;};};\
  9105. if(angle2 == 0 && angle != 0){\
  9106.  ctx.save();\
  9107.  if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  9108.  if(use_rotate == 1 ){\
  9109.  ctx.rotate(angle*Math.PI/180);};\
  9110.  ctx.restore();\
  9111. };\
  9112. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  9113. if(angle2 != 0){\
  9114.  ctx.save();\
  9115.  ctx.translate(x,y);\
  9116.  ctx.rotate((360-angle2)*(Math.PI / 180));\
  9117.  ctx.fillText(text,0,0);\
  9118.  ctx.restore();\
  9119. }\
  9120. else\
  9121. {\
  9122.  ctx.fillText(text,x,y);\
  9123. };\
  9124. return;\
  9125. };",canvas_root_id,canvas_root_id,canvas_root_id);
  9126.     break;
  9127.     case DRAW_CURVE:
  9128. fprintf(js_include_file,"\n/* draw curve */\n\
  9129. 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){\
  9130. var obj;\
  9131. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9132.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9133. }\
  9134. else\
  9135. {\
  9136.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9137. };\
  9138. var ctx = obj.getContext(\"2d\");\
  9139. ctx.save();\
  9140. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  9141. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  9142. ctx.beginPath();ctx.lineWidth = line_width;\
  9143. if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
  9144. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  9145. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  9146. ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
  9147. for(var p = 1 ; p < x_points.length ; p++){\
  9148.  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
  9149.  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
  9150.  }\
  9151.  else\
  9152.  {\
  9153.   ctx.stroke();\
  9154.   ctx.beginPath();\
  9155.   p++;\
  9156.   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
  9157.  };\
  9158. };\
  9159. ctx.stroke();\
  9160. ctx.restore();\
  9161. };",canvas_root_id,canvas_root_id,canvas_root_id);
  9162.     break;
  9163.  
  9164.     case DRAW_INPUTS:
  9165. fprintf(js_include_file,"\n/* draw input fields */\n\
  9166. var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value,use_offset){\
  9167. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  9168. var input = document.createElement(\"input\");\
  9169. input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  9170. input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  9171. input.setAttribute(\"size\",size);\
  9172. input.setAttribute(\"value\",value);\
  9173. input.addEventListener(\"touchstart\", function(e){this.focus();},false);\
  9174. if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
  9175. canvas_div.appendChild(input);\
  9176. if(use_offset != 0 ){ center_input('canvas_input'+input_cnt,x,y,style);};\
  9177. };\
  9178. function center_input(id,x,y,style){\
  9179. var inp = document.getElementById(id);\
  9180. var pos = inp.getBoundingClientRect();\
  9181. var center_x = parseInt(x - 0.5*(pos.width));\
  9182. var center_y = parseInt(y - 0.5*(pos.height));\
  9183. try{ inp.setAttribute(\"style\",\"position:absolute;left:\"+center_x+\"px;top:\"+center_y+\"px;\"+style );}\
  9184. catch(e){return;};\
  9185. };");
  9186.     break;
  9187.  
  9188.     case DRAW_TEXTAREAS:
  9189. fprintf(js_include_file,"\n/* draw text area inputfields */\n\
  9190. var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
  9191. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  9192. var textarea = document.createElement(\"textarea\");\
  9193. textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  9194. textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  9195. textarea.setAttribute(\"cols\",cols);\
  9196. textarea.setAttribute(\"rows\",rows);\
  9197. textarea.value = value;\
  9198. if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
  9199. canvas_div.appendChild(textarea);};");
  9200.     break;
  9201.  
  9202. case DRAW_PIXELS:
  9203. fprintf(js_include_file,"\n/* draw pixel */\n\
  9204. var draw_setpixel = function(x,y,color,opacity,pixelsize){\
  9205. var idx = 2000+Math.ceil(1000*(Math.random()));\
  9206. var canvas = create_canvas%d(idx,xsize,ysize);\
  9207. var d = 0.5*pixelsize;\
  9208. var ctx = canvas.getContext(\"2d\");\
  9209. if(pixelsize%%2 == 1){ ctx.translate(0.5,0.5);};\
  9210. ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
  9211. ctx.clearRect(0,0,xsize,ysize);\
  9212. for(var p=0; p<x.length;p++){\
  9213.  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
  9214. };\
  9215. ctx.fill();ctx.stroke();\
  9216. };",canvas_root_id);
  9217. break;
  9218.  
  9219. case DRAW_CLOCK:
  9220. fprintf(js_include_file,"\n/* begin command clock */\n\
  9221. var clock_canvas = create_canvas%d(%d,xsize,ysize);\
  9222. var clock_ctx = clock_canvas.getContext(\"2d\");\
  9223. var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
  9224. clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\
  9225. clock_ctx.save();\
  9226. clock_ctx.globalAlpha = clock_bg_opacity;\
  9227. this.type = type || 0;\
  9228. this.interaction = interaction || 0;\
  9229. this.H = H;\
  9230. this.M = M;\
  9231. this.S = S;\
  9232. this.xc = xc || xsize/2;\
  9233. this.yc = yc || ysize/2;\
  9234. this.radius = radius || xsize/4;\
  9235. var font_size = parseInt(0.2*this.radius);\
  9236. this.H_color = h_color || \"black\";\
  9237. this.M_color = m_color || \"black\";\
  9238. this.S_color = s_color || \"black\";\
  9239. this.fg_color = fg_color || \"black\";\
  9240. this.bg_color = bg_color || \"white\";\
  9241. clock_ctx.translate(this.xc,this.yc);\
  9242. clock_ctx.beginPath();\
  9243. clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
  9244. clock_ctx.fillStyle = this.bg_color;\
  9245. clock_ctx.fill();\
  9246. clock_ctx.closePath();\
  9247. clock_ctx.beginPath();\
  9248. clock_ctx.font = font_size+\"px Arial\";\
  9249. clock_ctx.fillStyle = this.fg_color;\
  9250. clock_ctx.textAlign = \"center\";\
  9251. clock_ctx.textBaseline = 'middle';\
  9252. var angle;var x1,y1,x2,y2;\
  9253. var angle_cos;var angle_sin;\
  9254. clock_ctx.globalAlpha = clock_fg_opacity;\
  9255. switch(type){\
  9256. case 0:clock_ctx.beginPath();\
  9257. for(var p = 1; p <= 12 ; p++){\
  9258.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  9259.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  9260.  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  9261.  clock_ctx.moveTo(x1,y1);\
  9262.  clock_ctx.lineTo(x2,y2);\
  9263. };\
  9264. for(var p = 1; p <= 60 ; p++){\
  9265.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  9266.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  9267.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  9268.  clock_ctx.moveTo(x1,y1);\
  9269.  clock_ctx.lineTo(x2,y2);\
  9270. };\
  9271. clock_ctx.closePath();\
  9272. clock_ctx.stroke();\
  9273. break;\
  9274. case 1:\
  9275. 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;\
  9276. case 2:\
  9277. 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);};\
  9278. clock_ctx.beginPath();\
  9279. for(var p = 1; p <= 12 ; p++){\
  9280.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  9281.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  9282.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  9283.  clock_ctx.moveTo(x1,y1);\
  9284.  clock_ctx.lineTo(x2,y2);\
  9285. };\
  9286. for(var p = 1; p <= 60 ; p++){\
  9287.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  9288.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  9289.  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  9290.  clock_ctx.moveTo(x1,y1);\
  9291.  clock_ctx.lineTo(x2,y2);\
  9292. };\
  9293. clock_ctx.closePath();\
  9294. clock_ctx.stroke();\
  9295. break;\
  9296. };\
  9297. angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
  9298. clock_ctx.rotate(angle);\
  9299. clock_ctx.beginPath();\
  9300. clock_ctx.moveTo(-3, -2);\
  9301. clock_ctx.lineTo(-3, 2);\
  9302. clock_ctx.lineTo(this.radius * 0.6, 1);\
  9303. clock_ctx.lineTo(this.radius  * 0.6, -1);\
  9304. clock_ctx.fillStyle = this.H_color;\
  9305. clock_ctx.fill();\
  9306. clock_ctx.rotate(-angle);\
  9307. angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
  9308. clock_ctx.rotate(angle);\
  9309. clock_ctx.beginPath();\
  9310. clock_ctx.moveTo(-3, -2);\
  9311. clock_ctx.lineTo(-3, 2);\
  9312. clock_ctx.lineTo(this.radius  * 0.8, 1);\
  9313. clock_ctx.lineTo(this.radius  * 0.8, -1);\
  9314. clock_ctx.fillStyle = this.M_color;\
  9315. clock_ctx.fill();\
  9316. clock_ctx.rotate(-angle);\
  9317. angle = (this.S - 15) * 2 * Math.PI / 60;\
  9318. clock_ctx.rotate(angle);\
  9319. clock_ctx.beginPath();\
  9320. clock_ctx.moveTo(0,0);\
  9321. clock_ctx.lineTo(this.radius  * 0.9, 1);\
  9322. clock_ctx.lineTo(this.radius  * 0.9, -1);\
  9323. clock_ctx.strokeStyle = this.S_color;\
  9324. clock_ctx.stroke();\
  9325. clock_ctx.restore();\
  9326. };",canvas_root_id,CLOCK_CANVAS);
  9327. break;
  9328.  
  9329. case DRAW_LATTICE:
  9330. fprintf(js_include_file,"\n/* draw lattice */\n\
  9331. 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){\
  9332. var obj;\
  9333. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9334.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9335. }\
  9336. else\
  9337. {\
  9338.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9339. };\
  9340. var ctx = obj.getContext(\"2d\");\
  9341. ctx.save();\
  9342. if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
  9343. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  9344. var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  9345. 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;};\
  9346. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  9347. var radius = line_width;\
  9348. var x = 0;\
  9349. var y = 0;\
  9350. var x_step_px = xsize/(xmax-xmin);\
  9351. var y_step_px = ysize/(ymax-ymin);\
  9352. var xv1 = dx1*x_step_px;\
  9353. var yv1 = dy1*y_step_px;\
  9354. var xv2 = dx2*x_step_px;\
  9355. var yv2 = dy2*y_step_px;\
  9356. for(var p = 0; p < n1 ;p++){\
  9357.  x = p*xv1 + x0;\
  9358.  y = p*yv1 + y0;\
  9359.  for(var c = 0; c < n2 ; c++){\
  9360.   ctx.beginPath();\
  9361.   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
  9362.   ctx.fill();\
  9363.   ctx.stroke();\
  9364.   ctx.closePath();\
  9365.  };\
  9366. };\
  9367. ctx.restore();\
  9368. return;\
  9369. };",canvas_root_id,canvas_root_id,canvas_root_id);
  9370.     break;
  9371. case DRAW_XYLOGSCALE:
  9372. fprintf(js_include_file,"\n/* draw xylogscale */\n\
  9373. 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){\
  9374. var obj;\
  9375. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9376.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9377. }\
  9378. else\
  9379. {\
  9380.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9381. };\
  9382. var ctx = obj.getContext(\"2d\");\
  9383. ctx.clearRect(0,0,xsize,ysize);\
  9384. ctx.save();\
  9385. var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
  9386. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  9387. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  9388. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  9389. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  9390. if(use_axis_numbering != -1){\
  9391.  ctx.font = font_family;\
  9392.  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
  9393.  ymarge = parseInt(1.5*font_size);\
  9394.  ctx.save();\
  9395.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  9396.  ctx.rect(0,0,xmarge,ysize);\
  9397.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  9398.  ctx.fill();\
  9399.  ctx.restore();\
  9400. }else{xmarge = 0;ymarge = 0;};\
  9401. if( typeof(xaxislabel) !== 'undefined' ){\
  9402.  ctx.save();\
  9403.  ctx.font = \"italic \"+font_size+\"px Arial\";\
  9404.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9405.  corr =  ctx.measureText(xaxislabel).width;\
  9406.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  9407.  ctx.restore();\
  9408. };\
  9409. if( typeof(yaxislabel) !== 'undefined' ){\
  9410.  ctx.save();\
  9411.  ctx.font = \"italic \"+font_size+\"px Arial\";\
  9412.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9413.  corr = ctx.measureText(yaxislabel).width;\
  9414.  ctx.translate(xmarge+font_size,corr+font_size);\
  9415.  ctx.rotate(-0.5*Math.PI);\
  9416.  ctx.fillText(yaxislabel,0,0);\
  9417.  ctx.restore();\
  9418. };\
  9419. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9420. ctx.lineWidth = line_width;\
  9421. for(var p = x_min; p <= x_max ; p++){\
  9422.  num = Math.pow(xlogbase,p);\
  9423.  for(var i = 1 ; i < xlogbase ; i++){\
  9424.   x_e = x2px(i*num);\
  9425.   if( i == 1 ){\
  9426.    ctx.lineWidth = line_width;\
  9427.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9428.    if( use_axis_numbering != -1 && p > x_min){\
  9429.      xtxt = xlogbase+'^'+p.toFixed(0);\
  9430.      corr = 0.5*(ctx.measureText(xtxt).width);\
  9431.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  9432.    };\
  9433.   }else{\
  9434.    ctx.lineWidth = 0.2*line_width;\
  9435.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9436.   };\
  9437.   if( x_e >= xmarge ){\
  9438.    ctx.beginPath();\
  9439.    ctx.moveTo(x_e,0);\
  9440.    ctx.lineTo(x_e,ysize - ymarge);\
  9441.    ctx.stroke();\
  9442.    ctx.closePath();\
  9443.   };\
  9444.  };\
  9445. };\
  9446. for(var p = y_min; p <= y_max ; p++){\
  9447.  num = Math.pow(ylogbase,p);\
  9448.  for(var i = 1 ; i < ylogbase ; i++){\
  9449.   y_e = y2px(i*num);\
  9450.   if( i == 1 ){\
  9451.    ctx.lineWidth = line_width;\
  9452.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9453.    if( use_axis_numbering != -1 && p > y_min){\
  9454.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  9455.    };\
  9456.   }else{\
  9457.    ctx.lineWidth = 0.2*line_width;\
  9458.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9459.   };\
  9460.   ctx.beginPath();\
  9461.   ctx.moveTo(xmarge,y_e);\
  9462.   ctx.lineTo(xsize,y_e);\
  9463.   ctx.stroke();\
  9464.   ctx.closePath();\
  9465.  };\
  9466. };\
  9467. ctx.restore();\
  9468. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  9469.     break;
  9470.  
  9471. case DRAW_XLOGSCALE:
  9472. fprintf(js_include_file,"\n/* draw xlogscale */\n\
  9473. 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){\
  9474. var obj;\
  9475. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9476.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9477. }\
  9478. else\
  9479. {\
  9480.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9481. };\
  9482. var ctx = obj.getContext(\"2d\");\
  9483. ctx.clearRect(0,0,xsize,ysize);\
  9484. ctx.save();\
  9485. ctx.lineWidth = line_width;\
  9486. var prec = Math.log(precision)/Math.log(10);\
  9487. var x_min = Math.log(xmin)/Math.log(xlogbase);\
  9488. var x_max = Math.log(xmax)/Math.log(xlogbase);\
  9489. var y_min = 0;var y_max = ysize;var x_e;var corr;\
  9490. var xtxt;var ytxt;var num;var xmarge;var ymarge;\
  9491. if(use_axis_numbering != -1){\
  9492.  ctx.font = font_family;\
  9493.  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
  9494.  ymarge = parseInt(1.5*font_size);\
  9495.  ctx.save();\
  9496.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  9497.  ctx.rect(0,0,xmarge,ysize);\
  9498.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  9499.  ctx.fill();\
  9500.  ctx.restore();\
  9501. }else{xmarge = 0;ymarge = 0;};\
  9502. if( typeof(xaxislabel) !== 'undefined' ){\
  9503.  ctx.save();\
  9504.  ctx.font = \"italic \"+font_size+\"px Arial\";\
  9505.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9506.  corr =  ctx.measureText(xaxislabel).width;\
  9507.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  9508.  ctx.restore();\
  9509. };\
  9510. if( typeof(yaxislabel) !== 'undefined' ){\
  9511.  ctx.save();\
  9512.  ctx.font = \"italic \"+font_size+\"px Arial\";\
  9513.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9514.  corr = ctx.measureText(yaxislabel).width;\
  9515.  ctx.translate(xmarge+font_size,corr+font_size);\
  9516.  ctx.rotate(-0.5*Math.PI);\
  9517.  ctx.fillText(yaxislabel,0,0);\
  9518.  ctx.restore();\
  9519. };\
  9520. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9521. ctx.lineWidth = line_width;\
  9522. for(var p = x_min; p <= x_max ; p++){\
  9523.  num = Math.pow(xlogbase,p);\
  9524.  for(var i = 1 ; i < xlogbase ; i++){\
  9525.   x_e = x2px(i*num);\
  9526.   if( i == 1 ){\
  9527.     ctx.lineWidth = line_width;\
  9528.     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9529.    if( use_axis_numbering != -1 && p > x_min ){\
  9530.      xtxt = xlogbase+'^'+p.toFixed(0);\
  9531.      corr = 0.5*(ctx.measureText(xtxt).width);\
  9532.      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
  9533.    };\
  9534.   }else{\
  9535.    ctx.lineWidth = 0.2*line_width;\
  9536.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9537.   };\
  9538.   if( x_e >= xmarge ){\
  9539.    ctx.beginPath();\
  9540.    ctx.moveTo(x_e,0);\
  9541.    ctx.lineTo(x_e,ysize - ymarge);\
  9542.    ctx.stroke();\
  9543.    ctx.closePath();\
  9544.   };\
  9545.  };\
  9546. };\
  9547. var stepy = Math.abs(y2px(ymajor) - y2px(0));\
  9548. var minor_step = stepy / yminor;\
  9549. for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
  9550.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9551.  ctx.lineWidth = line_width;\
  9552.  ctx.beginPath();\
  9553.  ctx.moveTo(xmarge,y);\
  9554.  ctx.lineTo(xsize,y);\
  9555.  ctx.stroke();\
  9556.  ctx.closePath();\
  9557.  if( use_axis_numbering != -1){\
  9558.   ytxt = (px2y(y)).toFixed(prec);\
  9559.   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
  9560.  };\
  9561.  for(var dy = 1 ; dy < yminor ; dy++){\
  9562.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9563.   ctx.lineWidth = 0.2*line_width;\
  9564.   ctx.beginPath();\
  9565.   ctx.moveTo(xmarge,y+dy*minor_step);\
  9566.   ctx.lineTo(xsize,y+dy*minor_step);\
  9567.   ctx.stroke();\
  9568.   ctx.closePath();\
  9569.  };\
  9570. };\
  9571. ctx.restore();\
  9572. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  9573.     break;
  9574. case DRAW_YLOGSCALE:
  9575. fprintf(js_include_file,"\n/* draw ylogscale */\n\
  9576. 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){\
  9577. var obj;\
  9578. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  9579.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  9580. }\
  9581. else\
  9582. {\
  9583.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  9584. };\
  9585. var ctx = obj.getContext(\"2d\");\
  9586. ctx.clearRect(0,0,xsize,ysize);\
  9587. ctx.save();\
  9588. ctx.lineWidth = line_width;\
  9589. var y_min = Math.log(ymin)/Math.log(ylogbase);\
  9590. var y_max = Math.log(ymax)/Math.log(ylogbase);\
  9591. var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
  9592. if(use_axis_numbering != -1){\
  9593.  ctx.font = font_family;\
  9594.  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
  9595.  ymarge = 2*font_size;\
  9596.  ctx.save();\
  9597.  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
  9598.  ctx.rect(0,0,xmarge,ysize);\
  9599.  ctx.rect(0,ysize-ymarge,xsize,ysize);\
  9600.  ctx.fill();\
  9601.  ctx.restore();\
  9602. }else{xmarge = 0;ymarge = 0;};\
  9603. if( typeof(xaxislabel) !== 'undefined' ){\
  9604.  ctx.save();\
  9605.  ctx.font = \"italic \"+font_size+\"px Arial\";\
  9606.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9607.  corr =  ctx.measureText(xaxislabel).width;\
  9608.  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
  9609.  ctx.restore();\
  9610. };\
  9611. if( typeof(yaxislabel) !== 'undefined' ){\
  9612.  ctx.save();\
  9613.  ctx.font = \"italic \"+font_size+\"px Arial\";\
  9614.  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9615.  corr = ctx.measureText(yaxislabel).width;\
  9616.  ctx.translate(xmarge+font_size,corr+font_size);\
  9617.  ctx.rotate(-0.5*Math.PI);\
  9618.  ctx.fillText(yaxislabel,0,0);\
  9619.  ctx.restore();\
  9620. };\
  9621. ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
  9622. ctx.lineWidth = line_width;\
  9623. for(var p = y_min; p <= y_max ; p++){\
  9624.  num = Math.pow(ylogbase,p);\
  9625.  for(var i = 1 ; i < ylogbase ; i++){\
  9626.   y_e = y2px(i*num);\
  9627.   if( i == 1 ){\
  9628.    ctx.lineWidth = line_width;\
  9629.    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9630.    if( use_axis_numbering != -1 && p > y_min){\
  9631.     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
  9632.    };\
  9633.   }else{\
  9634.    ctx.lineWidth = 0.2*line_width;\
  9635.    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9636.   };\
  9637.   ctx.beginPath();\
  9638.   ctx.moveTo(xmarge,y_e);\
  9639.   ctx.lineTo(xsize,y_e);\
  9640.   ctx.stroke();\
  9641.   ctx.closePath();\
  9642.  };\
  9643. };\
  9644. var stepx = Math.abs(x2px(xmajor) - x2px(0));\
  9645. var minor_step = stepx / xminor;\
  9646. var prec = Math.log(precision)/Math.log(10);\
  9647. var xtxt;var corr;var flip = 0;\
  9648. for(var x = stepx ; x < xsize ; x = x + stepx){\
  9649.  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
  9650.  ctx.lineWidth = line_width;\
  9651.  ctx.beginPath();\
  9652.  ctx.moveTo(x,ysize-ymarge);\
  9653.  ctx.lineTo(x,0);\
  9654.  ctx.stroke();\
  9655.  ctx.closePath();\
  9656.  if( use_axis_numbering != -1){\
  9657.   xtxt = (px2x(x)).toFixed(prec);\
  9658.   corr = 0.5*(ctx.measureText(xtxt).width);\
  9659.   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
  9660.   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
  9661.  };\
  9662.  for(var dx = 1 ; dx < xminor ; dx++){\
  9663.   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
  9664.   ctx.lineWidth = 0.2*line_width;\
  9665.   ctx.beginPath();\
  9666.   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
  9667.   ctx.lineTo(x+dx*minor_step,0);\
  9668.   ctx.stroke();\
  9669.   ctx.closePath();\
  9670.  };\
  9671. };\
  9672. ctx.restore();\
  9673. };",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  9674.     break;
  9675.  
  9676.     default:break;
  9677.    }
  9678.   }
  9679.  }
  9680.   return;
  9681. }
  9682.  
  9683. void check_string_length(int L){
  9684.  if( L > MAX_BUFFER-1){
  9685.   canvas_error("problem with your arguments to command...");
  9686.  }
  9687.  return;
  9688. }
  9689.  
  9690.  
  9691. int get_token(FILE *infile){
  9692.         int     c,i=0;
  9693.         char    temp[MAX_INT], *input_type;
  9694.         char    *line="line",
  9695.         *audio="audio",
  9696.         *blink="blink",
  9697.         *arrowhead="arrowhead",
  9698.         *crosshairsize="crosshairsize",
  9699.         *crosshair="crosshair",
  9700.         *crosshairs="crosshairs",
  9701.         *audioobject="audioobject",
  9702.         *style="style",
  9703.         *mouse="mouse",
  9704.         *mousex="mousex",
  9705.         *mousey="mousey",
  9706.         *mouse_display="display",
  9707.         *mouse_degree="mouse_degree",
  9708.         *userdraw="userdraw",
  9709.         *highlight="highlight",
  9710.         *http="http",
  9711.         *rays="rays",
  9712.         *dashtype="dashtype",
  9713.         *dashed="dashed",
  9714.         *filled="filled",
  9715.         *lattice="lattice",
  9716.         *parallel="parallel",
  9717.         *segment="segment",
  9718.         *segments="segments",
  9719.         *dsegment="dsegment",
  9720.         *dsegments="dsegments",
  9721.         *seg="seg",
  9722.         *segs="segs",
  9723.         *bgimage="bgimage",
  9724.         *bgcolor="bgcolor",
  9725.         *strokecolor="strokecolor",
  9726.         *backgroundimage="backgroundimage",
  9727.         *text="text",
  9728.         *textup="textup",
  9729.         *mouseprecision="mouseprecision",
  9730.         *precision="precision",
  9731.         *plotsteps="plotsteps",
  9732.         *plotstep="plotstep",
  9733.         *tsteps="tsteps",
  9734.         *curve="curve",
  9735.         *dcurve="dcurve",
  9736.         *curvedarrow="curvedarrow",
  9737.         *curvedarrows="curvedarrows",
  9738.         *curvedarrow2="curvedarrow2",
  9739.         *curvedarrows2="curvedarrows2",
  9740.         *plot="plot",
  9741.         *dplot="dplot",
  9742.         *levelcurve="levelcurve",
  9743.         *fontsize="fontsize",
  9744.         *fontcolor="fontcolor",
  9745.         *axis="axis",
  9746.         *axisnumbering="axisnumbering",
  9747.         *axisnumbers="axisnumbers",
  9748.         *arrow="arrow",
  9749.         *vector="vector",
  9750.         *vectors="vectors",
  9751.         *darrow="darrow",
  9752.         *arrow2="arrow2",
  9753.         *darrow2="darrow2",
  9754.         *arrows="arrows",
  9755.         *arrows2="arrows2",
  9756.         *zoom="zoom",
  9757.         *grid="grid",
  9758.         *hline="hline",
  9759.         *dhline="dhline",
  9760.         *drag="drag",
  9761.         *horizontalline="horizontalline",
  9762.         *horizontallines="horizontallines",
  9763.         *vline="vline",
  9764.         *dvline="dvline",
  9765.         *verticalline="verticalline",
  9766.         *verticallines="verticallines",
  9767.         *triangle="triangle",
  9768.         *triangles="triangles",
  9769.         *ftriangle="ftriangle",
  9770.         *ftriangles="ftriangles",
  9771.         *mathml="mathml",
  9772.         *html="html",
  9773.         *input="input",
  9774.         *clearbutton="clearbutton",
  9775.         *erase="erase",
  9776.         *delete="delete",
  9777.         *inputstyle="inputstyle",
  9778.         *textarea="textarea",
  9779.         *trange="trange",
  9780.         *ranget="ranget",
  9781.         *xrange="xrange",
  9782.         *yrange="yrange",
  9783.         *rangex="rangex",
  9784.         *rangey="rangey",
  9785.         *path="path",
  9786.         *polyline="polyline",
  9787.         *brokenline="brokenline",
  9788.         *lines="lines",
  9789.         *poly="poly",
  9790.         *polygon="polygon",
  9791.         *fpolygon="fpolygon",
  9792.         *fpoly="fpoly",
  9793.         *filledpoly="filledpoly",
  9794.         *filledpolygon="filledpolygon",
  9795.         *rect="rect",
  9796.         *frect="frect",
  9797.         *rectangle="rectangle",
  9798.         *frectangle="frectangle",
  9799.         *square="square",
  9800.         *fsquare="fsquare",
  9801.         *fsquares="fsquares",
  9802.         *rects="rects",
  9803.         *frects="frects",
  9804.         *dline="dline",
  9805.         *arc="arc",
  9806.         *filledarc="filledarc",
  9807.         *farc="farc",
  9808.         *size="size",
  9809.         *string="string",
  9810.         *stringup="stringup",
  9811.         *copy="copy",
  9812.         *copyresized="copyresized",
  9813.         *opacity="opacity",
  9814.         *transparent="transparent",
  9815.         *fill="fill",
  9816.         *point="point",
  9817.         *points="points",
  9818.         *linewidth="linewidth",
  9819.         *circle="circle",
  9820.         *circles="circles",
  9821.         *fcircle="fcircle",
  9822.         *fcircles="fcircles",
  9823.         *disk="disk",
  9824.         *disks="disks",
  9825.         *comment="#",
  9826.         *end="end",
  9827.         *ellipse="ellipse",
  9828.         *ellipses="ellipses",
  9829.         *fellipse="fellipse",
  9830.         *rotate="rotate",
  9831.         *affine="affine",
  9832.         *rotationcenter="rotationcenter",
  9833.         *killrotate="killrotate",
  9834.         *killaffine="killaffine",
  9835.         *fontfamily="fontfamily",
  9836.         *fillcolor="fillcolor",
  9837.         *clicktile="clicktile",
  9838.         *clicktile_colors="clicktile_colors",
  9839.         *translation="translation",
  9840.         *translate="translate",
  9841.         *killtranslation="killtranslation",
  9842.         *killtranslate="killtranslate",
  9843.         *onclick="onclick",
  9844.         *roundrects="roundrects",
  9845.         *roundrect="roundrect",
  9846.         *froundrect="froundrect",
  9847.         *froundrects="froundrects",
  9848.         *roundrectangle="roundrectangle",
  9849.         *patternfill="patternfill",
  9850.         *hatchfill="hatchfill",
  9851.         *diafill="diafill",
  9852.         *diamondfill="diamondfill",
  9853.         *dotfill="dotfill",
  9854.         *textfill="textfill",
  9855.         *gridfill="gridfill",
  9856.         *imagefill="imagefill",
  9857.         *xlogbase="xlogbase",
  9858.         *ylogbase="ylogbase",
  9859.         *xlogscale="xlogscale",
  9860.         *ylogscale="ylogscale",
  9861.         *xylogscale="xylogscale",
  9862.         *intooltip="intooltip",
  9863.         *popup="popup",
  9864.         *replyformat="replyformat",
  9865.         *floodfill="floodfill",
  9866.         *fillall="fillall",
  9867.         *filltoborder="filltoborder",
  9868.         *setpixel="setpixel",
  9869.         *pixels="pixels",
  9870.         *pixelsize="pixelsize",
  9871.         *xaxis="xaxis",
  9872.         *xaxisup="xaxisup",
  9873.         *yaxis="yaxis",
  9874.         *xaxistext="xaxistext",
  9875.         *xaxistextup="xaxistextup",
  9876.         *yaxistext="yaxistext",
  9877.         *piechart="piechart",
  9878.         *boxplot="boxplot",
  9879.         *boxplotdata="boxplotdata",
  9880.         *userboxplot="userboxplot",
  9881.         *userboxplotdata="userboxplotdata",
  9882.         *legend="legend",
  9883.         *legendcolors="legendcolors",
  9884.         *xlabel="xlabel",
  9885.         *ylabel="ylabel",
  9886.         *barchart="barchart",
  9887.         *linegraph="linegraph",
  9888.         *clock="clock",
  9889.         *animate="animate",
  9890.         *video="video",
  9891.         *status="status",
  9892.         *nostatus="nostatus",
  9893.         *snaptogrid="snaptogrid",
  9894.         *xsnaptogrid="xsnaptogrid",
  9895.         *ysnaptogrid="ysnaptogrid",
  9896.         *snaptopoints="snaptopoints",
  9897.         *snaptofunction="snaptofunction",
  9898.         *snaptofun="snaptofun",
  9899.         *userinput_xy="userinput_xy",
  9900.         *userinput_function="userinput_function",
  9901.         *usertextarea_xy="usertextarea_xy",
  9902.         *userinput="userinput",
  9903.         *jsmath="jsmath",
  9904.         *trace_jscurve="trace_jscurve",
  9905.         *setlimits="setlimits",
  9906.         *jscurve="jscurve",
  9907.         *jsplot="jsplot",
  9908.         *sgraph="sgraph",
  9909.         *title="title",
  9910.         *centerstring="centerstring",
  9911.         *xunit="xunit",
  9912.         *yunit="yunit",
  9913.         *slider="slider",
  9914.         *killslider="killslider",
  9915.         *angle="angle",
  9916.         *halflines="halflines",
  9917.         *demilines="demilines",
  9918.         *halfline="halfline",
  9919.         *demiline="demiline",
  9920.         *hlines="hlines",
  9921.         *vlines="vlines",
  9922.         *bezier="bezier",
  9923.         *functionlabel="functionlabel",
  9924.         *sliderfunction_x="sliderfunction_x",
  9925.         *sliderfunction_y="sliderfunction_y",
  9926.         *multidraw="multidraw",
  9927.         *linewidths="linewidths",
  9928.         *multilinewidth="multilinewidth",
  9929.         *multistrokecolors="multistrokecolors",
  9930.         *multicolors="multistrokecolors",
  9931.         *colors="colors",
  9932.         *multifillcolors="multifillcolors",
  9933.         *fillcolors="fillcolors",
  9934.         *multistrokeopacity="multistrokeopacity",
  9935.         *multifillopacity="multifillopacity",
  9936.         *multifill="multifill",
  9937.         *multidash="multidash",
  9938.         *multilabel="multilabel",
  9939.         *multiuserinput="multiuserinput",
  9940.         *multiinput="multiinput",
  9941.         *multisnaptogrid="multisnaptogrid",
  9942.         *multisnap="multisnap",
  9943.         *protractor="protractor",
  9944.         *ruler="ruler",
  9945.         *cursor="cursor",
  9946.         *pointer="pointer",
  9947.         *yerrorbars="yerrorbars",
  9948.         *xerrorbars="xerrorbars",
  9949.         *noxaxis="noxaxis",
  9950.         *noyaxis="noyaxis",
  9951.         *colorpalette="colorpalette",
  9952.         *imagepalette="imagepalette",
  9953.         *yoffset="yoffset",
  9954.         *xoffset="xoffset",
  9955.         *latex="latex",
  9956.         *centered="centered",
  9957.         *xyoffset="xyoffset",
  9958.         *resetoffset="resetoffset",
  9959.         *fillpattern="fillpattern",
  9960.         *numberline="numberline",
  9961.         *duplicates="duplicates",
  9962.         *allowdups="allowdups",
  9963.         *canvastype="canvastype";
  9964.  
  9965.         while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){
  9966.          if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */
  9967.          }else{
  9968.           if( c == ' ' ){
  9969.             break;
  9970.           }else{
  9971.            temp[i] = c;
  9972.            if(i > MAX_INT - 2){canvas_error("command string too long !");}
  9973.            i++;
  9974.           }
  9975.          }
  9976.          if(temp[0] == '#'){ break; }
  9977.         }
  9978.         if (c == '\n' || c == '\r' || c == '\t' ){  line_number++; }
  9979.         if (c == EOF) {finished=1;return 0;}
  9980.  
  9981.         temp[i]='\0';
  9982.         input_type=(char*)my_newmem(strlen(temp));
  9983.         snprintf(input_type,sizeof(temp),"%s",temp);
  9984. /* fprintf(stdout,"temp = %s <br/>",input_type); */
  9985.         if( strcmp(input_type, size) == 0 ){
  9986.         free(input_type);
  9987.         return SIZE;
  9988.         }
  9989.         if( strcmp(input_type, xrange) == 0 ){
  9990.         free(input_type);
  9991.         return XRANGE;
  9992.         }
  9993.         if( strcmp(input_type, rangex) == 0 ){
  9994.         free(input_type);
  9995.         return XRANGE;
  9996.         }
  9997.         if( strcmp(input_type, trange) == 0 ){
  9998.         free(input_type);
  9999.         return TRANGE;
  10000.         }
  10001.         if( strcmp(input_type, ranget) == 0 ){
  10002.         free(input_type);
  10003.         return TRANGE;
  10004.         }
  10005.         if( strcmp(input_type, yrange) == 0 ){
  10006.         free(input_type);
  10007.         return YRANGE;
  10008.         }
  10009.         if( strcmp(input_type, rangey) == 0 ){
  10010.         free(input_type);
  10011.         return YRANGE;
  10012.         }
  10013.         if( strcmp(input_type, linewidth) == 0 ){
  10014.         free(input_type);
  10015.         return LINEWIDTH;
  10016.         }
  10017.         if( strcmp(input_type, dashed) == 0 ){
  10018.         free(input_type);
  10019.         return DASHED;
  10020.         }
  10021.         if( strcmp(input_type, dashtype) == 0 ){
  10022.         free(input_type);
  10023.         return DASHTYPE;
  10024.         }
  10025.         if( strcmp(input_type, axisnumbering) == 0 ){
  10026.         free(input_type);
  10027.         return AXIS_NUMBERING;
  10028.         }
  10029.         if( strcmp(input_type, axisnumbers) == 0 ){
  10030.         free(input_type);
  10031.         return AXIS_NUMBERING;
  10032.         }
  10033.         if( strcmp(input_type, axis) == 0 ){
  10034.         free(input_type);
  10035.         return AXIS;
  10036.         }
  10037.         if( strcmp(input_type, grid) == 0 ){
  10038.         free(input_type);
  10039.         return GRID;
  10040.         }
  10041.         if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){
  10042.         free(input_type);
  10043.         return HLINES;
  10044.         }
  10045.         if( strcmp(input_type, vlines) == 0 ||  strcmp(input_type, verticallines) == 0 ){
  10046.         free(input_type);
  10047.         return VLINES;
  10048.         }
  10049.         if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){
  10050.         free(input_type);
  10051.         return HLINE;
  10052.         }
  10053.         if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
  10054.         free(input_type);
  10055.         return VLINE;
  10056.         }
  10057.         if( strcmp(input_type, line) == 0 ){
  10058.         free(input_type);
  10059.         return LINE;
  10060.         }
  10061.         if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){
  10062.         free(input_type);
  10063.         return SEGMENTS;
  10064.         }
  10065.         if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
  10066.         free(input_type);
  10067.         return SEGMENT;
  10068.         }
  10069.         if( strcmp(input_type, dsegments) == 0 ){
  10070.         free(input_type);
  10071.         use_dashed = TRUE;
  10072.         return SEGMENTS;
  10073.         }
  10074.         if( strcmp(input_type, dsegment) == 0 ){
  10075.         free(input_type);
  10076.         use_dashed = TRUE;
  10077.         return SEGMENT;
  10078.         }
  10079.         if( strcmp(input_type, crosshairsize) == 0 ){
  10080.         free(input_type);
  10081.         return CROSSHAIRSIZE;
  10082.         }
  10083.         if( strcmp(input_type, arrowhead) == 0 ){
  10084.         free(input_type);
  10085.         return ARROWHEAD;
  10086.         }
  10087.         if( strcmp(input_type, crosshairs) == 0 ){
  10088.         free(input_type);
  10089.         return CROSSHAIRS;
  10090.         }
  10091.         if( strcmp(input_type, crosshair) == 0 ){
  10092.         free(input_type);
  10093.         return CROSSHAIR;
  10094.         }
  10095.         if( strcmp(input_type, onclick) == 0 ){
  10096.         free(input_type);
  10097.         return ONCLICK;
  10098.         }
  10099.         if( strcmp(input_type, drag) == 0 ){
  10100.         free(input_type);
  10101.         return DRAG;
  10102.         }
  10103.         if( strcmp(input_type, userdraw) == 0 ){
  10104.         free(input_type);
  10105.         return USERDRAW;
  10106.         }
  10107.         if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
  10108.         free(input_type);
  10109.         return STYLE;
  10110.         }
  10111.         if( strcmp(input_type, fillcolor) == 0 ){
  10112.         free(input_type);
  10113.         return FILLCOLOR;
  10114.         }
  10115.         if( strcmp(input_type, strokecolor) == 0 ){
  10116.         free(input_type);
  10117.         return STROKECOLOR;
  10118.         }
  10119.         if( strcmp(input_type, filled) == 0 ){
  10120.         free(input_type);
  10121.         return FILLED;
  10122.         }
  10123.         if( strcmp(input_type, http) == 0 ){
  10124.         free(input_type);
  10125.         return HTTP;
  10126.         }
  10127.         if( strcmp(input_type, rays) == 0 ){
  10128.         free(input_type);
  10129.         return RAYS;
  10130.         }
  10131.         if( strcmp(input_type, lattice) == 0 ){
  10132.         free(input_type);
  10133.         return LATTICE;
  10134.         }
  10135.         if( strcmp(input_type, bgimage) == 0 ){
  10136.         free(input_type);
  10137.         return BGIMAGE;
  10138.         }
  10139.         if( strcmp(input_type, bgcolor) == 0 ){
  10140.         free(input_type);
  10141.         return BGCOLOR;
  10142.         }
  10143.         if( strcmp(input_type, backgroundimage) == 0 ){
  10144.         free(input_type);
  10145.         return BGIMAGE;
  10146.         }
  10147.         if( strcmp(input_type, text) == 0 ){
  10148.         free(input_type);
  10149.         return FLY_TEXT;
  10150.         }
  10151.         if( strcmp(input_type, textup) == 0 ){
  10152.         free(input_type);
  10153.         return FLY_TEXTUP;
  10154.         }
  10155.         if( strcmp(input_type, mouse) == 0 ){
  10156.         free(input_type);
  10157.         return MOUSE;
  10158.         }
  10159.         if( strcmp(input_type, mousex) == 0 ){
  10160.         free(input_type);
  10161.         return MOUSEX;
  10162.         }
  10163.         if( strcmp(input_type, mousey) == 0 ){
  10164.         free(input_type);
  10165.         return MOUSEY;
  10166.         }
  10167.         if( strcmp(input_type, mouse_degree) == 0 ){
  10168.         free(input_type);
  10169.         return MOUSE_DEGREE;
  10170.         }
  10171.         if( strcmp(input_type, mouse_display) == 0 ){
  10172.         free(input_type);
  10173.         return MOUSE_DISPLAY;
  10174.         }
  10175.         if( strcmp(input_type, mouseprecision) == 0 ){
  10176.         free(input_type);
  10177.         return MOUSE_PRECISION;
  10178.         }
  10179.         if( strcmp(input_type, precision) == 0 ){
  10180.         free(input_type);
  10181.         return MOUSE_PRECISION;
  10182.         }
  10183.         if( strcmp(input_type, curve) == 0 ){
  10184.         free(input_type);
  10185.         return CURVE;
  10186.         }
  10187.         if( strcmp(input_type, dcurve) == 0 ){
  10188.         use_dashed = TRUE;
  10189.         free(input_type);
  10190.         return CURVE;
  10191.         }
  10192.         if( strcmp(input_type, plot) == 0 ){
  10193.         free(input_type);
  10194.         return CURVE;
  10195.         }
  10196.         if( strcmp(input_type, dplot) == 0 ){
  10197.         use_dashed = TRUE;
  10198.         free(input_type);
  10199.         return CURVE;
  10200.         }
  10201.         if( strcmp(input_type, levelcurve) == 0 ){
  10202.         free(input_type);
  10203.         return LEVELCURVE;
  10204.         }
  10205.         if( strcmp(input_type, plotsteps) == 0 ){
  10206.         free(input_type);
  10207.         return PLOTSTEPS;
  10208.         }
  10209.         if( strcmp(input_type, plotstep) == 0 ){
  10210.         free(input_type);
  10211.         return PLOTSTEPS;
  10212.         }
  10213.         if( strcmp(input_type, tsteps) == 0 ){
  10214.         free(input_type);
  10215.         return PLOTSTEPS;
  10216.         }
  10217.         if( strcmp(input_type, fontsize) == 0 ){
  10218.         free(input_type);
  10219.         return FONTSIZE;
  10220.         }
  10221.         if( strcmp(input_type, fontcolor) == 0 ){
  10222.         free(input_type);
  10223.         return FONTCOLOR;
  10224.         }
  10225.         if( strcmp(input_type, arrow2) == 0 ){
  10226.         free(input_type);
  10227.         return ARROW2;
  10228.         }
  10229.         if( strcmp(input_type, darrow) == 0 ){
  10230.         free(input_type);
  10231.         use_dashed = TRUE;
  10232.         return ARROW;
  10233.         }
  10234.         if( strcmp(input_type, darrow2) == 0 ){
  10235.         free(input_type);
  10236.         use_dashed = TRUE;
  10237.         return ARROW2;
  10238.         }
  10239.         if( strcmp(input_type, arrows2) == 0 ){
  10240.         free(input_type);
  10241.         return ARROWS2;
  10242.         }
  10243.         if( strcmp(input_type, arrows) == 0  || strcmp(input_type, vectors) == 0 ){
  10244.         free(input_type);
  10245.         return ARROWS;
  10246.         }
  10247.         if( strcmp(input_type, arrow) == 0 ||  strcmp(input_type, vector) == 0 ){
  10248.         free(input_type);
  10249.         return ARROW;
  10250.         }
  10251.         if( strcmp(input_type, zoom) == 0 ){
  10252.         free(input_type);
  10253.         return ZOOM;
  10254.         }
  10255.         if( strcmp(input_type, triangle) == 0 ){
  10256.         free(input_type);
  10257.         return TRIANGLE;
  10258.         }
  10259.         if( strcmp(input_type, triangles) == 0 ){
  10260.         free(input_type);
  10261.         return TRIANGLES;
  10262.         }
  10263.         if( strcmp(input_type, ftriangles) == 0 ){
  10264.         free(input_type);
  10265.         use_filled = TRUE;
  10266.         return TRIANGLES;
  10267.         }
  10268.         if( strcmp(input_type, ftriangle) == 0 ){
  10269.         free(input_type);
  10270.         use_filled = TRUE;
  10271.         return TRIANGLE;
  10272.         }
  10273.         if( strcmp(input_type, input) == 0 ){
  10274.         free(input_type);
  10275.         return INPUT;
  10276.         }
  10277.         if( strcmp(input_type, inputstyle) == 0 ){
  10278.         free(input_type);
  10279.         return INPUTSTYLE;
  10280.         }
  10281.         if( strcmp(input_type, textarea) == 0 ){
  10282.         free(input_type);
  10283.         return TEXTAREA;
  10284.         }
  10285.         if( strcmp(input_type, mathml) == 0 ){
  10286.         free(input_type);
  10287.         return MATHML;
  10288.         }
  10289.         if( strcmp(input_type, html) == 0 ){
  10290.         free(input_type);
  10291.         return MATHML;
  10292.         }
  10293.         if( strcmp(input_type, fontfamily) == 0 ){
  10294.         free(input_type);
  10295.         return FONTFAMILY;
  10296.         }
  10297.         if( strcmp(input_type, polyline) == 0 ||  strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){
  10298.         free(input_type);
  10299.         return POLYLINE;
  10300.         }
  10301.         if( strcmp(input_type, lines) == 0 ){
  10302.         free(input_type);
  10303.         return LINES;
  10304.         }
  10305.         if( strcmp(input_type, rects) == 0){
  10306.         free(input_type);
  10307.         return RECTS;
  10308.         }
  10309.         if( strcmp(input_type, frects) == 0 ){
  10310.         free(input_type);
  10311.         use_filled = TRUE;
  10312.         return RECTS;
  10313.         }
  10314.         if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
  10315.         free(input_type);
  10316.         return RECT;
  10317.         }
  10318.         if( strcmp(input_type, square) == 0 ){
  10319.         free(input_type);
  10320.         return SQUARE;
  10321.         }
  10322.         if( strcmp(input_type, fsquare) == 0 ){
  10323.         free(input_type);
  10324.         use_filled = TRUE;
  10325.         return SQUARE;
  10326.         }
  10327.         if( strcmp(input_type, fsquares) == 0 ){
  10328.         free(input_type);
  10329.         use_filled = TRUE;
  10330.         return RECTS;
  10331.         }
  10332.         if( strcmp(input_type, roundrects) == 0 ){
  10333.         free(input_type);
  10334.         return ROUNDRECTS;
  10335.         }
  10336.         if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
  10337.         free(input_type);
  10338.         return ROUNDRECT;
  10339.         }
  10340.         if( strcmp(input_type, froundrects) == 0 ){
  10341.         free(input_type);
  10342.         use_filled = TRUE;
  10343.         return ROUNDRECTS;
  10344.         }
  10345.         if( strcmp(input_type, froundrect) == 0 ){
  10346.         free(input_type);
  10347.         use_filled = TRUE;
  10348.         return ROUNDRECT;
  10349.         }
  10350.         if( strcmp(input_type, dline) == 0 ){
  10351.         use_dashed = TRUE;
  10352.         free(input_type);
  10353.         return LINE;
  10354.         }
  10355.         if( strcmp(input_type, dvline) == 0 ){
  10356.         use_dashed = TRUE;
  10357.         free(input_type);
  10358.         return VLINE;
  10359.         }
  10360.         if( strcmp(input_type, dhline) == 0 ){
  10361.         use_dashed = TRUE;
  10362.         free(input_type);
  10363.         return HLINE;
  10364.         }
  10365.         if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0 ){
  10366.         free(input_type);
  10367.         return HALFLINES;
  10368.         }
  10369.         if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0 ){
  10370.         free(input_type);
  10371.         return HALFLINE;
  10372.         }
  10373.         if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
  10374.         use_filled = TRUE;
  10375.         free(input_type);
  10376.         return RECT;
  10377.         }
  10378.         if( strcmp(input_type, circles) == 0 ){
  10379.         free(input_type);
  10380.         return CIRCLES;
  10381.         }
  10382.         if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
  10383.         use_filled = TRUE;
  10384.         free(input_type);
  10385.         return CIRCLE;
  10386.         }
  10387.         if( strcmp(input_type, fcircles) == 0  ||  strcmp(input_type, disks) == 0 ){
  10388.         use_filled = TRUE;
  10389.         free(input_type);
  10390.         return CIRCLES;
  10391.         }
  10392.         if( strcmp(input_type, circle) == 0 ){
  10393.         free(input_type);
  10394.         return CIRCLE;
  10395.         }
  10396.         if( strcmp(input_type, point) == 0 ){
  10397.         free(input_type);
  10398.         return POINT;
  10399.         }
  10400.         if( strcmp(input_type, points) == 0 ){
  10401.         free(input_type);
  10402.         return POINTS;
  10403.         }
  10404.         if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){
  10405.         use_filled = TRUE;
  10406.         free(input_type);
  10407.         return ARC;
  10408.         }
  10409.         if( strcmp(input_type, arc) == 0 ){
  10410.         free(input_type);
  10411.         return ARC;
  10412.         }
  10413.         if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
  10414.         free(input_type);
  10415.         return POLY;
  10416.         }
  10417.         if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
  10418.         use_filled = TRUE;
  10419.         free(input_type);
  10420.         return POLY;
  10421.         }
  10422.         if( strcmp(input_type, ellipse) == 0){
  10423.         free(input_type);
  10424.         return ELLIPSE;
  10425.         }
  10426.         if( strcmp(input_type, ellipses) == 0){
  10427.         free(input_type);
  10428.         return ELLIPSES;
  10429.         }
  10430.         if( strcmp(input_type, string) == 0 ){
  10431.         free(input_type);
  10432.         return STRING;
  10433.         }
  10434.         if( strcmp(input_type, stringup) == 0 ){
  10435.         free(input_type);
  10436.         return STRINGUP;
  10437.         }
  10438.         if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){
  10439.         free(input_type);
  10440.         return OPACITY;
  10441.         }
  10442.         if( strcmp(input_type, comment) == 0){
  10443.         free(input_type);
  10444.         return COMMENT;
  10445.         }
  10446.         if( strcmp(input_type, fellipse) == 0){
  10447.         free(input_type);
  10448.         use_filled = TRUE;
  10449.         return ELLIPSE;
  10450.         }
  10451.         if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){
  10452.         free(input_type);
  10453.         return CLEARBUTTON;
  10454.         }
  10455.         if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0 ){
  10456.         free(input_type);
  10457.         return TRANSLATION;
  10458.         }
  10459.         if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
  10460.         free(input_type);
  10461.         return KILLTRANSLATION;
  10462.         }
  10463.         if( strcmp(input_type, rotate) == 0){
  10464.         free(input_type);
  10465.         return ROTATE;
  10466.         }
  10467.         if( strcmp(input_type, killrotate) == 0){
  10468.         free(input_type);
  10469.         return KILLROTATE;
  10470.         }
  10471.         if( strcmp(input_type, rotationcenter) == 0){
  10472.         free(input_type);
  10473.         return ROTATION_CENTER;
  10474.         }
  10475.         if( strcmp(input_type, affine) == 0){
  10476.         free(input_type);
  10477.         return AFFINE;
  10478.         }
  10479.         if( strcmp(input_type, killaffine) == 0){
  10480.         free(input_type);
  10481.         return KILLAFFINE;
  10482.         }
  10483.         if( strcmp(input_type, slider) == 0 ){
  10484.         free(input_type);
  10485.         return SLIDER;
  10486.         }
  10487.         if( strcmp(input_type, killslider) == 0 ){
  10488.         free(input_type);
  10489.         return KILLSLIDER;
  10490.         }
  10491.         if( strcmp(input_type, copy) == 0 ){
  10492.         free(input_type);
  10493.         return COPY;
  10494.         }
  10495.         if( strcmp(input_type, copyresized) == 0 ){
  10496.         free(input_type);
  10497.         return COPYRESIZED;
  10498.         }
  10499.         if( strcmp(input_type, xlogscale) == 0 ){
  10500.         free(input_type);
  10501.         return XLOGSCALE;
  10502.         }
  10503.         if( strcmp(input_type, ylogscale) == 0 ){
  10504.         free(input_type);
  10505.         return YLOGSCALE;
  10506.         }
  10507.         if( strcmp(input_type, xylogscale) == 0 ){
  10508.         free(input_type);
  10509.         return XYLOGSCALE;
  10510.         }
  10511.         if( strcmp(input_type, ylogscale) == 0 ){
  10512.         free(input_type);
  10513.         return YLOGSCALE;
  10514.         }
  10515.         if( strcmp(input_type, xlogbase) == 0 ){
  10516.         free(input_type);
  10517.         return XLOGBASE;
  10518.         }
  10519.         if( strcmp(input_type, ylogbase) == 0 ){
  10520.         free(input_type);
  10521.         return YLOGBASE;
  10522.         }
  10523.         if( strcmp(input_type, intooltip) == 0 ){
  10524.         free(input_type);
  10525.         return INTOOLTIP;
  10526.         }
  10527.         if( strcmp(input_type, popup) == 0 ){
  10528.         free(input_type);
  10529.         return POPUP;
  10530.         }
  10531.         if( strcmp(input_type,video) == 0 ){
  10532.         free(input_type);
  10533.         return VIDEO;
  10534.         }
  10535.         if( strcmp(input_type,latex) == 0 ){
  10536.         free(input_type);
  10537.         return LATEX;
  10538.         }
  10539.         if( strcmp(input_type,fillall) == 0 ){
  10540.         free(input_type);
  10541.         return FILLALL;
  10542.         }
  10543.         if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
  10544.         free(input_type);
  10545.         return FLOODFILL;
  10546.         }
  10547.         if( strcmp(input_type,filltoborder) == 0 ){
  10548.         free(input_type);
  10549.         return FILLTOBORDER;
  10550.         }
  10551.         if( strcmp(input_type, curvedarrow2) == 0 ){
  10552.         free(input_type);
  10553.         return CURVEDARROW2;
  10554.         }
  10555.         if( strcmp(input_type, curvedarrow) == 0 ){
  10556.         free(input_type);
  10557.         return CURVEDARROW;
  10558.         }
  10559.         if( strcmp(input_type, curvedarrows) == 0 ){
  10560.         free(input_type);
  10561.         return CURVEDARROWS;
  10562.         }
  10563.         if( strcmp(input_type, curvedarrows2) == 0 ){
  10564.         free(input_type);
  10565.         return CURVEDARROWS2;
  10566.         }
  10567.         if( strcmp(input_type, replyformat) == 0 ){
  10568.         free(input_type);
  10569.         return REPLYFORMAT;
  10570.         }
  10571.         if( strcmp(input_type, pixelsize) == 0 ){
  10572.         free(input_type);
  10573.         return PIXELSIZE;
  10574.         }
  10575.         if( strcmp(input_type, setpixel) == 0 ){
  10576.         free(input_type);
  10577.         return SETPIXEL;
  10578.         }
  10579.         if( strcmp(input_type, pixels) == 0 ){
  10580.         free(input_type);
  10581.         return PIXELS;
  10582.         }
  10583.         if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
  10584.         free(input_type);
  10585.         return X_AXIS_STRINGS;
  10586.         }
  10587.         if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){
  10588.         free(input_type);
  10589.         return X_AXIS_STRINGS_UP;
  10590.         }
  10591.         if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
  10592.         free(input_type);
  10593.         return Y_AXIS_STRINGS;
  10594.         }
  10595.         if( strcmp(input_type, legend) == 0 ){
  10596.         free(input_type);
  10597.         return LEGEND;
  10598.         }
  10599.         if( strcmp(input_type, legendcolors) == 0 ){
  10600.         free(input_type);
  10601.         return LEGENDCOLORS;
  10602.         }
  10603.         if( strcmp(input_type, xlabel) == 0 ){
  10604.         free(input_type);
  10605.         return XLABEL;
  10606.         }
  10607.         if( strcmp(input_type, ylabel) == 0 ){
  10608.         free(input_type);
  10609.         return YLABEL;
  10610.         }
  10611.         if( strcmp(input_type, bezier) == 0 ){
  10612.         free(input_type);
  10613.         return BEZIER;
  10614.         }
  10615.         if( strcmp(input_type, animate) == 0 ){
  10616.         free(input_type);
  10617.         return ANIMATE;
  10618.         }
  10619.         /* these are bitmap related flydraw commands...must be removed. eventually */
  10620.         if( strcmp(input_type, transparent) == 0 ){
  10621.         free(input_type);
  10622.         return TRANSPARENT;
  10623.         }
  10624.         if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
  10625.         free(input_type);
  10626.         return STATUS;
  10627.         }
  10628.         if( strcmp(input_type, xsnaptogrid) == 0 ){
  10629.         free(input_type);
  10630.         return XSNAPTOGRID;
  10631.         }
  10632.         if( strcmp(input_type, ysnaptogrid) == 0 ){
  10633.         free(input_type);
  10634.         return YSNAPTOGRID;
  10635.         }
  10636.         if( strcmp(input_type, snaptogrid) == 0 ){
  10637.         free(input_type);
  10638.         return SNAPTOGRID;
  10639.         }
  10640.         if( strcmp(input_type, snaptopoints) == 0 ){
  10641.         free(input_type);
  10642.         return SNAPTOPOINTS;
  10643.         }
  10644.         if( strcmp(input_type, snaptofunction) == 0  || strcmp(input_type, snaptofun) == 0 ){
  10645.         free(input_type);
  10646.         return SNAPTOFUNCTION;
  10647.         }
  10648.         if( strcmp(input_type, userinput_xy) == 0 ){
  10649.         free(input_type);
  10650.         return USERINPUT_XY;
  10651.         }
  10652.         if( strcmp(input_type, userinput_function) == 0 ){
  10653.         free(input_type);
  10654.         return USERINPUT_FUNCTION;
  10655.         }
  10656.         if( strcmp(input_type, usertextarea_xy) == 0 ){
  10657.         free(input_type);
  10658.         return USERTEXTAREA_XY;
  10659.         }
  10660.         if( strcmp(input_type, userinput) == 0 ){
  10661.         free(input_type);
  10662.         return USERINPUT;
  10663.         }
  10664.         if( strcmp(input_type, angle) == 0 ){
  10665.         free(input_type);
  10666.         return ANGLE;
  10667.         }
  10668.         if( strcmp(input_type, functionlabel) == 0 ){
  10669.         free(input_type);
  10670.         return FUNCTION_LABEL;
  10671.         }
  10672.         if( strcmp(input_type, sliderfunction_x) == 0 ){
  10673.         free(input_type);
  10674.         return SLIDER_X;
  10675.         }
  10676.         if( strcmp(input_type, sliderfunction_y) == 0 ){
  10677.         free(input_type);
  10678.         return SLIDER_Y;
  10679.         }
  10680.         if( strcmp(input_type, multidraw) == 0 ){
  10681.         free(input_type);
  10682.         return MULTIDRAW;
  10683.         }
  10684.         if( strcmp(input_type, multistrokeopacity) == 0 ){
  10685.         free(input_type);
  10686.         return MULTISTROKEOPACITY;
  10687.         }
  10688.         if( strcmp(input_type, multifillopacity) == 0 ){
  10689.         free(input_type);
  10690.         return MULTIFILLOPACITY;
  10691.         }
  10692.         if( strcmp(input_type, multilinewidth) == 0 ||  strcmp(input_type, linewidths) == 0 ){
  10693.         free(input_type);
  10694.         return MULTILINEWIDTH;
  10695.         }
  10696.         if( strcmp(input_type, multistrokecolors) == 0 ||strcmp(input_type, multicolors) == 0 ||strcmp(input_type,colors) == 0 ){
  10697.         free(input_type);
  10698.         return MULTISTROKECOLORS;
  10699.         }
  10700.         if( strcmp(input_type, multifill) == 0 ){
  10701.         free(input_type);
  10702.         return MULTIFILL;
  10703.         }
  10704.         if( strcmp(input_type, multifillcolors) == 0 || strcmp(input_type, fillcolors) == 0 ){
  10705.         free(input_type);
  10706.         return MULTIFILLCOLORS;
  10707.         }
  10708.         if( strcmp(input_type, multilabel) == 0 ){
  10709.         free(input_type);
  10710.         return MULTILABEL;
  10711.         }
  10712.         if( strcmp(input_type, multidash) == 0 ){
  10713.         free(input_type);
  10714.         return MULTIDASH;
  10715.         }
  10716.         if( strcmp(input_type, multisnaptogrid) == 0  ||  strcmp(input_type, multisnap) == 0 ){
  10717.         free(input_type);
  10718.         return MULTISNAPTOGRID;
  10719.         }
  10720.         if( strcmp(input_type, multiuserinput) == 0 || strcmp(input_type, multiinput) == 0 ){
  10721.         free(input_type);
  10722.         return MULTIUSERINPUT;
  10723.         }
  10724.         if( strcmp(input_type, parallel) == 0 ){
  10725.         free(input_type);
  10726.         return PARALLEL;
  10727.         }
  10728.         if( strcmp(input_type, protractor) == 0 ){
  10729.         free(input_type);
  10730.         return PROTRACTOR;
  10731.         }
  10732.         if( strcmp(input_type, ruler) == 0 ){
  10733.         free(input_type);
  10734.         return RULER;
  10735.         }
  10736.         if( strcmp(input_type, cursor) == 0 ||  strcmp(input_type, pointer) == 0 ){
  10737.         free(input_type);
  10738.         return CURSOR;
  10739.         }
  10740.         if( strcmp(input_type, sgraph) == 0 ){
  10741.         free(input_type);
  10742.         return SGRAPH;
  10743.         }
  10744.         if( strcmp(input_type, jsmath) == 0 ){
  10745.         free(input_type);
  10746.         return JSMATH;
  10747.         }
  10748.         if( strcmp(input_type, trace_jscurve) == 0 ){
  10749.         free(input_type);
  10750.         return TRACE_JSCURVE;
  10751.         }
  10752.         if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
  10753.         free(input_type);
  10754.         return JSCURVE;
  10755.         }
  10756.         if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
  10757.         free(input_type);
  10758.         return CENTERSTRING;
  10759.         }
  10760.         if( strcmp(input_type, setlimits) == 0 ){
  10761.         free(input_type);
  10762.         return SETLIMITS;
  10763.         }
  10764.         if( strcmp(input_type, xunit) == 0 ){
  10765.         free(input_type);
  10766.         return XUNIT;
  10767.         }
  10768.         if( strcmp(input_type, yunit) == 0 ){
  10769.         free(input_type);
  10770.         return YUNIT;
  10771.         }
  10772.         if( strcmp(input_type, fill) == 0 ){
  10773.         free(input_type);
  10774.         return FLOODFILL;
  10775.         }
  10776.         if( strcmp(input_type, end) == 0){
  10777.         free(input_type);
  10778.         return END;
  10779.         }
  10780.         if( strcmp(input_type, blink) == 0 ){
  10781.         free(input_type);
  10782.         return BLINK;
  10783.         }
  10784.         if( strcmp(input_type, audio) == 0 ){
  10785.         free(input_type);
  10786.         return AUDIO;
  10787.         }
  10788.         if( strcmp(input_type, audioobject) == 0 ){
  10789.         free(input_type);
  10790.         return AUDIOOBJECT;
  10791.         }
  10792.         if( strcmp(input_type, patternfill) == 0 ){
  10793.         free(input_type);
  10794.         return PATTERNFILL;
  10795.         }
  10796.         if( strcmp(input_type, hatchfill) == 0 ){
  10797.         free(input_type);
  10798.         return HATCHFILL;
  10799.         }
  10800.         if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0 ){
  10801.         free(input_type);
  10802.         return DIAMONDFILL;
  10803.         }
  10804.         if( strcmp(input_type, dotfill) == 0 ){
  10805.         free(input_type);
  10806.         return DOTFILL;
  10807.         }
  10808.         if( strcmp(input_type, textfill) == 0 ){
  10809.         free(input_type);
  10810.         return TEXTFILL;
  10811.         }
  10812.         if( strcmp(input_type, gridfill) == 0 ){
  10813.         free(input_type);
  10814.         return GRIDFILL;
  10815.         }
  10816.         if( strcmp(input_type, imagefill) == 0 ){
  10817.         free(input_type);
  10818.         return IMAGEFILL;
  10819.         }
  10820.         if( strcmp(input_type, clicktile_colors) == 0 ){
  10821.         free(input_type);
  10822.         return CLICKTILE_COLORS;
  10823.         }
  10824.         if( strcmp(input_type, clicktile) == 0 ){
  10825.         free(input_type);
  10826.         return CLICKTILE;
  10827.         }
  10828.         if( strcmp(input_type, piechart) == 0 ){
  10829.         free(input_type);
  10830.         return PIECHART;
  10831.         }
  10832.         if( strcmp(input_type, boxplot) == 0 ){
  10833.         free(input_type);
  10834.         return BOXPLOT;
  10835.         }
  10836.         if( strcmp(input_type, boxplotdata) == 0 ){
  10837.         free(input_type);
  10838.         return BOXPLOTDATA;
  10839.         }
  10840.         if( strcmp(input_type, userboxplot) == 0 ){
  10841.         free(input_type);
  10842.         return USERBOXPLOT;
  10843.         }
  10844.         if( strcmp(input_type, userboxplotdata) == 0 ){
  10845.         free(input_type);
  10846.         return USERBOXPLOT;
  10847.         }
  10848.         if( strcmp(input_type, barchart) == 0 ){
  10849.         free(input_type);
  10850.         return BARCHART;
  10851.         }
  10852.         if( strcmp(input_type, linegraph) == 0 ){
  10853.         free(input_type);
  10854.         return LINEGRAPH;
  10855.         }
  10856.         if( strcmp(input_type, clock) == 0 ){
  10857.         free(input_type);
  10858.         return CLOCK;
  10859.         }
  10860.         if( strcmp(input_type, yerrorbars) == 0 ){
  10861.         free(input_type);
  10862.         return YERRORBARS;
  10863.         }
  10864.         if( strcmp(input_type, xerrorbars) == 0 ){
  10865.         free(input_type);
  10866.         return XERRORBARS;
  10867.         }
  10868.         if( strcmp(input_type, canvastype) == 0 ){
  10869.         free(input_type);
  10870.         return CANVASTYPE;
  10871.         }
  10872.         if( strcmp(input_type, noyaxis) == 0 ){
  10873.         free(input_type);
  10874.         return NOYAXIS;
  10875.         }
  10876.         if( strcmp(input_type, noxaxis) == 0 ){
  10877.         free(input_type);
  10878.         return NOXAXIS;
  10879.         }
  10880.         if( strcmp(input_type, colorpalette) == 0 ){
  10881.         free(input_type);
  10882.         return COLORPALETTE;
  10883.         }
  10884.         if( strcmp(input_type, imagepalette) == 0 ){
  10885.         free(input_type);
  10886.         return IMAGEPALETTE;
  10887.         }
  10888.         if( strcmp(input_type, resetoffset) == 0 ){
  10889.         free(input_type);
  10890.         return RESETOFFSET;
  10891.         }
  10892.         if( strcmp(input_type, xyoffset) == 0 ){
  10893.         free(input_type);
  10894.         return XYOFFSET;
  10895.         }
  10896.         if( strcmp(input_type, centered) == 0 ){
  10897.         free(input_type);
  10898.         return CENTERED;
  10899.         }
  10900.         if( strcmp(input_type, yoffset) == 0 ){
  10901.         free(input_type);
  10902.         return YOFFSET;
  10903.         }
  10904.         if( strcmp(input_type, xoffset) == 0 ){
  10905.         free(input_type);
  10906.         return XOFFSET;
  10907.         }
  10908.         if( strcmp(input_type, fillpattern) == 0 ){
  10909.         free(input_type);
  10910.         return FILLPATTERN;
  10911.         }
  10912.         if( strcmp(input_type, numberline) == 0 ){
  10913.         free(input_type);
  10914.         return NUMBERLINE;
  10915.         }
  10916.         if( strcmp(input_type, duplicates) == 0 || strcmp(input_type, allowdups) == 0 ){
  10917.         free(input_type);
  10918.         return ALLOW_DUPLICATES;
  10919.         }
  10920.         free(input_type);
  10921.         ungetc(c,infile);
  10922.         return 0;
  10923. }
  10924.  
  10925.