Subversion Repositories wimsdev

Rev

Rev 18172 | 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.  
  290.         case ANIMATE:
  291.         /*
  292.          @ animate
  293.          @ keyword
  294.          @ if set, it will animate a point on a curve
  295.          @ 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'
  296.          @ the animated point is a filled rectangle ; adjust colour with command <code>fillcolor colorname/hexnumber</code>
  297.          @ use linewidth to adjust size of the points
  298.          @ 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
  299.          @ only usable in combination with command <a href='#jsplot'>jsplot</a> (normal functions or parametric)
  300.          @ 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>
  301.          @ 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>
  302.          @%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)
  303.          @%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
  304.         */
  305.             use_animate++;
  306.             if( use_animate == 1 ){
  307.             fprintf(js_include_file,"\nvar trace_canvas  = create_canvas%d(%d,xsize,ysize);\
  308.             var trace_ctx = trace_canvas.getContext('2d');\
  309.             trace_ctx.fillStyle = 'rgba(%s,%f)';\
  310.             trace_ctx.strokeStyle = 'rgba(%s,%f)';\
  311.             trace_ctx.lineWidth = %d;var anim_pos = 0;\n\
  312.             function animate_this(){\
  313.              var sync;\
  314.              var synchrone = Math.floor(animation_steps/animation_funs);\
  315.              trace_ctx.clearRect(0,0,xsize,ysize);\
  316.              for(var p=0; p<animation_funs;p++){\
  317.               sync = p*synchrone;\
  318.               trace_ctx.fillRect(x_anim_points[sync+anim_pos]-%d, y_anim_points[sync+anim_pos]-%d,%d,%d);\
  319.              };\
  320.              setTimeout(function(){\
  321.               requestAnimationFrame(animate_this);  anim_pos++;}, 50\
  322.              );\
  323.              if(anim_pos >= animation_steps){anim_pos = 0;};\
  324.              };",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);
  325.             }
  326.             else
  327.             {
  328.                 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)");
  329.             }
  330.             break;
  331.  
  332.         case ARC:
  333.         /*
  334.          @ arc xc,yc,x-width,y-height,start_angle,end_angle,color
  335.          @ may be set ''onclick`` or ''drag xy``
  336.          @ compatible with ''flydraw``
  337.          @ attention: width &amp; height in x/y-range
  338.          @ for arrow hats on an arc, see  command <a href='#arcarrow'>arcarrow or arrowarc</a>
  339.          @ better use command <a href='#angle'>angle</a> for use with a <a href='#slider'>slider</a>
  340.          @%arc%size 400,400%xrange -10,10%yrange -10,10%arc 0,0,4,4,10,135,red
  341.          @%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
  342.         */
  343.             for(i=0;i<7;i++){
  344.                 switch(i){
  345.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  346.                     case 1:double_data[1] = get_real(infile,0);
  347.                     if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  348.                     if(use_affine == TRUE ){ transform(4,2);}
  349.                     break; /* y-values */
  350.                     case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */
  351.                     case 3:double_data[3] = get_real(infile,0);
  352.                     break; /* height y-range no pixels ! */
  353.                     case 4:double_data[4] = get_real(infile,0) - angle ;break; /* start angle in degrees */
  354.                     case 5:double_data[5] = get_real(infile,0) - angle;break; /* end angle in degrees */
  355.                     case 6:stroke_color = get_color(infile,1);/* name or hex color */
  356.                     /* in Shape library:
  357.                         x[0] = x[1] = xc = double_data[0]
  358.                         y[0] = y[1] = yc = double_data[1]
  359.                         w[0] = width = double_data[2]
  360.                         w[1] = height = double_data[3]
  361.                         h[0] = start_angle = double_data[4]
  362.                         h[1] = end_angle = double_data[5]
  363.                     */
  364.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  365.                         decimals = find_number_of_digits(precision);
  366.                         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);
  367.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  368.                         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);
  369.                         add_to_buffer(tmp_buffer);reset();
  370.                         dragstuff[12] = 1;
  371.                         if(onclick != 0){object_cnt++;}
  372.                         if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  373.                     break;
  374.                 }
  375.             }
  376.             break;
  377.         case ARCARROW:
  378.         /*
  379.          @ arrowarc xc,yc,x-width,y-height,start_angle,end_angle,color,type
  380.          @ alternative: arcarrow
  381.          @ uses same syntax as <a href='#arc'>arc</a>
  382.          @ for arrow hat: type = 1 : right<br>type = 2 : left<br>type = 3 : left&amp;right
  383.          @ if the default arrow hat/head is not satisfactory , the size of the arrow may be set with command <a href='#arrowhead'>arrowhead</a>
  384.          @ no other arrow types are implemented...yet
  385.          @ may be set draggable or onclick
  386.          @ 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)
  387.          @%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
  388.         */
  389.             for(i=0;i<8;i++){
  390.                 switch(i){
  391.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  392.                     case 1:double_data[1] = get_real(infile,0);
  393.                     if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  394.                     if(use_affine == TRUE ){ transform(4,2);}
  395.                     break; /* y-values */
  396.                     case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */
  397.                     case 3:double_data[3] = get_real(infile,0);
  398.                     break; /* height y-range no pixels ! */
  399.                     case 4:double_data[4] = get_real(infile,0) - angle ;break; /* start angle in degrees */
  400.                     case 5:double_data[5] = get_real(infile,0) - angle;break; /* end angle in degrees */
  401.                     case 6:stroke_color = get_color(infile,0);/* name or hex color */
  402.                     break;
  403.                     case 7:int_data[0] = (int) get_real(infile,1);
  404.                         switch(int_data[0]){
  405.                          case 1: int_data[1] = 24;break; /* right */
  406.                          case 2: int_data[1] = 25;break; /* left */
  407.                          case 3: int_data[1] = 26;break; /* left&right */
  408.                          default:int_data[1] = 24;break;
  409.                         }
  410.                         if(int_data[0] == 1 ){int_data[1] = 24;}
  411.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  412.                         decimals = find_number_of_digits(precision);
  413.                         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);
  414.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  415.                         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);
  416.                         add_to_buffer(tmp_buffer);
  417.                         dragstuff[int_data[1]] = 1;
  418.                         if(onclick != 0){object_cnt++;}
  419.                         if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  420.                         js_function[JS_ARROWHEAD] = 1;
  421.                         reset();
  422.                 }
  423.             }
  424.             break;
  425.         case ARROW:
  426.         /*
  427.         @ arrow x1,y1,x2,y2,h,color
  428.         @ alternative: vector
  429.         @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br>with arrowhead size h in px and in color ''color``
  430.         @ use command <code>linewidth int</code> to adjust thickness of the arrow
  431.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  432.         @%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
  433.         @%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
  434.         */
  435.             for(i=0;i<6;i++){
  436.                 switch(i){
  437.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  438.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  439.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  440.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  441.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  442.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  443.                             if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);}
  444.                             if(use_affine == TRUE ){ transform(4,2);}
  445.                             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  446.                             decimals = find_number_of_digits(precision);
  447.                             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);
  448.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  449.                             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);
  450.                             if(onclick != 0){object_cnt++;}
  451.                             /* object_cnt++;*/
  452.                             add_to_buffer(tmp_buffer);reset();
  453.                             dragstuff[8] = 1;
  454.                             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  455.                             break;
  456.                 }
  457.             }
  458.             break;
  459.  
  460.         case ARROWS:
  461.         /*
  462.         @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n
  463.         @ alternative: vectors
  464.         @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
  465.         @ use command <code>linewidth int</code> to adjust thickness of the arrow
  466.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  467.         @%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%
  468.         @%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%
  469.         @%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%
  470.         */
  471.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  472.             fill_color = stroke_color;
  473.             arrow_head = (int) get_real(infile,0);/* h */
  474.             i=0;
  475.             while( ! done ){     /* get next item until EOL*/
  476.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  477.                 if(i%2 == 0 ){
  478.                     double_data[i] = get_real(infile,0); /* x */
  479.                 }
  480.                 else
  481.                 {
  482.                     double_data[i] = get_real(infile,1); /* y */
  483.                 }
  484.                 i++;
  485.             }
  486.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  487.             if( use_affine == TRUE ){ transform(i-1,2);}
  488.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  489.             decimals = find_number_of_digits(precision);
  490.             for(c = 0 ; c < i-1 ; c = c+4){
  491.                 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);
  492.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  493.                 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);
  494.                 add_to_buffer(tmp_buffer);
  495.                 if(onclick != 0){object_cnt++;}/* object_cnt++; */
  496.             }
  497.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  498.             dragstuff[8] = 1;
  499.             reset();
  500.             break;
  501.  
  502.         case ARROW2:
  503.         /*
  504.         @ arrow2 x1,y1,x2,y2,h,color
  505.         @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br>with arrowhead size h in px and in color ''color``
  506.         @ use command <code>arrowhead int</code> to adjust the arrow head size
  507.         @ use command <code>linewidth int</code> to adjust thickness of the arrow
  508.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  509.         @%arrow2%size 400,400%xrange -10,10%yrange -10,10%drag xy%arrow2 0,0,4,3,8,blue%
  510.         */
  511.             for(i=0;i<6;i++){
  512.                 switch(i){
  513.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  514.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  515.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  516.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  517.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  518.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  519.                         if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);}
  520.                         if( use_affine == 1 ){ transform(4,2);}
  521.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  522.                         decimals = find_number_of_digits(precision);
  523.                         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);
  524.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  525.                         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);
  526.                         add_to_buffer(tmp_buffer);
  527.                         if(onclick != 0){object_cnt++;}/* object_cnt++;*/
  528.                         if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  529.                         dragstuff[10] = 1;
  530.                         reset();
  531.                         break;
  532.                 }
  533.             }
  534.             break;
  535.  
  536.         case ARROWS2:
  537.         /*
  538.         @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n
  539.         @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color ''color``
  540.         @ use command <code>linewidth int</code> to adjust thickness of the arrows
  541.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  542.         @%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%
  543.         */
  544.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  545.             fill_color = stroke_color;
  546.             arrow_head = (int) get_real(infile,0);/* h */
  547.             i=0;
  548.             while( ! done ){     /* get next item until EOL*/
  549.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  550.                 if(i%2 == 0 ){
  551.                     double_data[i] = get_real(infile,0); /* x */
  552.                 }
  553.                 else
  554.                 {
  555.                     double_data[i] = get_real(infile,1); /* y */
  556.                 }
  557.                 i++;
  558.             }
  559.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  560.             if( use_affine == 1 ){ transform(i-1,2);}
  561.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  562.  
  563.             decimals = find_number_of_digits(precision);
  564.             for(c = 0 ; c < i-1 ; c = c+4){
  565.                 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);
  566.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  567.                 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);
  568.                 add_to_buffer(tmp_buffer);
  569.                 if(onclick != 0){object_cnt++;}/* object_cnt++; */
  570.             }
  571.             dragstuff[10] = 1;
  572.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  573.             reset();
  574.             break;
  575.         case ARROWHEAD:
  576.         /*
  577.         @ arrowhead int
  578.         @ default 8 (pixels)
  579.         */
  580.             arrow_head = (int) (get_real(infile,1));
  581.             break;
  582.  
  583.         case AUDIO:
  584.         /*
  585.         @ audio x,y,w,h,loop,visible,audiofile location
  586.         @ x,y: left top corner of audio element (in xrange / yrange)
  587.         @ w,y: width and height in pixels
  588.         @ loop: 0 or 1 ( 1 = loop audio fragment)
  589.         @ visible: 0 or 1 (1 = show controls)
  590.         @ audio format may be in *.mp3 or *.ogg
  591.         @ If you are using *.mp3: be aware that FireFox will not (never) play this ! (Pattented format)
  592.         @ if you are using *.ogg: be aware that Microsoft based systems not support it natively
  593.         @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br>the program will use both as source tag
  594.         */
  595.             js_function[DRAW_AUDIO] = 1;
  596.             for(i=0;i<7;i++){
  597.                 switch(i){
  598.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  599.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  600.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  601.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  602.                     case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
  603.                     case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
  604.                     case 6:
  605.                     temp = get_string(infile,1);
  606.                     if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
  607.                     if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
  608.                     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);
  609.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  610.                     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);
  611.                     add_to_buffer(tmp_buffer);
  612.                     break;
  613.                     default:break;
  614.                 }
  615.             }
  616.             reset();
  617.             break;
  618.  
  619.  
  620.         case AXIS_NUMBERING:
  621.         /*
  622.             @ axisnumbering
  623.             @ keyword (no arguments required)
  624.             @ 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>
  625.             @ to be used before command grid (see <a href="#grid">command grid</a>)
  626.         */
  627.             use_axis_numbering++;
  628.             break;
  629.         case AXIS:
  630.         /*
  631.             @ axis
  632.             @ keyword (no arguments required)
  633.             @ to be used before command grid (see <a href="#grid">command grid</a>)
  634.  
  635.         */
  636.             use_axis = TRUE;
  637.             break;
  638.  
  639.         case BARCHART:
  640.         /*
  641.         @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
  642.         @ may <b>only</b> to be used together with command <a href='#grid'>grid</a>
  643.         @ 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>
  644.         @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner
  645.         @ multiple barchart command may be used in a single script
  646.         @ also see command <a href='#piechart'>piechart</a>
  647.         @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble...
  648.         @%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
  649.         */
  650.             temp = get_string(infile,1);
  651.             if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
  652.             fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
  653.             barchart_cnt++;
  654.             reset();
  655.             break;
  656.  
  657.         case BEZIER:
  658.         /*
  659.         @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end
  660.         @ draw a bezier curve between points, starting from (x_start:y_start)
  661.         @ can <b>not</b> be dragged or set onclick
  662.         */
  663.             js_function[DRAW_BEZIER] = 1;
  664.             decimals = find_number_of_digits(precision);
  665.             for(i = 0 ; i < 9; i++){
  666.                 switch(i){
  667.                     case 0: stroke_color = get_color(infile,0);break;
  668.                     case 1: double_data[0] = get_real(infile,0);break;/* start x */
  669.                     case 2: double_data[1] = get_real(infile,0);break;/* start y */
  670.                     case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */
  671.                     case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */
  672.                     case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */
  673.                     case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */
  674.                     case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */
  675.                     case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */
  676.                         if(use_rotate == TRUE ){rotate(8,angle,rotationcenter,2);}
  677.                         if(use_affine == TRUE ){ transform(2,5);}
  678.                         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);
  679.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  680.                         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);
  681.                         add_to_buffer(tmp_buffer);
  682.                         break;
  683.                     default: break;
  684.                 }
  685.             }
  686.             reset();
  687.             break;
  688.  
  689.  
  690.         case BGCOLOR:
  691.         /*
  692.          @ bgcolor colorname or #hex
  693.          @ use this color as background of the "div" containing the canvas(es)
  694.          @%bgcolor%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue
  695.         */
  696.         /* [255,255,255]*/
  697.             bgcolor = get_string(infile,1);
  698.             if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
  699.                 int found = 0;
  700.                 for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  701.                     if( strcmp( colors[i].name , bgcolor ) == 0 ){
  702.                         bgcolor = colors[i].hex;
  703.                         found = 1;
  704.                         break;
  705.                     }
  706.                 }
  707.                 if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list: use hexcolor...something like #a0ffc4");}
  708.             }
  709.             fprintf(js_include_file,"/* set background color of canvas div */\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
  710.             break;
  711.  
  712.         case BGIMAGE:
  713.         /*
  714.          @ bgimage image_location
  715.          @ use an image as background; technical: we use the background of ''canvas_div``
  716.          @ the background image will be resized to match "width = xsize" and "height = ysize"
  717.          @%bgimage%size 400,400%xrange -10,10%yrange -10,10%bgimage https://wims.unice.fr/wims/gifs/en.gif
  718.         */
  719.         URL = get_string(infile,1);
  720.         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);
  721.             break;
  722.  
  723.         case BLINK:
  724.         /*
  725.          @ blink time(seconds)
  726.          @ NOT IMPLEMETED -YET
  727.         */
  728.             break;
  729.  
  730.         case BOXPLOT:
  731.         /*
  732.         @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max
  733.         @ 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
  734.         @ 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
  735.         @ 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
  736.         @ use command <a href='#fillpattern'>fillpattern some_pattern</a> to use a (diamond for Q1, hatch for Q3) pattern.
  737.         @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of stroke and fill colours
  738.         @ 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.
  739.         @ there is no limit to the number of boxplots used.
  740.         @ can <b>not</b> be set draggable and <a href='#onclick'>onclick</a> is not ready yet
  741.         @ 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)
  742.         @ use keyword <a href="#userboxplotdata">userboxplotdata</a> before command boxplot, if a pupil must generate the data by some means.
  743.         @ use command <a href="#boxplotdata">boxplotdata</a> when the boxplot should be drawn from wims-generated raw statistical date
  744.         @%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
  745.         @%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
  746.         @%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
  747.         */
  748.             js_function[DRAW_BOXPLOT] = 1;
  749.             for(i=0;i<8;i++){
  750.                 switch(i){
  751.                     case 0: temp = get_string_argument(infile,0);
  752.                             if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */
  753.                     case 1: double_data[0] = get_real(infile,0);break;/* height | width  */
  754.                     case 2:
  755.                     if( js_function[DRAW_JSBOXPLOT] == 0 ){
  756.                      double_data[1] = get_real(infile,0);
  757.                      fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */
  758.                     }
  759.                     else
  760.                     {
  761.                      double_data[1] = get_real(infile,1);
  762.                      double_data[2] = 1;
  763.                      double_data[3] = 1;
  764.                      double_data[4] = 1;
  765.                      double_data[5] = 1;
  766.                      double_data[6] = 1;
  767.                      double_data[7] = 1;
  768.                      i=8;
  769.                     }
  770.                     break;/* center value x or y */
  771.                     case 3: double_data[2] = get_real(infile,0); break;/* min */
  772.                     case 4: double_data[3] = get_real(infile,0); break;/* Q1 */
  773.                     case 5: double_data[4] = get_real(infile,0); break;/* median */
  774.                     case 6: double_data[5] = get_real(infile,0); break;/* Q3 */
  775.                     case 7: double_data[6] = get_real(infile,1); break;/* max */
  776.                     default:break;
  777.                 }
  778.             }
  779.             decimals = find_number_of_digits(precision);
  780.             /*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)*/
  781.             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]);
  782.             check_string_length(string_length);
  783.             tmp_buffer = my_newmem(string_length);
  784.             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]);
  785.             add_to_buffer(tmp_buffer);
  786.             boxplot_cnt++;
  787.             reset();
  788.         break;
  789.         case BOXPLOTDATA:
  790.         /*
  791.         @ boxplotdata some_data
  792.         @ 'some_data' are a list of numbers separated by a comma "," (items)
  793.         @ only be used before command <code>boxplot</code>: the command <a href="#boxplot">boxplot</a> will provide the boxplot drawing of the data.
  794.         @ 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
  795.         @ note: wims will not check your data input | format. use js-error console to debug any problems.
  796.         @ 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.
  797.         @ 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>
  798.         @%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
  799.         */
  800.             js_function[DRAW_JSBOXPLOT] = 1;
  801.             js_function[DRAW_BOXPLOT] = 1;
  802.             fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1));
  803.  
  804.         break;
  805.  
  806.         case CANVASTYPE:
  807.          canvas_type = (int) (get_real(infile,1));
  808.         /*
  809.         @ canvastype TYPE
  810.         @ for now only useful before commands filltoborder / floodfill / clickfill etc operations<br>Only the images of this TYPE will be scanned and filled
  811.         @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas)
  812.         @ use another TYPE, if you know what you are doing...
  813.         @ 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>
  814.         */
  815.         break;
  816.  
  817.         case CENTERED:
  818.          use_offset = 4;
  819.          /*
  820.          @ centered
  821.          @ keyword ; to place the text centered (in width and height) on the text coordinates(x:y)
  822.          @ may be used for text exactly centered on its (x;y)
  823.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  824.          @ 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``)
  825.          @%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
  826.         */
  827.         break;
  828.  
  829.         case CENTERSTRING:
  830.         /*
  831.          @ centerstring color,y-value,the text string
  832.          @ title color,y-value,the text string
  833.          @ draw a string centered on the canvas at y = y-value
  834.          @ can not be set ''onclick`` or ''drag xy`` (...)
  835.          @ unicode supported: <code>centerstring red,5,\\u2232</code>
  836.          @ use a command like <code>fontfamily italic 24pt Arial</code> to set fonts on browser that support font change
  837.          @%centerstring%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue%fontfamily italic 22pt Courier%centerstring blue,7,the center
  838.         */
  839.             js_function[DRAW_CENTERSTRING] = 1;
  840.             for(i=0;i<3;i++){
  841.                 switch(i){
  842.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  843.                     case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
  844.                     case 2: temp = get_string_argument(infile,1);
  845.                             /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
  846.                             decimals = find_number_of_digits(precision);
  847.                             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);
  848.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  849.                             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);
  850.                             add_to_buffer(tmp_buffer);
  851.                             break;
  852.                     default:break;
  853.                 }
  854.             }
  855.             break;
  856.         case CHEMTEX:
  857.         /*
  858.         chemtex
  859.         keyword...needs to be the first command in the script (even before the ''size`` command)
  860.         only for KaTeX enabled typesetting !
  861.         will include 80kB large js-library for chemisty typesetting
  862.         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>
  863.         using MathJaX : <code>latex x,y,\\ce{ chemistry tex code} like : \\ce{ Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2- }</code>
  864.         see https://mhchem.github.io/MathJax-mhchem/
  865.         %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-}
  866.         */
  867.          found_size_command = 1;
  868.           fprintf(stdout,"\n<script src=\"scripts/js/KaTeX/mhchem.js\" defer></script>\n");
  869.         break;
  870.  
  871.         case CIRCLE:
  872.         /*
  873.         @ circle xc,yc,width (2*r in pixels),color
  874.         @ use command <code>fcircle xc,yc,d,color</code>
  875.         @ alternative: disk
  876.         @ use command <code>fillcolor color</code> to set the fillcolor
  877.         @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a>
  878.         @ will shrink / expand on zoom out / zoom in
  879.         @%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
  880.         */
  881.             for(i=0;i<4;i++){
  882.                 switch(i){
  883.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  884.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  885.                     case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out: radius in 'dx' xrange*/
  886.                     case 3: stroke_color = get_color(infile,1);/* name or hex color */
  887.                         if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  888.                         if(use_affine == TRUE ){ transform(2,2);}
  889.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  890.                         decimals = find_number_of_digits(precision);
  891.                         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);
  892.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  893.                         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);
  894.                         add_to_buffer(tmp_buffer);
  895.                         if(onclick != 0){object_cnt++;}/* object_cnt++;*/
  896.                         dragstuff[13] = 1;
  897.                         if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  898.                         reset();
  899.                         break;
  900.                     default : break;
  901.                 }
  902.             }
  903.             break;
  904.  
  905.         case CIRCLES:
  906.         /*
  907.         @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n
  908.         @ <b>attention</b> r = radius in x-range (!)
  909.         @ use keyword <code>filled</code> or command <code>fcircles</code> to produce solid circles
  910.         @ alternative: disks
  911.         @ use command <code>fillcolor color</code> to set the fillcolor
  912.         @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> (individually)
  913.         @ will shrink / expand on zoom out / zoom in
  914.         @%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
  915.         @%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
  916.         @%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
  917.         */
  918.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  919.             fill_color = stroke_color;
  920.             i=1;
  921.             while( ! done ){     /* get next item until EOL*/
  922.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  923.                 switch (i%3){
  924.                  case 1:double_data[i-1] = get_real(infile,0);break; /* x */
  925.                  case 2:double_data[i-1] = get_real(infile,0);break; /* y */
  926.                  case 0:double_data[i-1] = get_real(infile,1);break; /* r */
  927.                 }
  928.                 i++;
  929.             }
  930.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,3);}
  931.             if(use_affine == TRUE ){ transform(i-1,3);}
  932.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  933.  
  934.             decimals = find_number_of_digits(precision);
  935.             for(c = 0 ; c < i-1 ; c = c+3){
  936.                 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);
  937.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  938.                 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);
  939.                 add_to_buffer(tmp_buffer);
  940.                 if(onclick != 0){object_cnt++;}/* object_cnt++; */
  941.             }
  942.             reset();
  943.             dragstuff[13] = 1;
  944.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  945.             break;
  946.         case CLEARBUTTON:
  947.         /*
  948.          @ clearbutton value
  949.          @ alternative: delete
  950.          @ alternative: erase
  951.          @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text ''value``
  952.          @ <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)
  953.          @ 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
  954.          @ uses the tooltip placeholder div element: may not be used with command <code>intooltip</code>
  955.          @ use command <a href="#css">css</a> to style the button...
  956.          @ 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>
  957.          @%clearbutton%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%userdraw circles,red%clearbutton Remove All
  958.         */
  959.         if(reply_format == 29){/* eg multidraw is selected */
  960.         // canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw");
  961.         }
  962.           add_clear_button(css_class,get_string(infile,1));
  963.         break;
  964.  
  965.         case CLOCK:
  966.         /*
  967.         @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
  968.         @ use command <code>opacity stroke-opacity,fill-opacity</code> to adjust foreground (stroke) and background (fill) transparency
  969.         @ type hourglass:<br>type = 0: only segments<br>type = 1: only numbers<br>type = 2: numbers and segments
  970.         @ 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
  971.         @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
  972.         @ 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>
  973.         @ canvasdraw will not check validity of colornames...the javascript console is your best friend
  974.         @ no combinations with other reply_types allowed, for now
  975.         @ 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
  976.         @ 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
  977.         @ note: clocks will not zoom or pan, when using command <a href='#zoom'>zoom</a>
  978.         @%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
  979.         @%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
  980.         @%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
  981.         @%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
  982.         @%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
  983.         @%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
  984.         @%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
  985.         */
  986.             js_function[DRAW_CLOCK] = 1;
  987.             js_function[INTERACTIVE] = 1;
  988.  
  989.         /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
  990.             for(i=0;i<9;i++){
  991.              switch(i){
  992.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
  993.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
  994.               case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
  995.               case 3: int_data[3] = get_real(infile,0);break;/* hours */
  996.               case 4: int_data[4] = get_real(infile,0);break;/* minutes */
  997.               case 5: int_data[5] = get_real(infile,0);break;/* seconds */
  998.               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 */
  999.               case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/
  1000.                 switch(int_data[7]){
  1001.                     case 0:break;
  1002.                     case 1:if(clock_cnt == 0){
  1003.                            if( reply_format == 0 ){
  1004.                             reply_format = 18; /* user sets clock */
  1005.                             /* 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");
  1006.                                check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1007.                                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");
  1008.                                add_to_buffer(tmp_buffer);
  1009.                            */
  1010.                             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");
  1011.                            }
  1012.                            else
  1013.                            {
  1014.                             canvas_error("interactive clock may not be used together with other reply_types...");
  1015.                            }
  1016.                           }
  1017.                           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);
  1018.                     break;
  1019.                     case 3:if(clock_cnt == 0){
  1020.                             if( reply_format == 0 ){
  1021.                              reply_format = 18; /* user sets clock */
  1022.                              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");
  1023.                             }
  1024.                             else
  1025.                             {
  1026.                              canvas_error("interactive clock may not be used together with other reply_types...");
  1027.                             }
  1028.                            }
  1029.                             /*
  1030.                             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);
  1031.                            */
  1032.                     break;
  1033.                     case 2:if( reply_format == 0 ){
  1034.                                 reply_format = 19; /* "onclick */
  1035.                                 js_function[INTERACTIVE] = 1;
  1036.                                 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");
  1037.                             }
  1038.                             else
  1039.                             {
  1040.                                 if( reply_format != 19){
  1041.                                    canvas_error("clickable clock(s) may not be used together with other reply_types...");
  1042.                                  }
  1043.                             }
  1044.                      break;
  1045.                      default: canvas_error("interactive must be set 0,1 or 2");break;
  1046.                 }
  1047.                 break;
  1048.                 case 8:
  1049.                         if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock(), for now it's OK */
  1050.                             fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
  1051.                         }
  1052.                         temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/
  1053.                         if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
  1054.                         else{
  1055.                         /* h_color,m_color,s_color,bg_color,fg_color */
  1056.                         temp = ",black\",\"black\",\"black\",\"white\",\"black";}
  1057.                         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);
  1058.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1059.                         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);
  1060.                         add_to_buffer(tmp_buffer);
  1061.                         fprintf(js_include_file,"var clocks%d;",clock_cnt);
  1062.                         clock_cnt++;
  1063.                         break;
  1064.                 default:break;
  1065.              }
  1066.             }
  1067.             break;
  1068.  
  1069.  
  1070.         case COLORPALETTE:
  1071.         /*
  1072.          @ colorpalette color_name_1,color_name_2,...,color_name_8
  1073.          @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a>
  1074.          @ 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
  1075.          @ make sure to include the ''remove button`` by using command <a href='#clearbutton'>clearbutton some_text</a>
  1076.         */
  1077.             if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");}
  1078.             fprintf(js_include_file,"var multifillcolors = [];var palettecolors = [");
  1079.             while( ! done ){
  1080.                 temp = get_color(infile,1);
  1081.                 fprintf(js_include_file,"\"%s\",",temp);
  1082.             }
  1083.             fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */
  1084.             add_color_palette(css_class);
  1085.             break;
  1086.  
  1087.         case COMMENT:
  1088.             sync_input(infile);
  1089.             break;
  1090.  
  1091.  
  1092.         case COPY:
  1093.         /*
  1094.         @ copy x,y,x1,y1,x2,y2,[filename URL]
  1095.         @ The image may be "bitmap" or "SVG"
  1096.         @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
  1097.         @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
  1098.         @ [filename] is the URL of the image
  1099.         @ <em>TODO:move special image functions to generic 'dragstuff' library</em>
  1100.         @ URL is normal URL of network reachable image file location
  1101.         @ 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>.
  1102.         @ 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
  1103.         @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves, embeded XML etc)
  1104.         @ you may draw / userdraw / drag other stuff on top of an "imported" image
  1105.         @ 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>
  1106.         @ use keyword <a href='#centered'>centered</a> before command ''copy`` to place image center at given coordinates.
  1107.         @%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
  1108.         @%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
  1109.         @%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
  1110.         */
  1111.             for(i = 0 ; i<7;i++){
  1112.                 switch(i){
  1113.                     case 0: double_data[0]=get_real(infile,0);break; /* x left top corner in x/y range  */
  1114.                     case 1: double_data[1]=get_real(infile,0);break; /* y left top corner in x/y range */
  1115.                     case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
  1116.                     case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
  1117.                     case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
  1118.                     case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
  1119.                     case 6: URL = get_string(infile,1);
  1120.                             if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  1121.                             if(use_affine == TRUE ){transform(2,2);}
  1122.                             int_data[0] = x2px(double_data[0]);
  1123.                             int_data[1] = y2px(double_data[1]);
  1124.                             int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
  1125.                             int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
  1126.                             if( onclick == 0 ){ /* no mouse needed static image copy  */
  1127.                              if(js_function[DRAW_EXTERNAL_IMAGE] == 0){/* create canvas just once */
  1128.                               fprintf(js_include_file,"var image_copy_canvas = create_canvas%d(%d,xsize,ysize);",canvas_root_id,STATIC_IMAGE_CANVAS);
  1129.                               js_function[DRAW_EXTERNAL_IMAGE] = 1;
  1130.                              }
  1131.                              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]);
  1132.                              check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1133.                              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]);
  1134.                             }
  1135.                             else /* onclick or drag & drop external copy images */
  1136.                             {
  1137.                              js_function[DRAG_EXTERNAL_IMAGE] = 1;
  1138.                              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]);
  1139.                              check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1140.                              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]);
  1141.                             }
  1142.                             add_to_buffer(tmp_buffer);
  1143.                             object_cnt++;
  1144.                             break;
  1145.                     default: break;
  1146.                 }
  1147.             }
  1148.             reset();
  1149.             break;
  1150. /*
  1151. HTML5 specs:
  1152. context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  1153. img     Specifies the image, canvas, or video element to use
  1154. sx      The x coordinate where to start clipping: x1 = int_data[0]
  1155. sy      The y coordinate where to start clipping: x2 = int_data[1]
  1156. swidth  The width of the clipped image: int_data[2] - int_data[0]
  1157. sheight The height of the clipped image: int_data[3] - int_data[1]
  1158. x       The x coordinate where to place the image on the canvas: dx1 = int_data[4]
  1159. y       The y coordinate where to place the image on the canvas: dy1 = int_data[5]
  1160. width   The width of the image to use (stretch or reduce the image): dx2 - dx1 = int_data[6]
  1161. height  The height of the image to use (stretch or reduce the image): dy2 - dy1 = int_data[7]
  1162. */
  1163.         case COPYRESIZED:
  1164.         /*
  1165.         @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
  1166.         @ The image may be any "bitmap" or "SVG"
  1167.         @ 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
  1168.         @ (dx1:dy1) must be left top corner; (dx2:dy2) must be right bottom corner of inserted image
  1169.         @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
  1170.         @ 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 !!)
  1171.         @ 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>
  1172.         @ 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
  1173.         @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves etc)
  1174.         @ you may draw / userdraw / drag stuff on top of an "imported" image
  1175.         @ 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``
  1176.         @ use keyword <a href='#centered'>centered</a> before command 'copyresized' to place image center at given coordinates.
  1177.         @ <em>TODO:move special image functions to generic 'dragstuff' library</em>
  1178.         */
  1179.             for(i = 0 ; i<9;i++){
  1180.                 switch(i){
  1181.                     case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
  1182.                     case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
  1183.                     case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
  1184.                     case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
  1185.                     case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
  1186.                     case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
  1187.                     case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
  1188.                     case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
  1189.                     case 8: URL = get_string(infile,1);
  1190.                             if( int_data[1] == -1 ){ int_data[10] = 1; }else{int_data[10] = 0; }/* resized / not resized */
  1191.                             /* flag error when wrong diagonal:  copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */
  1192.                             if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){
  1193.                                 canvas_error("in copyresized,  use:<br>left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! ");
  1194.                             }
  1195.                             int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */
  1196.                             int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */
  1197.                             int_data[6] = abs(int_data[6] - int_data[4]);/* width */
  1198.                             int_data[7] = abs(int_data[7] - int_data[5]);/* height */
  1199.                             if( onclick == 0 ){ /* no mouse needed static image copy  */
  1200.                              if(js_function[DRAW_EXTERNAL_IMAGE] == 0){
  1201.                               fprintf(js_include_file,"var image_copy_canvas = create_canvas%d(%d,xsize,ysize);",canvas_root_id,STATIC_IMAGE_CANVAS);
  1202.                               js_function[DRAW_EXTERNAL_IMAGE] = 1;
  1203.                              }
  1204.                              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]);
  1205.                              check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1206.                              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]);
  1207.                             }
  1208.                             else /* onclick or drag & drop external copy images */
  1209.                             {
  1210.                              js_function[DRAG_EXTERNAL_IMAGE] = 1;
  1211.                              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]);
  1212.                              check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1213.                              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]);
  1214.                              object_cnt++;
  1215.                             }
  1216.                             add_to_buffer(tmp_buffer);
  1217.                             break;
  1218.                     default: break;
  1219.                 }
  1220.             }
  1221.             reset();
  1222.             break;
  1223.  
  1224.         case CROSSHAIR:
  1225.         /*
  1226.         @ crosshair x,y,color
  1227.         @ draw a single crosshair point at (x;y) in color ''color``
  1228.         @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust
  1229.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1230.         @%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
  1231.         */
  1232.             for(i=0;i<3;i++){
  1233.                 switch(i){
  1234.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  1235.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  1236.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  1237.                         if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  1238.                         if(use_affine == TRUE ){ transform(2,2);}
  1239.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1240.                         decimals = find_number_of_digits(precision);
  1241.                         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);
  1242.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1243.                         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);
  1244.                         add_to_buffer(tmp_buffer);
  1245.                         if(onclick != 0){object_cnt++;}
  1246.                         /* object_cnt++ */
  1247.                         reset();
  1248.                         dragstuff[7] = 1;
  1249.                         break;
  1250.                     default:break;
  1251.                 }
  1252.             }
  1253.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1254.             break;
  1255.  
  1256.         case CROSSHAIRS:
  1257.         /*
  1258.         @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
  1259.         @ draw multiple crosshair points at given coordinates in color ''color``
  1260.         @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust
  1261.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  1262.         @%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
  1263.         @%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
  1264. */
  1265.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1266.             fill_color = stroke_color;
  1267.             i=0;
  1268.             while( ! done ){     /* get next item until EOL*/
  1269.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1270.                 if(i%2 == 0 ){
  1271.                     double_data[i] = get_real(infile,0); /* x */
  1272.                 }
  1273.                 else
  1274.                 {
  1275.                     double_data[i] = get_real(infile,1); /* y */
  1276.                 }
  1277.                 i++;
  1278.             }
  1279.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  1280.             if(use_affine == TRUE ){ transform(i-1,2);}
  1281.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1282.             decimals = find_number_of_digits(precision);
  1283.             for(c=0 ; c < i-1 ; c = c+2){
  1284.                 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);
  1285.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1286.                 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);
  1287.                 add_to_buffer(tmp_buffer);
  1288.                 if(onclick != 0){object_cnt++;}/* object_cnt++; */
  1289.             }
  1290.             dragstuff[7] = 1;
  1291.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1292.             reset();
  1293.             break;
  1294.  
  1295.         case CROSSHAIRSIZE:
  1296.         /*
  1297.         @ crosshairsize int
  1298.         @ default 8 (px)
  1299.         */
  1300.             crosshair_size = (int) (get_real(infile,1));
  1301.             break;
  1302.         case CSS:
  1303.         /*
  1304.         @ css css_class
  1305.         @ may be used before any ''style-able`` html object (like inputfields or buttons) or some html objects that are generated by some canvasdraw commands
  1306.         @ in case of <a href="#multidraw">multidraw</a> this command must be a table css class, for example "wimstable"
  1307.         @%css%size 400,400%xrange -10,10%yrange -10,10%css wims_button_help%input 0,0,10,1,Hello
  1308.         */
  1309.             css_class = get_string(infile,1);
  1310.             break;
  1311.  
  1312.         case CURSOR:
  1313.         /*
  1314.         @ cursor some CSS cursor_style
  1315.         @ alternative: pointer
  1316.         @ style can be any valid CSS property value
  1317.         @ 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
  1318.         @ note: wims will not check the validity of your cursor declaration
  1319.         @%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
  1320.         */
  1321.             fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1));
  1322.             break;
  1323.  
  1324.         case CURVE:
  1325.         /*
  1326.          @ curve color,formula(x)
  1327.          @ alternative: plot
  1328.          @ 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...
  1329.          @ use command <a href="#precision">precision</a> to increase the number of digits of the plotted points
  1330.          @ use command <a href="#plotsteps">plotsteps</a> to increase / decrease the amount of plotted points (default 150)
  1331.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1332.          @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">jsplot</a> (command ''curve`` will only calculate points within the xrange)
  1333.          @%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)
  1334.         */
  1335.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1336.  
  1337.             if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
  1338.                 use_parametric = FALSE;
  1339.                 stroke_color = get_color(infile,0);
  1340.                 char *fun1 = get_string_argument(infile,0);
  1341.                 char *fun2 = get_string_argument(infile,1);
  1342.                 if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
  1343.                 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);
  1344.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1345.                 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);
  1346.                 add_to_buffer(tmp_buffer);
  1347.             }
  1348.             else
  1349.             {
  1350.                 stroke_color = get_color(infile,0);
  1351.                 char *fun1 = get_string_argument(infile,1);
  1352.                 if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  1353.                 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);
  1354.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1355.                 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);
  1356.                 add_to_buffer(tmp_buffer);
  1357.             }
  1358.             if(onclick != 0){object_cnt++;}/* object_cnt++; */
  1359.             dragstuff[9] = 1;
  1360.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1361.             reset();
  1362.             break;
  1363.  
  1364.     case CURVEDARROW:
  1365.     /*
  1366.     @ curvedarrow x1,y1,xc,yc,x2,y2,color
  1367.     @ 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)
  1368.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1369.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1370.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1371.     @%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
  1372.     @%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
  1373.  
  1374. h[0] = arrowhead
  1375. h[1] = type: 1 = single 2=double arrow
  1376. 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)
  1377.     */
  1378.         for(i=0;i<7;i++){
  1379.             switch(i){
  1380.                 case 0: double_data[0] = get_real(infile,0);break; /* x1 */
  1381.                 case 1: double_data[1] = get_real(infile,0);break; /* y1 */
  1382.                 case 2: double_data[2] = get_real(infile,0);break; /* xc */
  1383.                 case 3: double_data[3] = get_real(infile,0);break; /* yc */
  1384.                 case 4: double_data[4] = get_real(infile,0);break; /* y3 */
  1385.                 case 5: double_data[5] = get_real(infile,0);break; /* y3 */
  1386.                 case 6: stroke_color = get_color(infile,1);/* name or hex color */
  1387.                 if(use_rotate == TRUE ){rotate(6,angle,rotationcenter,2);}
  1388.                 if(use_affine == TRUE ){ transform(6,2);}
  1389.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1390.                 decimals = find_number_of_digits(precision);
  1391.                 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);
  1392.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1393.                 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);
  1394.                 add_to_buffer(tmp_buffer);
  1395.                 if(onclick != 0){object_cnt++;}/* object_cnt++;*/
  1396.                 reset();
  1397.             break;
  1398.             }
  1399.         }
  1400.         dragstuff[21] = 1;
  1401.         if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1402.         break;
  1403.  
  1404.     case CURVEDARROW2:
  1405.     /*
  1406.     @ curvedarrow2 x1,y1,xc,yc,x2,y2,color
  1407.     @ 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)
  1408.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1409.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1410.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1411.     @%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
  1412.     @%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
  1413.  
  1414. h[0] = arrowhead
  1415. h[1] = type: 1 = single 2=double arrow
  1416. 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)
  1417.     */
  1418.         for(i=0;i<7;i++){
  1419.             switch(i){
  1420.                 case 0: double_data[0] = get_real(infile,0);break; /* x1 */
  1421.                 case 1: double_data[1] = get_real(infile,0);break; /* y1 */
  1422.                 case 2: double_data[2] = get_real(infile,0);break; /* xc */
  1423.                 case 3: double_data[3] = get_real(infile,0);break; /* yc */
  1424.                 case 4: double_data[4] = get_real(infile,0);break; /* y3 */
  1425.                 case 5: double_data[5] = get_real(infile,0);break; /* y3 */
  1426.                 case 6: stroke_color = get_color(infile,1);/* name or hex color */
  1427.                 if(use_rotate == TRUE ){rotate(6,angle,rotationcenter,2);}
  1428.                 if(use_affine == TRUE ){ transform(6,2);}
  1429.                 if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1430.                 decimals = find_number_of_digits(precision);
  1431.                 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);
  1432.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1433.                 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);
  1434.                 add_to_buffer(tmp_buffer);
  1435.                 if(onclick != 0){object_cnt++;}/* object_cnt++;*/
  1436.                 dragstuff[21] = 1;
  1437.                 if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1438.                 reset();
  1439.                 break;
  1440.             }
  1441.         }
  1442.         break;
  1443.     case CURVEDARROWS:
  1444.     /*
  1445.     @ curvedarrows color,x1,y1,xc,yc,x2,y2,...,x_(n-1),y_(n-1),xc,yc,x_n,y_n
  1446.     @ 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)
  1447.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1448.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1449.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1450.     @%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
  1451.     @%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
  1452.  
  1453. h[0] = arrowhead
  1454. h[1] = type: 1 = single 2=double arrow
  1455. 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)
  1456.     */
  1457.         stroke_color = get_color(infile,0);/* name or hex color */
  1458.         i = 0;
  1459.         decimals = find_number_of_digits(precision);
  1460.         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1461.         while( ! done ){
  1462.          if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1463.          double_data[0] = get_real(infile,0); /* x1 */
  1464.          double_data[1] = get_real(infile,0); /* y1 */
  1465.          double_data[2] = get_real(infile,0); /* xc */
  1466.          double_data[3] = get_real(infile,0); /* yc */
  1467.          double_data[4] = get_real(infile,0); /* x3 */
  1468.          double_data[5] = get_real(infile,1); /* y3 */
  1469.          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);
  1470.          check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1471.          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);
  1472.          add_to_buffer(tmp_buffer);
  1473.          if(onclick != 0){object_cnt++;}
  1474.          i = i + 6;
  1475.         }
  1476.         if(use_rotate == TRUE ){rotate(i-6,angle,rotationcenter,2);}
  1477.         if(use_affine == TRUE ){ transform(i-6,2);}
  1478.         dragstuff[21] = 1;
  1479.         if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1480.         reset();
  1481.         break;
  1482.  
  1483.     case CURVEDARROWS2:
  1484.     /*
  1485.     @ curvedarrows2 color,x1,y1,xc,yc,x2,y2,...x_(n-1),y_(n-1),xc,yc,x_n,y_n
  1486.     @ 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)
  1487.     @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
  1488.     @ use command <code>linewidth int</code> to adjust thickness of the arrow
  1489.     @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1490.     @%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
  1491.     @%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
  1492.  
  1493. h[0] = arrowhead
  1494. h[1] = type: 1 = single 2=double arrow
  1495. 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)
  1496.     */
  1497.         stroke_color = get_color(infile,0);/* name or hex color */
  1498.         i = 0;
  1499.         decimals = find_number_of_digits(precision);
  1500.         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1501.         while( ! done ){
  1502.          if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1503.          double_data[0] = get_real(infile,0); /* x1 */
  1504.          double_data[1] = get_real(infile,0); /* y1 */
  1505.          double_data[2] = get_real(infile,0); /* xc */
  1506.          double_data[3] = get_real(infile,0); /* yc */
  1507.          double_data[4] = get_real(infile,0); /* x3 */
  1508.          double_data[5] = get_real(infile,1); /* y3 */
  1509.          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);
  1510.          check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1511.          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);
  1512.          add_to_buffer(tmp_buffer);
  1513.          if(onclick != 0){object_cnt++;}
  1514.          i = i + 6;
  1515.         }
  1516.         if(use_rotate == TRUE ){rotate(i-6,angle,rotationcenter,2);}
  1517.         if(use_affine == TRUE ){ transform(i-6,2);}
  1518.         dragstuff[21] = 1;
  1519.         if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1520.         reset();
  1521.         break;
  1522.  
  1523.         case DASHED:
  1524.         /*
  1525.         @ dashed
  1526.         @ keyword (no arguments required)
  1527.         @ next object will be drawn with a dashed line
  1528.         @ change dashing scheme by using command <a href="#dashtype">dashtype</a>
  1529.         @%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
  1530.         */
  1531.             use_dashed = TRUE;
  1532.             break;
  1533.  
  1534.         case DASHTYPE:
  1535.         /*
  1536.         @ dashtype line_width_px,space_width_px
  1537.         @ every indiviual object may have its own dashtype, if needed...
  1538.         @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype
  1539.         @ default value <code>dashtype 2,2</code> e.g. 2px line and 2px space
  1540.         @ HTML5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable
  1541.         @%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
  1542.         */
  1543.             for(i=0;i<2;i++){
  1544.                 switch(i){
  1545.                     case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
  1546.                     case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
  1547.                 }
  1548.             }
  1549.         break;
  1550.  
  1551.         case DIAMONDFILL:
  1552.         /*
  1553.         @ diamondfill x0,y0,dx,dy,color
  1554.         @ x0,y0 in xrange / yrange
  1555.         @ distances dx,dy in pixels
  1556.         @ there is also a command <a href="#userdraw">userdraw diamondfill,color</a>
  1557.         @%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
  1558.         */
  1559.             js_function[DRAW_DIAMONDFILL] = 1;
  1560.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1561.              js_function[DRAW_FILLTOBORDER] = 1;
  1562.              add_js_filltoborder(canvas_type);
  1563.             }
  1564.             decimals = find_number_of_digits(precision);
  1565.             for(i=0;i<5;i++){
  1566.                 switch(i){
  1567.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  1568.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  1569.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1570.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1571.                     case 4: stroke_color = get_color(infile,1);
  1572.                     if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  1573.                     if(use_affine == TRUE ){ transform(2,2);}
  1574.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  1575.                     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);
  1576.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1577.                     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);
  1578.                     add_to_buffer(tmp_buffer);
  1579.                     fill_cnt++;
  1580.                     reset();
  1581.                     break;
  1582.                     default:break;
  1583.                 }
  1584.             }
  1585.         break;
  1586.  
  1587.         case DOTFILL:
  1588.         /*
  1589.         @ dotfill x0,y0,dx,dy,color
  1590.         @ x0,y0 in xrange / yrange
  1591.         @ distances dx,dy in pixels
  1592.         @ radius of dots is linewidth
  1593.         @ there is also a command <a href="#userdraw">userdraw dotfill,color</a>
  1594.         @%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
  1595.         */
  1596.             js_function[DRAW_DOTFILL] = 1;
  1597.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1598.              js_function[DRAW_FILLTOBORDER] = 1;
  1599.              add_js_filltoborder(canvas_type);
  1600.             }
  1601.             decimals = find_number_of_digits(precision);
  1602.             for(i=0;i<5;i++){
  1603.                 switch(i){
  1604.                     case 0: double_data[0] = get_real(infile,0); break; /* x in px */
  1605.                     case 1: double_data[1] = get_real(infile,0); break; /* y in py */
  1606.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  1607.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1608.                     case 4: stroke_color = get_color(infile,1);
  1609.                     if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  1610.                     if(use_affine == TRUE ){ transform(2,2);}
  1611.                     /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
  1612.                     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);
  1613.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1614.                     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);
  1615.                     add_to_buffer(tmp_buffer);
  1616.                     fill_cnt++;
  1617.                     reset();
  1618.                     break;
  1619.                     default:break;
  1620.                 }
  1621.             }
  1622.         break;
  1623.  
  1624.         case DRAG:
  1625.         /*
  1626.          @ drag [x][y][xy]
  1627.          @ the next object will be draggable in x / y / xy direction
  1628.          @ the displacement can be read by <code>javascript:read_dragdrop();</code>
  1629.          @ 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' !
  1630.          @ <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 )
  1631.          @ ''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)
  1632.          @ <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
  1633.          @ 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)
  1634.          @ 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
  1635.          @ 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.
  1636.          @%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
  1637.          @%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
  1638.          @%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
  1639.         */
  1640.             temp = get_string(infile,1);
  1641.             if(strstr(temp,"xy") != NULL ){
  1642.                 drag_type = 0;
  1643.             }
  1644.             else
  1645.             {
  1646.                 if(strstr(temp,"x") != NULL ){
  1647.                     drag_type = 1;
  1648.                 }
  1649.                 else
  1650.                 {
  1651.                     drag_type = 2;
  1652.                 }
  1653.             }
  1654.             /* assuming all drag&drop coordinates the same precision: so set only once */
  1655.             if( print_drag_params_only_once == FALSE ){
  1656.              fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;",precision);
  1657.              print_drag_params_only_once = TRUE;
  1658.             }
  1659.             onclick = 2;
  1660.             /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
  1661.             use_dragstuff = 2;
  1662.             js_function[INTERACTIVE] = 1;
  1663.             break;
  1664.  
  1665.         case ELLIPSE:
  1666.         /*
  1667.         @ ellipse xc,yc,width_x,height_y,color
  1668.         @ ellipses with center xc/yc and width/height in x/y-range etc (this differs from flydraw syntax!)
  1669.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1670.         @ will shrink / expand on zoom out / zoom in
  1671.         @%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
  1672.         */
  1673.             for(i=0;i<5;i++){
  1674.                 switch(i){
  1675.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  1676.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  1677.                     case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */
  1678.                     case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */
  1679.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  1680.                         if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,4);}
  1681.                         if(use_affine == TRUE ){ transform(2,4);}
  1682.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1683.                         decimals = find_number_of_digits(precision);
  1684.                         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);
  1685.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1686.                         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);
  1687.                         add_to_buffer(tmp_buffer);
  1688.                         if(onclick != 0){object_cnt++;}/* object_cnt++; */
  1689.                         dragstuff[3] = 1;
  1690.                         if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1691.                         reset();
  1692.                     break;
  1693.                 }
  1694.             }
  1695.             break;
  1696.  
  1697.         case ELLIPSES:
  1698.         /*
  1699.         @ ellipses color,xc1,yc1,width_x1,height_y1,xc2,yc2,width_x2,height_y2,xc3,yc3,width_x3,height_y3,...
  1700.         @ ellipses with center and height in x/y-range etc (this differs from flydraw syntax!)
  1701.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  1702.         @ will shrink / expand on zoom out / zoom in
  1703.         @%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
  1704.         */
  1705.  
  1706.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  1707.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1708.             fill_color = stroke_color;
  1709.             i=1;
  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.                 switch (i%4){
  1713.                  case 1:double_data[i-1] = get_real(infile,0);break; /* x */
  1714.                  case 2:double_data[i-1] = get_real(infile,0);break; /* y */
  1715.                  case 3:double_data[i-1] = get_real(infile,0);break; /* rx */
  1716.                  case 0:double_data[i-1] = get_real(infile,1);break; /* ry */
  1717.                  default: break;
  1718.                 }
  1719.                 i++;
  1720.             }
  1721.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,4);}
  1722.             if(use_affine == TRUE ){ transform(i-1,4);}
  1723.             decimals = find_number_of_digits(precision);
  1724.             for(c = 0 ; c < i-1 ; c = c+4){
  1725.              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);
  1726.              check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1727.              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);
  1728.              add_to_buffer(tmp_buffer);
  1729.              if(onclick != 0){object_cnt++;} /* object_cnt++; */
  1730.             }
  1731.             reset();
  1732.             dragstuff[3] = 1;
  1733.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  1734.             break;
  1735.  
  1736.         case FILLALL:
  1737.         /*
  1738.         @ fillall color,x1,y1,x2,y2...x_n,y_n
  1739.         @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color'
  1740.         @ any other colors (objects) in the <a href="#canvastype">canvastype</a> will act as border to the bucket fill
  1741.         @ use this command after all boundary objects are declared.
  1742.         @ Use command 'userdraw clickfill,color' for user click driven flood fill.
  1743.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1744.         @ 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..
  1745.         @%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
  1746.         */
  1747.             decimals = find_number_of_digits(precision);
  1748.             fill_color=get_color(infile,0); /* how nice: now the color comes first...*/
  1749.             i=0;
  1750.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1751.              js_function[DRAW_FILLTOBORDER] = 1;
  1752.              add_js_filltoborder(canvas_type);
  1753.             }
  1754.             while( ! done ){     /* get next item until EOL*/
  1755.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  1756.                 if(i%2 == 0 ){
  1757.                     double_data[i] = get_real(infile,0); /* x */
  1758.                 }
  1759.                 else
  1760.                 {
  1761.                     double_data[i] = get_real(infile,1); /* y */
  1762.                     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);
  1763.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1764.                     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);
  1765.                     add_to_buffer(tmp_buffer);
  1766.                     fill_cnt++;
  1767.                 }
  1768.                 i++;
  1769.             }
  1770.         break;
  1771.  
  1772.         case FILLED:
  1773.         /*
  1774.         @ filled
  1775.         @ keyword (no arguments required)
  1776.         @ the next ''fillable`` object (only the next !) will be filled
  1777.         @ use command <a href="#fillcolor">fillcolor color</a> to set fillcolor
  1778.         @ use <a href="#fillpattern">fillpattern</a> for non-solid color filling.
  1779.         @ use command <code>opacity 0-255,0-255</code> to set stroke and fill-opacity
  1780.         @ 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 !
  1781.         */
  1782.             use_filled = 1;
  1783.             break;
  1784.  
  1785.         case FILLCOLOR:
  1786.         /*
  1787.         @ fillcolor colorname or #hex
  1788.         @ set the color: mainly used for command 'userdraw obj,stroke_color'
  1789.         @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...)
  1790.         @ see <a href="#fillpattern">fillpattern</a> for non-solid color filling.
  1791.         */
  1792.             fill_color = get_color(infile,1);
  1793.             break;
  1794.  
  1795.         case FILLPATTERN:
  1796.         /*
  1797.         @ fillpattern grid | hatch | diamond | dot | image_url
  1798.         @ alternative: settile image_url
  1799.         @ use a pattern as fillstyle
  1800.         @ suitable for all fillable object including the <a href="#userdraw">userdraw objects' family</a>
  1801.         @ note: do not use the ''f`` for a fillable object : this is used exclusively for solid colour filling.
  1802.         @ 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>
  1803.         @ the pattern dimensions are hardcoded (linewidth, radius,dx,dy are fixed)
  1804.         @ the pattern color is set by command <a href='#fillcolor'>fillcolor</a> and <a href='#opacity'>opacity</a>
  1805.         @ see <a href="#fillcolor">fillcolor</a> for solid color filling.
  1806.         @ 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>
  1807.         @ 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
  1808.         @%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
  1809.         @%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
  1810.         */
  1811.             temp = get_string(infile,1);
  1812.             use_filled = 0;
  1813.             js_function[DRAW_FILL_PATTERN] = 1;
  1814.             if( strstr(temp,"grid") != 0 ){ use_filled = 2;}
  1815.              else{
  1816.              if( strstr(temp,"hatch") != 0 ){ use_filled = 3;}
  1817.               else{
  1818.               if( strstr(temp,"diamond") != 0 ){ use_filled = 4;}
  1819.                else{
  1820.                if( strstr(temp,"dot") != 0 ){ use_filled = 5;}
  1821.                 else{
  1822.                 if( strstr(temp,"/") != 0 ){ /* get_image_from_url() needs to be called after function definition...*/
  1823.                  use_filled = 6;js_function[JS_LOAD_IMAGE] = 1;
  1824.                  string_length = 1 + snprintf(NULL,0,"get_image_from_url(\"%s\");",temp);
  1825.                  check_string_length(string_length);
  1826.                  tmp_buffer = my_newmem(string_length);
  1827.                  snprintf(tmp_buffer,string_length,"get_image_from_url(\"%s\");",temp);
  1828.                  add_to_buffer(tmp_buffer);
  1829.                 }
  1830.                }
  1831.               }
  1832.              }
  1833.             }
  1834.             if( use_filled == 0 ){canvas_error("fillpattern unknown or typo...choose grid,hatch,diamond of dot...");}
  1835.             break;
  1836.         case FILLTOBORDER:
  1837.         /*
  1838.         @ filltoborder x,y,bordercolor,color
  1839.         @ fill the region of point (x:y) with color 'color'
  1840.         @ any other color will not act as border to the bucket fill
  1841.         @ use this command after all boundary objects are declared.
  1842.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1843.         @ 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..
  1844.         @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a>
  1845.         @%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
  1846.         */
  1847.             for(i=0 ;i < 4 ; i++){
  1848.                 switch(i){
  1849.                     case 0:double_data[0] = get_real(infile,0);break;
  1850.                     case 1:double_data[1] = get_real(infile,0);break;
  1851.                     case 2:bgcolor = get_color(infile,0);break;
  1852.                     case 3:fill_color = get_color(infile,1);
  1853.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1854.                             js_function[DRAW_FILLTOBORDER] = 1;
  1855.                             add_js_filltoborder(canvas_type);
  1856.                            }
  1857.                            decimals = find_number_of_digits(precision);
  1858.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  1859.                            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);
  1860.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1861.                            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);
  1862.                            add_to_buffer(tmp_buffer);
  1863.                            fill_cnt++;
  1864.                            reset();
  1865.                            break;
  1866.                     default:break;
  1867.                 }
  1868.             }
  1869.         break;
  1870.         case FLOODFILL:
  1871.         /*
  1872.         @ floodfill x,y,color
  1873.         @ alternative: fill
  1874.         @ fill the region of point (x:y) with color 'color'
  1875.         @ any other color or size of picture (borders of picture) will act as border to the bucket fill
  1876.         @ use this command after all boundary objects are declared.
  1877.         @ Use command <code>userdraw clickfill,color</code> for user click driven flood fill.
  1878.         @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
  1879.         @ 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..
  1880.         @%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
  1881.         */
  1882.             for(i=0 ;i < 4 ; i++){
  1883.                 switch(i){
  1884.                     case 0:double_data[0] = get_real(infile,0);break;
  1885.                     case 1:double_data[1] = get_real(infile,0);break;
  1886.                     case 2:fill_color = get_color(infile,1);
  1887.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1888.                             js_function[DRAW_FILLTOBORDER] = 1;
  1889.                             add_js_filltoborder(canvas_type);
  1890.                            }
  1891.                            decimals = find_number_of_digits(precision);
  1892.                            /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
  1893.                            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);
  1894.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1895.                            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);
  1896.                            add_to_buffer(tmp_buffer);
  1897.                            fill_cnt++;
  1898.                            break;
  1899.                     default:break;
  1900.                 }
  1901.             }
  1902.             reset();
  1903.         break;
  1904.  
  1905.         case FONTCOLOR:
  1906.         /*
  1907.          @ fontcolor color
  1908.          @ color: hexcolor or colorname
  1909.          @ default: black
  1910.          @ use command <a href="#fontfamily">fontfamily</a> to deviate from default font type
  1911.          @%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
  1912.         */
  1913.             font_color = get_color(infile,1);
  1914.             break;
  1915.  
  1916.         case FONTFAMILY:
  1917.         /*
  1918.          @ fontfamily font_description
  1919.          @ set the font family; for browsers that support it
  1920.          @ font_description: Arial, Courier, Helvetica etc
  1921.          @ 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``
  1922.          @%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
  1923.  
  1924.         */
  1925.             font_family = get_string(infile,1);
  1926.             break;
  1927.  
  1928.         case FONTSIZE:
  1929.         /*
  1930.          @ fontsize font_size
  1931.          @ default value 12
  1932.          @ 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
  1933.         */
  1934.             font_size = (int) (get_real(infile,1));
  1935.             break;
  1936.  
  1937.         case FUNCTION_LABEL:
  1938.         /*
  1939.          @ functionlabel label_1:label_2:label_3...
  1940.          @ alternative: functionlabels
  1941.          @ default value ''f(x)=:g(x)=:h(x)=:i(x)=:j(x)=:k(x)=:m(x)=:n(x)=``
  1942.          @ no mathml allowed (just ascii string)
  1943.          @ use command <a href='#fontsize'>fontsize int</a> to adjust the size
  1944.          @ use command <a href='#strokecolor'>strokecolor colorname</a> to adjust the labels (individually, if needed)
  1945.          @ if needed, use before every command <a href='#userinput'>userinput function | inputfield | textarea</a>
  1946.          @ no limit in amount of inputfields for userbased function plotting
  1947.          @%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
  1948.         */
  1949.             temp = get_string_argument(infile,1);
  1950.             function_label = list2js_array(temp,":");
  1951.  
  1952.             break;
  1953.  
  1954.         case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px), axis/tickscolor]*/
  1955.         /*
  1956.          @ grid step_x,step_y,gridcolor
  1957.          @ 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
  1958.          @ 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
  1959.          @ 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)
  1960.          @ can <b>not</b> be set <a href="#onclick">onclick</a> or <a href="#drag">drag xy</a>
  1961.          @ 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' !
  1962.          @ 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')
  1963.          @ 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')
  1964.          @%grid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%zoom red
  1965.          @%grid_axis%size 400,400%xrange -10,10%yrange -10,10%axis%grid 1,1,grey,2,2,6,black%zoom red
  1966.          @%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
  1967.         */
  1968.             if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
  1969.             js_function[DRAW_GRID] = 1;
  1970.             for(i=0;i<4;i++){
  1971.                 switch(i){
  1972.                     case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
  1973.                     case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
  1974.                     case 2:
  1975.                     if( use_axis == TRUE ){
  1976.                         stroke_color = get_color(infile,0);
  1977.                         done = FALSE;
  1978.                         int_data[0] = (int) (get_real(infile,0));/* xminor */
  1979.                         int_data[1] = (int) (get_real(infile,0));/* yminor */
  1980.                         int_data[2] = (int) (get_real(infile,0));/* tic_length */
  1981.                         fill_color = get_color(infile,1); /* used as axis_color*/
  1982.                     }
  1983.                     else
  1984.                     {
  1985.                         int_data[0] = 1;
  1986.                         int_data[1] = 1;
  1987.                         stroke_color = get_color(infile,1);
  1988.                         fill_color = stroke_color;
  1989.                     }
  1990.                     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 !");}
  1991.                     /* set snap_x snap_y values in pixels */
  1992.                     fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
  1993.                     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);
  1994.                     string_length = 1 + snprintf(NULL,0,  "redraw_grid();\n");
  1995.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  1996.                     snprintf(tmp_buffer,string_length,    "redraw_grid();\n");
  1997.                     add_to_buffer(tmp_buffer);
  1998.                     break;
  1999.                 }
  2000.             }
  2001.             reset();
  2002.             break;
  2003.         case GRIDFILL:
  2004.         /*
  2005.         @ gridfill x0,y0,dx,dy,color
  2006.         @ x0,y0 in xrange / yrange
  2007.         @ distances dx,dy in pixels
  2008.         @ there is also a command <a href="#userdraw">userdraw gridfill,color</a>
  2009.         @%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
  2010.  
  2011.         */
  2012.             js_function[DRAW_GRIDFILL] = 1;
  2013.             decimals = find_number_of_digits(precision);
  2014.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2015.              js_function[DRAW_FILLTOBORDER] = 1;
  2016.              add_js_filltoborder(canvas_type);
  2017.             }
  2018.             for(i=0;i<5;i++){
  2019.                 switch(i){
  2020.                     case 0: double_data[0] = get_real(infile,0); break; /* x  */
  2021.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  2022.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  2023.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2024.                     case 4: stroke_color = get_color(infile,1);
  2025.                     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);
  2026.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2027.                     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);
  2028.                     add_to_buffer(tmp_buffer);
  2029.                     fill_cnt++;
  2030.                     reset();
  2031.                     break;
  2032.                     default:break;
  2033.                 }
  2034.             }
  2035.         break;
  2036.  
  2037.         case GROUP:
  2038.         /*
  2039.          @ group
  2040.          @ keyword
  2041.          @ work in 'progress'
  2042.          @ 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)
  2043.          @ may be combined with slider driven movements or drag & drop
  2044.          @%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
  2045.         */
  2046.             use_slider++;
  2047.             add_slider(2);
  2048.             no_reset = TRUE;
  2049.             int c = 0;
  2050.             for(i=last_slider;i<=use_slider;i++){ int_data[c] = i; c++; }
  2051.             my_sliders = data2js_array(int_data,use_slider - last_slider+1);
  2052.             if( precision == 0 ){precision = 100;}
  2053.             onclick = 5;
  2054.             use_dragstuff = 2;
  2055.             drag_type = 0;
  2056.             js_function[INTERACTIVE] = 1;
  2057.             fprintf(js_include_file,"var slider%d;dragdrop_precision = %d;use_dragdrop_reply = true;",use_slider,precision);
  2058.             string_length = 1 + snprintf(NULL,0,"slider%d = new move_group(%d);\n",use_slider,use_slider);
  2059.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2060.             snprintf(tmp_buffer,string_length,"slider%d = new move_group(%d);\n",use_slider,use_slider);
  2061.             add_to_buffer(tmp_buffer);
  2062.         break;
  2063.  
  2064.         case HALFLINE:
  2065.         /*
  2066.         @ demiline x1,y1,x2,y2,color
  2067.         @ alternative: halfline
  2068.         @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex)
  2069.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2070.         @%halfline%size 400,400%xrange -10,10%yrange -10,10%halfline -5,5,0,0,red%halfline -5,-5,0,0,blue
  2071.         */
  2072.         for(i=0; i<13;i++){double_data[i]=0;}
  2073.  
  2074.             for(i=0;i<5;i++){
  2075.                 switch(i){
  2076.                     case 0: double_data[0]= get_real(infile,0);break; /* x-values */
  2077.                     case 1: double_data[1]= get_real(infile,0);break; /* y-values */
  2078.                     case 2: double_data[10]= get_real(infile,0);break; /* x-values */
  2079.                     case 3: double_data[11]= get_real(infile,0);break; /* y-values */
  2080.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  2081.                     if(double_data[0] == double_data[10]){ /* vertical halfline */
  2082.                         if(double_data[1] < double_data[11]){
  2083.                          double_data[3] = ymax + 1000;
  2084.                         }
  2085.                         else
  2086.                         {
  2087.                          double_data[3] = ymin - 1000;
  2088.                         }
  2089.                         double_data[2] = double_data[0];
  2090.                     }
  2091.                     else
  2092.                     { /* horizontal halfline*/
  2093.                      if( double_data[1] == double_data[11] ){
  2094.                       if( double_data[0] < double_data[10] ){
  2095.                         double_data[2] = xmax + 1000; /* halfline to the right */
  2096.                       }
  2097.                       else
  2098.                       {
  2099.                         double_data[2] = xmin - 1000; /* halfline to the left */
  2100.                       }
  2101.                       double_data[3] = double_data[1];
  2102.                      }
  2103.                      else
  2104.                      {
  2105.                       /* any other halfline */
  2106.                       /* slope */
  2107.                       double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
  2108.                       /* const */
  2109.                       double_data[13] = double_data[1] - double_data[12]*double_data[0];
  2110.                       if( double_data[0] < double_data[10] ){
  2111.                        double_data[2] = double_data[2] + 1000;
  2112.                       }
  2113.                       else
  2114.                       {
  2115.                        double_data[2] = double_data[2] - 1000;
  2116.                       }
  2117.                       double_data[3] = double_data[12]*double_data[2] + double_data[13];
  2118.                      }
  2119.                     }
  2120.                     if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2121.                     if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);}
  2122.                     if(use_affine == TRUE ){ transform(4,2);}
  2123.                     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);
  2124.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2125.                     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);
  2126.                     add_to_buffer(tmp_buffer);
  2127.                     if(onclick != 0){object_cnt++;}
  2128.                     /* object_cnt++; */
  2129.                     reset();
  2130.                     break;
  2131.                 }
  2132.             }
  2133.             dragstuff[18] = 1;
  2134.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2135.             break;
  2136.  
  2137.         case HALFLINES:
  2138.         /*
  2139.         @ demilines color,x1,y1,x2,y2,....
  2140.         @ alternative: halflines
  2141.         @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc
  2142.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually
  2143.         @%halflines%size 400,400%xrange -10,10%yrange -10,10%halflines red,-5,5,0,0,-5,-5,0,0
  2144.         */
  2145.             stroke_color=get_color(infile,0);
  2146.             fill_color = stroke_color;
  2147.             i=0;
  2148.             while( ! done ){     /* get next item until EOL*/
  2149.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2150.                 if(i%2 == 0 ){
  2151.                     double_data[i] = get_real(infile,0); /* x */
  2152.                 }
  2153.                 else
  2154.                 {
  2155.                     double_data[i] = get_real(infile,1); /* y */
  2156.                 }
  2157.                 i++;
  2158.             }
  2159.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2160.             decimals = find_number_of_digits(precision);
  2161.             for(c = 0 ; c < i-1 ; c = c+4){
  2162.                 if( double_data[c] == double_data[c+2] ){ /* vertical line*/
  2163.                     if(double_data[c+1] < double_data[c+3]){ /* upright halfline */
  2164.                         double_data[c+3] = ymax + 1000;
  2165.                     }
  2166.                     else
  2167.                     {
  2168.                      double_data[c+3] = ymin - 1000;/* descending halfline */
  2169.                     }
  2170.                 }
  2171.                 else
  2172.                 {
  2173.                     if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  2174.                         if(double_data[c] < double_data[c+2] ){ /* halfline to the right */
  2175.                             double_data[c+2] = xmax+100;
  2176.                         }
  2177.                         else
  2178.                         {
  2179.                             double_data[c+2] = xmin-1000; /* halfline to the right */
  2180.                         }
  2181.                     }
  2182.                     else
  2183.                     {
  2184.                         /* m */
  2185.                         double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  2186.                         /* q */
  2187.                         double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  2188.                         if(double_data[c] < double_data[c+2]){ /* to the right */
  2189.                             double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it is just segment */
  2190.                             double_data[c+3] = (m)*(double_data[c+2])+(q);
  2191.                         }
  2192.                         else
  2193.                         { /* to the left */
  2194.                             double_data[c+2] = xmin - 1000;
  2195.                             double_data[c+3] = (m)*(double_data[c+2])+(q);
  2196.                         }
  2197.                     }
  2198.                 }
  2199.                 if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  2200.                 if(use_affine == TRUE ){ transform(i-1,2);}
  2201.                 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);
  2202.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2203.                 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);
  2204.                 add_to_buffer(tmp_buffer);
  2205.                 if(onclick != 0){object_cnt++;}/* object_cnt++; */
  2206.             }
  2207.             reset();
  2208.             dragstuff[18] = 1;
  2209.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2210.             break;
  2211.         case HATCHFILL:
  2212.         /*
  2213.         @ hatchfill x0,y0,dx,dy,color
  2214.         @ x0,y0 in xrange / yrange
  2215.         @ distances dx,dy in pixels
  2216.         @ there is also a command <a href="#userdraw">userdraw hatchfill,color</a>
  2217.         @%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
  2218.         */
  2219.             js_function[DRAW_HATCHFILL] = 1;
  2220.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2221.              js_function[DRAW_FILLTOBORDER] = 1;
  2222.              add_js_filltoborder(canvas_type);
  2223.             }
  2224.             decimals = find_number_of_digits(precision);
  2225.             for(i=0;i<5;i++){
  2226.                 switch(i){
  2227.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  2228.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  2229.                     case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
  2230.                     case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
  2231.                     case 4: stroke_color = get_color(infile,1);
  2232.                     if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  2233.                     if(use_affine == TRUE ){ transform(2,2);}
  2234.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  2235.                     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);
  2236.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2237.                     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);
  2238.                     add_to_buffer(tmp_buffer);
  2239.                     fill_cnt++;
  2240.                     reset();
  2241.                     break;
  2242.                     default:break;
  2243.                 }
  2244.             }
  2245.         break;
  2246.  
  2247.         case HLINE:
  2248.         /*
  2249.         @ hline x,y,color
  2250.         @ alternative: horizontalline
  2251.         @ draw a horizontal line through point (x:y) in color 'color'
  2252.         @ 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)
  2253.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2254.         @%hline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hline 0,0,red%dhline 0,5,blue
  2255.         */
  2256.             for(i=0;i<3;i++) {
  2257.                 switch(i){
  2258.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  2259.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  2260.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  2261.                     double_data[3] = double_data[1];
  2262.                     if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  2263.                     if(use_affine == TRUE ){ transform(2,2);}
  2264.                     if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2265.                     decimals = find_number_of_digits(precision);
  2266.                     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);
  2267.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2268.                     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);
  2269.                     add_to_buffer(tmp_buffer);
  2270.                     if(onclick != 0){object_cnt++;}/* object_cnt++; */
  2271.                     dragstuff[4] = 1;
  2272.                     if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2273.                     reset();
  2274.                     break;
  2275.                 }
  2276.             }
  2277.             break;
  2278.  
  2279.         case HLINES:
  2280.         /*
  2281.         @ hlines color,x1,y1,x2,y2,...
  2282.         @ alternative: horizontallines
  2283.         @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color'
  2284.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  2285.         @%hlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hlines red,0,0,0,5,0,-5
  2286.         */
  2287.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  2288.             fill_color = stroke_color;
  2289.             i=0;
  2290.             while( ! done ){     /* get next item until EOL*/
  2291.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2292.                 if(i%2 == 0 ){
  2293.                     double_data[i] = get_real(infile,0); /* x */
  2294.                 }
  2295.                 else
  2296.                 {
  2297.                     double_data[i] = get_real(infile,1); /* y */
  2298.                 }
  2299.                 i++;
  2300.             }
  2301.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  2302.             if(use_affine == TRUE ){ transform(i-1,2);}
  2303.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2304.  
  2305.             decimals = find_number_of_digits(precision);
  2306.             for(c = 0 ; c < i-1 ; c = c+2){
  2307.                 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);
  2308.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2309.                 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);
  2310.                 add_to_buffer(tmp_buffer);
  2311.                 if(onclick != 0){object_cnt++;}/* object_cnt++; */
  2312.             }
  2313.             reset();
  2314.             dragstuff[4] = 1;
  2315.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2316.             break;
  2317.         case HTTP:
  2318.         /*
  2319.          @ http x1,y1,x2,y2,http://some_adress.com
  2320.          @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1), right bottom (x2:y2)
  2321.          @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe
  2322.          @ can <b>not</b> be ''set onclick`` or ''drag xy``
  2323.          @%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
  2324.         */
  2325.             js_function[DRAW_HTTP] = 1;
  2326.             for(i=0;i<5;i++){
  2327.                 switch(i){
  2328.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  2329.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  2330.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  2331.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  2332.                     case 4: decimals = find_number_of_digits(precision);
  2333.                             temp = get_string(infile,1);
  2334.                             if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
  2335.                             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);
  2336.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+2);
  2337.                             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);
  2338.                             add_to_buffer(tmp_buffer);
  2339.                     break;
  2340.                 }
  2341.             }
  2342.             reset();
  2343.             break;
  2344.         case HTML:
  2345.         /*
  2346.          @ html x1,y1,html_string
  2347.          @ all tags are allowed, html code using inputfields could be read using your own javascript code. Do not use ids like 'canvas_input0' etc.
  2348.          @ can be set <a href='#onclick'>onclick</a>  and <a href='#drag'>drag&amp;drop</a>
  2349.          @ command <a href='#affine'>affine</a> will produce CSS3 matrix transformations
  2350.          @ command <a href='#rotate'>rotate</a> will rotate the object
  2351.          @ use keyword <a href='#centered'>centered</a> to center the html object on (x1:y1)
  2352.          @ 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)``
  2353.          @ note: sub &amp; sup are supported in command family <a href='#string'>string</a>, e.g. real internal canvas objects !
  2354.          @%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
  2355.          @%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">
  2356.         */
  2357.             js_function[DRAW_XML] = 1;
  2358.             for(i=0;i<5;i++){
  2359.                 switch(i){
  2360.                     case 0: double_data[0] = get_real(infile,0);break;
  2361.                     case 1: double_data[1] = get_real(infile,0);break;
  2362.                     case 4: decimals = find_number_of_digits(precision);
  2363.                             if(use_affine == TRUE ){ transform(2,2);}/* needs double_data[] */
  2364.                             if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */
  2365.                             int_data[0] = x2px(double_data[0]);/* needs px */
  2366.                             int_data[1] = y2px(double_data[1]);
  2367.                             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2368.                             if( use_slider != -1 && drag_type != -1){ onclick = 5; }
  2369.                             temp = get_string(infile,1);
  2370.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","\\\""); }
  2371.                             if( strstr(temp,"<img ")!= 0){URL="image";}else{URL="html";}
  2372.                             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);
  2373.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2374.                             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);
  2375.                             add_to_buffer(tmp_buffer);
  2376.                             if(onclick != 0 ){object_cnt++;}
  2377.                             drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */
  2378.                             break;
  2379.                     default:break;
  2380.                 }
  2381.             }
  2382.             reset();
  2383.             break;
  2384.  
  2385.         case IMAGEFILL:
  2386.         /*
  2387.         @ imagefill x,y,scaling to xsize &times; ysize?,image_url
  2388.         @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
  2389.         @ scaling to xsize &times; ysize ? ... 1 = yes 0 = no
  2390.         @ After pattern filling, the fill-color should be reset !
  2391.         @ wims getins / image from class directory: imagefill 80,80,my_image.gif
  2392.         @ normal url: imagefill 80,80,0,&#36;module_dir/gifs/my_image.gif
  2393.         @ normal url: imagefill 80,80,1,http://adres/a/b/c/my_image.jpg
  2394.         @ if dx,dy is larger than the image, the whole image will be background to the next object.
  2395.         @%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
  2396.         @%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
  2397.         */
  2398.             js_function[DRAW_IMAGEFILL] = 1;
  2399.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  2400.              js_function[DRAW_FILLTOBORDER] = 1;
  2401.              add_js_filltoborder(canvas_type);
  2402.             }
  2403.             for(i=0 ;i < 4 ; i++){
  2404.                 switch(i){
  2405.                     case 0:int_data[0] = (int) (get_real(infile,0));break;
  2406.                     case 1:int_data[1] = (int) (get_real(infile,0));break;
  2407.                     case 2:int_data[2] = (int) (get_real(infile,0));break; /* 0 | 1 */
  2408.                     case 3: URL = get_string_argument(infile,1);
  2409.                             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]);
  2410.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2411.                             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]);
  2412.                             add_to_buffer(tmp_buffer);
  2413.                             fill_cnt++;
  2414.                     break;
  2415.                 }
  2416.             }
  2417.             reset();
  2418.         break;
  2419.  
  2420.         case IMAGEPALETTE:
  2421.         /*
  2422.          @ imagepalette image1,image2,image3,...
  2423.          @ 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``.
  2424.          @%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
  2425.          */
  2426.            temp = get_string(infile,1);
  2427.            temp = str_replace(temp,",","\",\"");
  2428.             if( use_tooltip == 1 ){canvas_error("command 'imagepalette' is incompatible with command 'intooltip tip_text',as they use the same div-element ");}
  2429.             fprintf(js_include_file,"\nvar current_id;var imagepalette = [\" %s \"];\n",temp);
  2430.         break;
  2431.  
  2432.         case INPUT:
  2433.         /*
  2434.          @ input x,y,size,editable,value
  2435.          @ to set inputfield "readonly", use editable = 0
  2436.          @ if no preset 'value' is needed...use a 'space' as last item argument
  2437.          @ only active inputfields (editable = 1) will be read with read_canvas();
  2438.          @ 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>
  2439.          @ may be further controlled by <a href="#css">css</a>
  2440.          @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
  2441.          @ 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)
  2442.          @ 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>
  2443.          @%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, ?
  2444.         */
  2445.         js_function[DRAW_INPUTS] = 1;
  2446.             for(i = 0 ; i<5;i++){
  2447.                 switch(i){
  2448.                     case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
  2449.                     case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
  2450.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
  2451.                     case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
  2452.                     case 4: temp = get_string(infile,3);
  2453.                             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);
  2454.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2455.                             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);
  2456.                             add_to_buffer(tmp_buffer);
  2457.                             input_cnt++;break;
  2458.                     default: break;
  2459.                 }
  2460.             }
  2461.             if(reply_format == 0 ){reply_format = 15;}
  2462.             reset();
  2463.             break;
  2464.  
  2465.         case INTOOLTIP:
  2466.             /*
  2467.             @ intooltip link_text
  2468.             @ link_text is a single line (span-element)
  2469.             @ link_text may also be an image URL ''http://some_server/images/my_image.png`` or ''&#36;module_dir/gifs/my_image.jpg``
  2470.             @ link_text may contain HTML markup
  2471.             @ the canvas will be displayed in a tooltip on ''link_text``
  2472.             @ 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'.
  2473.             @ 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...
  2474.             @%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>
  2475.             */
  2476.             if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");}
  2477.             if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");}
  2478.             tooltip_text = get_string(infile,1);
  2479.             if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
  2480.             use_tooltip = 1;
  2481.             break;
  2482.  
  2483.         case JSCURVE:
  2484.         /*
  2485.          @ jscurve color,formula1(x),formula2(x),formula3(x),...
  2486.          @ alternative: jsplot
  2487.          @ your function will be plotted by the javascript engine of the client browser
  2488.          @ 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
  2489.          @ use only basic math in your curve: <code>sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e</code>
  2490.          @ use parenthesis and rawmath: use 2*x instead of 2x ; use 2^(sin(x))...etc etc (use error console to debug any errors...)
  2491.          @ <b>attention</b>: last ''precision`` command in the canvasdraw script determines the calculation precision of the javascript curve plot !
  2492.          @ no validity check is done by wims.
  2493.          @ 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
  2494.          @ 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
  2495.          @ zooming & panning in case of userbased functionplot: reclick the OK button to re-plot curve onto the resized grid
  2496.          @ use keyword <a href='animate'>animate</a> for animating a point on the curve
  2497.          @ use command ''trace_jscurve formula(x)`` for tracing
  2498.          @ use command ''jsmath formula(x)`` for calculating and displaying indiviual points on the curve
  2499.          @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet)
  2500.          @ commands plotjump / plotstep are not active for ''jscurve``
  2501.          @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve.
  2502.          @ 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...)
  2503.          @%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)
  2504.         */
  2505.             jsplot_cnt++;/* -1 --> 0 */
  2506.             stroke_color = get_color(infile,0);
  2507.             js_function[JS_MATH] = 1;
  2508.             js_function[JS_PLOT] = 1;
  2509.             if( tmin != 0 && tmax !=0){use_parametric = TRUE;}
  2510.             temp = get_string(infile,1);
  2511.             temp = str_replace(temp,",","\",\"");
  2512.             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);
  2513.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2514.             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);
  2515.             add_to_buffer(tmp_buffer);
  2516.             fprintf(js_include_file,"if(typeof(all_jsplots) !== 'number'){var all_jsplots;};all_jsplots = %d;",jsplot_cnt);
  2517.  
  2518.              /* we need to create multiple canvasses, so we may zoom and pan ?? */
  2519.         break;
  2520.  
  2521.         case JSMATH:
  2522.         /*
  2523.             @ jsmath some_math_function
  2524.             @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
  2525.             @ 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
  2526.             @ use command 'css some_css' for styling the display fields. Use command 'fontsize int' to size the labels ''x`` and ''y``
  2527.             @ 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...
  2528.             @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
  2529.             @%jsmath%size 400,400%xrange -10,10%yrange -10,10%jsplot blue,sin(x^2)%jsmath sin(x^2)
  2530.         */
  2531.             js_function[DRAW_CROSSHAIRS] = 1;
  2532.             js_function[JS_MATH] = 1;
  2533.             add_calc_y(get_string(infile,1),font_size,css_class);
  2534.             break;
  2535.         case KILL:
  2536.         /*
  2537.         @ kill arguments
  2538.         @ arguments may be: affine linear translation rotation slider offset  reset
  2539.         @ for documentation see: killaffine,killlinear,killtranslation...
  2540.         @ multiple arguments are allowed (although not checked for validity...)
  2541.         */
  2542.             temp = get_string(infile,1);
  2543.             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;}
  2544.             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;}
  2545.             if(strstr(temp,"translation") != 0 || strstr(temp,"translate") != 0 ){affine_matrix[4] = 0.0;affine_matrix[5] = 0.0;}
  2546.             if(strstr(temp,"rotation") != 0 || strstr(temp,"rotate") != 0 ){use_rotate = FALSE;angle = 0.0;rotation_center="null";}
  2547.             if(strstr(temp,"slider") != 0 ){slider_type = "0";my_sliders = "[-1]";last_slider = use_slider+1;}
  2548.             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();}
  2549.             if(strstr(temp,"reset") != 0 ){if(no_reset == FALSE){no_reset = TRUE;}else{no_reset = FALSE;reset();}}
  2550.             if(strstr(temp,"offset") != 0 ){use_offset = 0;}
  2551.             break;
  2552.         case KILLAFFINE:
  2553.         /*
  2554.         @ killaffine
  2555.         @ keyword: resets the transformation matrix to 1,0,0,1,0,0
  2556.         @ note: any active linear transformation will also be reset: tx=0, ty=0
  2557.         */
  2558.             use_affine = FALSE;
  2559.             affine_matrix[0] = 1.0;
  2560.             affine_matrix[1] = 0.0;
  2561.             affine_matrix[2] = 0.0;
  2562.             affine_matrix[3] = 1.0;
  2563.             affine_matrix[4] = 0.0;
  2564.             affine_matrix[5] = 0.0;
  2565.             break;
  2566.         case KILLLINEAR:
  2567.         /*
  2568.         @ killlinear
  2569.         @ keyword: resets the transformation matrix to 1,0,0,1,tx,ty
  2570.         @ note:any active transformation or rotation will not be killed (tx,ty remain active)
  2571.         */
  2572.             affine_matrix[0] = 1.0;
  2573.             affine_matrix[1] = 0.0;
  2574.             affine_matrix[2] = 0.0;
  2575.             affine_matrix[3] = 1.0;
  2576.             break;
  2577.  
  2578.  
  2579.         case KILLROTATE:
  2580.         /*
  2581.          @ killrotate
  2582.          @ will set the rotation angle to 0.
  2583.          @ 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
  2584.          @ if not set, the rotation center will remain unchanged
  2585.          @ note:any active transformation or linear will not be killed (e.g an active transformation matrix remains active)
  2586.          @%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
  2587.         */
  2588.             use_rotate = FALSE;
  2589.             angle = 0.0;
  2590.             rotation_center="null";
  2591.          break;
  2592.  
  2593.         case KILLSLIDER:
  2594.         /*
  2595.          @ killslider
  2596.          @ keyword (no arguments required)
  2597.          @ ends grouping of object under a previously defined slider
  2598.         */
  2599.             slider_type = "0";
  2600.             my_sliders = "[-1]";
  2601.             last_slider = use_slider+1;
  2602.             break;
  2603.  
  2604.         case KILLTRANSLATION:
  2605.         /*
  2606.          @ killtranslation
  2607.          @ alternative: killtranslate
  2608.          @ note: a active linear or affine transformation will not be 100% reset...only tx=0,ty=0
  2609.          @ resets the translation matrix a,b,c,d,tx,ty to a,b,c,d,0,0
  2610.         */
  2611.             affine_matrix[4] = 0.0;
  2612.             affine_matrix[5] = 0.0;
  2613.             break;
  2614.  
  2615.         case LATEX:
  2616.         /*
  2617.          @ latex x,y,tex string
  2618.          @ alternative: math
  2619.          @ 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>
  2620.          @ 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)
  2621.          @ 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)
  2622.          @ 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
  2623.          @ 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...
  2624.          @ can be moved/rotated with command <a href='#slider'>slider</a>
  2625.          @ snaptogrid is supported
  2626.          @ 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
  2627.          @ userdraw may be combined with 'latex' ; the js-function 'read_canvas()' will contain the coordinates of the drawing.
  2628.          @ userdraw may be combined; the read_canvas() will contain the drawing.
  2629.          @ 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
  2630.          @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret...
  2631.          @ 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();"
  2632.          @ 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....
  2633.          @ 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]
  2634.          @ 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>)
  2635.          @ 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)``
  2636.          @%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}
  2637.          @%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
  2638.         */
  2639.             js_function[DRAW_XML] = 1;
  2640.             for(i=0;i<3;i++){
  2641.                 switch(i){
  2642.                     case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */
  2643.                     case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system  -> pixel height */
  2644.                     case 2: decimals = find_number_of_digits(precision);
  2645.                     temp = get_string(infile,1);
  2646.                     if(use_affine == TRUE ){ transform(2,2);}/* slider will use css-rotate transformation */
  2647.                     if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */
  2648.                     int_data[0] = x2px(double_data[0]);
  2649.                     int_data[1] = y2px(double_data[1]);
  2650.                     if( use_slider != -1 && onclick == 0 ){ onclick = 5;}
  2651.                     if( use_slider != -1 && drag_type != -1){ onclick = 5; }
  2652. #ifdef KATEX_INSTALLED
  2653.                     if( strstr(temp,"\\") != 0 ){ temp = str_replace(temp,"\\","\\\\"); }
  2654.                     if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2655.                     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);
  2656.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2657.                     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);
  2658. #else
  2659.                     temp = getMML(temp);/* generate MathML for Firefox or MathJaX */
  2660.                     if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2661.                     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);
  2662.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2663.                     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);
  2664. #endif
  2665.                     add_to_buffer(tmp_buffer);
  2666.                     if(onclick != 0 ){object_cnt++;}
  2667.                     drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */
  2668.                     break;
  2669.                     default:break;
  2670.                 }
  2671.             }
  2672.             reset();
  2673.             break;
  2674.         case LATTICE:
  2675.         /*
  2676.          @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
  2677.          @ can <b>not</b> be set ''onclick`` or ''drag xy``
  2678.          @%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
  2679.         */
  2680.             js_function[DRAW_LATTICE] = 1;
  2681.             for( i = 0; i<9; i++){
  2682.                 switch(i){
  2683.                     case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
  2684.                     case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
  2685.                     case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
  2686.                     case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
  2687.                     case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
  2688.                     case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
  2689.                     case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
  2690.                     case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
  2691.                     case 8: stroke_color=get_color(infile,1);
  2692.                         decimals = find_number_of_digits(precision);
  2693.                         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);
  2694.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2695.                         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);
  2696.                         add_to_buffer(tmp_buffer);break;
  2697.                     default:break;
  2698.                 }
  2699.             }
  2700.             reset();
  2701.             break;
  2702.         case LINEAR:
  2703.         /*
  2704.          @ linear a,b,c,d
  2705.          @ defines a transformation matrix for subsequent objects
  2706.          @ use keyword <a href='#killlinear'>killlinear</a> to end the transformation...the next objects will be drawn in the original x/y-range
  2707.          @ a: Scales the drawings horizontally
  2708.          @ b: Skews the drawings horizontally
  2709.          @ c: Skews the drawings vertically
  2710.          @ d: Scales the drawings vertically
  2711.          @ the data precision may be set by preceding command ''precision int``
  2712.          @ note: any active translation (tx,ty) is not changed
  2713.          @%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
  2714.         */
  2715.             for(i = 0 ; i<4;i++){
  2716.                 switch(i){
  2717.                     case 0: affine_matrix[0] = get_real(infile,0);break;
  2718.                     case 1: affine_matrix[1] = get_real(infile,0);break;
  2719.                     case 2: affine_matrix[2] = get_real(infile,0);break;
  2720.                     case 3: affine_matrix[3] = get_real(infile,1);
  2721.                      affine_matrix[4] = 0;affine_matrix[5] = 0;
  2722.                      use_affine = TRUE;
  2723.                      break;
  2724.                     default: break;
  2725.                 }
  2726.             }
  2727.             reset();
  2728.         break;
  2729.  
  2730.         case LINE:
  2731.         /*
  2732.         @ line x1,y1,x2,y2,color
  2733.         @ draw a line through points (x1:y1)--(x2:y2) in color ''color``
  2734.         @ or use command ''curve color,formula`` to draw the line (uses more points to draw the line; is however better draggable)
  2735.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2736.         @%line%size 400,400%xrange -10,10%yrange -10,10%line 0,1,2,-1,green
  2737.         */
  2738.             for(i=0;i<5;i++){
  2739.                 switch(i){
  2740.                     case 0: double_data[10]= get_real(infile,0);break; /* x-values */
  2741.                     case 1: double_data[11]= get_real(infile,0);break; /* y-values */
  2742.                     case 2: double_data[12]= get_real(infile,0);break; /* x-values */
  2743.                     case 3: double_data[13]= get_real(infile,0);break; /* y-values */
  2744.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  2745.                     if( double_data[10] == double_data[12] ){ /* vertical line*/
  2746.                         double_data[1] = xmin;
  2747.                         double_data[3] = ymax;
  2748.                         double_data[0] = double_data[10];
  2749.                         double_data[2] = double_data[10];
  2750.                     }
  2751.                     else
  2752.                     {
  2753.                         if( double_data[11] == double_data[13] ){ /* horizontal line */
  2754.                             double_data[1] = double_data[11];
  2755.                             double_data[3] = double_data[11];
  2756.                             double_data[0] = ymin;
  2757.                             double_data[2] = xmax;
  2758.                         }
  2759.                         else
  2760.                         {
  2761.                         /* m */
  2762.                         double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
  2763.                         /* q */
  2764.                         double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
  2765.  
  2766.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  2767.  
  2768.                             double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
  2769.                             double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
  2770.                             double_data[0] = xmin;
  2771.                             double_data[2] = xmax;
  2772.                         }
  2773.                     }
  2774.                     if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);}
  2775.                     if(use_affine == TRUE ){ transform(4,2);}
  2776.                     if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2777.  
  2778.                     decimals = find_number_of_digits(precision);
  2779.                     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);
  2780.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2781.                     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);
  2782.                     add_to_buffer(tmp_buffer);
  2783.                     if(onclick != 0){object_cnt++;}
  2784.                     /* object_cnt++;*/
  2785.                     reset();
  2786.                     break;
  2787.                 }
  2788.             }
  2789.             dragstuff[4] = 1;
  2790.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2791.             break;
  2792.  
  2793.         case LINES:
  2794.         /*
  2795.         @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n
  2796.         @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color'
  2797.         @ 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)
  2798.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  2799.         @ <b>attention</b>: the flydraw command ''lines`` is equivalent to canvasdraw command <a href="#polyline">polyline</a>
  2800.         @%lines%size 400,400%xrange -10,10%yrange -10,10%lines green,0,1,1,3,0,0,1,3,0,0,-2,1
  2801.         */
  2802.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  2803.             fill_color = stroke_color;
  2804.             i=0;
  2805.             while( ! done ){     /* get next item until EOL*/
  2806.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  2807.                 if(i%2 == 0 ){
  2808.                     double_data[i] = get_real(infile,0); /* x */
  2809.                 }
  2810.                 else
  2811.                 {
  2812.                     double_data[i] = get_real(infile,1); /* y */
  2813.                 }
  2814.                 i++;
  2815.             }
  2816.             decimals = find_number_of_digits(precision);
  2817.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2818.             for(c = 0 ; c < i-1 ; c = c+4){
  2819.                 if( double_data[c] == double_data[c+2] ){ /* vertical line*/
  2820.                     double_data[c+1] = xmin;
  2821.                     double_data[c+3] = ymax;
  2822.                     double_data[c+2] = double_data[c];
  2823.                 }
  2824.                 else
  2825.                 {
  2826.                     if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
  2827.                         double_data[c+3] = double_data[c+1];
  2828.                         double_data[c] = ymin;
  2829.                         double_data[c+2] = xmax;
  2830.                     }
  2831.                     else
  2832.                     {
  2833.                         /* m */
  2834.                         double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
  2835.                         /* q */
  2836.                         double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
  2837.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  2838.                         double_data[c+1] = (m)*(xmin)+(q);
  2839.                         double_data[c+3] = (m)*(xmax)+(q);
  2840.                         double_data[c] = xmin;
  2841.                         double_data[c+2] = xmax;
  2842.                     }
  2843.                 }
  2844.                 if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  2845.                 if(use_affine == TRUE ){ transform(i-1,2);}
  2846.  
  2847.                 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);
  2848.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2849.                 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);
  2850.                 add_to_buffer(tmp_buffer);
  2851.                 if(onclick != 0){object_cnt++;}
  2852.                 /* object_cnt++; */
  2853.             }
  2854.             dragstuff[4] = 1;
  2855.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2856.             reset();
  2857.             break;
  2858.  
  2859.  
  2860.         case LINEWIDTH:
  2861.         /*
  2862.         @ linewidth int
  2863.         @ default 1
  2864.         @%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
  2865.         */
  2866.             line_width = (int) (get_real(infile,1));
  2867.             break;
  2868.  
  2869.         case LEVELCURVE:
  2870.         /*
  2871.         @ levelcurve color,expression in x/y,l1,l2,...
  2872.         @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
  2873.         @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br>(choose flydraw if you want quality...)
  2874.         @ 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
  2875.         @ note: the arrays for holding the javascript data are limited in size
  2876.         @ note: reduce image size if javascript data arrays get overloaded<br>(command 'plotsteps int' will not control the data size of the plot...)
  2877.         @%levelcurve%size 400,400%xrange -10,10%yrange -10,10%levelcurve red,x*y,1,2,3,4
  2878.         */
  2879.             fill_color = get_color(infile,0);
  2880.             char *fun1 = get_string_argument(infile,0);
  2881.             if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
  2882.             i = 0;
  2883.             done = FALSE;
  2884.             while( !done ){
  2885.              double_data[i] = get_real(infile,1);
  2886.              i++;
  2887.             }
  2888.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2889.  
  2890.             for(c = 0 ; c < i; c++){
  2891.              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);
  2892.              check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2893.              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);
  2894.              add_to_buffer(tmp_buffer);
  2895.              if(onclick != 0){object_cnt++;}
  2896.              /* object_cnt++; */
  2897.             }
  2898.             dragstuff[16] = 1;
  2899.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  2900.             reset();
  2901.             break;
  2902.  
  2903.         case LEGEND:
  2904.         /*
  2905.         @ legend string1:string2:string3....string_n
  2906.         @ will be used to create a legend for a graph
  2907.         @ also see command <a href='#piechart'>piechart</a>
  2908.         @ will use the same colors per default as used in the graphs; use command <a href='#legendcolors'>legendcolors</a> to override the default
  2909.         @ use command <a href="#fontsize">fontsize</a> to adjust. (command ''fontfamily`` is not active for command ''legend``)
  2910.         @%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
  2911.         */
  2912.             temp = get_string(infile,1);
  2913.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2914.             legend_cnt++; /* attention: starts with -1: it will be used in piechart etc */
  2915.             fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
  2916.             break;
  2917.  
  2918.         case LEGENDCOLORS:
  2919.         /*
  2920.         @ legendcolors color1:color2:color3:...:color_n
  2921.         @ 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>.
  2922.         @ make sure the number of colors match the number of legend items
  2923.         @ command ''legend`` in case of ''piechart`` and ''barchart`` will use these colours per default (no need to specify ''legendcolors``)
  2924.         @%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
  2925.         */
  2926.             if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
  2927.             temp = get_string(infile,1);
  2928.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2929.             fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
  2930.             break;
  2931.  
  2932.         case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed', 'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
  2933.         /*
  2934.         @ linegraph x1:y1:x2:y2...x_n:y_n
  2935.         @ will plot your data in a graph
  2936.         @ may <b>only</b> to be used together with command <a href='#grid'>grid</a>
  2937.         @ 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>
  2938.         @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner
  2939.         @ also see command <a href='#piechart'>piechart</a>
  2940.         @ multiple linegraphs may be used in a single plot
  2941.         @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble...
  2942.         @ <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>
  2943.         @%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
  2944.         */
  2945.             temp = get_string(infile,1);
  2946.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2947.             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);
  2948.             linegraph_cnt++;
  2949.             reset();
  2950.             break;
  2951.  
  2952.         case MATHML:
  2953.         /*
  2954.         @ mathml x1,y1,mathml_string
  2955.         @ this command is special for GECKO browsers, and it makes use of Native Mathml
  2956.         @ For general use with all browsers, use command <a href='#latex'>latex</a>
  2957.         @ 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>
  2958.         @ command <a href='#affine'>affine</a> will produce CSS3 matrix transformations
  2959.         @ command <a href='#rotate'>rotate</a> will rotate the object
  2960.         @ the mathml object is centered at (x1:y1)
  2961.         @ the ''mathml_string`` can be produced using WIMS commands like ''texmath`` followed by ''mathmlmath``... or write correct TeX and use only ''mathmlmath``
  2962.         @ mathml will be displayed in a rectangle left top (x1:y1)
  2963.         @ 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
  2964.         @ 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...
  2965.         @ 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.
  2966.         @ 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.
  2967.         @ userdraw may be combined with 'mathml' ; the read_canvas() will contain the drawing.
  2968.         @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick mathml
  2969.         @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret...
  2970.         @ 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();"
  2971.         @ 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....
  2972.         @ use keyword <a href='#centered'>centered</a> to center the mathml/xml object on (x1:y1)
  2973.         @%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>
  2974.         @%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...
  2975.         */
  2976.             js_function[DRAW_XML] = 1;
  2977.             for(i=0;i<3;i++){
  2978.                 switch(i){
  2979.                     case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */
  2980.                     case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system  -> pixel height */
  2981.                     case 2: decimals = find_number_of_digits(precision);
  2982.  
  2983.                             if(use_affine == TRUE ){ transform(2,2);}/* needs double_data[] */
  2984.                             if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */
  2985.                             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  2986.                             int_data[0] = x2px(double_data[0]);/* needs px */
  2987.                             int_data[1] = y2px(double_data[1]);
  2988.                             if( use_slider != -1 && onclick == 0 ){ onclick = 3;}/* no drag&onclick but slideable */
  2989.                             if( use_slider != -1 && drag_type != -1){ onclick = 5; }
  2990.                             temp = get_string(infile,1);
  2991.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  2992.                             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);
  2993.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  2994.                             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);
  2995.                             add_to_buffer(tmp_buffer);
  2996.                             if(onclick != 0 ){object_cnt++;}
  2997.                             drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */
  2998.                             /*
  2999.                                 in case inputs are present, trigger adding the read_mathml()
  3000.                                 if no other reply_format is defined
  3001.                                 note: all other reply types will include a reading of elements with id='mathml'+p)
  3002.                             */
  3003.                             if(strstr(temp,"mathml0") != NULL){ if(reply_format == 0 ){reply_format = 16;}} /* no other reply type is defined */
  3004.                             break;
  3005.                     default:break;
  3006.                 }
  3007.             }
  3008.             reset();
  3009.             break;
  3010.  
  3011.         case MOUSE:
  3012.         /*
  3013.          @ mouse color,fontsize
  3014.          @ will display the cursor (x:y) coordinates in ''color`` and ''fontsize`` using default fontfamily Arial
  3015.          @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``)
  3016.          @%mouse%size 400,400%xrange -10,10%yrange -10,10%mouse red,22
  3017.         */
  3018.             stroke_color = get_color(infile,0);
  3019.             font_size = (int) (get_real(infile,1));
  3020.             tmp_buffer = my_newmem(26);
  3021.             snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  3022.             add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,2);
  3023.             js_function[INTERACTIVE] = 1;
  3024.             break;
  3025.  
  3026.  
  3027.         case MOUSE_DEGREE:
  3028.         /*
  3029.          @ mouse_degree color,fontsize
  3030.          @ 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
  3031.          @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
  3032.          @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
  3033.          @%mouse_degree%size 400,400%xrange -10,10%yrange -10,10%userdraw arc,blue%precision 100000%mouse_degree red,22
  3034.         */
  3035.             stroke_color = get_color(infile,0);
  3036.             font_size = (int) (get_real(infile,1));
  3037.             tmp_buffer = my_newmem(26);
  3038.             snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  3039.             add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,3);
  3040.             js_function[JS_FIND_ANGLE] = 1;
  3041.             js_function[INTERACTIVE] = 1;
  3042.             break;
  3043.         case MOUSE_DISPLAY:
  3044.         /*
  3045.          @ display TYPE,color,fontsize
  3046.          @ TYPE may be x | y | xy | degree | radian | radius
  3047.          @ 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).
  3048.          @ use commands ''xunit`` and / or ''yunit`` to add the units to the mouse values. The ''degree | radian`` will always have the appropriate symbol).
  3049.          @ just like commands ''mouse``, ''mousex``, ''mousey``, ''mouse_degree``... only other name
  3050.          @%display_x%size 400,400%xrange -10,10%yrange -10,10%xunit \\u212B%display x,red,22
  3051.          @%display_y%size 400,400%xrange -10,10%yrange -10,10%yunit seconds%display y,red,22
  3052.          @%display_xy%size 400,400%xrange -10,10%yrange -10,10%xunit centimetre%yunit seconds%display xy,red,22%userdraw segments,blue
  3053.          @%display_deg%size 400,400%xrange -10,10%yrange -10,10%display degree,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
  3054.          @%display_rad%size 400,400%xrange -10,10%yrange -10,10%display radian,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
  3055.          @%display_radius%size 400,400%xrange -10,10%yrange -10,10%xunit cm%xunit \\u212b%display radius,red,22%userdraw circle,blue
  3056.         */
  3057.         temp = get_string_argument(infile,0);
  3058.         if( strstr(temp,"xy") != NULL ){
  3059.             int_data[0] = 2;
  3060.         }else{
  3061.             if( strstr(temp,"y") != NULL ){
  3062.                 int_data[0] = 1;
  3063.             }else{
  3064.                 if( strstr(temp,"x") != NULL ){
  3065.                     int_data[0] = 0;
  3066.                 }else{
  3067.                     if(strstr(temp,"degree") != NULL){
  3068.                         int_data[0] = 3;
  3069.                         js_function[JS_FIND_ANGLE] = 1;
  3070.                     }else{
  3071.                         if(strstr(temp,"radian") != NULL){
  3072.                             int_data[0] = 4;
  3073.                             js_function[JS_FIND_ANGLE] = 1;
  3074.                         }else{
  3075.                             if(strstr(temp,"radius") != NULL){
  3076.                                 int_data[0] = 5;
  3077.                             }else{
  3078.                                 int_data[0] = 2;
  3079.                             }
  3080.                         }
  3081.                     }
  3082.                 }
  3083.             }
  3084.         }
  3085.         stroke_color = get_color(infile,0);
  3086.         font_size = (int) (get_real(infile,1));
  3087.         tmp_buffer = my_newmem(26);
  3088.         snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  3089.         add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
  3090.         js_function[INTERACTIVE] = 1;
  3091.         break;
  3092.  
  3093.         case MOUSE_PRECISION:
  3094.         /*
  3095.             @ precision int
  3096.             @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
  3097.             @ may be used / changed before every object
  3098.             @ In case of user interaction (like ''userdraw`` or ''multidraw``), this value will be used to determine the amount of decimals in the reply / answer
  3099.             @%precision%size 400,400%xrange -10,10%yrange -10,10%precision 1%userdraw segment,red
  3100.         */
  3101.             precision = (int) (get_real(infile,1));
  3102.             if(precision < 1 ){precision = 1;};
  3103.             break;
  3104.  
  3105.         case MOUSEX:
  3106.         /*
  3107.          @ mousex color,fontsize
  3108.          @ will display the cursor x-coordinate in ''color`` and ''font size`` using the fontfamily Arial.
  3109.          @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``).
  3110.  
  3111.         */
  3112.             stroke_color = get_color(infile,0);
  3113.             font_size = (int) (get_real(infile,1));
  3114.             tmp_buffer = my_newmem(26);
  3115.             snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  3116.             add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,0);
  3117.             js_function[INTERACTIVE] = 1;
  3118.             break;
  3119.         case MOUSEY:
  3120.         /*
  3121.          @ mousey color,fontsize
  3122.          @ will display the cursor y-coordinate in ''color`` and ''font size`` using default fontfamily Arial.
  3123.          @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``).
  3124.  
  3125.         */
  3126.             stroke_color = get_color(infile,0);
  3127.             font_size = (int) (get_real(infile,1));
  3128.             tmp_buffer = my_newmem(26);
  3129.             snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  3130.             add_js_mouse(MOUSE_CANVAS,precision,stroke_color,font_size,stroke_opacity,1);
  3131.             js_function[INTERACTIVE] = 1;
  3132.             break;
  3133.  
  3134.         case MULTIDASH:
  3135.         /*
  3136.          @ multidash 0,1,1
  3137.          @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <code>multifill points,circle,segments</code>, are dashed
  3138.          @ use before command <a href='#multidraw'>multidraw</a>
  3139.          @ if not set all objects will be set ''not dashed``... unless a generic keyword ''dashed`` was given before command ''multidraw``
  3140.          @ 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)
  3141.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  3142.          @ always use the same sequence as is used for ''multidraw``
  3143.         */
  3144.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3145.             temp = get_string(infile,1);
  3146.             temp = str_replace(temp,",","\",\"");
  3147.             fprintf(js_include_file,"var multidash = [\"%s\"];",temp);
  3148.             reset();/* if command 'dashed' was given...reset to not-dashed */
  3149.             break;
  3150.  
  3151.         case MULTIDRAW:
  3152.         /*
  3153.          @ multidraw obj_type_1,obj_type_2...obj_type_11
  3154.          @ for simple single object user drawings you could also use command <a href="#userdraw">userdraw</a>
  3155.          @ 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>
  3156.          @ 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
  3157.          @ 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...
  3158.          @ 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)
  3159.          @ 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'
  3160.          @ 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)
  3161.          @ a right mouse button click will remove the last drawn object of the selected drawing type. All other type of objects are not removed
  3162.          @ multidraw is incompatible with command ''tooltip`` (the reserved div_area is used for the multidraw control buttons)
  3163.          @ all ''multidraw`` drawings will scale on zooming.<br>this in contrast to the command <a href="#userdraw">userdraw</a>.
  3164.          @ wims will <b>not</b> check the amount or validity of your command arguments ! <br>( use javascript console to debug any typo's )
  3165.          @ 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>
  3166.          @ 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>
  3167.          @ <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.
  3168.          @ 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.
  3169.          @ 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.
  3170.          @ 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"
  3171.          @%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
  3172.          @%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
  3173.          @%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
  3174.          @%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
  3175.          @%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
  3176.         */
  3177.             js_function[INTERACTIVE] = 1;
  3178.             if(js_function[JS_ZOOM] == 1){use_zoom = 1;} /* use noisy zoom_code, when command zoom is given before command 'multidraw' */
  3179.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3180.             if( use_userdraw == 1 ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");}
  3181.             use_userdraw = 2;
  3182.             temp = get_string(infile,1);
  3183.             fprintf(js_include_file,"\
  3184.             var MMP = %d;\
  3185.             if( typeof(multisnaptogrid) == 'undefined' && multisnaptogrid == null){var multisnaptogrid = new Array(MMP);for(var i=0;i<MMP;i++){multisnaptogrid[i] = %d;};};\
  3186.             if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null){ var multistrokecolors = new Array(MMP);for(var i=0;i<MMP;i++){multistrokecolors[i] = '%s';};};\
  3187.             if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){var multifillcolors = new Array(MMP);for(var i=0;i<MMP;i++){multifillcolors[i] = '%s';};};\
  3188.             if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null){var multistrokeopacity = new Array(MMP);for(var i=0;i<MMP;i++){multistrokeopacity[i] = %.2f;};};\
  3189.             if( typeof(multifillopacity) === 'undefined' &&  multifillopacity == null){var multifillopacity = new Array(MMP);for(var i=0;i<MMP;i++){multifillopacity[i] = %.2f;};};\
  3190.             if( typeof(multilinewidth) === 'undefined' && multilinewidth == null){var multilinewidth = new Array(MMP);for(var i=0;i<MMP;i++){multilinewidth[i] = %d;};};\
  3191.             if( typeof(multifill) === 'undefined' && multifill == null){var multifill = new Array(MMP);for(var i=0;i<MMP;i++){multifill[i] = %d;};};\
  3192.             if( typeof(multidash) === 'undefined' && multidash == null){var multidash = new Array(MMP);for(var i=0;i<MMP;i++){multidash[i] = %d;};};\
  3193.             if( typeof(multilabel) === 'undefined' && multilabel == null){var multilabel = [\"%s\",\"stop drawing\"];};\
  3194.             if( typeof(multiuserinput) === 'undefined' && multiuserinput == null){var multiuserinput = new Array(MMP);for(var i=0;i<MMP;i++){multiuserinput[i] = '0';};};\
  3195.             var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';var forbidden_zone = [xsize+2,ysize+2];",
  3196.             MAX_MULTI_PRIMITIVES,
  3197.             use_snap,
  3198.             stroke_color,
  3199.             fill_color,
  3200.             stroke_opacity,
  3201.             fill_opacity,
  3202.             line_width,
  3203.             use_filled,
  3204.             use_dashed,
  3205.             str_replace(temp,",","\",\""),
  3206.             arrow_head,font_color,font_family);
  3207.             add_js_multidraw(temp,css_class,use_offset,int_data[MAX_MULTI_PRIMITIVES+1],crosshair_size,use_zoom);
  3208.             /* no_controls == int_data[MAX_MULTI_PRIMITIVES+1] */
  3209.             reply_precision = precision;
  3210.             if(strstr(temp,"text") != NULL){
  3211.              js_function[JS_SAFE_EVAL] = 1;
  3212.              js_function[DRAW_SUBSUP] = 1;
  3213.             }
  3214.             if(strstr(temp,"function") != NULL){
  3215.             int pp, funs = count_substring(temp, "function");
  3216.              js_function[JS_SAFE_EVAL] = 1;
  3217.              js_function[JS_RAWMATH] = 1;
  3218.              js_function[DRAW_JSFUNCTION] = 1;
  3219.              js_function[JS_MATH] = 1;
  3220.              js_function[JS_PLOT] = 1;
  3221.              for(pp = 0 ; pp< funs ;pp++){
  3222.              add_input_jsfunction(css_class,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size);
  3223.              input_cnt++;
  3224.              jsplot_cnt++;
  3225.              }
  3226.              fprintf(js_include_file,"if(typeof(all_jsplots) !== 'number'){var all_jsplots;};all_jsplots = %d;function redraw_userdraw(){redraw_jsplot();return;};",jsplot_cnt);
  3227.             }
  3228.             /* the canvasses range from 1000 ... 1008 */
  3229.             if( reply_format == 0){reply_format = 29;}
  3230.             reset();/* if command 'filled' / 'dashed' was given...reset all */
  3231.             break;
  3232.         case MULTILABEL:
  3233.         /*
  3234.          @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text'
  3235.          @ use before command <a href='#multidraw'>multidraw</a>
  3236.          @ 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'...)
  3237.          @ 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>
  3238.          @ 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``
  3239.          @ wims will not check the amount or validity of your input
  3240.          @ always use the same sequence as is used for ''multidraw``
  3241.          @ if you don't want the controls, and want to write your own interface, set <code>multilabel NOCONTROLS</code>
  3242.         */
  3243.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3244.             temp = get_string(infile,1);
  3245.             if( strcasestr(temp,"NOCONTROLS") ){
  3246.              int_data[MAX_MULTI_PRIMITIVES+1] = 1; /*int_data[25] = 1 --> 'no_controls = 1' in canvasmacro.c */
  3247.              fprintf(js_include_file,"var multilabel = null;");
  3248.             }
  3249.             else
  3250.             {
  3251.              int_data[MAX_MULTI_PRIMITIVES+1] = 0; /* so DO use control buttons etc */
  3252.              temp = str_replace(temp,",","\",\"");
  3253.              fprintf(js_include_file,"var multilabel = [\"%s\"];",temp);
  3254.             }
  3255.             break;
  3256.         case MULTILINEWIDTH:
  3257.         /*
  3258.          @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8
  3259.          @ use before command <a href='#multidraw'>multidraw</a>
  3260.          @ if not set all line widths will be set by a previous command ''linewidth int``
  3261.          @ 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>
  3262.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  3263.          @ always use the same sequence as is used for ''multidraw``
  3264.         */
  3265.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3266.             temp = get_string(infile,1);
  3267.             temp = str_replace(temp,",","\",\"");
  3268.             fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp);
  3269.             break;
  3270.         case MULTIFILL:
  3271.         /*
  3272.          @ multifill 0,0,1,0,1,0,0
  3273.          @ 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...)
  3274.          @ 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
  3275.          @ use before command <a href='#multidraw'>multidraw</a>
  3276.          @ 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>
  3277.          @ only suitable for draw_primitives like ''circle | circles``, ''triangle | triangles``, ''rect | rects``, ''poly[3-9] | polys[3-9]`` and ''polygon``
  3278.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  3279.          @ always use the same sequence as is used for ''multidraw``
  3280.         */
  3281.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3282.             i=0;
  3283.             while( ! done ){     /* get next item until EOL*/
  3284.                 if(i > MAX_MULTI_PRIMITIVES){canvas_error("too many multidraw primitives...read the documentation...");}
  3285.                 int_data[i] = (int)(get_real(infile,1)); /* 0,1,2,3,4,5 */
  3286.                 if(int_data[i] < 0 || int_data[i] > 5 ){canvas_error("the only possible multifill arguments are: 0,1,2,3,4,5 ");}
  3287.                 if(int_data[i] > 1 ){use_filled = 2;js_function[DRAW_FILL_PATTERN] = 1;}/* switch to trigger pattern filling */
  3288.                 i++;
  3289.             }
  3290.             fprintf(js_include_file,"var multifill = %s ;",data2js_array(int_data,i-1));
  3291.             break;
  3292.  
  3293.         case MULTIFILLCOLORS:
  3294.         /*
  3295.          @ multifillcolors color_name_1,color_name_2,...,color_name_8
  3296.          @ use before command <a href='#multidraw'>multidraw</a>
  3297.          @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be ''stroke_color``, ''fill_opacity``
  3298.          @ 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>
  3299.          @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
  3300.          @ always use the same sequence as is used for ''multidraw``
  3301.          @ 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>
  3302.         */
  3303.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3304.             fprintf(js_include_file,"var multifillcolors = [");
  3305.             while( ! done ){
  3306.                 temp = get_color(infile,1);
  3307.                 fprintf(js_include_file,"\"%s\",",temp);
  3308.             }
  3309.             fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
  3310.             break;
  3311.  
  3312.         case MULTIFILLOPACITY:
  3313.         /*
  3314.          @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8
  3315.          @ float values 0 - 1 or integer values 0 - 255
  3316.          @ use before command <a href='#multidraw'>multidraw</a>
  3317.          @ if not set all fill opacity_ will be set by previous command <code>opacity int,int</code> and keyword ''filled``
  3318.          @ 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>
  3319.          @ wims will not check the amount or validity of your input
  3320.          @ always use the same sequence as is used for ''multidraw``
  3321.         */
  3322.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3323.             temp = get_string(infile,1);
  3324.             temp = str_replace(temp,",","\",\"");
  3325.             fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp);
  3326.             break;
  3327.         case MULTISNAPTOGRID:
  3328.         /*
  3329.          @ multisnaptogrid 0,1,1
  3330.          @ alternative: multisnap
  3331.          @ 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>)
  3332.          @ freehand drawing...specify precision for reply: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code>
  3333.          @ only the xy-values snap_to_grid: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code>
  3334.          @ only the x-values snap_to_grid: all objects snap to x-grid <code>multisnaptogrid 2,2,2,...</code>
  3335.          @ only the y-values snap_to_grid: all objects snap to y-grid <code>multisnaptogrid 3,3,3,...</code>
  3336.          @ 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>
  3337.          @ <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>
  3338.          @ use before command <a href='#multidraw'>multidraw</a>
  3339.          @ attention: if not set all objects will be set ''no snap``... unless a generic command ''snaptogrid`` was given before command ''multidraw``
  3340.          @ 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>
  3341.          @ always use the same sequence as is used for ''multidraw``
  3342.          @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
  3343.         */
  3344.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3345.             temp = get_string(infile,1);
  3346.             fprintf(js_include_file,"var multisnaptogrid = [%s];",temp);
  3347.             reset();/* if command 'dashed' was given...reset to not-dashed */
  3348.             break;
  3349.         case MULTISTROKECOLORS:
  3350.         /*
  3351.          @ multistrokecolors color_name_1,color_name_2,...,color_name_8
  3352.          @ use before command <a href='#multidraw'>multidraw</a>
  3353.          @ if not set all colors will be ''stroke_color``, ''stroke_opacity``
  3354.          @ 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>
  3355.          @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
  3356.          @ always use the same sequence as is used for ''multidraw``
  3357.         */
  3358.             if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3359.             fprintf(js_include_file,"var multistrokecolors = [");
  3360.             while( ! done ){
  3361.                 temp = get_color(infile,1);
  3362.                 fprintf(js_include_file,"\"%s\",",temp);
  3363.             }
  3364.             fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
  3365.             break;
  3366.         case MULTISTROKEOPACITY:
  3367.         /*
  3368.          @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7
  3369.          @ float values 0 - 1 or integer values 0 - 255
  3370.          @ use before command <a href='#multidraw'>multidraw</a>
  3371.          @ if not set all stroke opacity_ will be set by previous command <code>opacity int,int</code>
  3372.          @ 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>
  3373.          @ wims will not check the amount or validity of your input
  3374.          @ always use the same sequence as is used for ''multidraw``
  3375.         */
  3376.             if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
  3377.             temp = get_string(infile,1);
  3378.             temp = str_replace(temp,",","\",\"");
  3379.             fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp);
  3380.             break;
  3381.  
  3382.         case MULTIUSERINPUT:
  3383.         /*
  3384.         @ multiuserinput 0,1,1,0
  3385.         @ alternative: multiinput
  3386.         @ 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
  3387.         @ 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
  3388.         @ 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...
  3389.         @ in case of a triangle | poly3, three inputfields are provided.
  3390.         @ in case of ''text`` and ''multiuserinput=1, 3`` inputfields will be shown: ''x,y,text``
  3391.         @ in case of ''text`` and ''multiuserinput=0, 1`` inputfield will be shown: text ... a mouse click will place the text on the canvas.
  3392.         @ may be styled using command <a href="#css">css</a>
  3393.         @ an additional button ''stop drawing`` may be used to combine userbased drawings with ''drag&and;drop`` or ''onclick`` elements
  3394.         @ when exercise if finished (status=done) the buttons will not be shown.<br>To override this default behaviour use command / keyword ''status``
  3395.         @ use before command <a href='#multidraw'>multidraw</a>
  3396.         @ always use the same sequence as is used for ''multidraw``
  3397.         */
  3398.             /* simple rawmath and input check */
  3399.             js_function[JS_SAFE_EVAL] = 1;
  3400.             temp = get_string(infile,1);
  3401.             temp = str_replace(temp,",","\",\"");
  3402.             fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp);
  3403.             break;
  3404.         case NORESET:
  3405.         /*
  3406.         @ noreset
  3407.         @ alternative: killreset
  3408.         @ keyword
  3409.         @ may come in handy if canvas script code is generated using loops
  3410.         @ 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>
  3411.         @ 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)
  3412.         @ etc etc
  3413.         @ 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>
  3414.         @ commands like 'opacity', 'linewidth', 'fontsize', 'fontfamily' are only changed when redefined again
  3415.         @%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
  3416.         @%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
  3417.         */
  3418.             if(no_reset == FALSE){no_reset = TRUE;}else{no_reset = FALSE;reset();}
  3419.             break;
  3420.         case NOXAXIS:
  3421.         /*
  3422.         @ noxaxis
  3423.         @ keyword
  3424.         @ if set, the automatic x-axis numbering will be ignored
  3425.         @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>)
  3426.         @ to be used before command grid (see <a href="#grid">command grid</a>)
  3427.         */
  3428.             fprintf(js_include_file,"x_strings = {};x_strings_up = [];\n");
  3429.             use_axis_numbering = -1;
  3430.             break;
  3431.         case NOYAXIS:
  3432.         /*
  3433.         @ noyaxis
  3434.         @ keyword
  3435.         @ if set, the automatic y-axis numbering will be ignored
  3436.         @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>)
  3437.         @ to be used before command grid (see <a href="#grid">command grid</a>)
  3438.         */
  3439.             fprintf(js_include_file,"y_strings = {};\n");
  3440.             break;
  3441.         case NUMBERLINE:
  3442.         /*
  3443.         @ numberline x0,x1,xmajor,xminor,y0,y1
  3444.         @ numberline is using xrange/yrange system for all dimensions
  3445.         @ multiple numberlines are allowed ; combinations with command <a href='#grid'>grid</a> is allowed; multiple commands <a href='#xaxis'>xaxis numbering</a> are allowed
  3446.         @ x0 is start x-value in xrange
  3447.         @ x1 is end x-value in xrange
  3448.         @ xmajor is step for major division
  3449.         @ xminor is divisor of xmajor; using small (30% of major tick) tick marks: this behaviour is ''hardcoded``
  3450.         @ is xminor is an even divisor, an extra tickmark (60% of major tick) is added to the numberline: this behaviour is ''hardcoded``
  3451.         @ y0 is bottom of numberline; y1 endpoint of major tics
  3452.         @ use command <a href="#linewidth">linewidth</a> to control appearance
  3453.         @ use <a href="#strokecolor">strokecolor</a> and <a href="#opacity">opacity</a> to controle measure line
  3454.         @ for all ticks linewidth and color / opacity are identical.
  3455.         @ 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
  3456.         @ use <a href="#fontfamily">fontfamily</a> and <a href="#fontcolor">fontcolor</a> to control fonts settings
  3457.         @ 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
  3458.         @ <a href="#snaptogrid">snaptogrid, snaptopoints etc</a> and <a href="#zoom">zooming and panning</a> is supported
  3459.         @ onclick and dragging of the numberline are not -yet- supported
  3460.         @ note: in case of multiple numberlines, make sure the numberline without special x-axis numbering (e.g. ranging from xmin to xmax) comes first !
  3461.         @%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
  3462.         */
  3463.             js_function[DRAW_NUMBERLINE] = 1;
  3464.             for(i=0;i<6;i++){
  3465.                 switch(i){
  3466.                     case 0: double_data[0] = get_real(infile,0);break;/* xmin */
  3467.                     case 1: double_data[1] = get_real(infile,0);break;/* xmax */
  3468.                     case 2: double_data[2] = get_real(infile,0);break;/* xmajor */
  3469.                     case 3: double_data[3] = get_real(infile,0);break;/* xminor */
  3470.                     case 4: double_data[4] = get_real(infile,0);break;/* ymin */
  3471.                     case 5: double_data[5] = get_real(infile,1);/* ymax */
  3472.                             /*
  3473.                             var draw_numberline%d = function(canvas_type,xmin,xmax,xmajor,xminor,ymin,ymax,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor);
  3474.                             */
  3475.                             fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[2] / double_data[3],double_data[5] - double_data[4] );
  3476.                             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);
  3477.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3478.                             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);
  3479.                             add_to_buffer(tmp_buffer);
  3480.                             numberline_cnt++;
  3481.                             break;
  3482.                     default:break;
  3483.                 }
  3484.             }
  3485.             reset();
  3486.             break;
  3487.  
  3488.         case OBABEL:
  3489.  
  3490.         /*
  3491.         @ obabel x,y,type input,molecule smiles-code or file location, extra arguments,extra arguments,...
  3492.         @ will call the ''obabel`` program, if installed.
  3493.         @ output will be an svg file
  3494.         @ see documentation of obabel for special keys
  3495.         @ command <a href='#affine'>affine</a> will produce CSS3 matrix transformations
  3496.         @ command <a href='#rotate'>rotate</a> will rotate the object
  3497.         @ 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
  3498.         @ 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...
  3499.         @ 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
  3500.         @ 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
  3501.         @%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
  3502.         */
  3503.             js_function[DRAW_XML] = 1;
  3504.             for(i=0;i<4;i++){
  3505.                 switch(i){
  3506.                     case 0: double_data[0]=get_real(infile,0);break; /* x in x/y-range coord system -> pixel width */
  3507.                     case 1: double_data[1]=get_real(infile,0);break; /* y in x/y-range coord system  -> pixel height */
  3508.                     case 2: URL = get_string_argument(infile,0);break;
  3509.                     case 3:
  3510.                     if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3511.                     temp = getSVGMOL(URL,get_string(infile,1));
  3512.                     decimals = find_number_of_digits(precision);
  3513.                     if(use_affine == TRUE ){ transform(2,2);}
  3514.                     if( use_offset != 0 || drag_type != -1 ){int_data[2] = 1;}else{int_data[2] = 0;} /* only centered or not-centered */
  3515.                     int_data[0] = x2px(double_data[0]);
  3516.                     int_data[1] = y2px(double_data[1]);
  3517.                     if( use_slider != -1 && onclick == 0 ){ onclick = 3;}/* no drag&onclick but slideable */
  3518.                     if( use_slider != -1 && drag_type > 0 ){ onclick = 5;}/* slider+drag*/
  3519.                     if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  3520.                     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);
  3521.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3522.                     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);
  3523.                     add_to_buffer(tmp_buffer);
  3524.                     if(onclick != 0 ){object_cnt++;}
  3525.                     drawxml_cnt++;/* keeps track on imported img,div,p,span,mathml,svg */
  3526.                     break;
  3527.                     default:break;
  3528.                 }
  3529.             }
  3530.             reset();
  3531.         break;
  3532.  
  3533.         case OPACITY:
  3534.         /*
  3535.         @ opacity [0-255],[0-255]
  3536.         @ opacity [0.0 - 1.0],[0.0 - 1.0]
  3537.         @ alternative: transparent
  3538.         @ first item is stroke opacity, second is fill opacity
  3539.         @%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
  3540.         */
  3541.             for(i = 0 ; i<2;i++){
  3542.                 switch(i){
  3543.                     case 0: double_data[0]= get_real(infile,0);break;
  3544.                     case 1: double_data[1]= get_real(infile,1);break;
  3545.                     default: break;
  3546.                 }
  3547.             }
  3548.             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 ? */
  3549.             if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = 0.0;} /* 0.0 - 1.0 */
  3550.             if( double_data[1] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = 0.0;} /* 0.0 - 1.0 */
  3551.             break;
  3552.  
  3553.         case ONCLICK:
  3554.         /*
  3555.          @ onclick
  3556.          @ keyword (no arguments required)
  3557.          @ if the next object is clicked, its ''object onclick_or_drag sequence number`` in fly script is returned by <code>javascript:read_canvas();</code>
  3558.          @ 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``
  3559.          @ line based objects will show an increase in line width<br>font based objects will show the text in ''bold`` when clicked.
  3560.          @ the click zone (accuracy) is determined by 2&times; the line width of the object
  3561.          @ 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...)
  3562.          @ note: not all objects may be set onclick
  3563.          @%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
  3564.         */
  3565.             fprintf(js_include_file,"use_dragdrop_reply = true;");
  3566.             onclick = 1;
  3567.             use_dragstuff=2;
  3568.             js_function[INTERACTIVE] = 1;
  3569.  
  3570.             break;
  3571.  
  3572.         case PARALLEL:
  3573.         /*
  3574.          @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
  3575.          @ affine transformations should be identical to flydraw
  3576.          @ 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.
  3577.          @ in case of <em>no rotation or transformations</em> the lines can not be set ''onclick`` or ''drag xy``.
  3578.          @ 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...)
  3579.          @%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
  3580.          @%parallel%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red
  3581.         */
  3582.             decimals = find_number_of_digits(precision);
  3583.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3584.  
  3585.             if( use_rotate == TRUE || use_affine == TRUE ){
  3586.                 for( i = 0;i < 8; i++ ){
  3587.                     switch(i){
  3588.                         case 0: double_data[0] = get_real(infile,0);break; /* x1-values */
  3589.                         case 1: double_data[1] = get_real(infile,0);break; /* y1-values */
  3590.                         case 2: double_data[2] = get_real(infile,0);break; /* x2-values */
  3591.                         case 3: double_data[3] = get_real(infile,0);break; /* y2-values */
  3592.                         case 4: double_data[4] = get_real(infile,0);break; /* xv  */
  3593.                         case 5: double_data[5] = get_real(infile,0);break; /* yv  */
  3594.                         case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
  3595.                         case 7: stroke_color=get_color(infile,1);break;/* name or hex color */
  3596.                         default: break;
  3597.                     }
  3598.                 }
  3599.                 double_data[6] = double_data[0]; /* x1 */
  3600.                 double_data[7] = double_data[1]; /* y1 */
  3601.                 double_data[8] = double_data[2]; /* x2 */
  3602.                 double_data[9] = double_data[3]; /* y2 */
  3603.                 for(i = 0 ; i < int_data[0] ; i++){
  3604.                     double_data[0] = double_data[6] + i*double_data[4];
  3605.                     double_data[1] = double_data[7] + i*double_data[5];
  3606.                     double_data[2] = double_data[8] + i*double_data[4];
  3607.                     double_data[3] = double_data[9] + i*double_data[5];
  3608.                     if(use_rotate == TRUE ){ rotate(4,angle,rotationcenter,2);}
  3609.                     if(use_affine == TRUE ){ transform(4,2);}
  3610.                     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);
  3611.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3612.                     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);
  3613.                     add_to_buffer(tmp_buffer);
  3614.                     if(onclick != 0){object_cnt++;}
  3615.                 }
  3616.                 dragstuff[4] = 1;
  3617.             }
  3618.             else  /* use the old parallel version: calculations in javascript */
  3619.             {
  3620.                 for( i = 0;i < 8; i++ ){
  3621.                     switch(i){
  3622.                         case 0: double_data[0] = get_real(infile,0);break; /* x1-values */
  3623.                         case 1: double_data[1] = get_real(infile,0);break; /* y1-values */
  3624.                         case 2: double_data[2] = get_real(infile,0);break; /* x2-values */
  3625.                         case 3: double_data[3] = get_real(infile,0);break; /* y2-values */
  3626.                         case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv  */
  3627.                         case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv  */
  3628.                         case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
  3629.                         case 7: stroke_color=get_color(infile,1);/* name or hex color */
  3630.                         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);
  3631.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3632.                         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);
  3633.                         add_to_buffer(tmp_buffer);
  3634.                         if(onclick != 0){object_cnt++;}
  3635.                         break;
  3636.                         default: break;
  3637.                     }
  3638.                     dragstuff[11] = 1;
  3639.                 }
  3640.             }
  3641.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3642.             reset();
  3643.             break;
  3644.  
  3645.         case PLOTSTEPS:
  3646.             /*
  3647.              @ plotsteps a_number
  3648.              @ default 150
  3649.              @ only used for commands <a href="#curve">curve / plot</a> and <a href="#levelcurve">levelcurve</a>
  3650.              @ use with care !
  3651.             */
  3652.             plot_steps = (int) (get_real(infile,1));
  3653.             break;
  3654.  
  3655.         case POINT:
  3656.         /*
  3657.         @ point x,y,color
  3658.         @ draw a single point at (x;y) in color 'color'
  3659.         @ use command <code>linewidth int</code> to adjust size
  3660.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3661.         @ will not resize on zooming (command <code>circle x,y,r,color</code> will resize on zooming)
  3662.         @ attention: in case of command <a href="#rotate">rotate angle</a> a point has rotation center (0:0) in x/y-range
  3663.         @%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
  3664.         */
  3665.             for(i=0;i<3;i++){
  3666.                 switch(i){
  3667.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  3668.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  3669.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  3670.                     if(use_rotate == TRUE ){rotate(2,angle,rotationcenter,2);}
  3671.                     if(use_affine == TRUE ){ transform(2,2);}
  3672.                     if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3673.  
  3674.                     decimals = find_number_of_digits(precision);
  3675.                     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);
  3676.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3677.                     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);
  3678.                     add_to_buffer(tmp_buffer);
  3679.                     /* object_cnt++; */
  3680.                     if(onclick != 0){object_cnt++;}
  3681.                     break;
  3682.                     default: break;
  3683.                 }
  3684.             }
  3685.             dragstuff[2] = 1;
  3686.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3687.             reset();
  3688.             break;
  3689.  
  3690.         case POINTS:
  3691.         /*
  3692.         @ points color,x1,y1,x2,y2,...,x_n,y_n
  3693.         @ draw multiple points at given coordinates in color 'color'
  3694.         @ use command <code>linewidth int</code> to adjust size
  3695.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  3696.         @ attention: in case of command <a href="#rotate">rotate angle</a> the points have rotation center (0:0) in x/y-range
  3697.         @%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
  3698.         @%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
  3699.         */
  3700.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3701.             fill_color = stroke_color;
  3702.             i=0;
  3703.             while( ! done ){     /* get next item until EOL*/
  3704.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3705.                 if(i%2 == 0 ){
  3706.                     double_data[i] = get_real(infile,0); /* x */
  3707.                 }
  3708.                 else
  3709.                 {
  3710.                     double_data[i] = get_real(infile,1); /* y */
  3711.                 }
  3712.                 i++;
  3713.             }
  3714.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  3715.             if(use_affine == TRUE ){ transform(i-1,2);}
  3716.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3717.             decimals = find_number_of_digits(precision);
  3718.             for(c = 0 ; c < i-1 ; c = c+2){
  3719.                 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);
  3720.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3721.                 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);
  3722.                 add_to_buffer(tmp_buffer);
  3723.                 /* object_cnt++; */
  3724.                 if(onclick != 0){object_cnt++;}
  3725.             }
  3726.             dragstuff[2] = 1;
  3727.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3728.             reset();
  3729.             break;
  3730.  
  3731.         case POLY:
  3732.         /*
  3733.         @ poly color,x1,y1,x2,y2...x_n,y_n
  3734.         @ polygon color,x1,y1,x2,y2...x_n,y_n
  3735.         @ draw closed polygon
  3736.         @ use command ''fpoly`` to fill it or use keyword <a href='#filled'>filled</a>
  3737.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3738.         @%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
  3739.         @%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
  3740.         */
  3741.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3742.             i=0;
  3743.             c=0;
  3744.             while( ! done ){     /* get next item until EOL*/
  3745.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3746.                 for( c = 0 ; c < 2; c++){
  3747.                     if(c == 0 ){
  3748.                         double_data[i] = get_real(infile,0);
  3749.                         i++;
  3750.                     }
  3751.                     else
  3752.                     {
  3753.                         double_data[i] = get_real(infile,1);
  3754.                         i++;
  3755.                     }
  3756.                 }
  3757.             }
  3758.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  3759.             if(use_affine == TRUE ){ transform(i-1,2);}
  3760.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3761.  
  3762.             /* draw path:  closed & optional filled */
  3763.             decimals = find_number_of_digits(precision);
  3764.             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);
  3765.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3766.             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);
  3767.             add_to_buffer(tmp_buffer);
  3768.             if(onclick != 0){object_cnt++;}
  3769.             reset();
  3770.             dragstuff[5] = 1;
  3771.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3772.             break;
  3773.  
  3774.         case POLYLINE:
  3775.         /*
  3776.         @ polyline color,x1,y1,x2,y2...x_n,y_n
  3777.         @ brokenline color,x1,y1,x2,y2...x_n,y_n
  3778.         @ path color,x1,y1,x2,y2...x_n,y_n
  3779.         @ 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>
  3780.         @ 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
  3781.         @ 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)
  3782.         @ use command <a href='#segments'>segments</a> for a series of segments. These may be clicked/dragged individually
  3783.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  3784.         @%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
  3785.         @%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
  3786.         */
  3787.  
  3788.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  3789.             i=0;
  3790.             c=0;
  3791.             while( ! done ){     /* get next item until EOL*/
  3792.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3793.                 for( c = 0 ; c < 2; c++){
  3794.                     if(c == 0 ){
  3795.                         double_data[i] = get_real(infile,0);
  3796.                         i++;
  3797.                     }
  3798.                     else
  3799.                     {
  3800.                         double_data[i] = get_real(infile,1);
  3801.                         i++;
  3802.                     }
  3803.                 }
  3804.             }
  3805.  
  3806.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  3807.             if(use_affine == TRUE ){ transform(i-1,2);}
  3808.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  3809.  
  3810.             /* draw path: not closed & not filled */
  3811.             decimals = find_number_of_digits(precision);
  3812.             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);
  3813.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3814.             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);
  3815.             add_to_buffer(tmp_buffer);
  3816.             if(onclick != 0){object_cnt++;}
  3817.             /* object_cnt++;*/
  3818.             reset();
  3819.             dragstuff[4] = 1;
  3820.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  3821.             break;
  3822.  
  3823.         case POPUP:
  3824.             /*
  3825.             @ popup
  3826.             @ keyword (no arguments)
  3827.             @ if fly-script starts with keyword ''popup``, the canvas image will be exclusively in a popup window (xsize px &times; ysize px)
  3828.             @ 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``
  3829.             @ the popup window will be embedded into the page as a normal image, when ''status=done``; override with keyword <a href="#status">nostatus</a>
  3830.             @ 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>
  3831.             @ 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
  3832.             @%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
  3833.             */
  3834.             use_tooltip = 2;
  3835.             break;
  3836.  
  3837.         case PROTRACTOR:
  3838.         /*
  3839.          @ protractor x,y,x_width,type,mode,use_a_scale
  3840.          @ x,y are the initial location
  3841.          @ x_width: give the width in x-coordinate system (e.g. not in pixels !)
  3842.          @ type = 1: a triangle range 0 - 180<br>type = 2: a circle shape 0 - 360
  3843.          @ 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
  3844.          @ 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>
  3845.          @ use_scale = 1: the protractor will have some scale values printed; use_scale=0 to disable
  3846.          @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor...
  3847.          @ commands ''stroke_color | fill_color | linewidth | opacity | font_family`` will determine the looks of the protractor.
  3848.          @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br>use command ''precision`` to set the reply precision.
  3849.          @ if combined with a ruler, use replyformat = 32
  3850.          @ command <code>snap_to_grid</code> may be used to assist the pupil at placing the protractor
  3851.          @ 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...
  3852.          @ only one protractor allowed (for the time being)
  3853.          @ 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...
  3854.          @%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
  3855.         */
  3856.             for( i = 0;i < 6; i++ ){
  3857.                 switch(i){
  3858.                     case 0: double_data[0] = get_real(infile,0);break; /* x-center */
  3859.                     case 1: double_data[1] = get_real(infile,0);break; /* y-center */
  3860.                     case 2: double_data[2] = get_real(infile,0);break; /* x-width */
  3861.                     case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */
  3862.                     case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */
  3863.                     case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */
  3864.                     decimals = find_number_of_digits(precision);
  3865.                     if( int_data[1] < 0 ){ js_function[JS_FIND_ANGLE] = 1;}
  3866.                     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);
  3867.  
  3868.                     string_length = 1 + snprintf(NULL,0,";protractor%d(); ",canvas_root_id);
  3869.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3870.                     snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id);
  3871.                     add_to_buffer(tmp_buffer);
  3872.                     reply_precision = precision;
  3873.                     /* no reply from protractor if non-interactive */
  3874.                     if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;}
  3875.                     js_function[INTERACTIVE] = 1;
  3876.                     break;
  3877.                     default: break;
  3878.                 }
  3879.             }
  3880.             break;
  3881.  
  3882.         case PIXELS:
  3883.         /*
  3884.         @ pixels color,x1,y1,x2,y2,x3,y3...
  3885.         @ draw rectangular "points" with diameter 1 pixel
  3886.         @ pixels can <b>not</b> be dragged or clicked
  3887.         @ "pixelsize = 1" may be changed by command <code>pixelsize int</code>
  3888.         @%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...
  3889.         */
  3890.             js_function[DRAW_PIXELS] = 1;
  3891.             stroke_color=get_color(infile,0);
  3892.             i=0;
  3893.             c=0;
  3894.             while( ! done ){     /* get next item until EOL*/
  3895.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  3896.                 for( c = 0 ; c < 2; c++){
  3897.                     if(c == 0 ){
  3898.                         double_data[i] = get_real(infile,0);
  3899.                         i++;
  3900.                     }
  3901.                     else
  3902.                     {
  3903.                         double_data[i] = get_real(infile,1);
  3904.                     }
  3905.                 }
  3906.             }
  3907.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  3908.             if(use_affine == TRUE ){ transform(i-1,2);}
  3909.             decimals = find_number_of_digits(precision);
  3910.             /*  *double_xy2js_array(double xy[],int len,int decimals) */
  3911.             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);
  3912.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3913.             snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  3914.             add_to_buffer(tmp_buffer);
  3915.             reset();
  3916.             break;
  3917.  
  3918.         case PIXELSIZE:
  3919.         /*
  3920.         @ pixelsize int
  3921.         @ in case you want to deviate from default pixelsize = 1(...)
  3922.         @ pixelsize 100 is of course a filled rectangle 100px &times; 100px
  3923.         */
  3924.             pixelsize = (int) get_real(infile,1);
  3925.         break;
  3926.  
  3927.         case PIECHART:
  3928.         /*
  3929.         @ piechart xc,yc,radius,'data+colorlist'
  3930.         @ (xc: yc) center of circle diagram in xrange/yrange
  3931.         @ radius in pixels
  3932.         @ 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
  3933.         @ example data+colorlist: 32:red:65:green:23:black:43:orange:43:yellow:14:white
  3934.         @ the number of colors must match the number of data.
  3935.         @ 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,...
  3936.         @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of colours
  3937.         @ 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.
  3938.         @ 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.
  3939.         @%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%
  3940.         @%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
  3941.         */
  3942.             js_function[DRAW_PIECHART] = 1;
  3943.             for(i=0;i<5;i++){
  3944.                 switch(i){
  3945.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  3946.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  3947.                     case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
  3948.                     case 3: temp = get_string(infile,1);
  3949.                             if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
  3950.                             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);
  3951.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  3952.                             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);
  3953.                             add_to_buffer(tmp_buffer);
  3954.                            break;
  3955.                     default:break;
  3956.                 }
  3957.             }
  3958.             reset();
  3959.         break;
  3960.  
  3961.         case RANGE:
  3962.         /*
  3963.         @ range xmin,xmax,ymin,ymax
  3964.         @ if not given: 0,xsize,0,ysize (eg in pixels)
  3965.         */
  3966.             for(i = 0 ; i<4; i++){
  3967.                 switch(i){
  3968.                     case 0: xmin = get_real(infile,0);break;
  3969.                     case 1: xmax = get_real(infile,1);break;
  3970.                     case 2: ymin = get_real(infile,0);break;
  3971.                     case 3: ymax = get_real(infile,1);break;
  3972.                     default: break;
  3973.                 }
  3974.             }
  3975.             if(xmin >= xmax){canvas_error(" xrange is not OK: xmin &lt; xmax !");}
  3976.             if(ymin >= ymax){canvas_error(" yrange is not OK: ymin &lt; ymax !");}
  3977.             fprintf(js_include_file,"var xmin = %f;var xmax = %f;var ymin = %f;var ymax = %f;",xmin,xmax,ymin,ymax);
  3978.             found_size_command = found_size_command+2;
  3979.             break;
  3980.  
  3981.  
  3982.         case RAYS:
  3983.         /*
  3984.          @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
  3985.          @ draw rays in color 'color' and center (xc:yc)
  3986.          @ may be set draggable or onclick (every individual ray)
  3987.          @%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
  3988.          @%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
  3989.         */
  3990.             stroke_color=get_color(infile,0);
  3991.             fill_color = stroke_color;
  3992.             double_data[0] = get_real(infile,0);/* xc */
  3993.             double_data[1] = get_real(infile,0);/* yc */
  3994.             i=2;
  3995.             while( ! done ){     /* get next item until EOL*/
  3996.                 if(i > MAX_INT - 1){canvas_error("in command rays too many points / rays in argument: repeat command multiple times to fit");}
  3997.                 if(i%2 == 0 ){
  3998.                     double_data[i] = get_real(infile,0); /* x */
  3999.                 }
  4000.                 else
  4001.                 {
  4002.                     double_data[i] = get_real(infile,1); /* y */
  4003.                 }
  4004.             fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
  4005.                 i++;
  4006.             }
  4007.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  4008.             if(use_affine == TRUE ){ transform(i-1,2);}
  4009.             if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
  4010.             decimals = find_number_of_digits(precision);
  4011.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4012.             for(c=2; c<i;c = c+2){
  4013.                 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);
  4014.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4015.                 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);
  4016.                 add_to_buffer(tmp_buffer);
  4017.                 /* object_cnt++; */
  4018.                 if(onclick != 0){object_cnt++;}
  4019.             }
  4020.             reset();
  4021.             dragstuff[4] = 1;
  4022.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4023.             break;
  4024.  
  4025.         case RECT:
  4026.         /*
  4027.         @ rect x1,y1,x2,y2,color
  4028.         @ use command <code>frect x1,y1,x2,y2,color</code> for a filled rectangle
  4029.         @ use command/keyword <a href='#filled'>filled</a> before command <code>rect x1,y1,x2,y2,color</code>
  4030.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4031.         @ 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
  4032.         @%rect%size 400,400%xrange -10,10%yrange -10,10%rect 0,0,4,-4,green%rect 0,5,4,1,red
  4033.         */
  4034.             for(i=0;i<5;i++){
  4035.                 switch(i){
  4036.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  4037.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  4038.                     case 2:double_data[4] = get_real(infile,0);break; /* x-values */
  4039.                     case 3:double_data[5] = get_real(infile,0);break; /* y-values */
  4040.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  4041.                         decimals = find_number_of_digits(precision);
  4042.                         double_data[2] = double_data[4];
  4043.                         double_data[3] = double_data[1];
  4044.                         double_data[6] = double_data[0];
  4045.                         double_data[7] = double_data[5];
  4046.                         /* using closed PATH (type=5) in stead of ctx.rect (type=1)!!!
  4047.                             0,1         2,3
  4048.                             6,7         4,5
  4049.                             x = [0,2,4,6]
  4050.                             y = [1,3,5,7]
  4051.                         */
  4052.                         if(use_rotate == TRUE ){rotate(8,angle,rotationcenter,2);}
  4053.                         if(use_affine == TRUE ){ transform(8,2);}
  4054.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4055.                         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);
  4056.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4057.                         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);
  4058.                         add_to_buffer(tmp_buffer);
  4059.                         if(onclick != 0){object_cnt++;}
  4060.                         /* object_cnt++; */
  4061.                         reset();
  4062.                         break;
  4063.                 }
  4064.             }
  4065.             dragstuff[5] = 1;
  4066.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4067.             break;
  4068.  
  4069.         case RECTS:
  4070.         /*
  4071.         @ rects color,x1,y1,x2,y2,.....
  4072.         @ use command <code>frect color,x1,y1,x2,y2,.....</code> for a filled rectangle
  4073.         @ use command/keyword <a href='#filled'>filled</a> before command <code>rects color,x1,y1,x2,y2,....</code>
  4074.         @ use command <code>fillcolor color</code> before ''frects`` to set the fill colour.
  4075.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  4076.         @%rects%size 400,400%xrange -10,10%yrange -10,10%rects red,0,0,4,-4,0,5,4,1
  4077.         */
  4078.         /* using closed PATH (type=5) in stead of ctx.rect (type=1)!!!
  4079.         0,1     2,3 .....8,9    10,11.....
  4080.         6,7     4,5 .....14,15  12,13.....
  4081.         x = [0,2,4,6,8,10,12,14...]
  4082.         y = [1,3,5,7,9,11,13,15...]
  4083.         */
  4084.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  4085.             fill_color = stroke_color;
  4086.             i=0;
  4087.             while( ! done ){     /* get next item until EOL*/
  4088.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4089.                 if(i%2 == 0 ){
  4090.                     double_data[i] = get_real(infile,0); /* x */
  4091.                 }
  4092.                 else
  4093.                 {
  4094.                     double_data[i] = get_real(infile,1); /* y */
  4095.                 }
  4096.                 i++;
  4097.             }
  4098.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  4099.             if(use_affine == TRUE ){ transform(i-1,2);}
  4100.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4101.  
  4102.             decimals = find_number_of_digits(precision);
  4103.             for(c = 0 ; c < i-1 ; c = c+4){
  4104.                 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);
  4105.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4106.                 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);
  4107.                 add_to_buffer(tmp_buffer);
  4108.                 if(onclick != 0){object_cnt++;}
  4109.                 /* object_cnt++; */
  4110.             }
  4111.             dragstuff[5] = 1;
  4112.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4113.             if(use_rotate == TRUE ){
  4114.              rotate(i-1,angle,rotationcenter,2);
  4115.             }
  4116.             reset();
  4117.             break;
  4118.  
  4119.         case REPLYFORMAT:
  4120.         /*
  4121.         @ replyformat number
  4122.         @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop()
  4123.         @ default values should be fine !
  4124.         @ 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
  4125.         @ the last value for ''precision int`` will be used to calculate the reply coordinates, if needed (read_canvas();)
  4126.         @ 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>
  4127.         @ 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'
  4128.         */
  4129.          reply_format = (int) get_real(infile,1);
  4130.          reply_precision = precision;
  4131.         break;
  4132.  
  4133.         case ROUNDRECT:
  4134.         /*
  4135.         @ roundrect x1,y1,x2,y2,radius in px,color
  4136.         @ use command <code>froundrect x1,y1,x2,y2,radius,color</code> for a filled rectangle
  4137.         @ use command/keyword <a href='#filled'>filled</a> before command <code>roundrect x1,y1,x2,y2,radius,color</code>
  4138.         @ fillcolor will be identical to ''color``
  4139.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4140.         @%roundrect%size 400,400%xrange -10,10%yrange -10,10%roundrect 0,0,4,-4,20,green%roundrect 0,5,4,1,10,red
  4141.         */
  4142.             for(i=0;i<6;i++){
  4143.                 switch(i){
  4144.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  4145.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  4146.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  4147.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  4148.                     case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
  4149.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  4150.                         if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);}
  4151.                         if(use_affine == TRUE ){ transform(2,4);}
  4152.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4153.                         /* ensure no inverted roundrect is produced... */
  4154.                         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];}
  4155.                         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];}
  4156.                         decimals = find_number_of_digits(precision);
  4157.                         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);
  4158.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4159.                         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);
  4160.                         add_to_buffer(tmp_buffer);
  4161.                         if(onclick != 0){object_cnt++;}
  4162.                         /* object_cnt++;*/
  4163.                         reset();
  4164.                     break;
  4165.                 }
  4166.             }
  4167.             dragstuff[6] = 1;
  4168.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4169.             break;
  4170.  
  4171.         case ROUNDRECTS:
  4172.         /*
  4173.         @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,....
  4174.         @ for filled roundrects use command/keyword <a href='#filled'>filled</a> before command
  4175.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  4176.         @%roundrects%size 400,400%xrange -10,10%yrange -10,10%roundrects blue,5,0,0,4,-4,5,4,1,2
  4177.         */
  4178.  
  4179.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  4180.             int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */
  4181.             fill_color = stroke_color;
  4182.             i=0;
  4183.             while( ! done ){     /* get next item until EOL*/
  4184.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4185.                 if(i%2 == 0 ){
  4186.                     double_data[i] = get_real(infile,0); /* x */
  4187.                 }
  4188.                 else
  4189.                 {
  4190.                     double_data[i] = get_real(infile,1); /* y */
  4191.                 }
  4192.                 i++;
  4193.             }
  4194.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  4195.             if(use_affine == TRUE ){ transform(i-1,2);}
  4196.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4197.             decimals = find_number_of_digits(precision);
  4198.             for(c = 0 ; c < i-1 ; c = c+4){
  4199.                 /* ensure no inverted roundrect is produced... */
  4200.                 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];}
  4201.                 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];}
  4202.                 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);
  4203.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4204.                 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);
  4205.                 add_to_buffer(tmp_buffer);
  4206.                 if(onclick != 0){object_cnt++;}
  4207.                 /* object_cnt++; */
  4208.             }
  4209.             dragstuff[6] = 1;
  4210.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4211.             reset();
  4212.             break;
  4213.  
  4214.         case RULER:
  4215.         /*
  4216.         @ ruler x,y,x-width,y-height,mode
  4217.         @ x,y are the initial location
  4218.         @ x-width, y-height are the ruler dimensions width &amp; height in xy-coordinate system
  4219.         @ 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
  4220.         @ 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
  4221.         @ if combined with a protractor, use replyformat = 32
  4222.         @ only one ruler allowed (for the time being)
  4223.         @ 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...
  4224.         @ 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...
  4225.         @%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
  4226.         @%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
  4227.         @%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
  4228.         */
  4229.             for( i = 0;i < 5; i++ ){
  4230.                 switch(i){
  4231.                     case 0: double_data[0] = get_real(infile,0);break; /* x-center */
  4232.                     case 1: double_data[1] = get_real(infile,0);break; /* y-center */
  4233.                     case 2: double_data[2] = get_real(infile,0);break; /* x-width */
  4234.                     case 3: double_data[3] = get_real(infile,0);break; /* y-width */
  4235.                     case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */
  4236.                     decimals = find_number_of_digits(precision);
  4237.                     if( int_data[0] < 0 ){
  4238.                       js_function[JS_FIND_ANGLE] = 1;
  4239.                     }
  4240.                     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);
  4241.                     string_length = 1 + snprintf(NULL,0,";ruler%d(); ",canvas_root_id);
  4242.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4243.                     snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id);
  4244.                     add_to_buffer(tmp_buffer);
  4245.                     reply_precision = precision;
  4246.                     /* no reply from ruler if non-interactive */
  4247.                     if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;}
  4248.                     break;
  4249.                     default: break;
  4250.                 }
  4251.             }
  4252.             break;
  4253.  
  4254.         case RESET:
  4255.         /*
  4256.         @ reset
  4257.         @ keyword
  4258.         @ disables the effects of the <a href="noreset">noreset</a> command
  4259.         @ so the next objects will not be <a href="#filled">filled</a> and <a href="#dashed">dashed</a>
  4260.         */
  4261.          no_reset = FALSE; reset();
  4262.         break;
  4263.  
  4264.         case RESETOFFSET:
  4265.         /*
  4266.          @ resetoffset
  4267.          @ keyword ; use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text
  4268.          @ 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
  4269.         */
  4270.          use_offset = 0;
  4271.          break;
  4272.  
  4273.         case ROTATE:
  4274.         /*
  4275.          @ rotate rotation_angle
  4276.          @ angle in degrees
  4277.          @ (only) the next object will be rotated is given angle
  4278.          @ positive values rotate counter clockwise
  4279.          @ 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)
  4280.          @ 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>
  4281.          @ 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
  4282.          @%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%
  4283.         */
  4284.             use_rotate = TRUE;
  4285.             angle = -1*(get_real(infile,1));/* -1: to be compatible with Flydraw... */
  4286.             break;
  4287.         case ROTATION_CENTER:
  4288.         /*
  4289.         @ rotationcenter x_center,y_center
  4290.         @ define an rotation center in your x/y-coordinate system
  4291.         @ wims will not check the validity of your input; use javascript console to debug any erors
  4292.         @ if not defined a rotation will be around the first point of an object
  4293.         @ to be used before command <a href="#rotate">rotate</a>
  4294.         @ 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))
  4295.         @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given
  4296.         @%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
  4297.         @%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
  4298.         */
  4299.             for( i = 0;i < 2; i++ ){
  4300.                 switch(i){
  4301.                     case 0: rotationcenter[0] = get_real(infile,0);break; /* x-center */
  4302.                     case 1: rotationcenter[1] = get_real(infile,1);break; /* y-center */
  4303.                 }
  4304.                 string_length = 1 + snprintf(NULL,0,"[%f,%f ]",rotationcenter[0],rotationcenter[1]);
  4305.                 check_string_length(string_length);
  4306.                 rotation_center = my_newmem(string_length);
  4307.                 snprintf(rotation_center,string_length,"[%f,%f]",rotationcenter[0],rotationcenter[1]);
  4308.             }
  4309.             break;
  4310.  
  4311.         case SIZE:
  4312.             /*
  4313.             @ size width,height
  4314.             @ set canvas size in pixels
  4315.             @ mandatory first command (can only be preceded by keyword <a href="#popup">popup</a>)
  4316.             @ 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
  4317.             */
  4318.             found_size_command = 1;
  4319.             /* using fabs: however "xsize == int": so "xsize = abs( (int) get_real(infile,0))" would be the idea... */
  4320.             xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
  4321.             ysize = (int)(fabs(round(get_real(infile,1))));
  4322.             /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
  4323.             xmin = 0;xmax = xsize;
  4324.             ymin = 0;ymax = ysize;
  4325.  
  4326. /*
  4327.  The sequence in which stuff is finally printed is important !!
  4328. */
  4329. fprintf(stdout,"\n\
  4330. <script>\n\
  4331. /*<![CDATA[*/\n\
  4332. if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\
  4333. if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\
  4334. if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\
  4335. canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\
  4336. ",canvas_root_id);
  4337.  
  4338. /* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */
  4339. if( use_tooltip != 2){
  4340.  fprintf(stdout,"<!-- canvasdraw div -->\n\
  4341. <div tabindex=\"0\" id=\"canvas_div%d\" style=\"max-width:%dpx;width:%dpx;height:%dpx\" class=\"canvas_wrapper\" oncontextmenu=\"return false;\">\
  4342.  <canvas class=\"canvas_placeholder\" width=\"%d\" height=\"%d\"></canvas>\
  4343. </div>\n\
  4344. <!-- tooltip and input placeholder -->\n\
  4345. <div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\">\
  4346.  <span id=\"tooltip_placeholder%d\" class=\"tooltip_placeholder\"></span></div>\
  4347. <!-- include actual object code via include file -->\n\
  4348. <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);
  4349. } else {
  4350. /*
  4351. set canvas_div invisible and do not include placeholder in main html page:
  4352. the js-include will also be in a popup window...to be shown when wims &#36;status = done
  4353. */
  4354.  fprintf(stdout,"<!-- canvasdraw div invisible -->\n\
  4355. <div tabindex=\"0\" id=\"canvas_div%d\" class=\"canvas_wrapper\" style=\"display:none;max-width:%dpx;width:%dpx;height:%dpx;\">\
  4356.  <canvas class=\"canvas_placeholder\" width=\"%d\" height=\"%d\"></canvas>\
  4357. </div>\n\
  4358. <div id=\"tooltip_placeholder_div%d\" style=\"display:none;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\">\
  4359.  <span id=\"tooltip_placeholder%d\" class=\"tooltip_placeholder\"></span></div>\
  4360. <!-- include actual object code via include file -->\n\
  4361. <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);
  4362. }
  4363.  
  4364. /* these must be global...it is all really very poor javascript:( */
  4365. fprintf(js_include_file,"\n/* begin generated javascript include for canvasdraw version %s */\n\
  4366. \"use strict\";\n\
  4367. /* these variables and functions must be global */\
  4368. var read_dragdrop%d;\
  4369. var read_canvas_images;\
  4370. var read_canvas%d;\
  4371. var set_clock;\
  4372. var clear_draw_area%d;\
  4373. var update_draw_area%d;\
  4374. var place_image_on_canvas;\
  4375. var draw_boxplot;\
  4376. var redraw_all%d;\
  4377. var userdraw_primitive;\
  4378. var wims_canvas_function%d = function(){\n/* common used stuff */\
  4379. var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\
  4380. var xsize = %d;\
  4381. var ysize = %d;\
  4382. var precision = 100;\
  4383. var canvas_div = document.getElementById(\"canvas_div%d\");\
  4384. 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;};\
  4385. 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;};\
  4386. 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);};};\
  4387. 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);};};\
  4388. 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);};};\
  4389. 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);};};\
  4390. function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
  4391. function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
  4392. function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\
  4393. 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) ));};\
  4394. 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;};\
  4395. var snap_x = 1;var snap_y = 1;\
  4396. function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
  4397. function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\
  4398. 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;};};\
  4399. var xlogbase = 10;\
  4400. var ylogbase = 10;\
  4401. var use_xlogscale = 0;\
  4402. var use_ylogscale = 0;\
  4403. var x_strings = {};var x_strings_up = [];\
  4404. var y_strings = null;\
  4405. var use_jsmath = 0;\
  4406. var xstart = 0;\
  4407. var ystart = 0;\
  4408. var unit_x=\" \";\
  4409. var unit_y=\" \";\
  4410. var dragdrop_reply = [];\
  4411. 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);
  4412. /* var xstart,ystart are normally 0 : in case of sgraph they have the 'jump' in the graph */
  4413.             break;
  4414.  
  4415.  
  4416.         case SEGMENT:
  4417.         /*
  4418.         @ segment x1,y1,x2,y2,color
  4419.         @ alternative: seg
  4420.         @ draw a line segment between points (x1:y1)--(x2:y2) in color ''color``
  4421.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4422.         @%segment_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segment 1,1,-9,3,green
  4423.         @%segment_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segment 1,1,-9,3,green
  4424.         */
  4425.             for(i=0;i<5;i++) {
  4426.                 switch(i){
  4427.                     case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
  4428.                     case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
  4429.                     case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
  4430.                     case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
  4431.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  4432.                         if(use_rotate == TRUE ){rotate(4,angle,rotationcenter,2);}
  4433.                         if(use_affine == TRUE ){ transform(4,2);}
  4434.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4435.                         decimals = find_number_of_digits(precision);
  4436.                         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);
  4437.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4438.                         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);
  4439.                         add_to_buffer(tmp_buffer);
  4440.                         if(onclick != 0){object_cnt++;}
  4441.                         /* object_cnt++; */
  4442.                         reset();
  4443.                         break;
  4444.                     default: break;
  4445.                 }
  4446.             }
  4447.             dragstuff[4] = 1;
  4448.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4449.             break;
  4450.  
  4451.         case SEGMENTS:
  4452.         /*
  4453.         @ segments color,x1,y1,x2,y2,...,x_n,y_n
  4454.         @ alternative: segs
  4455.         @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color ''color``
  4456.         @ use command ''linewidth int`` to adjust size
  4457.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  4458.         @%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
  4459.         @%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
  4460.         */
  4461.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  4462.             fill_color = stroke_color;
  4463.             i=0;
  4464.             while( ! done ){     /* get next item until EOL*/
  4465.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4466.                 if(i%2 == 0 ){
  4467.                     double_data[i] = get_real(infile,0); /* x */
  4468.                 }
  4469.                 else
  4470.                 {
  4471.                     double_data[i] = get_real(infile,1); /* y */
  4472.                 }
  4473.                 i++;
  4474.             }
  4475.             if(use_rotate == TRUE ){rotate(i-1,angle,rotationcenter,2);}
  4476.             if(use_affine == TRUE ){ transform(i-1,2);}
  4477.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4478.             decimals = find_number_of_digits(precision);
  4479.             for(c = 0 ; c < i-1 ; c = c+4){
  4480.                 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);
  4481.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4482.                 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);
  4483.                 add_to_buffer(tmp_buffer);
  4484.                 if(onclick != 0){object_cnt++;}
  4485.                 /* object_cnt++;*/
  4486.             }
  4487.             reset();
  4488.             dragstuff[4] = 1;
  4489.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4490.             break;
  4491.  
  4492.         case SETLIMITS:
  4493.         /*
  4494.             @ setlimits
  4495.             @ keyword: if set, it will produce 4 inputfields for ''xmin,xmax,ymin,ymax`` and an ''ok`` button
  4496.             @ may be used for inputfield based zooming / panning
  4497.             @ may be styled using command <a href="#css">css</a>
  4498.             @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to ''xlabel`` etc
  4499.             @ note: the input value will not be checked on validity
  4500.             @%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
  4501.         */
  4502.             js_function[JS_SAFE_EVAL] = 1;
  4503.             js_function[JSPLOT_AND_ZOOM] = 1;
  4504.             add_setlimits(font_size,css_class);
  4505.             done = TRUE;
  4506.             break;
  4507.  
  4508.         case SETPIXEL:
  4509.         /*
  4510.         @ setpixel x,y,color
  4511.         @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange
  4512.         @ pixels can <b>not</b> be dragged or clicked
  4513.         @ "pixelsize = 1" may be changed by command <code>pixelsize int</code>
  4514.         @%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%
  4515.         */
  4516.             js_function[DRAW_PIXELS] = 1;
  4517.             for(i=0;i<3;i++){
  4518.                 switch(i){
  4519.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  4520.                     case 1: double_data[1] = get_real(infile,0); break; /* y */
  4521.                     case 2: stroke_color = get_color(infile,1);
  4522.                            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);
  4523.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4524.                            snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  4525.                            add_to_buffer(tmp_buffer);
  4526.                            break;
  4527.                     default:break;
  4528.                 }
  4529.             }
  4530.             reset();
  4531.         break;
  4532.         case SLIDER:
  4533.         /*
  4534.         @ slider start_value,end_value,width px,height px,type,label
  4535.         @ type may be: ''x,y,angle``
  4536.         @ if a slider value display is desired, use for argument ''type``: ''x display``, ''y display``, ''angle radian``, ''angle degree``
  4537.         @ is the slider is used for animation, add keyword ''anim`` or ''animate`` to ''type``; for now only one animated slider may be used...
  4538.         @ 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>
  4539.         @ if a unit (or something like that...) for x/y-value display is needed, use commands ''xunit`` and / or ''yunit``
  4540.         @ 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>
  4541.         @ use command ''slider`` before draggable/clickable objects.
  4542.         @ 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'
  4543.         @ no slider for a math function, these can be traced using command ''trace_jscurve some_function_in_x``
  4544.         @ 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``
  4545.         @ amount of sliders is not limited.
  4546.         @ a slider can not be set ''snaptogrid`` or other ''snapto*`` : you may always use 'drag xy' in combination with the slider objects
  4547.         @ <code>javascript:read_dragdrop();</code> will return an array with ''object_number:slider_value``
  4548.         @ every draggable object may have its own slider (no limit in amount of sliders)
  4549.         @ 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.
  4550.         @ use fillcolor for slider controlkey
  4551.         @ use strokecolor for slider bar
  4552.         @ use fontfamily / fontcolor to set used fonts
  4553.         @ use opacity (only fill opacity will be used) to set transparency
  4554.         @ the slider canvas will be added to the ''tooltip div``: so incompatible with command tooltip ; setlimits etc
  4555.         @%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
  4556.         @%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
  4557.         @%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
  4558.         @%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
  4559.         @%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">
  4560.         */
  4561.             js_function[INTERACTIVE] = 1;
  4562.             int_data[2] = 0; /* --> show_display = 0; */
  4563.             for(i=0; i<6 ; i++){
  4564.                 switch(i){
  4565.                     case 0: double_data[0] = get_real(infile,0);break; /* start value */
  4566.                     case 1: double_data[1] = get_real(infile,0);break; /* end value */
  4567.                     case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
  4568.                     case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
  4569.                     case 4: temp = get_string_argument(infile,0); /* type: x,y,angle */
  4570.                             if( strstr(temp,"displ")!=0 ||  strstr(temp,"deg")!=0 ||  strstr(temp,"rad")!=0 ){int_data[5] = 1; }else{int_data[5] = 0;}
  4571.                             if(strstr(temp,"anim")!= 0){int_data[3] = 1;}else{int_data[3] = 0;}
  4572.                             if(strstr(temp,"active")!= 0){onclick = 4;}else{onclick=0;}
  4573.                             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;}}
  4574.                             else
  4575.                             if(strstr(temp,"xy") != 0){slider_type = "XY";if( strstr(temp,"disp")!= 0){int_data[2] = 5;}}
  4576.                             else
  4577.                             if(strstr(temp,"x") != 0){slider_type = "X";if( strstr(temp,"disp")!= 0){int_data[2] = 1;}}
  4578.                             else
  4579.                             if(strstr(temp,"y") != 0){slider_type = "Y";if( strstr(temp,"disp")!= 0){int_data[2] = 2;}}
  4580.                             else
  4581.                             canvas_error("slider can be of type: x,y,angle,fun_x:fun_y");
  4582.                             break;
  4583.                     case 5: temp = get_string_argument(infile,1); if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\""," ");}
  4584.                     /* slider label : in case of latex/mathmlmath we need to remove the extra " */
  4585.                     break;
  4586.                 }
  4587.              }
  4588.  
  4589.             if(use_slider == -1 ){ /* add once */
  4590.              add_slider(int_data[3]);
  4591.              if(int_data[5] == 1 ){add_slider_display(precision,font_size,font_color,stroke_opacity);}
  4592.             }
  4593.             use_slider++;
  4594.             if(int_data[3] == 0){\
  4595.              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]);
  4596.              check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4597.              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]);
  4598.             }else{
  4599.              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]);
  4600.              add_slider(int_data[3]);/* use only once !! */
  4601.              check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4602.              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]);
  4603.             }
  4604.             add_to_buffer(tmp_buffer);
  4605.             fprintf(js_include_file,"var slider%d;",use_slider);
  4606.             use_dragstuff = 2;
  4607. //          dragstuff[22] = 1; /* dragstuff switch no 22 is a slider...*/
  4608.             if(onclick != 4 ){ js_function[INTERACTIVE] = 1; }/* no need to click on object to use slider... */
  4609.             //js_function[JS_ROTATE_MOUSE] = 1;
  4610.             c = 0;
  4611.             for(i=last_slider;i<=use_slider;i++){
  4612.              int_data[c] = i; c++;
  4613.             }
  4614.             my_sliders = data2js_array(int_data,use_slider - last_slider+1);
  4615.         break;
  4616.  
  4617.         case SGRAPH:
  4618.         /*
  4619.          @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
  4620.          @ primitive implementation of a ''broken scale`` graph...
  4621.          @ 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>
  4622.          @%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
  4623.         */
  4624.             js_function[DRAW_SGRAPH] = 1;
  4625.             for(i = 0 ; i < 8 ;i++){
  4626.                 switch(i){
  4627.                     case 0:double_data[0] = get_real(infile,0);break;
  4628.                     case 1:double_data[1] = get_real(infile,0);break;
  4629.                     case 2:double_data[2] = get_real(infile,0);break;
  4630.                     case 3:double_data[3] = get_real(infile,0);break;
  4631.                     case 4:int_data[0] = (int)(get_real(infile,0));break;
  4632.                     case 5:int_data[1] = (int)(get_real(infile,0));break;
  4633.                     case 6:stroke_color = get_color(infile,0);break;
  4634.                     case 7:font_color = get_color(infile,1);
  4635.                     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);
  4636.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4637.                     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);
  4638.                     add_to_buffer(tmp_buffer);
  4639.                     break;
  4640.                     default:break;
  4641.                 }
  4642.             }
  4643.             /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
  4644.             break;
  4645.         case SNAPTOFUNCTION:
  4646.         /*
  4647.         @ snaptofunction some_function_in_x,some_funtion_in_y
  4648.         @ alternative: snaptofun
  4649.         @ the next object will snap to the calculated values
  4650.         @ note: snaptofun is probably not really useful feature...
  4651.         @ if you want only modification of y-values,just use: <code>snaptofunction x,5*sin(1/y)</code>
  4652.         @ if you want only modification of x-values,just use: <code>snaptofunction 5*sin(1/x),y</code>
  4653.         @ for now only one instance of ''snaptofunction`` is allowed
  4654.         @ use rawmath on your functions: no validity checking is done by wims !
  4655.         @ note: switching x and y coordinates? <code>snaptofunction y,x</code>
  4656.         @%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
  4657.         @%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
  4658.         */
  4659.         temp = get_string_argument(infile,0);
  4660.         use_snap = 2;
  4661.             use_snap = 5;
  4662.         js_function[JS_MATH] = 1;
  4663.         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));
  4664.         break;
  4665.         case SNAPTOPOINTS:
  4666.         /*
  4667.         @ snaptopoints x1,y1,x2,y2,x3,y3....
  4668.         @ a userdraw object will snap to these points.
  4669.         @ 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
  4670.         @ a draggable object (use command ''drag x|y|xy``) will snap to the closed of these points when dragged (mouseup)
  4671.         @ other options: use keyword ''snaptogrid``, ''xsnaptogrid`` or ''ysnaptogrid``
  4672.         @%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
  4673.         @%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
  4674.         */
  4675.             i = 0;
  4676.             while( ! done ){     /* get next item until EOL*/
  4677.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  4678.                 if(i%2 == 0 ){
  4679.                     double_data[i] = get_real(infile,0); /* x */
  4680.                 }
  4681.                 else
  4682.                 {
  4683.                     double_data[i] = get_real(infile,1); /* y */
  4684.                 }
  4685.                 i++;
  4686.             }
  4687.             decimals = find_number_of_digits(precision);
  4688.             /* NEED AN EXTRA COUNTER VARIABLE FOR MORE THAN 2 CALLS */
  4689.             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));
  4690.             if( snap_to_points_cnt == 0 ){
  4691.                 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)];};");
  4692.             }else{
  4693.                 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]);");
  4694.             }
  4695.             snap_to_points_cnt = 1; /* do not repeat including the js-functions...just once*/
  4696.             use_snap = 4;
  4697.         break;
  4698.  
  4699.         case SNAPTOGRID:
  4700.         /*
  4701.          @ snaptogrid
  4702.          @ keyword (no arguments required)
  4703.          @ a draggable object (use command ''drag x|y|xy``) will snap to the given grid when dragged (mouseup)
  4704.          @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
  4705.          @ if no grid is defined, points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1)
  4706.          @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
  4707.          @ 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 ...
  4708.          @%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
  4709.          @%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
  4710.         */
  4711.         use_snap = 1;
  4712.         break;
  4713.  
  4714.         case SQUARE:
  4715.         /*
  4716.         @ square x,y,side (px),color
  4717.         @ draw a square with left top corner (x:y) with side ''side`` in color 'color'
  4718.         @ use command <code>fsquare x,y,side,color</code> for a filled square
  4719.         @ use command/keyword <a href='#filled'>filled</a> before command <code>square x,y,side,color</code>
  4720.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  4721.         @%square%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%filled%fillcolor blue%square 0,0,120,green
  4722.         */
  4723.             for(i=0;i<4;i++){
  4724.                 switch(i){
  4725.                     case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
  4726.                     case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
  4727.                     case 2:double_data[2] = get_real(infile,0);break; /* width in px */
  4728.                     case 3:stroke_color = get_color(infile,1);/* name or hex color */
  4729.                            decimals = find_number_of_digits(precision);
  4730.                            double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
  4731.                            double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
  4732.                            if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4733.                            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);
  4734.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4735.                            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);
  4736.                            add_to_buffer(tmp_buffer);
  4737.                            if(onclick != 0){object_cnt++;}/* object_cnt++; */
  4738.                            reset();break;
  4739.                     default: break;
  4740.                 }
  4741.             }
  4742.             dragstuff[1] = 1;
  4743.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4744.             break;
  4745.  
  4746.         case STATUS:
  4747.         /*
  4748.         @ status
  4749.         @ keyword
  4750.         @ alernative: nostatus
  4751.         @ used to override the effects of ''status=done`` in wims (answer.phtml)
  4752.         @ affects ''readonly`` in inputfields / textareas in canvasimage and all userdraw based commands
  4753.         @ 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``
  4754.         */
  4755.  
  4756.             fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
  4757.             break;
  4758.  
  4759.         case STRING:
  4760.         /*
  4761.          @ string color,x,y,the text string
  4762.          @ may be set ''onclick`` or ''drag xy``
  4763.          @ 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
  4764.          @ 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>
  4765.          @ use a command like <code>fontfamily italic 24px Arial</code> to set fonts on browser that support font change
  4766.          @ 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:
  4767.          @%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%
  4768.          @%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
  4769.         */
  4770.             if( use_rotate == TRUE  ){js_function[JS_ROTATE_MOUSE] = 1; }
  4771.             dragstuff[14] = 1;
  4772.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4773.             for(i=0;i<5;i++){
  4774.                 switch(i){
  4775.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  4776.                     case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
  4777.                     case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
  4778.                     case 3: decimals = find_number_of_digits(precision);
  4779.                     if(use_affine == TRUE ){ transform(2,2);}
  4780.                     /* rotate is done by HTML5/CANVAS context rotation */
  4781.                         temp = get_string_argument(infile,1);
  4782.                         if(strstr(temp,"_") != NULL || strstr(temp,"^") != NULL){js_function[DRAW_SUBSUP] = 1;}
  4783.                         decimals = find_number_of_digits(precision);
  4784.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4785.                         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);
  4786.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4787.                         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);
  4788.                         add_to_buffer(tmp_buffer);
  4789.                         if(onclick != 0){object_cnt++;}
  4790.                         //onclick = 0;
  4791.                         //use_offset = 0;
  4792.                         reset();
  4793.                         break;
  4794.                     default:break;
  4795.                 }
  4796.             }
  4797.             break;
  4798.  
  4799.         case STRINGUP:
  4800.         /*
  4801.          @ stringup color,x,y,rotation_degrees,the text string
  4802.          @ may be set ''onclick`` or ''drag xy``
  4803.          @ 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
  4804.          @ unicode supported: <code>stringup red,0,0,45,\\u2232</code>
  4805.          @ use a command like <code>fontfamily bold 34px Courier</code> to set fonts on browser that support font change
  4806.          @ 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)
  4807.          @ 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>
  4808.          @ super / sub script is supported, using '<b>_</b>' and '<b>^</b>' <br>to end the subscript/supscript, use an extra space...see example:
  4809.          @%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%
  4810.          @%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
  4811.  
  4812.         */
  4813.             /* html5 canvas rotation is only used for text objects  */
  4814.             use_rotate = TRUE ;
  4815.             dragstuff[14] = 1;
  4816.             js_function[JS_ROTATE_MOUSE] = 1;
  4817.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4818.  
  4819.             for(i=0;i<6;i++){
  4820.                 switch(i){
  4821.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  4822.                     case 1: double_data[0] = get_real(infile,0);break; /* x */
  4823.                     case 2: double_data[1] = get_real(infile,0);break; /* y */
  4824.                     case 3: angle = get_real(infile,0);break;/* rotation */
  4825.                     case 4: decimals = find_number_of_digits(precision);
  4826.                         temp = get_string_argument(infile,1);
  4827.                         if(strstr(temp,"_") != NULL || strstr(temp,"^") != NULL){js_function[DRAW_SUBSUP] = 1;}
  4828.                         decimals = find_number_of_digits(precision);
  4829.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4830.                         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);
  4831.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4832.                         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);
  4833.                         add_to_buffer(tmp_buffer);
  4834.                         if(onclick != 0){object_cnt++;}
  4835.                         //onclick = 0;
  4836.                         //use_offset = 0;
  4837.                         reset();
  4838.                         break;
  4839.                     default:break;
  4840.                 }
  4841.             }
  4842.             use_rotate = FALSE;
  4843.             break;
  4844.  
  4845.         case STYLE:
  4846.         /*
  4847.          @ highlight color,opacity,linewidth
  4848.          @ NOT IMPLEMENTED
  4849.          @ use command ''onclick``: when the object receives a userclick it will increase its linewidth
  4850.         */
  4851.             break;
  4852.  
  4853.  
  4854.         case STROKECOLOR:
  4855.         /*
  4856.         @ strokecolor colorname or #hex
  4857.         @ to be used for commands that do not supply a color argument (like command ''linegraph``)
  4858.         */
  4859.             stroke_color = get_color(infile,1);
  4860.             break;
  4861.  
  4862.         case FLY_TEXT:
  4863.         /*
  4864.         @ text fontcolor,x,y,font,text_string
  4865.         @ font may be described by keywords: giant,huge,normal,small,tiny
  4866.         @ use command ''fontsize`` to increase base fontsize for these keywords
  4867.         @ may be set ''onclick`` or ''drag xy``
  4868.         @ backwards compatible with flydraw
  4869.         @ unicode supported: text red,0,0,huge,\\u2232
  4870.         @ special: use '_' and '^' to imitate html sup/sub, like H_3O^+ + OH^\\u22i2  \\u2192 2H_2 O
  4871.         @ 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
  4872.         @ 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
  4873.         @ 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.
  4874.         @%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
  4875.         */
  4876.             for(i = 0; i < 5 ;i++){
  4877.                 switch(i){
  4878.                     case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
  4879.                     case 1: double_data[0] = get_real(infile,0);break; /* x */
  4880.                     case 2: double_data[1] = get_real(infile,0);break; /* y */
  4881.                     case 3: fly_font = get_string_argument(infile,0);
  4882.                             if(strcmp(fly_font,"giant") == 0){
  4883.                                 fly_font_size = (int)(font_size + 24);
  4884.                             }
  4885.                             else
  4886.                             {
  4887.                                 if(strcmp(fly_font,"huge") == 0){
  4888.                                     fly_font_size = (int)(font_size + 14);
  4889.                                 }
  4890.                                 else
  4891.                                 {
  4892.                                     if(strcmp(fly_font,"large") == 0){
  4893.                                         fly_font_size = (int)(font_size + 6);
  4894.                                         }
  4895.                                         else
  4896.                                         {
  4897.                                             if(strcmp(fly_font,"small") == 0){
  4898.                                                 fly_font_size = (int)(font_size - 4);
  4899.                                                 if(fly_font_size<0){fly_font_size = 8;}
  4900.                                         }
  4901.                                     }
  4902.                                 }
  4903.                             }
  4904.                             break;
  4905.                     case 4:
  4906.                         temp = get_string_argument(infile,1);
  4907.                         if(strstr(temp,"_") != NULL || strstr(temp,"^") != NULL){js_function[DRAW_SUBSUP] = 1;}
  4908.                         decimals = find_number_of_digits(precision);
  4909.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  4910.                         if(use_affine == TRUE ){ transform(2,2);}
  4911.                         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);
  4912.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4913.                         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);
  4914.                         add_to_buffer(tmp_buffer);
  4915.                         if(onclick != 0){object_cnt++;}
  4916.                         reset();
  4917.                         break;
  4918.                     default:break;
  4919.                 }
  4920.             }
  4921.             dragstuff[14] = 1;
  4922.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  4923.             break;
  4924.         case TEXTAREA:
  4925.         /*
  4926.          @ textarea x,y,cols,rows,readonly,value
  4927.          @ may be further controlled by <a href="#css">css</a>
  4928.          @ 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>.
  4929.          @ 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>)
  4930.          @ keyword ''xoffset | centered`` is not active for command ''textarea``
  4931.          @%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,?
  4932.         */
  4933.             js_function[DRAW_TEXTAREAS] = 1;
  4934.             for(i = 0 ; i<6;i++){
  4935.                 switch(i){
  4936.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
  4937.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
  4938.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
  4939.                     case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
  4940.                     case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
  4941.                     case 5: temp = get_string_argument(infile,1);
  4942.                             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);
  4943.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4944.                             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);
  4945.                             add_to_buffer(tmp_buffer);
  4946.                             input_cnt++;break;
  4947.                     default: break;
  4948.                 }
  4949.             }
  4950.             if(reply_format == 0 ){reply_format = 15;}
  4951.             reset();
  4952.             break;
  4953.  
  4954.         case TEXTFILL:
  4955.         /*
  4956.         @ textfill x0,y0,color,some_text
  4957.         @ x0,y0 in xrange / yrange
  4958.         @ color will be used for the font color
  4959.         @ use command <a href="#fontfamily">fontfamily</a> to set font type and size
  4960.         @ there is also a command <a href="#userdraw">userdraw textfill,color,some_text</a>
  4961.         @%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
  4962.         */
  4963.  
  4964.             js_function[DRAW_TEXTFILL] = 1;
  4965.             if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  4966.              js_function[DRAW_FILLTOBORDER] = 1;
  4967.              add_js_filltoborder(canvas_type);
  4968.             }
  4969.             decimals = find_number_of_digits(precision);
  4970.             for(i=0;i<4;i++){
  4971.                 switch(i){
  4972.                     case 0: double_data[0] = get_real(infile,0); break; /* x in px */
  4973.                     case 1: double_data[1] = get_real(infile,0); break; /* y in py */
  4974.                     case 2: font_color = get_color(infile,0); break;
  4975.                     case 3: temp = get_string(infile,1);
  4976.                     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);
  4977.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  4978.                     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);
  4979.                     add_to_buffer(tmp_buffer);
  4980.                     fill_cnt++;
  4981.                     break;
  4982.                     default:break;
  4983.                 }
  4984.             }
  4985.             reset();
  4986.         break;
  4987.  
  4988.  
  4989.         case FLY_TEXTUP:
  4990.         /*
  4991.          @ textup fontcolor,x,y,font,text_string
  4992.          @ can <b>not</b> be set ''onclick`` or ''drag xy`` (because of translaton matrix...mouse incompatible)
  4993.          @ font may be described by keywords: giant,huge,normal,small,tiny
  4994.          @ use command ''fontsize`` to increase base fontsize for the keywords
  4995.          @ backwards compatible with flydraw
  4996.          @ unicode supported: textup red,0,0,huge,\\u2232
  4997.          @ use command ''stringup`` and ''fontfamily`` for a more fine grained control over html5 canvas text element
  4998.          @ 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.
  4999.         */
  5000.             js_function[DRAW_TEXTS] = 1;
  5001.             for(i = 0; i<5 ;i++){
  5002.                 switch(i){
  5003.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  5004.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  5005.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  5006.                     case 3: fly_font = get_string_argument(infile,0);
  5007.                             if(strcmp(fly_font,"giant") == 0){
  5008.                                 fly_font_size = (int)(font_size + 24);
  5009.                             }
  5010.                             else
  5011.                             {
  5012.                                 if(strcmp(fly_font,"huge") == 0){
  5013.                                     fly_font_size = (int)(font_size + 14);
  5014.                                 }
  5015.                                 else
  5016.                                 {
  5017.                                     if(strcmp(fly_font,"large") == 0){
  5018.                                         fly_font_size = (int)(font_size + 6);
  5019.                                         }
  5020.                                         else
  5021.                                         {
  5022.                                             if(strcmp(fly_font,"small") == 0){
  5023.                                                 fly_font_size = (int)(font_size - 4);
  5024.                                                 if(fly_font_size<0){fly_font_size = 8;}
  5025.                                         }
  5026.                                     }
  5027.                                 }
  5028.                             }
  5029.                             break;
  5030.                     case 4:
  5031.                     decimals = find_number_of_digits(precision);
  5032.                     temp = get_string_argument(infile,1);
  5033.                     if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  5034.                     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);
  5035.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5036.                     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);
  5037.                     add_to_buffer(tmp_buffer);
  5038.                     reset();
  5039.                     //use_offset = 0;
  5040.                     break;
  5041.                     default:break;
  5042.                 }
  5043.             }
  5044.             break;
  5045.  
  5046.  
  5047.         case TRACE_JSCURVE:
  5048.         /*
  5049.          @ trace_jscurve some_math_function
  5050.          @ will use a crosshair to trace the jsmath curve
  5051.          @ two inputfields will display the current x/y-values (numerical evaluation by javascript)
  5052.          @ 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
  5053.          @ use commands fontsize and css to format the fonts for labels and inputfields.
  5054.          @ use commands ''linewidth, strokecolor, crosshairsize`` to adjust the corsshair.
  5055.          @ 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...)
  5056.          @ be aware that the formulas of the plotted function(s) can be found in the page javascript source
  5057.          @%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
  5058.         */
  5059.             js_function[INTERACTIVE] = 1;
  5060.             js_function[DRAW_CROSSHAIRS] = 1;
  5061.             js_function[DRAW_LINES] = 1;
  5062.             js_function[JS_MATH] = 1;
  5063.             add_trace_js_mouse(TRACE_CANVAS,stroke_color,get_string(infile,1),font_size,stroke_opacity,line_width,crosshair_size,css_class);
  5064.             break;
  5065.  
  5066.  
  5067.         case TRANGE:
  5068.         /*
  5069.         @ trange tmin,tmax
  5070.         @ alternative: ranget
  5071.         @ default -2,2
  5072.         */
  5073.             use_parametric = TRUE;
  5074.             for(i = 0 ; i<2; i++){
  5075.                 switch(i){
  5076.                     case 0: tmin = get_real(infile,0);break;
  5077.                     case 1: tmax = get_real(infile,1);break;
  5078.                     default: break;
  5079.                 }
  5080.             }
  5081.             if(tmin >= tmax ){canvas_error(" trange is not OK: tmin &lt; tmax!\n");}
  5082.             break;
  5083.         case TRANSLATION:
  5084.         /*
  5085.          @ translation tx,ty
  5086.          @ alternative: translate
  5087.          @ will translate the next objects tx in xrange and ty in yrange
  5088.          @ use command ''killtranstation`` to end the command
  5089.          @%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
  5090.         */
  5091.             for(i = 0 ; i<2;i++){
  5092.                 switch(i){
  5093.                     case 0: affine_matrix[4] = get_real(infile,0);break;
  5094.                     case 1: affine_matrix[5] = get_real(infile,1);
  5095.                         use_affine = TRUE;
  5096.                         /* the other values affine_matrix[0..3] remain untouched*/
  5097.                         break;
  5098.                     default: break;
  5099.                 }
  5100.             }
  5101.         break;
  5102.  
  5103.         case TRIANGLE:
  5104.         /*
  5105.          @ triangle x1,y1,x2,y2,x3,y3,color
  5106.          @ use ftriangle or keyword <a href='#filled'>filled</a> for a solid triangle
  5107.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  5108.          @%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
  5109.         */
  5110.             for(i=0;i<7;i++){
  5111.                 switch(i){
  5112.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  5113.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  5114.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  5115.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  5116.                     case 4: double_data[4] = get_real(infile,0);break; /* x */
  5117.                     case 5: double_data[5] = get_real(infile,0);break; /* y */
  5118.                     case 6: stroke_color = get_color(infile,1);/* name or hex color */
  5119.                         decimals = find_number_of_digits(precision);
  5120.                         if( use_rotate == TRUE ){ rotate(6,angle,rotationcenter,2);}
  5121.                         if( use_affine == TRUE ){ transform(6,2);}
  5122.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  5123.                         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);
  5124.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5125.                         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);
  5126.                         add_to_buffer(tmp_buffer);
  5127.                         if(onclick != 0){object_cnt++;}
  5128.                         /* object_cnt++;*/
  5129.                         reset();
  5130.                         break;
  5131.                     default: break;
  5132.                 }
  5133.             }
  5134.             dragstuff[5] = 1;
  5135.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  5136.             break;
  5137.         case TRIANGLES:
  5138.         /*
  5139.          @ triangles color,x1,y1,x2,y2,x3,y3,...
  5140.          @ use ftriangles or keyword <a href='#filled'>filled</a> for solid triangles
  5141.          @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  5142.          @%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
  5143.         */
  5144.             stroke_color = get_color(infile,0);/* name or hex color */
  5145.             i = 0;
  5146.             decimals = find_number_of_digits(precision);
  5147.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  5148.  
  5149.             while( ! done ){
  5150.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5151.                 double_data[0] = get_real(infile,0); /* x1 */
  5152.                 double_data[1] = get_real(infile,0); /* y1 */
  5153.                 double_data[2] = get_real(infile,0); /* x2 */
  5154.                 double_data[3] = get_real(infile,0); /* y2 */
  5155.                 double_data[4] = get_real(infile,0); /* x3 */
  5156.                 double_data[5] = get_real(infile,1); /* y3 */
  5157.                 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);
  5158.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5159.                 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);
  5160.                 add_to_buffer(tmp_buffer);
  5161.                 if(onclick != 0){object_cnt++;}
  5162.                 i = i + 6;
  5163.             }
  5164.             reset();
  5165.             dragstuff[5] = 1;
  5166.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  5167.             break;
  5168.         case USERBOXPLOT:
  5169.         /*
  5170.          @ userboxplot
  5171.          @ keyword, no arguments
  5172.          @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a>
  5173.          @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the ''draw_boxplot`` function
  5174.          @ 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)
  5175.         */
  5176.             js_function[DRAW_BOXPLOT] = 1;
  5177.             fprintf(js_include_file,"var boxplot_source = 3;\n");
  5178.             js_function[DRAW_JSBOXPLOT] = 2;
  5179.         break;
  5180.  
  5181.         case USERBOXPLOTDATA:
  5182.         /*
  5183.          @ userboxplotdata
  5184.          @ keyword, no arguments
  5185.          @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a>
  5186.          @ if set, the student will have to generate some statistical data. These data should be put in a named array ''student_boxplot_data``
  5187.          @ ''min,Q1,median,Q3,max`` are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot.
  5188.          @ see command <a href="#userboxplot">userboxplot</a> for calling 'draw_boxplot()'
  5189.         */
  5190.             js_function[DRAW_BOXPLOT] = 1;
  5191.             fprintf(js_include_file,"var boxplot_source = 2;\n");
  5192.             js_function[DRAW_JSBOXPLOT] = 1;
  5193.  
  5194.         break;
  5195.  
  5196.         case USERDRAW:
  5197.         /*
  5198.         @ userdraw object_type,color
  5199.         @ only a single object_type is allowed.
  5200.         @ right mouse click will remove last drawn object.
  5201.         @ for multiple different 'userdraw' objects in an exercise, use command <a href="#multidraw">multidraw</a>
  5202.         @ 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>
  5203.         @ 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)
  5204.         @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br>Use command ''fontfamily`` to set font
  5205.         @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
  5206.         @ 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)
  5207.         @ 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 !
  5208.         @ for non solid filling, use command <a href="#fillpattern">fillpattern grid,hatch,diamond,dot</a>
  5209.         @ use <a href='#opacity'>opacity int,int</a> and <a href='#fillcolor'>fillcolor color</a> to trigger coloured filling of fillable objects
  5210.         @ use command ''dashed`` and/or ''dashtype int,int`` to trigger dashing
  5211.         @ use command ''replyformat int`` to control / adjust output formatting of javascript function read_canvas(); (the defaults should be fine...)
  5212.         @ may be combined with onclick or drag xy of other components of flyscript objects (although not very useful...)
  5213.         @ may be combined with keyword <a href='#userinput_xy'>userinput_xy</a>
  5214.         @ may be combined width the <a href='#snaptogrid'>snaptogrid snaptopoints </a> etc, to simplify the checking of the student reply
  5215.         @ the cursor may be appropriately styled using command <a href='cursor'>cursor</a>
  5216.         @ 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...
  5217.         @ 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)
  5218.         @ 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!)
  5219.         @ note: command <br><code>userdraw function,color</code> is identical to acombination of <code>strokecolor color</code> and <code>userinput function</code><br>
  5220.         @ 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>
  5221.         @%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
  5222.         @%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
  5223.         @%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
  5224.         @%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
  5225.         @%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
  5226.         @%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
  5227.         @%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
  5228.         @%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
  5229.         @%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
  5230.         @%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
  5231.         @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
  5232.         @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
  5233.         @%userdraw_vline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vline,green
  5234.         @%userdraw_vlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vlines,green
  5235.         @%userdraw_hline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hline,green
  5236.         @%userdraw_hlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hlines,green
  5237.         @%userdraw_demiline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demiline,green
  5238.         @%userdraw_demilines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demilines,green
  5239.         @%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
  5240.         @%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
  5241.         @%userdraw_point%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw point,green
  5242.         @%userdraw_points%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw points,green
  5243.         @%userdraw_arrow%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow,green
  5244.         @%userdraw_arrows%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows,green
  5245.         @%userdraw_arrow2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow2,green
  5246.         @%userdraw_arrows2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows2,green
  5247.         @%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
  5248.         @%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
  5249.         @%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
  5250.         @%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
  5251.         @%userdraw_crosshair%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshair,green
  5252.         @%userdraw_crosshairs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshairs,green
  5253.         @%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
  5254.         @%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
  5255.         @%userdraw_segment%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segment,green
  5256.         @%userdraw_segments%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segments,green
  5257.         @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
  5258.         @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
  5259.         @%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
  5260.         @%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
  5261.         @%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
  5262.         @%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
  5263.         @%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
  5264.         @%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
  5265.         @%userdraw_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandline,green
  5266.         @%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
  5267.         @%userdraw_freehandlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandlines,green
  5268.         @%userdraw_input%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw input,green
  5269.         @%userdraw_inputs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw inputs,green
  5270.         @%userdraw_text%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%fontfamily 42px Courier%userdraw text,green
  5271.         @%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
  5272.         @%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
  5273.         @%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
  5274.         @%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
  5275.         @%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
  5276.         */
  5277.             if( use_userdraw != 0 ){ /* only one object type may be drawn*/
  5278.                 canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");
  5279.             }
  5280.             js_function[INTERACTIVE] = 1;
  5281.             draw_type = get_string_argument(infile,0);
  5282.             if( strcmp(draw_type,"textfill") == 0){
  5283.              fprintf(js_include_file,"var userdraw_text_string = \"%s\";", get_string(infile,1));
  5284.             }
  5285.             else
  5286.             {
  5287.              if( strcmp(draw_type,"imagefill") == 0){
  5288.               fprintf(js_include_file,"var userdraw_image_url = \"%s\";", get_string(infile,1));
  5289.              }
  5290.              else
  5291.              {
  5292.               stroke_color = get_color(infile,1);
  5293.              }
  5294.             }
  5295.  
  5296.             if( strcmp(draw_type,"clickfill") == 0){use_filled = 1;fill_color = stroke_color;}
  5297.             reply_precision = precision;
  5298.             use_userdraw = 1;
  5299.             fprintf(js_include_file,"\n\
  5300. /* begin userdraw */\
  5301. userdraw_x = new Array();userdraw_y = new Array();userdraw_radius = new Array();\
  5302. var forbidden_zone=[xsize+1,ysize+1];var xy_cnt = 0;\
  5303. var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\
  5304. var context_userdraw = canvas_userdraw.getContext(\"2d\");\
  5305. var use_dashed = %d;\
  5306. 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];};};};\
  5307. context_userdraw.lineWidth = %d;var use_filled = %d;\
  5308. context_userdraw.strokeStyle =  \"rgba(%s,%.2f)\";\
  5309. context_userdraw.font = \"%s\";\
  5310. var user_is_dragging = false;\
  5311. if(wims_status != \"done\"){\
  5312. canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\
  5313. canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\
  5314. canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
  5315. canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\
  5316. canvas_div.addEventListener(\"touchend\" ,function(e){ e.preventDefault();user_drawstop(e.changedTouches[0]);},false);\
  5317. };",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);
  5318.  
  5319.             if( use_filled == 0 ){
  5320.              fprintf(js_include_file,"context_userdraw.fillStyle = \"rgba(255,255,255.0)\";");
  5321.             }
  5322.             else
  5323.             {
  5324.              if( use_filled == 1 ){
  5325.               fprintf(js_include_file,"context_userdraw.fillStyle = \"rgba(%s,%.2f)\";",fill_color,fill_opacity);
  5326.              }
  5327.              else
  5328.              {
  5329.               js_function[DRAW_FILL_PATTERN] = 1;
  5330.               fprintf(js_include_file,"context_userdraw.fillStyle = create_Pattern(0,0,%d,[%s]);\n",use_filled,fill_color);
  5331.              }
  5332.             }
  5333.             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);
  5334.             reset();
  5335.         break;
  5336.  
  5337.         case USERINPUT:
  5338.         /*
  5339.          @ userinput function inputfield
  5340.          @ alternative: userinput_function
  5341.          @ alternative: userinput_xy
  5342.          @ ''inputfield`` is only usable in combination with some ''userdraw draw_type``
  5343.          @ note: the input fields are not cleared after the object is drawn...be aware of multiple idential drawings (many clicks on the ''ok`` button)
  5344.          @ ''userinput function`` may be used any time (e.g. without userdraw)
  5345.          @ multiple ''userinput function`` commands may be used.
  5346.          @ use command <code>functionlabel some_string</code> to define the inputfield text: default value "f(x)="
  5347.          @ use command <code>strokecolor some_color</code> to adjust the plot / functionlabel color
  5348.          @ use command <code>css some_css</code> to adjust the inputfields
  5349.          @ use command <code>fontsize int</code> to adjust the label fonts. (default 12px)
  5350.          @ 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
  5351.          @%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
  5352.          @%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
  5353.          @%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
  5354.          @%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
  5355.         */
  5356.             temp = get_string_argument(infile,1);
  5357.             if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
  5358.              if( js_function[DRAW_JSFUNCTION] != 1 ){
  5359.               js_function[JS_RAWMATH] = 1;
  5360.               js_function[DRAW_JSFUNCTION] = 1;
  5361.               if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  5362.               add_input_jsfunction(css_class,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size);
  5363.               input_cnt++;
  5364.              }
  5365.              else
  5366.              {
  5367.               /* no need to add DRAW_JSFUNCTION, just call it with the parameters */
  5368.               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);
  5369.               input_cnt++;
  5370.              }
  5371.              js_function[JS_MATH] = 1;
  5372.              js_function[JS_PLOT] = 1;
  5373.             }
  5374.             else
  5375.             {
  5376.              if(strstr(temp,"inputfield") != 0 ){
  5377.               js_function[JS_SAFE_EVAL] = 1;
  5378.               js_function[ADD_USER_INPUTS] = 1;
  5379.              }
  5380.              else
  5381.              {
  5382.               canvas_error("userinput argument may be \"function\" or \"inputfield\"");
  5383.              }
  5384.             }
  5385.             break;
  5386.         case USERINPUT_XY:
  5387.         /*
  5388.         @ userinput_xy
  5389.         @ keyword (no arguments required)
  5390.         @ to be used in combination with command "userdraw object_type,color"
  5391.         @ 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)
  5392.         @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
  5393.         @ 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.
  5394.         @ can <b>not</b> be combined with command ''intooltip tiptext`` <br>note: the ''tooltip div element`` is used for placing inputfields
  5395.         @ user drawings will not zoom on zooming (or pan on panning)
  5396.         @ use command ''css some_css`` to adjust the inputarea.
  5397.         @ use command ''fontsize int`` to adjust the text labels (if needed)
  5398.         @%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
  5399.         */
  5400.             /* add simple eval check to avoid code injection with unprotected eval(string) */
  5401.             js_function[JS_SAFE_EVAL] = 1;
  5402.             js_function[ADD_USER_INPUTS] = 1;
  5403.             break;
  5404.  
  5405.         case USERINPUT_FUNCTION:
  5406.         /*
  5407.         @ userinput_function
  5408.         @ alternative: userinput
  5409.         @ keyword (no arguments required)
  5410.         @ if set, a inputfield will be added to the page
  5411.         @ repeat keyword for more function input fields
  5412.         @ the userinput value will be plotted in the canvas
  5413.         @ 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
  5414.         @ 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
  5415.         @ fontsize can be set using command ''fontsize int``
  5416.         @ incompatible with command ''intooltip link_text_or_image``: it uses the tooltip div for adding the inputfield
  5417.         @%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
  5418.         */
  5419.             if( js_function[DRAW_JSFUNCTION] != 1 ){
  5420.              js_function[DRAW_JSFUNCTION] = 1;
  5421.              js_function[JS_RAWMATH] = 1;
  5422.              if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
  5423.              add_input_jsfunction(css_class,function_label,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1],font_size);
  5424.              input_cnt++;
  5425.             }
  5426.             else
  5427.             {
  5428.               /* no need to add DRAW_JSFUNCTION, just call it with the parameters */
  5429.              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);
  5430.              input_cnt++;
  5431.             }
  5432.             js_function[JS_MATH] = 1;
  5433.             js_function[JS_PLOT] = 1;
  5434.             break;
  5435.  
  5436.         case VLINE:
  5437.         /*
  5438.         @ vline x,y,color
  5439.         @ alternative: verticalline
  5440.         @ draw a vertical line through point (x:y) in color 'color'
  5441.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
  5442.         @%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
  5443.         */
  5444.             for(i=0;i<3;i++) {
  5445.                 switch(i){
  5446.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  5447.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  5448.                     case 2: stroke_color=get_color(infile,1);/* name or hex color */
  5449.                         double_data[2] = double_data[0];
  5450.                         decimals = find_number_of_digits(precision);
  5451.                         if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  5452.                         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);
  5453.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5454.                         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);
  5455.                         add_to_buffer(tmp_buffer);
  5456.                         if(onclick != 0){object_cnt++;}
  5457.                         /* object_cnt++; */
  5458.                         reset();
  5459.                     break;
  5460.                 }
  5461.             }
  5462.             dragstuff[4] = 1;
  5463.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  5464.             break;
  5465.  
  5466.         case VLINES:
  5467.         /*
  5468.         @ vlines color,x1,y1,x2,y2....
  5469.         @ alternative: verticallines
  5470.         @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color'
  5471.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
  5472.         @%vlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%vlines red,1,0,2,0,3,0,4,0
  5473.         */
  5474.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5475.             fill_color = stroke_color;
  5476.             i=0;
  5477.             while( ! done ){     /* get next item until EOL*/
  5478.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5479.                 if(i%2 == 0 ){
  5480.                     double_data[i] = get_real(infile,0); /* x */
  5481.                 }
  5482.                 else
  5483.                 {
  5484.                     double_data[i] = get_real(infile,1); /* y */
  5485.                 }
  5486.                 i++;
  5487.             }
  5488.             decimals = find_number_of_digits(precision);
  5489.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  5490.             for(c = 0 ; c < i-1 ; c = c+2){
  5491.                 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);
  5492.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5493.                 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);
  5494.                 add_to_buffer(tmp_buffer);
  5495.                 if(onclick != 0){object_cnt++;}
  5496.                 /* object_cnt++; */
  5497.             }
  5498.             reset();
  5499.             dragstuff[4] = 1;
  5500.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  5501.             break;
  5502.  
  5503.         case VIDEO:
  5504.         /*
  5505.         @ video x,y,w,h,videofile location
  5506.         @ x,y: left top corner of audio element (in xrange / yrange)
  5507.         @ w,y: width and height in pixels
  5508.         @ video format may be in *.mp4 (todo: other formats)
  5509.         @%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
  5510.         */
  5511.             js_function[DRAW_VIDEO] = 1;
  5512.             for(i=0;i<5;i++){
  5513.                 switch(i){
  5514.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  5515.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */
  5516.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  5517.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  5518.                     case 4: temp = get_string(infile,1);
  5519.                             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);
  5520.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5521.                             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);
  5522.                             add_to_buffer(tmp_buffer);
  5523.                             break;
  5524.                     default:break;
  5525.                 }
  5526.             }
  5527.             reset();
  5528.             break;
  5529.  
  5530.         case X_AXIS_STRINGS:
  5531.         /*
  5532.          @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5533.          @ alternative: xaxistext
  5534.          @ usable for commands <a href="#numberline">numberline</a> and <a href="#grid">grid</a> or combinations thereof
  5535.          @ use these x-axis num1...num_n values instead of default xmin...xmax
  5536.          @ in case of command ''grid``. there is no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5537.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
  5538.          @ 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>)
  5539.          @ a javascript error message will flag non-matching value:name pairs
  5540.          @ if the ''x-axis words`` are too big and will overlap, a simple alternating offset will be applied
  5541.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  5542.          @ ''xmajor`` steps should be synchronised with numbers eg. ''1`` in the next example <code>grid 1,100,grey,1,4,6,grey</code>
  5543.          @%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
  5544.         */
  5545.             use_axis_numbering++;
  5546.             temp = get_string(infile,1);
  5547.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5548.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5549.             fprintf(js_include_file,"x_strings[%d] = [\"%s\"];x_strings_up[%d] = null;",use_axis_numbering,temp,use_axis_numbering);
  5550.             break;
  5551.         case X_AXIS_STRINGS_UP:
  5552.         /*
  5553.          @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5554.          @ alternative: xaxistextup
  5555.          @ the text will be rotated 90&deg; up
  5556.          @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5557.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
  5558.          @ use these x-axis num1...num_n values instead of default xmin...xmax
  5559.          @ 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>)
  5560.          @ a javascript error message will flag non-matching value:name pairs
  5561.          @ if the ''x-axis words`` are too big, they will overlap the graph<br> (in this case the text will start from ysize upwards)
  5562.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  5563.          @''xmajor`` steps should be synchronised with numbers eg. "1" in the next example <code>grid 1,100,grey,1,4,6,grey</code>
  5564.          @%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
  5565.         */
  5566.             use_axis_numbering++;
  5567.             temp = get_string(infile,1);
  5568.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5569.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5570.             fprintf(js_include_file,"x_strings_up[%d] = 1;x_strings[%d] = [\"%s\"];",use_axis_numbering,use_axis_numbering,temp);
  5571.             break;
  5572.  
  5573.         case XERRORBARS:
  5574.         /*
  5575.         @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
  5576.         @ 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'
  5577.         @ the errors E1 and E2 values are in xrange.
  5578.         @ use command ''linewidth int`` to adust size
  5579.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  5580.         @%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
  5581.  
  5582.         */
  5583.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5584.             fill_color = stroke_color;
  5585.             i=0;
  5586.             while( ! done ){     /* get next item until EOL*/
  5587.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5588.                 if(i%2 == 0 ){
  5589.                     double_data[i] = get_real(infile,0); /* x */
  5590.                 }
  5591.                 else
  5592.                 {
  5593.                     double_data[i] = get_real(infile,1); /* y */
  5594.                 }
  5595.                 i++;
  5596.             }
  5597.             decimals = find_number_of_digits(precision);
  5598.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  5599.             for(c = 2 ; c < i-1 ; c = c+2){
  5600.                 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);
  5601.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5602.                 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);
  5603.                 add_to_buffer(tmp_buffer);
  5604.                 /* object_cnt++; */
  5605.                 if(onclick != 0){object_cnt++;}
  5606.             }
  5607.             reset();
  5608.             dragstuff[20] = 1;
  5609.             if(use_dragstuff == 0 ){ use_dragstuff = 1; }
  5610.             break;
  5611.  
  5612.         case NEWRANGE:
  5613.         /*
  5614.         @ newrange xmin,xmax,ymin,ymax
  5615.         @ objects defined after command will make use of this new range
  5616.         @ https://wimsedu.info/?topic=dessiner-des-portions-de-fonctions-sur-un-meme-graphe
  5617.         */
  5618.             for(i = 0 ; i<4; i++){
  5619.                 switch(i){
  5620.                     case 0: xmin = get_real(infile,0);break;
  5621.                     case 1: xmax = get_real(infile,0);break;
  5622.                     case 2: ymin = get_real(infile,0);break;
  5623.                     case 3: ymax = get_real(infile,1);break;
  5624.                     default: break;
  5625.                 }
  5626.             }
  5627.             string_length = 1 + snprintf(NULL,0,"\n\nxmin = %f;xmax = %f;ymin = %f;ymax = %f;\n\n",xmin,xmax,ymin,ymax);
  5628.             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5629.             snprintf(tmp_buffer,string_length,"\n\nxmin = %f;xmax = %f;ymin = %f;ymax = %f;\n\n",xmin,xmax,ymin,ymax);
  5630.             add_to_buffer(tmp_buffer);
  5631.             break;
  5632.  
  5633.         case XRANGE:
  5634.         /*
  5635.         @ xrange xmin,xmax
  5636.         @ alternative: rangex
  5637.         @ if not given: 0,xsize (eg in pixels)
  5638.         */
  5639.             for(i = 0 ; i<2; i++){
  5640.                 switch(i){
  5641.                     case 0: xmin = get_real(infile,0);break;
  5642.                     case 1: xmax = get_real(infile,1);break;
  5643.                     default: break;
  5644.                 }
  5645.             }
  5646.             if(xmin >= xmax){canvas_error(" xrange is not OK: xmin &lt; xmax !");}
  5647.             fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax);
  5648.             found_size_command++;
  5649.             break;
  5650.  
  5651.         case XSNAPTOGRID:
  5652.         /*
  5653.          @ xsnaptogrid
  5654.          @ keyword (no arguments required)
  5655.          @ a draggable object (use command ''drag x|y|xy``) will snap to the given x-grid values when dragged (mouseup)
  5656.          @ in case of userdraw the drawn points will snap to xmajor grid
  5657.          @ if no grid is defined, points will snap to every integer xrange value. (eg snap_x=1)
  5658.          @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
  5659.          @ 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>
  5660.          @%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
  5661.          @%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
  5662.  
  5663.         */
  5664.         use_snap = 2;
  5665.         break;
  5666.  
  5667.         case XOFFSET:
  5668.         /*
  5669.          @ xoffset
  5670.          @ keyword ; to place the text centered above the text coordinates(x:y) ...
  5671.          @ may be used for points or other things requiring centered labels
  5672.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5673.          @ 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)
  5674.         @%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
  5675.         */
  5676.          use_offset = 2;
  5677.          break;
  5678.  
  5679.         case XYOFFSET:
  5680.         /*
  5681.          @ xyoffset
  5682.          @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily
  5683.          @ may be used for points or other things requiring labels
  5684.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5685.          @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy
  5686.          @ 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>
  5687.          @%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
  5688.         */
  5689.          use_offset = 3;
  5690.          break;
  5691.  
  5692.         case XUNIT:
  5693.         /*
  5694.          @ xunit some_unit_for_x-values
  5695.          @ unicode allowed (no html code)
  5696.          @ use together with command <a href="#display">display or mouse</a>
  5697.          @ will display the cursor x-coordinate in ''unit``
  5698.          @%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
  5699.         */
  5700.             fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
  5701.             break;
  5702.  
  5703.         case XLABEL:
  5704.         /*
  5705.         @ xlabel some_string
  5706.         @ will be used to create a label for the x-axis (label is in quadrant I)
  5707.         @ can only be used together with command ''grid``<br>not depending on keywords ''axis`` and ''axisnumbering``
  5708.         @ 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)
  5709.         @ use <a href="#ylabel">ylabel</a>
  5710.         @%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
  5711.         */
  5712.             temp = get_string(infile,1);
  5713.             fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
  5714.             break;
  5715.  
  5716.         case XLOGBASE:
  5717.         /*
  5718.         @ xlogbase number
  5719.         @ sets the logbase number for the x-axis
  5720.         @ default value 10
  5721.         @ use together with commands xlogscale / xylogscale
  5722.         */
  5723.             fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
  5724.             break;
  5725.  
  5726.         case XLOGSCALE:
  5727.         /*
  5728.          @ xlogscale ymajor,yminor,majorcolor,minorcolor
  5729.          @ the x/y-range are set using commands <code>xrange xmin,xmax</code> and <code>yrange ymin,ymax</code>
  5730.          @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
  5731.          @ the linewidth is set using command ''linewidth int``
  5732.          @ the opacity of major / minor grid lines is set by command <a href='#opacity'>opacity</a>
  5733.          @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number``
  5734.          @ 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>
  5735.          @ note: the complete canvas will be used for the ''log paper``
  5736.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5737.          @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br>\
  5738.          @ 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
  5739.          @ note: in case of userdraw, the use of keyword <a href='#userinput_xy'>userinput_xy</a> may be handy !
  5740.          @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
  5741.          @ <b>attention</b>: do not use command ''zoom``
  5742.          @%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
  5743.         */
  5744.             use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5745.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5746.             js_function[DRAW_XLOGSCALE] = 1;
  5747.             for(i=0;i<4;i++){
  5748.                 switch(i){
  5749.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  5750.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  5751.                     case 2: stroke_color = get_color(infile,0); break;
  5752.                     case 3: fill_color = get_color(infile,1);
  5753.                         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);
  5754.                         tmp_buffer = my_newmem(string_length);
  5755.                         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);
  5756.                         fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
  5757.                         add_to_buffer(tmp_buffer);
  5758.                         break;
  5759.                     default:break;
  5760.                 }
  5761.             }
  5762.             break;
  5763.  
  5764.         case XYLOGSCALE:
  5765.         /*
  5766.          @ xylogscale majorcolor,minorcolor
  5767.          @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax``
  5768.          @ the linewidth is set using command ''linewidth int``
  5769.          @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]``
  5770.          @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number`` and/or ''ylogbase number``
  5771.          @ 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>
  5772.          @ note: the complete canvas will be used for the ''log paper``
  5773.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5774.          @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br>\
  5775.          @ 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``)
  5776.          @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy !
  5777.          @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
  5778.          @ <b>attention</b>: do not use command ''zoom``
  5779.          @%xylogscale%size 400,400%xrange 10,50000%yrange 10,50000%xlabel x-axis%ylabel y-axis%xylogscale black,grey%display xy,red,22
  5780.         */
  5781.             use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5782.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5783.             js_function[DRAW_XYLOGSCALE] = 1;
  5784.             for(i=0;i<2;i++){
  5785.                 switch(i){
  5786.                     case 0: stroke_color = get_color(infile,0); break;
  5787.                     case 1: fill_color = get_color(infile,1);
  5788.                         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);
  5789.                         tmp_buffer = my_newmem(string_length);
  5790.                         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);
  5791.                         fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
  5792.                         add_to_buffer(tmp_buffer);
  5793.                         break;
  5794.                     default:break;
  5795.                 }
  5796.             }
  5797.         break;
  5798.  
  5799.  
  5800.         case Y_AXIS_STRINGS:
  5801.         /*
  5802.          @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  5803.          @ alternative: yaxistext
  5804.          @ 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>)
  5805.          @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
  5806.          @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
  5807.          @ use these y-axis num1...num_n values instead of default ymin...ymax
  5808.          @ a javascript error message will flag non-matching value:name pairs
  5809.          @ to be used before command grid (see <a href="#grid">command grid</a>)
  5810.          @%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
  5811.         */
  5812.             temp = get_string(infile,1);
  5813.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  5814.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  5815.             fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
  5816.             use_axis_numbering++;
  5817.             break;
  5818.  
  5819.  
  5820.         case YERRORBARS:
  5821.         /*
  5822.         @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
  5823.         @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color 'color'
  5824.         @ the errors E1 and E2 values are in yrange.
  5825.         @ use command ''linewidth int`` to adust size
  5826.         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
  5827.         @%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
  5828.         */
  5829.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  5830.             fill_color = stroke_color;
  5831.             i=0;
  5832.             while( ! done ){     /* get next item until EOL*/
  5833.                 if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
  5834.                 if(i%2 == 0 ){
  5835.                     double_data[i] = get_real(infile,0); /* x */
  5836.                 }
  5837.                 else
  5838.                 {
  5839.                     double_data[i] = get_real(infile,1); /* y */
  5840.                 }
  5841.                 i++;
  5842.             }
  5843.             if( use_slider != -1 && onclick == 0){ onclick = 3; }/* no drag&onclick but slideable */
  5844.             for(c = 2 ; c < i-1 ; c = c+2){
  5845.                 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);
  5846.                 check_string_length(string_length);tmp_buffer = my_newmem(string_length);
  5847.                 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);
  5848.                 add_to_buffer(tmp_buffer);
  5849.                 /* object_cnt++; */
  5850.                 if(onclick != 0){object_cnt++;}
  5851.             }
  5852.             decimals = find_number_of_digits(precision);
  5853.             reset();
  5854.             dragstuff[19] = 1;
  5855.             if(use_dragstuff == 0 ){ use_dragstuff = 1;}
  5856.             break;
  5857.         case YOFFSET:
  5858.         /*
  5859.          @ yoffset
  5860.          @ keyword; to place the text centered above the text coordinates(x:y) ...
  5861.          @ may be used for points or other things requiring centered labels
  5862.          @ use <a href="#fontfamily">fontfamily</a> for setting the font
  5863.          @ 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)
  5864.          @%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
  5865.         */
  5866.          use_offset = 1;
  5867.          break;
  5868.  
  5869.         case YRANGE:
  5870.         /*
  5871.         @ yrange ymin,ymax
  5872.         @ alternative: rangey
  5873.         @ if not given 0,ysize (eg in pixels)
  5874.         */
  5875.             for(i = 0 ; i<2; i++){
  5876.                 switch(i){
  5877.                     case 0: ymin = get_real(infile,0);break;
  5878.                     case 1: ymax = get_real(infile,1);break;
  5879.                     default: break;
  5880.                 }
  5881.             }
  5882.             if(ymin >= ymax){canvas_error(" yrange is not OK: ymin &lt; ymax !<br>");}
  5883.             fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax);
  5884.             found_size_command++;
  5885.             break;
  5886.  
  5887.         case YSNAPTOGRID:
  5888.         /*
  5889.          @ ysnaptogrid
  5890.          @ keyword (no arguments required)
  5891.          @ a draggable object (use command ''drag x|y|xy``) will snap to the given y-grid values when dragged (mouseup)
  5892.          @ in case of userdraw the drawn points will snap to ymajor grid
  5893.          @ if no grid is defined, points will snap to every integer yrange value. (eg snap_y=1)
  5894.          @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
  5895.          @ 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>
  5896.          @%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
  5897.          @%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
  5898.         */
  5899.         use_snap = 3;
  5900.         break;
  5901.  
  5902.         case YLABEL:
  5903.         /*
  5904.         @ ylabel some_string
  5905.         @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
  5906.         @ can only be used together with command <a href="#grid">grid</a><br>not depending on keywords ''axis`` and ''axisnumbering``
  5907.         @ 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)
  5908.         @ use <a href="#xlabel">xlabel</a>
  5909.         @%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
  5910.         */
  5911.             temp = get_string(infile,1);
  5912.             fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
  5913.             break;
  5914.         case YLOGBASE:
  5915.         /*
  5916.         @ ylogbase number
  5917.         @ sets the logbase number for the y-axis
  5918.         @ default value 10
  5919.         @ use together with commands ylogscale / xylogscale
  5920.         */
  5921.             fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
  5922.             break;
  5923.         case YLOGSCALE:
  5924.         /*
  5925.          @ ylogscale xmajor,xminor,majorcolor,minorcolor
  5926.          @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax``
  5927.          @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
  5928.          @ the linewidth is set using command ''linewidth int``
  5929.          @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]``
  5930.          @ default logbase number = 10 ... when needed, set the logbase number with command ''ylogbase number``
  5931.          @ 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>
  5932.          @ note: the complete canvas will be used for the ''log paper``
  5933.          @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
  5934.          @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br>\
  5935.          @ 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``)
  5936.          @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy !
  5937.          @ <b>attention</b>: do not use command ''zoom``
  5938.          @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
  5939.         */
  5940.             use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
  5941.             if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
  5942.             js_function[DRAW_YLOGSCALE] = 1;
  5943.             for(i=0;i<4;i++){
  5944.                 switch(i){
  5945.                     case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
  5946.                     case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
  5947.                     case 2: stroke_color = get_color(infile,0); break;
  5948.                     case 3: fill_color = get_color(infile,1);
  5949.                         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);
  5950.                         tmp_buffer = my_newmem(string_length);
  5951.                         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);
  5952.                         fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
  5953.                         add_to_buffer(tmp_buffer);
  5954.                         break;
  5955.                     default:break;
  5956.                 }
  5957.             }
  5958.             break;
  5959.  
  5960.         case YUNIT:
  5961.         /*
  5962.          @ yunit some_unit_for_y-values
  5963.          @ unicode allowed (no html code)
  5964.          @ use together with command mousey
  5965.          @ will display the cursor y-coordinate in ''unit``
  5966.         */
  5967.             fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
  5968.             break;
  5969.  
  5970.         case ZOOM:
  5971.         /*
  5972.          @ zoom button_color
  5973.          @ introduce a very small ''controlpanel`` at the lower right corner (font size of the panel is fixed to: 22px Arial)
  5974.          @ giving six 15&times;15px ''active`` rectangle areas<br>(''&times;,&darr;,&uarr;,&larr;,&rarr;,&minus;,+``) for zooming and/or panning of the image
  5975.          @ a mouse wheel is active for in/out zooming. Drag panning is not supported (this will conflict with many ''userdraw`` or ''multidraw`` primitives)
  5976.          @ the ''controlpanel`` is not active for a ''userdraw`` mousedown (but it can interfere with some ''userdraw`` types)
  5977.          @ the ''&times;`` symbol will reset to your original xmax/xmin ymax/ymin values.
  5978.          @ choose an appropriate color, so the small ''&times;,&darr;,&uarr;,&larr;,&rarr;,&minus;,+`` are clearly visible
  5979.          @ command ''opacity`` may be used to set stroke_opacity of buttons
  5980.          @ note: on zooming, text will not increase / decrease the font size (todo??)
  5981.          @ note: adding ''zooming`` will increase the size of the javascript include with approx. 11 kb
  5982.         */
  5983.             js_function[INTERACTIVE] = 1;
  5984.             js_function[JS_ZOOM] = 1;
  5985.             if( use_userdraw == 1 ){
  5986.               js_function[USERDRAW_AND_ZOOM] = 1;
  5987.               fprintf(js_include_file,"forbidden_zone = [%d,%d];",xsize-115,ysize - 20);
  5988.             }
  5989.             if(jsplot_cnt != -1){ js_function[JSPLOT_AND_ZOOM] = 1;}
  5990.             stroke_color = get_color(infile,1);
  5991.             /* we use BG_CANVAS (0) */
  5992.             add_js_zoom_buttons(stroke_color,stroke_opacity);
  5993.             done = TRUE;
  5994.             break;
  5995.  
  5996. /* ready */
  5997.         default:sync_input(infile);
  5998.         break;
  5999.     }
  6000.   }
  6001.   /* we are done parsing script file */
  6002.   if(use_dragstuff != 0){
  6003.   /*  add the 20kb drag code: nearly always used ... use_dragstuff==1: no-mouse ! */
  6004.      add_drag_code(DRAG_CANVAS,use_dragstuff,dragstuff,reply_format);
  6005.      if(js_function[JS_ZOOM] == 1){
  6006.         js_function[DRAG_AND_ZOOM] = 1;
  6007.      }
  6008.   }
  6009.  
  6010.   /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize: Quadrant I */
  6011.   if( found_size_command == 1 ){
  6012.     fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
  6013.   }
  6014.   else
  6015.   {
  6016.     if( found_size_command != 3 ){
  6017.      canvas_error("Please specify size first and then both xrange and yrange ...");
  6018.     }
  6019.   }
  6020.  
  6021.   /* if needed, add generic draw functions (grid / xml etc) to buffer: these are no draggable/clickable shapes / objects  ! */
  6022.   add_javascript_function();
  6023.    /* add read_canvas() etc functions if needed */
  6024.   if( reply_format > 0 ){ add_read_canvas(reply_format,reply_precision);}
  6025.   /* no zoom, just add buffer */
  6026.   fprintf(js_include_file,"\n/* add buffer */\n%s};\n/* end wims_canvas_function */\nwims_canvas_function%d();\n",buffer,canvas_root_id);
  6027. /* done writing the javascript include file */
  6028. fclose(js_include_file);
  6029. }
  6030.  
  6031. /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
  6032.  if( use_tooltip > 0 ){
  6033.   if( use_tooltip == 1 ){
  6034.    add_js_tooltip(tooltip_text,bgcolor);
  6035.   }
  6036.   else
  6037.   {
  6038.    if( use_tooltip == 2 ){
  6039.     add_js_popup(getfile_cmd);
  6040.    }
  6041.   }
  6042.  }
  6043. exit(EXIT_SUCCESS);
  6044. }
  6045. /* end main() */
  6046.  
  6047.  
  6048. /******************************************************************************
  6049. **
  6050. **  sync_input
  6051. **
  6052. **  synchronises input line - reads to end of line, leaving file pointer
  6053. **  at first character of next line.
  6054. **
  6055. **  Used by:
  6056. **  main program - error handling.
  6057. **
  6058. ******************************************************************************/
  6059. void sync_input(FILE *infile)
  6060. {
  6061.         int c = 0;
  6062.  
  6063.         if( c == '\n' || c == ';' ) return;
  6064.         while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
  6065.         if( c == EOF ) finished = 1;
  6066.         if( c == '\n' || c == '\r' || c == ';') line_number++;
  6067.         return;
  6068. }
  6069.  
  6070. /******************************************************************************/
  6071.  
  6072.  
  6073. void transform(int num,int incr){
  6074. /*.
  6075. only "double_data[]" is used for transformations !!
  6076. */
  6077.  int i;int ii;double x,y;
  6078.  for(i=0;i<num;i = i+incr){
  6079.   ii = i+1;
  6080.   x = double_data[i]*affine_matrix[0] + double_data[ii]*affine_matrix[1]+affine_matrix[4];
  6081.   y = double_data[i]*affine_matrix[2] + double_data[ii]*affine_matrix[3]+affine_matrix[5];
  6082.  /*
  6083.   printf("(%f:%f) &rarr; (%f:%f)<br>",double_data[i],double_data[ii],x,y);
  6084.  */
  6085.   double_data[i] = x;
  6086.   double_data[ii] = y;
  6087.  }
  6088. }
  6089.  
  6090. void rotate(int num,double angle,double center[],int incr){
  6091.  int i;int ii;double rad = angle * 0.0174532925199;
  6092.  double c = cos(rad);
  6093.  double s = sin(rad);
  6094.  double x,y;
  6095.  for(i=0;i<num;i = i+incr){
  6096.   ii = i+1;
  6097.   x = c*(double_data[i]-center[0]) + s*(double_data[ii] - center[1] ) + center[0];
  6098.   y = c*(double_data[ii]-center[1]) - s*(double_data[i] - center[0] ) + center[1];
  6099.   double_data[i] = x;
  6100.   double_data[ii] = y;
  6101.  // printf("(x:y) - (%f:%f)<br>",x,y);
  6102.  }
  6103. }
  6104. /* not used: see transform()
  6105. void translate(int num){
  6106.  int i;int ii;
  6107.  double x,y;
  6108.  for(i=0;i<num;i = i+2){
  6109.   ii = i+1;
  6110.   x = double_data[i] + affine_matrix[4];
  6111.   y = double_data[ii] + affine_matrix[5];
  6112.   double_data[i] = x;
  6113.   double_data[ii] = y;
  6114.  }
  6115. }
  6116. */
  6117. char *str_replace(const char *str, const char *old, const char *new){
  6118.     if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
  6119.     char *ret, *r;
  6120.     const char *p, *q;
  6121.     size_t oldlen = strlen(old);
  6122.     size_t count = 0;
  6123.     size_t retlen = 0;
  6124.     size_t newlen = strlen(new);
  6125.     if (oldlen != newlen){
  6126.         for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
  6127.             count++;
  6128.             retlen = p - str + strlen(p) + count * (newlen - oldlen);
  6129.         }
  6130.     }
  6131.     else
  6132.     {
  6133.         retlen = strlen(str);
  6134.     }
  6135.  
  6136.     if ((ret = malloc(retlen + 1)) == NULL){
  6137.         ret = NULL;
  6138.         canvas_error("string argument is NULL");
  6139.     }
  6140.     else
  6141.     {
  6142.         for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
  6143.             size_t l = q - p;
  6144.             memcpy(r, p, l);
  6145.             r += l;
  6146.             memcpy(r, new, newlen);
  6147.             r += newlen;
  6148.         }
  6149.         strcpy(r, p);
  6150.     }
  6151.     return ret;
  6152. }
  6153.  
  6154. /******************************************************************************/
  6155.  
  6156. char *get_color(FILE *infile , int last){
  6157.     int c,i = 0,is_hex = 0;
  6158.     char temp[MAX_COLOR_STRING], *string;
  6159.     const char *not_allowed = "0123456789";
  6160.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' )  && ( c != '\t' ) ){
  6161.         if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
  6162.         if( c == '#' ){
  6163.             is_hex = 1;
  6164.         }
  6165.         if( c != ' '){
  6166.             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 !!! ");}}
  6167.             temp[i]=tolower(c);
  6168.             i++;
  6169.         }
  6170.     }
  6171.     if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
  6172.     if( c == '\n' || c == ';'  || c == '\t' ){ done = TRUE; line_number++; }
  6173.     if( c == EOF ){finished = 1;}
  6174.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  6175.     temp[i]='\0';
  6176.     if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
  6177.     if( is_hex == 1 ){
  6178.         char red[3], green[3], blue[3];
  6179.         red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
  6180.         green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
  6181.         blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
  6182.         int r = (int) strtol(red,   NULL, 16);
  6183.         int g = (int) strtol(green, NULL, 16);
  6184.         int b = (int) strtol(blue,  NULL, 16);
  6185.         int L0 = 1+snprintf(NULL,0,"%d,%d,%d",r,g,b);
  6186.         string = my_newmem(L0);
  6187.         snprintf(string,L0,"%d,%d,%d",r,g,b);
  6188.         return string;
  6189.     }
  6190.     else
  6191.     {
  6192.         string = (char *)my_newmem(sizeof(temp));
  6193.         snprintf(string,sizeof(temp),"%s",temp);
  6194.         for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  6195.             if( strcmp( colors[i].name , string ) == 0 ){
  6196.                 return colors[i].rgb;
  6197.             }
  6198.         }
  6199.         canvas_error("I was expecting a color name or hexnumber...but found nothing.");
  6200.     }
  6201.     return "0,0,255";
  6202. }
  6203.  
  6204. char *get_string(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */
  6205.     int c,i=0;
  6206.     char  temp[MAX_BUFFER], *string;
  6207.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){
  6208.         temp[i]=c;
  6209.         i++;
  6210.         if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
  6211.     }
  6212.     if( ( c == '\n' ||  c == '\t'  || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  6213.     if( c == '\n' ||  c == '\t') { done = TRUE; line_number++; }
  6214.     if( c == EOF ) {finished = 1;}
  6215.     temp[i]='\0';
  6216.     if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing!");}
  6217.     string=(char *)my_newmem(strlen(temp));
  6218.     snprintf(string,sizeof(temp),"%s",temp);
  6219.     return string;
  6220. }
  6221.  
  6222. char *get_string_argument(FILE *infile,int last){  /* last = 0: more arguments ; last=1 final argument */
  6223.     int c,i=0;
  6224.     char temp[MAX_BUFFER], *string;
  6225.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){
  6226.         temp[i]=c;
  6227.         i++;
  6228.         if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
  6229.     }
  6230.     if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
  6231.     if( c == '\n' || c == '\t' ) { line_number++; }
  6232.     if( c == EOF ) {finished = 1;}
  6233.     if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");}
  6234.     temp[i]='\0';
  6235. /*
  6236.     17.10.2014 removed (question Perrin)
  6237.     may cause some unwanted effects...
  6238.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma), but found nothing !!");}
  6239. */
  6240.     string=(char *)my_newmem(sizeof(temp));
  6241.     snprintf(string,sizeof(temp),"%s",temp);
  6242.     done = TRUE;
  6243.     return string;
  6244. }
  6245.  
  6246. double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0: more arguments ; last=1 final argument */
  6247.     int c,i=0,found_calc = 0;
  6248.     double y;
  6249.     char tmp[MAX_INT];
  6250.     /*
  6251.      these things are 'allowed functions': *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs
  6252.      but there should be a better way to avoid segfaults !
  6253.     */
  6254.     const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/
  6255.     const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */
  6256.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){
  6257.      if( c != ' ' ){
  6258.       if( i == 0 &&  c == '+' ){
  6259.        continue;
  6260.       }
  6261.       else
  6262.       {
  6263.        c = tolower(c);
  6264.        if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");}
  6265.        if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */
  6266.        tmp[i] = c;
  6267.        i++;
  6268.       }
  6269.      }
  6270.      if( i > MAX_INT - 1){canvas_error("number too large");}
  6271.     }
  6272.     if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
  6273.     if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; }
  6274.     if( c == EOF ){done = TRUE ; finished = 1;}
  6275.     tmp[i]='\0';
  6276.     if( strlen(tmp) == 0 ){canvas_error("expected a number, but found nothing !!");}
  6277.     if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */
  6278.      void *f = eval_create(tmp);
  6279.      assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  6280.      y = eval_x(f, 1);
  6281.      /* if function is bogus; y = 1: so no core dumps */
  6282.      eval_destroy(f);
  6283.     }
  6284.     else
  6285.     {
  6286.      y = atof(tmp);
  6287.     }
  6288.     return y;
  6289. }
  6290.  
  6291.  
  6292. void canvas_error(char *msg){
  6293.     fprintf(stdout,"\n</script><hr><span style=\"color:red\">FATAL syntax error: line %d: %s</span><hr>",line_number,msg);
  6294.     finished = 1;
  6295.     exit(EXIT_SUCCESS);
  6296. }
  6297.  
  6298.  
  6299. /* convert x/y coordinates to pixel */
  6300. int x2px(double x){
  6301.  return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
  6302. }
  6303.  
  6304. int y2px(double y){
  6305.  return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
  6306. }
  6307.  
  6308. double px2x(int x){
  6309.  return (x*(xmax - xmin)/xsize + xmin);
  6310. }
  6311. double px2y(int y){
  6312.  return (y*(ymax - ymin)/ysize + ymin);
  6313. }
  6314.  
  6315. void add_to_buffer(char *tmp){
  6316. //fprintf(stdout,"tmp = %s<br>buffer = %s<br>",tmp,buffer);
  6317.  if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
  6318.  /*  do we have enough space left in buffer[MAX_BUFFER] ? */
  6319.  int space_left = (int) (sizeof(buffer) - strlen(buffer));
  6320.  if( space_left > strlen(tmp)){
  6321.   strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
  6322.  }
  6323.  else
  6324.  {
  6325.   canvas_error("your memory buffer is too big<br>simplify your script...it produces too many lines ");
  6326.  }
  6327.  tmp = NULL;free(tmp);
  6328.  return;
  6329. }
  6330.  
  6331. void reset(){
  6332.  if(no_reset == FALSE){ /* 8/5/2020 */
  6333.   use_filled = FALSE;
  6334.   use_dashed = FALSE;
  6335.   if(onclick != 4 ){onclick = 0;} /* slider param 'active'... onclick=4 */
  6336.   drag_type = -1;
  6337.   use_offset = 0;
  6338.  }
  6339. }
  6340.  
  6341. char *getMML(char *tex){
  6342.  int my_pipe[2];pid_t pid;
  6343.  if(pipe(my_pipe)){canvas_error("mathml(): pipe() failure.\n");}
  6344.   pid = fork();
  6345.   if (pid == (pid_t) 0){
  6346.    char *argv[]={"wims_mathml","--use-zoom","0","--tex-size 100%","--max-mml-size","1024","--tex-string",tex,NULL};
  6347.    close(my_pipe[0]);dup2(my_pipe[1], 1);dup2(my_pipe[1], 2);close(my_pipe[1]);
  6348.    execv("../bin/wims_mathml",argv);canvas_error("could not execute wims_mathml\n");
  6349.   }
  6350.   else
  6351.   {
  6352.   if (pid < (pid_t) 0){
  6353.    close(my_pipe[0]);close(my_pipe[1]);canvas_error("mathml(): fork() failure.\n");
  6354.   }
  6355.   int status;FILE *stream;close(my_pipe[1]);stream = fdopen (my_pipe[0], "r");
  6356.   char buffer[MAX_BUFFER+1];memset(buffer,'\0',MAX_BUFFER);
  6357.   fgets(buffer, MAX_BUFFER, stream);
  6358.   int L0 = 1 + snprintf(NULL,0,"%s", buffer);
  6359.   tex = my_newmem(L0);memset(tex,'\0',L0);
  6360.   snprintf(tex,L0,"%s",buffer);
  6361.   fclose (stream);close(my_pipe[0]);waitpid(pid, &status, 0);
  6362.  }
  6363.  return tex;
  6364. }
  6365.  
  6366. char *getSVGMOL(char *inputtype,char *keys){
  6367.   int idx;
  6368.   char *forbidden[] = {"-O","-H","-z","-L","-o","-m"};
  6369.   char *argv[1+strlen(keys)];
  6370.   argv[0] = "obabel"; argv[1] = "-i"; argv[2] = inputtype;
  6371.   idx = 3;int i;
  6372.   char *ptr = strtok(keys,",");
  6373.   while(ptr != NULL ){
  6374.     for(i = 0 ; i < 6; i++ ){if( strncmp(ptr,forbidden[i],2) == 0 ){return "NOT ALLOWED ARGUMENT";}}
  6375.     argv[idx] = ptr; idx++;
  6376.     if(idx > 18){canvas_error("too many arguments for obabel....see docs<br>");}
  6377.     ptr = strtok(NULL,",");
  6378.   }
  6379.   /* last arguments; no 'javascript', only 'svg to STDOUT' and 'NULL' */
  6380.   argv[idx] = "-xj";argv[idx+1] = "-o"; argv[idx+2] = "svg";argv[idx+3] = NULL;
  6381.   int link[2];
  6382.   pid_t pid;
  6383.   char buffer[MAX_BUFFER+1];
  6384.   memset(buffer,'\0',MAX_BUFFER);
  6385.   if (pipe(link)==-1){canvas_error("pipe");}
  6386.   if ((pid = fork()) == -1){canvas_error("fork");}
  6387.  
  6388.   char *svgmol = "error";
  6389.   int string_length = 0;
  6390.  
  6391.   if(pid == 0) {
  6392.     dup2 (link[1], STDOUT_FILENO);
  6393.     dup2(link[0],  STDERR_FILENO);/* remove annoying messages '1 molecule converted' */
  6394.     close(link[0]);
  6395.     close(link[1]);
  6396.     execvp("obabel",argv);
  6397.   } else {
  6398.     close(link[1]);
  6399.     read(link[0],buffer, sizeof(buffer));
  6400.     close(link[0]);
  6401.     /* need to remover newline from svg-string on freebsd */
  6402.     char *pch = strstr(buffer, "\n");
  6403.     while(pch != NULL){
  6404.      strncpy(pch, " ", 1);
  6405.      pch = strstr(buffer, "\n");
  6406.     }
  6407.     string_length = 1 + snprintf(NULL,0,"%s",buffer);
  6408.     svgmol= my_newmem(string_length);
  6409.     snprintf(svgmol,string_length,"%s",buffer);
  6410.     wait(NULL);
  6411.   }
  6412.  return svgmol;
  6413. }
  6414.  
  6415.  
  6416. /* GNU libmatheval library for evaluating mathematical functions. */
  6417. char *eval(int xsize,int ysize,char *fun,double xmin,double xmax,double ymin,double ymax,int plotsteps,int precision,double rotationcenter[]){
  6418.     void *f;
  6419.     double x;
  6420.     double y;
  6421.     double xorg;
  6422.     int xv;
  6423.     int i = 0;
  6424.     int xstep =(int)(xsize/plotsteps);
  6425.     if( xstep == 0 ){xstep = 1;}
  6426.     double a = (xmax - xmin)/xsize;
  6427.     f = eval_create(fun);
  6428.     assert (f);
  6429.     if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  6430.     /* we supply the true x/y values...draw_curve() will convert these (x:y) to pixels : used for pan/scale */
  6431.     double xydata[MAX_BUFFER+1];/* hmmm */
  6432.     int lim_ymin =(int)( ymin - 4*fabs(ymin));/* 19-4-2015 replacing "abs" by "fabs"*/
  6433.     int lim_ymax =(int)( ymax + 4*fabs(ymax));/* 19-4-2015 replacing "abs" by "fabs"*/
  6434.     double c = 1.0;double s = 1.0;
  6435.     if( use_rotate == TRUE ){s = sin(angle*0.0174533);c = cos(angle*0.0174533);}
  6436.     for ( xv = 0 ;xv < xsize ; xv = xv+xstep ){
  6437.         x = (double) (xv*a + xmin);
  6438.         xorg = x;
  6439.         if( i < MAX_BUFFER - 2){
  6440.             y = eval_x(f, x);
  6441.             if(y < lim_ymax && y > lim_ymin ){
  6442.                 if( use_affine == TRUE ){
  6443.                     x = x*affine_matrix[0] + y*affine_matrix[1]+affine_matrix[4];
  6444.                     y = xorg*affine_matrix[2] + y*affine_matrix[3]+affine_matrix[5];
  6445.                 }
  6446.                 if( use_rotate == TRUE){
  6447.                   x = (c * (x - rotationcenter[0])) + (s * (y - rotationcenter[1])) + rotationcenter[0];
  6448.                   y = (c * (y - rotationcenter[1])) - (s * (xorg - rotationcenter[0])) + rotationcenter[1];
  6449.                 }
  6450.                 xydata[i++] = x;
  6451.                 xydata[i++] = y;
  6452.             }
  6453.         }
  6454.         else
  6455.         {
  6456.             canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps or some other means to reduce the amount of data... ");
  6457.         }
  6458.     }
  6459.     eval_destroy(f);
  6460.     return double_xy2js_array(xydata,i,find_number_of_digits(precision));
  6461. }
  6462. /* plot a very primitive (!) levelcurve : not to be compared with "flydraw levelcurve" */
  6463. char *eval_levelcurve(int xsize,int ysize,char *fun,double xmin,double xmax,double ymin,double ymax,int plotsteps,int precision,double level){
  6464.     void *f = eval_create(fun);
  6465.     assert (f);
  6466.     if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  6467.     double a = (double)((xmax - xmin)/plotsteps);
  6468.     double b = (double)((ymax - ymin)/plotsteps);
  6469.     double x;double y;double diff;
  6470.     double xydata[MAX_BUFFER+1];
  6471.     int i = 0;
  6472.     ymin = ymin - 1;
  6473.     xmin = xmin - 1;
  6474.     ymax = ymax + 1;
  6475.     xmax = xmax + 1;
  6476.     for( x = xmin ;x < xmax ; x = x + a ){
  6477.         for ( y = ymin ;y < ymax ; y = y + b ){
  6478.             if( i < MAX_BUFFER - 2){
  6479.                 diff = level - eval_x_y(f, x,y);
  6480.                 if(diff < 0.1 && diff > -0.1){
  6481.                     xydata[i++] = x;
  6482.                     xydata[i++] = y;
  6483.                 }
  6484.             }
  6485.             else
  6486.             {
  6487.                 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... ");
  6488.             }
  6489.         }
  6490.     }
  6491.     eval_destroy(f);
  6492.     return double_xy2js_array(xydata,i,find_number_of_digits(precision));
  6493. }
  6494.  
  6495. /* plot parametric function */
  6496. char *eval_parametric(int xsize,int ysize,char *fun1,char* fun2,double xmin,double xmax,double ymin,double ymax,
  6497.  double tmin,double tmax,int plotsteps,int precision,double rotationcenter[]){
  6498.     void *fx;
  6499.     void *fy;
  6500.     double t;
  6501.     int i = 0;
  6502.     double tstep = (tmax-tmin)/plotsteps;
  6503.     if( tstep == 0 ){canvas_error("zero step for t variable : reduce plotsteps or inrease trange");}
  6504.     fx = eval_create(fun1);
  6505.     fy = eval_create(fun2);
  6506.     assert(fx);
  6507.     assert(fy);
  6508.     if( fx == NULL || fy == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  6509.     /* we supply the true x/y values...draw_curve() will convert these (x:y) to pixels : used for pan/scale */
  6510.     double xydata[MAX_BUFFER+1];/* hmmm */
  6511.     double x; /* real x-values */
  6512.     double y; /* real y-values */
  6513.     double xorg;
  6514.     /*
  6515.     29/12/2020
  6516.     disabled to try and synchronise curve+affine behaviour in complex scripts produced by "elec, tool circuit" (BPR)
  6517.     int lim_ymin =(int)( ymin - 4*fabs(ymin));
  6518.     int lim_ymax =(int)( ymax + 4*fabs(ymax));
  6519.     */
  6520.     double c = 1.0;double s = 1.0;if( use_rotate == TRUE ){s = sin(angle*0.0174533);c = cos(angle*0.0174533);}
  6521.     for( t = tmin ;t <= tmax ; t = t + tstep ){
  6522.         if( i < MAX_BUFFER - 2 ){
  6523.             y = eval_t(fy, t);
  6524.         /*    if(y > lim_ymin && y < lim_ymax){*/
  6525.                 x = eval_t(fx, t);
  6526.                 if( x == x){ /* no NaN */
  6527.                  xorg = x;
  6528.                  if( use_affine == TRUE ){
  6529.                   x = x*affine_matrix[0] + y*affine_matrix[1]+affine_matrix[4];
  6530.                   y = xorg*affine_matrix[2] + y*affine_matrix[3]+affine_matrix[5];
  6531.                  }
  6532.                  if( use_rotate == TRUE){
  6533.                    x = (c * (x - rotationcenter[0])) + (s * (y - rotationcenter[1])) + rotationcenter[0];
  6534.                    y = (c * (y - rotationcenter[1])) - (s * (xorg - rotationcenter[0])) + rotationcenter[1];
  6535.                  }
  6536.                  xydata[i++] = x;
  6537.                  xydata[i++] = y;
  6538.                 }
  6539.  
  6540.         /*    } */
  6541.         }
  6542.         else
  6543.         {
  6544.             canvas_error("\nYour curve plotting produces too many data \n Use less plotsteps or some other means to reduce the amount of data... ");
  6545.         }
  6546.     }
  6547.     eval_destroy(fx);
  6548.     eval_destroy(fy);
  6549.     return double_xy2js_array(xydata,i,find_number_of_digits(precision));
  6550. }
  6551.  
  6552. char *double_xy2js_array(double xy[],int len,int decimals){
  6553.  /*
  6554.     1,2,3,4,5,6,7,8 --> [1,3,5,7],[2,4,6,8]
  6555.     int xy[] is already checked for errors or overflow in "get_real()"
  6556.     just to be sure we double check the size of "temp"
  6557. */
  6558.     char temp[2*MAX_BUFFER], *string;
  6559.     char *tmp = my_newmem(16);/* <= 9999999999999999  */
  6560.     memset(temp,'\0',2*MAX_BUFFER);/* clear memory */
  6561.     int i;int space_left;
  6562.     temp[0] = '[';/* start js-array */
  6563.     for(i = 0; i < len;i = i + 2){ /*  x_points[] */
  6564.         if(i == len - 2){sprintf(tmp, "%.*f",decimals, xy[i]);}else{sprintf(tmp, "%.*f,",decimals,xy[i]);}
  6565.         space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1);
  6566.         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 ");}
  6567.     }
  6568.     strncat(temp,"],[",4); /* close js x_values array and start new */
  6569.     for(i = 1; i < len;i = i + 2){ /* y_points */
  6570.         if(i == len - 1){ sprintf(tmp, "%.*f",decimals,xy[i]);}else{sprintf(tmp, "%.*f,",decimals,xy[i]);}
  6571.         space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1);
  6572.         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");}
  6573.     }
  6574.     strncat(temp,"]",2);
  6575.     string=(char *)my_newmem(sizeof(temp));
  6576.     snprintf(string,sizeof(temp),"%s",temp);
  6577.     return string;
  6578. }
  6579.  
  6580. char *list2js_array(char *list, char *s){/* abc:defg:hjiuy:qwer --> ["abc","defg","hjiuy","qwer"] */
  6581. #define MAX_ARG 128
  6582.  if( strlen(list)> MAX_ARG - 1){canvas_error("argument is too large (&gt; 128)");}
  6583.  char tmp[MAX_ARG];
  6584.  size_t p = 0;
  6585.  tmp[0] = '[';
  6586.  tmp[1] = '\"';
  6587.  size_t t = 2;
  6588.  while(list[p] != '\0'){
  6589.   if( list[p] == s[0] ){
  6590.    tmp[t++]='\"';tmp[t++]=',';tmp[t++]='\"';
  6591.   }
  6592.   else
  6593.   {
  6594.    tmp[t++] = list[p];
  6595.   }
  6596.   p++;
  6597.  }
  6598.  tmp[t++]='\"';tmp[t++]=']';tmp[t++]= '\0';
  6599.  char *js_array = (char *)my_newmem(sizeof(tmp));
  6600.  snprintf(js_array,sizeof(tmp),"%s",tmp);
  6601.  return js_array;
  6602. }
  6603.  
  6604. char *xy2js_array(int xy[],int len){
  6605.  /*
  6606.     1,2,3,4,5,6,7,8 --> [1,3,5,7],[2,4,6,8]
  6607.     int xy[] is already checked for errors or overflow in "get_real()"
  6608.     just to be sure we double check the size of "temp"
  6609. */
  6610.     char temp[MAX_BUFFER], *string;
  6611.     char *tmp = my_newmem(16);/* <= 9999999999999999  */
  6612.     memset(temp,'\0',MAX_BUFFER);/* clear memory */
  6613.     int i;int space_left;
  6614.     temp[0] = '[';/* start js-array */
  6615.     for(i = 0; i < len;i = i + 2){ /*  x_points[] */
  6616.         if(i == len - 2){sprintf(tmp, "%d", xy[i]);}else{sprintf(tmp, "%d,", xy[i]);}
  6617.         space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1);
  6618.         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 ");}
  6619.     }
  6620.     strncat(temp,"],[",4); /* close js x_values array and start new */
  6621.     for(i = 1; i < len;i = i + 2){ /* y_points */
  6622.         if(i == len - 1){ sprintf(tmp, "%d", xy[i]);}else{sprintf(tmp, "%d,", xy[i]);}
  6623.         space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1);
  6624.         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");}
  6625.     }
  6626.     strncat(temp,"]",2);
  6627.     string=(char *)my_newmem(sizeof(temp));
  6628.     snprintf(string,sizeof(temp),"%s",temp);
  6629.     return string;
  6630. }
  6631.  
  6632. char *data2js_array(int data[],int len){
  6633.  /*
  6634.     1,2,3,4,5,6,7,8 --> [1,2,3,4,5,6,7,8]
  6635.     int data[] is already checked for errors or overflow in "get_real()"
  6636.     just to be sure we double check the size of "temp"
  6637. */
  6638.     char temp[MAX_BUFFER], *string;
  6639.     char *tmp = my_newmem(16);/* <= 9999999999999999  */
  6640.     memset(temp,'\0',MAX_BUFFER);/* clear memory */
  6641.     int i;int space_left;
  6642.     temp[0] = '[';/* start js-array */
  6643.     for(i = 0; i < len; i++){
  6644.         if(i == len - 1){sprintf(tmp, "%d", data[i]);}else{sprintf(tmp, "%d,", data[i]);}
  6645.         space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1);
  6646.         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 ");}
  6647.     }
  6648.     strncat(temp,"]",2);
  6649.     string=(char *)my_newmem(sizeof(temp));
  6650.     snprintf(string,sizeof(temp),"%s",temp);
  6651.     return string;
  6652. }
  6653.  
  6654. char *doubledata2js_array(double data[],int len, int decimals){
  6655.  /*
  6656.     1.4355,2.345353,3.3455 --> [1.44,2.35,3.35]
  6657.     double data[] is already checked for errors or overflow in "get_real()"
  6658.     just to be sure we double check the size of "temp"
  6659. */
  6660.     char temp[MAX_BUFFER], *string;
  6661.     char *tmp = my_newmem(16);/* <= 9999999999999999  */
  6662.     memset(temp,'\0',MAX_BUFFER);/* clear memory */
  6663.     int i;int space_left;
  6664.     temp[0] = '[';/* start js-array */
  6665.     for(i = 0; i < len; i++){
  6666.         if(i == len - 1){sprintf(tmp, "%.*f",decimals,data[i]);}else{sprintf(tmp, "%.*f,",decimals,data[i]);}
  6667.         space_left = (int) (sizeof(temp) - strlen(temp) - strlen(tmp) - 1);
  6668.         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 ");}
  6669.     }
  6670.     strncat(temp,"]",2);
  6671.     string=(char *)my_newmem(sizeof(temp));
  6672.     snprintf(string,sizeof(temp),"%s",temp);
  6673.     return string;
  6674. }
  6675.  
  6676.  
  6677. void *my_newmem(size_t size){
  6678.  void   *p;
  6679.  if((p = malloc(size +1)) == NULL){canvas_error("canvasdraw: ran out of memory\n");}
  6680.  return p;
  6681. }
  6682.  
  6683. int find_number_of_digits(int i){
  6684.  if(i < 0 ){ i = -1*i;}
  6685.  int digits = 0;
  6686.  while ( i > 0){
  6687.   digits++;
  6688.   i = i/10;
  6689.  }
  6690.  return digits;
  6691. }
  6692.  
  6693. int count_substring(char* string, char* substring) {
  6694.   int i, j, l1, l2;
  6695.   int count = 0;
  6696.   l1 = strlen(string);
  6697.   l2 = strlen(substring);
  6698.   for(i = 0; i < l1 - l2 + 1; i++) {
  6699.     if(strstr(string + i, substring) == string + i) {
  6700.       count++;
  6701.       i = i + l2 -1;
  6702.     }
  6703.   }
  6704.   return count;
  6705. }
  6706.  
  6707.  
  6708.  
  6709. void check_string_length(int L){
  6710.  if( L > MAX_BUFFER-1){
  6711.   canvas_error("problem with your arguments to command...");
  6712.  }
  6713.  return;
  6714. }
  6715.  
  6716. int get_token(FILE *infile){
  6717.         int     c,i=0;
  6718.         char    temp[MAX_INT], *input_type;
  6719.         char    *line="line",
  6720.         *audio="audio",
  6721.         *blink="blink",
  6722.         *arrowhead="arrowhead",
  6723.         *crosshairsize="crosshairsize",
  6724.         *crosshair="crosshair",
  6725.         *crosshairs="crosshairs",
  6726.         *audioobject="audioobject",
  6727.         *style="style",
  6728.         *mouse="mouse",
  6729.         *mousex="mousex",
  6730.         *mousey="mousey",
  6731.         *mouse_display="display",
  6732.         *mouse_degree="mouse_degree",
  6733.         *userdraw="userdraw",
  6734.         *highlight="highlight",
  6735.         *http="http",
  6736.         *rays="rays",
  6737.         *dashtype="dashtype",
  6738.         *dashed="dashed",
  6739.         *filled="filled",
  6740.         *lattice="lattice",
  6741.         *parallel="parallel",
  6742.         *segment="segment",
  6743.         *segments="segments",
  6744.         *dsegment="dsegment",
  6745.         *dsegments="dsegments",
  6746.         *seg="seg",
  6747.         *segs="segs",
  6748.         *bgimage="bgimage",
  6749.         *bgcolor="bgcolor",
  6750.         *strokecolor="strokecolor",
  6751.         *backgroundimage="backgroundimage",
  6752.         *text="text",
  6753.         *textup="textup",
  6754.         *mouseprecision="mouseprecision",
  6755.         *precision="precision",
  6756.         *plotsteps="plotsteps",
  6757.         *plotstep="plotstep",
  6758.         *tsteps="tsteps",
  6759.         *curve="curve",
  6760.         *dcurve="dcurve",
  6761.         *curvedarrow="curvedarrow",
  6762.         *curvedarrows="curvedarrows",
  6763.         *curvedarrow2="curvedarrow2",
  6764.         *curvedarrows2="curvedarrows2",
  6765.         *plot="plot",
  6766.         *dplot="dplot",
  6767.         *levelcurve="levelcurve",
  6768.         *fontsize="fontsize",
  6769.         *fontcolor="fontcolor",
  6770.         *axis="axis",
  6771.         *axisnumbering="axisnumbering",
  6772.         *axisnumbers="axisnumbers",
  6773.         *arrow="arrow",
  6774.         *vector="vector",
  6775.         *vectors="vectors",
  6776.         *darrow="darrow",
  6777.         *arrow2="arrow2",
  6778.         *darrow2="darrow2",
  6779.         *arrows="arrows",
  6780.         *arrows2="arrows2",
  6781.         *zoom="zoom",
  6782.         *grid="grid",
  6783.         *hline="hline",
  6784.         *dhline="dhline",
  6785.         *drag="drag",
  6786.         *horizontalline="horizontalline",
  6787.         *horizontallines="horizontallines",
  6788.         *vline="vline",
  6789.         *dvline="dvline",
  6790.         *verticalline="verticalline",
  6791.         *verticallines="verticallines",
  6792.         *triangle="triangle",
  6793.         *triangles="triangles",
  6794.         *ftriangle="ftriangle",
  6795.         *ftriangles="ftriangles",
  6796.         *mathml="mathml",
  6797.         *html="html",
  6798.         *input="input",
  6799.         *clearbutton="clearbutton",
  6800.         *erase="erase",
  6801.         *delete="delete",
  6802.         *css="css",
  6803.         *textarea="textarea",
  6804.         *range="range",
  6805.         *trange="trange",
  6806.         *ranget="ranget",
  6807.         *xrange="xrange",
  6808.         *yrange="yrange",
  6809.         *rangex="rangex",
  6810.         *rangey="rangey",
  6811.         *path="path",
  6812.         *polyline="polyline",
  6813.         *dpolyline="dpolyline",
  6814.         *brokenline="brokenline",
  6815.         *lines="lines",
  6816.         *poly="poly",
  6817.         *polygon="polygon",
  6818.         *fpolygon="fpolygon",
  6819.         *fpoly="fpoly",
  6820.         *filledpoly="filledpoly",
  6821.         *filledpolygon="filledpolygon",
  6822.         *rect="rect",
  6823.         *frect="frect",
  6824.         *rectangle="rectangle",
  6825.         *frectangle="frectangle",
  6826.         *square="square",
  6827.         *fsquare="fsquare",
  6828.         *fsquares="fsquares",
  6829.         *rects="rects",
  6830.         *frects="frects",
  6831.         *dline="dline",
  6832.         *arc="arc",
  6833.         *filledarc="filledarc",
  6834.         *farc="farc",
  6835.         *size="size",
  6836.         *string="string",
  6837.         *stringup="stringup",
  6838.         *copy="copy",
  6839.         *copyresized="copyresized",
  6840.         *opacity="opacity",
  6841.         *transparent="transparent",
  6842.         *fill="fill",
  6843.         *point="point",
  6844.         *points="points",
  6845.         *linewidth="linewidth",
  6846.         *circle="circle",
  6847.         *circles="circles",
  6848.         *fcircle="fcircle",
  6849.         *fcircles="fcircles",
  6850.         *disk="disk",
  6851.         *disks="disks",
  6852.         *comment="#",
  6853.         *end="end",
  6854.         *ellipse="ellipse",
  6855.         *ellipses="ellipses",
  6856.         *fellipse="fellipse",
  6857.         *rotate="rotate",
  6858.         *affine="affine",
  6859.         *rotationcenter="rotationcenter",
  6860.         *kill="kill",
  6861.         *killrotate="killrotate",
  6862.         *killaffine="killaffine",
  6863.         *killlinear="killlinear",
  6864.         *killinear="killinear",
  6865.         *fontfamily="fontfamily",
  6866.         *fillcolor="fillcolor",
  6867.         *clicktile="clicktile",
  6868.         *clicktile_colors="clicktile_colors",
  6869.         *translation="translation",
  6870.         *translate="translate",
  6871.         *killtranslation="killtranslation",
  6872.         *killtranslate="killtranslate",
  6873.         *onclick="onclick",
  6874.         *roundrects="roundrects",
  6875.         *roundrect="roundrect",
  6876.         *froundrect="froundrect",
  6877.         *froundrects="froundrects",
  6878.         *roundrectangle="roundrectangle",
  6879.         *patternfill="patternfill",
  6880.         *hatchfill="hatchfill",
  6881.         *diafill="diafill",
  6882.         *diamondfill="diamondfill",
  6883.         *dotfill="dotfill",
  6884.         *textfill="textfill",
  6885.         *gridfill="gridfill",
  6886.         *imagefill="imagefill",
  6887.         *xlogbase="xlogbase",
  6888.         *ylogbase="ylogbase",
  6889.         *xlogscale="xlogscale",
  6890.         *ylogscale="ylogscale",
  6891.         *xylogscale="xylogscale",
  6892.         *intooltip="intooltip",
  6893.         *popup="popup",
  6894.         *replyformat="replyformat",
  6895.         *floodfill="floodfill",
  6896.         *fillall="fillall",
  6897.         *filltoborder="filltoborder",
  6898.         *setpixel="setpixel",
  6899.         *pixels="pixels",
  6900.         *pixelsize="pixelsize",
  6901.         *xaxis="xaxis",
  6902.         *xaxisup="xaxisup",
  6903.         *yaxis="yaxis",
  6904.         *xaxistext="xaxistext",
  6905.         *xaxistextup="xaxistextup",
  6906.         *yaxistext="yaxistext",
  6907.         *piechart="piechart",
  6908.         *boxplot="boxplot",
  6909.         *boxplotdata="boxplotdata",
  6910.         *userboxplot="userboxplot",
  6911.         *userboxplotdata="userboxplotdata",
  6912.         *legend="legend",
  6913.         *legendcolors="legendcolors",
  6914.         *xlabel="xlabel",
  6915.         *ylabel="ylabel",
  6916.         *barchart="barchart",
  6917.         *linegraph="linegraph",
  6918.         *clock="clock",
  6919.         *animate="animate",
  6920.         *video="video",
  6921.         *status="status",
  6922.         *nostatus="nostatus",
  6923.         *snaptogrid="snaptogrid",
  6924.         *xsnaptogrid="xsnaptogrid",
  6925.         *ysnaptogrid="ysnaptogrid",
  6926.         *snaptopoints="snaptopoints",
  6927.         *snaptofunction="snaptofunction",
  6928.         *snaptofun="snaptofun",
  6929.         *userinput_xy="userinput_xy",
  6930.         *userinput_function="userinput_function",
  6931.         *userinput="userinput",
  6932.         *jsmath="jsmath",
  6933.         *trace_jscurve="trace_jscurve",
  6934.         *setlimits="setlimits",
  6935.         *jscurve="jscurve",
  6936.         *jsplot="jsplot",
  6937.         *sgraph="sgraph",
  6938.         *title="title",
  6939.         *centerstring="centerstring",
  6940.         *xunit="xunit",
  6941.         *yunit="yunit",
  6942.         *slider="slider",
  6943.         *killslider="killslider",
  6944.         *killgroup="killgroup",
  6945.         *angle="angle",
  6946.         *halflines="halflines",
  6947.         *demilines="demilines",
  6948.         *halfline="halfline",
  6949.         *demiline="demiline",
  6950.         *hlines="hlines",
  6951.         *vlines="vlines",
  6952.         *bezier="bezier",
  6953.         *functionlabel="functionlabel",
  6954.         *functionlabels="functionlabels",
  6955.         *group="group",
  6956.         *multidraw="multidraw",
  6957.         *multilinewidth="multilinewidth",
  6958.         *linewidths="linewidths",
  6959.         *multistrokecolors="multistrokecolors",
  6960.         *multicolors="multicolors",
  6961.         *strokecolors="strokecolors",
  6962.         *colors="colors",
  6963.         *multifillcolors="multifillcolors",
  6964.         *fillcolors="fillcolors",
  6965.         *multistrokeopacity="multistrokeopacity",
  6966.         *multifillopacity="multifillopacity",
  6967.         *multifill="multifill",
  6968.         *multidash="multidash",
  6969.         *multilabel="multilabel",
  6970.         *multiuserinput="multiuserinput",
  6971.         *multiinput="multiinput",
  6972.         *multisnaptogrid="multisnaptogrid",
  6973.         *multisnap="multisnap",
  6974.         *protractor="protractor",
  6975.         *ruler="ruler",
  6976.         *cursor="cursor",
  6977.         *pointer="pointer",
  6978.         *yerrorbars="yerrorbars",
  6979.         *xerrorbars="xerrorbars",
  6980.         *noxaxis="noxaxis",
  6981.         *noyaxis="noyaxis",
  6982.         *colorpalette="colorpalette",
  6983.         *imagepalette="imagepalette",
  6984.         *yoffset="yoffset",
  6985.         *xoffset="xoffset",
  6986.         *latex="latex",
  6987.         *katex="katex",
  6988.         *math="math",
  6989.         *centered="centered",
  6990.         *xyoffset="xyoffset",
  6991.         *resetoffset="resetoffset",
  6992.         *fillpattern="fillpattern",
  6993.         *settile="settile",
  6994.         *numberline="numberline",
  6995.         *duplicates="duplicates",
  6996.         *allowdups="allowdups",
  6997.         *linear="linear",
  6998.         *obabel="obabel",
  6999.         *chemtex="chemtex",
  7000.         *reset="reset",
  7001.         *noreset="noreset",
  7002.         *killreset="killreset",
  7003.         *arrowarc="arrowarc",
  7004.         *arcarrow="arcarrow",
  7005.         *newrange="newrange",
  7006.         *canvastype="canvastype";
  7007.  
  7008.         while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){
  7009.          if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */
  7010.          }else{
  7011.           if( c == ' ' ){
  7012.             break;
  7013.           }else{
  7014.            temp[i] = c;
  7015.            if(i > MAX_INT - 2){canvas_error("command string too long !");}
  7016.            i++;
  7017.           }
  7018.          }
  7019.          if(temp[0] == '#'){ break; }
  7020.         }
  7021.         if (c == '\n' || c == '\r' || c == '\t' ){  line_number++; }
  7022.         if (c == EOF) {finished=1;return 0;}
  7023.  
  7024.         temp[i]='\0';
  7025.         if(strstr(temp,"dash") !=0 && strlen(temp) > 4 && strstr(temp,"dashtype") == 0 ){
  7026.         /* 4/2024 adapt to Flydraw's dashing syntax for all objects with prefix "dash" */
  7027.             use_dashed = TRUE;int idx=0;int p;
  7028.             for( p = 4; p < strlen(temp); p++){temp[idx] = temp[p];idx++;}
  7029.             input_type = (char*)my_newmem(idx); snprintf(input_type,idx+1,"%s",temp);
  7030.         }else{
  7031.             input_type=(char*)my_newmem(strlen(temp));
  7032.             snprintf(input_type,sizeof(temp),"%s",temp);
  7033.         }
  7034. /*      fprintf(stdout,"input_type = %s no_reset = %d <br/>",input_type,no_reset);*/
  7035.         if( strcmp(input_type, size) == 0 ){
  7036.         free(input_type);
  7037.         return SIZE;
  7038.         }
  7039.         if( strcmp(input_type, range) == 0 ){
  7040.         free(input_type);
  7041.         return RANGE;
  7042.         }
  7043.         if( strcmp(input_type, xrange) == 0 ){
  7044.         free(input_type);
  7045.         return XRANGE;
  7046.         }
  7047.         if( strcmp(input_type, rangex) == 0 ){
  7048.         free(input_type);
  7049.         return XRANGE;
  7050.         }
  7051.         if( strcmp(input_type, trange) == 0 ){
  7052.         free(input_type);
  7053.         return TRANGE;
  7054.         }
  7055.         if( strcmp(input_type, ranget) == 0 ){
  7056.         free(input_type);
  7057.         return TRANGE;
  7058.         }
  7059.         if( strcmp(input_type, newrange) == 0 ){
  7060.         free(input_type);
  7061.         return NEWRANGE;
  7062.         }
  7063.         if( strcmp(input_type, yrange) == 0 ){
  7064.         free(input_type);
  7065.         return YRANGE;
  7066.         }
  7067.         if( strcmp(input_type, rangey) == 0 ){
  7068.         free(input_type);
  7069.         return YRANGE;
  7070.         }
  7071.         if( strcmp(input_type, linewidth) == 0 ){
  7072.         free(input_type);
  7073.         return LINEWIDTH;
  7074.         }
  7075.         if( strcmp(input_type, dashed) == 0 ){
  7076.         free(input_type);
  7077.         return DASHED;
  7078.         }
  7079.         if( strcmp(input_type, dashtype) == 0 ){
  7080.         free(input_type);
  7081.         return DASHTYPE;
  7082.         }
  7083.         if( strcmp(input_type, axisnumbering) == 0 ){
  7084.         free(input_type);
  7085.         return AXIS_NUMBERING;
  7086.         }
  7087.         if( strcmp(input_type, axisnumbers) == 0 ){
  7088.         free(input_type);
  7089.         return AXIS_NUMBERING;
  7090.         }
  7091.         if( strcmp(input_type, axis) == 0 ){
  7092.         free(input_type);
  7093.         return AXIS;
  7094.         }
  7095.         if( strcmp(input_type, grid) == 0 ){
  7096.         free(input_type);
  7097.         return GRID;
  7098.         }
  7099.         if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){
  7100.         free(input_type);
  7101.         return HLINES;
  7102.         }
  7103.         if( strcmp(input_type, vlines) == 0 ||  strcmp(input_type, verticallines) == 0 ){
  7104.         free(input_type);
  7105.         return VLINES;
  7106.         }
  7107.         if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){
  7108.         free(input_type);
  7109.         return HLINE;
  7110.         }
  7111.         if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
  7112.         free(input_type);
  7113.         return VLINE;
  7114.         }
  7115.         if( strcmp(input_type, line) == 0 ){
  7116.         free(input_type);
  7117.         return LINE;
  7118.         }
  7119.         if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){
  7120.         free(input_type);
  7121.         return SEGMENTS;
  7122.         }
  7123.         if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
  7124.         free(input_type);
  7125.         return SEGMENT;
  7126.         }
  7127.         if( strcmp(input_type, dsegments) == 0 ){
  7128.         free(input_type);
  7129.         use_dashed = TRUE;
  7130.         return SEGMENTS;
  7131.         }
  7132.         if( strcmp(input_type, dsegment) == 0 ){
  7133.         free(input_type);
  7134.         use_dashed = TRUE;
  7135.         return SEGMENT;
  7136.         }
  7137.         if( strcmp(input_type, crosshairsize) == 0 ){
  7138.         free(input_type);
  7139.         return CROSSHAIRSIZE;
  7140.         }
  7141.         if( strcmp(input_type, arrowhead) == 0 ){
  7142.         free(input_type);
  7143.         return ARROWHEAD;
  7144.         }
  7145.         if( strcmp(input_type, crosshairs) == 0 ){
  7146.         free(input_type);
  7147.         return CROSSHAIRS;
  7148.         }
  7149.         if( strcmp(input_type, crosshair) == 0 ){
  7150.         free(input_type);
  7151.         return CROSSHAIR;
  7152.         }
  7153.         if( strcmp(input_type, onclick) == 0 ){
  7154.         free(input_type);
  7155.         return ONCLICK;
  7156.         }
  7157.         if( strcmp(input_type, drag) == 0 ){
  7158.         free(input_type);
  7159.         return DRAG;
  7160.         }
  7161.         if( strcmp(input_type, userdraw) == 0 ){
  7162.         free(input_type);
  7163.         return USERDRAW;
  7164.         }
  7165.         if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
  7166.         free(input_type);
  7167.         return STYLE;
  7168.         }
  7169.         if( strcmp(input_type, fillcolor) == 0 ){
  7170.         free(input_type);
  7171.         return FILLCOLOR;
  7172.         }
  7173.         if( strcmp(input_type, strokecolor) == 0 ){
  7174.         free(input_type);
  7175.         return STROKECOLOR;
  7176.         }
  7177.         if( strcmp(input_type, filled) == 0  ){
  7178.         free(input_type);
  7179.         return FILLED;
  7180.         }
  7181.         if( strcmp(input_type, http) == 0 ){
  7182.         free(input_type);
  7183.         return HTTP;
  7184.         }
  7185.         if( strcmp(input_type, rays) == 0 ){
  7186.         free(input_type);
  7187.         return RAYS;
  7188.         }
  7189.         if( strcmp(input_type, lattice) == 0 ){
  7190.         free(input_type);
  7191.         return LATTICE;
  7192.         }
  7193.         if( strcmp(input_type, bgimage) == 0 ){
  7194.         free(input_type);
  7195.         return BGIMAGE;
  7196.         }
  7197.         if( strcmp(input_type, bgcolor) == 0 ){
  7198.         free(input_type);
  7199.         return BGCOLOR;
  7200.         }
  7201.         if( strcmp(input_type, backgroundimage) == 0 ){
  7202.         free(input_type);
  7203.         return BGIMAGE;
  7204.         }
  7205.         if( strcmp(input_type, text) == 0 ){
  7206.         free(input_type);
  7207.         return FLY_TEXT;
  7208.         }
  7209.         if( strcmp(input_type, textup) == 0 ){
  7210.         free(input_type);
  7211.         return FLY_TEXTUP;
  7212.         }
  7213.         if( strcmp(input_type, mouse) == 0 ){
  7214.         free(input_type);
  7215.         return MOUSE;
  7216.         }
  7217.         if( strcmp(input_type, mousex) == 0 ){
  7218.         free(input_type);
  7219.         return MOUSEX;
  7220.         }
  7221.         if( strcmp(input_type, mousey) == 0 ){
  7222.         free(input_type);
  7223.         return MOUSEY;
  7224.         }
  7225.         if( strcmp(input_type, mouse_degree) == 0 ){
  7226.         free(input_type);
  7227.         return MOUSE_DEGREE;
  7228.         }
  7229.         if( strcmp(input_type, mouse_display) == 0 ){
  7230.         free(input_type);
  7231.         return MOUSE_DISPLAY;
  7232.         }
  7233.         if( strcmp(input_type, mouseprecision) == 0 ){
  7234.         free(input_type);
  7235.         return MOUSE_PRECISION;
  7236.         }
  7237.         if( strcmp(input_type, precision) == 0 ){
  7238.         free(input_type);
  7239.         return MOUSE_PRECISION;
  7240.         }
  7241.         if( strcmp(input_type, curve) == 0 ){
  7242.         free(input_type);
  7243.         return CURVE;
  7244.         }
  7245.         if( strcmp(input_type, dcurve) == 0 ){
  7246.         use_dashed = TRUE;
  7247.         free(input_type);
  7248.         return CURVE;
  7249.         }
  7250.         if( strcmp(input_type, plot) == 0 ){
  7251.         free(input_type);
  7252.         return CURVE;
  7253.         }
  7254.         if( strcmp(input_type, dplot) == 0 ){
  7255.         use_dashed = TRUE;
  7256.         free(input_type);
  7257.         return CURVE;
  7258.         }
  7259.         if( strcmp(input_type, levelcurve) == 0 ){
  7260.         free(input_type);
  7261.         return LEVELCURVE;
  7262.         }
  7263.         if( strcmp(input_type, plotsteps) == 0 ){
  7264.         free(input_type);
  7265.         return PLOTSTEPS;
  7266.         }
  7267.         if( strcmp(input_type, plotstep) == 0 ){
  7268.         free(input_type);
  7269.         return PLOTSTEPS;
  7270.         }
  7271.         if( strcmp(input_type, tsteps) == 0 ){
  7272.         free(input_type);
  7273.         return PLOTSTEPS;
  7274.         }
  7275.         if( strcmp(input_type, fontsize) == 0 ){
  7276.         free(input_type);
  7277.         return FONTSIZE;
  7278.         }
  7279.         if( strcmp(input_type, fontcolor) == 0 ){
  7280.         free(input_type);
  7281.         return FONTCOLOR;
  7282.         }
  7283.         if( strcmp(input_type, arrow2) == 0 ){
  7284.         free(input_type);
  7285.         return ARROW2;
  7286.         }
  7287.         if( strcmp(input_type, darrow) == 0 ){
  7288.         free(input_type);
  7289.         use_dashed = TRUE;
  7290.         return ARROW;
  7291.         }
  7292.         if( strcmp(input_type, darrow2) == 0 ){
  7293.         free(input_type);
  7294.         use_dashed = TRUE;
  7295.         return ARROW2;
  7296.         }
  7297.         if( strcmp(input_type, arrows2) == 0 ){
  7298.         free(input_type);
  7299.         return ARROWS2;
  7300.         }
  7301.         if( strcmp(input_type, arrows) == 0  || strcmp(input_type, vectors) == 0 ){
  7302.         free(input_type);
  7303.         return ARROWS;
  7304.         }
  7305.         if( strcmp(input_type, arrow) == 0 ||  strcmp(input_type, vector) == 0 ){
  7306.         free(input_type);
  7307.         return ARROW;
  7308.         }
  7309.         if( strcmp(input_type, zoom) == 0 ){
  7310.         free(input_type);
  7311.         return ZOOM;
  7312.         }
  7313.         if( strcmp(input_type, triangle) == 0 ){
  7314.         free(input_type);
  7315.         return TRIANGLE;
  7316.         }
  7317.         if( strcmp(input_type, triangles) == 0 ){
  7318.         free(input_type);
  7319.         return TRIANGLES;
  7320.         }
  7321.         if( strcmp(input_type, ftriangles) == 0 ){
  7322.         free(input_type);
  7323.         use_filled = TRUE;
  7324.         return TRIANGLES;
  7325.         }
  7326.         if( strcmp(input_type, ftriangle) == 0 ){
  7327.         free(input_type);
  7328.         use_filled = TRUE;
  7329.         return TRIANGLE;
  7330.         }
  7331.         if( strcmp(input_type, input) == 0 ){
  7332.         free(input_type);
  7333.         return INPUT;
  7334.         }
  7335.         if( strcmp(input_type, css) == 0 ){
  7336.         free(input_type);
  7337.         return CSS;
  7338.         }
  7339.         if( strcmp(input_type, textarea) == 0 ){
  7340.         free(input_type);
  7341.         return TEXTAREA;
  7342.         }
  7343.         if( strcmp(input_type, mathml) == 0 ){
  7344.         free(input_type);
  7345.         return MATHML;
  7346.         }
  7347.         if( strcmp(input_type, html) == 0 ){
  7348.         free(input_type);
  7349.         return HTML;
  7350.         }
  7351.         if( strcmp(input_type, fontfamily) == 0 ){
  7352.         free(input_type);
  7353.         return FONTFAMILY;
  7354.         }
  7355.         if( strcmp(input_type, polyline) == 0 ||  strcmp(input_type, dpolyline) == 0 ||  strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){
  7356.         if(strcmp(input_type, dpolyline) == 0 ){use_dashed = TRUE;}
  7357.         free(input_type);
  7358.         return POLYLINE;
  7359.         }
  7360.         if( strcmp(input_type, lines) == 0 ){
  7361.         free(input_type);
  7362.         return LINES;
  7363.         }
  7364.         if( strcmp(input_type, rects) == 0){
  7365.         free(input_type);
  7366.         return RECTS;
  7367.         }
  7368.         if( strcmp(input_type, frects) == 0 ){
  7369.         free(input_type);
  7370.         use_filled = TRUE;
  7371.         return RECTS;
  7372.         }
  7373.         if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
  7374.         free(input_type);
  7375.         return RECT;
  7376.         }
  7377.         if( strcmp(input_type, square) == 0 ){
  7378.         free(input_type);
  7379.         return SQUARE;
  7380.         }
  7381.         if( strcmp(input_type, fsquare) == 0 ){
  7382.         free(input_type);
  7383.         use_filled = TRUE;
  7384.         return SQUARE;
  7385.         }
  7386.         if( strcmp(input_type, fsquares) == 0 ){
  7387.         free(input_type);
  7388.         use_filled = TRUE;
  7389.         return RECTS;
  7390.         }
  7391.         if( strcmp(input_type, roundrects) == 0 ){
  7392.         free(input_type);
  7393.         return ROUNDRECTS;
  7394.         }
  7395.         if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
  7396.         free(input_type);
  7397.         return ROUNDRECT;
  7398.         }
  7399.         if( strcmp(input_type, froundrects) == 0 ){
  7400.         free(input_type);
  7401.         use_filled = TRUE;
  7402.         return ROUNDRECTS;
  7403.         }
  7404.         if( strcmp(input_type, froundrect) == 0 ){
  7405.         free(input_type);
  7406.         use_filled = TRUE;
  7407.         return ROUNDRECT;
  7408.         }
  7409.         if( strcmp(input_type, dline) == 0 ){
  7410.         use_dashed = TRUE;
  7411.         free(input_type);
  7412.         return LINE;
  7413.         }
  7414.         if( strcmp(input_type, dvline) == 0 ){
  7415.         use_dashed = TRUE;
  7416.         free(input_type);
  7417.         return VLINE;
  7418.         }
  7419.         if( strcmp(input_type, dhline) == 0 ){
  7420.         use_dashed = TRUE;
  7421.         free(input_type);
  7422.         return HLINE;
  7423.         }
  7424.         if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0  ){
  7425.         free(input_type);
  7426.         return HALFLINES;
  7427.         }
  7428.         if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0  ){
  7429.         free(input_type);
  7430.         return HALFLINE;
  7431.         }
  7432.         if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
  7433.         use_filled = TRUE;
  7434.         free(input_type);
  7435.         return RECT;
  7436.         }
  7437.         if( strcmp(input_type, circles) == 0 ){
  7438.         free(input_type);
  7439.         return CIRCLES;
  7440.         }
  7441.         if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
  7442.         use_filled = TRUE;
  7443.         free(input_type);
  7444.         return CIRCLE;
  7445.         }
  7446.         if( strcmp(input_type, fcircles) == 0  ||  strcmp(input_type, disks) == 0 ){
  7447.         use_filled = TRUE;
  7448.         free(input_type);
  7449.         return CIRCLES;
  7450.         }
  7451.         if( strcmp(input_type, circle) == 0 ){
  7452.         free(input_type);
  7453.         return CIRCLE;
  7454.         }
  7455.         if( strcmp(input_type, point) == 0 ){
  7456.         free(input_type);
  7457.         return POINT;
  7458.         }
  7459.         if( strcmp(input_type, points) == 0 ){
  7460.         free(input_type);
  7461.         return POINTS;
  7462.         }
  7463.         if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){
  7464.         use_filled = TRUE;
  7465.         free(input_type);
  7466.         return ARC;
  7467.         }
  7468.         if( strcmp(input_type, arc) == 0 ){
  7469.         free(input_type);
  7470.         return ARC;
  7471.         }
  7472.         if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
  7473.         free(input_type);
  7474.         return POLY;
  7475.         }
  7476.         if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
  7477.         use_filled = TRUE;
  7478.         free(input_type);
  7479.         return POLY;
  7480.         }
  7481.         if( strcmp(input_type, ellipse) == 0){
  7482.         free(input_type);
  7483.         return ELLIPSE;
  7484.         }
  7485.         if( strcmp(input_type, ellipses) == 0){
  7486.         free(input_type);
  7487.         return ELLIPSES;
  7488.         }
  7489.         if( strcmp(input_type, string) == 0 ){
  7490.         free(input_type);
  7491.         return STRING;
  7492.         }
  7493.         if( strcmp(input_type, stringup) == 0 ){
  7494.         free(input_type);
  7495.         return STRINGUP;
  7496.         }
  7497.         if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){
  7498.         free(input_type);
  7499.         return OPACITY;
  7500.         }
  7501.         if( strcmp(input_type, comment) == 0){
  7502.         free(input_type);
  7503.         return COMMENT;
  7504.         }
  7505.         if( strcmp(input_type, fellipse) == 0){
  7506.         free(input_type);
  7507.         use_filled = TRUE;
  7508.         return ELLIPSE;
  7509.         }
  7510.         if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){
  7511.         free(input_type);
  7512.         return CLEARBUTTON;
  7513.         }
  7514.         if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
  7515.         free(input_type);
  7516.         return TRANSLATION;
  7517.         }
  7518.         if( strcmp(input_type, kill) == 0 ){
  7519.         free(input_type);
  7520.         return KILL;
  7521.         }
  7522.         if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
  7523.         free(input_type);
  7524.         return KILLTRANSLATION;
  7525.         }
  7526.         if( strcmp(input_type, rotate) == 0){
  7527.         free(input_type);
  7528.         return ROTATE;
  7529.         }
  7530.         if( strcmp(input_type, killrotate) == 0){
  7531.         free(input_type);
  7532.         return KILLROTATE;
  7533.         }
  7534.         if( strcmp(input_type, rotationcenter) == 0){
  7535.         free(input_type);
  7536.         return ROTATION_CENTER;
  7537.         }
  7538.         if( strcmp(input_type, affine) == 0){
  7539.         free(input_type);
  7540.         return AFFINE;
  7541.         }
  7542.         if( strcmp(input_type, linear) == 0){
  7543.         free(input_type);
  7544.         return LINEAR;
  7545.         }
  7546.         if( strcmp(input_type, killaffine) == 0){
  7547.         free(input_type);
  7548.         return KILLAFFINE;
  7549.         }
  7550.         if( strcmp(input_type, killlinear) == 0 || strcmp(input_type, killinear) == 0  ){
  7551.         free(input_type);
  7552.         return KILLLINEAR;
  7553.         }
  7554.         if( strcmp(input_type, slider) == 0 ){
  7555.         free(input_type);
  7556.         return SLIDER;
  7557.         }
  7558.         if( strcmp(input_type, killslider) == 0 || strcmp(input_type, killgroup) == 0 ){
  7559.         free(input_type);
  7560.         return KILLSLIDER;
  7561.         }
  7562.         if( strcmp(input_type, copy) == 0 ){
  7563.         free(input_type);
  7564.         return COPY;
  7565.         }
  7566.         if( strcmp(input_type, copyresized) == 0 ){
  7567.         free(input_type);
  7568.         return COPYRESIZED;
  7569.         }
  7570.         if( strcmp(input_type, xlogscale) == 0 ){
  7571.         free(input_type);
  7572.         return XLOGSCALE;
  7573.         }
  7574.         if( strcmp(input_type, ylogscale) == 0 ){
  7575.         free(input_type);
  7576.         return YLOGSCALE;
  7577.         }
  7578.         if( strcmp(input_type, xylogscale) == 0 ){
  7579.         free(input_type);
  7580.         return XYLOGSCALE;
  7581.         }
  7582.         if( strcmp(input_type, ylogscale) == 0 ){
  7583.         free(input_type);
  7584.         return YLOGSCALE;
  7585.         }
  7586.         if( strcmp(input_type, xlogbase) == 0 ){
  7587.         free(input_type);
  7588.         return XLOGBASE;
  7589.         }
  7590.         if( strcmp(input_type, ylogbase) == 0 ){
  7591.         free(input_type);
  7592.         return YLOGBASE;
  7593.         }
  7594.         if( strcmp(input_type, intooltip) == 0 ){
  7595.         free(input_type);
  7596.         return INTOOLTIP;
  7597.         }
  7598.         if( strcmp(input_type, popup) == 0 ){
  7599.         free(input_type);
  7600.         return POPUP;
  7601.         }
  7602.         if( strcmp(input_type,video) == 0 ){
  7603.         free(input_type);
  7604.         return VIDEO;
  7605.         }
  7606.         if( strcmp(input_type,math) == 0 || strcmp(input_type,latex) == 0 ||  strcmp(input_type,katex) == 0 ){
  7607.         free(input_type);
  7608.         return LATEX;
  7609.         }
  7610.         if( strcmp(input_type,fillall) == 0 ){
  7611.         free(input_type);
  7612.         return FILLALL;
  7613.         }
  7614.         if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
  7615.         free(input_type);
  7616.         return FLOODFILL;
  7617.         }
  7618.         if( strcmp(input_type,filltoborder) == 0 ){
  7619.         free(input_type);
  7620.         return FILLTOBORDER;
  7621.         }
  7622.         if( strcmp(input_type, curvedarrow2) == 0 ){
  7623.         free(input_type);
  7624.         return CURVEDARROW2;
  7625.         }
  7626.         if( strcmp(input_type, curvedarrow) == 0 ){
  7627.         free(input_type);
  7628.         return CURVEDARROW;
  7629.         }
  7630.         if( strcmp(input_type, curvedarrows) == 0 ){
  7631.         free(input_type);
  7632.         return CURVEDARROWS;
  7633.         }
  7634.         if( strcmp(input_type, curvedarrows2) == 0 ){
  7635.         free(input_type);
  7636.         return CURVEDARROWS2;
  7637.         }
  7638.         if( strcmp(input_type, replyformat) == 0 ){
  7639.         free(input_type);
  7640.         return REPLYFORMAT;
  7641.         }
  7642.         if( strcmp(input_type, pixelsize) == 0 ){
  7643.         free(input_type);
  7644.         return PIXELSIZE;
  7645.         }
  7646.         if( strcmp(input_type, setpixel) == 0 ){
  7647.         free(input_type);
  7648.         return SETPIXEL;
  7649.         }
  7650.         if( strcmp(input_type, pixels) == 0 ){
  7651.         free(input_type);
  7652.         return PIXELS;
  7653.         }
  7654.         if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
  7655.         free(input_type);
  7656.         return X_AXIS_STRINGS;
  7657.         }
  7658.         if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){
  7659.         free(input_type);
  7660.         return X_AXIS_STRINGS_UP;
  7661.         }
  7662.         if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
  7663.         free(input_type);
  7664.         return Y_AXIS_STRINGS;
  7665.         }
  7666.         if( strcmp(input_type, legend) == 0  ){
  7667.         free(input_type);
  7668.         return LEGEND;
  7669.         }
  7670.         if( strcmp(input_type, legendcolors) == 0  ){
  7671.         free(input_type);
  7672.         return LEGENDCOLORS;
  7673.         }
  7674.         if( strcmp(input_type, xlabel) == 0  ){
  7675.         free(input_type);
  7676.         return XLABEL;
  7677.         }
  7678.         if( strcmp(input_type, ylabel) == 0  ){
  7679.         free(input_type);
  7680.         return YLABEL;
  7681.         }
  7682.         if( strcmp(input_type, bezier) == 0  ){
  7683.         free(input_type);
  7684.         return BEZIER;
  7685.         }
  7686.         if( strcmp(input_type, animate) == 0  ){
  7687.         free(input_type);
  7688.         return ANIMATE;
  7689.         }
  7690.         /* these are bitmap related flydraw commands...must be removed. eventually */
  7691.         if( strcmp(input_type, transparent) == 0 ){
  7692.         free(input_type);
  7693.         return TRANSPARENT;
  7694.         }
  7695.         if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
  7696.         free(input_type);
  7697.         return STATUS;
  7698.         }
  7699.         if( strcmp(input_type, xsnaptogrid) == 0 ){
  7700.         free(input_type);
  7701.         return XSNAPTOGRID;
  7702.         }
  7703.         if( strcmp(input_type, ysnaptogrid) == 0 ){
  7704.         free(input_type);
  7705.         return YSNAPTOGRID;
  7706.         }
  7707.         if( strcmp(input_type, snaptogrid) == 0 ){
  7708.         free(input_type);
  7709.         return SNAPTOGRID;
  7710.         }
  7711.         if( strcmp(input_type, snaptopoints) == 0 ){
  7712.         free(input_type);
  7713.         return SNAPTOPOINTS;
  7714.         }
  7715.         if( strcmp(input_type, snaptofunction) == 0  || strcmp(input_type, snaptofun) == 0 ){
  7716.         free(input_type);
  7717.         return SNAPTOFUNCTION;
  7718.         }
  7719.         if( strcmp(input_type, userinput_xy) == 0 ){
  7720.         free(input_type);
  7721.         return USERINPUT_XY;
  7722.         }
  7723.         if( strcmp(input_type, userinput_function) == 0 ){
  7724.         free(input_type);
  7725.         return USERINPUT_FUNCTION;
  7726.         }
  7727.         if( strcmp(input_type, userinput) == 0 ){
  7728.         free(input_type);
  7729.         return USERINPUT;
  7730.         }
  7731.         if( strcmp(input_type, angle) == 0 ){
  7732.         free(input_type);
  7733.         return ANGLE;
  7734.         }
  7735.         if( strcmp(input_type, functionlabel) == 0 ||  strcmp(input_type, functionlabels) == 0 ){
  7736.         free(input_type);
  7737.         return FUNCTION_LABEL;
  7738.         }
  7739.         if( strcmp(input_type, group) == 0 ){
  7740.         free(input_type);
  7741.         return GROUP;
  7742.         }
  7743.         if( strcmp(input_type, multidraw) == 0 ){
  7744.         free(input_type);
  7745.         return MULTIDRAW;
  7746.         }
  7747.         if( strcmp(input_type, multistrokeopacity) == 0 ){
  7748.         free(input_type);
  7749.         return MULTISTROKEOPACITY;
  7750.         }
  7751.         if( strcmp(input_type, multifillopacity) == 0 ){
  7752.         free(input_type);
  7753.         return MULTIFILLOPACITY;
  7754.         }
  7755.         if( strcmp(input_type, multilinewidth) == 0 || strcmp(input_type, linewidths) == 0 ){
  7756.         free(input_type);
  7757.         return MULTILINEWIDTH;
  7758.         }
  7759.         if( strcmp(input_type, multistrokecolors) == 0 || strcmp(input_type,multicolors) == 0  || strcmp(input_type,strokecolors) == 0 ||  strcmp(input_type,colors) == 0 ){
  7760.         free(input_type);
  7761.         return MULTISTROKECOLORS;
  7762.         }
  7763.         if( strcmp(input_type, multifill) == 0 ){
  7764.         free(input_type);
  7765.         return MULTIFILL;
  7766.         }
  7767.         if( strcmp(input_type, multifillcolors) == 0 || strcmp(input_type, fillcolors) == 0  ){
  7768.         free(input_type);
  7769.         return MULTIFILLCOLORS;
  7770.         }
  7771.         if( strcmp(input_type, multilabel) == 0 ){
  7772.         free(input_type);
  7773.         return MULTILABEL;
  7774.         }
  7775.         if( strcmp(input_type, multidash) == 0 ){
  7776.         free(input_type);
  7777.         return MULTIDASH;
  7778.         }
  7779.         if( strcmp(input_type, multisnaptogrid) == 0  ||  strcmp(input_type, multisnap) == 0 ){
  7780.         free(input_type);
  7781.         return MULTISNAPTOGRID;
  7782.         }
  7783.         if( strcmp(input_type, multiuserinput) == 0 || strcmp(input_type, multiinput) == 0  ){
  7784.         free(input_type);
  7785.         return MULTIUSERINPUT;
  7786.         }
  7787.         if( strcmp(input_type, parallel) == 0 ){
  7788.         free(input_type);
  7789.         return PARALLEL;
  7790.         }
  7791.         if( strcmp(input_type, protractor) == 0 ){
  7792.         free(input_type);
  7793.         return PROTRACTOR;
  7794.         }
  7795.         if( strcmp(input_type, ruler) == 0 ){
  7796.         free(input_type);
  7797.         return RULER;
  7798.         }
  7799.         if( strcmp(input_type, cursor) == 0 ||  strcmp(input_type, pointer) == 0 ){
  7800.         free(input_type);
  7801.         return CURSOR;
  7802.         }
  7803.         if( strcmp(input_type, sgraph) == 0 ){
  7804.         free(input_type);
  7805.         return SGRAPH;
  7806.         }
  7807.         if( strcmp(input_type, jsmath) == 0 ){
  7808.         free(input_type);
  7809.         return JSMATH;
  7810.         }
  7811.         if( strcmp(input_type, trace_jscurve) == 0 ){
  7812.         free(input_type);
  7813.         return TRACE_JSCURVE;
  7814.         }
  7815.         if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
  7816.         free(input_type);
  7817.         return JSCURVE;
  7818.         }
  7819.         if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
  7820.         free(input_type);
  7821.         return CENTERSTRING;
  7822.         }
  7823.         if( strcmp(input_type, setlimits) == 0 ){
  7824.         free(input_type);
  7825.         return SETLIMITS;
  7826.         }
  7827.         if( strcmp(input_type, xunit) == 0 ){
  7828.         free(input_type);
  7829.         return XUNIT;
  7830.         }
  7831.         if( strcmp(input_type, yunit) == 0 ){
  7832.         free(input_type);
  7833.         return YUNIT;
  7834.         }
  7835.         if( strcmp(input_type, fill) == 0 ){
  7836.         free(input_type);
  7837.         return FLOODFILL;
  7838.         }
  7839.         if( strcmp(input_type, end) == 0){
  7840.         free(input_type);
  7841.         return END;
  7842.         }
  7843.         if( strcmp(input_type, blink) == 0 ){
  7844.         free(input_type);
  7845.         return BLINK;
  7846.         }
  7847.         if( strcmp(input_type, audio) == 0 ){
  7848.         free(input_type);
  7849.         return AUDIO;
  7850.         }
  7851.         if( strcmp(input_type, audioobject) == 0 ){
  7852.         free(input_type);
  7853.         return AUDIOOBJECT;
  7854.         }
  7855.         if( strcmp(input_type, patternfill) == 0 ){
  7856.         free(input_type);
  7857.         return PATTERNFILL;
  7858.         }
  7859.         if( strcmp(input_type, hatchfill) == 0 ){
  7860.         free(input_type);
  7861.         return HATCHFILL;
  7862.         }
  7863.         if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
  7864.         free(input_type);
  7865.         return DIAMONDFILL;
  7866.         }
  7867.         if( strcmp(input_type, dotfill) == 0 ){
  7868.         free(input_type);
  7869.         return DOTFILL;
  7870.         }
  7871.         if( strcmp(input_type, textfill) == 0 ){
  7872.         free(input_type);
  7873.         return TEXTFILL;
  7874.         }
  7875.         if( strcmp(input_type, gridfill) == 0 ){
  7876.         free(input_type);
  7877.         return GRIDFILL;
  7878.         }
  7879.         if( strcmp(input_type, imagefill) == 0 ){
  7880.         free(input_type);
  7881.         return IMAGEFILL;
  7882.         }
  7883.         if( strcmp(input_type, clicktile_colors) == 0 ){
  7884.         free(input_type);
  7885.         return CLICKTILE_COLORS;
  7886.         }
  7887.         if( strcmp(input_type, clicktile) == 0 ){
  7888.         free(input_type);
  7889.         return CLICKTILE;
  7890.         }
  7891.         if( strcmp(input_type, piechart) == 0  ){
  7892.         free(input_type);
  7893.         return PIECHART;
  7894.         }
  7895.         if( strcmp(input_type, boxplot) == 0  ){
  7896.         free(input_type);
  7897.         return BOXPLOT;
  7898.         }
  7899.         if( strcmp(input_type, boxplotdata) == 0  ){
  7900.         free(input_type);
  7901.         return BOXPLOTDATA;
  7902.         }
  7903.         if( strcmp(input_type, userboxplot) == 0  ){
  7904.         free(input_type);
  7905.         return USERBOXPLOT;
  7906.         }
  7907.         if( strcmp(input_type, userboxplotdata) == 0  ){
  7908.         free(input_type);
  7909.         return USERBOXPLOT;
  7910.         }
  7911.         if( strcmp(input_type, barchart) == 0  ){
  7912.         free(input_type);
  7913.         return BARCHART;
  7914.         }
  7915.         if( strcmp(input_type, linegraph) == 0  ){
  7916.         free(input_type);
  7917.         return LINEGRAPH;
  7918.         }
  7919.         if( strcmp(input_type, clock) == 0  ){
  7920.         free(input_type);
  7921.         return CLOCK;
  7922.         }
  7923.         if( strcmp(input_type, yerrorbars) == 0  ){
  7924.         free(input_type);
  7925.         return YERRORBARS;
  7926.         }
  7927.         if( strcmp(input_type, xerrorbars) == 0  ){
  7928.         free(input_type);
  7929.         return XERRORBARS;
  7930.         }
  7931.         if( strcmp(input_type, canvastype) == 0  ){
  7932.         free(input_type);
  7933.         return CANVASTYPE;
  7934.         }
  7935.         if( strcmp(input_type, noyaxis) == 0  ){
  7936.         free(input_type);
  7937.         return NOYAXIS;
  7938.         }
  7939.         if( strcmp(input_type, noxaxis) == 0  ){
  7940.         free(input_type);
  7941.         return NOXAXIS;
  7942.         }
  7943.         if( strcmp(input_type, colorpalette) == 0  ){
  7944.         free(input_type);
  7945.         return COLORPALETTE;
  7946.         }
  7947.         if( strcmp(input_type, imagepalette) == 0  ){
  7948.         free(input_type);
  7949.         return IMAGEPALETTE;
  7950.         }
  7951.         if( strcmp(input_type,reset) == 0){
  7952.         free(input_type);
  7953.         return RESET;
  7954.         }
  7955.         if( strcmp(input_type, resetoffset) == 0  ){
  7956.         free(input_type);
  7957.         return RESETOFFSET;
  7958.         }
  7959.         if( strcmp(input_type, xyoffset) == 0  ){
  7960.         free(input_type);
  7961.         return XYOFFSET;
  7962.         }
  7963.         if( strcmp(input_type, centered) == 0 ){
  7964.         free(input_type);
  7965.         return CENTERED;
  7966.         }
  7967.         if( strcmp(input_type, yoffset) == 0   ){
  7968.         free(input_type);
  7969.         return YOFFSET;
  7970.         }
  7971.         if( strcmp(input_type, xoffset) == 0   ){
  7972.         free(input_type);
  7973.         return XOFFSET;
  7974.         }
  7975.         if( strcmp(input_type, fillpattern) == 0 ||  strcmp(input_type, settile) == 0  ){
  7976.         free(input_type);
  7977.         return FILLPATTERN;
  7978.         }
  7979.         if( strcmp(input_type, numberline) == 0 ){
  7980.         free(input_type);
  7981.         return NUMBERLINE;
  7982.         }
  7983.         if( strcmp(input_type, obabel) == 0 ){
  7984.         free(input_type);
  7985.         return OBABEL;
  7986.         }
  7987.         if( strcmp(input_type, chemtex) == 0 ){
  7988.         free(input_type);
  7989.         return CHEMTEX;
  7990.         }
  7991.         if( strcmp(input_type, noreset) == 0  || strcmp(input_type, killreset) == 0 ){
  7992.          return NORESET;
  7993.         }
  7994.         if( strcmp(input_type, duplicates) == 0 || strcmp(input_type, allowdups) == 0 ){
  7995.         free(input_type);
  7996.         return ALLOW_DUPLICATES;
  7997.         }
  7998.         if( strcmp(input_type, arrowarc) == 0 || strcmp(input_type, arcarrow) == 0 ){
  7999.         free(input_type);
  8000.         return ARCARROW;
  8001.         }
  8002.         free(input_type);
  8003.         ungetc(c,infile);
  8004.         return 0;
  8005. }
  8006.  
  8007.  
  8008.  
  8009.