Subversion Repositories wimsdev

Rev

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

  1. /*27/7/2013 version  0.01
  2. "Inspired" by FLY program: http://martin.gleeson.com/fly
  3. *********************************************************************************
  4. * J.M. Evers 7/2013        *
  5. * This is all just amateur scriblings... So no copyrights.      *
  6. * This source code file, and compiled objects derived from it,      *
  7. * can be used and distributed without restriction, including for commercial use  *
  8. * No warrenty whatsoever      *
  9. *********************************************************************************
  10. */
  11. #define VERSION    "0.5"
  12.  
  13. #define _GNU_SOURCE
  14. #include <string.h>
  15.  
  16. #include "canvasdraw.h"
  17. void *tmp_buffer;
  18. FILE  *js_include_file;
  19. /******************************************************************************
  20. **  Internal Functions
  21. ******************************************************************************/
  22. void  add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */
  23. void  sync_input(FILE *infile);/* proceed with inputfile */
  24. void  reset();/* reset some global variables like "use_filled", "use_dashed" */
  25. int  get_token(FILE *infile); /* read next char until EOL*/
  26. /*
  27. int   x2px(double x);
  28. int   y2px(double y);
  29. */
  30. double   px2x(int x);
  31. double   px2y(int y);
  32. double  get_real(FILE *infile,int last); /* read a value; calculation and symbols allowed */
  33. char  *str_replace ( const char *word, const char *sub_word, const char *rep_word );
  34. char   *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */
  35. char  *get_string(FILE *infile,int last); /* get the string at the end of a command */
  36. char  *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as  separator */
  37. char   *convert_hex2rgb(char *hexcolor);
  38. void  make_js_include(int canvas_root_id);
  39. void  check_string_length(int length);/* checks if the length of string argument of command is correct */
  40. FILE   *js_include_file;
  41. FILE  *get_file(int *line_number, char **filename);
  42. FILE   *infile;    /* will be stdin */
  43. /******************************************************************************
  44. ** global
  45. ******************************************************************************/
  46. int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */
  47. int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */
  48. /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */
  49. int xsize = 320;
  50. int ysize = 320;
  51. double xmin = 0.0;
  52. double xmax = 320.0;
  53. double ymin = 0.0;
  54. double ymax = 320.0;
  55. double tmax = 0;
  56. double tmin = 0;
  57. /* flag to indicate parsing of line status */
  58. int done = FALSE;
  59. int type; /* eg command number */
  60. int onclick = 0;
  61. /*
  62. 0 = noninteractive ;
  63. 1 = onclick ;
  64. 2 = draggable ;
  65. 3 = click+slideable ;
  66. 4 = slideable without click
  67. 5 = draggable + slideable
  68. */
  69. char *slider_type="0";
  70. char *my_sliders = "[-1]";
  71. int use_slider = -1;
  72. int last_slider = 0;
  73. double double_data[MAX_INT+1];
  74. int int_data[MAX_INT+1];
  75. int dragstuff[MAX_DRAGSTUFF];
  76. int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis: only once per object type */
  77. double affine_matrix[] = {1,0,0,1,0,0};
  78. int use_affine = FALSE;
  79. int use_rotate = FALSE;
  80. int use_filled = 0; /* 0:no fill, 1:fill,2=grid?,3=hatch?,4=diamond?,5=dot?,6=image? */
  81. int use_dashed = FALSE; /* dashing not natively supported in firefox, for now... */
  82. double angle = 0.0;
  83. char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */
  84. char *getfile_cmd = "";
  85. int reply_format = 0;
  86. unsigned int canvas_root_id;
  87. char *css_class;
  88. int font_size;
  89. char *draw_type;
  90. int jsplot_cnt = -1;     /* keepint track on the curve identity */
  91. int input_cnt = 0;
  92. int dashtype[2] = { 4 , 4 }; /* just line_px and space_px: may have more arguments...if needed in future */
  93. char *function_label = "[\"f(x)=\",\"g(x)=\",\"h(x)=\"]";
  94. int drag_type = -1;/* 0,1,2: xy,x,y */
  95. int use_offset = 0;/* use_offset only for text shape objects... 0=none;1=yoffset;2=xoffset;3=xyoffset;4=centered*/
  96. int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
  97. int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/
  98. int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc  */
  99. int use_axis = FALSE;
  100. int use_axis_numbering = -1;
  101. int no_reset = FALSE;
  102.  
  103. /******************************************************************************
  104. ** Main Program
  105. ******************************************************************************/
  106. int main(int argc, char *argv[]){
  107.   /* need unique id for every call to canvasdraw: rand(); is too slow...will result in many identical id's */
  108.   struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);
  109.   canvas_root_id = (unsigned int) tv.tv_usec;
  110.   infile = stdin;/* read flyscript via stdin */
  111.   int i,c;
  112.   for(i=0;i<MAX_DRAGSTUFF;i++){dragstuff[i] = 0;}
  113.   for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;}
  114.   int use_snap = 0; /* 0 = none 1=grid: 2=x-grid: 3=y-grid: 4=snap to points */
  115.   int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */
  116.   int line_width = 1;
  117.   int decimals = 2;
  118.   int use_dragstuff = 0;
  119.   int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */
  120.   int use_userdraw = 0; /* 0=none,1=userdraw,2=multidraw flag to indicate user interaction */
  121.   int use_tooltip = -1; /* 1= tooltip 2= popup window*/
  122.   int use_parametric = FALSE;/* will be reset after parametric plotting */
  123.   char *tooltip_text = "Click here";
  124.   char *temp = ""; /* */
  125.   char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
  126.   char *stroke_color = "255,0,0";
  127.   char *fill_color = "255,255,255";
  128.   char *font_family = "12px Arial"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
  129.   char *font_color = "#00000";
  130.   draw_type = "points";
  131.   char *fly_font = "normal";
  132.   css_class = "none";
  133.   char *flytext = "";
  134.   int canvas_type = DRAG_CANVAS; /* to use a specific canvas  for filling etc */
  135.   int pixelsize = 1;
  136.   int fill_cnt = 0;
  137.   int use_zoom = 0;
  138.   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 !! */
  139.   int fly_font_size = 12; /*fly_font_size is relative to this... */
  140.   for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
  141.   int arrow_head = 8; /* size in px needed for arrow based  userdraw:  "userdraw arrow,color" */
  142.   int crosshair_size = 5; /* size in px*/
  143.   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  */
  144.   int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange: just to flag an error message */
  145.   int object_cnt = 0; /*counter to identify the "onclick" ojects ; 0 is first object set onclick: reply[object_cnt]=1 when clicked ; otherwise reply[object_cnt]=0 ; object_cnt is only increased when another object is set  again */
  146.   int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
  147.   int boxplot_cnt = 0;
  148.   int drawxml_cnt = 0;
  149.   int numberline_cnt = 0;
  150.   int snap_to_points_cnt = 0;
  151.   int reply_precision = 100; /* used for precision of student answers / drawings */
  152.   char *rotation_center = "null";/* needs to be removed... but is used for canvas CTX based rotation*/
  153.   double rotationcenter[] = {0,0}; /* use for recalculating x/y values on rotation() */
  154.   int use_animate = 0; /* used for jscurve / js parametric  */
  155.   int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/
  156.   size_t string_length = 0; /* measure the size of the user input fly-string */
  157.   double stroke_opacity = 0.8; /* use some opacity as default */
  158.   double fill_opacity = 0.5;/* use some opacity as default */
  159.   char *URL = "http://localhost/images";
  160.   memset(buffer,'\0',MAX_BUFFER);
  161.   void *tmp_buffer = "";
  162.   /* default writing a unzipped js-include file into wims getfile directory */
  163.   char *w_wims_session = getenv("w_wims_session");
  164.   if( w_wims_session == NULL || *w_wims_session == 0 ){canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");}
  165.   int L0=strlen(w_wims_session) + 21;
  166.   char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
  167.   snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
  168.   mode_t process_mask = umask(0); /* check if file exists */
  169.   int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
  170.   if( result == 0 || errno == EEXIST ){
  171.     umask(process_mask); /* be sure to set correct permission */
  172.     char *w_session = getenv("w_session");
  173.     int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
  174.     getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
  175.     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 */
  176.     /* write the include tag to html page:<script src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
  177.     /* now write file into getfile dir*/
  178.     char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims": we need absolute path for location */
  179.     int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
  180.     char *location = my_newmem(L2); /* create memory to fit string precisely */
  181.     snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
  182.     js_include_file = fopen(location,"w");/* open the file location for writing */
  183.     /* check on opening...if nogood: mount readonly? disk full? permissions not set correctly? */
  184.     if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN: could not write to javascript include file...check your system logfiles !" );}
  185.  
  186. /* ----------------------------------------------------- */
  187.  
  188. /*  while more lines to process */
  189.  
  190.     while(!finished){
  191.       if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
  192.       type = get_token(infile);
  193.       done = FALSE;
  194.   /*
  195.   @ canvasdraw
  196.   @ Canvasdraw will try use the same basic syntax structure as flydraw
  197.   @ General syntax <ul><li>The transparency of all objects can be controlled by command <a href="#opacity">opacity [0-255],[0,255]</a></li><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>please note: dashing may have different spacing depending on the angle of the line<br>see https://wimsedu.info/?topic=dashed-arrows-not-dashed-in-canvasdraw</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>note: do not use a <b>f</b> with this non-solid pattern filling !<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>object x1,y1,...,color</code></li><li><code>objects color,x1,y1,...</code></li></ul><li>All inputfields or textareas generated, can be styled individually using command <a href="#css">css 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>
  198.   @ 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 + "newline";<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> <br>(*) Note: the speed advantage over <em>canvas-do-it-all</em> libraries is reduced to zero, when multiple canvasdraw scripts are present in a single page...<br>For example a typical canvasdraw script is between 5 and 40 kB...a large library like JSXgraph is approx 600 kB<br>In these cases it would be much faster to load a static general HTML5 canvas javascript draw library and parse it multiple raw fly instructions !<br>
  199.   @ Canvasdraw can be used 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...)
  200.   @ 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>
  201.   @ 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>.
  202.   @ 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.
  203.   @ Be aware that combining several different objects and interactivity may lead to problems.
  204.   @ 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.
  205.   @ There is limited support for touch devices: touchstart, touchmove and touchend in commands <a href="#userdraw">userdraw primitives </a>, <a href="#multidraw">multidraw primitives </a>, <a href="#protractor">protractor</a>, <a href="#ruler">ruler</a> and probably a few others... <br>Only single finger gestures are supported (for now).<br>The use of a special pen is advised for interactive drawing on touch devices.<br>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>.
  206.   */
  207.       switch(type){
  208.         case END:finished = 1;done = TRUE;break;
  209.         case 0:sync_input(infile);break;
  210.         case AFFINE:
  211.   /*
  212.    @ affine a,b,c,d,tx,ty
  213.    @ defines a transformation matrix for subsequent objects
  214.    @ use keyword <a href='#killaffine'>killaffine</a> to end the transformation...the next objects will be drawn in the original x/y-range
  215.    @ a: Scales the drawings horizontally
  216.    @ b: Skews the drawings horizontally
  217.    @ c: Skews the drawings vertically
  218.    @ d: Scales the drawings vertically
  219.    @ tx: Moves the drawings horizontally in xrange coordinate system
  220.    @ ty: Moves the drawings vertically in yrange coordinate system
  221.    @ the data precision may be set by preceding command ''precision int``
  222.    @ <b>note</b>: not all affine operations on canvasdraw objects will be identical to flydraw's behaviour. Make sure to check !
  223.    @%affine%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%#use larger linewith to improve selecting a draggable object !%linewidth 4%drag xy%frect 0,5,3,3,red%affine cos(pi/4),sin(pi/4),-cos(pi/2),sin(pi/2),-5,-5%drag xy%frect 0,5,3,3,red
  224.    @%affine+latex%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%strokecolor blue%fontfamily 42px Arial%centered%drag xy%latex 5,5,\\frac{123}{\\pi^{234}}%affine cos(pi/4),sin(pi/4),-cos(pi/2),sin(pi/2),-5,-5%drag xy%latex 5,5,\\frac{123}{\\pi^{234}}
  225.   */
  226.           for(i = 0 ; i<6;i++){
  227.             switch(i){
  228.               case 0: affine_matrix[0] = get_real(infile,0);break;
  229.               case 1: affine_matrix[1] = get_real(infile,0);break;
  230.               case 2: affine_matrix[2] = get_real(infile,0);break;
  231.               case 3: affine_matrix[3] = get_real(infile,0);break;
  232.               case 4: affine_matrix[4] = get_real(infile,0);break;
  233.               case 5: affine_matrix[5] = get_real(infile,1);
  234.               use_affine = TRUE;
  235.               break;
  236.               default: break;
  237.             }
  238.           }
  239.           break;
  240.         case ALLOW_DUPLICATES:
  241.         /*
  242.          @ duplicates || allowdups
  243.          @ keyword (no arguments)
  244.          @ only useful in case of a <a href="#multidraw">multidraw</a> student reply.
  245.          @ only useful in default <a href="#replyformat">replyformat</a> (eg in case of a not specified replyformat).
  246.          @ if set, duplicate (x:y) coordinates will not be removed from the student reply.
  247.          @ technical: a javascript variable "allow_duplicate_answer = 1;" is declared.
  248.          @ default for command multidraw is: removal of duplicates.
  249.         */
  250.           fprintf(js_include_file,"var allow_duplicate_answers = 1;");
  251.           break;
  252.         case ANGLE:
  253.         /*
  254.          @ angle xc,yc,width,start_angle,end_angle,color
  255.          @ width is in x-range
  256.          @ angles are in degrees
  257.          @ not compatible with ''flydraw``
  258.          @ will zoom in/out
  259.          @ may be set onclick or drag&amp;drop
  260.          @ if angle size is controlled by command <a href='#slider'>slider</a>, use radians to set limits of slider
  261.          @ ''angle`` and <a href="#arc">arc</a>  are exceptions in case of sliders...they are always active (e.g. not click-activated)
  262.          @%angle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%angle 0,0,4,10,135,blue
  263.         @%angle_slider%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%strokecolor blue%slider -2*pi,2*pi,260,28,angle active degree,blue arrow%arrow 0,0,8,0,8,blue%fillpattern diamond%angle 0,0,2,0,0,blue%killslider%strokecolor red%slider -2*pi,2*pi,260,28,angle active radian,red arrow%arrow 0,1,8,1,8,red%fillpattern dot%angle 0,1,2,0,0,red
  264.         */
  265.           for(i=0;i<7;i++){
  266.             switch(i){
  267.               case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  268.               case 1:double_data[1] = get_real(infile,0);
  269.               if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  270.               if(use_affine == TRUE ){ transform(2,2);}
  271.               break; /* y-values */
  272.               case 2:double_data[2] = get_real(infile,0);break; /* width x-range ! */
  273.               case 3:double_data[3] = 0.0174532925*(get_real(infile,0) - angle);break; /* start angle in degrees -> radians  */
  274.               case 4:double_data[4] = 0.0174532925*(get_real(infile,0) - angle);break; /* end angle in degrees -> radians */
  275.               case 5:stroke_color = get_color(infile,1);/* name or hex color */
  276.               if( use_slider != -1 ){ onclick = 3; }/* always active in case of slider */
  277.               decimals = find_number_of_digits(precision);
  278.               string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  279.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  280.               snprintf(tmp_buffer,string_length,  "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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  281.               add_to_buffer(tmp_buffer);
  282.               dragstuff[17] = 1;
  283.               if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  284.               if(onclick != 0){object_cnt++;}/* object_cnt++;*/
  285.               break;
  286.             }
  287.           }
  288.           break;
  289.         case ANIMATE:
  290.   /*
  291.    @ animate
  292.    @ keyword
  293.    @ if set, it will animate a point on a curve
  294.    @ all other canvas object or group of objects (like lines,circles,rects,points...images,svg,latex,mathml etc)<br>may be animated using command <a href='#slider'>slider</a> with keyword 'anim'
  295.    @ the animated point is a filled rectangle ; adjust colour with command <code>fillcolor colorname/hexnumber</code>
  296.    @ use linewidth to adjust size of the points
  297.    @ 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
  298.    @ only usable in combination with command <a href='#jsplot'>jsplot</a> (normal functions or parametric)
  299.    @ 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>
  300.    @ use commands <a href='#multilinewidth'>multilinewidth</a>, <a href='#multistrokecolor'>multistrokecolor</a> etc in case of multiple animated functions.<br>use multiple functions as argument in a single call to <a href='#jsplot'>jsplot color,fun1,fun2,fun3...fun_n</a>
  301.    @%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)
  302.    @%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
  303.   */
  304.           use_animate++;
  305.           if( use_animate == 1 ){
  306.             fprintf(js_include_file,"\nvar trace_canvas  = create_canvas%d(%d,xsize,ysize);\
  307.              var trace_ctx = trace_canvas.getContext('2d');\
  308.              trace_ctx.fillStyle = 'rgba(%s,%f)';\
  309.              trace_ctx.strokeStyle = 'rgba(%s,%f)';\
  310.              trace_ctx.lineWidth = %d;var anim_pos = 0;\n\
  311.              function animate_this(){\
  312.              var sync;\
  313.              var synchrone = Math.floor(animation_steps/animation_funs);\
  314.              trace_ctx.clearRect(0,0,xsize,ysize);\
  315.              for(var p=0; p<animation_funs;p++){\
  316.               sync = p*synchrone;\
  317.               trace_ctx.fillRect(x_anim_points[sync+anim_pos]-%d, y_anim_points[sync+anim_pos]-%d,%d,%d);\
  318.              };\
  319.              setTimeout(function(){\
  320.               requestAnimationFrame(animate_this);  anim_pos++;}, 50\
  321.              );\
  322.              if(anim_pos >= animation_steps){anim_pos = 0;};\
  323.              };",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);
  324.           } else {
  325.             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)");
  326.           }
  327.           break;
  328.         case ARC:
  329.   /*
  330.    @ arc xc,yc,x-width,y-height,start_angle,end_angle,color
  331.    @ may be set ''onclick`` or ''drag xy``
  332.    @ compatible with ''flydraw``
  333.    @ attention: width &amp; height in x/y-range
  334.    @ for arrow hats on an arc, see  command <a href='#arcarrow'>arcarrow or arrowarc</a>
  335.    @ better use command <a href='#angle'>angle</a> for use with a <a href='#slider'>slider</a>
  336.    @%arc%size 400,400%xrange -10,10%yrange -10,10%arc 0,0,4,4,10,135,red
  337.    @%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
  338.   */
  339.           for(i=0;i<7;i++){
  340.             switch(i){
  341.               case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  342.               case 1:double_data[1] = get_real(infile,0);
  343.               if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  344.               if(use_affine == TRUE ){ transform(4,2);}
  345.               break; /* y-values */
  346.               case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */
  347.               case 3:double_data[3] = get_real(infile,0);
  348.               break; /* height y-range no pixels ! */
  349.               case 4:double_data[4] = get_real(infile,0) - angle ;break; /* start angle in degrees */
  350.               case 5:double_data[5] = get_real(infile,0) - angle;break; /* end angle in degrees */
  351.               case 6:stroke_color = get_color(infile,1);/* name or hex color */
  352.         /* in Shape library:
  353.       x[0] = x[1] = xc = double_data[0]
  354.       y[0] = y[1] = yc = double_data[1]
  355.       w[0] = width = double_data[2]
  356.       w[1] = height = double_data[3]
  357.       h[0] = start_angle = double_data[4]
  358.       h[1] = end_angle = double_data[5]
  359.         */
  360.               if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  361.               decimals = find_number_of_digits(precision);
  362.               string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  363.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  364.               snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  365.               add_to_buffer(tmp_buffer);reset();
  366.               dragstuff[12] = 1;
  367.               if(onclick != 0){object_cnt++;}
  368.               if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  369.               break;
  370.             }
  371.           }
  372.           break;
  373.         case ARCARROW:
  374.   /*
  375.    @ arrowarc xc,yc,x-width,y-height,start_angle,end_angle,color,type
  376.    @ alternative: arcarrow
  377.    @ uses same syntax as <a href='#arc'>arc</a>
  378.    @ for arrow hat: type = 1 : right<br>type = 2 : left<br>type = 3 : left&amp;right
  379.    @ if the default arrow hat/head is not satisfactory , the size of the arrow may be set with command <a href='#arrowhead'>arrowhead</a>
  380.    @ no other arrow types are implemented...yet
  381.    @ may be set draggable or onclick
  382.    @ attention: when width ad height are very different, the arrow hat is not drawn correctly. This is a flaw and not a feature...(for now: too much calculations to correct)
  383.    @%arcarrow%size 400,400%xrange -10,10%yrange -10,10%noreset%onclick%arcarrow 0,0,7,7,50,275,blue,3%arcarrow 0,0,8,8,50,275,red,2%arcarrow 0,0,9,9,50,275,green,1
  384.   */
  385.           for(i=0;i<8;i++){
  386.             switch(i){
  387.               case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  388.               case 1:double_data[1] = get_real(infile,0);
  389.                 if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  390.                 if(use_affine == TRUE ){ transform(4,2);}
  391.                 break; /* y-values */
  392.               case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */
  393.               case 3:double_data[3] = get_real(infile,0);
  394.                 break; /* height y-range no pixels ! */
  395.               case 4:double_data[4] = get_real(infile,0) - angle ;break; /* start angle in degrees */
  396.               case 5:double_data[5] = get_real(infile,0) - angle;break; /* end angle in degrees */
  397.               case 6:stroke_color = get_color(infile,0);/* name or hex color */
  398.                 break;
  399.               case 7:int_data[0] = (int) get_real(infile,1);
  400.                 switch(int_data[0]){
  401.                   case 1: int_data[1] = 24;break; /* right */
  402.                   case 2: int_data[1] = 25;break; /* left */
  403.                   case 3: int_data[1] = 26;break; /* left&right */
  404.                   default:int_data[1] = 24;break;
  405.                 }
  406.               if(int_data[0] == 1 ){int_data[1] = 24;}
  407.               if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  408.               decimals = find_number_of_digits(precision);
  409.               string_length = 1 + snprintf(NULL,0,"var arrow_head = %d;dragstuff.addShape(new Shape(%d,%d,%d,%d,%d,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",arrow_head,drag_type,object_cnt,onclick,use_snap,int_data[1],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,my_sliders,rotation_center,use_offset);
  410.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  411.               snprintf(tmp_buffer,string_length,"var arrow_head = %d;dragstuff.addShape(new Shape(%d,%d,%d,%d,%d,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",arrow_head,drag_type,object_cnt,onclick,use_snap,int_data[1],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,my_sliders,rotation_center,use_offset);
  412.               add_to_buffer(tmp_buffer);
  413.               dragstuff[int_data[1]] = 1;
  414.               if(onclick != 0){object_cnt++;}
  415.               if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  416.               js_function[JS_ARROWHEAD] = 1;
  417.               reset();
  418.             }
  419.           }
  420.           break;
  421.         case ARROW:
  422.   /*
  423.   @ arrow x1,y1,x2,y2,h,color
  424.   @ alternative: vector
  425.   @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br>with arrowhead size h in px and in color ''color``
  426.   @ use command <code>linewidth int</code> to adjust thickness of the arrow
  427.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  428.   @%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
  429.   @%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
  430.   */
  431.           for(i=0;i<6;i++){
  432.             switch(i){
  433.               case 0: double_data[0] = get_real(infile,0);break; /* x */
  434.               case 1: double_data[1] = get_real(infile,0);break; /* y */
  435.               case 2: double_data[2] = get_real(infile,0);break; /* x */
  436.               case 3: double_data[3] = get_real(infile,0);break; /* y */
  437.               case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  438.               case 5: stroke_color = get_color(infile,1);/* name or hex color */
  439.                 if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);}
  440.                 if(use_affine == TRUE ){ transform(4,2);}
  441.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  442.                 decimals = find_number_of_digits(precision);
  443.                 string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  444.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  445.                 snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  446.                 if(onclick != 0){object_cnt++;}
  447.           /* object_cnt++;*/
  448.                 add_to_buffer(tmp_buffer);reset();
  449.                 dragstuff[8] = 1;
  450.                 if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  451.               break;
  452.             }
  453.           }
  454.           break;
  455.         case ARROWS:
  456.   /*
  457.   @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n
  458.   @ alternative: vectors
  459.   @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
  460.   @ use command <code>linewidth int</code> to adjust thickness of the arrow
  461.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  462.   @%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%
  463.   @%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%
  464.   @%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%
  465.   */
  466.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  467.           fill_color = stroke_color;
  468.           arrow_head = (int) get_real(infile,0);/* h */
  469.           i=0;
  470.           while( ! done ){     /* get next item until EOL*/
  471.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  472.             if(i%2 == 0 ){
  473.               double_data[i] = get_real(infile,0); /* x */
  474.             } else {
  475.               double_data[i] = get_real(infile,1); /* y */
  476.             }
  477.           i++;
  478.           }
  479.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  480.           if( use_affine == TRUE ){ transform(i-1,2);}
  481.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  482.           decimals = find_number_of_digits(precision);
  483.           for(c = 0 ; c < i-1 ; c = c+4){
  484.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  485.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  486.             snprintf(tmp_buffer,string_length,  "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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  487.             add_to_buffer(tmp_buffer);
  488.             if(onclick != 0){object_cnt++;}/* object_cnt++; */
  489.           }
  490.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  491.           dragstuff[8] = 1;
  492.           reset();
  493.           break;
  494.         case ARROW2:
  495.   /*
  496.   @ arrow2 x1,y1,x2,y2,h,color
  497.   @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br>with arrowhead size h in px and in color ''color``
  498.   @ use command <code>arrowhead int</code> to adjust the arrow head size
  499.   @ use command <code>linewidth int</code> to adjust thickness of the arrow
  500.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  501.   @%arrow2%size 400,400%xrange -10,10%yrange -10,10%drag xy%arrow2 0,0,4,3,8,blue%
  502.   */
  503.           for(i=0;i<6;i++){
  504.             switch(i){
  505.               case 0: double_data[0] = get_real(infile,0);break; /* x */
  506.               case 1: double_data[1] = get_real(infile,0);break; /* y */
  507.               case 2: double_data[2] = get_real(infile,0);break; /* x */
  508.               case 3: double_data[3] = get_real(infile,0);break; /* y */
  509.               case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  510.               case 5: stroke_color = get_color(infile,1);/* name or hex color */
  511.                 if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);}
  512.                 if( use_affine == 1 ){ transform(4,2);}
  513.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  514.                 decimals = find_number_of_digits(precision);
  515.                 string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  516.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  517.                 snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  518.                 add_to_buffer(tmp_buffer);
  519.                 if(onclick != 0){object_cnt++;}/* object_cnt++;*/
  520.                 if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  521.                 dragstuff[10] = 1;
  522.                 reset();
  523.                 break;
  524.             }
  525.           }
  526.           break;
  527.         case ARROWS2:
  528.   /*
  529.   @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n
  530.   @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color ''color``
  531.   @ use command <code>linewidth int</code> to adjust thickness of the arrows
  532.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  533.   @%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%
  534.   */
  535.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  536.           fill_color = stroke_color;
  537.           arrow_head = (int) get_real(infile,0);/* h */
  538.           i=0;
  539.           while( ! done ){     /* get next item until EOL*/
  540.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  541.             if(i%2 == 0 ){
  542.               double_data[i] = get_real(infile,0); /* x */
  543.             } else {
  544.               double_data[i] = get_real(infile,1); /* y */
  545.             }
  546.             i++;
  547.           }
  548.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  549.           if( use_affine == 1 ){ transform(i-1,2);}
  550.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  551.  
  552.           decimals = find_number_of_digits(precision);
  553.           for(c = 0 ; c < i-1 ; c = c+4){
  554.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  555.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  556.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  557.             add_to_buffer(tmp_buffer);
  558.             if(onclick != 0){object_cnt++;}/* object_cnt++; */
  559.           }
  560.           dragstuff[10] = 1;
  561.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  562.           reset();
  563.           break;
  564.         case ARROWHEAD:
  565.   /*
  566.   @ arrowhead int
  567.   @ default 8 (pixels)
  568.   */
  569.           arrow_head = (int) (get_real(infile,1));
  570.           break;
  571.         case AUDIO:
  572.   /*
  573.   @ audio x,y,w,h,loop,visible,audiofile location
  574.   @ x,y: left top corner of audio element (in xrange / yrange)
  575.   @ w,y: width and height in pixels
  576.   @ loop: 0 or 1 ( 1 = loop audio fragment)
  577.   @ visible: 0 or 1 (1 = show controls)
  578.   @ audio format may be in *.mp3 or *.ogg
  579.   @ If you are using *.mp3: be aware that FireFox will not (never) play this ! (Pattented format)
  580.   @ if you are using *.ogg: be aware that Microsoft based systems not support it natively
  581.   @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br>the program will use both as source tag
  582.   */
  583.           js_function[DRAW_AUDIO] = 1;
  584.           for(i=0;i<7;i++){
  585.             switch(i){
  586.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  587.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  588.               case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  589.               case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  590.               case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
  591.               case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
  592.               case 6:
  593.                 temp = get_string(infile,1);
  594.                 if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
  595.                 if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
  596.                 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);
  597.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  598.                 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);
  599.                 add_to_buffer(tmp_buffer);
  600.                 break;
  601.               default:break;
  602.             }
  603.           }
  604.           reset();
  605.           break;
  606.         case AXIS_NUMBERING:
  607.   /*
  608.       @ axisnumbering
  609.       @ keyword (no arguments required)
  610.       @ 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>
  611.       @ to be used before command grid (see <a href="#grid">command grid</a>)
  612.   */
  613.           use_axis_numbering++;
  614.           break;
  615.         case AXIS:
  616.   /*
  617.       @ axis
  618.       @ keyword (no arguments required)
  619.       @ to be used before command grid (see <a href="#grid">command grid</a>)
  620.  
  621.   */
  622.           use_axis = TRUE;
  623.           break;
  624.         case BARCHART:
  625.   /*
  626.   @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
  627.   @ may <b>only</b> to be used together with command <a href='#grid'>grid</a>
  628.   @ 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>
  629.   @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner
  630.   @ multiple barchart command may be used in a single script
  631.   @ also see command <a href='#piechart'>piechart</a>
  632.   @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble...
  633.   @%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
  634.   */
  635.           temp = get_string(infile,1);
  636.           if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
  637.           fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
  638.           barchart_cnt++;
  639.           reset();
  640.           break;
  641.         case BEZIER:
  642.   /*
  643.   @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end
  644.   @ draw a bezier curve between points, starting from (x_start:y_start)
  645.   @ can <b>not</b> be dragged or set onclick
  646.   */
  647.           js_function[DRAW_BEZIER] = 1;
  648.           decimals = find_number_of_digits(precision);
  649.           for(i = 0 ; i < 9; i++){
  650.             switch(i){
  651.               case 0: stroke_color = get_color(infile,0);break;
  652.               case 1: double_data[0] = get_real(infile,0);break;/* start x */
  653.               case 2: double_data[1] = get_real(infile,0);break;/* start y */
  654.               case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */
  655.               case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */
  656.               case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */
  657.               case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */
  658.               case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */
  659.               case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */
  660.                 if(use_rotate == TRUE ){rotate(8,angle,rotationcenter,2);}
  661.                 if(use_affine == TRUE ){ transform(2,5);}
  662.                 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);",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);
  663.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  664.                 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);",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);
  665.                 add_to_buffer(tmp_buffer);
  666.                 break;
  667.               default: break;
  668.             }
  669.           }
  670.           reset();
  671.           break;
  672.         case BGCOLOR:
  673.   /*
  674.    @ bgcolor colorname or #hex
  675.    @ use this color as background of the "div" containing the canvas(es)
  676.    @%bgcolor%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue
  677.   */
  678.   /* [255,255,255]*/
  679.           bgcolor = get_string(infile,1);
  680.           if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
  681.             int found = 0;
  682.             for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  683.               if( strcmp( colors[i].name , bgcolor ) == 0 ){
  684.                 bgcolor = colors[i].hex;
  685.                 found = 1;
  686.               break;
  687.               }
  688.             }
  689.             if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list: use hexcolor...something like #a0ffc4");}
  690.           }
  691.           fprintf(js_include_file,"/* set background color of canvas div */\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
  692.           break;
  693.         case BGIMAGE:
  694.   /*
  695.    @ bgimage image_location
  696.    @ use an image as background; technical: we use the background of ''canvas_div``
  697.    @ the background image will be resized to match "width = xsize" and "height = ysize"
  698.    @%bgimage%size 400,400%xrange -10,10%yrange -10,10%bgimage https://wims.unice.fr/wims/gifs/en.gif
  699.   */
  700.           URL = get_string(infile,1);
  701.           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);
  702.           break;
  703.         case BLINK:
  704.   /*
  705.    @ blink time(seconds)
  706.    @ NOT IMPLEMETED -YET
  707.   */
  708.           break;
  709.         case BOXPLOT:
  710.   /*
  711.   @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max
  712.   @ 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
  713.   @ 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
  714.   @ 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
  715.   @ use command <a href='#fillpattern'>fillpattern some_pattern</a> to use a (diamond for Q1, hatch for Q3) pattern.
  716.   @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of stroke and fill colours
  717.   @ 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.
  718.   @ there is no limit to the number of boxplots used.
  719.   @ can <b>not</b> be set draggable and <a href='#onclick'>onclick</a> is not ready yet
  720.   @ 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)
  721.   @ use keyword <a href="#userboxplotdata">userboxplotdata</a> before command boxplot, if a pupil must generate the data by some means.
  722.   @ use command <a href="#boxplotdata">boxplotdata</a> when the boxplot should be drawn from wims-generated raw statistical date
  723.   @%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
  724.   @%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
  725.   @%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
  726.   */
  727.           js_function[DRAW_BOXPLOT] = 1;
  728.           for(i=0;i<8;i++){
  729.             switch(i){
  730.               case 0: temp = get_string_argument(infile,0);
  731.                 if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */
  732.               case 1: double_data[0] = get_real(infile,0);break;/* height | width  */
  733.               case 2:
  734.                 if( js_function[DRAW_JSBOXPLOT] == 0 ){
  735.                   double_data[1] = get_real(infile,0);
  736.                   fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */
  737.                 }
  738.                 else {
  739.                   double_data[1] = get_real(infile,1);
  740.                   double_data[2] = 1;
  741.                   double_data[3] = 1;
  742.                   double_data[4] = 1;
  743.                   double_data[5] = 1;
  744.                   double_data[6] = 1;
  745.                   double_data[7] = 1;
  746.                   i=8;
  747.                 }
  748.                 break;/* center value x or y */
  749.               case 3: double_data[2] = get_real(infile,0); break;/* min */
  750.               case 4: double_data[3] = get_real(infile,0); break;/* Q1 */
  751.               case 5: double_data[4] = get_real(infile,0); break;/* median */
  752.               case 6: double_data[5] = get_real(infile,0); break;/* Q3 */
  753.               case 7: double_data[6] = get_real(infile,1); break;/* max */
  754.               default:break;
  755.             }
  756.           }
  757.           decimals = find_number_of_digits(precision);
  758.           /*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)*/
  759.           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]);
  760.           check_string_length(string_length);
  761.           tmp_buffer = my_newmem(string_length);
  762.           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]);
  763.           add_to_buffer(tmp_buffer);
  764.           boxplot_cnt++;
  765.           reset();
  766.           break;
  767.         case BOXPLOTDATA:
  768.   /*
  769.   @ boxplotdata some_data
  770.   @ 'some_data' are a list of numbers separated by a comma "," (items)
  771.   @ only be used before command <code>boxplot</code>: the command <a href="#boxplot">boxplot</a> will provide the boxplot drawing of the data.
  772.   @ 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
  773.   @ note: wims will not check your data input | format. use js-error console to debug any problems.
  774.   @ 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.
  775.   @ 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>
  776.   @%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
  777.   */
  778.           js_function[DRAW_JSBOXPLOT] = 1;
  779.           js_function[DRAW_BOXPLOT] = 1;
  780.           fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1));
  781.           break;
  782.         case CANVASTYPE:
  783.           canvas_type = (int) (get_real(infile,1));
  784.   /*
  785.   @ canvastype TYPE
  786.   @ for now only useful before commands filltoborder / floodfill / clickfill etc operations<br>Only the images of this TYPE will be scanned and filled
  787.   @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas)
  788.   @ use another TYPE, if you know what you are doing...
  789.   @ other possible canvasses (e.g. transparent PNG pictures, xsize &times; 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>
  790.   */
  791.           break;
  792.         case CENTERED:
  793.           use_offset = 4;
  794.    /*
  795.    @ centered
  796.    @ keyword ; to place the text centered (in width and height) on the text coordinates(x:y)
  797.    @ may be used for text exactly centered on its (x;y)
  798.    @ use <a href="#fontfamily">fontfamily</a> for setting the font
  799.    @ 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``)
  800.    @%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
  801.   */
  802.          break;
  803.         case CENTERSTRING:
  804.   /*
  805.    @ centerstring color,y-value,the text string
  806.    @ title color,y-value,the text string
  807.    @ draw a string centered on the canvas at y = y-value
  808.    @ can not be set ''onclick`` or ''drag xy`` (...)
  809.    @ unicode supported: <code>centerstring red,5,\\u2232</code>
  810.    @ use a command like <code>fontfamily italic 24pt Arial</code> to set fonts on browser that support font change
  811.    @%centerstring%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue%fontfamily italic 22pt Courier%centerstring blue,7,the center
  812.   */
  813.           js_function[DRAW_CENTERSTRING] = 1;
  814.           for(i=0;i<3;i++){
  815.             switch(i){
  816.               case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  817.               case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
  818.               case 2: temp = get_string_argument(infile,1);
  819.                 /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
  820.                 decimals = find_number_of_digits(precision);
  821.                 string_length = 1 + snprintf(NULL,0,"draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
  822.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  823.                 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);
  824.                 add_to_buffer(tmp_buffer);
  825.                 break;
  826.               default:break;
  827.             }
  828.           }
  829.           break;
  830.         case CHEMTEX:
  831.   /*
  832.   chemtex
  833.   keyword...needs to be the first command in the script (even before the ''size`` command)
  834.   only for KaTeX enabled typesetting !
  835.   will include 80kB large js-library for chemisty typesetting
  836.   using <a href="http://85.148.206.56/wims/download/katex.for.wims.tar.gz">KaTeX</a> : <code>katex x,y,\\ce{ chemistry tex code} like : \\ce{ Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2- }</code>
  837.   using MathJaX : <code>latex x,y,\\ce{ chemistry tex code} like : \\ce{ Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2- }</code>
  838.   see https://mhchem.github.io/MathJax-mhchem/
  839.   %chemtex_katex_mathjax%chemtex%size 400,400%xrange -10,10%yrange -10,10%snaptogrid%fontfamily 22px Arial%strokecolor red%drag xy%centered%latex 0,8,\\ce{Hg^2+}%drag xy%centered%latex 0,4,\\ce{\\xrightarrow{\\text{I}^{-}}}%drag xy%centered%latex 0,0,\\ce{HgI2}%centered%drag xy%latex 0,-4,\\ce{\\xrightarrow{\\text{I}^{-}}}%drag xy%centered%latex 0,-8,\\ce{[Hg^{II}I4]^2-}
  840.   */
  841.           found_size_command = 1;
  842.           fprintf(stdout,"\n<script src=\"scripts/js/KaTeX/mhchem.js\" defer></script>\n");
  843.           break;
  844.  
  845.         case CIRCLE:
  846.   /*
  847.   @ circle xc,yc,width (2*r in pixels),color
  848.   @ use command <code>fcircle xc,yc,d,color</code>
  849.   @ alternative: disk
  850.   @ use command <code>fillcolor color</code> to set the fillcolor
  851.   @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a>
  852.   @ will shrink / expand on zoom out / zoom in
  853.   @%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
  854.   */
  855.           for(i=0;i<4;i++){
  856.             switch(i){
  857.               case 0: double_data[0] = get_real(infile,0);break; /* x */
  858.               case 1: double_data[1] = get_real(infile,0);break; /* y */
  859.               case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out: radius in 'dx' xrange*/
  860.               case 3: stroke_color = get_color(infile,1);/* name or hex color */
  861.                 if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  862.                 if(use_affine == TRUE ){ transform(2,2);}
  863.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  864.                 decimals = find_number_of_digits(precision);
  865.                 string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  866.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  867.                 snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  868.                 add_to_buffer(tmp_buffer);
  869.                 if(onclick != 0){object_cnt++;}/* object_cnt++;*/
  870.                 dragstuff[13] = 1;
  871.                 if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  872.                 reset();
  873.                 break;
  874.               default : break;
  875.             }
  876.           }
  877.           break;
  878.         case CIRCLES:
  879.   /*
  880.   @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n
  881.   @ <b>attention</b> r = radius in x-range (!)
  882.   @ use keyword <code>filled</code> or command <code>fcircles</code> to produce solid circles
  883.   @ alternative: disks
  884.   @ use command <code>fillcolor color</code> to set the fillcolor
  885.   @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> (individually)
  886.   @ will shrink / expand on zoom out / zoom in
  887.   @%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
  888.   @%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
  889.   @%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
  890.   */
  891.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  892.           fill_color = stroke_color;
  893.           i=1;
  894.           while( ! done ){     /* get next item until EOL*/
  895.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  896.             switch (i%3){
  897.               case 1:double_data[i-1] = get_real(infile,0);break; /* x */
  898.               case 2:double_data[i-1] = get_real(infile,0);break; /* y */
  899.               case 0:double_data[i-1] = get_real(infile,1);break; /* r */
  900.             }
  901.             i++;
  902.           }
  903.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,3);}
  904.           if(use_affine == TRUE ){ transform(i-1,3);}
  905.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  906.  
  907.           decimals = find_number_of_digits(precision);
  908.           for(c = 0 ; c < i-1 ; c = c+3){
  909.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  910.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  911.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  912.             add_to_buffer(tmp_buffer);
  913.             if(onclick != 0){object_cnt++;}/* object_cnt++; */
  914.           }
  915.           reset();
  916.           dragstuff[13] = 1;
  917.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  918.           break;
  919.         case CLEARBUTTON:
  920.   /*
  921.    @ clearbutton value
  922.    @ alternative: delete
  923.    @ alternative: erase
  924.    @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text ''value``
  925.    @ <b>attention</b> command <code>clearbutton</code> is incompatible with <a href="#multidraw">multidraw</a> based drawings<br/>(in <code>multidraw</code> there is always a remove_object_button for every draw primitive)
  926.    @ normally <a href="#userdraw">userdraw</a> primitives have the option to use middle/right mouse button on<br> a point of the object to remove this specific object...this clear button will remove all drawings
  927.    @ uses the tooltip placeholder div element: may not be used with command <code>intooltip</code>
  928.    @ use command <a href="#css">css</a> to style the button...
  929.    @ the clearbutton will have id="canvas_scripts[%d]" ; starting with %d=0 for the first script<br>to change the style of all ''clearbutton`` of all included canvasdraw scripts, use something like<br><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>
  930.    @%clearbutton%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%userdraw circles,red%clearbutton Remove All
  931.   */
  932.           if(reply_format == 29){/* eg multidraw is selected */
  933.   // canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw");
  934.           }
  935.           add_clear_button(css_class,get_string(infile,1));
  936.           break;
  937.         case CLOCK:
  938.   /*
  939.   @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
  940.   @ use command <code>opacity stroke-opacity,fill-opacity</code> to adjust foreground (stroke) and background (fill) transparency
  941.   @ type hourglass:<br>type = 0: only segments<br>type = 1: only numbers<br>type = 2: numbers and segments
  942.   @ 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
  943.   @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
  944.   @ 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>
  945.   @ canvasdraw will not check validity of colornames...the javascript console is your best friend
  946.   @ no combinations with other reply_types allowed, for now
  947.   @ 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
  948.   @ 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
  949.   @ note: clocks will not zoom or pan, when using command <a href='#zoom'>zoom</a>
  950.   @%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
  951.   @%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
  952.   @%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
  953.   @%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
  954.   @%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
  955.   @%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
  956.   @%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
  957.   */
  958.           js_function[DRAW_CLOCK] = 1;
  959.           js_function[INTERACTIVE] = 1;
  960.  
  961.   /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
  962.           for(i=0;i<9;i++){
  963.             switch(i){
  964.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
  965.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
  966.               case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
  967.               case 3: int_data[3] = get_real(infile,0);break;/* hours */
  968.               case 4: int_data[4] = get_real(infile,0);break;/* minutes */
  969.               case 5: int_data[5] = get_real(infile,0);break;/* seconds */
  970.               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 */
  971.               case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/
  972.                 switch(int_data[7]){
  973.                   case 0:break;
  974.                   case 1:
  975.                     if(clock_cnt == 0){
  976.                       if( reply_format == 0 ){
  977.                         reply_format = 18; /* user sets clock */
  978.                   /* 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");
  979.                      check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  980.                      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");
  981.                      add_to_buffer(tmp_buffer);
  982.                  */
  983.                         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");
  984.                       }
  985.                       else {
  986.                         canvas_error("interactive clock may not be used together with other reply_types...");
  987.                       }
  988.                     }
  989.                     fprintf(stdout,"<p style=\"text-align:center\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\"><br><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H&minus;\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M&minus;\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S&minus;\"></p>",css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt);
  990.                     break;
  991.                   case 3:
  992.                     if(clock_cnt == 0){
  993.                       if( reply_format == 0 ){
  994.                         reply_format = 18; /* user sets clock */
  995.                         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");
  996.                        }
  997.                       else {
  998.                         canvas_error("interactive clock may not be used together with other reply_types...");
  999.                       }
  1000.                     }
  1001.           /*
  1002.           fprintf(stdout,"<p style=\"text-align:center\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\"><br><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H&minus;\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M&minus;\"><input class=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S&minus;\"></p>",css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt,css_class,clock_cnt);
  1003.          */
  1004.                   break;
  1005.                   case 2:
  1006.                     if( reply_format == 0 ){
  1007.                       reply_format = 19; /* "onclick */
  1008.                       js_function[INTERACTIVE] = 1;
  1009.                       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.button == 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");
  1010.                     }
  1011.                     else {
  1012.                       if( reply_format != 19){
  1013.                         canvas_error("clickable clock(s) may not be used together with other reply_types...");
  1014.                       }
  1015.                     }
  1016.                     break;
  1017.                   default: canvas_error("interactive must be set 0,1 or 2");break;
  1018.                 }
  1019.                 break;
  1020.               case 8:
  1021.                 if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock(), for now it's OK */
  1022.                   fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
  1023.                 }
  1024.                 temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/
  1025.                 if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
  1026.                 else{
  1027.                 /* h_color,m_color,s_color,bg_color,fg_color */
  1028.                   temp = ",black\",\"black\",\"black\",\"white\",\"black";}
  1029.                 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);
  1030.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1031.                 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);
  1032.                 add_to_buffer(tmp_buffer);
  1033.                 fprintf(js_include_file,"var clocks%d;",clock_cnt);
  1034.                 clock_cnt++;
  1035.                 break;
  1036.               default:break;
  1037.             }
  1038.           }
  1039.           break;
  1040.         case COLORPALETTE:
  1041.   /*
  1042.    @ colorpalette color_name_1,color_name_2,...,color_name_8
  1043.    @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a>
  1044.    @ 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
  1045.    @ make sure to include the ''remove button`` by using command <a href='#clearbutton'>clearbutton some_text</a>
  1046.   */
  1047.           if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");}
  1048.           fprintf(js_include_file,"var multifillcolors = [];var palettecolors = [");
  1049.           while( ! done ){
  1050.             temp = get_color(infile,1);
  1051.             fprintf(js_include_file,"\"%s\",",temp);
  1052.           }
  1053.           fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */
  1054.           add_color_palette(css_class);
  1055.           break;
  1056.  
  1057.         case COMMENT:
  1058.           sync_input(infile);
  1059.           break;
  1060.  
  1061.         case COPY:
  1062.   /*
  1063.   @ copy x,y,x1,y1,x2,y2,[filename URL]
  1064.   @ The image may be "bitmap" or "SVG"
  1065.   @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
  1066.   @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
  1067.   @ [filename] is the URL of the image
  1068.   @ <em>TODO:move special image functions to generic 'dragstuff' library</em>
  1069.   @ URL is normal URL of network reachable image file location
  1070.   @ if command <a href="#drag">drag x/y/xy</a> is set before command ''copy``, the images will be draggable<br>javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br>the command drag is only valid for the next image<br>draggable / non-draggable images may be mixed<br>may be used together with preceding keywords ''snaptogrid``, ''xsnaptogrid``, ''ysnaptogrid`` or <code>snaptopoints x1,y1,x2,y2...</code>.
  1071.   @ 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
  1072.   @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves, embeded XML etc)
  1073.   @ you may draw / userdraw / drag other stuff on top of an "imported" image
  1074.   @ the use of a slider is not possible: if needed, use command <a href='#html'>html x,y,&lt;img src=my_image.svg /&gt; </a>
  1075.   @ use keyword <a href='#centered'>centered</a> before command ''copy`` to place image center at given coordinates.
  1076.   @%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
  1077.   @%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
  1078.   @%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
  1079.   */
  1080.           for(i = 0 ; i<7;i++){
  1081.             switch(i){
  1082.               case 0: double_data[0]=get_real(infile,0);break; /* x left top corner in x/y range  */
  1083.               case 1: double_data[1]=get_real(infile,0);break; /* y left top corner in x/y range */
  1084.               case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
  1085.               case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
  1086.               case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
  1087.               case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
  1088.               case 6: URL = get_string(infile,1);
  1089.                 if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  1090.                 if(use_affine == TRUE ){transform(2,2);}
  1091.                 int_data[0] = x2px(double_data[0]);
  1092.                 int_data[1] = y2px(double_data[1]);
  1093.                 int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
  1094.                 int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
  1095.                 if( onclick == 0 ){ /* no mouse needed static image copy  */
  1096.                   if(js_function[DRAW_EXTERNAL_IMAGE] == 0){/* create canvas just once */
  1097.                     fprintf(js_include_file,"var image_copy_canvas = create_canvas%d(%d,xsize,ysize);",canvas_root_id,STATIC_IMAGE_CANVAS);
  1098.                     js_function[DRAW_EXTERNAL_IMAGE] = 1;
  1099.                   }
  1100.                   string_length = 1 + snprintf(NULL,0,  "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],use_offset,int_data[10]);
  1101.                   check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1102.                   snprintf(tmp_buffer,string_length,    "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],use_offset,int_data[10]);
  1103.                 }
  1104.                 else /* onclick or drag & drop external copy images */
  1105.                 {
  1106.                   js_function[DRAG_EXTERNAL_IMAGE] = 1;
  1107.                   string_length = 1 + snprintf(NULL,0,  "drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],onclick,object_cnt,use_offset,use_snap,int_data[10]);
  1108.                   check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1109.                   snprintf(tmp_buffer,string_length,    "drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],onclick,object_cnt,use_offset,use_snap,int_data[10]);
  1110.                 }
  1111.                 add_to_buffer(tmp_buffer);
  1112.                 object_cnt++;
  1113.                 break;
  1114.               default: break;
  1115.             }
  1116.           }
  1117.           reset();
  1118.           break;
  1119. /*
  1120. HTML5 specs:
  1121. context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  1122. img   Specifies the image, canvas, or video element to use
  1123. sx   The x coordinate where to start clipping: x1 = int_data[0]
  1124. sy   The y coordinate where to start clipping: x2 = int_data[1]
  1125. swidth   The width of the clipped image: int_data[2] - int_data[0]
  1126. sheight The height of the clipped image: int_data[3] - int_data[1]
  1127. x   The x coordinate where to place the image on the canvas: dx1 = int_data[4]
  1128. y   The y coordinate where to place the image on the canvas: dy1 = int_data[5]
  1129. width   The width of the image to use (stretch or reduce the image): dx2 - dx1 = int_data[6]
  1130. height   The height of the image to use (stretch or reduce the image): dy2 - dy1 = int_data[7]
  1131. */
  1132.         case COPYRESIZED:
  1133.   /*
  1134.   @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
  1135.   @ The image may be any "bitmap" or "SVG"
  1136.   @ 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
  1137.   @ (dx1:dy1) must be left top corner; (dx2:dy2) must be right bottom corner of inserted image
  1138.   @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
  1139.   @ URL is normal URL of network reachable image file location<br>(as seen from public_html-root or network reachable 'http://some_server/my_images/test.gif'<br>(eg no special wims paths are searched !!)
  1140.   @ if command <a href="#drag">drag x/y/xy</a> is set before command ''copy``, the images will be draggable<br>javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br>the command drag is only valid for the next image<br>draggable / non-draggable images may be mixed<br>may be used together with preceding keywords ''snaptogrid``,''xsnaptogrid``,''ysnaptogrid`` or <code>snaptopoints x1,y1,x2,y2...</code>
  1141.   @ 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
  1142.   @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves etc)
  1143.   @ you may draw / userdraw / drag stuff on top of an "imported" image
  1144.   @ 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``
  1145.   @ use keyword <a href='#centered'>centered</a> before command 'copyresized' to place image center at given coordinates.
  1146.   @ <em>TODO:move special image functions to generic 'dragstuff' library</em>
  1147.   */
  1148.           for(i = 0 ; i<9;i++){
  1149.            switch(i){
  1150.             case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
  1151.             case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
  1152.             case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
  1153.             case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
  1154.             case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
  1155.             case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
  1156.             case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
  1157.             case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
  1158.             case 8: URL = get_string(infile,1);
  1159.               if( int_data[1] == -1 ){ int_data[10] = 1; }else{int_data[10] = 0; }/* resized / not resized */
  1160.           /* flag error when wrong diagonal:  copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */
  1161.               if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){
  1162.                 canvas_error("in copyresized,  use:<br>left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! ");
  1163.               }
  1164.               int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */
  1165.               int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */
  1166.               int_data[6] = abs(int_data[6] - int_data[4]);/* width */
  1167.               int_data[7] = abs(int_data[7] - int_data[5]);/* height */
  1168.               if( onclick == 0 ){ /* no mouse needed static image copy  */
  1169.                 if(js_function[DRAW_EXTERNAL_IMAGE] == 0){
  1170.                   fprintf(js_include_file,"var image_copy_canvas = create_canvas%d(%d,xsize,ysize);",canvas_root_id,STATIC_IMAGE_CANVAS);
  1171.                   js_function[DRAW_EXTERNAL_IMAGE] = 1;
  1172.                 }
  1173.                 string_length = 1 + snprintf(NULL,0,  "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],use_offset,int_data[10]);
  1174.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1175.                 snprintf(tmp_buffer,string_length,    "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],use_offset,int_data[10]);
  1176.               }
  1177.               else /* onclick or drag & drop external copy images */
  1178.               {
  1179.                 js_function[DRAG_EXTERNAL_IMAGE] = 1;
  1180.                 string_length = 1 + snprintf(NULL,0,  "drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],onclick,object_cnt,use_offset,use_snap,int_data[10]);
  1181.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1182.                 snprintf(tmp_buffer,string_length,    "drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],onclick,object_cnt,use_offset,use_snap,int_data[10]);
  1183.                 object_cnt++;
  1184.               }
  1185.               add_to_buffer(tmp_buffer);
  1186.               break;
  1187.             default: break;
  1188.             }
  1189.           }
  1190.           reset();
  1191.           break;
  1192.  
  1193.         case CROSSHAIR:
  1194.   /*
  1195.   @ crosshair x,y,color
  1196.   @ draw a single crosshair point at (x;y) in color ''color``
  1197.   @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust
  1198.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1199.   @%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
  1200.   */
  1201.           for(i=0;i<3;i++){
  1202.             switch(i){
  1203.               case 0: double_data[0] = get_real(infile,0);break; /* x */
  1204.               case 1: double_data[1] = get_real(infile,0);break; /* y */
  1205.               case 2: stroke_color = get_color(infile,1);/* name or hex color */
  1206.                 if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  1207.                 if(use_affine == TRUE ){ transform(2,2);}
  1208.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1209.                 decimals = find_number_of_digits(precision);
  1210.                 string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1211.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1212.                 snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1213.                 add_to_buffer(tmp_buffer);
  1214.                 if(onclick != 0){object_cnt++;}
  1215.           /* object_cnt++ */
  1216.                 reset();
  1217.                 dragstuff[7] = 1;
  1218.                 break;
  1219.               default:break;
  1220.             }
  1221.           }
  1222.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1223.           break;
  1224.  
  1225.         case CROSSHAIRS:
  1226.   /*
  1227.   @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
  1228.   @ draw multiple crosshair points at given coordinates in color ''color``
  1229.   @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust
  1230.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  1231.   @%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
  1232.   @%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
  1233. */
  1234.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1235.           fill_color = stroke_color;
  1236.           i=0;
  1237.           while( ! done ){     /* get next item until EOL*/
  1238.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1239.             if(i%2 == 0 ){
  1240.               double_data[i] = get_real(infile,0); /* x */
  1241.             }
  1242.             else {
  1243.               double_data[i] = get_real(infile,1); /* y */
  1244.             }
  1245.             i++;
  1246.           }
  1247.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  1248.           if(use_affine == TRUE ){ transform(i-1,2);}
  1249.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1250.           decimals = find_number_of_digits(precision);
  1251.           for(c=0 ; c < i-1 ; c = c+2){
  1252.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1253.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1254.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1255.             add_to_buffer(tmp_buffer);
  1256.             if(onclick != 0){object_cnt++;}/* object_cnt++; */
  1257.           }
  1258.           dragstuff[7] = 1;
  1259.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1260.           reset();
  1261.           break;
  1262.  
  1263.         case CROSSHAIRSIZE:
  1264.   /*
  1265.   @ crosshairsize int
  1266.   @ default 8 (px)
  1267.   */
  1268.           crosshair_size = (int) (get_real(infile,1));
  1269.           break;
  1270.         case CSS:
  1271.   /*
  1272.   @ css css_class
  1273.   @ may be used before any ''style-able`` html object (like inputfields or buttons) or some html objects that are generated by some canvasdraw commands
  1274.   @ in case of <a href="#multidraw">multidraw</a> this command must be a table css class, for example "wimstable"
  1275.   @%css%size 400,400%xrange -10,10%yrange -10,10%css wims_button_help%input 0,0,10,1,Hello
  1276.   */
  1277.           css_class = get_string(infile,1);
  1278.           break;
  1279.         case CURSOR:
  1280.   /*
  1281.   @ cursor some CSS cursor_style
  1282.   @ alternative: pointer
  1283.   @ style can be any valid CSS property value
  1284.   @ 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
  1285.   @ note: wims will not check the validity of your cursor declaration
  1286.   @%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
  1287.   */
  1288.           fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1));
  1289.          break;
  1290.         case CURVE:
  1291.   /*
  1292.    @ curve color,formula(x)
  1293.    @ alternative: plot
  1294.    @ use command <a href="#trange">trange</a> in parametric functions before <b>every</b> command curve / plot <code>trange -pi,pi<br>curve color,formula1(t),formula2(t)</code><br>A next parametric curve will only be correctly plot when trange is set again !<br/>this is a design flaw and not a feature...
  1295.    @ use command <a href="#precision">precision</a> to increase the number of digits of the plotted points
  1296.    @ use command <a href="#plotsteps">plotsteps</a> to increase / decrease the amount of plotted points (default 150)
  1297.    @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1298.    @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">jsplot</a> (command ''curve`` will only calculate points within the xrange)
  1299.    @%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)
  1300.   */
  1301.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1302.  
  1303.           if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
  1304.             use_parametric = FALSE;
  1305.             stroke_color = get_color(infile,0);
  1306.             char *fun1 = get_string_argument(infile,0);
  1307.             char *fun2 = get_string_argument(infile,1);
  1308.             if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
  1309.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision,rotationcenter),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,my_sliders,rotation_center,use_offset);
  1310.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1311.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision,rotationcenter),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,my_sliders,rotation_center,use_offset);
  1312.             add_to_buffer(tmp_buffer);
  1313.           }
  1314.           else{
  1315.             stroke_color = get_color(infile,0);
  1316.             char *fun1 = get_string_argument(infile,1);
  1317.             if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  1318.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,rotationcenter),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,my_sliders,rotation_center,use_offset);
  1319.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1320.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,rotationcenter),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,my_sliders,rotation_center,use_offset);
  1321.             add_to_buffer(tmp_buffer);
  1322.           }
  1323.           if(onclick != 0){object_cnt++;}/* object_cnt++; */
  1324.           dragstuff[9] = 1;
  1325.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1326.           reset();
  1327.           break;
  1328.  
  1329.         case CURVEDARROW:
  1330.     /*
  1331.     @ curvedarrow x1,y1,xc,yc,x2,y2,color
  1332.     @ draw a single 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)
  1333.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1334.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1335.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1336.     @%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
  1337.     @%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
  1338.  
  1339. h[0] = arrowhead
  1340. h[1] = type: 1 = single 2=double arrow
  1341. function Shape(object_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_slider,rotation_center,use_offset)
  1342.     */
  1343.           for(i=0;i<7;i++){
  1344.             switch(i){
  1345.               case 0: double_data[0] = get_real(infile,0);break; /* x1 */
  1346.               case 1: double_data[1] = get_real(infile,0);break; /* y1 */
  1347.               case 2: double_data[2] = get_real(infile,0);break; /* xc */
  1348.               case 3: double_data[3] = get_real(infile,0);break; /* yc */
  1349.               case 4: double_data[4] = get_real(infile,0);break; /* y3 */
  1350.               case 5: double_data[5] = get_real(infile,0);break; /* y3 */
  1351.               case 6: stroke_color = get_color(infile,1);/* name or hex color */
  1352.                 if(use_rotate == TRUE ){rotate(6,angle,rotationcenter,2);}
  1353.                 if(use_affine == TRUE ){ transform(6,2);}
  1354.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1355.                 decimals = find_number_of_digits(precision);
  1356.                 string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1357.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1358.                 snprintf(tmp_buffer,string_length,  "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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1359.                 add_to_buffer(tmp_buffer);
  1360.                 if(onclick != 0){object_cnt++;}/* object_cnt++;*/
  1361.                 reset();
  1362.                 break;
  1363.             }
  1364.           }
  1365.           dragstuff[21] = 1;
  1366.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1367.           break;
  1368.  
  1369.         case CURVEDARROW2:
  1370.     /*
  1371.     @ curvedarrow2 x1,y1,xc,yc,x2,y2,color
  1372.     @ 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)
  1373.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1374.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1375.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1376.     @%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
  1377.     @%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
  1378.  
  1379. h[0] = arrowhead
  1380. h[1] = type: 1 = single 2=double arrow
  1381. function Shape(object_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_slider,rotation_center,use_offset)
  1382.     */
  1383.           for(i=0;i<7;i++){
  1384.             switch(i){
  1385.               case 0: double_data[0] = get_real(infile,0);break; /* x1 */
  1386.               case 1: double_data[1] = get_real(infile,0);break; /* y1 */
  1387.               case 2: double_data[2] = get_real(infile,0);break; /* xc */
  1388.               case 3: double_data[3] = get_real(infile,0);break; /* yc */
  1389.               case 4: double_data[4] = get_real(infile,0);break; /* y3 */
  1390.               case 5: double_data[5] = get_real(infile,0);break; /* y3 */
  1391.               case 6: stroke_color = get_color(infile,1);/* name or hex color */
  1392.               if(use_rotate == TRUE ){rotate(6,angle,rotationcenter,2);}
  1393.               if(use_affine == TRUE ){ transform(6,2);}
  1394.               if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1395.               decimals = find_number_of_digits(precision);
  1396.               string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1397.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1398.               snprintf(tmp_buffer,string_length,  "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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1399.               add_to_buffer(tmp_buffer);
  1400.               if(onclick != 0){object_cnt++;}/* object_cnt++;*/
  1401.               dragstuff[21] = 1;
  1402.               if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1403.               reset();
  1404.               break;
  1405.             }
  1406.           }
  1407.           break;
  1408.         case CURVEDARROWS:
  1409.     /*
  1410.     @ curvedarrows color,x1,y1,xc,yc,x2,y2,...,x_(n-1),y_(n-1),xc,yc,x_n,y_n
  1411.     @ 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)
  1412.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1413.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1414.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1415.     @%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
  1416.     @%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
  1417.  
  1418. h[0] = arrowhead
  1419. h[1] = type: 1 = single 2=double arrow
  1420. function Shape(object_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_slider,rotation_center,use_offset)
  1421.     */
  1422.           stroke_color = get_color(infile,0);/* name or hex color */
  1423.           i = 0;
  1424.           decimals = find_number_of_digits(precision);
  1425.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1426.           while( ! done ){
  1427.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1428.             double_data[0] = get_real(infile,0); /* x1 */
  1429.             double_data[1] = get_real(infile,0); /* y1 */
  1430.             double_data[2] = get_real(infile,0); /* xc */
  1431.             double_data[3] = get_real(infile,0); /* yc */
  1432.             double_data[4] = get_real(infile,0); /* x3 */
  1433.             double_data[5] = get_real(infile,1); /* y3 */
  1434.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1435.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1436.             snprintf(tmp_buffer,string_length,  "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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1437.             add_to_buffer(tmp_buffer);
  1438.             if(onclick != 0){object_cnt++;}
  1439.             i = i + 6;
  1440.           }
  1441.           if(use_rotate == TRUE ){rotate(i-6,angle,rotationcenter,2);}
  1442.           if(use_affine == TRUE ){ transform(i-6,2);}
  1443.           dragstuff[21] = 1;
  1444.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1445.           reset();
  1446.           break;
  1447.  
  1448.         case CURVEDARROWS2:
  1449.     /*
  1450.     @ curvedarrows2 color,x1,y1,xc,yc,x2,y2,...x_(n-1),y_(n-1),xc,yc,x_n,y_n
  1451.     @ 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)
  1452.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1453.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1454.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1455.     @%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
  1456.     @%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
  1457.  
  1458. h[0] = arrowhead
  1459. h[1] = type: 1 = single 2=double arrow
  1460. function Shape(object_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_slider,rotation_center,use_offset)
  1461.     */
  1462.           stroke_color = get_color(infile,0);/* name or hex color */
  1463.           i = 0;
  1464.           decimals = find_number_of_digits(precision);
  1465.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1466.           while( ! done ){
  1467.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1468.             double_data[0] = get_real(infile,0); /* x1 */
  1469.             double_data[1] = get_real(infile,0); /* y1 */
  1470.             double_data[2] = get_real(infile,0); /* xc */
  1471.             double_data[3] = get_real(infile,0); /* yc */
  1472.             double_data[4] = get_real(infile,0); /* x3 */
  1473.             double_data[5] = get_real(infile,1); /* y3 */
  1474.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1475.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1476.             snprintf(tmp_buffer,string_length,  "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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1477.             add_to_buffer(tmp_buffer);
  1478.             if(onclick != 0){object_cnt++;}
  1479.             i = i + 6;
  1480.           }
  1481.           if(use_rotate == TRUE ){rotate(i-6,angle,rotationcenter,2);}
  1482.           if(use_affine == TRUE ){ transform(i-6,2);}
  1483.           dragstuff[21] = 1;
  1484.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1485.           reset();
  1486.           break;
  1487.         case DASHED:
  1488.   /*
  1489.   @ dashed
  1490.   @ keyword (no arguments required)
  1491.   @ next object will be drawn with a dashed line
  1492.   @ change dashing scheme by using command <a href="#dashtype">dashtype</a>
  1493.   @%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
  1494.   */
  1495.           use_dashed = TRUE;
  1496.           break;
  1497.         case DASHTYPE:
  1498.   /*
  1499.   @ dashtype line_width_px,space_width_px
  1500.   @ every indiviual object may have its own dashtype, if needed...
  1501.   @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype
  1502.   @ default value <code>dashtype 2,2</code> e.g. 2px line and 2px space
  1503.   @ HTML5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable
  1504.   @%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
  1505.   */
  1506.           for(i=0;i<2;i++){
  1507.             switch(i){
  1508.               case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
  1509.               case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
  1510.             }
  1511.           }
  1512.           break;
  1513.  
  1514.         case DIAMONDFILL:
  1515.   /*
  1516.   @ diamondfill x0,y0,dx,dy,color
  1517.   @ x0,y0 in xrange / yrange
  1518.   @ distances dx,dy in pixels
  1519.   @ there is also a command <a href="#userdraw">userdraw diamondfill,color</a>
  1520.   @%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
  1521.   */
  1522.           js_function[DRAW_DIAMONDFILL] = 1;
  1523.           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1524.             js_function[DRAW_FILLTOBORDER] = 1;
  1525.             add_js_filltoborder(canvas_type);
  1526.           }
  1527.           decimals = find_number_of_digits(precision);
  1528.           for(i=0;i<5;i++){
  1529.             switch(i){
  1530.               case 0: double_data[0] = get_real(infile,0); break; /* x */
  1531.               case 1: double_data[1] = get_real(infile,0); break; /* y  */
  1532.               case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1533.               case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1534.               case 4: stroke_color = get_color(infile,1);
  1535.                 if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  1536.                 if(use_affine == TRUE ){ transform(2,2);}
  1537.               /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  1538.                 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);
  1539.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1540.                 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);
  1541.                 add_to_buffer(tmp_buffer);
  1542.                 fill_cnt++;
  1543.                 reset();
  1544.                 break;
  1545.               default:break;
  1546.             }
  1547.           }
  1548.           break;
  1549.         case DOTFILL:
  1550.   /*
  1551.   @ dotfill x0,y0,dx,dy,color
  1552.   @ x0,y0 in xrange / yrange
  1553.   @ distances dx,dy in pixels
  1554.   @ radius of dots is linewidth
  1555.   @ there is also a command <a href="#userdraw">userdraw dotfill,color</a>
  1556.   @%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
  1557.   */
  1558.           js_function[DRAW_DOTFILL] = 1;
  1559.           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1560.             js_function[DRAW_FILLTOBORDER] = 1;
  1561.             add_js_filltoborder(canvas_type);
  1562.           }
  1563.           decimals = find_number_of_digits(precision);
  1564.           for(i=0;i<5;i++){
  1565.             switch(i){
  1566.               case 0: double_data[0] = get_real(infile,0); break; /* x in px */
  1567.               case 1: double_data[1] = get_real(infile,0); break; /* y in py */
  1568.               case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1569.               case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1570.               case 4: stroke_color = get_color(infile,1);
  1571.                 if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  1572.                 if(use_affine == TRUE ){ transform(2,2);}
  1573.         /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
  1574.                 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);
  1575.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1576.                 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);
  1577.                 add_to_buffer(tmp_buffer);
  1578.                 fill_cnt++;
  1579.                 reset();
  1580.                 break;
  1581.               default:break;
  1582.             }
  1583.           }
  1584.           break;
  1585.         case DRAG:
  1586.   /*
  1587.    @ drag [x][y][xy]
  1588.    @ the next object will be draggable in x / y / xy direction
  1589.    @ the displacement can be read by <code>javascript:read_dragdrop();</code>
  1590.    @ 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' !
  1591.    @ <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 )
  1592.    @ ''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)
  1593.    @ <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<br> <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<br><code>linewidth 4<br>drag xy<br>point 0,0,red<br>drag xy<br>point 0,0,blue</code><br>both points will be recognised
  1594.    @ 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)
  1595.    @ 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
  1596.    @ 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.
  1597.    @%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
  1598.    @%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
  1599.    @%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
  1600.   */
  1601.           temp = get_string(infile,1);
  1602.           if(strstr(temp,"xy") != NULL ){
  1603.             drag_type = 0;
  1604.           } else {
  1605.             if(strstr(temp,"x") != NULL ){
  1606.               drag_type = 1;
  1607.             }
  1608.             else { drag_type = 2;}
  1609.           }
  1610.       /* assuming all drag&drop coordinates the same precision: so set only once */
  1611.           if( print_drag_params_only_once == FALSE ){
  1612.             fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;",precision);
  1613.             print_drag_params_only_once = TRUE;
  1614.           }
  1615.           onclick = 2;
  1616.       /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
  1617.           use_dragstuff = 2;
  1618.           js_function[INTERACTIVE] = 1;
  1619.           break;
  1620.  
  1621.         case ELLIPSE:
  1622.   /*
  1623.   @ ellipse xc,yc,width_x,height_y,color
  1624.   @ ellipses with center xc/yc and width/height in x/y-range etc (this differs from flydraw syntax!)
  1625.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1626.   @ will shrink / expand on zoom out / zoom in
  1627.   @%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
  1628.   */
  1629.           for(i=0;i<5;i++){
  1630.             switch(i){
  1631.               case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  1632.               case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  1633.               case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */
  1634.               case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */
  1635.               case 4:stroke_color = get_color(infile,1);/* name or hex color */
  1636.                 if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,4);}
  1637.                 if(use_affine == TRUE ){ transform(2,4);}
  1638.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1639.                 decimals = find_number_of_digits(precision);
  1640.                 string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1641.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1642.                 snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1643.                 add_to_buffer(tmp_buffer);
  1644.                 if(onclick != 0){object_cnt++;}/* object_cnt++; */
  1645.                 dragstuff[3] = 1;
  1646.                 if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1647.                 reset();
  1648.               break;
  1649.             }
  1650.           }
  1651.           break;
  1652.  
  1653.         case ELLIPSES:
  1654.   /*
  1655.   @ ellipses color,xc1,yc1,width_x1,height_y1,xc2,yc2,width_x2,height_y2,xc3,yc3,width_x3,height_y3,...
  1656.   @ ellipses with center and height in x/y-range etc (this differs from flydraw syntax!)
  1657.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1658.   @ will shrink / expand on zoom out / zoom in
  1659.   @%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
  1660.   */
  1661.  
  1662.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1663.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1664.           fill_color = stroke_color;
  1665.           i=1;
  1666.           while( ! done ){     /* get next item until EOL*/
  1667.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1668.             switch (i%4){
  1669.               case 1:double_data[i-1] = get_real(infile,0);break; /* x */
  1670.               case 2:double_data[i-1] = get_real(infile,0);break; /* y */
  1671.               case 3:double_data[i-1] = get_real(infile,0);break; /* rx */
  1672.               case 0:double_data[i-1] = get_real(infile,1);break; /* ry */
  1673.               default: break;
  1674.             }
  1675.             i++;
  1676.           }
  1677.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,4);}
  1678.           if(use_affine == TRUE ){ transform(i-1,4);}
  1679.           decimals = find_number_of_digits(precision);
  1680.           for(c = 0 ; c < i-1 ; c = c+4){
  1681.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1682.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1683.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  1684.             add_to_buffer(tmp_buffer);
  1685.             if(onclick != 0){object_cnt++;} /* object_cnt++; */
  1686.           }
  1687.           reset();
  1688.           dragstuff[3] = 1;
  1689.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1690.           break;
  1691.  
  1692.         case FILLALL:
  1693.   /*
  1694.   @ fillall color,x1,y1,x2,y2...x_n,y_n
  1695.   @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color'
  1696.   @ any other colors (objects) in the <a href="#canvastype">canvastype</a> will act as border to the bucket fill
  1697.   @ use this command after all boundary objects are declared.
  1698.   @ Use command 'userdraw clickfill,color' for user click driven flood fill.
  1699.   @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1700.   @ 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..
  1701.   @%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
  1702.   */
  1703.           decimals = find_number_of_digits(precision);
  1704.           fill_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1705.           i=0;
  1706.           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1707.             js_function[DRAW_FILLTOBORDER] = 1;
  1708.             add_js_filltoborder(canvas_type);
  1709.           }
  1710.           while( ! done ){     /* get next item until EOL*/
  1711.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1712.             if(i%2 == 0 ){
  1713.               double_data[i] = get_real(infile,0); /* x */
  1714.             }
  1715.             else {
  1716.               double_data[i] = get_real(infile,1); /* y */
  1717.               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);
  1718.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1719.               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);
  1720.               add_to_buffer(tmp_buffer);
  1721.               fill_cnt++;
  1722.             }
  1723.             i++;
  1724.           }
  1725.           break;
  1726.  
  1727.         case FILLED:
  1728.   /*
  1729.   @ filled
  1730.   @ keyword (no arguments required)
  1731.   @ the next ''fillable`` object (only the next !) will be filled
  1732.   @ use command <a href="#fillcolor">fillcolor color</a> to set fillcolor
  1733.   @ use <a href="#fillpattern">fillpattern</a> for non-solid color filling.
  1734.   @ use command <code>opacity 0-255,0-255</code> to set stroke and fill-opacity
  1735.   @ 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 !
  1736.   */
  1737.           use_filled = 1;
  1738.           break;
  1739.  
  1740.         case FILLCOLOR:
  1741.   /*
  1742.   @ fillcolor colorname or #hex
  1743.   @ set the color: mainly used for command 'userdraw obj,stroke_color'
  1744.   @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...)
  1745.   @ see <a href="#fillpattern">fillpattern</a> for non-solid color filling.
  1746.   */
  1747.           fill_color = get_color(infile,1);
  1748.           break;
  1749.  
  1750.         case FILLPATTERN:
  1751.   /*
  1752.   @ fillpattern grid | hatch | diamond | dot | image_url
  1753.   @ alternative: settile image_url
  1754.   @ use a pattern as fillstyle
  1755.   @ suitable for all fillable object including the <a href="#userdraw">userdraw objects' family</a>
  1756.   @ note: do not use the ''f`` for a fillable object : this is used exclusively for solid colour filling.
  1757.   @ 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>
  1758.   @ the pattern dimensions are hardcoded (linewidth, radius,dx,dy are fixed)
  1759.   @ the pattern color is set by command <a href='#fillcolor'>fillcolor</a> and <a href='#opacity'>opacity</a>
  1760.   @ see <a href="#fillcolor">fillcolor</a> for solid color filling.
  1761.   @ when using an image-url, make sure it contains an ''/`` in the filename...''fillpattern &#36;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>
  1762.   @ fillpattern is also active for <a href="#userdraw">userdraw object,color</a>...<br>the userdraw family a has also ''clickfill type`` (e.g. an object gets filled between boundaries, when clicked) commands like:<br>'userdraw dotfill,color'<br>'userdraw hatchfill,color' etc
  1763.   @%fillpattern_1%size 400,400%xrange -5,5%yrange -5,5%opacity 165,150%fillpattern grid%circle -6,3,160,blue%fillpattern dot%circle -3,-3,160,red%fillpattern hatch%circle 0,3,160,green%filpattern diamond%circle 3,-3,160,cyan%zoom red
  1764.   @%fillpattern_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%fillcolor green%fillpattern hatch%#fillpattern dot,diamond,grid,imageurl%userdraw circle,red
  1765.   */
  1766.           temp = get_string(infile,1);
  1767.           use_filled = 0;
  1768.           js_function[DRAW_FILL_PATTERN] = 1;
  1769.           if( strstr(temp,"grid") != 0 ){ use_filled = 2;}
  1770.           else{
  1771.             if( strstr(temp,"hatch") != 0 ){ use_filled = 3;}
  1772.             else{
  1773.               if( strstr(temp,"diamond") != 0 ){ use_filled = 4;}
  1774.               else{
  1775.                 if( strstr(temp,"dot") != 0 ){ use_filled = 5;}
  1776.                 else{
  1777.                   if( strstr(temp,"/") != 0 ){ /* get_image_from_url() needs to be called after function definition...*/
  1778.                     use_filled = 6;js_function[JS_LOAD_IMAGE] = 1;
  1779.                     string_length = 1 + snprintf(NULL,0,"get_image_from_url(\"%s\");",temp);
  1780.                     check_string_length(string_length);
  1781.                     tmp_buffer = my_newmem(string_length);
  1782.                     snprintf(tmp_buffer,string_length,"get_image_from_url(\"%s\");",temp);
  1783.                     add_to_buffer(tmp_buffer);
  1784.                   }
  1785.                 }
  1786.               }
  1787.             }
  1788.           }
  1789.           if( use_filled == 0 ){canvas_error("fillpattern unknown or typo...choose grid,hatch,diamond of dot...");}
  1790.           break;
  1791.         case FILLTOBORDER:
  1792.   /*
  1793.   @ filltoborder x,y,bordercolor,color
  1794.   @ fill the region of point (x:y) with color 'color'
  1795.   @ any other color will not act as border to the bucket fill
  1796.   @ use this command after all boundary objects are declared.
  1797.   @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1798.   @ 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..
  1799.   @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a>
  1800.   @%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
  1801.   */
  1802.           for(i=0 ;i < 4 ; i++){
  1803.             switch(i){
  1804.               case 0:double_data[0] = get_real(infile,0);break;
  1805.               case 1:double_data[1] = get_real(infile,0);break;
  1806.               case 2:bgcolor = get_color(infile,0);break;
  1807.               case 3:fill_color = get_color(infile,1);
  1808.                 if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1809.                   js_function[DRAW_FILLTOBORDER] = 1;
  1810.                   add_js_filltoborder(canvas_type);
  1811.                 }
  1812.                 decimals = find_number_of_digits(precision);
  1813.          /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  1814.                 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);
  1815.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1816.                 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);
  1817.                 add_to_buffer(tmp_buffer);
  1818.                 fill_cnt++;
  1819.                 reset();
  1820.                 break;
  1821.               default:break;
  1822.             }
  1823.           }
  1824.           break;
  1825.         case FLOODFILL:
  1826.   /*
  1827.   @ floodfill x,y,color
  1828.   @ alternative: fill
  1829.   @ fill the region of point (x:y) with color 'color'
  1830.   @ any other color or size of picture (borders of picture) will act as border to the bucket fill
  1831.   @ use this command after all boundary objects are declared.
  1832.   @ Use command <code>userdraw clickfill,color</code> for user click driven flood fill.
  1833.   @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1834.   @ 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..
  1835.   @%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
  1836.   */
  1837.           for(i=0 ;i < 4 ; i++){
  1838.             switch(i){
  1839.               case 0:double_data[0] = get_real(infile,0);break;
  1840.               case 1:double_data[1] = get_real(infile,0);break;
  1841.               case 2:fill_color = get_color(infile,1);
  1842.                 if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1843.                   js_function[DRAW_FILLTOBORDER] = 1;
  1844.                   add_js_filltoborder(canvas_type);
  1845.                 }
  1846.                 decimals = find_number_of_digits(precision);
  1847.          /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  1848.                 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);
  1849.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1850.                 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);
  1851.                 add_to_buffer(tmp_buffer);
  1852.                 fill_cnt++;
  1853.                 break;
  1854.             default:break;
  1855.             }
  1856.           }
  1857.           reset();
  1858.           break;
  1859.         case FONTCOLOR:
  1860.   /*
  1861.    @ fontcolor color
  1862.    @ color: hexcolor or colorname
  1863.    @ default: black
  1864.    @ use command <a href="#fontfamily">fontfamily</a> to deviate from default font type
  1865.    @%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
  1866.   */
  1867.           font_color = get_color(infile,1);
  1868.           break;
  1869.         case FONTFAMILY:
  1870.   /*
  1871.    @ fontfamily font_description
  1872.    @ set the font family; for browsers that support it
  1873.    @ font_description: Arial, Courier, Helvetica etc
  1874.    @ 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``
  1875.    @%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
  1876.  
  1877.   */
  1878.           font_family = get_string(infile,1);
  1879.           break;
  1880.         case FONTSIZE:
  1881.   /*
  1882.    @ fontsize font_size
  1883.    @ default value 12
  1884.    @ note: for some macros (like ''grid | legend | xaxistext | xlabel`` etc) sometimes command <a href="#fontfamily">fontfamily</a> can be used for some specific font-setting<br>this is however not always very straight forward... so just try and see what happens
  1885.   */
  1886.           font_size = (int) (get_real(infile,1));
  1887.           break;
  1888.         case FUNCTION_LABEL:
  1889.   /*
  1890.    @ functionlabel label_1:label_2:label_3...
  1891.    @ alternative: functionlabels
  1892.    @ default value ''f(x)=:g(x)=:h(x)=:i(x)=:j(x)=:k(x)=:m(x)=:n(x)=``
  1893.    @ no mathml allowed (just ascii string)
  1894.    @ use command <a href='#fontsize'>fontsize int</a> to adjust the size
  1895.    @ use command <a href='#strokecolor'>strokecolor colorname</a> to adjust the labels (individually, if needed)
  1896.    @ if needed, use before every command <a href='#userinput'>userinput function | inputfield | textarea</a>
  1897.    @ no limit in amount of inputfields for userbased function plotting
  1898.    @%function_label%size 400,400%xrange -5,5%yrange -5,5%precision 0%axis%axisnumbering%opacity 100,190%grid 1,1,grey,2,2,5,black%linewidth 3%linewidth 1%precision 1000%functionlabels F(x)=:H(x)=:Yield(x)=%strokecolor green%userinput function%strokecolor red%userinput function%strokecolor blue%userinput function
  1899.   */
  1900.           temp = get_string_argument(infile,1);
  1901.           function_label = list2js_array(temp,":");
  1902.           break;
  1903.         case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px), axis/tickscolor]*/
  1904.   /*
  1905.    @ grid step_x,step_y,gridcolor
  1906.    @ 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
  1907.    @ 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
  1908.    @ 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)
  1909.    @ can <b>not</b> be set <a href="#onclick">onclick</a> or <a href="#drag">drag xy</a>
  1910.    @ 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' !
  1911.    @ 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')
  1912.    @ 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')
  1913.    @%grid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%zoom red
  1914.    @%grid_axis%size 400,400%xrange -10,10%yrange -10,10%axis%grid 1,1,grey,2,2,6,black%zoom red
  1915.    @%grid_axis_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%fontfamily Italic 14px Courier%axis%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red
  1916.   */
  1917.           if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
  1918.           js_function[DRAW_GRID] = 1;
  1919.           for(i=0;i<4;i++){
  1920.             switch(i){
  1921.               case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
  1922.               case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
  1923.               case 2:
  1924.               if( use_axis == TRUE ){
  1925.                 stroke_color = get_color(infile,0);
  1926.                 done = FALSE;
  1927.                 int_data[0] = (int) (get_real(infile,0));/* xminor */
  1928.                 int_data[1] = (int) (get_real(infile,0));/* yminor */
  1929.                 int_data[2] = (int) (get_real(infile,0));/* tic_length */
  1930.                 fill_color = get_color(infile,1); /* used as axis_color*/
  1931.               }
  1932.               else {
  1933.               int_data[0] = 1;
  1934.               int_data[1] = 1;
  1935.               stroke_color = get_color(infile,1);
  1936.               fill_color = stroke_color;
  1937.               }
  1938.               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 !");}
  1939.               /* set snap_x snap_y values in pixels */
  1940.               fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
  1941.               fprintf(js_include_file,"\n/* add grid */function redraw_grid(){draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%d,%d,\"%s\",%.2f);return;};",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_dashed,dashtype[0],dashtype[1],font_color,fill_opacity);
  1942.               string_length = 1 + snprintf(NULL,0,  "redraw_grid();\n");
  1943.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1944.               snprintf(tmp_buffer,string_length,    "redraw_grid();\n");
  1945.               add_to_buffer(tmp_buffer);
  1946.               break;
  1947.             }
  1948.           }
  1949.           reset();
  1950.           break;
  1951.         case GRIDFILL:
  1952.   /*
  1953.   @ gridfill x0,y0,dx,dy,color
  1954.   @ x0,y0 in xrange / yrange
  1955.   @ distances dx,dy in pixels
  1956.   @ there is also a command <a href="#userdraw">userdraw gridfill,color</a>
  1957.   @%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
  1958.  
  1959.   */
  1960.           js_function[DRAW_GRIDFILL] = 1;
  1961.           decimals = find_number_of_digits(precision);
  1962.           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1963.             js_function[DRAW_FILLTOBORDER] = 1;
  1964.             add_js_filltoborder(canvas_type);
  1965.           }
  1966.           for(i=0;i<5;i++){
  1967.             switch(i){
  1968.               case 0: double_data[0] = get_real(infile,0); break; /* x  */
  1969.               case 1: double_data[1] = get_real(infile,0); break; /* y  */
  1970.               case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1971.               case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1972.               case 4: stroke_color = get_color(infile,1);
  1973.               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);
  1974.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1975.               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);
  1976.               add_to_buffer(tmp_buffer);
  1977.               fill_cnt++;
  1978.               reset();
  1979.               break;
  1980.               default:break;
  1981.             }
  1982.           }
  1983.           break;
  1984.         case GROUP:
  1985.   /*
  1986.    @ group
  1987.    @ keyword
  1988.    @ work in 'progress'
  1989.    @ all objects(*) after the command and until <a href="#kill">kill group</a> or <a href="#killslider">killslider</a> may be moved together with mouse moverments<br> (*) for now all real canvas objects and latex / xml ; but no images (work in progress)
  1990.    @ may be combined with slider driven movements or drag & drop
  1991.    @%group%%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%rotationcenter 0,0%slider -2*pi,2*pi,300,40,angle active,rotate%snaptogrid%ftriangle 0,-4,-2,-2,4,--5,blue%fillcolor red%fcircle -4.4,4.4,40,blue%kill slider%slider -20,20,300,40,x active,x-slide%ftriangle -2,0,0,4,2,0,green%fcircle 4.4,4.5,40,red%kill slider%slider -20,20,300,40,y active,y-slide%fcircle 4,-4,40,green%linewidth 4%fcircle -4,-4,40,orange%kill slider%group%fcircle -4.4,4.5,10,blue%fcircle -5.4,4.5,10,blue%fcircle -6.4,4.5,10,blue%fcircle -4.4,8,16,green%fcircle -5.4,8,16,green%fcircle -6.4,8,16,green%mouse red,22%zoom red
  1992.   */
  1993.           use_slider++;
  1994.           add_slider(2);
  1995.           no_reset = TRUE;
  1996.           int c = 0;
  1997.           for(i=last_slider;i<=use_slider;i++){ int_data[c] = i; c++; }
  1998.           my_sliders = data2js_array(int_data,use_slider - last_slider+1);
  1999.           if( precision == 0 ){precision = 100;}
  2000.           onclick = 5;
  2001.           use_dragstuff = 2;
  2002.           drag_type = 0;
  2003.           js_function[INTERACTIVE] = 1;
  2004.           fprintf(js_include_file,"var slider%d;dragdrop_precision = %d;use_dragdrop_reply = true;",use_slider,precision);
  2005.           string_length = 1 + snprintf(NULL,0,"slider%d = new move_group(%d);\n",use_slider,use_slider);
  2006.           check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2007.           snprintf(tmp_buffer,string_length,"slider%d = new move_group(%d);\n",use_slider,use_slider);
  2008.           add_to_buffer(tmp_buffer);
  2009.           break;
  2010.         case HALFLINE:
  2011.   /*
  2012.   @ demiline x1,y1,x2,y2,color
  2013.   @ alternative: halfline
  2014.   @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex)
  2015.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2016.   @%halfline%size 400,400%xrange -10,10%yrange -10,10%halfline -5,5,0,0,red%halfline -5,-5,0,0,blue
  2017.   */
  2018.           for(i=0; i<13;i++){double_data[i]=0;}
  2019.           for(i=0;i<5;i++){
  2020.             switch(i){
  2021.               case 0: double_data[0]= get_real(infile,0);break; /* x-values */
  2022.               case 1: double_data[1]= get_real(infile,0);break; /* y-values */
  2023.               case 2: double_data[10]= get_real(infile,0);break; /* x-values */
  2024.               case 3: double_data[11]= get_real(infile,0);break; /* y-values */
  2025.               case 4: stroke_color=get_color(infile,1);/* name or hex color */
  2026.                 if(double_data[0] == double_data[10]){ /* vertical halfline */
  2027.                   if(double_data[1] < double_data[11]){
  2028.                     double_data[3] = ymax + 1000;
  2029.                   }
  2030.                   else {
  2031.                     double_data[3] = ymin - 1000;
  2032.                   }
  2033.                   double_data[2] = double_data[0];
  2034.                 } else { /* horizontal halfline*/
  2035.                   if( double_data[1] == double_data[11] ){
  2036.                     if( double_data[0] < double_data[10] ){
  2037.                       double_data[2] = xmax + 1000; /* halfline to the right */
  2038.                     }
  2039.                     else {
  2040.                       double_data[2] = xmin - 1000; /* halfline to the left */
  2041.                     }
  2042.                     double_data[3] = double_data[1];
  2043.                   }
  2044.                 else {
  2045.           /* any other halfline */
  2046.           /* slope */
  2047.                   double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
  2048.                 /* const */
  2049.                   double_data[13] = double_data[1] - double_data[12]*double_data[0];
  2050.                   if( double_data[0] < double_data[10] ){
  2051.                     double_data[2] = double_data[2] + 1000;
  2052.                   }
  2053.                   else {
  2054.                     double_data[2] = double_data[2] - 1000;
  2055.                   }
  2056.                   double_data[3] = double_data[12]*double_data[2] + double_data[13];
  2057.                 }
  2058.               }
  2059.               if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2060.               if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);}
  2061.               if(use_affine == TRUE ){ transform(4,2);}
  2062.               string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2063.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2064.               snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2065.               add_to_buffer(tmp_buffer);
  2066.               if(onclick != 0){object_cnt++;}
  2067.         /* object_cnt++; */
  2068.               reset();
  2069.               break;
  2070.             }
  2071.           }
  2072.           dragstuff[18] = 1;
  2073.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2074.           break;
  2075.  
  2076.         case HALFLINES:
  2077.   /*
  2078.   @ demilines color,x1,y1,x2,y2,....
  2079.   @ alternative: halflines
  2080.   @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc
  2081.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually
  2082.   @%halflines%size 400,400%xrange -10,10%yrange -10,10%halflines red,-5,5,0,0,-5,-5,0,0
  2083.   */
  2084.           stroke_color=get_color(infile,0);
  2085.           fill_color = stroke_color;
  2086.           i=0;
  2087.           while( ! done ){     /* get next item until EOL*/
  2088.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2089.             if(i%2 == 0 ){
  2090.               double_data[i] = get_real(infile,0); /* x */
  2091.             } else {
  2092.               double_data[i] = get_real(infile,1); /* y */
  2093.             }
  2094.             i++;
  2095.           }
  2096.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2097.           decimals = find_number_of_digits(precision);
  2098.           for(c = 0 ; c < i-1 ; c = c+4){
  2099.             if( double_data[c] == double_data[c+2] ){ /* vertical line*/
  2100.               if(double_data[c+1] < double_data[c+3]){ /* upright halfline */
  2101.                 double_data[c+3] = ymax + 1000;
  2102.               }
  2103.               else {
  2104.                 double_data[c+3] = ymin - 1000;/* descending halfline */
  2105.               }
  2106.             }
  2107.             else {
  2108.               if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  2109.                 if(double_data[c] < double_data[c+2] ){ /* halfline to the right */
  2110.                   double_data[c+2] = xmax+100;
  2111.                 }
  2112.                 else {
  2113.                   double_data[c+2] = xmin-1000; /* halfline to the right */
  2114.                 }
  2115.               }
  2116.               else {
  2117.       /* m */
  2118.                 double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  2119.       /* q */
  2120.                 double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  2121.                 if(double_data[c] < double_data[c+2]){ /* to the right */
  2122.                   double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it is just segment */
  2123.                   double_data[c+3] = (m)*(double_data[c+2])+(q);
  2124.                   }
  2125.                   else { /* to the left */
  2126.                     double_data[c+2] = xmin - 1000;
  2127.                     double_data[c+3] = (m)*(double_data[c+2])+(q);
  2128.                   }
  2129.                 }
  2130.               }
  2131.               if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  2132.               if(use_affine == TRUE ){ transform(i-1,2);}
  2133.               string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2134.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2135.               snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2136.               add_to_buffer(tmp_buffer);
  2137.               if(onclick != 0){object_cnt++;}/* object_cnt++; */
  2138.             }
  2139.           reset();
  2140.           dragstuff[18] = 1;
  2141.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2142.           break;
  2143.         case HATCHFILL:
  2144.   /*
  2145.   @ hatchfill x0,y0,dx,dy,color
  2146.   @ x0,y0 in xrange / yrange
  2147.   @ distances dx,dy in pixels
  2148.   @ there is also a command <a href="#userdraw">userdraw hatchfill,color</a>
  2149.   @%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
  2150.   */
  2151.           js_function[DRAW_HATCHFILL] = 1;
  2152.           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2153.             js_function[DRAW_FILLTOBORDER] = 1;
  2154.             add_js_filltoborder(canvas_type);
  2155.           }
  2156.           decimals = find_number_of_digits(precision);
  2157.           for(i=0;i<5;i++){
  2158.             switch(i){
  2159.               case 0: double_data[0] = get_real(infile,0); break; /* x */
  2160.               case 1: double_data[1] = get_real(infile,0); break; /* y  */
  2161.               case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  2162.               case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2163.               case 4: stroke_color = get_color(infile,1);
  2164.                 if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  2165.                 if(use_affine == TRUE ){ transform(2,2);}
  2166.                 /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2167.                 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);
  2168.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2169.                 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);
  2170.                 add_to_buffer(tmp_buffer);
  2171.                 fill_cnt++;
  2172.                 reset();
  2173.                 break;
  2174.               default:break;
  2175.             }
  2176.           }
  2177.           break;
  2178.  
  2179.         case HLINE:
  2180.   /*
  2181.   @ hline x,y,color
  2182.   @ alternative: horizontalline
  2183.   @ draw a horizontal line through point (x:y) in color 'color'
  2184.   @ 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)
  2185.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2186.   @%hline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hline 0,0,red%dhline 0,5,blue
  2187.   */
  2188.           for(i=0;i<3;i++) {
  2189.             switch(i){
  2190.               case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  2191.               case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  2192.               case 2: stroke_color = get_color(infile,1);/* name or hex color */
  2193.                 double_data[3] = double_data[1];
  2194.                 if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  2195.                 if(use_affine == TRUE ){ transform(2,2);}
  2196.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2197.                 decimals = find_number_of_digits(precision);
  2198.                 string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2199.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2200.                 snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2201.                 add_to_buffer(tmp_buffer);
  2202.                 if(onclick != 0){object_cnt++;}/* object_cnt++; */
  2203.                 dragstuff[4] = 1;
  2204.                 if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2205.                 reset();
  2206.                 break;
  2207.             }
  2208.           }
  2209.           break;
  2210.         case HLINES:
  2211.   /*
  2212.   @ hlines color,x1,y1,x2,y2,...
  2213.   @ alternative: horizontallines
  2214.   @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color'
  2215.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  2216.   @%hlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hlines red,0,0,0,5,0,-5
  2217.   */
  2218.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  2219.           fill_color = stroke_color;
  2220.           i=0;
  2221.           while( ! done ){     /* get next item until EOL*/
  2222.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2223.             if(i%2 == 0 ){
  2224.                 double_data[i] = get_real(infile,0); /* x */
  2225.             }
  2226.             else {
  2227.               double_data[i] = get_real(infile,1); /* y */
  2228.             }
  2229.             i++;
  2230.           }
  2231.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  2232.           if(use_affine == TRUE ){ transform(i-1,2);}
  2233.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2234.  
  2235.           decimals = find_number_of_digits(precision);
  2236.           for(c = 0 ; c < i-1 ; c = c+2){
  2237.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2238.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2239.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2240.             add_to_buffer(tmp_buffer);
  2241.             if(onclick != 0){object_cnt++;}/* object_cnt++; */
  2242.           }
  2243.           reset();
  2244.           dragstuff[4] = 1;
  2245.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2246.           break;
  2247.         case HTTP:
  2248.   /*
  2249.    @ http x1,y1,x2,y2,http://some_adress.com
  2250.    @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1), right bottom (x2:y2)
  2251.    @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe
  2252.    @ can <b>not</b> be ''set onclick`` or ''drag xy``
  2253.    @%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
  2254.   */
  2255.           js_function[DRAW_HTTP] = 1;
  2256.           for(i=0;i<5;i++){
  2257.             switch(i){
  2258.               case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2259.               case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2260.               case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  2261.               case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  2262.               case 4: decimals = find_number_of_digits(precision);
  2263.                 temp = get_string(infile,1);
  2264.                 if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
  2265.                 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);
  2266.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+2);
  2267.                 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);
  2268.                 add_to_buffer(tmp_buffer);
  2269.                break;
  2270.             }
  2271.           }
  2272.           reset();
  2273.           break;
  2274.         case HTML:
  2275.   /*
  2276.    @ html x1,y1,html_string
  2277.    @ all tags are allowed, html code using inputfields could be read using your own javascript code. Do not use ids like 'canvas_input0' etc.
  2278.    @ can be set <a href='#onclick'>onclick</a>  and <a href='#drag'>drag&amp;drop</a>
  2279.    @ command <a href='#affine'>affine</a> will produce CSS3 matrix transformations
  2280.    @ command <a href='#rotate'>rotate</a> will rotate the object
  2281.    @ use keyword <a href='#centered'>centered</a> to center the html object on (x1:y1)
  2282.    @ note: using drag&amp;drop for all external P,SPAN,DIV,IMG,SVG-images onto a canvasdraw element, use ''onclick=javascript:place_image_on_canvas(this.id)``
  2283.    @ note: sub &amp; sup are supported in command family <a href='#string'>string</a>, e.g. real internal canvas objects !
  2284.    @%html-text%size 500,500%xrange -10,10%yrange -10,10%drag xy%centered%fillcolor lightblue%html 2,2,<h1 style='color:red'>DRAG ME</h1> %opacity 200,50%drag xy%fcircle 0,0,100,green
  2285.    @%html-image-slider%size 500,500%xrange -10,10%yrange -10,10%fontsize 42%rotationcenter 0,0%centered%html 0,0,<img src="http://85.148.206.56/gifs/can1.gif">%slider 0,pi,400,40,angle active degree, %centered%html 0,0,<img src="http://85.148.206.56/gifs/can2.gif">
  2286.   */
  2287.           js_function[DRAW_XML] = 1;
  2288.           for(i=0;i<5;i++){
  2289.             switch(i){
  2290.               case 0: double_data[0] = get_real(infile,0);break;
  2291.               case 1: double_data[1] = get_real(infile,0);break;
  2292.               case 4: decimals = find_number_of_digits(precision);
  2293.                 if(use_affine == TRUE ){ transform(2,2);}/* needs double_data[] */
  2294.                 if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */
  2295.                 int_data[0] = x2px(double_data[0]);/* needs px */
  2296.                 int_data[1] = y2px(double_data[1]);
  2297.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2298.                 if( use_slider != -1 && drag_type != -1){ onclick = 5; }
  2299.                 temp = get_string(infile,1);
  2300.                 if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","\\\""); }
  2301.                 if( strstr(temp,"<img ")!= 0){URL="image";}else{URL="html";}
  2302.                 string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'%s',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,URL,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt);
  2303.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2304.                 snprintf(tmp_buffer,string_length,  "var draw_xml%d = {id:%d,type:'%s',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,URL,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt);
  2305.                 add_to_buffer(tmp_buffer);
  2306.                 if(onclick != 0 ){object_cnt++;}
  2307.                 drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */
  2308.                 break;
  2309.               default:break;
  2310.             }
  2311.           }
  2312.           reset();
  2313.           break;
  2314.  
  2315.         case IMAGEFILL:
  2316.   /*
  2317.   @ imagefill x,y,scaling to xsize &times; ysize?,image_url
  2318.   @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
  2319.   @ scaling to xsize &times; ysize ? ... 1 = yes 0 = no
  2320.   @ After pattern filling, the fill-color should be reset !
  2321.   @ wims getins / image from class directory: imagefill 80,80,my_image.gif
  2322.   @ normal url: imagefill 80,80,0,&#36;module_dir/gifs/my_image.gif
  2323.   @ normal url: imagefill 80,80,1,http://adres/a/b/c/my_image.jpg
  2324.   @ if dx,dy is larger than the image, the whole image will be background to the next object.
  2325.   @%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
  2326.   @%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
  2327.   */
  2328.           js_function[DRAW_IMAGEFILL] = 1;
  2329.           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2330.             js_function[DRAW_FILLTOBORDER] = 1;
  2331.             add_js_filltoborder(canvas_type);
  2332.           }
  2333.           for(i=0 ;i < 4 ; i++){
  2334.             switch(i){
  2335.               case 0:int_data[0] = (int) (get_real(infile,0));break;
  2336.               case 1:int_data[1] = (int) (get_real(infile,0));break;
  2337.               case 2:int_data[2] = (int) (get_real(infile,0));break; /* 0 | 1 */
  2338.               case 3: URL = get_string_argument(infile,1);
  2339.                 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]);
  2340.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2341.                 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]);
  2342.                 add_to_buffer(tmp_buffer);
  2343.                 fill_cnt++;
  2344.               break;
  2345.             }
  2346.           }
  2347.           reset();
  2348.           break;
  2349.         case IMAGEPALETTE:
  2350.   /*
  2351.    @ imagepalette image1,image2,image3,...
  2352.    @ 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``.
  2353.    @%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%css 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
  2354.    */
  2355.           temp = get_string(infile,1);
  2356.           temp = str_replace(temp,",","\",\"");
  2357.           if( use_tooltip == 1 ){canvas_error("command 'imagepalette' is incompatible with command 'intooltip tip_text',as they use the same div-element ");}
  2358.           fprintf(js_include_file,"\nvar current_id;var imagepalette = [\" %s \"];\n",temp);
  2359.           break;
  2360.         case INPUT:
  2361.   /*
  2362.    @ input x,y,size,editable,value
  2363.    @ to set inputfield "readonly", use editable = 0
  2364.    @ if no preset 'value' is needed...use a 'space' as last item argument
  2365.    @ only active inputfields (editable = 1) will be read with read_canvas();
  2366.    @ 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>
  2367.    @ may be further controlled by <a href="#css">css</a>
  2368.    @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
  2369.    @ 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)
  2370.    @ 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>
  2371.    @%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, ?
  2372.   */
  2373.           js_function[DRAW_INPUTS] = 1;
  2374.           for(i = 0 ; i<5;i++){
  2375.             switch(i){
  2376.               case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
  2377.               case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
  2378.               case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
  2379.               case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
  2380.               case 4: temp = get_string(infile,3);
  2381.                 string_length = 1 + snprintf(NULL,0,  "draw_static_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],css_class,temp,use_offset);
  2382.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2383.                 snprintf(tmp_buffer,string_length,"draw_static_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],css_class,temp,use_offset);
  2384.                 add_to_buffer(tmp_buffer);
  2385.                 input_cnt++;break;
  2386.               default: break;
  2387.             }
  2388.           }
  2389.           if(reply_format == 0 ){reply_format = 15;}
  2390.           reset();
  2391.           break;
  2392.  
  2393.         case INTOOLTIP:
  2394.       /*
  2395.       @ intooltip link_text
  2396.       @ link_text is a single line (span-element)
  2397.       @ link_text may also be an image URL ''http://some_server/images/my_image.png`` or ''&#36;module_dir/gifs/my_image.jpg``
  2398.       @ link_text may contain HTML markup
  2399.       @ the canvas will be displayed in a tooltip on ''link_text``
  2400.       @ 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'.
  2401.       @ 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...
  2402.       @%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>
  2403.       */
  2404.           if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");}
  2405.           if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");}
  2406.           tooltip_text = get_string(infile,1);
  2407.           if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
  2408.           use_tooltip = 1;
  2409.           break;
  2410.         case JSCURVE:
  2411.   /*
  2412.    @ jscurve color,formula1(x),formula2(x),formula3(x),...
  2413.    @ alternative: jsplot
  2414.    @ your function will be plotted by the javascript engine of the client browser
  2415.    @ 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
  2416.    @ use only basic math in your curve: <code>sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e</code>
  2417.    @ use parenthesis and rawmath: use 2*x instead of 2x ; use 2^(sin(x))...etc etc (use error console to debug any errors...)
  2418.    @ <b>attention</b>: last ''precision`` command in the canvasdraw script determines the calculation precision of the javascript curve plot !
  2419.    @ no validity check is done by wims.
  2420.    @ 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
  2421.    @ 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
  2422.    @ zooming & panning in case of userbased functionplot: reclick the OK button to re-plot curve onto the resized grid
  2423.    @ use keyword <a href='animate'>animate</a> for animating a point on the curve
  2424.    @ use command ''trace_jscurve formula(x)`` for tracing
  2425.    @ use command ''jsmath formula(x)`` for calculating and displaying indiviual points on the curve
  2426.    @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet)
  2427.    @ commands plotjump / plotstep are not active for ''jscurve``
  2428.    @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve.
  2429.    @ 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...)
  2430.    @%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)
  2431.   */
  2432.           jsplot_cnt++;/* -1 --> 0 */
  2433.           stroke_color = get_color(infile,0);
  2434.           js_function[JS_MATH] = 1;
  2435.           js_function[JS_PLOT] = 1;
  2436.           if( tmin != 0 && tmax !=0){use_parametric = TRUE;}
  2437.           temp = get_string(infile,1);
  2438.           temp = str_replace(temp,",","\",\"");
  2439.           string_length = 1 + snprintf(NULL,0,  "var js_plot%d = function(){jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d,0);};js_plot%d();",jsplot_cnt,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,jsplot_cnt);
  2440.           check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2441.           snprintf(tmp_buffer,string_length,    "var js_plot%d = function(){jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d,0);};js_plot%d();",jsplot_cnt,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,jsplot_cnt);
  2442.           add_to_buffer(tmp_buffer);
  2443.           fprintf(js_include_file,"if(typeof(all_jsplots) !== 'number'){var all_jsplots;};all_jsplots = %d;",jsplot_cnt);
  2444.  
  2445.        /* we need to create multiple canvasses, so we may zoom and pan ?? */
  2446.           break;
  2447.  
  2448.         case JSMATH:
  2449.   /*
  2450.       @ jsmath some_math_function
  2451.       @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
  2452.       @ 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
  2453.       @ use command 'css some_css' for styling the display fields. Use command 'fontsize int' to size the labels ''x`` and ''y``
  2454.       @ 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...
  2455.       @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
  2456.       @%jsmath%size 400,400%xrange -10,10%yrange -10,10%jsplot blue,sin(x^2)%jsmath sin(x^2)
  2457.   */
  2458.           js_function[DRAW_CROSSHAIRS] = 1;
  2459.           js_function[JS_MATH] = 1;
  2460.           add_calc_y(get_string(infile,1),font_size,css_class);
  2461.           break;
  2462.         case KILL:
  2463.   /*
  2464.   @ kill arguments
  2465.   @ arguments may be: affine linear translation rotation slider offset  reset
  2466.   @ for documentation see: killaffine,killlinear,killtranslation...
  2467.   @ multiple arguments are allowed (although not checked for validity...)
  2468.   */
  2469.           temp = get_string(infile,1);
  2470.           if(strstr(temp,"affine") != 0 ){use_affine = FALSE;affine_matrix[0] = 1.0;affine_matrix[1] = 0.0;affine_matrix[2] = 0.0;affine_matrix[3] = 1.0;affine_matrix[4] = 0.0;affine_matrix[5] = 0.0;}
  2471.           if(strstr(temp,"linear") != 0 ){affine_matrix[0] = 1.0;affine_matrix[1] = 0.0;affine_matrix[2] = 0.0;affine_matrix[3] = 1.0;}
  2472.           if(strstr(temp,"translation") != 0 || strstr(temp,"translate") != 0 ){affine_matrix[4] = 0.0;affine_matrix[5] = 0.0;}
  2473.           if(strstr(temp,"rotation") != 0 || strstr(temp,"rotate") != 0 ){use_rotate = FALSE;angle = 0.0;rotation_center="null";}
  2474.           if(strstr(temp,"slider") != 0 ){slider_type = "0";my_sliders = "[-1]";last_slider = use_slider+1;}
  2475.           if(strstr(temp,"group") != 0 ){onclick = 0;drag_type = -1;slider_type = "0";my_sliders = "[-1]";last_slider = use_slider+1;use_slider = -1;reset();}
  2476.           if(strstr(temp,"reset") != 0 ){if(no_reset == FALSE){no_reset = TRUE;}else{no_reset = FALSE;reset();}}
  2477.           if(strstr(temp,"offset") != 0 ){use_offset = 0;}
  2478.           break;
  2479.         case KILLAFFINE:
  2480.   /*
  2481.   @ killaffine
  2482.   @ keyword: resets the transformation matrix to 1,0,0,1,0,0
  2483.   @ note: any active linear transformation will also be reset: tx=0, ty=0
  2484.   */
  2485.           use_affine = FALSE;
  2486.           affine_matrix[0] = 1.0;
  2487.           affine_matrix[1] = 0.0;
  2488.           affine_matrix[2] = 0.0;
  2489.           affine_matrix[3] = 1.0;
  2490.           affine_matrix[4] = 0.0;
  2491.           affine_matrix[5] = 0.0;
  2492.           break;
  2493.         case KILLLINEAR:
  2494.   /*
  2495.   @ killlinear
  2496.   @ keyword: resets the transformation matrix to 1,0,0,1,tx,ty
  2497.   @ note:any active transformation or rotation will not be killed (tx,ty remain active)
  2498.   */
  2499.           affine_matrix[0] = 1.0;
  2500.           affine_matrix[1] = 0.0;
  2501.           affine_matrix[2] = 0.0;
  2502.           affine_matrix[3] = 1.0;
  2503.           break;
  2504.  
  2505.         case KILLROTATE:
  2506.   /*
  2507.    @ killrotate
  2508.    @ will set the rotation angle to 0.
  2509.    @ will also reset the command <a href="#rotationcenter">rotationcenter</a> to the first (x;y) of the next rotatable/slidable object(s) <br/>eg a following rotate command will have the first object point as rotation center
  2510.    @ if not set, the rotation center will remain unchanged
  2511.    @ note:any active transformation or linear will not be killed (e.g an active transformation matrix remains active)
  2512.    @%killrotate%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%rotationcenter 0,0%# slider is active for all following objects until 'killslider'%slider -10,10,300,40,angle degree,Rotate%drag xy%# after dragging the object must be clicked to re-activate the slider%linewidth 4%arrow 0,0,6,0,9,blue%%# reset rotation center to the first (x,y) of the next object/arrow...%killrotate%drag xy%# after dragging the object must be clicked to re-activate the slider%arrow 0,0,6,1,9,red
  2513.   */
  2514.           use_rotate = FALSE;
  2515.           angle = 0.0;
  2516.           rotation_center="null";
  2517.           break;
  2518.         case KILLSLIDER:
  2519.   /*
  2520.    @ killslider
  2521.    @ keyword (no arguments required)
  2522.    @ ends grouping of object under a previously defined slider
  2523.   */
  2524.           slider_type = "0";
  2525.           my_sliders = "[-1]";
  2526.           last_slider = use_slider+1;
  2527.           break;
  2528.         case KILLTRANSLATION:
  2529.   /*
  2530.    @ killtranslation
  2531.    @ alternative: killtranslate
  2532.    @ note: a active linear or affine transformation will not be 100% reset...only tx=0,ty=0
  2533.    @ resets the translation matrix a,b,c,d,tx,ty to a,b,c,d,0,0
  2534.   */
  2535.           affine_matrix[4] = 0.0;
  2536.           affine_matrix[5] = 0.0;
  2537.           break;
  2538.         case LATEX:
  2539.   /*
  2540.    @ latex x,y,tex string
  2541.    @ alternative: math
  2542.    @ note: <b>for a single greek letter</b> ,please be smart and use a command like <a href='#string'>string</a> along with <b>unicode</b> !! <br>possibly together with command <a href="#xyoffset">xoffset, yoffset or xyoffset</a><br/> See <a target='new' href='https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode'>https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode</a><br/> See <a target='new' href='https://en.wikipedia.org/wiki/Greek_script_in_Unicode'>https://en.wikipedia.org/wiki/Greek_script_in_Unicode</a>
  2543.    @ you may also use command <a href="#mathml">mathml</a> for xml strings generated with wims commmand ''mathmlmath`` (will not work on KaTeX enabled WIMS)
  2544.    @ transformation commands <a href='#affine'>affine</a>, <a href='#translation'>translation</a> and <a href='#rotate'>rotate</a> are supported.(onclick and drag will work)
  2545.    @ can be set onclick: <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects<br>if 4 clickable object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object
  2546.    @ 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...
  2547.    @ can be moved/rotated with command <a href='#slider'>slider</a>
  2548.    @ snaptogrid is supported
  2549.    @ when clicked, the colour of the 'div background' of the 'mathobject' will be determined by the <a href="#fillcolor">fillcolor</a> and <a href="#opacity">opacity</a> settings
  2550.    @ userdraw may be combined with 'latex' ; the js-function 'read_canvas()' will contain the coordinates of the drawing.
  2551.    @ userdraw may be combined; the read_canvas() will contain the drawing.
  2552.    @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> and all objects from commands <a href='#html'>html</a> or <a href='#obabel'>obabel</a> can be combined with drag and/or onclick mathml
  2553.    @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret...
  2554.    @ 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();"
  2555.    @ 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....
  2556.    @ use keyword <a href='#centered'>centered</a> to center the katex div object on (x1:y1) <br>this may not work as expected for MathJaX [TO BE TESTED]
  2557.    @ note: if you want to include external TeX via drag&amp;drop onto a canvasdraw element, use \\mmlid{integer} in the tex-command:''!insmath \\mmlid{1}\\frac{1}{\pi}``<br> (if your wims_mathml does not support it...use <a href="http://85.148.206.56/wims/download/Mathml.tar.gz">this version...</a>)
  2558.    @ note: the same is true for all external P,SPAN,DIV,IMG,SVG-images via drag&amp;drop onto a canvasdraw element, use ''onclick=javascript:place_image_on_canvas(this.id)``
  2559.    @%latex_drag%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%strokecolor red%drag xy%centered%latex -6,5,\\frac{1}{2}+ \\frac{\\pi}{2}%strokecolor blue%drag xy%centered%latex -3,5,\\frac{1}{3}+ \\frac{\\pi}{3}%strokecolor green%drag xy%centered%latex 0,5,\\frac{1}{4}+ \\frac{\\pi}{4}%strokecolor orange%drag xy%fontfamily 26px Times%centered%latex 3,5,\\frac{1}{5}+ \\frac{\\pi}{6}
  2560.    @%latex%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%vline 0,0,green%hline 0,0,green%fontfamily 16px Arial%fillcolor orange%strokecolor blue%linewidth 2%slider 0,4*pi,400,40,angle degree active, %centered%latex 0,0,\\frac{12345}{23456} \\times \\frac{12345}{23456}%translate 4,4%centered%rotate 180%drag xy%html 0,0,<table><tr><th>HTML TABLE</th></tr><tr><th><a href="https://wimsedu.info/">WIMS EDU </a> </th></tr><tr><td><img src="gifs/en.gif"></tr><tr><td><img src="gifs/nl.gif"></tr><tr><td><img src="gifs/fr.gif"></tr><tr><td><img src="gifs/cn.gif"></tr><tr><td><img src="gifs/it.gif"></tr></table>%userdraw arrow2,red
  2561.   */
  2562.           js_function[DRAW_XML] = 1;
  2563.           for(i=0;i<3;i++){
  2564.             switch(i){
  2565.               case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */
  2566.               case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system  -> pixel height */
  2567.               case 2: decimals = find_number_of_digits(precision);
  2568.                 temp = get_string(infile,1);
  2569.                 if(use_affine == TRUE ){ transform(2,2);}/* slider will use css-rotate transformation */
  2570.                 if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */
  2571.                 int_data[0] = x2px(double_data[0]);
  2572.                 int_data[1] = y2px(double_data[1]);
  2573.                 if( use_slider != -1 && onclick == 0 ){ onclick = 5;}
  2574.                 if( use_slider != -1 && drag_type != -1){ onclick = 5; }
  2575. #ifdef KATEX_INSTALLED
  2576.                 if( strstr(temp,"\\") != 0 ){ temp = str_replace(temp,"\\","\\\\"); }
  2577.                 if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2578.                 string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'katex',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,drawxml_cnt);
  2579.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2580.                 snprintf(tmp_buffer,string_length,  "var draw_xml%d = {id:%d,type:'katex',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,drawxml_cnt);
  2581. #else
  2582.                 temp = getMML(temp);/* generate MathML for Firefox or MathJaX */
  2583.                 if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2584.                 string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'mathml',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,drawxml_cnt);
  2585.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2586.                 snprintf(tmp_buffer,string_length,  "var draw_xml%d = {id:%d,type:'mathml',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,drawxml_cnt);
  2587. #endif
  2588.                 add_to_buffer(tmp_buffer);
  2589.                 if(onclick != 0 ){object_cnt++;}
  2590.                 drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */
  2591.                 break;
  2592.               default:break;
  2593.               }
  2594.           }
  2595.           reset();
  2596.           break;
  2597.         case LATTICE:
  2598.   /*
  2599.    @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
  2600.    @ can <b>not</b> be set ''onclick`` or ''drag xy``
  2601.    @%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
  2602.   */
  2603.           js_function[DRAW_LATTICE] = 1;
  2604.           for( i = 0; i<9; i++){
  2605.             switch(i){
  2606.               case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
  2607.               case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
  2608.               case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
  2609.               case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
  2610.               case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
  2611.               case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
  2612.               case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
  2613.               case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
  2614.               case 8: stroke_color=get_color(infile,1);
  2615.                 decimals = find_number_of_digits(precision);
  2616.                 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); ",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_filled);
  2617.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2618.                 snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%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_filled);
  2619.                 add_to_buffer(tmp_buffer);break;
  2620.               default:break;
  2621.             }
  2622.           }
  2623.           reset();
  2624.           break;
  2625.         case LINEAR:
  2626.   /*
  2627.    @ linear a,b,c,d
  2628.    @ defines a transformation matrix for subsequent objects
  2629.    @ use keyword <a href='#killlinear'>killlinear</a> to end the transformation...the next objects will be drawn in the original x/y-range
  2630.    @ a: Scales the drawings horizontally
  2631.    @ b: Skews the drawings horizontally
  2632.    @ c: Skews the drawings vertically
  2633.    @ d: Scales the drawings vertically
  2634.    @ the data precision may be set by preceding command ''precision int``
  2635.    @ note: any active translation (tx,ty) is not changed
  2636.    @%linear%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%fcircle 5,5,40,blue%linear 0.2,0,0,0.2%fcircle 5,5,40,green
  2637.   */
  2638.           for(i = 0 ; i<4;i++){
  2639.             switch(i){
  2640.               case 0: affine_matrix[0] = get_real(infile,0);break;
  2641.               case 1: affine_matrix[1] = get_real(infile,0);break;
  2642.               case 2: affine_matrix[2] = get_real(infile,0);break;
  2643.               case 3: affine_matrix[3] = get_real(infile,1);
  2644.                 affine_matrix[4] = 0;affine_matrix[5] = 0;
  2645.                 use_affine = TRUE;
  2646.                 break;
  2647.               default: break;
  2648.             }
  2649.           }
  2650.           reset();
  2651.          break;
  2652.         case LINE:
  2653.   /*
  2654.   @ line x1,y1,x2,y2,color
  2655.   @ draw a line through points (x1:y1)--(x2:y2) in color ''color``
  2656.   @ or use command ''curve color,formula`` to draw the line (uses more points to draw the line; is however better draggable)
  2657.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2658.   @%line%size 400,400%xrange -10,10%yrange -10,10%line 0,1,2,-1,green
  2659.   */
  2660.           for(i=0;i<5;i++){
  2661.             switch(i){
  2662.               case 0: double_data[10]= get_real(infile,0);break; /* x-values */
  2663.               case 1: double_data[11]= get_real(infile,0);break; /* y-values */
  2664.               case 2: double_data[12]= get_real(infile,0);break; /* x-values */
  2665.               case 3: double_data[13]= get_real(infile,0);break; /* y-values */
  2666.               case 4: stroke_color=get_color(infile,1);/* name or hex color */
  2667.                 if( double_data[10] == double_data[12] ){ /* vertical line*/
  2668.                   double_data[1] = xmin;
  2669.                   double_data[3] = ymax;
  2670.                   double_data[0] = double_data[10];
  2671.                   double_data[2] = double_data[10];
  2672.                 }
  2673.                 else{
  2674.                   if( double_data[11] == double_data[13] ){ /* horizontal line */
  2675.                     double_data[1] = double_data[11];
  2676.                     double_data[3] = double_data[11];
  2677.                     double_data[0] = ymin;
  2678.                     double_data[2] = xmax;
  2679.                 }
  2680.                 else {
  2681.       /* m */
  2682.                   double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
  2683.       /* q */
  2684.                   double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
  2685.       /*xmin,m*xmin+q,xmax,m*xmax+q*/
  2686.                   double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
  2687.                   double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
  2688.                   double_data[0] = xmin;
  2689.                   double_data[2] = xmax;
  2690.                 }
  2691.               }
  2692.               if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);}
  2693.               if(use_affine == TRUE ){ transform(4,2);}
  2694.               if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2695.  
  2696.               decimals = find_number_of_digits(precision);
  2697.               string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2698.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2699.               snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2700.               add_to_buffer(tmp_buffer);
  2701.               if(onclick != 0){object_cnt++;}
  2702.         /* object_cnt++;*/
  2703.               reset();
  2704.               break;
  2705.             }
  2706.           }
  2707.           dragstuff[4] = 1;
  2708.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2709.           break;
  2710.         case LINES:
  2711.   /*
  2712.   @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n
  2713.   @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color'
  2714.   @ or use multiple commands ''curve color,formula`` or ''jscurve color,formule`` to draw the line <br>(uses more points to draw the line; is however better draggable)
  2715.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2716.   @ <b>attention</b>: the flydraw command ''lines`` is equivalent to canvasdraw command <a href="#polyline">polyline</a>
  2717.   @%lines%size 400,400%xrange -10,10%yrange -10,10%lines green,0,1,1,3,0,0,1,3,0,0,-2,1
  2718.   */
  2719.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  2720.           fill_color = stroke_color;
  2721.           i=0;
  2722.           while( ! done ){     /* get next item until EOL*/
  2723.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2724.             if(i%2 == 0 ){
  2725.               double_data[i] = get_real(infile,0); /* x */
  2726.             }
  2727.             else {
  2728.               double_data[i] = get_real(infile,1); /* y */
  2729.             }
  2730.             i++;
  2731.           }
  2732.           decimals = find_number_of_digits(precision);
  2733.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2734.           for(c = 0 ; c < i-1 ; c = c+4){
  2735.             if(double_data[c] == double_data[c+2] ){ /* vertical line*/
  2736.               double_data[c+1] = xmin;
  2737.               double_data[c+3] = ymax;
  2738.               double_data[c+2] = double_data[c];
  2739.             }
  2740.             else {
  2741.               if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  2742.                 double_data[c+3] = double_data[c+1];
  2743.                 double_data[c] = ymin;
  2744.                 double_data[c+2] = xmax;
  2745.               }
  2746.               else {
  2747.       /* m */
  2748.                 double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  2749.       /* q */
  2750.                 double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  2751.       /*xmin,m*xmin+q,xmax,m*xmax+q*/
  2752.                 double_data[c+1] = (m)*(xmin)+(q);
  2753.                 double_data[c+3] = (m)*(xmax)+(q);
  2754.                 double_data[c] = xmin;
  2755.                 double_data[c+2] = xmax;
  2756.               }
  2757.             }
  2758.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  2759.             if(use_affine == TRUE ){ transform(i-1,2);}
  2760.  
  2761.           string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2762.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2763.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2764.             add_to_buffer(tmp_buffer);
  2765.             if(onclick != 0){object_cnt++;}
  2766.     /* object_cnt++; */
  2767.           }
  2768.           dragstuff[4] = 1;
  2769.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2770.           reset();
  2771.           break;
  2772.         case LINEWIDTH:
  2773.   /*
  2774.   @ linewidth int
  2775.   @ default 1
  2776.   @%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
  2777.   */
  2778.           line_width = (int) (get_real(infile,1));
  2779.           break;
  2780.         case LEVELCURVE:
  2781.   /*
  2782.   @ levelcurve color,expression in x/y,l1,l2,...
  2783.   @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
  2784.   @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br>(choose flydraw if you want quality...)
  2785.   @ every individual level curve may be set 'onclick / drag xy' <br>e.g. every single level curve (l1,l2,l3...l_n) has a unique identifier
  2786.   @ note: the arrays for holding the javascript data are limited in size
  2787.   @ note: reduce image size if javascript data arrays get overloaded<br>(command 'plotsteps int' will not control the data size of the plot...)
  2788.   @%levelcurve%size 400,400%xrange -10,10%yrange -10,10%levelcurve red,x*y,1,2,3,4
  2789.   */
  2790.           fill_color = get_color(infile,0);
  2791.           char *fun1 = get_string_argument(infile,0);
  2792.           if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  2793.           i = 0;
  2794.           done = FALSE;
  2795.           while( !done ){
  2796.             double_data[i] = get_real(infile,1);
  2797.             i++;
  2798.           }
  2799.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2800.  
  2801.           for(c = 0 ; c < i; c++){
  2802.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2803.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2804.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  2805.             add_to_buffer(tmp_buffer);
  2806.             if(onclick != 0){object_cnt++;}
  2807.            /* object_cnt++; */
  2808.           }
  2809.           dragstuff[16] = 1;
  2810.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2811.           reset();
  2812.           break;
  2813.  
  2814.         case LEGEND:
  2815.   /*
  2816.   @ legend string1:string2:string3....string_n
  2817.   @ will be used to create a legend for a graph
  2818.   @ also see command <a href='#piechart'>piechart</a>
  2819.   @ will use the same colors per default as used in the graphs; use command <a href='#legendcolors'>legendcolors</a> to override the default
  2820.   @ use command <a href="#fontsize">fontsize</a> to adjust. (command ''fontfamily`` is not active for command ''legend``)
  2821.   @%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
  2822.   */
  2823.           temp = get_string(infile,1);
  2824.           if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2825.           legend_cnt++; /* attention: starts with -1: it will be used in piechart etc */
  2826.           fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
  2827.           break;
  2828.  
  2829.         case LEGENDCOLORS:
  2830.   /*
  2831.   @ legendcolors color1:color2:color3:...:color_n
  2832.   @ 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>.
  2833.   @ make sure the number of colors match the number of legend items
  2834.   @ command ''legend`` in case of ''piechart`` and ''barchart`` will use these colours per default (no need to specify ''legendcolors``)
  2835.   @%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
  2836.   */
  2837.           if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
  2838.           temp = get_string(infile,1);
  2839.           if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2840.           fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
  2841.           break;
  2842.         case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed', 'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
  2843.   /*
  2844.   @ linegraph x1:y1:x2:y2...x_n:y_n
  2845.   @ will plot your data in a graph
  2846.   @ may <b>only</b> to be used together with command <a href='#grid'>grid</a>
  2847.   @ 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>
  2848.   @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner
  2849.   @ also see command <a href='#piechart'>piechart</a>
  2850.   @ multiple linegraphs may be used in a single plot
  2851.   @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble...
  2852.   @ <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>
  2853.   @%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
  2854.   */
  2855.           temp = get_string(infile,1);
  2856.           if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2857.           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);
  2858.           linegraph_cnt++;
  2859.           reset();
  2860.           break;
  2861.         case MATHML:
  2862.   /*
  2863.   @ mathml x1,y1,mathml_string
  2864.   @ this command is special for GECKO browsers, and it makes use of Native Mathml
  2865.   @ For general use with all browsers, use command <a href='#latex'>latex</a>
  2866.   @ can be set <a href='onclick'>onclick</a>  and <a href='drag'>drag&amp;drop</a> <br>Note: dragging is fairly primitive dragging of the div-element, and is not done using the <em>dragstuff library</em>
  2867.   @ command <a href='#affine'>affine</a> will produce CSS3 matrix transformations
  2868.   @ command <a href='#rotate'>rotate</a> will rotate the object
  2869.   @ the mathml object is centered at (x1:y1)
  2870.   @ the ''mathml_string`` can be produced using WIMS commands like ''texmath`` followed by ''mathmlmath``... or write correct TeX and use only ''mathmlmath``
  2871.   @ mathml will be displayed in a rectangle left top (x1:y1)
  2872.   @ 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
  2873.   @ 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...
  2874.   @ 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.
  2875.   @ 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.
  2876.   @ userdraw may be combined with 'mathml' ; the read_canvas() will contain the drawing.
  2877.   @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick mathml
  2878.   @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret...
  2879.   @ 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();"
  2880.   @ 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....
  2881.   @ use keyword <a href='#centered'>centered</a> to center the mathml/xml object on (x1:y1)
  2882.   @%mathml_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%strokecolor red%mathml -5,5,<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,<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>
  2883.   @%mathml_drag%size 400,400%xrange -10,10%yrange -10,10%drag xy%strokecolor red%mathml -5,5,<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,<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...
  2884.   */
  2885.           js_function[DRAW_XML] = 1;
  2886.           for(i=0;i<3;i++){
  2887.             switch(i){
  2888.               case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */
  2889.               case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system  -> pixel height */
  2890.               case 2: decimals = find_number_of_digits(precision);
  2891.                 if(use_affine == TRUE ){ transform(2,2);}/* needs double_data[] */
  2892.                 if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */
  2893.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2894.                 int_data[0] = x2px(double_data[0]);/* needs px */
  2895.                 int_data[1] = y2px(double_data[1]);
  2896.                 if( use_slider != -1 && onclick == 0 ){ onclick = 3;}/* no drag&onclick but slideable */
  2897.                 if( use_slider != -1 && drag_type != -1){ onclick = 5; }
  2898.                 temp = get_string(infile,1);
  2899.                 if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2900.                 string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'mathml',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%d,rotation_center:%s,once:true};draw_xml(draw_xml%d);slidergroup[%d] = null;\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,use_slider,rotation_center,drawxml_cnt,object_cnt);
  2901.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2902.                 snprintf(tmp_buffer,string_length,  "var draw_xml%d = {id:%d,type:'mathml',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%d,rotation_center:%s,once:true};draw_xml(draw_xml%d);slidergroup[%d] = null;\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,use_slider,rotation_center,drawxml_cnt,object_cnt);
  2903.                 add_to_buffer(tmp_buffer);
  2904.                 if(onclick != 0 ){object_cnt++;}
  2905.                 drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */
  2906.           /*
  2907.             in case inputs are present, trigger adding the read_mathml()
  2908.             if no other reply_format is defined
  2909.             note: all other reply types will include a reading of elements with id='mathml'+p)
  2910.           */
  2911.                 if(strstr(temp,"mathml0") != NULL){ if(reply_format == 0 ){reply_format = 16;}} /* no other reply type is defined */
  2912.                 break;
  2913.               default:break;
  2914.             }
  2915.           }
  2916.           reset();
  2917.           break;
  2918.         case MOUSE:
  2919.   /*
  2920.    @ mouse color,fontsize
  2921.    @ will display the cursor (x:y) coordinates in ''color`` and ''fontsize`` using default fontfamily Arial
  2922.    @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``)
  2923.    @%mouse%size 400,400%xrange -10,10%yrange -10,10%mouse red,22
  2924.   */
  2925.           stroke_color = get_color(infile,0);
  2926.           font_size = (int) (get_real(infile,1));
  2927.           tmp_buffer = my_newmem(26);
  2928.           snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2929.           add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,2);
  2930.           js_function[INTERACTIVE] = 1;
  2931.           break;
  2932.         case MOUSE_DEGREE:
  2933.   /*
  2934.    @ mouse_degree color,fontsize
  2935.    @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in 'color' and 'font size'<br> using a fontfamily Arial
  2936.    @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
  2937.    @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  2938.    @%mouse_degree%size 400,400%xrange -10,10%yrange -10,10%userdraw arc,blue%precision 100000%mouse_degree red,22
  2939.   */
  2940.           stroke_color = get_color(infile,0);
  2941.           font_size = (int) (get_real(infile,1));
  2942.           tmp_buffer = my_newmem(26);
  2943.           snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2944.           add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,3);
  2945.           js_function[JS_FIND_ANGLE] = 1;
  2946.           js_function[INTERACTIVE] = 1;
  2947.           break;
  2948.         case MOUSE_DISPLAY:
  2949.   /*
  2950.    @ display TYPE,color,fontsize
  2951.    @ TYPE may be x | y | xy | degree | radian | radius
  2952.    @ will display the mouse cursor coordinates as x-only,y-only,(x:y), the radius of a circle (this only in case 'userdraw circle(s),color') or the angle in degrees or radians for commands <code>userdraw arc,color</code> or protractor, ruler (if set dynamic).
  2953.    @ use commands ''xunit`` and / or ''yunit`` to add the units to the mouse values. The ''degree | radian`` will always have the appropriate symbol).
  2954.    @ just like commands ''mouse``, ''mousex``, ''mousey``, ''mouse_degree``... only other name
  2955.    @%display_x%size 400,400%xrange -10,10%yrange -10,10%xunit \\u212B%display x,red,22
  2956.    @%display_y%size 400,400%xrange -10,10%yrange -10,10%yunit seconds%display y,red,22
  2957.    @%display_xy%size 400,400%xrange -10,10%yrange -10,10%xunit centimetre%yunit seconds%display xy,red,22%userdraw segments,blue
  2958.    @%display_deg%size 400,400%xrange -10,10%yrange -10,10%display degree,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
  2959.    @%display_rad%size 400,400%xrange -10,10%yrange -10,10%display radian,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
  2960.    @%display_radius%size 400,400%xrange -10,10%yrange -10,10%xunit cm%xunit \\u212b%display radius,red,22%userdraw circle,blue
  2961.   */
  2962.           temp = get_string_argument(infile,0);
  2963.           if( strstr(temp,"xy") != NULL ){
  2964.             int_data[0] = 2;
  2965.           } else {
  2966.             if( strstr(temp,"y") != NULL ){
  2967.               int_data[0] = 1;
  2968.             }else{
  2969.               if( strstr(temp,"x") != NULL ){
  2970.                 int_data[0] = 0;
  2971.               }else{
  2972.                 if(strstr(temp,"degree") != NULL){
  2973.                 int_data[0] = 3;
  2974.                 js_function[JS_FIND_ANGLE] = 1;
  2975.                 }else{
  2976.                   if(strstr(temp,"radian") != NULL){
  2977.                     int_data[0] = 4;
  2978.                     js_function[JS_FIND_ANGLE] = 1;
  2979.                   }else{
  2980.                     if(strstr(temp,"radius") != NULL){
  2981.                       int_data[0] = 5;
  2982.                     }else{
  2983.                       int_data[0] = 2;
  2984.                     }
  2985.                   }
  2986.                 }
  2987.               }
  2988.             }
  2989.           }
  2990.           stroke_color = get_color(infile,0);
  2991.           font_size = (int) (get_real(infile,1));
  2992.           tmp_buffer = my_newmem(26);
  2993.           snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2994.           add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
  2995.           js_function[INTERACTIVE] = 1;
  2996.           break;
  2997.         case MOUSE_PRECISION:
  2998.   /*
  2999.       @ precision int
  3000.       @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
  3001.       @ may be used / changed before every object
  3002.       @ In case of user interaction (like ''userdraw`` or ''multidraw``), this value will be used to determine the amount of decimals in the reply / answer
  3003.       @%precision%size 400,400%xrange -10,10%yrange -10,10%precision 1%userdraw segment,red
  3004.   */
  3005.           precision = (int) (get_real(infile,1));
  3006.           if(precision < 1 ){precision = 1;};
  3007.           break;
  3008.         case MOUSEX:
  3009.   /*
  3010.    @ mousex color,fontsize
  3011.    @ will display the cursor x-coordinate in ''color`` and ''font size`` using the fontfamily Arial.
  3012.    @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``).
  3013.  
  3014.   */
  3015.           stroke_color = get_color(infile,0);
  3016.           font_size = (int) (get_real(infile,1));
  3017.           tmp_buffer = my_newmem(26);
  3018.           snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  3019.           add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,0);
  3020.           js_function[INTERACTIVE] = 1;
  3021.           break;
  3022.         case MOUSEY:
  3023.   /*
  3024.    @ mousey color,fontsize
  3025.    @ will display the cursor y-coordinate in ''color`` and ''font size`` using default fontfamily Arial.
  3026.    @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``).
  3027.  
  3028.   */
  3029.           stroke_color = get_color(infile,0);
  3030.           font_size = (int) (get_real(infile,1));
  3031.           tmp_buffer = my_newmem(26);
  3032.           snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  3033.           add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,1);
  3034.           js_function[INTERACTIVE] = 1;
  3035.           break;
  3036.         case MULTIDASH:
  3037.   /*
  3038.    @ multidash 0,1,1
  3039.    @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <code>multifill points,circle,segments</code>, are dashed
  3040.    @ use before command <a href='#multidraw'>multidraw</a>
  3041.    @ if not set all objects will be set ''not dashed``... unless a generic keyword ''dashed`` was given before command ''multidraw``
  3042.    @ the dash-type is not -yet- adjustable <br>(e.g. command <code>dashtype line_px,space_px</code> will give no control over multidraw objects)
  3043.    @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  3044.    @ always use the same sequence as is used for ''multidraw``
  3045.   */
  3046.           if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3047.           temp = get_string(infile,1);
  3048.           temp = str_replace(temp,",","\",\"");
  3049.           fprintf(js_include_file,"var multidash = [\"%s\"];",temp);
  3050.           reset();/* if command 'dashed' was given...reset to not-dashed */
  3051.           break;
  3052.         case MULTIDRAW:
  3053.   /*
  3054.    @ multidraw obj_type_1,obj_type_2...obj_type_11
  3055.    @ for simple single object user drawings you could also use command <a href="#userdraw">userdraw</a>
  3056.    @ 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<br><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><li>crosshair | crosshairs</li><li>function <br/>for more function user input fields, use it multiple times<br>for 4 inputfields use : multidraw function,function,function,function</li></ul>
  3057.    @ additionally objects may be user labelled, using obj_type ''text``...<br>in this case allways a text input field and if <a href='#multiuserinput'> multiuserinput=1 </a> also (x:y) inputfields will be added to the page.<br>use commands ''fontfamily`` and ''fontcolor`` to adjust (command ''multistrokeopacity`` may be set to adjust text opacity)<br>note: text is always centered on the mouse-click or user-input coordinates !<br>note: no keyboard listeners are used
  3058.    @ it makes no sense using something like ''multidraw point,points`` ... <br>something like "multidraw polys4,polys7" will only result in drawing a ''4 point polygone`` and not a ''7 point polygone``: this is a design flaw and not a feature...
  3059.    @ 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)
  3060.    @ 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 'css some_css'
  3061.    @ the button label will be default the ''object primitive name`` (like ''point``, ''circles``).<br>If you want a different label (e.g. an other language), use command ''multilabel``<br>for example in dutch: <br><code>multilabel cirkel,lijnstuk,punten,STOP<br>multidraw circle,segment,points</code><br>(see command <a href='#multilabel'>multilabel</a> for more details)
  3062.    @ a right mouse button click will remove the last drawn object of the selected drawing type. All other type of objects are not removed
  3063.    @ multidraw is incompatible with command ''tooltip`` (the reserved div_area is used for the multidraw control buttons)
  3064.    @ all ''multidraw`` drawings will scale on zooming.<br>this in contrast to the command <a href="#userdraw">userdraw</a>.
  3065.    @ wims will <b>not</b> check the amount or validity of your command arguments ! <br>( use javascript console to debug any typo's )
  3066.    @ a local function <code>read_canvas%d</code> will read all userbased drawings.<br>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 = crosshairs_x +";"+ crosshairs_y +"\\n"<br>line 16 = userdraw_x +";"+userdraw_y + "\\n" note: this is for single ''userdraw object,color`` and ''replyformat 29``<br/>line 17 = 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>
  3067.    @ It is best to prepare / format the student reply in clientside javascript.<br>However in ''wims`` language you could use something like this<br>for example you are interested in the polys5 drawings of a pupil (the pupil may draw multiple poly5 objects...)<br>note: the reply for 2 poly5's is: x11,x12,x13,x14,x15,x21,x22,x23,x24,x25 ; y11,y12,y13,y14,y15,y21,y22,y23,y24,y25<br>rep = !line 7 of reply <br>rep = !translate ';' to '\\n' in &#36;rep <br>pts = 5 # 5 points for polygon <br>x_rep = !line 1 of &#36;rep <br>y_rep = !line 2 of &#36;rep <br>tot = !itemcnt &#36;x_rep <br>num_poly = &#36;[&#36;tot/&#36;pts] <br>idx = 0 <br>!for p=1 to &#36;num_poly <br>&nbsp;!for s=1 to &#36;pts <br>&nbsp;&nbsp;!increase idx <br>&nbsp;&nbsp;X = !item &#36;idx of &#36;x_rep <br>&nbsp;&nbsp;Y = !item &#36;idx of &#36;y_rep <br>&nbsp;&nbsp;# do some checking <br>&nbsp;!next s <br>!next p <br>
  3068.    @ <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.
  3069.    @ technical: all 10 ''draw primitives`` + ''text`` will have their own -transparent- PNG bitmap canvas. <br>So for example there can be a points_canvas entirely separated from a line_canvas.<br>This to avoid the need for a complete redraw when something is drawn to the canvas...(eg only the object_type_canvas is redrawn), this in contrast too many very slow do-it-all HTML5 canvas javascript libraries.<br>The mouselisteners are attached to the canvas-div element.
  3070.    @ 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<br> (left mouse button/onclick) and placed on the canvas...left mouse click.<br>using div's will enable you -amongst other content- to add math typesetting from the exercise page onto the canvas.
  3071.    @ When you are not content with the default ''multidraw control panel``, you can create your own interface, using a few javascript functions to call the drawprimitives, delete things and ''stop drawing`` in case you also want to drag&drop stuff...</br>To activate this feature, use <a href='#multilabel'>multilabel NOCONTROLS</a><br>The object types are internally represented by the following numbers (making typos will render your exercise null and void)<br/>point = 0<br>points =1<br>circle = 2<br>circles = 3<br>line = 4<br>lines = 5<br>segment = 6<br>segments = 7<br>arrow = 8<br>arrows = 9<br>triangle = 10<br>triangles = 11<br>closedspoly = 12<br>text = 13<br>rect = 14<br>rects = 15<br>poly[3-9] = 16<br>polys[3-9] = 17<br>parallelogram = 18<br>parallelograms = 19<br>images  = 20<br>curvedarrow = 21<br>curvedarrows = 22<br>curvedarrow2 = 23<br>curvedarrows2 = 24<br>crosshair = 25<br>crosshairs = 26 <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_object_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 canvas_scripts[n] <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')<br>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"
  3072.    @%multidraw_function%size 400,400%xrange -10,10%yrange -10,10%fontfamily Italic 22px Helvetica%axis%axisnumbering%precision 0%grid 2,2,grey,1,1,5,black%multicolors red,green,blue%fontcolor orange%multilinewidth 1,2,3%multidraw text,function,function,function,line
  3073.    @%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
  3074.    @%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%css 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
  3075.    @%multidraw_demo%size 800,800%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%css 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
  3076.    @%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
  3077.   */
  3078.           js_function[INTERACTIVE] = 1;
  3079.           if(js_function[JS_ZOOM] == 1){use_zoom = 1;} /* use noisy zoom_code, when command zoom is given before command 'multidraw' */
  3080.           if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3081.           if( use_userdraw == 1 ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");}
  3082.           use_userdraw = 2;
  3083.           temp = get_string(infile,1);
  3084.           fprintf(js_include_file,"\
  3085.            var MMP = %d;\
  3086.            if( typeof(multisnaptogrid) == 'undefined' && multisnaptogrid == null){var multisnaptogrid = new Array(MMP);for(var i=0;i<MMP;i++){multisnaptogrid[i] = %d;};};\
  3087.            if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null){ var multistrokecolors = new Array(MMP);for(var i=0;i<MMP;i++){multistrokecolors[i] = '%s';};};\
  3088.            if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){var multifillcolors = new Array(MMP);for(var i=0;i<MMP;i++){multifillcolors[i] = '%s';};};\
  3089.            if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null){var multistrokeopacity = new Array(MMP);for(var i=0;i<MMP;i++){multistrokeopacity[i] = %.2f;};};\
  3090.            if( typeof(multifillopacity) === 'undefined' &&  multifillopacity == null){var multifillopacity = new Array(MMP);for(var i=0;i<MMP;i++){multifillopacity[i] = %.2f;};};\
  3091.            if( typeof(multilinewidth) === 'undefined' && multilinewidth == null){var multilinewidth = new Array(MMP);for(var i=0;i<MMP;i++){multilinewidth[i] = %d;};};\
  3092.            if( typeof(multifill) === 'undefined' && multifill == null){var multifill = new Array(MMP);for(var i=0;i<MMP;i++){multifill[i] = %d;};};\
  3093.            if( typeof(multidash) === 'undefined' && multidash == null){var multidash = new Array(MMP);for(var i=0;i<MMP;i++){multidash[i] = %d;};};\
  3094.            if( typeof(multilabel) === 'undefined' && multilabel == null){var multilabel = [\"%s\",\"stop drawing\"];};\
  3095.            if( typeof(multiuserinput) === 'undefined' && multiuserinput == null){var multiuserinput = new Array(MMP);for(var i=0;i<MMP;i++){multiuserinput[i] = '0';};};\
  3096.            var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';var forbidden_zone = [xsize+2,ysize+2];",
  3097.             MAX_MULTI_PRIMITIVES,
  3098.             use_snap,
  3099.             stroke_color,
  3100.             fill_color,
  3101.             stroke_opacity,
  3102.             fill_opacity,
  3103.             line_width,
  3104.             use_filled,
  3105.             use_dashed,
  3106.             str_replace(temp,",","\",\""),
  3107.             arrow_head,font_color,font_family);
  3108.           add_js_multidraw(temp,css_class,use_offset,int_data[MAX_MULTI_PRIMITIVES+1],crosshair_size,use_zoom);
  3109.             /* no_controls == int_data[MAX_MULTI_PRIMITIVES+1] */
  3110.           reply_precision = precision;
  3111.           if(strstr(temp,"text") != NULL){
  3112.             js_function[JS_SAFE_EVAL] = 1;
  3113.             js_function[DRAW_SUBSUP] = 1;
  3114.           }
  3115.           if(strstr(temp,"function") != NULL){
  3116.             int pp, funs = count_substring(temp, "function");
  3117.             js_function[JS_SAFE_EVAL] = 1;
  3118.             js_function[JS_RAWMATH] = 1;
  3119.             js_function[DRAW_JSFUNCTION] = 1;
  3120.             js_function[JS_MATH] = 1;
  3121.             js_function[JS_PLOT] = 1;
  3122.             for(pp = 0 ; pp< funs ;pp++){
  3123.               add_input_jsfunction(css_class,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size);
  3124.               input_cnt++;
  3125.               jsplot_cnt++;
  3126.             }
  3127.             fprintf(js_include_file,"if(typeof(all_jsplots) !== 'number'){var all_jsplots;};all_jsplots = %d;function redraw_userdraw(){redraw_jsplot();return;};",jsplot_cnt);
  3128.           }
  3129.       /* the canvasses range from 1000 ... 1008 */
  3130.           if( reply_format == 0){reply_format = 29;}
  3131.           reset();/* if command 'filled' / 'dashed' was given...reset all */
  3132.           break;
  3133.         case MULTILABEL:
  3134.   /*
  3135.    @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text'
  3136.    @ use before command <a href='#multidraw'>multidraw</a>
  3137.    @ 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'...)
  3138.    @ 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>
  3139.    @ all buttons can be ''styled`` by using command <code>css</code><br><b>note:</b>If you want to add some CSS style to the buttons...<br>the id's of the ''draw buttons`` are their english command argument<br>(e.g. id="canvasdraw_points" for the draw points button).<br>the id of the ''stop drawing`` button is "canvasdraw_stop_drawing".<br>the id of the "OK" button is ''canvasdraw_ok_button``
  3140.    @ wims will not check the amount or validity of your input
  3141.    @ always use the same sequence as is used for ''multidraw``
  3142.    @ if you don't want the controls, and want to write your own interface, set <code>multilabel NOCONTROLS</code>
  3143.   */
  3144.           if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3145.           temp = get_string(infile,1);
  3146.           if( strcasestr(temp,"NOCONTROLS") ){
  3147.             int_data[MAX_MULTI_PRIMITIVES+1] = 1; /*int_data[25] = 1 --> 'no_controls = 1' in canvasmacro.c */
  3148.             fprintf(js_include_file,"var multilabel = null;");
  3149.           }
  3150.           else {
  3151.             int_data[MAX_MULTI_PRIMITIVES+1] = 0; /* so DO use control buttons etc */
  3152.             temp = str_replace(temp,",","\",\"");
  3153.             fprintf(js_include_file,"var multilabel = [\"%s\"];",temp);
  3154.           }
  3155.           break;
  3156.         case MULTILINEWIDTH:
  3157.   /*
  3158.    @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8
  3159.    @ use before command <a href='#multidraw'>multidraw</a>
  3160.    @ if not set all line widths will be set by a previous command ''linewidth int``
  3161.    @ 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>
  3162.    @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  3163.    @ always use the same sequence as is used for ''multidraw``
  3164.   */
  3165.           if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3166.           temp = get_string(infile,1);
  3167.           temp = str_replace(temp,",","\",\"");
  3168.           fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp);
  3169.           break;
  3170.         case MULTIFILL:
  3171.   /*
  3172.    @ multifill 0,0,1,0,1,0,0
  3173.    @ 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...)
  3174.    @ using a fillpattern: multifill 0,1,2,5,3,4<br>meaning: first object is not filled...second object is solid color filled...2=grid | 3=hatch | 4=diamond | 5=dot
  3175.    @ use before command <a href='#multidraw'>multidraw</a>
  3176.    @ 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>
  3177.    @ only suitable for draw_primitives like ''circle | circles``, ''triangle | triangles``, ''rect | rects``, ''poly[3-9] | polys[3-9]`` and ''polygon``
  3178.    @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  3179.    @ always use the same sequence as is used for ''multidraw``
  3180.   */
  3181.           if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3182.           i=0;
  3183.           while( ! done ){     /* get next item until EOL*/
  3184.             if(i > MAX_MULTI_PRIMITIVES){canvas_error("too many multidraw primitives...read the documentation...");}
  3185.             int_data[i] = (int)(get_real(infile,1)); /* 0,1,2,3,4,5 */
  3186.             if(int_data[i] < 0 || int_data[i] > 5 ){canvas_error("the only possible multifill arguments are: 0,1,2,3,4,5 ");}
  3187.             if(int_data[i] > 1 ){use_filled = 2;js_function[DRAW_FILL_PATTERN] = 1;}/* switch to trigger pattern filling */
  3188.             i++;
  3189.           }
  3190.           fprintf(js_include_file,"var multifill = %s ;",data2js_array(int_data,i-1));
  3191.           break;
  3192.         case MULTIFILLCOLORS:
  3193.   /*
  3194.    @ multifillcolors color_name_1,color_name_2,...,color_name_8
  3195.    @ use before command <a href='#multidraw'>multidraw</a>
  3196.    @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be ''stroke_color``, ''fill_opacity``
  3197.    @ 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>
  3198.    @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
  3199.    @ always use the same sequence as is used for ''multidraw``
  3200.    @ can also be used with command <a href='#userdraw'>userdraw clickfill,color</a> when more than one fillcolor is wanted.<br>in that case use for example <a href='#replyformat'>replyformat 10</a> ... reply=x1:y1:color1,x2:y2:color2...<br>the colors will restart at the first color, when there are more fill-clicks than multi-fill-colors<br>if more control over the used colours is wanted, see command <a href='#colorpalette'>colorpalette color1,color2...</a>
  3201.   */
  3202.           if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3203.           fprintf(js_include_file,"var multifillcolors = [");
  3204.           while( ! done ){
  3205.             temp = get_color(infile,1);
  3206.             fprintf(js_include_file,"\"%s\",",temp);
  3207.           }
  3208.           fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
  3209.           break;
  3210.         case MULTIFILLOPACITY:
  3211.   /*
  3212.    @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8
  3213.    @ float values 0 - 1 or integer values 0 - 255
  3214.    @ use before command <a href='#multidraw'>multidraw</a>
  3215.    @ if not set all fill opacity_ will be set by previous command <code>opacity int,int</code> and keyword ''filled``
  3216.    @ 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>
  3217.    @ wims will not check the amount or validity of your input
  3218.    @ always use the same sequence as is used for ''multidraw``
  3219.   */
  3220.           if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3221.           temp = get_string(infile,1);
  3222.           temp = str_replace(temp,",","\",\"");
  3223.           fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp);
  3224.           break;
  3225.         case MULTISNAPTOGRID:
  3226.   /*
  3227.    @ multisnaptogrid 0,1,1
  3228.    @ alternative: multisnap
  3229.    @ 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>)
  3230.    @ freehand drawing...specify precision for reply: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code>
  3231.    @ only the xy-values snap_to_grid: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code>
  3232.    @ only the x-values snap_to_grid: all objects snap to x-grid <code>multisnaptogrid 2,2,2,...</code>
  3233.    @ only the y-values snap_to_grid: all objects snap to y-grid <code>multisnaptogrid 3,3,3,...</code>
  3234.    @ 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>
  3235.    @ <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>
  3236.    @ use before command <a href='#multidraw'>multidraw</a>
  3237.    @ attention: if not set all objects will be set ''no snap``... unless a generic command ''snaptogrid`` was given before command ''multidraw``
  3238.    @ commands <a href='#xsnaptogrid'>xsnaptogrid</a>, <a href='#ysnaptogrid'>ysnaptogrid</a>, <a href='#snaptofunction'>snaptofunction</a> are <b>not</b> supported amd only functional for command <a href='#userdraw'>userdraw</a>
  3239.    @ always use the same sequence as is used for ''multidraw``
  3240.    @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  3241.   */
  3242.           if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3243.           temp = get_string(infile,1);
  3244.           fprintf(js_include_file,"var multisnaptogrid = [%s];",temp);
  3245.           reset();/* if command 'dashed' was given...reset to not-dashed */
  3246.           break;
  3247.         case MULTISTROKECOLORS:
  3248.   /*
  3249.    @ multistrokecolors color_name_1,color_name_2,...,color_name_8
  3250.    @ use before command <a href='#multidraw'>multidraw</a>
  3251.    @ if not set all colors will be ''stroke_color``, ''stroke_opacity``
  3252.    @ 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>
  3253.    @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
  3254.    @ always use the same sequence as is used for ''multidraw``
  3255.   */
  3256.           if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3257.           fprintf(js_include_file,"var multistrokecolors = [");
  3258.           while( ! done ){
  3259.             temp = get_color(infile,1);
  3260.             fprintf(js_include_file,"\"%s\",",temp);
  3261.           }
  3262.           fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
  3263.           break;
  3264.         case MULTISTROKEOPACITY:
  3265.   /*
  3266.    @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7
  3267.    @ float values 0 - 1 or integer values 0 - 255
  3268.    @ use before command <a href='#multidraw'>multidraw</a>
  3269.    @ if not set all stroke opacity_ will be set by previous command <code>opacity int,int</code>
  3270.    @ 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>
  3271.    @ wims will not check the amount or validity of your input
  3272.    @ always use the same sequence as is used for ''multidraw``
  3273.   */
  3274.           if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3275.           temp = get_string(infile,1);
  3276.           temp = str_replace(temp,",","\",\"");
  3277.           fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp);
  3278.           break;
  3279.  
  3280.         case MULTIUSERINPUT:
  3281.   /*
  3282.   @ multiuserinput 0,1,1,0
  3283.   @ alternative: multiinput
  3284.   @ meaning, when the command ''multidraw`` is used <code>multidraw circles,points,lines,triangles</code><br>objects ''points`` and ''lines`` may additionally be ''drawn`` by direct input (inputfields)<br/>all other objects must be drawn with a mouse
  3285.   @ 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
  3286.   @ 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...
  3287.   @ in case of a triangle | poly3, three inputfields are provided.
  3288.   @ in case of ''text`` and ''multiuserinput=1, 3`` inputfields will be shown: ''x,y,text``
  3289.   @ in case of ''text`` and ''multiuserinput=0, 1`` inputfield will be shown: text ... a mouse click will place the text on the canvas.
  3290.   @ may be styled using command <a href="#css">css</a>
  3291.   @ an additional button ''stop drawing`` may be used to combine userbased drawings with ''drag&and;drop`` or ''onclick`` elements
  3292.   @ when exercise if finished (status=done) the buttons will not be shown.<br>To override this default behaviour use command / keyword ''status``
  3293.   @ use before command <a href='#multidraw'>multidraw</a>
  3294.   @ always use the same sequence as is used for ''multidraw``
  3295.   */
  3296.       /* simple rawmath and input check */
  3297.           js_function[JS_SAFE_EVAL] = 1;
  3298.           temp = get_string(infile,1);
  3299.           temp = str_replace(temp,",","\",\"");
  3300.           fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp);
  3301.           break;
  3302.         case NORESET:
  3303.   /*
  3304.   @ noreset
  3305.   @ alternative: killreset
  3306.   @ keyword
  3307.   @ may come in handy if canvas script code is generated using loops
  3308.   @ if used the following properties will remain to be valid<br><ul><li>filled</li><li>dash settings</li><li>onclick or drag settings</li><li>centering or offset</li></ul>
  3309.   @ if used again, these properies will be reset to the default values and normal behaviour is continued (e.g. the above properties will be reset after 'use' on a canvas object)
  3310.   @ etc etc
  3311.   @ commands <a href='#slider'>slider</a>, <a href='#linear'>linear</a>, <a href='#rotate'>rotate</a>, <a href='#translate'>translate</a>, <a href='#affine'>affine</a> are always active until the 'kill' commands are given: <br><a href='#killlinear'>killlinear</a>, <a href='#killrotate'>killrotate</a>, <a href='#killtranslate'>killtranslate</a> and <a href='#killaffine'>killaffine</a>
  3312.   @ commands like 'opacity', 'linewidth', 'fontsize', 'fontfamily' are only changed when redefined again
  3313.   @%noreset%size 400,400%xrange -10,10%yrange -10,10%noreset%drag xy%linewidth 4%filled%rect -4,4,-2,2,blue%triangle -3,-3,0,0,1,-5,green%circle 0,0,50,orange%noreset%rect 2,4,4,2,blue
  3314.   @%noreset_oefgraduation%size 800,100%xrange 0,11%yrange -1,1%hline 0,0,black%parallel 0,0,0,0.5,1,0,11,blue%noreset%onclick%centered%text black,1,0.6,large,20%text black,2,0.6,large,30%text black,3,0.6,large,40%text black,4,0.6,large,50%text black,5,0.6,large,60%text black,6,0.6,large,70%text black,7,0.6,large,80%text black,8,0.6,large,90%text black,9,0.6,large,100%text black,10,0.6,large,110
  3315.   */
  3316.           if(no_reset == FALSE){no_reset = TRUE;}else{no_reset = FALSE;reset();}
  3317.           break;
  3318.         case NOXAXIS:
  3319.   /*
  3320.   @ noxaxis
  3321.   @ keyword
  3322.   @ if set, the automatic x-axis numbering will be ignored
  3323.   @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>)
  3324.   @ to be used before command grid (see <a href="#grid">command grid</a>)
  3325.   */
  3326.           fprintf(js_include_file,"x_strings = {};x_strings_up = [];\n");
  3327.           use_axis_numbering = -1;
  3328.           break;
  3329.         case NOYAXIS:
  3330.   /*
  3331.   @ noyaxis
  3332.   @ keyword
  3333.   @ if set, the automatic y-axis numbering will be ignored
  3334.   @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>)
  3335.   @ to be used before command grid (see <a href="#grid">command grid</a>)
  3336.   */
  3337.           fprintf(js_include_file,"y_strings = {};\n");
  3338.           break;
  3339.         case NUMBERLINE:
  3340.   /*
  3341.   @ numberline x0,x1,xmajor,xminor,y0,y1
  3342.   @ numberline is using xrange/yrange system for all dimensions
  3343.   @ multiple numberlines are allowed ; combinations with command <a href='#grid'>grid</a> is allowed; multiple commands <a href='#xaxis'>xaxis numbering</a> are allowed
  3344.   @ x0 is start x-value in xrange
  3345.   @ x1 is end x-value in xrange
  3346.   @ xmajor is step for major division
  3347.   @ xminor is divisor of xmajor; using small (30% of major tick) tick marks: this behaviour is ''hardcoded``
  3348.   @ is xminor is an even divisor, an extra tickmark (60% of major tick) is added to the numberline: this behaviour is ''hardcoded``
  3349.   @ y0 is bottom of numberline; y1 endpoint of major tics
  3350.   @ use command <a href="#linewidth">linewidth</a> to control appearance
  3351.   @ use <a href="#strokecolor">strokecolor</a> and <a href="#opacity">opacity</a> to controle measure line
  3352.   @ for all ticks linewidth and color / opacity are identical.
  3353.   @ 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
  3354.   @ use <a href="#fontfamily">fontfamily</a> and <a href="#fontcolor">fontcolor</a> to control fonts settings
  3355.   @ 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
  3356.   @ <a href="#snaptogrid">snaptogrid, snaptopoints etc</a> and <a href="#zoom">zooming and panning</a> is supported
  3357.   @ onclick and dragging of the numberline are not -yet- supported
  3358.   @ note: in case of multiple numberlines, make sure the numberline without special x-axis numbering (e.g. ranging from xmin to xmax) comes first !
  3359.   @%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
  3360.   */
  3361.           js_function[DRAW_NUMBERLINE] = 1;
  3362.           for(i=0;i<6;i++){
  3363.             switch(i){
  3364.               case 0: double_data[0] = get_real(infile,0);break;/* xmin */
  3365.               case 1: double_data[1] = get_real(infile,0);break;/* xmax */
  3366.               case 2: double_data[2] = get_real(infile,0);break;/* xmajor */
  3367.               case 3: double_data[3] = get_real(infile,0);break;/* xminor */
  3368.               case 4: double_data[4] = get_real(infile,0);break;/* ymin */
  3369.               case 5: double_data[5] = get_real(infile,1);/* ymax */
  3370.             /*
  3371.             var draw_numberline%d = function(canvas_type,xmin,xmax,xmajor,xminor,ymin,ymax,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor);
  3372.             */
  3373.                 fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[2] / double_data[3],double_data[5] - double_data[4] );
  3374.                 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);
  3375.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3376.                 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);
  3377.                 add_to_buffer(tmp_buffer);
  3378.                 numberline_cnt++;
  3379.                 break;
  3380.               default:break;
  3381.             }
  3382.           }
  3383.           reset();
  3384.           break;
  3385.         case OBABEL:
  3386.  
  3387.   /*
  3388.   @ obabel x,y,type input,molecule smiles-code or file location, extra arguments,extra arguments,...
  3389.   @ will call the ''obabel`` program, if installed.
  3390.   @ output will be an svg file
  3391.   @ see documentation of obabel for special keys
  3392.   @ command <a href='#affine'>affine</a> will produce CSS3 matrix transformations
  3393.   @ command <a href='#rotate'>rotate</a> will rotate the object
  3394.   @ can be set onclick: <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects<br>if 4 clickable object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object
  3395.   @ 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...
  3396.   @ 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
  3397.   @ external files may be loaded if they are present on the server or in the modules <br>for example:<br> obabel 0,0,mol,&#36;module_dir/caffeine.mol,-P100,-xb none
  3398.   @%obabel_smi%size 400,400%xrange -10,10%yrange -10,10%fillcolor green%drag xy%centered%obabel 0,0,smi,-:c1cFccc1cc,-xb none,-xB blue,-xi,-xt,-xa,-xX,-xP180,-h
  3399.   */
  3400.           js_function[DRAW_XML] = 1;
  3401.           for(i=0;i<4;i++){
  3402.             switch(i){
  3403.               case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */
  3404.               case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system  -> pixel height */
  3405.               case 2: URL = get_string_argument(infile,0);break;
  3406.               case 3:
  3407.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3408.                 temp = getSVGMOL(URL,get_string(infile,1));
  3409.                 decimals = find_number_of_digits(precision);
  3410.                 if(use_affine == TRUE ){ transform(2,2);}
  3411.                 if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */
  3412.                 int_data[0] = x2px(double_data[0]);
  3413.                 int_data[1] = y2px(double_data[1]);
  3414.                 if( use_slider != -1 && onclick == 0 ){ onclick = 3;}/* no drag&onclick but slideable */
  3415.                 if( use_slider != -1 && drag_type > 0 ){ onclick = 5;}/* slider+drag*/
  3416.                 if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  3417.                 string_length = 1 + snprintf(NULL,0,"var draw_xml%d = {id:%d,type:'svg',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt);
  3418.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3419.                 snprintf(tmp_buffer,string_length,  "var draw_xml%d = {id:%d,type:'svg',x:[%d],y:[%d],mathml:\"%s\",drag_type:%d,onclick:%d,object_cnt:%d,stroke_color:\"%s\",stroke_opacity:%.2f,fill_color:\"%s\",fill_opacity:%.2f,use_center:%d,use_snap:%d,angle:%f,fontfamily:\"%s\",transform:%s,use_affine:%d,offset:[0,0],use_slider:%s,rotation_center:%s,once:true};slidergroup[%d] = null;draw_xml(draw_xml%d);\n",drawxml_cnt,drawxml_cnt,int_data[0],int_data[1],temp,drag_type,onclick,object_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,int_data[2],use_snap,angle,font_family,doubledata2js_array(affine_matrix,6,decimals),use_affine,my_sliders,rotation_center,object_cnt,drawxml_cnt);
  3420.                 add_to_buffer(tmp_buffer);
  3421.                 if(onclick != 0 ){object_cnt++;}
  3422.                 drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */
  3423.                 break;
  3424.               default:break;
  3425.             }
  3426.           }
  3427.           reset();
  3428.           break;
  3429.         case OPACITY:
  3430.   /*
  3431.   @ opacity [0-255],[0-255]
  3432.   @ opacity [0.0 - 1.0],[0.0 - 1.0]
  3433.   @ alternative: transparent
  3434.   @ first item is stroke opacity, second is fill opacity
  3435.   @%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
  3436.   */
  3437.           for(i = 0 ; i<2;i++){
  3438.             switch(i){
  3439.               case 0: double_data[0]= get_real(infile,0);break;
  3440.               case 1: double_data[1]= get_real(infile,1);break;
  3441.               default: break;
  3442.             }
  3443.            }
  3444.           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 ? */
  3445.           if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = 0.0;} /* 0.0 - 1.0 */
  3446.           if( double_data[1] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = 0.0;} /* 0.0 - 1.0 */
  3447.           break;
  3448.         case ONCLICK:
  3449.   /*
  3450.    @ onclick
  3451.    @ keyword (no arguments required)
  3452.    @ if the next object is clicked, its ''object onclick_or_drag sequence number`` in fly script is returned by <code>javascript:read_canvas();</code>
  3453.    @ 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``
  3454.    @ line based objects will show an increase in line width<br>font based objects will show the text in ''bold`` when clicked.
  3455.    @ the click zone (accuracy) is determined by 2&times; the line width of the object
  3456.    @ 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...)
  3457.    @ note: not all objects may be set onclick
  3458.    @%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
  3459.   */
  3460.           fprintf(js_include_file,"use_dragdrop_reply = true;");
  3461.           onclick = 1;
  3462.           use_dragstuff=2;
  3463.           js_function[INTERACTIVE] = 1;
  3464.           break;
  3465.         case PARALLEL:
  3466.   /*
  3467.    @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
  3468.    @ affine transformations should be identical to flydraw
  3469.    @ in case of <a href='#rotate'>rotation</a>  or <a href='#affine'>affine transformation </a>, command parallel will produce <em>n</em> individual segments, and these may be set ''onclick`` or ''drag xy`` individually.
  3470.    @ in case of <em>no rotation or transformations</em> the lines can not be set ''onclick`` or ''drag xy``.
  3471.    @ note: a large number of parallel lines (large <em>n</em>) may result in a canvasdraw error (...simplify your script...it produces too many lines...)
  3472.    @%parallel_click%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red%rotate 45%onclick%parallel -5,5,-4,-5,0.25,0,40,blue
  3473.    @%parallel%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red
  3474.   */
  3475.           decimals = find_number_of_digits(precision);
  3476.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3477.           if( use_rotate == TRUE || use_affine == TRUE ){
  3478.             for( i = 0;i < 8; i++ ){
  3479.               switch(i){
  3480.                 case 0: double_data[0] = get_real(infile,0);break; /* x1-values */
  3481.                 case 1: double_data[1] = get_real(infile,0);break; /* y1-values */
  3482.                 case 2: double_data[2] = get_real(infile,0);break; /* x2-values */
  3483.                 case 3: double_data[3] = get_real(infile,0);break; /* y2-values */
  3484.                 case 4: double_data[4] = get_real(infile,0);break; /* xv  */
  3485.                 case 5: double_data[5] = get_real(infile,0);break; /* yv  */
  3486.                 case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
  3487.                 case 7: stroke_color=get_color(infile,1);break;/* name or hex color */
  3488.                 default: break;
  3489.               }
  3490.             }
  3491.             double_data[6] = double_data[0]; /* x1 */
  3492.             double_data[7] = double_data[1]; /* y1 */
  3493.             double_data[8] = double_data[2]; /* x2 */
  3494.             double_data[9] = double_data[3]; /* y2 */
  3495.             for(i = 0 ; i < int_data[0] ; i++){
  3496.               double_data[0] = double_data[6] + i*double_data[4];
  3497.               double_data[1] = double_data[7] + i*double_data[5];
  3498.               double_data[2] = double_data[8] + i*double_data[4];
  3499.               double_data[3] = double_data[9] + i*double_data[5];
  3500.               if(use_rotate == TRUE ){ rotate(4,angle,rotationcenter,2);}
  3501.               if(use_affine == TRUE ){ transform(4,2);}
  3502.               string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3503.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3504.               snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3505.               add_to_buffer(tmp_buffer);
  3506.               if(onclick != 0){object_cnt++;}
  3507.             }
  3508.             dragstuff[4] = 1;
  3509.           }
  3510.           else  /* use the old parallel version: calculations in javascript */
  3511.           {
  3512.             for( i = 0;i < 8; i++ ){
  3513.               switch(i){
  3514.                 case 0: double_data[0] = get_real(infile,0);break; /* x1-values */
  3515.                 case 1: double_data[1] = get_real(infile,0);break; /* y1-values */
  3516.                 case 2: double_data[2] = get_real(infile,0);break; /* x2-values */
  3517.                 case 3: double_data[3] = get_real(infile,0);break; /* y2-values */
  3518.                 case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv  */
  3519.                 case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv  */
  3520.                 case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
  3521.                 case 7: stroke_color=get_color(infile,1);/* name or hex color */
  3522.                   string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3523.                   check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3524.                   snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3525.                   add_to_buffer(tmp_buffer);
  3526.                   if(onclick != 0){object_cnt++;}
  3527.                   break;
  3528.                 default: break;
  3529.               }
  3530.               dragstuff[11] = 1;
  3531.             }
  3532.           }
  3533.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3534.           reset();
  3535.           break;
  3536.         case PLOTSTEPS:
  3537.       /*
  3538.        @ plotsteps a_number
  3539.        @ default 150
  3540.        @ only used for commands <a href="#curve">curve / plot</a> and <a href="#levelcurve">levelcurve</a>
  3541.        @ use with care !
  3542.       */
  3543.           plot_steps = (int) (get_real(infile,1));
  3544.           break;
  3545.         case POINT:
  3546.   /*
  3547.   @ point x,y,color
  3548.   @ draw a single point at (x;y) in color 'color'
  3549.   @ use command <code>linewidth int</code> to adjust size
  3550.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3551.   @ will not resize on zooming (command <code>circle x,y,r,color</code> will resize on zooming)
  3552.   @ attention: in case of command <a href="#rotate">rotate angle</a> a point has rotation center (0:0) in x/y-range
  3553.   @%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
  3554.   */
  3555.           for(i=0;i<3;i++){
  3556.             switch(i){
  3557.               case 0: double_data[0] = get_real(infile,0);break; /* x */
  3558.               case 1: double_data[1] = get_real(infile,0);break; /* y */
  3559.               case 2: stroke_color = get_color(infile,1);/* name or hex color */
  3560.                 if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  3561.                 if(use_affine == TRUE ){ transform(2,2);}
  3562.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3563.  
  3564.                 decimals = find_number_of_digits(precision);
  3565.                 string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3566.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3567.                 snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3568.                 add_to_buffer(tmp_buffer);
  3569.                 /* object_cnt++; */
  3570.                 if(onclick != 0){object_cnt++;}
  3571.                 break;
  3572.               default: break;
  3573.             }
  3574.           }
  3575.           dragstuff[2] = 1;
  3576.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3577.           reset();
  3578.           break;
  3579.         case POINTS:
  3580.   /*
  3581.   @ points color,x1,y1,x2,y2,...,x_n,y_n
  3582.   @ draw multiple points at given coordinates in color 'color'
  3583.   @ use command <code>linewidth int</code> to adjust size
  3584.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  3585.   @ attention: in case of command <a href="#rotate">rotate angle</a> the points have rotation center (0:0) in x/y-range
  3586.   @%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
  3587.   @%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
  3588.   */
  3589.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3590.           fill_color = stroke_color;
  3591.           i=0;
  3592.           while( ! done ){     /* get next item until EOL*/
  3593.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3594.             if(i%2 == 0 ){
  3595.               double_data[i] = get_real(infile,0); /* x */
  3596.             }
  3597.             else {
  3598.               double_data[i] = get_real(infile,1); /* y */
  3599.             }
  3600.             i++;
  3601.           }
  3602.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  3603.           if(use_affine == TRUE ){ transform(i-1,2);}
  3604.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3605.           decimals = find_number_of_digits(precision);
  3606.           for(c = 0 ; c < i-1 ; c = c+2){
  3607.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3608.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3609.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3610.             add_to_buffer(tmp_buffer);
  3611.             /* object_cnt++; */
  3612.             if(onclick != 0){object_cnt++;}
  3613.           }
  3614.           dragstuff[2] = 1;
  3615.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3616.           reset();
  3617.           break;
  3618.         case POLY:
  3619.   /*
  3620.   @ poly color,x1,y1,x2,y2...x_n,y_n
  3621.   @ polygon color,x1,y1,x2,y2...x_n,y_n
  3622.   @ draw closed polygon
  3623.   @ use command ''fpoly`` to fill it or use keyword <a href='#filled'>filled</a>
  3624.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3625.   @%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
  3626.   @%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
  3627.   */
  3628.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3629.           i=0;
  3630.           c=0;
  3631.           while( ! done ){     /* get next item until EOL*/
  3632.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3633.             for( c = 0 ; c < 2; c++){
  3634.               if(c == 0 ){
  3635.                 double_data[i] = get_real(infile,0);
  3636.                 i++;
  3637.               }
  3638.               else {
  3639.                 double_data[i] = get_real(infile,1);
  3640.                 i++;
  3641.               }
  3642.             }
  3643.           }
  3644.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  3645.           if(use_affine == TRUE ){ transform(i-1,2);}
  3646.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3647.  
  3648.       /* draw path:  closed & optional filled */
  3649.           decimals = find_number_of_digits(precision);
  3650.           string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3651.           check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3652.           snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3653.           add_to_buffer(tmp_buffer);
  3654.           if(onclick != 0){object_cnt++;}
  3655.           reset();
  3656.           dragstuff[5] = 1;
  3657.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3658.           break;
  3659.         case POLYLINE:
  3660.   /*
  3661.   @ polyline color,x1,y1,x2,y2...x_n,y_n
  3662.   @ brokenline color,x1,y1,x2,y2...x_n,y_n
  3663.   @ path color,x1,y1,x2,y2...x_n,y_n
  3664.   @ 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>
  3665.   @ 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
  3666.   @ 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)
  3667.   @ use command <a href='#segments'>segments</a> for a series of segments. These may be clicked/dragged individually
  3668.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3669.   @%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
  3670.   @%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
  3671.   */
  3672.  
  3673.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3674.           i=0;
  3675.           c=0;
  3676.           while( ! done ){     /* get next item until EOL*/
  3677.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3678.             for( c = 0 ; c < 2; c++){
  3679.               if(c == 0 ){
  3680.                 double_data[i] = get_real(infile,0);
  3681.                 i++;
  3682.               }
  3683.               else {
  3684.                 double_data[i] = get_real(infile,1);
  3685.                 i++;
  3686.               }
  3687.             }
  3688.           }
  3689.  
  3690.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  3691.           if(use_affine == TRUE ){ transform(i-1,2);}
  3692.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3693.  
  3694.       /* draw path: not closed & not filled */
  3695.           decimals = find_number_of_digits(precision);
  3696.           string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3697.           check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3698.           snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3699.           add_to_buffer(tmp_buffer);
  3700.           if(onclick != 0){object_cnt++;}
  3701.           /* object_cnt++;*/
  3702.           reset();
  3703.           dragstuff[4] = 1;
  3704.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3705.           break;
  3706.         case POPUP:
  3707.       /*
  3708.       @ popup
  3709.       @ keyword (no arguments)
  3710.       @ if fly-script starts with keyword ''popup``, the canvas image will be exclusively in a popup window (xsize px &times; ysize px)
  3711.       @ 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``
  3712.       @ the popup window will be embedded into the page as a normal image, when ''status=done``; override with keyword <a href="#status">nostatus</a>
  3713.       @ to access the read_canvas and read_dragdrop functions in a popup window, use:<br> <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>
  3714.       @ 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
  3715.       @%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 H(x)=%userinput function
  3716.       */
  3717.           use_tooltip = 2;
  3718.           break;
  3719.         case PROTRACTOR:
  3720.   /*
  3721.    @ protractor x,y,x_width,type,mode,use_a_scale
  3722.    @ x,y are the initial location
  3723.    @ x_width: give the width in x-coordinate system (e.g. not in pixels !)
  3724.    @ type = 1: a triangle range 0 - 180<br>type = 2: a circle shape 0 - 360
  3725.    @ 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
  3726.    @ 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>
  3727.    @ use_scale = 1: the protractor will have some scale values printed; use_scale=0 to disable
  3728.    @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor...
  3729.    @ commands ''stroke_color | fill_color | linewidth | opacity | font_family`` will determine the looks of the protractor.
  3730.    @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br>use command ''precision`` to set the reply precision.
  3731.    @ if combined with a ruler, use replyformat = 32
  3732.    @ command <code>snap_to_grid</code> may be used to assist the pupil at placing the protractor
  3733.    @ 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...
  3734.    @ only one protractor allowed (for the time being)
  3735.    @ usage: first left click on the protractor will activate dragging;<br>a second left click will activate rotating (just move mouse around)<br>a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br>a next click will restart this sequence...
  3736.    @%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%mouse red,22
  3737.   */
  3738.           for( i = 0;i < 6; i++ ){
  3739.             switch(i){
  3740.               case 0: double_data[0] = get_real(infile,0);break; /* x-center */
  3741.               case 1: double_data[1] = get_real(infile,0);break; /* y-center */
  3742.               case 2: double_data[2] = get_real(infile,0);break; /* x-width */
  3743.               case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */
  3744.               case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */
  3745.               case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */
  3746.                 decimals = find_number_of_digits(precision);
  3747.                 if( int_data[1] < 0 ){ js_function[JS_FIND_ANGLE] = 1;}
  3748.                 add_js_protractor(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);
  3749.                 string_length = 1 + snprintf(NULL,0,";protractor%d(); ",canvas_root_id);
  3750.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3751.                 snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id);
  3752.                 add_to_buffer(tmp_buffer);
  3753.                 reply_precision = precision;
  3754.         /* no reply from protractor if non-interactive */
  3755.                 if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;}
  3756.                 js_function[INTERACTIVE] = 1;
  3757.                 break;
  3758.               default: break;
  3759.             }
  3760.           }
  3761.           break;
  3762.         case PIXELS:
  3763.   /*
  3764.   @ pixels color,x1,y1,x2,y2,x3,y3...
  3765.   @ draw rectangular "points" with diameter 1 pixel
  3766.   @ pixels can <b>not</b> be dragged or clicked
  3767.   @ "pixelsize = 1" may be changed by command <code>pixelsize int</code>
  3768.   @%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...
  3769.   */
  3770.           js_function[DRAW_PIXELS] = 1;
  3771.           stroke_color=get_color(infile,0);
  3772.           i=0;
  3773.           c=0;
  3774.           while( ! done ){     /* get next item until EOL*/
  3775.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3776.             for( c = 0 ; c < 2; c++){
  3777.               if(c == 0 ){
  3778.                 double_data[i] = get_real(infile,0);
  3779.                 i++;
  3780.               }
  3781.               else {
  3782.                 double_data[i] = get_real(infile,1);
  3783.               }
  3784.             }
  3785.         }
  3786.         if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  3787.         if(use_affine == TRUE ){ transform(i-1,2);}
  3788.         decimals = find_number_of_digits(precision);
  3789.         /*  *double_xy2js_array(double xy[],int len,int decimals) */
  3790.         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);
  3791.         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3792.         snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  3793.         add_to_buffer(tmp_buffer);
  3794.         reset();
  3795.         break;
  3796.         case PIXELSIZE:
  3797.   /*
  3798.   @ pixelsize int
  3799.   @ in case you want to deviate from default pixelsize = 1(...)
  3800.   @ pixelsize 100 is of course a filled rectangle 100px &times; 100px
  3801.   */
  3802.           pixelsize = (int) get_real(infile,1);
  3803.           break;
  3804.  
  3805.         case PIECHART:
  3806.   /*
  3807.   @ piechart xc,yc,radius,'data+colorlist'
  3808.   @ (xc: yc) center of circle diagram in xrange/yrange
  3809.   @ radius in pixels
  3810.   @ 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
  3811.   @ example data+colorlist: 32:red:65:green:23:black:43:orange:43:yellow:14:white
  3812.   @ the number of colors must match the number of data.
  3813.   @ 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,...
  3814.   @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of colours
  3815.   @ 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.
  3816.   @ 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.
  3817.   @%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%
  3818.   @%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
  3819.   */
  3820.           js_function[DRAW_PIECHART] = 1;
  3821.           for(i=0;i<5;i++){
  3822.             switch(i){
  3823.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  3824.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  3825.               case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
  3826.               case 3: temp = get_string(infile,1);
  3827.                 if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
  3828.                 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);
  3829.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3830.                 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);
  3831.                 add_to_buffer(tmp_buffer);
  3832.                 break;
  3833.               default:break;
  3834.             }
  3835.           }
  3836.           reset();
  3837.           break;
  3838.         case RANGE:
  3839.   /*
  3840.   @ range xmin,xmax,ymin,ymax
  3841.   @ if not given: 0,xsize,0,ysize (eg in pixels)
  3842.   */
  3843.           for(i = 0 ; i<4; i++){
  3844.             switch(i){
  3845.               case 0: xmin = get_real(infile,0);break;
  3846.               case 1: xmax = get_real(infile,1);break;
  3847.               case 2: ymin = get_real(infile,0);break;
  3848.               case 3: ymax = get_real(infile,1);break;
  3849.               default: break;
  3850.             }
  3851.           }
  3852.           if(xmin >= xmax){canvas_error(" xrange is not OK: xmin &lt; xmax !");}
  3853.           if(ymin >= ymax){canvas_error(" yrange is not OK: ymin &lt; ymax !");}
  3854.           fprintf(js_include_file,"var xmin = %f;var xmax = %f;var ymin = %f;var ymax = %f;",xmin,xmax,ymin,ymax);
  3855.           found_size_command = found_size_command+2;
  3856.           break;
  3857.         case RAYS:
  3858.   /*
  3859.    @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
  3860.    @ draw rays in color 'color' and center (xc:yc)
  3861.    @ may be set draggable or onclick (every individual ray)
  3862.    @%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
  3863.    @%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
  3864.   */
  3865.           stroke_color=get_color(infile,0);
  3866.           fill_color = stroke_color;
  3867.           double_data[0] = get_real(infile,0);/* xc */
  3868.           double_data[1] = get_real(infile,0);/* yc */
  3869.           i=2;
  3870.           while( ! done ){     /* get next item until EOL*/
  3871.             if(i > MAX_INT - 1){canvas_error("in command rays too many points / rays in argument: repeat command multiple times to fit");}
  3872.             if(i%2 == 0 ){
  3873.               double_data[i] = get_real(infile,0); /* x */
  3874.             }
  3875.             else {
  3876.               double_data[i] = get_real(infile,1); /* y */
  3877.             }
  3878.             fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
  3879.             i++;
  3880.           }
  3881.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  3882.           if(use_affine == TRUE ){ transform(i-1,2);}
  3883.           if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
  3884.           decimals = find_number_of_digits(precision);
  3885.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3886.           for(c=2; c<i;c = c+2){
  3887.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3888.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3889.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3890.             add_to_buffer(tmp_buffer);
  3891.     /* object_cnt++; */
  3892.             if(onclick != 0){object_cnt++;}
  3893.           }
  3894.           reset();
  3895.           dragstuff[4] = 1;
  3896.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3897.           break;
  3898.         case RECT:
  3899.   /*
  3900.   @ rect x1,y1,x2,y2,color
  3901.   @ use command <code>frect x1,y1,x2,y2,color</code> for a filled rectangle
  3902.   @ use command/keyword <a href='#filled'>filled</a> before command <code>rect x1,y1,x2,y2,color</code>
  3903.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3904.   @ note: internally a rect is defined with 4 points. So when performing some affine transformation, other than translation, it will result in some morphing of the rectangle !<br/>this is a deviation of flydraw's rect&amp;affine
  3905.   @%rect%size 400,400%xrange -10,10%yrange -10,10%rect 0,0,4,-4,green%rect 0,5,4,1,red
  3906.   */
  3907.           for(i=0;i<5;i++){
  3908.             switch(i){
  3909.               case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  3910.               case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  3911.               case 2:double_data[4] = get_real(infile,0);break; /* x-values */
  3912.               case 3:double_data[5] = get_real(infile,0);break; /* y-values */
  3913.               case 4:stroke_color = get_color(infile,1);/* name or hex color */
  3914.                 decimals = find_number_of_digits(precision);
  3915.                 double_data[2] = double_data[4];
  3916.                 double_data[3] = double_data[1];
  3917.                 double_data[6] = double_data[0];
  3918.                 double_data[7] = double_data[5];
  3919.           /* using closed PATH (type=5) instead of ctx.rect (type=1)!!!
  3920.               0,1   2,3
  3921.           6,7      4,5
  3922.           x = [0,2,4,6]
  3923.           y = [1,3,5,7]
  3924.           */
  3925.                 if(use_rotate == TRUE ){rotate(8,angle,rotationcenter,2);}
  3926.                 if(use_affine == TRUE ){ transform(8,2);}
  3927.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3928.                 string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[6],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],decimals,double_data[7],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,my_sliders,rotation_center,use_offset);
  3929.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3930.                 snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[6],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],decimals,double_data[7],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,my_sliders,rotation_center,use_offset);
  3931.                 add_to_buffer(tmp_buffer);
  3932.                 if(onclick != 0){object_cnt++;}
  3933.       /* object_cnt++; */
  3934.                 reset();
  3935.                 break;
  3936.               }
  3937.             }
  3938.           dragstuff[5] = 1;
  3939.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3940.           break;
  3941.         case RECTS:
  3942.   /*
  3943.   @ rects color,x1,y1,x2,y2,.....
  3944.   @ use command <code>frect color,x1,y1,x2,y2,.....</code> for a filled rectangle
  3945.   @ use command/keyword <a href='#filled'>filled</a> before command <code>rects color,x1,y1,x2,y2,....</code>
  3946.   @ use command <code>fillcolor color</code> before ''frects`` to set the fill colour.
  3947.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  3948.   @%rects%size 400,400%xrange -10,10%yrange -10,10%rects red,0,0,4,-4,0,5,4,1
  3949.   */
  3950.       /* using closed PATH (type=5) in stead of ctx.rect (type=1)!!!
  3951.       0,1   2,3 .....8,9  10,11.....
  3952.   6,7      4,5 .....14,15  12,13.....
  3953.   x = [0,2,4,6,8,10,12,14...]
  3954.   y = [1,3,5,7,9,11,13,15...]
  3955.       */
  3956.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3957.           fill_color = stroke_color;
  3958.           i=0;
  3959.           while( ! done ){     /* get next item until EOL*/
  3960.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3961.             if(i%2 == 0 ){
  3962.               double_data[i] = get_real(infile,0); /* x */
  3963.             }
  3964.             else {
  3965.               double_data[i] = get_real(infile,1); /* y */
  3966.             }
  3967.             i++;
  3968.           }
  3969.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  3970.           if(use_affine == TRUE ){ transform(i-1,2);}
  3971.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3972.  
  3973.           decimals = find_number_of_digits(precision);
  3974.           for(c = 0 ; c < i-1 ; c = c+4){
  3975.             string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3976.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3977.             snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  3978.             add_to_buffer(tmp_buffer);
  3979.             if(onclick != 0){object_cnt++;}
  3980.     /* object_cnt++; */
  3981.           }
  3982.           dragstuff[5] = 1;
  3983.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3984.           if(use_rotate == TRUE ){
  3985.             rotate(i-1,angle,rotationcenter,2);
  3986.           }
  3987.           reset();
  3988.           break;
  3989.         case REPLYFORMAT:
  3990.   /*
  3991.   @ replyformat number
  3992.   @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop()
  3993.   @ default values should be fine !
  3994.   @ 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
  3995.   @ the last value for ''precision int`` will be used to calculate the reply coordinates, if needed (read_canvas();)
  3996.   @ 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 <code>H1: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>
  3997.   @ special replyformat = 100 ; will access to the raw javascript object data...use: read_dragdrop([property,property,...])<br>for example  properies like 'clicked','text', 'angle' , 'x'
  3998.   */
  3999.           reply_format = (int) get_real(infile,1);
  4000.           reply_precision = precision;
  4001.           break;
  4002.         case ROUNDRECT:
  4003.   /*
  4004.   @ roundrect x1,y1,x2,y2,radius in px,color
  4005.   @ use command <code>froundrect x1,y1,x2,y2,radius,color</code> for a filled rectangle
  4006.   @ use command/keyword <a href='#filled'>filled</a> before command <code>roundrect x1,y1,x2,y2,radius,color</code>
  4007.   @ fillcolor will be identical to ''color``
  4008.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4009.   @%roundrect%size 400,400%xrange -10,10%yrange -10,10%roundrect 0,0,4,-4,20,green%roundrect 0,5,4,1,10,red
  4010.   */
  4011.           for(i=0;i<6;i++){
  4012.             switch(i){
  4013.               case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  4014.               case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  4015.               case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  4016.               case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  4017.               case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
  4018.               case 5:stroke_color = get_color(infile,1);/* name or hex color */
  4019.                 if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);}
  4020.                 if(use_affine == TRUE ){ transform(2,4);}
  4021.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4022.       /* ensure no inverted roundrect is produced... */
  4023.                 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];}
  4024.                 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];}
  4025.                 decimals = find_number_of_digits(precision);
  4026.                 string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4027.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4028.                 snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4029.                 add_to_buffer(tmp_buffer);
  4030.                 if(onclick != 0){object_cnt++;}
  4031.       /* object_cnt++;*/
  4032.                 reset();
  4033.                 break;
  4034.             }
  4035.           }
  4036.           dragstuff[6] = 1;
  4037.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4038.           break;
  4039.         case ROUNDRECTS:
  4040.   /*
  4041.   @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,....
  4042.   @ for filled roundrects use command/keyword <a href='#filled'>filled</a> before command
  4043.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  4044.   @%roundrects%size 400,400%xrange -10,10%yrange -10,10%roundrects blue,5,0,0,4,-4,5,4,1,2
  4045.   */
  4046.  
  4047.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  4048.           int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */
  4049.           fill_color = stroke_color;
  4050.           i=0;
  4051.           while( ! done ){     /* get next item until EOL*/
  4052.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4053.             if(i%2 == 0 ){
  4054.               double_data[i] = get_real(infile,0); /* x */
  4055.             }
  4056.             else {
  4057.               double_data[i] = get_real(infile,1); /* y */
  4058.             }
  4059.             i++;
  4060.           }
  4061.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  4062.           if(use_affine == TRUE ){ transform(i-1,2);}
  4063.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4064.           decimals = find_number_of_digits(precision);
  4065.           for(c = 0 ; c < i-1 ; c = c+4){
  4066.     /* ensure no inverted roundrect is produced... */
  4067.             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];}
  4068.             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];}
  4069.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4070.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4071.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4072.             add_to_buffer(tmp_buffer);
  4073.             if(onclick != 0){object_cnt++;}
  4074.     /* object_cnt++; */
  4075.           }
  4076.           dragstuff[6] = 1;
  4077.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4078.           reset();
  4079.           break;
  4080.         case RULER:
  4081.   /*
  4082.   @ ruler x,y,x-width,y-height,mode
  4083.   @ x,y are the initial location
  4084.   @ x-width, y-height are the ruler dimensions width &amp; height in xy-coordinate system
  4085.   @ 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
  4086.   @ 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
  4087.   @ if combined with a protractor, use replyformat = 32
  4088.   @ only one ruler allowed (for the time being)
  4089.   @ 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...
  4090.   @ 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...
  4091.   @%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
  4092.   @%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
  4093.   @%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
  4094.   */
  4095.           for( i = 0;i < 5; i++ ){
  4096.             switch(i){
  4097.               case 0: double_data[0] = get_real(infile,0);break; /* x-center */
  4098.               case 1: double_data[1] = get_real(infile,0);break; /* y-center */
  4099.               case 2: double_data[2] = get_real(infile,0);break; /* x-width */
  4100.               case 3: double_data[3] = get_real(infile,0);break; /* y-width */
  4101.               case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */
  4102.                 decimals = find_number_of_digits(precision);
  4103.                 if( int_data[0] < 0 ){
  4104.                   js_function[JS_FIND_ANGLE] = 1;
  4105.                 }
  4106.                 add_js_ruler(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);
  4107.                 string_length = 1 + snprintf(NULL,0,";ruler%d(); ",canvas_root_id);
  4108.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4109.                 snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id);
  4110.                 add_to_buffer(tmp_buffer);
  4111.                 reply_precision = precision;
  4112.                 /* no reply from ruler if non-interactive */
  4113.                 if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;}
  4114.                 break;
  4115.               default: break;
  4116.             }
  4117.           }
  4118.           break;
  4119.         case RESET:
  4120.   /*
  4121.   @ reset
  4122.   @ keyword
  4123.   @ disables the effects of the <a href="noreset">noreset</a> command
  4124.   @ so the next objects will not be <a href="#filled">filled</a> and <a href="#dashed">dashed</a>
  4125.   */
  4126.           no_reset = FALSE; reset();
  4127.           break;
  4128.         case RESETOFFSET:
  4129.   /*
  4130.    @ resetoffset
  4131.    @ keyword ; use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text
  4132.    @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy
  4133.   */
  4134.           use_offset = 0;
  4135.           break;
  4136.         case ROTATE:
  4137.   /*
  4138.    @ rotate rotation_angle
  4139.    @ angle in degrees
  4140.    @ (only) the next object will be rotated is given angle
  4141.    @ positive values rotate counter clockwise
  4142.    @ 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)
  4143.    @ 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>
  4144.    @ attention: rotate will mess up the interactivity of the rotated object <br>e.g. if combined with command <a href="#drag">drag xy</a> or keyword <a href="#onclick">onclick</a>: the mouse recognises the original -unrotated- coordinates of the object
  4145.    @%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%
  4146.   */
  4147.           use_rotate = TRUE;
  4148.           angle = -1*(get_real(infile,1));/* -1: to be compatible with Flydraw... */
  4149.           break;
  4150.         case ROTATION_CENTER:
  4151.   /*
  4152.   @ rotationcenter x_center,y_center
  4153.   @ define an rotation center in your x/y-coordinate system
  4154.   @ wims will not check the validity of your input; use javascript console to debug any erors
  4155.   @ if not defined a rotation will be around the first point of an object
  4156.   @ to be used before command <a href="#rotate">rotate</a>
  4157.   @ use <a href="#killrotate">killrotate</a> to reset to 'null' <br/>(eg. the rotationcenter of the next object(s) will be the first (x;y) coordinate of the object(s))
  4158.   @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given
  4159.   @%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
  4160.   @%rotationcenter_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fillcolor black%strokecolor yellow%rotationcenter 0,0%fontsize 28%slider 0,2*pi,400,30,angle degrees active, rotate...%plot red,5*sin(x)%filled%linewidth 1%opacity 150,50%fillcolor orange%angle 0,0,pi,0,0,blue
  4161.   */
  4162.           for( i = 0;i < 2; i++ ){
  4163.             switch(i){
  4164.               case 0: rotationcenter[0] = get_real(infile,0);break; /* x-center */
  4165.               case 1: rotationcenter[1] = get_real(infile,1);break; /* y-center */
  4166.             }
  4167.             string_length = 1 + snprintf(NULL,0,"[%f,%f ]",rotationcenter[0],rotationcenter[1]);
  4168.             check_string_length(string_length);
  4169.             rotation_center = my_newmem(string_length);
  4170.             snprintf(rotation_center,string_length,"[%f,%f]",rotationcenter[0],rotationcenter[1]);
  4171.           }
  4172.           break;
  4173.         case SIZE:
  4174.       /*
  4175.       @ size width,height
  4176.       @ set canvas size in pixels
  4177.       @ mandatory first command (can only be preceded by keyword <a href="#popup">popup</a>)
  4178.       @ 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
  4179.       */
  4180.           found_size_command = 1;
  4181.           /* using fabs: however "xsize == int": so "xsize = abs( (int) get_real(infile,0))" would be the idea... */
  4182.           xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
  4183.           ysize = (int)(fabs(round(get_real(infile,1))));
  4184.           /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
  4185.           xmin = 0;xmax = xsize;
  4186.           ymin = 0;ymax = ysize;
  4187.  
  4188. /*
  4189.  The sequence in which stuff is finally printed is important !!
  4190. */
  4191.           fprintf(stdout,"\n\
  4192.          <script>\n\
  4193.          /*<![CDATA[*/\n\
  4194.          if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\
  4195.          if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\
  4196.          if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\
  4197.          canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\
  4198.          ",canvas_root_id);
  4199.  
  4200.           /* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */
  4201.           if( use_tooltip != 2){
  4202.             fprintf(stdout,"<!-- canvasdraw div -->\n\
  4203.            <div tabindex=\"0\" id=\"canvas_div%d\" style=\"max-width:%dpx;width:%dpx;height:%dpx\" class=\"canvas_wrapper\" oncontextmenu=\"return false;\">\
  4204.             <canvas class=\"canvas_placeholder\" width=\"%d\" height=\"%d\"></canvas>\
  4205.            </div>\n\
  4206.            <!-- tooltip and input placeholder -->\n\
  4207.            <div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\">\
  4208.             <span id=\"tooltip_placeholder%d\" class=\"tooltip_placeholder\"></span></div>\
  4209.            <!-- include actual object code via include file -->\n\
  4210.            <script id=\"canvas_script%d\" src=\"%s\" defer></script>\n",canvas_root_id,xsize,xsize,ysize,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd);
  4211.           } else {
  4212. /*
  4213. set canvas_div invisible and do not include placeholder in main html page:
  4214. the js-include will also be in a popup window...to be shown when wims &#36;status = done
  4215. */
  4216.             fprintf(stdout,"<!-- canvasdraw div invisible -->\n\
  4217.            <div tabindex=\"0\" id=\"canvas_div%d\" class=\"canvas_wrapper\" style=\"display:none;max-width:%dpx;width:%dpx;height:%dpx;\">\
  4218.             <canvas class=\"canvas_placeholder\" width=\"%d\" height=\"%d\"></canvas>\
  4219.            </div>\n\
  4220.            <div id=\"tooltip_placeholder_div%d\" style=\"display:none;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\">\
  4221.             <span id=\"tooltip_placeholder%d\" class=\"tooltip_placeholder\"></span></div>\
  4222.            <!-- include actual object code via include file -->\n\
  4223.            <script id=\"canvas_script%d\" src=\"%s\"></script>\n",canvas_root_id,xsize,xsize,ysize,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd);
  4224.           }
  4225.  
  4226. /* these must be global...it is all really very poor javascript:( */
  4227. fprintf(js_include_file,"\n/* begin generated javascript include for canvasdraw version %s */\n\
  4228. \"use strict\";\n\
  4229. /* these variables and functions must be global */\
  4230. var read_dragdrop%d;\
  4231. var read_canvas_images;\
  4232. var read_canvas%d;\
  4233. var set_clock;\
  4234. var clear_draw_area%d;\
  4235. var update_draw_area%d;\
  4236. var place_image_on_canvas;\
  4237. var draw_boxplot;\
  4238. var redraw_all%d;\
  4239. var userdraw_primitive;\
  4240. var wims_canvas_function%d = function(){\n/* common used stuff */\
  4241. var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\
  4242. var xsize = %d;\
  4243. var ysize = %d;\
  4244. var precision = 100;\
  4245. var canvas_div = document.getElementById(\"canvas_div%d\");\
  4246. 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;};\
  4247. 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;};\
  4248. 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);};};\
  4249. 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);};};\
  4250. 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);};};\
  4251. 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);};};\
  4252. function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
  4253. function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
  4254. function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\
  4255. 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) ));};\
  4256. 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;};\
  4257. var snap_x = 1;var snap_y = 1;\
  4258. function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
  4259. function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\
  4260. 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;case 5: return snap_to_fun(x,y);break;default: return [x,y];break;};};\
  4261. var xlogbase = 10;\
  4262. var ylogbase = 10;\
  4263. var use_xlogscale = 0;\
  4264. var use_ylogscale = 0;\
  4265. var x_strings = {};var x_strings_up = [];\
  4266. var y_strings = null;\
  4267. var use_jsmath = 0;\
  4268. var xstart = 0;\
  4269. var ystart = 0;\
  4270. var unit_x=\" \";\
  4271. var unit_y=\" \";\
  4272. var dragdrop_reply = [];\
  4273. var external_canvas = create_canvas%d(%d,xsize,ysize);",VERSION,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);
  4274. /* var xstart,ystart are normally 0 : in case of sgraph they have the 'jump' in the graph */
  4275.           break;
  4276.         case SEGMENT:
  4277.   /*
  4278.   @ segment x1,y1,x2,y2,color
  4279.   @ alternative: seg
  4280.   @ draw a line segment between points (x1:y1)--(x2:y2) in color ''color``
  4281.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4282.   @%segment_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segment 1,1,-9,3,green
  4283.   @%segment_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segment 1,1,-9,3,green
  4284.   */
  4285.           for(i=0;i<5;i++) {
  4286.             switch(i){
  4287.               case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
  4288.               case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
  4289.               case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
  4290.               case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
  4291.               case 4: stroke_color=get_color(infile,1);/* name or hex color */
  4292.                 if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);}
  4293.                 if(use_affine == TRUE ){ transform(4,2);}
  4294.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4295.                 decimals = find_number_of_digits(precision);
  4296.                 string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4297.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4298.                 snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4299.                 add_to_buffer(tmp_buffer);
  4300.                 if(onclick != 0){object_cnt++;}
  4301.                 /* object_cnt++; */
  4302.                 reset();
  4303.                 break;
  4304.               default: break;
  4305.             }
  4306.           }
  4307.           dragstuff[4] = 1;
  4308.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4309.           break;
  4310.         case SEGMENTS:
  4311.   /*
  4312.   @ segments color,x1,y1,x2,y2,...,x_n,y_n
  4313.   @ alternative: segs
  4314.   @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color ''color``
  4315.   @ use command ''linewidth int`` to adjust size
  4316.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  4317.   @%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
  4318.   @%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
  4319.   */
  4320.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  4321.           fill_color = stroke_color;
  4322.           i=0;
  4323.           while( ! done ){     /* get next item until EOL*/
  4324.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4325.             if(i%2 == 0 ){
  4326.               double_data[i] = get_real(infile,0); /* x */
  4327.             }
  4328.             else {
  4329.               double_data[i] = get_real(infile,1); /* y */
  4330.             }
  4331.             i++;
  4332.           }
  4333.           if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  4334.           if(use_affine == TRUE ){ transform(i-1,2);}
  4335.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4336.           decimals = find_number_of_digits(precision);
  4337.           for(c = 0 ; c < i-1 ; c = c+4){
  4338.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4339.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4340.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4341.             add_to_buffer(tmp_buffer);
  4342.             if(onclick != 0){object_cnt++;}
  4343.     /* object_cnt++;*/
  4344.           }
  4345.           reset();
  4346.           dragstuff[4] = 1;
  4347.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4348.           break;
  4349.         case SETLIMITS:
  4350.   /*
  4351.       @ setlimits
  4352.       @ keyword: if set, it will produce 4 inputfields for ''xmin,xmax,ymin,ymax`` and an ''ok`` button
  4353.       @ may be used for inputfield based zooming / panning
  4354.       @ may be styled using command <a href="#css">css</a>
  4355.       @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to ''xlabel`` etc
  4356.       @ note: the input value will not be checked on validity
  4357.       @%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
  4358.   */
  4359.           js_function[JS_SAFE_EVAL] = 1;
  4360.           js_function[JSPLOT_AND_ZOOM] = 1;
  4361.           add_setlimits(font_size,css_class);
  4362.           done = TRUE;
  4363.           break;
  4364.         case SETPIXEL:
  4365.   /*
  4366.   @ setpixel x,y,color
  4367.   @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange
  4368.   @ pixels can <b>not</b> be dragged or clicked
  4369.   @ "pixelsize = 1" may be changed by command <code>pixelsize int</code>
  4370.   @%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%
  4371.   */
  4372.           js_function[DRAW_PIXELS] = 1;
  4373.           for(i=0;i<3;i++){
  4374.             switch(i){
  4375.               case 0: double_data[0] = get_real(infile,0); break; /* x */
  4376.               case 1: double_data[1] = get_real(infile,0); break; /* y */
  4377.               case 2: stroke_color = get_color(infile,1);
  4378.                 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);
  4379.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4380.                 snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  4381.                 add_to_buffer(tmp_buffer);
  4382.                 break;
  4383.               default:break;
  4384.             }
  4385.           }
  4386.           reset();
  4387.           break;
  4388.         case SLIDER:
  4389.   /*
  4390.   @ slider start_value,end_value,width px,height px,type,label
  4391.   @ type may be: ''x,y,angle``
  4392.   @ if a slider value display is desired, use for argument ''type``: ''x display``, ''y display``, ''angle radian``, ''angle degree``
  4393.   @ is the slider is used for animation, add keyword ''anim`` or ''animate`` to ''type``; for now only one animated slider may be used...
  4394.   @ default behaviour is: click on an object to use its slider(s)<br/>to use sliders without clicking on an object, use for ''type`` keyword ''active``<br>eg: <code>slider -2*pi,2*pi,300,30,angle degree active,Rotate</code>
  4395.   @ if a unit (or something like that...) for x/y-value display is needed, use commands ''xunit`` and / or ''yunit``
  4396.   @ if the translation should be performed using a function, use for type: ''x function``, ''y function``<br>use commands ''sliderfunction_x`` and/or ''sliderfunction_y`` before the slider command to define the functions. Example:<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>
  4397.   @ use command ''slider`` before draggable/clickable objects.
  4398.   @ 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><br>note: except a combination 'drag' and 'slider' for command 'latex, katex, mathml, html, obabel'
  4399.   @ no slider for a math function, these can be traced using command ''trace_jscurve some_function_in_x``
  4400.   @ 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``
  4401.   @ amount of sliders is not limited.
  4402.   @ a slider can not be set ''snaptogrid`` or other ''snapto*`` : you may always use 'drag xy' in combination with the slider objects
  4403.   @ <code>javascript:read_dragdrop();</code> will return an array with ''object_number:slider_value``
  4404.   @ every draggable object may have its own slider (no limit in amount of sliders)
  4405.   @ label: some slider text. <br>Note: on <a target='new' href='https://katex.org'>KaTeX</a> enabled wims, TeX produced by wims command ''mathmlmath``, is allowed.
  4406.   @ use fillcolor for slider controlkey
  4407.   @ use strokecolor for slider bar
  4408.   @ use fontfamily / fontcolor to set used fonts
  4409.   @ use opacity (only fill opacity will be used) to set transparency
  4410.   @ the slider canvas will be added to the ''tooltip div``: so incompatible with command tooltip ; setlimits etc
  4411.   @%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 active degrees,Rotate arrow%arrow 0,0,4.5,0,8,red%killslider%opacity 200,100%slider -2,2,300,30,x active,move blue rectangle%frect -4,4,1,-1,blue%killslider%linewidth 2%slider -2,2,300,30,y,move green rectangle%frect -4,4,1,-1,green
  4412.   @%slider_click%%size 300,300%xrange -6,6%yrange -6,6%grid 1,1,grey%linewidth 2%slider 0,2*pi,300,28,angle degree, name%fillcolor lightgreen%#CLICK ON THE OBJECTS TO ACTIVATE%opacity 255,30%ftriangle 2,2,-2,2,0,0,red%ftriangle -2,2,-2,-2,0,0,blue%ftriangle -2,-2,2,-2,0,0,green%ftriangle 2,-2,2,2,0,0,orange%rotationcenter 0,0%frect -2,2,2,-2,black
  4413.   @%slider_active%%size 300,300%xrange -6,6%yrange -6,6%grid 1,1,grey%linewidth 1%slider 0,2*pi,300,28,angle degree active, name%fillcolor lightgreen%opacity 255,30%ftriangle 2,2,-2,2,0,0,red%ftriangle -2,2,-2,-2,0,0,blue%ftriangle -2,-2,2,-2,0,0,green%ftriangle 2,-2,2,2,0,0,orange%rotationcenter 0,0%frect -2,2,2,-2,black
  4414.   @%slider_animate%%size 300,300%xrange -6,6%yrange -6,6%grid 1,1,grey%linewidth 1%slider 0,2*pi,300,28,angle anim active, name%fillcolor lightgreen%opacity 255,30%ftriangle 2,2,-2,2,0,0,red%ftriangle -2,2,-2,-2,0,0,blue%ftriangle -2,-2,2,-2,0,0,green%ftriangle 2,-2,2,2,0,0,orange%rotationcenter 0,0%frect -2,2,2,-2,black
  4415.   @%slider_html_image%%size 400,400%xrange -6,6%yrange -6,6%bgcolor white%grid 1,1,grey%linewidth 1%slider 0,2*pi,300,28,angle active degree,%centered%html 0,0,<img src="gifs/domains/sciences/flasks.svg" width="100px" height="100px">
  4416.   */
  4417.           js_function[INTERACTIVE] = 1;
  4418.           int_data[2] = 0; /* --> show_display = 0; */
  4419.           for(i=0; i<6 ; i++){
  4420.             switch(i){
  4421.               case 0: double_data[0] = get_real(infile,0);break; /* start value */
  4422.               case 1: double_data[1] = get_real(infile,0);break; /* end value */
  4423.               case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
  4424.               case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
  4425.               case 4: temp = get_string_argument(infile,0); /* type: x,y,angle */
  4426.                 if( strstr(temp,"displ")!=0 ||  strstr(temp,"deg")!=0 || strstr(temp,"rad")!=0 ){int_data[5] = 1; }else{int_data[5] = 0;}
  4427.                 if(strstr(temp,"anim")!= 0){int_data[3] = 1;}else{int_data[3] = 0;}
  4428.                 if(strstr(temp,"active")!= 0){onclick = 4;}else{onclick=0;}
  4429.                 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;}}
  4430.                 else
  4431.                   if(strstr(temp,"xy") != 0){slider_type = "XY";if( strstr(temp,"disp")!= 0){int_data[2] = 5;}}
  4432.                     else
  4433.                       if(strstr(temp,"x") != 0){slider_type = "X";if( strstr(temp,"disp")!= 0){int_data[2] = 1;}}
  4434.                       else
  4435.                         if(strstr(temp,"y") != 0){slider_type = "Y";if( strstr(temp,"disp")!= 0){int_data[2] = 2;}}
  4436.                           else
  4437.                             canvas_error("slider can be of type: x,y,angle,fun_x:fun_y");
  4438.                   break;
  4439.                 case 5: temp = get_string_argument(infile,1); if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\""," ");}
  4440.         /* slider label : in case of latex/mathmlmath we need to remove the extra " */
  4441.               break;
  4442.             }
  4443.           }
  4444.           if(use_slider == -1 ){ /* add once */
  4445.             add_slider(int_data[3]);
  4446.             if(int_data[5] == 1 ){add_slider_display(precision,font_size,font_color,stroke_opacity);}
  4447.           }
  4448.           use_slider++;
  4449.           if(int_data[3] == 0){\
  4450.             string_length = 1 + snprintf(NULL,0,"slider%d = new slider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,'%s',%d);\n",use_slider,slider_type,temp,use_slider,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]);
  4451.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4452.             snprintf(tmp_buffer,string_length  ,"slider%d = new slider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,'%s',%d);\n",use_slider,slider_type,temp,use_slider,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]);
  4453.           }else{
  4454.             string_length = 1 + snprintf(NULL,0,"slider%d = new animslider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,'%s',%d);\n",use_slider,slider_type,temp,use_slider,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]);
  4455.             add_slider(int_data[3]);/* use only once !! */
  4456.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4457.             snprintf(tmp_buffer,string_length  ,"slider%d = new animslider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,'%s',%d);\n",use_slider,slider_type,temp,use_slider,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]);
  4458.           }
  4459.           add_to_buffer(tmp_buffer);
  4460.           fprintf(js_include_file,"var slider%d;",use_slider);
  4461.           use_dragstuff = 2;
  4462. //      dragstuff[22] = 1; /* dragstuff switch no 22 is a slider...*/
  4463.           if(onclick != 4 ){ js_function[INTERACTIVE] = 1; }/* no need to click on object to use slider... */
  4464.       //js_function[JS_ROTATE_MOUSE] = 1;
  4465.           c = 0;
  4466.           for(i=last_slider;i<=use_slider;i++){
  4467.             int_data[c] = i; c++;
  4468.           }
  4469.           my_sliders = data2js_array(int_data,use_slider - last_slider+1);
  4470.           break;
  4471.         case SGRAPH:
  4472.   /*
  4473.    @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
  4474.    @ primitive implementation of a ''broken scale`` graph...
  4475.    @ 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>
  4476.    @%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
  4477.   */
  4478.             js_function[DRAW_SGRAPH] = 1;
  4479.             for(i = 0 ; i < 8 ;i++){
  4480.               switch(i){
  4481.                 case 0:double_data[0] = get_real(infile,0);break;
  4482.                 case 1:double_data[1] = get_real(infile,0);break;
  4483.                 case 2:double_data[2] = get_real(infile,0);break;
  4484.                 case 3:double_data[3] = get_real(infile,0);break;
  4485.                 case 4:int_data[0] = (int)(get_real(infile,0));break;
  4486.                 case 5:int_data[1] = (int)(get_real(infile,0));break;
  4487.                 case 6:stroke_color = get_color(infile,0);break;
  4488.                 case 7:font_color = get_color(infile,1);
  4489.                 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);
  4490.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4491.                 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);
  4492.                 add_to_buffer(tmp_buffer);
  4493.                 break;
  4494.                 default:break;
  4495.               }
  4496.             }
  4497.       /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
  4498.           break;
  4499.         case SNAPTOFUNCTION:
  4500.   /*
  4501.   @ snaptofunction some_function_in_x,some_funtion_in_y
  4502.   @ alternative: snaptofun
  4503.   @ the next object will snap to the calculated values
  4504.   @ note: snaptofun is probably not really useful feature...
  4505.   @ if you want only modification of y-values,just use: <code>snaptofunction x,5*sin(1/y)</code>
  4506.   @ if you want only modification of x-values,just use: <code>snaptofunction 5*sin(1/x),y</code>
  4507.   @ for now only one instance of ''snaptofunction`` is allowed
  4508.   @ use rawmath on your functions: no validity checking is done by wims !
  4509.   @ note: switching x and y coordinates? <code>snaptofunction y,x</code>
  4510.   @%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
  4511.   @%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
  4512.   */
  4513.           temp = get_string_argument(infile,0);
  4514.           use_snap = 2;
  4515.           use_snap = 5;
  4516.           js_function[JS_MATH] = 1;
  4517.           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));
  4518.           break;
  4519.         case SNAPTOPOINTS:
  4520.   /*
  4521.   @ snaptopoints x1,y1,x2,y2,x3,y3....
  4522.   @ a userdraw object will snap to these points.
  4523.   @ the array size (e.g. the number of points) of command ''snaptopoints`` is limited by constant MAX_INT (canvasdraw.h)<br/>this command may be repeated multiple times (no limit) to add points
  4524.   @ a draggable object (use command ''drag x|y|xy``) will snap to the closed of these points when dragged (mouseup)
  4525.   @ other options: use keyword ''snaptogrid``, ''xsnaptogrid`` or ''ysnaptogrid``
  4526.   @%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
  4527.   @%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 3%%points blue,-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%drag xy%ftriangle -4,0,-2,3,0,0,red
  4528.   */
  4529.           i = 0;
  4530.           while( ! done ){     /* get next item until EOL*/
  4531.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4532.             if(i%2 == 0 ){
  4533.               double_data[i] = get_real(infile,0); /* x */
  4534.             }
  4535.             else {
  4536.               double_data[i] = get_real(infile,1); /* y */
  4537.             }
  4538.             i++;
  4539.           }
  4540.           decimals = find_number_of_digits(precision);
  4541.       /* NEED AN EXTRA COUNTER VARIABLE FOR MORE THAN 2 CALLS */
  4542.           fprintf(js_include_file,"if( temp_push_array === 'undefined' ){var temp_push_array;};if( points_to_snap_on === 'undefined' ){var points_to_snap_on;};var temp_push_array = [%s];\n",double_xy2js_array(double_data,i,decimals));
  4543.           if( snap_to_points_cnt == 0 ){
  4544.             fprintf(js_include_file,"points_to_snap_on = temp_push_array;function find_min_diff(x,y,X,Y){var diff = 100000000;var chk;var idx = 0;var p = 0;while(X[p] != null){chk = distance(x,y,X[p],Y[p]);if( chk  < diff ){ diff = chk; idx = p;};p++;};return idx;};function snap_to_points(x,y){x = px2x(x); y = px2y(y);var xpoints = points_to_snap_on[0];var ypoints = points_to_snap_on[1];var idx = find_min_diff(x,y,xpoints,ypoints);x = xpoints[idx];y = ypoints[idx];return [x2px(x),y2px(y)];};");
  4545.           }else{
  4546.             fprintf(js_include_file,"points_to_snap_on[0].push.apply(points_to_snap_on[0],temp_push_array[0]);points_to_snap_on[1].push.apply(points_to_snap_on[1],temp_push_array[1]);");
  4547.           }
  4548.           snap_to_points_cnt = 1; /* do not repeat including the js-functions...just once*/
  4549.           use_snap = 4;
  4550.           break;
  4551.         case SNAPTOGRID:
  4552.   /*
  4553.    @ snaptogrid
  4554.    @ keyword (no arguments required)
  4555.    @ a draggable object (use command ''drag x|y|xy``) will snap to the given grid when dragged (mouseup)
  4556.    @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
  4557.    @ if no grid is defined, points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1)
  4558.    @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
  4559.    @ 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 ...
  4560.    @%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
  4561.    @%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
  4562.   */
  4563.           use_snap = 1;
  4564.           break;
  4565.         case SQUARE:
  4566.   /*
  4567.   @ square x,y,side (px),color
  4568.   @ draw a square with left top corner (x:y) with side ''side`` in color 'color'
  4569.   @ use command <code>fsquare x,y,side,color</code> for a filled square
  4570.   @ use command/keyword <a href='#filled'>filled</a> before command <code>square x,y,side,color</code>
  4571.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4572.   @%square%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%filled%fillcolor blue%square 0,0,120,green
  4573.   */
  4574.           for(i=0;i<4;i++){
  4575.             switch(i){
  4576.             case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
  4577.             case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
  4578.             case 2:double_data[2] = get_real(infile,0);break; /* width in px */
  4579.             case 3:stroke_color = get_color(infile,1);/* name or hex color */
  4580.               decimals = find_number_of_digits(precision);
  4581.               double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
  4582.               double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
  4583.               if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4584.               string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4585.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4586.               snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4587.               add_to_buffer(tmp_buffer);
  4588.               if(onclick != 0){object_cnt++;}/* object_cnt++; */
  4589.               reset();break;
  4590.             default: break;
  4591.             }
  4592.           }
  4593.           dragstuff[1] = 1;
  4594.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4595.           break;
  4596.         case STATUS:
  4597.   /*
  4598.   @ status
  4599.   @ keyword
  4600.   @ alernative: nostatus
  4601.   @ used to override the effects of ''status=done`` in wims (answer.phtml)
  4602.   @ affects ''readonly`` in inputfields / textareas in canvasimage and all userdraw based commands
  4603.   @ 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``
  4604.   */
  4605.  
  4606.           fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
  4607.           break;
  4608.         case STRING:
  4609.   /*
  4610.    @ string color,x,y,the text string
  4611.    @ may be set ''onclick`` or ''drag xy``
  4612.    @ 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
  4613.    @ unicode supported: <code>string red,0,0,\\u2232</code><br/> See <a target='new' href='https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode'>https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode</a><br/> See <a  target='new' href='https://en.wikipedia.org/wiki/Greek_script_in_Unicode'>https://en.wikipedia.org/wiki/Greek_script_in_Unicode</a>
  4614.    @ use a command like <code>fontfamily italic 24px Arial</code> to set fonts on browser that support font change
  4615.    @ super / sub script is supported, using '<b>_</b>' and '<b>^</b>' <br>The font family for the sub/sup string will be Helvetica e.g. your font family settings will be ignored <br>to force end the subscript/supscript, use an extra space...see example:
  4616.    @%string_sup_sub%size 400,400%xrange -6,6%yrange -6,6%fontfamily 22px Arial%# you can use a single space for separation in formula...%# use double space to create new word%string blue,-5,3,H_3O^+ + OH^-  \\u2192 2H_2O%# you can use a single space for separation in formula...%string red,-5,-3,H_3 O^+ + OH^\\u2212  \\u2192 2H_2 O%
  4617.    @%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
  4618.   */
  4619.           if( use_rotate == TRUE  ){js_function[JS_ROTATE_MOUSE] = 1; }
  4620.           dragstuff[14] = 1;
  4621.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4622.           for(i=0;i<5;i++){
  4623.             switch(i){
  4624.               case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  4625.               case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
  4626.               case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
  4627.               case 3: decimals = find_number_of_digits(precision);
  4628.                 if(use_affine == TRUE ){ transform(2,2);}
  4629.         /* rotate is done by HTML5/CANVAS context rotation */
  4630.                 temp = get_string_argument(infile,1);
  4631.                 if(strstr(temp,"_") != NULL || strstr(temp,"^") != NULL){js_function[DRAW_SUBSUP] = 1;}
  4632.                 decimals = find_number_of_digits(precision);
  4633.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4634.                 string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4635.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4636.                 snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4637.                 add_to_buffer(tmp_buffer);
  4638.                 if(onclick != 0){object_cnt++;}
  4639.       //onclick = 0;
  4640.       //use_offset = 0;
  4641.                 reset();
  4642.                 break;
  4643.               default:break;
  4644.             }
  4645.           }
  4646.           break;
  4647.         case STRINGUP:
  4648.   /*
  4649.    @ stringup color,x,y,rotation_degrees,the text string
  4650.    @ may be set ''onclick`` or ''drag xy``
  4651.    @ 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
  4652.    @ unicode supported: <code>stringup red,0,0,45,\\u2232</code>
  4653.    @ use a command like <code>fontfamily bold 34px Courier</code> to set fonts on browser that support font change
  4654.    @ 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 thesame coordinates)
  4655.    @ 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>
  4656.    @ super / sub script is supported, using '<b>_</b>' and '<b>^</b>' <br>to end the subscript/supscript, use an extra space...see example:
  4657.    @%stringup_sub_sup%size 400,400%xrange -6,6%yrange -6,6%fontfamily 22px Arial%# use single space for separation in formula...%# use double space to create new word%stringup red,-5,0,45,H_3 O^+ + OH^\\u2212  \\u2192 2H_2 O%
  4658.    @%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 red,-3,0,-90,Hello World%drag xy%stringup red,-3,0,-45,Hello World%stringup red,-3,0,45,Hello World%stringup red,-3,0,90,Hello World%stringup blue,3,0,-90,Hello World%stringup blue,3,0,-45,Hello World%stringup blue,3,0,45,Hello World%stringup blue,3,0,90,Hello World
  4659.  
  4660.   */
  4661.       /* html5 canvas rotation is only used for text objects  */
  4662.           use_rotate = TRUE ;
  4663.           dragstuff[14] = 1;
  4664.           js_function[JS_ROTATE_MOUSE] = 1;
  4665.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4666.  
  4667.           for(i=0;i<6;i++){
  4668.             switch(i){
  4669.               case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  4670.               case 1: double_data[0] = get_real(infile,0);break; /* x */
  4671.               case 2: double_data[1] = get_real(infile,0);break; /* y */
  4672.               case 3: angle = get_real(infile,0);break;/* rotation */
  4673.               case 4: decimals = find_number_of_digits(precision);
  4674.                 temp = get_string_argument(infile,1);
  4675.                 if(strstr(temp,"_") != NULL || strstr(temp,"^") != NULL){js_function[DRAW_SUBSUP] = 1;}
  4676.                 decimals = find_number_of_digits(precision);
  4677.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4678.                 string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4679.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4680.                 snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4681.                 add_to_buffer(tmp_buffer);
  4682.                 if(onclick != 0){object_cnt++;}
  4683.                 //onclick = 0;
  4684.                 //use_offset = 0;
  4685.                 reset();
  4686.                 break;
  4687.               default:break;
  4688.             }
  4689.           }
  4690.           use_rotate = FALSE;
  4691.           break;
  4692.         case STYLE:
  4693.   /*
  4694.    @ highlight color,opacity,linewidth
  4695.    @ NOT IMPLEMENTED
  4696.    @ use command ''onclick``: when the object receives a userclick it will increase its linewidth
  4697.   */
  4698.          break;
  4699.         case STROKECOLOR:
  4700.   /*
  4701.   @ strokecolor colorname or #hex
  4702.   @ to be used for commands that do not supply a color argument (like command ''linegraph``)
  4703.   */
  4704.           stroke_color = get_color(infile,1);
  4705.           break;
  4706.         case FLY_TEXT:
  4707.   /*
  4708.   @ text fontcolor,x,y,font,text_string
  4709.   @ font may be described by keywords: giant,huge,normal,small,tiny
  4710.   @ use command ''fontsize`` to increase base fontsize for these keywords
  4711.   @ may be set ''onclick`` or ''drag xy``
  4712.   @ backwards compatible with flydraw
  4713.   @ unicode supported: text red,0,0,huge,\\u2232
  4714.   @ special: use '_' and '^' to imitate html sup/sub, like H_3O^+ + OH^\\u22i2  \\u2192 2H_2 O
  4715.   @ much better to use command <a href='#string'>string</a> combined with <a href='#fontfamily'>fontfamily</a> for a more fine grained control over html5 canvas text element
  4716.   @ super / sub script is supported, using '<b>_</b>' and '<b>^</b>' <br>to end the subscript/supscript, use an extra space...see <a href='#string'>string </a> command
  4717.   @ 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 lke ''fontfamily Arial`` before the old flydraw commands.
  4718.   @%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
  4719.   */
  4720.         for(i = 0; i < 5 ;i++){
  4721.           switch(i){
  4722.             case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
  4723.             case 1: double_data[0] = get_real(infile,0);break; /* x */
  4724.             case 2: double_data[1] = get_real(infile,0);break; /* y */
  4725.             case 3: fly_font = get_string_argument(infile,0);
  4726.               if(strcmp(fly_font,"giant") == 0){
  4727.                 fly_font_size = (int)(font_size + 24);
  4728.               }
  4729.               else {
  4730.                 if(strcmp(fly_font,"huge") == 0){
  4731.                   fly_font_size = (int)(font_size + 14);
  4732.                 }
  4733.                 else {
  4734.                   if(strcmp(fly_font,"large") == 0){
  4735.                     fly_font_size = (int)(font_size + 6);
  4736.                   }
  4737.                   else {
  4738.                     if(strcmp(fly_font,"small") == 0){
  4739.                       fly_font_size = (int)(font_size - 4);
  4740.                       if(fly_font_size<0){fly_font_size = 8;}
  4741.                     }
  4742.                   }
  4743.                 }
  4744.               }
  4745.               break;
  4746.             case 4:
  4747.               temp = get_string_argument(infile,1);
  4748.               if(strstr(temp,"_") != NULL || strstr(temp,"^") != NULL){js_function[DRAW_SUBSUP] = 1;}
  4749.               decimals = find_number_of_digits(precision);
  4750.               if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4751.               if(use_affine == TRUE ){ transform(2,2);}
  4752.               string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,%s,%s,%s,%d));\n",drag_type,object_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",my_sliders,rotation_center,use_offset);
  4753.               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4754.               snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,14,[%.*f],[%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,%s,%s,%s,%d));\n",drag_type,object_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",my_sliders,rotation_center,use_offset);
  4755.               add_to_buffer(tmp_buffer);
  4756.               if(onclick != 0){object_cnt++;}
  4757.               reset();
  4758.               break;
  4759.             default:break;
  4760.             }
  4761.           }
  4762.           dragstuff[14] = 1;
  4763.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4764.           break;
  4765.         case TEXTAREA:
  4766.   /*
  4767.    @ textarea x,y,cols,rows,readonly,value
  4768.    @ may be further controlled by <a href="#css">css</a>
  4769.    @ 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>.
  4770.    @ 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>)
  4771.    @ keyword ''xoffset | centered`` is not active for command ''textarea``
  4772.    @%textarea%size 400,400%xrange -10,10%yrange -10,10%css color:red;background-color:lightblue;font-size:14px;text-align:center%textarea -3,-2,6,3,1,?%css color:blue;background-color:yellow;font-size:14px;text-align:center%textarea 0,-2,8,2,1,?
  4773.   */
  4774.           js_function[DRAW_TEXTAREAS] = 1;
  4775.           for(i = 0 ; i<6;i++){
  4776.             switch(i){
  4777.               case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
  4778.               case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
  4779.               case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
  4780.               case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
  4781.               case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
  4782.               case 5: temp = get_string_argument(infile,1);
  4783.                 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],css_class,temp);
  4784.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4785.                 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],css_class,temp);
  4786.                 add_to_buffer(tmp_buffer);
  4787.                 input_cnt++;break;
  4788.               default: break;
  4789.             }
  4790.           }
  4791.           if(reply_format == 0 ){reply_format = 15;}
  4792.           reset();
  4793.           break;
  4794.         case TEXTFILL:
  4795.   /*
  4796.   @ textfill x0,y0,color,some_text
  4797.   @ x0,y0 in xrange / yrange
  4798.   @ color will be used for the font color
  4799.   @ use command <a href="#fontfamily">fontfamily</a> to set font type and size
  4800.   @ there is also a command <a href="#userdraw">userdraw textfill,color,some_text</a>
  4801.   @%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
  4802.   */
  4803.  
  4804.           js_function[DRAW_TEXTFILL] = 1;
  4805.           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  4806.             js_function[DRAW_FILLTOBORDER] = 1;
  4807.             add_js_filltoborder(canvas_type);
  4808.           }
  4809.           decimals = find_number_of_digits(precision);
  4810.           for(i=0;i<4;i++){
  4811.             switch(i){
  4812.               case 0: double_data[0] = get_real(infile,0); break; /* x in px */
  4813.               case 1: double_data[1] = get_real(infile,0); break; /* y in py */
  4814.               case 2: font_color = get_color(infile,0); break;
  4815.               case 3: temp = get_string(infile,1);
  4816.                 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);
  4817.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4818.                 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);
  4819.                 add_to_buffer(tmp_buffer);
  4820.                 fill_cnt++;
  4821.                 break;
  4822.               default:break;
  4823.             }
  4824.           }
  4825.           reset();
  4826.           break;
  4827.         case FLY_TEXTUP:
  4828.   /*
  4829.    @ textup fontcolor,x,y,font,text_string
  4830.    @ can <b>not</b> be set ''onclick`` or ''drag xy`` (because of translaton matrix...mouse incompatible)
  4831.    @ font may be described by keywords: giant,huge,normal,small,tiny
  4832.    @ use command ''fontsize`` to increase base fontsize for the keywords
  4833.    @ backwards compatible with flydraw
  4834.    @ unicode supported: textup red,0,0,huge,\\u2232
  4835.    @ use command ''stringup`` and ''fontfamily`` for a more fine grained control over html5 canvas text element
  4836.    @ 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.
  4837.   */
  4838.           js_function[DRAW_TEXTS] = 1;
  4839.           for(i = 0; i<5 ;i++){
  4840.             switch(i){
  4841.               case 0: font_color = get_color(infile,0);break;/* name or hex color */
  4842.               case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  4843.               case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  4844.               case 3: fly_font = get_string_argument(infile,0);
  4845.                 if(strcmp(fly_font,"giant") == 0){
  4846.                   fly_font_size = (int)(font_size + 24);
  4847.                 }
  4848.                 else {
  4849.                   if(strcmp(fly_font,"huge") == 0){
  4850.                     fly_font_size = (int)(font_size + 14);
  4851.                   }
  4852.                   else {
  4853.                     if(strcmp(fly_font,"large") == 0){
  4854.                       fly_font_size = (int)(font_size + 6);
  4855.                     }
  4856.                     else {
  4857.                       if(strcmp(fly_font,"small") == 0){
  4858.                         fly_font_size = (int)(font_size - 4);
  4859.                         if(fly_font_size<0){fly_font_size = 8;}
  4860.                       }
  4861.                     }
  4862.                   }
  4863.                 }
  4864.                 break;
  4865.               case 4:
  4866.                 decimals = find_number_of_digits(precision);
  4867.                 temp = get_string_argument(infile,1);
  4868.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4869.                 string_length = 1 + snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_offset);
  4870.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4871.                 snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_offset);
  4872.                 add_to_buffer(tmp_buffer);
  4873.                 reset();
  4874.         //use_offset = 0;
  4875.                 break;
  4876.               default:break;
  4877.             }
  4878.           }
  4879.           break;
  4880.         case TRACE_JSCURVE:
  4881.   /*
  4882.    @ trace_jscurve some_math_function
  4883.    @ will use a crosshair to trace the jsmath curve
  4884.    @ two inputfields will display the current x/y-values (numerical evaluation by javascript)
  4885.    @ 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
  4886.    @ use commands fontsize and css to format the fonts for labels and inputfields.
  4887.    @ use commands ''linewidth, strokecolor, crosshairsize`` to adjust the corsshair.
  4888.    @ 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...)
  4889.    @ be aware that the formulas of the plotted function(s) can be found in the page javascript source
  4890.    @%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%css 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
  4891.   */
  4892.           js_function[INTERACTIVE] = 1;
  4893.           js_function[DRAW_CROSSHAIRS] = 1;
  4894.           js_function[DRAW_LINES] = 1;
  4895.           js_function[JS_MATH] = 1;
  4896.           add_trace_js_mouse(TRACE_CANVAS,stroke_color,get_string(infile,1),font_size,stroke_opacity,line_width,crosshair_size,css_class);
  4897.           break;
  4898.         case TRANGE:
  4899.   /*
  4900.   @ trange tmin,tmax
  4901.   @ alternative: ranget
  4902.   @ default -2,2
  4903.   */
  4904.           use_parametric = TRUE;
  4905.           for(i = 0 ; i<2; i++){
  4906.             switch(i){
  4907.               case 0: tmin = get_real(infile,0);break;
  4908.               case 1: tmax = get_real(infile,1);break;
  4909.               default: break;
  4910.             }
  4911.           }
  4912.           if(tmin >= tmax ){canvas_error(" trange is not OK: tmin &lt; tmax!\n");}
  4913.           break;
  4914.         case TRANSLATION:
  4915.   /*
  4916.    @ translation tx,ty
  4917.    @ alternative: translate
  4918.    @ will translate the next objects tx in xrange and ty in yrange
  4919.    @ use command ''killtranstation`` to end the command
  4920.    @%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
  4921.   */
  4922.           for(i = 0 ; i<2;i++){
  4923.             switch(i){
  4924.               case 0: affine_matrix[4] = get_real(infile,0);break;
  4925.               case 1: affine_matrix[5] = get_real(infile,1);
  4926.                 use_affine = TRUE;
  4927.       /* the other values affine_matrix[0..3] remain untouched*/
  4928.                 break;
  4929.               default: break;
  4930.             }
  4931.           }
  4932.           break;
  4933.         case TRIANGLE:
  4934.   /*
  4935.    @ triangle x1,y1,x2,y2,x3,y3,color
  4936.    @ use ftriangle or keyword <a href='#filled'>filled</a> for a solid triangle
  4937.    @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4938.    @%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
  4939.   */
  4940.           for(i=0;i<7;i++){
  4941.             switch(i){
  4942.               case 0: double_data[0] = get_real(infile,0);break; /* x */
  4943.               case 1: double_data[1] = get_real(infile,0);break; /* y */
  4944.               case 2: double_data[2] = get_real(infile,0);break; /* x */
  4945.               case 3: double_data[3] = get_real(infile,0);break; /* y */
  4946.               case 4: double_data[4] = get_real(infile,0);break; /* x */
  4947.               case 5: double_data[5] = get_real(infile,0);break; /* y */
  4948.               case 6: stroke_color = get_color(infile,1);/* name or hex color */
  4949.                 decimals = find_number_of_digits(precision);
  4950.                 if( use_rotate == TRUE ){ rotate(6,angle,rotationcenter,2);}
  4951.                 if( use_affine == TRUE ){ transform(6,2);}
  4952.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4953.                 string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4954.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4955.                 snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4956.                 add_to_buffer(tmp_buffer);
  4957.                 if(onclick != 0){object_cnt++;}
  4958.           /* object_cnt++;*/
  4959.                 reset();
  4960.                 break;
  4961.               default: break;
  4962.             }
  4963.           }
  4964.           dragstuff[5] = 1;
  4965.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4966.           break;
  4967.         case TRIANGLES:
  4968.   /*
  4969.    @ triangles color,x1,y1,x2,y2,x3,y3,...
  4970.    @ use ftriangles or keyword <a href='#filled'>filled</a> for solid triangles
  4971.    @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  4972.    @%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
  4973.   */
  4974.           stroke_color = get_color(infile,0);/* name or hex color */
  4975.           i = 0;
  4976.           decimals = find_number_of_digits(precision);
  4977.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4978.  
  4979.           while( ! done ){
  4980.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4981.             double_data[0] = get_real(infile,0); /* x1 */
  4982.             double_data[1] = get_real(infile,0); /* y1 */
  4983.             double_data[2] = get_real(infile,0); /* x2 */
  4984.             double_data[3] = get_real(infile,0); /* y2 */
  4985.             double_data[4] = get_real(infile,0); /* x3 */
  4986.             double_data[5] = get_real(infile,1); /* y3 */
  4987.             string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4988.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4989.             snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,5,%s,[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  4990.             add_to_buffer(tmp_buffer);
  4991.             if(onclick != 0){object_cnt++;}
  4992.             i = i + 6;
  4993.           }
  4994.           reset();
  4995.           dragstuff[5] = 1;
  4996.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4997.           break;
  4998.         case USERBOXPLOT:
  4999.   /*
  5000.    @ userboxplot
  5001.    @ keyword, no arguments
  5002.    @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a>
  5003.    @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the ''draw_boxplot`` function
  5004.    @ 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)
  5005.   */
  5006.           js_function[DRAW_BOXPLOT] = 1;
  5007.           fprintf(js_include_file,"var boxplot_source = 3;\n");
  5008.           js_function[DRAW_JSBOXPLOT] = 2;
  5009.           break;
  5010.         case USERBOXPLOTDATA:
  5011.   /*
  5012.    @ userboxplotdata
  5013.    @ keyword, no arguments
  5014.    @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a>
  5015.    @ if set, the student will have to generate some statistical data. These data should be put in a named array ''student_boxplot_data``
  5016.    @ ''min,Q1,median,Q3,max`` are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot.
  5017.    @ see command <a href="#userboxplot">userboxplot</a> for calling 'draw_boxplot()'
  5018.   */
  5019.           js_function[DRAW_BOXPLOT] = 1;
  5020.           fprintf(js_include_file,"var boxplot_source = 2;\n");
  5021.           js_function[DRAW_JSBOXPLOT] = 1;
  5022.           break;
  5023.         case USERDRAW:
  5024.   /*
  5025.   @ userdraw object_type,color
  5026.   @ only a single object_type is allowed.
  5027.   @ right mouse click will remove last drawn object.
  5028.   @ for multiple different 'userdraw' objects in an exercise, use command <a href="#multidraw">multidraw</a>
  5029.   @ 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<br>multiple areas may be selected <br>multiple colors may be provided using commands <a href='#colorpalette'>colorpalette color1,color2,color3,...</a> use <a href='#replyformat'>replyformat 10</a> for checking the user click color ... reply=x1:y1:color1,x2:y2:color2...<br/>attention: this will <b>not</b> work for pattern filling, because the pattern image is only generated once and after creation can not be changed !<br>the opacity of this image on a separate canvas is set to 0.01 and not 0 (!!)...in the ''fill algorithm`` the opacity of the matching pixels is set to 1</li><li>dotfill: fill the clicked area with a dot pattern; use command linewidth to change dot size</li><li>diamondfill: fill the clicked area with a diamond pattern</li><li>hatchfill: fill the clicked area with a hatch pattern</li><li>gridfill: fill the clicked area with a grid pattern</li><li>textfill: fill the clicked area with a repeating string<br>userdraw textfill,blue,some_text<br>use command <a href="#fontfamily">fontfamily</a> to adjust text style and size</li><li>''clickfill | pattern filling`` in general:<br>the clicks may be set <a href="#snaptogrid">snaptogrid</a><br>can be used together with command <a href="#floodfill">floodfill or fill</a><br><b>always</b> use together with command <a href="#clearbutton">clearbutton some_text</a> for removal of all click_colored areas<br>the function read_canvas() will return the click coordinates in the sequence of the user clicks<br>use command <a href="#canvastype">canvastype</a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)</li><li>text <br>an inputfield is provided, unicode allowed. The text is drawn a the mouse click, or if used with command ''userinput inputfield`` also at the given x/y-coordonates</li><li>arc</li><li>arcs</li><li>image<br/>only a single "image" of every supported type(*) may be added to canvas window from the surrounding html page.<br>the image should have an 'id' and an onclick handler.<br>(*) supported types are ''svg``,''bitmap``,''p-element``,''div-element`` and ''mathml/tex-code`` with ''\\mmlid{int}``.</li><li>images</li><li>input<br/>place a single inputfield on ''canvas`` <br>use commands 'css' for css styling: use command ''linewidth`` for adjusting the input field size (default 1)</li><li>inputs<br/>place multiple inputfield: placing inputfields on top of each other is not possible</li><li>function : identical to <a href="#userinput">userinput function</a></li></ul>
  5030.   @ 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)
  5031.   @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br>Use command ''fontfamily`` to set font
  5032.   @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
  5033.   @ 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.button != 1: all buttons but left)
  5034.   @ use a prefix <a href='#filled'>filled</a> or ''f`` to set fillable objects filled. (fcircles,filledcircles etc)<br/> in case of ''fillpattern`` do not use the ''f`` prefix !
  5035.   @ for non solid filling, use command <a href="#fillpattern">fillpattern grid,hatch,diamond,dot</a>
  5036.   @ use <a href='#opacity'>opacity int,int</a> and <a href='#fillcolor'>fillcolor color</a> to trigger coloured filling of fillable objects
  5037.   @ use command ''dashed`` and/or ''dashtype int,int`` to trigger dashing
  5038.   @ use command ''replyformat int`` to control / adjust output formatting of javascript function read_canvas(); (the defaults should be fine...)
  5039.   @ may be combined with onclick or drag xy of other components of flyscript objects (although not very useful...)
  5040.   @ may be combined with keyword <a href='#userinput_xy'>userinput_xy</a>
  5041.   @ may be combined width the <a href='#snaptogrid'>snaptogrid snaptopoints </a> etc, to simplify the checking of the student reply
  5042.   @ the cursor may be appropriately styled using command <a href='cursor'>cursor</a>
  5043.   @ note: when zooming / panning after a drawing, the drawing will NOT be zoomed / panned...this is a "design" flaw and not a feature <br>To avoid trouble do not use zooming / panning together width userdraw.!<br>use command <a href="#multidraw">multidraw</a> is this is a problem for you...
  5044.   @ 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)
  5045.   @ note: a special case is ''userdraw image,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!)
  5046.   @ note: command <br><code>userdraw function,color</code> is identical to acombination of <code>strokecolor color</code> and <code>userinput function</code><br>
  5047.   @ note: commands :<br><code>multicolors red,green,blue<br>multilabel f(x)=:g(x)=:h(x)=<br>userdraw functions3,color</code><br>is identical to commands :<br><code>functionlabel f(x)=:p(x)=:w(x)=<br/>strokecolor red<br>userinput function <br>strokecolor green<br>userinput function <br>strokecolor blue<br>userinput function</code>
  5048.   @%userdraw_canvastype_a%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%grid 2,2,grey%replyformat 10%colorpalette orange,yellow,red,green,lightgreen,blue,lightblue,cyan%canvastype 4%userdraw clickfill,blue%clearbutton REMOVE LAST RECTANGLE
  5049.   @%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
  5050.   @%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
  5051.   @%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
  5052.   @%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
  5053.   @%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
  5054.   @%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
  5055.   @%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
  5056.   @%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
  5057.   @%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
  5058.   @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
  5059.   @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
  5060.   @%userdraw_vline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vline,green
  5061.   @%userdraw_vlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vlines,green
  5062.   @%userdraw_hline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hline,green
  5063.   @%userdraw_hlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hlines,green
  5064.   @%userdraw_demiline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demiline,green
  5065.   @%userdraw_demilines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demilines,green
  5066.   @%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
  5067.   @%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
  5068.   @%userdraw_point%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw point,green
  5069.   @%userdraw_points%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw points,green
  5070.   @%userdraw_arrow%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow,green
  5071.   @%userdraw_arrows%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows,green
  5072.   @%userdraw_arrow2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow2,green
  5073.   @%userdraw_arrows2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows2,green
  5074.   @%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
  5075.   @%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
  5076.   @%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
  5077.   @%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
  5078.   @%userdraw_crosshair%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshair,green
  5079.   @%userdraw_crosshairs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshairs,green
  5080.   @%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
  5081.   @%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
  5082.   @%userdraw_segment%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segment,green
  5083.   @%userdraw_segments%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segments,green
  5084.   @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
  5085.   @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
  5086.   @%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
  5087.   @%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
  5088.   @%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
  5089.   @%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
  5090.   @%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
  5091.   @%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
  5092.   @%userdraw_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandline,green
  5093.   @%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
  5094.   @%userdraw_freehandlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandlines,green
  5095.   @%userdraw_input%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw input,green
  5096.   @%userdraw_inputs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw inputs,green
  5097.   @%userdraw_text%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%fontfamily 42px Courier%userdraw text,green
  5098.   @%userdraw_function%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%multicolors orange,red,green,blue,cyan%precision 1000%userdraw functions3,red%jscurve blue,x^2,-x^2,5*cos(x)%precision 1%mouse red,22
  5099.   @%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
  5100.   @%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
  5101.   @%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
  5102.   @%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
  5103.   */
  5104.           if( use_userdraw != 0 ){ /* only one object type may be drawn*/
  5105.             canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");
  5106.           }
  5107.           js_function[INTERACTIVE] = 1;
  5108.           draw_type = get_string_argument(infile,0);
  5109.           if( strcmp(draw_type,"textfill") == 0){
  5110.             fprintf(js_include_file,"var userdraw_text_string = \"%s\";", get_string(infile,1));
  5111.           }
  5112.           else {
  5113.             if( strcmp(draw_type,"imagefill") == 0){
  5114.               fprintf(js_include_file,"var userdraw_image_url = \"%s\";", get_string(infile,1));
  5115.             }
  5116.             else {
  5117.               stroke_color = get_color(infile,1);
  5118.             }
  5119.           }
  5120.           if( strcmp(draw_type,"clickfill") == 0){use_filled = 1;fill_color = stroke_color;}
  5121.           reply_precision = precision;
  5122.           use_userdraw = 1;
  5123.           fprintf(js_include_file,"\n\
  5124. /* begin userdraw */\
  5125. userdraw_x = new Array();userdraw_y = new Array();userdraw_radius = new Array();\
  5126. var forbidden_zone=[xsize+1,ysize+1];var xy_cnt = 0;\
  5127. var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\
  5128. var context_userdraw = canvas_userdraw.getContext(\"2d\");\
  5129. var use_dashed = %d;\
  5130. var use_snap = %d;if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\
  5131. context_userdraw.lineWidth = %d;var use_filled = %d;\
  5132. context_userdraw.strokeStyle =  \"rgba(%s,%.2f)\";\
  5133. context_userdraw.font = \"%s\";\
  5134. var user_is_dragging = false;\
  5135. if(wims_status != \"done\"){\
  5136. canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\
  5137. canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\
  5138. canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
  5139. canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\
  5140. canvas_div.addEventListener(\"touchend\" ,function(e){ e.preventDefault();user_drawstop(e.changedTouches[0]);},false);\
  5141. };",canvas_root_id,DRAW_CANVAS,use_dashed,use_snap,dashtype[0],dashtype[1],dashtype[0],dashtype[1],line_width,use_filled,stroke_color,stroke_opacity,font_family);
  5142.  
  5143.           if( use_filled == 0 ){
  5144.             fprintf(js_include_file,"context_userdraw.fillStyle = \"rgba(255,255,255.0)\";");
  5145.           }
  5146.           else {
  5147.             if( use_filled == 1 ){
  5148.               fprintf(js_include_file,"context_userdraw.fillStyle = \"rgba(%s,%.2f)\";",fill_color,fill_opacity);
  5149.             }
  5150.             else {
  5151.               js_function[DRAW_FILL_PATTERN] = 1;
  5152.               fprintf(js_include_file,"context_userdraw.fillStyle = create_Pattern(0,0,%d,[%s]);\n",use_filled,fill_color);
  5153.             }
  5154.           }
  5155.           add_js_userdraw(draw_type,stroke_color,stroke_opacity,crosshair_size,arrow_head,use_offset,css_class,use_snap,canvas_type,use_filled,fill_color,fill_opacity,line_width,font_family);
  5156.           reset();
  5157.           break;
  5158.         case USERINPUT:
  5159.   /*
  5160.    @ userinput function inputfield
  5161.    @ alternative: userinput_function
  5162.    @ alternative: userinput_xy
  5163.    @ ''inputfield`` is only usable in combination with some ''userdraw draw_type``
  5164.    @ note: the input fields are not cleared after the object is drawn...be aware of multiple idential drawings (many clicks on the ''ok`` button)
  5165.    @ ''userinput function`` may be used any time (e.g. without userdraw)
  5166.    @ multiple ''userinput function`` commands may be used.
  5167.    @ use command <code>functionlabel some_string</code> to define the inputfield text: default value "f(x)="
  5168.    @ use command <code>strokecolor some_color</code> to adjust the plot / functionlabel color
  5169.    @ use command <code>css some_css</code> to adjust the inputfields
  5170.    @ use command <code>fontsize int</code> to adjust the label fonts. (default 12px)
  5171.    @ 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
  5172.    @%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%css color:blue;text-align:center%userinput function%# note: number of function inputs not limited
  5173.    @%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
  5174.    @%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
  5175.    @%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%css color:blue;text-align:center%precision 1000%strokecolor red%opacity 255,255%userinput function%# note: number of function inputs not limited%userdraw line,blue
  5176.   */
  5177.           temp = get_string_argument(infile,1);
  5178.           if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
  5179.             if( js_function[DRAW_JSFUNCTION] != 1 ){
  5180.               js_function[JS_RAWMATH] = 1;
  5181.               js_function[DRAW_JSFUNCTION] = 1;
  5182.               if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  5183.               add_input_jsfunction(css_class,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size);
  5184.               input_cnt++;
  5185.             }
  5186.             else {
  5187.         /* no need to add DRAW_JSFUNCTION, just call it with the parameters */
  5188.             fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",%s,%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,css_class,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size);
  5189.             input_cnt++;
  5190.             }
  5191.             js_function[JS_MATH] = 1;
  5192.             js_function[JS_PLOT] = 1;
  5193.           }
  5194.           else {
  5195.             if(strstr(temp,"inputfield") != 0 ){
  5196.               js_function[JS_SAFE_EVAL] = 1;
  5197.               js_function[ADD_USER_INPUTS] = 1;
  5198.             }
  5199.             else {
  5200.               canvas_error("userinput argument may be \"function\" or \"inputfield\"");
  5201.             }
  5202.           }
  5203.           break;
  5204.         case USERINPUT_XY:
  5205.   /*
  5206.   @ userinput_xy
  5207.   @ keyword (no arguments required)
  5208.   @ to be used in combination with command "userdraw object_type,color"
  5209.   @ 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)
  5210.   @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  5211.   @ 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.
  5212.   @ can <b>not</b> be combined with command ''intooltip tiptext`` <br>note: the ''tooltip div element`` is used for placing inputfields
  5213.   @ user drawings will not zoom on zooming (or pan on panning)
  5214.   @ use command ''css some_css`` to adjust the inputarea.
  5215.   @ use command ''fontsize int`` to adjust the text labels (if needed)
  5216.   @%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
  5217.   */
  5218.       /* add simple eval check to avoid code injection with unprotected eval(string) */
  5219.           js_function[JS_SAFE_EVAL] = 1;
  5220.           js_function[ADD_USER_INPUTS] = 1;
  5221.           break;
  5222.         case USERINPUT_FUNCTION:
  5223.   /*
  5224.   @ userinput_function
  5225.   @ alternative: userinput
  5226.   @ keyword (no arguments required)
  5227.   @ if set, a inputfield will be added to the page
  5228.   @ repeat keyword for more function input fields
  5229.   @ the userinput value will be plotted in the canvas
  5230.   @ 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
  5231.   @ use before this command ''userinput_function``,<br>commands like ''css some_css``, ''xlabel some_description``, ''opacity int,int``, ''linewidth int``, ''dashed`` and ''dashtype int,int`` to modify
  5232.   @ fontsize can be set using command ''fontsize int``
  5233.   @ incompatible with command ''intooltip link_text_or_image``: it uses the tooltip div for adding the inputfield
  5234.   @%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%css color:blue;text-align:center;font-family:Italic;%strokecolor blue%functionlabel g(x)=:p(x)=:k(x)=%userinput function%# second inputfield%css color:green;text-align:center;font-family:Italic;%strokecolor green%userinput function%# third inputfield%css color:purple;text-align:center;font-family:Italic;%strokecolor purple%userinput function%# no limit in number of function inputfields
  5235.   */
  5236.           if( js_function[DRAW_JSFUNCTION] != 1 ){
  5237.             js_function[DRAW_JSFUNCTION] = 1;
  5238.             js_function[JS_RAWMATH] = 1;
  5239.             if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  5240.             add_input_jsfunction(css_class,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size);
  5241.             input_cnt++;
  5242.           }
  5243.           else {
  5244.         /* no need to add DRAW_JSFUNCTION, just call it with the parameters */
  5245.           fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",%s,%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,css_class,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size);
  5246.           input_cnt++;
  5247.           }
  5248.           js_function[JS_MATH] = 1;
  5249.           js_function[JS_PLOT] = 1;
  5250.           break;
  5251.         case VLINE:
  5252.   /*
  5253.   @ vline x,y,color
  5254.   @ alternative: verticalline
  5255.   @ draw a vertical line through point (x:y) in color 'color'
  5256.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  5257.   @%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
  5258.   */
  5259.           for(i=0;i<3;i++) {
  5260.             switch(i){
  5261.               case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  5262.               case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  5263.               case 2: stroke_color=get_color(infile,1);/* name or hex color */
  5264.                 double_data[2] = double_data[0];
  5265.                 decimals = find_number_of_digits(precision);
  5266.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  5267.                 string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  5268.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5269.                 snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  5270.                 add_to_buffer(tmp_buffer);
  5271.                 if(onclick != 0){object_cnt++;}
  5272.       /* object_cnt++; */
  5273.                 reset();
  5274.                break;
  5275.             }
  5276.           }
  5277.           dragstuff[4] = 1;
  5278.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  5279.           break;
  5280.         case VLINES:
  5281.   /*
  5282.   @ vlines color,x1,y1,x2,y2....
  5283.   @ alternative: verticallines
  5284.   @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color'
  5285.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  5286.   @%vlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%vlines red,1,0,2,0,3,0,4,0
  5287.   */
  5288.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5289.           fill_color = stroke_color;
  5290.           i=0;
  5291.           while( ! done ){     /* get next item until EOL*/
  5292.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5293.             if(i%2 == 0 ){
  5294.               double_data[i] = get_real(infile,0); /* x */
  5295.             }
  5296.             else {
  5297.               double_data[i] = get_real(infile,1); /* y */
  5298.             }
  5299.             i++;
  5300.           }
  5301.           decimals = find_number_of_digits(precision);
  5302.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  5303.           for(c = 0 ; c < i-1 ; c = c+2){
  5304.             string_length = 1 + snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  5305.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5306.             snprintf(tmp_buffer,string_length,"dragstuff.addShape(new Shape(%d,%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[0],[0],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  5307.             add_to_buffer(tmp_buffer);
  5308.             if(onclick != 0){object_cnt++;}
  5309.             /* object_cnt++; */
  5310.           }
  5311.           reset();
  5312.           dragstuff[4] = 1;
  5313.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  5314.           break;
  5315.         case VIDEO:
  5316.   /*
  5317.   @ video x,y,w,h,videofile location
  5318.   @ x,y: left top corner of audio element (in xrange / yrange)
  5319.   @ w,y: width and height in pixels
  5320.   @ video format may be in *.mp4 (todo: other formats)
  5321.   @%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
  5322.   */
  5323.           js_function[DRAW_VIDEO] = 1;
  5324.           for(i=0;i<5;i++){
  5325.             switch(i){
  5326.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  5327.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */
  5328.               case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  5329.               case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  5330.               case 4: temp = get_string(infile,1);
  5331.                 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);
  5332.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5333.                 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);
  5334.                 add_to_buffer(tmp_buffer);
  5335.                 break;
  5336.               default:break;
  5337.             }
  5338.           }
  5339.           reset();
  5340.           break;
  5341.         case X_AXIS_STRINGS:
  5342.   /*
  5343.    @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5344.    @ alternative: xaxistext
  5345.    @ usable for commands <a href="#numberline">numberline</a> and <a href="#grid">grid</a> or combinations thereof
  5346.    @ use these x-axis num1...num_n values instead of default xmin...xmax
  5347.    @ in case of command ''grid``. there is no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5348.    @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
  5349.    @ 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>)
  5350.    @ a javascript error message will flag non-matching value:name pairs
  5351.    @ if the ''x-axis words`` are too big and will overlap, a simple alternating offset will be applied
  5352.    @ to be used before command grid (see <a href="#grid">command grid</a>)
  5353.    @ ''xmajor`` steps should be synchronised with numbers eg. ''1`` in the next example <code>grid 1,100,grey,1,4,6,grey</code>
  5354.    @%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
  5355.   */
  5356.           use_axis_numbering++;
  5357.           temp = get_string(infile,1);
  5358.           if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5359.           if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5360.           fprintf(js_include_file,"x_strings[%d] = [\"%s\"];x_strings_up[%d] = null;",use_axis_numbering,temp,use_axis_numbering);
  5361.           break;
  5362.         case X_AXIS_STRINGS_UP:
  5363.   /*
  5364.    @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5365.    @ alternative: xaxistextup
  5366.    @ the text will be rotated 90&deg; up
  5367.    @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5368.    @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
  5369.    @ use these x-axis num1...num_n values instead of default xmin...xmax
  5370.    @ 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>)
  5371.    @ a javascript error message will flag non-matching value:name pairs
  5372.    @ if the ''x-axis words`` are too big, they will overlap the graph<br> (in this case the text will start from ysize upwards)
  5373.    @ to be used before command grid (see <a href="#grid">command grid</a>)
  5374.    @''xmajor`` steps should be synchronised with numbers eg. "1" in the next example <code>grid 1,100,grey,1,4,6,grey</code>
  5375.    @%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
  5376.   */
  5377.           use_axis_numbering++;
  5378.           temp = get_string(infile,1);
  5379.           if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5380.           if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5381.           fprintf(js_include_file,"x_strings_up[%d] = 1;x_strings[%d] = [\"%s\"];",use_axis_numbering,use_axis_numbering,temp);
  5382.           break;
  5383.         case XERRORBARS:
  5384.   /*
  5385.   @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
  5386.   @ 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'
  5387.   @ the errors E1 and E2 values are in xrange.
  5388.   @ use command ''linewidth int`` to adust size
  5389.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  5390.   @%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
  5391.  
  5392.   */
  5393.           stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5394.           fill_color = stroke_color;
  5395.           i=0;
  5396.           while( ! done ){     /* get next item until EOL*/
  5397.             if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5398.             if(i%2 == 0 ){
  5399.                 double_data[i] = get_real(infile,0); /* x */
  5400.             }
  5401.             else {
  5402.               double_data[i] = get_real(infile,1); /* y */
  5403.             }
  5404.             i++;
  5405.           }
  5406.           decimals = find_number_of_digits(precision);
  5407.           if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  5408.           for(c = 2 ; c < i-1 ; c = c+2){
  5409.             string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  5410.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5411.             snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  5412.             add_to_buffer(tmp_buffer);
  5413.             /* object_cnt++; */
  5414.             if(onclick != 0){object_cnt++;}
  5415.           }
  5416.           reset();
  5417.           dragstuff[20] = 1;
  5418.           if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  5419.           break;
  5420.         case NEWRANGE:
  5421.   /*
  5422.   @ newrange xmin,xmax,ymin,ymax
  5423.   @ objects defined after command will make use of this new range
  5424.   @ https://wimsedu.info/?topic=dessiner-des-portions-de-fonctions-sur-un-meme-graphe
  5425.   */
  5426.           for(i = 0 ; i<4; i++){
  5427.             switch(i){
  5428.               case 0: xmin = get_real(infile,0);break;
  5429.               case 1: xmax = get_real(infile,0);break;
  5430.               case 2: ymin = get_real(infile,0);break;
  5431.               case 3: ymax = get_real(infile,1);break;
  5432.               default: break;
  5433.             }
  5434.           }
  5435.           string_length = 1 + snprintf(NULL,0,"\n\nxmin = %f;xmax = %f;ymin = %f;ymax = %f;\n\n",xmin,xmax,ymin,ymax);
  5436.           check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5437.           snprintf(tmp_buffer,string_length,"\n\nxmin = %f;xmax = %f;ymin = %f;ymax = %f;\n\n",xmin,xmax,ymin,ymax);
  5438.           add_to_buffer(tmp_buffer);
  5439.           break;
  5440.         case XRANGE:
  5441.   /*
  5442.   @ xrange xmin,xmax
  5443.   @ alternative: rangex
  5444.   @ if not given: 0,xsize (eg in pixels)
  5445.   */
  5446.       for(i = 0 ; i<2; i++){
  5447.     switch(i){
  5448.         case 0: xmin = get_real(infile,0);break;
  5449.         case 1: xmax = get_real(infile,1);break;
  5450.         default: break;
  5451.     }
  5452.       }
  5453.       if(xmin >= xmax){canvas_error(" xrange is not OK: xmin &lt; xmax !");}
  5454.       fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax);
  5455.       found_size_command++;
  5456.       break;
  5457.  
  5458.         case XSNAPTOGRID:
  5459.   /*
  5460.    @ xsnaptogrid
  5461.    @ keyword (no arguments required)
  5462.    @ a draggable object (use command ''drag x|y|xy``) will snap to the given x-grid values when dragged (mouseup)
  5463.    @ in case of userdraw the drawn points will snap to xmajor grid
  5464.    @ if no grid is defined, points will snap to every integer xrange value. (eg snap_x=1)
  5465.    @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
  5466.    @ if xminor is defined (use keyword ''axis`` to activate xminor), the drawing will snap to xminor <br>use only even dividers in x-minor...for example<br><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 ...<br>
  5467.    @%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
  5468.    @%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
  5469.  
  5470.   */
  5471.   use_snap = 2;
  5472.   break;
  5473.  
  5474.         case XOFFSET:
  5475.   /*
  5476.    @ xoffset
  5477.    @ keyword ; to place the text centered above the text coordinates(x:y) ...
  5478.    @ may be used for points or other things requiring centered labels
  5479.    @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5480.    @ 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)
  5481.   @%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
  5482.   */
  5483.    use_offset = 2;
  5484.    break;
  5485.  
  5486.         case XYOFFSET:
  5487.   /*
  5488.    @ xyoffset
  5489.    @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily
  5490.    @ may be used for points or other things requiring labels
  5491.    @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5492.    @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy
  5493.    @ 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>
  5494.    @%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
  5495.   */
  5496.    use_offset = 3;
  5497.    break;
  5498.  
  5499.         case XUNIT:
  5500.   /*
  5501.    @ xunit some_unit_for_x-values
  5502.    @ unicode allowed (no html code)
  5503.    @ use together with command <a href="#display">display or mouse</a>
  5504.    @ will display the cursor x-coordinate in ''unit``
  5505.    @%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
  5506.   */
  5507.       fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
  5508.       break;
  5509.  
  5510.         case XLABEL:
  5511.   /*
  5512.   @ xlabel some_string
  5513.   @ will be used to create a label for the x-axis (label is in quadrant I)
  5514.   @ can only be used together with command ''grid``<br>not depending on keywords ''axis`` and ''axisnumbering``
  5515.   @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br>use command ''fontsize`` to adjust.<br>(command ''fontfamily`` is not active for this command)
  5516.   @ use <a href="#ylabel">ylabel</a>
  5517.   @%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
  5518.   */
  5519.       temp = get_string(infile,1);
  5520.       fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
  5521.       break;
  5522.  
  5523.         case XLOGBASE:
  5524.   /*
  5525.   @ xlogbase number
  5526.   @ sets the logbase number for the x-axis
  5527.   @ default value 10
  5528.   @ use together with commands xlogscale / xylogscale
  5529.   */
  5530.       fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
  5531.       break;
  5532.  
  5533.         case XLOGSCALE:
  5534.   /*
  5535.    @ xlogscale ymajor,yminor,majorcolor,minorcolor
  5536.    @ the x/y-range are set using commands <code>xrange xmin,xmax</code> and <code>yrange ymin,ymax</code>
  5537.    @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
  5538.    @ the linewidth is set using command ''linewidth int``
  5539.    @ the opacity of major / minor grid lines is set by command <a href='#opacity'>opacity</a>
  5540.    @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number``
  5541.    @ 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>
  5542.    @ note: the complete canvas will be used for the ''log paper``
  5543.    @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5544.    @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br>\
  5545.    @ 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
  5546.    @ note: in case of userdraw, the use of keyword <a href='#userinput_xy'>userinput_xy</a> may be handy !
  5547.    @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
  5548.    @ <b>attention</b>: do not use command ''zoom``
  5549.    @%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
  5550.   */
  5551.       use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5552.       if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5553.       js_function[DRAW_XLOGSCALE] = 1;
  5554.       for(i=0;i<4;i++){
  5555.     switch(i){
  5556.         case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  5557.         case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  5558.         case 2: stroke_color = get_color(infile,0); break;
  5559.         case 3: fill_color = get_color(infile,1);
  5560.       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);
  5561.       tmp_buffer = my_newmem(string_length);
  5562.             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);
  5563.             fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
  5564.       add_to_buffer(tmp_buffer);
  5565.             break;
  5566.         default:break;
  5567.     }
  5568.       }
  5569.       break;
  5570.  
  5571.         case XYLOGSCALE:
  5572.   /*
  5573.    @ xylogscale majorcolor,minorcolor
  5574.    @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax``
  5575.    @ the linewidth is set using command ''linewidth int``
  5576.    @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]``
  5577.    @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number`` and/or ''ylogbase number``
  5578.    @ 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>
  5579.    @ note: the complete canvas will be used for the ''log paper``
  5580.    @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5581.    @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br>\
  5582.    @ 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``)
  5583.    @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy !
  5584.    @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
  5585.    @ <b>attention</b>: do not use command ''zoom``
  5586.    @%xylogscale%size 400,400%xrange 10,50000%yrange 10,50000%xlabel x-axis%ylabel y-axis%xylogscale black,grey%display xy,red,22
  5587.   */
  5588.       use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5589.       if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5590.       js_function[DRAW_XYLOGSCALE] = 1;
  5591.       for(i=0;i<2;i++){
  5592.     switch(i){
  5593.         case 0: stroke_color = get_color(infile,0); break;
  5594.         case 1: fill_color = get_color(infile,1);
  5595.       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);
  5596.       tmp_buffer = my_newmem(string_length);
  5597.             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);
  5598.             fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
  5599.       add_to_buffer(tmp_buffer);
  5600.             break;
  5601.         default:break;
  5602.     }
  5603.       }
  5604.   break;
  5605.  
  5606.  
  5607.         case Y_AXIS_STRINGS:
  5608.   /*
  5609.    @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5610.    @ alternative: yaxistext
  5611.    @ 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>)
  5612.    @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5613.    @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
  5614.    @ use these y-axis num1...num_n values instead of default ymin...ymax
  5615.    @ a javascript error message will flag non-matching value:name pairs
  5616.    @ to be used before command grid (see <a href="#grid">command grid</a>)
  5617.    @%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
  5618.   */
  5619.       temp = get_string(infile,1);
  5620.       if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5621.       if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5622.       fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
  5623.       use_axis_numbering++;
  5624.       break;
  5625.  
  5626.  
  5627.         case YERRORBARS:
  5628.   /*
  5629.   @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
  5630.   @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color 'color'
  5631.   @ the errors E1 and E2 values are in yrange.
  5632.   @ use command ''linewidth int`` to adust size
  5633.   @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  5634.   @%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
  5635.   */
  5636.       stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5637.       fill_color = stroke_color;
  5638.       i=0;
  5639.       while( ! done ){     /* get next item until EOL*/
  5640.     if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5641.     if(i%2 == 0 ){
  5642.         double_data[i] = get_real(infile,0); /* x */
  5643.     }
  5644.     else
  5645.     {
  5646.         double_data[i] = get_real(infile,1); /* y */
  5647.     }
  5648.     i++;
  5649.       }
  5650.       if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  5651.       for(c = 2 ; c < i-1 ; c = c+2){
  5652.     string_length = 1 + snprintf(NULL,0,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  5653.     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5654.     snprintf(tmp_buffer,string_length,"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\",%s,%s,%d));\n",drag_type,object_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,my_sliders,rotation_center,use_offset);
  5655.     add_to_buffer(tmp_buffer);
  5656.     /* object_cnt++; */
  5657.     if(onclick != 0){object_cnt++;}
  5658.       }
  5659.       decimals = find_number_of_digits(precision);
  5660.       reset();
  5661.       dragstuff[19] = 1;
  5662.       if(use_dragstuff == 0 ){ use_dragstuff = 1;}
  5663.       break;
  5664.         case YOFFSET:
  5665.   /*
  5666.    @ yoffset
  5667.    @ keyword; to place the text centered above the text coordinates(x:y) ...
  5668.    @ may be used for points or other things requiring centered labels
  5669.    @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5670.    @ 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)
  5671.    @%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
  5672.   */
  5673.    use_offset = 1;
  5674.    break;
  5675.  
  5676.         case YRANGE:
  5677.   /*
  5678.   @ yrange ymin,ymax
  5679.   @ alternative: rangey
  5680.   @ if not given 0,ysize (eg in pixels)
  5681.   */
  5682.       for(i = 0 ; i<2; i++){
  5683.     switch(i){
  5684.         case 0: ymin = get_real(infile,0);break;
  5685.         case 1: ymax = get_real(infile,1);break;
  5686.         default: break;
  5687.     }
  5688.       }
  5689.       if(ymin >= ymax){canvas_error(" yrange is not OK: ymin &lt; ymax !<br>");}
  5690.       fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax);
  5691.       found_size_command++;
  5692.       break;
  5693.  
  5694.         case YSNAPTOGRID:
  5695.   /*
  5696.    @ ysnaptogrid
  5697.    @ keyword (no arguments required)
  5698.    @ a draggable object (use command ''drag x|y|xy``) will snap to the given y-grid values when dragged (mouseup)
  5699.    @ in case of userdraw the drawn points will snap to ymajor grid
  5700.    @ if no grid is defined, points will snap to every integer yrange value. (eg snap_y=1)
  5701.    @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
  5702.    @ 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>
  5703.    @%ysnaptogrid_1%size 400,400%xrange -10,10%yrange -10,10%ysnaptogrid%grid 1,1,grey%linewidth 2%userdraw crosshairs,blue%css font-size:8px;color:blue%clearbutton delete all crosshairs
  5704.    @%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
  5705.   */
  5706.   use_snap = 3;
  5707.   break;
  5708.  
  5709.         case YLABEL:
  5710.   /*
  5711.   @ ylabel some_string
  5712.   @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
  5713.   @ can only be used together with command <a href="#grid">grid</a><br>not depending on keywords ''axis`` and ''axisnumbering``
  5714.   @ 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)
  5715.   @ use <a href="#xlabel">xlabel</a>
  5716.   @%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
  5717.   */
  5718.       temp = get_string(infile,1);
  5719.       fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
  5720.       break;
  5721.         case YLOGBASE:
  5722.   /*
  5723.   @ ylogbase number
  5724.   @ sets the logbase number for the y-axis
  5725.   @ default value 10
  5726.   @ use together with commands ylogscale / xylogscale
  5727.   */
  5728.           fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
  5729.           break;
  5730.         case YLOGSCALE:
  5731.   /*
  5732.    @ ylogscale xmajor,xminor,majorcolor,minorcolor
  5733.    @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax``
  5734.    @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
  5735.    @ the linewidth is set using command ''linewidth int``
  5736.    @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]``
  5737.    @ default logbase number = 10 ... when needed, set the logbase number with command ''ylogbase number``
  5738.    @ 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>
  5739.    @ note: the complete canvas will be used for the ''log paper``
  5740.    @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5741.    @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br>\
  5742.    @ 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``)
  5743.    @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy !
  5744.    @ <b>attention</b>: do not use command ''zoom``
  5745.    @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
  5746.   */
  5747.       use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5748.       if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5749.       js_function[DRAW_YLOGSCALE] = 1;
  5750.       for(i=0;i<4;i++){
  5751.     switch(i){
  5752.         case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  5753.         case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  5754.         case 2: stroke_color = get_color(infile,0); break;
  5755.         case 3: fill_color = get_color(infile,1);
  5756.       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);
  5757.       tmp_buffer = my_newmem(string_length);
  5758.             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);
  5759.             fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
  5760.       add_to_buffer(tmp_buffer);
  5761.             break;
  5762.         default:break;
  5763.     }
  5764.       }
  5765.       break;
  5766.  
  5767.         case YUNIT:
  5768.   /*
  5769.    @ yunit some_unit_for_y-values
  5770.    @ unicode allowed (no html code)
  5771.    @ use together with command mousey
  5772.    @ will display the cursor y-coordinate in ''unit``
  5773.   */
  5774.           fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
  5775.           break;
  5776.  
  5777.         case ZOOM:
  5778.   /*
  5779.    @ zoom button_color
  5780.    @ introduce a very small ''controlpanel`` at the lower right corner (font size of the panel is fixed to: 22px Arial)
  5781.    @ giving six 15&times;15px ''active`` rectangle areas<br>(''&times;,&darr;,&uarr;,&larr;,&rarr;,&minus;,+``) for zooming and/or panning of the image
  5782.    @ a mouse wheel is active for in/out zooming. Drag panning is not supported (this will conflict with many ''userdraw`` or ''multidraw`` primitives)
  5783.    @ the ''controlpanel`` is not active for a ''userdraw`` mousedown (but it can interfere with some ''userdraw`` types)
  5784.    @ the ''&times;`` symbol will reset to your original xmax/xmin ymax/ymin values.
  5785.    @ choose an appropriate color, so the small ''&times;,&darr;,&uarr;,&larr;,&rarr;,&minus;,+`` are clearly visible
  5786.    @ command ''opacity`` may be used to set stroke_opacity of buttons
  5787.    @ note: on zooming, text will not increase / decrease the font size (todo??)
  5788.    @ note: adding ''zooming`` will increase the size of the javascript include with approx. 11 kb
  5789.   */
  5790.           js_function[INTERACTIVE] = 1;
  5791.           js_function[JS_ZOOM] = 1;
  5792.           if( use_userdraw == 1 ){
  5793.             js_function[USERDRAW_AND_ZOOM] = 1;
  5794.             fprintf(js_include_file,"forbidden_zone = [%d,%d];",xsize-115,ysize - 20);
  5795.           }
  5796.           if(jsplot_cnt != -1){ js_function[JSPLOT_AND_ZOOM] = 1;}
  5797.           stroke_color = get_color(infile,1);
  5798.           /* we use BG_CANVAS (0) */
  5799.           add_js_zoom_buttons(stroke_color,stroke_opacity);
  5800.           done = TRUE;
  5801.           break;
  5802.  
  5803. /* ready */
  5804.         default:sync_input(infile);
  5805.         break;
  5806.       }
  5807.     }
  5808.   /* we are done parsing script file */
  5809.   if(use_dragstuff != 0){
  5810.   /*  add the 20kb drag code: nearly always used ... use_dragstuff==1: no-mouse ! */
  5811.      add_drag_code(DRAG_CANVAS,use_dragstuff,dragstuff,reply_format);
  5812.      if(js_function[JS_ZOOM] == 1){
  5813.         js_function[DRAG_AND_ZOOM] = 1;
  5814.      }
  5815.   }
  5816.  
  5817.   /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize: Quadrant I */
  5818.   if( found_size_command == 1 ){
  5819.     fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
  5820.   }
  5821.   else
  5822.   {
  5823.     if( found_size_command != 3 ){
  5824.      canvas_error("Please specify size first and then both xrange and yrange ...");
  5825.     }
  5826.   }
  5827.  
  5828.   /* if needed, add generic draw functions (grid / xml etc) to buffer: these are no draggable/clickable shapes / objects  ! */
  5829.   add_javascript_function();
  5830.    /* add read_canvas() etc functions if needed */
  5831.   if( reply_format > 0 ){ add_read_canvas(reply_format,reply_precision);}
  5832.   /* no zoom, just add buffer */
  5833.   fprintf(js_include_file,"\n/* add buffer */\n%s};\n/* end wims_canvas_function */\nwims_canvas_function%d();\n",buffer,canvas_root_id);
  5834. /* done writing the javascript include file */
  5835. fclose(js_include_file);
  5836. }
  5837.  
  5838. /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
  5839.  if( use_tooltip > 0 ){
  5840.   if( use_tooltip == 1 ){
  5841.    add_js_tooltip(tooltip_text,bgcolor);
  5842.   }
  5843.   else
  5844.   {
  5845.    if( use_tooltip == 2 ){
  5846.     add_js_popup(getfile_cmd);
  5847.    }
  5848.   }
  5849.  }
  5850. exit(EXIT_SUCCESS);
  5851. }
  5852. /* end main() */
  5853.  
  5854.  
  5855. /******************************************************************************
  5856. **
  5857. **  sync_input
  5858. **
  5859. **  synchronises input line - reads to end of line, leaving file pointer
  5860. **  at first character of next line.
  5861. **
  5862. **  Used by:
  5863. **  main program - error handling.
  5864. **
  5865. ******************************************************************************/
  5866. void sync_input(FILE *infile)
  5867. {
  5868.   int c = 0;
  5869.  
  5870.   if( c == '\n' || c == ';' ) return;
  5871.   while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
  5872.   if( c == EOF ) finished = 1;
  5873.   if( c == '\n' || c == '\r' || c == ';') line_number++;
  5874.   return;
  5875. }
  5876.  
  5877. /******************************************************************************/
  5878.  
  5879.  
  5880. void transform(int num,int incr){
  5881. /*.
  5882. only "double_data[]" is used for transformations !!
  5883. */
  5884.  int i;int ii;double x,y;
  5885.  for(i=0;i<num;i = i+incr){
  5886.   ii = i+1;
  5887.   x = double_data[i]*affine_matrix[0] + double_data[ii]*affine_matrix[1]+affine_matrix[4];
  5888.   y = double_data[i]*affine_matrix[2] + double_data[ii]*affine_matrix[3]+affine_matrix[5];
  5889.  /*
  5890.   printf("(%f:%f) &rarr; (%f:%f)<br>",double_data[i],double_data[ii],x,y);
  5891.  */
  5892.   double_data[i] = x;
  5893.   double_data[ii] = y;
  5894.  }
  5895. }
  5896.  
  5897. void rotate(int num,double angle,double center[],int incr){
  5898.  int i;int ii;double rad = angle * 0.0174532925199;
  5899.  double c = cos(rad);
  5900.  double s = sin(rad);
  5901.  double x,y;
  5902.  for(i=0;i<num;i = i+incr){
  5903.   ii = i+1;
  5904.   x = c*(double_data[i]-center[0]) + s*(double_data[ii] - center[1] ) + center[0];
  5905.   y = c*(double_data[ii]-center[1]) - s*(double_data[i] - center[0] ) + center[1];
  5906.   double_data[i] = x;
  5907.   double_data[ii] = y;
  5908.  // printf("(x:y) - (%f:%f)<br>",x,y);
  5909.  }
  5910. }
  5911. /* not used: see transform()
  5912. void translate(int num){
  5913.  int i;int ii;
  5914.  double x,y;
  5915.  for(i=0;i<num;i = i+2){
  5916.   ii = i+1;
  5917.   x = double_data[i] + affine_matrix[4];
  5918.   y = double_data[ii] + affine_matrix[5];
  5919.   double_data[i] = x;
  5920.   double_data[ii] = y;
  5921.  }
  5922. }
  5923. */
  5924. char *str_replace(const char *str, const char *old, const char *new){
  5925.     if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
  5926.     char *ret, *r;
  5927.     const char *p, *q;
  5928.     size_t oldlen = strlen(old);
  5929.     size_t count = 0;
  5930.     size_t retlen = 0;
  5931.     size_t newlen = strlen(new);
  5932.     if (oldlen != newlen){
  5933.   for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
  5934.       count++;
  5935.       retlen = p - str + strlen(p) + count * (newlen - oldlen);
  5936.   }
  5937.     }
  5938.     else
  5939.     {
  5940.   retlen = strlen(str);
  5941.     }
  5942.  
  5943.     if ((ret = malloc(retlen + 1)) == NULL){
  5944.   ret = NULL;
  5945.   canvas_error("string argument is NULL");
  5946.     }
  5947.     else
  5948.     {
  5949.   for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
  5950.       size_t l = q - p;
  5951.       memcpy(r, p, l);
  5952.       r += l;
  5953.       memcpy(r, new, newlen);
  5954.       r += newlen;
  5955.   }
  5956.   strcpy(r, p);
  5957.     }
  5958.     return ret;
  5959. }
  5960.  
  5961. /******************************************************************************/
  5962.  
  5963. char *get_color(FILE *infile , int last){
  5964.     int c,i = 0,is_hex = 0;
  5965.     char temp[MAX_COLOR_STRING], *string;
  5966.     const char *not_allowed = "0123456789";
  5967.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' )  && ( c != '\t' ) ){
  5968.   if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
  5969.   if( c == '#' ){
  5970.       is_hex = 1;
  5971.   }
  5972.   if( c != ' '){
  5973.       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 !!! ");}}
  5974.       temp[i]=tolower(c);
  5975.       i++;
  5976.   }
  5977.     }
  5978.     if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
  5979.     if( c == '\n' || c == ';'  || c == '\t' ){ done = TRUE; line_number++; }
  5980.     if( c == EOF ){finished = 1;}
  5981.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  5982.     temp[i]='\0';
  5983.     if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
  5984.     if( is_hex == 1 ){
  5985.   char red[3], green[3], blue[3];
  5986.   red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
  5987.   green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
  5988.   blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
  5989.   int r = (int) strtol(red,   NULL, 16);
  5990.   int g = (int) strtol(green, NULL, 16);
  5991.   int b = (int) strtol(blue,  NULL, 16);
  5992.   int L0 = 1+snprintf(NULL,0,"%d,%d,%d",r,g,b);
  5993.         string = my_newmem(L0);
  5994.   snprintf(string,L0,"%d,%d,%d",r,g,b);
  5995.   return string;
  5996.     }
  5997.     else
  5998.     {
  5999.         string = (char *)my_newmem(sizeof(temp));
  6000.   snprintf(string,sizeof(temp),"%s",temp);
  6001.   for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  6002.       if( strcmp( colors[i].name , string ) == 0 ){
  6003.     return colors[i].rgb;
  6004.       }
  6005.   }
  6006.   canvas_error("I was expecting a color name or hexnumber...but found nothing.");
  6007.     }
  6008.     return "0,0,255";
  6009. }
  6010.  
  6011. char *get_string(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */
  6012.     int c,i=0;
  6013.     char  temp[MAX_BUFFER], *string;
  6014.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){
  6015.   temp[i]=c;
  6016.   i++;
  6017.   if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
  6018.     }
  6019.     if( ( c == '\n' ||  c == '\t'  || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  6020.     if( c == '\n' ||  c == '\t') { done = TRUE; line_number++; }
  6021.     if( c == EOF ) {finished = 1;}
  6022.     temp[i]='\0';
  6023.     if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing!");}
  6024.     string=(char *)my_newmem(strlen(temp));
  6025.     snprintf(string,sizeof(temp),"%s",temp);
  6026.     return string;
  6027. }
  6028.  
  6029. char *get_string_argument(FILE *infile,int last){  /* last = 0: more arguments ; last=1 final argument */
  6030.     int c,i=0;
  6031.     char temp[MAX_BUFFER], *string;
  6032.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){
  6033.   temp[i]=c;
  6034.   i++;
  6035.   if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
  6036.     }
  6037.     if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
  6038.     if( c == '\n' || c == '\t' ) { line_number++; }
  6039.     if( c == EOF ) {finished = 1;}
  6040.     if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");}
  6041.     temp[i]='\0';
  6042. /*
  6043.     17.10.2014 removed (question Perrin)
  6044.     may cause some unwanted effects...
  6045.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma), but found nothing !!");}
  6046. */
  6047.     string=(char *)my_newmem(sizeof(temp));
  6048.     snprintf(string,sizeof(temp),"%s",temp);
  6049.     done = TRUE;
  6050.     return string;
  6051. }
  6052.  
  6053. double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0: more arguments ; last=1 final argument */
  6054.     int c,i=0,found_calc = 0;
  6055.     double y;
  6056.     char tmp[MAX_INT];
  6057.     /*
  6058.      these things are 'allowed functions': *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs
  6059.      but there should be a better way to avoid segfaults !
  6060.     */
  6061.     const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/
  6062.     const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */
  6063.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){
  6064.      if( c != ' ' ){
  6065.       if( i == 0 &&  c == '+' ){
  6066.        continue;
  6067.       }
  6068.       else
  6069.       {
  6070.        c = tolower(c);
  6071.        if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");}
  6072.        if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */
  6073.        tmp[i] = c;
  6074.        i++;
  6075.       }
  6076.      }
  6077.      if( i > MAX_INT - 1){canvas_error("number too large");}
  6078.     }
  6079.     if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
  6080.     if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; }
  6081.     if( c == EOF ){done = TRUE ; finished = 1;}
  6082.     tmp[i]='\0';
  6083.     if( strlen(tmp) == 0 ){canvas_error("expected a number, but found nothing !!");}
  6084.     if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */
  6085.      void *f = eval_create(tmp);
  6086.      assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  6087.      y = eval_x(f, 1);
  6088.      /* if function is bogus; y = 1: so no core dumps */
  6089.      eval_destroy(f);
  6090.     }
  6091.     else
  6092.     {
  6093.      y = atof(tmp);
  6094.     }
  6095.     return y;
  6096. }
  6097.  
  6098.  
  6099. void canvas_error(char *msg){
  6100.     fprintf(stdout,"\n</script><hr><span style=\"color:red\">FATAL syntax error: line %d: %s</span><hr>",line_number,msg);
  6101.     finished = 1;
  6102.     exit(EXIT_SUCCESS);
  6103. }
  6104.  
  6105.  
  6106. /* convert x/y coordinates to pixel */
  6107. int x2px(double x){
  6108.  return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
  6109. }
  6110.  
  6111. int y2px(double y){
  6112.  return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
  6113. }
  6114.  
  6115. double px2x(int x){
  6116.  return (x*(xmax - xmin)/xsize + xmin);
  6117. }
  6118. double px2y(int y){
  6119.  return (y*(ymax - ymin)/ysize + ymin);
  6120. }
  6121.  
  6122. void add_to_buffer(char *tmp){
  6123. //fprintf(stdout,"tmp = %s<br>buffer = %s<br>",tmp,buffer);
  6124.  if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
  6125.  /*  do we have enough space left in buffer[MAX_BUFFER] ? */
  6126.  int space_left = (int) (sizeof(buffer) - strlen(buffer));
  6127.  if( space_left > strlen(tmp)){
  6128.   strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
  6129.  }
  6130.  else
  6131.  {
  6132.   canvas_error("your memory buffer is too big<br>simplify your script...it produces too many lines ");
  6133.  }
  6134.  tmp = NULL;free(tmp);
  6135.  return;
  6136. }
  6137.  
  6138. void reset(){
  6139.  if(no_reset == FALSE){ /* 8/5/2020 */
  6140.   use_filled = FALSE;
  6141.   use_dashed = FALSE;
  6142.   if(onclick != 4 ){onclick = 0;} /* slider param 'active'... onclick=4 */
  6143.   drag_type = -1;
  6144.   use_offset = 0;
  6145.  }
  6146. }
  6147.  
  6148. char *getMML(char *tex){
  6149.  int my_pipe[2];pid_t pid;
  6150.  if(pipe(my_pipe)){canvas_error("mathml(): pipe() failure.\n");}
  6151.   pid = fork();
  6152.   if (pid == (pid_t) 0){
  6153.    char *argv[]={"wims_mathml","--use-zoom","0","--tex-size 100%","--max-mml-size","1024","--tex-string",tex,NULL};
  6154.    close(my_pipe[0]);dup2(my_pipe[1], 1);dup2(my_pipe[1], 2);close(my_pipe[1]);
  6155.    execv("../bin/wims_mathml",argv);canvas_error("could not execute wims_mathml\n");
  6156.   }
  6157.   else
  6158.   {
  6159.   if (pid < (pid_t) 0){
  6160.    close(my_pipe[0]);close(my_pipe[1]);canvas_error("mathml(): fork() failure.\n");
  6161.   }
  6162.   int status;FILE *stream;close(my_pipe[1]);stream = fdopen (my_pipe[0], "r");
  6163.   char buffer[MAX_BUFFER+1];memset(buffer,'\0',MAX_BUFFER);
  6164.   fgets(buffer, MAX_BUFFER, stream);
  6165.   int L0 = 1 + snprintf(NULL,0,"%s", buffer);
  6166.   tex = my_newmem(L0);memset(tex,'\0',L0);
  6167.   snprintf(tex,L0,"%s",buffer);
  6168.   fclose (stream);close(my_pipe[0]);waitpid(pid, &status, 0);
  6169.  }
  6170.  return tex;
  6171. }
  6172.  
  6173. char *getSVGMOL(char *inputtype,char *keys){
  6174.   int idx;
  6175.   char *forbidden[] = {"-O","-H","-z","-L","-o","-m"};
  6176.   char *argv[1+strlen(keys)];
  6177.   argv[0] = "obabel"; argv[1] = "-i"; argv[2] = inputtype;
  6178.   idx = 3;int i;
  6179.   char *ptr = strtok(keys,",");
  6180.   while(ptr != NULL ){
  6181.     for(i = 0 ; i < 6; i++ ){if( strncmp(ptr,forbidden[i],2) == 0 ){return "NOT ALLOWED ARGUMENT";}}
  6182.     argv[idx] = ptr; idx++;
  6183.     if(idx > 18){canvas_error("too many arguments for obabel....see docs<br>");}
  6184.     ptr = strtok(NULL,",");
  6185.   }
  6186.   /* last arguments; no 'javascript', only 'svg to STDOUT' and 'NULL' */
  6187.   argv[idx] = "-xj";argv[idx+1] = "-o"; argv[idx+2] = "svg";argv[idx+3] = NULL;
  6188.   int link[2];
  6189.   pid_t pid;
  6190.   char buffer[MAX_BUFFER+1];
  6191.   memset(buffer,'\0',MAX_BUFFER);
  6192.   if (pipe(link)==-1){canvas_error("pipe");}
  6193.   if ((pid = fork()) == -1){canvas_error("fork");}
  6194.  
  6195.   char *svgmol = "error";
  6196.   int string_length = 0;
  6197.  
  6198.   if(pid == 0) {
  6199.     dup2 (link[1], STDOUT_FILENO);
  6200.     dup2(link[0],  STDERR_FILENO);/* remove annoying messages '1 molecule converted' */
  6201.     close(link[0]);
  6202.     close(link[1]);
  6203.     execvp("obabel",argv);
  6204.   } else {
  6205.     close(link[1]);
  6206.     read(link[0],buffer, sizeof(buffer));
  6207.     close(link[0]);
  6208.     /* need to remover newline from svg-string on freebsd */
  6209.     char *pch = strstr(buffer, "\n");
  6210.     while(pch != NULL){
  6211.      strncpy(pch, " ", 1);
  6212.      pch = strstr(buffer, "\n");
  6213.     }
  6214.     string_length = 1 + snprintf(NULL,0,"%s",buffer);
  6215.     svgmol= my_newmem(string_length);
  6216.     snprintf(svgmol,string_length,"%s",buffer);
  6217.     wait(NULL);
  6218.   }
  6219.  return svgmol;
  6220. }
  6221.  
  6222.  
  6223. /* GNU libmatheval library for evaluating mathematical functions. */
  6224. char *eval(int xsize,int ysize,char *fun,double xmin,double xmax,double ymin,double ymax,int plotsteps,int precision,double rotationcenter[]){
  6225.     void *f;
  6226.     double x;
  6227.     double y;
  6228.     double xorg;
  6229.     int xv;
  6230.     int i = 0;
  6231.     int xstep =(int)(xsize/plotsteps);
  6232.     if( xstep == 0 ){xstep = 1;}
  6233.     double a = (xmax - xmin)/xsize;
  6234.     f = eval_create(fun);
  6235.     assert (f);
  6236.     if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  6237.     /* we supply the true x/y values...draw_curve() will convert these (x:y) to pixels : used for pan/scale */
  6238.     double xydata[MAX_BUFFER+1];/* hmmm */
  6239.     int lim_ymin =(int)( ymin - 4*fabs(ymin));/* 19-4-2015 replacing "abs" by "fabs"*/
  6240.     int lim_ymax =(int)( ymax + 4*fabs(ymax));/* 19-4-2015 replacing "abs" by "fabs"*/
  6241.     double c = 1.0;double s = 1.0;
  6242.     if( use_rotate == TRUE ){s = sin(angle*0.0174533);c = cos(angle*0.0174533);}
  6243.     for ( xv = 0 ;xv < xsize ; xv = xv+xstep ){
  6244.   x = (double) (xv*a + xmin);
  6245.   xorg = x;
  6246.   if( i < MAX_BUFFER - 2){
  6247.       y = eval_x(f, x);
  6248.       if(y < lim_ymax && y > lim_ymin ){
  6249.     if( use_affine == TRUE ){
  6250.         x = x*affine_matrix[0] + y*affine_matrix[1]+affine_matrix[4];
  6251.         y = xorg*affine_matrix[2] + y*affine_matrix[3]+affine_matrix[5];
  6252.     }
  6253.     if( use_rotate == TRUE){
  6254.       x = (c * (x - rotationcenter[0])) + (s * (y - rotationcenter[1])) + rotationcenter[0];
  6255.       y = (c * (y - rotationcenter[1])) - (s * (xorg - rotationcenter[0])) + rotationcenter[1];
  6256.     }
  6257.     xydata[i++] = x;
  6258.         xydata[i++] = y;
  6259.       }
  6260.   }
  6261.   else
  6262.   {
  6263.       canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps or some other means to reduce the amount of data... ");
  6264.   }
  6265.     }
  6266.     eval_destroy(f);
  6267.     return double_xy2js_array(xydata,i,find_number_of_digits(precision));
  6268. }
  6269. /* plot a very primitive (!) levelcurve : not to be compared with "flydraw levelcurve" */
  6270. char *eval_levelcurve(int xsize,int ysize,char *fun,double xmin,double xmax,double ymin,double ymax,int plotsteps,int precision,double level){
  6271.     void *f = eval_create(fun);
  6272.     assert (f);
  6273.     if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  6274.     double a = (double)((xmax - xmin)/plotsteps);
  6275.     double b = (double)((ymax - ymin)/plotsteps);
  6276.     double x;double y;double diff;
  6277.     double xydata[MAX_BUFFER+1];
  6278.     int i = 0;
  6279.     ymin = ymin - 1;
  6280.     xmin = xmin - 1;
  6281.     ymax = ymax + 1;
  6282.     xmax = xmax + 1;
  6283.     for( x = xmin ;x < xmax ; x = x + a ){
  6284.   for ( y = ymin ;y < ymax ; y = y + b ){
  6285.       if( i < MAX_BUFFER - 2){
  6286.     diff = level - eval_x_y(f, x,y);
  6287.     if(diff < 0.1 && diff > -0.1){
  6288.         xydata[i++] = x;
  6289.         xydata[i++] = y;
  6290.     }
  6291.       }
  6292.       else
  6293.       {
  6294.     canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps, decrease image size...\nor some other means to reduce the amount of data... ");
  6295.       }
  6296.   }
  6297.     }
  6298.     eval_destroy(f);
  6299.     return double_xy2js_array(xydata,i,find_number_of_digits(precision));
  6300. }
  6301.  
  6302. /* plot parametric function */
  6303. char *eval_parametric(int xsize,int ysize,char *fun1,char* fun2,double xmin,double xmax,double ymin,double ymax,
  6304.  double tmin,double tmax,int plotsteps,int precision,double rotationcenter[]){
  6305.     void *fx;
  6306.     void *fy;
  6307.     double t;
  6308.     int i = 0;
  6309.     double tstep = (tmax-tmin)/plotsteps;
  6310.     if( tstep == 0 ){canvas_error("zero step for t variable : reduce plotsteps or inrease trange");}
  6311.     fx = eval_create(fun1);
  6312.     fy = eval_create(fun2);
  6313.     assert(fx);
  6314.     assert(fy);
  6315.     if( fx == NULL || fy == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  6316.     /* we supply the true x/y values...draw_curve() will convert these (x:y) to pixels : used for pan/scale */
  6317.     double xydata[MAX_BUFFER+1];/* hmmm */
  6318.     double x; /* real x-values */
  6319.     double y; /* real y-values */
  6320.     double xorg;
  6321.     /*
  6322.     29/12/2020
  6323.     disabled to try and synchronise curve+affine behaviour in complex scripts produced by "elec, tool circuit" (BPR)
  6324.     int lim_ymin =(int)( ymin - 4*fabs(ymin));
  6325.     int lim_ymax =(int)( ymax + 4*fabs(ymax));
  6326.     */
  6327.     double c = 1.0;double s = 1.0;if( use_rotate == TRUE ){s = sin(angle*0.0174533);c = cos(angle*0.0174533);}
  6328.     for( t = tmin ;t <= tmax ; t = t + tstep ){
  6329.   if( i < MAX_BUFFER - 2 ){
  6330.       y = eval_t(fy, t);
  6331.   /*    if(y > lim_ymin && y < lim_ymax){*/
  6332.     x = eval_t(fx, t);
  6333.     if( x == x){ /* no NaN */
  6334.      xorg = x;
  6335.      if( use_affine == TRUE ){
  6336.       x = x*affine_matrix[0] + y*affine_matrix[1]+affine_matrix[4];
  6337.       y = xorg*affine_matrix[2] + y*affine_matrix[3]+affine_matrix[5];
  6338.      }
  6339.      if( use_rotate == TRUE){
  6340.        x = (c * (x - rotationcenter[0])) + (s * (y - rotationcenter[1])) + rotationcenter[0];
  6341.        y = (c * (y - rotationcenter[1])) - (s * (xorg - rotationcenter[0])) + rotationcenter[1];
  6342.      }
  6343.      xydata[i++] = x;
  6344.      xydata[i++] = y;
  6345.     }
  6346.  
  6347.   /*    } */
  6348.   }
  6349.   else
  6350.   {
  6351.       canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps or some other means to reduce the amount of data... ");
  6352.   }
  6353.     }
  6354.     eval_destroy(fx);
  6355.     eval_destroy(fy);
  6356.     return double_xy2js_array(xydata,i,find_number_of_digits(precision));
  6357. }
  6358.  
  6359. char *double_xy2js_array(double xy[],int len,int decimals){
  6360.  /*
  6361.     1,2,3,4,5,6,7,8 --> [1,3,5,7],[2,4,6,8]
  6362.     int xy[] is already checked for errors or overflow in "get_real()"
  6363.     just to be sure we double check the size of "temp"
  6364. */
  6365.     char temp[2*MAX_BUFFER], *string;
  6366.     char *tmp = my_newmem(16);/* <= 9999999999999999  */
  6367.     memset(temp,'\0',2*MAX_BUFFER);/* clear memory */
  6368.     int i;int space_left;
  6369.     temp[0] = '[';/* start js-array */
  6370.     for(i = 0; i < len;i = i + 2){ /*  x_points[] */
  6371.   if(i == len - 2){sprintf(tmp, "%.*f",decimals, xy[i]);}else{sprintf(tmp, "%.*f,",decimals,xy[i]);}
  6372.   space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1);
  6373.   if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce your image size or plotsteps ");}
  6374.     }
  6375.     strncat(temp,"],[",4); /* close js x_values array and start new */
  6376.     for(i = 1; i < len;i = i + 2){ /* y_points */
  6377.   if(i == len - 1){ sprintf(tmp, "%.*f",decimals,xy[i]);}else{sprintf(tmp, "%.*f,",decimals,xy[i]);}
  6378.   space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1);
  6379.   if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce your image size or plotsteps");}
  6380.     }
  6381.     strncat(temp,"]",2);
  6382.     string=(char *)my_newmem(sizeof(temp));
  6383.     snprintf(string,sizeof(temp),"%s",temp);
  6384.     return string;
  6385. }
  6386.  
  6387. char *list2js_array(char *list, char *s){/* abc:defg:hjiuy:qwer --> ["abc","defg","hjiuy","qwer"] */
  6388. #define MAX_ARG 128
  6389.  if( strlen(list)> MAX_ARG - 1){canvas_error("argument is too large (&gt; 128)");}
  6390.  char tmp[MAX_ARG];
  6391.  size_t p = 0;
  6392.  tmp[0] = '[';
  6393.  tmp[1] = '\"';
  6394.  size_t t = 2;
  6395.  while(list[p] != '\0'){
  6396.   if( list[p] == s[0] ){
  6397.    tmp[t++]='\"';tmp[t++]=',';tmp[t++]='\"';
  6398.   }
  6399.   else
  6400.   {
  6401.    tmp[t++] = list[p];
  6402.   }
  6403.   p++;
  6404.  }
  6405.  tmp[t++]='\"';tmp[t++]=']';tmp[t++]= '\0';
  6406.  char *js_array = (char *)my_newmem(sizeof(tmp));
  6407.  snprintf(js_array,sizeof(tmp),"%s",tmp);
  6408.  return js_array;
  6409. }
  6410.  
  6411. char *xy2js_array(int xy[],int len){
  6412.  /*
  6413.     1,2,3,4,5,6,7,8 --> [1,3,5,7],[2,4,6,8]
  6414.     int xy[] is already checked for errors or overflow in "get_real()"
  6415.     just to be sure we double check the size of "temp"
  6416. */
  6417.     char temp[MAX_BUFFER], *string;
  6418.     char *tmp = my_newmem(16);/* <= 9999999999999999  */
  6419.     memset(temp,'\0',MAX_BUFFER);/* clear memory */
  6420.     int i;int space_left;
  6421.     temp[0] = '[';/* start js-array */
  6422.     for(i = 0; i < len;i = i + 2){ /*  x_points[] */
  6423.   if(i == len - 2){sprintf(tmp, "%d", xy[i]);}else{sprintf(tmp, "%d,", xy[i]);}
  6424.   space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1);
  6425.   if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce image size or plotsteps ");}
  6426.     }
  6427.     strncat(temp,"],[",4); /* close js x_values array and start new */
  6428.     for(i = 1; i < len;i = i + 2){ /* y_points */
  6429.   if(i == len - 1){ sprintf(tmp, "%d", xy[i]);}else{sprintf(tmp, "%d,", xy[i]);}
  6430.   space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1);
  6431.   if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data\nreduce image size or plotsteps \n");}
  6432.     }
  6433.     strncat(temp,"]",2);
  6434.     string=(char *)my_newmem(sizeof(temp));
  6435.     snprintf(string,sizeof(temp),"%s",temp);
  6436.     return string;
  6437. }
  6438.  
  6439. char *data2js_array(int data[],int len){
  6440.  /*
  6441.     1,2,3,4,5,6,7,8 --> [1,2,3,4,5,6,7,8]
  6442.     int data[] is already checked for errors or overflow in "get_real()"
  6443.     just to be sure we double check the size of "temp"
  6444. */
  6445.     char temp[MAX_BUFFER], *string;
  6446.     char *tmp = my_newmem(16);/* <= 9999999999999999  */
  6447.     memset(temp,'\0',MAX_BUFFER);/* clear memory */
  6448.     int i;int space_left;
  6449.     temp[0] = '[';/* start js-array */
  6450.     for(i = 0; i < len; i++){
  6451.   if(i == len - 1){sprintf(tmp, "%d", data[i]);}else{sprintf(tmp, "%d,", data[i]);}
  6452.   space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1);
  6453.   if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce image size or plotsteps ");}
  6454.     }
  6455.     strncat(temp,"]",2);
  6456.     string=(char *)my_newmem(sizeof(temp));
  6457.     snprintf(string,sizeof(temp),"%s",temp);
  6458.     return string;
  6459. }
  6460.  
  6461. char *doubledata2js_array(double data[],int len, int decimals){
  6462.  /*
  6463.     1.4355,2.345353,3.3455 --> [1.44,2.35,3.35]
  6464.     double data[] is already checked for errors or overflow in "get_real()"
  6465.     just to be sure we double check the size of "temp"
  6466. */
  6467.     char temp[MAX_BUFFER], *string;
  6468.     char *tmp = my_newmem(16);/* <= 9999999999999999  */
  6469.     memset(temp,'\0',MAX_BUFFER);/* clear memory */
  6470.     int i;int space_left;
  6471.     temp[0] = '[';/* start js-array */
  6472.     for(i = 0; i < len; i++){
  6473.   if(i == len - 1){sprintf(tmp, "%.*f",decimals,data[i]);}else{sprintf(tmp, "%.*f,",decimals,data[i]);}
  6474.   space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1);
  6475.   if( space_left > 0 ){ strncat(temp,tmp,space_left - 1);}else{canvas_error("can not parse integer to js-array:\nYour curve plotting produces too many data \nreduce image size or plotsteps ");}
  6476.     }
  6477.     strncat(temp,"]",2);
  6478.     string=(char *)my_newmem(sizeof(temp));
  6479.     snprintf(string,sizeof(temp),"%s",temp);
  6480.     return string;
  6481. }
  6482.  
  6483.  
  6484. void *my_newmem(size_t size){
  6485.  void  *p;
  6486.  if((p = malloc(size +1)) == NULL){canvas_error("canvasdraw: ran out of memory\n");}
  6487.  return p;
  6488. }
  6489.  
  6490. int find_number_of_digits(int i){
  6491.  if(i < 0 ){ i = -1*i;}
  6492.  int digits = 0;
  6493.  while ( i > 0){
  6494.   digits++;
  6495.   i = i/10;
  6496.  }
  6497.  return digits;
  6498. }
  6499.  
  6500. int count_substring(char* string, char* substring) {
  6501.   int i, j, l1, l2;
  6502.   int count = 0;
  6503.   l1 = strlen(string);
  6504.   l2 = strlen(substring);
  6505.   for(i = 0; i < l1 - l2 + 1; i++) {
  6506.     if(strstr(string + i, substring) == string + i) {
  6507.       count++;
  6508.       i = i + l2 -1;
  6509.     }
  6510.   }
  6511.   return count;
  6512. }
  6513.  
  6514.  
  6515.  
  6516. void check_string_length(int L){
  6517.  if( L > MAX_BUFFER-1){
  6518.   canvas_error("problem with your arguments to command...");
  6519.  }
  6520.  return;
  6521. }
  6522.  
  6523. int get_token(FILE *infile){
  6524.   int     c,i=0;
  6525.   char    temp[MAX_INT], *input_type;
  6526.   char  *line="line",
  6527.   *audio="audio",
  6528.   *blink="blink",
  6529.   *arrowhead="arrowhead",
  6530.   *crosshairsize="crosshairsize",
  6531.   *crosshair="crosshair",
  6532.   *crosshairs="crosshairs",
  6533.   *audioobject="audioobject",
  6534.   *style="style",
  6535.   *mouse="mouse",
  6536.   *mousex="mousex",
  6537.   *mousey="mousey",
  6538.   *mouse_display="display",
  6539.   *mouse_degree="mouse_degree",
  6540.   *userdraw="userdraw",
  6541.   *highlight="highlight",
  6542.   *http="http",
  6543.   *rays="rays",
  6544.   *dashtype="dashtype",
  6545.   *dashed="dashed",
  6546.   *filled="filled",
  6547.   *lattice="lattice",
  6548.   *parallel="parallel",
  6549.   *segment="segment",
  6550.   *segments="segments",
  6551.   *dsegment="dsegment",
  6552.   *dsegments="dsegments",
  6553.   *seg="seg",
  6554.   *segs="segs",
  6555.   *bgimage="bgimage",
  6556.   *bgcolor="bgcolor",
  6557.   *strokecolor="strokecolor",
  6558.   *backgroundimage="backgroundimage",
  6559.   *text="text",
  6560.   *textup="textup",
  6561.   *mouseprecision="mouseprecision",
  6562.   *precision="precision",
  6563.   *plotsteps="plotsteps",
  6564.   *plotstep="plotstep",
  6565.   *tsteps="tsteps",
  6566.   *curve="curve",
  6567.   *dcurve="dcurve",
  6568.   *curvedarrow="curvedarrow",
  6569.   *curvedarrows="curvedarrows",
  6570.   *curvedarrow2="curvedarrow2",
  6571.   *curvedarrows2="curvedarrows2",
  6572.   *plot="plot",
  6573.   *dplot="dplot",
  6574.   *levelcurve="levelcurve",
  6575.   *fontsize="fontsize",
  6576.   *fontcolor="fontcolor",
  6577.   *axis="axis",
  6578.   *axisnumbering="axisnumbering",
  6579.   *axisnumbers="axisnumbers",
  6580.   *arrow="arrow",
  6581.   *vector="vector",
  6582.   *vectors="vectors",
  6583.   *darrow="darrow",
  6584.   *arrow2="arrow2",
  6585.   *darrow2="darrow2",
  6586.   *arrows="arrows",
  6587.   *arrows2="arrows2",
  6588.   *zoom="zoom",
  6589.   *grid="grid",
  6590.   *hline="hline",
  6591.   *dhline="dhline",
  6592.   *drag="drag",
  6593.   *horizontalline="horizontalline",
  6594.   *horizontallines="horizontallines",
  6595.   *vline="vline",
  6596.   *dvline="dvline",
  6597.   *verticalline="verticalline",
  6598.   *verticallines="verticallines",
  6599.   *triangle="triangle",
  6600.   *triangles="triangles",
  6601.   *ftriangle="ftriangle",
  6602.   *ftriangles="ftriangles",
  6603.   *mathml="mathml",
  6604.   *html="html",
  6605.   *input="input",
  6606.   *clearbutton="clearbutton",
  6607.   *erase="erase",
  6608.   *delete="delete",
  6609.   *css="css",
  6610.   *textarea="textarea",
  6611.   *range="range",
  6612.   *trange="trange",
  6613.   *ranget="ranget",
  6614.   *xrange="xrange",
  6615.   *yrange="yrange",
  6616.   *rangex="rangex",
  6617.   *rangey="rangey",
  6618.   *path="path",
  6619.   *polyline="polyline",
  6620.   *dpolyline="dpolyline",
  6621.   *brokenline="brokenline",
  6622.   *lines="lines",
  6623.   *poly="poly",
  6624.   *polygon="polygon",
  6625.   *fpolygon="fpolygon",
  6626.   *fpoly="fpoly",
  6627.   *filledpoly="filledpoly",
  6628.   *filledpolygon="filledpolygon",
  6629.   *rect="rect",
  6630.   *frect="frect",
  6631.   *rectangle="rectangle",
  6632.   *frectangle="frectangle",
  6633.   *square="square",
  6634.   *fsquare="fsquare",
  6635.   *fsquares="fsquares",
  6636.   *rects="rects",
  6637.   *frects="frects",
  6638.   *dline="dline",
  6639.   *arc="arc",
  6640.   *filledarc="filledarc",
  6641.   *farc="farc",
  6642.   *size="size",
  6643.   *string="string",
  6644.   *stringup="stringup",
  6645.   *copy="copy",
  6646.   *copyresized="copyresized",
  6647.   *opacity="opacity",
  6648.   *transparent="transparent",
  6649.   *fill="fill",
  6650.   *point="point",
  6651.   *points="points",
  6652.   *linewidth="linewidth",
  6653.   *circle="circle",
  6654.   *circles="circles",
  6655.   *fcircle="fcircle",
  6656.   *fcircles="fcircles",
  6657.   *disk="disk",
  6658.   *disks="disks",
  6659.   *comment="#",
  6660.   *end="end",
  6661.   *ellipse="ellipse",
  6662.   *ellipses="ellipses",
  6663.   *fellipse="fellipse",
  6664.   *rotate="rotate",
  6665.   *affine="affine",
  6666.   *rotationcenter="rotationcenter",
  6667.   *kill="kill",
  6668.   *killrotate="killrotate",
  6669.   *killaffine="killaffine",
  6670.   *killlinear="killlinear",
  6671.   *killinear="killinear",
  6672.   *fontfamily="fontfamily",
  6673.   *fillcolor="fillcolor",
  6674.   *clicktile="clicktile",
  6675.   *clicktile_colors="clicktile_colors",
  6676.   *translation="translation",
  6677.   *translate="translate",
  6678.   *killtranslation="killtranslation",
  6679.   *killtranslate="killtranslate",
  6680.   *onclick="onclick",
  6681.   *roundrects="roundrects",
  6682.   *roundrect="roundrect",
  6683.   *froundrect="froundrect",
  6684.   *froundrects="froundrects",
  6685.   *roundrectangle="roundrectangle",
  6686.   *patternfill="patternfill",
  6687.   *hatchfill="hatchfill",
  6688.   *diafill="diafill",
  6689.   *diamondfill="diamondfill",
  6690.   *dotfill="dotfill",
  6691.   *textfill="textfill",
  6692.   *gridfill="gridfill",
  6693.   *imagefill="imagefill",
  6694.   *xlogbase="xlogbase",
  6695.   *ylogbase="ylogbase",
  6696.   *xlogscale="xlogscale",
  6697.   *ylogscale="ylogscale",
  6698.   *xylogscale="xylogscale",
  6699.   *intooltip="intooltip",
  6700.   *popup="popup",
  6701.   *replyformat="replyformat",
  6702.   *floodfill="floodfill",
  6703.   *fillall="fillall",
  6704.   *filltoborder="filltoborder",
  6705.   *setpixel="setpixel",
  6706.   *pixels="pixels",
  6707.   *pixelsize="pixelsize",
  6708.   *xaxis="xaxis",
  6709.   *xaxisup="xaxisup",
  6710.   *yaxis="yaxis",
  6711.   *xaxistext="xaxistext",
  6712.   *xaxistextup="xaxistextup",
  6713.   *yaxistext="yaxistext",
  6714.   *piechart="piechart",
  6715.   *boxplot="boxplot",
  6716.   *boxplotdata="boxplotdata",
  6717.   *userboxplot="userboxplot",
  6718.   *userboxplotdata="userboxplotdata",
  6719.   *legend="legend",
  6720.   *legendcolors="legendcolors",
  6721.   *xlabel="xlabel",
  6722.   *ylabel="ylabel",
  6723.   *barchart="barchart",
  6724.   *linegraph="linegraph",
  6725.   *clock="clock",
  6726.   *animate="animate",
  6727.   *video="video",
  6728.   *status="status",
  6729.   *nostatus="nostatus",
  6730.   *snaptogrid="snaptogrid",
  6731.   *xsnaptogrid="xsnaptogrid",
  6732.   *ysnaptogrid="ysnaptogrid",
  6733.   *snaptopoints="snaptopoints",
  6734.   *snaptofunction="snaptofunction",
  6735.   *snaptofun="snaptofun",
  6736.   *userinput_xy="userinput_xy",
  6737.   *userinput_function="userinput_function",
  6738.   *userinput="userinput",
  6739.   *jsmath="jsmath",
  6740.   *trace_jscurve="trace_jscurve",
  6741.   *setlimits="setlimits",
  6742.   *jscurve="jscurve",
  6743.   *jsplot="jsplot",
  6744.   *sgraph="sgraph",
  6745.   *title="title",
  6746.   *centerstring="centerstring",
  6747.   *xunit="xunit",
  6748.   *yunit="yunit",
  6749.   *slider="slider",
  6750.   *killslider="killslider",
  6751.   *killgroup="killgroup",
  6752.   *angle="angle",
  6753.   *halflines="halflines",
  6754.   *demilines="demilines",
  6755.   *halfline="halfline",
  6756.   *demiline="demiline",
  6757.   *hlines="hlines",
  6758.   *vlines="vlines",
  6759.   *bezier="bezier",
  6760.   *functionlabel="functionlabel",
  6761.   *functionlabels="functionlabels",
  6762.   *group="group",
  6763.   *multidraw="multidraw",
  6764.   *multilinewidth="multilinewidth",
  6765.   *linewidths="linewidths",
  6766.   *multistrokecolors="multistrokecolors",
  6767.   *multicolors="multicolors",
  6768.   *strokecolors="strokecolors",
  6769.   *colors="colors",
  6770.   *multifillcolors="multifillcolors",
  6771.   *fillcolors="fillcolors",
  6772.   *multistrokeopacity="multistrokeopacity",
  6773.   *multifillopacity="multifillopacity",
  6774.   *multifill="multifill",
  6775.   *multidash="multidash",
  6776.   *multilabel="multilabel",
  6777.   *multiuserinput="multiuserinput",
  6778.   *multiinput="multiinput",
  6779.   *multisnaptogrid="multisnaptogrid",
  6780.   *multisnap="multisnap",
  6781.   *protractor="protractor",
  6782.   *ruler="ruler",
  6783.   *cursor="cursor",
  6784.   *pointer="pointer",
  6785.   *yerrorbars="yerrorbars",
  6786.   *xerrorbars="xerrorbars",
  6787.   *noxaxis="noxaxis",
  6788.   *noyaxis="noyaxis",
  6789.   *colorpalette="colorpalette",
  6790.   *imagepalette="imagepalette",
  6791.   *yoffset="yoffset",
  6792.   *xoffset="xoffset",
  6793.   *latex="latex",
  6794.   *katex="katex",
  6795.   *math="math",
  6796.   *centered="centered",
  6797.   *xyoffset="xyoffset",
  6798.   *resetoffset="resetoffset",
  6799.   *fillpattern="fillpattern",
  6800.   *settile="settile",
  6801.   *numberline="numberline",
  6802.   *duplicates="duplicates",
  6803.   *allowdups="allowdups",
  6804.   *linear="linear",
  6805.   *obabel="obabel",
  6806.   *chemtex="chemtex",
  6807.   *reset="reset",
  6808.   *noreset="noreset",
  6809.   *killreset="killreset",
  6810.   *arrowarc="arrowarc",
  6811.   *arcarrow="arcarrow",
  6812.   *newrange="newrange",
  6813.   *canvastype="canvastype";
  6814.  
  6815.   while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){
  6816.    if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */
  6817.    }else{
  6818.     if( c == ' ' ){
  6819.       break;
  6820.     }else{
  6821.      temp[i] = c;
  6822.      if(i > MAX_INT - 2){canvas_error("command string too long !");}
  6823.      i++;
  6824.     }
  6825.    }
  6826.    if(temp[0] == '#'){ break; }
  6827.   }
  6828.   if (c == '\n' || c == '\r' || c == '\t' ){  line_number++; }
  6829.   if (c == EOF) {finished=1;return 0;}
  6830.  
  6831.   temp[i]='\0';
  6832.   if(strstr(temp,"dash") !=0 && strlen(temp) > 4 && strstr(temp,"dashtype") == 0 ){
  6833.   /* 4/2024 adapt to Flydraw's dashing syntax for all objects with prefix "dash" */
  6834.       use_dashed = TRUE;int idx=0;int p;
  6835.       for( p = 4; p < strlen(temp); p++){temp[idx] = temp[p];idx++;}
  6836.       input_type = (char*)my_newmem(idx); snprintf(input_type,idx+1,"%s",temp);
  6837.   }else{
  6838.       input_type=(char*)my_newmem(strlen(temp));
  6839.       snprintf(input_type,sizeof(temp),"%s",temp);
  6840.   }
  6841. /*  fprintf(stdout,"input_type = %s no_reset = %d <br/>",input_type,no_reset);*/
  6842.   if( strcmp(input_type, size) == 0 ){
  6843.     free(input_type);
  6844.     return SIZE;
  6845.   }
  6846.   if( strcmp(input_type, range) == 0 ){
  6847.     free(input_type);
  6848.     return RANGE;
  6849.   }
  6850.   if( strcmp(input_type, xrange) == 0 ){
  6851.     free(input_type);
  6852.     return XRANGE;
  6853.   }
  6854.   if( strcmp(input_type, rangex) == 0 ){
  6855.     free(input_type);
  6856.     return XRANGE;
  6857.   }
  6858.   if( strcmp(input_type, trange) == 0 ){
  6859.     free(input_type);
  6860.     return TRANGE;
  6861.   }
  6862.   if( strcmp(input_type, ranget) == 0 ){
  6863.     free(input_type);
  6864.     return TRANGE;
  6865.   }
  6866.   if( strcmp(input_type, newrange) == 0 ){
  6867.     free(input_type);
  6868.     return NEWRANGE;
  6869.   }
  6870.   if( strcmp(input_type, yrange) == 0 ){
  6871.     free(input_type);
  6872.     return YRANGE;
  6873.   }
  6874.   if( strcmp(input_type, rangey) == 0 ){
  6875.     free(input_type);
  6876.     return YRANGE;
  6877.   }
  6878.   if( strcmp(input_type, linewidth) == 0 ){
  6879.     free(input_type);
  6880.     return LINEWIDTH;
  6881.   }
  6882.   if( strcmp(input_type, dashed) == 0 ){
  6883.     free(input_type);
  6884.     return DASHED;
  6885.   }
  6886.   if( strcmp(input_type, dashtype) == 0 ){
  6887.     free(input_type);
  6888.     return DASHTYPE;
  6889.   }
  6890.   if( strcmp(input_type, axisnumbering) == 0 ){
  6891.     free(input_type);
  6892.     return AXIS_NUMBERING;
  6893.   }
  6894.   if( strcmp(input_type, axisnumbers) == 0 ){
  6895.     free(input_type);
  6896.     return AXIS_NUMBERING;
  6897.   }
  6898.   if( strcmp(input_type, axis) == 0 ){
  6899.     free(input_type);
  6900.     return AXIS;
  6901.   }
  6902.   if( strcmp(input_type, grid) == 0 ){
  6903.     free(input_type);
  6904.     return GRID;
  6905.   }
  6906.   if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){
  6907.     free(input_type);
  6908.     return HLINES;
  6909.   }
  6910.   if( strcmp(input_type, vlines) == 0 ||  strcmp(input_type, verticallines) == 0 ){
  6911.     free(input_type);
  6912.     return VLINES;
  6913.   }
  6914.   if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){
  6915.     free(input_type);
  6916.     return HLINE;
  6917.   }
  6918.   if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
  6919.     free(input_type);
  6920.     return VLINE;
  6921.   }
  6922.   if( strcmp(input_type, line) == 0 ){
  6923.     free(input_type);
  6924.     return LINE;
  6925.   }
  6926.   if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){
  6927.     free(input_type);
  6928.     return SEGMENTS;
  6929.   }
  6930.   if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
  6931.     free(input_type);
  6932.     return SEGMENT;
  6933.   }
  6934.   if( strcmp(input_type, dsegments) == 0 ){
  6935.     free(input_type);
  6936.     use_dashed = TRUE;
  6937.     return SEGMENTS;
  6938.   }
  6939.   if( strcmp(input_type, dsegment) == 0 ){
  6940.     free(input_type);
  6941.     use_dashed = TRUE;
  6942.     return SEGMENT;
  6943.   }
  6944.   if( strcmp(input_type, crosshairsize) == 0 ){
  6945.     free(input_type);
  6946.     return CROSSHAIRSIZE;
  6947.   }
  6948.   if( strcmp(input_type, arrowhead) == 0 ){
  6949.     free(input_type);
  6950.     return ARROWHEAD;
  6951.   }
  6952.   if( strcmp(input_type, crosshairs) == 0 ){
  6953.     free(input_type);
  6954.     return CROSSHAIRS;
  6955.   }
  6956.   if( strcmp(input_type, crosshair) == 0 ){
  6957.     free(input_type);
  6958.     return CROSSHAIR;
  6959.   }
  6960.   if( strcmp(input_type, onclick) == 0 ){
  6961.     free(input_type);
  6962.     return ONCLICK;
  6963.   }
  6964.   if( strcmp(input_type, drag) == 0 ){
  6965.     free(input_type);
  6966.     return DRAG;
  6967.   }
  6968.   if( strcmp(input_type, userdraw) == 0 ){
  6969.     free(input_type);
  6970.     return USERDRAW;
  6971.   }
  6972.   if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
  6973.     free(input_type);
  6974.     return STYLE;
  6975.   }
  6976.   if( strcmp(input_type, fillcolor) == 0 ){
  6977.     free(input_type);
  6978.     return FILLCOLOR;
  6979.   }
  6980.   if( strcmp(input_type, strokecolor) == 0 ){
  6981.     free(input_type);
  6982.     return STROKECOLOR;
  6983.   }
  6984.   if( strcmp(input_type, filled) == 0  ){
  6985.     free(input_type);
  6986.     return FILLED;
  6987.   }
  6988.   if( strcmp(input_type, http) == 0 ){
  6989.     free(input_type);
  6990.     return HTTP;
  6991.   }
  6992.   if( strcmp(input_type, rays) == 0 ){
  6993.     free(input_type);
  6994.     return RAYS;
  6995.   }
  6996.   if( strcmp(input_type, lattice) == 0 ){
  6997.     free(input_type);
  6998.     return LATTICE;
  6999.   }
  7000.   if( strcmp(input_type, bgimage) == 0 ){
  7001.     free(input_type);
  7002.     return BGIMAGE;
  7003.   }
  7004.   if( strcmp(input_type, bgcolor) == 0 ){
  7005.     free(input_type);
  7006.     return BGCOLOR;
  7007.   }
  7008.   if( strcmp(input_type, backgroundimage) == 0 ){
  7009.     free(input_type);
  7010.     return BGIMAGE;
  7011.   }
  7012.   if( strcmp(input_type, text) == 0 ){
  7013.     free(input_type);
  7014.     return FLY_TEXT;
  7015.   }
  7016.   if( strcmp(input_type, textup) == 0 ){
  7017.     free(input_type);
  7018.     return FLY_TEXTUP;
  7019.   }
  7020.   if( strcmp(input_type, mouse) == 0 ){
  7021.     free(input_type);
  7022.     return MOUSE;
  7023.   }
  7024.   if( strcmp(input_type, mousex) == 0 ){
  7025.     free(input_type);
  7026.     return MOUSEX;
  7027.   }
  7028.   if( strcmp(input_type, mousey) == 0 ){
  7029.     free(input_type);
  7030.     return MOUSEY;
  7031.   }
  7032.   if( strcmp(input_type, mouse_degree) == 0 ){
  7033.     free(input_type);
  7034.     return MOUSE_DEGREE;
  7035.   }
  7036.   if( strcmp(input_type, mouse_display) == 0 ){
  7037.     free(input_type);
  7038.     return MOUSE_DISPLAY;
  7039.   }
  7040.   if( strcmp(input_type, mouseprecision) == 0 ){
  7041.     free(input_type);
  7042.     return MOUSE_PRECISION;
  7043.   }
  7044.   if( strcmp(input_type, precision) == 0 ){
  7045.     free(input_type);
  7046.     return MOUSE_PRECISION;
  7047.   }
  7048.   if( strcmp(input_type, curve) == 0 ){
  7049.     free(input_type);
  7050.     return CURVE;
  7051.   }
  7052.   if( strcmp(input_type, dcurve) == 0 ){
  7053.     use_dashed = TRUE;
  7054.     free(input_type);
  7055.     return CURVE;
  7056.   }
  7057.   if( strcmp(input_type, plot) == 0 ){
  7058.     free(input_type);
  7059.     return CURVE;
  7060.   }
  7061.   if( strcmp(input_type, dplot) == 0 ){
  7062.     use_dashed = TRUE;
  7063.     free(input_type);
  7064.     return CURVE;
  7065.   }
  7066.   if( strcmp(input_type, levelcurve) == 0 ){
  7067.     free(input_type);
  7068.     return LEVELCURVE;
  7069.   }
  7070.   if( strcmp(input_type, plotsteps) == 0 ){
  7071.     free(input_type);
  7072.     return PLOTSTEPS;
  7073.   }
  7074.   if( strcmp(input_type, plotstep) == 0 ){
  7075.     free(input_type);
  7076.     return PLOTSTEPS;
  7077.   }
  7078.   if( strcmp(input_type, tsteps) == 0 ){
  7079.     free(input_type);
  7080.     return PLOTSTEPS;
  7081.   }
  7082.   if( strcmp(input_type, fontsize) == 0 ){
  7083.     free(input_type);
  7084.     return FONTSIZE;
  7085.   }
  7086.   if( strcmp(input_type, fontcolor) == 0 ){
  7087.     free(input_type);
  7088.     return FONTCOLOR;
  7089.   }
  7090.   if( strcmp(input_type, arrow2) == 0 ){
  7091.     free(input_type);
  7092.     return ARROW2;
  7093.   }
  7094.   if( strcmp(input_type, darrow) == 0 ){
  7095.     free(input_type);
  7096.     use_dashed = TRUE;
  7097.     return ARROW;
  7098.   }
  7099.   if( strcmp(input_type, darrow2) == 0 ){
  7100.     free(input_type);
  7101.     use_dashed = TRUE;
  7102.     return ARROW2;
  7103.   }
  7104.   if( strcmp(input_type, arrows2) == 0 ){
  7105.     free(input_type);
  7106.     return ARROWS2;
  7107.   }
  7108.   if( strcmp(input_type, arrows) == 0  || strcmp(input_type, vectors) == 0 ){
  7109.     free(input_type);
  7110.     return ARROWS;
  7111.   }
  7112.   if( strcmp(input_type, arrow) == 0 ||  strcmp(input_type, vector) == 0 ){
  7113.     free(input_type);
  7114.     return ARROW;
  7115.   }
  7116.   if( strcmp(input_type, zoom) == 0 ){
  7117.     free(input_type);
  7118.     return ZOOM;
  7119.   }
  7120.   if( strcmp(input_type, triangle) == 0 ){
  7121.     free(input_type);
  7122.     return TRIANGLE;
  7123.   }
  7124.   if( strcmp(input_type, triangles) == 0 ){
  7125.     free(input_type);
  7126.     return TRIANGLES;
  7127.   }
  7128.   if( strcmp(input_type, ftriangles) == 0 ){
  7129.     free(input_type);
  7130.     use_filled = TRUE;
  7131.     return TRIANGLES;
  7132.   }
  7133.   if( strcmp(input_type, ftriangle) == 0 ){
  7134.     free(input_type);
  7135.     use_filled = TRUE;
  7136.     return TRIANGLE;
  7137.   }
  7138.   if( strcmp(input_type, input) == 0 ){
  7139.     free(input_type);
  7140.     return INPUT;
  7141.   }
  7142.   if( strcmp(input_type, css) == 0 ){
  7143.     free(input_type);
  7144.     return CSS;
  7145.   }
  7146.   if( strcmp(input_type, textarea) == 0 ){
  7147.     free(input_type);
  7148.     return TEXTAREA;
  7149.   }
  7150.   if( strcmp(input_type, mathml) == 0 ){
  7151.     free(input_type);
  7152.     return MATHML;
  7153.   }
  7154.   if( strcmp(input_type, html) == 0 ){
  7155.     free(input_type);
  7156.     return HTML;
  7157.   }
  7158.   if( strcmp(input_type, fontfamily) == 0 ){
  7159.     free(input_type);
  7160.     return FONTFAMILY;
  7161.   }
  7162.   if( strcmp(input_type, polyline) == 0 ||  strcmp(input_type, dpolyline) == 0 ||  strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){
  7163.   if(strcmp(input_type, dpolyline) == 0 ){use_dashed = TRUE;}
  7164.     free(input_type);
  7165.     return POLYLINE;
  7166.   }
  7167.   if( strcmp(input_type, lines) == 0 ){
  7168.     free(input_type);
  7169.     return LINES;
  7170.   }
  7171.   if( strcmp(input_type, rects) == 0){
  7172.     free(input_type);
  7173.     return RECTS;
  7174.   }
  7175.   if( strcmp(input_type, frects) == 0 ){
  7176.     free(input_type);
  7177.     use_filled = TRUE;
  7178.     return RECTS;
  7179.   }
  7180.   if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
  7181.     free(input_type);
  7182.     return RECT;
  7183.   }
  7184.   if( strcmp(input_type, square) == 0 ){
  7185.     free(input_type);
  7186.     return SQUARE;
  7187.   }
  7188.   if( strcmp(input_type, fsquare) == 0 ){
  7189.     free(input_type);
  7190.     use_filled = TRUE;
  7191.     return SQUARE;
  7192.   }
  7193.   if( strcmp(input_type, fsquares) == 0 ){
  7194.     free(input_type);
  7195.     use_filled = TRUE;
  7196.     return RECTS;
  7197.   }
  7198.   if( strcmp(input_type, roundrects) == 0 ){
  7199.     free(input_type);
  7200.     return ROUNDRECTS;
  7201.   }
  7202.   if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
  7203.     free(input_type);
  7204.     return ROUNDRECT;
  7205.   }
  7206.   if( strcmp(input_type, froundrects) == 0 ){
  7207.     free(input_type);
  7208.     use_filled = TRUE;
  7209.     return ROUNDRECTS;
  7210.   }
  7211.   if( strcmp(input_type, froundrect) == 0 ){
  7212.     free(input_type);
  7213.     use_filled = TRUE;
  7214.     return ROUNDRECT;
  7215.   }
  7216.   if( strcmp(input_type, dline) == 0 ){
  7217.     use_dashed = TRUE;
  7218.     free(input_type);
  7219.     return LINE;
  7220.   }
  7221.   if( strcmp(input_type, dvline) == 0 ){
  7222.     use_dashed = TRUE;
  7223.     free(input_type);
  7224.     return VLINE;
  7225.   }
  7226.   if( strcmp(input_type, dhline) == 0 ){
  7227.     use_dashed = TRUE;
  7228.     free(input_type);
  7229.     return HLINE;
  7230.   }
  7231.   if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0  ){
  7232.     free(input_type);
  7233.     return HALFLINES;
  7234.   }
  7235.   if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0  ){
  7236.     free(input_type);
  7237.     return HALFLINE;
  7238.   }
  7239.   if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
  7240.     use_filled = TRUE;
  7241.     free(input_type);
  7242.     return RECT;
  7243.   }
  7244.   if( strcmp(input_type, circles) == 0 ){
  7245.     free(input_type);
  7246.     return CIRCLES;
  7247.   }
  7248.   if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
  7249.     use_filled = TRUE;
  7250.     free(input_type);
  7251.     return CIRCLE;
  7252.   }
  7253.   if( strcmp(input_type, fcircles) == 0  ||  strcmp(input_type, disks) == 0 ){
  7254.     use_filled = TRUE;
  7255.     free(input_type);
  7256.     return CIRCLES;
  7257.   }
  7258.   if( strcmp(input_type, circle) == 0 ){
  7259.     free(input_type);
  7260.     return CIRCLE;
  7261.   }
  7262.   if( strcmp(input_type, point) == 0 ){
  7263.     free(input_type);
  7264.     return POINT;
  7265.   }
  7266.   if( strcmp(input_type, points) == 0 ){
  7267.     free(input_type);
  7268.     return POINTS;
  7269.   }
  7270.   if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){
  7271.     use_filled = TRUE;
  7272.     free(input_type);
  7273.     return ARC;
  7274.   }
  7275.   if( strcmp(input_type, arc) == 0 ){
  7276.     free(input_type);
  7277.     return ARC;
  7278.   }
  7279.   if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
  7280.     free(input_type);
  7281.     return POLY;
  7282.   }
  7283.   if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
  7284.     use_filled = TRUE;
  7285.     free(input_type);
  7286.     return POLY;
  7287.   }
  7288.   if( strcmp(input_type, ellipse) == 0){
  7289.     free(input_type);
  7290.     return ELLIPSE;
  7291.   }
  7292.   if( strcmp(input_type, ellipses) == 0){
  7293.   free(input_type);
  7294.   return ELLIPSES;
  7295.   }
  7296.   if( strcmp(input_type, string) == 0 ){
  7297.     free(input_type);
  7298.     return STRING;
  7299.   }
  7300.   if( strcmp(input_type, stringup) == 0 ){
  7301.     free(input_type);
  7302.     return STRINGUP;
  7303.   }
  7304.   if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){
  7305.     free(input_type);
  7306.     return OPACITY;
  7307.   }
  7308.   if( strcmp(input_type, comment) == 0){
  7309.     free(input_type);
  7310.     return COMMENT;
  7311.   }
  7312.   if( strcmp(input_type, fellipse) == 0){
  7313.     free(input_type);
  7314.     use_filled = TRUE;
  7315.     return ELLIPSE;
  7316.   }
  7317.   if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){
  7318.     free(input_type);
  7319.     return CLEARBUTTON;
  7320.   }
  7321.   if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
  7322.     free(input_type);
  7323.     return TRANSLATION;
  7324.   }
  7325.   if( strcmp(input_type, kill) == 0 ){
  7326.     free(input_type);
  7327.     return KILL;
  7328.   }
  7329.   if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
  7330.     free(input_type);
  7331.     return KILLTRANSLATION;
  7332.   }
  7333.   if( strcmp(input_type, rotate) == 0){
  7334.     free(input_type);
  7335.     return ROTATE;
  7336.   }
  7337.   if( strcmp(input_type, killrotate) == 0){
  7338.     free(input_type);
  7339.     return KILLROTATE;
  7340.   }
  7341.   if( strcmp(input_type, rotationcenter) == 0){
  7342.     free(input_type);
  7343.     return ROTATION_CENTER;
  7344.   }
  7345.   if( strcmp(input_type, affine) == 0){
  7346.     free(input_type);
  7347.     return AFFINE;
  7348.   }
  7349.   if( strcmp(input_type, linear) == 0){
  7350.     free(input_type);
  7351.     return LINEAR;
  7352.   }
  7353.   if( strcmp(input_type, killaffine) == 0){
  7354.     free(input_type);
  7355.     return KILLAFFINE;
  7356.   }
  7357.   if( strcmp(input_type, killlinear) == 0 || strcmp(input_type, killinear) == 0  ){
  7358.     free(input_type);
  7359.     return KILLLINEAR;
  7360.   }
  7361.   if( strcmp(input_type, slider) == 0 ){
  7362.     free(input_type);
  7363.     return SLIDER;
  7364.   }
  7365.   if( strcmp(input_type, killslider) == 0 || strcmp(input_type, killgroup) == 0 ){
  7366.     free(input_type);
  7367.     return KILLSLIDER;
  7368.   }
  7369.   if( strcmp(input_type, copy) == 0 ){
  7370.     free(input_type);
  7371.     return COPY;
  7372.   }
  7373.   if( strcmp(input_type, copyresized) == 0 ){
  7374.     free(input_type);
  7375.     return COPYRESIZED;
  7376.   }
  7377.   if( strcmp(input_type, xlogscale) == 0 ){
  7378.     free(input_type);
  7379.     return XLOGSCALE;
  7380.   }
  7381.   if( strcmp(input_type, ylogscale) == 0 ){
  7382.     free(input_type);
  7383.     return YLOGSCALE;
  7384.   }
  7385.   if( strcmp(input_type, xylogscale) == 0 ){
  7386.     free(input_type);
  7387.     return XYLOGSCALE;
  7388.   }
  7389.   if( strcmp(input_type, ylogscale) == 0 ){
  7390.     free(input_type);
  7391.     return YLOGSCALE;
  7392.   }
  7393.   if( strcmp(input_type, xlogbase) == 0 ){
  7394.     free(input_type);
  7395.     return XLOGBASE;
  7396.   }
  7397.   if( strcmp(input_type, ylogbase) == 0 ){
  7398.     free(input_type);
  7399.     return YLOGBASE;
  7400.   }
  7401.   if( strcmp(input_type, intooltip) == 0 ){
  7402.     free(input_type);
  7403.     return INTOOLTIP;
  7404.   }
  7405.   if( strcmp(input_type, popup) == 0 ){
  7406.     free(input_type);
  7407.     return POPUP;
  7408.   }
  7409.   if( strcmp(input_type,video) == 0 ){
  7410.     free(input_type);
  7411.     return VIDEO;
  7412.   }
  7413.   if( strcmp(input_type,math) == 0 || strcmp(input_type,latex) == 0 ||  strcmp(input_type,katex) == 0 ){
  7414.     free(input_type);
  7415.     return LATEX;
  7416.   }
  7417.   if( strcmp(input_type,fillall) == 0 ){
  7418.     free(input_type);
  7419.     return FILLALL;
  7420.   }
  7421.   if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
  7422.     free(input_type);
  7423.     return FLOODFILL;
  7424.   }
  7425.   if( strcmp(input_type,filltoborder) == 0 ){
  7426.     free(input_type);
  7427.     return FILLTOBORDER;
  7428.   }
  7429.   if( strcmp(input_type, curvedarrow2) == 0 ){
  7430.     free(input_type);
  7431.     return CURVEDARROW2;
  7432.   }
  7433.   if( strcmp(input_type, curvedarrow) == 0 ){
  7434.     free(input_type);
  7435.     return CURVEDARROW;
  7436.   }
  7437.   if( strcmp(input_type, curvedarrows) == 0 ){
  7438.     free(input_type);
  7439.     return CURVEDARROWS;
  7440.   }
  7441.   if( strcmp(input_type, curvedarrows2) == 0 ){
  7442.     free(input_type);
  7443.     return CURVEDARROWS2;
  7444.   }
  7445.   if( strcmp(input_type, replyformat) == 0 ){
  7446.     free(input_type);
  7447.     return REPLYFORMAT;
  7448.   }
  7449.   if( strcmp(input_type, pixelsize) == 0 ){
  7450.     free(input_type);
  7451.     return PIXELSIZE;
  7452.   }
  7453.   if( strcmp(input_type, setpixel) == 0 ){
  7454.     free(input_type);
  7455.     return SETPIXEL;
  7456.   }
  7457.   if( strcmp(input_type, pixels) == 0 ){
  7458.     free(input_type);
  7459.     return PIXELS;
  7460.   }
  7461.   if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
  7462.     free(input_type);
  7463.     return X_AXIS_STRINGS;
  7464.   }
  7465.   if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){
  7466.     free(input_type);
  7467.     return X_AXIS_STRINGS_UP;
  7468.   }
  7469.   if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
  7470.     free(input_type);
  7471.     return Y_AXIS_STRINGS;
  7472.   }
  7473.   if( strcmp(input_type, legend) == 0  ){
  7474.     free(input_type);
  7475.     return LEGEND;
  7476.   }
  7477.   if( strcmp(input_type, legendcolors) == 0  ){
  7478.     free(input_type);
  7479.     return LEGENDCOLORS;
  7480.   }
  7481.   if( strcmp(input_type, xlabel) == 0  ){
  7482.     free(input_type);
  7483.     return XLABEL;
  7484.   }
  7485.   if( strcmp(input_type, ylabel) == 0  ){
  7486.     free(input_type);
  7487.     return YLABEL;
  7488.   }
  7489.   if( strcmp(input_type, bezier) == 0  ){
  7490.     free(input_type);
  7491.     return BEZIER;
  7492.   }
  7493.   if( strcmp(input_type, animate) == 0  ){
  7494.     free(input_type);
  7495.     return ANIMATE;
  7496.   }
  7497.   /* these are bitmap related flydraw commands...must be removed. eventually */
  7498.   if( strcmp(input_type, transparent) == 0 ){
  7499.     free(input_type);
  7500.     return TRANSPARENT;
  7501.   }
  7502.   if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
  7503.     free(input_type);
  7504.     return STATUS;
  7505.   }
  7506.   if( strcmp(input_type, xsnaptogrid) == 0 ){
  7507.     free(input_type);
  7508.     return XSNAPTOGRID;
  7509.   }
  7510.   if( strcmp(input_type, ysnaptogrid) == 0 ){
  7511.     free(input_type);
  7512.     return YSNAPTOGRID;
  7513.   }
  7514.   if( strcmp(input_type, snaptogrid) == 0 ){
  7515.     free(input_type);
  7516.     return SNAPTOGRID;
  7517.   }
  7518.   if( strcmp(input_type, snaptopoints) == 0 ){
  7519.     free(input_type);
  7520.     return SNAPTOPOINTS;
  7521.   }
  7522.   if( strcmp(input_type, snaptofunction) == 0  || strcmp(input_type, snaptofun) == 0 ){
  7523.     free(input_type);
  7524.     return SNAPTOFUNCTION;
  7525.   }
  7526.   if( strcmp(input_type, userinput_xy) == 0 ){
  7527.     free(input_type);
  7528.     return USERINPUT_XY;
  7529.   }
  7530.   if( strcmp(input_type, userinput_function) == 0 ){
  7531.     free(input_type);
  7532.     return USERINPUT_FUNCTION;
  7533.   }
  7534.   if( strcmp(input_type, userinput) == 0 ){
  7535.     free(input_type);
  7536.     return USERINPUT;
  7537.   }
  7538.   if( strcmp(input_type, angle) == 0 ){
  7539.     free(input_type);
  7540.     return ANGLE;
  7541.   }
  7542.   if( strcmp(input_type, functionlabel) == 0 ||  strcmp(input_type, functionlabels) == 0 ){
  7543.     free(input_type);
  7544.     return FUNCTION_LABEL;
  7545.   }
  7546.   if( strcmp(input_type, group) == 0 ){
  7547.     free(input_type);
  7548.     return GROUP;
  7549.   }
  7550.   if( strcmp(input_type, multidraw) == 0 ){
  7551.     free(input_type);
  7552.     return MULTIDRAW;
  7553.   }
  7554.   if( strcmp(input_type, multistrokeopacity) == 0 ){
  7555.     free(input_type);
  7556.     return MULTISTROKEOPACITY;
  7557.   }
  7558.   if( strcmp(input_type, multifillopacity) == 0 ){
  7559.     free(input_type);
  7560.     return MULTIFILLOPACITY;
  7561.   }
  7562.   if( strcmp(input_type, multilinewidth) == 0 || strcmp(input_type, linewidths) == 0 ){
  7563.     free(input_type);
  7564.     return MULTILINEWIDTH;
  7565.   }
  7566.   if( strcmp(input_type, multistrokecolors) == 0 || strcmp(input_type,multicolors) == 0  || strcmp(input_type,strokecolors) == 0 ||  strcmp(input_type,colors) == 0 ){
  7567.     free(input_type);
  7568.     return MULTISTROKECOLORS;
  7569.   }
  7570.   if( strcmp(input_type, multifill) == 0 ){
  7571.     free(input_type);
  7572.     return MULTIFILL;
  7573.   }
  7574.   if( strcmp(input_type, multifillcolors) == 0 || strcmp(input_type, fillcolors) == 0  ){
  7575.     free(input_type);
  7576.     return MULTIFILLCOLORS;
  7577.   }
  7578.   if( strcmp(input_type, multilabel) == 0 ){
  7579.     free(input_type);
  7580.     return MULTILABEL;
  7581.   }
  7582.   if( strcmp(input_type, multidash) == 0 ){
  7583.     free(input_type);
  7584.     return MULTIDASH;
  7585.   }
  7586.   if( strcmp(input_type, multisnaptogrid) == 0  ||  strcmp(input_type, multisnap) == 0 ){
  7587.     free(input_type);
  7588.     return MULTISNAPTOGRID;
  7589.   }
  7590.   if( strcmp(input_type, multiuserinput) == 0 || strcmp(input_type, multiinput) == 0  ){
  7591.     free(input_type);
  7592.     return MULTIUSERINPUT;
  7593.   }
  7594.   if( strcmp(input_type, parallel) == 0 ){
  7595.     free(input_type);
  7596.     return PARALLEL;
  7597.   }
  7598.   if( strcmp(input_type, protractor) == 0 ){
  7599.     free(input_type);
  7600.     return PROTRACTOR;
  7601.   }
  7602.   if( strcmp(input_type, ruler) == 0 ){
  7603.     free(input_type);
  7604.     return RULER;
  7605.   }
  7606.   if( strcmp(input_type, cursor) == 0 || strcmp(input_type, pointer) == 0 ){
  7607.     free(input_type);
  7608.     return CURSOR;
  7609.   }
  7610.   if( strcmp(input_type, sgraph) == 0 ){
  7611.     free(input_type);
  7612.     return SGRAPH;
  7613.   }
  7614.   if( strcmp(input_type, jsmath) == 0 ){
  7615.     free(input_type);
  7616.     return JSMATH;
  7617.   }
  7618.   if( strcmp(input_type, trace_jscurve) == 0 ){
  7619.     free(input_type);
  7620.     return TRACE_JSCURVE;
  7621.   }
  7622.   if( strcmp(input_type, jscurve) == 0 || strcmp(input_type, jsplot) == 0 ){
  7623.     free(input_type);
  7624.     return JSCURVE;
  7625.   }
  7626.   if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
  7627.     free(input_type);
  7628.     return CENTERSTRING;
  7629.   }
  7630.   if( strcmp(input_type, setlimits) == 0 ){
  7631.     free(input_type);
  7632.     return SETLIMITS;
  7633.   }
  7634.   if( strcmp(input_type, xunit) == 0 ){
  7635.     free(input_type);
  7636.     return XUNIT;
  7637.   }
  7638.   if( strcmp(input_type, yunit) == 0 ){
  7639.     free(input_type);
  7640.     return YUNIT;
  7641.   }
  7642.   if( strcmp(input_type, fill) == 0 ){
  7643.     free(input_type);
  7644.     return FLOODFILL;
  7645.   }
  7646.   if( strcmp(input_type, end) == 0){
  7647.     free(input_type);
  7648.     return END;
  7649.   }
  7650.   if( strcmp(input_type, blink) == 0 ){
  7651.     free(input_type);
  7652.     return BLINK;
  7653.   }
  7654.   if( strcmp(input_type, audio) == 0 ){
  7655.     free(input_type);
  7656.     return AUDIO;
  7657.   }
  7658.   if( strcmp(input_type, audioobject) == 0 ){
  7659.     free(input_type);
  7660.     return AUDIOOBJECT;
  7661.   }
  7662.   if( strcmp(input_type, patternfill) == 0 ){
  7663.     free(input_type);
  7664.     return PATTERNFILL;
  7665.   }
  7666.   if( strcmp(input_type, hatchfill) == 0 ){
  7667.     free(input_type);
  7668.     return HATCHFILL;
  7669.   }
  7670.   if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
  7671.     free(input_type);
  7672.     return DIAMONDFILL;
  7673.   }
  7674.   if( strcmp(input_type, dotfill) == 0 ){
  7675.     free(input_type);
  7676.     return DOTFILL;
  7677.   }
  7678.   if( strcmp(input_type, textfill) == 0 ){
  7679.     free(input_type);
  7680.     return TEXTFILL;
  7681.   }
  7682.   if( strcmp(input_type, gridfill) == 0 ){
  7683.     free(input_type);
  7684.     return GRIDFILL;
  7685.   }
  7686.   if( strcmp(input_type, imagefill) == 0 ){
  7687.     free(input_type);
  7688.     return IMAGEFILL;
  7689.   }
  7690.   if( strcmp(input_type, clicktile_colors) == 0 ){
  7691.     free(input_type);
  7692.     return CLICKTILE_COLORS;
  7693.   }
  7694.   if( strcmp(input_type, clicktile) == 0 ){
  7695.     free(input_type);
  7696.     return CLICKTILE;
  7697.   }
  7698.   if( strcmp(input_type, piechart) == 0  ){
  7699.     free(input_type);
  7700.     return PIECHART;
  7701.   }
  7702.   if( strcmp(input_type, boxplot) == 0  ){
  7703.     free(input_type);
  7704.     return BOXPLOT;
  7705.   }
  7706.   if( strcmp(input_type, boxplotdata) == 0  ){
  7707.     free(input_type);
  7708.     return BOXPLOTDATA;
  7709.   }
  7710.   if( strcmp(input_type, userboxplot) == 0  ){
  7711.     free(input_type);
  7712.     return USERBOXPLOT;
  7713.   }
  7714.   if( strcmp(input_type, userboxplotdata) == 0  ){
  7715.     free(input_type);
  7716.     return USERBOXPLOT;
  7717.   }
  7718.   if( strcmp(input_type, barchart) == 0  ){
  7719.     free(input_type);
  7720.     return BARCHART;
  7721.   }
  7722.   if( strcmp(input_type, linegraph) == 0  ){
  7723.     free(input_type);
  7724.     return LINEGRAPH;
  7725.   }
  7726.   if( strcmp(input_type, clock) == 0  ){
  7727.     free(input_type);
  7728.     return CLOCK;
  7729.   }
  7730.   if( strcmp(input_type, yerrorbars) == 0  ){
  7731.     free(input_type);
  7732.     return YERRORBARS;
  7733.   }
  7734.   if( strcmp(input_type, xerrorbars) == 0  ){
  7735.     free(input_type);
  7736.     return XERRORBARS;
  7737.   }
  7738.   if( strcmp(input_type, canvastype) == 0  ){
  7739.     free(input_type);
  7740.     return CANVASTYPE;
  7741.   }
  7742.   if( strcmp(input_type, noyaxis) == 0  ){
  7743.     free(input_type);
  7744.     return NOYAXIS;
  7745.   }
  7746.   if( strcmp(input_type, noxaxis) == 0  ){
  7747.     free(input_type);
  7748.     return NOXAXIS;
  7749.   }
  7750.   if( strcmp(input_type, colorpalette) == 0  ){
  7751.     free(input_type);
  7752.     return COLORPALETTE;
  7753.   }
  7754.   if( strcmp(input_type, imagepalette) == 0  ){
  7755.     free(input_type);
  7756.     return IMAGEPALETTE;
  7757.   }
  7758.   if( strcmp(input_type,reset) == 0){
  7759.     free(input_type);
  7760.     return RESET;
  7761.   }
  7762.   if( strcmp(input_type, resetoffset) == 0  ){
  7763.     free(input_type);
  7764.     return RESETOFFSET;
  7765.   }
  7766.   if( strcmp(input_type, xyoffset) == 0  ){
  7767.     free(input_type);
  7768.     return XYOFFSET;
  7769.   }
  7770.   if( strcmp(input_type, centered) == 0 ){
  7771.     free(input_type);
  7772.     return CENTERED;
  7773.   }
  7774.   if( strcmp(input_type, yoffset) == 0   ){
  7775.     free(input_type);
  7776.     return YOFFSET;
  7777.   }
  7778.   if( strcmp(input_type, xoffset) == 0   ){
  7779.     free(input_type);
  7780.     return XOFFSET;
  7781.   }
  7782.   if( strcmp(input_type, fillpattern) == 0 ||  strcmp(input_type, settile) == 0  ){
  7783.     free(input_type);
  7784.     return FILLPATTERN;
  7785.   }
  7786.   if( strcmp(input_type, numberline) == 0 ){
  7787.     free(input_type);
  7788.     return NUMBERLINE;
  7789.   }
  7790.   if( strcmp(input_type, obabel) == 0 ){
  7791.     free(input_type);
  7792.     return OBABEL;
  7793.   }
  7794.   if( strcmp(input_type, chemtex) == 0 ){
  7795.     free(input_type);
  7796.     return CHEMTEX;
  7797.   }
  7798.   if( strcmp(input_type, noreset) == 0  || strcmp(input_type, killreset) == 0 ){
  7799.     return NORESET;
  7800.   }
  7801.   if( strcmp(input_type, duplicates) == 0 || strcmp(input_type, allowdups) == 0 ){
  7802.     free(input_type);
  7803.     return ALLOW_DUPLICATES;
  7804.   }
  7805.   if( strcmp(input_type, arrowarc) == 0 || strcmp(input_type, arcarrow) == 0 ){
  7806.     free(input_type);
  7807.     return ARCARROW;
  7808.   }
  7809.     free(input_type);
  7810.     ungetc(c,infile);
  7811.     return 0;
  7812. }
  7813.  
  7814.  
  7815.  
  7816.